Blender V4.3
transform_mode_maskshrinkfatten.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2001-2002 NaN Holding BV. All rights reserved.
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
9#include <cstdlib>
10
11#include "BLI_math_vector.h"
12#include "BLI_string.h"
13
14#include "BKE_unit.hh"
15
16#include "ED_screen.hh"
17
18#include "UI_interface.hh"
19
20#include "BLT_translation.hh"
21
22#include "transform.hh"
23#include "transform_convert.hh"
24#include "transform_snap.hh"
25
26#include "transform_mode.hh"
27
28/* -------------------------------------------------------------------- */
33{
34 float ratio;
35 int i;
36 bool initial_feather = false;
37 char str[UI_MAX_DRAW_STR];
38
39 ratio = t->values[0] + t->values_modal_offset[0];
40
41 transform_snap_increment(t, &ratio);
42
43 applyNumInput(&t->num, &ratio);
44
45 t->values_final[0] = ratio;
46
47 /* Header print for NumInput. */
48 if (hasNumInput(&t->num)) {
49 char c[NUM_STR_REP_LEN];
50
51 outputNumInput(&(t->num), c, &t->scene->unit);
52 SNPRINTF(str, IFACE_("Feather Shrink/Fatten: %s"), c);
53 }
54 else {
55 SNPRINTF(str, IFACE_("Feather Shrink/Fatten: %3f"), ratio);
56 }
57
58 /* Detect if no points have feather yet. */
59 if (ratio > 1.0f) {
60 initial_feather = true;
61
63 TransData *td = tc->data;
64 for (i = 0; i < tc->data_len; i++, td++) {
65 if (td->flag & TD_SKIP) {
66 continue;
67 }
68
69 if (td->ival >= 0.001f) {
70 initial_feather = false;
71 }
72 }
73 }
74 }
75
76 /* Apply shrink/fatten. */
78 TransData *td;
79 for (td = tc->data, i = 0; i < tc->data_len; i++, td++) {
80 if (td->flag & TD_SKIP) {
81 continue;
82 }
83
84 if (td->val) {
85 if (initial_feather) {
86 *td->val = td->ival + (ratio - 1.0f) * 0.01f;
87 }
88 else {
89 *td->val = td->ival * ratio;
90 }
91
92 /* Apply proportional editing. */
93 *td->val = interpf(*td->val, td->ival, td->factor);
94 if (*td->val <= 0.0f) {
95 *td->val = 0.001f;
96 }
97 }
98 }
99 }
100
101 recalc_data(t);
102
104}
105
107{
109
111
112 t->idx_max = 0;
113 t->num.idx_max = 0;
114 t->snap[0] = 0.1f;
115 t->snap[1] = t->snap[0] * 0.1f;
116
117 copy_v3_fl(t->num.val_inc, t->snap[0]);
118 t->num.unit_sys = t->scene->unit.system;
119 t->num.unit_type[0] = B_UNIT_NONE;
120
121#ifdef USE_NUM_NO_ZERO
122 t->num.val_flag[0] |= NUM_NO_ZERO;
123#endif
124}
125
129 /*flags*/ T_NO_CONSTRAINT,
130 /*init_fn*/ initMaskShrinkFatten,
131 /*transform_fn*/ applyMaskShrinkFatten,
132 /*transform_matrix_fn*/ nullptr,
133 /*handle_event_fn*/ nullptr,
134 /*snap_distance_fn*/ nullptr,
135 /*snap_apply_fn*/ nullptr,
136 /*draw_fn*/ nullptr,
137};
@ B_UNIT_NONE
Definition BKE_unit.hh:106
MINLINE float interpf(float target, float origin, float t)
MINLINE void copy_v3_fl(float r[3], float f)
#define SNPRINTF(dst, format,...)
Definition BLI_string.h:597
#define IFACE_(msgid)
#define NUM_STR_REP_LEN
void outputNumInput(NumInput *n, char *str, const UnitSettings *unit_settings)
Definition numinput.cc:88
bool applyNumInput(NumInput *n, float *vec)
Definition numinput.cc:190
@ NUM_NO_ZERO
bool hasNumInput(const NumInput *n)
Definition numinput.cc:171
void ED_area_status_text(ScrArea *area, const char *str)
Definition area.cc:803
@ TFM_MASK_SHRINKFATTEN
#define UI_MAX_DRAW_STR
#define str(s)
short idx_max
short val_flag[NUM_MAX_ELEMENTS]
float val_inc[NUM_MAX_ELEMENTS]
int unit_type[NUM_MAX_ELEMENTS]
struct UnitSettings unit
eTfmMode mode
Definition transform.hh:517
float snap[2]
Definition transform.hh:561
float values[4]
Definition transform.hh:624
short idx_max
Definition transform.hh:559
float values_modal_offset[4]
Definition transform.hh:627
NumInput num
Definition transform.hh:540
Scene * scene
Definition transform.hh:654
MouseInput mouse
Definition transform.hh:543
float values_final[4]
Definition transform.hh:632
ScrArea * area
Definition transform.hh:651
@ INPUT_SPRING
Definition transform.hh:743
@ T_NO_CONSTRAINT
Definition transform.hh:95
void initMouseInputMode(TransInfo *t, MouseInput *mi, MouseInputMode mode)
#define FOREACH_TRANS_DATA_CONTAINER(t, th)
Definition transform.hh:854
void recalc_data(TransInfo *t)
conversion and adaptation of different datablocks to a common struct.
@ TD_SKIP
transform modes used by different operators.
static void initMaskShrinkFatten(TransInfo *t, wmOperator *)
TransModeInfo TransMode_maskshrinkfatten
static void applyMaskShrinkFatten(TransInfo *t)
bool transform_snap_increment(const TransInfo *t, float *r_val)