Blender  V2.93
uvedit_draw.c
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
17  * All rights reserved.
18  */
19 
24 #include "BLI_math.h"
25 #include "BLI_utildefines.h"
26 
27 #include "DNA_scene_types.h"
28 #include "DNA_screen_types.h"
29 #include "DNA_userdef_types.h"
30 
31 #include "GPU_immediate.h"
32 #include "GPU_matrix.h"
33 
34 #include "UI_interface.h"
35 #include "UI_view2d.h"
36 
37 #include "ED_uvedit.h"
38 
39 /* ------------------------- */
40 
41 void ED_image_draw_cursor(ARegion *region, const float cursor[2])
42 {
43  float zoom[2], x_fac, y_fac;
44 
45  UI_view2d_scale_get_inverse(&region->v2d, &zoom[0], &zoom[1]);
46 
47  mul_v2_fl(zoom, 256.0f * UI_DPI_FAC);
48  x_fac = zoom[0];
49  y_fac = zoom[1];
50 
51  GPU_line_width(1.0f);
52 
54 
55  const uint shdr_pos = GPU_vertformat_attr_add(
57 
59 
60  float viewport_size[4];
61  GPU_viewport_size_get_f(viewport_size);
62  immUniform2f("viewport_size", viewport_size[2] / UI_DPI_FAC, viewport_size[3] / UI_DPI_FAC);
63 
64  immUniform1i("colors_len", 2); /* "advanced" mode */
66  "colors", (float *)(float[][4]){{1.0f, 0.0f, 0.0f, 1.0f}, {1.0f, 1.0f, 1.0f, 1.0f}}, 2);
67  immUniform1f("dash_width", 8.0f);
68  immUniform1f("dash_factor", 0.5f);
69 
71 
72  immVertex2f(shdr_pos, -0.05f * x_fac, 0.0f);
73  immVertex2f(shdr_pos, 0.0f, 0.05f * y_fac);
74 
75  immVertex2f(shdr_pos, 0.0f, 0.05f * y_fac);
76  immVertex2f(shdr_pos, 0.05f * x_fac, 0.0f);
77 
78  immVertex2f(shdr_pos, 0.05f * x_fac, 0.0f);
79  immVertex2f(shdr_pos, 0.0f, -0.05f * y_fac);
80 
81  immVertex2f(shdr_pos, 0.0f, -0.05f * y_fac);
82  immVertex2f(shdr_pos, -0.05f * x_fac, 0.0f);
83 
84  immEnd();
85 
87  "colors", (float *)(float[][4]){{1.0f, 1.0f, 1.0f, 1.0f}, {0.0f, 0.0f, 0.0f, 1.0f}}, 2);
88  immUniform1f("dash_width", 2.0f);
89  immUniform1f("dash_factor", 0.5f);
90 
92 
93  immVertex2f(shdr_pos, -0.020f * x_fac, 0.0f);
94  immVertex2f(shdr_pos, -0.1f * x_fac, 0.0f);
95 
96  immVertex2f(shdr_pos, 0.1f * x_fac, 0.0f);
97  immVertex2f(shdr_pos, 0.020f * x_fac, 0.0f);
98 
99  immVertex2f(shdr_pos, 0.0f, -0.020f * y_fac);
100  immVertex2f(shdr_pos, 0.0f, -0.1f * y_fac);
101 
102  immVertex2f(shdr_pos, 0.0f, 0.1f * y_fac);
103  immVertex2f(shdr_pos, 0.0f, 0.020f * y_fac);
104 
105  immEnd();
106 
108 
109  GPU_matrix_translate_2f(-cursor[0], -cursor[1]);
110 }
MINLINE void mul_v2_fl(float r[2], float f)
unsigned int uint
Definition: BLI_sys_types.h:83
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)
void immUniformArray4fv(const char *bare_name, const float *data, int count)
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:199
void GPU_matrix_translate_2f(float x, float y)
Definition: gpu_matrix.cc:190
@ GPU_PRIM_LINES
Definition: GPU_primitive.h:36
@ GPU_SHADER_2D_LINE_DASHED_UNIFORM_COLOR
Definition: GPU_shader.h:365
void GPU_line_width(float width)
Definition: gpu_state.cc:173
void GPU_viewport_size_get_f(float coords[4])
Definition: gpu_state.cc:279
@ 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:309
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:41