Current Frame Indicator tweaks

* Draw the frame/time number box over the scrollbar instead of above it,
  to reduce the clutter/clashes with markers.

* Draw the box centered around the line instead of off to one side,
  making it clearer that the frame shown is the one being affected.

* Make the box larger than the scrollbar + use white text to make it
  stand out from the neighbouring frame numbers (otherwise, it's easy
  to misread that it's just another one of those)
This commit is contained in:
2018-04-24 19:18:22 +02:00
parent 9511cc13d7
commit b05fd95f8a
6 changed files with 68 additions and 40 deletions

View File

@@ -69,14 +69,20 @@
/* CURRENT FRAME DRAWING */
/* 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)
void ANIM_draw_cfra_number(const bContext *C, View2D *v2d, short flag)
{
Scene *scene = CTX_data_scene(C);
const float time = scene->r.cfra + scene->r.subframe;
const float cfra = (float)(time * scene->r.framelen);
const bool show_time = (flag & DRAWCFRA_UNIT_SECONDS) != 0;
const uiFontStyle *fstyle = UI_FSTYLE_WIDGET;
Gwn_VertFormat *format = immVertexFormat();
unsigned int pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
unsigned char col[4];
float xscale, x, y;
char numstr[32] = " t"; /* t is the character to start replacing from */
char numstr[32] = " t "; /* t is the character to start replacing from */
float hlen;
int slen;
/* because the frame number text is subject to the same scaling as the contents of the view */
@@ -86,33 +92,39 @@ static void draw_cfra_number(Scene *scene, View2D *v2d, const float cfra, const
/* get timecode string
* - padding on str-buf passed so that it doesn't sit on the frame indicator
* - power = 0, gives 'standard' behavior for time
* but power = 1 is required for frames (to get integer frames)
*/
if (time) {
BLI_timecode_string_from_time(&numstr[4], sizeof(numstr) - 4, 0, FRA2TIME(cfra), FPS, U.timecode_style);
if (show_time) {
BLI_timecode_string_from_time(&numstr[2], sizeof(numstr) - 2, 0, FRA2TIME(cfra), FPS, U.timecode_style);
}
else {
BLI_timecode_string_from_time_seconds(&numstr[4], sizeof(numstr) - 4, 1, cfra);
BLI_timecode_string_from_time_seconds(&numstr[2], sizeof(numstr) - 2, 1, cfra);
}
slen = UI_fontstyle_string_width(fstyle, numstr) - 1;
hlen = slen * 0.5f;
/* get starting coordinates for drawing */
x = cfra * xscale;
y = 0.9f * U.widget_unit;
y = 0.02f * U.widget_unit;
immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
/* draw green box around/behind text */
immUniformThemeColorShade(TH_CFRAME, 0);
immRectf(pos, x, y, x + slen, y + 0.75f * U.widget_unit);
immRectf(pos,
x - hlen - 0.20f * U.widget_unit,
y,
x + hlen + 0.2f * U.widget_unit,
y + U.widget_unit);
immUnbindProgram();
/* draw current frame number */
UI_GetThemeColor4ubv(TH_TEXT, col);
UI_fontstyle_draw_simple(fstyle, x - 0.25f * U.widget_unit, y + 0.15f * U.widget_unit, numstr, col);
UI_GetThemeColor4ubv(TH_TEXT_HI, col);
UI_fontstyle_draw_simple(fstyle,
x - hlen - 0.15f * U.widget_unit,
y + 0.28f * U.widget_unit,
numstr, col);
/* restore view transform */
gpuPopMatrix();
@@ -141,12 +153,6 @@ void ANIM_draw_cfra(const bContext *C, View2D *v2d, short flag)
immVertex2f(pos, x, v2d->cur.ymax);
immEnd();
immUnbindProgram();
/* Draw current frame number in a little box */
if (flag & DRAWCFRA_SHOW_NUMBOX) {
UI_view2d_view_orthoSpecial(CTX_wm_region(C), v2d, 1);
draw_cfra_number(scene, v2d, x, (flag & DRAWCFRA_UNIT_SECONDS) != 0);
}
}
/* *************************************************** */

View File

@@ -535,17 +535,18 @@ void ANIM_fcurve_delete_from_animdata(bAnimContext *ac, struct AnimData *adt, st
enum eAnimEditDraw_CurrentFrame {
/* plain time indicator with no special indicators */
DRAWCFRA_PLAIN = 0,
/* draw box indicating current frame number */
DRAWCFRA_SHOW_NUMBOX = (1 << 0),
/* time indication in seconds or frames */
DRAWCFRA_UNIT_SECONDS = (1 << 1),
DRAWCFRA_UNIT_SECONDS = (1 << 0),
/* draw indicator extra wide (for timeline) */
DRAWCFRA_WIDE = (1 << 2)
DRAWCFRA_WIDE = (1 << 1)
};
/* main call to draw current-frame indicator in an Animation Editor */
void ANIM_draw_cfra(const struct bContext *C, struct View2D *v2d, short flag);
/* main call to draw "number box" in scrollbar for current frame indicator */
void ANIM_draw_cfra_number(const struct bContext *C, struct View2D *v2d, short flag);
/* ------------- Preview Range Drawing -------------- */
/* main call to draw preview range curtains */

View File

@@ -217,7 +217,9 @@ static void action_main_region_draw(const bContext *C, ARegion *ar)
View2D *v2d = &ar->v2d;
View2DGrid *grid;
View2DScrollers *scrollers;
short unit = 0, flag = 0;
short marker_flag = 0;
short cfra_flag = 0;
short unit = 0;
/* clear and setup matrix */
UI_ThemeClearColor(TH_BACK);
@@ -242,15 +244,14 @@ static void action_main_region_draw(const bContext *C, ARegion *ar)
}
/* current frame */
if (saction->flag & SACTION_DRAWTIME) flag |= DRAWCFRA_UNIT_SECONDS;
if ((saction->flag & SACTION_NODRAWCFRANUM) == 0) flag |= DRAWCFRA_SHOW_NUMBOX;
ANIM_draw_cfra(C, v2d, flag);
if (saction->flag & SACTION_DRAWTIME) cfra_flag |= DRAWCFRA_UNIT_SECONDS;
ANIM_draw_cfra(C, v2d, cfra_flag);
/* markers */
UI_view2d_view_orthoSpecial(ar, v2d, 1);
flag = ((ac.markers && (ac.markers != &ac.scene->markers)) ? DRAW_MARKERS_LOCAL : 0) | DRAW_MARKERS_MARGIN;
ED_markers_draw(C, flag);
marker_flag = ((ac.markers && (ac.markers != &ac.scene->markers)) ? DRAW_MARKERS_LOCAL : 0) | DRAW_MARKERS_MARGIN;
ED_markers_draw(C, marker_flag);
/* caches */
if (saction->mode == SACTCONT_TIMELINE) {
@@ -272,6 +273,12 @@ static void action_main_region_draw(const bContext *C, ARegion *ar)
scrollers = UI_view2d_scrollers_calc(C, v2d, unit, V2D_GRID_CLAMP, V2D_ARG_DUMMY, V2D_ARG_DUMMY);
UI_view2d_scrollers_draw(C, v2d, scrollers);
UI_view2d_scrollers_free(scrollers);
/* draw current frame number-indicator on top of scrollers */
if ((saction->flag & SACTION_NODRAWCFRANUM) == 0) {
UI_view2d_view_orthoSpecial(ar, v2d, 1);
ANIM_draw_cfra_number(C, v2d, cfra_flag);
}
}
/* add handlers, stuff you only do once or on area/region changes */

View File

@@ -234,7 +234,7 @@ static void graph_main_region_draw(const bContext *C, ARegion *ar)
View2DGrid *grid;
View2DScrollers *scrollers;
float col[3];
short unitx = 0, unity = V2D_UNIT_VALUES, flag = 0;
short unitx = 0, unity = V2D_UNIT_VALUES, cfra_flag = 0;
/* clear and setup matrix */
UI_GetThemeColor3fv(TH_BACK, col);
@@ -281,7 +281,6 @@ static void graph_main_region_draw(const bContext *C, ARegion *ar)
/* horizontal component of value-cursor (value line before the current frame line) */
if ((sipo->flag & SIPO_NODRAWCURSOR) == 0) {
float y = sipo->cursorVal;
/* Draw a green line to indicate the cursor value */
@@ -320,9 +319,8 @@ static void graph_main_region_draw(const bContext *C, ARegion *ar)
if (sipo->mode != SIPO_MODE_DRIVERS) {
/* current frame */
if (sipo->flag & SIPO_DRAWTIME) flag |= DRAWCFRA_UNIT_SECONDS;
if ((sipo->flag & SIPO_NODRAWCFRANUM) == 0) flag |= DRAWCFRA_SHOW_NUMBOX;
ANIM_draw_cfra(C, v2d, flag);
if (sipo->flag & SIPO_DRAWTIME) cfra_flag |= DRAWCFRA_UNIT_SECONDS;
ANIM_draw_cfra(C, v2d, cfra_flag);
}
/* markers */
@@ -345,6 +343,12 @@ static void graph_main_region_draw(const bContext *C, ARegion *ar)
scrollers = UI_view2d_scrollers_calc(C, v2d, unitx, V2D_GRID_NOCLAMP, unity, V2D_GRID_NOCLAMP);
UI_view2d_scrollers_draw(C, v2d, scrollers);
UI_view2d_scrollers_free(scrollers);
/* draw current frame number-indicator on top of scrollers */
if ((sipo->mode != SIPO_MODE_DRIVERS) && ((sipo->flag & SIPO_NODRAWCFRANUM) == 0)) {
UI_view2d_view_orthoSpecial(ar, v2d, 1);
ANIM_draw_cfra_number(C, v2d, cfra_flag);
}
}
static void graph_channel_region_init(wmWindowManager *wm, ARegion *ar)

View File

@@ -274,7 +274,7 @@ static void nla_main_region_draw(const bContext *C, ARegion *ar)
View2D *v2d = &ar->v2d;
View2DGrid *grid;
View2DScrollers *scrollers;
short unit = 0, flag = 0;
short unit = 0, cfra_flag = 0;
/* clear and setup matrix */
UI_ThemeClearColor(TH_BACK);
@@ -305,9 +305,8 @@ static void nla_main_region_draw(const bContext *C, ARegion *ar)
UI_view2d_view_ortho(v2d);
/* current frame */
if (snla->flag & SNLA_DRAWTIME) flag |= DRAWCFRA_UNIT_SECONDS;
if ((snla->flag & SNLA_NODRAWCFRANUM) == 0) flag |= DRAWCFRA_SHOW_NUMBOX;
ANIM_draw_cfra(C, v2d, flag);
if (snla->flag & SNLA_DRAWTIME) cfra_flag |= DRAWCFRA_UNIT_SECONDS;
ANIM_draw_cfra(C, v2d, cfra_flag);
/* markers */
UI_view2d_view_orthoSpecial(ar, v2d, 1);
@@ -328,6 +327,12 @@ static void nla_main_region_draw(const bContext *C, ARegion *ar)
scrollers = UI_view2d_scrollers_calc(C, v2d, unit, V2D_GRID_CLAMP, V2D_ARG_DUMMY, V2D_ARG_DUMMY);
UI_view2d_scrollers_draw(C, v2d, scrollers);
UI_view2d_scrollers_free(scrollers);
/* draw current frame number-indicator on top of scrollers */
if ((snla->flag & SNLA_NODRAWCFRANUM) == 0) {
UI_view2d_view_orthoSpecial(ar, v2d, 1);
ANIM_draw_cfra_number(C, v2d, cfra_flag);
}
}

View File

@@ -1668,7 +1668,7 @@ void draw_timeline_seq(const bContext *C, ARegion *ar)
SpaceSeq *sseq = CTX_wm_space_seq(C);
View2D *v2d = &ar->v2d;
View2DScrollers *scrollers;
short unit = 0, flag = 0;
short unit = 0, cfra_flag = 0;
float col[3];
/* clear and setup matrix */
@@ -1715,9 +1715,8 @@ void draw_timeline_seq(const bContext *C, ARegion *ar)
/* current frame */
UI_view2d_view_ortho(v2d);
if ((sseq->flag & SEQ_DRAWFRAMES) == 0) flag |= DRAWCFRA_UNIT_SECONDS;
if ((sseq->flag & SEQ_NO_DRAW_CFRANUM) == 0) flag |= DRAWCFRA_SHOW_NUMBOX;
ANIM_draw_cfra(C, v2d, flag);
if ((sseq->flag & SEQ_DRAWFRAMES) == 0) cfra_flag |= DRAWCFRA_UNIT_SECONDS;
ANIM_draw_cfra(C, v2d, cfra_flag);
/* markers */
UI_view2d_view_orthoSpecial(ar, v2d, 1);
@@ -1755,6 +1754,12 @@ void draw_timeline_seq(const bContext *C, ARegion *ar)
scrollers = UI_view2d_scrollers_calc(C, v2d, unit, V2D_GRID_CLAMP, V2D_UNIT_VALUES, V2D_GRID_CLAMP);
UI_view2d_scrollers_draw(C, v2d, scrollers);
UI_view2d_scrollers_free(scrollers);
/* draw current frame number-indicator on top of scrollers */
if ((sseq->flag & SEQ_NO_DRAW_CFRANUM) == 0) {
UI_view2d_view_orthoSpecial(ar, v2d, 1);
ANIM_draw_cfra_number(C, v2d, cfra_flag);
}
}