Blender V5.0
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
8
9#include <cstdlib>
10
11#include "BLI_math_vector.h"
12#include "BLI_string_utf8.h"
13
14#include "BKE_unit.hh"
15
16#include "ED_screen.hh"
17
18#include "BLT_translation.hh"
19
20#include "UI_interface_types.hh"
21
22#include "transform.hh"
23#include "transform_convert.hh"
24#include "transform_snap.hh"
25
26#include "transform_mode.hh"
27
28namespace blender::ed::transform {
29
30/* -------------------------------------------------------------------- */
33
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_UTF8(str, IFACE_("Opacity: %s"), c);
54 }
55 else {
56 SNPRINTF_UTF8(str, IFACE_("Opacity: %3f"), ratio);
57 }
58
59 bool recalc = false;
61 TransData *td = tc->data;
62
63 recalc = true;
64
65 for (i = 0; i < tc->data_len; i++, td++) {
66 if (td->flag & TD_SKIP) {
67 continue;
68 }
69
70 if (td->val) {
71 *td->val = td->ival * ratio;
72 /* Apply proportional editing. */
73 *td->val = interpf(*td->val, td->ival, td->factor);
74 CLAMP(*td->val, 0.0f, 1.0f);
75 }
76 }
77 }
78
79 if (recalc) {
80 recalc_data(t);
81 }
82
84}
85
86static void initGPOpacity(TransInfo *t, wmOperator * /*op*/)
87{
89
91
92 t->idx_max = 0;
93 t->num.idx_max = 0;
94 t->increment[0] = 0.1f;
95 t->increment_precision = 0.1f;
96
98 t->num.unit_sys = t->scene->unit.system;
100
101#ifdef USE_NUM_NO_ZERO
102 t->num.val_flag[0] |= NUM_NO_ZERO;
103#endif
104}
105
107
109 /*flags*/ T_NO_CONSTRAINT,
110 /*init_fn*/ initGPOpacity,
111 /*transform_fn*/ applyGPOpacity,
112 /*transform_matrix_fn*/ nullptr,
113 /*handle_event_fn*/ nullptr,
114 /*snap_distance_fn*/ nullptr,
115 /*snap_apply_fn*/ nullptr,
116 /*draw_fn*/ nullptr,
117};
118
119} // namespace blender::ed::transform
@ B_UNIT_NONE
Definition BKE_unit.hh:136
MINLINE float interpf(float target, float origin, float t)
MINLINE void copy_v3_fl(float r[3], float f)
#define SNPRINTF_UTF8(dst, format,...)
#define CLAMP(a, b, c)
#define IFACE_(msgid)
#define NUM_STR_REP_LEN
bool applyNumInput(NumInput *n, float *vec)
Definition numinput.cc:190
@ NUM_NO_ZERO
void outputNumInput(NumInput *n, char *str, const UnitSettings &unit_settings)
Definition numinput.cc:88
bool hasNumInput(const NumInput *n)
Definition numinput.cc:171
void ED_area_status_text(ScrArea *area, const char *str)
Definition area.cc:851
#define UI_MAX_DRAW_STR
#define str(s)
static void initGPOpacity(TransInfo *t, wmOperator *)
void initMouseInputMode(TransInfo *t, MouseInput *mi, MouseInputMode mode)
void recalc_data(TransInfo *t)
static void applyGPOpacity(TransInfo *t)
bool transform_snap_increment(const TransInfo *t, float *r_val)
short idx_max
short val_flag[NUM_MAX_ELEMENTS]
float val_inc[NUM_MAX_ELEMENTS]
int unit_type[NUM_MAX_ELEMENTS]
struct UnitSettings unit
i
Definition text_draw.cc:230
#define FOREACH_TRANS_DATA_CONTAINER(t, th)
Definition transform.hh:42
conversion and adaptation of different datablocks to a common struct.
transform modes used by different operators.