diff options
author | Campbell Barton <ideasman42@gmail.com> | 2021-10-07 04:32:04 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2021-10-07 19:27:55 +0300 |
commit | d04d27b406b856396102452cab0eedf315e94a54 (patch) | |
tree | 4a881ab29123828287f83272a0ca1d03b62b4472 /source/blender/draw | |
parent | 919e513fa8f9fb4f1304ea4b752869b6d63b1608 (diff) |
Sequencer: 2D cursor for the preview & transform
- Use 2D cursor in the preview space using shortcuts
matching the UV editor and 3D view.
- Add Cursor tool, cursor transform.
- Support for cursor and bound-box pivot.
- Add pivot pie menu.
Diffstat (limited to 'source/blender/draw')
-rw-r--r-- | source/blender/draw/DRW_engine.h | 3 | ||||
-rw-r--r-- | source/blender/draw/intern/draw_view.c | 70 | ||||
-rw-r--r-- | source/blender/draw/intern/draw_view.h | 2 |
3 files changed, 48 insertions, 27 deletions
diff --git a/source/blender/draw/DRW_engine.h b/source/blender/draw/DRW_engine.h index 927a29ed6b6..af6c8ea62b2 100644 --- a/source/blender/draw/DRW_engine.h +++ b/source/blender/draw/DRW_engine.h @@ -179,6 +179,9 @@ void DRW_viewport_data_free(struct DRWData *drw_data); bool DRW_opengl_context_release(void); void DRW_opengl_context_activate(bool drw_state); +/* We may want to move this into a more general location. */ +void DRW_draw_cursor_2d_ex(const struct ARegion *region, const float cursor[2]); + #ifdef __cplusplus } #endif diff --git a/source/blender/draw/intern/draw_view.c b/source/blender/draw/intern/draw_view.c index 90bb3762473..bbd345271b1 100644 --- a/source/blender/draw/intern/draw_view.c +++ b/source/blender/draw/intern/draw_view.c @@ -28,6 +28,7 @@ #include "DNA_view3d_types.h" #include "ED_screen.h" +#include "ED_util.h" #include "ED_view3d.h" #include "GPU_immediate.h" @@ -226,6 +227,46 @@ static bool is_cursor_visible_2d(const DRWContextState *draw_ctx) return (sima->overlay.flag & SI_OVERLAY_SHOW_OVERLAYS) != 0; } +/* -------------------------------------------------------------------- */ +/** \name Generic Cursor + * \{ */ + +/** + * \note This doesn't require the draw context to be in use. + */ +void DRW_draw_cursor_2d_ex(const ARegion *region, const float cursor[2]) +{ + int co[2]; + UI_view2d_view_to_region(®ion->v2d, cursor[0], cursor[1], &co[0], &co[1]); + + /* Draw nice Anti Aliased cursor. */ + GPU_line_width(1.0f); + GPU_blend(GPU_BLEND_ALPHA); + 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(GPU_BLEND_NONE); + GPU_line_smooth(false); + GPU_matrix_pop(); + GPU_matrix_projection_set(original_proj); +} + +/** \} */ + void DRW_draw_cursor_2d(void) { const DRWContextState *draw_ctx = DRW_context_state_get(); @@ -236,33 +277,8 @@ void DRW_draw_cursor_2d(void) 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(GPU_BLEND_ALPHA); - 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(GPU_BLEND_NONE); - GPU_line_smooth(false); - GPU_matrix_pop(); - GPU_matrix_projection_set(original_proj); + const SpaceImage *sima = (SpaceImage *)draw_ctx->space_data; + DRW_draw_cursor_2d_ex(region, sima->cursor); } } /** \} */ diff --git a/source/blender/draw/intern/draw_view.h b/source/blender/draw/intern/draw_view.h index 24fabaae05e..2646918cd3e 100644 --- a/source/blender/draw/intern/draw_view.h +++ b/source/blender/draw/intern/draw_view.h @@ -22,6 +22,8 @@ #pragma once +struct ARegion; + void DRW_draw_region_info(void); void DRW_clear_background(void); void DRW_draw_cursor(void); |