[Bf-committers] New circle select callback executer
joeedh
joeeagar at prodigy.net
Sun Apr 24 09:07:49 CEST 2005
Hi, I've noticed that the current circle select callback
executer-function is. . . bad. More specifically, its vulnerable to
overloads in the event queue. You select, and if you declick the mouse
it will still select or a few moments afterward.
As such, I've rewritten it into a fixed-time system, that seems to work
much, much better.
patch from inside the blender/ base dir (not below it, and not
source/blender).
joeedh
-------------- next part --------------
Index: source/blender/src/edit.c
===================================================================
RCS file: /cvsroot/bf-blender/blender/source/blender/src/edit.c,v
retrieving revision 1.62
diff -u -r1.62 edit.c
--- source/blender/src/edit.c 12 Apr 2005 11:53:46 -0000 1.62
+++ source/blender/src/edit.c 24 Apr 2005 06:54:02 -0000
@@ -390,16 +390,17 @@
* but the selection actions are defined by a callback, making
* it (hopefully) reusable for other windows than the 3D view.
*/
-
+#include "time.h"
void circle_selectCB(select_CBfunc callback)
{
static float rad= 40.0;
float rado;
int firsttime=1;
+ double stime, ttime;
unsigned short event;
short mvalo[2], mval[2], val;
- short selecting=0;
Object *obj;
+ short selecting=0, die=0;
if(G.obedit) obj = G.obedit;
else obj = OBACT;
@@ -412,66 +413,61 @@
draw_sel_circle(mval, NULL, rad, 0.0, selecting); // draws frontbuffer, but sets backbuf again
rado= rad;
+ /*clear event queue*/
+ while (qtest()) {
+ event = extern_qread(&val);
+ }
- while(TRUE) {
-
- if(mval[0]!=mvalo[0] || mval[1]!=mvalo[1] || rado!=rad || firsttime) {
- firsttime= 0;
+ /*enter time-controlled loop*/
+ stime = (float)clock() / CLOCKS_PER_SEC;
+ ttime = stime;
+ while (!die) { /*we break-out of the loop*/
+ if (stime-ttime > 0.009) {
+ getmouseco_areawin(mval);
+ if(mval[0]!=mvalo[0] || mval[1]!=mvalo[1] || rado!=rad || firsttime) {
+ firsttime= 0;
- if(selecting) {
- callback(selecting, obj, mval, rad);
- }
+ if(selecting) {
+ callback(selecting, obj, mval, rad);
+ }
- draw_sel_circle(mval, mvalo, rad, rado, selecting);
-
- mvalo[0]= mval[0];
- mvalo[1]= mval[1];
- rado= rad;
-
- }
+ draw_sel_circle(mval, mvalo, rad, rado, selecting);
- event= extern_qread(&val);
- if (event) {
- int afbreek= 0;
+ mvalo[0]= mval[0];
+ mvalo[1]= mval[1];
+ rado= rad;
- /* for when another window is open and a mouse cursor activates it */
- if(event!=MOUSEY && event!=MOUSEX) mywinset(curarea->win);
-
- getmouseco_areawin(mval); // important to do here, trust events!
-
- switch(event) {
+ }
+ while (qtest()) {
+ event = extern_qread(&val);
+ ttime = (float)clock() / CLOCKS_PER_SEC;
+ switch (event) {
+ case LEFTMOUSE:
+ case MIDDLEMOUSE:
+ if (val) selecting = event;
+ else selecting = 0;
+ break;
+ case WHEELDOWNMOUSE:
+ case PADPLUSKEY:
+ case EQUALKEY:
+ if(val) if(rad<200.0) rad*= 1.2;
+ break;
+ case WHEELUPMOUSE:
+ case PADMINUS:
+ case MINUSKEY:
+ if(val) if(rad>5.0) rad/= 1.2;
+ break;
+
+ case ESCKEY: case SPACEKEY: case RIGHTMOUSE: case INPUTCHANGE:
+ case GKEY: case SKEY: case RKEY: case XKEY: case EKEY: case TABKEY:
+ die= 1;
+ break;
- case LEFTMOUSE:
- case MIDDLEMOUSE:
- if(val) selecting= event;
- else selecting= 0;
- firsttime= 1;
-
- break;
- case WHEELDOWNMOUSE:
- case PADPLUSKEY:
- case EQUALKEY:
- if(val) if(rad<200.0) rad*= 1.2;
- break;
- case WHEELUPMOUSE:
- case PADMINUS:
- case MINUSKEY:
- if(val) if(rad>5.0) rad/= 1.2;
- break;
-
- case ESCKEY: case SPACEKEY: case RIGHTMOUSE: case INPUTCHANGE:
- case GKEY: case SKEY: case RKEY: case XKEY: case EKEY: case TABKEY:
- afbreek= 1;
- break;
-
+ }
}
-
- if(afbreek) break;
}
- else PIL_sleep_ms(10);
+ stime = (float)clock() / CLOCKS_PER_SEC;
}
-
- /* clear circle */
draw_sel_circle(NULL, mvalo, 0, rad, 1);
BIF_undo_push("Circle Select");
countall();
More information about the Bf-committers
mailing list