Added ability to get mouse button count or touch ID count.
[freeglut] / src / blackberry / fg_state_blackberry.c
index 600a826..f16aea6 100644 (file)
@@ -35,6 +35,9 @@
 //From fg_state_android.c
 int fgPlatformGlutDeviceGet ( GLenum eWhat )
 {
+    int deviceCount, i, value;
+    screen_device_t* devices;
+
     switch( eWhat )
     {
     case GLUT_HAS_KEYBOARD:
@@ -42,13 +45,36 @@ int fgPlatformGlutDeviceGet ( GLenum eWhat )
         return 1;
 
     case GLUT_HAS_MOUSE:
-        /* BlackBerry has a touchscreen; until we get proper touchscreen
-           support, consider it as a mouse. */
+        /* BlackBerry has a touchscreen. Consider it as a mouse since we have no guarantee
+           that a mouse will be used (in which case it's a simulator). */
         return 1 ;
 
     case GLUT_NUM_MOUSE_BUTTONS:
-        /* BlackBerry has a touchscreen; until we get proper touchscreen
-           support, consider it as a 1-button mouse. */
+        /* BlackBerry has a touchscreen, which we can consider a 1-button mouse at min.
+           Otherwise check for an actual mouse, else get max touch points */
+        if(!screen_get_context_property_iv(fgDisplay.pDisplay.screenContext, SCREEN_PROPERTY_DEVICE_COUNT, &deviceCount)) {
+            devices = (screen_device_t*)calloc(deviceCount, sizeof(screen_device_t));
+            if(!screen_get_context_property_pv(fgDisplay.pDisplay.screenContext, SCREEN_PROPERTY_DEVICES, (void**)devices)) {
+                /* Check for a pointer */
+                for(i = 0; i < deviceCount; i++) {
+                    if(!screen_get_device_property_iv(devices[i], SCREEN_PROPERTY_TYPE, &value) &&
+                            value == SCREEN_EVENT_POINTER &&
+                            !screen_get_device_property_iv(devices[i], SCREEN_PROPERTY_BUTTON_COUNT, &value)) {
+                        return value;
+                    }
+                }
+                /* Check for mtouch */
+                for(i = 0; i < deviceCount; i++) {
+                    if(!screen_get_device_property_iv(devices[i], SCREEN_PROPERTY_TYPE, &value) &&
+                            value == SCREEN_EVENT_MTOUCH_TOUCH &&
+                            !screen_get_device_property_iv(devices[i], SCREEN_PROPERTY_MAXIMUM_TOUCH_ID, &value)) {
+                        return value;
+                    }
+                }
+            }
+            free(devices);
+        }
+        /* Backup, pretend it's a 1-button mouse */
         return 1;
 
     default:
@@ -62,38 +88,39 @@ int fgPlatformGlutDeviceGet ( GLenum eWhat )
 
 int fgPlatformGlutGet ( GLenum eWhat )
 {
-  switch (eWhat) {
-  /* One full-screen window only */
-  case GLUT_WINDOW_X:
-  case GLUT_WINDOW_Y:
-  case GLUT_WINDOW_BORDER_WIDTH:
-  case GLUT_WINDOW_HEADER_HEIGHT:
-      return 0;
+    switch (eWhat) {
+    /* One full-screen window only */
+    case GLUT_WINDOW_X:
+    case GLUT_WINDOW_Y:
+    case GLUT_WINDOW_BORDER_WIDTH:
+    case GLUT_WINDOW_HEADER_HEIGHT:
+        return 0;
 
-  case GLUT_WINDOW_WIDTH:
-  case GLUT_WINDOW_HEIGHT:
+    case GLUT_WINDOW_WIDTH:
+    case GLUT_WINDOW_HEIGHT:
     {
-      if ( fgStructure.CurrentWindow == NULL )
-               return 0;
-      int size[2];
-      if ( screen_get_window_property_iv(fgStructure.CurrentWindow->Window.Handle, SCREEN_PROPERTY_SIZE, size) != 0 )
-       return 0;
-         switch ( eWhat )
-               {
-               case GLUT_WINDOW_WIDTH:
-                 return size[0];
-               case GLUT_WINDOW_HEIGHT:
-                 return size[1];
-               }
+        if ( fgStructure.CurrentWindow == NULL )
+            return 0;
+        int size[2];
+        if ( screen_get_window_property_iv(fgStructure.CurrentWindow->Window.Handle, SCREEN_PROPERTY_BUFFER_SIZE, size) != 0 )
+            return 0;
+        switch ( eWhat )
+        {
+        case GLUT_WINDOW_WIDTH:
+            return size[0];
+        case GLUT_WINDOW_HEIGHT:
+            return size[1];
+        }
+        break;
     }
 
-  case GLUT_WINDOW_COLORMAP_SIZE:
-      /* 0 for RGBA/non-indexed mode */
-      /* Under BlackBerry and GLES more generally, no indexed-mode */
-      return 0;
+    case GLUT_WINDOW_COLORMAP_SIZE:
+        /* 0 for RGBA/non-indexed mode */
+        /* Under BlackBerry and GLES more generally, no indexed-mode */
+        return 0;
 
-  default:
-    return fghPlatformGlutGetEGL(eWhat);
-  }
-  return -1;
+    default:
+        return fghPlatformGlutGetEGL(eWhat);
+    }
+    return -1;
 }