[Bf-blender-cvs] [fa59346c134] master: Refactor: Support arbitrary y offset for channel list
Jacques Lucke
noreply at git.blender.org
Fri May 3 13:06:29 CEST 2019
Commit: fa59346c1340da4189e5c7d38164a74dc096db10
Author: Jacques Lucke
Date: Fri May 3 13:00:18 2019 +0200
Branches: master
https://developer.blender.org/rBfa59346c1340da4189e5c7d38164a74dc096db10
Refactor: Support arbitrary y offset for channel list
At first you could think that this refactor would not be
necessary, because `ACHANNEL_FIRST` exists already.
It contained the small y offset that all channels had.
Unfortunately, a lot of code assumed that
`ACHANNEL_FIRST = -ACHANNEL_HEIGHT`, making the
define pretty much useless. This refactor fixes that
for the action and nla editor.
As a nice side effect, this patch fixes channel box select.
Before there was always have a half-channel offset.
Reviewers: brecht
Differential Revision: https://developer.blender.org/D4783
===================================================================
M source/blender/editors/animation/anim_channels_edit.c
M source/blender/editors/include/ED_anim_api.h
M source/blender/editors/include/UI_view2d.h
M source/blender/editors/interface/view2d.c
M source/blender/editors/space_action/action_draw.c
M source/blender/editors/space_action/action_edit.c
M source/blender/editors/space_action/action_select.c
M source/blender/editors/space_graph/graph_draw.c
M source/blender/editors/space_nla/nla_channels.c
M source/blender/editors/space_nla/nla_draw.c
M source/blender/editors/space_nla/nla_edit.c
M source/blender/editors/space_nla/nla_select.c
===================================================================
diff --git a/source/blender/editors/animation/anim_channels_edit.c b/source/blender/editors/animation/anim_channels_edit.c
index 6e0277d5fff..adc6ec3f6be 100644
--- a/source/blender/editors/animation/anim_channels_edit.c
+++ b/source/blender/editors/animation/anim_channels_edit.c
@@ -2531,17 +2531,6 @@ static void box_select_anim_channels(bAnimContext *ac, rcti *rect, short selectm
SpaceNla *snla = (SpaceNla *)ac->sl;
View2D *v2d = &ac->ar->v2d;
rctf rectf;
- float ymin, ymax;
-
- /* set initial y extents */
- if (ac->datatype == ANIMCONT_NLA) {
- ymin = (float)(-NLACHANNEL_HEIGHT(snla));
- ymax = 0.0f;
- }
- else {
- ymin = 0.0f;
- ymax = (float)(-ACHANNEL_HEIGHT(ac));
- }
/* convert border-region to view coordinates */
UI_view2d_region_to_view(v2d, rect->xmin, rect->ymin + 2, &rectf.xmin, &rectf.ymin);
@@ -2551,8 +2540,17 @@ static void box_select_anim_channels(bAnimContext *ac, rcti *rect, short selectm
filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE | ANIMFILTER_LIST_CHANNELS);
ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype);
+ float ymax;
+ if (ac->datatype == ANIMCONT_NLA) {
+ ymax = NLACHANNEL_FIRST_TOP(snla);
+ }
+ else {
+ ymax = ACHANNEL_FIRST_TOP(ac);
+ }
+
/* loop over data, doing box select */
for (ale = anim_data.first; ale; ale = ale->next) {
+ float ymin;
if (ac->datatype == ANIMCONT_NLA) {
ymin = ymax - NLACHANNEL_STEP(snla);
}
@@ -2729,32 +2727,25 @@ static int animchannels_channel_get(bAnimContext *ac, const int mval[2])
ar = ac->ar;
v2d = &ar->v2d;
- /* Figure out which channel user clicked in.
- *
- * Note: although channels technically start at (y = ACHANNEL_FIRST),
- * we need to adjust by half a channel's height so that the tops of channels get caught ok.
- * Since ACHANNEL_FIRST is really ACHANNEL_HEIGHT, we simply use ACHANNEL_HEIGHT_HALF.
- */
+ /* Figure out which channel user clicked in. */
UI_view2d_region_to_view(v2d, mval[0], mval[1], &x, &y);
if (ac->datatype == ANIMCONT_NLA) {
SpaceNla *snla = (SpaceNla *)ac->sl;
- UI_view2d_listview_view_to_cell(v2d,
- NLACHANNEL_NAMEWIDTH,
+ UI_view2d_listview_view_to_cell(NLACHANNEL_NAMEWIDTH,
NLACHANNEL_STEP(snla),
0,
- (float)NLACHANNEL_HEIGHT_HALF(snla),
+ NLACHANNEL_FIRST_TOP(snla),
x,
y,
NULL,
&channel_index);
}
else {
- UI_view2d_listview_view_to_cell(v2d,
- ACHANNEL_NAMEWIDTH,
+ UI_view2d_listview_view_to_cell(ACHANNEL_NAMEWIDTH,
ACHANNEL_STEP(ac),
0,
- (float)ACHANNEL_HEIGHT_HALF(ac),
+ ACHANNEL_FIRST_TOP(ac),
x,
y,
NULL,
@@ -3206,19 +3197,12 @@ static int animchannels_mouseclick_invoke(bContext *C, wmOperator *op, const wmE
selectmode = SELECT_REPLACE;
}
- /* figure out which channel user clicked in
- *
- * Note:
- * although channels technically start at (y = ACHANNEL_FIRST),
- * we need to adjust by half a channel's height so that the tops of channels get caught ok.
- * Since ACHANNEL_FIRST is really ACHANNEL_HEIGHT, we simply use ACHANNEL_HEIGHT_HALF.
- */
+ /* figure out which channel user clicked in */
UI_view2d_region_to_view(v2d, event->mval[0], event->mval[1], &x, &y);
- UI_view2d_listview_view_to_cell(v2d,
- ACHANNEL_NAMEWIDTH,
+ UI_view2d_listview_view_to_cell(ACHANNEL_NAMEWIDTH,
ACHANNEL_STEP(&ac),
0,
- (float)ACHANNEL_HEIGHT_HALF(&ac),
+ ACHANNEL_FIRST_TOP(&ac),
x,
y,
NULL,
diff --git a/source/blender/editors/include/ED_anim_api.h b/source/blender/editors/include/ED_anim_api.h
index d947322f708..6342a8b26d9 100644
--- a/source/blender/editors/include/ED_anim_api.h
+++ b/source/blender/editors/include/ED_anim_api.h
@@ -403,11 +403,13 @@ typedef enum eAnimFilter_Flags {
/* -------------- Channel Defines -------------- */
/* channel heights */
-#define ACHANNEL_FIRST(ac) (-0.8f * (ac)->yscale_fac * U.widget_unit)
+#define ACHANNEL_FIRST_TOP(ac) (-0.4f * (ac)->yscale_fac * U.widget_unit)
#define ACHANNEL_HEIGHT(ac) (0.8f * (ac)->yscale_fac * U.widget_unit)
-#define ACHANNEL_HEIGHT_HALF(ac) (0.4f * (ac)->yscale_fac * U.widget_unit)
#define ACHANNEL_SKIP (0.1f * U.widget_unit)
#define ACHANNEL_STEP(ac) (ACHANNEL_HEIGHT(ac) + ACHANNEL_SKIP)
+/* Additional offset to give some room at the end. */
+#define ACHANNEL_TOT_HEIGHT(ac, item_amount) \
+ (-ACHANNEL_FIRST_TOP(ac) + ACHANNEL_STEP(ac) * (item_amount + 1))
/* channel widths */
#define ACHANNEL_NAMEWIDTH (10 * U.widget_unit)
@@ -418,13 +420,14 @@ typedef enum eAnimFilter_Flags {
/* -------------- NLA Channel Defines -------------- */
/* NLA channel heights */
-#define NLACHANNEL_FIRST (-0.8f * U.widget_unit)
+#define NLACHANNEL_FIRST_TOP(snla) (-0.4f * U.widget_unit)
#define NLACHANNEL_HEIGHT(snla) \
((snla && (snla->flag & SNLA_NOSTRIPCURVES)) ? (0.8f * U.widget_unit) : (1.2f * U.widget_unit))
-#define NLACHANNEL_HEIGHT_HALF(snla) \
- ((snla && (snla->flag & SNLA_NOSTRIPCURVES)) ? (0.4f * U.widget_unit) : (0.6f * U.widget_unit))
#define NLACHANNEL_SKIP (0.1f * U.widget_unit)
#define NLACHANNEL_STEP(snla) (NLACHANNEL_HEIGHT(snla) + NLACHANNEL_SKIP)
+/* Additional offset to give some room at the end. */
+#define NLACHANNEL_TOT_HEIGHT(snla, item_amount) \
+ (-NLACHANNEL_FIRST_TOP(snla) + NLACHANNEL_STEP(snla) * (item_amount + 1))
/* channel widths */
#define NLACHANNEL_NAMEWIDTH (10 * U.widget_unit)
diff --git a/source/blender/editors/include/UI_view2d.h b/source/blender/editors/include/UI_view2d.h
index 07dbb49ac07..b1dfa89ae7d 100644
--- a/source/blender/editors/include/UI_view2d.h
+++ b/source/blender/editors/include/UI_view2d.h
@@ -183,16 +183,7 @@ void UI_view2d_scrollers_draw(struct View2D *v2d, View2DScrollers *scrollers);
void UI_view2d_scrollers_free(View2DScrollers *scrollers);
/* list view tools */
-void UI_view2d_listview_cell_to_view(struct View2D *v2d,
- float columnwidth,
- float rowheight,
- float startx,
- float starty,
- int column,
- int row,
- struct rctf *rect);
-void UI_view2d_listview_view_to_cell(struct View2D *v2d,
- float columnwidth,
+void UI_view2d_listview_view_to_cell(float columnwidth,
float rowheight,
float startx,
float starty,
@@ -200,15 +191,6 @@ void UI_view2d_listview_view_to_cell(struct View2D *v2d,
float viewy,
int *column,
int *row);
-void UI_view2d_listview_visible_cells(struct View2D *v2d,
- float columnwidth,
- float rowheight,
- float startx,
- float starty,
- int *column_min,
- int *column_max,
- int *row_min,
- int *row_max);
/* coordinate conversion */
float UI_view2d_region_to_view_x(const struct View2D *v2d, float x);
diff --git a/source/blender/editors/interface/view2d.c b/source/blender/editors/interface/view2d.c
index 58d26c4a840..9de7a33b757 100644
--- a/source/blender/editors/interface/view2d.c
+++ b/source/blender/editors/interface/view2d.c
@@ -1644,59 +1644,6 @@ void UI_view2d_scrollers_free(View2DScrollers *scrollers)
/* *********************************************************************** */
/* List View Utilities */
-/** Get the view-coordinates of the nominated cell
- *
- * \param columnwidth, rowheight: size of each 'cell'
- * \param startx, starty: coordinates (in 'tot' rect space) that the list starts from.
- * This should be (0,0) for most views. However, for those where the starting row was offsetted
- * (like for Animation Editor channel lists, to make the first entry more visible), these will be
- * the min-coordinates of the first item.
- * \param column, row: The 2d-coordinates
- * (in 2D-view / 'tot' rect space) the cell exists at
- * \param rect: coordinates of the cell
- * (passed as single var instead of 4 separate, as it's more useful this way)
- */
-void UI_view2d_listview_cell_to_view(View2D *v2d,
- float columnwidth,
- float rowheight,
- float startx,
- float starty,
- int column,
- int row,
- rctf *rect)
-{
- /* sanity checks */
- if (ELEM(NULL, v2d, rect)) {
- return;
- }
-
- if ((columnwidth <= 0) && (rowheight <= 0)) {
- rect->xmin = rect->xmax = 0.0f;
- rect->ymin = rect->ymax = 0.0f;
- return;
- }
-
- /* x-coordinates */
- rect->xmin = startx + (float)(columnwidth * column);
- rect->xmax = startx + (float)(columnwidth * (column + 1));
-
- if ((v2d->align & V2D_ALIGN_NO_POS_X) && !(v2d->align & V2D_ALIGN_NO_NEG_X)) {
- /* simply negate the values for the coord
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list