Browse Source

Added platform abstraction for sprite_tint

Eiyeron Fulmincendii 10 years ago
parent
commit
760c693c46
3 changed files with 28 additions and 4 deletions
  1. 9 4
      platform/include/Graphics.h
  2. 7 0
      platform/nspire/Graphics.cpp
  3. 12 0
      platform/sfml/Graphics.cpp

+ 9 - 4
platform/include/Graphics.h

@@ -31,14 +31,19 @@ namespace WalrusRPG
         void frame_end();
 
         /*
-         * Current prototype is the same as the nspire fb implementation
-         * for now, need to add a texture type and get rid of the Rect
-         * (not sure the GC supports drawing parts of a texture, but it
-         * may be worth trying
+         * Draws a sprite with clipping given as window.
          */
         void put_sprite(const Texture &sheet, int x, int y,
                         const WalrusRPG::Utils::Rect &window);
 
+        /*
+         * Draws a sprite with clipping given as window and color
+         * tinting.
+         */
+        void put_sprite_tint(const Texture &sheet, int x, int y,
+                             const WalrusRPG::Utils::Rect &window,
+                             const WalrusRPG::Graphics::Pixel &color);
+
         /*
          * Fill the screen with a color
          */

+ 7 - 0
platform/nspire/Graphics.cpp

@@ -31,6 +31,13 @@ void GRAPHICS::put_sprite(const Texture &sheet, int x, int y,
     CXfb::draw_sprite_sheet(sheet.data, x, y, window);
 }
 
+void GRAPHICS::put_sprite_tint(const Texture &sheet, int x, int y,
+                     const WalrusRPG::Utils::Rect &window,
+                     const WalrusRPG::Graphics::Pixel &color)
+{
+	CXfb::draw_sprite_sheet_tint(sheet.data, x, y, window, color.value);
+}
+
 void GRAPHICS::fill(const WalrusRPG::Graphics::Pixel &color)
 {
     CXfb::buffer_fill(color);

+ 12 - 0
platform/sfml/Graphics.cpp

@@ -58,6 +58,18 @@ void GRAPHICS::put_sprite(const Texture &sheet, int x, int y,
     buffer.draw(sprite);
 }
 
+void GRAPHICS::put_sprite_tint(const Texture &sheet, int x, int y,
+                     const WalrusRPG::Utils::Rect &window,
+                     const WalrusRPG::Graphics::Pixel &color)
+{
+    sf::Sprite sprite;
+    sprite.setTexture(sheet.data);
+    sprite.setTextureRect(sf::IntRect(window.x, window.y, window.width, window.height));
+    sprite.setPosition(x, y);
+    sprite.setColor(sf::Color(color.r<<3, color.g<<2, color.b<<3, 255));
+    buffer.draw(sprite);
+}
+
 void GRAPHICS::fill(const WalrusRPG::Graphics::Pixel &color)
 {
     buffer.clear(sf::Color(color.r<<3, color.g<<2, color.b<<2, 255));