[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [16967] trunk/blender/source: * Joystick sensor is now only triggered from events of the selected type.

Campbell Barton ideasman42 at gmail.com
Wed Oct 8 05:16:21 CEST 2008


Revision: 16967
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=16967
Author:   campbellbarton
Date:     2008-10-08 05:16:19 +0200 (Wed, 08 Oct 2008)

Log Message:
-----------
* Joystick sensor is now only triggered from events of the selected type.
* Keyboard sensor - added (back?) support for qualifiers (Hold buttons in the UI)

Modified Paths:
--------------
    trunk/blender/source/blender/src/buttons_logic.c
    trunk/blender/source/gameengine/Converter/KX_ConvertSensors.cpp
    trunk/blender/source/gameengine/GameLogic/Joystick/SCA_Joystick.cpp
    trunk/blender/source/gameengine/GameLogic/Joystick/SCA_Joystick.h
    trunk/blender/source/gameengine/GameLogic/Joystick/SCA_JoystickEvents.cpp
    trunk/blender/source/gameengine/GameLogic/SCA_JoystickSensor.cpp
    trunk/blender/source/gameengine/GameLogic/SCA_KeyboardSensor.cpp

Modified: trunk/blender/source/blender/src/buttons_logic.c
===================================================================
--- trunk/blender/source/blender/src/buttons_logic.c	2008-10-08 01:04:07 UTC (rev 16966)
+++ trunk/blender/source/blender/src/buttons_logic.c	2008-10-08 03:16:19 UTC (rev 16967)
@@ -1204,42 +1204,44 @@
 		}
 	case SENS_KEYBOARD:
 		{
+			ks= sens->data;
+			
 			/* 5 lines: 120 height */
-			ysize= 120;
+			ysize= (ks->type&1) ? 96:120;
 			
 			glRects(xco, yco-ysize, xco+width, yco);
 			uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
 			
 			/* header line */
 			draw_default_sensor_header(sens, block, xco, yco, width);
-			ks= sens->data;
 			
-			/* line 2: hotkey and allkeys toggle */
-			uiDefKeyevtButS(block, B_DIFF, "", xco+40, yco-44, (width)/2, 19, &ks->key, "Key code");
-			
-			/* line 3: two key modifyers (qual1, qual2) */
-			uiDefKeyevtButS(block, B_DIFF, "", xco+40, yco-68, (width-50)/2, 19, &ks->qual, "Modifier key code");
-			uiDefKeyevtButS(block, B_DIFF, "", xco+40+(width-50)/2, yco-68, (width-50)/2, 19, &ks->qual2, "Second Modifier key code");
-			
-			/* labels for line 1 and 2 */
-			uiDefBut(block, LABEL, 0, "Key",	  xco, yco-44, 40, 19, NULL, 0, 0, 0, 0, "");
-			uiDefBut(block, LABEL, 0, "Hold",	  xco, yco-68, 40, 19, NULL, 0, 0, 0, 0, "");
-			
 			/* part of line 1 */
 			uiBlockSetCol(block, TH_BUT_SETTING2);
-			uiDefButBitS(block, TOG, 1, 0, "All keys",	  xco+40+(width/2), yco-44, (width/2)-50, 19,
+			uiDefBut(block, LABEL, 0, "Key",	  xco, yco-44, 40, 19, NULL, 0, 0, 0, 0, "");
+			uiDefButBitS(block, TOG, 1, B_REDR, "All keys",	  xco+40+(width/2), yco-44, (width/2)-50, 19,
 				&ks->type, 0, 0, 0, 0, "");
 			
+			
+			if ((ks->type&1)==0) { /* is All Keys option off? */
+				/* line 2: hotkey and allkeys toggle */
+				uiDefKeyevtButS(block, B_DIFF, "", xco+40, yco-44, (width)/2, 19, &ks->key, "Key code");
+				
+				/* line 3: two key modifyers (qual1, qual2) */
+				uiDefBut(block, LABEL, 0, "Hold",	  xco, yco-68, 40, 19, NULL, 0, 0, 0, 0, "");
+				uiDefKeyevtButS(block, B_DIFF, "", xco+40, yco-68, (width-50)/2, 19, &ks->qual, "Modifier key code");
+				uiDefKeyevtButS(block, B_DIFF, "", xco+40+(width-50)/2, yco-68, (width-50)/2, 19, &ks->qual2, "Second Modifier key code");
+			}
+			
 			/* line 4: toggle property for string logging mode */
 			uiDefBut(block, TEX, 1, "LogToggle: ",
-				xco+10, yco-92, (width-20), 19,
+				xco+10, yco-((ks->type&1) ? 68:92), (width-20), 19,
 				ks->toggleName, 0, 31, 0, 0,
 				"Property that indicates whether to log "
 				"keystrokes as a string.");
 			
 			/* line 5: target property for string logging mode */
 			uiDefBut(block, TEX, 1, "Target: ",
-				xco+10, yco-116, (width-20), 19,
+				xco+10, yco-((ks->type&1) ? 92:116), (width-20), 19,
 				ks->targetName, 0, 31, 0, 0,
 				"Property that receives the keystrokes in case "
 				"a string is logged.");
@@ -1456,13 +1458,27 @@
 				&joy->type, 0, 31, 0, 0,
 				"The type of event this joystick sensor is triggered on.");
 			
-			uiDefButBitS(block, TOG, SENS_JOY_ANY_EVENT, B_REDR,
-				(joy->flag & SENS_JOY_ANY_EVENT) ? "All Events" : "All",
-				xco+10 + 0.5 * (width-20), yco-68, ((joy->flag & SENS_JOY_ANY_EVENT) ? 0.5 : 0.098) * (width-20), 19,
+			if (joy->flag & SENS_JOY_ANY_EVENT) {
+				switch (joy->type) {
+				case SENS_JOY_AXIS:	
+					str = "All Axis Events";
+					break;
+				case SENS_JOY_BUTTON:	
+					str = "All Button Events";
+					break;
+				default:
+					str = "All Hat Events";
+					break;
+				}
+			} else {
+				str = "All";
+			}
+			
+			uiDefButBitS(block, TOG, SENS_JOY_ANY_EVENT, B_REDR, str,
+				xco+10 + 0.475 * (width-20), yco-68, ((joy->flag & SENS_JOY_ANY_EVENT) ? 0.525 : 0.12) * (width-20), 19,
 				&joy->flag, 0, 0, 0, 0,
-				"Trigger from all events of the current (axis/button/hat)");
+				"Triggered by all events on this joysticks current type (axis/button/hat)");
 			
-			
 			if(joy->type == SENS_JOY_BUTTON)
 			{
 				if ((joy->flag & SENS_JOY_ANY_EVENT)==0) {
@@ -1475,7 +1491,7 @@
 			{
 				uiDefButI(block, NUM, 1, "Number:", xco+10, yco-68, 0.46 * (width-20), 19,
 				&joy->axis, 1, 2.0, 100, 0,
-				"Specify which axis to use");
+				"Specify which axis pair to use, 1 is useually the main direction input.");
 
 				uiDefButI(block, NUM, 1, "Threshold:", xco+10 + 0.6 * (width-20),yco-44, 0.4 * (width-20), 19,
 				&joy->precision, 0, 32768.0, 100, 0,
@@ -1485,7 +1501,7 @@
 					str = "Type %t|Up Axis %x1 |Down Axis %x3|Left Axis %x2|Right Axis %x0"; 
 					uiDefButI(block, MENU, B_REDR, str, xco+10 + 0.6 * (width-20), yco-68, 0.4 * (width-20), 19,
 					&joy->axisf, 2.0, 31, 0, 0,
-					"The direction of the axis");
+					"The direction of the axis, use 'All Events' to recieve events on any direction");
 				}
 			}
 			else

Modified: trunk/blender/source/gameengine/Converter/KX_ConvertSensors.cpp
===================================================================
--- trunk/blender/source/gameengine/Converter/KX_ConvertSensors.cpp	2008-10-08 01:04:07 UTC (rev 16966)
+++ trunk/blender/source/gameengine/Converter/KX_ConvertSensors.cpp	2008-10-08 03:16:19 UTC (rev 16967)
@@ -433,8 +433,8 @@
 				{
 					gamesensor = new SCA_KeyboardSensor(eventmgr,
 						gReverseKeyTranslateTable[blenderkeybdsensor->key],
-						blenderkeybdsensor->qual,
-						blenderkeybdsensor->qual2,
+						gReverseKeyTranslateTable[blenderkeybdsensor->qual],
+						gReverseKeyTranslateTable[blenderkeybdsensor->qual2],
 						(blenderkeybdsensor->type == SENS_ALL_KEYS),
 						blenderkeybdsensor->targetName,
 						blenderkeybdsensor->toggleName,

Modified: trunk/blender/source/gameengine/GameLogic/Joystick/SCA_Joystick.cpp
===================================================================
--- trunk/blender/source/gameengine/GameLogic/Joystick/SCA_Joystick.cpp	2008-10-08 01:04:07 UTC (rev 16966)
+++ trunk/blender/source/gameengine/GameLogic/Joystick/SCA_Joystick.cpp	2008-10-08 03:16:19 UTC (rev 16967)
@@ -42,7 +42,9 @@
 	m_buttonnum(-2),
 	m_hatdir(-2),
 	m_isinit(0),
-	m_istrig(0),
+	m_istrig_axis(0),
+	m_istrig_button(0),
+	m_istrig_hat(0),
 	m_axismax(-1),
 	m_buttonmax(-1),
 	m_hatmax(-1)
@@ -310,13 +312,25 @@
 	return 0;
 }
 
-#define MAX2(x,y)               ( (x)>(y) ? (x) : (y) )
 int SCA_Joystick::pAxisTest(int axisnum)
 {
 #ifndef DISABLE_SDL
-	if(axisnum == 1)return MAX2(abs(m_axis10), abs(m_axis11));
-	if(axisnum == 2)return MAX2(abs(m_axis20), abs(m_axis21));
+	short i1,i2;
+	if(axisnum == 1) {
+		i1 = m_axis10;	i2 = m_axis11;
+	}
+	else if(axisnum == 2) {
+		i1 = m_axis20;	i2 = m_axis21;
+	}
+	/* long winded way to do
+	 *   return MAX2(abs(i1), abs(i2))
+	 * avoid abs from math.h */
+	if (i1 < 0) i1 = -i1;
+	if (i2 < 0) i2 = -i2;
+	if (i1 <i2) return i2;
+	else		return i1;
+#else
+	return 0;
 #endif
-	return 0;
 }
 

Modified: trunk/blender/source/gameengine/GameLogic/Joystick/SCA_Joystick.h
===================================================================
--- trunk/blender/source/gameengine/GameLogic/Joystick/SCA_Joystick.h	2008-10-08 01:04:07 UTC (rev 16966)
+++ trunk/blender/source/gameengine/GameLogic/Joystick/SCA_Joystick.h	2008-10-08 03:16:19 UTC (rev 16967)
@@ -90,7 +90,7 @@
 	int 			m_buttonmax;
 	int 			m_hatmax;
 	
-	 /* 
+	/*
 	 * hat values stored here 
 	 */
 	int 			m_hatnum;
@@ -106,8 +106,10 @@
 	bool			m_isinit;
 
 	
-	/* is triggered */
-	bool			m_istrig;
+	/* is triggered for each event type */
+	bool			m_istrig_axis;
+	bool			m_istrig_button;
+	bool			m_istrig_hat;
 
 #ifndef DISABLE_SDL
 	/*
@@ -212,9 +214,17 @@
 		return m_prec;
 	}
 
-	bool IsTrig(void){
-		return m_istrig;
+	bool IsTrigAxis(void){
+		return m_istrig_axis;
 	}
+	
+	bool IsTrigButton(void){
+		return m_istrig_button;
+	}
+	
+	bool IsTrigHat(void){
+		return m_istrig_hat;
+	}
 
 	/*
 	 * returns the # of...

Modified: trunk/blender/source/gameengine/GameLogic/Joystick/SCA_JoystickEvents.cpp
===================================================================
--- trunk/blender/source/gameengine/GameLogic/Joystick/SCA_JoystickEvents.cpp	2008-10-08 01:04:07 UTC (rev 16966)
+++ trunk/blender/source/gameengine/GameLogic/Joystick/SCA_JoystickEvents.cpp	2008-10-08 03:16:19 UTC (rev 16967)
@@ -38,7 +38,7 @@
 	pFillAxes();
 	m_axisnum	= sdl_event->jaxis.axis;
 	m_axisvalue = sdl_event->jaxis.value;
-	m_istrig = 1;
+	m_istrig_axis = 1;
 }
 
 
@@ -46,12 +46,12 @@
 {
 	m_hatdir = sdl_event->jhat.value;
 	m_hatnum = sdl_event->jhat.hat;
-	m_istrig = 1;
+	m_istrig_hat = 1;
 }
 
 void SCA_Joystick::OnButtonUp(SDL_Event* sdl_event)
 {
-	m_istrig = 1;
+	m_istrig_button = 1;
 	
 	/* this is needed for the "all events" option
 	 * so we know if there are no buttons pressed */
@@ -70,7 +70,7 @@
 {
 	if(sdl_event->jbutton.button >= 0 || sdl_event->jbutton.button <= m_buttonmax)
 	{
-		m_istrig = 1;
+		m_istrig_button = 1;
 		m_buttonnum = sdl_event->jbutton.button;
 	}
 }
@@ -78,7 +78,7 @@
 
 void SCA_Joystick::OnNothing(SDL_Event* sdl_event)
 {
-	m_istrig = 0;
+	m_istrig_axis = m_istrig_button = m_istrig_hat = 0;
 }
 
 /* only handle events for 1 joystick */

Modified: trunk/blender/source/gameengine/GameLogic/SCA_JoystickSensor.cpp
===================================================================
--- trunk/blender/source/gameengine/GameLogic/SCA_JoystickSensor.cpp	2008-10-08 01:04:07 UTC (rev 16966)
+++ trunk/blender/source/gameengine/GameLogic/SCA_JoystickSensor.cpp	2008-10-08 03:16:19 UTC (rev 16967)
@@ -110,9 +110,6 @@
 	if(js==NULL) /* no joystick - dont do anything */
 		return false;
 	
-	if (!js->IsTrig()) /* No events from SDL? - dont bother */
-		return reset ? true : false;
-	
 	m_reset = false;
 	switch(m_joymode)
 	{
@@ -125,6 +122,10 @@
 			m_axisf == 3 == down
 			numberof== m_axis  -- max 2
 			*/
+			
+			if (!js->IsTrigAxis()) /* No events from SDL? - dont bother */
+				return reset ? true : false;
+			
 			js->cSetPrecision(m_precision);
 			if (m_bAllEvents) {
 				if(js->aAnyAxisIsPositive(m_axis)){
@@ -188,6 +189,9 @@
 		/* what is what!
 			m_button = the actual button in question
 			*/
+			if (!js->IsTrigButton()) /* No events from SDL? - dont bother */
+				return reset ? true : false;
+			
 			if(( m_bAllEvents && js->aAnyButtonPressIsPositive()) || (!m_bAllEvents && js->aButtonPressIsPositive(m_button))) {
 				m_istrig = 1;
 				result = true;
@@ -205,6 +209,10 @@
 			numberof = m_hat  -- max 2
 			direction= m_hatf -- max 12
 			*/
+			
+			if (!js->IsTrigHat()) /* No events from SDL? - dont bother */
+				return reset ? true : false;
+			

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list