Blender  V2.93
view3d_header.c
Go to the documentation of this file.
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  * The Original Code is Copyright (C) 2004-2008 Blender Foundation.
17  * All rights reserved.
18  */
19 
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <string.h>
27 
28 #include "DNA_gpencil_types.h"
29 #include "DNA_object_types.h"
30 #include "DNA_scene_types.h"
31 
32 #include "BLI_math_base.h"
33 #include "BLI_utildefines.h"
34 
35 #include "BLT_translation.h"
36 
37 #include "BKE_context.h"
38 #include "BKE_editmesh.h"
39 
40 #include "DEG_depsgraph.h"
41 
42 #include "RNA_access.h"
43 
44 #include "WM_api.h"
45 #include "WM_types.h"
46 
47 #include "ED_mesh.h"
48 #include "ED_undo.h"
49 
50 #include "UI_interface.h"
51 #include "UI_resources.h"
52 
53 #include "view3d_intern.h"
54 
55 static void do_view3d_header_buttons(bContext *C, void *arg, int event);
56 
57 #define B_SEL_VERT 110
58 #define B_SEL_EDGE 111
59 #define B_SEL_FACE 112
60 
61 /* -------------------------------------------------------------------- */
66 {
67  View3D *v3d = CTX_wm_view3d(C);
68 
69  if (v3d) {
73  }
74  else {
79  }
80 
81  return OPERATOR_FINISHED;
82 }
83 
85 {
86  /* identifiers */
87  ot->name = "Flip MatCap";
88  ot->description = "Flip MatCap";
89  ot->idname = "VIEW3D_OT_toggle_matcap_flip";
90 
91  /* api callbacks */
93 }
94 
97 /* -------------------------------------------------------------------- */
101 static void do_view3d_header_buttons(bContext *C, void *UNUSED(arg), int event)
102 {
103  wmWindow *win = CTX_wm_window(C);
104  const int ctrl = win->eventstate->ctrl, shift = win->eventstate->shift;
105 
106  /* watch it: if area->win does not exist, check that when calling direct drawing routines */
107 
108  switch (event) {
109  case B_SEL_VERT:
110  if (EDBM_selectmode_toggle_multi(C, SCE_SELECT_VERTEX, -1, shift, ctrl)) {
111  ED_undo_push(C, "Selectmode Set: Vertex");
112  }
113  break;
114  case B_SEL_EDGE:
115  if (EDBM_selectmode_toggle_multi(C, SCE_SELECT_EDGE, -1, shift, ctrl)) {
116  ED_undo_push(C, "Selectmode Set: Edge");
117  }
118  break;
119  case B_SEL_FACE:
120  if (EDBM_selectmode_toggle_multi(C, SCE_SELECT_FACE, -1, shift, ctrl)) {
121  ED_undo_push(C, "Selectmode Set: Face");
122  }
123  break;
124  default:
125  break;
126  }
127 }
128 
130 {
131  Object *obedit = CTX_data_edit_object(C);
132  uiBlock *block = uiLayoutGetBlock(layout);
133 
135 
136  if (obedit && (obedit->type == OB_MESH)) {
137  BMEditMesh *em = BKE_editmesh_from_object(obedit);
138  uiLayout *row;
139  uiBut *but;
140 
141  row = uiLayoutRow(layout, true);
142  block = uiLayoutGetBlock(row);
143  but = uiDefIconButBitS(
144  block,
147  B_SEL_VERT,
148  ICON_VERTEXSEL,
149  0,
150  0,
151  UI_UNIT_X,
152  UI_UNIT_Y,
153  &em->selectmode,
154  1.0,
155  0.0,
156  0,
157  0,
158  TIP_("Vertex select - Shift-Click for multiple modes, Ctrl-Click contracts selection"));
160  but = uiDefIconButBitS(
161  block,
164  B_SEL_EDGE,
165  ICON_EDGESEL,
166  0,
167  0,
168  ceilf(UI_UNIT_X - U.pixelsize),
169  UI_UNIT_Y,
170  &em->selectmode,
171  1.0,
172  0.0,
173  0,
174  0,
175  TIP_("Edge select - Shift-Click for multiple modes, "
176  "Ctrl-Click expands/contracts selection depending on the current mode"));
178  but = uiDefIconButBitS(
179  block,
182  B_SEL_FACE,
183  ICON_FACESEL,
184  0,
185  0,
186  ceilf(UI_UNIT_X - U.pixelsize),
187  UI_UNIT_Y,
188  &em->selectmode,
189  1.0,
190  0.0,
191  0,
192  0,
193  TIP_("Face select - Shift-Click for multiple modes, Ctrl-Click expands selection"));
195  }
196 }
197 
198 static void uiTemplatePaintModeSelection(uiLayout *layout, struct bContext *C)
199 {
200  ViewLayer *view_layer = CTX_data_view_layer(C);
201  Object *ob = OBACT(view_layer);
202 
203  /* Gizmos aren't used in paint modes */
205  /* masks aren't used for sculpt and particle painting */
206  PointerRNA meshptr;
207 
208  RNA_pointer_create(ob->data, &RNA_Mesh, ob->data, &meshptr);
209  if (ob->mode & OB_MODE_TEXTURE_PAINT) {
210  uiItemR(layout, &meshptr, "use_paint_mask", UI_ITEM_R_ICON_ONLY, "", ICON_NONE);
211  }
212  else {
213  uiLayout *row = uiLayoutRow(layout, true);
214  uiItemR(row, &meshptr, "use_paint_mask", UI_ITEM_R_ICON_ONLY, "", ICON_NONE);
215  uiItemR(row, &meshptr, "use_paint_mask_vertex", UI_ITEM_R_ICON_ONLY, "", ICON_NONE);
216  }
217  }
218 }
219 
221 {
222  ViewLayer *view_layer = CTX_data_view_layer(C);
223  Object *ob = OBACT(view_layer);
224  Object *obedit = CTX_data_edit_object(C);
226 
227  bool is_paint = (ob && !(gpd && (gpd->flag & GP_DATA_STROKE_EDITMODE)) &&
228  ELEM(ob->mode,
233 
235  if ((obedit == NULL) && is_paint) {
237  }
238 }
239 
struct ScrArea * CTX_wm_area(const bContext *C)
Definition: context.c:714
struct Scene * CTX_data_scene(const bContext *C)
Definition: context.c:1034
struct Object * CTX_data_edit_object(const bContext *C)
Definition: context.c:1296
struct ViewLayer * CTX_data_view_layer(const bContext *C)
Definition: context.c:1044
struct bGPdata * CTX_data_gpencil_data(const bContext *C)
Definition: context.c:1371
struct View3D * CTX_wm_view3d(const bContext *C)
Definition: context.c:760
struct Main * CTX_data_main(const bContext *C)
Definition: context.c:1018
struct wmWindow * CTX_wm_window(const bContext *C)
Definition: context.c:699
BMEditMesh * BKE_editmesh_from_object(struct Object *ob)
Return the BMEditMesh for a given object.
Definition: editmesh.c:85
#define UNUSED(x)
#define ELEM(...)
#define TIP_(msgid)
void DEG_id_tag_update(struct ID *id, int flag)
@ ID_RECALC_COPY_ON_WRITE
Definition: DNA_ID.h:654
@ GP_DATA_STROKE_EDITMODE
@ OB_MODE_PARTICLE_EDIT
@ OB_MODE_WEIGHT_PAINT
@ OB_MODE_SCULPT
@ OB_MODE_TEXTURE_PAINT
@ OB_MODE_VERTEX_PAINT
Object is a sort of wrapper for general info.
@ OB_MESH
#define SCE_SELECT_FACE
#define OBACT(_view_layer)
#define SCE_SELECT_VERTEX
#define SCE_SELECT_EDGE
@ V3D_SHADING_MATCAP_FLIP_X
@ OPERATOR_FINISHED
bool EDBM_selectmode_toggle_multi(struct bContext *C, const short selectmode_new, const int action, const bool use_extend, const bool use_expand)
void ED_undo_push(struct bContext *C, const char *str)
Definition: ed_undo.c:117
void ED_view3d_shade_update(struct Main *bmain, struct View3D *v3d, struct ScrArea *area)
Definition: space_view3d.c:248
StructRNA RNA_Mesh
#define C
Definition: RandGen.cpp:39
void UI_but_flag_disable(uiBut *but, int flag)
Definition: interface.c:6082
#define UI_UNIT_Y
@ UI_ITEM_R_ICON_ONLY
uiBlock * uiLayoutGetBlock(uiLayout *layout)
@ UI_BUT_UNDO
Definition: UI_interface.h:208
void UI_block_func_handle_set(uiBlock *block, uiBlockHandleFunc func, void *arg)
Definition: interface.c:6247
uiLayout * uiLayoutRow(uiLayout *layout, bool align)
uiBut * uiDefIconButBitS(uiBlock *block, int type, int bit, int retval, int icon, int x, int y, short width, short height, short *poin, float min, float max, float a1, float a2, const char *tip)
Definition: interface.c:5433
void uiItemR(uiLayout *layout, struct PointerRNA *ptr, const char *propname, int flag, const char *name, int icon)
#define UI_UNIT_X
@ UI_BTYPE_TOGGLE
Definition: UI_interface.h:344
#define ND_RENDER_OPTIONS
Definition: WM_types.h:335
#define NC_SCENE
Definition: WM_types.h:279
#define ND_SPACE_VIEW3D
Definition: WM_types.h:423
#define NC_SPACE
Definition: WM_types.h:293
unsigned int U
Definition: btGjkEpa3.h:78
Scene scene
#define ceilf(x)
void RNA_pointer_create(ID *id, StructRNA *type, void *data, PointerRNA *r_ptr)
Definition: rna_access.c:146
short selectmode
Definition: BKE_editmesh.h:72
void * data
View3DShading shading
struct SceneDisplay display
View3DShading shading
short shift
Definition: WM_types.h:618
short ctrl
Definition: WM_types.h:618
const char * name
Definition: WM_types.h:721
const char * idname
Definition: WM_types.h:723
const char * description
Definition: WM_types.h:726
int(* exec)(struct bContext *, struct wmOperator *) ATTR_WARN_UNUSED_RESULT
Definition: WM_types.h:736
struct wmEvent * eventstate
static int toggle_matcap_flip(bContext *C, wmOperator *UNUSED(op))
Definition: view3d_header.c:65
#define B_SEL_EDGE
Definition: view3d_header.c:58
void uiTemplateHeader3D_mode(uiLayout *layout, struct bContext *C)
#define B_SEL_FACE
Definition: view3d_header.c:59
void uiTemplateEditModeSelection(uiLayout *layout, struct bContext *C)
#define B_SEL_VERT
Definition: view3d_header.c:57
void VIEW3D_OT_toggle_matcap_flip(wmOperatorType *ot)
Definition: view3d_header.c:84
static void uiTemplatePaintModeSelection(uiLayout *layout, struct bContext *C)
static void do_view3d_header_buttons(bContext *C, void *arg, int event)
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
wmOperatorType * ot
Definition: wm_files.c:3156