View2D - Another WIP commit
* Start of basic scrollbar drawing. This will be improved. Only Outliner shows these for now, as although the Timeline should show them, the old files didn't have them turned on. * Tidied up the view-panning operator - Fixed naming convention - Added user-adjustable properties (deltax, deltay in screenspace) * Added ctrl-scrollwheel (horizontal) and shift-scrollwheel (vertical) scroll operators. These use the view-panning code too. Unfortunately, I haven't been able to figure out why the WHEELMOUSEDOWN events don't seem to be triggering the operators!
This commit is contained in:
@@ -79,17 +79,19 @@ typedef struct View2DScrollers View2DScrollers;
|
||||
/* Prototypes: */
|
||||
|
||||
/* setup */
|
||||
void UI_view2d_ortho(const struct bContext *C, struct View2D *v2d);
|
||||
void UI_view2d_view_ortho(const struct bContext *C, struct View2D *v2d);
|
||||
void UI_view2d_view_restore(const struct bContext *C);
|
||||
|
||||
void UI_view2d_update_size(struct View2D *v2d, int winx, int winy);
|
||||
void UI_view2d_enforce_status(struct View2D *v2d, int winx, int winy);
|
||||
|
||||
/* grid drawing */
|
||||
View2DGrid *UI_view2d_calc_grid(const struct bContext *C, struct View2D *v2d, short unit, short type, int winx, int winy);
|
||||
View2DGrid *UI_view2d_calc_grid(const struct bContext *C, struct View2D *v2d, short unit, short clamp, int winx, int winy);
|
||||
void UI_view2d_draw_grid(const struct bContext *C, struct View2D *v2d, View2DGrid *grid, int flag);
|
||||
void UI_view2d_free_grid(View2DGrid *grid);
|
||||
|
||||
/* scrollbar drawing */
|
||||
|
||||
View2DScrollers *UI_view2d_calc_scrollers(const struct bContext *C, struct View2D *v2d, short units, short clamp);
|
||||
void UI_view2d_draw_scrollers(const struct bContext *C, struct View2D *v2d, View2DScrollers *scrollers, int flag);
|
||||
void UI_view2d_free_scrollbars(View2DScrollers *scrollers);
|
||||
|
||||
|
||||
@@ -40,6 +40,7 @@
|
||||
#include "WM_api.h"
|
||||
|
||||
#include "BIF_gl.h"
|
||||
#include "BIF_glutil.h"
|
||||
|
||||
#include "UI_resources.h"
|
||||
#include "UI_view2d.h"
|
||||
@@ -47,13 +48,51 @@
|
||||
/* *********************************************************************** */
|
||||
/* Setup and Refresh Code */
|
||||
|
||||
|
||||
/* ---------------------- */
|
||||
|
||||
/* Set view matrices to ortho for View2D drawing */
|
||||
// XXX in past, this was not always the case!
|
||||
void UI_view2d_ortho(const bContext *C, View2D *v2d)
|
||||
void UI_view2d_view_ortho(const bContext *C, View2D *v2d)
|
||||
{
|
||||
wmOrtho2(C->window, v2d->cur.xmin, v2d->cur.xmax, v2d->cur.ymin, v2d->cur.ymax);
|
||||
ARegion *region= C->region;
|
||||
int winx, winy;
|
||||
float ofsx, ofsy;
|
||||
|
||||
/* calculate extents of region */
|
||||
winx= region->winrct.xmax - region->winrct.xmin;
|
||||
winy= region->winrct.ymax - region->winrct.ymin;
|
||||
ofsx= ofsy= 0.0f;
|
||||
|
||||
/* these checks here make sure that the region is large-enough to show scrollers */
|
||||
if ((winx > SCROLLB+10) && (winy > SCROLLH+10)) {
|
||||
if (v2d->scroll) {
|
||||
if (v2d->scroll & (HOR_SCROLL|HOR_SCROLLO))
|
||||
ofsy= (float)-SCROLLB;
|
||||
if (v2d->scroll & VERT_SCROLL)
|
||||
ofsx= (float)-SCROLLH;
|
||||
}
|
||||
}
|
||||
|
||||
/* note: 0.375 is constant factor to get 1:1 correspondance with pixels */
|
||||
wmOrtho2(C->window, v2d->cur.xmin+ofsx-0.375f, v2d->cur.xmax-0.375f, v2d->cur.ymin+ofsy-0.375f, v2d->cur.ymax-0.375f);
|
||||
}
|
||||
|
||||
/* Restore view matrices after drawing */
|
||||
void UI_view2d_view_restore(const bContext *C)
|
||||
{
|
||||
ARegion *region= C->region;
|
||||
int winx, winy;
|
||||
|
||||
/* calculate extents of region */
|
||||
winx= region->winrct.xmax - region->winrct.xmin;
|
||||
winy= region->winrct.ymax - region->winrct.ymin;
|
||||
|
||||
/* note: 0.375 is constant factor to get 1:1 correspondance with pixels */
|
||||
wmOrtho2(C->window, -0.375f, winx-0.375f, -0.375f, winy-0.375f);
|
||||
}
|
||||
|
||||
/* ---------------------- */
|
||||
|
||||
/* Adjust mask size in response to view size changes */
|
||||
// XXX pre2.5 -> this used to be called calc_scrollrcts()
|
||||
void UI_view2d_update_size(View2D *v2d, int winx, int winy)
|
||||
@@ -110,8 +149,7 @@ void UI_view2d_enforce_status(View2D *v2d, int winx, int winy)
|
||||
|
||||
/* correct winx for scrollbars */
|
||||
if (v2d->scroll & L_SCROLL) winx-= SCROLLB;
|
||||
if (v2d->scroll & B_SCROLL) winy-= SCROLLH;
|
||||
if (v2d->scroll & B_SCROLLO) winy-= SCROLLH; /* B_SCROLL and B_SCROLLO are basically same thing */
|
||||
if (v2d->scroll & (B_SCROLL|B_SCROLLO)) winy-= SCROLLH;
|
||||
|
||||
/* header completely closed window */
|
||||
if (winy <= 0) return;
|
||||
@@ -338,7 +376,7 @@ void UI_view2d_enforce_status(View2D *v2d, int winx, int winy)
|
||||
/* View2DGrid is typedef'd in UI_view2d.h */
|
||||
struct View2DGrid {
|
||||
float dx, dy; /* stepsize (in pixels) between gridlines */
|
||||
float startx, starty; /* */
|
||||
float startx, starty; /* initial coordinates to start drawing grid from */
|
||||
int powerx, powery; /* step as power of 10 */
|
||||
};
|
||||
|
||||
@@ -387,7 +425,7 @@ static void step_to_grid(float *step, int *power, int unit)
|
||||
/* Intialise settings necessary for drawing gridlines in a 2d-view
|
||||
* - Currently, will return pointer to View2DGrid struct that needs to
|
||||
* be freed with UI_view2d_free_grid()
|
||||
* - Is used for scrollbar drawing too (for units drawing) --> (XXX needs review)
|
||||
* - Is used for scrollbar drawing too (for units drawing)
|
||||
*
|
||||
* - unit = V2D_UNIT_* grid steps in seconds or frames
|
||||
* - clamp = V2D_CLAMP_* only show whole-number intervals
|
||||
@@ -548,7 +586,70 @@ void UI_view2d_free_grid(View2DGrid *grid)
|
||||
/* *********************************************************************** */
|
||||
/* Scrollbars */
|
||||
|
||||
/* View2DScrollers is typedef'd in UI_view2d.h */
|
||||
struct View2DScrollers {
|
||||
View2DGrid *grid; /* grid for coordinate drawing */
|
||||
|
||||
int vertmin, vertmax; /* vertical scrollbar - current 'focus' button */
|
||||
int hormin, hormax; /* horizontal scrollbar - current 'focus' button */
|
||||
};
|
||||
|
||||
View2DScrollers *UI_view2d_calc_scrollers(const bContext *C, View2D *v2d, short units, short clamp)
|
||||
{
|
||||
View2DScrollers *scrollers;
|
||||
|
||||
/* scrollers is allocated here... */
|
||||
scrollers= MEM_callocN(sizeof(View2DScrollers), "View2DScrollers");
|
||||
|
||||
// ... add some stuff here...
|
||||
|
||||
return scrollers;
|
||||
}
|
||||
|
||||
|
||||
/* Draw scrollbars in the given 2d-region */
|
||||
void UI_view2d_draw_scrollers(const bContext *C, View2D *v2d, View2DScrollers *scrollers, int flag)
|
||||
{
|
||||
const int darker= -40, dark= 0, light= 20, lighter= 50;
|
||||
float fac, dfac, val, fac2, tim;
|
||||
rcti vert, hor;
|
||||
|
||||
vert= v2d->vert;
|
||||
hor= v2d->hor;
|
||||
|
||||
/* horizontal scrollbar */
|
||||
if ((v2d->scroll & HOR_SCROLL) || (v2d->scroll & HOR_SCROLLO)) {
|
||||
/* scroller backdrop */
|
||||
UI_ThemeColorShade(TH_SHADE1, light);
|
||||
glRecti(hor.xmin, hor.ymin, hor.xmax, hor.ymax);
|
||||
|
||||
// FIXME: add slider bar
|
||||
|
||||
/* decoration bright line */
|
||||
UI_ThemeColorShade(TH_SHADE1, lighter);
|
||||
sdrawline(hor.xmin, hor.ymax, hor.xmax, hor.ymax);
|
||||
}
|
||||
|
||||
/* vertical scrollbar */
|
||||
if (v2d->scroll & VERT_SCROLL) {
|
||||
/* scroller backdrop */
|
||||
UI_ThemeColorShade(TH_SHADE1, light);
|
||||
glRecti(vert.xmin, vert.ymin, vert.xmax, vert.ymax);
|
||||
|
||||
/* decoration black line */
|
||||
UI_ThemeColorShade(TH_SHADE1, darker);
|
||||
if (v2d->scroll & HOR_SCROLL)
|
||||
sdrawline(vert.xmax, vert.ymin+SCROLLH, vert.xmax, vert.ymax);
|
||||
else
|
||||
sdrawline(vert.xmax, vert.ymin, vert.xmax, vert.ymax);
|
||||
}
|
||||
}
|
||||
|
||||
/* free temporary memory used for drawing scrollers */
|
||||
void UI_view2d_free_scrollers(View2DScrollers *scrollers)
|
||||
{
|
||||
MEM_freeN(scrollers);
|
||||
}
|
||||
|
||||
/* *********************************************************************** */
|
||||
/* Coordinate Conversions */
|
||||
|
||||
@@ -49,57 +49,33 @@
|
||||
#include "UI_view2d.h"
|
||||
|
||||
/* ********************************************************* */
|
||||
/* VIEW PANNING OPERATOR */
|
||||
|
||||
/* ********************************************************* */
|
||||
/* View Panning Operator */
|
||||
|
||||
/*
|
||||
operator state vars:
|
||||
(currently none) // XXX must figure out some vars to expose to user!
|
||||
|
||||
operator customdata:
|
||||
area pointer to (active) area
|
||||
x, y last used mouse pos
|
||||
(more, see below)
|
||||
|
||||
functions:
|
||||
|
||||
init() set default property values, find v2d based on context
|
||||
|
||||
apply() split area based on state vars
|
||||
|
||||
exit() cleanup, send notifier
|
||||
|
||||
cancel() remove duplicated area
|
||||
|
||||
callbacks:
|
||||
|
||||
exec() execute without any user interaction, based on state vars
|
||||
call init(), apply(), exit()
|
||||
|
||||
invoke() gets called on mouse click in action-widget
|
||||
call init(), add modal handler
|
||||
call apply() with initial motion
|
||||
|
||||
modal() accept modal events while doing it
|
||||
call move-areas code with delta motion
|
||||
call exit() or cancel() and remove handler
|
||||
|
||||
*/
|
||||
/* This group of operators come in several forms:
|
||||
* 1) Modal 'dragging' with MMB - where movement of mouse dictates amount to pan view by
|
||||
* 2) Scrollwheel 'steps' - rolling mousewheel by one step moves view by predefined amount
|
||||
* 3) Scroller drag - similar to 1), but only while mouse is still in view
|
||||
*
|
||||
* In order to make sure this works, each operator must define the following RNA-Operator Props:
|
||||
* deltax, deltay - define how much to move view by (relative to zoom-correction factor)
|
||||
*/
|
||||
|
||||
/* ------------------ Shared 'core' stuff ---------------------- */
|
||||
|
||||
/* temp customdata for operator */
|
||||
typedef struct v2dViewPanData {
|
||||
ARegion *region; /* region we're operating in */
|
||||
View2D *v2d; /* view2d we're operating in */
|
||||
|
||||
float facx, facy; /* amount to move view relative to zoom */
|
||||
|
||||
/* mouse stuff... */
|
||||
int lastx, lasty; /* previous x/y values of mouse in area */
|
||||
int x, y; /* current x/y values of mosue in area */
|
||||
/* options for version 1 */
|
||||
int startx, starty; /* mouse x/y values in window when operator was initiated */
|
||||
int lastx, lasty; /* previous x/y values of mouse in window */
|
||||
} v2dViewPanData;
|
||||
|
||||
|
||||
static int pan_view_init(bContext *C, wmOperator *op)
|
||||
|
||||
/* initialise panning customdata */
|
||||
static int view_pan_init(bContext *C, wmOperator *op)
|
||||
{
|
||||
v2dViewPanData *vpd;
|
||||
ARegion *ar;
|
||||
@@ -123,19 +99,20 @@ static int pan_view_init(bContext *C, wmOperator *op)
|
||||
winy= (float)(ar->winrct.ymax - ar->winrct.ymin);
|
||||
vpd->facx= (v2d->cur.xmax - v2d->cur.xmin) / winx;
|
||||
vpd->facy= (v2d->cur.ymax - v2d->cur.ymin) / winy;
|
||||
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void pan_view_apply(bContext *C, wmOperator *op)
|
||||
/* apply transform to view (i.e. adjust 'cur' rect) */
|
||||
static void view_pan_apply(bContext *C, wmOperator *op)
|
||||
{
|
||||
v2dViewPanData *vpd= op->customdata;
|
||||
View2D *v2d= vpd->v2d;
|
||||
float dx, dy;
|
||||
|
||||
/* calculate amount to move view by */
|
||||
dx= vpd->facx * (vpd->lastx - vpd->x);
|
||||
dy= vpd->facy * (vpd->lasty - vpd->y);
|
||||
dx= vpd->facx * (float)RNA_int_get(op->ptr, "deltax");
|
||||
dy= vpd->facy * (float)RNA_int_get(op->ptr, "deltay");
|
||||
|
||||
/* only move view on an axis if change is allowed */
|
||||
if ((v2d->keepofs & V2D_LOCKOFS_X)==0) {
|
||||
@@ -147,67 +124,96 @@ static void pan_view_apply(bContext *C, wmOperator *op)
|
||||
v2d->cur.ymax += dy;
|
||||
}
|
||||
|
||||
vpd->lastx= vpd->x;
|
||||
vpd->lasty= vpd->y;
|
||||
|
||||
WM_event_add_notifier(C->wm, C->window, 0, WM_NOTE_SCREEN_CHANGED, 0, NULL);
|
||||
/* request updates to be done... */
|
||||
WM_event_add_notifier(C->wm, C->window, 0, WM_NOTE_AREA_REDRAW, 0, NULL);
|
||||
/* XXX: add WM_NOTE_TIME_CHANGED? */
|
||||
}
|
||||
|
||||
static void pan_view_exit(bContext *C, wmOperator *op)
|
||||
/* cleanup temp customdata */
|
||||
static void view_pan_exit(bContext *C, wmOperator *op)
|
||||
{
|
||||
if (op->customdata) {
|
||||
MEM_freeN(op->customdata);
|
||||
op->customdata= NULL;
|
||||
WM_event_remove_modal_handler(&C->window->handlers, op);
|
||||
op->customdata= NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* ------------------ Modal Drag Version (1) ---------------------- */
|
||||
|
||||
static int pan_view_exec(bContext *C, wmOperator *op)
|
||||
/* for 'redo' only, with no user input */
|
||||
static int view_pan_exec(bContext *C, wmOperator *op)
|
||||
{
|
||||
if (!pan_view_init(C, op))
|
||||
if (!view_pan_init(C, op))
|
||||
return OPERATOR_CANCELLED;
|
||||
|
||||
pan_view_apply(C, op);
|
||||
pan_view_exit(C, op);
|
||||
view_pan_apply(C, op);
|
||||
view_pan_exit(C, op);
|
||||
return OPERATOR_FINISHED;
|
||||
}
|
||||
|
||||
static int pan_view_invoke(bContext *C, wmOperator *op, wmEvent *event)
|
||||
/* set up modal operator and relevant settings */
|
||||
static int view_pan_invoke(bContext *C, wmOperator *op, wmEvent *event)
|
||||
{
|
||||
v2dViewPanData *vpd= op->customdata;
|
||||
v2dViewPanData *vpd;
|
||||
View2D *v2d;
|
||||
|
||||
pan_view_init(C, op);
|
||||
/* set up customdata */
|
||||
if (!view_pan_init(C, op))
|
||||
return OPERATOR_CANCELLED;
|
||||
|
||||
vpd= op->customdata;
|
||||
vpd->lastx= vpd->x= event->x;
|
||||
vpd->lasty= vpd->y= event->y;
|
||||
v2d= vpd->v2d;
|
||||
|
||||
/* set initial settings */
|
||||
vpd->startx= vpd->lastx= event->x;
|
||||
vpd->starty= vpd->lasty= event->y;
|
||||
RNA_int_set(op->ptr, "deltax", 0);
|
||||
RNA_int_set(op->ptr, "deltay", 0);
|
||||
|
||||
#if 0 // XXX - enable this when cursors are working properly
|
||||
if (v2d->keepofs & V2D_LOCKOFS_X)
|
||||
WM_set_cursor(C, BC_NS_SCROLLCURSOR);
|
||||
else if (v2d->keepofs & V2D_LOCKOFS_Y)
|
||||
WM_set_cursor(C, BC_EW_SCROLLCURSOR);
|
||||
else
|
||||
WM_set_cursor(C, BC_NSEW_SCROLLCURSOR);
|
||||
#endif // XXX - enable this when cursors are working properly
|
||||
|
||||
pan_view_apply(C, op);
|
||||
|
||||
/* add temp handler */
|
||||
WM_event_add_modal_handler(&C->window->handlers, op);
|
||||
|
||||
return OPERATOR_RUNNING_MODAL;
|
||||
}
|
||||
|
||||
static int pan_view_modal(bContext *C, wmOperator *op, wmEvent *event)
|
||||
/* handle user input - calculations of mouse-movement need to be done here, not in the apply callback! */
|
||||
static int view_pan_modal(bContext *C, wmOperator *op, wmEvent *event)
|
||||
{
|
||||
v2dViewPanData *vpd= op->customdata;
|
||||
|
||||
/* execute the events */
|
||||
switch(event->type) {
|
||||
switch (event->type) {
|
||||
case MOUSEMOVE:
|
||||
vpd->x= event->x;
|
||||
vpd->y= event->y;
|
||||
{
|
||||
/* calculate new delta transform, then store mouse-coordinates for next-time */
|
||||
RNA_int_set(op->ptr, "deltax", (vpd->lastx - event->x));
|
||||
RNA_int_set(op->ptr, "deltay", (vpd->lasty - event->y));
|
||||
vpd->lastx= event->x;
|
||||
vpd->lasty= event->y;
|
||||
|
||||
pan_view_apply(C, op);
|
||||
view_pan_apply(C, op);
|
||||
}
|
||||
break;
|
||||
|
||||
case MIDDLEMOUSE:
|
||||
if (event->val==0) {
|
||||
pan_view_exit(C, op);
|
||||
WM_event_remove_modal_handler(&C->window->handlers, op);
|
||||
/* calculate overall delta mouse-movement for redo */
|
||||
RNA_int_set(op->ptr, "deltax", (vpd->startx - vpd->lastx));
|
||||
RNA_int_set(op->ptr, "deltay", (vpd->starty - vpd->lasty));
|
||||
|
||||
view_pan_exit(C, op);
|
||||
//WM_set_cursor(C, CURSOR_STD); // XXX - enable this when cursors are working properly
|
||||
WM_event_remove_modal_handler(&C->window->handlers, op);
|
||||
|
||||
return OPERATOR_FINISHED;
|
||||
}
|
||||
break;
|
||||
@@ -218,14 +224,164 @@ static int pan_view_modal(bContext *C, wmOperator *op, wmEvent *event)
|
||||
|
||||
void ED_View2D_OT_view_pan(wmOperatorType *ot)
|
||||
{
|
||||
PropertyRNA *prop;
|
||||
|
||||
/* identifiers */
|
||||
ot->name= "Pan View";
|
||||
ot->idname= "ED_View2D_OT_view_pan";
|
||||
|
||||
/* api callbacks */
|
||||
ot->exec= pan_view_exec;
|
||||
ot->invoke= pan_view_invoke;
|
||||
ot->modal= pan_view_modal;
|
||||
ot->exec= view_pan_exec;
|
||||
ot->invoke= view_pan_invoke;
|
||||
ot->modal= view_pan_modal;
|
||||
|
||||
/* rna - must keep these in sync with the other operators */
|
||||
prop= RNA_def_property(ot->srna, "deltax", PROP_INT, PROP_NONE);
|
||||
prop= RNA_def_property(ot->srna, "deltay", PROP_INT, PROP_NONE);
|
||||
}
|
||||
|
||||
/* ------------------ Scrollwheel Versions (2) ---------------------- */
|
||||
// XXX should these be unified a bit?
|
||||
|
||||
/* this operator only needs this single callback, where it callsthe view_pan_*() methods */
|
||||
static int view_scrollright_exec(bContext *C, wmOperator *op)
|
||||
{
|
||||
/* initialise default settings (and validate if ok to run) */
|
||||
if (!view_pan_init(C, op))
|
||||
return OPERATOR_CANCELLED;
|
||||
|
||||
/* set RNA-Props - only movement in positive x-direction */
|
||||
RNA_int_set(op->ptr, "deltax", 20);
|
||||
RNA_int_set(op->ptr, "deltay", 0);
|
||||
|
||||
/* apply movement, then we're done */
|
||||
view_pan_apply(C, op);
|
||||
view_pan_exit(C, op);
|
||||
|
||||
return OPERATOR_FINISHED;
|
||||
}
|
||||
|
||||
void ED_View2D_OT_view_scrollright(wmOperatorType *ot)
|
||||
{
|
||||
PropertyRNA *prop;
|
||||
|
||||
/* identifiers */
|
||||
ot->name= "Scroll Right";
|
||||
ot->idname= "ED_View2D_OT_view_rightscroll";
|
||||
|
||||
/* api callbacks */
|
||||
ot->exec= view_scrollright_exec;
|
||||
|
||||
/* rna - must keep these in sync with the other operators */
|
||||
prop= RNA_def_property(ot->srna, "deltax", PROP_INT, PROP_NONE);
|
||||
prop= RNA_def_property(ot->srna, "deltay", PROP_INT, PROP_NONE);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* this operator only needs this single callback, where it callsthe view_pan_*() methods */
|
||||
static int view_scrollleft_exec(bContext *C, wmOperator *op)
|
||||
{
|
||||
/* initialise default settings (and validate if ok to run) */
|
||||
if (!view_pan_init(C, op))
|
||||
return OPERATOR_CANCELLED;
|
||||
|
||||
/* set RNA-Props - only movement in negative x-direction */
|
||||
RNA_int_set(op->ptr, "deltax", -20);
|
||||
RNA_int_set(op->ptr, "deltay", 0);
|
||||
|
||||
/* apply movement, then we're done */
|
||||
view_pan_apply(C, op);
|
||||
view_pan_exit(C, op);
|
||||
|
||||
return OPERATOR_FINISHED;
|
||||
}
|
||||
|
||||
void ED_View2D_OT_view_scrollleft(wmOperatorType *ot)
|
||||
{
|
||||
PropertyRNA *prop;
|
||||
|
||||
/* identifiers */
|
||||
ot->name= "Scroll Left";
|
||||
ot->idname= "ED_View2D_OT_view_leftscroll";
|
||||
|
||||
/* api callbacks */
|
||||
ot->exec= view_scrollleft_exec;
|
||||
|
||||
/* rna - must keep these in sync with the other operators */
|
||||
prop= RNA_def_property(ot->srna, "deltax", PROP_INT, PROP_NONE);
|
||||
prop= RNA_def_property(ot->srna, "deltay", PROP_INT, PROP_NONE);
|
||||
}
|
||||
|
||||
|
||||
/* this operator only needs this single callback, where it callsthe view_pan_*() methods */
|
||||
static int view_scrolldown_exec(bContext *C, wmOperator *op)
|
||||
{
|
||||
/* initialise default settings (and validate if ok to run) */
|
||||
if (!view_pan_init(C, op))
|
||||
return OPERATOR_CANCELLED;
|
||||
|
||||
/* set RNA-Props - only movement in positive x-direction */
|
||||
RNA_int_set(op->ptr, "deltax", 0);
|
||||
RNA_int_set(op->ptr, "deltay", -20);
|
||||
|
||||
/* apply movement, then we're done */
|
||||
view_pan_apply(C, op);
|
||||
view_pan_exit(C, op);
|
||||
|
||||
return OPERATOR_FINISHED;
|
||||
}
|
||||
|
||||
void ED_View2D_OT_view_scrolldown(wmOperatorType *ot)
|
||||
{
|
||||
PropertyRNA *prop;
|
||||
|
||||
/* identifiers */
|
||||
ot->name= "Scroll Down";
|
||||
ot->idname= "ED_View2D_OT_view_downscroll";
|
||||
|
||||
/* api callbacks */
|
||||
ot->exec= view_scrolldown_exec;
|
||||
|
||||
/* rna - must keep these in sync with the other operators */
|
||||
prop= RNA_def_property(ot->srna, "deltax", PROP_INT, PROP_NONE);
|
||||
prop= RNA_def_property(ot->srna, "deltay", PROP_INT, PROP_NONE);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* this operator only needs this single callback, where it callsthe view_pan_*() methods */
|
||||
static int view_scrollup_exec(bContext *C, wmOperator *op)
|
||||
{
|
||||
/* initialise default settings (and validate if ok to run) */
|
||||
if (!view_pan_init(C, op))
|
||||
return OPERATOR_CANCELLED;
|
||||
|
||||
/* set RNA-Props - only movement in negative x-direction */
|
||||
RNA_int_set(op->ptr, "deltax", 0);
|
||||
RNA_int_set(op->ptr, "deltay", 20);
|
||||
|
||||
/* apply movement, then we're done */
|
||||
view_pan_apply(C, op);
|
||||
view_pan_exit(C, op);
|
||||
|
||||
return OPERATOR_FINISHED;
|
||||
}
|
||||
|
||||
void ED_View2D_OT_view_scrollup(wmOperatorType *ot)
|
||||
{
|
||||
PropertyRNA *prop;
|
||||
|
||||
/* identifiers */
|
||||
ot->name= "Scroll Up";
|
||||
ot->idname= "ED_View2D_OT_view_upscroll";
|
||||
|
||||
/* api callbacks */
|
||||
ot->exec= view_scrollup_exec;
|
||||
|
||||
/* rna - must keep these in sync with the other operators */
|
||||
prop= RNA_def_property(ot->srna, "deltax", PROP_INT, PROP_NONE);
|
||||
prop= RNA_def_property(ot->srna, "deltay", PROP_INT, PROP_NONE);
|
||||
}
|
||||
|
||||
/* ********************************************************* */
|
||||
@@ -234,6 +390,11 @@ void ED_View2D_OT_view_pan(wmOperatorType *ot)
|
||||
void ui_view2d_operatortypes(void)
|
||||
{
|
||||
WM_operatortype_append(ED_View2D_OT_view_pan);
|
||||
|
||||
WM_operatortype_append(ED_View2D_OT_view_scrollleft);
|
||||
WM_operatortype_append(ED_View2D_OT_view_scrollright);
|
||||
WM_operatortype_append(ED_View2D_OT_view_scrollup);
|
||||
WM_operatortype_append(ED_View2D_OT_view_scrolldown);
|
||||
}
|
||||
|
||||
void UI_view2d_keymap(wmWindowManager *wm)
|
||||
@@ -243,11 +404,11 @@ void UI_view2d_keymap(wmWindowManager *wm)
|
||||
/* pan/scroll operators */
|
||||
WM_keymap_add_item(&wm->view2dkeymap, "ED_View2D_OT_view_pan", MIDDLEMOUSE, KM_PRESS, 0, 0);
|
||||
|
||||
//WM_keymap_add_item(&wm->view2dkeymap, "ED_View2D_OT_view_scrollright", WHEELDOWNMOUSE, KM_PRESS, KM_CTRL, 0);
|
||||
//WM_keymap_add_item(&wm->view2dkeymap, "ED_View2D_OT_view_scrollleft", WHEELUPMOUSE, KM_CTRL, 0, 0);
|
||||
WM_keymap_add_item(&wm->view2dkeymap, "ED_View2D_OT_view_rightscroll", WHEELDOWNMOUSE, KM_PRESS, KM_CTRL, 0);
|
||||
WM_keymap_add_item(&wm->view2dkeymap, "ED_View2D_OT_view_leftscroll", WHEELUPMOUSE, KM_PRESS, KM_CTRL, 0);
|
||||
|
||||
//WM_keymap_add_item(&wm->view2dkeymap, "ED_View2D_OT_view_scrolldown", WHEELDOWNMOUSE, KM_PRESS, KM_SHIFT, 0);
|
||||
//WM_keymap_add_item(&wm->view2dkeymap, "ED_View2D_OT_view_scrollup", WHEELUPMOUSE, KM_SHIFT, 0, 0);
|
||||
WM_keymap_add_item(&wm->view2dkeymap, "ED_View2D_OT_view_downscroll", WHEELDOWNMOUSE, KM_PRESS, KM_SHIFT, 0);
|
||||
WM_keymap_add_item(&wm->view2dkeymap, "ED_View2D_OT_view_upscroll", WHEELUPMOUSE, KM_PRESS, KM_SHIFT, 0);
|
||||
|
||||
/* zoom */
|
||||
|
||||
|
||||
@@ -350,6 +350,8 @@ static void outliner_main_area_draw(const bContext *C, ARegion *ar)
|
||||
awidth= width= ar->winrct.xmax - ar->winrct.xmin;
|
||||
aheight= height= ar->winrct.ymax - ar->winrct.ymin;
|
||||
|
||||
UI_view2d_update_size(v2d, awidth, aheight);
|
||||
|
||||
/* create table */
|
||||
cell.space= soutliner;
|
||||
cell.lastrow= -1;
|
||||
@@ -405,7 +407,8 @@ static void outliner_main_area_draw(const bContext *C, ARegion *ar)
|
||||
rct.ymax= 0;
|
||||
|
||||
/* set matrix for 2d-view controls */
|
||||
UI_view2d_ortho(C, v2d);
|
||||
//UI_view2d_view_init(C, v2d);
|
||||
UI_view2d_view_ortho(C, v2d);
|
||||
|
||||
/* create and draw table */
|
||||
table= UI_table_create(rows, 2, &rct, rna_table_cell_func, &cell);
|
||||
@@ -415,6 +418,13 @@ static void outliner_main_area_draw(const bContext *C, ARegion *ar)
|
||||
RNA_property_collection_end(&cell.iter);
|
||||
|
||||
UI_table_free(table);
|
||||
|
||||
/* reset view matrix */
|
||||
UI_view2d_view_restore(C);
|
||||
|
||||
/* scrollers */
|
||||
// FIXME: this is just a quick test
|
||||
UI_view2d_draw_scrollers(C, &ar->v2d, NULL, (0));
|
||||
}
|
||||
|
||||
static void outliner_main_area_free(ARegion *ar)
|
||||
|
||||
@@ -119,15 +119,15 @@ static void time_main_area_draw(const bContext *C, ARegion *ar)
|
||||
|
||||
winx= ar->winrct.xmax-ar->winrct.xmin;
|
||||
winy= ar->winrct.ymax-ar->winrct.ymin;
|
||||
|
||||
|
||||
UI_view2d_update_size(v2d, winx, winy);
|
||||
|
||||
/* clear and setup matrix */
|
||||
UI_GetThemeColor3fv(TH_BACK, col);
|
||||
glClearColor(col[0], col[1], col[2], 0.0);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
UI_view2d_ortho(C, v2d);
|
||||
|
||||
UI_view2d_view_ortho(C, v2d);
|
||||
|
||||
/* start and end frame */
|
||||
time_draw_sfra_efra(C, stime, ar);
|
||||
@@ -143,6 +143,13 @@ static void time_main_area_draw(const bContext *C, ARegion *ar)
|
||||
|
||||
/* markers */
|
||||
draw_markers_time(C, 0);
|
||||
|
||||
/* reset view matrix */
|
||||
UI_view2d_view_restore(C);
|
||||
|
||||
/* scrollers */
|
||||
// FIXME: this is just a quick test
|
||||
UI_view2d_draw_scrollers(C, &ar->v2d, NULL, (0));
|
||||
}
|
||||
|
||||
static void time_main_area_listener(ARegion *ar, wmNotifier *wmn)
|
||||
|
||||
Reference in New Issue
Block a user