[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Pingus-CVS] r3096 - in trunk/pingus/src: display gui
From: |
grumbel at BerliOS |
Subject: |
[Pingus-CVS] r3096 - in trunk/pingus/src: display gui |
Date: |
Thu, 6 Sep 2007 18:12:02 +0200 |
Author: grumbel
Date: 2007-09-06 18:12:02 +0200 (Thu, 06 Sep 2007)
New Revision: 3096
Modified:
trunk/pingus/src/display/drawing_context.cpp
trunk/pingus/src/display/drawing_context.hpp
trunk/pingus/src/display/drawing_request.hpp
trunk/pingus/src/display/scene_context.cpp
trunk/pingus/src/display/scene_context.hpp
trunk/pingus/src/gui/screen_manager.cpp
Log:
- added way to have DrawingContext smaller then the screen
Modified: trunk/pingus/src/display/drawing_context.cpp
===================================================================
--- trunk/pingus/src/display/drawing_context.cpp 2007-09-06 01:56:21 UTC
(rev 3095)
+++ trunk/pingus/src/display/drawing_context.cpp 2007-09-06 16:12:02 UTC
(rev 3096)
@@ -27,14 +27,14 @@
#include "../font.hpp"
#include "../math/origin.hpp"
-
+
struct DrawingRequestsSorter
{
bool operator()(DrawingRequest* a, DrawingRequest* b) {
return a->get_z_pos() < b->get_z_pos();
}
};
-
+
class FontDrawingRequest : public DrawingRequest
{
private:
@@ -54,11 +54,11 @@
virtual ~FontDrawingRequest() {}
- void draw(SDL_Surface* target) {
- font.draw(origin, static_cast<int>(pos.x), static_cast<int>(pos.y), text,
target);
+ void render(SDL_Surface* target, const Rect& rect) {
+ font.draw(origin, static_cast<int>(pos.x + rect.left),
static_cast<int>(pos.y + rect.top), text, target);
}
};
-
+
class SpriteDrawingRequest : public DrawingRequest
{
private:
@@ -73,11 +73,11 @@
virtual ~SpriteDrawingRequest() {}
- void draw(SDL_Surface* target) {
- sprite.draw(pos.x, pos.y, target);
+ void render(SDL_Surface* target, const Rect& rect) {
+ sprite.draw(pos.x + rect.left, pos.y + rect.top, target);
}
};
-
+
class FillScreenDrawingRequest : public DrawingRequest
{
private:
@@ -89,11 +89,16 @@
}
virtual ~FillScreenDrawingRequest() {}
- void draw(SDL_Surface* target) {
- SDL_FillRect(target, NULL, SDL_MapRGB(target->format, color.r, color.g,
color.b));
+ void render(SDL_Surface* target, const Rect& rect) {
+ SDL_Rect r;
+ r.x = rect.left;
+ r.y = rect.top;
+ r.w = rect.get_width();
+ r.h = rect.get_height();
+ SDL_FillRect(target, &r, SDL_MapRGB(target->format, color.r, color.g,
color.b));
}
};
-
+
class LineDrawingRequest : public DrawingRequest
{
private:
@@ -113,54 +118,45 @@
{
}
- void draw(SDL_Surface* target)
+ void render(SDL_Surface* target, const Rect& rect)
{
- Display::draw_line(pos1, pos2, color);
+ Display::draw_line(pos1 + Vector2i(rect.left, rect.top),
+ pos2 + Vector2i(rect.left, rect.top), color);
}
};
-
+
class RectDrawingRequest : public DrawingRequest
{
private:
- Rect rect;
+ Rect d_rect;
Color color;
bool filled;
public:
RectDrawingRequest(const Rect& rect_, const Color& color_, bool filled_,
float z)
- : DrawingRequest(Vector3f((float)rect.left, (float)rect.top, z)),
- rect(rect_), color(color_), filled(filled_)
+ : DrawingRequest(Vector3f(0,0)),
+ d_rect(rect_), color(color_), filled(filled_)
{}
- void draw(SDL_Surface* target)
+ void render(SDL_Surface* target, const Rect& rect)
{
if (filled)
{
- Display::fill_rect(rect, color);
+ Display::fill_rect(Rect(Vector2i(d_rect.left + rect.left,
+ d_rect.top + rect.top),
+ d_rect.get_size()),
+ color);
}
else
{
- Display::draw_rect(rect, color);
+ Display::draw_rect(Rect(Vector2i(d_rect.left + rect.left,
+ d_rect.top + rect.top),
+ d_rect.get_size()),
+ color);
}
}
};
-
-class TextDrawingRequest : public DrawingRequest
-{
-private:
- std::string text;
-public:
- TextDrawingRequest(const std::string& text_, const Vector3f& pos_)
- : DrawingRequest(pos_),
- text(text_)
- {}
- virtual ~TextDrawingRequest() {}
-
- void draw(SDL_Surface* target) {
- // FIXME: not implemented
- }
-};
-
+
class DrawingContextDrawingRequest : public DrawingRequest
{
private:
@@ -177,12 +173,20 @@
delete dc;
}
- void draw(SDL_Surface* screen) {
- dc->render(screen);
+ void render(SDL_Surface* target, const Rect& rect) {
+ dc->render(target, rect);
}
};
+
+DrawingContext::DrawingContext(const Rect& rect_, bool clip)
+ : rect(rect_),
+ do_clipping(clip)
+{
+
+}
DrawingContext::DrawingContext()
+ : rect(0, 0, Display::get_width(), Display::get_height())
{
translate_stack.push_back(Vector3f(0, 0));
}
@@ -194,8 +198,16 @@
}
void
-DrawingContext::render(SDL_Surface* screen)
+DrawingContext::render(SDL_Surface* screen, const Rect& parent_rect)
{
+ Rect this_rect(Math::max(rect.left + parent_rect.left, parent_rect.left),
+ Math::max(rect.top + parent_rect.top, parent_rect.left),
+ Math::min(rect.right + parent_rect.left, parent_rect.right),
+ Math::min(rect.bottom + parent_rect.top,
parent_rect.bottom));
+
+ if (do_clipping)
+ Display::push_cliprect(this_rect);
+
std::stable_sort(drawingrequests.begin(), drawingrequests.end(),
DrawingRequestsSorter());
if (0)
@@ -208,8 +220,11 @@
for(DrawingRequests::iterator i = drawingrequests.begin(); i !=
drawingrequests.end(); ++i)
{
//std::cout << this << ": " << (*i)->get_z_pos() << std::endl;
- (*i)->draw(screen);
+ (*i)->render(screen, this_rect); // FIXME: Should we clip size against
parent rect?
}
+
+ if (do_clipping)
+ Display::pop_cliprect();
}
void
@@ -250,12 +265,6 @@
}
void
-DrawingContext::draw(const std::string& text, float x, float y, float z)
-{
- draw(new TextDrawingRequest(text, Vector3f(x, y, z)));
-}
-
-void
DrawingContext::draw_line (float x1, float y1, float x2, float y2,
const Color& color, float z)
{
@@ -357,16 +366,17 @@
static_cast<int>(-translate_stack.back().y)),
Size((int)get_width(), (int)get_height()));
}
+
float
DrawingContext::get_width() const
{
- return (float)Display::get_width();
+ return rect.get_width();
}
float
DrawingContext::get_height() const
{
- return (float)Display::get_height();
+ return rect.get_height();
}
void
Modified: trunk/pingus/src/display/drawing_context.hpp
===================================================================
--- trunk/pingus/src/display/drawing_context.hpp 2007-09-06 01:56:21 UTC
(rev 3095)
+++ trunk/pingus/src/display/drawing_context.hpp 2007-09-06 16:12:02 UTC
(rev 3096)
@@ -46,12 +46,18 @@
std::vector<Vector3f> translate_stack;
+ /** The rectangle that the DrawingContext uses on the screen */
+ Rect rect;
+
+ bool do_clipping;
+
public:
DrawingContext();
+ DrawingContext(const Rect& rect, bool clip = true);
virtual ~DrawingContext();
/** Draws everything in the drawing context to the screen */
- void render(SDL_Surface* screen);
+ void render(SDL_Surface* screen, const Rect& rect);
/** Empties the drawing context */
void clear();
@@ -73,8 +79,6 @@
queue */
void fill_screen(const Color& color);
- void draw(const std::string& text, float x, float y, float z = 0);
-
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: trunk/pingus/src/display/drawing_request.hpp
===================================================================
--- trunk/pingus/src/display/drawing_request.hpp 2007-09-06 01:56:21 UTC
(rev 3095)
+++ trunk/pingus/src/display/drawing_request.hpp 2007-09-06 16:12:02 UTC
(rev 3096)
@@ -22,6 +22,7 @@
#include "SDL.h"
#include "math/vector3f.hpp"
+#include "math/rect.hpp"
/**
*/
@@ -34,7 +35,7 @@
DrawingRequest(const Vector3f& pos_) : pos(pos_) {}
virtual ~DrawingRequest() {};
- virtual void draw(SDL_Surface* gc) = 0;
+ virtual void render(SDL_Surface* gc, const Rect& rect) = 0;
/** Returns true if the request contains an alpha channel and needs
to be drawn in order */
Modified: trunk/pingus/src/display/scene_context.cpp
===================================================================
--- trunk/pingus/src/display/scene_context.cpp 2007-09-06 01:56:21 UTC (rev
3095)
+++ trunk/pingus/src/display/scene_context.cpp 2007-09-06 16:12:02 UTC (rev
3096)
@@ -29,6 +29,7 @@
DrawingContext color;
DrawingContext light;
DrawingContext highlight;
+
Rect cliprect;
bool use_cliprect;
@@ -36,6 +37,14 @@
: use_cliprect(false)
{
}
+
+ SceneContextImpl(const Rect& rect)
+ : color(rect),
+ light(rect),
+ highlight(rect),
+ use_cliprect(false)
+ {
+ }
};
SceneContext::SceneContext()
@@ -43,6 +52,11 @@
impl = new SceneContextImpl();
}
+SceneContext::SceneContext(const Rect& rect)
+{
+ impl = new SceneContextImpl(rect);
+}
+
SceneContext::~SceneContext()
{
delete impl;
@@ -132,19 +146,19 @@
}
void
-SceneContext::render(SDL_Surface* target)
+SceneContext::render(SDL_Surface* target, const Rect& rect)
{
// Render all buffers
// FIXME: Render all to pbuffer for later combining of them
if (impl->use_cliprect)
{
Display::push_cliprect(impl->cliprect);
- impl->color.render(target);
+ impl->color.render(target, rect);
Display::pop_cliprect();
}
else
{
- impl->color.render(target);
+ impl->color.render(target, rect);
}
#if 0
@@ -161,7 +175,7 @@
}
#endif
- impl->highlight.render(target);
+ impl->highlight.render(target, rect);
}
void
@@ -184,9 +198,9 @@
}
void
-SceneContextDrawingRequest::draw(SDL_Surface* gc)
+SceneContextDrawingRequest::render(SDL_Surface* gc, const Rect& rect)
{
- sc->render(gc);
+ sc->render(gc, rect);
}
Modified: trunk/pingus/src/display/scene_context.hpp
===================================================================
--- trunk/pingus/src/display/scene_context.hpp 2007-09-06 01:56:21 UTC (rev
3095)
+++ trunk/pingus/src/display/scene_context.hpp 2007-09-06 16:12:02 UTC (rev
3096)
@@ -33,6 +33,7 @@
{
public:
SceneContext();
+ SceneContext(const Rect& rect);
~SceneContext();
/** The main drawing context, also known as color buffer, to this
@@ -73,7 +74,7 @@
/** Takes all the buffers and combines them to form the final image
that will be shown on the screen */
- void render(SDL_Surface* gc);
+ void render(SDL_Surface* gc, const Rect& rect);
void clear();
private:
@@ -91,7 +92,7 @@
public:
SceneContextDrawingRequest(SceneContext* sc, const Vector3f& pos_ =
Vector3f(0,0,0));
virtual ~SceneContextDrawingRequest();
- void draw(SDL_Surface* gc);
+ void render(SDL_Surface* gc, const Rect& render);
};
Modified: trunk/pingus/src/gui/screen_manager.cpp
===================================================================
--- trunk/pingus/src/gui/screen_manager.cpp 2007-09-06 01:56:21 UTC (rev
3095)
+++ trunk/pingus/src/gui/screen_manager.cpp 2007-09-06 16:12:02 UTC (rev
3096)
@@ -127,7 +127,8 @@
{
if (get_current_screen()->draw(*display_gc))
{
- display_gc->render(Display::get_screen());
+ display_gc->render(Display::get_screen(), Rect(Vector2i(0,0),
Size(Display::get_width(),
+
Display::get_height())));
Display::flip_display ();
display_gc->clear();
}
@@ -260,14 +261,16 @@
int border_y = int((Display::get_height()/2) * (1.0f - progress));
old_screen->draw(*display_gc);
- display_gc->render(Display::get_screen());
+ display_gc->render(Display::get_screen(), Rect(Vector2i(0,0),
Size(Display::get_width(),
+
Display::get_height())));
display_gc->clear();
Display::push_cliprect(Rect(Vector2i(0 + border_x, 0 + border_y),
Size(screen_width - 2*border_x,
screen_height - 2*border_y)));
new_screen->draw(*display_gc);
- display_gc->render(Display::get_screen());
+ display_gc->render(Display::get_screen(), Rect(Vector2i(0,0),
Size(Display::get_width(),
+
Display::get_height())));
display_gc->clear();
//GameDelta delta (time_delta, CL_System::get_time(), events);
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Pingus-CVS] r3096 - in trunk/pingus/src: display gui,
grumbel at BerliOS <=