UI: various panels fixes.

* Fix sometimes non-working close/open button.
* Fix panels being a bit out of the view on startup.
* Fix too large totrct region for view2d.
* Fix wrong panel order when changing vertical <-> horizontal.
* Fix wrong panel positions after switching contexts.
* Fix an access of freed memory when collapsing panels.

* Free align mode works again.
* Animations work again.
This commit is contained in:
Brecht Van Lommel
2009-04-02 01:39:33 +00:00
parent ecdd332021
commit 4bb41c3dcd
10 changed files with 184 additions and 127 deletions

View File

@@ -496,19 +496,15 @@ void autocomplete_end(AutoComplete *autocpl, char *autoname);
extern void uiNewPanelTabbed(char *, char *);
extern int uiNewPanel(const struct bContext *C, struct ARegion *ar, uiBlock *block, char *panelname, char *tabname, int ofsx, int ofsy, int sizex, int sizey);
extern void uiBeginPanels(const struct bContext *C, struct ARegion *ar);
extern void uiEndPanels(const struct bContext *C, struct ARegion *ar);
extern void uiFreePanels(struct ListBase *lb);
extern void uiDrawPanels(const struct bContext *C, int re_align);
extern void uiSetPanelsView2d(struct ARegion *ar);
extern void uiMatchPanelsView2d(struct ARegion *ar);
extern void uiPanelsHome(struct ARegion *ar);
extern void uiNewPanelHeight(struct uiBlock *block, int sizey);
extern void uiNewPanelTitle(struct uiBlock *block, char *str);
extern uiBlock *uiFindOpenPanelBlockName(struct ListBase *lb, char *name);
extern int uiAlignPanelStep(struct ScrArea *sa, struct ARegion *ar, float fac);
extern void uiPanelControl(int);
extern void uiSetPanelHandler(int);
struct Panel *uiPanelFromBlock(struct uiBlock *block);
/* Handlers

View File

@@ -34,6 +34,8 @@
#include "WM_api.h"
#include "WM_types.h"
#include "interface_intern.h"
/************************ Structs and Defines *************************/
#define COLUMN_SPACE 5
@@ -918,7 +920,7 @@ void uiRegionPanelLayout(const bContext *C, ARegion *ar, int vertical, char *con
PanelType *pt;
Panel *panel;
float col[3];
int xco, yco, x=0, y=0, w;
int xco, yco, x=PNL_DIST, y=-PNL_HEADER-PNL_DIST, w;
// XXX this only hides cruft
@@ -930,38 +932,43 @@ void uiRegionPanelLayout(const bContext *C, ARegion *ar, int vertical, char *con
/* set view2d view matrix for scrolling (without scrollers) */
UI_view2d_view_ortho(C, &ar->v2d);
uiBeginPanels(C, ar);
for(pt= ar->type->paneltypes.first; pt; pt= pt->next) {
if(context)
if(!pt->context || strcmp(context, pt->context) != 0)
continue;
if(pt->draw && (!pt->poll || pt->poll(C))) {
block= uiBeginBlock(C, ar, pt->idname, UI_EMBOSS, UI_HELV);
w= (ar->type->minsizex)? ar->type->minsizex-22: UI_PANEL_WIDTH-22;
block= uiBeginBlock(C, ar, pt->idname, UI_EMBOSS, UI_HELV);
if(uiNewPanel(C, ar, block, pt->name, pt->name, x, y, w, 0)==0) return;
panel= uiPanelFromBlock(block);
panel->type= pt;
panel->layout= uiLayoutBegin(UI_LAYOUT_VERTICAL, x, y, w, 0);
if(uiNewPanel(C, ar, block, pt->name, pt->name, x, y, w, 0)) {
panel= uiPanelFromBlock(block);
panel->type= pt;
panel->layout= uiLayoutBegin(UI_LAYOUT_VERTICAL, x, y, w, 0);
pt->draw(C, panel);
pt->draw(C, panel);
uiLayoutEnd(C, block, panel->layout, &xco, &yco);
panel->layout= NULL;
uiNewPanelHeight(block, y - yco + 6);
}
else {
w= PNL_HEADER;
yco= PNL_HEADER;
}
uiLayoutEnd(C, block, panel->layout, &xco, &yco);
uiEndBlock(C, block);
panel->layout= NULL;
uiNewPanelHeight(block, y - yco + 6);
if(vertical)
y += yco;
y += yco+PNL_DIST;
else
x += xco;
x += w+PNL_DIST;
}
}
uiDrawPanels(C, 1);
uiMatchPanelsView2d(ar);
uiEndPanels(C, ar);
/* restore view matrix? */
UI_view2d_view_restore(C);

View File

@@ -100,7 +100,7 @@ static void panel_activate_state(bContext *C, Panel *pa, uiHandlePanelState stat
static int panel_aligned(ScrArea *sa, ARegion *ar)
{
if(sa->spacetype==SPACE_BUTS) {
if(sa->spacetype==SPACE_BUTS && ar->regiontype == RGN_TYPE_WINDOW) {
SpaceButs *sbuts= sa->spacedata.first;
return sbuts->align;
}
@@ -110,6 +110,26 @@ static int panel_aligned(ScrArea *sa, ARegion *ar)
return 0;
}
static int panels_re_align(ScrArea *sa, ARegion *ar)
{
if(sa->spacetype==SPACE_BUTS && ar->regiontype == RGN_TYPE_WINDOW) {
SpaceButs *sbuts= sa->spacedata.first;
if(sbuts->align) {
if(sbuts->re_align || sbuts->mainbo!=sbuts->mainb || sbuts->tabo!=sbuts->tab[sbuts->mainb]) {
sbuts->re_align= 0;
return 1;
}
}
return 0;
}
else if(ar->regiontype==RGN_TYPE_UI)
return 1;
return 0;
}
/* ************** panels ************* */
static void copy_panel_offset(Panel *pa, Panel *papar)
@@ -317,7 +337,7 @@ static void ui_scale_panel_block(uiBlock *block)
}
// for 'home' key
void uiSetPanelsView2d(ARegion *ar)
void uiPanelsHome(ARegion *ar)
{
Panel *pa;
uiBlock *block;
@@ -362,7 +382,7 @@ void uiSetPanelsView2d(ARegion *ar)
}
// make sure the panels are not outside 'tot' area
void uiMatchPanelsView2d(ARegion *ar)
static void ui_panels_update_totrct(ARegion *ar)
{
Panel *pa;
uiBlock *block;
@@ -370,14 +390,22 @@ void uiMatchPanelsView2d(ARegion *ar)
int done=0;
v2d= &ar->v2d;
v2d->tot.xmin= 0.0f;
v2d->tot.xmax= ar->winx;
v2d->tot.ymax= 0.0f;
v2d->tot.ymin= -ar->winy;
for(pa= ar->panels.first; pa; pa=pa->next) {
if(pa->active && pa->paneltab==NULL) {
done= 1;
if(pa->ofsx < v2d->tot.xmin) v2d->tot.xmin= pa->ofsx;
if(pa->ofsx+pa->sizex > v2d->tot.xmax)
if(pa->ofsx < v2d->tot.xmin)
v2d->tot.xmin= pa->ofsx;
if(pa->ofsx+pa->sizex > v2d->tot.xmax)
v2d->tot.xmax= pa->ofsx+pa->sizex;
if(pa->ofsy < v2d->tot.ymin) v2d->tot.ymin= pa->ofsy;
if(pa->ofsy < v2d->tot.ymin)
v2d->tot.ymin= pa->ofsy;
if(pa->ofsy+pa->sizey+PNL_HEADER > v2d->tot.ymax)
v2d->tot.ymax= pa->ofsy+pa->sizey+PNL_HEADER;
}
@@ -394,6 +422,8 @@ void uiMatchPanelsView2d(ARegion *ar)
//XXX }
}
}
UI_view2d_totRect_set(v2d, v2d->tot.xmax, v2d->tot.ymin);
}
/* extern used by previewrender */
@@ -877,8 +907,8 @@ static int find_highest_panel(const void *a1, const void *a2)
{
const PanelSort *ps1=a1, *ps2=a2;
if( ps1->pa->ofsy < ps2->pa->ofsy) return 1;
else if( ps1->pa->ofsy > ps2->pa->ofsy) return -1;
if( ps1->pa->ofsy+ps1->pa->sizey < ps2->pa->ofsy+ps2->pa->sizey) return 1;
else if( ps1->pa->ofsy+ps1->pa->sizey > ps2->pa->ofsy+ps2->pa->sizey) return -1;
else if( ps1->pa->sortcounter > ps2->pa->sortcounter) return 1;
else if( ps1->pa->sortcounter < ps2->pa->sortcounter) return -1;
@@ -938,7 +968,7 @@ int uiAlignPanelStep(ScrArea *sa, ARegion *ar, float fac)
ps->pa->ofsy= -ps->pa->sizey-PNL_HEADER-PNL_DIST;
else
ps->pa->ofsy= -ps->pa->sizey-PNL_HEADER-PNL_DIST; // XXX was 0;
for(a=0 ; a<tot-1; a++, ps++) {
psnext= ps+1;
@@ -1010,11 +1040,20 @@ static void ui_do_animate(bContext *C, Panel *panel)
}
}
void uiBeginPanels(const bContext *C, ARegion *ar)
{
Panel *pa;
/* set all panels as inactive, so that at the end we know
* which ones were used */
for(pa=ar->panels.first; pa; pa=pa->next)
pa->active= 0;
}
/* only draws blocks with panels */
void uiDrawPanels(const bContext *C, int re_align)
void uiEndPanels(const bContext *C, ARegion *ar)
{
ScrArea *sa= CTX_wm_area(C);
ARegion *ar= CTX_wm_region(C);
uiBlock *block;
Panel *panot, *panew, *patest;
@@ -1049,7 +1088,8 @@ void uiDrawPanels(const bContext *C, int re_align)
}
/* re-align */
if(re_align) uiAlignPanelStep(sa, ar, 1.0);
if(panels_re_align(sa, ar))
uiAlignPanelStep(sa, ar, 1.0);
if(sa->spacetype!=SPACE_BUTS) {
#if 0 // XXX make float panel exception
@@ -1133,6 +1173,11 @@ void uiDrawPanels(const bContext *C, int re_align)
#endif
}
/* update v2d->totrct and update view */
ui_panels_update_totrct(ar);
UI_view2d_view_restore(C);
UI_view2d_view_ortho(C, &ar->v2d);
/* draw panels, selected on top */
for(block= ar->uiblocks.first; block; block=block->next) {
if(block->active && block->panel && !(block->panel->flag & PNL_SELECT)) {
@@ -1435,7 +1480,7 @@ int ui_handler_panel_region(bContext *C, wmEvent *event)
{
ARegion *ar= CTX_wm_region(C);
uiBlock *block;
int retval, mx, my, inside_header= 0, inside_scale= 0;
int retval, mx, my, inside_header= 0, inside_scale= 0, inside;
retval= WM_UI_HANDLER_CONTINUE;
@@ -1445,72 +1490,73 @@ int ui_handler_panel_region(bContext *C, wmEvent *event)
ui_window_to_block(ar, block, &mx, &my);
/* check if inside boundbox */
inside= 0;
if(block->panel && block->panel->paneltab==NULL)
if(block->minx <= mx && block->maxx >= mx)
if(block->miny <= my && block->maxy+PNL_HEADER >= my)
break;
}
inside= 1;
if(!block)
return retval;
if(inside) {
/* clicked at panel header? */
if(block->panel->flag & PNL_CLOSEDX) {
if(block->minx <= mx && block->minx+PNL_HEADER >= mx)
inside_header= 1;
}
else if((block->maxy <= my) && (block->maxy+PNL_HEADER >= my)) {
inside_header= 1;
}
else if(block->panel->control & UI_PNL_SCALE) {
if(block->maxx-PNL_HEADER <= mx)
if(block->miny+PNL_HEADER >= my)
inside_scale= 1;
}
/* clicked at panel header? */
if(block->panel->flag & PNL_CLOSEDX) {
if(block->minx <= mx && block->minx+PNL_HEADER >= mx)
inside_header= 1;
}
else if((block->maxy <= my) && (block->maxy+PNL_HEADER >= my)) {
inside_header= 1;
}
else if(block->panel->control & UI_PNL_SCALE) {
if(block->maxx-PNL_HEADER <= mx)
if(block->miny+PNL_HEADER >= my)
inside_scale= 1;
}
if(event->val==KM_PRESS) {
if(event->type == LEFTMOUSE) {
if(inside_header)
ui_handle_panel_header(C, block, mx, my);
else if(inside_scale && !(block->panel->flag & PNL_CLOSED))
panel_activate_state(C, block->panel, PANEL_STATE_DRAG_SCALE);
}
else if(event->type == ESCKEY) {
/*XXX 2.50 if(block->handler) {
rem_blockhandler(sa, block->handler);
ED_region_tag_redraw(ar);
retval= WM_UI_HANDLER_BREAK;
}*/
}
else if(event->type==PADPLUSKEY || event->type==PADMINUS) {
int zoom=0;
/* if panel is closed, only zoom if mouse is over the header */
if (block->panel->flag & (PNL_CLOSEDX|PNL_CLOSEDY)) {
if (inside_header)
zoom=1;
}
else
zoom=1;
if(event->val!=KM_PRESS)
return retval;
if(event->type == LEFTMOUSE) {
if(inside_header)
ui_handle_panel_header(C, block, mx, my);
else if(inside_scale && !(block->panel->flag & PNL_CLOSED))
panel_activate_state(C, block->panel, PANEL_STATE_DRAG_SCALE);
}
else if(event->type == ESCKEY) {
/*XXX 2.50 if(block->handler) {
rem_blockhandler(sa, block->handler);
ED_region_tag_redraw(ar);
retval= WM_UI_HANDLER_BREAK;
}*/
}
else if(event->type==PADPLUSKEY || event->type==PADMINUS) {
int zoom=0;
/* if panel is closed, only zoom if mouse is over the header */
if (block->panel->flag & (PNL_CLOSEDX|PNL_CLOSEDY)) {
if (inside_header)
zoom=1;
}
else
zoom=1;
#if 0 // XXX make float panel exception?
if(zoom) {
ScrArea *sa= CTX_wm_area(C);
SpaceLink *sl= sa->spacedata.first;
if(zoom) {
ScrArea *sa= CTX_wm_area(C);
SpaceLink *sl= sa->spacedata.first;
if(sa->spacetype!=SPACE_BUTS) {
if(!(block->panel->control & UI_PNL_SCALE)) {
if(event->type==PADPLUSKEY) sl->blockscale+= 0.1;
else sl->blockscale-= 0.1;
CLAMP(sl->blockscale, 0.6, 1.0);
if(sa->spacetype!=SPACE_BUTS) {
if(!(block->panel->control & UI_PNL_SCALE)) {
if(event->type==PADPLUSKEY) sl->blockscale+= 0.1;
else sl->blockscale-= 0.1;
CLAMP(sl->blockscale, 0.6, 1.0);
ED_region_tag_redraw(ar);
retval= WM_UI_HANDLER_BREAK;
}
ED_region_tag_redraw(ar);
retval= WM_UI_HANDLER_BREAK;
}
}
}
#endif
}
}
}
#endif
}
return retval;
@@ -1525,7 +1571,15 @@ static int ui_handler_panel(bContext *C, wmEvent *event, void *userdata)
/* verify if we can stop */
if(event->type == LEFTMOUSE && event->val!=KM_PRESS) {
panel_activate_state(C, panel, PANEL_STATE_ANIMATION);
ScrArea *sa= CTX_wm_area(C);
ARegion *ar= CTX_wm_region(C);
int align= panel_aligned(sa, ar);
if(align)
panel_activate_state(C, panel, PANEL_STATE_ANIMATION);
else
panel_activate_state(C, panel, PANEL_STATE_EXIT);
return WM_UI_HANDLER_BREAK;
}
else if(event->type == MOUSEMOVE) {
@@ -1541,7 +1595,9 @@ static int ui_handler_panel(bContext *C, wmEvent *event, void *userdata)
ui_do_drag(C, event, panel);
}
if(data->state == PANEL_STATE_ANIMATION)
data= panel->activedata;
if(data && data->state == PANEL_STATE_ANIMATION)
return WM_UI_HANDLER_CONTINUE;
else
return WM_UI_HANDLER_BREAK;

View File

@@ -261,7 +261,7 @@ void UI_view2d_region_reinit(View2D *v2d, short type, int winx, int winy)
v2d->maxzoom= 2.0f;
v2d->align= (V2D_ALIGN_NO_NEG_X|V2D_ALIGN_NO_POS_Y);
v2d->keeptot= V2D_KEEPTOT_BOUNDS;
v2d->keeptot= V2D_KEEPTOT_STRICT;
v2d->tot.xmin= 0.0f;
v2d->tot.xmax= winx;
@@ -421,6 +421,14 @@ void UI_view2d_curRect_validate(View2D *v2d)
/* special exception for Outliner (and later channel-lists):
* - Currently, no actions need to be taken here...
*/
if (winy < v2d->oldwiny) {
float temp = v2d->oldwiny - winy;
cur->ymin += temp;
cur->ymax += temp;
}
}
else {
/* landscape window: correct for y */

View File

@@ -70,10 +70,8 @@ static void do_viewmenu(bContext *C, void *arg, int event)
case 1:
case 2:
sbuts->align= event;
if(event) {
if(sbuts->align)
sbuts->re_align= 1;
// uiAlignPanelStep(sa, 1.0);
}
break;
}

View File

@@ -176,7 +176,6 @@ static void buttons_main_area_draw(const bContext *C, ARegion *ar)
else {
View2D *v2d= &ar->v2d;
float col[3], fac;
//int align= 0;
/* clear and setup matrix */
UI_GetThemeColor3fv(TH_BACK, col);
@@ -193,15 +192,6 @@ static void buttons_main_area_draw(const bContext *C, ARegion *ar)
/* panels */
drawnewstuff();
#if 0
if(sbuts->align)
if(sbuts->re_align || sbuts->mainbo!=sbuts->mainb || sbuts->tabo!=sbuts->tab[sbuts->mainb])
align= 1;
#endif
uiDrawPanels(C, 1); // XXX align);
uiMatchPanelsView2d(ar);
/* reset view matrix */
UI_view2d_view_restore(C);

View File

@@ -846,6 +846,8 @@ void graph_region_buttons(const bContext *C, ARegion *ar)
if (ale == NULL)
return;
uiBeginPanels(C, ar);
/* for now, the properties panel displays info about the selected channels */
graph_panel_properties(C, ar, 0, ale);
@@ -857,8 +859,7 @@ void graph_region_buttons(const bContext *C, ARegion *ar)
graph_panel_modifiers(C, ar, 0, ale);
uiDrawPanels(C, 1); /* 1 = align */
uiMatchPanelsView2d(ar); /* sets v2d->totrct */
uiEndPanels(C, ar);
/* free temp data */
MEM_freeN(ale);

View File

@@ -1424,7 +1424,8 @@ static void image_panel_properties(const bContext *C, ARegion *ar)
void image_buttons_area_defbuts(const bContext *C, ARegion *ar)
{
uiBeginPanels(C, ar);
image_panel_properties(C, ar);
image_panel_game_properties(C, ar);
image_panel_view_properties(C, ar);
@@ -1432,9 +1433,7 @@ void image_buttons_area_defbuts(const bContext *C, ARegion *ar)
image_panel_paintcolor(C, ar);
image_panel_curves(C, ar);
uiDrawPanels(C, 1); /* 1 = align */
uiMatchPanelsView2d(ar); /* sets v2d->totrct */
uiEndPanels(C, ar);
}

View File

@@ -1700,6 +1700,7 @@ static void view3d_panel_bonesketch_spaces(const bContext *C, ARegion *ar, short
void view3d_buttons_area_defbuts(const bContext *C, ARegion *ar)
{
uiBeginPanels(C, ar);
view3d_panel_object(C, ar, 0);
view3d_panel_properties(C, ar, 0);
@@ -1713,9 +1714,7 @@ void view3d_buttons_area_defbuts(const bContext *C, ARegion *ar)
view3d_panel_bonesketch_spaces(C, ar, 0);
uiDrawPanels(C, 1); /* 1 = align */
uiMatchPanelsView2d(ar); /* sets v2d->totrct */
uiEndPanels(C, ar);
}

View File

@@ -191,26 +191,29 @@ static PyObject *Method_drawBlock( PyObject * self, PyObject * args )
Py_RETURN_NONE;
}
static PyObject *Method_drawPanels( PyObject * self, PyObject * args )
static PyObject *Method_beginPanels( PyObject * self, PyObject * args )
{
bContext *C;
PyObject *py_context;
int align;
if( !PyArg_ParseTuple( args, "O!i:drawPanels", &PyCObject_Type, &py_context, &align) )
if( !PyArg_ParseTuple( args, "O!i:beginPanels", &PyCObject_Type, &py_context) )
return NULL;
uiDrawPanels(PyCObject_AsVoidPtr(py_context), align);
C= PyCObject_AsVoidPtr(py_context);
uiBeginPanels(C, CTX_wm_region(C));
Py_RETURN_NONE;
}
static PyObject *Method_matchPanelsView2d( PyObject * self, PyObject * args )
static PyObject *Method_endPanels( PyObject * self, PyObject * args )
{
PyObject *py_ar;
bContext *C;
PyObject *py_context;
if( !PyArg_ParseTuple( args, "O!:matchPanelsView2d", &PyCObject_Type, &py_ar) )
if( !PyArg_ParseTuple( args, "O!:endPanels", &PyCObject_Type, &py_context) )
return NULL;
uiMatchPanelsView2d(PyCObject_AsVoidPtr(py_ar));
C= PyCObject_AsVoidPtr(py_context);
uiEndPanels(C, CTX_wm_region(C));
Py_RETURN_NONE;
}
@@ -413,8 +416,8 @@ static struct PyMethodDef ui_methods[] = {
{"blockEndAlign", (PyCFunction)Method_blockEndAlign, METH_VARARGS, ""},
{"blockSetFlag", (PyCFunction)Method_blockSetFlag, METH_VARARGS, ""},
{"newPanel", (PyCFunction)Method_newPanel, METH_VARARGS, ""},
{"drawPanels", (PyCFunction)Method_drawPanels, METH_VARARGS, ""},
{"matchPanelsView2d", (PyCFunction)Method_matchPanelsView2d, METH_VARARGS, ""},
{"beginPanels", (PyCFunction)Method_beginPanels, METH_VARARGS, ""},
{"endPanels", (PyCFunction)Method_endPanels, METH_VARARGS, ""},
{"register", (PyCFunction)Method_register, METH_VARARGS, ""}, // XXX not sure about this - registers current script with the ScriptSpace, like Draw.Register()
{"registerKey", (PyCFunction)Method_registerKey, METH_VARARGS, ""}, // XXX could have this in another place too