Blender  V2.93
MOD_gpenciltime.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) 2018, Blender Foundation
17  * This is a new part of Blender
18  */
19 
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <string.h>
27 
28 #include "BLI_utildefines.h"
29 
30 #include "BLT_translation.h"
31 
32 #include "DNA_defaults.h"
34 #include "DNA_gpencil_types.h"
35 #include "DNA_scene_types.h"
36 #include "DNA_screen_types.h"
37 
38 #include "BKE_context.h"
39 #include "BKE_gpencil_modifier.h"
40 #include "BKE_screen.h"
41 
42 #include "UI_interface.h"
43 #include "UI_resources.h"
44 
45 #include "RNA_access.h"
46 
48 #include "MOD_gpencil_ui_common.h"
49 
50 static void initData(GpencilModifierData *md)
51 {
53 
54  BLI_assert(MEMCMP_STRUCT_AFTER_IS_ZERO(gpmd, modifier));
55 
57 }
58 
59 static void copyData(const GpencilModifierData *md, GpencilModifierData *target)
60 {
62 }
63 
64 static int remapTime(struct GpencilModifierData *md,
65  struct Depsgraph *UNUSED(depsgraph),
66  struct Scene *scene,
67  struct Object *UNUSED(ob),
68  struct bGPDlayer *gpl,
69  int cfra)
70 {
72  const bool custom = mmd->flag & GP_TIME_CUSTOM_RANGE;
73  const bool invgpl = mmd->flag & GP_TIME_INVERT_LAYER;
74  const bool invpass = mmd->flag & GP_TIME_INVERT_LAYERPASS;
75  int sfra = custom ? mmd->sfra : scene->r.sfra;
76  int efra = custom ? mmd->efra : scene->r.efra;
77  CLAMP_MIN(sfra, 0);
78  CLAMP_MIN(efra, 0);
79 
80  /* Avoid inverse ranges. */
81  if (efra < sfra) {
82  return cfra;
83  }
84 
85  const int time_range = efra - sfra + 1;
86  int offset = mmd->offset;
87  int segments = 0;
88 
89  /* omit if filter by layer */
90  if (mmd->layername[0] != '\0') {
91  if (invgpl == false) {
92  if (!STREQ(mmd->layername, gpl->info)) {
93  return cfra;
94  }
95  }
96  else {
97  if (STREQ(mmd->layername, gpl->info)) {
98  return cfra;
99  }
100  }
101  }
102  /* verify pass */
103  if (mmd->layer_pass > 0) {
104  if (invpass == false) {
105  if (gpl->pass_index != mmd->layer_pass) {
106  return cfra;
107  }
108  }
109  else {
110  if (gpl->pass_index == mmd->layer_pass) {
111  return cfra;
112  }
113  }
114  }
115 
116  /* if fix mode, return predefined frame number */
117  if (mmd->mode == GP_TIME_MODE_FIX) {
118  return offset;
119  }
120 
121  /* invert current frame number */
122  if (mmd->mode == GP_TIME_MODE_REVERSE) {
123  cfra = efra - cfra + sfra;
124  }
125 
126  /* apply frame scale */
127  cfra *= mmd->frame_scale;
128 
129  /* verify offset never is greater than frame range */
130  if (abs(offset) > time_range) {
131  offset = offset - ((offset / time_range) * time_range);
132  }
133 
134  /* verify not outside range if loop is disabled */
135  if ((mmd->flag & GP_TIME_KEEP_LOOP) == 0) {
136  if (cfra + offset < sfra) {
137  return sfra;
138  }
139  if (cfra + offset > efra) {
140  return efra;
141  }
142  }
143 
144  /* check frames before start */
145  if (cfra < sfra) {
146  segments = ((cfra + sfra) / time_range);
147  cfra = cfra + (segments * time_range);
148  }
149 
150  /* check frames after end */
151  if (cfra > efra) {
152  segments = ((cfra - sfra) / time_range);
153  cfra = cfra - (segments * time_range);
154  }
155 
156  if (mmd->flag & GP_TIME_KEEP_LOOP) {
157  const int nfra = cfra + offset;
158 
159  /* if the sum of the cfra is out scene frame range, recalc */
160  if (cfra + offset < sfra) {
161  const int delta = abs(sfra - nfra);
162  return efra - delta + 1;
163  }
164  if (cfra + offset > efra) {
165  return nfra - efra + sfra - 1;
166  }
167  }
168 
169  return cfra + offset;
170 }
171 
172 static void panel_draw(const bContext *UNUSED(C), Panel *panel)
173 {
174  uiLayout *row, *col;
175  uiLayout *layout = panel->layout;
176 
178 
179  int mode = RNA_enum_get(ptr, "mode");
180 
181  uiLayoutSetPropSep(layout, true);
182 
183  uiItemR(layout, ptr, "mode", 0, NULL, ICON_NONE);
184 
185  col = uiLayoutColumn(layout, false);
186 
187  const char *text = (mode == GP_TIME_MODE_FIX) ? IFACE_("Frame") : IFACE_("Frame Offset");
188  uiItemR(col, ptr, "offset", 0, text, ICON_NONE);
189 
190  row = uiLayoutRow(col, false);
191  uiLayoutSetActive(row, mode != GP_TIME_MODE_FIX);
192  uiItemR(row, ptr, "frame_scale", 0, IFACE_("Scale"), ICON_NONE);
193 
194  row = uiLayoutRow(layout, false);
195  uiLayoutSetActive(row, mode != GP_TIME_MODE_FIX);
196  uiItemR(row, ptr, "use_keep_loop", 0, NULL, ICON_NONE);
197 
199 }
200 
201 static void custom_range_header_draw(const bContext *UNUSED(C), Panel *panel)
202 {
203  uiLayout *layout = panel->layout;
204 
206 
207  int mode = RNA_enum_get(ptr, "mode");
208 
209  uiLayoutSetActive(layout, mode != GP_TIME_MODE_FIX);
210 
211  uiItemR(layout, ptr, "use_custom_frame_range", 0, NULL, ICON_NONE);
212 }
213 
214 static void custom_range_panel_draw(const bContext *UNUSED(C), Panel *panel)
215 {
216  uiLayout *col;
217  uiLayout *layout = panel->layout;
218 
220 
221  int mode = RNA_enum_get(ptr, "mode");
222 
223  uiLayoutSetPropSep(layout, true);
224 
226  layout, (mode != GP_TIME_MODE_FIX) && (RNA_boolean_get(ptr, "use_custom_frame_range")));
227 
228  col = uiLayoutColumn(layout, true);
229  uiItemR(col, ptr, "frame_start", 0, IFACE_("Frame Start"), ICON_NONE);
230  uiItemR(col, ptr, "frame_end", 0, IFACE_("End"), ICON_NONE);
231 }
232 
233 static void mask_panel_draw(const bContext *UNUSED(C), Panel *panel)
234 {
235  gpencil_modifier_masking_panel_draw(panel, false, false);
236 }
237 
238 static void panelRegister(ARegionType *region_type)
239 {
241  region_type, eGpencilModifierType_Time, panel_draw);
243  "custom_range",
244  "",
247  panel_type);
249  region_type, "mask", "Influence", NULL, mask_panel_draw, panel_type);
250 }
251 
253  /* name */ "TimeOffset",
254  /* structName */ "TimeGpencilModifierData",
255  /* structSize */ sizeof(TimeGpencilModifierData),
258 
259  /* copyData */ copyData,
260 
261  /* deformStroke */ NULL,
262  /* generateStrokes */ NULL,
263  /* bakeModifier */ NULL,
264  /* remapTime */ remapTime,
265 
266  /* initData */ initData,
267  /* freeData */ NULL,
268  /* isDisabled */ NULL,
269  /* updateDepsgraph */ NULL,
270  /* dependsOnTime */ NULL,
271  /* foreachIDLink */ NULL,
272  /* foreachTexLink */ NULL,
273  /* panelRegister */ panelRegister,
274 };
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:58
#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:51
#define DNA_struct_default_get(struct_name)
Definition: DNA_defaults.h:44
@ 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:39
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
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
Definition: rna_access.c:6261
int RNA_enum_get(PointerRNA *ptr, const char *name)
Definition: rna_access.c:6402
struct uiLayout * layout
struct RenderData r
char info[128]
__forceinline const avxi abs(const avxi &a)
Definition: util_avxi.h:186
PointerRNA * ptr
Definition: wm_files.c:3157