[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [17656] branches/blender2.5/blender/source /blender/editors: View2D - Another WIP commit
Joshua Leung
aligorith at gmail.com
Mon Dec 1 01:20:19 CET 2008
Revision: 17656
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=17656
Author: aligorith
Date: 2008-12-01 01:20:19 +0100 (Mon, 01 Dec 2008)
Log Message:
-----------
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!
Modified Paths:
--------------
branches/blender2.5/blender/source/blender/editors/include/UI_view2d.h
branches/blender2.5/blender/source/blender/editors/interface/view2d.c
branches/blender2.5/blender/source/blender/editors/interface/view2d_ops.c
branches/blender2.5/blender/source/blender/editors/space_outliner/space_outliner.c
branches/blender2.5/blender/source/blender/editors/space_time/space_time.c
Modified: branches/blender2.5/blender/source/blender/editors/include/UI_view2d.h
===================================================================
--- branches/blender2.5/blender/source/blender/editors/include/UI_view2d.h 2008-11-30 23:27:10 UTC (rev 17655)
+++ branches/blender2.5/blender/source/blender/editors/include/UI_view2d.h 2008-12-01 00:20:19 UTC (rev 17656)
@@ -79,17 +79,19 @@
/* 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);
Modified: branches/blender2.5/blender/source/blender/editors/interface/view2d.c
===================================================================
--- branches/blender2.5/blender/source/blender/editors/interface/view2d.c 2008-11-30 23:27:10 UTC (rev 17655)
+++ branches/blender2.5/blender/source/blender/editors/interface/view2d.c 2008-12-01 00:20:19 UTC (rev 17656)
@@ -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 @@
/* 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 @@
/* 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 @@
/* 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,8 +586,71 @@
/* *********************************************************************** */
/* 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 */
Modified: branches/blender2.5/blender/source/blender/editors/interface/view2d_ops.c
===================================================================
--- branches/blender2.5/blender/source/blender/editors/interface/view2d_ops.c 2008-11-30 23:27:10 UTC (rev 17655)
+++ branches/blender2.5/blender/source/blender/editors/interface/view2d_ops.c 2008-12-01 00:20:19 UTC (rev 17656)
@@ -49,57 +49,33 @@
#include "UI_view2d.h"
/* ********************************************************* */
+/* VIEW PANNING OPERATOR */
-/* ********************************************************* */
-/* View Panning Operator */
+/* 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)
+ */
-/*
-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
-
-*/
-
+ /* ------------------ 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 @@
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);
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list