Patch #3365, Toolbox from Tuhopuu

Patch prvovided by Guillermo, code was - afaik - from Rob Haarsma.

This changes the toolbox (space menu) to have the first level aligned
vertically. Works much easier that way, and since the items open either
left or right, it doesn't flip order of the contents for it either.

To allow people to test (and to compare) it's a user menu setting (in
View & Controls, "Plain menus"). I've turned this on by default though,
since I propose to not have it a user setting. User setting can be
removed later.

Fixed two bugs in patch:
- if saved in user settings, first time usage of this toolbox opened in
  wrong location
- Button for "plain menus" was writing a short in an int
  (causing this new menu not to work for big endian systems)

As a bonus I've added the long wanted hotkey support for opening and
closing sublevels of pulldowns with arrow keys!

I didn't add the commenting out of correcting pulldown menu order, which
is based on location of the originating button in the UI. This uncommenting
didn't solve anything, since button definitions itself can be flipped too.
(Example: the data brose menus in top bar need to be corrected).

I can imagine the order flipping is sometimes annoying, but it still has
reasons to be there;
- the most important / most used items are always closest to the mouse.
  (like opening properties panel, or "Add new" for material.
- it follows muscle memory and 'locus of attention' (mouse position).
- menus are configured to open to the top for bottom headers, and to the
  bottom for top headers. We can expect the UI is configured consistantly
  for headers, so in general the menus will appear consistant as well.

Where menu flipping fails is especially for alphabetic listings, like in
the menu button of fileselect. However, that one should be configured to
open by default to the bottom, so ordering is consistant as well.

If people like to check this themselves; uncomment the lines in the top
of the function uiBlockFlipOrder() in src/interface.c
This commit is contained in:
2005-11-19 15:16:34 +00:00
parent 555a3d02c7
commit ca320003f4
10 changed files with 335 additions and 125 deletions

View File

@@ -109,6 +109,7 @@ void toolbox (void);
void toolbox_n(void);
void toolbox_n_add(void);
void reset_toolbox(void);
void notice (char *str, ...);
void error (char *fmt, ...);

View File

@@ -162,7 +162,7 @@
#define B_REDRCURW3D 63
#define B_FLIPINFOMENU 64
#define B_FLIPFULLSCREEN 65
#define B_EASYTOOLBOX 66
#define B_PLAINMENUS 66
#define B_SHOWSPLASH 70

View File

@@ -186,6 +186,7 @@ struct uiBlock {
short autofill, win, winq, direction, dt;
short needflush, auto_open, in_use, pad; //flush see below
void *overdraw;
struct uiBlock *parent; // nested pulldowns
float xofs, yofs; // offset to parent button
rctf parentrct; // for pulldowns, rect the mouse is allowed outside of menu (parent button)

View File

@@ -197,7 +197,7 @@ extern UserDef U; /* from usiblender.c !!!! */
#define USER_WHEELZOOMDIR 4
#define USER_FILTERFILEEXTS 8
#define USER_DRAWVIEWINFO 16
#define USER_EVTTOCONSOLE 32 // print ghost events, here for tuhopuu compat. --phase
#define USER_PLAINMENUS 32 // old EVTTOCONSOLE print ghost events, here for tuhopuu compat. --phase
// old flag for hide pulldown was here
#define USER_FLIPFULLSCREEN 128
#define USER_ALLWINCODECS 256

View File

@@ -1135,13 +1135,9 @@ void transform_nlachannel_keys(int mode, int dummy)
DAG_scene_flush_update(G.scene, screen_view3d_layers());
allqueue (REDRAWVIEW3D, 0);
allqueue (REDRAWNLA, 0);
allqueue (REDRAWIPO, 0);
force_draw_all(0);
}
else {
addqueue (curarea->win, REDRAWALL, 0);
force_draw(0);
}
}

View File

@@ -1333,6 +1333,10 @@ void do_global_buttons(unsigned short event)
allqueue(REDRAWVIEW3D, 0);
break;
case B_PLAINMENUS: /* is button from space.c *info* */
reset_toolbox();
break;
case B_FLIPINFOMENU: /* is button from space.c *info* */
scrarea_queue_headredraw(curarea);
break;

View File

@@ -934,8 +934,6 @@ void uiDrawBlock(uiBlock *block)
if(testmouse && uibut_contains_pt(but, mouse))
but->flag |= UI_ACTIVE;
else
but->flag &= ~UI_ACTIVE;
ui_draw_but(but);
}
@@ -1241,7 +1239,49 @@ static int ui_do_but_MENU(uiBut *but)
return -1;
}
/* ********************** NEXT/PREV for arrowkeys etc ************** */
static uiBut *ui_but_prev(uiBut *but)
{
while(but->prev) {
but= but->prev;
if(but->type!=LABEL && but->type!=SEPR && but->type!=ROUNDBOX) return but;
}
return NULL;
}
static uiBut *ui_but_next(uiBut *but)
{
while(but->next) {
but= but->next;
if(but->type!=LABEL && but->type!=SEPR && but->type!=ROUNDBOX) return but;
}
return NULL;
}
static uiBut *ui_but_first(uiBlock *block)
{
uiBut *but;
but= block->buttons.first;
while(but) {
if(but->type!=LABEL && but->type!=SEPR && but->type!=ROUNDBOX) return but;
but= but->next;
}
return NULL;
}
static uiBut *ui_but_last(uiBlock *block)
{
uiBut *but;
but= block->buttons.last;
while(but) {
if(but->type!=LABEL && but->type!=SEPR && but->type!=ROUNDBOX) return but;
but= but->prev;
}
return NULL;
}
/* ************* EVENTS ************* */
@@ -2168,7 +2208,8 @@ static int ui_do_but_NUMSLI(uiBut *but)
return but->retval;
}
static int ui_do_but_BLOCK(uiBut *but)
/* event denotes if we make first item active or not */
static int ui_do_but_BLOCK(uiBut *but, int event)
{
uiBlock *block;
uiBut *bt;
@@ -2177,6 +2218,7 @@ static int ui_do_but_BLOCK(uiBut *but)
ui_draw_but(but);
block= but->block_func(but->poin);
block->parent= but->block; /* allows checking for nested pulldowns */
block->xofs = -2; /* for proper alignment */
@@ -2200,6 +2242,11 @@ static int ui_do_but_BLOCK(uiBut *but)
/* postpone draw, this will cause a new window matrix, first finish all other buttons */
block->flag |= UI_BLOCK_REDRAW;
if(event!=MOUSEX && event!=MOUSEY && event!=LEFTMOUSE && but->type==BLOCK) {
bt= ui_but_first(block);
if(bt) bt->flag |= UI_ACTIVE;
}
but->flag &= ~UI_SELECT;
uibut_do_func(but);
@@ -2869,50 +2916,6 @@ void uiClearButLock()
UIlockstr= NULL;
}
/* ********************** NEXT/PREV for arrowkeys etc ************** */
static uiBut *ui_but_prev(uiBut *but)
{
while(but->prev) {
but= but->prev;
if(but->type!=LABEL && but->type!=SEPR && but->type!=ROUNDBOX) return but;
}
return NULL;
}
static uiBut *ui_but_next(uiBut *but)
{
while(but->next) {
but= but->next;
if(but->type!=LABEL && but->type!=SEPR && but->type!=ROUNDBOX) return but;
}
return NULL;
}
static uiBut *ui_but_first(uiBlock *block)
{
uiBut *but;
but= block->buttons.first;
while(but) {
if(but->type!=LABEL && but->type!=SEPR && but->type!=ROUNDBOX) return but;
but= but->next;
}
return NULL;
}
static uiBut *ui_but_last(uiBlock *block)
{
uiBut *but;
but= block->buttons.last;
while(but) {
if(but->type!=LABEL && but->type!=SEPR && but->type!=ROUNDBOX) return but;
but= but->prev;
}
return NULL;
}
/* *************************************************************** */
static void setup_file(uiBlock *block)
@@ -3071,7 +3074,7 @@ static int ui_do_button(uiBlock *block, uiBut *but, uiEvent *uevent)
case BLOCK:
case PULLDOWN:
if(uevent->val) {
retval= ui_do_but_BLOCK(but);
retval= ui_do_but_BLOCK(but, uevent->event);
if(block->auto_open==0) block->auto_open= 1;
}
break;
@@ -3412,8 +3415,32 @@ static int ui_do_block(uiBlock *block, uiEvent *uevent)
}
switch(uevent->event) {
case LEFTARROWKEY: // later on implement opening/closing sublevels of pupmenus
case RIGHTARROWKEY:
case LEFTARROWKEY: /* closing sublevels of pulldowns */
if(uevent->val && (block->flag & UI_BLOCK_LOOP) && block->parent) {
return UI_RETURN_OUT;
}
break;
case RIGHTARROWKEY: /* opening sublevels of pulldowns */
if(uevent->val && (block->flag & UI_BLOCK_LOOP)) {
for(but= block->buttons.first; but; but= but->next) {
if(but->flag & UI_ACTIVE) {
if(but->type==BLOCK) {
but->flag &= ~UI_MOUSE_OVER;
uevent->event= BUT_ACTIVATE;
}
break;
}
}
if(but==NULL) { /* no item active, we make first active */
if(block->direction & UI_TOP) but= ui_but_last(block);
else but= ui_but_first(block);
if(but) {
but->flag |= UI_ACTIVE;
ui_draw_but(but);
}
}
}
break;
case PAD8: case PAD2:
@@ -3734,6 +3761,7 @@ static int ui_do_block(uiBlock *block, uiEvent *uevent)
if(uevent->val && (uevent->event==XKEY || uevent->event==DELKEY))
ui_delete_active_linkline(block);
/* here we check return conditions for menus */
if(block->flag & UI_BLOCK_LOOP) {
if(inside==0 && uevent->val==1) {
@@ -3749,8 +3777,20 @@ static int ui_do_block(uiBlock *block, uiEvent *uevent)
/* check outside */
if(inside==0) {
uiBlock *tblock= NULL;
/* check for all parent rects, enables arrowkeys to be used */
if(uevent->event!=MOUSEX && uevent->event!=MOUSEY) {
for(tblock=block->parent; tblock; tblock= tblock->parent) {
if( BLI_in_rctf(&tblock->parentrct, (float)uevent->mval[0], (float)uevent->mval[1]))
break;
else if( BLI_in_rctf(&tblock->safety, (float)uevent->mval[0], (float)uevent->mval[1]))
break;
}
}
/* strict check, and include the parent rect */
if( BLI_in_rctf(&block->parentrct, (float)uevent->mval[0], (float)uevent->mval[1]));
if(tblock);
else if( BLI_in_rctf(&block->parentrct, (float)uevent->mval[0], (float)uevent->mval[1]));
else if( ui_mouse_motion_towards_block(block, uevent));
else if( BLI_in_rctf(&block->safety, (float)uevent->mval[0], (float)uevent->mval[1]));
else return UI_RETURN_OUT;
@@ -5118,6 +5158,9 @@ void uiBlockFlipOrder(uiBlock *block)
uiBut *but, *next;
float centy, miny=10000, maxy= -10000;
// if(U.uiflag & USER_PLAINMENUS)
// return;
for(but= block->buttons.first; but; but= but->next) {
if(but->flag & UI_BUT_ALIGN) return;
if(but->y1 < miny) miny= but->y1;

View File

@@ -2441,6 +2441,10 @@ void drawinfospace(ScrArea *sa, void *spacedata)
#else
U.curssize=0; /*Small Cursor always for OS X for now */
#endif
uiDefButBitI(block, TOG, USER_PLAINMENUS, B_PLAINMENUS, "Plain menus",
(xpos+edgsp),y1,spref,buth,
&(U.uiflag), 0, 0, 0, 0,
"Use column layout for toolbox and do not flip contents in any menu");
uiBlockEndAlign(block);
uiDefBut(block, LABEL,0,"Menus:",

View File

@@ -84,15 +84,17 @@
#include "BIF_editlattice.h"
#include "BIF_editsima.h"
#include "BIF_editoops.h"
#include "BIF_editview.h"
#include "BIF_gl.h"
#include "BIF_graphics.h"
#include "BIF_imasel.h"
#include "BIF_mainqueue.h"
#include "BIF_interface.h"
#include "BIF_toolbox.h"
#include "BIF_mainqueue.h"
#include "BIF_mywindow.h"
#include "BIF_renderwin.h"
#include "BIF_screen.h"
#include "BIF_space.h"
#include "BIF_toolbox.h"
#include "BIF_tbcallback.h"
#include "BIF_transform.h"
@@ -2225,6 +2227,36 @@ static TBitem tb_empty[]= {
{ -1, "", 0, NULL}};
/* *************RENDER ********** */
static void tb_do_render(void *arg, int event){
switch(event)
{
case 1: /* set render border */
set_render_border();
break;
case 2: /* render */
BIF_do_render(0);
break;
case 3: /* render anim */
BIF_do_render(1);
break;
case 4: /* render anim */
if(G.scene->r.scemode & R_PASSEPARTOUT) G.scene->r.scemode &= ~R_PASSEPARTOUT;
else G.scene->r.scemode |= R_PASSEPARTOUT;
allqueue(REDRAWVIEW3D, 0);
break;
}
}
static TBitem tb_render[]= {
{ 0, "Passepartout", 4, NULL},
{ 0, "Set Border", 1, NULL},
{ 0, "SEPR", 0, NULL},
{ 0, "Render|F12", 2, NULL},
{ 0, "Anim", 3, NULL},
{ -1, "", 0, tb_do_render}};
static uiBlock *tb_makemenu(void *arg)
{
@@ -2265,12 +2297,15 @@ static uiBlock *tb_makemenu(void *arg)
uiTextBoundsBlock(block, 60);
/* direction is also set in the function that calls this */
if(U.uiflag & USER_PLAINMENUS)
uiBlockSetDirection(block, UI_RIGHT);
else
uiBlockSetDirection(block, UI_RIGHT|UI_CENTRE);
return block;
}
static int tb_mainx= 0, tb_mainy= -5;
static int tb_mainx= 1234, tb_mainy= 0;
static void store_main(void *arg1, void *arg2)
{
tb_mainx= (int)arg1;
@@ -2283,9 +2318,21 @@ void toolbox_n(void)
uiBut *but;
TBitem *menu1=NULL, *menu2=NULL, *menu3=NULL;
TBitem *menu4=NULL, *menu5=NULL, *menu6=NULL;
int dx;
TBitem *menu7=NULL;
int dx=0;
short event, mval[2], tot=0;
char *str1=NULL, *str2=NULL, *str3=NULL, *str4=NULL, *str5=NULL, *str6=NULL;
char *str1=NULL, *str2=NULL, *str3=NULL, *str4=NULL, *str5=NULL, *str6=NULL, *str7=NULL;
/* temporal too... when this flag is (was) saved, it should initialize OK */
if(tb_mainx==1234) {
if(U.uiflag & USER_PLAINMENUS) {
tb_mainx= -32;
tb_mainy= -5;
} else {
tb_mainx= 0;
tb_mainy= -5;
}
}
mywinset(G.curscreen->mainwin); // we go to screenspace
@@ -2293,11 +2340,27 @@ void toolbox_n(void)
uiBlockSetFlag(block, UI_BLOCK_LOOP|UI_BLOCK_REDRAW|UI_BLOCK_RET_1);
uiBlockSetCol(block, TH_MENU_ITEM);
dx= 64;
/* select context for main items */
if(curarea->spacetype==SPACE_VIEW3D) {
/* standard menu */
if(U.uiflag & USER_PLAINMENUS) {
/* column layout menu */
if (G.scene->r.renderer==R_YAFRAY) {
menu1= tb_add_YF; str1= "Add";
} else {
menu1= tb_add; str1= "Add";
}
menu2= tb_object_edit; str2= "Edit";
menu3= tb_object_select; str3= "Select";
menu4= tb_transform; str4= "Transform";
menu5= tb_object; str5= "Object";
menu6= tb_view; str6= "View";
menu7= tb_render; str7= "Render";
dx= 96;
tot= 7;
} else {
/* 3x2 layout menu */
menu1= tb_object; str1= "Object";
if (G.scene->r.renderer==R_YAFRAY) {
menu2= tb_add_YF; str2= "Add";
@@ -2309,7 +2372,57 @@ void toolbox_n(void)
menu5= tb_transform; str5= "Transform";
menu6= tb_view; str6= "View";
dx= 64;
tot= 6;
}
if(G.obedit) {
if(U.uiflag & USER_PLAINMENUS) {
switch(G.obedit->type){
case OB_MESH:
menu1= addmenu_mesh;
menu2= tb_mesh_edit;
menu3= tb_mesh_select;
menu4= tb_transform_editmode1;
menu5= tb_mesh; str5= "Mesh";
break;
case OB_CURVE:
menu1= addmenu_curve;
menu2= tb_curve_edit;
menu3= tb_curve_select;
menu4= tb_transform_editmode1;
menu5= tb_curve; str5= "Curve";
break;
case OB_SURF:
menu1= addmenu_surf;
menu2= tb_curve_edit;
menu3= tb_curve_select;
menu4= tb_transform_editmode1;
menu5= tb_curve; str5= "Surface";
break;
case OB_MBALL:
menu1= addmenu_meta;
menu2= tb_edit;
menu3= tb__select;
menu4= tb_transform_editmode2;
menu5= tb_obdata; str5= "Meta";
break;
case OB_ARMATURE:
menu1= addmenu_armature;
menu2= tb_edit;
menu3= tb__select;
menu4= tb_transform_editmode2;
menu5= tb_obdata;str5= "Armature";
break;
case OB_LATTICE:
menu1= tb_empty;
menu2= tb_edit;
menu3= tb__select;
menu4= tb_transform_editmode1;
menu5= tb_empty;str5= "Lattice";
break;
}
} else {
if(G.obedit->type==OB_MESH) {
menu1= tb_mesh; str1= "Mesh";
menu2= addmenu_mesh;
@@ -2352,11 +2465,10 @@ void toolbox_n(void)
menu4= tb_edit;
menu5= tb_transform_editmode1;
}
}
}
else {
}
tot= 6;
}
getmouseco_sc(mval);
@@ -2396,6 +2508,43 @@ void toolbox_n(void)
but=uiDefBlockBut(block, tb_makemenu, menu6, str6, mval[0]+(0.5*dx)+tb_mainx,mval[1]+tb_mainy-20, dx, 19, "");
uiButSetFlag(but, UI_MAKE_DOWN|UI_MAKE_LEFT);
uiButSetFunc(but, store_main, (void *)-dx, (void *)5);
} else if (tot==7) {
/* check if it fits, dubious */
if(mval[0]-0.25*dx+tb_mainx < 6) mval[0]= 6 + 0.25*dx -tb_mainx;
else if(mval[0]+0.25*dx+tb_mainx > G.curscreen->sizex-6)
mval[0]= G.curscreen->sizex-6-0.25*dx-tb_mainx;
if(mval[1]-20+tb_mainy < 6) mval[1]= 6+20 -tb_mainy;
else if(mval[1]+20+tb_mainy > G.curscreen->sizey-6)
mval[1]= G.curscreen->sizey-6-20-tb_mainy;
but=uiDefIconTextBlockBut(block, tb_makemenu, menu1, ICON_RIGHTARROW_THIN, str1, mval[0]+tb_mainx,mval[1]+tb_mainy, dx, 19, "");
uiButSetFlag(but, UI_MAKE_RIGHT);
uiButSetFunc(but, store_main, (void *)-32, (void *)-5);
but=uiDefIconTextBlockBut(block, tb_makemenu, menu2, ICON_RIGHTARROW_THIN, str2, mval[0]+tb_mainx,mval[1]+tb_mainy-20, dx, 19, "");
uiButSetFlag(but, UI_MAKE_RIGHT);
uiButSetFunc(but, store_main, (void *)-32, (void *)15);
but=uiDefIconTextBlockBut(block, tb_makemenu, menu3, ICON_RIGHTARROW_THIN, str3, mval[0]+tb_mainx,mval[1]+tb_mainy-40, dx, 19, "");
uiButSetFlag(but, UI_MAKE_RIGHT);
uiButSetFunc(but, store_main, (void *)-32, (void *)35);
but=uiDefIconTextBlockBut(block, tb_makemenu, menu4, ICON_RIGHTARROW_THIN, str4, mval[0]+tb_mainx,mval[1]+tb_mainy-60, dx, 19, "");
uiButSetFlag(but, UI_MAKE_RIGHT);
uiButSetFunc(but, store_main, (void *)-32, (void *)55);
but=uiDefIconTextBlockBut(block, tb_makemenu, menu5, ICON_RIGHTARROW_THIN, str5, mval[0]+tb_mainx,mval[1]+tb_mainy-80, dx, 19, "");
uiButSetFlag(but, UI_MAKE_RIGHT);
uiButSetFunc(but, store_main, (void *)-32, (void *)75);
but=uiDefIconTextBlockBut(block, tb_makemenu, menu6, ICON_RIGHTARROW_THIN, str6, mval[0]+tb_mainx,mval[1]+tb_mainy-100, dx, 19, "");
uiButSetFlag(but, UI_MAKE_RIGHT);
uiButSetFunc(but, store_main, (void *)-32, (void *)95);
but=uiDefIconTextBlockBut(block, tb_makemenu, menu7, ICON_RIGHTARROW_THIN, str7, mval[0]+tb_mainx,mval[1]+tb_mainy-120, dx, 19, "");
uiButSetFlag(but, UI_MAKE_RIGHT);
uiButSetFunc(but, store_main, (void *)-32, (void *)105);
}
uiBoundsBlock(block, 2);
@@ -2406,7 +2555,17 @@ void toolbox_n(void)
void toolbox_n_add(void)
{
tb_mainx= 0;
tb_mainy= -5;
reset_toolbox();
toolbox_n();
}
void reset_toolbox(void)
{
if(U.uiflag & USER_PLAINMENUS) {
tb_mainx= -32;
tb_mainy= -5;
} else {
tb_mainx= 0;
tb_mainy= -5;
}
}

View File

@@ -256,6 +256,8 @@ static void init_userdef_file(void)
/* Lamp theme, check for alpha==0 is safe, then color was never set */
if(btheme->tv3d.lamp[3]==0) {
SETCOL(btheme->tv3d.lamp, 0, 0, 0, 40);
/* TEMPORAL, remove me! (ton) */
U.uiflag |= USER_PLAINMENUS;
}
}
if(U.obcenter_dia==0) U.obcenter_dia= 6;