2008-12-26 13:11:04 +00:00
|
|
|
/**
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* ***** BEGIN GPL LICENSE BLOCK *****
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
2010-02-12 13:34:04 +00:00
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2008-12-26 13:11:04 +00:00
|
|
|
*
|
|
|
|
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
2009-04-09 18:11:18 +00:00
|
|
|
* Contributor(s): Blender Foundation, 2003-2009 full recode.
|
2008-12-26 13:11:04 +00:00
|
|
|
*
|
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
|
|
|
*/
|
|
|
|
|
2010-10-13 14:44:22 +00:00
|
|
|
/* a full doc with API notes can be found in bf-blender/trunk/blender/doc/guides/interface_API.txt */
|
2008-12-26 13:11:04 +00:00
|
|
|
|
|
|
|
#include <math.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
|
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
|
|
|
#include "PIL_time.h"
|
|
|
|
|
|
|
|
#include "BLI_blenlib.h"
|
2009-11-10 20:43:45 +00:00
|
|
|
#include "BLI_math.h"
|
2008-12-26 13:11:04 +00:00
|
|
|
|
|
|
|
#include "DNA_userdef_types.h"
|
|
|
|
|
|
|
|
#include "BKE_context.h"
|
|
|
|
#include "BKE_screen.h"
|
|
|
|
|
|
|
|
#include "BIF_gl.h"
|
|
|
|
#include "BIF_glutil.h"
|
|
|
|
|
|
|
|
#include "WM_api.h"
|
|
|
|
#include "WM_types.h"
|
|
|
|
|
|
|
|
#include "ED_screen.h"
|
|
|
|
|
|
|
|
#include "UI_interface.h"
|
|
|
|
|
|
|
|
#include "interface_intern.h"
|
|
|
|
|
2009-04-16 21:39:45 +00:00
|
|
|
/*********************** defines and structs ************************/
|
2008-12-26 13:11:04 +00:00
|
|
|
|
|
|
|
#define ANIMATION_TIME 0.30
|
|
|
|
#define ANIMATION_INTERVAL 0.02
|
|
|
|
|
2009-04-16 21:39:45 +00:00
|
|
|
#define PNL_LAST_ADDED 1
|
|
|
|
#define PNL_ACTIVE 2
|
|
|
|
#define PNL_WAS_ACTIVE 4
|
|
|
|
#define PNL_ANIM_ALIGN 8
|
2009-06-16 01:08:39 +00:00
|
|
|
#define PNL_NEW_ADDED 16
|
2009-06-19 23:11:41 +00:00
|
|
|
#define PNL_FIRST 32
|
2009-04-16 21:39:45 +00:00
|
|
|
|
2008-12-26 13:11:04 +00:00
|
|
|
typedef enum uiHandlePanelState {
|
|
|
|
PANEL_STATE_DRAG,
|
|
|
|
PANEL_STATE_DRAG_SCALE,
|
|
|
|
PANEL_STATE_WAIT_UNTAB,
|
|
|
|
PANEL_STATE_ANIMATION,
|
|
|
|
PANEL_STATE_EXIT
|
|
|
|
} uiHandlePanelState;
|
|
|
|
|
|
|
|
typedef struct uiHandlePanelData {
|
|
|
|
uiHandlePanelState state;
|
|
|
|
|
|
|
|
/* animation */
|
|
|
|
wmTimer *animtimer;
|
|
|
|
double starttime;
|
|
|
|
|
|
|
|
/* dragging */
|
|
|
|
int startx, starty;
|
|
|
|
int startofsx, startofsy;
|
|
|
|
int startsizex, startsizey;
|
|
|
|
} uiHandlePanelData;
|
|
|
|
|
2009-04-16 21:39:45 +00:00
|
|
|
static void panel_activate_state(const bContext *C, Panel *pa, uiHandlePanelState state);
|
2008-12-26 13:11:04 +00:00
|
|
|
|
2009-04-16 21:39:45 +00:00
|
|
|
/*********************** space specific code ************************/
|
|
|
|
/* temporary code to remove all sbuts stuff from panel code */
|
2009-02-10 15:38:00 +00:00
|
|
|
|
|
|
|
static int panel_aligned(ScrArea *sa, ARegion *ar)
|
|
|
|
{
|
2009-04-02 01:39:33 +00:00
|
|
|
if(sa->spacetype==SPACE_BUTS && ar->regiontype == RGN_TYPE_WINDOW) {
|
2009-02-10 15:38:00 +00:00
|
|
|
SpaceButs *sbuts= sa->spacedata.first;
|
|
|
|
return sbuts->align;
|
|
|
|
}
|
2009-08-18 12:58:51 +00:00
|
|
|
else if(sa->spacetype==SPACE_USERPREF && ar->regiontype == RGN_TYPE_WINDOW)
|
2009-07-15 19:19:43 +00:00
|
|
|
return BUT_VERTICAL;
|
2009-06-29 20:23:40 +00:00
|
|
|
else if(sa->spacetype==SPACE_FILE && ar->regiontype == RGN_TYPE_CHANNELS)
|
|
|
|
return BUT_VERTICAL;
|
2010-01-19 01:32:06 +00:00
|
|
|
else if(sa->spacetype==SPACE_IMAGE && ar->regiontype == RGN_TYPE_PREVIEW)
|
|
|
|
return BUT_VERTICAL;
|
2009-07-02 18:12:46 +00:00
|
|
|
else if(ELEM3(ar->regiontype, RGN_TYPE_UI, RGN_TYPE_TOOLS, RGN_TYPE_TOOL_PROPS))
|
2009-02-10 15:38:00 +00:00
|
|
|
return BUT_VERTICAL;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-04-16 21:39:45 +00:00
|
|
|
static int panels_re_align(ScrArea *sa, ARegion *ar, Panel **r_pa)
|
2009-04-02 01:39:33 +00:00
|
|
|
{
|
2009-04-16 21:39:45 +00:00
|
|
|
Panel *pa;
|
|
|
|
int active= 0;
|
|
|
|
|
|
|
|
*r_pa= NULL;
|
|
|
|
|
2009-04-02 01:39:33 +00:00
|
|
|
if(sa->spacetype==SPACE_BUTS && ar->regiontype == RGN_TYPE_WINDOW) {
|
|
|
|
SpaceButs *sbuts= sa->spacedata.first;
|
|
|
|
|
2009-04-03 23:30:32 +00:00
|
|
|
if(sbuts->align)
|
2009-06-03 23:33:56 +00:00
|
|
|
if(sbuts->re_align || sbuts->mainbo!=sbuts->mainb)
|
2009-04-02 01:39:33 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
else if(ar->regiontype==RGN_TYPE_UI)
|
|
|
|
return 1;
|
2010-01-19 01:32:06 +00:00
|
|
|
else if(sa->spacetype==SPACE_IMAGE && ar->regiontype == RGN_TYPE_PREVIEW)
|
|
|
|
return 1;
|
2009-06-29 20:23:40 +00:00
|
|
|
else if(sa->spacetype==SPACE_FILE && ar->regiontype == RGN_TYPE_CHANNELS)
|
|
|
|
return 1;
|
2009-04-16 21:39:45 +00:00
|
|
|
|
2009-05-19 17:13:33 +00:00
|
|
|
/* in case panel is added or disappears */
|
2009-04-16 21:39:45 +00:00
|
|
|
for(pa=ar->panels.first; pa; pa=pa->next) {
|
|
|
|
if((pa->runtime_flag & PNL_WAS_ACTIVE) && !(pa->runtime_flag & PNL_ACTIVE))
|
|
|
|
return 1;
|
|
|
|
if(!(pa->runtime_flag & PNL_WAS_ACTIVE) && (pa->runtime_flag & PNL_ACTIVE))
|
|
|
|
return 1;
|
|
|
|
if(pa->activedata)
|
|
|
|
active= 1;
|
|
|
|
}
|
|
|
|
|
2009-05-19 17:13:33 +00:00
|
|
|
/* in case we need to do an animation (size changes) */
|
2009-04-16 21:39:45 +00:00
|
|
|
for(pa=ar->panels.first; pa; pa=pa->next) {
|
|
|
|
if(pa->runtime_flag & PNL_ANIM_ALIGN) {
|
|
|
|
if(!active)
|
|
|
|
*r_pa= pa;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
2009-04-02 01:39:33 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-04-16 21:39:45 +00:00
|
|
|
/****************************** panels ******************************/
|
2008-12-26 13:11:04 +00:00
|
|
|
|
2009-04-16 21:39:45 +00:00
|
|
|
static void ui_panel_copy_offset(Panel *pa, Panel *papar)
|
2008-12-26 13:11:04 +00:00
|
|
|
{
|
|
|
|
/* with respect to sizes... papar is parent */
|
|
|
|
|
|
|
|
pa->ofsx= papar->ofsx;
|
|
|
|
pa->ofsy= papar->ofsy + papar->sizey-pa->sizey;
|
|
|
|
}
|
|
|
|
|
2009-06-16 01:08:39 +00:00
|
|
|
Panel *uiBeginPanel(ScrArea *sa, ARegion *ar, uiBlock *block, PanelType *pt, int *open)
|
2008-12-26 13:11:04 +00:00
|
|
|
{
|
UI: Layout Engine
* Buttons are now created first, and after that the layout is computed.
This means the layout engine now works at button level, and makes it
easier to write templates. Otherwise you had to store all info and
create the buttons later.
* Added interface_templates.c as a separate file to put templates in.
These can contain regular buttons, and can be put in a Free layout,
which means you can specify manual coordinates, but still get nested
correct inside other layouts.
* API was changed to allow better nesting. Previously items were added
in the last added layout specifier, i.e. one level up in the layout
hierarchy. This doesn't work well in always, so now when creating things
like rows or columns it always returns a layout which you have to add
the items in. All py scripts were updated to follow this.
* Computing the layout now goes in two passes, first estimating the
required width/height of all nested layouts, and then in the second
pass using the results of that to decide on the actual locations.
* Enum and array buttons now follow the direction of the layout, i.e.
they are vertical or horizontal depending if they are in a column or row.
* Color properties now get a color picker, and only get the additional
RGB sliders with Expand=True.
* File/directory string properties now get a button next to them for
opening the file browse, though this is not implemented yet.
* Layout items can now be aligned, set align=True when creating a column,
row, etc.
* Buttons now get a minimum width of one icon (avoids squashing icon
buttons).
* Moved some more space variables into Style.
2009-05-15 11:19:59 +00:00
|
|
|
uiStyle *style= U.uistyles.first;
|
2009-04-17 13:37:03 +00:00
|
|
|
Panel *pa, *patab, *palast, *panext;
|
2009-06-16 01:08:39 +00:00
|
|
|
char *drawname= pt->label;
|
|
|
|
char *idname= pt->idname;
|
|
|
|
char *tabname= pt->idname;
|
2009-04-16 21:39:45 +00:00
|
|
|
char *hookname= NULL;
|
2009-04-17 11:59:25 +00:00
|
|
|
int newpanel;
|
2009-06-16 01:08:39 +00:00
|
|
|
int align= panel_aligned(sa, ar);
|
2009-04-16 21:39:45 +00:00
|
|
|
|
|
|
|
/* check if Panel exists, then use that one */
|
|
|
|
for(pa=ar->panels.first; pa; pa=pa->next)
|
2009-06-16 01:08:39 +00:00
|
|
|
if(strncmp(pa->panelname, idname, UI_MAX_NAME_STR)==0)
|
2009-04-16 21:39:45 +00:00
|
|
|
if(strncmp(pa->tabname, tabname, UI_MAX_NAME_STR)==0)
|
|
|
|
break;
|
|
|
|
|
2009-04-17 11:59:25 +00:00
|
|
|
newpanel= (pa == NULL);
|
|
|
|
|
|
|
|
if(!newpanel) {
|
2009-04-16 21:39:45 +00:00
|
|
|
pa->type= pt;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* new panel */
|
|
|
|
pa= MEM_callocN(sizeof(Panel), "new panel");
|
|
|
|
pa->type= pt;
|
2009-06-16 01:08:39 +00:00
|
|
|
BLI_strncpy(pa->panelname, idname, UI_MAX_NAME_STR);
|
2009-04-16 21:39:45 +00:00
|
|
|
BLI_strncpy(pa->tabname, tabname, UI_MAX_NAME_STR);
|
2009-06-16 01:08:39 +00:00
|
|
|
|
|
|
|
if(pt->flag & PNL_DEFAULT_CLOSED) {
|
|
|
|
if(align == BUT_VERTICAL)
|
|
|
|
pa->flag |= PNL_CLOSEDY;
|
|
|
|
else
|
|
|
|
pa->flag |= PNL_CLOSEDX;
|
|
|
|
}
|
2009-04-16 21:39:45 +00:00
|
|
|
|
2009-05-19 17:13:33 +00:00
|
|
|
pa->ofsx= 0;
|
UI: Layout Engine
* Buttons are now created first, and after that the layout is computed.
This means the layout engine now works at button level, and makes it
easier to write templates. Otherwise you had to store all info and
create the buttons later.
* Added interface_templates.c as a separate file to put templates in.
These can contain regular buttons, and can be put in a Free layout,
which means you can specify manual coordinates, but still get nested
correct inside other layouts.
* API was changed to allow better nesting. Previously items were added
in the last added layout specifier, i.e. one level up in the layout
hierarchy. This doesn't work well in always, so now when creating things
like rows or columns it always returns a layout which you have to add
the items in. All py scripts were updated to follow this.
* Computing the layout now goes in two passes, first estimating the
required width/height of all nested layouts, and then in the second
pass using the results of that to decide on the actual locations.
* Enum and array buttons now follow the direction of the layout, i.e.
they are vertical or horizontal depending if they are in a column or row.
* Color properties now get a color picker, and only get the additional
RGB sliders with Expand=True.
* File/directory string properties now get a button next to them for
opening the file browse, though this is not implemented yet.
* Layout items can now be aligned, set align=True when creating a column,
row, etc.
* Buttons now get a minimum width of one icon (avoids squashing icon
buttons).
* Moved some more space variables into Style.
2009-05-15 11:19:59 +00:00
|
|
|
pa->ofsy= style->panelouter;
|
2009-04-16 21:39:45 +00:00
|
|
|
pa->sizex= 0;
|
|
|
|
pa->sizey= 0;
|
2009-06-16 01:08:39 +00:00
|
|
|
pa->runtime_flag |= PNL_NEW_ADDED;
|
2009-04-17 11:59:25 +00:00
|
|
|
|
|
|
|
BLI_addtail(&ar->panels, pa);
|
2009-04-16 21:39:45 +00:00
|
|
|
|
|
|
|
/* make new Panel tabbed? */
|
|
|
|
if(hookname) {
|
|
|
|
for(patab= ar->panels.first; patab; patab= patab->next) {
|
|
|
|
if((patab->runtime_flag & PNL_ACTIVE) && patab->paneltab==NULL) {
|
|
|
|
if(strncmp(hookname, patab->panelname, UI_MAX_NAME_STR)==0) {
|
|
|
|
if(strncmp(tabname, patab->tabname, UI_MAX_NAME_STR)==0) {
|
|
|
|
pa->paneltab= patab;
|
|
|
|
ui_panel_copy_offset(pa, patab);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-12-26 13:11:04 +00:00
|
|
|
|
2009-06-16 01:08:39 +00:00
|
|
|
BLI_strncpy(pa->drawname, drawname, UI_MAX_NAME_STR);
|
|
|
|
|
2009-04-17 11:59:25 +00:00
|
|
|
/* if a new panel is added, we insert it right after the panel
|
|
|
|
* that was last added. this way new panels are inserted in the
|
|
|
|
* right place between versions */
|
2009-04-16 21:39:45 +00:00
|
|
|
for(palast=ar->panels.first; palast; palast=palast->next)
|
|
|
|
if(palast->runtime_flag & PNL_LAST_ADDED)
|
|
|
|
break;
|
2009-04-17 11:59:25 +00:00
|
|
|
|
|
|
|
if(newpanel) {
|
|
|
|
pa->sortorder= (palast)? palast->sortorder+1: 0;
|
2009-04-16 21:39:45 +00:00
|
|
|
|
2009-04-17 13:37:03 +00:00
|
|
|
for(panext=ar->panels.first; panext; panext=panext->next)
|
|
|
|
if(panext != pa && panext->sortorder >= pa->sortorder)
|
|
|
|
panext->sortorder++;
|
2009-04-16 21:39:45 +00:00
|
|
|
}
|
|
|
|
|
2009-04-17 11:59:25 +00:00
|
|
|
if(palast)
|
|
|
|
palast->runtime_flag &= ~PNL_LAST_ADDED;
|
|
|
|
|
2009-04-16 21:39:45 +00:00
|
|
|
/* assign to block */
|
|
|
|
block->panel= pa;
|
2009-04-17 11:59:25 +00:00
|
|
|
pa->runtime_flag |= PNL_ACTIVE|PNL_LAST_ADDED;
|
2009-04-16 21:39:45 +00:00
|
|
|
|
2009-05-19 17:13:33 +00:00
|
|
|
*open= 0;
|
2009-04-16 21:39:45 +00:00
|
|
|
|
2009-05-19 17:13:33 +00:00
|
|
|
if(pa->paneltab) return pa;
|
|
|
|
if(pa->flag & PNL_CLOSED) return pa;
|
|
|
|
|
|
|
|
*open= 1;
|
2009-04-16 21:39:45 +00:00
|
|
|
|
|
|
|
return pa;
|
2008-12-26 13:11:04 +00:00
|
|
|
}
|
|
|
|
|
2009-04-16 21:39:45 +00:00
|
|
|
void uiEndPanel(uiBlock *block, int width, int height)
|
|
|
|
{
|
|
|
|
Panel *pa= block->panel;
|
|
|
|
|
2009-06-16 01:08:39 +00:00
|
|
|
if(pa->runtime_flag & PNL_NEW_ADDED) {
|
|
|
|
pa->runtime_flag &= ~PNL_NEW_ADDED;
|
|
|
|
pa->sizex= width;
|
|
|
|
pa->sizey= height;
|
2009-04-16 21:39:45 +00:00
|
|
|
}
|
2009-07-15 22:58:34 +00:00
|
|
|
else {
|
|
|
|
/* check if we need to do an animation */
|
|
|
|
if(!ELEM(width, 0, pa->sizex) || !ELEM(height, 0, pa->sizey)) {
|
2009-06-16 01:08:39 +00:00
|
|
|
pa->runtime_flag |= PNL_ANIM_ALIGN;
|
2009-07-15 22:58:34 +00:00
|
|
|
if(height != 0)
|
|
|
|
pa->ofsy += pa->sizey-height;
|
2009-06-16 01:08:39 +00:00
|
|
|
}
|
2009-04-16 21:39:45 +00:00
|
|
|
|
2009-07-15 22:58:34 +00:00
|
|
|
/* update width/height if non-zero */
|
|
|
|
if(width != 0)
|
|
|
|
pa->sizex= width;
|
|
|
|
if(height != 0)
|
|
|
|
pa->sizey= height;
|
2009-06-16 01:08:39 +00:00
|
|
|
}
|
2009-04-16 21:39:45 +00:00
|
|
|
}
|
2008-12-26 13:11:04 +00:00
|
|
|
|
2009-05-19 17:13:33 +00:00
|
|
|
static void ui_offset_panel_block(uiBlock *block)
|
2008-12-26 13:11:04 +00:00
|
|
|
{
|
UI: Layout Engine
* Buttons are now created first, and after that the layout is computed.
This means the layout engine now works at button level, and makes it
easier to write templates. Otherwise you had to store all info and
create the buttons later.
* Added interface_templates.c as a separate file to put templates in.
These can contain regular buttons, and can be put in a Free layout,
which means you can specify manual coordinates, but still get nested
correct inside other layouts.
* API was changed to allow better nesting. Previously items were added
in the last added layout specifier, i.e. one level up in the layout
hierarchy. This doesn't work well in always, so now when creating things
like rows or columns it always returns a layout which you have to add
the items in. All py scripts were updated to follow this.
* Computing the layout now goes in two passes, first estimating the
required width/height of all nested layouts, and then in the second
pass using the results of that to decide on the actual locations.
* Enum and array buttons now follow the direction of the layout, i.e.
they are vertical or horizontal depending if they are in a column or row.
* Color properties now get a color picker, and only get the additional
RGB sliders with Expand=True.
* File/directory string properties now get a button next to them for
opening the file browse, though this is not implemented yet.
* Layout items can now be aligned, set align=True when creating a column,
row, etc.
* Buttons now get a minimum width of one icon (avoids squashing icon
buttons).
* Moved some more space variables into Style.
2009-05-15 11:19:59 +00:00
|
|
|
uiStyle *style= U.uistyles.first;
|
2008-12-26 13:11:04 +00:00
|
|
|
uiBut *but;
|
2009-05-20 14:46:49 +00:00
|
|
|
int ofsy;
|
2008-12-26 13:11:04 +00:00
|
|
|
|
2009-05-20 14:46:49 +00:00
|
|
|
/* compute bounds and offset */
|
2.5: UI & Menus
* Cleaned up UI_interface.h a bit, and added some comments to
organize things a bit and indicate what should be used when.
* uiMenu* functions can now be used to create menus for headers
too, this is done with a uiDefMenuBut, which takes a pointer
to a uiMenuCreateFunc, that will then call uiMenu* functions.
* Renamed uiMenuBegin/End to uiPupMenuBegin/End, as these are
specific to making popup menus. Will convert the other
conformation popup menu functions to use this too so we can
remove some code.
* Extended uiMenu functions, now there is is also:
BooleanO, FloatO, BooleanR, EnumR, LevelEnumR, Separator.
* Converted image window headers to use uiMenu functions, simplifies
menu code further here. Did not remove the uiDefMenu functions as
they are used in sequencer/view3d in some places now (will fix).
* Also tried to simplify and fix bounds computation a bit better
for popup menus. It tried to find out in advance what the size
of the menu was but this is difficult with keymap strings in
there, now uiPopupBoundsBlock can figure this out afterwards and
ensure the popup is within the window bounds. Will convert some
other functions to use this too.
2009-01-30 12:18:08 +00:00
|
|
|
ui_bounds_block(block);
|
2008-12-26 13:11:04 +00:00
|
|
|
|
2009-05-20 14:46:49 +00:00
|
|
|
ofsy= block->panel->sizey - style->panelspace;
|
|
|
|
|
2009-04-16 21:39:45 +00:00
|
|
|
for(but= block->buttons.first; but; but=but->next) {
|
2009-05-20 14:46:49 +00:00
|
|
|
but->y1 += ofsy;
|
|
|
|
but->y2 += ofsy;
|
2008-12-26 13:11:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
block->maxx= block->panel->sizex;
|
|
|
|
block->maxy= block->panel->sizey;
|
|
|
|
block->minx= block->miny= 0.0;
|
|
|
|
}
|
|
|
|
|
2009-04-16 21:39:45 +00:00
|
|
|
/**************************** drawing *******************************/
|
|
|
|
|
2008-12-26 13:11:04 +00:00
|
|
|
/* extern used by previewrender */
|
|
|
|
void uiPanelPush(uiBlock *block)
|
|
|
|
{
|
|
|
|
glPushMatrix();
|
|
|
|
|
|
|
|
if(block->panel)
|
|
|
|
glTranslatef((float)block->panel->ofsx, (float)block->panel->ofsy, 0.0);
|
|
|
|
}
|
|
|
|
|
2010-10-16 02:40:31 +00:00
|
|
|
void uiPanelPop(uiBlock *UNUSED(block))
|
2008-12-26 13:11:04 +00:00
|
|
|
{
|
|
|
|
glPopMatrix();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* triangle 'icon' for panel header */
|
2009-04-09 18:11:18 +00:00
|
|
|
void ui_draw_tria_icon(float x, float y, char dir)
|
2008-12-26 13:11:04 +00:00
|
|
|
{
|
|
|
|
if(dir=='h') {
|
2009-04-16 21:39:45 +00:00
|
|
|
ui_draw_anti_tria(x-1, y, x-1, y+11.0, x+9, y+6.25);
|
2008-12-26 13:11:04 +00:00
|
|
|
}
|
|
|
|
else {
|
2009-04-16 21:39:45 +00:00
|
|
|
ui_draw_anti_tria(x-3, y+10, x+8-1, y+10, x+4.25-2, y);
|
2008-12-26 13:11:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-12 13:40:29 +00:00
|
|
|
/* triangle 'icon' inside rect */
|
|
|
|
void ui_draw_tria_rect(rctf *rect, char dir)
|
|
|
|
{
|
|
|
|
if(dir=='h') {
|
|
|
|
float half= 0.5f*(rect->ymax - rect->ymin);
|
|
|
|
ui_draw_anti_tria(rect->xmin, rect->ymin, rect->xmin, rect->ymax, rect->xmax, rect->ymin+half);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
float half= 0.5f*(rect->xmax - rect->xmin);
|
|
|
|
ui_draw_anti_tria(rect->xmin, rect->ymax, rect->xmax, rect->ymax, rect->xmin+half, rect->ymin);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-26 13:11:04 +00:00
|
|
|
void ui_draw_anti_x(float x1, float y1, float x2, float y2)
|
|
|
|
{
|
|
|
|
|
|
|
|
/* set antialias line */
|
2009-04-16 21:39:45 +00:00
|
|
|
glEnable(GL_LINE_SMOOTH);
|
|
|
|
glEnable(GL_BLEND);
|
2008-12-26 13:11:04 +00:00
|
|
|
|
|
|
|
glLineWidth(2.0);
|
|
|
|
|
|
|
|
fdrawline(x1, y1, x2, y2);
|
|
|
|
fdrawline(x1, y2, x2, y1);
|
|
|
|
|
|
|
|
glLineWidth(1.0);
|
|
|
|
|
2009-04-16 21:39:45 +00:00
|
|
|
glDisable(GL_LINE_SMOOTH);
|
|
|
|
glDisable(GL_BLEND);
|
2008-12-26 13:11:04 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/* x 'icon' for panel header */
|
|
|
|
static void ui_draw_x_icon(float x, float y)
|
|
|
|
{
|
|
|
|
|
2009-04-16 21:39:45 +00:00
|
|
|
ui_draw_anti_x(x, y, x+9.375, y+9.375);
|
2008-12-26 13:11:04 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#define PNL_ICON 20
|
|
|
|
|
2009-04-09 18:11:18 +00:00
|
|
|
static void ui_draw_panel_scalewidget(rcti *rect)
|
2008-12-26 13:11:04 +00:00
|
|
|
{
|
|
|
|
float xmin, xmax, dx;
|
|
|
|
float ymin, ymax, dy;
|
|
|
|
|
2009-04-09 18:11:18 +00:00
|
|
|
xmin= rect->xmax-PNL_HEADER+2;
|
|
|
|
xmax= rect->xmax-3;
|
|
|
|
ymin= rect->ymin+3;
|
|
|
|
ymax= rect->ymin+PNL_HEADER-2;
|
2008-12-26 13:11:04 +00:00
|
|
|
|
|
|
|
dx= 0.5f*(xmax-xmin);
|
|
|
|
dy= 0.5f*(ymax-ymin);
|
|
|
|
|
|
|
|
glEnable(GL_BLEND);
|
|
|
|
glColor4ub(255, 255, 255, 50);
|
|
|
|
fdrawline(xmin, ymin, xmax, ymax);
|
|
|
|
fdrawline(xmin+dx, ymin, xmax, ymax-dy);
|
|
|
|
|
|
|
|
glColor4ub(0, 0, 0, 50);
|
2009-04-09 18:11:18 +00:00
|
|
|
fdrawline(xmin, ymin+1, xmax, ymax+1);
|
|
|
|
fdrawline(xmin+dx, ymin+1, xmax, ymax-dy+1);
|
2008-12-26 13:11:04 +00:00
|
|
|
glDisable(GL_BLEND);
|
|
|
|
}
|
|
|
|
|
2009-04-12 13:40:29 +00:00
|
|
|
static void ui_draw_panel_dragwidget(rctf *rect)
|
2009-04-08 16:51:35 +00:00
|
|
|
{
|
|
|
|
float xmin, xmax, dx;
|
|
|
|
float ymin, ymax, dy;
|
|
|
|
|
2009-04-12 13:40:29 +00:00
|
|
|
xmin= rect->xmin;
|
|
|
|
xmax= rect->xmax;
|
|
|
|
ymin= rect->ymin;
|
|
|
|
ymax= rect->ymax;
|
2009-04-08 16:51:35 +00:00
|
|
|
|
|
|
|
dx= 0.333f*(xmax-xmin);
|
|
|
|
dy= 0.333f*(ymax-ymin);
|
|
|
|
|
|
|
|
glEnable(GL_BLEND);
|
|
|
|
glColor4ub(255, 255, 255, 50);
|
|
|
|
fdrawline(xmin, ymax, xmax, ymin);
|
|
|
|
fdrawline(xmin+dx, ymax, xmax, ymin+dy);
|
|
|
|
fdrawline(xmin+2*dx, ymax, xmax, ymin+2*dy);
|
|
|
|
|
|
|
|
glColor4ub(0, 0, 0, 50);
|
2009-04-09 18:11:18 +00:00
|
|
|
fdrawline(xmin, ymax+1, xmax, ymin+1);
|
|
|
|
fdrawline(xmin+dx, ymax+1, xmax, ymin+dy+1);
|
|
|
|
fdrawline(xmin+2*dx, ymax+1, xmax, ymin+2*dy+1);
|
2009-04-08 16:51:35 +00:00
|
|
|
glDisable(GL_BLEND);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-10-16 02:40:31 +00:00
|
|
|
static void ui_draw_aligned_panel_header(uiStyle *style, uiBlock *block, rcti *rect, char dir)
|
2009-04-08 16:51:35 +00:00
|
|
|
{
|
2009-04-12 13:40:29 +00:00
|
|
|
Panel *panel= block->panel;
|
2009-04-09 18:11:18 +00:00
|
|
|
rcti hrect;
|
2009-10-19 03:54:30 +00:00
|
|
|
int pnl_icons;
|
2009-04-08 16:51:35 +00:00
|
|
|
char *activename= panel->drawname[0]?panel->drawname:panel->panelname;
|
|
|
|
|
2009-05-19 17:13:33 +00:00
|
|
|
/* + 0.001f to avoid flirting with float inaccuracy */
|
2009-05-20 17:18:48 +00:00
|
|
|
if(panel->control & UI_PNL_CLOSE) pnl_icons=(panel->labelofs+2*PNL_ICON+5)/block->aspect + 0.001f;
|
|
|
|
else pnl_icons= (panel->labelofs+PNL_ICON+5)/block->aspect + 0.001f;
|
2009-04-08 16:51:35 +00:00
|
|
|
|
2009-10-19 03:54:30 +00:00
|
|
|
/* active tab */
|
|
|
|
/* draw text label */
|
|
|
|
UI_ThemeColor(TH_TITLE);
|
|
|
|
|
|
|
|
hrect= *rect;
|
|
|
|
if(dir == 'h') {
|
2009-04-09 18:11:18 +00:00
|
|
|
hrect.xmin= rect->xmin+pnl_icons;
|
2009-04-10 14:06:24 +00:00
|
|
|
uiStyleFontDraw(&style->paneltitle, &hrect, activename);
|
2009-04-08 16:51:35 +00:00
|
|
|
}
|
2009-10-19 03:54:30 +00:00
|
|
|
else {
|
|
|
|
/* ignore 'pnl_icons', otherwise the text gets offset horizontally
|
|
|
|
* + 0.001f to avoid flirting with float inaccuracy
|
|
|
|
*/
|
|
|
|
hrect.xmin= rect->xmin + (PNL_ICON+5)/block->aspect + 0.001f;
|
|
|
|
uiStyleFontDrawRotated(&style->paneltitle, &hrect, activename);
|
2009-04-08 16:51:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-12 13:40:29 +00:00
|
|
|
static void rectf_scale(rctf *rect, float scale)
|
|
|
|
{
|
|
|
|
float centx= 0.5f*(rect->xmin+rect->xmax);
|
|
|
|
float centy= 0.5f*(rect->ymin+rect->ymax);
|
|
|
|
float sizex= 0.5f*scale*(rect->xmax - rect->xmin);
|
|
|
|
float sizey= 0.5f*scale*(rect->ymax - rect->ymin);
|
|
|
|
|
|
|
|
rect->xmin= centx - sizex;
|
|
|
|
rect->xmax= centx + sizex;
|
|
|
|
rect->ymin= centy - sizey;
|
|
|
|
rect->ymax= centy + sizey;
|
|
|
|
}
|
|
|
|
|
2.5
Summary of ain features:
- Themes and Styles are now editable.
- CTRL+U "Save user defaults" now goes to new .B25.blend, so you
can use 2.4x and 2.5x next to each other. If B25 doesn't exist, it
reads the regular .B.blend
- Press Tkey in 3d window for (unfinished) toolbar WIP. It now only
shows the last operator, if appropriate.
Nkey properties moved to the other side.
A lot of work was done on removing old themes for good and properly
getting it work with the 2.5 region system. Here's some notes;
- Buttons now all have a complete set of colors, based on button classifications
(See outliner -> user prefs -> Interface
- Theme colors have been extended with basic colors for region types.
Currently colors are defined for Window, Header, List/Channels and
for Button/Tool views.
The screen manager handles this btw, so a TH_BACK will always pick the
right backdrop color.
- Menu backdrops are in in Button theme colors. Floating Panels will be in
the per-space type Themes.
- Styles were added in RNA too, but only for the font settings now.
Only Panel font, widget font and widget-label work now. The 'group label'
will be for templates mostly.
Style settings will be expanded with spacing defaults, label conventions,
etc.
- Label text colors are stored in per-space Theme too, to make sure they fit.
Same goes for Panel title color.
Note that 'shadow' for fonts can conflict with text colors; shadow color is
currently stored in Style... shadow code needs a bit of work still.
2009-04-27 13:44:11 +00:00
|
|
|
/* panel integrated in buttonswindow, tool/property lists etc */
|
2010-10-16 02:40:31 +00:00
|
|
|
void ui_draw_aligned_panel(uiStyle *style, uiBlock *block, rcti *rect)
|
2009-04-02 15:01:11 +00:00
|
|
|
{
|
2009-06-19 23:11:41 +00:00
|
|
|
Panel *panel= block->panel;
|
2009-04-12 13:40:29 +00:00
|
|
|
rcti headrect;
|
|
|
|
rctf itemrect;
|
2009-04-02 15:01:11 +00:00
|
|
|
int ofsx;
|
|
|
|
|
|
|
|
if(panel->paneltab) return;
|
2009-07-08 15:34:41 +00:00
|
|
|
if(panel->type && (panel->type->flag & PNL_NO_HEADER)) return;
|
2009-04-16 21:39:45 +00:00
|
|
|
|
2009-04-12 13:40:29 +00:00
|
|
|
/* calculate header rect */
|
2009-05-19 17:13:33 +00:00
|
|
|
/* + 0.001f to prevent flicker due to float inaccuracy */
|
2009-04-12 13:40:29 +00:00
|
|
|
headrect= *rect;
|
|
|
|
headrect.ymin= headrect.ymax;
|
2009-05-19 17:13:33 +00:00
|
|
|
headrect.ymax= headrect.ymin + floor(PNL_HEADER/block->aspect + 0.001f);
|
2009-04-12 13:40:29 +00:00
|
|
|
|
2009-06-19 23:11:41 +00:00
|
|
|
if(!(panel->runtime_flag & PNL_FIRST)) {
|
2009-05-19 17:13:33 +00:00
|
|
|
float minx= rect->xmin+5.0f/block->aspect;
|
2009-05-01 06:24:52 +00:00
|
|
|
float maxx= rect->xmax-5.0f/block->aspect;
|
2009-04-12 13:40:29 +00:00
|
|
|
float y= headrect.ymax;
|
2009-04-02 15:01:11 +00:00
|
|
|
|
|
|
|
glEnable(GL_BLEND);
|
|
|
|
glColor4f(0.0f, 0.0f, 0.0f, 0.5f);
|
2009-04-12 13:40:29 +00:00
|
|
|
fdrawline(minx, y+1, maxx, y+1);
|
2009-04-02 15:01:11 +00:00
|
|
|
glColor4f(1.0f, 1.0f, 1.0f, 0.25f);
|
2009-04-12 13:40:29 +00:00
|
|
|
fdrawline(minx, y, maxx, y);
|
2009-04-02 15:01:11 +00:00
|
|
|
glDisable(GL_BLEND);
|
|
|
|
}
|
|
|
|
|
2009-10-19 03:54:30 +00:00
|
|
|
/* horizontal title */
|
2009-04-02 15:01:11 +00:00
|
|
|
if(!(panel->flag & PNL_CLOSEDX)) {
|
2010-10-16 02:40:31 +00:00
|
|
|
ui_draw_aligned_panel_header(style, block, &headrect, 'h');
|
2009-04-12 13:40:29 +00:00
|
|
|
|
|
|
|
/* itemrect smaller */
|
2009-05-19 17:13:33 +00:00
|
|
|
itemrect.xmax= headrect.xmax - 5.0f/block->aspect;
|
2009-04-12 13:40:29 +00:00
|
|
|
itemrect.xmin= itemrect.xmax - (headrect.ymax-headrect.ymin);
|
|
|
|
itemrect.ymin= headrect.ymin;
|
|
|
|
itemrect.ymax= headrect.ymax;
|
|
|
|
rectf_scale(&itemrect, 0.8f);
|
|
|
|
ui_draw_panel_dragwidget(&itemrect);
|
2009-04-02 15:01:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* if the panel is minimized vertically:
|
|
|
|
* (------)
|
|
|
|
*/
|
|
|
|
if(panel->flag & PNL_CLOSEDY) {
|
|
|
|
|
|
|
|
}
|
|
|
|
else if(panel->flag & PNL_CLOSEDX) {
|
2009-10-19 03:54:30 +00:00
|
|
|
/* draw vertical title */
|
2010-10-16 02:40:31 +00:00
|
|
|
ui_draw_aligned_panel_header(style, block, &headrect, 'v');
|
2009-04-02 15:01:11 +00:00
|
|
|
}
|
|
|
|
/* an open panel */
|
|
|
|
else {
|
|
|
|
|
|
|
|
/* in some occasions, draw a border */
|
|
|
|
if(panel->flag & PNL_SELECT) {
|
|
|
|
if(panel->control & UI_PNL_SOLID) uiSetRoundBox(15);
|
|
|
|
else uiSetRoundBox(3);
|
|
|
|
|
2.5
Summary of ain features:
- Themes and Styles are now editable.
- CTRL+U "Save user defaults" now goes to new .B25.blend, so you
can use 2.4x and 2.5x next to each other. If B25 doesn't exist, it
reads the regular .B.blend
- Press Tkey in 3d window for (unfinished) toolbar WIP. It now only
shows the last operator, if appropriate.
Nkey properties moved to the other side.
A lot of work was done on removing old themes for good and properly
getting it work with the 2.5 region system. Here's some notes;
- Buttons now all have a complete set of colors, based on button classifications
(See outliner -> user prefs -> Interface
- Theme colors have been extended with basic colors for region types.
Currently colors are defined for Window, Header, List/Channels and
for Button/Tool views.
The screen manager handles this btw, so a TH_BACK will always pick the
right backdrop color.
- Menu backdrops are in in Button theme colors. Floating Panels will be in
the per-space type Themes.
- Styles were added in RNA too, but only for the font settings now.
Only Panel font, widget font and widget-label work now. The 'group label'
will be for templates mostly.
Style settings will be expanded with spacing defaults, label conventions,
etc.
- Label text colors are stored in per-space Theme too, to make sure they fit.
Same goes for Panel title color.
Note that 'shadow' for fonts can conflict with text colors; shadow color is
currently stored in Style... shadow code needs a bit of work still.
2009-04-27 13:44:11 +00:00
|
|
|
UI_ThemeColorShade(TH_BACK, -120);
|
2009-06-08 16:24:37 +00:00
|
|
|
uiRoundRect(0.5f + rect->xmin, 0.5f + rect->ymin, 0.5f + rect->xmax, 0.5f + headrect.ymax+1, 8);
|
2009-04-02 15:01:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(panel->control & UI_PNL_SCALE)
|
2009-04-09 18:11:18 +00:00
|
|
|
ui_draw_panel_scalewidget(rect);
|
2009-04-02 15:01:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* draw optional close icon */
|
|
|
|
|
|
|
|
ofsx= 6;
|
|
|
|
if(panel->control & UI_PNL_CLOSE) {
|
|
|
|
|
2.5
Summary of ain features:
- Themes and Styles are now editable.
- CTRL+U "Save user defaults" now goes to new .B25.blend, so you
can use 2.4x and 2.5x next to each other. If B25 doesn't exist, it
reads the regular .B.blend
- Press Tkey in 3d window for (unfinished) toolbar WIP. It now only
shows the last operator, if appropriate.
Nkey properties moved to the other side.
A lot of work was done on removing old themes for good and properly
getting it work with the 2.5 region system. Here's some notes;
- Buttons now all have a complete set of colors, based on button classifications
(See outliner -> user prefs -> Interface
- Theme colors have been extended with basic colors for region types.
Currently colors are defined for Window, Header, List/Channels and
for Button/Tool views.
The screen manager handles this btw, so a TH_BACK will always pick the
right backdrop color.
- Menu backdrops are in in Button theme colors. Floating Panels will be in
the per-space type Themes.
- Styles were added in RNA too, but only for the font settings now.
Only Panel font, widget font and widget-label work now. The 'group label'
will be for templates mostly.
Style settings will be expanded with spacing defaults, label conventions,
etc.
- Label text colors are stored in per-space Theme too, to make sure they fit.
Same goes for Panel title color.
Note that 'shadow' for fonts can conflict with text colors; shadow color is
currently stored in Style... shadow code needs a bit of work still.
2009-04-27 13:44:11 +00:00
|
|
|
UI_ThemeColor(TH_TEXT);
|
2009-04-09 18:11:18 +00:00
|
|
|
ui_draw_x_icon(rect->xmin+2+ofsx, rect->ymax+2);
|
2009-04-02 15:01:11 +00:00
|
|
|
ofsx= 22;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* draw collapse icon */
|
|
|
|
UI_ThemeColor(TH_TEXT);
|
|
|
|
|
2009-04-12 13:40:29 +00:00
|
|
|
/* itemrect smaller */
|
2009-05-19 17:13:33 +00:00
|
|
|
itemrect.xmin= headrect.xmin + 5.0f/block->aspect;
|
2009-04-12 13:40:29 +00:00
|
|
|
itemrect.xmax= itemrect.xmin + (headrect.ymax-headrect.ymin);
|
|
|
|
itemrect.ymin= headrect.ymin;
|
|
|
|
itemrect.ymax= headrect.ymax;
|
|
|
|
|
2009-05-19 17:13:33 +00:00
|
|
|
rectf_scale(&itemrect, 0.5f);
|
2009-04-12 13:40:29 +00:00
|
|
|
|
2009-04-02 15:01:11 +00:00
|
|
|
if(panel->flag & PNL_CLOSEDY)
|
2009-04-12 13:40:29 +00:00
|
|
|
ui_draw_tria_rect(&itemrect, 'h');
|
2009-04-02 15:01:11 +00:00
|
|
|
else if(panel->flag & PNL_CLOSEDX)
|
2009-04-12 13:40:29 +00:00
|
|
|
ui_draw_tria_rect(&itemrect, 'h');
|
2009-04-02 15:01:11 +00:00
|
|
|
else
|
2009-04-12 13:40:29 +00:00
|
|
|
ui_draw_tria_rect(&itemrect, 'v');
|
2009-04-02 15:01:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2009-04-16 21:39:45 +00:00
|
|
|
/************************** panel alignment *************************/
|
2008-12-26 13:11:04 +00:00
|
|
|
|
2009-07-08 15:34:41 +00:00
|
|
|
static int get_panel_header(Panel *pa)
|
|
|
|
{
|
|
|
|
if(pa->type && (pa->type->flag & PNL_NO_HEADER))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return PNL_HEADER;
|
|
|
|
}
|
|
|
|
|
2009-07-09 19:45:27 +00:00
|
|
|
static int get_panel_size_y(uiStyle *style, Panel *pa)
|
|
|
|
{
|
|
|
|
if(pa->type && (pa->type->flag & PNL_NO_HEADER))
|
|
|
|
return pa->sizey;
|
|
|
|
|
|
|
|
return PNL_HEADER + pa->sizey + style->panelouter;
|
|
|
|
}
|
|
|
|
|
2008-12-26 13:11:04 +00:00
|
|
|
/* this function is needed because uiBlock and Panel itself dont
|
|
|
|
change sizey or location when closed */
|
|
|
|
static int get_panel_real_ofsy(Panel *pa)
|
|
|
|
{
|
|
|
|
if(pa->flag & PNL_CLOSEDY) return pa->ofsy+pa->sizey;
|
|
|
|
else if(pa->paneltab && (pa->paneltab->flag & PNL_CLOSEDY)) return pa->ofsy+pa->sizey;
|
2009-04-08 16:51:35 +00:00
|
|
|
else if(pa->paneltab) return pa->paneltab->ofsy;
|
2008-12-26 13:11:04 +00:00
|
|
|
else return pa->ofsy;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int get_panel_real_ofsx(Panel *pa)
|
|
|
|
{
|
2009-07-08 15:34:41 +00:00
|
|
|
if(pa->flag & PNL_CLOSEDX) return pa->ofsx+get_panel_header(pa);
|
|
|
|
else if(pa->paneltab && (pa->paneltab->flag & PNL_CLOSEDX)) return pa->ofsx+get_panel_header(pa);
|
2008-12-26 13:11:04 +00:00
|
|
|
else return pa->ofsx+pa->sizex;
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef struct PanelSort {
|
|
|
|
Panel *pa, *orig;
|
|
|
|
} PanelSort;
|
|
|
|
|
|
|
|
/* note about sorting;
|
2009-04-17 11:59:25 +00:00
|
|
|
the sortorder has a lower value for new panels being added.
|
2008-12-26 13:11:04 +00:00
|
|
|
however, that only works to insert a single panel, when more new panels get
|
|
|
|
added the coordinates of existing panels and the previously stored to-be-insterted
|
|
|
|
panels do not match for sorting */
|
|
|
|
|
|
|
|
static int find_leftmost_panel(const void *a1, const void *a2)
|
|
|
|
{
|
|
|
|
const PanelSort *ps1=a1, *ps2=a2;
|
|
|
|
|
2009-04-16 21:39:45 +00:00
|
|
|
if(ps1->pa->ofsx > ps2->pa->ofsx) return 1;
|
|
|
|
else if(ps1->pa->ofsx < ps2->pa->ofsx) return -1;
|
2009-04-17 11:59:25 +00:00
|
|
|
else if(ps1->pa->sortorder > ps2->pa->sortorder) return 1;
|
|
|
|
else if(ps1->pa->sortorder < ps2->pa->sortorder) return -1;
|
2008-12-26 13:11:04 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int find_highest_panel(const void *a1, const void *a2)
|
|
|
|
{
|
|
|
|
const PanelSort *ps1=a1, *ps2=a2;
|
|
|
|
|
2010-06-09 07:55:49 +00:00
|
|
|
/* stick uppermost header-less panels to the top of the region -
|
|
|
|
* prevent them from being sorted */
|
|
|
|
if (ps1->pa->sortorder < ps2->pa->sortorder && ps1->pa->type->flag & PNL_NO_HEADER) return -1;
|
|
|
|
|
2009-04-16 21:39:45 +00:00
|
|
|
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;
|
2009-04-17 11:59:25 +00:00
|
|
|
else if(ps1->pa->sortorder > ps2->pa->sortorder) return 1;
|
|
|
|
else if(ps1->pa->sortorder < ps2->pa->sortorder) return -1;
|
2009-04-16 21:39:45 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int compare_panel(const void *a1, const void *a2)
|
|
|
|
{
|
|
|
|
const PanelSort *ps1=a1, *ps2=a2;
|
|
|
|
|
2009-04-17 11:59:25 +00:00
|
|
|
if(ps1->pa->sortorder > ps2->pa->sortorder) return 1;
|
|
|
|
else if(ps1->pa->sortorder < ps2->pa->sortorder) return -1;
|
2008-12-26 13:11:04 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* this doesnt draw */
|
|
|
|
/* returns 1 when it did something */
|
2009-04-17 11:59:25 +00:00
|
|
|
int uiAlignPanelStep(ScrArea *sa, ARegion *ar, float fac, int drag)
|
2008-12-26 13:11:04 +00:00
|
|
|
{
|
UI: Layout Engine
* Buttons are now created first, and after that the layout is computed.
This means the layout engine now works at button level, and makes it
easier to write templates. Otherwise you had to store all info and
create the buttons later.
* Added interface_templates.c as a separate file to put templates in.
These can contain regular buttons, and can be put in a Free layout,
which means you can specify manual coordinates, but still get nested
correct inside other layouts.
* API was changed to allow better nesting. Previously items were added
in the last added layout specifier, i.e. one level up in the layout
hierarchy. This doesn't work well in always, so now when creating things
like rows or columns it always returns a layout which you have to add
the items in. All py scripts were updated to follow this.
* Computing the layout now goes in two passes, first estimating the
required width/height of all nested layouts, and then in the second
pass using the results of that to decide on the actual locations.
* Enum and array buttons now follow the direction of the layout, i.e.
they are vertical or horizontal depending if they are in a column or row.
* Color properties now get a color picker, and only get the additional
RGB sliders with Expand=True.
* File/directory string properties now get a button next to them for
opening the file browse, though this is not implemented yet.
* Layout items can now be aligned, set align=True when creating a column,
row, etc.
* Buttons now get a minimum width of one icon (avoids squashing icon
buttons).
* Moved some more space variables into Style.
2009-05-15 11:19:59 +00:00
|
|
|
uiStyle *style= U.uistyles.first;
|
2008-12-26 13:11:04 +00:00
|
|
|
Panel *pa;
|
|
|
|
PanelSort *ps, *panelsort, *psnext;
|
|
|
|
int a, tot=0, done;
|
2009-02-10 15:38:00 +00:00
|
|
|
int align= panel_aligned(sa, ar);
|
2008-12-26 13:11:04 +00:00
|
|
|
|
2009-04-16 21:39:45 +00:00
|
|
|
/* count active, not tabbed panels */
|
|
|
|
for(pa= ar->panels.first; pa; pa= pa->next)
|
|
|
|
if((pa->runtime_flag & PNL_ACTIVE) && pa->paneltab==NULL)
|
|
|
|
tot++;
|
2008-12-26 13:11:04 +00:00
|
|
|
|
|
|
|
if(tot==0) return 0;
|
|
|
|
|
|
|
|
/* extra; change close direction? */
|
|
|
|
for(pa= ar->panels.first; pa; pa= pa->next) {
|
2009-04-16 21:39:45 +00:00
|
|
|
if((pa->runtime_flag & PNL_ACTIVE) && pa->paneltab==NULL) {
|
|
|
|
if((pa->flag & PNL_CLOSEDX) && (align==BUT_VERTICAL))
|
2008-12-26 13:11:04 +00:00
|
|
|
pa->flag ^= PNL_CLOSED;
|
2009-04-16 21:39:45 +00:00
|
|
|
else if((pa->flag & PNL_CLOSEDY) && (align==BUT_HORIZONTAL))
|
2008-12-26 13:11:04 +00:00
|
|
|
pa->flag ^= PNL_CLOSED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-16 21:39:45 +00:00
|
|
|
/* sort panels */
|
|
|
|
panelsort= MEM_callocN(tot*sizeof(PanelSort), "panelsort");
|
2008-12-26 13:11:04 +00:00
|
|
|
|
|
|
|
ps= panelsort;
|
|
|
|
for(pa= ar->panels.first; pa; pa= pa->next) {
|
2009-04-16 21:39:45 +00:00
|
|
|
if((pa->runtime_flag & PNL_ACTIVE) && pa->paneltab==NULL) {
|
2008-12-26 13:11:04 +00:00
|
|
|
ps->pa= MEM_dupallocN(pa);
|
|
|
|
ps->orig= pa;
|
|
|
|
ps++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-17 11:59:25 +00:00
|
|
|
if(drag) {
|
|
|
|
/* while we are dragging, we sort on location and update sortorder */
|
|
|
|
if(align==BUT_VERTICAL)
|
|
|
|
qsort(panelsort, tot, sizeof(PanelSort), find_highest_panel);
|
|
|
|
else
|
|
|
|
qsort(panelsort, tot, sizeof(PanelSort), find_leftmost_panel);
|
|
|
|
|
|
|
|
for(ps=panelsort, a=0; a<tot; a++, ps++)
|
|
|
|
ps->orig->sortorder= a;
|
|
|
|
}
|
2008-12-26 13:11:04 +00:00
|
|
|
else
|
2009-04-17 11:59:25 +00:00
|
|
|
/* otherwise use sortorder */
|
|
|
|
qsort(panelsort, tot, sizeof(PanelSort), compare_panel);
|
2008-12-26 13:11:04 +00:00
|
|
|
|
|
|
|
/* no smart other default start loc! this keeps switching f5/f6/etc compatible */
|
|
|
|
ps= panelsort;
|
2009-05-19 17:13:33 +00:00
|
|
|
ps->pa->ofsx= 0;
|
2009-07-09 19:45:27 +00:00
|
|
|
ps->pa->ofsy= -get_panel_size_y(style, ps->pa);
|
2009-04-02 01:39:33 +00:00
|
|
|
|
2009-04-16 21:39:45 +00:00
|
|
|
for(a=0; a<tot-1; a++, ps++) {
|
2008-12-26 13:11:04 +00:00
|
|
|
psnext= ps+1;
|
|
|
|
|
2009-02-10 15:38:00 +00:00
|
|
|
if(align==BUT_VERTICAL) {
|
2009-04-16 21:39:45 +00:00
|
|
|
psnext->pa->ofsx= ps->pa->ofsx;
|
2009-07-09 19:45:27 +00:00
|
|
|
psnext->pa->ofsy= get_panel_real_ofsy(ps->pa) - get_panel_size_y(style, psnext->pa);
|
2008-12-26 13:11:04 +00:00
|
|
|
}
|
|
|
|
else {
|
2009-05-19 17:13:33 +00:00
|
|
|
psnext->pa->ofsx= get_panel_real_ofsx(ps->pa);
|
2009-07-09 19:45:27 +00:00
|
|
|
psnext->pa->ofsy= ps->pa->ofsy + get_panel_size_y(style, ps->pa) - get_panel_size_y(style, psnext->pa);
|
2008-12-26 13:11:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* we interpolate */
|
|
|
|
done= 0;
|
|
|
|
ps= panelsort;
|
|
|
|
for(a=0; a<tot; a++, ps++) {
|
|
|
|
if((ps->pa->flag & PNL_SELECT)==0) {
|
|
|
|
if((ps->orig->ofsx != ps->pa->ofsx) || (ps->orig->ofsy != ps->pa->ofsy)) {
|
|
|
|
ps->orig->ofsx= floor(0.5 + fac*ps->pa->ofsx + (1.0-fac)*ps->orig->ofsx);
|
|
|
|
ps->orig->ofsy= floor(0.5 + fac*ps->pa->ofsy + (1.0-fac)*ps->orig->ofsy);
|
|
|
|
done= 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* copy locations to tabs */
|
|
|
|
for(pa= ar->panels.first; pa; pa= pa->next)
|
2009-04-16 21:39:45 +00:00
|
|
|
if(pa->paneltab && (pa->runtime_flag & PNL_ACTIVE))
|
|
|
|
ui_panel_copy_offset(pa, pa->paneltab);
|
2008-12-26 13:11:04 +00:00
|
|
|
|
|
|
|
/* free panelsort array */
|
|
|
|
for(ps= panelsort, a=0; a<tot; a++, ps++)
|
|
|
|
MEM_freeN(ps->pa);
|
|
|
|
MEM_freeN(panelsort);
|
|
|
|
|
|
|
|
return done;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-16 21:39:45 +00:00
|
|
|
static void ui_do_animate(const bContext *C, Panel *panel)
|
2008-12-26 13:11:04 +00:00
|
|
|
{
|
|
|
|
uiHandlePanelData *data= panel->activedata;
|
|
|
|
ScrArea *sa= CTX_wm_area(C);
|
|
|
|
ARegion *ar= CTX_wm_region(C);
|
|
|
|
float fac;
|
|
|
|
|
|
|
|
fac= (PIL_check_seconds_timer()-data->starttime)/ANIMATION_TIME;
|
|
|
|
fac= sqrt(fac);
|
|
|
|
fac= MIN2(fac, 1.0f);
|
|
|
|
|
|
|
|
/* for max 1 second, interpolate positions */
|
2009-04-17 11:59:25 +00:00
|
|
|
if(uiAlignPanelStep(sa, ar, fac, 0))
|
2008-12-26 13:11:04 +00:00
|
|
|
ED_region_tag_redraw(ar);
|
|
|
|
else
|
|
|
|
fac= 1.0f;
|
|
|
|
|
2009-04-16 21:39:45 +00:00
|
|
|
if(fac >= 1.0f) {
|
2008-12-26 13:11:04 +00:00
|
|
|
panel_activate_state(C, panel, PANEL_STATE_EXIT);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-14 12:24:08 +00:00
|
|
|
void uiBeginPanels(const bContext *UNUSED(C), ARegion *ar)
|
2009-04-02 01:39:33 +00:00
|
|
|
{
|
|
|
|
Panel *pa;
|
|
|
|
|
2010-03-22 09:30:00 +00:00
|
|
|
/* set all panels as inactive, so that at the end we know
|
2009-04-02 01:39:33 +00:00
|
|
|
* which ones were used */
|
2009-04-16 21:39:45 +00:00
|
|
|
for(pa=ar->panels.first; pa; pa=pa->next) {
|
|
|
|
if(pa->runtime_flag & PNL_ACTIVE)
|
|
|
|
pa->runtime_flag= PNL_WAS_ACTIVE;
|
|
|
|
else
|
|
|
|
pa->runtime_flag= 0;
|
|
|
|
}
|
2009-04-02 01:39:33 +00:00
|
|
|
}
|
|
|
|
|
2008-12-26 13:11:04 +00:00
|
|
|
/* only draws blocks with panels */
|
2009-04-02 01:39:33 +00:00
|
|
|
void uiEndPanels(const bContext *C, ARegion *ar)
|
2008-12-26 13:11:04 +00:00
|
|
|
{
|
|
|
|
ScrArea *sa= CTX_wm_area(C);
|
|
|
|
uiBlock *block;
|
2009-06-19 23:11:41 +00:00
|
|
|
Panel *panot, *panew, *patest, *pa, *firstpa;
|
2008-12-26 13:11:04 +00:00
|
|
|
|
2009-05-20 14:46:49 +00:00
|
|
|
/* offset contents */
|
2008-12-26 13:11:04 +00:00
|
|
|
for(block= ar->uiblocks.first; block; block= block->next)
|
|
|
|
if(block->active && block->panel)
|
2009-05-19 17:13:33 +00:00
|
|
|
ui_offset_panel_block(block);
|
2008-12-26 13:11:04 +00:00
|
|
|
|
2011-01-06 04:35:57 +00:00
|
|
|
/* consistency; are panels not made, whilst they have tabs */
|
2008-12-26 13:11:04 +00:00
|
|
|
for(panot= ar->panels.first; panot; panot= panot->next) {
|
2009-04-16 21:39:45 +00:00
|
|
|
if((panot->runtime_flag & PNL_ACTIVE)==0) { // not made
|
2008-12-26 13:11:04 +00:00
|
|
|
|
|
|
|
for(panew= ar->panels.first; panew; panew= panew->next) {
|
2009-04-16 21:39:45 +00:00
|
|
|
if((panew->runtime_flag & PNL_ACTIVE)) {
|
2008-12-26 13:11:04 +00:00
|
|
|
if(panew->paneltab==panot) { // panew is tab in notmade pa
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* now panew can become the new parent, check all other tabs */
|
|
|
|
if(panew) {
|
|
|
|
for(patest= ar->panels.first; patest; patest= patest->next) {
|
|
|
|
if(patest->paneltab == panot) {
|
|
|
|
patest->paneltab= panew;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
panot->paneltab= panew;
|
|
|
|
panew->paneltab= NULL;
|
|
|
|
ED_region_tag_redraw(ar); // the buttons panew were not made
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-16 21:39:45 +00:00
|
|
|
/* re-align, possibly with animation */
|
|
|
|
if(panels_re_align(sa, ar, &pa)) {
|
|
|
|
if(pa)
|
|
|
|
panel_activate_state(C, pa, PANEL_STATE_ANIMATION);
|
|
|
|
else
|
2009-04-17 11:59:25 +00:00
|
|
|
uiAlignPanelStep(sa, ar, 1.0, 0);
|
2009-04-16 21:39:45 +00:00
|
|
|
}
|
2009-04-02 01:39:33 +00:00
|
|
|
|
2009-06-19 23:11:41 +00:00
|
|
|
/* tag first panel */
|
|
|
|
firstpa= NULL;
|
|
|
|
for(block= ar->uiblocks.first; block; block=block->next)
|
|
|
|
if(block->active && block->panel)
|
|
|
|
if(!firstpa || block->panel->sortorder < firstpa->sortorder)
|
|
|
|
firstpa= block->panel;
|
|
|
|
|
|
|
|
if(firstpa)
|
|
|
|
firstpa->runtime_flag |= PNL_FIRST;
|
|
|
|
|
2010-04-06 09:05:00 +00:00
|
|
|
UI_ThemeClearColor(TH_BACK);
|
|
|
|
|
2008-12-26 13:11:04 +00:00
|
|
|
/* draw panels, selected on top */
|
|
|
|
for(block= ar->uiblocks.first; block; block=block->next) {
|
|
|
|
if(block->active && block->panel && !(block->panel->flag & PNL_SELECT)) {
|
|
|
|
uiDrawBlock(C, block);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for(block= ar->uiblocks.first; block; block=block->next) {
|
|
|
|
if(block->active && block->panel && (block->panel->flag & PNL_SELECT)) {
|
|
|
|
uiDrawBlock(C, block);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ------------ panel merging ---------------- */
|
|
|
|
|
|
|
|
static void check_panel_overlap(ARegion *ar, Panel *panel)
|
|
|
|
{
|
|
|
|
Panel *pa;
|
|
|
|
|
|
|
|
/* also called with panel==NULL for clear */
|
|
|
|
|
|
|
|
for(pa=ar->panels.first; pa; pa=pa->next) {
|
|
|
|
pa->flag &= ~PNL_OVERLAP;
|
|
|
|
if(panel && (pa != panel)) {
|
2009-04-16 21:39:45 +00:00
|
|
|
if(pa->paneltab==NULL && (pa->runtime_flag & PNL_ACTIVE)) {
|
2008-12-26 13:11:04 +00:00
|
|
|
float safex= 0.2, safey= 0.2;
|
|
|
|
|
2009-04-16 21:39:45 +00:00
|
|
|
if(pa->flag & PNL_CLOSEDX) safex= 0.05;
|
2008-12-26 13:11:04 +00:00
|
|
|
else if(pa->flag & PNL_CLOSEDY) safey= 0.05;
|
2009-04-16 21:39:45 +00:00
|
|
|
else if(panel->flag & PNL_CLOSEDX) safex= 0.05;
|
2008-12-26 13:11:04 +00:00
|
|
|
else if(panel->flag & PNL_CLOSEDY) safey= 0.05;
|
|
|
|
|
2009-04-16 21:39:45 +00:00
|
|
|
if(pa->ofsx > panel->ofsx- safex*panel->sizex)
|
|
|
|
if(pa->ofsx+pa->sizex < panel->ofsx+ (1.0+safex)*panel->sizex)
|
|
|
|
if(pa->ofsy > panel->ofsy- safey*panel->sizey)
|
|
|
|
if(pa->ofsy+pa->sizey < panel->ofsy+ (1.0+safey)*panel->sizey)
|
2008-12-26 13:11:04 +00:00
|
|
|
pa->flag |= PNL_OVERLAP;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-16 21:39:45 +00:00
|
|
|
/************************ panel dragging ****************************/
|
2008-12-26 13:11:04 +00:00
|
|
|
|
2009-04-16 21:39:45 +00:00
|
|
|
static void ui_do_drag(const bContext *C, wmEvent *event, Panel *panel)
|
2008-12-26 13:11:04 +00:00
|
|
|
{
|
|
|
|
uiHandlePanelData *data= panel->activedata;
|
|
|
|
ScrArea *sa= CTX_wm_area(C);
|
|
|
|
ARegion *ar= CTX_wm_region(C);
|
2009-02-10 15:38:00 +00:00
|
|
|
short align= panel_aligned(sa, ar), dx=0, dy=0;
|
2008-12-26 13:11:04 +00:00
|
|
|
|
|
|
|
/* first clip for window, no dragging outside */
|
|
|
|
if(!BLI_in_rcti(&ar->winrct, event->x, event->y))
|
|
|
|
return;
|
|
|
|
|
|
|
|
dx= (event->x-data->startx) & ~(PNL_GRID-1);
|
|
|
|
dy= (event->y-data->starty) & ~(PNL_GRID-1);
|
2009-07-23 20:50:24 +00:00
|
|
|
|
|
|
|
dx *= (float)(ar->v2d.cur.xmax - ar->v2d.cur.xmin)/(float)(ar->winrct.xmax - ar->winrct.xmin);
|
|
|
|
dy *= (float)(ar->v2d.cur.ymax - ar->v2d.cur.ymin)/(float)(ar->winrct.ymax - ar->winrct.ymin);
|
2008-12-26 13:11:04 +00:00
|
|
|
|
|
|
|
if(data->state == PANEL_STATE_DRAG_SCALE) {
|
|
|
|
panel->sizex = MAX2(data->startsizex+dx, UI_PANEL_MINX);
|
|
|
|
|
2009-04-16 21:39:45 +00:00
|
|
|
if(data->startsizey-dy < UI_PANEL_MINY)
|
2008-12-26 13:11:04 +00:00
|
|
|
dy= -UI_PANEL_MINY+data->startsizey;
|
|
|
|
|
2009-04-16 21:39:45 +00:00
|
|
|
panel->sizey= data->startsizey-dy;
|
|
|
|
panel->ofsy= data->startofsy+dy;
|
2008-12-26 13:11:04 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* reset the panel snapping, to allow dragging away from snapped edges */
|
|
|
|
panel->snap = PNL_SNAP_NONE;
|
|
|
|
|
|
|
|
panel->ofsx = data->startofsx+dx;
|
|
|
|
panel->ofsy = data->startofsy+dy;
|
|
|
|
check_panel_overlap(ar, panel);
|
|
|
|
|
2009-04-17 11:59:25 +00:00
|
|
|
if(align) uiAlignPanelStep(sa, ar, 0.2, 1);
|
2008-12-26 13:11:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ED_region_tag_redraw(ar);
|
|
|
|
}
|
|
|
|
|
2009-04-16 21:39:45 +00:00
|
|
|
/******************* region level panel interaction *****************/
|
2008-12-26 13:11:04 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* this function is supposed to call general window drawing too */
|
|
|
|
/* also it supposes a block has panel, and isnt a menu */
|
2010-04-11 11:52:39 +00:00
|
|
|
static void ui_handle_panel_header(const bContext *C, uiBlock *block, int mx, int my, int event)
|
2008-12-26 13:11:04 +00:00
|
|
|
{
|
|
|
|
ScrArea *sa= CTX_wm_area(C);
|
|
|
|
ARegion *ar= CTX_wm_region(C);
|
|
|
|
Panel *pa;
|
2009-02-10 15:38:00 +00:00
|
|
|
int align= panel_aligned(sa, ar), button= 0;
|
2008-12-26 13:11:04 +00:00
|
|
|
|
|
|
|
/* mouse coordinates in panel space! */
|
|
|
|
|
2009-04-12 13:40:29 +00:00
|
|
|
/* XXX weak code, currently it assumes layout style for location of widgets */
|
|
|
|
|
2008-12-26 13:11:04 +00:00
|
|
|
/* check open/collapsed button */
|
2010-04-11 11:52:39 +00:00
|
|
|
if(event==RETKEY)
|
|
|
|
button= 1;
|
2010-04-12 17:45:51 +00:00
|
|
|
else if(event==AKEY)
|
|
|
|
button= 1;
|
2010-04-11 11:52:39 +00:00
|
|
|
else if(block->panel->flag & PNL_CLOSEDX) {
|
2008-12-26 13:11:04 +00:00
|
|
|
if(my >= block->maxy) button= 1;
|
|
|
|
}
|
|
|
|
else if(block->panel->control & UI_PNL_CLOSE) {
|
2009-04-12 13:40:29 +00:00
|
|
|
if(mx <= block->minx+10+PNL_ICON-2) button= 2;
|
|
|
|
else if(mx <= block->minx+10+2*PNL_ICON+2) button= 1;
|
2008-12-26 13:11:04 +00:00
|
|
|
}
|
2009-04-12 13:40:29 +00:00
|
|
|
else if(mx <= block->minx+10+PNL_ICON+2) {
|
2008-12-26 13:11:04 +00:00
|
|
|
button= 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(button) {
|
|
|
|
if(button==2) { // close
|
|
|
|
ED_region_tag_redraw(ar);
|
|
|
|
}
|
|
|
|
else { // collapse
|
|
|
|
if(block->panel->flag & PNL_CLOSED) {
|
|
|
|
block->panel->flag &= ~PNL_CLOSED;
|
|
|
|
/* snap back up so full panel aligns with screen edge */
|
|
|
|
if (block->panel->snap & PNL_SNAP_BOTTOM)
|
|
|
|
block->panel->ofsy= 0;
|
|
|
|
}
|
|
|
|
else if(align==BUT_HORIZONTAL) {
|
|
|
|
block->panel->flag |= PNL_CLOSEDX;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* snap down to bottom screen edge*/
|
|
|
|
block->panel->flag |= PNL_CLOSEDY;
|
|
|
|
if (block->panel->snap & PNL_SNAP_BOTTOM)
|
|
|
|
block->panel->ofsy= -block->panel->sizey;
|
|
|
|
}
|
|
|
|
|
|
|
|
for(pa= ar->panels.first; pa; pa= pa->next) {
|
|
|
|
if(pa->paneltab==block->panel) {
|
|
|
|
if(block->panel->flag & PNL_CLOSED) pa->flag |= PNL_CLOSED;
|
|
|
|
else pa->flag &= ~PNL_CLOSED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(align)
|
|
|
|
panel_activate_state(C, block->panel, PANEL_STATE_ANIMATION);
|
|
|
|
else
|
|
|
|
ED_region_tag_redraw(ar);
|
|
|
|
}
|
|
|
|
else if(block->panel->flag & PNL_CLOSED) {
|
|
|
|
panel_activate_state(C, block->panel, PANEL_STATE_DRAG);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
panel_activate_state(C, block->panel, PANEL_STATE_DRAG);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-04-11 11:52:39 +00:00
|
|
|
/* XXX should become modal keymap */
|
2010-04-12 17:45:51 +00:00
|
|
|
/* AKey is opening/closing panels, independent of button state now */
|
|
|
|
|
2008-12-26 13:11:04 +00:00
|
|
|
int ui_handler_panel_region(bContext *C, wmEvent *event)
|
|
|
|
{
|
|
|
|
ARegion *ar= CTX_wm_region(C);
|
|
|
|
uiBlock *block;
|
2009-07-08 15:34:41 +00:00
|
|
|
Panel *pa;
|
2009-04-02 01:39:33 +00:00
|
|
|
int retval, mx, my, inside_header= 0, inside_scale= 0, inside;
|
2008-12-26 13:11:04 +00:00
|
|
|
|
|
|
|
retval= WM_UI_HANDLER_CONTINUE;
|
|
|
|
for(block=ar->uiblocks.last; block; block=block->prev) {
|
|
|
|
mx= event->x;
|
|
|
|
my= event->y;
|
|
|
|
ui_window_to_block(ar, block, &mx, &my);
|
|
|
|
|
|
|
|
/* check if inside boundbox */
|
2009-04-02 01:39:33 +00:00
|
|
|
inside= 0;
|
2009-07-08 15:34:41 +00:00
|
|
|
pa= block->panel;
|
|
|
|
|
|
|
|
if(!pa || pa->paneltab!=NULL)
|
|
|
|
continue;
|
2009-08-16 07:26:29 +00:00
|
|
|
if(pa->type && pa->type->flag & PNL_NO_HEADER) // XXX - accessed freed panels when scripts reload, need to fix.
|
2009-07-08 15:34:41 +00:00
|
|
|
continue;
|
2009-04-02 01:39:33 +00:00
|
|
|
|
2009-07-08 15:34:41 +00:00
|
|
|
if(block->minx <= mx && block->maxx >= mx)
|
|
|
|
if(block->miny <= my && block->maxy+PNL_HEADER >= my)
|
|
|
|
inside= 1;
|
2010-04-12 17:45:51 +00:00
|
|
|
|
|
|
|
if(inside && event->val==KM_PRESS) {
|
2010-06-18 20:19:24 +00:00
|
|
|
if(event->type == AKEY && !ELEM4(1, event->ctrl, event->oskey, event->shift, event->alt)) {
|
2010-04-12 17:45:51 +00:00
|
|
|
|
|
|
|
if(pa->flag & PNL_CLOSEDY) {
|
|
|
|
if((block->maxy <= my) && (block->maxy+PNL_HEADER >= my))
|
|
|
|
ui_handle_panel_header(C, block, mx, my, event->type);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ui_handle_panel_header(C, block, mx, my, event->type);
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* on active button, do not handle panels */
|
|
|
|
if(ui_button_is_active(ar))
|
|
|
|
continue;
|
|
|
|
|
2009-04-02 01:39:33 +00:00
|
|
|
if(inside) {
|
|
|
|
/* clicked at panel header? */
|
2009-07-08 15:34:41 +00:00
|
|
|
if(pa->flag & PNL_CLOSEDX) {
|
2009-04-02 01:39:33 +00:00
|
|
|
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;
|
|
|
|
}
|
2009-07-08 15:34:41 +00:00
|
|
|
else if(pa->control & UI_PNL_SCALE) {
|
2009-04-02 01:39:33 +00:00
|
|
|
if(block->maxx-PNL_HEADER <= mx)
|
|
|
|
if(block->miny+PNL_HEADER >= my)
|
|
|
|
inside_scale= 1;
|
|
|
|
}
|
2008-12-26 13:11:04 +00:00
|
|
|
|
2009-04-02 01:39:33 +00:00
|
|
|
if(event->val==KM_PRESS) {
|
2010-04-11 11:52:39 +00:00
|
|
|
/* open close on header */
|
|
|
|
if(ELEM(event->type, RETKEY, PADENTER)) {
|
|
|
|
if(inside_header) {
|
|
|
|
ui_handle_panel_header(C, block, mx, my, RETKEY);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(event->type == LEFTMOUSE) {
|
2009-04-17 13:37:03 +00:00
|
|
|
if(inside_header) {
|
2010-04-11 11:52:39 +00:00
|
|
|
ui_handle_panel_header(C, block, mx, my, 0);
|
2009-04-17 13:37:03 +00:00
|
|
|
break;
|
|
|
|
}
|
2009-07-08 15:34:41 +00:00
|
|
|
else if(inside_scale && !(pa->flag & PNL_CLOSED)) {
|
|
|
|
panel_activate_state(C, pa, PANEL_STATE_DRAG_SCALE);
|
2009-04-17 13:37:03 +00:00
|
|
|
break;
|
|
|
|
}
|
2009-04-02 01:39:33 +00:00
|
|
|
}
|
|
|
|
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 */
|
2009-07-08 15:34:41 +00:00
|
|
|
if (pa->flag & (PNL_CLOSEDX|PNL_CLOSEDY)) {
|
2009-04-02 01:39:33 +00:00
|
|
|
if (inside_header)
|
|
|
|
zoom=1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
zoom=1;
|
2008-12-26 13:11:04 +00:00
|
|
|
|
2009-02-10 15:38:00 +00:00
|
|
|
#if 0 // XXX make float panel exception?
|
2009-04-02 01:39:33 +00:00
|
|
|
if(zoom) {
|
|
|
|
ScrArea *sa= CTX_wm_area(C);
|
|
|
|
SpaceLink *sl= sa->spacedata.first;
|
|
|
|
|
|
|
|
if(sa->spacetype!=SPACE_BUTS) {
|
2009-07-08 15:34:41 +00:00
|
|
|
if(!(pa->control & UI_PNL_SCALE)) {
|
2009-04-02 01:39:33 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
2008-12-26 13:11:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2009-04-16 21:39:45 +00:00
|
|
|
/**************** window level modal panel interaction **************/
|
2008-12-26 13:11:04 +00:00
|
|
|
|
2009-06-27 12:41:28 +00:00
|
|
|
/* note, this is modal handler and should not swallow events for animation */
|
2008-12-26 13:11:04 +00:00
|
|
|
static int ui_handler_panel(bContext *C, wmEvent *event, void *userdata)
|
|
|
|
{
|
|
|
|
Panel *panel= userdata;
|
|
|
|
uiHandlePanelData *data= panel->activedata;
|
|
|
|
|
|
|
|
/* verify if we can stop */
|
2009-02-02 16:30:03 +00:00
|
|
|
if(event->type == LEFTMOUSE && event->val!=KM_PRESS) {
|
2009-04-02 01:39:33 +00:00
|
|
|
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);
|
2008-12-26 13:11:04 +00:00
|
|
|
}
|
|
|
|
else if(event->type == MOUSEMOVE) {
|
2009-10-19 03:54:30 +00:00
|
|
|
if(data->state == PANEL_STATE_DRAG)
|
2008-12-26 13:11:04 +00:00
|
|
|
ui_do_drag(C, event, panel);
|
|
|
|
}
|
|
|
|
else if(event->type == TIMER && event->customdata == data->animtimer) {
|
|
|
|
if(data->state == PANEL_STATE_ANIMATION)
|
|
|
|
ui_do_animate(C, panel);
|
|
|
|
else if(data->state == PANEL_STATE_DRAG)
|
|
|
|
ui_do_drag(C, event, panel);
|
|
|
|
}
|
|
|
|
|
2009-04-02 01:39:33 +00:00
|
|
|
data= panel->activedata;
|
|
|
|
|
|
|
|
if(data && data->state == PANEL_STATE_ANIMATION)
|
2008-12-26 13:11:04 +00:00
|
|
|
return WM_UI_HANDLER_CONTINUE;
|
|
|
|
else
|
|
|
|
return WM_UI_HANDLER_BREAK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ui_handler_remove_panel(bContext *C, void *userdata)
|
|
|
|
{
|
|
|
|
Panel *pa= userdata;
|
|
|
|
|
|
|
|
panel_activate_state(C, pa, PANEL_STATE_EXIT);
|
|
|
|
}
|
|
|
|
|
2009-04-16 21:39:45 +00:00
|
|
|
static void panel_activate_state(const bContext *C, Panel *pa, uiHandlePanelState state)
|
2008-12-26 13:11:04 +00:00
|
|
|
{
|
|
|
|
uiHandlePanelData *data= pa->activedata;
|
|
|
|
wmWindow *win= CTX_wm_window(C);
|
|
|
|
ARegion *ar= CTX_wm_region(C);
|
2009-04-08 16:51:35 +00:00
|
|
|
|
2008-12-26 13:11:04 +00:00
|
|
|
if(data && data->state == state)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if(state == PANEL_STATE_EXIT || state == PANEL_STATE_ANIMATION) {
|
|
|
|
if(data && data->state != PANEL_STATE_ANIMATION) {
|
2009-09-23 11:49:12 +00:00
|
|
|
/* XXX:
|
|
|
|
* - the panel tabbing function call below (test_add_new_tabs()) has been commented out
|
|
|
|
* "It is too easy to do by accident when reordering panels, is very hard to control and use, and has no real benefit." - BillRey
|
|
|
|
* Aligorith, 2009Sep
|
|
|
|
*/
|
|
|
|
//test_add_new_tabs(ar); // also copies locations of tabs in dragged panel
|
2008-12-26 13:11:04 +00:00
|
|
|
check_panel_overlap(ar, NULL); // clears
|
|
|
|
}
|
|
|
|
|
|
|
|
pa->flag &= ~PNL_SELECT;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
pa->flag |= PNL_SELECT;
|
|
|
|
|
|
|
|
if(data && data->animtimer) {
|
2009-10-20 13:58:53 +00:00
|
|
|
WM_event_remove_timer(CTX_wm_manager(C), win, data->animtimer);
|
2008-12-26 13:11:04 +00:00
|
|
|
data->animtimer= NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(state == PANEL_STATE_EXIT) {
|
|
|
|
MEM_freeN(data);
|
|
|
|
pa->activedata= NULL;
|
|
|
|
|
2009-09-18 12:43:36 +00:00
|
|
|
WM_event_remove_ui_handler(&win->modalhandlers, ui_handler_panel, ui_handler_remove_panel, pa);
|
2008-12-26 13:11:04 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
if(!data) {
|
|
|
|
data= MEM_callocN(sizeof(uiHandlePanelData), "uiHandlePanelData");
|
|
|
|
pa->activedata= data;
|
|
|
|
|
2009-09-18 12:43:36 +00:00
|
|
|
WM_event_add_ui_handler(C, &win->modalhandlers, ui_handler_panel, ui_handler_remove_panel, pa);
|
2008-12-26 13:11:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(ELEM(state, PANEL_STATE_ANIMATION, PANEL_STATE_DRAG))
|
2009-10-20 13:58:53 +00:00
|
|
|
data->animtimer= WM_event_add_timer(CTX_wm_manager(C), win, TIMER, ANIMATION_INTERVAL);
|
2008-12-26 13:11:04 +00:00
|
|
|
|
|
|
|
data->state= state;
|
|
|
|
data->startx= win->eventstate->x;
|
|
|
|
data->starty= win->eventstate->y;
|
|
|
|
data->startofsx= pa->ofsx;
|
|
|
|
data->startofsy= pa->ofsy;
|
|
|
|
data->startsizex= pa->sizex;
|
|
|
|
data->startsizey= pa->sizey;
|
|
|
|
data->starttime= PIL_check_seconds_timer();
|
|
|
|
}
|
|
|
|
|
|
|
|
ED_region_tag_redraw(ar);
|
|
|
|
|
|
|
|
/* XXX exception handling, 3d window preview panel */
|
|
|
|
/* if(block->drawextra==BIF_view3d_previewdraw)
|
|
|
|
BIF_view3d_previewrender_clear(curarea);*/
|
|
|
|
|
|
|
|
/* XXX exception handling, 3d window preview panel */
|
|
|
|
/* if(block->drawextra==BIF_view3d_previewdraw)
|
|
|
|
BIF_view3d_previewrender_signal(curarea, PR_DISPRECT);
|
|
|
|
else if(strcmp(block->name, "image_panel_preview")==0)
|
|
|
|
image_preview_event(2); */
|
|
|
|
}
|
|
|
|
|