Cycles: UI tweak some quick code to auto hide scrollbars. Not happy with this

yet because it runs python draw functions twice when scrollers are showing.
This commit is contained in:
Brecht Van Lommel
2011-06-06 20:07:08 +00:00
parent 966e004bbe
commit a07d0a7fc2
5 changed files with 64 additions and 37 deletions

View File

@@ -583,6 +583,7 @@ void autocomplete_end(AutoComplete *autocpl, char *autoname);
void uiBeginPanels(const struct bContext *C, struct ARegion *ar);
void uiEndPanels(const struct bContext *C, struct ARegion *ar);
void uiDrawPanels(const struct bContext *C, struct ARegion *ar);
struct Panel *uiBeginPanel(struct ScrArea *sa, struct ARegion *ar, uiBlock *block, struct PanelType *pt, int *open);
void uiEndPanel(uiBlock *block, int width, int height);

View File

@@ -846,6 +846,11 @@ void uiEndPanels(const bContext *C, ARegion *ar)
if(firstpa)
firstpa->runtime_flag |= PNL_FIRST;
}
void uiDrawPanels(const bContext *C, ARegion *ar)
{
uiBlock *block;
UI_ThemeClearColor(TH_BACK);

View File

@@ -122,7 +122,7 @@ static uiStyle *ui_style_new(ListBase *styles, const char *name)
style->buttonspacex= 8;
style->buttonspacey= 2;
style->panelspace= 8;
style->panelouter= 4;
style->panelouter= 3;
return style;
}

View File

@@ -278,10 +278,9 @@ void UI_view2d_region_reinit(View2D *v2d, short type, int winx, int winy)
v2d->align= (V2D_ALIGN_NO_NEG_X|V2D_ALIGN_NO_POS_Y);
v2d->keeptot= V2D_KEEPTOT_BOUNDS;
/*v2d->scroll |= (V2D_SCROLL_RIGHT|V2D_SCROLL_BOTTOM);
v2d->scroll |= (V2D_SCROLL_RIGHT|V2D_SCROLL_BOTTOM);
v2d->scroll |= V2D_SCROLL_HORIZONTAL_HIDE;
v2d->scroll &= ~V2D_SCROLL_VERTICAL_HIDE;*/
v2d->scroll= 0;
v2d->scroll &= ~V2D_SCROLL_VERTICAL_HIDE;
v2d->tot.xmin= 0.0f;
v2d->tot.xmax= winx;
@@ -291,7 +290,7 @@ void UI_view2d_region_reinit(View2D *v2d, short type, int winx, int winy)
v2d->cur.xmin= 0.0f;
/* bad workaround for keeping zoom level with scrollers */
v2d->cur.xmax= (winx/* - V2D_SCROLL_WIDTH*/)*panelzoom;
v2d->cur.xmax= (winx - V2D_SCROLL_WIDTH)*panelzoom;
v2d->cur.ymax= 0.0f;
v2d->cur.ymin= (-winy)*panelzoom;

View File

@@ -1145,28 +1145,15 @@ int ED_area_header_standardbuttons(const bContext *C, uiBlock *block, int yco)
/************************ standard UI regions ************************/
void ED_region_panels(const bContext *C, ARegion *ar, int vertical, const char *context, int contextnr)
static void region_panels_layout(const bContext *C, ARegion *ar, int vertical, const char *context, int w, int em, int *r_x, int *r_y)
{
ScrArea *sa= CTX_wm_area(C);
uiStyle *style= U.uistyles.first;
uiBlock *block;
PanelType *pt;
Panel *panel;
View2D *v2d= &ar->v2d;
View2DScrollers *scrollers;
int xco, yco, x, y, miny=0, w, em, header, triangle, open, newcontext= 0;
if(contextnr >= 0)
newcontext= UI_view2d_tab_set(v2d, contextnr);
if(vertical) {
w= v2d->cur.xmax - v2d->cur.xmin;
em= (ar->type->prefsizex)? 10: 20;
}
else {
w= UI_PANEL_WIDTH;
em= (ar->type->prefsizex)? 10: 20;
}
uiBlock *block;
uiStyle *style= U.uistyles.first;
int x, y, miny=0, xco, yco;
int open, header, triangle;
x= 0;
y= -style->panelouter;
@@ -1174,9 +1161,6 @@ void ED_region_panels(const bContext *C, ARegion *ar, int vertical, const char *
/* create panels */
uiBeginPanels(C, ar);
/* set view2d view matrix for scrolling (without scrollers) */
UI_view2d_view_ortho(v2d);
for(pt= ar->type->paneltypes.first; pt; pt= pt->next) {
/* verify context */
if(context)
@@ -1261,6 +1245,40 @@ void ED_region_panels(const bContext *C, ARegion *ar, int vertical, const char *
y= UI_PANEL_WIDTH;
}
uiEndPanels(C, ar);
*r_x = x;
*r_y = y;
}
void ED_region_panels(const bContext *C, ARegion *ar, int vertical, const char *context, int contextnr)
{
View2D *v2d= &ar->v2d;
View2DScrollers *scrollers;
int x, y, w, em, newcontext= 0, need_scrollers;
if(contextnr >= 0)
newcontext= UI_view2d_tab_set(v2d, contextnr);
if(vertical) {
w= v2d->cur.xmax - v2d->cur.xmin;
em= (ar->type->prefsizex)? 10: 20;
}
else {
w= UI_PANEL_WIDTH;
em= (ar->type->prefsizex)? 10: 20;
}
/* try to draw without scrollbars */
UI_view2d_view_ortho(v2d);
region_panels_layout(C, ar, vertical, context, ar->winx, em, &x, &y);
/* if it doesn't fit, draw again in smaller space with scrollers */
need_scrollers = (abs(y) > ar->winy);
if(need_scrollers)
region_panels_layout(C, ar, vertical, context, ar->winx-V2D_SCROLL_WIDTH, em, &x, &y);
/* clear */
UI_ThemeClearColor((ar->type->regionid == RGN_TYPE_PREVIEW)?TH_PREVIEW_BACK:TH_BACK);
glClear(GL_COLOR_BUFFER_BIT);
@@ -1270,8 +1288,9 @@ void ED_region_panels(const bContext *C, ARegion *ar, int vertical, const char *
/* only allow scrolling in vertical direction */
v2d->keepofs |= V2D_LOCKOFS_X|V2D_KEEPOFS_Y;
v2d->keepofs &= ~(V2D_LOCKOFS_Y|V2D_KEEPOFS_X);
//v2d->scroll |= V2D_SCROLL_HORIZONTAL_HIDE;
//v2d->scroll &= ~V2D_SCROLL_VERTICAL_HIDE;
v2d->scroll &= ~(V2D_SCROLL_HORIZONTAL_HIDE|V2D_SCROLL_VERTICAL_HIDE);
if(!need_scrollers)
v2d->scroll |= V2D_SCROLL_HORIZONTAL_HIDE;
// don't jump back when panels close or hide
if(!newcontext)
@@ -1286,8 +1305,9 @@ void ED_region_panels(const bContext *C, ARegion *ar, int vertical, const char *
v2d->keepofs &= ~(V2D_LOCKOFS_X|V2D_LOCKOFS_Y|V2D_KEEPOFS_X|V2D_KEEPOFS_Y);
//v2d->keepofs |= V2D_LOCKOFS_Y|V2D_KEEPOFS_X;
//v2d->keepofs &= ~(V2D_LOCKOFS_X|V2D_KEEPOFS_Y);
//v2d->scroll |= V2D_SCROLL_VERTICAL_HIDE;
//v2d->scroll &= ~V2D_SCROLL_HORIZONTAL_HIDE;
v2d->scroll &= ~(V2D_SCROLL_HORIZONTAL_HIDE|V2D_SCROLL_VERTICAL_HIDE);
if(!need_scrollers)
v2d->scroll |= V2D_SCROLL_VERTICAL_HIDE;
// don't jump back when panels close or hide
if(!newcontext)
@@ -1297,20 +1317,23 @@ void ED_region_panels(const bContext *C, ARegion *ar, int vertical, const char *
// +V2D_SCROLL_HEIGHT is workaround to set the actual height
UI_view2d_totRect_set(v2d, x+V2D_SCROLL_WIDTH, y+V2D_SCROLL_HEIGHT);
UI_view2d_totRect_set(v2d, x+V2D_SCROLL_WIDTH, y+V2D_SCROLL_HEIGHT);
/* set the view */
UI_view2d_view_ortho(v2d);
/* this does the actual drawing! */
uiEndPanels(C, ar);
uiDrawPanels(C, ar);
/* restore view matrix */
UI_view2d_view_restore(C);
/* scrollers */
//scrollers= UI_view2d_scrollers_calc(C, v2d, V2D_ARG_DUMMY, V2D_ARG_DUMMY, V2D_ARG_DUMMY, V2D_ARG_DUMMY);
//UI_view2d_scrollers_draw(C, v2d, scrollers);
//UI_view2d_scrollers_free(scrollers);
if(need_scrollers) {
scrollers= UI_view2d_scrollers_calc(C, v2d, V2D_ARG_DUMMY, V2D_ARG_DUMMY, V2D_ARG_DUMMY, V2D_ARG_DUMMY);
UI_view2d_scrollers_draw(C, v2d, scrollers);
UI_view2d_scrollers_free(scrollers);
}
}
void ED_region_panels_init(wmWindowManager *wm, ARegion *ar)
@@ -1319,10 +1342,9 @@ void ED_region_panels_init(wmWindowManager *wm, ARegion *ar)
// XXX quick hacks for files saved with 2.5 already (i.e. the builtin defaults file)
// scrollbars for button regions
/*ar->v2d.scroll |= (V2D_SCROLL_RIGHT|V2D_SCROLL_BOTTOM);
ar->v2d.scroll |= (V2D_SCROLL_RIGHT|V2D_SCROLL_BOTTOM);
ar->v2d.scroll |= V2D_SCROLL_HORIZONTAL_HIDE;
ar->v2d.scroll &= ~V2D_SCROLL_VERTICAL_HIDE;*/
ar->v2d.scroll= 0;
ar->v2d.scroll &= ~V2D_SCROLL_VERTICAL_HIDE;
ar->v2d.keepzoom |= V2D_KEEPZOOM;
// correctly initialised User-Prefs?