[Bf-committers] Grab cursor

Peter den Bak bf-committers@blender.org
Sat, 7 Aug 2004 16:14:08 +0200


This is a multi-part message in MIME format.

------=_NextPart_000_001E_01C47C99.9151E380
Content-Type: text/plain;
	charset="us-ascii"
Content-Transfer-Encoding: quoted-printable

Hi,

Here is my contribution to the garb cursor discussion.
I created a separate function to handle the cursor movement called: void
transform_3d_cursor(void).

The reason for this is that the transform function is already very
complicated and fragile.
Another reason is that the cursor behaves different than an object and
therefore makes it hard to integrate the code into the transform =
function
because of al the exceptions you have to code.

A separate function also has the advantage of easy adding future
functionality, and it's easy to change the code that fires it.

For now you can fire it with SHIFT-LMB, but I will not take part in that
discussion ;-)

How it works:
It is basically a striped down version of the transform function. It has =
the
same functionality, but it is tailored down to serve the cursor. It
preserves the scene and leaves the objects selected. It also allows
XYZtransform and the numerical input behaves the same as in the =
transform
function.

I attached a patch, so just play with it, and if you like =
it.........commit
it.

Kind Regards,

Peter den Bak


------=_NextPart_000_001E_01C47C99.9151E380
Content-Type: application/octet-stream;
	name="cursor.diff"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
	filename="cursor.diff"

Index: include/BDR_editobject.h
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: =
/cvsroot/bf-blender/blender/source/blender/include/BDR_editobject.h,v
retrieving revision 1.11
diff -u -r1.11 BDR_editobject.h
--- include/BDR_editobject.h	8 Jul 2004 20:38:23 -0000	1.11
+++ include/BDR_editobject.h	7 Aug 2004 13:19:08 -0000
@@ -92,6 +92,7 @@
 int sphere_intersect_test(void);
 int my_clock(void);
 void transform(int mode);
+void transform_3d_cursor(void);
 void std_rmouse_transform(void (*xf_func)(int));
 void rightmouse_transform(void);
 void single_object_users(int flag);
Index: src/editobject.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /cvsroot/bf-blender/blender/source/blender/src/editobject.c,v
retrieving revision 1.102
diff -u -r1.102 editobject.c
--- src/editobject.c	27 Jul 2004 12:25:37 -0000	1.102
+++ src/editobject.c	7 Aug 2004 13:19:11 -0000
@@ -6110,6 +6110,366 @@
 	tottrans=3D 0;
 }
=20
+void transform_3d_cursor(void)
+{
+	short breakloop=3D0, xn, yn, xo, yo, val;
+	short mval[2];
+	char str[100];
+	int time, fast=3D0, firsttime=3D1, update=3D0, midtog=3D0, gridflag, =
axismode=3D0;
+	float *curs, oldcurs[3], oldval[3], dvec[3], d_dvec[3];
+	float vx[3] =3D {1,0,0}, vy[3] =3D {0,1,0}, vz[3] =3D {0,0,1}, =
imat[3][3];
+	unsigned short event=3D0;
+
+	/* variables for new typing mode */
+	float addvec[3] =3D {0,0,0}; // result
+	short ax =3D 0, del =3D 0, typemode =3D 0;
+	short pe[3] =3D {0,0,0}; // Determines if the period key has been =
pressed.
+	short mi[3] =3D {1,1,1}; // Determines whether or not the minus key =
has been pressed.
+
+	/* init */
+	d_dvec[0]=3D d_dvec[1]=3D d_dvec[2]=3D 0.0;
+	dvec[0]=3D dvec[1]=3D dvec[2]=3D 0.0;
+
+	curs=3D give_cursor();
+	VECCOPY(centre, curs);
+	VECCOPY(oldcurs, curs);
+
+	G.moving=3D 2; //needed to show X,Y,Z axis during XYZtrans
+
+	areawinset(curarea->win);
+
+	getmouseco_areawin(mval);
+	xn=3Dxo=3D mval[0];
+	yn=3Dyo=3D mval[1];
+
+	gridflag=3D U.flag;
+
+	/* go for it */
+	while(breakloop =3D=3D 0)
+	{
+		char gmode[10] =3D "";
+
+		getmouseco_areawin(mval);
+
+		if(mval[0]!=3Dxo || mval[1]!=3Dyo || firsttime) {
+			if(firsttime) {
+				oldval[0]=3D oldval[1]=3D oldval[2]=3D MAXFLOAT;
+				update =3D 1;
+			}
+			firsttime=3D 0;
+
+			if (axismode=3D=3DXTRANS) strcpy(gmode, "X Axis: ");
+			if (axismode=3D=3DYTRANS) strcpy(gmode, "Y Axis: ");
+			if (axismode=3D=3DZTRANS) strcpy(gmode, "Z Axis: ");
+
+			window_to_3d(dvec, mval[0]-xn, mval[1]-yn);
+			if(axismode) {
+				if(axismode & XTRANS) dvec[1]=3Ddvec[2]=3D 0.0;
+				if(axismode & YTRANS) dvec[0]=3Ddvec[2]=3D 0.0;
+				if(axismode & ZTRANS) dvec[0]=3Ddvec[1]=3D 0.0;
+			}
+
+			if (typemode){
+				dvec[0] =3D addvec[0];
+				dvec[1] =3D addvec[1];
+				dvec[2] =3D addvec[2];
+				if(axismode =3D=3D XTRANS) dvec[1]=3Ddvec[2]=3D 0.0;
+				if(axismode =3D=3D YTRANS) dvec[0]=3Ddvec[2]=3D 0.0;
+				if(axismode =3D=3D ZTRANS) dvec[0]=3Ddvec[1]=3D 0.0;
+			}
+
+			/* grids */
+			if(G.qual & LR_SHIFTKEY) {
+				dvec[0]=3D 0.1*(dvec[0]-d_dvec[0])+d_dvec[0];
+				dvec[1]=3D 0.1*(dvec[1]-d_dvec[1])+d_dvec[1];
+				dvec[2]=3D 0.1*(dvec[2]-d_dvec[2])+d_dvec[2];
+			}
+			apply_keyb_grid(dvec, 0.0, G.vd->grid, 0.1*G.vd->grid, gridflag & =
USER_AUTOGRABGRID);
+			apply_keyb_grid(dvec+1, 0.0, G.vd->grid, 0.1*G.vd->grid, gridflag & =
USER_AUTOGRABGRID);
+			apply_keyb_grid(dvec+2, 0.0, G.vd->grid, 0.1*G.vd->grid, gridflag & =
USER_AUTOGRABGRID);
+
+			if(dvec[0]!=3Doldval[0] ||dvec[1]!=3Doldval[1] =
||dvec[2]!=3Doldval[2] || update) {
+				VECCOPY(oldval, dvec);
+				update =3D 0;
+
+				/* apply */
+				VecAddf(curs, oldcurs, dvec);  =20
+
+				if (typemode){
+					switch (ax){
+					case 0:
+						sprintf(str, "%sDx: >%.4f<   Dy: %.4f  Dz: %.4f", gmode, dvec[0], =
dvec[1], dvec[2]);
+						break;
+					case 1:
+						sprintf(str, "%sDx: %.4f   Dy: >%.4f<  Dz: %.4f", gmode, dvec[0], =
dvec[1], dvec[2]);
+						break;
+					case 2:
+						sprintf(str, "%sDx: %.4f   Dy: %.4f  Dz: >%.4f<", gmode, dvec[0], =
dvec[1], dvec[2]);
+					}
+				}
+				else
+					sprintf(str, "%sDx: %.4f   Dy: %.4f  Dz: %.4f", gmode, dvec[0], =
dvec[1], dvec[2]);
+
+				headerprint(str);
+				time=3D my_clock();
+
+				//needed to show X,Y,Z axis during XYZtrans
+				set_constline_callback('g', axismode, midtog, centre, imat, vx, vy, =
vz);
+
+				if(fast=3D=3D0) {
+					force_draw();
+					time=3D my_clock()-time;
+					if(time>50) fast=3D 1;
+				}
+				else {
+					scrarea_do_windraw(curarea);
+					screen_swapbuffers();
+				}
+			}
+		}
+
+		while( qtest() ) {
+			float add_num =3D 0; // numerical value to be added
+
+			event=3D extern_qread(&val);
+
+			if(val) {
+				switch(event) {
+				case ESCKEY:
+				case LEFTMOUSE:
+				case RIGHTMOUSE:
+				case SPACEKEY:
+				case PADENTER:
+				case RETKEY:
+					breakloop=3D 1;
+					break;
+
+				case MIDDLEMOUSE:
+					midtog=3D ~midtog;
+					if(midtog) {
+						int proj;
+
+						proj=3D test_midtog_proj(xn, yn, mval);
+						if (proj=3D=3D0)
+							axismode=3D XTRANS;
+						if (proj=3D=3D1)
+							axismode=3D YTRANS;
+						if (proj=3D=3D2)
+							axismode=3D ZTRANS;
+					}
+					else
+						axismode =3D 0;
+
+					firsttime=3D 1;
+					break;
+
+				case XKEY:
+					if (axismode=3D=3DXTRANS)
+						axismode=3D 0;
+					else {
+						axismode=3D XTRANS;
+						ax=3D 0;
+					}
+					firsttime=3D 1;
+					break;
+
+				case YKEY:
+					if (axismode=3D=3DYTRANS)
+						axismode=3D 0;
+					else {
+						axismode=3D YTRANS;
+						ax=3D 1;
+					}
+					firsttime=3D 1;
+					break;
+
+				case ZKEY:
+					if (axismode=3D=3DZTRANS)
+						axismode=3D 0;
+					else {
+						axismode=3D ZTRANS;
+						ax=3D 2;
+					}
+					firsttime=3D 1;
+					break;
+
+				case WHEELDOWNMOUSE:
+				case PADPLUSKEY:
+					if(G.f & G_PROPORTIONAL) {
+						prop_size*=3D 1.1;
+						firsttime=3D 1;
+					}
+					else {
+						if(event =3D=3D WHEELDOWNMOUSE)
+							view_editmove(event);
+						else
+							persptoetsen(PADPLUSKEY);
+							firsttime=3D 1;
+					}
+					break;
+
+				case WHEELUPMOUSE:
+				case PADMINUS:
+					if(G.f & G_PROPORTIONAL) {
+						prop_size*=3D 0.90909090;
+						firsttime=3D 1;
+					}
+					else {
+						if(event =3D=3D WHEELUPMOUSE)
+							view_editmove(event);
+						else
+						  persptoetsen(PADMINUS);
+					  firsttime=3D 1;
+					}
+					break;
+
+				case LEFTSHIFTKEY:
+				case RIGHTSHIFTKEY:
+					VECCOPY(d_dvec, dvec);
+				case LEFTCTRLKEY:
+				case RIGHTCTRLKEY:
+					firsttime=3D 1;
+					break;
+
+				case NKEY:
+					{
+						// toggle between typemode =3D 0 and typemode =3D 1
+						typemode *=3D -1;
+						typemode +=3D 1;
+						firsttime =3D 1;
+					}
+					break;
+
+				case BACKSPACEKEY:
+					{
+						if (typemode){
+							if (del =3D=3D 1){
+								addvec[0]=3Daddvec[1]=3Daddvec[2]=3D0;
+								pe[0]=3Dpe[1]=3Dpe[2]=3D0;
+								mi[0]=3Dmi[1]=3Dmi[2]=3D1;
+								del =3D 0;
+							}
+							else{
+								addvec[ax] =3D 0;
+								pe[ax]=3D0;
+								mi[ax]=3D1;
+								del =3D 1;
+							}
+						}
+						else{
+							getmouseco_areawin(mval);
+							xn=3Dxo=3D mval[0];
+							yn=3Dxo=3D mval[1];
+						}
+
+						firsttime=3D 1;
+						break;
+					}
+				case PERIODKEY:
+				case PADPERIOD:
+					{
+						typemode=3D 1;
+						del=3D 0;
+						if (pe[ax]=3D=3D0) pe[ax]=3D 1;
+					=09
+						firsttime=3D 1;
+						break;
+					}
+				case MINUSKEY:
+					{
+						del =3D 0;
+						addvec[ax] *=3D -1;
+						mi[ax] *=3D -1;
+
+						firsttime =3D 1;
+						break;
+					}
+				case TABKEY:
+					{
+						typemode=3D 1;
+						del =3D 0;
+						ax +=3D 1;
+						if (ax =3D=3D 3) ax =3D 0;
+
+						firsttime=3D 1;
+						break;
+					}
+				case PAD9:
+				case NINEKEY:
+					{add_num +=3D 1;}
+				case PAD8:
+				case EIGHTKEY:
+					{add_num +=3D 1;}
+				case PAD7:
+				case SEVENKEY:
+					{add_num +=3D 1;}
+				case PAD6:
+				case SIXKEY:
+					{add_num +=3D 1;}
+				case PAD5:
+				case FIVEKEY:
+					{add_num +=3D 1;}
+				case PAD4:
+				case FOURKEY:
+					{add_num +=3D 1;}
+				case PAD3:
+				case THREEKEY:
+					{add_num +=3D 1;}
+				case PAD2:
+				case TWOKEY:
+					{add_num +=3D 1;}
+				case PAD1:
+				case ONEKEY:
+					{add_num +=3D 1;}
+				case PAD0:
+				case ZEROKEY:
+					{
+						typemode =3D 1;
+						del =3D 0;
+						if (axismode & XTRANS)
+								ax =3D 0;
+						if (axismode & YTRANS)
+								ax =3D 1;
+						if (axismode & ZTRANS)
+								ax =3D 2;
+						if (pe[ax]){
+							int div =3D 1;
+							int i;
+							for (i =3D 0; i < pe[ax]; i++){div*=3D10;}
+							addvec[ax] +=3D mi[ax] * add_num / div;
+							pe[ax]+=3D1;
+						}
+						else{
+							addvec[ax] *=3D 10;
+							addvec[ax] +=3D mi[ax] * add_num;
+						}
+						firsttime=3D1;
+					}
+					break;
+				} // end switch
+
+				arrows_move_cursor(event);
+			} // end if val
+
+			if(event=3D=3D0 || breakloop) break;
+		} // end while qtest
+
+		xo=3D mval[0];
+		yo=3D mval[1];
+
+		if( qtest()=3D=3D0) PIL_sleep_ms(10);
+	} // end while mainloop
+
+	G.moving=3D 0;
+
+	if(event=3D=3DESCKEY || event=3D=3DRIGHTMOUSE) {
+		VECCOPY(curs, centre); //undo changes
+	}
+
+	allqueue(REDRAWVIEW3D, 0);
+	scrarea_queue_headredraw(curarea);
+}
+
 void std_rmouse_transform(void (*xf_func)(int))
 {
 	short mval[2];
Index: src/space.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /cvsroot/bf-blender/blender/source/blender/src/space.c,v
retrieving revision 1.163
diff -u -r1.163 space.c
--- src/space.c	5 Aug 2004 10:54:00 -0000	1.163
+++ src/space.c	7 Aug 2004 13:19:13 -0000
@@ -782,7 +782,11 @@
 			 */
 			case LEFTMOUSE:=20
 				if ((G.obedit) || =
!(G.f&(G_VERTEXPAINT|G_WEIGHTPAINT|G_TEXTUREPAINT))) {
-					mouse_cursor();
+					if(G.qual=3D=3DLR_SHIFTKEY)
+						transform_3d_cursor();
+					else
+						mouse_cursor();
+
 				} else if (G.f & G_VERTEXPAINT) {
 					vertex_paint();
 				}


------=_NextPart_000_001E_01C47C99.9151E380--