Cleanup: use 'mesh' in preselect identifiers
[blender.git] / source / blender / editors / space_view3d / view3d_gizmo_preselect.c
1 /*
2  * ***** BEGIN GPL LICENSE BLOCK *****
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software Foundation,
16  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  *
18  * ***** END GPL LICENSE BLOCK *****
19  */
20
21 /** \file blender/editors/space_view3d/view3d_gizmo_preselect.c
22  *  \ingroup spview3d
23  */
24
25 #include "MEM_guardedalloc.h"
26
27 #include "BLI_blenlib.h"
28 #include "BLI_math.h"
29 #include "BLI_utildefines.h"
30
31 #include "BKE_context.h"
32
33 #include "ED_screen.h"
34
35 #include "UI_resources.h"
36
37 #include "WM_api.h"
38 #include "WM_types.h"
39 #include "WM_toolsystem.h"
40
41 #include "view3d_intern.h"  /* own include */
42
43 /* -------------------------------------------------------------------- */
44 /** \name Mesh Pre-Select Element Gizmo
45  *
46  * \{ */
47
48 struct GizmoGroupPreSelElem {
49         wmGizmo *gizmo;
50 };
51
52 static bool WIDGETGROUP_mesh_preselect_elem_poll(const bContext *C, wmGizmoGroupType *gzgt)
53 {
54         bToolRef_Runtime *tref_rt = WM_toolsystem_runtime_from_context((bContext *)C);
55         if ((tref_rt == NULL) ||
56             !STREQ(gzgt->idname, tref_rt->gizmo_group))
57         {
58                 WM_gizmo_group_type_unlink_delayed_ptr(gzgt);
59                 return false;
60         }
61         return true;
62 }
63
64 static void WIDGETGROUP_mesh_preselect_elem_setup(const bContext *UNUSED(C), wmGizmoGroup *gzgroup)
65 {
66         const wmGizmoType *gzt_presel = WM_gizmotype_find("GIZMO_GT_mesh_preselect_elem_3d", true);
67         struct GizmoGroupPreSelElem *man = MEM_callocN(sizeof(struct GizmoGroupPreSelElem), __func__);
68         gzgroup->customdata = man;
69
70         wmGizmo *gz = man->gizmo = WM_gizmo_new_ptr(gzt_presel, gzgroup, NULL);
71         UI_GetThemeColor3fv(TH_GIZMO_PRIMARY, gz->color);
72         UI_GetThemeColor3fv(TH_GIZMO_HI, gz->color_hi);
73 }
74
75 void VIEW3D_GGT_mesh_preselect_elem(wmGizmoGroupType *gzgt)
76 {
77         gzgt->name = "Mesh Preselect Element";
78         gzgt->idname = "VIEW3D_GGT_mesh_preselect_elem";
79
80         gzgt->flag = WM_GIZMOGROUPTYPE_3D;
81
82         gzgt->gzmap_params.spaceid = SPACE_VIEW3D;
83         gzgt->gzmap_params.regionid = RGN_TYPE_WINDOW;
84
85         gzgt->poll = WIDGETGROUP_mesh_preselect_elem_poll;
86         gzgt->setup = WIDGETGROUP_mesh_preselect_elem_setup;
87 }
88
89 /** \} */
90
91 /* -------------------------------------------------------------------- */
92 /** \name Mesh Pre-Select Edge Ring Gizmo
93  *
94  * \{ */
95
96 struct GizmoGroupPreSelEdgeRing {
97         wmGizmo *gizmo;
98 };
99
100 static bool WIDGETGROUP_mesh_preselect_edgering_poll(const bContext *C, wmGizmoGroupType *gzgt)
101 {
102         bToolRef_Runtime *tref_rt = WM_toolsystem_runtime_from_context((bContext *)C);
103         if ((tref_rt == NULL) ||
104             !STREQ(gzgt->idname, tref_rt->gizmo_group))
105         {
106                 WM_gizmo_group_type_unlink_delayed_ptr(gzgt);
107                 return false;
108         }
109         return true;
110 }
111
112 static void WIDGETGROUP_mesh_preselect_edgering_setup(const bContext *UNUSED(C), wmGizmoGroup *gzgroup)
113 {
114         const wmGizmoType *gzt_presel = WM_gizmotype_find("GIZMO_GT_mesh_preselect_edgering_3d", true);
115         struct GizmoGroupPreSelEdgeRing *man = MEM_callocN(sizeof(struct GizmoGroupPreSelEdgeRing), __func__);
116         gzgroup->customdata = man;
117
118         wmGizmo *gz = man->gizmo = WM_gizmo_new_ptr(gzt_presel, gzgroup, NULL);
119         UI_GetThemeColor3fv(TH_GIZMO_PRIMARY, gz->color);
120         UI_GetThemeColor3fv(TH_GIZMO_HI, gz->color_hi);
121 }
122
123 void VIEW3D_GGT_mesh_preselect_edgering(wmGizmoGroupType *gzgt)
124 {
125         gzgt->name = "Mesh Preselect Edge Ring";
126         gzgt->idname = "VIEW3D_GGT_mesh_preselect_edgering";
127
128         gzgt->flag = WM_GIZMOGROUPTYPE_3D;
129
130         gzgt->gzmap_params.spaceid = SPACE_VIEW3D;
131         gzgt->gzmap_params.regionid = RGN_TYPE_WINDOW;
132
133         gzgt->poll = WIDGETGROUP_mesh_preselect_edgering_poll;
134         gzgt->setup = WIDGETGROUP_mesh_preselect_edgering_setup;
135 }
136
137 /** \} */