[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Pingus-CVS] r2586 - in trunk/src: . display
From: |
jave27 |
Subject: |
[Pingus-CVS] r2586 - in trunk/src: . display |
Date: |
Tue, 10 Jan 2006 18:44:22 +0100 |
Author: jave27
Date: 2006-01-10 18:44:01 +0100 (Tue, 10 Jan 2006)
New Revision: 2586
Modified:
trunk/src/blitter.cxx
trunk/src/display/drawing_context.cxx
trunk/src/display/scene_context.cxx
trunk/src/layer_manager.cxx
trunk/src/layer_manager.hxx
trunk/src/pingus_menu_manager.cxx
Log:
Made a lot of changes to enable resolutions other than 800x600 to work
correctly.
Still not perfect, but much closer, plus this fixed a blitter scaling issue
with indexed pngs.
Removed some old blitter code.
Modified: trunk/src/blitter.cxx
===================================================================
--- trunk/src/blitter.cxx 2006-01-09 21:28:30 UTC (rev 2585)
+++ trunk/src/blitter.cxx 2006-01-10 17:44:01 UTC (rev 2586)
@@ -501,44 +501,31 @@
unsigned char* tbuffer = static_cast<unsigned char*>(canvas.get_data ());
int pwidth = provider.get_width ();
int pheight = provider.get_height ();
+ int pitch = provider.get_pitch();
- if (provider.get_format().get_type() == pixelformat_index)
- {
- CL_Colorf color;
-
- // Slow but generic, using get_data () would be better, but would
- // require quite a bit of work
- for (int y = 0; y < height; ++y)
+ if (provider.get_format().get_type() == pixelformat_index)
{
- for (int x = 0; x < width; ++x)
- {
- unsigned char pixel = *(static_cast<unsigned
char*>(provider.get_data ())
- + (y * pheight/height) *
provider.get_pitch() + (x * pwidth/width));
+ CL_Color color;
+ pout(PINGUS_DEBUG_ACTIONS) <<
+ "Blitter::scale_surface_to_canvas() - Scaling indexed
image" << std::endl;
+
+ for (int y = 0; y < height; ++y)
+ for (int x = 0; x < width; ++x)
+ {
+ unsigned offset = (y * pheight/height) * pitch
+ (x * pwidth/width);
- if (!CL_Endian::is_system_big())
- {
- color.red = provider.get_palette().colors[pixel*3 +0].color /
255.0f;
- color.green = provider.get_palette().colors[pixel*3
+1].color / 255.0f;
- color.blue = provider.get_palette().colors[pixel*3 +2].color /
255.0f;
- }
- else
- {
- color.red = provider.get_palette().colors[pixel*3 +1].color /
255.0f;
- color.green = provider.get_palette().colors[pixel*3 +1].color /
255.0f;
- color.blue = provider.get_palette().colors[pixel*3 +0].color /
255.0f;
- }
+ color =
provider.get_palette().colors[sbuffer[offset]];
- if (provider.get_format().has_colorkey()
- && provider.get_format().get_colorkey() == pixel)
- color.alpha = 0.0f;
- else
- color.alpha = 1.0f;
-
- // FIXME: ignoring the source alpha due to get_pixel brokeness...
no time to test the patch
- canvas.draw_pixel(x, y, CL_Color(color));
- }
+ // Detrmine alpha channel
+ if (provider.get_format().has_colorkey()
+ && provider.get_format().get_colorkey()
== sbuffer[offset])
+ color.set_alpha(0);
+ else
+ color.set_alpha(255);
+
+ canvas.draw_pixel(x, y, color);
+ }
}
- }
else
{
switch (provider.get_format().get_depth())
@@ -547,6 +534,8 @@
{
// We assume that we have the data in RGB888, which might not be
// the case
+ pout(PINGUS_DEBUG_ACTIONS) <<
+ "Blitter::scale_surface_to_canvas() - Scaling 24 bit image" <<
std::endl;
for (int y = 0; y < height; ++y)
for (int x = 0; x < width; ++x)
{
@@ -575,6 +564,9 @@
{
// We assume that we have the data in RGBA8888, which might not be
// the case
+ pout(PINGUS_DEBUG_ACTIONS) <<
+ "Blitter::scale_surface_to_canvas() - Scaling 32 bit
image" << std::endl;
+
for (int y = 0; y < height; ++y)
for (int x = 0; x < width; ++x)
{
@@ -600,18 +592,22 @@
}
break;
default:
- // Slow but generic, using get_data () would be better, but would
- // require quite a bit of work
- for (int y = 0; y < height; ++y)
- for (int x = 0; x < width; ++x)
- {
- CL_Color color = provider.get_pixel(x * provider.get_width () /
width,
- y * provider.get_height ()
/ height);
- // FIXME: ignoring the source alpha due to get_pixel
- // brokeness... no time to test the patch
- canvas.draw_pixel(x, y, color);
- }
- break;
+ // Slow but generic, using get_data () would be better, but
would
+ // require quite a bit of work
+ pout(PINGUS_DEBUG_ACTIONS) <<
+ "Blitter::scale_surface_to_canvas() - Scaling image
using default method"
+ << std::endl;
+
+ for (int y = 0; y < height; ++y)
+ for (int x = 0; x < width; ++x)
+ {
+ CL_Color color = provider.get_pixel(x * pwidth
/ width,
+ y * pheight / height);
+ // FIXME: ignoring the source alpha due to
get_pixel
+ // brokeness... no time to test the patch
+ canvas.draw_pixel(x, y, color);
+ }
+ break;
}
}
@@ -627,76 +623,6 @@
return Blitter::scale_surface_to_canvas(sur.get_pixeldata(), width, height);
}
-/*
-// Converts a SurfaceProvider based surface, to a Canvas
-// based one. The old one will not be deleted.
-CL_Surface
-Blitter::convert_to_emptyprovider(CL_Surface ssurf)
-{
-CL_PixelBuffer& tprov = convert_to_emptyprovider(ssurf.get_provider());
-return CL_Surface::create(tprov, true);
-}
-
-// Converts a SurfaceProvider, to an Canvas and returns
-// the newly allocated provider, you need to delete it yourself.
-CL_PixelBuffer&
-Blitter::convert_to_emptyprovider(CL_PixelBuffer& sprov)
-{
- CL_PixelBuffer* tprov;
- CL_Palette* palette;
- unsigned char* sbuffer;
- unsigned char* tbuffer;
- int i;
-
- sprov.lock();
- switch(sprov.get_format().get_depth())
- {
- case 32:
- tprov = new CL_PixelBuffer(sprov.get_width(),
- sprov.get_height());
- tprov.lock();
-
- sbuffer = static_cast<unsigned char*>(sprov.get_data());
- tbuffer = static_cast<unsigned char*>(tprov.get_data());
-
- for(i=0; i < (tprov.get_height() * tprov.get_pitch()); ++i)
- {
- tbuffer[i] = sbuffer[i];
- }
-
- tprov.unlock();
- break;
- case 8:
- tprov = new CL_PixelBuffer(sprov.get_width(),
- sprov.get_height());
- palette = sprov.get_palette();
- tprov.lock();
-
- sbuffer = static_cast<unsigned char*>(sprov.get_data());
- tbuffer = static_cast<unsigned char*>(tprov.get_data());
-
- for(i=0; i < (sprov.get_height() * sprov.get_pitch()); ++i)
- {
- tbuffer[i * 4 + 0] = 255;
- tbuffer[i * 4 + 1] = palette.palette[sbuffer[i] * 3 + 2];
- tbuffer[i * 4 + 2] = palette.palette[sbuffer[i] * 3 + 1];
- tbuffer[i * 4 + 3] = palette.palette[sbuffer[i] * 3 + 0];
- }
-
- tprov.unlock();
- break;
- default:
- std::cout << "convert_to_emptyprovider(): Wrong source format: "
- << static_cast<int>(sprov.get_format().get_depth()) <<
std::endl;
- assert(false);
- break;
- }
- sprov.unlock();
-
- return tprov;
-}
-*/
-
/** Flip a surface horizontal */
CL_PixelBuffer
Blitter::flip_horizontal (CL_PixelBuffer prov)
Modified: trunk/src/display/drawing_context.cxx
===================================================================
--- trunk/src/display/drawing_context.cxx 2006-01-09 21:28:30 UTC (rev
2585)
+++ trunk/src/display/drawing_context.cxx 2006-01-10 17:44:01 UTC (rev
2586)
@@ -19,6 +19,7 @@
#include <assert.h>
#include <iostream>
+#include <ClanLib/Display/display.h>
#include <ClanLib/Display/sprite.h>
#include <ClanLib/Display/font.h>
#include <ClanLib/Display/graphic_context.h>
@@ -371,19 +372,19 @@
{
return CL_Rect(CL_Point(static_cast<int>(-translate_stack.back().x),
static_cast<int>(-translate_stack.back().y)),
- CL_Size(800, 600));
+ CL_Size((int)get_width(), (int)get_height()));
}
float
DrawingContext::get_width() const
{
- return 800;
+ return CL_Display::get_width();
}
float
DrawingContext::get_height() const
{
- return 600;
+ return CL_Display::get_height();
}
void
Modified: trunk/src/display/scene_context.cxx
===================================================================
--- trunk/src/display/scene_context.cxx 2006-01-09 21:28:30 UTC (rev 2585)
+++ trunk/src/display/scene_context.cxx 2006-01-10 17:44:01 UTC (rev 2586)
@@ -36,9 +36,9 @@
//CL_Canvas canvas;
SceneContextImpl()
- : lightmap(CL_PixelBuffer(static_cast<int>(800/SCALE_FACTOR),
- static_cast<int>(600/SCALE_FACTOR),
- static_cast<int>(800/SCALE_FACTOR*4),
+ :
lightmap(CL_PixelBuffer(static_cast<int>(CL_Display::get_width()/SCALE_FACTOR),
+
static_cast<int>(CL_Display::get_height()/SCALE_FACTOR),
+
static_cast<int>(CL_Display::get_width()/SCALE_FACTOR*4),
CL_PixelFormat::rgba8888))
//canvas(lightmap)
{
Modified: trunk/src/layer_manager.cxx
===================================================================
--- trunk/src/layer_manager.cxx 2006-01-09 21:28:30 UTC (rev 2585)
+++ trunk/src/layer_manager.cxx 2006-01-10 17:44:01 UTC (rev 2586)
@@ -31,9 +31,9 @@
}
void
-LayerManager::add_layer (const CL_Sprite& sur, float x_o, float y_o, float
x_u, float y_u)
+LayerManager::add_layer (const CL_PixelBuffer& sur, float x_o, float y_o,
float x_u, float y_u)
{
- layers.push_back (Layer(sur, x_o, y_o, x_u, y_u));
+ layers.push_back (Layer(CL_Surface(sur), x_o, y_o, x_u, y_u));
}
void
Modified: trunk/src/layer_manager.hxx
===================================================================
--- trunk/src/layer_manager.hxx 2006-01-09 21:28:30 UTC (rev 2585)
+++ trunk/src/layer_manager.hxx 2006-01-10 17:44:01 UTC (rev 2586)
@@ -22,7 +22,8 @@
#include "pingus.hxx"
#include <cmath>
-#include <ClanLib/Display/sprite.h>
+#include <ClanLib/Display/surface.h>
+#include <ClanLib/Display/display.h>
#include "display/drawing_context.hxx"
namespace Pingus {
@@ -33,7 +34,7 @@
class Layer
{
private:
- CL_Sprite sur;
+ CL_Surface sur;
float x_pos;
float y_pos;
@@ -51,7 +52,7 @@
x_offset(0), y_offset(0)
{}
- Layer (const CL_Sprite& arg_sur, float x_o, float y_o, float x_u, float
y_u)
+ Layer (const CL_Surface& arg_sur, float x_o, float y_o, float x_u, float
y_u)
: sur(arg_sur),
x_pos(0), y_pos(0),
x_update(x_u), y_update(y_u),
@@ -61,13 +62,13 @@
void draw (DrawingContext& gc)
{
gc.draw(sur, Vector(x_pos + x_offset, y_pos + y_offset));
- gc.draw(sur, Vector(x_pos + x_offset - 800, y_pos + y_offset));
+ gc.draw(sur, Vector(x_pos + x_offset - gc.get_width(), y_pos +
y_offset));
}
void update (float delta)
{
- x_pos = fmod((x_pos + x_update * delta),800);
- y_pos = fmod((y_pos + y_update * delta),600);
+ x_pos = fmod((x_pos + x_update * delta),CL_Display::get_width());
+ y_pos = fmod((y_pos + y_update * delta),CL_Display::get_height());
}
};
@@ -77,7 +78,7 @@
LayerManager ();
~LayerManager();
- void add_layer (const CL_Sprite& sur, float x_o, float y_o, float x_u, float
y_u);
+ void add_layer (const CL_PixelBuffer& sur, float x_o, float y_o, float x_u,
float y_u);
void draw (DrawingContext& gc);
void update (float delta);
Modified: trunk/src/pingus_menu_manager.cxx
===================================================================
--- trunk/src/pingus_menu_manager.cxx 2006-01-09 21:28:30 UTC (rev 2585)
+++ trunk/src/pingus_menu_manager.cxx 2006-01-10 17:44:01 UTC (rev 2586)
@@ -22,6 +22,7 @@
#include "gui/screen_manager.hxx"
#include "sound/sound.hxx"
#include "resource.hxx"
+#include "blitter.hxx"
#include "pingus_menu_manager.hxx"
namespace Pingus {
@@ -32,13 +33,20 @@
: mainmenu (this),
exitmenu (this)
{
- background.add_layer (Resource::load_sprite("core/menu/layer1"), 0, 0, 12,
0);
- background.add_layer (Resource::load_sprite("core/menu/layer2"), 0, 150,
25, 0);
- background.add_layer (Resource::load_sprite("core/menu/layer3"), 0, 200, 50,
0);
- background.add_layer (Resource::load_sprite("core/menu/layer4"), 0, 600 -
171, 100, 0);
- background.add_layer (Resource::load_sprite("core/menu/layer5"), 0, 500,
200, 0);
-
- push_menu (&mainmenu);
+ int w = (int)CL_Display::get_width();
+ int h = (int)CL_Display::get_height();
+ background.add_layer (Blitter::scale_surface_to_canvas(
+ Resource::load_pixelbuffer("core/menu/layer1"), w, 185 * h /
600), 0, 0, 12, 0);
+ background.add_layer (Blitter::scale_surface_to_canvas(
+ Resource::load_pixelbuffer("core/menu/layer2"), w, 362 * h /
600), 0, 150 * h / 600, 25, 0);
+ background.add_layer (Blitter::scale_surface_to_canvas(
+ Resource::load_pixelbuffer("core/menu/layer3"), w, 306 * h /
600), 0, 200 * h / 600, 50, 0);
+ background.add_layer (Blitter::scale_surface_to_canvas(
+ Resource::load_pixelbuffer("core/menu/layer4"), w, 171 * h /
600), 0, 429 * h / 600, 100, 0);
+ background.add_layer (Blitter::scale_surface_to_canvas(
+ Resource::load_pixelbuffer("core/menu/layer5"), 302 * w / 800,
104 * h / 600), 0, 500 * h / 600, 200, 0);
+
+ push_menu (&mainmenu);
}
PingusMenuManager::~PingusMenuManager ()
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Pingus-CVS] r2586 - in trunk/src: . display,
jave27 <=