diff options
author | Campbell Barton <ideasman42@gmail.com> | 2019-05-31 14:45:28 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2019-05-31 14:51:02 +0300 |
commit | a9450dbf0d8bd3f4d03808220fbc4353ce563d3f (patch) | |
tree | 162394bf6fab05bca3e34e2b93e6cf03975f3d99 /source/blender/editors | |
parent | 56a533c0711a486375408afaa7ac51da1613ccee (diff) |
Gizmo: add 2D navigation for image/clip/sequencer views
Diffstat (limited to 'source/blender/editors')
-rw-r--r-- | source/blender/editors/include/UI_view2d.h | 7 | ||||
-rw-r--r-- | source/blender/editors/interface/CMakeLists.txt | 1 | ||||
-rw-r--r-- | source/blender/editors/interface/view2d_gizmo_navigate.c | 246 | ||||
-rw-r--r-- | source/blender/editors/screen/area.c | 2 | ||||
-rw-r--r-- | source/blender/editors/space_clip/space_clip.c | 18 | ||||
-rw-r--r-- | source/blender/editors/space_image/space_image.c | 10 | ||||
-rw-r--r-- | source/blender/editors/space_sequencer/space_sequencer.c | 18 |
7 files changed, 299 insertions, 3 deletions
diff --git a/source/blender/editors/include/UI_view2d.h b/source/blender/editors/include/UI_view2d.h index 42ac3bb30d8..4f880a8d46f 100644 --- a/source/blender/editors/include/UI_view2d.h +++ b/source/blender/editors/include/UI_view2d.h @@ -99,6 +99,7 @@ struct ScrArea; struct bContext; struct bScreen; struct rctf; +struct wmGizmoGroupType; struct wmKeyConfig; typedef struct View2DScrollers View2DScrollers; @@ -262,4 +263,10 @@ void UI_view2d_smooth_view(struct bContext *C, #define UI_MARKER_MARGIN_Y (42 * UI_DPI_FAC) #define UI_TIME_SCRUB_MARGIN_Y (23 * UI_DPI_FAC) +/* Gizmo Types */ + +/* view2d_gizmo_navigate.c */ +/* Caller passes in own idname. */ +void VIEW2D_GGT_navigate_impl(struct wmGizmoGroupType *gzgt, const char *idname); + #endif /* __UI_VIEW2D_H__ */ diff --git a/source/blender/editors/interface/CMakeLists.txt b/source/blender/editors/interface/CMakeLists.txt index 6ab1761e7f8..bc8d25e8d9e 100644 --- a/source/blender/editors/interface/CMakeLists.txt +++ b/source/blender/editors/interface/CMakeLists.txt @@ -73,6 +73,7 @@ set(SRC resources.c view2d.c view2d_draw.c + view2d_gizmo_navigate.c view2d_ops.c interface_eyedropper_intern.h diff --git a/source/blender/editors/interface/view2d_gizmo_navigate.c b/source/blender/editors/interface/view2d_gizmo_navigate.c new file mode 100644 index 00000000000..a32179834b1 --- /dev/null +++ b/source/blender/editors/interface/view2d_gizmo_navigate.c @@ -0,0 +1,246 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +/** \file + * \ingroup edinterface + */ + +#include "BLI_utildefines.h" + +#include "BKE_context.h" + +#include "ED_screen.h" +#include "ED_gizmo_library.h" + +#include "UI_interface.h" +#include "UI_resources.h" + +#include "MEM_guardedalloc.h" + +#include "RNA_access.h" + +#include "WM_api.h" +#include "WM_types.h" + +#include "UI_view2d.h" + +/* -------------------------------------------------------------------- */ +/** \name View2D Navigation Gizmo Group + * + * A simpler version of #VIEW3D_GGT_navigate + * + * Written to be used by different kinds of 2D view types. + * \{ */ + +/* Size of main icon. */ +#define GIZMO_SIZE 80 +/* Factor for size of smaller button. */ +#define GIZMO_MINI_FAC 0.35f +/* How much mini buttons offset from the primary. */ +#define GIZMO_MINI_OFFSET_FAC 0.38f + +enum { + GZ_INDEX_MOVE = 0, + GZ_INDEX_ZOOM = 1, + + GZ_INDEX_TOTAL = 2, +}; + +struct NavigateGizmoInfo { + const char *opname; + const char *gizmo; + uint icon; +}; + +static struct NavigateGizmoInfo g_navigate_params_for_space_image[GZ_INDEX_TOTAL] = { + { + .opname = "IMAGE_OT_view_pan", + .gizmo = "GIZMO_GT_button_2d", + ICON_VIEW_PAN, + }, + { + .opname = "IMAGE_OT_view_zoom", + .gizmo = "GIZMO_GT_button_2d", + ICON_VIEW_ZOOM, + }, +}; + +static struct NavigateGizmoInfo g_navigate_params_for_space_clip[GZ_INDEX_TOTAL] = { + { + .opname = "CLIP_OT_view_pan", + .gizmo = "GIZMO_GT_button_2d", + ICON_VIEW_PAN, + }, + { + .opname = "CLIP_OT_view_zoom", + .gizmo = "GIZMO_GT_button_2d", + ICON_VIEW_ZOOM, + }, +}; + +static struct NavigateGizmoInfo g_navigate_params_for_view2d[GZ_INDEX_TOTAL] = { + { + .opname = "VIEW2D_OT_pan", + .gizmo = "GIZMO_GT_button_2d", + ICON_VIEW_PAN, + }, + { + .opname = "VIEW2D_OT_zoom", + .gizmo = "GIZMO_GT_button_2d", + ICON_VIEW_ZOOM, + }, +}; + +static struct NavigateGizmoInfo *navigate_params_from_space_type(short space_type) +{ + switch (space_type) { + case SPACE_IMAGE: + return g_navigate_params_for_space_image; + case SPACE_CLIP: + return g_navigate_params_for_space_clip; + default: + /* Used for sequencer. */ + return g_navigate_params_for_view2d; + } +} + +struct NavigateWidgetGroup { + wmGizmo *gz_array[GZ_INDEX_TOTAL]; + /* Store the view state to check for changes. */ + struct { + rcti rect_visible; + } state; + int region_size[2]; +}; + +static void WIDGETGROUP_navigate_setup(const bContext *UNUSED(C), wmGizmoGroup *gzgroup) +{ + struct NavigateWidgetGroup *navgroup = MEM_callocN(sizeof(struct NavigateWidgetGroup), __func__); + + navgroup->region_size[0] = -1; + navgroup->region_size[1] = -1; + + const struct NavigateGizmoInfo *navigate_params = navigate_params_from_space_type( + gzgroup->type->gzmap_params.spaceid); + + for (int i = 0; i < GZ_INDEX_TOTAL; i++) { + const struct NavigateGizmoInfo *info = &navigate_params[i]; + navgroup->gz_array[i] = WM_gizmo_new(info->gizmo, gzgroup, NULL); + wmGizmo *gz = navgroup->gz_array[i]; + gz->flag |= WM_GIZMO_MOVE_CURSOR | WM_GIZMO_DRAW_MODAL; + + { + uchar icon_color[3]; + UI_GetThemeColor3ubv(TH_TEXT, icon_color); + int color_tint, color_tint_hi; + if (icon_color[0] > 128) { + color_tint = -40; + color_tint_hi = 60; + gz->color[3] = 0.5f; + gz->color_hi[3] = 0.5f; + } + else { + color_tint = 60; + color_tint_hi = 60; + gz->color[3] = 0.5f; + gz->color_hi[3] = 0.75f; + } + UI_GetThemeColorShade3fv(TH_HEADER, color_tint, gz->color); + UI_GetThemeColorShade3fv(TH_HEADER, color_tint_hi, gz->color_hi); + } + + /* may be overwritten later */ + gz->scale_basis = (GIZMO_SIZE * GIZMO_MINI_FAC) / 2; + if (info->icon != 0) { + PropertyRNA *prop = RNA_struct_find_property(gz->ptr, "icon"); + RNA_property_enum_set(gz->ptr, prop, info->icon); + RNA_enum_set( + gz->ptr, "draw_options", ED_GIZMO_BUTTON_SHOW_OUTLINE | ED_GIZMO_BUTTON_SHOW_BACKDROP); + } + + wmOperatorType *ot = WM_operatortype_find(info->opname, true); + WM_gizmo_operator_set(gz, 0, ot, NULL); + } + + /* Modal operators, don't use initial mouse location since we're clicking on a button. */ + { + int gz_ids[] = {GZ_INDEX_ZOOM}; + for (int i = 0; i < ARRAY_SIZE(gz_ids); i++) { + wmGizmo *gz = navgroup->gz_array[gz_ids[i]]; + wmGizmoOpElem *gzop = WM_gizmo_operator_get(gz, 0); + RNA_boolean_set(&gzop->ptr, "use_cursor_init", false); + } + } + + gzgroup->customdata = navgroup; +} + +static void WIDGETGROUP_navigate_draw_prepare(const bContext *C, wmGizmoGroup *gzgroup) +{ + struct NavigateWidgetGroup *navgroup = gzgroup->customdata; + ARegion *ar = CTX_wm_region(C); + + rcti rect_visible; + ED_region_visible_rect(ar, &rect_visible); + + if ((navgroup->state.rect_visible.xmax == rect_visible.xmax) && + (navgroup->state.rect_visible.ymax == rect_visible.ymax)) { + return; + } + + navgroup->state.rect_visible = rect_visible; + + const float icon_size = GIZMO_SIZE; + const float icon_offset_mini = icon_size * GIZMO_MINI_OFFSET_FAC * UI_DPI_FAC; + const float co[2] = { + rect_visible.xmax - (icon_offset_mini * 0.75f), + rect_visible.ymax - (icon_offset_mini * 0.75f), + }; + + wmGizmo *gz; + + for (uint i = 0; i < ARRAY_SIZE(navgroup->gz_array); i++) { + gz = navgroup->gz_array[i]; + WM_gizmo_set_flag(gz, WM_GIZMO_HIDDEN, true); + } + + int icon_mini_slot = 0; + + gz = navgroup->gz_array[GZ_INDEX_ZOOM]; + gz->matrix_basis[3][0] = co[0] - (icon_offset_mini * icon_mini_slot++); + gz->matrix_basis[3][1] = co[1]; + WM_gizmo_set_flag(gz, WM_GIZMO_HIDDEN, false); + + gz = navgroup->gz_array[GZ_INDEX_MOVE]; + gz->matrix_basis[3][0] = co[0] - (icon_offset_mini * icon_mini_slot++); + gz->matrix_basis[3][1] = co[1]; + WM_gizmo_set_flag(gz, WM_GIZMO_HIDDEN, false); +} + +/* Caller defines the name for gizmo group. */ +void VIEW2D_GGT_navigate_impl(wmGizmoGroupType *gzgt, const char *idname) +{ + gzgt->name = "View2D Navigate"; + gzgt->idname = idname; + + gzgt->flag |= (WM_GIZMOGROUPTYPE_PERSISTENT | WM_GIZMOGROUPTYPE_SCALE | + WM_GIZMOGROUPTYPE_DRAW_MODAL_ALL); + + gzgt->setup = WIDGETGROUP_navigate_setup; + gzgt->draw_prepare = WIDGETGROUP_navigate_draw_prepare; +} + +/** \} */ diff --git a/source/blender/editors/screen/area.c b/source/blender/editors/screen/area.c index 83058f2bc95..c74841b3ede 100644 --- a/source/blender/editors/screen/area.c +++ b/source/blender/editors/screen/area.c @@ -1586,7 +1586,7 @@ static void ed_default_handlers( UI_region_handlers_add(handlers); } if (flag & ED_KEYMAP_GIZMO) { - BLI_assert(ar && ar->type->regionid == RGN_TYPE_WINDOW); + BLI_assert(ar && ELEM(ar->type->regionid, RGN_TYPE_WINDOW, RGN_TYPE_PREVIEW)); if (ar) { /* Anything else is confusing, only allow this. */ BLI_assert(&ar->handlers == handlers); diff --git a/source/blender/editors/space_clip/space_clip.c b/source/blender/editors/space_clip/space_clip.c index 4df435270ce..c290e3a21d1 100644 --- a/source/blender/editors/space_clip/space_clip.c +++ b/source/blender/editors/space_clip/space_clip.c @@ -802,6 +802,19 @@ static void clip_refresh(const bContext *C, ScrArea *sa) BKE_movieclip_user_set_frame(&sc->user, scene->r.cfra); } +static void CLIP_GGT_navigate(wmGizmoGroupType *gzgt) +{ + VIEW2D_GGT_navigate_impl(gzgt, "CLIP_GGT_navigate"); +} + +static void clip_gizmos(void) +{ + wmGizmoMapType *gzmap_type = WM_gizmomaptype_ensure( + &(const struct wmGizmoMapType_Params){SPACE_CLIP, RGN_TYPE_WINDOW}); + + WM_gizmogrouptype_append_and_link(gzmap_type, CLIP_GGT_navigate); +} + /********************* main region ********************/ /* sets up the fields of the View2D from zoom and offset */ @@ -973,6 +986,8 @@ static void clip_main_region_draw(const bContext *C, ARegion *ar) /* draw Grease Pencil - screen space only */ clip_draw_grease_pencil((bContext *)C, false); } + + WM_gizmomap_draw(ar->gizmo_map, C, WM_GIZMOMAP_DRAWSTEP_2D); } static void clip_main_region_listener(wmWindow *UNUSED(win), @@ -1344,6 +1359,7 @@ void ED_spacetype_clip(void) st->keymap = clip_keymap; st->listener = clip_listener; st->context = clip_context; + st->gizmos = clip_gizmos; st->dropboxes = clip_dropboxes; st->refresh = clip_refresh; st->id_remap = clip_id_remap; @@ -1354,7 +1370,7 @@ void ED_spacetype_clip(void) art->init = clip_main_region_init; art->draw = clip_main_region_draw; art->listener = clip_main_region_listener; - art->keymapflag = ED_KEYMAP_FRAMES | ED_KEYMAP_UI | ED_KEYMAP_GPENCIL; + art->keymapflag = ED_KEYMAP_GIZMO | ED_KEYMAP_FRAMES | ED_KEYMAP_UI | ED_KEYMAP_GPENCIL; BLI_addhead(&st->regiontypes, art); diff --git a/source/blender/editors/space_image/space_image.c b/source/blender/editors/space_image/space_image.c index 539c9c09389..d01bd9f29a8 100644 --- a/source/blender/editors/space_image/space_image.c +++ b/source/blender/editors/space_image/space_image.c @@ -466,9 +466,19 @@ static void IMAGE_GGT_gizmo2d(wmGizmoGroupType *gzgt) gzgt->draw_prepare = ED_widgetgroup_gizmo2d_draw_prepare; } +static void IMAGE_GGT_navigate(wmGizmoGroupType *gzgt) +{ + VIEW2D_GGT_navigate_impl(gzgt, "IMAGE_GGT_navigate"); +} + static void image_widgets(void) { + wmGizmoMapType *gzmap_type = WM_gizmomaptype_ensure( + &(const struct wmGizmoMapType_Params){SPACE_IMAGE, RGN_TYPE_WINDOW}); + WM_gizmogrouptype_append(IMAGE_GGT_gizmo2d); + + WM_gizmogrouptype_append_and_link(gzmap_type, IMAGE_GGT_navigate); } /************************** main region ***************************/ diff --git a/source/blender/editors/space_sequencer/space_sequencer.c b/source/blender/editors/space_sequencer/space_sequencer.c index 6ab44ded046..1bc21664287 100644 --- a/source/blender/editors/space_sequencer/space_sequencer.c +++ b/source/blender/editors/space_sequencer/space_sequencer.c @@ -457,6 +457,19 @@ static int sequencer_context(const bContext *C, const char *member, bContextData return false; } +static void SEQUENCER_GGT_navigate(wmGizmoGroupType *gzgt) +{ + VIEW2D_GGT_navigate_impl(gzgt, "SEQUENCER_GGT_navigate"); +} + +static void sequencer_gizmos(void) +{ + wmGizmoMapType *gzmap_type = WM_gizmomaptype_ensure( + &(const struct wmGizmoMapType_Params){SPACE_SEQ, RGN_TYPE_PREVIEW}); + + WM_gizmogrouptype_append_and_link(gzmap_type, SEQUENCER_GGT_navigate); +} + /* *********************** sequencer (main) region ************************ */ /* add handlers, stuff you only do once or on area/region changes */ static void sequencer_main_region_init(wmWindowManager *wm, ARegion *ar) @@ -659,6 +672,8 @@ static void sequencer_preview_region_draw(const bContext *C, ARegion *ar) } } + WM_gizmomap_draw(ar->gizmo_map, C, WM_GIZMOMAP_DRAWSTEP_2D); + if ((U.uiflag & USER_SHOW_FPS) && ED_screen_animation_no_scrub(wm)) { rcti rect; ED_region_visible_rect(ar, &rect); @@ -805,6 +820,7 @@ void ED_spacetype_sequencer(void) st->operatortypes = sequencer_operatortypes; st->keymap = sequencer_keymap; st->context = sequencer_context; + st->gizmos = sequencer_gizmos; st->dropboxes = sequencer_dropboxes; st->refresh = sequencer_refresh; st->listener = sequencer_listener; @@ -827,7 +843,7 @@ void ED_spacetype_sequencer(void) art->init = sequencer_preview_region_init; art->draw = sequencer_preview_region_draw; art->listener = sequencer_preview_region_listener; - art->keymapflag = ED_KEYMAP_VIEW2D | ED_KEYMAP_FRAMES | ED_KEYMAP_GPENCIL; + art->keymapflag = ED_KEYMAP_GIZMO | ED_KEYMAP_VIEW2D | ED_KEYMAP_FRAMES | ED_KEYMAP_GPENCIL; BLI_addhead(&st->regiontypes, art); /* regions: listview/buttons */ |