2011-02-23 10:52:22 +00:00
|
|
|
/*
|
2008-12-12 18:47:12 +00:00
|
|
|
* 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
|
2018-06-01 18:19:39 +02:00
|
|
|
* of the License, or (at your option) any later version.
|
2008-12-12 18:47:12 +00:00
|
|
|
*
|
|
|
|
|
* 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,
|
2010-02-12 13:34:04 +00:00
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2008-12-12 18:47:12 +00:00
|
|
|
*
|
2008-12-20 12:36:14 +00:00
|
|
|
* The Original Code is Copyright (C) 2004-2008 Blender Foundation.
|
2008-12-12 18:47:12 +00:00
|
|
|
* All rights reserved.
|
|
|
|
|
*/
|
|
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
|
* \ingroup spview3d
|
2011-02-27 20:29:51 +00:00
|
|
|
*/
|
|
|
|
|
|
2008-12-12 18:47:12 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
#include <stdio.h>
|
2008-12-20 12:36:14 +00:00
|
|
|
#include <stdlib.h>
|
2008-12-12 18:47:12 +00:00
|
|
|
|
|
|
|
|
#include "DNA_scene_types.h"
|
2010-08-10 05:41:51 +00:00
|
|
|
#include "DNA_object_types.h"
|
2015-12-13 21:03:13 +13:00
|
|
|
#include "DNA_gpencil_types.h"
|
2008-12-12 18:47:12 +00:00
|
|
|
|
2018-12-18 15:28:24 +01:00
|
|
|
#include "BLI_math_base.h"
|
2011-01-07 18:36:47 +00:00
|
|
|
#include "BLI_utildefines.h"
|
|
|
|
|
|
2015-08-16 17:32:01 +10:00
|
|
|
#include "BLT_translation.h"
|
2011-06-15 11:41:15 +00:00
|
|
|
|
2008-12-18 02:56:48 +00:00
|
|
|
#include "BKE_context.h"
|
2013-04-13 20:31:52 +00:00
|
|
|
#include "BKE_editmesh.h"
|
2008-12-12 18:47:12 +00:00
|
|
|
|
2017-06-08 10:14:53 +02:00
|
|
|
#include "DEG_depsgraph.h"
|
|
|
|
|
|
2013-03-07 02:44:55 +00:00
|
|
|
#include "RNA_access.h"
|
|
|
|
|
#include "RNA_define.h"
|
|
|
|
|
#include "RNA_enum_types.h"
|
|
|
|
|
|
|
|
|
|
#include "WM_api.h"
|
|
|
|
|
#include "WM_types.h"
|
|
|
|
|
|
2009-01-01 18:05:12 +00:00
|
|
|
#include "ED_mesh.h"
|
2018-04-02 15:02:08 +02:00
|
|
|
#include "ED_undo.h"
|
2009-01-05 19:32:04 +00:00
|
|
|
#include "ED_screen.h"
|
2008-12-12 18:47:12 +00:00
|
|
|
|
|
|
|
|
#include "UI_interface.h"
|
|
|
|
|
#include "UI_resources.h"
|
|
|
|
|
|
|
|
|
|
#include "view3d_intern.h"
|
|
|
|
|
|
2009-02-10 15:38:00 +00:00
|
|
|
static void do_view3d_header_buttons(bContext *C, void *arg, int event);
|
2008-12-20 12:36:14 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
#define B_SEL_VERT 110
|
|
|
|
|
#define B_SEL_EDGE 111
|
|
|
|
|
#define B_SEL_FACE 112
|
2009-10-26 12:42:25 +00:00
|
|
|
|
2018-06-08 16:12:25 +02:00
|
|
|
/* -------------------------------------------------------------------- */
|
2018-07-05 12:28:03 +02:00
|
|
|
/** \name Toggle Matcap Flip Operator
|
2018-06-08 16:12:25 +02:00
|
|
|
* \{ */
|
|
|
|
|
|
|
|
|
|
static int toggle_matcap_flip(bContext *C, wmOperator *UNUSED(op))
|
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
View3D *v3d = CTX_wm_view3d(C);
|
|
|
|
|
|
|
|
|
|
if (v3d) {
|
|
|
|
|
v3d->shading.flag ^= V3D_SHADING_MATCAP_FLIP_X;
|
|
|
|
|
ED_view3d_shade_update(CTX_data_main(C), v3d, CTX_wm_area(C));
|
|
|
|
|
WM_event_add_notifier(C, NC_SPACE | ND_SPACE_VIEW3D, v3d);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
Scene *scene = CTX_data_scene(C);
|
|
|
|
|
scene->display.shading.flag ^= V3D_SHADING_MATCAP_FLIP_X;
|
|
|
|
|
WM_event_add_notifier(C, NC_SCENE | NA_EDITED, v3d);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return OPERATOR_FINISHED;
|
2018-06-08 16:12:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void VIEW3D_OT_toggle_matcap_flip(wmOperatorType *ot)
|
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
/* identifiers */
|
|
|
|
|
ot->name = "Flip MatCap";
|
|
|
|
|
ot->description = "Flip MatCap";
|
|
|
|
|
ot->idname = "VIEW3D_OT_toggle_matcap_flip";
|
2018-06-08 16:12:25 +02:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
/* api callbacks */
|
|
|
|
|
ot->exec = toggle_matcap_flip;
|
2018-06-08 16:12:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** \} */
|
|
|
|
|
|
2019-03-28 15:00:27 +11:00
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
/** \name UI Templates
|
|
|
|
|
* \{ */
|
2018-05-22 14:12:47 +02:00
|
|
|
|
2010-10-14 01:22:14 +00:00
|
|
|
static void do_view3d_header_buttons(bContext *C, void *UNUSED(arg), int event)
|
2008-12-20 12:36:14 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
wmWindow *win = CTX_wm_window(C);
|
|
|
|
|
const int ctrl = win->eventstate->ctrl, shift = win->eventstate->shift;
|
|
|
|
|
|
|
|
|
|
/* watch it: if sa->win does not exist, check that when calling direct drawing routines */
|
|
|
|
|
|
|
|
|
|
switch (event) {
|
|
|
|
|
case B_SEL_VERT:
|
|
|
|
|
if (EDBM_selectmode_toggle(C, SCE_SELECT_VERTEX, -1, shift, ctrl)) {
|
|
|
|
|
ED_undo_push(C, "Selectmode Set: Vertex");
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case B_SEL_EDGE:
|
|
|
|
|
if (EDBM_selectmode_toggle(C, SCE_SELECT_EDGE, -1, shift, ctrl)) {
|
|
|
|
|
ED_undo_push(C, "Selectmode Set: Edge");
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case B_SEL_FACE:
|
|
|
|
|
if (EDBM_selectmode_toggle(C, SCE_SELECT_FACE, -1, shift, ctrl)) {
|
|
|
|
|
ED_undo_push(C, "Selectmode Set: Face");
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
2008-12-20 12:36:14 +00:00
|
|
|
}
|
|
|
|
|
|
2011-05-02 11:34:57 +00:00
|
|
|
void uiTemplateEditModeSelection(uiLayout *layout, struct bContext *C)
|
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
Object *obedit = CTX_data_edit_object(C);
|
|
|
|
|
uiBlock *block = uiLayoutGetBlock(layout);
|
|
|
|
|
|
|
|
|
|
UI_block_func_handle_set(block, do_view3d_header_buttons, NULL);
|
|
|
|
|
|
|
|
|
|
if (obedit && (obedit->type == OB_MESH)) {
|
|
|
|
|
BMEditMesh *em = BKE_editmesh_from_object(obedit);
|
|
|
|
|
uiLayout *row;
|
|
|
|
|
|
|
|
|
|
row = uiLayoutRow(layout, true);
|
|
|
|
|
block = uiLayoutGetBlock(row);
|
|
|
|
|
uiDefIconButBitS(
|
|
|
|
|
block,
|
|
|
|
|
UI_BTYPE_TOGGLE,
|
|
|
|
|
SCE_SELECT_VERTEX,
|
|
|
|
|
B_SEL_VERT,
|
|
|
|
|
ICON_VERTEXSEL,
|
|
|
|
|
0,
|
|
|
|
|
0,
|
|
|
|
|
UI_UNIT_X,
|
|
|
|
|
UI_UNIT_Y,
|
|
|
|
|
&em->selectmode,
|
|
|
|
|
1.0,
|
|
|
|
|
0.0,
|
|
|
|
|
0,
|
|
|
|
|
0,
|
|
|
|
|
TIP_("Vertex select - Shift-Click for multiple modes, Ctrl-Click contracts selection"));
|
|
|
|
|
uiDefIconButBitS(block,
|
|
|
|
|
UI_BTYPE_TOGGLE,
|
|
|
|
|
SCE_SELECT_EDGE,
|
|
|
|
|
B_SEL_EDGE,
|
|
|
|
|
ICON_EDGESEL,
|
|
|
|
|
0,
|
|
|
|
|
0,
|
|
|
|
|
ceilf(UI_UNIT_X - U.pixelsize),
|
|
|
|
|
UI_UNIT_Y,
|
|
|
|
|
&em->selectmode,
|
|
|
|
|
1.0,
|
|
|
|
|
0.0,
|
|
|
|
|
0,
|
|
|
|
|
0,
|
|
|
|
|
TIP_("Edge select - Shift-Click for multiple modes, Ctrl-Click "
|
|
|
|
|
"expands/contracts selection"));
|
|
|
|
|
uiDefIconButBitS(
|
|
|
|
|
block,
|
|
|
|
|
UI_BTYPE_TOGGLE,
|
|
|
|
|
SCE_SELECT_FACE,
|
|
|
|
|
B_SEL_FACE,
|
|
|
|
|
ICON_FACESEL,
|
|
|
|
|
0,
|
|
|
|
|
0,
|
|
|
|
|
ceilf(UI_UNIT_X - U.pixelsize),
|
|
|
|
|
UI_UNIT_Y,
|
|
|
|
|
&em->selectmode,
|
|
|
|
|
1.0,
|
|
|
|
|
0.0,
|
|
|
|
|
0,
|
|
|
|
|
0,
|
|
|
|
|
TIP_("Face select - Shift-Click for multiple modes, Ctrl-Click expands selection"));
|
|
|
|
|
}
|
2011-05-02 11:34:57 +00:00
|
|
|
}
|
|
|
|
|
|
2018-05-01 20:12:06 +02:00
|
|
|
static void uiTemplatePaintModeSelection(uiLayout *layout, struct bContext *C)
|
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
ViewLayer *view_layer = CTX_data_view_layer(C);
|
|
|
|
|
Object *ob = OBACT(view_layer);
|
|
|
|
|
|
|
|
|
|
/* Gizmos aren't used in paint modes */
|
|
|
|
|
if (!ELEM(ob->mode, OB_MODE_SCULPT, OB_MODE_PARTICLE_EDIT)) {
|
|
|
|
|
/* masks aren't used for sculpt and particle painting */
|
|
|
|
|
PointerRNA meshptr;
|
|
|
|
|
|
|
|
|
|
RNA_pointer_create(ob->data, &RNA_Mesh, ob->data, &meshptr);
|
|
|
|
|
if (ob->mode & (OB_MODE_TEXTURE_PAINT)) {
|
|
|
|
|
uiItemR(layout, &meshptr, "use_paint_mask", UI_ITEM_R_ICON_ONLY, "", ICON_NONE);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
uiLayout *row = uiLayoutRow(layout, true);
|
|
|
|
|
uiItemR(row, &meshptr, "use_paint_mask", UI_ITEM_R_ICON_ONLY, "", ICON_NONE);
|
|
|
|
|
uiItemR(row, &meshptr, "use_paint_mask_vertex", UI_ITEM_R_ICON_ONLY, "", ICON_NONE);
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-05-01 20:12:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void uiTemplateHeader3D_mode(uiLayout *layout, struct bContext *C)
|
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
ViewLayer *view_layer = CTX_data_view_layer(C);
|
|
|
|
|
Object *ob = OBACT(view_layer);
|
|
|
|
|
Object *obedit = CTX_data_edit_object(C);
|
|
|
|
|
bGPdata *gpd = CTX_data_gpencil_data(C);
|
|
|
|
|
|
|
|
|
|
bool is_paint = (ob && !(gpd && (gpd->flag & GP_DATA_STROKE_EDITMODE)) &&
|
|
|
|
|
ELEM(ob->mode,
|
|
|
|
|
OB_MODE_SCULPT,
|
|
|
|
|
OB_MODE_VERTEX_PAINT,
|
|
|
|
|
OB_MODE_WEIGHT_PAINT,
|
|
|
|
|
OB_MODE_TEXTURE_PAINT));
|
|
|
|
|
|
|
|
|
|
uiTemplateEditModeSelection(layout, C);
|
|
|
|
|
if ((obedit == NULL) && is_paint) {
|
|
|
|
|
uiTemplatePaintModeSelection(layout, C);
|
|
|
|
|
}
|
2018-05-01 20:12:06 +02:00
|
|
|
}
|
2019-03-28 15:00:27 +11:00
|
|
|
|
|
|
|
|
/** \} */
|