48#define GIZMO_MARGIN_OFFSET_SCALE 1.5f
50#define CIRCLE_RESOL 32
56 float matrix_final_no_offset[4][4];
57 float x_axis[3], y_axis[3];
62 float len_x_axis =
len_v3(x_axis);
63 float len_y_axis =
len_v3(y_axis);
78 margin[0] = (handle_size * scale_xy[0]);
79 margin[1] = (handle_size * scale_xy[1]);
89 const float margin[2],
91 const float line_width)
133 const int highlighted,
135 const float margin[2],
136 const float line_width,
138 const int draw_options)
145 switch (highlighted) {
149 r.
xmax = -size[0] + margin[0];
150 r.
ymin = -size[1] + margin[1];
151 r.
ymax = size[1] - margin[1];
169 r.
xmin = size[0] - margin[0];
171 r.
ymin = -size[1] + margin[1];
172 r.
ymax = size[1] - margin[1];
190 r.
xmin = -size[0] + margin[0];
191 r.
xmax = size[0] - margin[0];
193 r.
ymax = -size[1] + margin[1];
211 r.
xmin = -size[0] + margin[0];
212 r.
xmax = size[0] - margin[0];
213 r.
ymin = size[1] - margin[1];
233 r.
xmax = -size[0] + margin[0];
235 r.
ymax = -size[1] + margin[1];
254 r.
xmax = -size[0] + margin[0];
255 r.
ymin = size[1] - margin[1];
274 r.
xmin = size[0] - margin[0];
277 r.
ymax = -size[1] + margin[1];
295 r.
xmin = size[0] - margin[0];
297 r.
ymin = size[1] - margin[1];
315 const float rotate_pt[2] = {0.0f, size[1] + margin[1]};
317 r_rotate.
xmin = rotate_pt[0] - margin[0] / 2.0f;
318 r_rotate.
xmax = rotate_pt[0] + margin[0] / 2.0f;
319 r_rotate.
ymin = rotate_pt[1] - margin[1] / 2.0f;
320 r_rotate.
ymax = rotate_pt[1] + margin[1] / 2.0f;
385 if (margin[0] == 0.0f && margin[1] == 0.0) {
389 else if (margin[0] == 0.0f || margin[1] == 0.0) {
399 immAttr3f(attr_id.col, 0.0f, 0.0f, 0.0f);
400 for (
uint i = 0; i < verts_len; i++) {
414 immUniform1f(
"lineWidth", (line_width * 3.0f) *
U.pixelsize);
417 immAttr3f(attr_id.col, 0.0f, 0.0f, 0.0f);
418 for (
uint i = 0; i < verts_len; i++) {
427 for (
uint i = 0; i < verts_len; i++) {
446 uint pos,
float x,
float y,
float rad_x,
float rad_y,
bool solid)
448 if (rad_x == 0 && rad_y == 0) {
455 if (rad_x == 0 || rad_y == 0) {
492 const float margin[2],
493 const float color[3],
494 const int transform_flag,
495 const int draw_options,
496 const float line_width)
537 const float rad[2] = {margin[0] / 2, margin[1] / 2};
541 immVertex3f(pos, center[0] - rad[0], center[1] - rad[1], 0.0f);
542 immVertex3f(pos, center[0] + rad[0], center[1] + rad[1], 0.0f);
543 immVertex3f(pos, center[0] + rad[0], center[1] - rad[1], 0.0f);
544 immVertex3f(pos, center[0] - rad[0], center[1] + rad[1], 0.0f);
554 const float margin[2],
555 const int transform_flag,
556 const int draw_options,
557 const float line_width)
593 const float rad[2] = {margin[0] / 2, margin[1] / 2};
594 const float center[2] = {0.0f, 0.0f};
597 immVertex3f(pos, center[0] - rad[0], center[1] - rad[1], 0.0f);
598 immVertex3f(pos, center[0] + rad[0], center[1] + rad[1], 0.0f);
599 immVertex3f(pos, center[0] + rad[0], center[1] - rad[1], 0.0f);
600 immVertex3f(pos, center[0] - rad[0], center[1] + rad[1], 0.0f);
610 return ELEM(highlighted,
618 const float margin[2],
619 const float color[3],
626 const int resolu = 12;
627 const float rad[2] = {margin[0] / 3, margin[1] / 3};
632 const float handle[2] = {
636 circle_fn(pos, handle[0], handle[1], rad[0], rad[1], resolu);
642 const float margin[2],
643 const float color[3],
647 const float rad[2] = {margin[0] / 3, margin[1] / 3};
664 const int highlighted,
666 const float margin[2],
667 const float color[3],
675 switch (highlighted) {
678 const float rad[2] = {0.2f * margin[0], 0.4f * size[1]};
685 const float rad[2] = {0.4f * size[0], 0.2f * margin[1]};
699 const bool highlight,
705 float matrix_final[4][4];
711 const float size_real[2] = {dims[0] / 2.0f, dims[1] / 2.0f};
735 const float size[2] = {size_real[0] + margin[0] / 2, size_real[1] + margin[1] / 2};
744 int scale_parts[] = {
755 for (
int i = 0; i <
ARRAY_SIZE(scale_parts); i++) {
758 gz->
color, scale_parts[i], size, margin, gz->
line_width,
true, draw_options);
765 gz->
color, transform_part, size, margin, gz->
line_width,
true, draw_options);
780 r.
xmin = -size_real[0];
781 r.
ymin = -size_real[1];
782 r.
xmax = size_real[0];
783 r.
ymax = size_real[1];
786 float color[4], black[3] = {0, 0, 0};
823 float color[4], black[3] = {0, 0, 0};
828 float outline_line_width = gz->
line_width + 3.0f;
852 black, size_real, margin, transform_flag, draw_options, outline_line_width);
854 color, size_real, margin, transform_flag, draw_options, gz->
line_width);
904 switch (highlight_part) {
930 float point_local[2];
933 const float size_real[2] = {dims[0] / 2.0f, dims[1] / 2.0f};
943 const float size[2] = {size_real[0] + margin[0] / 2, size_real[1] + margin[1] / 2};
951 r.
xmin = -margin[0] / 2;
952 r.
ymin = -margin[1] / 2;
953 r.
xmax = margin[0] / 2;
954 r.
ymax = margin[1] / 2;
957 r.
xmin = -size[0] + margin[0];
958 r.
ymin = -size[1] + margin[1];
959 r.
xmax = size[0] - margin[0];
960 r.
ymax = size[1] - margin[1];
975 r_xmin.
xmin = -size[0];
976 r_xmin.
ymin = -size[1];
977 r_xmin.
xmax = -size[0] + margin[0];
978 r_xmin.
ymax = size[1];
981 r_xmax.
xmin = size[0] - margin[0];
982 r_xmax.
ymin = -size[1];
983 r_xmax.
xmax = size[0];
984 r_xmax.
ymax = size[1];
987 r_ymin.
xmin = -size[0];
988 r_ymin.
ymin = -size[1];
989 r_ymin.
xmax = size[0];
990 r_ymin.
ymax = -size[1] + margin[1];
993 r_ymax.
xmin = -size[0];
994 r_ymax.
ymin = size[1] - margin[1];
995 r_ymax.
xmax = size[0];
996 r_ymax.
ymax = size[1];
1038 r_rotate.
xmin = r_rotate_pt[0] - margin[0] / 2.0f;
1039 r_rotate.
xmax = r_rotate_pt[0] + margin[0] / 2.0f;
1040 r_rotate.
ymin = r_rotate_pt[1] - margin[1] / 2.0f;
1041 r_rotate.
ymax = r_rotate_pt[1] + margin[1] / 2.0f;
1053struct RectTransformInteraction {
1054 float orig_mouse[2];
1055 float orig_matrix_offset[4][4];
1056 float orig_matrix_final_no_offset[4][4];
1058 bool use_temp_uniform;
1065 RectTransformInteraction *
data =
static_cast<RectTransformInteraction *
>(gz->
interaction_data);
1068 if (
data->use_temp_uniform) {
1072 return transform_flag;
1157 RectTransformInteraction *
data =
static_cast<RectTransformInteraction *
>(gz->
interaction_data);
1162 const bool use_temp_uniform = (
event->modifier &
KM_SHIFT) != 0;
1163 const bool changed =
data->use_temp_uniform != use_temp_uniform;
1164 data->use_temp_uniform = use_temp_uniform;
1165 if (use_temp_uniform) {
1177 float point_local[2];
1183 float matrix_back[4][4];
1199 if (gz_prop->
type !=
nullptr) {
1207 (point_local[0] -
data->orig_mouse[0]);
1209 (point_local[1] -
data->orig_mouse[1]);
1213#define MUL_V2_V3_M4_FINAL(test_co, mouse_co) \
1214 mul_v3_m4v3(test_co, data->orig_matrix_final_no_offset, float3{UNPACK2(mouse_co), 0.0})
1218 if (
data->dial ==
nullptr) {
1231 float matrix_space_inv[4][4];
1232 float matrix_rotate[4][4];
1240 mul_m4_m4m4(matrix_rotate, matrix_rotate, matrix_space_inv);
1249#undef MUL_V2_V3_M4_FINAL
1265 float curr_mouse[2];
1285 bool constrain_axis[2] = {
false};
1288 float size_new[2], size_orig[2];
1289 for (
int i = 0; i < 2; i++) {
1290 size_orig[i] =
len_v3(
data->orig_matrix_offset[i]);
1291 size_new[i] = size_orig[i];
1292 if (constrain_axis[i] ==
false) {
1294 const float delta_orig = curr_mouse[i] -
data->orig_matrix_offset[3][i] -
1295 pivot[i] * size_orig[i];
1296 const float delta_curr = point_local[i] -
data->orig_matrix_offset[3][i] -
1297 pivot[i] * size_orig[i];
1309 size_new[i] = delta_curr / (
signf(delta_orig) * 0.5f * dims[i] - pivot[i]);
1313 size_new[i] = size_orig[i] * (delta_curr / delta_orig);
1318 float scale[2] = {1.0f, 1.0f};
1319 for (
int i = 0; i < 2; i++) {
1320 if (size_orig[i] == 0) {
1321 size_orig[i] = 1.0f;
1324 scale[i] = size_new[i] / size_orig[i];
1328 if (constrain_axis[0] ==
false && constrain_axis[1] ==
false) {
1339 else if (constrain_axis[0] ==
false) {
1342 else if (constrain_axis[1] ==
false) {
1351 float matrix_scale[4][4];
1361 if (gz_prop->
type !=
nullptr) {
1388 RectTransformInteraction *
data =
static_cast<RectTransformInteraction *
>(gz->
interaction_data);
1392 data->dial =
nullptr;
1405 if (gz_prop->
type !=
nullptr) {
1419 gzt->
idname =
"GIZMO_GT_cage_2d";
1439 {0,
nullptr, 0,
nullptr,
nullptr},
1446 {0,
nullptr, 0,
nullptr,
nullptr},
1451 {0,
nullptr, 0,
nullptr,
nullptr},
1453 static const float unit_v2[2] = {1.0f, 1.0f};
1454 static const float zero_v2[2] = {0.0f, 0.0f};
1462 rna_enum_draw_style,
1468 rna_enum_draw_options,
Read Blender memory allocation and freeing.
#define ARRAY_SET_ITEMS(...)
SIMD_FORCE_INLINE btScalar angle(const btVector3 &v) const
Return the angle between this and another vector.
#define GIZMO_MARGIN_OFFSET_SCALE
#define MUL_V2_V3_M4_FINAL(test_co, mouse_co)
float3x3 scale(float3x3 mat, float2 scale)
static void gizmo_calc_rect_view_margin(const wmGizmo *gz, float margin[2])
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
static void cage2d_draw_rect_rotate_handle(const rctf *r, const float margin[2], const float color[3], bool solid)
MINLINE bool is_zero_v2(const float v[2]) ATTR_WARN_UNUSED_RESULT
void mat4_to_loc_rot_size(float loc[3], float rot[3][3], float size[3], const float wmat[4][4])
int RNA_enum_get(PointerRNA *ptr, const char *name)
void immAttr3f(uint attr_id, float x, float y, float z)
bool BLI_rctf_isect_pt_v(const struct rctf *rect, const float xy[2])
MINLINE void copy_v3_v3(float r[3], const float a[3])
bool GPU_select_load_id(unsigned int id)
void imm_draw_circle_wire_aspect_3d(uint pos, float x, float y, float radius_x, float radius_y, int nsegments)
void WM_gizmotype_append(void(*gtfunc)(wmGizmoType *))
void WM_gizmo_target_property_float_get_array(const wmGizmo *gz, wmGizmoProperty *gz_prop, float *value)
static void cage2d_draw_box_interaction(const float color[4], const int highlighted, const float size[2], const float margin[2], const float line_width, const bool is_solid, const int draw_options)
static void gizmo_constrain_from_scale_part(int part, bool r_constrain_axis[2])
static int gizmo_cage2d_get_cursor(wmGizmo *gz)
MINLINE void copy_v2_v2(float r[2], const float a[2])
GPUVertFormat * immVertexFormat()
void WM_gizmo_target_property_anim_autokey(bContext *C, const wmGizmo *, wmGizmoProperty *gz_prop)
void ED_gizmotypes_cage_2d()
bool invert_m4_m4(float inverse[4][4], const float mat[4][4])
void immBegin(GPUPrimType, uint vertex_len)
PropertyRNA * RNA_def_enum(StructOrFunctionRNA *cont_, const char *identifier, const EnumPropertyItem *items, const int default_value, const char *ui_name, const char *ui_description)
void WM_gizmo_calc_matrix_final_no_offset(const wmGizmo *gz, float r_mat[4][4])
void mul_v3_mat3_m4v3(float r[3], const float mat[4][4], const float vec[3])
static int gizmo_cage2d_test_select(bContext *C, wmGizmo *gz, const int mval[2])
void mul_m4_m4m4(float R[4][4], const float A[4][4], const float B[4][4])
void WM_gizmo_calc_matrix_final(const wmGizmo *gz, float r_mat[4][4])
void mul_m3_v2(const float m[3][3], float r[2])
static void cage2d_draw_circle_wire(const float color[3], const float size[2], const float margin[2], const int transform_flag, const int draw_options, const float line_width)
void WM_gizmotype_target_property_def(wmGizmoType *gzt, const char *idname, int data_type, int array_length)
void BLI_rctf_sanitize(struct rctf *rect)
@ ED_GIZMO_CAGE_XFORM_FLAG_SCALE
@ ED_GIZMO_CAGE_XFORM_FLAG_TRANSLATE
@ ED_GIZMO_CAGE_XFORM_FLAG_SCALE_SIGNED
@ ED_GIZMO_CAGE_XFORM_FLAG_ROTATE
@ ED_GIZMO_CAGE_XFORM_FLAG_SCALE_UNIFORM
void ED_region_tag_redraw_editor_overlays(ARegion *region)
static void imm_draw_point_aspect_2d(uint pos, float x, float y, float rad_x, float rad_y, bool solid)
void GPU_matrix_mul(const float m[4][4])
MINLINE void mul_v3_fl(float r[3], float f)
MINLINE void mul_v2_v2(float r[2], const float a[2])
static void gizmo_cage2d_setup(wmGizmo *gz)
PropertyRNA * RNA_def_float_vector(StructOrFunctionRNA *cont_, const char *identifier, const int len, const float *default_value, const float hardmin, const float hardmax, const char *ui_name, const char *ui_description, const float softmin, const float softmax)
@ ED_GIZMO_CAGE2D_STYLE_CIRCLE
@ ED_GIZMO_CAGE2D_STYLE_BOX_TRANSFORM
@ ED_GIZMO_CAGE2D_STYLE_BOX
static wmOperatorStatus gizmo_cage2d_invoke(bContext *C, wmGizmo *gz, const wmEvent *event)
static void cage2d_draw_rect_corner_handles(const rctf *r, const float margin[2], const float color[3], bool solid)
void immAttr3fv(uint attr_id, const float data[3])
void immBindBuiltinProgram(GPUBuiltinShader shader_id)
bool BLI_rctf_is_valid(const struct rctf *rect)
void WM_gizmo_target_property_float_set_array(bContext *C, const wmGizmo *gz, wmGizmoProperty *gz_prop, const float *value)
static void gizmo_cage2d_exit(bContext *C, wmGizmo *gz, const bool cancel)
VecBase< int32_t, 2 > int2
VecBase< float, 2 > float2
void immUniform1f(const char *name, float x)
static void gizmo_calc_rect_view_scale(const wmGizmo *gz, float scale[2])
void * MEM_new_zeroed(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
void immVertex2f(uint attr_id, float x, float y)
MINLINE void add_v2_v2(float r[2], const float a[2])
eWM_GizmoFlagTweak
Gizmo tweak flag. Bit-flag passed to gizmo while tweaking.
void GPU_viewport_size_get_f(float coords[4])
MINLINE int signum_i(float a)
BMesh const char void * data
static void GIZMO_GT_cage_2d(wmGizmoType *gzt)
MINLINE float signf(float f)
@ GPU_SHADER_3D_POLYLINE_UNIFORM_COLOR
@ GPU_SHADER_3D_POLYLINE_FLAT_COLOR
@ GPU_SHADER_3D_UNIFORM_COLOR
@ GPU_SHADER_3D_POINT_UNIFORM_COLOR
@ GPU_SHADER_3D_FLAT_COLOR
@ GPU_SHADER_3D_POINT_UNIFORM_SIZE_UNIFORM_COLOR_AA
@ GPU_SHADER_3D_POINT_FLAT_COLOR
static void cage2d_draw_rect_wire(const rctf *r, const float margin[2], const float color[3], const int transform_flag, const int draw_options, const float line_width)
wmGizmoProperty * WM_gizmo_target_property_find(wmGizmo *gz, const char *idname)
static bool is_corner_highlighted(const int highlighted)
void immUniformColor4f(float r, float g, float b, float a)
constexpr size_t ARRAY_SIZE(const T(&arg)[N]) noexcept
bool WM_gizmo_target_property_is_valid(const wmGizmoProperty *gz_prop)
void unit_m4(float m[4][4])
static void gizmo_cage2d_draw_intern(wmGizmo *gz, const bool select, const bool highlight, const int select_id)
void transform_pivot_set_m4(float mat[4][4], const float pivot[3])
MINLINE float len_v3(const float a[3]) ATTR_WARN_UNUSED_RESULT
void gizmo_color_get(const wmGizmo *gz, bool highlight, float r_color[4])
MINLINE void zero_v3(float r[3])
uint GPU_vertformat_attr_add(GPUVertFormat *format, StringRef name, gpu::VertAttrType type)
bool invert_m3(float mat[3][3])
void imm_draw_circle_wire_aspect_2d(uint shdr_pos, float x, float y, float radius_x, float radius_y, int nsegments)
void rotate_m4(float mat[4][4], char axis, float angle)
@ WM_GIZMO_STATE_HIGHLIGHT
void imm_draw_circle_fill_aspect_2d(uint shdr_pos, float x, float y, float radius_x, float radius_y, int nsegments)
void BLI_dial_free(Dial *dial)
static void gizmo_cage2d_draw_select(const bContext *, wmGizmo *gz, int select_id)
bool gizmo_window_project_2d(bContext *C, const wmGizmo *gz, const float mval[2], int axis, bool use_offset, float r_co[2])
void mul_m4_m4_post(float R[4][4], const float B[4][4])
BLI_INLINE float BLI_rctf_cent_y(const struct rctf *rct)
Dial * BLI_dial_init(const float start_position[2], float threshold)
PropertyRNA * RNA_def_enum_flag(StructOrFunctionRNA *cont_, const char *identifier, const EnumPropertyItem *items, const int default_value, const char *ui_name, const char *ui_description)
static void cage2d_draw_box_corners(const rctf *r, const float margin[2], const float color[3], const float line_width)
static int gizmo_cage2d_transform_flag_get(const wmGizmo *gz)
void immUniform2fv(const char *name, const float data[2])
@ ED_GIZMO_CAGE_DRAW_FLAG_XFORM_CENTER_HANDLE
@ ED_GIZMO_CAGE_DRAW_FLAG_CORNER_HANDLES
static void cage2d_draw_rect_edge_handles(const rctf *r, const int highlighted, const float size[2], const float margin[2], const float color[3], bool solid)
MINLINE void sub_v2_v2(float r[2], const float a[2])
void immUniformColor3fv(const float rgb[3])
void immVertex3f(uint attr_id, float x, float y, float z)
float BLI_dial_angle(Dial *dial, const float current_position[2])
void GPU_blend(GPUBlend blend)
void copy_m4_m4(float m1[4][4], const float m2[4][4])
MINLINE float len_v2(const float v[2]) ATTR_WARN_UNUSED_RESULT
VecBase< float, 3 > float3
void immVertex2fv(uint attr_id, const float data[2])
MINLINE float safe_divide(float a, float b)
void immRectf(uint pos, float x1, float y1, float x2, float y2)
MINLINE void zero_v2(float r[2])
ARegion * CTX_wm_region(const bContext *C)
BLI_INLINE float BLI_rctf_cent_x(const struct rctf *rct)
static wmOperatorStatus gizmo_cage2d_modal(bContext *C, wmGizmo *gz, const wmEvent *event, eWM_GizmoFlagTweak)
int WM_gizmo_target_property_array_length(const wmGizmo *, wmGizmoProperty *gz_prop)
static void gizmo_cage2d_property_update(wmGizmo *gz, wmGizmoProperty *gz_prop)
void RNA_float_get_array(PointerRNA *ptr, const char *name, float *values)
static void gizmo_cage2d_draw(const bContext *, wmGizmo *gz)
@ ED_GIZMO_CAGE2D_PART_SCALE_MIN_X
@ ED_GIZMO_CAGE2D_PART_SCALE_MAX_X
@ ED_GIZMO_CAGE2D_PART_ROTATE
@ ED_GIZMO_CAGE2D_PART_SCALE_MIN_X_MAX_Y
@ ED_GIZMO_CAGE2D_PART_SCALE_MIN_X_MIN_Y
@ ED_GIZMO_CAGE2D_PART_SCALE_MAX_X_MAX_Y
@ ED_GIZMO_CAGE2D_PART_TRANSLATE
@ ED_GIZMO_CAGE2D_PART_SCALE_MAX_X_MIN_Y
@ ED_GIZMO_CAGE2D_PART_SCALE_MAX_Y
@ ED_GIZMO_CAGE2D_PART_SCALE
@ ED_GIZMO_CAGE2D_PART_SCALE_MIN_Y
static void gizmo_pivot_from_scale_part(int part, float r_pt[2])
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
eWM_GizmoFlagGroupTypeFlag flag
const wmGizmoPropertyType * type
wmGizmoFnDrawSelect draw_select
wmGizmoFnCursorGet cursor_get
wmGizmoFnPropertyUpdate property_update
wmGizmoFnTestSelect test_select
float matrix_offset[4][4]
wmGizmoGroup * parent_gzgroup