Quellcode durchsuchen

Font has now its drawing functions

Eiyeron Fulmincendii vor 9 Jahren
Ursprung
Commit
a088dfc4b3
3 geänderte Dateien mit 54 neuen und 39 gelöschten Zeilen
  1. 7 38
      src/map/StateMap.cpp
  2. 41 1
      src/render/Font.cpp
  3. 6 0
      src/render/Font.h

+ 7 - 38
src/map/StateMap.cpp

@@ -26,37 +26,6 @@ namespace
     }
 }
 
-void StateMap::putchar_haeccity(unsigned char c, unsigned x, unsigned y)
-{
-    // Rect letter{haeccity[c][0], haeccity[c][1], haeccity[c][2], haeccity[c][3]};
-    // put_sprite(tex_haeccity, x + haeccity[c][4], y + haeccity[c][5], letter);
-    put_sprite(txt.font_tex, x + txt.chars[c].x_offset, y + txt.chars[c].y_offset, txt.chars[c].dimensions);
-}
-
-void StateMap::putchar_haeccity_tint(unsigned char c, unsigned x, unsigned y,
-                                     const Pixel &col)
-{
-    put_sprite_tint(txt.font_tex, x + txt.chars[c].x_offset, y + txt.chars[c].y_offset, txt.chars[c].dimensions, col);
-}
-
-
-void StateMap::print_haeccity(const char *str, unsigned x, unsigned y,
-                              const Pixel &col = White)
-{
-    const bool must_tint = (col != White);
-    for (unsigned i = 0; str[i] && x < 320; i++)
-    {
-        unsigned char c = str[i];
-        if(c == 32) {x += txt.space_width; continue;}
-        // printf("%c = %d\n", c, c);
-        if (must_tint)
-            putchar_haeccity_tint(c, x, y, col);
-        else
-            putchar_haeccity(c, x, y);
-        x += txt.chars[c].dimensions.width + 1;
-    }
-}
-
 // TODO : We definitely need a Resource Manager
 StateMap::StateMap(int x, int y, Map &map)
     : camera(x, y), map(map), data("data/out.wrf"),
@@ -76,23 +45,23 @@ void StateMap::render(unsigned dt)
 
     // print_debug_camera_data(camera);
     // print_debug_map_data(map);
-    print_haeccity("Hello world! :D", 0, 0);
-    print_haeccity("This isn't actually a utility nor built-ins functions.", 0, 9);
-    print_haeccity("This is a quick prototype to see if variable-wdith fonts works.", 0,
+    txt.draw("Hello world! :D", 0, 0);
+    txt.draw("This isn't actually a utility nor built-ins functions.", 0, 9);
+    txt.draw("This is a quick prototype to see if variable-wdith fonts works.", 0,
                    18);
-    print_haeccity("Builting it myself allows me to make it work on calc too.", 0, 27,
+    txt.draw("Builting it myself allows me to make it work on calc too.", 0, 27,
                    Yellow);
-    print_haeccity(
+    txt.draw(
         "( I wonder if a conditionnal to tint the text slows down a lot the process. )",
         0, 36, Gray);
-    print_haeccity("Oh well, I hope I'll get to do a pretty textbox like in games !", 0,
+    txt.draw("Oh well, I hope I'll get to do a pretty textbox like in games !", 0,
                    45);
 
     for (int i = 0; i < 16; ++i)
     {
         for (int j = 0; j < 16; ++j)
         {
-            putchar_haeccity_tint(16 * j + i, 6 * i, 9 * j + 54,
+            txt.draw(16 * j + i, 6 * i, 9 * j + 54,
                                   Pixel(i * 16, j * 16, 255));
         }
     }

+ 41 - 1
src/render/Font.cpp

@@ -6,6 +6,7 @@
 using WalrusRPG::Font::Font;
 using WalrusRPG::Font::CharacterParameters;
 using WalrusRPG::Graphics::Texture;
+using WalrusRPG::Graphics::Pixel;
 
 Font::Font(Texture& font_tex, WalrusRPG::PIAF::File font_config)
 	: baseline(0), space_width(1), font_tex(font_tex)
@@ -42,4 +43,43 @@ Font::Font(Texture& font_tex, WalrusRPG::PIAF::File font_config)
 
 Font::~Font()
 {
-}
+}
+
+void Font::draw(const char c, uint16_t x, uint16_t y)
+{
+	uint8_t c2 = (uint8_t)c;
+    put_sprite(font_tex, x + chars[c2].x_offset, y + chars[c2].y_offset, chars[c2].dimensions);
+
+}
+
+void Font::draw(const char c, uint16_t x, uint16_t y, const Pixel &col)
+{
+	uint8_t c2 = (uint8_t)c;
+    put_sprite_tint(font_tex, x + chars[c2].x_offset, y + chars[c2].y_offset, chars[c2].dimensions, col);
+}
+
+void Font::draw(const char *str, uint16_t x, uint16_t y)
+{	
+    for (unsigned i = 0; str[i] && x < 320; i++)
+  	{
+        unsigned char c = str[i];
+        if(c == 32) {x += space_width; continue;}
+            draw(c, x, y);
+        x += chars[c].dimensions.width + 1;
+
+  	}
+}
+
+void Font::draw(const char *str, uint16_t x, uint16_t y, const Pixel &col)
+{
+    for (unsigned i = 0; str[i] && x < 320; i++)
+  	{
+        unsigned char c = str[i];
+        if(c == 32) {x += space_width; continue;}
+            draw(c, x, y, col);
+        x += chars[c].dimensions.width + 1;
+
+  	}
+
+}
+

+ 6 - 0
src/render/Font.h

@@ -29,6 +29,12 @@ namespace WalrusRPG
 
 			Font(WalrusRPG::Graphics::Texture& font_tex, WalrusRPG::PIAF::File font_config);
 			~Font();
+
+			void draw(const char c, uint16_t x, uint16_t y);
+			void draw(const char c, uint16_t x, uint16_t y, const WalrusRPG::Graphics::Pixel &col);
+			void draw(const char *str, uint16_t x, uint16_t y);
+			void draw(const char *str, uint16_t x, uint16_t y, const WalrusRPG::Graphics::Pixel &col);
+
 		};
 	}
 }