Blender  V2.93
FX_ui_common.c
Go to the documentation of this file.
1 /* This program is free software; you can redistribute it and/or
2  * modify it under the terms of the GNU General Public License
3  * as published by the Free Software Foundation; either version 2
4  * of the License, or (at your option) any later version.
5  *
6  * This program is distributed in the hope that it will be useful,
7  * but WITHOUT ANY WARRANTY; without even the implied warranty of
8  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9  * GNU General Public License for more details.
10  *
11  * You should have received a copy of the GNU General Public License
12  * along with this program; if not, write to the Free Software Foundation,
13  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
14  */
15 
20 #include "BLI_listbase.h"
21 #include "BLI_string.h"
22 
23 #include "MEM_guardedalloc.h"
24 
25 #include "BKE_context.h"
26 #include "BKE_object.h"
27 #include "BKE_screen.h"
28 #include "BKE_shader_fx.h"
29 
30 #include "DNA_object_types.h"
31 #include "DNA_scene_types.h"
32 #include "DNA_screen_types.h"
33 #include "DNA_shader_fx_types.h"
34 
35 #include "ED_object.h"
36 
37 #include "BLT_translation.h"
38 
39 #include "UI_interface.h"
40 #include "UI_resources.h"
41 
42 #include "RNA_access.h"
43 
44 #include "WM_api.h"
45 #include "WM_types.h"
46 
47 #include "FX_ui_common.h" /* Self include */
48 
49 /* -------------------------------------------------------------------- */
56 static void shaderfx_reorder(bContext *C, Panel *panel, int new_index)
57 {
58  PointerRNA *fx_ptr = UI_panel_custom_data_get(panel);
59  ShaderFxData *fx = (ShaderFxData *)fx_ptr->data;
60 
61  PointerRNA props_ptr;
62  wmOperatorType *ot = WM_operatortype_find("OBJECT_OT_shaderfx_move_to_index", false);
64  RNA_string_set(&props_ptr, "shaderfx", fx->name);
65  RNA_int_set(&props_ptr, "index", new_index);
67  WM_operator_properties_free(&props_ptr);
68 }
69 
73 static short get_shaderfx_expand_flag(const bContext *UNUSED(C), Panel *panel)
74 {
75  PointerRNA *fx_ptr = UI_panel_custom_data_get(panel);
76  ShaderFxData *fx = (ShaderFxData *)fx_ptr->data;
77  return fx->ui_expand_flag;
78 }
79 
83 static void set_shaderfx_expand_flag(const bContext *UNUSED(C), Panel *panel, short expand_flag)
84 {
85  PointerRNA *fx_ptr = UI_panel_custom_data_get(panel);
86  ShaderFxData *fx = (ShaderFxData *)fx_ptr->data;
87  fx->ui_expand_flag = expand_flag;
88 }
89 
92 /* -------------------------------------------------------------------- */
100 {
101  ShaderFxData *fx = ptr->data;
102  if (fx->error) {
103  uiLayout *row = uiLayoutRow(layout, false);
104  uiItemL(row, IFACE_(fx->error), ICON_ERROR);
105  }
106 }
107 
112 {
115 
116  if (r_ob_ptr != NULL) {
118  }
119 
120  uiLayoutSetContextPointer(panel->layout, "shaderfx", ptr);
121 
122  return ptr;
123 }
124 
125 #define ERROR_LIBDATA_MESSAGE TIP_("External library data")
126 
127 static void gpencil_shaderfx_ops_extra_draw(bContext *C, uiLayout *layout, void *fx_v)
128 {
129  PointerRNA op_ptr;
130  uiLayout *row;
131  ShaderFxData *fx = (ShaderFxData *)fx_v;
132 
133  PointerRNA ptr;
135  RNA_pointer_create(&ob->id, &RNA_ShaderFx, fx, &ptr);
136  uiLayoutSetContextPointer(layout, "shaderfx", &ptr);
138 
139  uiLayoutSetUnitsX(layout, 4.0f);
140 
141  /* Duplicate. */
142  uiItemO(layout,
144  ICON_DUPLICATE,
145  "OBJECT_OT_shaderfx_copy");
146 
147  uiItemS(layout);
148 
149  /* Move to first. */
150  row = uiLayoutColumn(layout, false);
151  uiItemFullO(row,
152  "OBJECT_OT_shaderfx_move_to_index",
153  IFACE_("Move to First"),
154  ICON_TRIA_UP,
155  NULL,
157  0,
158  &op_ptr);
159  RNA_int_set(&op_ptr, "index", 0);
160  if (!fx->prev) {
161  uiLayoutSetEnabled(row, false);
162  }
163 
164  /* Move to last. */
165  row = uiLayoutColumn(layout, false);
166  uiItemFullO(row,
167  "OBJECT_OT_shaderfx_move_to_index",
168  IFACE_("Move to Last"),
169  ICON_TRIA_DOWN,
170  NULL,
172  0,
173  &op_ptr);
174  RNA_int_set(&op_ptr, "index", BLI_listbase_count(&ob->shader_fx) - 1);
175  if (!fx->next) {
176  uiLayoutSetEnabled(row, false);
177  }
178 }
179 
180 static void shaderfx_panel_header(const bContext *UNUSED(C), Panel *panel)
181 {
182  uiLayout *layout = panel->layout;
183  bool narrow_panel = (panel->sizex < UI_UNIT_X * 7 && panel->sizex != 0);
184 
186  Object *ob = (Object *)ptr->owner_id;
187  ShaderFxData *fx = (ShaderFxData *)ptr->data;
188 
189  const ShaderFxTypeInfo *fxti = BKE_shaderfx_get_info(fx->type);
190 
192 
193  /* Effect type icon. */
194  uiLayout *row = uiLayoutRow(layout, false);
195  if (fxti->isDisabled && fxti->isDisabled(fx, 0)) {
196  uiLayoutSetRedAlert(row, true);
197  }
198  uiItemL(row, "", RNA_struct_ui_icon(ptr->type));
199 
200  /* Effect name. */
201  row = uiLayoutRow(layout, true);
202  if (!narrow_panel) {
203  uiItemR(row, ptr, "name", 0, "", ICON_NONE);
204  }
205 
206  /* Mode enabling buttons. */
208  uiLayout *sub = uiLayoutRow(row, true);
209  uiLayoutSetActive(sub, false);
210  uiItemR(sub, ptr, "show_in_editmode", 0, "", ICON_NONE);
211  }
212  uiItemR(row, ptr, "show_viewport", 0, "", ICON_NONE);
213  uiItemR(row, ptr, "show_render", 0, "", ICON_NONE);
214 
215  /* Extra operators. */
216  uiItemMenuF(row, "", ICON_DOWNARROW_HLT, gpencil_shaderfx_ops_extra_draw, fx);
217 
218  row = uiLayoutRow(row, false);
220  uiItemO(row, "", ICON_X, "OBJECT_OT_shaderfx_remove");
221 
222  /* Some padding so the X isn't too close to the drag icon. */
223  uiItemS(layout);
224 }
225 
228 /* -------------------------------------------------------------------- */
232 static bool shaderfx_ui_poll(const bContext *C, PanelType *UNUSED(pt))
233 {
235 
236  return (ob != NULL) && (ob->type == OB_GPENCIL);
237 }
238 
243 {
244  PanelType *panel_type = MEM_callocN(sizeof(PanelType), __func__);
245 
246  BKE_shaderfxType_panel_id(type, panel_type->idname);
247  BLI_strncpy(panel_type->label, "", BKE_ST_MAXNAME);
248  BLI_strncpy(panel_type->context, "shaderfx", BKE_ST_MAXNAME);
250 
251  panel_type->draw_header = shaderfx_panel_header;
252  panel_type->draw = draw;
253  panel_type->poll = shaderfx_ui_poll;
254 
255  /* Give the panel the special flag that says it was built here and corresponds to a
256  * shader effect rather than a PanelType. */
258  panel_type->reorder = shaderfx_reorder;
261 
262  BLI_addtail(&region_type->paneltypes, panel_type);
263 
264  return panel_type;
265 }
266 
274  const char *name,
275  const char *label,
276  PanelDrawFn draw_header,
277  PanelDrawFn draw,
278  PanelType *parent)
279 {
280  PanelType *panel_type = MEM_callocN(sizeof(PanelType), __func__);
281 
282  BLI_snprintf(panel_type->idname, BKE_ST_MAXNAME, "%s_%s", parent->idname, name);
283  BLI_strncpy(panel_type->label, label, BKE_ST_MAXNAME);
284  BLI_strncpy(panel_type->context, "shaderfx", BKE_ST_MAXNAME);
286 
287  panel_type->draw_header = draw_header;
288  panel_type->draw = draw;
289  panel_type->poll = shaderfx_ui_poll;
291 
292  BLI_assert(parent != NULL);
293  BLI_strncpy(panel_type->parent_id, parent->idname, BKE_ST_MAXNAME);
294  panel_type->parent = parent;
295  BLI_addtail(&parent->children, BLI_genericNodeN(panel_type));
296  BLI_addtail(&region_type->paneltypes, panel_type);
297 
298  return panel_type;
299 }
300 
General operations, lookup, etc. for blender objects.
#define BKE_ST_MAXNAME
Definition: BKE_screen.h:68
@ PANEL_TYPE_DRAW_BOX
Definition: BKE_screen.h:305
@ PANEL_TYPE_INSTANCED
Definition: BKE_screen.h:303
@ PANEL_TYPE_DEFAULT_CLOSED
Definition: BKE_screen.h:297
@ PANEL_TYPE_HEADER_EXPAND
Definition: BKE_screen.h:300
void BKE_shaderfxType_panel_id(ShaderFxType type, char *r_idname)
Definition: shader_fx.c:173
const ShaderFxTypeInfo * BKE_shaderfx_get_info(ShaderFxType type)
Definition: shader_fx.c:157
@ eShaderFxTypeFlag_SupportsEditmode
Definition: BKE_shader_fx.h:53
#define BLI_assert(a)
Definition: BLI_assert.h:58
struct LinkData * BLI_genericNodeN(void *data)
Definition: listbase.c:923
void BLI_addtail(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition: listbase.c:110
int BLI_listbase_count(const struct ListBase *listbase) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
size_t BLI_snprintf(char *__restrict dst, size_t maxncpy, const char *__restrict format,...) ATTR_NONNULL(1
char * BLI_strncpy(char *__restrict dst, const char *__restrict src, const size_t maxncpy) ATTR_NONNULL()
Definition: string.c:108
#define UNUSED(x)
#define CTX_IFACE_(context, msgid)
#define BLT_I18NCONTEXT_OPERATOR_DEFAULT
#define IFACE_(msgid)
#define BLT_I18NCONTEXT_DEFAULT_BPYRNA
#define ID_IS_LINKED(_id)
Definition: DNA_ID.h:426
Object is a sort of wrapper for general info.
@ OB_GPENCIL
ShaderFxType
struct Object * ED_object_active_context(const struct bContext *C)
static void set_shaderfx_expand_flag(const bContext *UNUSED(C), Panel *panel, short expand_flag)
Definition: FX_ui_common.c:83
PanelType * shaderfx_panel_register(ARegionType *region_type, ShaderFxType type, PanelDrawFn draw)
Definition: FX_ui_common.c:242
static void shaderfx_panel_header(const bContext *UNUSED(C), Panel *panel)
Definition: FX_ui_common.c:180
static short get_shaderfx_expand_flag(const bContext *UNUSED(C), Panel *panel)
Definition: FX_ui_common.c:73
static bool shaderfx_ui_poll(const bContext *C, PanelType *UNUSED(pt))
Definition: FX_ui_common.c:232
static void shaderfx_reorder(bContext *C, Panel *panel, int new_index)
Definition: FX_ui_common.c:56
PanelType * shaderfx_subpanel_register(ARegionType *region_type, const char *name, const char *label, PanelDrawFn draw_header, PanelDrawFn draw, PanelType *parent)
Definition: FX_ui_common.c:273
void shaderfx_panel_end(uiLayout *layout, PointerRNA *ptr)
Definition: FX_ui_common.c:99
static void gpencil_shaderfx_ops_extra_draw(bContext *C, uiLayout *layout, void *fx_v)
Definition: FX_ui_common.c:127
PointerRNA * shaderfx_panel_get_property_pointers(Panel *panel, PointerRNA *r_ob_ptr)
Definition: FX_ui_common.c:111
#define ERROR_LIBDATA_MESSAGE
Definition: FX_ui_common.c:125
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum type
Read Guarded memory(de)allocation.
StructRNA RNA_ShaderFx
StructRNA RNA_Object
#define C
Definition: RandGen.cpp:39
void uiLayoutSetActive(uiLayout *layout, bool active)
uiBlock * uiLayoutGetBlock(uiLayout *layout)
@ UI_EMBOSS_NONE
Definition: UI_interface.h:108
void uiLayoutSetOperatorContext(uiLayout *layout, int opcontext)
void uiLayoutSetEnabled(uiLayout *layout, bool enabled)
uiLayout * uiLayoutColumn(uiLayout *layout, bool align)
void uiItemFullO(uiLayout *layout, const char *opname, const char *name, int icon, struct IDProperty *properties, int context, int flag, struct PointerRNA *r_opptr)
void uiItemL(uiLayout *layout, const char *name, int icon)
void uiLayoutSetRedAlert(uiLayout *layout, bool redalert)
struct PointerRNA * UI_panel_custom_data_get(const struct Panel *panel)
void uiItemS(uiLayout *layout)
uiLayout * uiLayoutRow(uiLayout *layout, bool align)
void uiLayoutSetUnitsX(uiLayout *layout, float unit)
void uiItemR(uiLayout *layout, struct PointerRNA *ptr, const char *propname, int flag, const char *name, int icon)
void uiLayoutSetEmboss(uiLayout *layout, eUIEmbossType emboss)
void uiItemO(uiLayout *layout, const char *name, int icon, const char *opname)
void uiLayoutSetContextPointer(uiLayout *layout, const char *name, struct PointerRNA *ptr)
void uiItemMenuF(uiLayout *layout, const char *name, int icon, uiMenuCreateFunc func, void *arg)
#define UI_UNIT_X
void UI_block_lock_set(uiBlock *block, bool val, const char *lockstr)
Definition: interface.c:2211
@ WM_OP_INVOKE_DEFAULT
Definition: WM_types.h:197
const char * label
void(* PanelDrawFn)(const bContext *, struct Panel *)
Definition: fmodifier_ui.c:61
void *(* MEM_callocN)(size_t len, const char *str)
Definition: mallocn.c:45
bool RNA_struct_is_a(const StructRNA *type, const StructRNA *srna)
Definition: rna_access.c:844
void RNA_pointer_create(ID *id, StructRNA *type, void *data, PointerRNA *r_ptr)
Definition: rna_access.c:146
void RNA_string_set(PointerRNA *ptr, const char *name, const char *value)
Definition: rna_access.c:6550
void RNA_int_set(PointerRNA *ptr, const char *name, int value)
Definition: rna_access.c:6319
int RNA_struct_ui_icon(const StructRNA *type)
Definition: rna_access.c:738
ListBase paneltypes
Definition: BKE_screen.h:216
ListBase shader_fx
short(* get_list_data_expand_flag)(const struct bContext *C, struct Panel *pa)
Definition: BKE_screen.h:278
void(* draw)(const struct bContext *C, struct Panel *panel)
Definition: BKE_screen.h:266
bool(* poll)(const struct bContext *C, struct PanelType *pt)
Definition: BKE_screen.h:260
void(* draw_header)(const struct bContext *C, struct Panel *panel)
Definition: BKE_screen.h:262
char idname[BKE_ST_MAXNAME]
Definition: BKE_screen.h:241
void(* set_list_data_expand_flag)(const struct bContext *C, struct Panel *pa, short expand_flag)
Definition: BKE_screen.h:285
char context[BKE_ST_MAXNAME]
Definition: BKE_screen.h:245
void(* reorder)(struct bContext *C, struct Panel *pa, int new_index)
Definition: BKE_screen.h:271
char translation_context[BKE_ST_MAXNAME]
Definition: BKE_screen.h:244
ListBase children
Definition: BKE_screen.h:289
struct PanelType * parent
Definition: BKE_screen.h:288
char label[BKE_ST_MAXNAME]
Definition: BKE_screen.h:242
char parent_id[BKE_ST_MAXNAME]
Definition: BKE_screen.h:248
struct uiLayout * layout
struct StructRNA * type
Definition: RNA_types.h:51
void * data
Definition: RNA_types.h:52
struct ID * owner_id
Definition: RNA_types.h:50
struct ShaderFxData * prev
struct ShaderFxData * next
ShaderFxTypeFlag flags
Definition: BKE_shader_fx.h:89
bool(* isDisabled)(struct ShaderFxData *fx, int userRenderParams)
int WM_operator_name_call_ptr(bContext *C, wmOperatorType *ot, short context, PointerRNA *properties)
PointerRNA * ptr
Definition: wm_files.c:3157
wmOperatorType * ot
Definition: wm_files.c:3156
wmOperatorType * WM_operatortype_find(const char *idname, bool quiet)
void WM_operator_properties_create_ptr(PointerRNA *ptr, wmOperatorType *ot)
Definition: wm_operators.c:584
void WM_operator_properties_free(PointerRNA *ptr)
Definition: wm_operators.c:711