Welcome to mirror list, hosted at ThFree Co, Russian Federation.

view3d_header.c « space_view3d « editors « blender « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 9f0eb18e284bceee2bac1d1a58ecd7e81299ae6f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
/* SPDX-License-Identifier: GPL-2.0-or-later
 * Copyright 2004-2008 Blender Foundation. All rights reserved. */

/** \file
 * \ingroup spview3d
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "DNA_gpencil_types.h"
#include "DNA_object_types.h"
#include "DNA_scene_types.h"

#include "BLI_math_base.h"
#include "BLI_utildefines.h"

#include "BLT_translation.h"

#include "BKE_context.h"
#include "BKE_editmesh.h"

#include "DEG_depsgraph.h"

#include "RNA_access.h"

#include "WM_api.h"
#include "WM_types.h"

#include "ED_mesh.h"
#include "ED_undo.h"

#include "UI_interface.h"
#include "UI_resources.h"

#include "view3d_intern.h"

#define B_SEL_VERT 110
#define B_SEL_EDGE 111
#define B_SEL_FACE 112

/* -------------------------------------------------------------------- */
/** \name Toggle Matcap Flip Operator
 * \{ */

static int toggle_matcap_flip(bContext *C, wmOperator *UNUSED(op))
{
  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;
    DEG_id_tag_update(&scene->id, ID_RECALC_COPY_ON_WRITE);
    WM_event_add_notifier(C, NC_SCENE | ND_RENDER_OPTIONS, scene);
  }

  return OPERATOR_FINISHED;
}

void VIEW3D_OT_toggle_matcap_flip(wmOperatorType *ot)
{
  /* identifiers */
  ot->name = "Flip MatCap";
  ot->description = "Flip MatCap";
  ot->idname = "VIEW3D_OT_toggle_matcap_flip";

  /* api callbacks */
  ot->exec = toggle_matcap_flip;
}

/** \} */

/* -------------------------------------------------------------------- */
/** \name UI Templates
 * \{ */

void uiTemplateEditModeSelection(uiLayout *layout, struct bContext *C)
{
  Object *obedit = CTX_data_edit_object(C);
  if (!obedit || obedit->type != OB_MESH) {
    return;
  }

  BMEditMesh *em = BKE_editmesh_from_object(obedit);
  uiLayout *row = uiLayoutRow(layout, true);

  PointerRNA op_ptr;
  wmOperatorType *ot = WM_operatortype_find("MESH_OT_select_mode", true);
  uiItemFullO_ptr(row,
                  ot,
                  "",
                  ICON_VERTEXSEL,
                  NULL,
                  WM_OP_INVOKE_DEFAULT,
                  (em->selectmode & SCE_SELECT_VERTEX) ? UI_ITEM_O_DEPRESS : 0,
                  &op_ptr);
  RNA_enum_set(&op_ptr, "type", SCE_SELECT_VERTEX);
  uiItemFullO_ptr(row,
                  ot,
                  "",
                  ICON_EDGESEL,
                  NULL,
                  WM_OP_INVOKE_DEFAULT,
                  (em->selectmode & SCE_SELECT_EDGE) ? UI_ITEM_O_DEPRESS : 0,
                  &op_ptr);
  RNA_enum_set(&op_ptr, "type", SCE_SELECT_EDGE);
  uiItemFullO_ptr(row,
                  ot,
                  "",
                  ICON_FACESEL,
                  NULL,
                  WM_OP_INVOKE_DEFAULT,
                  (em->selectmode & SCE_SELECT_FACE) ? UI_ITEM_O_DEPRESS : 0,
                  &op_ptr);
  RNA_enum_set(&op_ptr, "type", SCE_SELECT_FACE);
}

static void uiTemplatePaintModeSelection(uiLayout *layout, struct bContext *C)
{
  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);
    }
  }
}

void uiTemplateHeader3D_mode(uiLayout *layout, struct bContext *C)
{
  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);
  }
}

/** \} */