Hi,
Maybe you should abstract away the Graphics system as well as surfaces.
For instance assume Sprite should, for performance reasons, create some
surface in the graphics system (if that is possible for that graphics system
on GDI based system it would just use system memory).
For instance:
---------------------------------------------------------------------------------
#include <list>
using namespace std;
// Generic Class that holds a piece of memory to prepare sprite on (could be
located on the graphics card in system core or ....
class GRGB;
class GSprite;
class GSurface
{
private:
unsigned long Width,Height;
public:
GSurface( unsigned long Width, unsigned long Height ):
Width( Width ),
Height( Height )
{
}
// Draw
virtual void Prepare( unsigned long X, unsigned long Y, unsigned
long Width, GRGB *BunchOfRgbValues ) = 0;
};
class GGDISurface : public GSurface
{
public:
// New some memory from the heap on construction
GGDISurface( unsigned long Width, unsigned long Height ):
GSurface( Width, Height )
{
// Do stuff
}
// GDI Implementation draw on a piece of system memory, this is to
prepare the sprite
virtual void Prepare( unsigned long X, unsigned long Y, unsigned
long Width, GRGB *BunchOfRgbValues )
{
}
};
class GDirectXSurface : public GSurface
{
public:
// Get some memory from the graphics card on construction
GDirectXSurface( unsigned long Width, unsigned long Height ):
GSurface( Width, Height )
{}
// DirectX Implementation draw on the piece of memory on the
graphics card
virtual void Prepare( unsigned long X, unsigned long Y, unsigned
long Width, GRGB *BunchOfRgbValues )
{
}
};
class GGraphicsSystem
{
private:
std::list<GSprite*> SpriteList;
public:
virtual void AddSprite( GSprite *Sprite );
virtual GSurface *CreateSurface( unsigned long Width, unsigned long
Height ) = 0;
};
class GDirectXGraphicsSystem : public GGraphicsSystem
{
public:
GDirectXSurface *CreateSurface( unsigned long Width, unsigned long
Height )
{
}
};
class GSprite
{
private:
GSurface *Surface;
public:
GSprite( GGraphicsSystem * GraphicsSystem )
{
Surface = GraphicsSystem->CreateSurface( 200, 200 );
GRGB *Values;
Surface->Prepare( 10, 10, 100, Values );
}
// Called by graphic system when sprites need to be redrawn (to keep it
simple I assume the 'real' screen is also a surface
void Draw( GSurface *ScreenSurface )
{
// Draw myself GSurface should also contain some (virtual) methods to
draw GSurfaces on GSurfaces
}
};
int main( int ArgC, char *ArgV[] )
{
return 0;
}
Regards, Ron AF Greve
http://moonlit.xs4all.nl
"Chocawok" <> wrote in message
news:3NxCf.204940$ .uk...
>
>
> Some of the classes in my app are graphical.
>
> To encapsulate the graphical side of things I had created a class called
> "sprite" which holds a bit map and knows how to draw itself etc.
>
>
>
> The classes that are graphical contain a sprite object.
>
>
>
> MyClass
>
> {
>
> private:
>
> Sprite this_objects_sprite;
>
> }
>
>
>
>
>
> The sprite class requires a pointer to a "video surface". There is no way
> around this. The pointer is required for the construction and drawing of
> the sprite object.
>
>
>
> My problem is this:
>
>
>
> This design means that I have to pass the pointer to the video surface to
> myclass in its constructor, e.g.
>
>
>
> MyClass
>
> {
>
> private:
>
> Sprite this_objects_sprite;
>
>
>
> public:
>
> MyClass(VideoSurface* s)
>
> {
>
> this_objects_sprite = new Sprite(VideoSurface* s);
>
> ...
>
> ...
>
> }
>
> ...
>
> ...
>
> }
>
>
>
> Obviously this means all my graphical objects are tightly coupled to the
> graphics system I am using. Also obviously (I think) is that this is
> undesireable.
>
>
>
> I was thinking of maybe arranging things so that the sprite is not
> automatically instantiated in the container objects constructor.
>
> That is, I construct my object THEN call a function to construct the
> objects sprite, e.g.
>
>
>
> MyClass c = new MyClass();
>
> c.CreateSprite(VideoSurface* s);
>
>
>
> But then this raised other issues like, how do I handle what happens if i
> try to draw the object before creating its sprite.
>
>
>
> Any thoughts on this?
>
> Dean
>