Eiyeron Fulmincendii 9 gadi atpakaļ
vecāks
revīzija
12fa7be920
3 mainītis faili ar 87 papildinājumiem un 87 dzēšanām
  1. 6 11
      src/map/StateMap.cpp
  2. 51 47
      src/render/Font.cpp
  3. 30 29
      src/render/Font.h

+ 6 - 11
src/map/StateMap.cpp

@@ -14,7 +14,6 @@ using WalrusRPG::Graphics::Texture;
 
 namespace
 {
-
     void print_debug_camera_data(const Camera &camera)
     {
         Text::print_format(0, 8, "CAM : X : %d Y: %d", camera.get_x(), camera.get_y());
@@ -28,8 +27,8 @@ namespace
 
 // TODO : We definitely need a Resource Manager
 StateMap::StateMap(int x, int y, Map &map)
-    : camera(x, y), map(map), data("data/out.wrf"),
-      tex_haeccity(data.get("t_haeccity")), txt(tex_haeccity, data.get("f_haeccity"))
+    : camera(x, y), map(map), data("data/out.wrf"), tex_haeccity(data.get("t_haeccity")),
+      txt(tex_haeccity, data.get("f_haeccity"))
 {
 }
 
@@ -47,22 +46,18 @@ void StateMap::render(unsigned dt)
     // print_debug_map_data(map);
     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);
-    txt.draw("Builting it myself allows me to make it work on calc too.", 0, 27,
-                   Yellow);
+    txt.draw("This is a quick prototype to see if variable-wdith fonts works.", 0, 18);
+    txt.draw("Builting it myself allows me to make it work on calc too.", 0, 27, Yellow);
     txt.draw(
         "( I wonder if a conditionnal to tint the text slows down a lot the process. )",
         0, 36, Gray);
-    txt.draw("Oh well, I hope I'll get to do a pretty textbox like in games !", 0,
-                   45);
+    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)
         {
-            txt.draw(16 * j + i, 6 * i, 9 * j + 54,
-                                  Pixel(i * 16, j * 16, 255));
+            txt.draw(16 * j + i, 6 * i, 9 * j + 54, Pixel(i * 16, j * 16, 255));
         }
     }
 }

+ 51 - 47
src/render/Font.cpp

@@ -8,37 +8,36 @@ 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)
+Font::Font(Texture &font_tex, WalrusRPG::PIAF::File font_config)
+    : baseline(0), space_width(1), font_tex(font_tex)
 {
-	const uint8_t* ptr = font_config.get();
-	// TODO : parse file
-	// TODO : forgot to put the version and the font type
-	if(strncmp((const char*)ptr, "WFONT", 4) != 0)
-	{
-		// TODO : wrong header
-	}
-	uint32_t expected_checksum = read_big_endian_value<uint32_t>(&ptr[4]);
-	uint32_t calculated_checksum = crc32(0L, (const unsigned char *) (&ptr[8]),
-		font_config.file_size - 8
-		);
-	if(expected_checksum != calculated_checksum)
-	{
-		// printf("Bad checksum : %x != %x\n", expected_checksum, calculated_checksum);
-	}
+    const uint8_t *ptr = font_config.get();
+    // TODO : parse file
+    // TODO : forgot to put the version and the font type
+    if (strncmp((const char *) ptr, "WFONT", 4) != 0)
+    {
+        // TODO : wrong header
+    }
+    uint32_t expected_checksum = read_big_endian_value<uint32_t>(&ptr[4]);
+    uint32_t calculated_checksum =
+        crc32(0L, (const unsigned char *) (&ptr[8]), font_config.file_size - 8);
+    if (expected_checksum != calculated_checksum)
+    {
+        // printf("Bad checksum : %x != %x\n", expected_checksum, calculated_checksum);
+    }
 
-	baseline = read_big_endian_value<uint8_t>(&ptr[12]);
-	space_width = read_big_endian_value<uint32_t>(&ptr[20]);
-	for (int i = 0; i < 256; ++i)
-	{
-		const uint8_t* current_char = ptr + 24 + (6*sizeof(uint16_t))*i;
-		chars[i].dimensions.x = read_big_endian_value<int16_t>(current_char);
-		chars[i].dimensions.y = read_big_endian_value<int16_t>(current_char+2);
-		chars[i].dimensions.width = read_big_endian_value<uint16_t>(current_char+4);
-		chars[i].dimensions.height = read_big_endian_value<uint16_t>(current_char+6);
-		chars[i].x_offset = read_big_endian_value<int16_t>(current_char+8);
-		chars[i].y_offset = read_big_endian_value<int16_t>(current_char+10);
-	}
+    baseline = read_big_endian_value<uint8_t>(&ptr[12]);
+    space_width = read_big_endian_value<uint32_t>(&ptr[20]);
+    for (int i = 0; i < 256; ++i)
+    {
+        const uint8_t *current_char = ptr + 24 + (6 * sizeof(uint16_t)) * i;
+        chars[i].dimensions.x = read_big_endian_value<int16_t>(current_char);
+        chars[i].dimensions.y = read_big_endian_value<int16_t>(current_char + 2);
+        chars[i].dimensions.width = read_big_endian_value<uint16_t>(current_char + 4);
+        chars[i].dimensions.height = read_big_endian_value<uint16_t>(current_char + 6);
+        chars[i].x_offset = read_big_endian_value<int16_t>(current_char + 8);
+        chars[i].y_offset = read_big_endian_value<int16_t>(current_char + 10);
+    }
 }
 
 Font::~Font()
@@ -47,39 +46,44 @@ 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);
-
+    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);
+    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);
+        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);
+        if (c == 32)
+        {
+            x += space_width;
+            continue;
+        }
+        draw(c, x, y, col);
         x += chars[c].dimensions.width + 1;
-
-  	}
-
+    }
 }
-

+ 30 - 29
src/render/Font.h

@@ -8,35 +8,36 @@
 
 namespace WalrusRPG
 {
-	namespace Font
-	{
-		struct CharacterParameters
-		{
-			// Sprite clip
-			WalrusRPG::Utils::Rect dimensions;
-			// Character rendering offset
-			int16_t x_offset, y_offset;
-		};
-
-		class Font
-		{
-
-		public:
-		 uint8_t baseline;
-		 uint8_t space_width;
-		 CharacterParameters chars[256];
-		 WalrusRPG::Graphics::Texture& font_tex;
-
-			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);
-
-		};
-	}
+    namespace Font
+    {
+        struct CharacterParameters
+        {
+            // Sprite clip
+            WalrusRPG::Utils::Rect dimensions;
+            // Character rendering offset
+            int16_t x_offset, y_offset;
+        };
+
+        class Font
+        {
+          public:
+            uint8_t baseline;
+            uint8_t space_width;
+            CharacterParameters chars[256];
+            WalrusRPG::Graphics::Texture &font_tex;
+
+            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);
+        };
+    }
 }
 
 #endif