Removed fg_main_blackberry.h. It wasn't needed
[freeglut] / src / blackberry / fg_main_blackberry.c
index 82a2705..65b5954 100644 (file)
@@ -139,18 +139,25 @@ unsigned char key_ascii(int qnxKeycode)
   return qnxKeycode;
 }
 
-uint64_t fgPlatformSystemTime ( void )
+//From fg_main_x11
+fg_time_t fgPlatformSystemTime ( void )
 {
-  struct timespec now;
-  clock_gettime(CLOCK_REALTIME, &now);
-  return (1000 * now.tv_sec) + (now.tv_nsec / 1000000);
+#ifdef CLOCK_MONOTONIC
+    struct timespec now;
+    clock_gettime(CLOCK_MONOTONIC, &now);
+    return now.tv_nsec/1000000 + now.tv_sec*1000;
+#elif defined(HAVE_GETTIMEOFDAY)
+    struct timeval now;
+    gettimeofday( &now, NULL );
+    return now.tv_usec/1000 + now.tv_sec*1000;
+#endif
 }
 
 /*
  * Does the magic required to relinquish the CPU until something interesting
  * happens.
  */
-void fgPlatformSleepForEvents( uint64_t msec )
+void fgPlatformSleepForEvents( fg_time_t msec )
 {
   //XXX: Is this right? Is there a more direct way to access the context?
   if(bps_get_event(&fgStructure.CurrentWindow->Window.pContext.event, (int)msec) != BPS_SUCCESS) {
@@ -276,11 +283,24 @@ void fgPlatformProcessSingleEvent ( void )
                {
                  mtouch_event_t touchEvent;
                  screen_get_mtouch_event(screenEvent, &touchEvent, 0);
-                 if(touchEvent.contact_id == 0) { //XXX Only support one contact for now
+                 LOGI("fgPlatformProcessSingleEvent: SCREEN_EVENT_MTOUCH_*: Type: 0x%X, X: %d, Y: %d, Contact Id: %d", SLOG2_FA_SIGNED(eventType), SLOG2_FA_SIGNED(touchEvent.x), SLOG2_FA_SIGNED(touchEvent.y), SLOG2_FA_SIGNED(touchEvent.contact_id), SLOG2_FA_END);
+                 if(touchEvent.contact_id == 0) {
                        int size[2];
                        screen_get_window_property_iv(window->Window.Handle, SCREEN_PROPERTY_BUFFER_SIZE, size);
                        handle_left_mouse(touchEvent.x, touchEvent.y, size[1], eventType, window);
                  }
+
+                 //Now handle mutlitouch (adapted from fg_main_windows)
+                 if (eventType == SCREEN_EVENT_MTOUCH_TOUCH) {
+                       INVOKE_WCB( *window, MultiEntry,  ( touchEvent.contact_id, GLUT_ENTERED ) );
+                       INVOKE_WCB( *window, MultiButton, ( touchEvent.contact_id, touchEvent.x, touchEvent.y, 0, GLUT_DOWN ) );
+                 } else if (eventType == SCREEN_EVENT_MTOUCH_MOVE) {
+                       INVOKE_WCB( *window, MultiMotion, ( touchEvent.contact_id, touchEvent.x, touchEvent.y ) );
+                       //XXX No motion is performed without contact, thus MultiPassive is never used
+                 } else if (eventType == SCREEN_EVENT_MTOUCH_RELEASE) {
+                       INVOKE_WCB( *window, MultiButton, ( touchEvent.contact_id, touchEvent.x, touchEvent.y, 0, GLUT_UP ) );
+                       INVOKE_WCB( *window, MultiEntry,  ( touchEvent.contact_id, GLUT_LEFT ) );
+                 }
                  break;
                }
 
@@ -290,15 +310,21 @@ void fgPlatformProcessSingleEvent ( void )
                  static int mouse_pressed = 0;
                  int buttons;
                  int position[2];
+                 int wheel;
                  // A move event will be fired unless a button state changed.
                  bool move = true;
                  bool left_move = false;
                  // This is a mouse move event, it is applicable to a device with a usb mouse or simulator.
                  screen_get_event_property_iv(screenEvent, SCREEN_PROPERTY_BUTTONS, &buttons);
                  screen_get_event_property_iv(screenEvent, SCREEN_PROPERTY_SOURCE_POSITION, position);
+                 screen_get_event_property_iv(screenEvent, SCREEN_PROPERTY_MOUSE_WHEEL, &wheel);
                  int size[2];
                  screen_get_window_property_iv(window->Window.Handle, SCREEN_PROPERTY_BUFFER_SIZE, size);
 
+                 LOGI("fgPlatformProcessSingleEvent: SCREEN_EVENT_POINTER: Buttons: 0x%X, X: %d, Y: %d, Wheel: %d", SLOG2_FA_SIGNED(buttons), SLOG2_FA_SIGNED(position[0]), SLOG2_FA_SIGNED(position[1]), SLOG2_FA_SIGNED(wheel), SLOG2_FA_END);
+
+                 //XXX Should multitouch be handled?
+
                  // Handle left mouse. Interpret as touch if the left mouse event is not consumed.
                  if (buttons & SCREEN_LEFT_MOUSE_BUTTON) {
                        if (mouse_pressed & SCREEN_LEFT_MOUSE_BUTTON) {
@@ -344,6 +370,11 @@ void fgPlatformProcessSingleEvent ( void )
                  if (left_move || move) {
                        handle_left_mouse(position[0], position[1], size[1], SCREEN_EVENT_MTOUCH_MOVE, window);
                  }
+
+                 if (wheel) {
+                       fgState.MouseWheelTicks -= wheel;
+                       //TODO: Implement wheel support (based on fg_main_mswin... though it seems excessive)
+                 }
                  break;
                }
 
@@ -356,7 +387,7 @@ void fgPlatformProcessSingleEvent ( void )
                  screen_get_event_property_iv(screenEvent, SCREEN_PROPERTY_KEY_SYM, &value);
                  LOGI("fgPlatformProcessSingleEvent: SCREEN_EVENT_KEYBOARD. Flags: 0x%X, Sym: 0x%X", SLOG2_FA_SIGNED(flags), SLOG2_FA_SIGNED(value), SLOG2_FA_END);
                  // Suppress key repeats if desired
-                 if (!fgStructure.CurrentWindow->State.IgnoreKeyRepeat && (flags & KEY_REPEAT) == 0) {
+                 if ((flags & KEY_REPEAT) == 0 || (fgState.KeyRepeat == GLUT_KEY_REPEAT_ON && !fgStructure.CurrentWindow->State.IgnoreKeyRepeat)) {
                        unsigned int keypress = 0;
                        unsigned char ascii = 0;
                        if ((keypress = key_special(value))) {
@@ -375,9 +406,14 @@ void fgPlatformProcessSingleEvent ( void )
                  }
                  break;
                }
+
+               default:
+                 LOGW("fgPlatformProcessSingleEvent: unknown screen event: 0x%X", SLOG2_FA_SIGNED(eventType), SLOG2_FA_END);
+                 break;
                }
          } else if (domain == navigator_get_domain()) {
-               switch (bps_event_get_code(event)) {
+               int eventType = bps_event_get_code(event);
+               switch (eventType) {
 
                case NAVIGATOR_WINDOW_STATE:
                {
@@ -394,6 +430,9 @@ void fgPlatformProcessSingleEvent ( void )
                        LOGI("fgPlatformProcessSingleEvent: NAVIGATOR_WINDOW_STATE-NAVIGATOR_WINDOW_THUMBNAIL/NAVIGATOR_WINDOW_INVISIBLE", SLOG2_FA_END);
                        INVOKE_WCB(*window, AppStatus, (GLUT_APPSTATUS_PAUSE));
                        break;
+                 default:
+                       LOGW("fgPlatformProcessSingleEvent: NAVIGATOR_WINDOW_STATE unknown: 0x%X", SLOG2_FA_SIGNED(state), SLOG2_FA_END);
+                       break;
                  }
                  break;
                }
@@ -406,10 +445,14 @@ void fgPlatformProcessSingleEvent ( void )
                        if (window != NULL) {
                          fgDestroyWindow(window);
                        } else {
-                         LOGI("NAVIGATOR_EXIT: No current window", SLOG2_FA_END);
+                         LOGW("NAVIGATOR_EXIT: No current window", SLOG2_FA_END);
                        }
                  }
                  break;
+
+               default:
+                 LOGW("fgPlatformProcessSingleEvent: unknown navigator event: 0x%X", SLOG2_FA_SIGNED(eventType), SLOG2_FA_END);
+                 break;
                }
          }
        }