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 17 /** \file 18 * \ingroup wm 19 */ 20 21 #pragma once 22 23 struct BLI_Buffer; 24 struct wmGizmoMap; 25 struct wmKeyConfig; 26 27 #include "wm_gizmo_fn.h" 28 29 /* -------------------------------------------------------------------- */ 30 /* wmGizmo */ 31 32 bool wm_gizmo_select_set_ex( 33 struct wmGizmoMap *gzmap, struct wmGizmo *gz, bool select, bool use_array, bool use_callback); 34 bool wm_gizmo_select_and_highlight(bContext *C, struct wmGizmoMap *gzmap, struct wmGizmo *gz); 35 36 void wm_gizmo_calculate_scale(struct wmGizmo *gz, const bContext *C); 37 void wm_gizmo_update(struct wmGizmo *gz, const bContext *C, const bool refresh_map); 38 39 int wm_gizmo_is_visible(struct wmGizmo *gz); 40 enum { 41 WM_GIZMO_IS_VISIBLE_UPDATE = (1 << 0), 42 WM_GIZMO_IS_VISIBLE_DRAW = (1 << 1), 43 }; 44 45 /* -------------------------------------------------------------------- */ 46 /* wmGizmoGroup */ 47 48 enum { 49 TWEAK_MODAL_CANCEL = 1, 50 TWEAK_MODAL_CONFIRM, 51 TWEAK_MODAL_PRECISION_ON, 52 TWEAK_MODAL_PRECISION_OFF, 53 TWEAK_MODAL_SNAP_ON, 54 TWEAK_MODAL_SNAP_OFF, 55 }; 56 57 struct wmGizmoGroup *wm_gizmogroup_new_from_type(struct wmGizmoMap *gzmap, 58 struct wmGizmoGroupType *gzgt); 59 void wm_gizmogroup_free(bContext *C, struct wmGizmoGroup *gzgroup); 60 void wm_gizmogroup_gizmo_register(struct wmGizmoGroup *gzgroup, struct wmGizmo *gz); 61 struct wmGizmoGroup *wm_gizmogroup_find_by_type(const struct wmGizmoMap *gzmap, 62 const struct wmGizmoGroupType *gzgt); 63 struct wmGizmo *wm_gizmogroup_find_intersected_gizmo(wmWindowManager *wm, 64 const struct wmGizmoGroup *gzgroup, 65 struct bContext *C, 66 const int event_modifier, 67 const int mval[2], 68 int *r_part); 69 void wm_gizmogroup_intersectable_gizmos_to_list(wmWindowManager *wm, 70 const struct wmGizmoGroup *gzgroup, 71 const int event_modifier, 72 struct BLI_Buffer *visible_gizmos); 73 bool wm_gizmogroup_is_visible_in_drawstep(const struct wmGizmoGroup *gzgroup, 74 const eWM_GizmoFlagMapDrawStep drawstep); 75 76 void wm_gizmogrouptype_setup_keymap(struct wmGizmoGroupType *gzgt, struct wmKeyConfig *keyconf); 77 78 wmKeyMap *wm_gizmogroup_tweak_modal_keymap(struct wmKeyConfig *keyconf); 79 80 /* -------------------------------------------------------------------- */ 81 /* wmGizmoMap */ 82 83 typedef struct wmGizmoMapSelectState { 84 struct wmGizmo **items; 85 int len, len_alloc; 86 } wmGizmoMapSelectState; 87 88 struct wmGizmoMap { 89 90 struct wmGizmoMapType *type; 91 ListBase groups; /* wmGizmoGroup */ 92 93 /* private, update tagging (enum defined in C source). */ 94 char update_flag[WM_GIZMOMAP_DRAWSTEP_MAX]; 95 96 /** Private, true when not yet used. */ 97 bool is_init; 98 99 /** When set, one of of the items in 'groups' has #wmGizmoGroup.tag_remove set. */ 100 bool tag_remove_group; 101 102 /** 103 * \brief Gizmo map runtime context 104 * 105 * Contains information about this gizmo-map. Currently 106 * highlighted gizmo, currently selected gizmos, ... 107 */ 108 struct { 109 /* we redraw the gizmo-map when this changes */ 110 struct wmGizmo *highlight; 111 /* User has clicked this gizmo and it gets all input. */ 112 struct wmGizmo *modal; 113 /* array for all selected gizmos */ 114 struct wmGizmoMapSelectState select; 115 /* cursor location at point of entering modal (see: WM_GIZMO_MOVE_CURSOR) */ 116 int event_xy[2]; 117 short event_grabcursor; 118 /* until we have nice cursor push/pop API. */ 119 int last_cursor; 120 } gzmap_context; 121 }; 122 123 /** 124 * This is a container for all gizmo types that can be instantiated in a region. 125 * (similar to dropboxes). 126 * 127 * \note There is only ever one of these for every (area, region) combination. 128 */ 129 struct wmGizmoMapType { 130 struct wmGizmoMapType *next, *prev; 131 short spaceid, regionid; 132 /* types of gizmo-groups for this gizmo-map type */ 133 ListBase grouptype_refs; 134 135 /* eGizmoMapTypeUpdateFlags */ 136 eWM_GizmoFlagMapTypeUpdateFlag type_update_flag; 137 }; 138 139 void wm_gizmomap_select_array_clear(struct wmGizmoMap *gzmap); 140 bool wm_gizmomap_deselect_all(struct wmGizmoMap *gzmap); 141 void wm_gizmomap_select_array_shrink(struct wmGizmoMap *gzmap, int len_subtract); 142 void wm_gizmomap_select_array_push_back(struct wmGizmoMap *gzmap, wmGizmo *gz); 143 void wm_gizmomap_select_array_remove(struct wmGizmoMap *gzmap, wmGizmo *gz); 144