Cleanup: use a const pointer for unit-settings
This commit is contained in:
parent
e04aa7c188
commit
4365d0496a
|
@ -98,14 +98,14 @@ static void ui_def_but_rna__menu_type(bContext * /*C*/, uiLayout *layout, void *
|
|||
|
||||
static void ui_but_free(const bContext *C, uiBut *but);
|
||||
|
||||
static bool ui_but_is_unit_radians_ex(UnitSettings *unit, const int unit_type)
|
||||
static bool ui_but_is_unit_radians_ex(const UnitSettings *unit, const int unit_type)
|
||||
{
|
||||
return (unit->system_rotation == USER_UNIT_ROT_RADIANS && unit_type == PROP_UNIT_ROTATION);
|
||||
}
|
||||
|
||||
static bool ui_but_is_unit_radians(const uiBut *but)
|
||||
{
|
||||
UnitSettings *unit = but->block->unit;
|
||||
const UnitSettings *unit = but->block->unit;
|
||||
const int unit_type = UI_but_unit_type_get(but);
|
||||
|
||||
return ui_but_is_unit_radians_ex(unit, unit_type);
|
||||
|
@ -2425,7 +2425,7 @@ bool ui_but_is_bool(const uiBut *but)
|
|||
|
||||
bool ui_but_is_unit(const uiBut *but)
|
||||
{
|
||||
UnitSettings *unit = but->block->unit;
|
||||
const UnitSettings *unit = but->block->unit;
|
||||
const int unit_type = UI_but_unit_type_get(but);
|
||||
|
||||
if (unit_type == PROP_UNIT_NONE) {
|
||||
|
@ -2683,7 +2683,7 @@ uiBut *ui_but_drag_multi_edit_get(uiBut *but)
|
|||
|
||||
static double ui_get_but_scale_unit(uiBut *but, double value)
|
||||
{
|
||||
UnitSettings *unit = but->block->unit;
|
||||
const UnitSettings *unit = but->block->unit;
|
||||
const int unit_type = UI_but_unit_type_get(but);
|
||||
|
||||
/* Time unit is a bit special, not handled by BKE_scene_unit_scale() for now. */
|
||||
|
@ -2700,7 +2700,7 @@ void ui_but_convert_to_unit_alt_name(uiBut *but, char *str, size_t str_maxncpy)
|
|||
return;
|
||||
}
|
||||
|
||||
UnitSettings *unit = but->block->unit;
|
||||
const UnitSettings *unit = but->block->unit;
|
||||
const int unit_type = UI_but_unit_type_get(but);
|
||||
char *orig_str;
|
||||
|
||||
|
@ -2718,7 +2718,7 @@ void ui_but_convert_to_unit_alt_name(uiBut *but, char *str, size_t str_maxncpy)
|
|||
static void ui_get_but_string_unit(
|
||||
uiBut *but, char *str, int str_maxncpy, double value, bool pad, int float_precision)
|
||||
{
|
||||
UnitSettings *unit = but->block->unit;
|
||||
const UnitSettings *unit = but->block->unit;
|
||||
const int unit_type = UI_but_unit_type_get(but);
|
||||
int precision;
|
||||
|
||||
|
@ -3443,7 +3443,7 @@ void UI_block_free(const bContext *C, uiBlock *block)
|
|||
}
|
||||
|
||||
if (block->unit) {
|
||||
MEM_freeN(block->unit);
|
||||
MEM_freeN((void *)block->unit);
|
||||
}
|
||||
|
||||
if (block->func_argN) {
|
||||
|
@ -3586,9 +3586,10 @@ uiBlock *UI_block_begin(const bContext *C, ARegion *region, std::string name, eU
|
|||
*/
|
||||
STRNCPY(block->display_device, scene->display_settings.display_device);
|
||||
|
||||
/* copy to avoid crash when scene gets deleted with ui still open */
|
||||
block->unit = MEM_new<UnitSettings>(__func__);
|
||||
memcpy(block->unit, &scene->unit, sizeof(scene->unit));
|
||||
/* Copy to avoid crash when scene gets deleted with UI still open. */
|
||||
UnitSettings *unit = MEM_new<UnitSettings>(__func__);
|
||||
memcpy(unit, &scene->unit, sizeof(scene->unit));
|
||||
block->unit = unit;
|
||||
}
|
||||
else {
|
||||
STRNCPY(block->display_device, IMB_colormanagement_display_get_default_name());
|
||||
|
|
|
@ -4992,7 +4992,7 @@ static float ui_numedit_apply_snapf(
|
|||
float fac = 1.0f;
|
||||
|
||||
if (ui_but_is_unit(but)) {
|
||||
UnitSettings *unit = but->block->unit;
|
||||
const UnitSettings *unit = but->block->unit;
|
||||
const int unit_type = RNA_SUBTYPE_UNIT_VALUE(UI_but_unit_type_get(but));
|
||||
|
||||
if (BKE_unit_is_valid(unit->system, unit_type)) {
|
||||
|
@ -5015,7 +5015,7 @@ static float ui_numedit_apply_snapf(
|
|||
/* snapping by 10's for float buttons is quite annoying (location, scale...),
|
||||
* but allow for rotations */
|
||||
if (softrange >= 21.0f) {
|
||||
UnitSettings *unit = but->block->unit;
|
||||
const UnitSettings *unit = but->block->unit;
|
||||
const int unit_type = UI_but_unit_type_get(but);
|
||||
if ((unit_type == PROP_UNIT_ROTATION) && (unit->system_rotation != USER_UNIT_ROT_RADIANS)) {
|
||||
/* Pass (degrees). */
|
||||
|
|
|
@ -619,7 +619,7 @@ struct uiBlock {
|
|||
|
||||
/** unit system, used a lot for numeric buttons so include here
|
||||
* rather than fetching through the scene every time. */
|
||||
UnitSettings *unit;
|
||||
const UnitSettings *unit;
|
||||
/** \note only accessed by color picker templates. */
|
||||
ColorPickerData color_pickers;
|
||||
|
||||
|
|
|
@ -507,7 +507,7 @@ 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);
|
||||
|
||||
UnitSettings *unit = &kcd->scene->unit;
|
||||
const UnitSettings *unit = &kcd->scene->unit;
|
||||
if (unit->system == USER_UNIT_NONE) {
|
||||
SNPRINTF(numstr, "%.*f", distance_precision, cut_len);
|
||||
}
|
||||
|
@ -643,7 +643,7 @@ static void knifetool_draw_angle(const KnifeTool_OpData *kcd,
|
|||
float numstr_size[2];
|
||||
float posit[2];
|
||||
|
||||
UnitSettings *unit = &kcd->scene->unit;
|
||||
const UnitSettings *unit = &kcd->scene->unit;
|
||||
if (unit->system == USER_UNIT_NONE) {
|
||||
SNPRINTF(numstr, "%.*f" BLI_STR_UTF8_DEGREE_SIGN, angle_precision, RAD2DEGF(angle));
|
||||
}
|
||||
|
|
|
@ -314,7 +314,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);
|
||||
UnitSettings *unit = &scene->unit;
|
||||
const UnitSettings *unit = &scene->unit;
|
||||
BKE_unit_value_as_string(str,
|
||||
VOXEL_SIZE_EDIT_MAX_STR_LEN,
|
||||
double(cd->voxel_size * unit->scale_length),
|
||||
|
|
|
@ -202,7 +202,7 @@ static void headerTranslation(TransInfo *t, const float vec[3], char str[UI_MAX_
|
|||
char dist_str[NUM_STR_REP_LEN];
|
||||
float dist;
|
||||
|
||||
UnitSettings *unit = nullptr;
|
||||
const UnitSettings *unit = nullptr;
|
||||
if (!(t->flag & T_2D_EDIT)) {
|
||||
unit = &t->scene->unit;
|
||||
}
|
||||
|
|
|
@ -2860,7 +2860,7 @@ const EnumPropertyItem *rna_UnitSettings_length_unit_itemf(bContext * /*C*/,
|
|||
PropertyRNA * /*prop*/,
|
||||
bool *r_free)
|
||||
{
|
||||
UnitSettings *units = static_cast<UnitSettings *>(ptr->data);
|
||||
const UnitSettings *units = static_cast<const UnitSettings *>(ptr->data);
|
||||
return rna_UnitSettings_itemf_wrapper(units->system, B_UNIT_LENGTH, r_free);
|
||||
}
|
||||
|
||||
|
@ -2869,7 +2869,7 @@ const EnumPropertyItem *rna_UnitSettings_mass_unit_itemf(bContext * /*C*/,
|
|||
PropertyRNA * /*prop*/,
|
||||
bool *r_free)
|
||||
{
|
||||
UnitSettings *units = static_cast<UnitSettings *>(ptr->data);
|
||||
const UnitSettings *units = static_cast<const UnitSettings *>(ptr->data);
|
||||
return rna_UnitSettings_itemf_wrapper(units->system, B_UNIT_MASS, r_free);
|
||||
}
|
||||
|
||||
|
@ -2878,7 +2878,7 @@ const EnumPropertyItem *rna_UnitSettings_time_unit_itemf(bContext * /*C*/,
|
|||
PropertyRNA * /*prop*/,
|
||||
bool *r_free)
|
||||
{
|
||||
UnitSettings *units = static_cast<UnitSettings *>(ptr->data);
|
||||
const UnitSettings *units = static_cast<const UnitSettings *>(ptr->data);
|
||||
return rna_UnitSettings_itemf_wrapper(units->system, B_UNIT_TIME, r_free);
|
||||
}
|
||||
|
||||
|
@ -2887,7 +2887,7 @@ const EnumPropertyItem *rna_UnitSettings_temperature_unit_itemf(bContext * /*C*/
|
|||
PropertyRNA * /*prop*/,
|
||||
bool *r_free)
|
||||
{
|
||||
UnitSettings *units = static_cast<UnitSettings *>(ptr->data);
|
||||
const UnitSettings *units = static_cast<const UnitSettings *>(ptr->data);
|
||||
return rna_UnitSettings_itemf_wrapper(units->system, B_UNIT_TEMPERATURE, r_free);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue