Explorar o código

Merge pull request #408 from blackberry-gaming/next-ablake

Next ablake
Sean Paul Taylor %!s(int64=13) %!d(string=hai) anos
pai
achega
7963bd1b38
Modificáronse 3 ficheiros con 91 adicións e 124 borrados
  1. 2 2
      gameplay/src/Font.cpp
  2. 29 28
      gameplay/src/Font.h
  3. 60 94
      gameplay/src/SpriteBatch.h

+ 2 - 2
gameplay/src/Font.cpp

@@ -400,9 +400,9 @@ Font::Text* Font::createText(const char* text, const Rectangle& area, const Vect
     return batch;
 }
 
-void Font::drawText(Text* textBatch)
+void Font::drawText(Text* text)
 {
-    _batch->draw(textBatch->_vertices, textBatch->_vertexCount, textBatch->_indices, textBatch->_indexCount);
+    _batch->draw(text->_vertices, text->_vertexCount, text->_indices, text->_indexCount);
 }
 
 void Font::drawText(const char* text, int x, int y, const Vector4& color, unsigned int size, bool rightToLeft)

+ 29 - 28
gameplay/src/Font.h

@@ -107,6 +107,7 @@ public:
         unsigned short* _indices;
         unsigned int _vertexCount;
         unsigned int _indexCount;
+        Vector4 _color;
     };
 
     /**
@@ -159,10 +160,20 @@ public:
     void end();
 
     /**
-     * Create a Text object from a given string.
-     * Vertex coordinates, UVs and indices will be computed and stored in the Text object.
-     * For static text labels that do not change frequently, this means these computations
-     * need not be performed every frame.
+     * Draws the specified text in a solid color, with a scaling factor.
+     *
+     * @param text The text to draw.
+     * @param x The viewport x position to draw text at.
+     * @param y The viewport y position to draw text at.
+     * @param color The color of text.
+     * @param size The size to draw text (0 for default size).
+     * @param rightToLeft Whether to draw text from right to left.
+     */
+    void drawText(const char* text, int x, int y, const Vector4& color, unsigned int size = 0, bool rightToLeft = false);
+
+    /**
+     * Draws the specified text within a rectangular area, with a specified alignment and scale.
+     * Clips text outside the viewport. Optionally wraps text to fit within the width of the viewport.
      *
      * @param text The text to draw.
      * @param area The viewport area to draw within.  Text will be clipped outside this rectangle.
@@ -172,11 +183,9 @@ public:
      * @param wrap Wraps text to fit within the width of the viewport if true.
      * @param rightToLeft Whether to draw text from right to left.
      * @param clip A region to clip text within after applying justification to the viewport area.
-     *
-     * @return A Text object.
      */
-    Text* createText(const char* text, const Rectangle& area, const Vector4& color, unsigned int size = 0,
-        Justify justify = ALIGN_TOP_LEFT, bool wrap = true, bool rightToLeft = false, const Rectangle* clip = NULL);
+    void drawText(const char* text, const Rectangle& area, const Vector4& color, unsigned int size = 0, 
+                  Justify justify = ALIGN_TOP_LEFT, bool wrap = true, bool rightToLeft = false, const Rectangle* clip = NULL);
 
     /**
      * Draw a string from a precomputed Text object.
@@ -186,20 +195,10 @@ public:
     void drawText(Text* text);
 
     /**
-     * Draws the specified text in a solid color, with a scaling factor.
-     *
-     * @param text The text to draw.
-     * @param x The viewport x position to draw text at.
-     * @param y The viewport y position to draw text at.
-     * @param color The color of text.
-     * @param size The size to draw text (0 for default size).
-     * @param rightToLeft Whether to draw text from right to left.
-     */
-    void drawText(const char* text, int x, int y, const Vector4& color, unsigned int size = 0, bool rightToLeft = false);
-
-    /**
-     * Draws the specified text within a rectangular area, with a specified alignment and scale.
-     * Clips text outside the viewport.  Optionally wraps text to fit within the width of the viewport.
+     * Create an immutable Text object from a given string.
+     * Vertex coordinates, UVs and indices will be computed and stored in the Text object.
+     * For static text labels that do not change frequently, this means these computations
+     * need not be performed every frame.
      *
      * @param text The text to draw.
      * @param area The viewport area to draw within.  Text will be clipped outside this rectangle.
@@ -209,9 +208,11 @@ public:
      * @param wrap Wraps text to fit within the width of the viewport if true.
      * @param rightToLeft Whether to draw text from right to left.
      * @param clip A region to clip text within after applying justification to the viewport area.
+     *
+     * @return A Text object.
      */
-    void drawText(const char* text, const Rectangle& area, const Vector4& color, unsigned int size = 0, 
-                  Justify justify = ALIGN_TOP_LEFT, bool wrap = true, bool rightToLeft = false, const Rectangle* clip = NULL);
+    Text* createText(const char* text, const Rectangle& area, const Vector4& color, unsigned int size = 0,
+                     Justify justify = ALIGN_TOP_LEFT, bool wrap = true, bool rightToLeft = false, const Rectangle* clip = NULL);
 
     /**
      * Measures a string's width and height without alignment, wrapping or clipping.
@@ -239,10 +240,10 @@ public:
                      Justify justify = ALIGN_TOP_LEFT, bool wrap = true, bool ignoreClip = false);
 
     /**
-     * Get an index into a string corresponding to the character nearest the given location within the clip region.
+     * Get an character index into a string corresponding to the character nearest the given location within the clip region.
      */
     int getIndexAtLocation(const char* text, const Rectangle& clip, unsigned int size, const Vector2& inLocation, Vector2* outLocation,
-                                    Justify justify = ALIGN_TOP_LEFT, bool wrap = true, bool rightToLeft = false);
+                           Justify justify = ALIGN_TOP_LEFT, bool wrap = true, bool rightToLeft = false);
 
     /**
      * Get the location of the character at the given index.
@@ -286,10 +287,10 @@ private:
     ~Font();
 
     void getMeasurementInfo(const char* text, const Rectangle& area, unsigned int size, Justify justify, bool wrap, bool rightToLeft,
-        std::vector<int>* xPositions, int* yPosition, std::vector<unsigned int>* lineLengths);
+                            std::vector<int>* xPositions, int* yPosition, std::vector<unsigned int>* lineLengths);
 
     int getIndexOrLocation(const char* text, const Rectangle& clip, unsigned int size, const Vector2& inLocation, Vector2* outLocation,
-                                    const int destIndex = -1, Justify justify = ALIGN_TOP_LEFT, bool wrap = true, bool rightToLeft = false);
+                           const int destIndex = -1, Justify justify = ALIGN_TOP_LEFT, bool wrap = true, bool rightToLeft = false);
 
     unsigned int getTokenWidth(const char* token, unsigned int length, unsigned int size, float scale);
 

+ 60 - 94
gameplay/src/SpriteBatch.h

@@ -25,60 +25,10 @@ namespace gameplay
 class SpriteBatch
 {
     friend class Bundle;
+    friend class Font;
 
 public:
 
-    /**
-     * Sprite vertex structure used for batching.
-     */
-    struct SpriteVertex
-    {
-        /**
-         * The x coordinate of the vertex.
-         */
-        float x;
-    
-        /**
-         * The y coordinate of the vertex.
-         */
-        float y;
-    
-        /**
-         * The z coordinate of the vertex.
-         */
-        float z;
-
-        /**
-         * The u component of the (u, v) texture coordinates for the vertex.
-         */
-        float u;
-    
-        /**
-         * The v component of the (u, v) texture coordinates for the vertex.
-         */
-        float v;
-
-        /**
-         * The red color component of the vertex.
-         */
-        float r;
-    
-        /**
-         * The green color component of the vertex.
-         */
-        float g;
-    
-        /**
-         * The blue color component of the vertex.
-         */
-        float b;
-    
-        /**
-         * The alpha component of the vertex.
-         */
-        float a;
-    };
-
     /**
      * Creates a new SpriteBatch for drawing sprites with the given texture.
      *
@@ -214,7 +164,7 @@ public:
      * @param rotationAngle The rotation angle.
      */
     void draw(const Vector3& position, const Vector3& right, const Vector3& forward, float width, float height, 
-        float u1, float v1, float u2, float v2, const Vector4& color, const Vector2& rotationPoint, float rotationAngle);
+              float u1, float v1, float u2, float v2, const Vector4& color, const Vector2& rotationPoint, float rotationAngle);
 
     /**
      * Draws a single sprite.
@@ -247,48 +197,6 @@ public:
      */
     void draw(float x, float y, float width, float height, float u1, float v1, float u2, float v2, const Vector4& color, const Rectangle& clip);
 
-    /**
-     * Adds a single sprite to a SpriteVertex array.
-     * 
-     * @param x The x coordinate.
-     * @param y The y coordinate.
-     * @param width The sprite width.
-     * @param height The sprite height
-     * @param u1 Texture coordinate.
-     * @param v1 Texture coordinate.
-     * @param u2 Texture coordinate.
-     * @param v2 Texture coordinate.
-     * @param color The color to tint the sprite. Use white for no tint.
-     * @param clip The clip rectangle.
-     */
-    void addSprite(float x, float y, float width, float height, float u1, float v1, float u2, float v2, const Vector4& color, SpriteBatch::SpriteVertex* vertices);
-
-    /**
-     * Adds a single sprite to a SpriteVertex array, clipped within a rectangle.
-     * 
-     * @param x The x coordinate.
-     * @param y The y coordinate.
-     * @param width The sprite width.
-     * @param height The sprite height
-     * @param u1 Texture coordinate.
-     * @param v1 Texture coordinate.
-     * @param u2 Texture coordinate.
-     * @param v2 Texture coordinate.
-     * @param color The color to tint the sprite. Use white for no tint.
-     * @param clip The clip rectangle.
-     */
-    void addSprite(float x, float y, float width, float height, float u1, float v1, float u2, float v2, const Vector4& color, const Rectangle& clip, SpriteBatch::SpriteVertex* vertices);
-
-    /**
-     * Draws an array of vertices.
-     *
-     * @param vertices The vertices to draw.
-     * @param vertexCount The number of vertices within the vertex array.
-     * @param indices The vertex indices.
-     * @param indexCount The number of indices within the index array.
-     */
-    void draw(SpriteBatch::SpriteVertex* vertices, unsigned int vertexCount, unsigned short* indices, unsigned int indexCount);
-
     /**
      * Draws a single sprite.
      * 
@@ -346,6 +254,22 @@ public:
 
 private:
 
+    /**
+     * Sprite vertex structure used for batching.
+     */
+    struct SpriteVertex
+    {
+        float x;        
+        float y;
+        float z;
+        float u;
+        float v;
+        float r;
+        float g;
+        float b;
+        float a;
+    };
+
     /**
      * Constructor.
      */
@@ -360,6 +284,48 @@ private:
 
     const Matrix& getOrthoMatrix() const;
 
+    /**
+     * Adds a single sprite to a SpriteVertex array.
+     * 
+     * @param x The x coordinate.
+     * @param y The y coordinate.
+     * @param width The sprite width.
+     * @param height The sprite height
+     * @param u1 Texture coordinate.
+     * @param v1 Texture coordinate.
+     * @param u2 Texture coordinate.
+     * @param v2 Texture coordinate.
+     * @param color The color to tint the sprite. Use white for no tint.
+     * @param clip The clip rectangle.
+     */
+    void addSprite(float x, float y, float width, float height, float u1, float v1, float u2, float v2, const Vector4& color, SpriteBatch::SpriteVertex* vertices);
+
+    /**
+     * Adds a single sprite to a SpriteVertex array, clipped within a rectangle.
+     * 
+     * @param x The x coordinate.
+     * @param y The y coordinate.
+     * @param width The sprite width.
+     * @param height The sprite height
+     * @param u1 Texture coordinate.
+     * @param v1 Texture coordinate.
+     * @param u2 Texture coordinate.
+     * @param v2 Texture coordinate.
+     * @param color The color to tint the sprite. Use white for no tint.
+     * @param clip The clip rectangle.
+     */
+    void addSprite(float x, float y, float width, float height, float u1, float v1, float u2, float v2, const Vector4& color, const Rectangle& clip, SpriteBatch::SpriteVertex* vertices);
+
+    /**
+     * Draws an array of vertices.
+     *
+     * @param vertices The vertices to draw.
+     * @param vertexCount The number of vertices within the vertex array.
+     * @param indices The vertex indices.
+     * @param indexCount The number of indices within the index array.
+     */
+    void draw(SpriteBatch::SpriteVertex* vertices, unsigned int vertexCount, unsigned short* indices, unsigned int indexCount);
+
     /**
      * Clip position and size to fit within clip region.
      *