#include "MEM_guardedalloc.h"
+ #include "DNA_action_types.h"
#include "DNA_scene_types.h"
#include "DNA_screen_types.h"
#include "DNA_space_types.h"
#include "BKE_context.h"
#include "BKE_global.h"
-#include "BKE_fcurve.h"
#include "BKE_utildefines.h"
#include "WM_api.h"
return &CTX_data_scene(C)->markers;
}
-/* Get the marker that is closest to this point */
-TimeMarker *ED_markers_find_nearest_marker (ListBase *markers, float x)
-{
- TimeMarker *marker, *nearest=NULL;
- float dist, min_dist= 1000000;
-
- if (markers) {
- for (marker= markers->first; marker; marker= marker->next) {
- dist = ABS((float)marker->frame - x);
-
- if (dist < min_dist) {
- min_dist= dist;
- nearest= marker;
- }
- }
- }
-
- return nearest;
-}
-
-/* Return the time of the marker that occurs on a frame closest to the given time */
-int ED_markers_find_nearest_marker_time (ListBase *markers, float x)
-{
- TimeMarker *nearest= ED_markers_find_nearest_marker(markers, x);
- return (nearest) ? (nearest->frame) : (int)floor(x + 0.5f);
-}
-
-
-void ED_markers_get_minmax (ListBase *markers, short sel, float *first, float *last)
-{
- TimeMarker *marker;
- float min, max;
- int selcount = 0;
-
- /* sanity check */
- if (markers == NULL) {
- *first = 0.0f;
- *last = 0.0f;
- return;
- }
-
- if (markers->first && markers->last) {
- TimeMarker *first= markers->first;
- TimeMarker *last= markers->last;
-
- min= first->frame;
- max= last->frame;
- }
- else {
- *first = 0.0f;
- *last = 0.0f;
- return;
- }
-
- /* count how many markers are usable - see later */
- if (sel) {
- for (marker= markers->first; marker; marker= marker->next) {
- if (marker->flag & SELECT)
- selcount++;
- }
- }
- else
- selcount= BLI_countlist(markers);
-
- /* if only selected are to be considered, only consider the selected ones
- * (optimisation for not searching list)
- */
- if (selcount > 1) {
- for (marker= markers->first; marker; marker= marker->next) {
- if (sel) {
- if (marker->flag & SELECT) {
- if (marker->frame < min)
- min= (float)marker->frame;
- else if (marker->frame > max)
- max= (float)marker->frame;
- }
- }
- else {
- if (marker->frame < min)
- min= marker->frame;
- else if (marker->frame > max)
- max= marker->frame;
- }
- }
- }
-
- /* set the min/max values */
- *first= min;
- *last= max;
-}
-
-/* Adds a marker to list of cfra elems */
-void add_marker_to_cfra_elem(ListBase *lb, TimeMarker *marker, short only_sel)
-{
- CfraElem *ce, *cen;
-
- /* should this one only be considered if it is selected? */
- if ((only_sel) && ((marker->flag & SELECT)==0))
- return;
-
- /* insertion sort - try to find a previous cfra elem */
- for (ce= lb->first; ce; ce= ce->next) {
- if (ce->cfra == marker->frame) {
- /* do because of double keys */
- if (marker->flag & SELECT)
- ce->sel= marker->flag;
- return;
- }
- else if (ce->cfra > marker->frame) break;
- }
-
- cen= MEM_callocN(sizeof(CfraElem), "add_to_cfra_elem");
- if (ce) BLI_insertlinkbefore(lb, ce, cen);
- else BLI_addtail(lb, cen);
-
- cen->cfra= marker->frame;
- cen->sel= marker->flag;
-}
-
-/* This function makes a list of all the markers. The only_sel
- * argument is used to specify whether only the selected markers
- * are added.
- */
-void ED_markers_make_cfra_list(ListBase *markers, ListBase *lb, short only_sel)
-{
- TimeMarker *marker;
-
- if (markers == NULL)
- return;
-
- for (marker= markers->first; marker; marker= marker->next)
- add_marker_to_cfra_elem(lb, marker, only_sel);
-}
-
/* ************* Marker Drawing ************ */
/* function to draw markers */
ypixels= v2d->mask.ymax-v2d->mask.ymin;
UI_view2d_getscale(v2d, &xscale, &yscale);
- glScalef(1.0/xscale, 1.0, 1.0);
+ glScalef(1.0f/xscale, 1.0f, 1.0f);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
/* vertical line - dotted */
+ // NOTE: currently only used for sequencer
if (flag & DRAW_MARKERS_LINES) {
setlinestyle(3);
glColor4ub(0, 0, 0, 96);
glBegin(GL_LINES);
- glVertex2f((xpos*xscale)+0.5, 12);
- glVertex2f((xpos*xscale)+0.5, 34*yscale); /* a bit lazy but we know it cant be greater then 34 strips high*/
+ glVertex2f((xpos*xscale)+0.5f, 12.0f);
+ glVertex2f((xpos*xscale)+0.5f, 34.0f*yscale); /* a bit lazy but we know it cant be greater then 34 strips high */
glEnd();
setlinestyle(0);
ICON_MARKER;
}
- UI_icon_draw(xpos*xscale-5.0, 16.0, icon_id);
+ UI_icon_draw(xpos*xscale-5.0f, 16.0f, icon_id);
glBlendFunc(GL_ONE, GL_ZERO);
glDisable(GL_BLEND);
if (marker->name && marker->name[0]) {
float x, y;
- if(marker->flag & SELECT) {
+ if (marker->flag & SELECT) {
UI_ThemeColor(TH_TEXT_HI);
- x= xpos*xscale+4.0;
- y= (ypixels<=39.0)?(ypixels-10.0):29.0;
+ x= xpos*xscale + 4.0f;
+ y= (ypixels <= 39.0f)? (ypixels-10.0f) : 29.0f;
}
else {
UI_ThemeColor(TH_TEXT);
if((marker->frame <= cfra) && (marker->frame+5 > cfra)) {
- x= xpos*xscale+4.0;
- y= (ypixels<=39.0)?(ypixels-10.0):29.0;
+ x= xpos*xscale + 4.0f;
+ y= (ypixels <= 39.0f)? (ypixels - 10.0f) : 29.0f;
}
else {
- x= xpos*xscale+4.0;
- y= 17.0;
+ x= xpos*xscale + 4.0f;
+ y= 17.0f;
}
}
UI_DrawString(x, y, marker->name);
}
- glScalef(xscale, 1.0, 1.0);
+
+ glScalef(xscale, 1.0f, 1.0f);
}
/* Draw Scene-Markers in time window */
View2D *v2d= UI_view2d_fromcontext(C);
TimeMarker *marker;
- if(markers == NULL)
+ if (markers == NULL)
return;
/* unselected markers are drawn at the first time */
for (marker= markers->first; marker; marker= marker->next) {
- if (!(marker->flag & SELECT)) draw_marker(v2d, marker, CTX_data_scene(C)->r.cfra, flag);
+ if ((marker->flag & SELECT) == 0)
+ draw_marker(v2d, marker, CTX_data_scene(C)->r.cfra, flag);
}
/* selected markers are drawn later */
for (marker= markers->first; marker; marker= marker->next) {
- if (marker->flag & SELECT) draw_marker(v2d, marker, CTX_data_scene(C)->r.cfra, flag);
+ if (marker->flag & SELECT)
+ draw_marker(v2d, marker, CTX_data_scene(C)->r.cfra, flag);
}
}
+
+
/* ************************** add markers *************************** */
/* add TimeMarker at curent frame */
TimeMarker *marker;
int frame= CTX_data_scene(C)->r.cfra;
- if(markers == NULL)
+ if (markers == NULL)
return OPERATOR_CANCELLED;
/* two markers can't be at the same place */
- for(marker= markers->first; marker; marker= marker->next)
- if(marker->frame == frame)
+ for (marker= markers->first; marker; marker= marker->next) {
+ if (marker->frame == frame)
return OPERATOR_CANCELLED;
+ }
/* deselect all */
for(marker= markers->first; marker; marker= marker->next)
{
MarkerMove *mm= op->customdata;
+ /* free data */
MEM_freeN(mm->oldframe);
MEM_freeN(op->customdata);
op->customdata= NULL;
+
+ /* clear custom header prints */
+ ED_area_headerprint(CTX_wm_area(C), NULL);
}
static int ed_marker_move_invoke(bContext *C, wmOperator *op, wmEvent *evt)
case ESCKEY:
ed_marker_move_cancel(C, op);
return OPERATOR_CANCELLED;
-
+
case LEFTMOUSE:
case MIDDLEMOUSE:
case RIGHTMOUSE:
break;
case MOUSEMOVE:
-
dx= v2d->mask.xmax-v2d->mask.xmin;
dx= (v2d->cur.xmax-v2d->cur.xmin)/dx;
sprintf(str, "Marker %.2f offset %.2f", FRA2TIME(selmarker->frame), FRA2TIME(offs));
}
else if (mm->slink->spacetype == SPACE_ACTION) {
- #if 0
- XXX if (saction->flag & SACTION_DRAWTIME)
+ SpaceAction *saction= (SpaceAction *)mm->slink;
+ if (saction->flag & SACTION_DRAWTIME)
sprintf(str, "Marker %.2f offset %.2f", FRA2TIME(selmarker->frame), FRA2TIME(offs));
else
sprintf(str, "Marker %.2f offset %.2f", (double)(selmarker->frame), (double)(offs));
- #endif
}
else {
sprintf(str, "Marker %.2f offset %.2f", (double)(selmarker->frame), (double)(offs));
else
sprintf(str, "Marker offset %.2f ", FRA2TIME(offs));
}
- #if 0
- XXX else if (mm->slink->spacetype == SPACE_ACTION) {
+ else if (mm->slink->spacetype == SPACE_ACTION) {
+ SpaceAction *saction= (SpaceAction *)mm->slink;
if (saction->flag & SACTION_DRAWTIME)
sprintf(str, "Marker offset %.2f ", FRA2TIME(offs));
else
sprintf(str, "Marker offset %.2f ", (double)(offs));
}
- #endif
else {
sprintf(str, "Marker offset %.2f ", (double)(offs));
}
}
WM_event_add_notifier(C, NC_SCENE|ND_MARKERS, NULL);
- // headerprint(str); XXX
+ ED_area_headerprint(CTX_wm_area(C), str);
}
}
ListBase *markers= context_get_markers(C);
TimeMarker *marker, *newmarker;
- if(markers == NULL) return;
+ if (markers == NULL)
+ return;
/* go through the list of markers, duplicate selected markers and add duplicated copies
- * to the begining of the list (unselect original markers) */
- for(marker= markers->first; marker; marker= marker->next) {
- if(marker->flag & SELECT){
+ * to the begining of the list (unselect original markers)
+ */
+ for (marker= markers->first; marker; marker= marker->next) {
+ if (marker->flag & SELECT) {
/* unselect selected marker */
marker->flag &= ~SELECT;
+
/* create and set up new marker */
newmarker = MEM_callocN(sizeof(TimeMarker), "TimeMarker");
newmarker->flag= SELECT;
newmarker->frame= marker->frame;
BLI_strncpy(newmarker->name, marker->name, sizeof(marker->name));
+
/* new marker is added to the begining of list */
BLI_addhead(markers, newmarker);
}
TimeMarker *marker;
int select=0;
- for(marker= markers->first; marker; marker= marker->next) {
+ for (marker= markers->first; marker; marker= marker->next) {
/* if Shift is not set, then deselect Markers */
- if(!shift) marker->flag &= ~SELECT;
+ if (!shift) marker->flag &= ~SELECT;
+
/* this way a not-shift select will allways give 1 selected marker */
- if((marker->frame == frame) && (!select)) {
- if(marker->flag & SELECT)
+ if ((marker->frame == frame) && (!select)) {
+ if (marker->flag & SELECT)
marker->flag &= ~SELECT;
else
marker->flag |= SELECT;
}
}
- int find_nearest_marker_time(ListBase *markers, float dx)
++int find_nearest_marker_time (ListBase *markers, float dx)
+{
+ TimeMarker *marker, *nearest= NULL;
+ float dist, min_dist= 1000000;
+
- for(marker= markers->first; marker; marker= marker->next) {
++ for (marker= markers->first; marker; marker= marker->next) {
+ dist = ABS((float)marker->frame - dx);
- if(dist < min_dist){
++ if (dist < min_dist) {
+ min_dist= dist;
+ nearest= marker;
+ }
+ }
+
- if(nearest) return nearest->frame;
++ if (nearest) return nearest->frame;
+ else return (int)floor(dx); /* hrmf? */
+}
+
+
static int ed_marker_select(bContext *C, wmEvent *evt, int extend)
{
ListBase *markers= context_get_markers(C);
UI_view2d_region_to_view(v2d, x, y, &viewx, NULL);
- cfra= ED_markers_find_nearest_marker_time(markers, viewx);
+ cfra= find_nearest_marker_time(markers, viewx);
if (extend)
select_timeline_marker_frame(markers, cfra, 1);
}
}
- if (changed)
+ if(changed) {
WM_event_add_notifier(C, NC_SCENE|ND_MARKERS, NULL);
-
+ }
return OPERATOR_FINISHED;
}
#include "RNA_access.h"
#include "RNA_define.h"
+ #include "RNA_enum_types.h"
#include "BKE_action.h"
#include "BKE_depsgraph.h"
/* ******************** Set Interpolation-Type Operator *********************** */
- /* defines for set ipo-type for selected keyframes tool */
- EnumPropertyItem prop_actkeys_ipo_types[] = {
- {BEZT_IPO_CONST, "CONSTANT", "Constant Interpolation", ""},
- {BEZT_IPO_LIN, "LINEAR", "Linear Interpolation", ""},
- {BEZT_IPO_BEZ, "BEZIER", "Bezier Interpolation", ""},
- {0, NULL, NULL, NULL}
- };
-
/* this function is responsible for setting interpolation mode for keyframes */
static void setipo_action_keys(bAnimContext *ac, short mode)
{
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
/* id-props */
- RNA_def_enum(ot->srna, "type", prop_actkeys_ipo_types, 0, "Type", "");
+ RNA_def_enum(ot->srna, "type", beztriple_interpolation_mode_items, 0, "Type", "");
}
/* ******************** Set Handle-Type Operator *********************** */
- /* defines for set handle-type for selected keyframes tool */
- EnumPropertyItem prop_actkeys_handletype_types[] = {
- {HD_AUTO, "AUTO", "Auto Handles", ""},
- {HD_VECT, "VECTOR", "Vector Handles", ""},
- {HD_FREE, "FREE", "Free Handles", ""},
- {HD_ALIGN, "ALIGN", "Aligned Handles", ""},
- // {-1, "TOGGLE", "Toggle between Free and Aligned Handles", ""},
- {0, NULL, NULL, NULL}
- };
-
/* this function is responsible for setting handle-type of selected keyframes */
static void sethandles_action_keys(bAnimContext *ac, short mode)
{
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
/* id-props */
- RNA_def_enum(ot->srna, "type", prop_actkeys_handletype_types, 0, "Type", "");
+ RNA_def_enum(ot->srna, "type", beztriple_handle_type_items, 0, "Type", "");
}
/* ************************************************************************** */
memset(&bed, 0, sizeof(BeztEditData));
bed.scene= ac->scene;
- bed.list= ac->scene->markers; /* for marker-snapping option */
/* snap keyframes */
for (ale= anim_data.first; ale; ale= ale->next) {
#include "RNA_access.h"
#include "RNA_define.h"
+ #include "RNA_enum_types.h"
#include "BKE_action.h"
#include "BKE_depsgraph.h"
/* ******************** Set Interpolation-Type Operator *********************** */
- /* defines for set ipo-type for selected keyframes tool */
- EnumPropertyItem prop_graphkeys_ipo_types[] = {
- {BEZT_IPO_CONST, "CONSTANT", "Constant Interpolation", ""},
- {BEZT_IPO_LIN, "LINEAR", "Linear Interpolation", ""},
- {BEZT_IPO_BEZ, "BEZIER", "Bezier Interpolation", ""},
- {0, NULL, NULL, NULL}
- };
-
/* this function is responsible for setting interpolation mode for keyframes */
static void setipo_graph_keys(bAnimContext *ac, short mode)
{
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
/* id-props */
- RNA_def_enum(ot->srna, "type", prop_graphkeys_ipo_types, 0, "Type", "");
+ RNA_def_enum(ot->srna, "type", beztriple_interpolation_mode_items, 0, "Type", "");
}
/* ******************** Set Handle-Type Operator *********************** */
- /* defines for set handle-type for selected keyframes tool */
- EnumPropertyItem prop_graphkeys_handletype_types[] = {
- {HD_AUTO, "AUTO", "Auto Handles", ""},
- {HD_VECT, "VECTOR", "Vector Handles", ""},
- {HD_FREE, "FREE", "Free Handles", ""},
- {HD_ALIGN, "ALIGN", "Aligned Handles", ""},
- // {-1, "TOGGLE", "Toggle between Free and Aligned Handles", ""},
- {0, NULL, NULL, NULL}
- };
-
/* this function is responsible for setting handle-type of selected keyframes */
static void sethandles_graph_keys(bAnimContext *ac, short mode)
{
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
/* id-props */
- RNA_def_enum(ot->srna, "type", prop_graphkeys_handletype_types, 0, "Type", "");
+ RNA_def_enum(ot->srna, "type", beztriple_handle_type_items, 0, "Type", "");
}
/* ************************************************************************** */
BeztEditFunc edit_cb;
/* filter data */
- filter= (ANIMFILTER_VISIBLE | ANIMFILTER_CURVEVISIBLE | ANIMFILTER_FOREDIT | ANIMFILTER_CURVESONLY);
+ filter= (ANIMFILTER_VISIBLE | ANIMFILTER_CURVEVISIBLE| ANIMFILTER_FOREDIT | ANIMFILTER_CURVESONLY);
ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype);
/* get beztriple editing callbacks */
memset(&bed, 0, sizeof(BeztEditData));
bed.scene= ac->scene;
- bed.list= ac->markers; /* for marker-snapping option */
/* snap keyframes */
for (ale= anim_data.first; ale; ale= ale->next) {
/* for 'first selected marker' mode, need to find first selected marker first! */
// XXX should this be made into a helper func in the API?
if (mode == GRAPHKEYS_MIRROR_MARKER) {
+ Scene *scene= ac->scene;
TimeMarker *marker= NULL;
/* find first selected marker */
- for (marker= ac->markers.first; marker; marker=marker->next) {
+ for (marker= scene->markers.first; marker; marker=marker->next) {
if (marker->flag & SELECT) {
break;
}
/* ******************** Add F-Curve Modifier Operator *********************** */
- /* F-Modifier types - duplicate of existing codes... */
- // XXX how can we have this list from the RNA definitions instead?
- EnumPropertyItem prop_fmodifier_types[] = {
- {FMODIFIER_TYPE_GENERATOR, "GENERATOR", "Generator", ""},
- {FMODIFIER_TYPE_ENVELOPE, "ENVELOPE", "Envelope", ""},
- {FMODIFIER_TYPE_CYCLES, "CYCLES", "Cycles", ""},
- {FMODIFIER_TYPE_NOISE, "NOISE", "Noise", ""},
- {FMODIFIER_TYPE_FILTER, "FILTER", "Filter", ""},
- {FMODIFIER_TYPE_PYTHON, "PYTHON", "Python", ""},
- {FMODIFIER_TYPE_LIMITS, "LIMITS", "Limits", ""},
- {0, NULL, NULL, NULL}
- };
-
static int graph_fmodifier_add_exec(bContext *C, wmOperator *op)
{
bAnimContext ac;
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
/* id-props */
- RNA_def_enum(ot->srna, "type", prop_fmodifier_types, 0, "Type", "");
+ RNA_def_enum(ot->srna, "type", fmodifier_type_items, 0, "Type", "");
}
/* ************************************************************************** */