Ver Fonte

Renamed Game::resized to Game::resizeEvent to be more consistent with other game events.
Added support for listening to game resize events from script.

sgrenier há 13 anos atrás
pai
commit
9a0d34dde2

+ 2 - 2
gameplay/src/Game.cpp

@@ -293,7 +293,7 @@ void Game::frame()
         _initialized = true;
 
         // Fire first game resize event
-        resized(_width, _height);
+        Platform::resizeEventInternal(_width, _height);
     }
 
 	static double lastFrameTime = Game::getGameTime();
@@ -469,7 +469,7 @@ bool Game::mouseEvent(Mouse::MouseEvent evt, int x, int y, int wheelDelta)
     return false;
 }
 
-void Game::resized(unsigned int width, unsigned int height)
+void Game::resizeEvent(unsigned int width, unsigned int height)
 {
 }
 

+ 1 - 1
gameplay/src/Game.h

@@ -325,7 +325,7 @@ public:
      * @param width The new game window width.
      * @param height The new game window height.
      */
-    virtual void resized(unsigned int width, unsigned int height);
+    virtual void resizeEvent(unsigned int width, unsigned int height);
 
     /** 
      * Gets whether the current platform supports mouse input.

+ 2 - 1
gameplay/src/Platform.cpp

@@ -49,7 +49,8 @@ void Platform::resizeEventInternal(unsigned int width, unsigned int height)
     {
         game->_width = width;
         game->_height = height;
-        game->resized(width, height);
+        game->resizeEvent(width, height);
+        game->getScriptController()->resizeEvent(width, height);
     }
 }
 

+ 10 - 0
gameplay/src/ScriptController.cpp

@@ -766,6 +766,14 @@ void ScriptController::render(float elapsedTime)
     }
 }
 
+void ScriptController::resizeEvent(unsigned int width, unsigned int height)
+{
+    if (_callbacks[RESIZE_EVENT])
+    {
+        executeFunction<void>(_callbacks[RESIZE_EVENT]->c_str(), "uiui", width, height);
+    }
+}
+
 void ScriptController::keyEvent(Keyboard::KeyEvent evt, int key)
 {
     if (_callbacks[KEY_EVENT])
@@ -943,6 +951,8 @@ ScriptController::ScriptCallback ScriptController::toCallback(const char* name)
         return ScriptController::RENDER;
     else if (strcmp(name, "finalize") == 0)
         return ScriptController::FINALIZE;
+    else if (strcmp(name, "resizeEvent") == 0)
+        return ScriptController::RESIZE_EVENT;
     else if (strcmp(name, "keyEvent") == 0)
         return ScriptController::KEY_EVENT;
     else if (strcmp(name, "touchEvent") == 0)

+ 9 - 0
gameplay/src/ScriptController.h

@@ -740,6 +740,7 @@ private:
         UPDATE,
         RENDER,
         FINALIZE,
+        RESIZE_EVENT,
         KEY_EVENT,
         MOUSE_EVENT,
         TOUCH_EVENT,
@@ -793,6 +794,14 @@ private:
      */
     void render(float elapsedTime);
 
+    /**
+     * Script callback for game resize events.
+     *
+     * @param width The new width of the game window content area.
+     * @param height The new height of the game window content area.
+     */
+    void resizeEvent(unsigned int width, unsigned int height);
+
     /**
      * Script keyboard callback on key events.
      *