View2D - Some more tweaks...

* Improved scrollbar drawing a bit more - only cosmetic lines
* Added new view2d view-matrix api method to only use 'cur' coordinates on one axis, for use when drawing markers, etc. that need to be glued to a certain time but stay fixed in space in another dimension. This should improve the sitation for drawing markers
* To aid testing, adding markers now sets the marker to have frame number as it's "name". This will need to be removed later...
This commit is contained in:
Joshua Leung 2008-12-02 09:43:23 +00:00
parent f8d5883a5b
commit 628d7013e2
7 changed files with 175 additions and 110 deletions

@ -80,6 +80,7 @@ typedef struct View2DScrollers View2DScrollers;
/* setup */
void UI_view2d_view_ortho(const struct bContext *C, struct View2D *v2d);
void UI_view2d_view_orthospecial(const struct bContext *C, struct View2D *v2d, short xaxis);
void UI_view2d_view_restore(const struct bContext *C);
void UI_view2d_update_size(struct View2D *v2d, int winx, int winy);
@ -101,6 +102,7 @@ void UI_view2d_view_to_region(struct View2D *v2d, float x, float y, short *regio
void UI_view2d_to_region_no_clip(struct View2D *v2d, float x, float y, short *regionx, short *region_y);
/* utilities */
struct View2D *UI_view2d_fromcontext(const struct bContext *C);
void UI_view2d_getscale(struct View2D *v2d, float *x, float *y);

@ -2069,16 +2069,14 @@ static void ui_draw_text_icon(uiBut *but)
/* If there's an icon too (made with uiDefIconTextBut) then draw the icon
and offset the text label to accomodate it */
/* XXX 2.50 need interface_icons.c */
#if 0
if ( (but->flag & UI_HAS_ICON) && (but->flag & UI_ICON_LEFT) ) {
if ( (but->flag & UI_HAS_ICON) && (but->flag & UI_ICON_LEFT) )
{
ui_draw_icon(but, but->icon, 0);
if(but->editstr || (but->flag & UI_TEXT_LEFT)) x= but->x1 + but->aspect*UI_icon_get_width(but->icon)+5.0;
else x= (but->x1+but->x2-but->strwidth+1)/2.0;
}
else
#endif
{
if(but->editstr || (but->flag & UI_TEXT_LEFT))
x= but->x1+4.0;

@ -46,52 +46,7 @@
#include "UI_view2d.h"
/* *********************************************************************** */
/* Setup and Refresh Code */
/* Set view matrices to ortho for View2D drawing */
void UI_view2d_view_ortho(const bContext *C, View2D *v2d)
{
ARegion *region= C->region;
int winx, winy;
float ofsx1, ofsy1, ofsx2, ofsy2;
/* calculate extents of region */
winx= region->winrct.xmax - region->winrct.xmin;
winy= region->winrct.ymax - region->winrct.ymin;
ofsx1= ofsy1= ofsx2= ofsy2= 0.0f;
/* these checks here make sure that the region is large-enough to show scrollers */
if ((winx > SCROLLB+10) && (winy > SCROLLH+10)) {
/* calculate offset factor required on each axis */
if (v2d->scroll & L_SCROLL)
ofsy1= (float)SCROLLB;
if (v2d->scroll & R_SCROLL)
ofsy2= (float)SCROLLB;
if (v2d->scroll & T_SCROLL)
ofsx1= (float)SCROLLH;
if (v2d->scroll & B_SCROLL)
ofsx2= (float)SCROLLH;
}
/* note: 0.375 is constant factor to get 1:1 correspondance with pixels */
wmOrtho2(C->window, v2d->cur.xmin-ofsx1-0.375f, v2d->cur.xmax-ofsx2-0.375f, v2d->cur.ymin-ofsy1-0.375f, v2d->cur.ymax-ofsx2-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);
}
/* ---------------------- */
/* Refresh and Validation */
/* Adjust mask size in response to view size changes */
// XXX pre2.5 -> this used to be called calc_scrollrcts()
@ -121,7 +76,7 @@ void UI_view2d_update_size(View2D *v2d, int winx, int winy)
}
/* horizontal scrollbar */
if ((v2d->scroll & B_SCROLL) || (v2d->scroll & B_SCROLLO)) {
if (v2d->scroll & (B_SCROLL|B_SCROLLO)) {
/* on bottom edge of region (B_SCROLLO is outliner, the ohter is for standard) */
v2d->hor= v2d->mask;
v2d->hor.ymax= SCROLLH;
@ -367,6 +322,86 @@ void UI_view2d_enforce_status(View2D *v2d, int winx, int winy)
}
}
/* *********************************************************************** */
/* View Matrix Setup */
/* Set view matrices to use 'cur' rect as viewing frame for View2D drawing
* - Scrollbars are taken into account when making this matrix, given that most regions have them
*/
void UI_view2d_view_ortho(const bContext *C, View2D *v2d)
{
float ofsx1, ofsy1, ofsx2, ofsy2;
ofsx1= ofsy1= ofsx2= ofsy2= 0.0f;
/* calculate offset factor required on each axis */
if (v2d->scroll & L_SCROLL)
ofsy1= (float)SCROLLB;
if (v2d->scroll & R_SCROLL)
ofsy2= (float)SCROLLB;
if (v2d->scroll & T_SCROLL)
ofsx1= (float)SCROLLH;
if (v2d->scroll & B_SCROLL)
ofsx2= (float)SCROLLH;
/* set the matrix - pixel offsets (-0.375) for 1:1 correspondance are not applied,
* as they were causing some unwanted offsets when drawing
*/
wmOrtho2(C->window, v2d->cur.xmin-ofsx1, v2d->cur.xmax-ofsx2, v2d->cur.ymin-ofsy1, v2d->cur.ymax-ofsx2);
}
/* Set view matices to only use one axis of 'cur' only
* - Scrollbars on appropriate axis will be taken into account
*
* - xaxis = if non-zero, only use cur x-axis, otherwise use cur-yaxis (mostly this will be used for x)
*/
void UI_view2d_view_orthospecial(const bContext *C, View2D *v2d, short xaxis)
{
ARegion *region= C->region;
int winx, winy;
float ofsx1, ofsy1, ofsx2, ofsy2;
/* calculate extents of region */
winx= region->winrct.xmax - region->winrct.xmin;
winy= region->winrct.ymax - region->winrct.ymin;
ofsx1= ofsy1= ofsx2= ofsy2= 0.0f;
/* calculate offset factor required on each axis */
if (v2d->scroll & L_SCROLL)
ofsy1= (float)SCROLLB;
if (v2d->scroll & R_SCROLL)
ofsy2= (float)SCROLLB;
if (v2d->scroll & T_SCROLL)
ofsx1= (float)SCROLLH;
if (v2d->scroll & B_SCROLL)
ofsx2= (float)SCROLLH;
/* set the matrix - pixel offsets (-0.375) for 1:1 correspondance are not applied,
* as they were causing some unwanted offsets when drawing
*/
if (xaxis)
wmOrtho2(C->window, v2d->cur.xmin-ofsx1, v2d->cur.xmax-ofsx2, 0, winy);
else
wmOrtho2(C->window, 0, winx, v2d->cur.ymin-ofsy1, v2d->cur.ymax-ofsx2);
}
/* 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;
/* set default region matrix - pixel offsets (0.375) for 1:1 correspondance are not applied,
* as they were causing some unwanted offsets when drawing
*/
wmOrtho2(C->window, 0, winx, 0, winy);
}
/* *********************************************************************** */
/* Gridlines */
@ -498,7 +533,6 @@ void UI_view2d_draw_grid(const bContext *C, View2D *v2d, View2DGrid *grid, int f
/* minor gridlines */
step= (v2d->mask.xmax - v2d->mask.xmin + 1) / MINGRIDSTEP;
UI_ThemeColor(TH_GRID);
for (a=0; a<step; a++) {
@ -512,7 +546,6 @@ void UI_view2d_draw_grid(const bContext *C, View2D *v2d, View2DGrid *grid, int f
/* major gridlines */
vec2[0]= vec1[0]-= 0.5f*grid->dx;
UI_ThemeColorShade(TH_GRID, 16);
step++;
@ -591,7 +624,7 @@ struct View2DScrollers {
View2DGrid *grid; /* grid for coordinate drawing */
int vert_min, vert_max; /* vertical scrollbar - current 'focus' button */
int hor_min, hor_max; /* horizontal scrollbar - current 'focus' button */
int hor_min, hor_max; /* horizontal scrollbar - current 'focus' button */
};
/* Calculate relevant scroller properties */
@ -666,19 +699,30 @@ void UI_view2d_draw_scrollers(const bContext *C, View2D *v2d, View2DScrollers *s
/* slider 'button' */
// FIXME: implement fancy one... but only when we get this working first!
UI_ThemeColorShade(TH_SHADE1, dark);
glRecti(scrollers->hor_min, hor.ymin, scrollers->hor_max, hor.ymax);
{
UI_ThemeColorShade(TH_SHADE1, dark);
glRecti(scrollers->hor_min, hor.ymin, scrollers->hor_max, hor.ymax);
/* draw lines on either end of 'box' */
glLineWidth(2.0);
UI_ThemeColorShade(TH_SHADE1, darker);
sdrawline(scrollers->hor_min, hor.ymin, scrollers->hor_min, hor.ymax);
sdrawline(scrollers->hor_max, hor.ymin, scrollers->hor_max, hor.ymax);
glLineWidth(1.0);
}
/* draw lines on either end of 'box' */
glLineWidth(2.0);
UI_ThemeColorShade(TH_SHADE1, darker);
sdrawline(scrollers->hor_min, hor.ymin, scrollers->hor_min, hor.ymax);
sdrawline(scrollers->hor_max, hor.ymin, scrollers->hor_max, hor.ymax);
glLineWidth(1.0);
/* scale indicators */
// XXX will need to update the font drawing when the new stuff comes in
if (v2d->scroll & HOR_SCROLLGRID) {
}
/* decoration bright line */
/* decoration outer bevel line */
UI_ThemeColorShade(TH_SHADE1, lighter);
sdrawline(hor.xmin, hor.ymax, hor.xmax, hor.ymax);
if (v2d->scroll & B_SCROLL)
sdrawline(hor.xmin, hor.ymax, hor.xmax, hor.ymax);
else if (v2d->scroll & T_SCROLL)
sdrawline(hor.xmin, hor.ymin, hor.xmax, hor.ymin);
}
/* vertical scrollbar */
@ -689,20 +733,28 @@ void UI_view2d_draw_scrollers(const bContext *C, View2D *v2d, View2DScrollers *s
/* slider 'button' */
// FIXME: implement fancy one... but only when we get this working first!
UI_ThemeColorShade(TH_SHADE1, dark);
glRecti(vert.xmin, scrollers->vert_min, vert.xmax, scrollers->vert_max);
{
UI_ThemeColorShade(TH_SHADE1, dark);
glRecti(vert.xmin, scrollers->vert_min, vert.xmax, scrollers->vert_max);
/* draw lines on either end of 'box' */
glLineWidth(2.0);
UI_ThemeColorShade(TH_SHADE1, darker);
sdrawline(vert.xmin, scrollers->vert_min, vert.xmax, scrollers->vert_min);
sdrawline(vert.xmin, scrollers->vert_max, vert.xmax, scrollers->vert_max);
glLineWidth(1.0);
}
/* draw lines on either end of 'box' */
glLineWidth(2.0);
UI_ThemeColorShade(TH_SHADE1, darker);
sdrawline(vert.xmin, scrollers->vert_min, vert.xmax, scrollers->vert_min);
sdrawline(vert.xmin, scrollers->vert_max, vert.xmax, scrollers->vert_max);
glLineWidth(1.0);
/* scale indiators */
// XXX will need to update the font drawing when the new stuff comes in
if (v2d->scroll & VERT_SCROLLGRID) {
}
/* decoration black line */
UI_ThemeColorShade(TH_SHADE1, darker);
if (v2d->scroll & HOR_SCROLL)
sdrawline(vert.xmax, vert.ymin+SCROLLH, vert.xmax, vert.ymax);
/* decoration outer bevel line */
UI_ThemeColorShade(TH_SHADE1, lighter);
if (v2d->scroll & R_SCROLL)
sdrawline(vert.xmin, vert.ymin, vert.xmin, vert.ymax);
else
sdrawline(vert.xmax, vert.ymin, vert.xmax, vert.ymax);
}
@ -800,6 +852,14 @@ void UI_view2d_to_region_no_clip(View2D *v2d, float x, float y, short *regionx,
/* *********************************************************************** */
/* Utilities */
/* View2D data by default resides in region, so get from region stored in context */
View2D *UI_view2d_fromcontext(const bContext *C)
{
if (C->area == NULL) return NULL;
if (C->region == NULL) return NULL;
return &(C->region->v2d);
}
/* Calculate the scale per-axis of the drawing-area
* - Is used to inverse correct drawing of icons, etc. that need to follow view
* but not be affected by scale

@ -48,6 +48,11 @@
#include "UI_resources.h"
#include "UI_view2d.h"
/* ********************************************************* */
/* General Polling Funcs */
/* ********************************************************* */
/* VIEW PANNING OPERATOR */
@ -241,7 +246,6 @@ void ED_View2D_OT_view_pan(wmOperatorType *ot)
/* ------------------ Scrollwheel Versions (2) ---------------------- */
// XXX scroll down operator not working yet! (doesn't get called on wheeldownmouse for some reason)
/* this operator only needs this single callback, where it callsthe view_pan_*() methods */
static int view_scrollright_exec(bContext *C, wmOperator *op)
{
@ -312,7 +316,6 @@ void ED_View2D_OT_view_scrollleft(wmOperatorType *ot)
prop= RNA_def_property(ot->srna, "deltay", PROP_INT, PROP_NONE);
}
// XXX scroll down operator not working yet! (doesn't get called on wheeldownmouse for some reason)
/* this operator only needs this single callback, where it callsthe view_pan_*() methods */
static int view_scrolldown_exec(bContext *C, wmOperator *op)
{
@ -537,6 +540,9 @@ void ED_View2D_OT_view_zoomout(wmOperatorType *ot)
prop= RNA_def_property(ot->srna, "zoomfacy", PROP_FLOAT, PROP_NONE);
}
/* ********************************************************* */
/* Scrollers */
/* ********************************************************* */
/* Registration */
@ -561,15 +567,15 @@ 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_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_rightscroll", WHEELDOWNMOUSE, KM_ANY, KM_CTRL, 0);
WM_keymap_add_item(&wm->view2dkeymap, "ED_View2D_OT_view_leftscroll", WHEELUPMOUSE, KM_ANY, KM_CTRL, 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);
WM_keymap_add_item(&wm->view2dkeymap, "ED_View2D_OT_view_downscroll", WHEELDOWNMOUSE, KM_ANY, KM_SHIFT, 0);
WM_keymap_add_item(&wm->view2dkeymap, "ED_View2D_OT_view_upscroll", WHEELUPMOUSE, KM_ANY, KM_SHIFT, 0);
/* zoom */
WM_keymap_add_item(&wm->view2dkeymap, "ED_View2D_OT_view_zoomout", WHEELUPMOUSE, KM_PRESS, 0, 0);
WM_keymap_add_item(&wm->view2dkeymap, "ED_View2D_OT_view_zoomin", WHEELDOWNMOUSE, KM_PRESS, 0, 0);
WM_keymap_add_item(&wm->view2dkeymap, "ED_View2D_OT_view_zoomout", WHEELUPMOUSE, KM_ANY, 0, 0);
WM_keymap_add_item(&wm->view2dkeymap, "ED_View2D_OT_view_zoomin", WHEELDOWNMOUSE, KM_ANY, 0, 0);
WM_keymap_add_item(&wm->view2dkeymap, "ED_View2D_OT_view_zoomout", PADMINUS, KM_PRESS, 0, 0);
WM_keymap_add_item(&wm->view2dkeymap, "ED_View2D_OT_view_zoomin", PADPLUSKEY, KM_PRESS, 0, 0);

@ -81,14 +81,6 @@ static ListBase *context_get_markers(const bContext *C)
return &C->scene->markers;
}
static View2D *context_get_view2d(const bContext *C)
{
/* XXX solve, get from view2d api? */
SpaceTime *stime= C->area->spacedata.first;
return &stime->v2d;
}
/* ************* Marker Drawing ************ */
/* XXX */
@ -106,7 +98,7 @@ static void draw_marker(View2D *v2d, TimeMarker *marker, int cfra, int flag)
ypixels= v2d->mask.ymax-v2d->mask.ymin;
UI_view2d_getscale(v2d, &xscale, &yscale);
glScalef( 1.0/xscale, 1.0/yscale, 1.0);
glScalef(1.0/xscale, 1.0, 1.0);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
@ -137,7 +129,7 @@ static void draw_marker(View2D *v2d, TimeMarker *marker, int cfra, int flag)
ICON_MARKER;
}
UI_icon_draw(xpos*xscale-5.0, 8.0, icon_id);
UI_icon_draw(xpos*xscale-5.0, 16.0, icon_id);
glBlendFunc(GL_ONE, GL_ZERO);
glDisable(GL_BLEND);
@ -145,26 +137,26 @@ static void draw_marker(View2D *v2d, TimeMarker *marker, int cfra, int flag)
/* and the marker name too, shifted slightly to the top-right */
if(marker->name && marker->name[0]) {
if(marker->flag & SELECT) {
//BIF_ThemeColor(TH_TEXT_HI);
UI_ThemeColor(TH_TEXT_HI);
ui_rasterpos_safe(xpos*xscale+4.0, (ypixels<=39.0)?(ypixels-10.0):29.0, 1.0);
}
else {
// BIF_ThemeColor(TH_TEXT);
UI_ThemeColor(TH_TEXT);
if((marker->frame <= cfra) && (marker->frame+5 > cfra))
ui_rasterpos_safe(xpos*xscale+4.0, (ypixels<=39.0)?(ypixels-10.0):29.0, 1.0);
else
ui_rasterpos_safe(xpos*xscale+4.0, 17.0, 1.0);
}
// BIF_DrawString(G.font, marker->name, 0);
UI_DrawString(G.font, marker->name, 0);
}
glScalef(xscale, yscale, 1.0);
glScalef(xscale, 1.0, 1.0);
}
/* Draw Scene-Markers in time window */
void draw_markers_time(const bContext *C, int flag)
{
ListBase *markers= context_get_markers(C);
View2D *v2d= context_get_view2d(C);
View2D *v2d= UI_view2d_fromcontext(C);
TimeMarker *marker;
/* unselected markers are drawn at the first time */
@ -201,6 +193,7 @@ static int ed_marker_add(bContext *C, wmOperator *op)
marker = MEM_callocN(sizeof(TimeMarker), "TimeMarker");
marker->flag= SELECT;
marker->frame= frame;
sprintf(marker->name, "Frame %d", frame); // XXX - temp code only
BLI_addtail(markers, marker);
//BIF_undo_push("Add Marker");
@ -368,7 +361,7 @@ int WM_modal_tweak_check(wmEvent *evt, int tweak_event)
static int ed_marker_move_modal(bContext *C, wmOperator *op, wmEvent *evt)
{
MarkerMove *mm= op->customdata;
View2D *v2d= context_get_view2d(C);
View2D *v2d= UI_view2d_fromcontext(C);
TimeMarker *marker, *selmarker=NULL;
float dx, fac;
char str[256];
@ -612,7 +605,7 @@ static int find_nearest_marker_time(ListBase *markers, float dx)
static int ed_marker_select(bContext *C, wmEvent *evt, int extend)
{
ListBase *markers= context_get_markers(C);
View2D *v2d= context_get_view2d(C);
View2D *v2d= UI_view2d_fromcontext(C);
float viewx;
int x, y, cfra;
@ -689,7 +682,7 @@ callbacks:
static int ed_marker_border_select_exec(bContext *C, wmOperator *op)
{
View2D *v2d= context_get_view2d(C);
View2D *v2d= UI_view2d_fromcontext(C);
ListBase *markers= context_get_markers(C);
wmGesture *gesture= op->customdata;
TimeMarker *marker;

@ -80,22 +80,24 @@ static void time_draw_cfra_time(const bContext *C, SpaceTime *stime, ARegion *ar
static void time_draw_sfra_efra(const bContext *C, SpaceTime *stime, ARegion *ar)
{
/* draw darkened area outside of active timeline
View2D *v2d= UI_view2d_fromcontext(C);
/* draw darkened area outside of active timeline
* frame range used is preview range or scene range */
UI_ThemeColorShade(TH_BACK, -25);
if (PSFRA < PEFRA) {
glRectf(ar->v2d.cur.xmin, ar->v2d.cur.ymin, PSFRA, ar->v2d.cur.ymax);
glRectf(PEFRA, ar->v2d.cur.ymin, ar->v2d.cur.xmax, ar->v2d.cur.ymax);
glRectf(v2d->cur.xmin, v2d->cur.ymin, PSFRA, v2d->cur.ymax);
glRectf(PEFRA, v2d->cur.ymin, v2d->cur.xmax, v2d->cur.ymax);
}
else {
glRectf(ar->v2d.cur.xmin, ar->v2d.cur.ymin, ar->v2d.cur.xmax, ar->v2d.cur.ymax);
glRectf(v2d->cur.xmin, v2d->cur.ymin, v2d->cur.xmax, v2d->cur.ymax);
}
UI_ThemeColorShade(TH_BACK, -60);
/* thin lines where the actual frames are */
fdrawline(PSFRA, ar->v2d.cur.ymin, PSFRA, ar->v2d.cur.ymax);
fdrawline(PEFRA, ar->v2d.cur.ymin, PEFRA, ar->v2d.cur.ymax);
fdrawline(PSFRA, v2d->cur.ymin, PSFRA, v2d->cur.ymax);
fdrawline(PEFRA, v2d->cur.ymin, PEFRA, v2d->cur.ymax);
}
static void time_main_area_init(const bContext *C, ARegion *ar)
@ -143,6 +145,7 @@ static void time_main_area_draw(const bContext *C, ARegion *ar)
time_draw_cfra_time(C, stime, ar);
/* markers */
UI_view2d_view_orthospecial(C, v2d, 1);
draw_markers_time(C, 0);
/* reset view matrix */

@ -94,11 +94,14 @@ typedef struct View2D {
/* special hacks for outliner hscroll - prevent hanging older versions of Blender */
#define B_SCROLLO (1<<4)
#define HOR_SCROLLO (T_SCROLL|B_SCROLLO)
/* scale markings */
/* scale markings - vertical */
#define LGRID_SCROLL (1<<5)
#define RGRID_SCROLL (1<<6)
#define VERT_SCROLLGRID (LGRID_SCROLL|RGRID_SCROLL)
/* scale markings - horizontal */
#define BGRID_SCROLL (1<<7)
#define TGRID_SCROLL (1<<8)
#define HOR_SCROLLGRID (BGRID_SCROLL|TGRID_SCROLL)
#endif