[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Pingus-CVS] r2691 - branches/pingus_sdl/src
From: |
grumbel at BerliOS |
Subject: |
[Pingus-CVS] r2691 - branches/pingus_sdl/src |
Date: |
Thu, 18 Jan 2007 15:36:20 +0100 |
Author: grumbel
Date: 2007-01-18 15:36:19 +0100 (Thu, 18 Jan 2007)
New Revision: 2691
Modified:
branches/pingus_sdl/src/font.cpp
branches/pingus_sdl/src/font.hpp
branches/pingus_sdl/src/fonts.cpp
branches/pingus_sdl/src/resource.cpp
branches/pingus_sdl/src/shared_ptr.hpp
Log:
- some work on the font class
Modified: branches/pingus_sdl/src/font.cpp
===================================================================
--- branches/pingus_sdl/src/font.cpp 2007-01-18 12:53:19 UTC (rev 2690)
+++ branches/pingus_sdl/src/font.cpp 2007-01-18 14:36:19 UTC (rev 2691)
@@ -23,12 +23,151 @@
** 02111-1307, USA.
*/
+#include <iostream>
+#include "SDL.h"
+#include "SDL_image.h"
#include "font.hpp"
+static bool vline_empty(SDL_Surface* surface, int x, Uint8 threshold)
+{
+ Uint8* pixels = (Uint8*)surface->pixels;
+
+ for(int y = 0; y < surface->h; ++y)
+ {
+ const Uint8& p = pixels[surface->pitch * y +
x*surface->format->BytesPerPixel];
+ if (p > threshold)
+ {
+ return false;
+ }
+ }
+ return true;
+}
+
+class FontImpl
+{
+public:
+ SDL_Surface* surface;
+
+ FontImpl(const std::string& name)
+ {
+ std::cout << "Font: Trying to load: " << name << std::endl;
+ surface = IMG_Load(name.c_str());
+ assert(surface);
+
+ SDL_LockSurface(surface);
+
+ int last_empty = 0;
+ int chr = 0;
+ for(int x = 0; x < surface->w; ++x)
+ {
+ if (vline_empty(surface, x, 0))
+ {
+ if (x != last_empty + 1)
+ {
+ std::cout << chr << " Empty: " << last_empty << " - " << x <<
std::endl;
+ chr += 1;
+ }
+ last_empty = x;
+ }
+ }
+
+ SDL_UnlockSurface(surface);
+ }
+
+ ~FontImpl()
+ {
+ SDL_FreeSurface(surface);
+ }
+
+ void draw(int, int, const std::string& text, SDL_Surface* target)
+ {
+
+ }
+
+ void set_alignment(Origin origin)
+ {
+
+ }
+
+ int get_height()
+ {
+ return 0;
+ }
+
+ int get_width(char)
+ {
+ return 0;
+ }
+
+ Size get_size(const std::string& str)
+ {
+ return Size();
+ }
+
+ Rect bounding_rect(int , int, const std::string& str) const
+ {
+ return Rect();
+ }
+};
+
+Font::Font()
+ : impl(0)
+{
+}
+
+Font::Font(const std::string& name)
+ : impl(new FontImpl(name))
+{
+}
+
+void
+Font::draw(int x, int y, const std::string& text, SDL_Surface* target)
+{
+ if (impl)
+ impl->draw(x,y,text, target);
+}
+
+void
+Font::set_alignment(Origin origin)
+{
+ if (impl)
+ impl->set_alignment(origin);
+}
+
+int
+Font::get_height()
+{
+ if (impl)
+ return impl->get_height();
+ else
+ return 0;
+}
+
+int
+Font::get_width(char c)
+{
+ if (impl)
+ return impl->get_width(c);
+ else
+ return 0;
+}
+
+Size
+Font::get_size(const std::string& str)
+{
+ if (impl)
+ return impl->get_size(str);
+ else
+ return Size();
+}
+
Rect
-Font::bounding_rect(int, int, const std::string& str) const
+Font::bounding_rect(int x, int y, const std::string& str) const
{
- return Rect();
+ if (impl)
+ return impl->bounding_rect(x, y, str);
+ else
+ return Rect();
}
/* EOF */
Modified: branches/pingus_sdl/src/font.hpp
===================================================================
--- branches/pingus_sdl/src/font.hpp 2007-01-18 12:53:19 UTC (rev 2690)
+++ branches/pingus_sdl/src/font.hpp 2007-01-18 14:36:19 UTC (rev 2691)
@@ -31,19 +31,26 @@
#include "math/origin.hpp"
#include "math/rect.hpp"
#include "math/size.hpp"
+#include "shared_ptr.hpp"
+class FontImpl;
+
/** */
class Font
{
-private:
public:
- Font() {}
- void draw(int, int, const std::string& text, SDL_Surface* target = 0) {}
- void set_alignment(Origin origin) {}
- int get_height() { return 0; }
- int get_width(char) { return 0; }
- Size get_size(const std::string& str) { return Size(0,0);}
+ Font();
+ Font(const std::string& name);
+
+ void draw(int, int, const std::string& text, SDL_Surface* target = 0);
+ void set_alignment(Origin origin);
+ int get_height();
+ int get_width(char);
+ Size get_size(const std::string& str);
Rect bounding_rect(int , int, const std::string& str) const;
+
+private:
+ SharedPtr<FontImpl> impl;
};
#endif
Modified: branches/pingus_sdl/src/fonts.cpp
===================================================================
--- branches/pingus_sdl/src/fonts.cpp 2007-01-18 12:53:19 UTC (rev 2690)
+++ branches/pingus_sdl/src/fonts.cpp 2007-01-18 14:36:19 UTC (rev 2691)
@@ -22,7 +22,8 @@
namespace Fonts {
-std::string encoding("ISO-8859-1");
+////std::string encoding("ISO-8859-1");
+std::string encoding("iso-8859-1");
Font chalk_large;
Font chalk_normal;
@@ -42,20 +43,20 @@
void
init ()
{
- chalk_large = Resource::load_font("fonts/chalk_large" + std::string(".") +
encoding);
- chalk_normal = Resource::load_font("fonts/chalk_normal" + std::string(".") +
encoding);
- chalk_small = Resource::load_font("fonts/chalk_small" + std::string(".") +
encoding);
+ chalk_large = Resource::load_font("fonts/chalk_large" + std::string("-") +
encoding);
+ chalk_normal = Resource::load_font("fonts/chalk_normal" + std::string("-") +
encoding);
+ chalk_small = Resource::load_font("fonts/chalk_small" + std::string("-") +
encoding);
- pingus_small = Resource::load_font("fonts/pingus_small" + std::string(".") +
encoding);
- pingus_small_fix_num = Resource::load_font("fonts/pingus_small_fix_num" +
std::string(".") + encoding);
- pingus_large = Resource::load_font("fonts/pingus" + std::string(".") +
encoding);
+ pingus_small = Resource::load_font("fonts/pingus_small" + std::string("-") +
encoding);
+ pingus_small_fix_num = Resource::load_font("fonts/pingus_small_fix_num" +
std::string("-") + encoding);
+ pingus_large = Resource::load_font("fonts/pingus" + std::string("-") +
encoding);
- courier_small = Resource::load_font("fonts/courier_small" + std::string(".")
+ encoding);
- xterm = Resource::load_font("fonts/courier_small" + std::string(".")
+ encoding);
- 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");
+ courier_small = Resource::load_font("fonts/courier_small" + std::string("-")
+ encoding);
+ xterm = Resource::load_font("fonts/courier_small" + std::string("-")
+ encoding);
+ 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/courier_small" + std::string("-")
+ encoding); // PingusResource::load_font("Fonts/numbers", "fonts");
}
void deinit ()
Modified: branches/pingus_sdl/src/resource.cpp
===================================================================
--- branches/pingus_sdl/src/resource.cpp 2007-01-18 12:53:19 UTC (rev
2690)
+++ branches/pingus_sdl/src/resource.cpp 2007-01-18 14:36:19 UTC (rev
2691)
@@ -313,7 +313,7 @@
Resource::load_font(const std::string& res_name)
{
////return Font(res_name, &resmgr);
- return Font();
+ return Font("data/images/" + res_name + ".png");
}
void
Modified: branches/pingus_sdl/src/shared_ptr.hpp
===================================================================
--- branches/pingus_sdl/src/shared_ptr.hpp 2007-01-18 12:53:19 UTC (rev
2690)
+++ branches/pingus_sdl/src/shared_ptr.hpp 2007-01-18 14:36:19 UTC (rev
2691)
@@ -44,6 +44,8 @@
T const* operator->() const { assert(ptr); return ptr; }
T* get() const { return ptr; }
+
+ operator bool() const { return ptr; }
};
#endif
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Pingus-CVS] r2691 - branches/pingus_sdl/src,
grumbel at BerliOS <=