Blender V4.3
transform_mode_gpopacity.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
17
18#include "ED_screen.hh"
19
20#include "UI_interface.hh"
21
22#include "BLT_translation.hh"
23
24#include "transform.hh"
25#include "transform_convert.hh"
26#include "transform_snap.hh"
27
28#include "transform_mode.hh"
29
30/* -------------------------------------------------------------------- */
35{
36 float ratio;
37 int i;
38 char str[UI_MAX_DRAW_STR];
39
40 ratio = t->values[0] + t->values_modal_offset[0];
41
42 transform_snap_increment(t, &ratio);
43
44 applyNumInput(&t->num, &ratio);
45
46 t->values_final[0] = ratio;
47
48 /* Header print for NumInput. */
49 if (hasNumInput(&t->num)) {
50 char c[NUM_STR_REP_LEN];
51
52 outputNumInput(&(t->num), c, &t->scene->unit);
53 SNPRINTF(str, IFACE_("Opacity: %s"), c);
54 }
55 else {
56 SNPRINTF(str, IFACE_("Opacity: %3f"), ratio);
57 }
58
59 bool recalc = false;
61 TransData *td = tc->data;
62
64 bGPdata *gpd = static_cast<bGPdata *>(td->ob->data);
65 const bool is_curve_edit = bool(GPENCIL_CURVE_EDIT_SESSIONS_ON(gpd));
66 /* Only recalculate data when in curve edit mode. */
67 if (is_curve_edit) {
68 recalc = true;
69 }
70 }
71 else if (t->obedit_type == OB_GREASE_PENCIL) {
72 recalc = true;
73 }
74
75 for (i = 0; i < tc->data_len; i++, td++) {
76 if (td->flag & TD_SKIP) {
77 continue;
78 }
79
80 if (td->val) {
81 *td->val = td->ival * ratio;
82 /* Apply proportional editing. */
83 *td->val = interpf(*td->val, td->ival, td->factor);
84 CLAMP(*td->val, 0.0f, 1.0f);
85 }
86 }
87 }
88
89 if (recalc) {
90 recalc_data(t);
91 }
92
94}
95
96static void initGPOpacity(TransInfo *t, wmOperator * /*op*/)
97{
99
101
102 t->idx_max = 0;
103 t->num.idx_max = 0;
104 t->snap[0] = 0.1f;
105 t->snap[1] = t->snap[0] * 0.1f;
106
107 copy_v3_fl(t->num.val_inc, t->snap[0]);
108 t->num.unit_sys = t->scene->unit.system;
109 t->num.unit_type[0] = B_UNIT_NONE;
110
111#ifdef USE_NUM_NO_ZERO
112 t->num.val_flag[0] |= NUM_NO_ZERO;
113#endif
114}
115
119 /*flags*/ T_NO_CONSTRAINT,
120 /*init_fn*/ initGPOpacity,
121 /*transform_fn*/ applyGPOpacity,
122 /*transform_matrix_fn*/ nullptr,
123 /*handle_event_fn*/ nullptr,
124 /*snap_distance_fn*/ nullptr,
125 /*snap_apply_fn*/ nullptr,
126 /*draw_fn*/ nullptr,
127};
@ 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 CLAMP(a, b, c)
#define IFACE_(msgid)
#define GPENCIL_CURVE_EDIT_SESSIONS_ON(gpd)
@ OB_GREASE_PENCIL
@ OB_GPENCIL_LEGACY
#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_GPENCIL_OPACITY
#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
short obedit_type
Definition transform.hh:584
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 applyGPOpacity(TransInfo *t)
TransModeInfo TransMode_gpopacity
static void initGPOpacity(TransInfo *t, wmOperator *)
bool transform_snap_increment(const TransInfo *t, float *r_val)