Nodes to be created at the location in which the mouse cursor was initially

This commit changes the way new nodes are created. Previously nodes were created
at the last location of the mouse cursor before creating a new node. After this
commit the nodes are created at the initial location in which the cursor was
before the menu used to add the node was opened.

This makes it possible for the user to predict where the new node appears without
having to move it to desired location like before. There is no option for this as
this behaviour is clearly superior to previous.

Codewise it uses static variables. This is something to fix during 2.50 rewrite.

Thanks to paprmh for contribution!
This commit is contained in:
Juho Vepsalainen 2008-02-23 10:33:36 +00:00
parent 14fafab60a
commit 206021113d
3 changed files with 28 additions and 1 deletions

@ -73,4 +73,6 @@ typedef struct TBitem {
} TBitem; } TBitem;
void toolbox_generic( struct TBitem *generic_menu ); /* for external toolbox - python only for now */ void toolbox_generic( struct TBitem *generic_menu ); /* for external toolbox - python only for now */
void toolbox_mousepos( short *mpos, int save ); /* saves/restores mouse position when entering/exiting menus */
#endif #endif

@ -216,7 +216,7 @@ void do_node_addmenu(void *arg, int event)
else node->flag &= ~NODE_TEST; else node->flag &= ~NODE_TEST;
} }
getmouseco_areawin(mval); toolbox_mousepos(mval, 0 ); /* get initial mouse position */
areamouseco_to_ipoco(G.v2d, mval, &locx, &locy); areamouseco_to_ipoco(G.v2d, mval, &locx, &locy);
node= node_add_node(snode, event, locx, locy); node= node_add_node(snode, event, locx, locy);

@ -1977,6 +1977,9 @@ void toolbox_n(void)
} }
} }
/* save present mouse position */
toolbox_mousepos(mval, 1);
mywinset(G.curscreen->mainwin); // we go to screenspace mywinset(G.curscreen->mainwin); // we go to screenspace
block= uiNewBlock(&tb_listb, "toolbox", UI_EMBOSSP, UI_HELV, G.curscreen->mainwin); block= uiNewBlock(&tb_listb, "toolbox", UI_EMBOSSP, UI_HELV, G.curscreen->mainwin);
@ -2307,3 +2310,25 @@ void toolbox_generic( TBitem *generic_menu )
mywinset(curarea->win); mywinset(curarea->win);
} }
/* save or restore mouse position when entering/exiting menus */
void toolbox_mousepos( short *mpos, int save )
{
static short initpos[2];
static int tog;
if (save) {
getmouseco_areawin(mpos);
initpos[0]= mpos[0];
initpos[1]= mpos[1];
tog=1;
} else {
if (tog) {
mpos[0]= initpos[0];
mpos[1]= initpos[1];
} else {
getmouseco_areawin(mpos);
}
tog= 0;
}
}