Browse Source

Edit browser sample to show new gestures

SAUVAGEOT Paul-Arthur 12 years ago
parent
commit
b472ea8891

+ 58 - 1
samples/browser/src/GestureSample.cpp

@@ -42,6 +42,24 @@ void GestureSample::initialize()
         registerGesture(Gesture::GESTURE_PINCH);
         GP_ASSERT(isGestureRegistered(Gesture::GESTURE_PINCH));
     }
+	if (isGestureSupported(Gesture::GESTURE_LONG_TAP))
+	{
+        anySupported = true;
+        registerGesture(Gesture::GESTURE_LONG_TAP);
+        GP_ASSERT(isGestureRegistered(Gesture::GESTURE_LONG_TAP));
+	}
+	if (isGestureSupported(Gesture::GESTURE_DRAG))
+	{
+        anySupported = true;
+        registerGesture(Gesture::GESTURE_DRAG);
+        GP_ASSERT(isGestureRegistered(Gesture::GESTURE_DRAG));
+	}
+	if (isGestureSupported(Gesture::GESTURE_DROP))
+	{
+        anySupported = true;
+        registerGesture(Gesture::GESTURE_DROP);
+        GP_ASSERT(isGestureRegistered(Gesture::GESTURE_DROP));
+	}
     GP_ASSERT(anySupported == isGestureSupported(Gesture::GESTURE_ANY_SUPPORTED));
 }
 
@@ -52,6 +70,9 @@ void GestureSample::finalize()
     unregisterGesture(Gesture::GESTURE_TAP);
     unregisterGesture(Gesture::GESTURE_SWIPE);
     unregisterGesture(Gesture::GESTURE_PINCH);
+	unregisterGesture(Gesture::GESTURE_LONG_TAP);
+	unregisterGesture(Gesture::GESTURE_DRAG);
+	unregisterGesture(Gesture::GESTURE_DROP);
 }
 
 void GestureSample::update(float elapsedTime)
@@ -83,7 +104,7 @@ void GestureSample::render(float elapsedTime)
     }
     
     int x = getWidth() - 200;
-    y = getHeight() - _font->getSize() * 3;
+    y = getHeight() - _font->getSize() * 6;
 
     if (isGestureSupported(Gesture::GESTURE_TAP))
     {
@@ -100,6 +121,21 @@ void GestureSample::render(float elapsedTime)
         _font->drawText("Pinch supported", x, y, fontColor, _font->getSize());
         y += _font->getSize();
     }
+    if (isGestureSupported(Gesture::GESTURE_LONG_TAP))
+    {
+        _font->drawText("Long tap supported", x, y, fontColor, _font->getSize());
+        y += _font->getSize();
+    }
+    if (isGestureSupported(Gesture::GESTURE_DRAG))
+    {
+        _font->drawText("Drag supported", x, y, fontColor, _font->getSize());
+        y += _font->getSize();
+    }
+    if (isGestureSupported(Gesture::GESTURE_DROP))
+    {
+        _font->drawText("Drop supported", x, y, fontColor, _font->getSize());
+        y += _font->getSize();
+    }
 
     _font->finish();
 }
@@ -160,3 +196,24 @@ void GestureSample::gestureTapEvent(int x, int y)
     _eventLog.push_front(convert.str());
 }
 
+void GestureSample::gestureLongTapEvent(int x, int y, float duration)
+{
+    std::ostringstream convert;
+    convert << "Long tap " << x << ", " << y << " (" << duration << "ms)";
+    _eventLog.push_front(convert.str());
+}
+
+void GestureSample::gestureDragEvent(int x, int y)
+{
+    std::ostringstream convert;
+    convert << "Drag " << x << ", " << y;
+    _eventLog.push_front(convert.str());
+}
+
+void GestureSample::gestureDropEvent(int x, int y)
+{
+    std::ostringstream convert;
+    convert << "Drop " << x << ", " << y;
+    _eventLog.push_front(convert.str());
+}
+

+ 6 - 0
samples/browser/src/GestureSample.h

@@ -23,6 +23,12 @@ public:
     
     void gestureTapEvent(int x, int y);
 
+	void gestureLongTapEvent(int x, int y, float duration);
+
+	void gestureDragEvent(int x, int y);
+	
+	void gestureDropEvent(int x, int y);
+
 protected:
 
     void initialize();

+ 12 - 0
samples/browser/src/Sample.cpp

@@ -237,6 +237,18 @@ void Sample::gestureTapEvent(int x, int y)
 {
 }
 
+void Sample::gestureLongTapEvent(int x, int y, float duration)
+{
+}
+
+void Sample::gestureDragEvent(int x, int y)
+{
+}
+
+void Sample::gestureDropEvent(int x, int y)
+{
+}
+
 void Sample::gamepadEvent(Gamepad::GamepadEvent evt, Gamepad* gamepad)
 {
 }

+ 4 - 1
samples/browser/src/Sample.h

@@ -72,7 +72,10 @@ public:
     virtual void gestureSwipeEvent(int x, int y, int direction);
     virtual void gesturePinchEvent(int x, int y, float scale);
     virtual void gestureTapEvent(int x, int y);
-    virtual void gamepadEvent(Gamepad::GamepadEvent evt, Gamepad* gamepad);
+    virtual void gestureLongTapEvent(int x, int y, float duration);
+    virtual void gestureDragEvent(int x, int y);
+	virtual void gestureDropEvent(int x, int y);
+	virtual void gamepadEvent(Gamepad::GamepadEvent evt, Gamepad* gamepad);
     unsigned int getGamepadCount() const;
     Gamepad* getGamepad(unsigned int index, bool preferPhysical = true) const;
 

+ 18 - 0
samples/browser/src/SamplesGame.cpp

@@ -206,6 +206,24 @@ void SamplesGame::gestureTapEvent(int x, int y)
         _activeSample->gestureTapEvent(x, y);
 }
 
+void SamplesGame::gestureLongTapEvent(int x, int y, float duration)
+{
+	if (_activeSample)
+		_activeSample->gestureLongTapEvent(x, y, duration);
+}
+
+void SamplesGame::gestureDragEvent(int x, int y)
+{
+	if (_activeSample)
+		_activeSample->gestureDragEvent(x, y);
+}
+
+void SamplesGame::gestureDropEvent(int x, int y)
+{
+	if (_activeSample)
+		_activeSample->gestureDropEvent(x, y);
+}
+
 void SamplesGame::controlEvent(Control* control, EventType evt)
 {
     const size_t size = _samples->size();

+ 7 - 1
samples/browser/src/SamplesGame.h

@@ -49,7 +49,13 @@ public:
     
     void gestureTapEvent(int x, int y);
 
-    void controlEvent(Control* control, EventType evt);
+	void gestureLongTapEvent(int x, int y, float duration);
+
+	void gestureDragEvent(int x, int y);
+
+	void gestureDropEvent(int x, int y);
+
+	void controlEvent(Control* control, EventType evt);
 
     void gamepadEvent(Gamepad::GamepadEvent evt, Gamepad* gamepad, unsigned int analogIndex = 0);