Blender V5.3
numinput.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include <algorithm>
10#include <limits>
11
12#include "MEM_guardedalloc.h"
13
15#include "BLI_math_vector_c.hh"
16#include "BLI_string.hh"
18#include "BLI_string_utf8.hh"
19#include "BLI_utildefines.hh"
20
21#include "BLT_translation.hh"
22
23#include "BKE_context.hh"
24#include "BKE_report.hh"
25#include "BKE_unit.hh"
26
27#include "DNA_scene_types.h"
28
29#include "WM_api.hh"
30#include "WM_types.hh"
31
32#ifdef WITH_PYTHON
33# include "BPY_extern_run.hh"
34#endif
35
36#include "ED_numinput.hh"
37
38#include "UI_interface.hh"
39
40namespace blender {
41
42/* Numeric input which isn't allowing full numeric editing. */
43#define USE_FAKE_EDIT
44
49enum {
51 NUM_EDIT_FULL = (1 << 9),
52#ifdef USE_FAKE_EDIT
54 NUM_FAKE_EDITED = (1 << 10),
55#endif
56};
57
58/* NumInput.val_flag[] */
59enum {
60 /* (1 << 8) and below are reserved for public flags! */
62 NUM_EDITED = (1 << 9),
63 NUM_INVALID = (1 << 10),
64#ifdef USE_FAKE_EDIT
66 NUM_NEGATE = (1 << 11),
67 NUM_INVERSE = (1 << 12),
68#endif
69};
70
71/* ************************** Functions *************************** */
72
73bool ED_numinput_double_is_int(double value)
74{
75 value = std::abs(value);
76 /* Use `>=` because `uint64_t::max` rounds up to 2^64 when converted to double. */
77 if (!isfinite(value) || value >= double(std::numeric_limits<uint64_t>::max())) {
78 return false;
79 }
80 return value == double(uint64_t(value));
81}
82
83/* ************************** NUMINPUT **************************** */
84
86{
87 n->idx_max = 0;
89 std::fill_n(n->unit_type, NUM_MAX_ELEMENTS, B_UNIT_NONE);
90 n->unit_use_radians = false;
91
92 n->flag = 0;
93 std::fill_n(n->val_flag, NUM_MAX_ELEMENTS, 0);
94 zero_v3(n->val);
95 std::fill_n(n->val_no_units, NUM_MAX_ELEMENTS, 0.0);
96 std::fill_n(n->val_org, NUM_MAX_ELEMENTS, 0.0f);
97 std::fill_n(n->val_inc, NUM_MAX_ELEMENTS, 1.0f);
98
99 n->idx = 0;
100 n->str[0] = '\0';
101 n->str_cur = 0;
102}
103
104void outputNumInput(NumInput *n, char *str, const UnitSettings &unit_settings)
105{
106 short j;
107 const int ln = NUM_STR_REP_LEN;
108 int prec = 2; /* draw-only, and avoids too much issues with radian->degrees conversion. */
109
110 for (j = 0; j <= n->idx_max; j++) {
111 /* if AFFECTALL and no number typed and cursor not on number, use first number */
112 const short i = (n->flag & NUM_AFFECT_ALL && n->idx != j && !(n->val_flag[j] & NUM_EDITED)) ?
113 0 :
114 j;
115
116 /* Use scale_length if needed! */
117 const float fac = float(BKE_unit_value_scale(unit_settings, n->unit_type[j], 1.0));
118
119 if (n->val_flag[i] & NUM_EDITED) {
120 /* Get the best precision, allows us to draw '10.0001' as '10' instead! */
121 prec = ui::calc_float_precision(prec, double(n->val[i]));
122 if (i == n->idx) {
123 const char *heading_exp = "", *trailing_exp = "";
124 char before_cursor[NUM_STR_REP_LEN];
125 char val[16];
126
127#ifdef USE_FAKE_EDIT
128 if (n->val_flag[i] & NUM_NEGATE) {
129 heading_exp = (n->val_flag[i] & NUM_INVERSE) ? "-1/(" : "-(";
130 trailing_exp = ")";
131 }
132 else if (n->val_flag[i] & NUM_INVERSE) {
133 heading_exp = "1/(";
134 trailing_exp = ")";
135 }
136#endif
137
138 if (n->val_flag[i] & NUM_INVALID) {
139 STRNCPY_UTF8(val, RPT_("Invalid"));
140 }
141 else {
143 sizeof(val),
144 double(n->val[i] * fac),
145 prec,
146 n->unit_sys,
147 n->unit_type[i],
148 true,
149 false,
150 true);
151 }
152
153 /* +1 because of trailing '\0' */
154 BLI_strncpy_utf8(before_cursor, n->str, n->str_cur + 1);
155 BLI_snprintf_utf8(&str[j * ln],
156 ln,
157 "[%s%s|%s%s] = %s",
158 heading_exp,
159 before_cursor,
160 &n->str[n->str_cur],
161 trailing_exp,
162 val);
163 }
164 else {
165 const char *cur = (i == n->idx) ? "|" : "";
166 if (n->unit_use_radians && n->unit_type[i] == B_UNIT_ROTATION) {
167 /* Radian exception... */
168 BLI_snprintf_utf8(&str[j * ln], ln, "%s%.6gr%s", cur, n->val[i], cur);
169 }
170 else {
171 char tstr[NUM_STR_REP_LEN];
173 tstr, ln, double(n->val[i]), prec, n->unit_sys, n->unit_type[i], true, false, true);
174 BLI_snprintf_utf8(&str[j * ln], ln, "%s%s%s", cur, tstr, cur);
175 }
176 }
177 }
178 else {
179 const char *cur = (i == n->idx) ? "|" : "";
180 BLI_snprintf_utf8(&str[j * ln], ln, "%sNONE%s", cur, cur);
181 }
182 /* We might have cut some multi-bytes UTF8 chars
183 * (e.g. trailing degrees symbol values can become only 'A'). */
184 BLI_str_utf8_invalid_strip(&str[j * ln], strlen(&str[j * ln]));
185 }
186}
187
188bool hasNumInput(const NumInput *n)
189{
190 short i;
191
192#ifdef USE_FAKE_EDIT
193 if (n->flag & NUM_FAKE_EDITED) {
194 return true;
195 }
196#endif
197
198 for (i = 0; i <= n->idx_max; i++) {
199 if (n->val_flag[i] & NUM_EDITED) {
200 return true;
201 }
202 }
203
204 return false;
205}
206
207bool applyNumInput(NumInput *n, float *vec)
208{
209 short i, j;
210 float val;
211
212 if (hasNumInput(n)) {
213 for (j = 0; j <= n->idx_max; j++) {
214#ifdef USE_FAKE_EDIT
215 if (n->flag & NUM_FAKE_EDITED) {
216 val = n->val[j];
217 }
218 else
219#endif
220 {
221 /* if AFFECTALL and no number typed and cursor not on number, use first number */
222 i = (n->flag & NUM_AFFECT_ALL && n->idx != j && !(n->val_flag[j] & NUM_EDITED)) ? 0 : j;
223 val = (!(n->val_flag[i] & NUM_EDITED) && n->val_flag[i] & NUM_NULL_ONE) ? 1.0f : n->val[i];
224
225 if (n->val_flag[i] & NUM_NO_NEGATIVE && val < 0.0f) {
226 val = 0.0f;
227 }
228 if (n->val_flag[i] & NUM_NO_FRACTION && val != floorf(val)) {
229 val = floorf(val + 0.5f);
230 if (n->val_flag[i] & NUM_NO_ZERO && val == 0.0f) {
231 val = 1.0f;
232 }
233 }
234 else if (n->val_flag[i] & NUM_NO_ZERO && val == 0.0f) {
235 val = 0.0001f;
236 }
237 }
238 vec[j] = val;
239 }
240#ifdef USE_FAKE_EDIT
242#endif
243 return true;
244 }
245
246 /* Else, we set the 'org' values for numinput! */
247 for (j = 0; j <= n->idx_max; j++) {
248 n->val[j] = n->val_org[j] = vec[j];
249 }
250 return false;
251}
252
253static void value_to_editstr(NumInput *n, int idx)
254{
255 const int prec = 6; /* editing, higher precision needed. */
258 double(n->val[idx]),
259 prec,
260 n->unit_sys,
261 n->unit_type[idx],
262 true,
263 false,
264 true);
265}
266
267static bool editstr_insert_at_cursor(NumInput *n, const char *buf, const int buf_len)
268{
269 int cur = n->str_cur;
270 int len = strlen(&n->str[cur]) + 1; /* +1 for the trailing '\0'. */
271 int n_cur = cur + buf_len;
272
273 if (n_cur + len >= NUM_STR_REP_LEN) {
274 return false;
275 }
276
277 memmove(&n->str[n_cur], &n->str[cur], len);
278 memcpy(&n->str[cur], buf, sizeof(char) * buf_len);
279
280 n->str_cur = n_cur;
281 return true;
282}
283
285 const char *str,
286 const UnitSettings &unit,
287 int type,
288 double *r_value,
289 double *r_value_no_units,
290 const bool use_single_line_error,
291 char **r_error)
292{
293#ifdef WITH_PYTHON
294 BPy_RunErrInfo err_info{};
295 err_info.use_single_line_error = use_single_line_error;
296 err_info.r_string = r_error;
297
298 const double unit_scale = BKE_unit_value_scale(unit, type, 1.0);
300 char str_unit_convert[256];
301 STRNCPY_UTF8(str_unit_convert, str);
303 str_unit_convert, sizeof(str_unit_convert), str, unit_scale, unit.system, type);
304
305 bool success = BPY_run_string_as_number(C, nullptr, str_unit_convert, &err_info, r_value);
306 if (r_value_no_units) {
307 /* When explicit units are in the string, the pre-scale value isn't directly recoverable.
308 * Store the post-conversion value; callers relying on integer detection will naturally
309 * reject non-integer results (e.g. "90deg" evaluates to ~1.5708 radians). */
310 *r_value_no_units = *r_value;
311 }
312 return success;
313 }
314
315 bool success = BPY_run_string_as_number(C, nullptr, str, &err_info, r_value);
316 if (r_value_no_units) {
317 *r_value_no_units = *r_value;
318 }
319 *r_value = BKE_unit_apply_preferred_unit(unit, type, *r_value);
320 *r_value /= unit_scale;
321 return success;
322
323#else
324 UNUSED_VARS(C, unit, type, use_single_line_error, r_error);
325 *r_value = atof(str);
326 if (r_value_no_units) {
327 *r_value_no_units = *r_value;
328 }
329 return true;
330#endif
331}
332
333static bool editstr_is_simple_numinput(const char ascii)
334{
335 if (ascii >= '0' && ascii <= '9') {
336 return true;
337 }
338 if (ascii == '.') {
339 return true;
340 }
341 return false;
342}
343
344bool handleNumInput(bContext *C, NumInput *n, const wmEvent *event)
345{
346 const char *utf8_buf = nullptr;
347 const char event_ascii = WM_event_utf8_to_ascii(event);
348 char ascii[2] = {'\0', '\0'};
349 bool updated = false;
350 short idx = n->idx, idx_max = n->idx_max;
351 short dir = STRCUR_DIR_NEXT, mode = STRCUR_JUMP_NONE;
352 int cur;
353
354#ifdef USE_FAKE_EDIT
356#endif
357 {
358 if (((event->modifier & (KM_CTRL | KM_ALT)) == 0) && (event_ascii != '\0') &&
359 strchr("01234567890@%^&*-+/{}()[]<>.|", event_ascii))
360 {
361 if (!(n->flag & NUM_EDIT_FULL)) {
362 n->flag |= NUM_EDITED;
363 n->flag |= NUM_EDIT_FULL;
364 n->val_flag[idx] |= NUM_EDITED;
365 }
366 }
367 }
368
369#ifdef USE_FAKE_EDIT
370 /* XXX Hack around keyboards without direct access to '=' nor '*'... */
371 if (ELEM(event_ascii, '=', '*')) {
372 if (!(n->flag & NUM_EDIT_FULL)) {
373 n->flag |= NUM_EDIT_FULL;
374 n->val_flag[idx] |= NUM_EDITED;
375 return true;
376 }
377 if (event->modifier & KM_CTRL) {
378 n->flag &= ~NUM_EDIT_FULL;
379 return true;
380 }
381 }
382#endif
383
384 switch (event->type) {
385 case EVT_MODAL_MAP:
387 n->val[idx] += (event->val == NUM_MODAL_INCREMENT_UP) ? n->val_inc[idx] : -n->val_inc[idx];
388 value_to_editstr(n, idx);
389 n->val_flag[idx] |= NUM_EDITED;
390 updated = true;
391 }
392 else {
393 /* might be a char too... */
394 utf8_buf = event->utf8_buf;
395 ascii[0] = event_ascii;
396 }
397 break;
398 case EVT_BACKSPACEKEY:
399 /* Part specific to backspace... */
400 if (!(n->val_flag[idx] & NUM_EDITED)) {
401 copy_v3_v3(n->val, n->val_org);
402 n->val_flag[0] &= ~NUM_EDITED;
403 n->val_flag[1] &= ~NUM_EDITED;
404 n->val_flag[2] &= ~NUM_EDITED;
405#ifdef USE_FAKE_EDIT
406 n->flag |= NUM_FAKE_EDITED;
407#else
408 n->flag |= NUM_EDIT_FULL;
409#endif
410 updated = true;
411 break;
412 }
413 else if ((event->modifier & KM_SHIFT) || !n->str[0]) {
414 n->val[idx] = n->val_org[idx];
415 n->val_flag[idx] &= ~NUM_EDITED;
416 n->str[0] = '\0';
417 n->str_cur = 0;
418 updated = true;
419 break;
420 }
421 /* Else, common behavior with DELKEY,
422 * only difference is remove char(s) before/after the cursor. */
423 dir = STRCUR_DIR_PREV;
425 case EVT_DELKEY:
426 if ((n->val_flag[idx] & NUM_EDITED) && n->str[0]) {
427 int t_cur = cur = n->str_cur;
428 if (event->modifier & KM_CTRL) {
429 mode = STRCUR_JUMP_DELIM;
430 }
432 strlen(n->str),
433 &t_cur,
435 eStrCursorJumpType(mode),
436 true);
437 if (t_cur != cur) {
438 if (t_cur < cur) {
439 std::swap(t_cur, cur);
440 n->str_cur = cur;
441 }
442 /* +1 for trailing '\0'. */
443 memmove(&n->str[cur], &n->str[t_cur], strlen(&n->str[t_cur]) + 1);
444 updated = true;
445 }
446 if (!n->str[0]) {
447 n->val[idx] = n->val_org[idx];
448 }
449 }
450 else {
451 return false;
452 }
453 break;
454 case EVT_LEFTARROWKEY:
455 dir = STRCUR_DIR_PREV;
458 cur = n->str_cur;
459 if (event->modifier & KM_CTRL) {
460 mode = STRCUR_JUMP_DELIM;
461 }
463 strlen(n->str),
464 &cur,
466 eStrCursorJumpType(mode),
467 true);
468 if (cur != n->str_cur) {
469 n->str_cur = cur;
470 return true;
471 }
472 return false;
473 case EVT_HOMEKEY:
474 if (n->str[0]) {
475 n->str_cur = 0;
476 return true;
477 }
478 return false;
479 case EVT_ENDKEY:
480 if (n->str[0]) {
481 n->str_cur = strlen(n->str);
482 return true;
483 }
484 return false;
485 case EVT_TABKEY:
486#ifdef USE_FAKE_EDIT
487 n->val_flag[idx] &= ~(NUM_NEGATE | NUM_INVERSE);
488#endif
489
490 idx = (idx + idx_max + ((event->modifier & KM_CTRL) ? 0 : 2)) % (idx_max + 1);
491 n->idx = idx;
492 if (n->val_flag[idx] & NUM_EDITED) {
493 value_to_editstr(n, idx);
494 }
495 else {
496 n->str[0] = '\0';
497 n->str_cur = 0;
498 }
499 return true;
500 case EVT_PADPERIOD:
501 case EVT_PERIODKEY:
502 /* Force number-pad "." since some OS's/countries generate a comma char, see: #37992 */
503 ascii[0] = '.';
504 utf8_buf = ascii;
505 break;
506#if 0
507 /* Those keys are not directly accessible in all layouts,
508 * preventing to generate matching events.
509 * So we use a hack (ASCII value) instead, see below. */
510 case EQUALKEY:
511 case PADASTERKEY:
512 if (!(n->flag & NUM_EDIT_FULL)) {
513 n->flag |= NUM_EDIT_FULL;
514 n->val_flag[idx] |= NUM_EDITED;
515 return true;
516 }
517 else if (event->modifier & KM_CTRL) {
518 n->flag &= ~NUM_EDIT_FULL;
519 return true;
520 }
521 break;
522#endif
523
524#ifdef USE_FAKE_EDIT
525 case EVT_PADMINUS:
526 case EVT_MINUSKEY:
527 if ((event->modifier & KM_CTRL) || !(n->flag & NUM_EDIT_FULL)) {
528 n->val_flag[idx] ^= NUM_NEGATE;
529 updated = true;
530 }
531 break;
532 case EVT_PADSLASHKEY:
533 case EVT_SLASHKEY:
534 if ((event->modifier & KM_CTRL) || !(n->flag & NUM_EDIT_FULL)) {
535 n->val_flag[idx] ^= NUM_INVERSE;
536 updated = true;
537 }
538 break;
539#endif
540 case EVT_CKEY:
541 if (event->modifier & KM_CTRL) {
542 /* Copy current `str` to the copy/paste buffer. */
543 WM_clipboard_text_set(n->str, false);
544 updated = true;
545 }
546 break;
547 case EVT_VKEY:
548 if (event->modifier & KM_CTRL) {
549 /* extract the first line from the clipboard */
550 int pbuf_len;
551 char *pbuf = WM_clipboard_text_get_firstline(false, true, &pbuf_len);
552
553 if (pbuf) {
554 const bool success = editstr_insert_at_cursor(n, pbuf, pbuf_len);
555
556 MEM_delete(pbuf);
557 if (!success) {
558 return false;
559 }
560
561 n->val_flag[idx] |= NUM_EDITED;
562 }
563 updated = true;
564 }
565 break;
566 default:
567 break;
568 }
569
570 if (!updated && !utf8_buf && event->utf8_buf[0]) {
571 utf8_buf = event->utf8_buf;
572 ascii[0] = event_ascii;
573 }
574
575 /* Up to this point, if we have a ctrl modifier, skip.
576 * This allows to still access most of modals' shortcuts even in numinput mode.
577 */
578 if (!updated && (event->modifier & KM_CTRL)) {
579 return false;
580 }
581
582 if ((!utf8_buf || !utf8_buf[0]) && ascii[0]) {
583 /* Fall back to ascii. */
584 utf8_buf = ascii;
585 }
586
587 if (utf8_buf && utf8_buf[0]) {
588 if (!(n->flag & NUM_EDIT_FULL)) {
589 /* In simple edit mode, we only keep a few chars as valid! */
590 /* no need to decode unicode, ASCII is first char only. */
591 if (!editstr_is_simple_numinput(utf8_buf[0])) {
592 return false;
593 }
594 }
595
596 const int utf8_buf_len = BLI_str_utf8_size_or_error(utf8_buf);
597 BLI_assert(utf8_buf_len != -1);
598 if (!editstr_insert_at_cursor(n, utf8_buf, utf8_buf_len)) {
599 return false;
600 }
601
602 n->val_flag[idx] |= NUM_EDITED;
603 }
604 else if (!updated) {
605 return false;
606 }
607
608 /* At this point, our value has changed, try to interpret it with python
609 * (if str is not empty!). */
610 if (n->str[0]) {
611 const float val_prev = n->val[idx];
612 Scene *sce = CTX_data_scene(C);
613 char *error = nullptr;
614
615 double val = 0.0;
616 double val_no_units = 0.0;
617 int success = user_string_to_number(
618 C, n->str, sce->unit, n->unit_type[idx], &val, &val_no_units, false, &error);
619
620 if (error) {
621 ReportList *reports = CTX_wm_reports(C);
622 printf("%s\n", error);
623 BKE_report(reports, RPT_ERROR, error);
624 BKE_report(reports, RPT_ERROR, "Numeric input evaluation");
625 MEM_delete(error);
626 }
627
628 if (success) {
629 n->val[idx] = float(val);
630 n->val_flag[idx] &= ~NUM_INVALID;
631
632 /* Store the pre-unit-scale value and check if it's an integer. */
633 n->val_no_units[idx] = val_no_units;
634 if (ED_numinput_double_is_int(val_no_units)) {
635 n->val_flag[idx] |= NUM_INT_INPUT_VALUE;
636 }
637 else {
639 }
640 }
641 else {
642 n->val_flag[idx] |= NUM_INVALID;
644 }
645
646#ifdef USE_FAKE_EDIT
647 if (n->val_flag[idx] & NUM_NEGATE) {
648 n->val[idx] = -n->val[idx];
649 n->val_no_units[idx] = -n->val_no_units[idx];
650 }
651 if (n->val_flag[idx] & NUM_INVERSE) {
652 val = n->val[idx];
653 /* If we invert on radians when user is in degrees,
654 * you get unexpected results... See #53463. */
655 if (!n->unit_use_radians && n->unit_type[idx] == B_UNIT_ROTATION) {
656 val = RAD2DEG(val);
657 }
658 val = 1.0 / val;
659 if (!n->unit_use_radians && n->unit_type[idx] == B_UNIT_ROTATION) {
660 val = DEG2RAD(val);
661 }
662 n->val[idx] = float(val);
663 n->val_no_units[idx] = 1.0 / n->val_no_units[idx];
664 /* Inverse transforms the value to 1/x, invalidating the integer property. */
666 }
667#endif
668
669 if (!isfinite(n->val[idx])) [[unlikely]] {
670 n->val[idx] = val_prev;
671 n->val_flag[idx] |= NUM_INVALID;
672 }
673 }
674
675 /* REDRAW SINCE NUMBERS HAVE CHANGED */
676 return true;
677}
678
679} // namespace blender
#define ATTR_FALLTHROUGH
#define DEG2RAD(_deg)
#define RAD2DEG(_rad)
#define STRNCPY_UTF8(dst, src)
#define RPT_(msgid)
#define NUM_STR_REP_LEN
#define NUM_MODAL_INCREMENT_DOWN
#define NUM_MAX_ELEMENTS
#define NUM_MODAL_INCREMENT_UP
Read Blender memory allocation and freeing.
#define C
Definition RandGen.cpp:29
#define UNUSED_VARS(...)
#define ELEM(...)
#define str(s)
ccl_device_inline dual1 len(const ccl_private dual< T > &a)
Definition math_dual.h:263
int calc_float_precision(int prec, double value)
BMesh Iterators.
UserDef U
Definition blender.cc:58
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
size_t size_t size_t BLI_snprintf_utf8(char *__restrict dst, size_t dst_maxncpy, const char *__restrict format,...) ATTR_NONNULL(1
unsigned __int64 uint64_t
Definition BKE_text.h:91
double BKE_unit_value_scale(const UnitSettings &settings, int unit_type, double value)
Definition unit.cc:1963
bool ED_numinput_double_is_int(double value)
Definition numinput.cc:73
@ NUM_EDIT_FULL
Definition numinput.cc:51
@ NUM_FAKE_EDITED
Definition numinput.cc:54
MINLINE void copy_v3_v3(float r[3], const float a[3])
@ NUM_INVALID
Definition numinput.cc:63
@ NUM_NEGATE
Definition numinput.cc:66
@ NUM_EDITED
Definition numinput.cc:62
@ NUM_INVERSE
Definition numinput.cc:67
bool handleNumInput(bContext *C, NumInput *n, const wmEvent *event)
Definition numinput.cc:344
bool BPY_run_string_as_number(bContext *C, const char *imports[], const char *expr, BPy_RunErrInfo *err_info, double *r_value) ATTR_NONNULL(1
char * BLI_strncpy_utf8(char *__restrict dst, const char *__restrict src, size_t dst_maxncpy) ATTR_NONNULL(1
bool hasNumInput(const NumInput *n)
Definition numinput.cc:188
char WM_event_utf8_to_ascii(const wmEvent *event)
@ NUM_AFFECT_ALL
bool BKE_unit_replace_string(char *str, int str_maxncpy, const char *str_prev, double scale_pref, int system, int type)
Definition unit.cc:2414
bool user_string_to_number(bContext *C, const char *str, const UnitSettings &unit, int type, double *r_value, double *r_value_no_units, bool use_single_line_error, char **r_error)
Definition numinput.cc:284
char * WM_clipboard_text_get_firstline(bool selection, bool ensure_utf8, int *r_len)
void BKE_report(ReportList *reports, eReportType type, const char *message)
Definition report.cc:162
void initNumInput(NumInput *n)
Definition numinput.cc:85
size_t BKE_unit_value_as_string_adaptive(char *str, int str_maxncpy, double value, int prec, int system, int type, bool split, bool pad, bool do_unit_suffix)
Definition unit.cc:1908
const char int BLI_str_utf8_size_or_error(const char *p) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
bool BKE_unit_string_contains_unit(const char *str, int type)
Definition unit.cc:2388
MINLINE void zero_v3(float r[3])
bool applyNumInput(NumInput *n, float *vec)
Definition numinput.cc:207
static bool editstr_is_simple_numinput(const char ascii)
Definition numinput.cc:333
void BLI_str_cursor_step_utf8(const char *str, int str_maxlen, int *pos, eStrCursorJumpDirection direction, eStrCursorJumpType jump, bool use_init_step)
@ USER_FLAG_NUMINPUT_ADVANCED
void outputNumInput(NumInput *n, char *str, const UnitSettings &unit_settings)
Definition numinput.cc:104
void WM_clipboard_text_set(const char *buf, bool selection)
Scene * CTX_data_scene(const bContext *C)
static void value_to_editstr(NumInput *n, int idx)
Definition numinput.cc:253
ReportList * CTX_wm_reports(const bContext *C)
@ B_UNIT_NONE
Definition BKE_unit.hh:165
@ B_UNIT_ROTATION
Definition BKE_unit.hh:170
int BLI_str_utf8_invalid_strip(char *str, size_t str_len) ATTR_NONNULL(1)
double BKE_unit_apply_preferred_unit(const UnitSettings &settings, int type, double value)
Definition unit.cc:2402
@ NUM_INT_INPUT_VALUE
@ NUM_NO_NEGATIVE
@ NUM_NO_FRACTION
static bool editstr_insert_at_cursor(NumInput *n, const char *buf, const int buf_len)
Definition numinput.cc:267
#define USE_FAKE_EDIT
Definition numinput.cc:43
#define floorf
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
float val[NUM_MAX_ELEMENTS]
int unit_type[NUM_MAX_ELEMENTS]
float val_org[NUM_MAX_ELEMENTS]
float val_inc[NUM_MAX_ELEMENTS]
char str[NUM_STR_REP_LEN]
double val_no_units[NUM_MAX_ELEMENTS]
short val_flag[NUM_MAX_ELEMENTS]
struct UnitSettings unit
wmEventType type
Definition WM_types.hh:817
wmEventModifierFlag modifier
Definition WM_types.hh:834