[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Pingus-CVS] r3786 - in trunk/pingus/src: . display editor screen
From: |
grumbel at BerliOS |
Subject: |
[Pingus-CVS] r3786 - in trunk/pingus/src: . display editor screen |
Date: |
Fri, 11 Jul 2008 14:53:36 +0200 |
Author: grumbel
Date: 2008-07-11 14:53:35 +0200 (Fri, 11 Jul 2008)
New Revision: 3786
Modified:
trunk/pingus/src/display/display.cpp
trunk/pingus/src/display/display.hpp
trunk/pingus/src/display/framebuffer.cpp
trunk/pingus/src/display/framebuffer.hpp
trunk/pingus/src/display/scene_context.cpp
trunk/pingus/src/editor/editor_screen.cpp
trunk/pingus/src/font.cpp
trunk/pingus/src/screen/screen_manager.cpp
trunk/pingus/src/screenshot.cpp
trunk/pingus/src/sprite_impl.cpp
Log:
Change some more code to use Framebuffer
Modified: trunk/pingus/src/display/display.cpp
===================================================================
--- trunk/pingus/src/display/display.cpp 2008-07-11 11:33:37 UTC (rev
3785)
+++ trunk/pingus/src/display/display.cpp 2008-07-11 12:53:35 UTC (rev
3786)
@@ -28,24 +28,6 @@
std::auto_ptr<Framebuffer> Display::framebuffer;
void
-Display::draw_line(const Vector2i& pos1, const Vector2i& pos2, const Color&
color)
-{
- framebuffer->draw_line(pos1, pos2, color);
-}
-
-void
-Display::draw_rect(const Rect& rect, const Color& color)
-{
- framebuffer->draw_rect(rect, color);
-}
-
-void
-Display::fill_rect(const Rect& rect, const Color& color)
-{
- framebuffer->fill_rect(rect, color);
-}
-
-void
Display::flip_display()
{
return framebuffer->flip();
@@ -77,35 +59,11 @@
framebuffer->set_video_mode(width, height, fullscreen);
}
-
-void
-Display::clear()
-{
- framebuffer->clear();
-}
-SDL_Surface*
-Display::get_screen()
-{
- return framebuffer->get_screen();
-}
-
Framebuffer&
Display::get_framebuffer()
{
return *framebuffer.get();
}
-
-void
-Display::push_cliprect(const Rect& rect)
-{
- framebuffer->push_cliprect(rect);
-}
-
-void
-Display::pop_cliprect()
-{
- framebuffer->pop_cliprect();
-}
/* EOF */
Modified: trunk/pingus/src/display/display.hpp
===================================================================
--- trunk/pingus/src/display/display.hpp 2008-07-11 11:33:37 UTC (rev
3785)
+++ trunk/pingus/src/display/display.hpp 2008-07-11 12:53:35 UTC (rev
3786)
@@ -18,7 +18,6 @@
#define HEADER_PINGUS_DISPLAY_HPP
#include <memory>
-#include "SDL.h"
#include <list>
#include <vector>
#include "../math/size.hpp"
@@ -34,11 +33,6 @@
static std::auto_ptr<Framebuffer> framebuffer;
public:
- static void draw_line(const Vector2i& pos1, const Vector2i& pos2, const
Color& color);
-
- static void draw_rect(const Rect& rect, const Color& color);
- static void fill_rect(const Rect& rect, const Color& color);
-
static void flip_display();
static int get_width();
@@ -47,14 +41,8 @@
static void set_video_mode(int width, int height, bool fullscreen);
- static void clear();
-
- static SDL_Surface* get_screen();
static Framebuffer& get_framebuffer();
- static void push_cliprect(const Rect&);
- static void pop_cliprect();
-
private:
Display ();
Display (const Display&);
Modified: trunk/pingus/src/display/framebuffer.cpp
===================================================================
--- trunk/pingus/src/display/framebuffer.cpp 2008-07-11 11:33:37 UTC (rev
3785)
+++ trunk/pingus/src/display/framebuffer.cpp 2008-07-11 12:53:35 UTC (rev
3786)
@@ -21,9 +21,11 @@
namespace {
-void draw_pixel16(int x, int y, const Color& c)
+typedef void (*draw_pixel_func)(SDL_Surface* screen, int, int, const Color&);
+
+inline void draw_pixel16(SDL_Surface* screen, int x, int y, const Color& c)
{
- Uint32 color = SDL_MapRGBA(Display::get_screen()->format, c.r, c.g, c.b,
c.a);
+ Uint32 color = SDL_MapRGBA(screen->format, c.r, c.g, c.b, c.a);
if (c.a < 255) {
Uint16 *p;
@@ -33,20 +35,20 @@
// Loses precision for speed
alpha = (255 - c.a) >> 3;
- p = &((Uint16 *)Display::get_screen()->pixels)[x + y *
Display::get_screen()->w];
+ p = &((Uint16 *)screen->pixels)[x + y * screen->w];
color = (((color << 16) | color) & 0x07E0F81F);
dp = *p;
dp = ((dp << 16) | dp) & 0x07E0F81F;
dp = ((((dp - color) * alpha) >> 5) + color) & 0x07E0F81F;
*p = (Uint16)((dp >> 16) | dp);
} else {
- ((Uint16 *)Display::get_screen()->pixels)[x + y *
Display::get_screen()->w] = color;
+ ((Uint16 *)screen->pixels)[x + y * screen->w] = color;
}
}
-void draw_pixel32(int x, int y, const Color& c)
+inline void draw_pixel32(SDL_Surface* screen, int x, int y, const Color& c)
{
- Uint32 color = SDL_MapRGBA(Display::get_screen()->format, c.r, c.g, c.b,
c.a);
+ Uint32 color = SDL_MapRGBA(screen->format, c.r, c.g, c.b, c.a);
if (c.a < 255) {
Uint32 *p;
@@ -57,7 +59,7 @@
alpha = 255 - c.a;
- p = &((Uint32*)Display::get_screen()->pixels)[x + y *
Display::get_screen()->w];
+ p = &((Uint32*)screen->pixels)[x + y * screen->w];
sp2 = (color & 0xFF00FF00) >> 8;
color &= 0x00FF00FF;
@@ -70,14 +72,13 @@
dp2 = ((((dp2 - sp2) * alpha) >> 8) + sp2) & 0x00FF00FF;
*p = (dp1 | (dp2 << 8));
} else {
- ((Uint32 *)Display::get_screen()->pixels)[x + y *
Display::get_screen()->w] = color;
+ ((Uint32 *)screen->pixels)[x + y * screen->w] = color;
}
}
-typedef void (*draw_pixel_func)(int, int, const Color&);
-draw_pixel_func get_draw_pixel()
+draw_pixel_func get_draw_pixel(SDL_Surface* screen)
{
- switch (Display::get_screen()->format->BitsPerPixel)
+ switch (screen->format->BitsPerPixel)
{
case 16:
return draw_pixel16;
@@ -87,30 +88,30 @@
return NULL;
}
-void draw_vline(int x, int y, int length, const Color& color)
+void draw_vline(SDL_Surface* screen, int x, int y, int length, const Color&
color)
{
- draw_pixel_func draw_pixel = get_draw_pixel();
+ draw_pixel_func draw_pixel = get_draw_pixel(screen);
if (!draw_pixel)
return;
- SDL_LockSurface(Display::get_screen());
+ SDL_LockSurface(screen);
for (int i = 0; i < length; ++i) {
- draw_pixel(x, y + i, color);
+ draw_pixel(screen, x, y + i, color);
}
- SDL_UnlockSurface(Display::get_screen());
+ SDL_UnlockSurface(screen);
}
-void draw_hline(int x, int y, int length, const Color& color)
+void draw_hline(SDL_Surface* screen, int x, int y, int length, const Color&
color)
{
- draw_pixel_func draw_pixel = get_draw_pixel();
+ draw_pixel_func draw_pixel = get_draw_pixel(screen);
if (!draw_pixel)
return;
- SDL_LockSurface(Display::get_screen());
+ SDL_LockSurface(screen);
for (int i = 0; i < length; ++i) {
- draw_pixel(x + i, y, color);
+ draw_pixel(screen, x + i, y, color);
}
- SDL_UnlockSurface(Display::get_screen());
+ SDL_UnlockSurface(screen);
}
SDL_Rect Intersection(SDL_Rect* r1, SDL_Rect* r2)
@@ -157,7 +158,7 @@
}
void
-Framebuffer::draw_surface(SDL_Surface* src, const Vector2i& pos, const Rect&
rect)
+Framebuffer::draw_surface(SDL_Surface* src, const Rect& srcrect, const
Vector2i& pos)
{
SDL_Rect dstrect;
dstrect.x = (Sint16)pos.x;
@@ -165,13 +166,13 @@
dstrect.w = 0;
dstrect.h = 0;
- SDL_Rect srcrect;
- srcrect.x = rect.left;
- srcrect.y = rect.top;
- srcrect.w = rect.get_width();
- srcrect.h = rect.get_height();
+ SDL_Rect sdlsrcrect;
+ sdlsrcrect.x = srcrect.left;
+ sdlsrcrect.y = srcrect.top;
+ sdlsrcrect.w = srcrect.get_width();
+ sdlsrcrect.h = srcrect.get_height();
- SDL_BlitSurface(src, &srcrect, screen, &dstrect);
+ SDL_BlitSurface(src, &sdlsrcrect, screen, &dstrect);
}
void
@@ -182,11 +183,11 @@
int sy = pos1.y;
int dx = pos2.x;
int dy = pos2.y;
- void (*draw_pixel)(int x, int y, const Color& color);
+ draw_pixel_func draw_pixel;
int clipx1, clipx2, clipy1, clipy2;
SDL_Rect rect;
- SDL_GetClipRect(Display::get_screen(), &rect);
+ SDL_GetClipRect(screen, &rect);
clipx1 = rect.x;
clipx2 = rect.x + rect.w - 1;
clipy1 = rect.y;
@@ -200,9 +201,9 @@
clip(sy, clipy1, clipy2);
clip(dy, clipy1, clipy2);
if (sy < dy) {
- draw_vline(sx, sy, dy - sy + 1, color);
+ draw_vline(screen, sx, sy, dy - sy + 1, color);
} else {
- draw_vline(dx, dy, sy - dy + 1, color);
+ draw_vline(screen, dx, dy, sy - dy + 1, color);
}
return;
}
@@ -215,14 +216,14 @@
clip(sx, clipx1, clipx2);
clip(dx, clipx1, clipx2);
if (sx < dx) {
- draw_hline(sx, sy, dx - sx + 1, color);
+ draw_hline(screen, sx, sy, dx - sx + 1, color);
} else {
- draw_hline(dx, dy, sx - dx + 1, color);
+ draw_hline(screen, dx, dy, sx - dx + 1, color);
}
return;
}
- draw_pixel = get_draw_pixel();
+ draw_pixel = get_draw_pixel(screen);
if (!draw_pixel) {
return;
}
@@ -262,7 +263,7 @@
SDL_LockSurface(screen);
for (x = sx; x < dx; ++x) {
if (x >= clipx1 && x <= clipx2 && y >= clipy1 && y <= clipy2) {
- draw_pixel(x, y, color);
+ draw_pixel(screen, x, y, color);
}
if (p >= 0) {
y += incr;
@@ -281,7 +282,7 @@
SDL_LockSurface(screen);
for (y = sy; y < dy; ++y) {
if (x >= clipx1 && x <= clipx2 && y >= clipy1 && y <= clipy2) {
- draw_pixel(x, y, color);
+ draw_pixel(screen, x, y, color);
}
if (p >= 0) {
x += incr;
@@ -299,7 +300,7 @@
SDL_LockSurface(screen);
while (y != dy) {
if (x >= clipx1 && x <= clipx2 && y >= clipy1 && y <= clipy2) {
- draw_pixel(x, y, color);
+ draw_pixel(screen, x, y, color);
}
x += incr;
++y;
@@ -354,14 +355,14 @@
left = rect.left < clipx1 ? clipx1 : rect.left;
right = rect.right > clipx2 ? clipx2 : rect.right;
- draw_pixel_func draw_pixel = get_draw_pixel();
+ draw_pixel_func draw_pixel = get_draw_pixel(screen);
if (!draw_pixel)
return;
SDL_LockSurface(screen);
for (int j = top; j <= bottom; ++j) {
for (int i = left; i <= right; ++i) {
- draw_pixel(i, j, color);
+ draw_pixel(screen, i, j, color);
}
}
SDL_UnlockSurface(screen);
@@ -400,7 +401,7 @@
void
Framebuffer::clear()
{
- SDL_FillRect(screen, NULL, SDL_MapRGB(Display::get_screen()->format, 0, 0,
0));
+ SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0, 0, 0));
}
void
Modified: trunk/pingus/src/display/framebuffer.hpp
===================================================================
--- trunk/pingus/src/display/framebuffer.hpp 2008-07-11 11:33:37 UTC (rev
3785)
+++ trunk/pingus/src/display/framebuffer.hpp 2008-07-11 12:53:35 UTC (rev
3786)
@@ -40,8 +40,8 @@
void push_cliprect(const Rect&);
void pop_cliprect();
- void draw_surface(SDL_Surface* sur, const Vector2i& pos);
- void draw_surface(SDL_Surface* sur, const Vector2i& pos, const Rect& rect);
+ void draw_surface(SDL_Surface* src, const Vector2i& pos);
+ void draw_surface(SDL_Surface* src, const Rect& srcrect, const Vector2i&
pos);
void draw_line(const Vector2i& pos1, const Vector2i& pos2, const Color&
color);
Modified: trunk/pingus/src/display/scene_context.cpp
===================================================================
--- trunk/pingus/src/display/scene_context.cpp 2008-07-11 11:33:37 UTC (rev
3785)
+++ trunk/pingus/src/display/scene_context.cpp 2008-07-11 12:53:35 UTC (rev
3786)
@@ -14,7 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
-#include "display/display.hpp"
+#include "display/framebuffer.hpp"
#include "scene_context.hpp"
#define SCALE_FACTOR 8.0f
@@ -156,9 +156,9 @@
// FIXME: Render all to pbuffer for later combining of them
if (impl->use_cliprect)
{
- Display::push_cliprect(impl->cliprect);
+ fb.push_cliprect(impl->cliprect);
impl->color.render(fb, rect);
- Display::pop_cliprect();
+ fb.pop_cliprect();
}
else
{
Modified: trunk/pingus/src/editor/editor_screen.cpp
===================================================================
--- trunk/pingus/src/editor/editor_screen.cpp 2008-07-11 11:33:37 UTC (rev
3785)
+++ trunk/pingus/src/editor/editor_screen.cpp 2008-07-11 12:53:35 UTC (rev
3786)
@@ -55,8 +55,8 @@
{
// Create the viewport for the images and data
viewport = new Viewport(this, Rect(0, 38,
- Display::get_width() - 244,
- Display::get_height()));
+ size.width - 244,
+ size.height));
gui_manager->add(viewport);
// Create the panel for the buttons
@@ -85,8 +85,8 @@
gui_manager->add(object_selector);
file_load_dialog = new FileDialog(this, Rect(Vector2i(50, 50),
- Size(Display::get_width() -
100,
- Display::get_height() -
100)),
+ Size(size.width - 100,
+ size.height - 100)),
FileDialog::LOAD);
file_load_dialog->set_directory(".");
file_load_dialog->hide();
Modified: trunk/pingus/src/font.cpp
===================================================================
--- trunk/pingus/src/font.cpp 2008-07-11 11:33:37 UTC (rev 3785)
+++ trunk/pingus/src/font.cpp 2008-07-11 12:53:35 UTC (rev 3786)
@@ -45,7 +45,7 @@
{
public:
SDL_Surface* surface;
- SDL_Rect chrs[256];
+ Rect chrs[256];
int space_length;
float char_spacing;
float vertical_spacing;
@@ -59,9 +59,6 @@
//std::cout << "desc.space: " << desc.space_length << std::endl;
//std::cout << "Characters: " << desc.characters << std::endl;
- for(int i = 0; i < 256; ++i)
- chrs[i].x = chrs[i].y = chrs[i].w = chrs[i].h = 0;
-
surface = IMG_Load(desc.image.get_sys_path().c_str());
if (!surface)
{
@@ -109,11 +106,9 @@
//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;
- rect.y = 0;
- rect.w = x - first;
- rect.h = surface->h;
+ chrs[static_cast<unsigned char>(desc.characters[idx])]
+ = Rect(Vector2i(first, 0),
+ Size(x - first, surface->h));
}
else
{
@@ -147,12 +142,9 @@
for(int i = 0; i < int(desc.characters.size()); ++i)
{
- SDL_Rect& rect = chrs[static_cast<unsigned
char>(desc.characters[i])];
-
- rect.x = i * space_length;
- rect.y = 0;
- rect.w = space_length;
- rect.h = surface->h;
+ chrs[static_cast<unsigned char>(desc.characters[i])]
+ = Rect(Vector2i(i * space_length, 0),
+ Size(space_length, surface->h));
}
}
@@ -190,12 +182,11 @@
}
else
{
- SDL_Rect& srcrect = chrs[static_cast<unsigned char>(text[i])];
- if (srcrect.w != 0 && srcrect.h != 0)
+ Rect& srcrect = chrs[static_cast<unsigned char>(text[i])];
+ if (srcrect.get_width() != 0 && srcrect.get_height() != 0)
{
- SDL_Rect dstrect = { int(dstx), int(dsty), 0, 0 };
- SDL_BlitSurface(surface, &srcrect, fb.get_screen(), &dstrect);
- dstx += srcrect.w + char_spacing;
+ fb.draw_surface(surface, srcrect, Vector2i(dstx, dsty));
+ dstx += srcrect.get_width() + char_spacing;
}
else
{
@@ -212,7 +203,7 @@
int get_width(char idx) const
{
- return chrs[static_cast<unsigned char>(idx)].w;
+ return chrs[static_cast<unsigned char>(idx)].get_width();
}
int get_width(const std::string& text) const
@@ -232,7 +223,7 @@
}
else
{
- width += chrs[static_cast<unsigned char>(text[i])].w +
char_spacing;
+ width += chrs[static_cast<unsigned char>(text[i])].get_width() +
char_spacing;
}
}
return int(std::max(width, last_width));
Modified: trunk/pingus/src/screen/screen_manager.cpp
===================================================================
--- trunk/pingus/src/screen/screen_manager.cpp 2008-07-11 11:33:37 UTC (rev
3785)
+++ trunk/pingus/src/screen/screen_manager.cpp 2008-07-11 12:53:35 UTC (rev
3786)
@@ -21,6 +21,7 @@
#include "math/size.hpp"
#include "pathname.hpp"
#include "display/display.hpp"
+#include "display/framebuffer.hpp"
#include "screen_manager.hpp"
#include "../path_manager.hpp"
#include "screen.hpp"
@@ -342,17 +343,18 @@
Uint32 last_ticks = SDL_GetTicks();
float progress = 0.0f;
+ Framebuffer& fb = Display::get_framebuffer();
while (progress <= 1.0f)
{
int border_x = int((Display::get_width()/2) * (1.0f - progress));
int border_y = int((Display::get_height()/2) * (1.0f - progress));
old_screen->draw(*display_gc);
- display_gc->render(Display::get_framebuffer(), Rect(Vector2i(0,0),
Size(Display::get_width(),
+ display_gc->render(fb, 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),
+ fb.push_cliprect(Rect(Vector2i(0 + border_x, 0 + border_y),
Size(Display::get_width() - 2*border_x,
Display::get_height() - 2*border_y)));
@@ -361,8 +363,8 @@
Display::get_height())));
display_gc->clear();
- Display::pop_cliprect();
- Display::flip_display();
+ fb.pop_cliprect();
+ fb.flip();
display_gc->clear();
progress = (SDL_GetTicks() - last_ticks)/1000.0f;
Modified: trunk/pingus/src/screenshot.cpp
===================================================================
--- trunk/pingus/src/screenshot.cpp 2008-07-11 11:33:37 UTC (rev 3785)
+++ trunk/pingus/src/screenshot.cpp 2008-07-11 12:53:35 UTC (rev 3786)
@@ -21,6 +21,7 @@
#include <fstream>
#include <iostream>
#include "display/display.hpp"
+#include "display/framebuffer.hpp"
#include "system.hpp"
#include "screenshot.hpp"
#include "gettext.h"
@@ -33,7 +34,7 @@
{
std::string filename = get_filename();
std::cout << _("Screenshot: Saving screenshot to: ") << filename <<
std::endl;
- save(Display::get_screen(), filename);
+ save(Display::get_framebuffer().get_screen(), filename);
std::cout << _("Screenshot: Screenshot is done.") << std::endl;
return filename;
Modified: trunk/pingus/src/sprite_impl.cpp
===================================================================
--- trunk/pingus/src/sprite_impl.cpp 2008-07-11 11:33:37 UTC (rev 3785)
+++ trunk/pingus/src/sprite_impl.cpp 2008-07-11 12:53:35 UTC (rev 3786)
@@ -117,10 +117,10 @@
optimize();
fb.draw_surface(surface.get_surface(),
- Vector2i(static_cast<int>(x - offset.x), static_cast<int>(y
- offset.y)),
Rect(frame_pos + Vector2i(frame_size.width *
(frame%array.width),
frame_size.height *
(frame/array.width)),
- frame_size));
+ frame_size),
+ Vector2i(static_cast<int>(x - offset.x), static_cast<int>(y
- offset.y)));
}
void
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Pingus-CVS] r3786 - in trunk/pingus/src: . display editor screen,
grumbel at BerliOS <=