Blender V5.0
numinput.cc File Reference
#include "MEM_guardedalloc.h"
#include "BLI_math_rotation.h"
#include "BLI_math_vector.h"
#include "BLI_string.h"
#include "BLI_string_cursor_utf8.h"
#include "BLI_string_utf8.h"
#include "BLI_utildefines.h"
#include "BLT_translation.hh"
#include "BKE_context.hh"
#include "BKE_report.hh"
#include "BKE_unit.hh"
#include "DNA_scene_types.h"
#include "WM_api.hh"
#include "WM_types.hh"
#include "ED_numinput.hh"
#include "UI_interface.hh"

Go to the source code of this file.

Macros

#define USE_FAKE_EDIT

Enumerations

enum  { NUM_EDIT_FULL = (1 << 9) , NUM_FAKE_EDITED = (1 << 10) }
enum  { NUM_EDITED = (1 << 9) , NUM_INVALID = (1 << 10) , NUM_NEGATE = (1 << 11) , NUM_INVERSE = (1 << 12) }

Functions

void initNumInput (NumInput *n)
void outputNumInput (NumInput *n, char *str, const UnitSettings &unit_settings)
bool hasNumInput (const NumInput *n)
bool applyNumInput (NumInput *n, float *vec)
static void value_to_editstr (NumInput *n, int idx)
static bool editstr_insert_at_cursor (NumInput *n, const char *buf, const int buf_len)
bool user_string_to_number (bContext *C, const char *str, const UnitSettings &unit, int type, double *r_value, const bool use_single_line_error, char **r_error)
static bool editstr_is_simple_numinput (const char ascii)
bool handleNumInput (bContext *C, NumInput *n, const wmEvent *event)

Macro Definition Documentation

◆ USE_FAKE_EDIT

#define USE_FAKE_EDIT

Definition at line 38 of file numinput.cc.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum

NumInput.flag (1 << 8) and below are reserved for public flags!

Enumerator
NUM_EDIT_FULL 

Enable full editing, with units and math operators support.

NUM_FAKE_EDITED 

Fake edited state (temp, avoids issue with backspace).

Definition at line 44 of file numinput.cc.

◆ anonymous enum

anonymous enum
Enumerator
NUM_EDITED 

User has edited this value somehow.

NUM_INVALID 

Current expression for this value is invalid.

NUM_NEGATE 

Current expression's result has to be negated.

NUM_INVERSE 

Current expression's result has to be inverted.

Definition at line 54 of file numinput.cc.

Function Documentation

◆ applyNumInput()

bool applyNumInput ( NumInput * n,
float * vec )
Warning
vec must be set beforehand otherwise we risk uninitialized vars.

Definition at line 190 of file numinput.cc.

References NumInput::flag, floorf, hasNumInput(), i, NumInput::idx, NumInput::idx_max, NUM_AFFECT_ALL, NUM_EDITED, NUM_FAKE_EDITED, NUM_NO_FRACTION, NUM_NO_NEGATIVE, NUM_NO_ZERO, NUM_NULL_ONE, NumInput::val, NumInput::val_flag, and NumInput::val_org.

Referenced by blender::ed::transform::apply_shear(), blender::ed::transform::apply_value_impl(), blender::ed::transform::applyBakeTime(), blender::ed::transform::applyBoneEnvelope(), blender::ed::transform::applyBoneRoll(), blender::ed::transform::applyBoneSize(), blender::ed::transform::applyCurveShrinkFatten(), blender::ed::transform::applyEdgeSlide(), blender::ed::transform::applyGPOpacity(), blender::ed::transform::applyMaskShrinkFatten(), blender::ed::transform::applyNormalRotation(), blender::ed::transform::applyPushPull(), blender::ed::transform::applyResize(), blender::ed::transform::applyRotation(), blender::ed::transform::applySeqSlide(), blender::ed::transform::applyShrinkFatten(), blender::ed::transform::applySkinResize(), blender::ed::transform::applyTilt(), blender::ed::transform::applyTimeScale(), blender::ed::transform::applyTimeSlide(), blender::ed::transform::applyTimeTranslate(), blender::ed::transform::applyToSphere(), blender::ed::transform::applyTrackball(), blender::ed::transform::applyTranslation(), blender::ed::transform::applyVertSlide(), blender::ed::transform::Bend(), ed_marker_move_modal(), edbm_bevel_numinput_set_value(), edbm_inset_modal(), blender::ed::transform::ElementResize(), graph_slider_modal(), blender::ed::sculpt_paint::greasepencil::grease_pencil_interpolate_modal(), knifetool_modal(), loopcut_modal(), pose_slide_modal(), radial_control_modal(), and blender::ed::vse::slip_handle_num_input().

◆ editstr_insert_at_cursor()

bool editstr_insert_at_cursor ( NumInput * n,
const char * buf,
const int buf_len )
static

Definition at line 249 of file numinput.cc.

References len, NUM_STR_REP_LEN, NumInput::str, and NumInput::str_cur.

Referenced by handleNumInput().

◆ editstr_is_simple_numinput()

bool editstr_is_simple_numinput ( const char ascii)
static

Definition at line 301 of file numinput.cc.

Referenced by handleNumInput().

◆ handleNumInput()

bool handleNumInput ( bContext * C,
NumInput * n,
const wmEvent * event )

Definition at line 312 of file numinput.cc.

References ATTR_FALLTHROUGH, B_UNIT_ROTATION, BKE_report(), BLI_assert, BLI_str_cursor_step_utf8(), BLI_str_utf8_size_or_error(), C, copy_v3_v3(), CTX_data_scene(), CTX_wm_reports(), DEG2RAD, editstr_insert_at_cursor(), editstr_is_simple_numinput(), ELEM, error(), EVT_BACKSPACEKEY, EVT_CKEY, EVT_DELKEY, EVT_ENDKEY, EVT_HOMEKEY, EVT_LEFTARROWKEY, EVT_MINUSKEY, EVT_MODAL_MAP, EVT_PADMINUS, EVT_PADPERIOD, EVT_PADSLASHKEY, EVT_PERIODKEY, EVT_RIGHTARROWKEY, EVT_SLASHKEY, EVT_TABKEY, EVT_VKEY, NumInput::flag, float, NumInput::idx, NumInput::idx_max, KM_ALT, KM_CTRL, KM_SHIFT, MEM_freeN(), wmEvent::modifier, NUM_EDIT_FULL, NUM_EDITED, NUM_FAKE_EDITED, NUM_INVALID, NUM_INVERSE, NUM_MODAL_INCREMENT_DOWN, NUM_MODAL_INCREMENT_UP, NUM_NEGATE, printf, RAD2DEG, RPT_ERROR, NumInput::str, NumInput::str_cur, STRCUR_DIR_NEXT, STRCUR_DIR_PREV, STRCUR_JUMP_DELIM, STRCUR_JUMP_NONE, wmEvent::type, U, Scene::unit, NumInput::unit_type, NumInput::unit_use_radians, UNLIKELY, USER_FLAG_NUMINPUT_ADVANCED, user_string_to_number(), wmEvent::utf8_buf, NumInput::val, wmEvent::val, NumInput::val_flag, NumInput::val_inc, NumInput::val_org, value_to_editstr(), WM_clipboard_text_get_firstline(), WM_clipboard_text_set(), and WM_event_utf8_to_ascii().

Referenced by ed_marker_move_modal(), edbm_bevel_modal(), edbm_inset_modal(), graph_slider_modal(), blender::ed::sculpt_paint::greasepencil::grease_pencil_interpolate_modal(), knifetool_modal(), loopcut_modal(), pose_slide_modal(), radial_control_modal(), blender::ed::vse::sequencer_slip_modal(), and blender::ed::transform::transformEvent().

◆ hasNumInput()

bool hasNumInput ( const NumInput * n)

Definition at line 171 of file numinput.cc.

References NumInput::flag, i, NumInput::idx_max, NUM_EDITED, NUM_FAKE_EDITED, and NumInput::val_flag.

Referenced by blender::ed::transform::apply_shear(), blender::ed::transform::apply_value_impl(), blender::ed::transform::applyBakeTime(), blender::ed::transform::applyBoneEnvelope(), blender::ed::transform::applyBoneRoll(), blender::ed::transform::applyCurveShrinkFatten(), blender::ed::transform::applyEdgeSlide(), blender::ed::transform::applyGPOpacity(), blender::ed::transform::applyMaskShrinkFatten(), applyNumInput(), blender::ed::transform::applyPushPull(), blender::ed::transform::applyRotation(), blender::ed::transform::applyShrinkFatten(), blender::ed::transform::applyTilt(), blender::ed::transform::applyToSphere(), blender::ed::transform::applyTrackball(), blender::ed::transform::applyVertSlide(), blender::ed::transform::Bend(), common_draw_status_header(), decimate_draw_status(), ease_draw_status_header(), ed_marker_move_modal(), ed_marker_move_update_header(), edbm_bevel_modal(), edbm_inset_modal(), edbm_inset_update_header(), graph_slider_modal(), blender::ed::sculpt_paint::greasepencil::grease_pencil_interpolate_modal(), blender::ed::sculpt_paint::greasepencil::grease_pencil_interpolate_status_indicators(), blender::ed::transform::headerBoneSize(), blender::ed::transform::headerResize(), blender::ed::transform::headerRotation(), blender::ed::transform::headerSeqSlide(), blender::ed::transform::headerTimeScale(), blender::ed::transform::headerTimeSlide(), blender::ed::transform::headerTimeTranslate(), blender::ed::transform::headerTranslation(), knifetool_modal(), loopcut_init(), loopcut_modal(), pose_slide_draw_status(), pose_slide_modal(), radial_control_modal(), radial_control_update_header(), scale_from_neighbor_draw_status_header(), blender::ed::vse::sequencer_slip_modal(), shear_draw_status_header(), blender::ed::vse::slip_update_header(), and blender::ed::transform::transformEvent().

◆ initNumInput()

void initNumInput ( NumInput * n)

There are important things to note here for code using numeric-input:

  • Values passed to applyNumInput() should be valid and are stored as default ones (val_org), if it is not EDITED.
  • bool returned by applyNumInput should be used to decide whether to apply numeric-input-specific post-process to data.
  • Once applyNumInput has been called, hasNumInput returns a valid value to decide whether to use numinput as drawstr source or not (i.e. to call outputNumInput).

Those two steps have to be separated (so do not use a common call to hasNumInput() to do both in the same time!).

Definition at line 70 of file numinput.cc.

References B_UNIT_NONE, copy_vn_fl(), copy_vn_i(), copy_vn_short(), NumInput::flag, NumInput::idx, NumInput::idx_max, NUM_MAX_ELEMENTS, NumInput::str, NumInput::str_cur, NumInput::unit_sys, NumInput::unit_type, NumInput::unit_use_radians, USER_UNIT_NONE, NumInput::val, NumInput::val_flag, NumInput::val_inc, NumInput::val_org, and zero_v3().

Referenced by ed_marker_move_init(), edbm_bevel_init(), edbm_inset_init(), blender::ed::transform::initTransInfo(), knifetool_init(), pose_slide_init(), radial_control_invoke(), ringsel_init(), and blender::ed::vse::sequencer_slip_invoke().

◆ outputNumInput()

void outputNumInput ( NumInput * n,
char * str,
const UnitSettings & unit_settings )
Parameters
strMust be NUM_STR_REP_LEN * (idx_max + 1) length.

Definition at line 88 of file numinput.cc.

References B_UNIT_ROTATION, BKE_unit_value_as_string_adaptive(), BKE_unit_value_scale(), BLI_snprintf_utf8(), BLI_str_utf8_invalid_strip(), BLI_strncpy_utf8(), NumInput::flag, float, i, NumInput::idx, NumInput::idx_max, NUM_AFFECT_ALL, NUM_EDITED, NUM_INVALID, NUM_INVERSE, NUM_NEGATE, NUM_STR_REP_LEN, RPT_, NumInput::str, str, NumInput::str_cur, STRNCPY_UTF8, UI_calc_float_precision(), NumInput::unit_sys, NumInput::unit_type, NumInput::unit_use_radians, NumInput::val, and NumInput::val_flag.

Referenced by blender::ed::transform::apply_shear(), blender::ed::transform::apply_value_impl(), blender::ed::transform::applyBakeTime(), blender::ed::transform::applyBoneEnvelope(), blender::ed::transform::applyBoneRoll(), blender::ed::transform::applyCurveShrinkFatten(), blender::ed::transform::applyEdgeSlide(), blender::ed::transform::applyGPOpacity(), blender::ed::transform::applyMaskShrinkFatten(), blender::ed::transform::applyPushPull(), blender::ed::transform::applyShrinkFatten(), blender::ed::transform::applyTilt(), blender::ed::transform::applyToSphere(), blender::ed::transform::applyTrackball(), blender::ed::transform::applyVertSlide(), blender::ed::transform::Bend(), common_draw_status_header(), decimate_draw_status(), ease_draw_status_header(), ed_marker_move_update_header(), edbm_inset_update_header(), blender::ed::sculpt_paint::greasepencil::grease_pencil_interpolate_status_indicators(), blender::ed::transform::headerBoneSize(), blender::ed::transform::headerResize(), blender::ed::transform::headerRotation(), blender::ed::transform::headerSeqSlide(), blender::ed::transform::headerTimeScale(), blender::ed::transform::headerTimeSlide(), blender::ed::transform::headerTimeTranslate(), blender::ed::transform::headerTranslation(), loopcut_init(), loopcut_modal(), pose_slide_draw_status(), radial_control_update_header(), scale_from_neighbor_draw_status_header(), shear_draw_status_header(), and blender::ed::vse::slip_update_header().

◆ user_string_to_number()

bool user_string_to_number ( bContext * C,
const char * str,
const UnitSettings & unit,
int type,
double * r_value,
const bool use_single_line_error,
char ** r_error )

◆ value_to_editstr()

void value_to_editstr ( NumInput * n,
int idx )
static