26
24
* ***** END GPL LICENSE BLOCK *****
27
/** \file blender/editors/space_time/time_ops.c
29
32
#include <stdlib.h>
32
#include "MEM_guardedalloc.h"
34
35
#include "DNA_scene_types.h"
36
37
#include "BLI_blenlib.h"
38
#include "BLI_utildefines.h"
38
40
#include "BKE_context.h"
39
#include "BKE_utildefines.h"
42
42
#include "ED_screen.h"
45
44
#include "WM_api.h"
46
45
#include "WM_types.h"
47
#include "time_intern.h"
49
49
/* ****************** Start/End Frame Operators *******************************/
51
static int time_set_sfra_exec (bContext *C, wmOperator *op)
50
static int time_set_sfra_exec (bContext *C, wmOperator *UNUSED(op))
53
52
Scene *scene= CTX_data_scene(C);
57
56
return OPERATOR_CANCELLED;
59
/* if 'end frame' (Preview Range or Actual) is less than 'frame',
60
* clamp 'frame' to 'end frame'
62
if (PEFRA < frame) frame= PEFRA;
64
60
/* if Preview Range is defined, set the 'start' frame for that */
66
62
scene->r.psfra= frame;
68
64
scene->r.sfra= frame;
68
scene->r.pefra= frame;
70
73
WM_event_add_notifier(C, NC_SCENE|ND_FRAME, scene);
72
75
return OPERATOR_FINISHED;
75
void TIME_OT_start_frame_set (wmOperatorType *ot)
78
static void TIME_OT_start_frame_set (wmOperatorType *ot)
78
ot->name= "Set Start Frame";
79
ot->idname= "TIME_OT_start_frame_set";
80
ot->description="Set the start frame";
81
ot->name = "Set Start Frame";
82
ot->idname = "TIME_OT_start_frame_set";
83
ot->description = "Set the start frame";
82
85
/* api callbacks */
83
ot->exec= time_set_sfra_exec;
84
ot->poll= ED_operator_timeline_active;
86
ot->exec = time_set_sfra_exec;
87
ot->poll = ED_operator_timeline_active;
87
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
90
ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
91
static int time_set_efra_exec (bContext *C, wmOperator *op)
94
static int time_set_efra_exec (bContext *C, wmOperator *UNUSED(op))
93
96
Scene *scene= CTX_data_scene(C);
97
100
return OPERATOR_CANCELLED;
99
/* if 'start frame' (Preview Range or Actual) is greater than 'frame',
100
* clamp 'frame' to 'end frame'
102
if (PSFRA > frame) frame= PSFRA;
104
104
/* if Preview Range is defined, set the 'end' frame for that */
106
106
scene->r.pefra= frame;
108
108
scene->r.efra= frame;
112
scene->r.psfra= frame;
114
scene->r.sfra= frame;
110
117
WM_event_add_notifier(C, NC_SCENE|ND_FRAME, scene);
112
119
return OPERATOR_FINISHED;
115
void TIME_OT_end_frame_set (wmOperatorType *ot)
122
static void TIME_OT_end_frame_set (wmOperatorType *ot)
117
124
/* identifiers */
118
ot->name= "Set End Frame";
119
ot->idname= "TIME_OT_end_frame_set";
120
ot->description="Set the end frame";
125
ot->name = "Set End Frame";
126
ot->idname = "TIME_OT_end_frame_set";
127
ot->description = "Set the end frame";
122
129
/* api callbacks */
123
ot->exec= time_set_efra_exec;
124
ot->poll= ED_operator_timeline_active;
130
ot->exec = time_set_efra_exec;
131
ot->poll = ED_operator_timeline_active;
127
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
134
ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
130
137
/* ************************ View All Operator *******************************/
132
static int time_view_all_exec (bContext *C, wmOperator *op)
139
static int time_view_all_exec (bContext *C, wmOperator *UNUSED(op))
134
141
Scene *scene= CTX_data_scene(C);
135
142
ARegion *ar= CTX_wm_region(C);
136
143
View2D *v2d= (ar) ? &ar->v2d : NULL;
139
if ELEM(NULL, scene, ar)
146
if (ELEM(NULL, scene, ar))
140
147
return OPERATOR_CANCELLED;
142
149
/* set extents of view to start/end frames (Preview Range too) */
143
v2d->cur.xmin= (float)PSFRA;
144
v2d->cur.xmax= (float)PEFRA;
150
v2d->cur.xmin = (float)PSFRA;
151
v2d->cur.xmax = (float)PEFRA;
146
153
/* we need an extra "buffer" factor on either side so that the endpoints are visible */
147
154
extra= 0.01f * (v2d->cur.xmax - v2d->cur.xmin);
154
161
return OPERATOR_FINISHED;
157
void TIME_OT_view_all (wmOperatorType *ot)
164
static void TIME_OT_view_all (wmOperatorType *ot)
159
166
/* identifiers */
160
ot->name= "View All";
161
ot->idname= "TIME_OT_view_all";
162
ot->description= "Show the entire playable frame range";
167
ot->name = "View All";
168
ot->idname = "TIME_OT_view_all";
169
ot->description = "Show the entire playable frame range";
164
171
/* api callbacks */
165
ot->exec= time_view_all_exec;
166
ot->poll= ED_operator_timeline_active;
172
ot->exec = time_view_all_exec;
173
ot->poll = ED_operator_timeline_active;
169
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
176
ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
172
179
/* ************************** registration **********************************/
181
188
void time_keymap(wmKeyConfig *keyconf)
183
wmKeyMap *keymap= WM_keymap_find(keyconf, "Timeline", SPACE_TIME, 0);
190
wmKeyMap *keymap = WM_keymap_find(keyconf, "Timeline", SPACE_TIME, 0);
185
192
WM_keymap_add_item(keymap, "TIME_OT_start_frame_set", SKEY, KM_PRESS, 0, 0);
186
193
WM_keymap_add_item(keymap, "TIME_OT_end_frame_set", EKEY, KM_PRESS, 0, 0);