[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Pingus-CVS] r2844 - in branches/pingus_sdl/src: . components display gu
From: |
grumbel at BerliOS |
Subject: |
[Pingus-CVS] r2844 - in branches/pingus_sdl/src: . components display gui |
Date: |
Sun, 12 Aug 2007 01:31:49 +0200 |
Author: grumbel
Date: 2007-08-12 01:31:48 +0200 (Sun, 12 Aug 2007)
New Revision: 2844
Modified:
branches/pingus_sdl/src/components/playfield.cpp
branches/pingus_sdl/src/credits.cpp
branches/pingus_sdl/src/display/drawing_context.cpp
branches/pingus_sdl/src/display/scene_context.cpp
branches/pingus_sdl/src/display/scene_context.hpp
branches/pingus_sdl/src/display/scene_graph.cpp
branches/pingus_sdl/src/gui/display.cpp
branches/pingus_sdl/src/gui/display.hpp
branches/pingus_sdl/src/gui/gui_screen.cpp
branches/pingus_sdl/src/gui/screen_manager.cpp
branches/pingus_sdl/src/pingus_menu.cpp
branches/pingus_sdl/src/world.cpp
Log:
- moved clipping from SpriteDrawingRequest to SceneContext
- replaced a few SDL_Get/SetClipRect with Display::push/pop_cliprect()
Modified: branches/pingus_sdl/src/components/playfield.cpp
===================================================================
--- branches/pingus_sdl/src/components/playfield.cpp 2007-08-11 23:20:37 UTC
(rev 2843)
+++ branches/pingus_sdl/src/components/playfield.cpp 2007-08-11 23:31:48 UTC
(rev 2844)
@@ -58,7 +58,9 @@
Playfield::draw (DrawingContext& gc)
{
scene_context->clear();
- scene_context->light().fill_screen(Color(50, 50, 50));
+ scene_context->set_cliprect(Rect(Vector2i(0, 0), Size(world->get_width(),
world->get_height())));
+
+ //scene_context->light().fill_screen(Color(50, 50, 50));
state.push(*scene_context);
Modified: branches/pingus_sdl/src/credits.cpp
===================================================================
--- branches/pingus_sdl/src/credits.cpp 2007-08-11 23:20:37 UTC (rev 2843)
+++ branches/pingus_sdl/src/credits.cpp 2007-08-11 23:31:48 UTC (rev 2844)
@@ -265,10 +265,13 @@
gc.print_right(Fonts::chalk_normal,
static_cast<float>(Display::get_width()/2 + 275),
static_cast<float>(Display::get_height()/2 + 110),
- _("Skip"));
-
- Display::push_cliprect(Rect(0, static_cast<int>(gc.get_height()/2-225),
- 600, static_cast<int>(gc.get_height()/2+200)));
+ _("Exit"));
+
+ // FIXME: Doesn't work here, due to DrawingContext, needs a little
+ // more work to get fixed properly
+ // Display::push_cliprect(Rect(0,
+ // static_cast<int>(gc.get_height()/2-225), 600,
+ // static_cast<int>(gc.get_height()/2+200)));
yof = 0;
for (std::vector<std::string>::iterator i = credits.begin(); i !=
credits.end(); ++i)
@@ -291,7 +294,7 @@
break;
}
}
- Display::pop_cliprect();
+ //Display::pop_cliprect();
}
void
@@ -320,7 +323,7 @@
Credits::deinit()
{
delete instance_;
- instance_ = 0;
+ instance_ = 0;
}
void
Modified: branches/pingus_sdl/src/display/drawing_context.cpp
===================================================================
--- branches/pingus_sdl/src/display/drawing_context.cpp 2007-08-11 23:20:37 UTC
(rev 2843)
+++ branches/pingus_sdl/src/display/drawing_context.cpp 2007-08-11 23:31:48 UTC
(rev 2844)
@@ -63,37 +63,18 @@
{
private:
Sprite sprite;
- SDL_Rect clip_rect;
- SDL_Rect Intersection(SDL_Rect* r1, SDL_Rect* r2)
- {
- SDL_Rect rect;
- rect.x = Math::max(r1->x, r2->y);
- rect.y = Math::max(r1->y, r2->y);
- int endx = Math::min(r1->x + r1->w, r2->x + r2->w);
- rect.w = Math::max(endx - rect.x, 0);
- int endy = Math::min(r1->y + r1->h, r2->y + r2->h);
- rect.h = Math::max(endy - rect.y, 0);
- return rect;
- }
-
public:
SpriteDrawingRequest(const Sprite& sprite_, const Vector3f& pos_)
: DrawingRequest(pos_),
sprite(sprite_)
{
- SDL_GetClipRect(Display::get_screen(), &clip_rect);
}
+
virtual ~SpriteDrawingRequest() {}
void draw(SDL_Surface* target) {
- SDL_Rect orig_rect;
- SDL_Rect rect;
- SDL_GetClipRect(Display::get_screen(), &orig_rect);
- rect = Intersection(&orig_rect, &clip_rect);
- SDL_SetClipRect(Display::get_screen(), &rect);
sprite.draw(pos.x, pos.y, target);
- SDL_SetClipRect(Display::get_screen(), &orig_rect);
}
};
Modified: branches/pingus_sdl/src/display/scene_context.cpp
===================================================================
--- branches/pingus_sdl/src/display/scene_context.cpp 2007-08-11 23:20:37 UTC
(rev 2843)
+++ branches/pingus_sdl/src/display/scene_context.cpp 2007-08-11 23:31:48 UTC
(rev 2844)
@@ -29,8 +29,11 @@
DrawingContext color;
DrawingContext light;
DrawingContext highlight;
+ Rect cliprect;
+ bool use_cliprect;
SceneContextImpl()
+ : use_cliprect(false)
{
}
};
@@ -116,11 +119,33 @@
}
void
+SceneContext::set_cliprect(const Rect& rect)
+{
+ impl->cliprect = rect;
+ impl->use_cliprect = true;
+}
+
+void
+SceneContext::reset_cliprect()
+{
+ impl->use_cliprect = false;
+}
+
+void
SceneContext::render(SDL_Surface* target)
{
// Render all buffers
// FIXME: Render all to pbuffer for later combining of them
- impl->color.render(target);
+ if (impl->use_cliprect)
+ {
+ Display::push_cliprect(impl->cliprect);
+ impl->color.render(target);
+ Display::pop_cliprect();
+ }
+ else
+ {
+ impl->color.render(target);
+ }
#if 0
{ // lightmap support
Modified: branches/pingus_sdl/src/display/scene_context.hpp
===================================================================
--- branches/pingus_sdl/src/display/scene_context.hpp 2007-08-11 23:20:37 UTC
(rev 2843)
+++ branches/pingus_sdl/src/display/scene_context.hpp 2007-08-11 23:31:48 UTC
(rev 2844)
@@ -68,6 +68,9 @@
void pop_modelview();
void reset_modelview();
+ void set_cliprect(const Rect& rect);
+ void reset_cliprect();
+
/** Takes all the buffers and combines them to form the final image
that will be shown on the screen */
void render(SDL_Surface* gc);
Modified: branches/pingus_sdl/src/display/scene_graph.cpp
===================================================================
--- branches/pingus_sdl/src/display/scene_graph.cpp 2007-08-11 23:20:37 UTC
(rev 2843)
+++ branches/pingus_sdl/src/display/scene_graph.cpp 2007-08-11 23:31:48 UTC
(rev 2844)
@@ -54,7 +54,7 @@
return;
-
+#if 0
screen.clear();
// Find out what regions of the screen have changed
for(Nodes::iterator i = nodes.begin(); i != nodes.end(); ++i)
@@ -75,7 +75,6 @@
for(Nodes::iterator i = nodes.begin(); i != nodes.end(); ++i)
{ // FIXME: could optimize this to only draw the ones that touch
the region
-
SDL_Rect clip_rect;
clip_rect.x = x*32;
@@ -91,6 +90,7 @@
x += width;
}
}
+#endif
}
void
Modified: branches/pingus_sdl/src/gui/display.cpp
===================================================================
--- branches/pingus_sdl/src/gui/display.cpp 2007-08-11 23:20:37 UTC (rev
2843)
+++ branches/pingus_sdl/src/gui/display.cpp 2007-08-11 23:31:48 UTC (rev
2844)
@@ -24,11 +24,27 @@
#include "../math/vector2i.hpp"
#include "../math/rect.hpp"
#include "../math/color.hpp"
+#include "../math.hpp"
#include "display.hpp"
std::list<DisplayHook*> Display::display_hooks;
+std::vector<SDL_Rect> Display::cliprect_stack;
SDL_Surface* Display::screen;
+namespace {
+SDL_Rect Intersection(SDL_Rect* r1, SDL_Rect* r2)
+{
+ SDL_Rect rect;
+ rect.x = Math::max(r1->x, r2->y);
+ rect.y = Math::max(r1->y, r2->y);
+ int endx = Math::min(r1->x + r1->w, r2->x + r2->w);
+ rect.w = Math::max(endx - rect.x, 0);
+ int endy = Math::min(r1->y + r1->h, r2->y + r2->h);
+ rect.h = Math::max(endy - rect.y, 0);
+ return rect;
+}
+} // namespace
+
DisplayHook::DisplayHook() : is_visible(false)
{
}
@@ -161,12 +177,12 @@
static draw_pixel_func get_draw_pixel()
{
switch (Display::get_screen()->format->BitsPerPixel)
- {
- case 16:
- return draw_pixel16;
- case 32:
- return draw_pixel32;
- }
+ {
+ case 16:
+ return draw_pixel16;
+ case 32:
+ return draw_pixel32;
+ }
return NULL;
}
@@ -374,13 +390,25 @@
}
void
-Display::push_cliprect(const Rect&)
+Display::push_cliprect(const Rect& rect)
{
+ SDL_Rect sdl_rect = { rect.left, rect.top, rect.get_width(),
rect.get_height() };
+
+ if (!cliprect_stack.empty())
+ sdl_rect = Intersection(&cliprect_stack.back(), &sdl_rect);
+
+ cliprect_stack.push_back(sdl_rect);
+ SDL_SetClipRect(screen, &cliprect_stack.back());
}
void
Display::pop_cliprect()
{
+ cliprect_stack.pop_back();
+ if (cliprect_stack.empty())
+ SDL_SetClipRect(screen, NULL);
+ else
+ SDL_SetClipRect(screen, &cliprect_stack.back());
}
/* EOF */
Modified: branches/pingus_sdl/src/gui/display.hpp
===================================================================
--- branches/pingus_sdl/src/gui/display.hpp 2007-08-11 23:20:37 UTC (rev
2843)
+++ branches/pingus_sdl/src/gui/display.hpp 2007-08-11 23:31:48 UTC (rev
2844)
@@ -23,6 +23,7 @@
#include "../pingus.hpp"
#include "SDL.h"
#include <list>
+#include <vector>
class Vector2i;
class Rect;
@@ -54,6 +55,7 @@
{
private:
static std::list<DisplayHook*> display_hooks;
+ static std::vector<SDL_Rect> cliprect_stack;
static SDL_Surface* screen;
public:
static void draw_line(int x1, int y1, int x2, int y2, const Color& color);
Modified: branches/pingus_sdl/src/gui/gui_screen.cpp
===================================================================
--- branches/pingus_sdl/src/gui/gui_screen.cpp 2007-08-11 23:20:37 UTC (rev
2843)
+++ branches/pingus_sdl/src/gui/gui_screen.cpp 2007-08-11 23:31:48 UTC (rev
2844)
@@ -50,7 +50,7 @@
// Dispatch the recieved input events
gui_manager->update (delta);
- update (delta.get_time ());
+ update(delta.get_time ());
for (Input::EventLst::const_iterator i = delta.get_events ().begin ();
i != delta.get_events ().end (); ++i)
Modified: branches/pingus_sdl/src/gui/screen_manager.cpp
===================================================================
--- branches/pingus_sdl/src/gui/screen_manager.cpp 2007-08-11 23:20:37 UTC
(rev 2843)
+++ branches/pingus_sdl/src/gui/screen_manager.cpp 2007-08-11 23:31:48 UTC
(rev 2844)
@@ -263,14 +263,9 @@
display_gc->render(Display::get_screen());
display_gc->clear();
- SDL_Rect clip_rect;
- clip_rect.x = 0 + border_x;
- clip_rect.y = 0 + border_y;
- clip_rect.w = screen_width - 2*border_x;
- clip_rect.h = screen_height - 2*border_y;
+ Display::push_cliprect(Rect(Vector2i(0 + border_x, 0 + border_y),
+ Size(screen_width - 2*border_x,
screen_height - 2*border_y)));
- SDL_SetClipRect(Display::get_screen(), &clip_rect);
-
new_screen->draw(*display_gc);
display_gc->render(Display::get_screen());
display_gc->clear();
@@ -280,8 +275,7 @@
//new_screen->update (delta);
//old_screen->update (delta);
- SDL_SetClipRect(Display::get_screen(), NULL);
-
+ Display::pop_cliprect();
Display::flip_display ();
display_gc->clear();
Modified: branches/pingus_sdl/src/pingus_menu.cpp
===================================================================
--- branches/pingus_sdl/src/pingus_menu.cpp 2007-08-11 23:20:37 UTC (rev
2843)
+++ branches/pingus_sdl/src/pingus_menu.cpp 2007-08-11 23:31:48 UTC (rev
2844)
@@ -46,19 +46,19 @@
is_init = false;
start_button = new MenuButton(this, Vector2i(Display::get_width() * 400 /
800,
- Display::get_height() * 450 / 600),
+ Display::get_height() * 390 / 600),
Resource::load_sprite("core/menu/play_on"),
_("Start"),
_("..:: Start the game ::.."));
-
+
quit_button = new MenuButton(this, Vector2i(Display::get_width() * 650 / 800,
- Display::get_height() * 450 / 600),
+ Display::get_height() * 390 / 600),
Resource::load_sprite("core/menu/exit_on"),
_("Exit"),
_("..:: Bye, bye ::.."));
credits_button = new MenuButton(this, Vector2i(Display::get_width() * 150 /
800,
- Display::get_height() * 450 / 600),
+ Display::get_height() * 390 / 600),
Resource::load_sprite("core/menu/credits_on"),
_("Credits"),
_("..:: See the credits ::.."));
Modified: branches/pingus_sdl/src/world.cpp
===================================================================
--- branches/pingus_sdl/src/world.cpp 2007-08-11 23:20:37 UTC (rev 2843)
+++ branches/pingus_sdl/src/world.cpp 2007-08-11 23:31:48 UTC (rev 2844)
@@ -120,17 +120,10 @@
gc.light().fill_screen(Color(ambient_light));
- SDL_Rect orig_rect;
- SDL_Rect rect = { 0, 0, this->get_width(), this->get_height() };
- SDL_GetClipRect(Display::get_screen(), &orig_rect);
- SDL_SetClipRect(Display::get_screen(), &rect);
-
for(WorldObjIter obj = world_obj.begin(); obj != world_obj.end(); ++obj)
{
(*obj)->draw(gc);
}
-
- SDL_SetClipRect(Display::get_screen(), &orig_rect);
}
void
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Pingus-CVS] r2844 - in branches/pingus_sdl/src: . components display gui,
grumbel at BerliOS <=