Graph Editor: Allow "cursor x" to have fractional values when working with Drivers (T46004)

When working is the Graph Editor it can be very important to be able to work with fractions
(sub integers), especially when working with Drivers. Currently the "Cursor Y" is hooked up
to "cursor_position_y" which allows fractions  but "Cursor X" is directly hooked up to
"frame_current" which is an integer.

This commit adds initial support for this feature.
* When in Drivers mode, the x-part of the cursor is mapped to a new "cursor_position_x"
  value which can have fractional values. Animation mode however remains mapped to frame_current

* This commit only adds the UI/property/drawing tweaks needed to support this.
  Many operators still need to be modified to consider this value instead of the
  current frame, for this to be more useful.
This commit is contained in:
Joshua Leung 2015-10-10 18:26:09 +13:00
parent 2092056745
commit 65072499c6
Notes: blender-bot 2023-02-14 08:38:11 +01:00
Referenced by commit 6f29801f1b, Fix Drivers Editor not hiding vertical part of cursor
Referenced by issue #54569, Graph Editor’s Cursor: X values do not affect the position of the cursor
5 changed files with 53 additions and 13 deletions

View File

@ -133,7 +133,10 @@ static void graph_panel_view(const bContext *C, Panel *pa)
sub = uiLayoutColumn(col, true);
uiLayoutSetActive(sub, RNA_boolean_get(&spaceptr, "show_cursor"));
row = uiLayoutSplit(sub, 0.7f, true);
uiItemR(row, &sceneptr, "frame_current", 0, IFACE_("Cursor X"), ICON_NONE);
if (sipo->mode == SIPO_MODE_DRIVERS)
uiItemR(row, &spaceptr, "cursor_position_x", 0, IFACE_("Cursor X"), ICON_NONE);
else
uiItemR(row, &sceneptr, "frame_current", 0, IFACE_("Cursor X"), ICON_NONE);
uiItemEnumO(row, "GRAPH_OT_snap", IFACE_("To Keys"), 0, "type", GRAPHKEYS_SNAP_CFRA);
row = uiLayoutSplit(sub, 0.7f, true);

View File

@ -83,13 +83,20 @@ static void graphview_cursor_apply(bContext *C, wmOperator *op)
Scene *scene = CTX_data_scene(C);
SpaceIpo *sipo = CTX_wm_space_graph(C);
/* adjust the frame
* NOTE: sync this part of the code with ANIM_OT_change_frame
*/
CFRA = RNA_int_get(op->ptr, "frame");
FRAMENUMBER_MIN_CLAMP(CFRA);
SUBFRA = 0.f;
BKE_sound_seek_scene(bmain, scene);
/* adjust the frame or the cursor x-value */
if (sipo->mode == SIPO_MODE_DRIVERS) {
/* adjust cursor x-value */
sipo->cursorTime = (float)RNA_int_get(op->ptr, "frame"); // XXX: need new prop
}
else {
/* adjust the frame
* NOTE: sync this part of the code with ANIM_OT_change_frame
*/
CFRA = RNA_int_get(op->ptr, "frame");
FRAMENUMBER_MIN_CLAMP(CFRA);
SUBFRA = 0.f;
BKE_sound_seek_scene(bmain, scene);
}
/* set the cursor value */
sipo->cursorVal = RNA_float_get(op->ptr, "value");
@ -200,7 +207,7 @@ static void GRAPH_OT_cursor_set(wmOperatorType *ot)
/* identifiers */
ot->name = "Set Cursor";
ot->idname = "GRAPH_OT_cursor_set";
ot->description = "Interactively set the current frame number and value cursor";
ot->description = "Interactively set the current frame and value cursor";
/* api callbacks */
ot->exec = graphview_cursor_exec;

View File

@ -286,10 +286,33 @@ static void graph_main_area_draw(const bContext *C, ARegion *ar)
glDisable(GL_BLEND);
}
/* 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);
/* current frame or vertical component of vertical component of the cursor */
if (sipo->mode == SIPO_MODE_DRIVERS) {
/* cursor x-value */
float vec[2];
vec[0] = sipo->cursorTime;
/* to help differentiate this from the current frame, draw slightly darker like the horizontal one */
UI_ThemeColorShadeAlpha(TH_CFRAME, -40, -50);
glLineWidth(2.0);
glEnable(GL_BLEND);
glBegin(GL_LINE_STRIP);
vec[1] = v2d->cur.ymin;
glVertex2fv(vec);
vec[1] = v2d->cur.ymax;
glVertex2fv(vec);
glEnd(); // GL_LINE_STRIP
glDisable(GL_BLEND);
}
else {
/* 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);
}
/* markers */
UI_view2d_view_orthoSpecial(ar, v2d, 1);

View File

@ -327,8 +327,10 @@ typedef struct SpaceIpo {
short autosnap; /* time-transform autosnapping settings for Graph editor (eAnimEdit_AutoSnap in DNA_action_types.h) */
int flag; /* settings for Graph editor (eGraphEdit_Flag) */
float cursorTime; /* time value for cursor (when in drivers mode; animation uses current frame) */
float cursorVal; /* cursor value (y-value, x-value is current frame) */
int around; /* pivot point for transforms */
int pad;
} SpaceIpo;

View File

@ -3504,6 +3504,11 @@ static void rna_def_space_graph(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Show Cursor", "Show 2D cursor");
RNA_def_property_update(prop, NC_SPACE | ND_SPACE_GRAPH, NULL);
prop = RNA_def_property(srna, "cursor_position_x", PROP_FLOAT, PROP_NONE);
RNA_def_property_float_sdna(prop, NULL, "cursorTime");
RNA_def_property_ui_text(prop, "Cursor X-Value", "Graph Editor 2D-Value cursor - X-Value component");
RNA_def_property_update(prop, NC_SPACE | ND_SPACE_GRAPH, NULL);
prop = RNA_def_property(srna, "cursor_position_y", PROP_FLOAT, PROP_NONE);
RNA_def_property_float_sdna(prop, NULL, "cursorVal");
RNA_def_property_ui_text(prop, "Cursor Y-Value", "Graph Editor 2D-Value cursor - Y-Value component");