Cleanup: pass UnitSettings as a const reference
This commit is contained in:
@@ -34,7 +34,7 @@ size_t BKE_unit_value_as_string(char *str,
|
||||
double value,
|
||||
int prec,
|
||||
int type,
|
||||
const UnitSettings *settings,
|
||||
const UnitSettings &settings,
|
||||
bool pad);
|
||||
|
||||
/**
|
||||
@@ -45,7 +45,7 @@ size_t BKE_unit_value_as_string_scaled(char *str,
|
||||
double value,
|
||||
int prec,
|
||||
int type,
|
||||
const UnitSettings *settings,
|
||||
const UnitSettings &settings,
|
||||
bool pad);
|
||||
|
||||
/**
|
||||
@@ -76,7 +76,7 @@ bool BKE_unit_string_contains_unit(const char *str, int type);
|
||||
/**
|
||||
* If user does not specify a unit, this converts it to the unit from the settings.
|
||||
*/
|
||||
double BKE_unit_apply_preferred_unit(const UnitSettings *settings, int type, double value);
|
||||
double BKE_unit_apply_preferred_unit(const UnitSettings &settings, int type, double value);
|
||||
|
||||
/**
|
||||
* Make string keyboard-friendly, e.g: `10µm -> 10um`.
|
||||
@@ -102,7 +102,7 @@ bool BKE_unit_is_valid(int system, int type);
|
||||
* Apply the needed correction factor to value, based on unit_type
|
||||
* (only length-related are affected currently) and `unit->scale_length`.
|
||||
*/
|
||||
double BKE_unit_value_scale(const UnitSettings *unit, int unit_type, double value);
|
||||
double BKE_unit_value_scale(const UnitSettings &settings, int unit_type, double value);
|
||||
|
||||
/**
|
||||
* Loop over scales, could add names later.
|
||||
|
||||
@@ -1734,15 +1734,15 @@ struct PreferredUnits {
|
||||
int temperature;
|
||||
};
|
||||
|
||||
static PreferredUnits preferred_units_from_UnitSettings(const UnitSettings *settings)
|
||||
static PreferredUnits preferred_units_from_UnitSettings(const UnitSettings &settings)
|
||||
{
|
||||
PreferredUnits units = {0};
|
||||
units.system = settings->system;
|
||||
units.rotation = settings->system_rotation;
|
||||
units.length = settings->length_unit;
|
||||
units.mass = settings->mass_unit;
|
||||
units.time = settings->time_unit;
|
||||
units.temperature = settings->temperature_unit;
|
||||
units.system = settings.system;
|
||||
units.rotation = settings.system_rotation;
|
||||
units.length = settings.length_unit;
|
||||
units.mass = settings.mass_unit;
|
||||
units.time = settings.time_unit;
|
||||
units.temperature = settings.temperature_unit;
|
||||
return units;
|
||||
}
|
||||
|
||||
@@ -1878,10 +1878,10 @@ size_t BKE_unit_value_as_string(char *str,
|
||||
double value,
|
||||
int prec,
|
||||
int type,
|
||||
const UnitSettings *settings,
|
||||
const UnitSettings &settings,
|
||||
bool pad)
|
||||
{
|
||||
bool do_split = (settings->flag & USER_UNIT_OPT_SPLIT) != 0;
|
||||
bool do_split = (settings.flag & USER_UNIT_OPT_SPLIT) != 0;
|
||||
PreferredUnits units = preferred_units_from_UnitSettings(settings);
|
||||
return unit_as_string_main(str, str_maxncpy, value, prec, type, do_split, pad, units);
|
||||
}
|
||||
@@ -1891,16 +1891,16 @@ size_t BKE_unit_value_as_string_scaled(char *str,
|
||||
double value,
|
||||
int prec,
|
||||
int type,
|
||||
const UnitSettings *settings,
|
||||
const UnitSettings &settings,
|
||||
bool pad)
|
||||
{
|
||||
return BKE_unit_value_as_string(
|
||||
str, str_maxncpy, BKE_unit_value_scale(settings, type, value), prec, type, settings, pad);
|
||||
}
|
||||
|
||||
double BKE_unit_value_scale(const UnitSettings *unit, const int unit_type, double value)
|
||||
double BKE_unit_value_scale(const UnitSettings &settings, const int unit_type, double value)
|
||||
{
|
||||
if (unit->system == USER_UNIT_NONE) {
|
||||
if (settings.system == USER_UNIT_NONE) {
|
||||
/* Never apply scale_length when not using a unit setting! */
|
||||
return value;
|
||||
}
|
||||
@@ -1909,14 +1909,14 @@ double BKE_unit_value_scale(const UnitSettings *unit, const int unit_type, doubl
|
||||
case B_UNIT_LENGTH:
|
||||
case B_UNIT_VELOCITY:
|
||||
case B_UNIT_ACCELERATION:
|
||||
return value * double(unit->scale_length);
|
||||
return value * double(settings.scale_length);
|
||||
case B_UNIT_AREA:
|
||||
case B_UNIT_POWER:
|
||||
return value * pow(unit->scale_length, 2);
|
||||
return value * pow(settings.scale_length, 2);
|
||||
case B_UNIT_VOLUME:
|
||||
return value * pow(unit->scale_length, 3);
|
||||
return value * pow(settings.scale_length, 3);
|
||||
case B_UNIT_MASS:
|
||||
return value * pow(unit->scale_length, 3);
|
||||
return value * pow(settings.scale_length, 3);
|
||||
case B_UNIT_CAMERA: /* *Do not* use scene's unit scale for camera focal lens! See #42026. */
|
||||
case B_UNIT_WAVELENGTH: /* Wavelength values are independent of the scene scale. */
|
||||
default:
|
||||
@@ -2338,7 +2338,7 @@ bool BKE_unit_string_contains_unit(const char *str, int type)
|
||||
return false;
|
||||
}
|
||||
|
||||
double BKE_unit_apply_preferred_unit(const UnitSettings *settings, int type, double value)
|
||||
double BKE_unit_apply_preferred_unit(const UnitSettings &settings, int type, double value)
|
||||
{
|
||||
PreferredUnits units = preferred_units_from_UnitSettings(settings);
|
||||
const bUnitDef *unit = get_preferred_display_unit_if_used(type, units);
|
||||
|
||||
@@ -349,7 +349,7 @@ class Meshes : Overlay {
|
||||
edit_mesh_skin_roots_ps_.draw_expand(geom, GPU_PRIM_LINES, 32, 1, res_handle);
|
||||
}
|
||||
if (state.show_text && (state.overlay.edit_flag & overlay_edit_text)) {
|
||||
DRW_text_edit_mesh_measure_stats(state.region, state.v3d, ob, &state.scene->unit, state.dt);
|
||||
DRW_text_edit_mesh_measure_stats(state.region, state.v3d, ob, state.scene->unit, state.dt);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -259,7 +259,7 @@ void DRW_text_cache_draw(DRWTextStore *dt, ARegion *region, View3D *v3d)
|
||||
void DRW_text_edit_mesh_measure_stats(const ARegion *region,
|
||||
const View3D *v3d,
|
||||
const Object *ob,
|
||||
const UnitSettings *unit,
|
||||
const UnitSettings &unit,
|
||||
DRWTextStore *dt)
|
||||
{
|
||||
/* Do not use ascii when using non-default unit system, some unit chars are utf8 (micro, square,
|
||||
@@ -277,7 +277,7 @@ void DRW_text_edit_mesh_measure_stats(const ARegion *region,
|
||||
char numstr[32]; /* Stores the measurement display text here */
|
||||
const char *conv_float; /* Use a float conversion matching the grid size */
|
||||
blender::uchar4 col = {0, 0, 0, 255}; /* color of the text to draw */
|
||||
const float grid = unit->system ? unit->scale_length : v3d->grid;
|
||||
const float grid = unit.system ? unit.scale_length : v3d->grid;
|
||||
const bool do_global = (v3d->flag & V3D_GLOBAL_STATS) != 0;
|
||||
const bool do_moving = (G.moving & G_TRANSFORM_EDIT) != 0;
|
||||
blender::float4x4 clip_planes;
|
||||
@@ -363,7 +363,7 @@ void DRW_text_edit_mesh_measure_stats(const ARegion *region,
|
||||
}
|
||||
|
||||
const size_t numstr_len =
|
||||
unit->system ?
|
||||
unit.system ?
|
||||
BKE_unit_value_as_string_scaled(
|
||||
numstr, sizeof(numstr), len_v3v3(v1, v2), 3, B_UNIT_LENGTH, unit, false) :
|
||||
SNPRINTF_RLEN(numstr, conv_float, len_v3v3(v1, v2));
|
||||
@@ -375,7 +375,7 @@ void DRW_text_edit_mesh_measure_stats(const ARegion *region,
|
||||
}
|
||||
|
||||
if (v3d->overlay.edit_flag & V3D_OVERLAY_EDIT_EDGE_ANG) {
|
||||
const bool is_rad = (unit->system_rotation == USER_UNIT_ROT_RADIANS);
|
||||
const bool is_rad = (unit.system_rotation == USER_UNIT_ROT_RADIANS);
|
||||
BMEdge *eed;
|
||||
|
||||
UI_GetThemeColor3ubv(TH_DRAWEXTRA_EDGEANG, col);
|
||||
@@ -498,9 +498,9 @@ void DRW_text_edit_mesh_measure_stats(const ARegion *region,
|
||||
vmid = blender::math::transform_point(ob->object_to_world(), vmid);
|
||||
|
||||
const size_t numstr_len =
|
||||
unit->system ? BKE_unit_value_as_string_scaled(
|
||||
numstr, sizeof(numstr), area, 3, B_UNIT_AREA, unit, false) :
|
||||
SNPRINTF_RLEN(numstr, conv_float, area);
|
||||
unit.system ? BKE_unit_value_as_string_scaled(
|
||||
numstr, sizeof(numstr), area, 3, B_UNIT_AREA, unit, false) :
|
||||
SNPRINTF_RLEN(numstr, conv_float, area);
|
||||
|
||||
DRW_text_cache_add(dt, vmid, numstr, numstr_len, 0, 0, txt_flag, col);
|
||||
}
|
||||
@@ -510,7 +510,7 @@ void DRW_text_edit_mesh_measure_stats(const ARegion *region,
|
||||
|
||||
if (v3d->overlay.edit_flag & V3D_OVERLAY_EDIT_FACE_ANG) {
|
||||
BMFace *efa;
|
||||
const bool is_rad = (unit->system_rotation == USER_UNIT_ROT_RADIANS);
|
||||
const bool is_rad = (unit.system_rotation == USER_UNIT_ROT_RADIANS);
|
||||
|
||||
UI_GetThemeColor3ubv(TH_DRAWEXTRA_FACEANG, col);
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ void DRW_text_cache_draw(DRWTextStore *dt, ARegion *region, View3D *v3d);
|
||||
void DRW_text_edit_mesh_measure_stats(const ARegion *region,
|
||||
const View3D *v3d,
|
||||
const Object *ob,
|
||||
const UnitSettings *unit,
|
||||
const UnitSettings &unit,
|
||||
DRWTextStore *dt = DRW_text_cache_ensure());
|
||||
|
||||
enum {
|
||||
|
||||
@@ -857,7 +857,7 @@ static void ed_marker_move_update_header(bContext *C, wmOperator *op)
|
||||
}
|
||||
|
||||
if (hasNumInput(&mm->num)) {
|
||||
outputNumInput(&mm->num, str_ofs, &scene->unit);
|
||||
outputNumInput(&mm->num, str_ofs, scene->unit);
|
||||
}
|
||||
else if (use_time) {
|
||||
SNPRINTF(str_ofs, "%.2f", FRA2TIME(ofs));
|
||||
|
||||
@@ -967,7 +967,7 @@ static void pose_slide_draw_status(bContext *C, tPoseSlideOp *pso)
|
||||
Scene *scene = pso->scene;
|
||||
char str_offs[NUM_STR_REP_LEN];
|
||||
|
||||
outputNumInput(&pso->num, str_offs, &scene->unit);
|
||||
outputNumInput(&pso->num, str_offs, scene->unit);
|
||||
|
||||
SNPRINTF(status_str, "%s: %s | %s", mode_str, str_offs, limits_str);
|
||||
}
|
||||
|
||||
@@ -81,7 +81,7 @@ void initNumInput(NumInput *n);
|
||||
/**
|
||||
* \param str: Must be NUM_STR_REP_LEN * (idx_max + 1) length.
|
||||
*/
|
||||
void outputNumInput(NumInput *n, char *str, const UnitSettings *unit_settings);
|
||||
void outputNumInput(NumInput *n, char *str, const UnitSettings &unit_settings);
|
||||
bool hasNumInput(const NumInput *n);
|
||||
/**
|
||||
* \warning \a vec must be set beforehand otherwise we risk uninitialized vars.
|
||||
@@ -95,7 +95,7 @@ bool handleNumInput(bContext *C, NumInput *n, const wmEvent *event);
|
||||
|
||||
bool user_string_to_number(bContext *C,
|
||||
const char *str,
|
||||
const UnitSettings *unit,
|
||||
const UnitSettings &unit,
|
||||
int type,
|
||||
double *r_value,
|
||||
bool use_single_line_error,
|
||||
|
||||
@@ -285,7 +285,7 @@ static void depthdropper_depth_sample_pt(bContext *C,
|
||||
double(*r_depth),
|
||||
4,
|
||||
B_UNIT_LENGTH,
|
||||
&scene->unit,
|
||||
scene->unit,
|
||||
false);
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -2837,7 +2837,7 @@ static double ui_get_but_scale_unit(uiBut *but, double value)
|
||||
Scene *scene = CTX_data_scene(static_cast<const bContext *>(but->block->evil_C));
|
||||
return FRA2TIME(value);
|
||||
}
|
||||
return BKE_unit_value_scale(unit, RNA_SUBTYPE_UNIT_VALUE(unit_type), value);
|
||||
return BKE_unit_value_scale(*unit, RNA_SUBTYPE_UNIT_VALUE(unit_type), value);
|
||||
}
|
||||
|
||||
void ui_but_convert_to_unit_alt_name(uiBut *but, char *str, size_t str_maxncpy)
|
||||
@@ -2890,7 +2890,7 @@ static void ui_get_but_string_unit(
|
||||
ui_get_but_scale_unit(but, value),
|
||||
precision,
|
||||
RNA_SUBTYPE_UNIT_VALUE(unit_type),
|
||||
unit,
|
||||
*unit,
|
||||
pad);
|
||||
}
|
||||
|
||||
@@ -3128,7 +3128,7 @@ static bool ui_number_from_string_units(
|
||||
bContext *C, const char *str, const int unit_type, const UnitSettings *unit, double *r_value)
|
||||
{
|
||||
char *error = nullptr;
|
||||
const bool ok = user_string_to_number(C, str, unit, unit_type, r_value, true, &error);
|
||||
const bool ok = user_string_to_number(C, str, *unit, unit_type, r_value, true, &error);
|
||||
if (error) {
|
||||
ReportList *reports = CTX_wm_reports(C);
|
||||
BKE_reportf(reports, RPT_ERROR, "%s: %s", UI_NUMBER_EVAL_ERROR_PREFIX, error);
|
||||
|
||||
@@ -134,7 +134,7 @@ static void edbm_bevel_update_status_text(bContext *C, wmOperator *op)
|
||||
else {
|
||||
double offset_val = double(RNA_float_get(op->ptr, "offset"));
|
||||
BKE_unit_value_as_string_scaled(
|
||||
offset_str, NUM_STR_REP_LEN, offset_val, 3, B_UNIT_LENGTH, &sce->unit, true);
|
||||
offset_str, NUM_STR_REP_LEN, offset_val, 3, B_UNIT_LENGTH, sce->unit, true);
|
||||
}
|
||||
|
||||
PropertyRNA *prop;
|
||||
|
||||
@@ -80,7 +80,7 @@ static void edbm_inset_update_header(wmOperator *op, bContext *C)
|
||||
char msg[UI_MAX_DRAW_STR];
|
||||
char flts_str[NUM_STR_REP_LEN * 2];
|
||||
if (hasNumInput(&opdata->num_input)) {
|
||||
outputNumInput(&opdata->num_input, flts_str, &sce->unit);
|
||||
outputNumInput(&opdata->num_input, flts_str, sce->unit);
|
||||
}
|
||||
else {
|
||||
BKE_unit_value_as_string(flts_str,
|
||||
@@ -88,14 +88,14 @@ static void edbm_inset_update_header(wmOperator *op, bContext *C)
|
||||
RNA_float_get(op->ptr, "thickness"),
|
||||
4,
|
||||
B_UNIT_LENGTH,
|
||||
&sce->unit,
|
||||
sce->unit,
|
||||
true);
|
||||
BKE_unit_value_as_string(flts_str + NUM_STR_REP_LEN,
|
||||
NUM_STR_REP_LEN,
|
||||
RNA_float_get(op->ptr, "depth"),
|
||||
4,
|
||||
B_UNIT_LENGTH,
|
||||
&sce->unit,
|
||||
sce->unit,
|
||||
true);
|
||||
}
|
||||
SNPRINTF(msg, IFACE_("Thickness: %s, Depth: %s"), flts_str, flts_str + NUM_STR_REP_LEN);
|
||||
|
||||
@@ -509,8 +509,8 @@ static void knifetool_draw_visible_distances(const KnifeTool_OpData *kcd)
|
||||
/* Calculate distance and convert to string. */
|
||||
const float cut_len = len_v3v3(kcd->prev.cage, kcd->curr.cage);
|
||||
|
||||
const UnitSettings *unit = &kcd->scene->unit;
|
||||
if (unit->system == USER_UNIT_NONE) {
|
||||
const UnitSettings &unit = kcd->scene->unit;
|
||||
if (unit.system == USER_UNIT_NONE) {
|
||||
SNPRINTF(numstr, "%.*f", distance_precision, cut_len);
|
||||
}
|
||||
else {
|
||||
@@ -640,8 +640,8 @@ static void knifetool_draw_angle(const KnifeTool_OpData *kcd,
|
||||
float numstr_size[2];
|
||||
float posit[2];
|
||||
|
||||
const UnitSettings *unit = &kcd->scene->unit;
|
||||
if (unit->system == USER_UNIT_NONE) {
|
||||
const UnitSettings &unit = kcd->scene->unit;
|
||||
if (unit.system == USER_UNIT_NONE) {
|
||||
SNPRINTF(numstr, "%.*f" BLI_STR_UTF8_DEGREE_SIGN, angle_precision, RAD2DEGF(angle));
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -460,7 +460,7 @@ static int loopcut_init(bContext *C, wmOperator *op, const wmEvent *event)
|
||||
char buf[UI_MAX_DRAW_STR];
|
||||
char str_rep[NUM_STR_REP_LEN * 2];
|
||||
if (hasNumInput(&lcd->num)) {
|
||||
outputNumInput(&lcd->num, str_rep, &scene->unit);
|
||||
outputNumInput(&lcd->num, str_rep, scene->unit);
|
||||
}
|
||||
else {
|
||||
BLI_snprintf(str_rep, NUM_STR_REP_LEN, "%d", int(lcd->cuts));
|
||||
@@ -692,7 +692,7 @@ static int loopcut_modal(bContext *C, wmOperator *op, const wmEvent *event)
|
||||
char buf[UI_MAX_DRAW_STR];
|
||||
char str_rep[NUM_STR_REP_LEN * 2];
|
||||
if (hasNumInput(&lcd->num)) {
|
||||
outputNumInput(&lcd->num, str_rep, &sce->unit);
|
||||
outputNumInput(&lcd->num, str_rep, sce->unit);
|
||||
}
|
||||
else {
|
||||
BLI_snprintf(str_rep, NUM_STR_REP_LEN, "%d", int(lcd->cuts));
|
||||
|
||||
@@ -319,7 +319,7 @@ static void voxel_size_edit_draw(const bContext *C, ARegion * /*region*/, void *
|
||||
char str[VOXEL_SIZE_EDIT_MAX_STR_LEN];
|
||||
short strdrawlen = 0;
|
||||
Scene *scene = CTX_data_scene(C);
|
||||
const UnitSettings *unit = &scene->unit;
|
||||
const UnitSettings &unit = scene->unit;
|
||||
|
||||
BKE_unit_value_as_string_scaled(str, sizeof(str), cd->voxel_size, -3, B_UNIT_LENGTH, unit, true);
|
||||
strdrawlen = BLI_strlen_utf8(str);
|
||||
|
||||
@@ -584,7 +584,7 @@ static void grease_pencil_interpolate_status_indicators(bContext &C,
|
||||
std::string status;
|
||||
if (hasNumInput(&opdata.numeric_input)) {
|
||||
char str_ofs[NUM_STR_REP_LEN];
|
||||
outputNumInput(&const_cast<NumInput &>(opdata.numeric_input), str_ofs, &scene.unit);
|
||||
outputNumInput(&const_cast<NumInput &>(opdata.numeric_input), str_ofs, scene.unit);
|
||||
status = msg + std::string(str_ofs);
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -134,7 +134,7 @@ static void common_draw_status_header(bContext *C, tGraphSliderOp *gso, const ch
|
||||
if (hasNumInput(&gso->num)) {
|
||||
char str_ofs[NUM_STR_REP_LEN];
|
||||
|
||||
outputNumInput(&gso->num, str_ofs, &gso->scene->unit);
|
||||
outputNumInput(&gso->num, str_ofs, gso->scene->unit);
|
||||
|
||||
SNPRINTF(status_str, "%s: %s", mode_str, str_ofs);
|
||||
}
|
||||
@@ -464,7 +464,7 @@ static void decimate_draw_status(bContext *C, tGraphSliderOp *gso)
|
||||
if (hasNumInput(&gso->num)) {
|
||||
char str_ofs[NUM_STR_REP_LEN];
|
||||
|
||||
outputNumInput(&gso->num, str_ofs, &gso->scene->unit);
|
||||
outputNumInput(&gso->num, str_ofs, gso->scene->unit);
|
||||
|
||||
SNPRINTF(status_str, "%s: %s", mode_str, str_ofs);
|
||||
}
|
||||
@@ -973,7 +973,7 @@ static void ease_draw_status_header(bContext *C, wmOperator *op)
|
||||
if (hasNumInput(&gso->num)) {
|
||||
char str_ofs[NUM_STR_REP_LEN];
|
||||
|
||||
outputNumInput(&gso->num, str_ofs, &gso->scene->unit);
|
||||
outputNumInput(&gso->num, str_ofs, gso->scene->unit);
|
||||
|
||||
SNPRINTF(status_str, "%s: %s", mode_str, str_ofs);
|
||||
}
|
||||
@@ -1577,7 +1577,7 @@ static void shear_draw_status_header(bContext *C, tGraphSliderOp *gso)
|
||||
if (hasNumInput(&gso->num)) {
|
||||
char str_ofs[NUM_STR_REP_LEN];
|
||||
|
||||
outputNumInput(&gso->num, str_ofs, &gso->scene->unit);
|
||||
outputNumInput(&gso->num, str_ofs, gso->scene->unit);
|
||||
|
||||
SNPRINTF(status_str, "%s: %s", mode_str, str_ofs);
|
||||
}
|
||||
@@ -2467,7 +2467,7 @@ static void scale_from_neighbor_draw_status_header(bContext *C, wmOperator *op)
|
||||
if (hasNumInput(&gso->num)) {
|
||||
char str_ofs[NUM_STR_REP_LEN];
|
||||
|
||||
outputNumInput(&gso->num, str_ofs, &gso->scene->unit);
|
||||
outputNumInput(&gso->num, str_ofs, gso->scene->unit);
|
||||
|
||||
SNPRINTF(status_str, "%s: %s", mode_str, str_ofs);
|
||||
}
|
||||
|
||||
@@ -637,7 +637,7 @@ static void sequencer_slip_update_header(Scene *scene, ScrArea *area, SlipData *
|
||||
char msg[UI_MAX_DRAW_STR];
|
||||
if (hasNumInput(&data->num_input)) {
|
||||
char num_str[NUM_STR_REP_LEN];
|
||||
outputNumInput(&data->num_input, num_str, &scene->unit);
|
||||
outputNumInput(&data->num_input, num_str, scene->unit);
|
||||
SNPRINTF(msg, IFACE_("Slip offset: %s"), num_str);
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -193,13 +193,13 @@ static void ruler_item_remove(bContext *C, wmGizmoGroup *gzgroup, RulerItem *rul
|
||||
}
|
||||
|
||||
static void ruler_item_as_string(
|
||||
RulerItem *ruler_item, UnitSettings *unit, char *numstr, size_t numstr_size, int prec)
|
||||
RulerItem *ruler_item, const UnitSettings &unit, char *numstr, size_t numstr_size, int prec)
|
||||
{
|
||||
if (ruler_item->flag & RULERITEM_USE_ANGLE) {
|
||||
const float ruler_angle = angle_v3v3v3(
|
||||
ruler_item->co[0], ruler_item->co[1], ruler_item->co[2]);
|
||||
|
||||
if (unit->system == USER_UNIT_NONE) {
|
||||
if (unit.system == USER_UNIT_NONE) {
|
||||
BLI_snprintf(
|
||||
numstr, numstr_size, "%.*f" BLI_STR_UTF8_DEGREE_SIGN, prec, RAD2DEGF(ruler_angle));
|
||||
}
|
||||
@@ -211,7 +211,7 @@ static void ruler_item_as_string(
|
||||
else {
|
||||
const float ruler_len = len_v3v3(ruler_item->co[0], ruler_item->co[2]);
|
||||
|
||||
if (unit->system == USER_UNIT_NONE) {
|
||||
if (unit.system == USER_UNIT_NONE) {
|
||||
BLI_snprintf(numstr, numstr_size, "%.*f", prec, ruler_len);
|
||||
}
|
||||
else {
|
||||
@@ -639,7 +639,7 @@ static bool view3d_ruler_from_gpencil(const bContext *C, wmGizmoGroup *gzgroup)
|
||||
static void gizmo_ruler_draw(const bContext *C, wmGizmo *gz)
|
||||
{
|
||||
Scene *scene = CTX_data_scene(C);
|
||||
UnitSettings *unit = &scene->unit;
|
||||
const UnitSettings &unit = scene->unit;
|
||||
RulerInfo *ruler_info = static_cast<RulerInfo *>(gz->parent_gzgroup->customdata);
|
||||
RulerItem *ruler_item = (RulerItem *)gz;
|
||||
ARegion *region = ruler_info->region;
|
||||
|
||||
@@ -540,7 +540,7 @@ void headerRotation(TransInfo *t, char *str, const int str_size, float final)
|
||||
if (hasNumInput(&t->num)) {
|
||||
char c[NUM_STR_REP_LEN];
|
||||
|
||||
outputNumInput(&(t->num), c, &t->scene->unit);
|
||||
outputNumInput(&(t->num), c, t->scene->unit);
|
||||
|
||||
ofs += BLI_snprintf_rlen(
|
||||
str + ofs, str_size - ofs, IFACE_("Rotation: %s %s %s"), &c[0], t->con.text, t->proptext);
|
||||
@@ -841,7 +841,7 @@ void headerResize(TransInfo *t, const float vec[3], char *str, const int str_siz
|
||||
char tvec[NUM_STR_REP_LEN * 3];
|
||||
size_t ofs = 0;
|
||||
if (hasNumInput(&t->num)) {
|
||||
outputNumInput(&(t->num), tvec, &t->scene->unit);
|
||||
outputNumInput(&(t->num), tvec, t->scene->unit);
|
||||
}
|
||||
else {
|
||||
BLI_snprintf(&tvec[0], NUM_STR_REP_LEN, "%.4f", vec[0]);
|
||||
|
||||
@@ -59,7 +59,7 @@ static void applyBakeTime(TransInfo *t)
|
||||
if (hasNumInput(&t->num)) {
|
||||
char c[NUM_STR_REP_LEN];
|
||||
|
||||
outputNumInput(&(t->num), c, &t->scene->unit);
|
||||
outputNumInput(&(t->num), c, t->scene->unit);
|
||||
|
||||
if (time >= 0.0f) {
|
||||
SNPRINTF(str, IFACE_("Time: +%s %s"), c, t->proptext);
|
||||
|
||||
@@ -35,7 +35,7 @@ static void headerBoneSize(TransInfo *t, const float vec[3], char str[UI_MAX_DRA
|
||||
{
|
||||
char tvec[NUM_STR_REP_LEN * 3];
|
||||
if (hasNumInput(&t->num)) {
|
||||
outputNumInput(&(t->num), tvec, &t->scene->unit);
|
||||
outputNumInput(&(t->num), tvec, t->scene->unit);
|
||||
}
|
||||
else {
|
||||
BLI_snprintf(&tvec[0], NUM_STR_REP_LEN, "%.4f", vec[0]);
|
||||
|
||||
@@ -225,7 +225,7 @@ static void Bend(TransInfo *t)
|
||||
if (hasNumInput(&t->num)) {
|
||||
char c[NUM_STR_REP_LEN * 2];
|
||||
|
||||
outputNumInput(&(t->num), c, &t->scene->unit);
|
||||
outputNumInput(&(t->num), c, t->scene->unit);
|
||||
|
||||
SNPRINTF(str,
|
||||
IFACE_("Bend Angle: %s, Radius: %s, Alt: Clamp %s"),
|
||||
|
||||
@@ -47,7 +47,7 @@ static void applyBoneEnvelope(TransInfo *t)
|
||||
if (hasNumInput(&t->num)) {
|
||||
char c[NUM_STR_REP_LEN];
|
||||
|
||||
outputNumInput(&(t->num), c, &t->scene->unit);
|
||||
outputNumInput(&(t->num), c, t->scene->unit);
|
||||
SNPRINTF(str, IFACE_("Envelope: %s"), c);
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -48,7 +48,7 @@ static void applyBoneRoll(TransInfo *t)
|
||||
if (hasNumInput(&t->num)) {
|
||||
char c[NUM_STR_REP_LEN];
|
||||
|
||||
outputNumInput(&(t->num), c, &t->scene->unit);
|
||||
outputNumInput(&(t->num), c, t->scene->unit);
|
||||
|
||||
SNPRINTF(str, IFACE_("Roll: %s"), &c[0]);
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ static void applyCurveShrinkFatten(TransInfo *t)
|
||||
if (hasNumInput(&t->num)) {
|
||||
char c[NUM_STR_REP_LEN];
|
||||
|
||||
outputNumInput(&(t->num), c, &t->scene->unit);
|
||||
outputNumInput(&(t->num), c, t->scene->unit);
|
||||
SNPRINTF(str, IFACE_("Shrink/Fatten: %s"), c);
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -90,7 +90,7 @@ static void apply_value_impl(TransInfo *t, const char *value_name)
|
||||
if (hasNumInput(&t->num)) {
|
||||
char c[NUM_STR_REP_LEN];
|
||||
|
||||
outputNumInput(&(t->num), c, &t->scene->unit);
|
||||
outputNumInput(&(t->num), c, t->scene->unit);
|
||||
|
||||
if (value >= 0.0f) {
|
||||
SNPRINTF(str, "%s: +%s %s", value_name, c, t->proptext);
|
||||
|
||||
@@ -43,7 +43,7 @@ static void headerSeqSlide(TransInfo *t, const float val[2], char str[UI_MAX_DRA
|
||||
size_t ofs = 0;
|
||||
|
||||
if (hasNumInput(&t->num)) {
|
||||
outputNumInput(&(t->num), tvec, &t->scene->unit);
|
||||
outputNumInput(&(t->num), tvec, t->scene->unit);
|
||||
}
|
||||
else {
|
||||
BLI_snprintf(&tvec[0], NUM_STR_REP_LEN, "%.0f, %.0f", val[0], val[1]);
|
||||
|
||||
@@ -793,7 +793,7 @@ static void applyEdgeSlide(TransInfo *t)
|
||||
ofs += BLI_strncpy_rlen(str + ofs, RPT_("Edge Slide: "), sizeof(str) - ofs);
|
||||
if (hasNumInput(&t->num)) {
|
||||
char c[NUM_STR_REP_LEN];
|
||||
outputNumInput(&(t->num), c, &t->scene->unit);
|
||||
outputNumInput(&(t->num), c, t->scene->unit);
|
||||
ofs += BLI_strncpy_rlen(str + ofs, &c[0], sizeof(str) - ofs);
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -49,7 +49,7 @@ static void applyGPOpacity(TransInfo *t)
|
||||
if (hasNumInput(&t->num)) {
|
||||
char c[NUM_STR_REP_LEN];
|
||||
|
||||
outputNumInput(&(t->num), c, &t->scene->unit);
|
||||
outputNumInput(&(t->num), c, t->scene->unit);
|
||||
SNPRINTF(str, IFACE_("Opacity: %s"), c);
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -48,7 +48,7 @@ static void applyMaskShrinkFatten(TransInfo *t)
|
||||
if (hasNumInput(&t->num)) {
|
||||
char c[NUM_STR_REP_LEN];
|
||||
|
||||
outputNumInput(&(t->num), c, &t->scene->unit);
|
||||
outputNumInput(&(t->num), c, t->scene->unit);
|
||||
SNPRINTF(str, IFACE_("Feather Shrink/Fatten: %s"), c);
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -121,7 +121,7 @@ static void applyPushPull(TransInfo *t)
|
||||
if (hasNumInput(&t->num)) {
|
||||
char c[NUM_STR_REP_LEN];
|
||||
|
||||
outputNumInput(&(t->num), c, &t->scene->unit);
|
||||
outputNumInput(&(t->num), c, t->scene->unit);
|
||||
|
||||
SNPRINTF(str, IFACE_("Push/Pull: %s%s %s"), c, t->con.text, t->proptext);
|
||||
}
|
||||
|
||||
@@ -304,7 +304,7 @@ static void apply_shear(TransInfo *t)
|
||||
/* Header print for NumInput. */
|
||||
if (hasNumInput(&t->num)) {
|
||||
char c[NUM_STR_REP_LEN];
|
||||
outputNumInput(&(t->num), c, &t->scene->unit);
|
||||
outputNumInput(&(t->num), c, t->scene->unit);
|
||||
SNPRINTF(str, IFACE_("Shear: %s %s"), c, t->proptext);
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -95,7 +95,7 @@ static void applyShrinkFatten(TransInfo *t)
|
||||
float distance;
|
||||
int i;
|
||||
fmt::memory_buffer str;
|
||||
UnitSettings *unit = &t->scene->unit;
|
||||
const UnitSettings &unit = t->scene->unit;
|
||||
|
||||
distance = t->values[0] + t->values_modal_offset[0];
|
||||
|
||||
@@ -114,7 +114,7 @@ static void applyShrinkFatten(TransInfo *t)
|
||||
}
|
||||
else {
|
||||
/* Default header print. */
|
||||
if (unit->system != USER_UNIT_NONE) {
|
||||
if (unit.system != USER_UNIT_NONE) {
|
||||
char unit_str[64];
|
||||
BKE_unit_value_as_string_scaled(
|
||||
unit_str, sizeof(unit_str), distance, 4, B_UNIT_LENGTH, unit, true);
|
||||
|
||||
@@ -48,7 +48,7 @@ static void applyTilt(TransInfo *t)
|
||||
if (hasNumInput(&t->num)) {
|
||||
char c[NUM_STR_REP_LEN];
|
||||
|
||||
outputNumInput(&(t->num), c, &t->scene->unit);
|
||||
outputNumInput(&(t->num), c, t->scene->unit);
|
||||
|
||||
SNPRINTF(str, "%s %s" BLI_STR_UTF8_DEGREE_SIGN " %s", IFACE_("Tilt:"), &c[0], t->proptext);
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ static void headerTimeScale(TransInfo *t, char str[UI_MAX_DRAW_STR])
|
||||
char tvec[NUM_STR_REP_LEN * 3];
|
||||
|
||||
if (hasNumInput(&t->num)) {
|
||||
outputNumInput(&(t->num), tvec, &t->scene->unit);
|
||||
outputNumInput(&(t->num), tvec, t->scene->unit);
|
||||
}
|
||||
else {
|
||||
BLI_snprintf(&tvec[0], NUM_STR_REP_LEN, "%.4f", t->values_final[0]);
|
||||
|
||||
@@ -38,7 +38,7 @@ static void headerTimeSlide(TransInfo *t, const float sval, char str[UI_MAX_DRAW
|
||||
char tvec[NUM_STR_REP_LEN * 3];
|
||||
|
||||
if (hasNumInput(&t->num)) {
|
||||
outputNumInput(&(t->num), tvec, &t->scene->unit);
|
||||
outputNumInput(&(t->num), tvec, t->scene->unit);
|
||||
}
|
||||
else {
|
||||
const float *range = static_cast<const float *>(t->custom.mode.data);
|
||||
|
||||
@@ -37,7 +37,7 @@ static void headerTimeTranslate(TransInfo *t, char str[UI_MAX_DRAW_STR])
|
||||
|
||||
/* If numeric input is active, use results from that, otherwise apply snapping to result. */
|
||||
if (hasNumInput(&t->num)) {
|
||||
outputNumInput(&(t->num), tvec, &t->scene->unit);
|
||||
outputNumInput(&(t->num), tvec, t->scene->unit);
|
||||
}
|
||||
else {
|
||||
eSnapMode snap_mode = t->tsnap.mode;
|
||||
|
||||
@@ -193,7 +193,7 @@ static void applyToSphere(TransInfo *t)
|
||||
if (hasNumInput(&t->num)) {
|
||||
char c[NUM_STR_REP_LEN];
|
||||
|
||||
outputNumInput(&(t->num), c, &t->scene->unit);
|
||||
outputNumInput(&(t->num), c, t->scene->unit);
|
||||
|
||||
SNPRINTF(str, IFACE_("To Sphere: %s %s"), c, t->proptext);
|
||||
}
|
||||
|
||||
@@ -140,7 +140,7 @@ static void applyTrackball(TransInfo *t)
|
||||
if (hasNumInput(&t->num)) {
|
||||
char c[NUM_STR_REP_LEN * 2];
|
||||
|
||||
outputNumInput(&(t->num), c, &t->scene->unit);
|
||||
outputNumInput(&(t->num), c, t->scene->unit);
|
||||
|
||||
ofs += BLI_snprintf_rlen(str + ofs,
|
||||
sizeof(str) - ofs,
|
||||
|
||||
@@ -188,7 +188,7 @@ static void translate_dist_to_str(char *r_str,
|
||||
const UnitSettings *unit)
|
||||
{
|
||||
if (unit && (unit->system != USER_UNIT_NONE)) {
|
||||
BKE_unit_value_as_string_scaled(r_str, r_str_maxncpy, val, 4, B_UNIT_LENGTH, unit, false);
|
||||
BKE_unit_value_as_string_scaled(r_str, r_str_maxncpy, val, 4, B_UNIT_LENGTH, *unit, false);
|
||||
}
|
||||
else {
|
||||
/* Check range to prevent string buffer overflow. */
|
||||
@@ -209,7 +209,7 @@ static void headerTranslation(TransInfo *t, const float vec[3], char str[UI_MAX_
|
||||
}
|
||||
|
||||
if (hasNumInput(&t->num)) {
|
||||
outputNumInput(&(t->num), dvec_str[0], &t->scene->unit);
|
||||
outputNumInput(&(t->num), dvec_str[0], t->scene->unit);
|
||||
dist = len_v3(t->num.val);
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -507,7 +507,7 @@ static void applyVertSlide(TransInfo *t)
|
||||
ofs += BLI_strncpy_rlen(str + ofs, IFACE_("Vertex Slide: "), sizeof(str) - ofs);
|
||||
if (hasNumInput(&t->num)) {
|
||||
char c[NUM_STR_REP_LEN];
|
||||
outputNumInput(&(t->num), c, &t->scene->unit);
|
||||
outputNumInput(&(t->num), c, t->scene->unit);
|
||||
ofs += BLI_strncpy_rlen(str + ofs, &c[0], sizeof(str) - ofs);
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -85,7 +85,7 @@ void initNumInput(NumInput *n)
|
||||
n->str_cur = 0;
|
||||
}
|
||||
|
||||
void outputNumInput(NumInput *n, char *str, const UnitSettings *unit_settings)
|
||||
void outputNumInput(NumInput *n, char *str, const UnitSettings &unit_settings)
|
||||
{
|
||||
short j;
|
||||
const int ln = NUM_STR_REP_LEN;
|
||||
@@ -265,7 +265,7 @@ static bool editstr_insert_at_cursor(NumInput *n, const char *buf, const int buf
|
||||
|
||||
bool user_string_to_number(bContext *C,
|
||||
const char *str,
|
||||
const UnitSettings *unit,
|
||||
const UnitSettings &unit,
|
||||
int type,
|
||||
double *r_value,
|
||||
const bool use_single_line_error,
|
||||
@@ -281,7 +281,7 @@ bool user_string_to_number(bContext *C,
|
||||
char str_unit_convert[256];
|
||||
STRNCPY(str_unit_convert, str);
|
||||
BKE_unit_replace_string(
|
||||
str_unit_convert, sizeof(str_unit_convert), str, unit_scale, unit->system, type);
|
||||
str_unit_convert, sizeof(str_unit_convert), str, unit_scale, unit.system, type);
|
||||
|
||||
return BPY_run_string_as_number(C, nullptr, str_unit_convert, &err_info, r_value);
|
||||
}
|
||||
@@ -583,7 +583,7 @@ bool handleNumInput(bContext *C, NumInput *n, const wmEvent *event)
|
||||
|
||||
double val;
|
||||
int success = user_string_to_number(
|
||||
C, n->str, &sce->unit, n->unit_type[idx], &val, false, &error);
|
||||
C, n->str, sce->unit, n->unit_type[idx], &val, false, &error);
|
||||
|
||||
if (error) {
|
||||
ReportList *reports = CTX_wm_reports(C);
|
||||
|
||||
@@ -2539,7 +2539,7 @@ static void radial_control_update_header(wmOperator *op, bContext *C)
|
||||
|
||||
if (hasNumInput(&rc->num_input)) {
|
||||
char num_str[NUM_STR_REP_LEN];
|
||||
outputNumInput(&rc->num_input, num_str, &scene->unit);
|
||||
outputNumInput(&rc->num_input, num_str, scene->unit);
|
||||
SNPRINTF(msg, "%s: %s", RNA_property_ui_name(rc->prop), num_str);
|
||||
}
|
||||
else {
|
||||
|
||||
Reference in New Issue
Block a user