Blender  V3.3
uvedit_draw.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2001-2002 NaN Holding BV. All rights reserved. */
3 
8 #include "BLI_math.h"
9 #include "BLI_utildefines.h"
10 
11 #include "DNA_scene_types.h"
12 #include "DNA_screen_types.h"
13 #include "DNA_userdef_types.h"
14 
15 #include "GPU_immediate.h"
16 #include "GPU_matrix.h"
17 
18 #include "UI_interface.h"
19 #include "UI_view2d.h"
20 
21 #include "ED_uvedit.h"
22 
23 /* ------------------------- */
24 
25 void ED_image_draw_cursor(ARegion *region, const float cursor[2])
26 {
27  float zoom[2], x_fac, y_fac;
28 
29  UI_view2d_scale_get_inverse(&region->v2d, &zoom[0], &zoom[1]);
30 
31  mul_v2_fl(zoom, 256.0f * UI_DPI_FAC);
32  x_fac = zoom[0];
33  y_fac = zoom[1];
34 
35  GPU_line_width(1.0f);
36 
38 
39  const uint shdr_pos = GPU_vertformat_attr_add(
41 
43 
44  float viewport_size[4];
45  GPU_viewport_size_get_f(viewport_size);
46  immUniform2f("viewport_size", viewport_size[2] / UI_DPI_FAC, viewport_size[3] / UI_DPI_FAC);
47 
48  immUniform1i("colors_len", 2); /* "advanced" mode */
49  immUniform4f("color", 1.0f, 0.0f, 0.0f, 1.0f);
50  immUniform4f("color2", 1.0f, 1.0f, 1.0f, 1.0f);
51  immUniform1f("dash_width", 8.0f);
52  immUniform1f("dash_factor", 0.5f);
53 
55 
56  immVertex2f(shdr_pos, -0.05f * x_fac, 0.0f);
57  immVertex2f(shdr_pos, 0.0f, 0.05f * y_fac);
58 
59  immVertex2f(shdr_pos, 0.0f, 0.05f * y_fac);
60  immVertex2f(shdr_pos, 0.05f * x_fac, 0.0f);
61 
62  immVertex2f(shdr_pos, 0.05f * x_fac, 0.0f);
63  immVertex2f(shdr_pos, 0.0f, -0.05f * y_fac);
64 
65  immVertex2f(shdr_pos, 0.0f, -0.05f * y_fac);
66  immVertex2f(shdr_pos, -0.05f * x_fac, 0.0f);
67 
68  immEnd();
69 
70  immUniform4f("color", 1.0f, 1.0f, 1.0f, 1.0f);
71  immUniform4f("color2", 0.0f, 0.0f, 0.0f, 1.0f);
72  immUniform1f("dash_width", 2.0f);
73  immUniform1f("dash_factor", 0.5f);
74 
76 
77  immVertex2f(shdr_pos, -0.020f * x_fac, 0.0f);
78  immVertex2f(shdr_pos, -0.1f * x_fac, 0.0f);
79 
80  immVertex2f(shdr_pos, 0.1f * x_fac, 0.0f);
81  immVertex2f(shdr_pos, 0.020f * x_fac, 0.0f);
82 
83  immVertex2f(shdr_pos, 0.0f, -0.020f * y_fac);
84  immVertex2f(shdr_pos, 0.0f, -0.1f * y_fac);
85 
86  immVertex2f(shdr_pos, 0.0f, 0.1f * y_fac);
87  immVertex2f(shdr_pos, 0.0f, 0.020f * y_fac);
88 
89  immEnd();
90 
92 
93  GPU_matrix_translate_2f(-cursor[0], -cursor[1]);
94 }
MINLINE void mul_v2_fl(float r[2], float f)
unsigned int uint
Definition: BLI_sys_types.h:67
void immUniform4f(const char *name, float x, float y, float z, float w)
void immUniform2f(const char *name, float x, float y)
void immUnbindProgram(void)
void immVertex2f(uint attr_id, float x, float y)
void immBindBuiltinProgram(eGPUBuiltinShader shader_id)
void immUniform1i(const char *name, int x)
void immUniform1f(const char *name, float x)
GPUVertFormat * immVertexFormat(void)
void immBegin(GPUPrimType, uint vertex_len)
void immEnd(void)
void GPU_matrix_translate_2fv(const float vec[2])
Definition: gpu_matrix.cc:183
void GPU_matrix_translate_2f(float x, float y)
Definition: gpu_matrix.cc:174
@ GPU_PRIM_LINES
Definition: GPU_primitive.h:20
@ GPU_SHADER_2D_LINE_DASHED_UNIFORM_COLOR
Definition: GPU_shader.h:349
void GPU_line_width(float width)
Definition: gpu_state.cc:158
void GPU_viewport_size_get_f(float coords[4])
Definition: gpu_state.cc:259
@ GPU_FETCH_FLOAT
uint GPU_vertformat_attr_add(GPUVertFormat *, const char *name, GPUVertCompType, uint comp_len, GPUVertFetchMode)
@ GPU_COMP_F32
#define UI_DPI_FAC
Definition: UI_interface.h:305
void UI_view2d_scale_get_inverse(const struct View2D *v2d, float *r_x, float *r_y)
void ED_image_draw_cursor(ARegion *region, const float cursor[2])
Definition: uvedit_draw.c:25