diff options
Diffstat (limited to 'source/blender/draw/intern/draw_view.c')
-rw-r--r-- | source/blender/draw/intern/draw_view.c | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/source/blender/draw/intern/draw_view.c b/source/blender/draw/intern/draw_view.c index d01e1a51080..3033cf70b29 100644 --- a/source/blender/draw/intern/draw_view.c +++ b/source/blender/draw/intern/draw_view.c @@ -35,6 +35,7 @@ #include "GPU_shader.h" #include "UI_resources.h" +#include "UI_view2d.h" #include "WM_types.h" @@ -196,6 +197,65 @@ void DRW_draw_cursor(void) } } +/* -------------------------------------------------------------------- */ + +/** \name 2D Cursor + * \{ */ + +static bool is_cursor_visible_2d(const DRWContextState *draw_ctx) +{ + SpaceInfo *space_data = (SpaceInfo *)draw_ctx->space_data; + if (space_data == NULL) { + return false; + } + if (space_data->spacetype == SPACE_IMAGE) { + SpaceImage *sima = (SpaceImage *)draw_ctx->space_data; + return sima->mode == SI_MODE_UV; + } + return false; +} + +void DRW_draw_cursor_2d(void) +{ + const DRWContextState *draw_ctx = DRW_context_state_get(); + ARegion *region = draw_ctx->region; + + GPU_color_mask(true, true, true, true); + GPU_depth_mask(false); + GPU_depth_test(GPU_DEPTH_NONE); + + if (is_cursor_visible_2d(draw_ctx)) { + SpaceImage *sima = (SpaceImage *)draw_ctx->space_data; + int co[2]; + UI_view2d_view_to_region(®ion->v2d, sima->cursor[0], sima->cursor[1], &co[0], &co[1]); + + /* Draw nice Anti Aliased cursor. */ + GPU_line_width(1.0f); + GPU_blend(true); + GPU_line_smooth(true); + + /* Draw lines */ + float original_proj[4][4]; + GPU_matrix_projection_get(original_proj); + GPU_matrix_push(); + ED_region_pixelspace(region); + GPU_matrix_translate_2f(co[0] + 0.5f, co[1] + 0.5f); + GPU_matrix_scale_2f(U.widget_unit, U.widget_unit); + + GPUBatch *cursor_batch = DRW_cache_cursor_get(true); + GPUShader *shader = GPU_shader_get_builtin_shader(GPU_SHADER_2D_FLAT_COLOR); + GPU_batch_set_shader(cursor_batch, shader); + + GPU_batch_draw(cursor_batch); + + GPU_blend(false); + GPU_line_smooth(false); + GPU_matrix_pop(); + GPU_matrix_projection_set(original_proj); + } +} +/* \} */ + /* **************************** 3D Gizmo ******************************** */ void DRW_draw_gizmo_3d(void) |