[Bf-python] Logical Window.GetMouseButtons()

Michael Schardt M.Schardt at web.de
Wed May 2 15:12:00 CEST 2007


Hello again,

I got no replies on my previous mail, but hopefully this time...
Window.GetMouseButtons() allways returns the physical button state. A option to respect the user preferences (Select with Right / Left mousebutton) might be nice.
Here's a modification to the Window.GetMouseButtons() - function. It now takes an optional argument if you want it to return not the physical but the logical button state. I made the argument optional so no existing scripts will break. The returned value is still compared against Window.MButs. 
In logical mode, Window.Mbuts.R refers to the Select button (Could be the physical left mousebutton if user changed preferences to "Select with: Left Mouse".
Any arguments against? If not, could anyone put it in? (i do not have CVS-access)

Michael

Here's the modification:

/*************/
/* prototype */
/*************/

static PyObject *M_Window_GetMouseButtons( PyObject * self, PyObject * args );


/**************/
/* doc string */
/**************/

...
static char M_Window_GetMouseButtons_doc[] =
 "(logical = 0) - Get the current mouse button state (see Blender.Window.MButs dict).\n\
(logical) - int: set to 1 for logical mouse buttons.\n\
                 logical buttons respect user settings in preferences - Window.MButs.R corresponds to Select button)";
...


/*****************************************************************/
/* Python method structure definition for Blender.Window module: */
/*****************************************************************/

...
 {"GetMouseButtons", ( PyCFunction ) M_Window_GetMouseButtons,
  METH_VARARGS,
...


/************/
/* Function */
/************/

static PyObject *M_Window_GetMouseButtons( PyObject * self, PyObject * args )
{
 short mbut = get_mbut(  );

 short logical = 0;
 if( !PyArg_ParseTuple( args, "|i", &logical ) )
  return EXPP_ReturnPyObjError( PyExc_TypeError,
           "expected nothing or an int as argument" );

 if ((logical) && (U.flag & USER_LMOUSESELECT)) {
  short L = (mbut & L_MOUSE) ? 1:0;
  short M = (mbut & M_MOUSE) ? 1:0;
  short R = (mbut & R_MOUSE) ? 1:0;
  mbut = L * R_MOUSE | M * M_MOUSE | R * L_MOUSE;
 }

 return Py_BuildValue( "h", mbut );
}

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.blender.org/pipermail/bf-python/attachments/20070502/98d42a24/attachment.html>


More information about the Bf-python mailing list