Blender  V3.3
MOD_gpenciltime.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2018 Blender Foundation. */
3 
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <string.h>
11 
12 #include "BLI_utildefines.h"
13 
14 #include "BLT_translation.h"
15 
16 #include "DNA_defaults.h"
18 #include "DNA_gpencil_types.h"
19 #include "DNA_scene_types.h"
20 #include "DNA_screen_types.h"
21 
22 #include "BKE_context.h"
23 #include "BKE_gpencil_modifier.h"
24 #include "BKE_screen.h"
25 
26 #include "UI_interface.h"
27 #include "UI_resources.h"
28 
29 #include "RNA_access.h"
30 
32 #include "MOD_gpencil_ui_common.h"
33 
34 static void initData(GpencilModifierData *md)
35 {
37 
38  BLI_assert(MEMCMP_STRUCT_AFTER_IS_ZERO(gpmd, modifier));
39 
41 }
42 
43 static void copyData(const GpencilModifierData *md, GpencilModifierData *target)
44 {
46 }
47 
48 static int remapTime(struct GpencilModifierData *md,
49  struct Depsgraph *UNUSED(depsgraph),
50  struct Scene *scene,
51  struct Object *UNUSED(ob),
52  struct bGPDlayer *gpl,
53  int cfra)
54 {
56  const bool custom = mmd->flag & GP_TIME_CUSTOM_RANGE;
57  const bool invgpl = mmd->flag & GP_TIME_INVERT_LAYER;
58  const bool invpass = mmd->flag & GP_TIME_INVERT_LAYERPASS;
59  int sfra = custom ? mmd->sfra : scene->r.sfra;
60  int efra = custom ? mmd->efra : scene->r.efra;
61  int offset = mmd->offset;
62  int nfra = 0;
63  CLAMP_MIN(sfra, 0);
64  CLAMP_MIN(efra, 0);
65 
66  if (offset < 0) {
67  offset = abs(efra - sfra + offset + 1);
68  }
69  /* Avoid inverse ranges. */
70  if (efra < sfra) {
71  return cfra;
72  }
73 
74  /* omit if filter by layer */
75  if (mmd->layername[0] != '\0') {
76  if (invgpl == false) {
77  if (!STREQ(mmd->layername, gpl->info)) {
78  return cfra;
79  }
80  }
81  else {
82  if (STREQ(mmd->layername, gpl->info)) {
83  return cfra;
84  }
85  }
86  }
87  /* verify pass */
88  if (mmd->layer_pass > 0) {
89  if (invpass == false) {
90  if (gpl->pass_index != mmd->layer_pass) {
91  return cfra;
92  }
93  }
94  else {
95  if (gpl->pass_index == mmd->layer_pass) {
96  return cfra;
97  }
98  }
99  }
100 
101  /* apply frame scale */
102  cfra *= mmd->frame_scale;
103 
104  /* if fix mode, return predefined frame number */
105  if (mmd->mode == GP_TIME_MODE_FIX) {
106  return offset;
107  }
108 
109  if (mmd->mode == GP_TIME_MODE_NORMAL) {
110  if ((mmd->flag & GP_TIME_KEEP_LOOP) == 0) {
111  nfra = cfra + sfra + offset - 1 < efra ? cfra + sfra + offset - 1 : efra;
112  }
113  else {
114  nfra = (offset + cfra - 1) % (efra - sfra + 1) + sfra;
115  }
116  }
117  if (mmd->mode == GP_TIME_MODE_REVERSE) {
118  if ((mmd->flag & GP_TIME_KEEP_LOOP) == 0) {
119  nfra = efra - cfra - offset > sfra ? efra - cfra - offset + 1 : sfra;
120  }
121  else {
122  nfra = (efra + 1 - (cfra + offset - 1) % (efra - sfra + 1)) - 1;
123  }
124  }
125 
126  if (mmd->mode == GP_TIME_MODE_PINGPONG) {
127  if ((mmd->flag & GP_TIME_KEEP_LOOP) == 0) {
128  if (((int)(cfra + offset - 1) / (efra - sfra)) % (2)) {
129  nfra = efra - (cfra + offset - 1) % (efra - sfra);
130  }
131  else {
132  nfra = sfra + (cfra + offset - 1) % (efra - sfra);
133  }
134  if (cfra > (efra - sfra) * 2) {
135  nfra = sfra + offset;
136  }
137  }
138  else {
139 
140  if (((int)(cfra + offset - 1) / (efra - sfra)) % (2)) {
141  nfra = efra - (cfra + offset - 1) % (efra - sfra);
142  }
143  else {
144  nfra = sfra + (cfra + offset - 1) % (efra - sfra);
145  }
146  }
147  }
148 
149  return nfra;
150 }
151 
152 static void panel_draw(const bContext *UNUSED(C), Panel *panel)
153 {
154  uiLayout *row, *col;
155  uiLayout *layout = panel->layout;
156 
158 
159  int mode = RNA_enum_get(ptr, "mode");
160 
161  uiLayoutSetPropSep(layout, true);
162 
163  uiItemR(layout, ptr, "mode", 0, NULL, ICON_NONE);
164 
165  col = uiLayoutColumn(layout, false);
166 
167  const char *text = (mode == GP_TIME_MODE_FIX) ? IFACE_("Frame") : IFACE_("Frame Offset");
168  uiItemR(col, ptr, "offset", 0, text, ICON_NONE);
169 
170  row = uiLayoutRow(col, false);
171  uiLayoutSetActive(row, mode != GP_TIME_MODE_FIX);
172  uiItemR(row, ptr, "frame_scale", 0, IFACE_("Scale"), ICON_NONE);
173 
174  row = uiLayoutRow(layout, false);
175  uiLayoutSetActive(row, mode != GP_TIME_MODE_FIX);
176  uiItemR(row, ptr, "use_keep_loop", 0, NULL, ICON_NONE);
177 
179 }
180 
181 static void custom_range_header_draw(const bContext *UNUSED(C), Panel *panel)
182 {
183  uiLayout *layout = panel->layout;
184 
186 
187  int mode = RNA_enum_get(ptr, "mode");
188 
189  uiLayoutSetActive(layout, mode != GP_TIME_MODE_FIX);
190 
191  uiItemR(layout, ptr, "use_custom_frame_range", 0, NULL, ICON_NONE);
192 }
193 
194 static void custom_range_panel_draw(const bContext *UNUSED(C), Panel *panel)
195 {
196  uiLayout *col;
197  uiLayout *layout = panel->layout;
198 
200 
201  int mode = RNA_enum_get(ptr, "mode");
202 
203  uiLayoutSetPropSep(layout, true);
204 
206  layout, (mode != GP_TIME_MODE_FIX) && (RNA_boolean_get(ptr, "use_custom_frame_range")));
207 
208  col = uiLayoutColumn(layout, true);
209  uiItemR(col, ptr, "frame_start", 0, IFACE_("Frame Start"), ICON_NONE);
210  uiItemR(col, ptr, "frame_end", 0, IFACE_("End"), ICON_NONE);
211 }
212 
213 static void mask_panel_draw(const bContext *UNUSED(C), Panel *panel)
214 {
215  gpencil_modifier_masking_panel_draw(panel, false, false);
216 }
217 
218 static void panelRegister(ARegionType *region_type)
219 {
221  region_type, eGpencilModifierType_Time, panel_draw);
223  "custom_range",
224  "",
227  panel_type);
229  region_type, "mask", "Influence", NULL, mask_panel_draw, panel_type);
230 }
231 
233  /* name */ N_("TimeOffset"),
234  /* structName */ "TimeGpencilModifierData",
235  /* structSize */ sizeof(TimeGpencilModifierData),
238 
239  /* copyData */ copyData,
240 
241  /* deformStroke */ NULL,
242  /* generateStrokes */ NULL,
243  /* bakeModifier */ NULL,
244  /* remapTime */ remapTime,
245 
246  /* initData */ initData,
247  /* freeData */ NULL,
248  /* isDisabled */ NULL,
249  /* updateDepsgraph */ NULL,
250  /* dependsOnTime */ NULL,
251  /* foreachIDLink */ NULL,
252  /* foreachTexLink */ NULL,
253  /* panelRegister */ panelRegister,
254 };
void BKE_gpencil_modifier_copydata_generic(const struct GpencilModifierData *md_src, struct GpencilModifierData *md_dst)
@ eGpencilModifierTypeFlag_NoApply
@ eGpencilModifierTypeType_Gpencil
#define BLI_assert(a)
Definition: BLI_assert.h:46
#define UNUSED(x)
#define MEMCMP_STRUCT_AFTER_IS_ZERO(struct_var, member)
#define MEMCPY_STRUCT_AFTER(struct_dst, struct_src, member)
#define STREQ(a, b)
#define CLAMP_MIN(a, b)
#define IFACE_(msgid)
struct Depsgraph Depsgraph
Definition: DEG_depsgraph.h:35
#define DNA_struct_default_get(struct_name)
Definition: DNA_defaults.h:29
@ GP_TIME_INVERT_LAYERPASS
@ eGpencilModifierType_Time
struct TimeGpencilModifierData TimeGpencilModifierData
PointerRNA * gpencil_modifier_panel_get_property_pointers(Panel *panel, PointerRNA *r_ob_ptr)
void gpencil_modifier_masking_panel_draw(Panel *panel, bool use_material, bool use_vertex)
void gpencil_modifier_panel_end(uiLayout *layout, PointerRNA *ptr)
PanelType * gpencil_modifier_subpanel_register(ARegionType *region_type, const char *name, const char *label, PanelDrawFn draw_header, PanelDrawFn draw, PanelType *parent)
PanelType * gpencil_modifier_panel_register(ARegionType *region_type, GpencilModifierType type, PanelDrawFn draw)
static int remapTime(struct GpencilModifierData *md, struct Depsgraph *UNUSED(depsgraph), struct Scene *scene, struct Object *UNUSED(ob), struct bGPDlayer *gpl, int cfra)
static void custom_range_header_draw(const bContext *UNUSED(C), Panel *panel)
static void mask_panel_draw(const bContext *UNUSED(C), Panel *panel)
static void copyData(const GpencilModifierData *md, GpencilModifierData *target)
static void panel_draw(const bContext *UNUSED(C), Panel *panel)
GpencilModifierTypeInfo modifierType_Gpencil_Time
static void panelRegister(ARegionType *region_type)
static void custom_range_panel_draw(const bContext *UNUSED(C), Panel *panel)
static void initData(GpencilModifierData *md)
#define C
Definition: RandGen.cpp:25
void uiLayoutSetActive(uiLayout *layout, bool active)
uiLayout * uiLayoutColumn(uiLayout *layout, bool align)
void uiLayoutSetPropSep(uiLayout *layout, bool is_sep)
uiLayout * uiLayoutRow(uiLayout *layout, bool align)
void uiItemR(uiLayout *layout, struct PointerRNA *ptr, const char *propname, int flag, const char *name, int icon)
Scene scene
const Depsgraph * depsgraph
uint col
ccl_gpu_kernel_postfix ccl_global float int int int int float bool int offset
T abs(const T &a)
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
Definition: rna_access.c:4863
int RNA_enum_get(PointerRNA *ptr, const char *name)
Definition: rna_access.c:5004
struct uiLayout * layout
struct RenderData r
char info[128]
#define N_(msgid)
PointerRNA * ptr
Definition: wm_files.c:3480