Blender V4.3
transform_draw_cursors.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 "GPU_immediate.hh"
10#include "GPU_matrix.hh"
11#include "GPU_state.hh"
12
13#include "BLI_math_rotation.h"
14
15#include "BKE_context.hh"
16
17#include "DNA_screen_types.h"
18#include "DNA_userdef_types.h"
19
20#include "UI_resources.hh"
21
22#include "transform.hh"
23#include "transform_draw_cursors.hh" /* Own include. */
24
25using namespace blender;
26
33
34#define ARROW_WIDTH (2.0f * U.pixelsize)
35#define DASH_WIDTH (1.0f)
36#define DASH_LENGTH (8.0f * DASH_WIDTH * U.pixelsize)
37
38static void drawArrow(const uint pos_id, const enum eArrowDirection dir)
39{
40 int offset = 5.0f * UI_SCALE_FAC;
41 int length = (6.0f * UI_SCALE_FAC) + (4.0f * U.pixelsize);
42 int size = (3.0f * UI_SCALE_FAC) + (2.0f * U.pixelsize);
43
44 /* To line up the arrow point nicely, one end has to be extended by half its width. But
45 * being on a 45 degree angle, Pythagoras says a movement of `sqrt(2) / 2 * (line width / 2)`. */
46 float adjust = (M_SQRT2 * ARROW_WIDTH / 4.0f);
47
48 if (ELEM(dir, LEFT, DOWN)) {
49 offset = -offset;
50 length = -length;
51 size = -size;
52 adjust = -adjust;
53 }
54
56
57 if (ELEM(dir, LEFT, RIGHT)) {
58 immVertex2f(pos_id, offset, 0);
59 immVertex2f(pos_id, offset + length, 0);
60 immVertex2f(pos_id, offset + length + adjust, adjust);
61 immVertex2f(pos_id, offset + length - size, -size);
62 immVertex2f(pos_id, offset + length, 0);
63 immVertex2f(pos_id, offset + length - size, size);
64 }
65 else {
66 immVertex2f(pos_id, 0, offset);
67 immVertex2f(pos_id, 0, offset + length);
68 immVertex2f(pos_id, adjust, offset + length + adjust);
69 immVertex2f(pos_id, -size, offset + length - size);
70 immVertex2f(pos_id, 0, offset + length);
71 immVertex2f(pos_id, size, offset + length - size);
72 }
73
74 immEnd();
75}
76
78{
79 ARegion *region = CTX_wm_region(C);
80 return (region && ELEM(region->regiontype, RGN_TYPE_WINDOW, RGN_TYPE_PREVIEW)) ? true : false;
81}
82
83void transform_draw_cursor_draw(bContext * /*C*/, int x, int y, void *customdata)
84{
85 TransInfo *t = (TransInfo *)customdata;
86
87 if (t->helpline == HLP_NONE) {
88 return;
89 }
90
91 /* Offset the values for the area region. */
92 const float2 offset = {
95 };
96
97 float2 cent;
98 float2 tmval = t->mval;
99
101
102 cent += offset;
103 tmval += offset;
104
105 float viewport_size[4];
106 GPU_viewport_size_get_f(viewport_size);
107
108 GPU_line_smooth(true);
110 const uint pos_id = GPU_vertformat_attr_add(
112
113 /* Dashed lines first. */
114 if (ELEM(t->helpline, HLP_SPRING, HLP_ANGLE)) {
117 immUniform2f("viewport_size", viewport_size[2], viewport_size[3]);
118 immUniform1i("colors_len", 0); /* "simple" mode. */
120 immUniform1f("dash_width", DASH_LENGTH);
121 immUniform1f("udash_factor", 0.5f);
123 immVertex2fv(pos_id, cent);
124 immVertex2f(pos_id, tmval[0], tmval[1]);
125 immEnd();
127 }
128
129 /* And now, solid lines. */
130
133 immUniform2fv("viewportSize", &viewport_size[2]);
134 immUniform1f("lineWidth", ARROW_WIDTH);
135
137 GPU_matrix_translate_3f(float(x), float(y), 0.0f);
138
139 switch (t->helpline) {
140 case HLP_SPRING:
141 GPU_matrix_rotate_axis(-RAD2DEGF(atan2f(cent[0] - tmval[0], cent[1] - tmval[1])), 'Z');
142 drawArrow(pos_id, UP);
143 drawArrow(pos_id, DOWN);
144 break;
145 case HLP_HARROW:
146 drawArrow(pos_id, RIGHT);
147 drawArrow(pos_id, LEFT);
148 break;
149 case HLP_VARROW:
150 drawArrow(pos_id, UP);
151 drawArrow(pos_id, DOWN);
152 break;
153 case HLP_CARROW: {
154 /* Draw arrow based on direction defined by custom-points. */
155 const int *data = static_cast<const int *>(t->mouse.data);
156 const float angle = -atan2f(data[2] - data[0], data[3] - data[1]);
157 GPU_matrix_rotate_axis(RAD2DEGF(angle), 'Z');
158 drawArrow(pos_id, UP);
159 drawArrow(pos_id, DOWN);
160 break;
161 }
162 case HLP_ANGLE: {
164 float angle = atan2f(tmval[1] - cent[1], tmval[0] - cent[0]);
165 GPU_matrix_translate_3f(cosf(angle), sinf(angle), 0);
166 GPU_matrix_rotate_axis(RAD2DEGF(angle), 'Z');
167 drawArrow(pos_id, DOWN);
169 GPU_matrix_translate_3f(cosf(angle), sinf(angle), 0);
170 GPU_matrix_rotate_axis(RAD2DEGF(angle), 'Z');
171 drawArrow(pos_id, UP);
172 break;
173 }
174 case HLP_TRACKBALL: {
175 uchar col[3], col2[3];
177 UI_make_axis_color(col, 'X', col2);
179 drawArrow(pos_id, RIGHT);
180 drawArrow(pos_id, LEFT);
181 UI_make_axis_color(col, 'Y', col2);
183 drawArrow(pos_id, UP);
184 drawArrow(pos_id, DOWN);
185 break;
186 }
187 case HLP_NONE:
188 break;
189 }
190
193 GPU_line_smooth(false);
195}
ARegion * CTX_wm_region(const bContext *C)
#define M_SQRT2
#define RAD2DEGF(_rad)
unsigned char uchar
unsigned int uint
#define ELEM(...)
@ RGN_TYPE_WINDOW
@ RGN_TYPE_PREVIEW
#define UI_SCALE_FAC
@ V3D_PROJ_TEST_CLIP_ZERO
Definition ED_view3d.hh:271
void immEnd()
void immUniform2fv(const char *name, const float data[2])
void immUnbindProgram()
void immUniform2f(const char *name, float x, float y)
void immVertex2f(uint attr_id, float x, float y)
void immBindBuiltinProgram(eGPUBuiltinShader shader_id)
void immVertex2fv(uint attr_id, const float data[2])
void immUniformColor3ubv(const unsigned char rgb[3])
void immUniform1i(const char *name, int x)
void immUniformThemeColor3(int color_id)
void immUniform1f(const char *name, float x)
GPUVertFormat * immVertexFormat()
void immBegin(GPUPrimType, uint vertex_len)
void GPU_matrix_rotate_axis(float deg, char axis)
void GPU_matrix_push()
void GPU_matrix_translate_3f(float x, float y, float z)
void GPU_matrix_pop()
@ GPU_PRIM_LINES
@ GPU_SHADER_3D_LINE_DASHED_UNIFORM_COLOR
@ GPU_SHADER_3D_POLYLINE_UNIFORM_COLOR
@ GPU_BLEND_NONE
Definition GPU_state.hh:85
@ GPU_BLEND_ALPHA
Definition GPU_state.hh:87
void GPU_blend(eGPUBlend blend)
Definition gpu_state.cc:42
void GPU_line_width(float width)
Definition gpu_state.cc:161
void GPU_line_smooth(bool enable)
Definition gpu_state.cc:78
void GPU_viewport_size_get_f(float coords[4])
Definition gpu_state.cc:262
@ GPU_FETCH_FLOAT
uint GPU_vertformat_attr_add(GPUVertFormat *, const char *name, GPUVertCompType, uint comp_len, GPUVertFetchMode)
@ GPU_COMP_F32
@ TH_GRID
@ TH_VIEW_OVERLAY
void UI_GetThemeColor3ubv(int colorid, unsigned char col[3])
void UI_make_axis_color(const unsigned char col[3], char axis, unsigned char r_col[3])
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition btDbvt.cpp:52
unsigned int U
Definition btGjkEpa3.h:78
SIMD_FORCE_INLINE btScalar length() const
Return the length of the vector.
Definition btVector3.h:257
#define sinf(x)
#define cosf(x)
#define atan2f(x, y)
void projectFloatViewEx(TransInfo *t, const float vec[3], float adr[2], const eV3DProjTest flag)
draw_view in_light_buf[] float
uint col
void * data
Definition transform.hh:390
eTHelpline helpline
Definition transform.hh:531
ARegion * region
Definition transform.hh:652
MouseInput mouse
Definition transform.hh:543
float center_global[3]
Definition transform.hh:555
blender::float2 mval
Definition transform.hh:663
int ymin
int xmin
@ HLP_HARROW
Definition transform.hh:226
@ HLP_ANGLE
Definition transform.hh:225
@ HLP_SPRING
Definition transform.hh:224
@ HLP_CARROW
Definition transform.hh:228
@ HLP_TRACKBALL
Definition transform.hh:229
@ HLP_NONE
Definition transform.hh:223
@ HLP_VARROW
Definition transform.hh:227
bool transform_draw_cursor_poll(bContext *C)
static void drawArrow(const uint pos_id, const enum eArrowDirection dir)
#define DASH_WIDTH
#define ARROW_WIDTH
#define DASH_LENGTH
void transform_draw_cursor_draw(bContext *, int x, int y, void *customdata)