I started cleaning up UI_view2d_scale_get where the y scale was unused, then got carried away...

- for loop scope
- declare variables closer to where they are used
- move early exits closer to function start
- unsigned --> unsigned int
This commit is contained in:
Mike Erwin 2017-04-04 15:39:38 -04:00
parent db0f67f464
commit 125ce644f2
5 changed files with 116 additions and 172 deletions

View File

@ -71,17 +71,12 @@
/* Draw current frame number in a little green box beside the current frame indicator */
static void draw_cfra_number(Scene *scene, View2D *v2d, const float cfra, const bool time)
{
const uiFontStyle *fstyle = UI_FSTYLE_WIDGET;
VertexFormat *format = immVertexFormat();
unsigned int pos = add_attrib(format, "pos", GL_FLOAT, 2, KEEP_FLOAT);
unsigned char col[4];
float xscale, yscale, x, y;
char numstr[32] = " t"; /* t is the character to start replacing from */
int slen;
/* because the frame number text is subject to the same scaling as the contents of the view */
float xscale;
UI_view2d_scale_get(v2d, &xscale, NULL);
gpuPushMatrix();
UI_view2d_scale_get(v2d, &xscale, &yscale);
gpuScale2f(1.0f / xscale, 1.0f);
/* get timecode string
@ -96,11 +91,15 @@ static void draw_cfra_number(Scene *scene, View2D *v2d, const float cfra, const
BLI_timecode_string_from_time_seconds(&numstr[4], sizeof(numstr) - 4, 1, cfra);
}
slen = UI_fontstyle_string_width(fstyle, numstr) - 1;
const uiFontStyle *fstyle = UI_FSTYLE_WIDGET;
int slen = UI_fontstyle_string_width(fstyle, numstr) - 1;
/* get starting coordinates for drawing */
x = cfra * xscale;
y = 0.9f * U.widget_unit;
float x = cfra * xscale;
float y = 0.9f * U.widget_unit;
VertexFormat *format = immVertexFormat();
unsigned int pos = add_attrib(format, "pos", GL_FLOAT, 2, KEEP_FLOAT);
immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
@ -110,7 +109,8 @@ static void draw_cfra_number(Scene *scene, View2D *v2d, const float cfra, const
immRectf(pos, x, y, x + slen, y + 0.75f * U.widget_unit);
immUnbindProgram();
/* draw current frame number - black text */
/* draw current frame number */
unsigned char col[4];
UI_GetThemeColor4ubv(TH_TEXT, col);
UI_fontstyle_draw_simple(fstyle, x - 0.25f * U.widget_unit, y + 0.15f * U.widget_unit, numstr, col);

View File

@ -131,8 +131,7 @@ ListBase *ED_animcontext_get_markers(const bAnimContext *ac)
*/
int ED_markers_post_apply_transform(ListBase *markers, Scene *scene, int mode, float value, char side)
{
TimeMarker *marker;
float cfra = (float)CFRA;
const float cfra = (float)CFRA;
int changed_tot = 0;
/* sanity check */
@ -140,7 +139,7 @@ int ED_markers_post_apply_transform(ListBase *markers, Scene *scene, int mode, f
return changed_tot;
/* affect selected markers - it's unlikely that we will want to affect all in this way? */
for (marker = markers->first; marker; marker = marker->next) {
for (TimeMarker *marker = markers->first; marker; marker = marker->next) {
if (marker->flag & SELECT) {
switch (mode) {
case TFM_TIME_TRANSLATE:
@ -235,13 +234,12 @@ void ED_markers_get_minmax(ListBase *markers, short sel, float *first, float *la
/* Adds a marker to list of cfra elems */
static 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 */
CfraElem *ce;
for (ce = lb->first; ce; ce = ce->next) {
if (ce->cfra == marker->frame) {
/* do because of double keys */
@ -254,7 +252,7 @@ static void add_marker_to_cfra_elem(ListBase *lb, TimeMarker *marker, short only
}
}
cen = MEM_callocN(sizeof(CfraElem), "add_to_cfra_elem");
CfraElem *cen = MEM_callocN(sizeof(CfraElem), "add_to_cfra_elem");
if (ce) BLI_insertlinkbefore(lb, ce, cen);
else BLI_addtail(lb, cen);
@ -268,8 +266,6 @@ static void add_marker_to_cfra_elem(ListBase *lb, TimeMarker *marker, short only
*/
void ED_markers_make_cfra_list(ListBase *markers, ListBase *lb, short only_sel)
{
TimeMarker *marker;
if (lb) {
/* Clear the list first, since callers have no way of knowing
* whether this terminated early otherwise. This may lead
@ -285,7 +281,7 @@ void ED_markers_make_cfra_list(ListBase *markers, ListBase *lb, short only_sel)
return;
}
for (marker = markers->first; marker; marker = marker->next)
for (TimeMarker *marker = markers->first; marker; marker = marker->next)
add_marker_to_cfra_elem(lb, marker, only_sel);
}
@ -294,10 +290,8 @@ void ED_markers_make_cfra_list(ListBase *markers, ListBase *lb, short only_sel)
/* Get the first selected marker */
TimeMarker *ED_markers_get_first_selected(ListBase *markers)
{
TimeMarker *marker;
if (markers) {
for (marker = markers->first; marker; marker = marker->next) {
for (TimeMarker *marker = markers->first; marker; marker = marker->next) {
if (marker->flag & SELECT)
return marker;
}
@ -313,8 +307,6 @@ TimeMarker *ED_markers_get_first_selected(ListBase *markers)
*/
void debug_markers_print_list(ListBase *markers)
{
TimeMarker *marker;
if (markers == NULL) {
printf("No markers list to print debug for\n");
return;
@ -322,7 +314,7 @@ void debug_markers_print_list(ListBase *markers)
printf("List of markers follows: -----\n");
for (marker = markers->first; marker; marker = marker->next) {
for (TimeMarker *marker = markers->first; marker; marker = marker->next) {
printf("\t'%s' on %d at %p with %u\n", marker->name, marker->frame, (void *)marker, marker->flag);
}
@ -391,7 +383,7 @@ static void draw_marker(
float x, y;
/* minimal y coordinate which wouldn't be occluded by scroll */
int min_y = 17.0f * UI_DPI_FAC;
const int min_y = 17.0f * UI_DPI_FAC;
if (marker->flag & SELECT) {
UI_GetThemeColor4ubv(TH_TEXT_HI, text_col);
@ -427,22 +419,14 @@ void ED_markers_draw(const bContext *C, int flag)
{
const uiFontStyle *fstyle = UI_FSTYLE_WIDGET;
ListBase *markers = ED_context_get_markers(C);
View2D *v2d;
TimeMarker *marker;
Scene *scene;
int select_pass;
int v2d_clip_range_x[2];
float font_width_max;
/* cache values */
float ypixels, xscale, yscale;
if (markers == NULL || BLI_listbase_is_empty(markers)) {
return;
}
scene = CTX_data_scene(C);
v2d = UI_view2d_fromcontext(C);
Scene *scene = CTX_data_scene(C);
View2D *v2d = UI_view2d_fromcontext(C);
if (flag & DRAW_MARKERS_MARGIN) {
unsigned int pos = add_attrib(immVertexFormat(), "pos", GL_FLOAT, 2, KEEP_FLOAT);
@ -462,18 +446,21 @@ void ED_markers_draw(const bContext *C, int flag)
}
/* no time correction for framelen! space is drawn with old values */
ypixels = BLI_rcti_size_y(&v2d->mask);
float ypixels = BLI_rcti_size_y(&v2d->mask);
float xscale, yscale;
UI_view2d_scale_get(v2d, &xscale, &yscale);
gpuPushMatrix();
gpuScale2f(1.0f / xscale, 1.0f);
/* x-bounds with offset for text (adjust for long string, avoid checking string width) */
font_width_max = (10 * UI_DPI_FAC) / xscale;
v2d_clip_range_x[0] = v2d->cur.xmin - (sizeof(marker->name) * font_width_max);
v2d_clip_range_x[1] = v2d->cur.xmax + font_width_max;
float font_width_max = (10 * UI_DPI_FAC) / xscale;
int v2d_clip_range_x[2] = {
v2d->cur.xmin - (sizeof(marker->name) * font_width_max),
v2d->cur.xmax + font_width_max
};
/* loop [unselected, selected] */
for (select_pass = 0; select_pass <= SELECT; select_pass += SELECT) {
for (int select_pass = 0; select_pass <= SELECT; select_pass += SELECT) {
/* unselected markers are drawn at the first time */
for (marker = markers->first; marker; marker = marker->next) {
if ((marker->flag & SELECT) == select_pass) {
@ -834,9 +821,9 @@ static void ed_marker_move_apply(bContext *C, wmOperator *op)
#endif
MarkerMove *mm = op->customdata;
TimeMarker *marker;
int a, offs;
offs = RNA_int_get(op->ptr, "frames");
const int offs = RNA_int_get(op->ptr, "frames");
int a;
for (a = 0, marker = mm->markers->first; marker; marker = marker->next) {
if (marker->flag & SELECT) {
marker->frame = mm->oldframe[a] + offs;
@ -1007,21 +994,20 @@ static void MARKER_OT_move(wmOperatorType *ot)
static void ed_marker_duplicate_apply(bContext *C)
{
ListBase *markers = ED_context_get_markers(C);
TimeMarker *marker, *newmarker;
if (markers == NULL)
if (markers == NULL)
return;
/* go through the list of markers, duplicate selected markers and add duplicated copies
* to the beginning of the list (unselect original markers)
*/
for (marker = markers->first; marker; marker = marker->next) {
for (TimeMarker *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");
TimeMarker *newmarker = MEM_callocN(sizeof(TimeMarker), "TimeMarker");
newmarker->flag = SELECT;
newmarker->frame = marker->frame;
BLI_strncpy(newmarker->name, marker->name, sizeof(marker->name));
@ -1117,25 +1103,20 @@ static int ed_marker_select(bContext *C, const wmEvent *event, bool extend, bool
ListBase *markers = ED_context_get_markers(C);
ARegion *ar = CTX_wm_region(C);
View2D *v2d = UI_view2d_fromcontext(C);
float viewx;
int x, cfra;
if (markers == NULL)
return OPERATOR_PASS_THROUGH;
x = event->x - ar->winrct.xmin;
viewx = UI_view2d_region_to_view_x(v2d, x);
cfra = ED_markers_find_nearest_marker_time(markers, viewx);
const int x = event->x - ar->winrct.xmin;
const float viewx = UI_view2d_region_to_view_x(v2d, x);
const int cfra = ED_markers_find_nearest_marker_time(markers, viewx);
select_timeline_marker_frame(markers, cfra, extend);
#ifdef DURIAN_CAMERA_SWITCH
if (camera) {
Scene *scene = CTX_data_scene(C);
BaseLegacy *base;
TimeMarker *marker;
int sel = 0;
@ -1152,7 +1133,7 @@ static int ed_marker_select(bContext *C, const wmEvent *event, bool extend, bool
for (marker = markers->first; marker; marker = marker->next) {
if (marker->camera) {
if (marker->frame == cfra) {
base = BKE_scene_base_find(scene, marker->camera);
BaseLegacy *base = BKE_scene_base_find(scene, marker->camera);
if (base) {
ED_base_object_select(base, sel);
if (sel)
@ -1192,8 +1173,6 @@ static int ed_marker_select_invoke_wrapper(bContext *C, wmOperator *op, const wm
static void MARKER_OT_select(wmOperatorType *ot)
{
PropertyRNA *prop;
/* identifiers */
ot->name = "Select Time Marker";
ot->description = "Select time marker(s)";
@ -1206,7 +1185,7 @@ static void MARKER_OT_select(wmOperatorType *ot)
/* flags */
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
prop = RNA_def_boolean(ot->srna, "extend", 0, "Extend", "Extend the selection");
PropertyRNA *prop = RNA_def_boolean(ot->srna, "extend", 0, "Extend", "Extend the selection");
RNA_def_property_flag(prop, PROP_SKIP_SAVE);
#ifdef DURIAN_CAMERA_SWITCH
prop = RNA_def_boolean(ot->srna, "camera", 0, "Camera", "Select the camera");
@ -1237,9 +1216,11 @@ static void MARKER_OT_select(wmOperatorType *ot)
static int ed_marker_border_select_exec(bContext *C, wmOperator *op)
{
View2D *v2d = UI_view2d_fromcontext(C);
ListBase *markers = ED_context_get_markers(C);
TimeMarker *marker;
if (markers == NULL)
return 0;
View2D *v2d = UI_view2d_fromcontext(C);
int gesture_mode = RNA_int_get(op->ptr, "gesture_mode");
bool extend = RNA_boolean_get(op->ptr, "extend");
rctf rect;
@ -1247,11 +1228,8 @@ static int ed_marker_border_select_exec(bContext *C, wmOperator *op)
WM_operator_properties_border_to_rctf(op, &rect);
UI_view2d_region_to_view_rctf(v2d, &rect, &rect);
if (markers == NULL)
return 0;
/* XXX marker context */
for (marker = markers->first; marker; marker = marker->next) {
for (TimeMarker *marker = markers->first; marker; marker = marker->next) {
if (BLI_rctf_isect_x(&rect, marker->frame)) {
switch (gesture_mode) {
case GESTURE_MODAL_SELECT:
@ -1305,17 +1283,17 @@ static void MARKER_OT_select_border(wmOperatorType *ot)
static int ed_marker_select_all_exec(bContext *C, wmOperator *op)
{
ListBase *markers = ED_context_get_markers(C);
TimeMarker *marker;
int action = RNA_enum_get(op->ptr, "action");
if (markers == NULL)
return OPERATOR_CANCELLED;
int action = RNA_enum_get(op->ptr, "action");
if (action == SEL_TOGGLE) {
action = (ED_markers_get_first_selected(markers) != NULL) ? SEL_DESELECT : SEL_SELECT;
}
for (marker = markers->first; marker; marker = marker->next) {
for (TimeMarker *marker = markers->first; marker; marker = marker->next) {
switch (action) {
case SEL_SELECT:
marker->flag |= SELECT;
@ -1360,13 +1338,13 @@ static void MARKER_OT_select_all(wmOperatorType *ot)
static int ed_marker_delete_exec(bContext *C, wmOperator *UNUSED(op))
{
ListBase *markers = ED_context_get_markers(C);
TimeMarker *marker, *nmarker;
bool changed = false;
if (markers == NULL)
return OPERATOR_CANCELLED;
for (marker = markers->first; marker; marker = nmarker) {
bool changed = false;
TimeMarker *nmarker;
for (TimeMarker *marker = markers->first; marker; marker = nmarker) {
nmarker = marker->next;
if (marker->flag & SELECT) {
BLI_freelinkN(markers, marker);
@ -1462,7 +1440,6 @@ static int ed_marker_make_links_scene_exec(bContext *C, wmOperator *op)
{
ListBase *markers = ED_context_get_markers(C);
Scene *scene_to = BLI_findlink(&CTX_data_main(C)->scene, RNA_enum_get(op->ptr, "scene"));
TimeMarker *marker, *marker_new;
if (scene_to == NULL) {
BKE_report(op->reports, RPT_ERROR, "Scene not found");
@ -1480,9 +1457,9 @@ static int ed_marker_make_links_scene_exec(bContext *C, wmOperator *op)
}
/* copy markers */
for (marker = markers->first; marker; marker = marker->next) {
for (TimeMarker *marker = markers->first; marker; marker = marker->next) {
if (marker->flag & SELECT) {
marker_new = MEM_dupallocN(marker);
TimeMarker *marker_new = MEM_dupallocN(marker);
marker_new->prev = marker_new->next = NULL;
BLI_addtail(&scene_to->markers, marker_new);
@ -1499,8 +1476,6 @@ static int ed_marker_make_links_scene_invoke_wrapper(bContext *C, wmOperator *op
static void MARKER_OT_make_links_scene(wmOperatorType *ot)
{
PropertyRNA *prop;
/* identifiers */
ot->name = "Make Links to Scene";
ot->description = "Copy selected markers to another scene";
@ -1515,11 +1490,10 @@ static void MARKER_OT_make_links_scene(wmOperatorType *ot)
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
/* properties */
prop = RNA_def_enum(ot->srna, "scene", DummyRNA_NULL_items, 0, "Scene", "");
PropertyRNA *prop = RNA_def_enum(ot->srna, "scene", DummyRNA_NULL_items, 0, "Scene", "");
RNA_def_enum_funcs(prop, RNA_scene_itemf);
RNA_def_property_flag(prop, PROP_ENUM_NO_TRANSLATE);
ot->prop = prop;
}
#ifdef DURIAN_CAMERA_SWITCH
@ -1527,15 +1501,14 @@ static void MARKER_OT_make_links_scene(wmOperatorType *ot)
static int ed_marker_camera_bind_exec(bContext *C, wmOperator *UNUSED(op))
{
ListBase *markers = ED_context_get_markers(C);
TimeMarker *marker = ED_markers_get_first_selected(markers);
if (marker == NULL)
return OPERATOR_CANCELLED;
bScreen *sc = CTX_wm_screen(C);
Scene *scene = CTX_data_scene(C);
Object *ob = CTX_data_active_object(C);
ListBase *markers = ED_context_get_markers(C);
TimeMarker *marker;
marker = ED_markers_get_first_selected(markers);
if (marker == NULL)
return OPERATOR_CANCELLED;
marker->camera = ob;

View File

@ -576,7 +576,6 @@ void ui_draw_aligned_panel(uiStyle *style, uiBlock *block, const rcti *rect, con
Panel *panel = block->panel;
rcti headrect;
rctf itemrect;
int ofsx;
float color[4];
const bool is_closed_x = (panel->flag & PNL_CLOSEDX) ? true : false;
const bool is_closed_y = (panel->flag & PNL_CLOSEDY) ? true : false;
@ -716,12 +715,11 @@ void ui_draw_aligned_panel(uiStyle *style, uiBlock *block, const rcti *rect, con
/* draw optional close icon */
ofsx = 6;
if (panel->control & UI_PNL_CLOSE) {
const int ofsx = 6;
immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
immUniformThemeColor(TH_TITLE);
ui_draw_x_icon(pos, rect->xmin + 2 + ofsx, rect->ymax + 2);
ofsx = 22;
immUnbindProgram();
}
@ -741,9 +739,6 @@ void ui_draw_aligned_panel(uiStyle *style, uiBlock *block, const rcti *rect, con
ui_draw_tria_rect(&itemrect, 'h');
else
ui_draw_tria_rect(&itemrect, 'v');
(void)ofsx;
}
/************************** panel alignment *************************/

View File

@ -66,18 +66,17 @@ void clip_graph_tracking_values_iterate_track(
void (*segment_end)(void *userdata, int coord))
{
MovieClip *clip = ED_space_clip_get_clip(sc);
int width, height, coord;
int width, height;
BKE_movieclip_get_size(clip, &sc->user, &width, &height);
for (coord = 0; coord < 2; coord++) {
int i, prevfra = 0;
for (int coord = 0; coord < 2; coord++) {
int prevfra = 0;
bool open = false;
float prevval = 0.0f;
for (i = 0; i < track->markersnr; i++) {
for (int i = 0; i < track->markersnr; i++) {
MovieTrackingMarker *marker = &track->markers[i];
float val;
if (marker->flag & MARKER_DISABLED) {
if (open) {
@ -105,7 +104,7 @@ void clip_graph_tracking_values_iterate_track(
}
/* value is a pixels per frame speed */
val = (marker->pos[coord] - prevval) * ((coord == 0) ? (width) : (height));
float val = (marker->pos[coord] - prevval) * ((coord == 0) ? (width) : (height));
val /= marker->framenr - prevfra;
if (func) {
@ -135,9 +134,8 @@ void clip_graph_tracking_values_iterate(
MovieClip *clip = ED_space_clip_get_clip(sc);
MovieTracking *tracking = &clip->tracking;
ListBase *tracksbase = BKE_tracking_get_active_tracks(tracking);
MovieTrackingTrack *track;
for (track = tracksbase->first; track; track = track->next) {
for (MovieTrackingTrack *track = tracksbase->first; track; track = track->next) {
if (!include_hidden && (track->flag & TRACK_HIDDEN) != 0)
continue;
@ -154,10 +152,8 @@ void clip_graph_tracking_iterate(SpaceClip *sc, bool selected_only, bool include
MovieClip *clip = ED_space_clip_get_clip(sc);
MovieTracking *tracking = &clip->tracking;
ListBase *tracksbase = BKE_tracking_get_active_tracks(tracking);
MovieTrackingTrack *track;
for (track = tracksbase->first; track; track = track->next) {
int i;
for (MovieTrackingTrack *track = tracksbase->first; track; track = track->next) {
if (!include_hidden && (track->flag & TRACK_HIDDEN) != 0)
continue;
@ -165,7 +161,7 @@ void clip_graph_tracking_iterate(SpaceClip *sc, bool selected_only, bool include
if (selected_only && !TRACK_SELECTED(track))
continue;
for (i = 0; i < track->markersnr; i++) {
for (int i = 0; i < track->markersnr; i++) {
MovieTrackingMarker *marker = &track->markers[i];
if (marker->flag & MARKER_DISABLED)
@ -246,7 +242,7 @@ void clip_draw_cfra(SpaceClip *sc, ARegion *ar, Scene *scene)
View2D *v2d = &ar->v2d;
float x = (float)(sc->user.framenr * scene->r.framelen);
unsigned pos = add_attrib(immVertexFormat(), "pos", GL_FLOAT, 2, KEEP_FLOAT);
unsigned int pos = add_attrib(immVertexFormat(), "pos", GL_FLOAT, 2, KEEP_FLOAT);
immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
immUniformThemeColor(TH_CFRAME);
@ -262,8 +258,8 @@ void clip_draw_cfra(SpaceClip *sc, ARegion *ar, Scene *scene)
UI_view2d_view_orthoSpecial(ar, v2d, 1);
/* because the frame number text is subject to the same scaling as the contents of the view */
float xscale, yscale;
UI_view2d_scale_get(v2d, &xscale, &yscale);
float xscale;
UI_view2d_scale_get(v2d, &xscale, NULL);
gpuPushMatrix();
gpuScale2f(1.0f / xscale, 1.0f);
@ -281,7 +277,7 @@ void clip_draw_sfra_efra(View2D *v2d, Scene *scene)
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);
unsigned pos = add_attrib(immVertexFormat(), "pos", GL_FLOAT, 2, KEEP_FLOAT);
unsigned int pos = add_attrib(immVertexFormat(), "pos", GL_FLOAT, 2, KEEP_FLOAT);
immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
immUniformColor4f(0.0f, 0.0f, 0.0f, 0.4f);

View File

@ -462,28 +462,21 @@ static void draw_fcurve_samples(SpaceIpo *sipo, ARegion *ar, FCurve *fcu)
/* helper func - just draw the F-Curve by sampling the visible region (for drawing curves with modifiers) */
static void draw_fcurve_curve(bAnimContext *ac, ID *id, FCurve *fcu, View2D *v2d, View2DGrid *grid, unsigned int pos)
{
SpaceIpo *sipo = (SpaceIpo *)ac->sl;
ChannelDriver *driver;
float samplefreq;
float stime, etime;
float unitFac, offset;
float dx, dy;
short mapping_flag = ANIM_get_normalization_flags(ac);
int i, n;
/* when opening a blend file on a different sized screen or while dragging the toolbar this can happen
* best just bail out in this case */
float dx, dy;
UI_view2d_grid_size(grid, &dx, &dy);
if (dx <= 0.0f)
return;
/* disable any drivers temporarily */
driver = fcu->driver;
ChannelDriver *driver = fcu->driver;
fcu->driver = NULL;
/* compute unit correction factor */
unitFac = ANIM_unit_mapping_get_factor(ac->scene, id, fcu, mapping_flag, &offset);
float offset;
const short mapping_flag = ANIM_get_normalization_flags(ac);
const float unitFac = ANIM_unit_mapping_get_factor(ac->scene, id, fcu, mapping_flag, &offset);
/* Note about sampling frequency:
* Ideally, this is chosen such that we have 1-2 pixels = 1 segment
@ -499,8 +492,9 @@ static void draw_fcurve_curve(bAnimContext *ac, ID *id, FCurve *fcu, View2D *v2d
*/
/* grid->dx represents the number of 'frames' between gridlines, but we divide by U.v2d_min_gridsize to get pixels-steps */
/* TODO: perhaps we should have 1.0 frames as upper limit so that curves don't get too distorted? */
samplefreq = dx / (U.v2d_min_gridsize * U.pixelsize);
float samplefreq = dx / (U.v2d_min_gridsize * U.pixelsize);
SpaceIpo *sipo = (SpaceIpo *)ac->sl;
if (sipo->flag & SIPO_BEAUTYDRAW_OFF) {
/* Low Precision = coarse lower-bound clamping
*
@ -522,8 +516,8 @@ static void draw_fcurve_curve(bAnimContext *ac, ID *id, FCurve *fcu, View2D *v2d
/* the start/end times are simply the horizontal extents of the 'cur' rect */
stime = v2d->cur.xmin;
etime = v2d->cur.xmax + samplefreq; /* + samplefreq here so that last item gets included... */
const float stime = v2d->cur.xmin;
const float etime = v2d->cur.xmax + samplefreq; /* + samplefreq here so that last item gets included... */
/* at each sampling interval, add a new vertex
@ -531,12 +525,12 @@ static void draw_fcurve_curve(bAnimContext *ac, ID *id, FCurve *fcu, View2D *v2d
* the displayed values appear correctly in the viewport
*/
n = (etime - stime) / samplefreq + 0.5f;
const int n = (etime - stime) / samplefreq + 0.5f;
if (n > 0) {
immBegin(PRIM_LINE_STRIP, (n + 1));
for (i = 0; i <= n; i++) {
for (int i = 0; i <= n; i++) {
float ctime = stime + i * samplefreq;
immVertex2f(pos, ctime, (evaluate_fcurve(fcu, ctime) + offset) * unitFac);
}
@ -554,22 +548,22 @@ static void draw_fcurve_curve_samples(bAnimContext *ac, ID *id, FCurve *fcu, Vie
FPoint *prevfpt = fcu->fpt;
FPoint *fpt = prevfpt + 1;
float fac, v[2];
int b = fcu->totvert;
float unit_scale, offset;
short mapping_flag = ANIM_get_normalization_flags(ac);
int count = fcu->totvert;
if (prevfpt->vec[0] > v2d->cur.xmin) {
count++;
}
int b = fcu->totvert;
if ((prevfpt + b - 1)->vec[0] < v2d->cur.xmax) {
count++;
}
/* apply unit mapping */
float offset;
const short mapping_flag = ANIM_get_normalization_flags(ac);
const float unit_scale = ANIM_unit_mapping_get_factor(ac->scene, id, fcu, mapping_flag, &offset);
gpuPushMatrix();
unit_scale = ANIM_unit_mapping_get_factor(ac->scene, id, fcu, mapping_flag, &offset);
gpuScale2f(1.0f, unit_scale);
gpuTranslate2f(0.0f, offset);
@ -654,22 +648,20 @@ static void draw_fcurve_curve_bezts(bAnimContext *ac, ID *id, FCurve *fcu, View2
BezTriple *prevbezt = fcu->bezt;
BezTriple *bezt = prevbezt + 1;
float v1[2], v2[2], v3[2], v4[2];
float *fp, data[120];
float fac = 0.0f;
int b = fcu->totvert - 1;
int resol;
float unit_scale, offset;
short mapping_flag = ANIM_get_normalization_flags(ac);
/* apply unit mapping */
float offset;
const short mapping_flag = ANIM_get_normalization_flags(ac);
const float unit_scale = ANIM_unit_mapping_get_factor(ac->scene, id, fcu, mapping_flag, &offset);
gpuPushMatrix();
unit_scale = ANIM_unit_mapping_get_factor(ac->scene, id, fcu, mapping_flag, &offset);
gpuScale2f(1.0f, unit_scale);
gpuTranslate2f(0.0f, offset);
/* For now, this assumes the worst case scenario, where all the keyframes have
* bezier interpolation, and are drawn at full res.
* This is tricky to optimize, but maybe can be improved at some point... */
int b = fcu->totvert - 1;
immBeginAtMost(PRIM_LINE_STRIP, (b * 32 + 3));
/* extrapolate to left? */
@ -725,10 +717,8 @@ static void draw_fcurve_curve_bezts(bAnimContext *ac, ID *id, FCurve *fcu, View2
immVertex2fv(pos, v1);
}
else if (prevbezt->ipo == BEZT_IPO_BEZ) {
/* Bezier-Interpolation: draw curve as series of segments between keyframes
* - resol determines number of points to sample in between keyframes
*/
/* Bezier-Interpolation: draw curve as series of segments between keyframes */
int resol; /* determines number of points to sample in between keyframes */
/* resol depends on distance between points (not just horizontal) OR is a fixed high res */
/* TODO: view scale should factor into this someday too... */
if (fcu->driver) {
@ -760,11 +750,13 @@ static void draw_fcurve_curve_bezts(bAnimContext *ac, ID *id, FCurve *fcu, View2
v4[1] = bezt->vec[1][1];
correct_bezpart(v1, v2, v3, v4);
float data[120];
BKE_curve_forward_diff_bezier(v1[0], v2[0], v3[0], v4[0], data, resol, sizeof(float) * 3);
BKE_curve_forward_diff_bezier(v1[1], v2[1], v3[1], v4[1], data + 1, resol, sizeof(float) * 3);
for (fp = data; resol; resol--, fp += 3) {
for (const float *fp = data; resol; resol--, fp += 3) {
immVertex2fv(pos, fp);
}
}
@ -824,9 +816,9 @@ static void graph_draw_driver_debug(bAnimContext *ac, ID *id, FCurve *fcu)
{
ChannelDriver *driver = fcu->driver;
View2D *v2d = &ac->ar->v2d;
short mapping_flag = ANIM_get_normalization_flags(ac);
const short mapping_flag = ANIM_get_normalization_flags(ac);
float offset;
float unitfac = ANIM_unit_mapping_get_factor(ac->scene, id, fcu, mapping_flag, &offset);
const float unitfac = ANIM_unit_mapping_get_factor(ac->scene, id, fcu, mapping_flag, &offset);
/* for now, only show when debugging driver... */
//if ((driver->flag & DRIVER_FLAG_SHOWDEBUG) == 0)
@ -839,8 +831,6 @@ static void graph_draw_driver_debug(bAnimContext *ac, ID *id, FCurve *fcu)
* => We still want to show the 1-1 default...
*/
if ((fcu->totvert == 0) && BLI_listbase_is_empty(&fcu->modifiers)) {
float t;
/* draw with thin dotted lines in style of what curve would have been */
immUniformColor3fv(fcu->color);
@ -852,7 +842,7 @@ static void graph_draw_driver_debug(bAnimContext *ac, ID *id, FCurve *fcu)
*/
immBegin(PRIM_LINES, 2);
t = v2d->cur.xmin;
float t = v2d->cur.xmin;
immVertex2f(pos, t, (t + offset) * unitfac);
t = v2d->cur.xmax;
@ -933,8 +923,6 @@ static void graph_draw_driver_debug(bAnimContext *ac, ID *id, FCurve *fcu)
*/
void graph_draw_ghost_curves(bAnimContext *ac, SpaceIpo *sipo, ARegion *ar)
{
FCurve *fcu;
/* draw with thick dotted lines */
setlinestyle(10);
glLineWidth(3.0f);
@ -947,7 +935,7 @@ void graph_draw_ghost_curves(bAnimContext *ac, SpaceIpo *sipo, ARegion *ar)
immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
/* the ghost curves are simply sampled F-Curves stored in sipo->ghostCurves */
for (fcu = sipo->ghostCurves.first; fcu; fcu = fcu->next) {
for (FCurve *fcu = sipo->ghostCurves.first; fcu; fcu = fcu->next) {
/* set whatever color the curve has set
* - this is set by the function which creates these
* - draw with a fixed opacity of 2
@ -972,20 +960,16 @@ void graph_draw_ghost_curves(bAnimContext *ac, SpaceIpo *sipo, ARegion *ar)
*/
void graph_draw_curves(bAnimContext *ac, SpaceIpo *sipo, ARegion *ar, View2DGrid *grid, short sel)
{
ListBase anim_data = {NULL, NULL};
bAnimListElem *ale;
int filter;
/* build list of curves to draw */
filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_CURVE_VISIBLE);
filter |= ((sel) ? (ANIMFILTER_SEL) : (ANIMFILTER_UNSEL));
ListBase anim_data = {NULL, NULL};
const int filter = ANIMFILTER_DATA_VISIBLE | ANIMFILTER_CURVE_VISIBLE | (sel ? ANIMFILTER_SEL : ANIMFILTER_UNSEL);
ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype);
/* for each curve:
* draw curve, then handle-lines, and finally vertices in this order so that
* the data will be layered correctly
*/
for (ale = anim_data.first; ale; ale = ale->next) {
for (bAnimListElem *ale = anim_data.first; ale; ale = ale->next) {
FCurve *fcu = (FCurve *)ale->key_data;
FModifier *fcm = find_active_fmodifier(&fcu->modifiers);
AnimData *adt = ANIM_nla_mapping_get(ac, ale);
@ -1138,18 +1122,12 @@ void graph_draw_curves(bAnimContext *ac, SpaceIpo *sipo, ARegion *ar, View2DGrid
/* left hand part */
void graph_draw_channel_names(bContext *C, bAnimContext *ac, ARegion *ar)
{
ListBase anim_data = {NULL, NULL};
bAnimListElem *ale;
int filter;
View2D *v2d = &ar->v2d;
float y = 0.0f, height;
size_t items;
int i = 0;
/* build list of channels to draw */
filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE | ANIMFILTER_LIST_CHANNELS);
items = ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype);
ListBase anim_data = {NULL, NULL};
const int filter = ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE | ANIMFILTER_LIST_CHANNELS;
const size_t items = ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype);
/* Update max-extent of channels here (taking into account scrollers):
* - this is done to allow the channel list to be scrollable, but must be done here
@ -1157,14 +1135,16 @@ void graph_draw_channel_names(bContext *C, bAnimContext *ac, ARegion *ar)
* - offset of ACHANNEL_HEIGHT*2 is added to the height of the channels, as first is for
* start of list offset, and the second is as a correction for the scrollers.
*/
height = (float)((items * ACHANNEL_STEP(ac)) + (ACHANNEL_HEIGHT(ac) * 2));
const float height = (float)((items * ACHANNEL_STEP(ac)) + (ACHANNEL_HEIGHT(ac) * 2));
UI_view2d_totRect_set(v2d, BLI_rcti_size_x(&ar->v2d.mask), height);
/* loop through channels, and set up drawing depending on their type */
bAnimListElem *ale;
int i;
{ /* first pass: just the standard GL-drawing for backdrop + text */
size_t channel_index = 0;
y = (float)ACHANNEL_FIRST(ac);
float y = (float)ACHANNEL_FIRST(ac);
for (ale = anim_data.first, i = 0; ale; ale = ale->next, i++) {
const float yminc = (float)(y - ACHANNEL_HEIGHT_HALF(ac));
@ -1187,7 +1167,7 @@ void graph_draw_channel_names(bContext *C, bAnimContext *ac, ARegion *ar)
uiBlock *block = UI_block_begin(C, ar, __func__, UI_EMBOSS);
size_t channel_index = 0;
y = (float)ACHANNEL_FIRST(ac);
float y = (float)ACHANNEL_FIRST(ac);
/* set blending again, as may not be set in previous step */
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);