[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Pingus-CVS] r2692 - in branches/pingus_sdl/src: . display
From: |
grumbel at BerliOS |
Subject: |
[Pingus-CVS] r2692 - in branches/pingus_sdl/src: . display |
Date: |
Thu, 18 Jan 2007 16:43:09 +0100 |
Author: grumbel
Date: 2007-01-18 16:43:08 +0100 (Thu, 18 Jan 2007)
New Revision: 2692
Modified:
branches/pingus_sdl/src/SConscript
branches/pingus_sdl/src/display/drawing_context.cpp
branches/pingus_sdl/src/display/drawing_context.hpp
branches/pingus_sdl/src/font.cpp
Log:
- implemented font support (resource files still missing)
- unlocked some DrawingContext stuff again
Modified: branches/pingus_sdl/src/SConscript
===================================================================
--- branches/pingus_sdl/src/SConscript 2007-01-18 14:36:19 UTC (rev 2691)
+++ branches/pingus_sdl/src/SConscript 2007-01-18 15:43:08 UTC (rev 2692)
@@ -22,7 +22,7 @@
env = Environment(# ENV = {'PKG_CONFIG_PATH' : os.getenv('PKG_CONFIG_PATH')},
CC = 'gcc',
- CCFLAGS = ['-O2', '-Wall', '-Werror', '-g'])
+ CCFLAGS = ['-O0', '-Wall', '-Werror', '-g'])
sdl_env = Environment(CC = 'gcc',
CCFLAGS = ['-O2', '-Wall', '-Werror', '-g'])
Modified: branches/pingus_sdl/src/display/drawing_context.cpp
===================================================================
--- branches/pingus_sdl/src/display/drawing_context.cpp 2007-01-18 14:36:19 UTC
(rev 2691)
+++ branches/pingus_sdl/src/display/drawing_context.cpp 2007-01-18 15:43:08 UTC
(rev 2692)
@@ -74,51 +74,33 @@
}
};
-#if 0
class FillScreenDrawingRequest : public DrawingRequest
{
private:
- CL_Color color;
+ Color color;
public:
- FillScreenDrawingRequest(const CL_Color& color_)
+ FillScreenDrawingRequest(const Color& color_)
: DrawingRequest(Vector3f(0, 0, -1000.0f)), color(color_)
{
}
virtual ~FillScreenDrawingRequest() {}
- void draw(CL_GraphicContext* gc) {
- gc->clear(color);
+ void draw(SDL_Surface* target) {
+ SDL_FillRect(target, NULL, SDL_MapRGB(target->format, color.r, color.g,
color.b));
}
};
-class SurfaceDrawingRequest : public DrawingRequest
-{
-private:
- CL_Surface sprite;
-
-public:
- SurfaceDrawingRequest(const CL_Surface& sprite_, const Vector3f& pos_)
- : DrawingRequest(pos_),
- sprite(sprite_)
- {}
- virtual ~SurfaceDrawingRequest() {}
-
- void draw(CL_GraphicContext* gc) {
- sprite.draw(pos.x, pos.y, gc);
- }
-};
-
class LineDrawingRequest : public DrawingRequest
{
private:
- Vector pos1;
- Vector pos2;
- CL_Color color;
+ Vector2i pos1;
+ Vector2i pos2;
+ Color color;
public:
- LineDrawingRequest(const Vector& pos1_,
- const Vector& pos2_,
- const CL_Color& color_,
+ LineDrawingRequest(const Vector2i& pos1_,
+ const Vector2i& pos2_,
+ const Color& color_,
float z)
: DrawingRequest(Vector3f(0, 0, z)),
pos1(pos1_),
@@ -127,32 +109,36 @@
{
}
- void draw(CL_GraphicContext* gc)
+ void draw(SDL_Surface* target)
{
- gc->draw_line(pos1.x, pos1.y, pos2.x, pos2.y,
- color);
+ ////gc->draw_line(pos1.x, pos1.y, pos2.x, pos2.y,
+ ////color);
}
};
class RectDrawingRequest : public DrawingRequest
{
private:
- CL_Rectf rect;
- CL_Color color;
- bool filled;
+ Rect rect;
+ Color color;
+ bool filled;
public:
- RectDrawingRequest(const CL_Rectf& rect_, const CL_Color& color_, bool
filled_, float z)
+ RectDrawingRequest(const Rect& rect_, const Color& color_, bool filled_,
float z)
: DrawingRequest(Vector3f(rect.left, rect.top, z)),
rect(rect_), color(color_), filled(filled_)
{}
- void draw(CL_GraphicContext* gc)
+ void draw(SDL_Surface* target)
{
if (filled)
- gc->fill_rect(rect, color);
+ {
+ Display::fill_rect(rect, color);
+ }
else
- gc->draw_rect(rect, color);
+ {
+ Display::draw_rect(rect, color);
+ }
}
};
@@ -167,12 +153,11 @@
{}
virtual ~TextDrawingRequest() {}
- void draw(CL_GraphicContext* gc) {
+ void draw(SDL_Surface* target) {
// FIXME: not implemented
}
};
-#endif
class DrawingContextDrawingRequest : public DrawingRequest
{
private:
@@ -246,17 +231,7 @@
draw(new DrawingContextDrawingRequest(dc, z));
}
-#if 0
void
-DrawingContext::draw(const CL_Surface& surface, const Vector& pos)
-{
- draw(new SurfaceDrawingRequest(surface, Vector3f(translate_stack.back().x +
pos.x,
- translate_stack.back().y +
pos.y,
- pos.z)));
-}
-#endif
-
-void
DrawingContext::draw(const Sprite& sprite, const Vector3f& pos)
{
draw(sprite, pos.x, pos.y, pos.z);
@@ -271,45 +246,39 @@
z)));
}
-#if 0
void
DrawingContext::draw(const std::string& text, float x, float y, float z)
{
draw(new TextDrawingRequest(text, Vector3f(x, y, z)));
}
-#endif
void
DrawingContext::draw_line (float x1, float y1, float x2, float y2,
const Color& color, float z)
{
- //// draw(new LineDrawingRequest(Vector(x1, y1), Vector(x2, y2), color, z));
+ draw(new LineDrawingRequest(Vector2i(int(x1), int(y1)), Vector2i(int(x2),
int(y2)), color, z));
}
void
DrawingContext::draw_fillrect (float x1, float y1, float x2, float y2,
const Color& color, float z)
{
-#if 0
- draw(new RectDrawingRequest(CL_Rectf(x1 + translate_stack.back().x, y1 +
translate_stack.back().y,
- x2 + translate_stack.back().x, y2 +
translate_stack.back().y),
+ draw(new RectDrawingRequest(Rect(int(x1 + translate_stack.back().x), int(y1
+ translate_stack.back().y),
+ int(x2 + translate_stack.back().x), int(y2
+ translate_stack.back().y)),
color,
true,
z));
-#endif
}
void
DrawingContext::draw_rect (float x1, float y1, float x2, float y2,
const Color& color, float z)
{
-#if 0
- draw(new RectDrawingRequest(CL_Rectf(x1 + translate_stack.back().x, y1 +
translate_stack.back().y,
- x2 + translate_stack.back().x, y2 +
translate_stack.back().y),
+ draw(new RectDrawingRequest(Rect(int(x1 + translate_stack.back().x), int(y1
+ translate_stack.back().y),
+ int(x2 + translate_stack.back().x), int(y2
+ translate_stack.back().y)),
color,
false,
z));
-#endif
}
void
@@ -335,7 +304,7 @@
void
DrawingContext::fill_screen(const Color& color)
{
- //// draw(new FillScreenDrawingRequest(color));
+ draw(new FillScreenDrawingRequest(color));
}
void
Modified: branches/pingus_sdl/src/display/drawing_context.hpp
===================================================================
--- branches/pingus_sdl/src/display/drawing_context.hpp 2007-01-18 14:36:19 UTC
(rev 2691)
+++ branches/pingus_sdl/src/display/drawing_context.hpp 2007-01-18 15:43:08 UTC
(rev 2692)
@@ -76,8 +76,6 @@
void draw(const std::string& text, float x, float y, float z = 0);
- ////void draw(const CL_Surface& surface, const Vector& pos);
-
void draw_line (float x1, float y1, float x2, float y2,
const Color& color, float z = 0);
void draw_fillrect (float x1, float y1, float x2, float y2,
Modified: branches/pingus_sdl/src/font.cpp
===================================================================
--- branches/pingus_sdl/src/font.cpp 2007-01-18 14:36:19 UTC (rev 2691)
+++ branches/pingus_sdl/src/font.cpp 2007-01-18 15:43:08 UTC (rev 2692)
@@ -24,6 +24,7 @@
*/
#include <iostream>
+#include <vector>
#include "SDL.h"
#include "SDL_image.h"
#include "font.hpp"
@@ -34,7 +35,7 @@
for(int y = 0; y < surface->h; ++y)
{
- const Uint8& p = pixels[surface->pitch * y +
x*surface->format->BytesPerPixel];
+ const Uint8& p = pixels[surface->pitch*y +
x*surface->format->BytesPerPixel];
if (p > threshold)
{
return false;
@@ -47,31 +48,62 @@
{
public:
SDL_Surface* surface;
-
+ SDL_Rect chrs[256];
+ int spacing;
+
FontImpl(const std::string& name)
+ : surface(0),
+ spacing(20)
{
+ for(int i = 0; i < 256; ++i)
+ chrs[i].x = chrs[i].y = chrs[i].w = chrs[i].h = 0;
+
std::cout << "Font: Trying to load: " << name << std::endl;
- surface = IMG_Load(name.c_str());
+ surface = IMG_Load("data/images/fonts/chalk_large-iso-8859-1.png");
//name.c_str());
assert(surface);
SDL_LockSurface(surface);
- int last_empty = 0;
+ std::string characters =
"!\"#$%&'()*+,-./0123456789:;<=>address@hidden|}~�����������������������������������������������������������������������������������������������";
+ std::cout << "Surface: " << surface->w << std::endl;
+ int first = -1; // -1 signals no character start found yet
int chr = 0;
for(int x = 0; x < surface->w; ++x)
{
+ ///std::cout << x << " " << surface->w << std::endl;
if (vline_empty(surface, x, 0))
{
- if (x != last_empty + 1)
+ if (first != -1) // skipping empty space
{
- std::cout << chr << " Empty: " << last_empty << " - " << x <<
std::endl;
+ if (chr < int(characters.size()))
+ {
+ std::cout << chr << " " << characters[chr]
+ << " Empty: " << first << " - " << x <<
std::endl;
+
+ SDL_Rect& rect = chrs[static_cast<unsigned
char>(characters[chr])];
+ rect.x = first;
+ rect.y = 0;
+ rect.w = x - first;
+ rect.h = surface->h;
+ }
+ else
+ std::cout << "Error: Found more characters then are mapped"
<< std::endl;
+
chr += 1;
+
+ first = -1;
}
- last_empty = x;
}
+ else
+ {
+ if (first == -1) // found the start of a character
+ first = x;
+ }
}
+ std::cout << "Font: Found " << chr << " expected " << characters.size()
<< std::endl;
SDL_UnlockSurface(surface);
+ std::cout << "Font created successfully" << std::endl;
}
~FontImpl()
@@ -79,9 +111,31 @@
SDL_FreeSurface(surface);
}
- void draw(int, int, const std::string& text, SDL_Surface* target)
+ void draw(int x, int y, const std::string& text, SDL_Surface* target)
{
-
+ SDL_Rect dstrect;
+ dstrect.x = x;
+ dstrect.y = y;
+ for(std::string::size_type i = 0; i < text.size(); ++i)
+ {
+ if (text[i] == ' ')
+ {
+ dstrect.x += spacing;
+ }
+ else
+ {
+ SDL_Rect& srcrect = chrs[static_cast<unsigned char>(text[i])];
+ if (srcrect.w != 0 && srcrect.h != 0)
+ {
+ SDL_BlitSurface(surface, &srcrect, target, &dstrect);
+ dstrect.x += srcrect.w + 1;
+ }
+ else
+ {
+ std::cout << "Font: character " << static_cast<unsigned
char>(text[i]) << " missing in font" << std::endl;
+ }
+ }
+ }
}
void set_alignment(Origin origin)
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Pingus-CVS] r2692 - in branches/pingus_sdl/src: . display,
grumbel at BerliOS <=