pingus-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Pingus-CVS] r2793 - in branches/pingus_sdl: data/images/fonts data/leve


From: grumbel at BerliOS
Subject: [Pingus-CVS] r2793 - in branches/pingus_sdl: data/images/fonts data/levels/test src
Date: Sat, 4 Aug 2007 16:56:21 +0200

Author: grumbel
Date: 2007-08-04 16:56:20 +0200 (Sat, 04 Aug 2007)
New Revision: 2793

Added:
   branches/pingus_sdl/data/images/fonts/number_fnt.font
Modified:
   branches/pingus_sdl/data/images/fonts/number_fnt.png
   branches/pingus_sdl/data/levels/test/rotation.pingus
   branches/pingus_sdl/src/font.cpp
   branches/pingus_sdl/src/font_description.cpp
   branches/pingus_sdl/src/font_description.hpp
   branches/pingus_sdl/src/fonts.cpp
Log:
- fixed off-by-one font error
- enabled number_fnt again (works, but not monospace like it should)


Added: branches/pingus_sdl/data/images/fonts/number_fnt.font
===================================================================
--- branches/pingus_sdl/data/images/fonts/number_fnt.font       2007-08-04 
14:17:18 UTC (rev 2792)
+++ branches/pingus_sdl/data/images/fonts/number_fnt.font       2007-08-04 
14:56:20 UTC (rev 2793)
@@ -0,0 +1,9 @@
+;; -*- scheme -*-
+(pingus-font
+ (name "LCD")
+ (space-length    9)
+ (alpha-threshold  0)
+ (characters "0123456789:")
+ (image "data/images/fonts/number_fnt.png"))
+
+;; EOF ;;

Modified: branches/pingus_sdl/data/images/fonts/number_fnt.png
===================================================================
--- branches/pingus_sdl/data/images/fonts/number_fnt.png        2007-08-04 
14:17:18 UTC (rev 2792)
+++ branches/pingus_sdl/data/images/fonts/number_fnt.png        2007-08-04 
14:56:20 UTC (rev 2793)
@@ -1,6 +1,5 @@
 �PNG
 
-
-w �vα8j ��I�wj�j���
-���;a��v��\,���޿a�R�n��
-��n3�L/*��;s�������yR�&��#��T�
\ No newline at end of file
+
+A�B�x��ڢ�<7_�Tu�4^�^�8��:w����~}}��>'ջ7�Q��#�vkN^m��^sR���̥�:�$��
+��R���$�����*�ύ�.P�*�I��;�:�J�o]=�՛�=���қ�*����*��x����:address@hidden
\ No newline at end of file

Modified: branches/pingus_sdl/data/levels/test/rotation.pingus
===================================================================
--- branches/pingus_sdl/data/levels/test/rotation.pingus        2007-08-04 
14:17:18 UTC (rev 2792)
+++ branches/pingus_sdl/data/levels/test/rotation.pingus        2007-08-04 
14:56:20 UTC (rev 2793)
@@ -1,151 +1,136 @@
 <?xml version="1.0"  encoding="ISO-8859-1"?>
 
 <pingus-level>
-  <global>
+  <head>
     <levelname lang="en">EditorDefaultValue: Please give me a 
name...</levelname>
     <description lang="en">EditorDefaultValue: ...and a short 
description</description>
     <author>Ingo Ruhnke &lt;address@hidden&gt;</author>
     <number-of-pingus>50</number-of-pingus>
     <number-to-save>25</number-to-save>
     <time>-1</time>
-    <width>1024</width>
-    <height>768</height>
+    <levelsize>
+      <width>1024</width>
+      <height>768</height>
+    </levelsize>
     <difficulty>40</difficulty>
     <playable>0</playable>
     <comment></comment>
     <music>none</music>
-  </global>
+  </head>
+  <objects>
+    <groundpiece>
+      <type>ground</type>
+      <surface>
+        <image>signposts/danger</image>
+        <modifier>ROT0</modifier>
+      </surface>
+      <position>
+        <x>215</x>
+        <y>162</y>
+        <z>0</z>
+      </position>
+    </groundpiece>
 
-  <action-list>
-     </action-list>
+    <groundpiece>
+      <type>ground</type>
+      <surface>
+        <image>signposts/danger</image>
+        <modifier>ROT0</modifier>
+      </surface>
+      <position>
+        <x>366</x>
+        <y>260</y>
+        <z>0</z>
+      </position>
+    </groundpiece>
 
-<worldobj type="groundpiece">
-  <type>ground</type>
-  <surface><resource type="datafile">
-    <resource-datafile>groundpieces-ground</resource-datafile>
-  <resource-ident>signposts/danger</resource-ident>
-    <modifier>ROT0</modifier>
-  </resource></surface>
-  <position>
-    <x-pos>215</x-pos>
-    <y-pos>162</y-pos>
-    <z-pos>0</z-pos>
-  </position>
-</worldobj>
+    <groundpiece>
+      <type>ground</type>
+      <surface>
+        <image>signposts/danger</image>
+        <modifier>ROT180</modifier>
+      </surface>
+      <position>
+        <x>195</x>
+        <y>433</y>
+        <z>0</z>
+      </position>
+    </groundpiece>
 
-<worldobj type="groundpiece">
-  <type>ground</type>
-  <surface><resource type="datafile">
-    <resource-datafile>groundpieces-ground</resource-datafile>
-  <resource-ident>signposts/danger</resource-ident>
-    <modifier>ROT90</modifier>
-  </resource></surface>
-  <position>
-    <x-pos>366</x-pos>
-    <y-pos>260</y-pos>
-    <z-pos>0</z-pos>
-  </position>
-</worldobj>
+    <groundpiece>
+      <type>ground</type>
+      <surface>
+        <image>signposts/danger</image>
+        <modifier>ROT270</modifier>
+      </surface>
+      <position>
+        <x>116</x>
+        <y>247</y>
+        <z>0</z>
+      </position>
+    </groundpiece>
 
-<worldobj type="groundpiece">
-  <type>ground</type>
-  <surface><resource type="datafile">
-    <resource-datafile>groundpieces-ground</resource-datafile>
-  <resource-ident>signposts/danger</resource-ident>
-    <modifier>ROT180</modifier>
-  </resource></surface>
-  <position>
-    <x-pos>195</x-pos>
-    <y-pos>433</y-pos>
-    <z-pos>0</z-pos>
-  </position>
-</worldobj>
+    <groundpiece>
+      <type>ground</type>
+      <surface>
+        <image>signposts/danger</image>
+        <modifier>ROT0FLIP</modifier>
+      </surface>
+      <position>
+        <x>638</x>
+        <y>174</y>
+        <z>0</z>
+      </position>
+    </groundpiece>
 
-<worldobj type="groundpiece">
-  <type>ground</type>
-  <surface><resource type="datafile">
-    <resource-datafile>groundpieces-ground</resource-datafile>
-  <resource-ident>signposts/danger</resource-ident>
-    <modifier>ROT270</modifier>
-  </resource></surface>
-  <position>
-    <x-pos>116</x-pos>
-    <y-pos>247</y-pos>
-    <z-pos>0</z-pos>
-  </position>
-</worldobj>
+    <groundpiece>
+      <type>ground</type>
+      <surface>
+        <image>signposts/danger</image>
+        <modifier>ROT90FLIP</modifier>
+      </surface>
+      <position>
+        <x>789</x>
+        <y>272</y>
+        <z>0</z>
+      </position>
+    </groundpiece>
 
-<worldobj type="groundpiece">
-  <type>ground</type>
-  <surface><resource type="datafile">
-    <resource-datafile>groundpieces-ground</resource-datafile>
-  <resource-ident>signposts/danger</resource-ident>
-    <modifier>ROT0FLIP</modifier>
-  </resource></surface>
-  <position>
-    <x-pos>638</x-pos>
-    <y-pos>174</y-pos>
-    <z-pos>0</z-pos>
-  </position>
-</worldobj>
+    <groundpiece>
+      <type>ground</type>
+      <surface>
+        <image>signposts/danger</image>
+        <modifier>ROT180FLIP</modifier>
+      </surface>
+      <position>
+        <x>618</x>
+        <y>445</y>
+        <z>0</z>
+      </position>
+    </groundpiece>
 
-<worldobj type="groundpiece">
-  <type>ground</type>
-  <surface><resource type="datafile">
-    <resource-datafile>groundpieces-ground</resource-datafile>
-  <resource-ident>signposts/danger</resource-ident>
-    <modifier>ROT90FLIP</modifier>
-  </resource></surface>
-  <position>
-    <x-pos>789</x-pos>
-    <y-pos>272</y-pos>
-    <z-pos>0</z-pos>
-  </position>
-</worldobj>
+    <groundpiece>
+      <type>ground</type>
+      <surface>
+        <image>signposts/danger</image>
+        <modifier>ROT270FLIP</modifier>
+      </surface>
+      <position>
+        <x>531</x>
+        <y>261</y>
+        <z>0</z>
+      </position>
+    </groundpiece>
 
-<worldobj type="groundpiece">
-  <type>ground</type>
-  <surface><resource type="datafile">
-    <resource-datafile>groundpieces-ground</resource-datafile>
-  <resource-ident>signposts/danger</resource-ident>
-    <modifier>ROT180FLIP</modifier>
-  </resource></surface>
-  <position>
-    <x-pos>618</x-pos>
-    <y-pos>445</y-pos>
-    <z-pos>0</z-pos>
-  </position>
-</worldobj>
+    <solidcolor-background>
+      <color>
+        <red>0</red>
+        <green>0</green>
+        <blue>0</blue>
+        <alpha>1</alpha>
+      </color>
+    </solidcolor-background>
 
-<worldobj type="groundpiece">
-  <type>ground</type>
-  <surface><resource type="datafile">
-    <resource-datafile>groundpieces-ground</resource-datafile>
-  <resource-ident>signposts/danger</resource-ident>
-    <modifier>ROT270FLIP</modifier>
-  </resource></surface>
-  <position>
-    <x-pos>531</x-pos>
-    <y-pos>261</y-pos>
-    <z-pos>0</z-pos>
-  </position>
-</worldobj>
-
-<worldobj type="solidcolor-background">
-<color>
-  <red>0</red>
-  <green>0</green>
-  <blue>0</blue>
-  <alpha>1</alpha>
-</color>
-</worldobj>
-  <start-position>
-  <position>
-    <x-pos>484</x-pos>
-    <y-pos>343</y-pos>
-    <z-pos>1000</z-pos>
-  </position>
-  </start-position>
-
+  </objects>
 </pingus-level>
 

Modified: branches/pingus_sdl/src/font.cpp
===================================================================
--- branches/pingus_sdl/src/font.cpp    2007-08-04 14:17:18 UTC (rev 2792)
+++ branches/pingus_sdl/src/font.cpp    2007-08-04 14:56:20 UTC (rev 2793)
@@ -63,25 +63,42 @@
     for(int i = 0; i < 256; ++i)
       chrs[i].x = chrs[i].y = chrs[i].w = chrs[i].h = 0;
 
+    // FIXME: Need monospace support
     surface = IMG_Load(desc.image.c_str());
     assert(surface);
-
+    if (surface->format->BitsPerPixel != 32)
+      {
+        std::cout << "Error: '" << desc.filename << "' invalid, fonts need to 
be RGBA, but is "
+                  << surface->format->BitsPerPixel << "bpp" << std::endl;
+        assert(0);
+      }
+        
     SDL_LockSurface(surface);
     
-    //std::cout << "Surface: " << surface->w << std::endl;
     int first = -1; // -1 signals no character start found yet
     int idx = 0;
     for(int x = 0; x < surface->w; ++x)
       {
-        ///std::cout << x << " " << surface->w << std::endl;
-        if (vline_empty(surface, x, desc.alpha_threshold))
-          {
-            if (first != -1) // skipping empty space
+        if (!vline_empty(surface, x, desc.alpha_threshold))
+          { // line contains a character
+            if (first == -1) 
+              { // found the start of a character
+                first = x;
+              } 
+            else 
               {
+                // do nothing and continue to search for an end
+              }
+          }
+        else
+          { // line doesn't contain a character
+            if (first != -1) 
+              { // we have a start and a end, so lets construct a char
+
                 if (idx < int(desc.characters.size()))
                   {
-                    //std::cout << idx << " " << desc.characters[idx]
-                    //<< " Empty: " << first << " - " << x << std::endl;
+                    std::cout << idx << " '" << desc.characters[idx] << "' " 
+                              <<  " glyph: " << first << " - " << x << 
std::endl;
 
                     SDL_Rect& rect = chrs[static_cast<unsigned 
char>(desc.characters[idx])];
                     rect.x = first;
@@ -90,23 +107,20 @@
                     rect.h = surface->h;
                   }
                 else
-                  std::cout << "Error: Found more desc.characters then are 
mapped" << std::endl;
+                  {
+                    std::cout << "Error: Found more desc.characters then are 
mapped" << std::endl;
+                  }
 
                 idx += 1;
                 first = -1;
               }
           }
-        else
-          {
-            if (first == -1) // found the start of a character
-              first = x;
-          }
       }
     
-    if (idx-1 != int(desc.characters.size())) // FIXME: is that -1 correct?!
+    if (idx != int(desc.characters.size())) 
       {
         std::cout << "Font: " << desc.image << "\n"
-                  << "  Error: " << idx-1 << " expected "  << 
desc.characters.size() << "\n"
+                  << "  Error: " << idx << " expected "  << 
desc.characters.size() << "\n"
                   << "  Format: bpp: " << int(surface->format->BitsPerPixel) 
<< "\n"
                   << "  Size: " << surface->w << "x" << surface->h
           //      << "  RMask: " << hex << surface->format->Rmask << "\n"
@@ -117,7 +131,6 @@
       }
 
     SDL_UnlockSurface(surface);
-    //std::cout << "Font created successfully" << std::endl;
   }
 
   ~FontImpl()
@@ -132,7 +145,6 @@
     int dstx = x - offset.x;
     int dsty = y - offset.y;
 
-
     for(std::string::size_type i = 0; i < text.size(); ++i)
       {
         if (text[i] == ' ')

Modified: branches/pingus_sdl/src/font_description.cpp
===================================================================
--- branches/pingus_sdl/src/font_description.cpp        2007-08-04 14:17:18 UTC 
(rev 2792)
+++ branches/pingus_sdl/src/font_description.cpp        2007-08-04 14:56:20 UTC 
(rev 2793)
@@ -27,19 +27,23 @@
 #include "file_reader.hpp"
 #include "font_description.hpp"
 
-FontDescription::FontDescription(const std::string& filename)
+FontDescription::FontDescription(const std::string& filename_)
+  : filename(filename_)
 {
+  name            = "<unknown>";
   space_length    = 20;
   alpha_threshold = 0;
 
   FileReader reader = FileReader::parse(filename);
 
+  // FIXME: We need support for monospace fonts
   if (reader.get_name() != "pingus-font")
     {
       PingusError::raise("FontDescription: not a pingus-font file");
     }
   else
     {
+      reader.read_string("name",         name);
       reader.read_string("image",        image);
       reader.read_string("characters",   characters);
       reader.read_int("space-length",    space_length);

Modified: branches/pingus_sdl/src/font_description.hpp
===================================================================
--- branches/pingus_sdl/src/font_description.hpp        2007-08-04 14:17:18 UTC 
(rev 2792)
+++ branches/pingus_sdl/src/font_description.hpp        2007-08-04 14:56:20 UTC 
(rev 2793)
@@ -30,6 +30,9 @@
 class FontDescription
 {
 public:
+  std::string filename;
+  std::string name;
+
   /** Image file from which the basic surface is loaded */
   std::string image;
 

Modified: branches/pingus_sdl/src/fonts.cpp
===================================================================
--- branches/pingus_sdl/src/fonts.cpp   2007-08-04 14:17:18 UTC (rev 2792)
+++ branches/pingus_sdl/src/fonts.cpp   2007-08-04 14:56:20 UTC (rev 2793)
@@ -56,7 +56,7 @@
   smallfont    = Resource::load_font("fonts/courier_small" + std::string("-") 
+ encoding); //PingusResource::load_font("Fonts/smallfont","fonts");
   smallfont_h  = Resource::load_font("fonts/courier_small" + std::string("-") 
+ encoding); // PingusResource::load_font("Fonts/smallfont_h","fonts");
 
-  lcd          = Resource::load_font("fonts/courier_small" + std::string("-") 
+ encoding); // PingusResource::load_font("Fonts/numbers", "fonts");
+  lcd          = Resource::load_font("fonts/number_fnt");
 }
 
 void deinit () 





reply via email to

[Prev in Thread] Current Thread [Next in Thread]