Modernized code in guisan objects, improved GUI layout
This commit is contained in:
parent
ed31f6849d
commit
ecb56ef5be
94 changed files with 7326 additions and 7347 deletions
|
@ -63,79 +63,79 @@
|
|||
|
||||
namespace gcn
|
||||
{
|
||||
/**
|
||||
* OpenGL implementation of the Graphics.
|
||||
*/
|
||||
class GCN_EXTENSION_DECLSPEC OpenGLGraphics: public Graphics
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* OpenGL implementation of the Graphics.
|
||||
*/
|
||||
class GCN_EXTENSION_DECLSPEC OpenGLGraphics : public Graphics
|
||||
{
|
||||
public:
|
||||
|
||||
// Needed so that drawImage(gcn::Image *, int, int) is visible.
|
||||
using Graphics::drawImage;
|
||||
// Needed so that drawImage(gcn::Image *, int, int) is visible.
|
||||
using Graphics::drawImage;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
OpenGLGraphics();
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
OpenGLGraphics();
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param width the width of the logical drawing surface. Should be the
|
||||
* same as the screen resolution.
|
||||
* same as the screen resolution.
|
||||
*
|
||||
* @param height the height ot the logical drawing surface. Should be
|
||||
* the same as the screen resolution.
|
||||
*/
|
||||
OpenGLGraphics(int width, int height);
|
||||
OpenGLGraphics(int width, int height);
|
||||
|
||||
/**
|
||||
* Destructor.
|
||||
*/
|
||||
virtual ~OpenGLGraphics();
|
||||
virtual ~OpenGLGraphics();
|
||||
|
||||
/**
|
||||
* Sets the target plane on where to draw.
|
||||
/**
|
||||
* Sets the target plane on where to draw.
|
||||
*
|
||||
* @param width the width of the logical drawing surface. Should be the
|
||||
* same as the screen resolution.
|
||||
* @param height the height ot the logical drawing surface. Should be
|
||||
* the same as the screen resolution.
|
||||
*/
|
||||
virtual void setTargetPlane(int width, int height);
|
||||
*/
|
||||
virtual void setTargetPlane(int width, int height);
|
||||
|
||||
|
||||
// Inherited from Graphics
|
||||
|
||||
virtual void _beginDraw();
|
||||
void _beginDraw() override;
|
||||
|
||||
virtual void _endDraw();
|
||||
void _endDraw() override;
|
||||
|
||||
virtual bool pushClipArea(Rectangle area);
|
||||
bool pushClipArea(Rectangle area) override;
|
||||
|
||||
virtual void popClipArea();
|
||||
void popClipArea() override;
|
||||
|
||||
virtual void drawImage(const Image* image, int srcX, int srcY,
|
||||
int dstX, int dstY, int width,
|
||||
int height);
|
||||
void drawImage(const Image* image, int srcX, int srcY,
|
||||
int dstX, int dstY, int width,
|
||||
int height) override;
|
||||
|
||||
virtual void drawPoint(int x, int y);
|
||||
void drawPoint(int x, int y) override;
|
||||
|
||||
virtual void drawLine(int x1, int y1, int x2, int y2);
|
||||
void drawLine(int x1, int y1, int x2, int y2) override;
|
||||
|
||||
virtual void drawRectangle(const Rectangle& rectangle);
|
||||
void drawRectangle(const Rectangle& rectangle) override;
|
||||
|
||||
virtual void fillRectangle(const Rectangle& rectangle);
|
||||
void fillRectangle(const Rectangle& rectangle) override;
|
||||
|
||||
virtual void setColor(const Color& color);
|
||||
void setColor(const Color& color) override;
|
||||
|
||||
virtual const Color& getColor();
|
||||
const Color& getColor() override;
|
||||
|
||||
protected:
|
||||
int mWidth, mHeight;
|
||||
protected:
|
||||
int mWidth, mHeight;
|
||||
bool mAlpha;
|
||||
Color mColor;
|
||||
};
|
||||
Color mColor;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // end GCN_OPENGLGRAPHICS_HPP
|
||||
|
|
|
@ -79,93 +79,92 @@
|
|||
|
||||
namespace gcn
|
||||
{
|
||||
/**
|
||||
* OpenGL implementation of Image.
|
||||
*/
|
||||
class GCN_EXTENSION_DECLSPEC OpenGLImage : public Image
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Constructor. Loads an image from an array of pixels. The pixel array is
|
||||
/**
|
||||
* OpenGL implementation of Image.
|
||||
*/
|
||||
class GCN_EXTENSION_DECLSPEC OpenGLImage : public Image
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Constructor. Loads an image from an array of pixels. The pixel array is
|
||||
* is copied in the constructor and should thus be freed after the constructor
|
||||
* has been called.
|
||||
*
|
||||
* NOTE: The functions getPixel and putPixel are only guaranteed to work
|
||||
* before an image has been converted to display format.
|
||||
*
|
||||
* @param pixels to load from.
|
||||
* @param width the width of the image.
|
||||
* @param height the height of the image.
|
||||
* @param convertToDisplayFormat true if the image should be converted
|
||||
* to display, false otherwise.
|
||||
*/
|
||||
OpenGLImage(unsigned int* pixels, int width, int height, bool convertToDisplayFormat = true);
|
||||
*
|
||||
* NOTE: The functions getPixel and putPixel are only guaranteed to work
|
||||
* before an image has been converted to display format.
|
||||
*
|
||||
* @param pixels to load from.
|
||||
* @param width the width of the image.
|
||||
* @param height the height of the image.
|
||||
* @param convertToDisplayFormat true if the image should be converted
|
||||
* to display, false otherwise.
|
||||
*/
|
||||
OpenGLImage(unsigned int* pixels, int width, int height, bool convertToDisplayFormat = true);
|
||||
|
||||
/**
|
||||
* Constructor. Load an image from an OpenGL texture handle. The width
|
||||
/**
|
||||
* Constructor. Load an image from an OpenGL texture handle. The width
|
||||
* and height specifies the size of the "interesting" part of the
|
||||
* texture, the real width and height of the texture are assumed to
|
||||
* be the closest higher power of two.
|
||||
*
|
||||
* @param textureHandle the texture handle from which to load.
|
||||
*
|
||||
* @param textureHandle the texture handle from which to load.
|
||||
* @param width the width of the image.
|
||||
* @param height the height of the image.
|
||||
* @param autoFree true if the surface should automatically be deleted.
|
||||
*/
|
||||
OpenGLImage(GLuint textureHandle, int width, int height, bool autoFree);
|
||||
* @param autoFree true if the surface should automatically be deleted.
|
||||
*/
|
||||
OpenGLImage(GLuint textureHandle, int width, int height, bool autoFree);
|
||||
|
||||
/**
|
||||
* Destructor.
|
||||
*/
|
||||
virtual ~OpenGLImage();
|
||||
/**
|
||||
* Destructor.
|
||||
*/
|
||||
virtual ~OpenGLImage();
|
||||
|
||||
/**
|
||||
* Gets the OpenGL texture handle for the image.
|
||||
*
|
||||
* @return the OpenGL texture handle for the image.
|
||||
*/
|
||||
/**
|
||||
* Gets the OpenGL texture handle for the image.
|
||||
*
|
||||
* @return the OpenGL texture handle for the image.
|
||||
*/
|
||||
|
||||
virtual GLuint getTextureHandle() const;
|
||||
[[nodiscard]] virtual GLuint getTextureHandle() const;
|
||||
|
||||
/**
|
||||
* Gets the width of texture.
|
||||
*
|
||||
* @return the width of the texture.
|
||||
*/
|
||||
virtual int getTextureWidth() const;
|
||||
/**
|
||||
* Gets the width of texture.
|
||||
*
|
||||
* @return the width of the texture.
|
||||
*/
|
||||
[[nodiscard]] virtual int getTextureWidth() const;
|
||||
|
||||
/**
|
||||
* Gets the height of the texture.
|
||||
*
|
||||
* @return the height of the texture.
|
||||
*/
|
||||
virtual int getTextureHeight() const;
|
||||
/**
|
||||
* Gets the height of the texture.
|
||||
*
|
||||
* @return the height of the texture.
|
||||
*/
|
||||
[[nodiscard]] virtual int getTextureHeight() const;
|
||||
|
||||
|
||||
// Inherited from Image
|
||||
// Inherited from Image
|
||||
|
||||
virtual void free();
|
||||
void free() override;
|
||||
|
||||
virtual int getWidth() const;
|
||||
[[nodiscard]] int getWidth() const override;
|
||||
|
||||
virtual int getHeight() const;
|
||||
[[nodiscard]] int getHeight() const override;
|
||||
|
||||
virtual Color getPixel(int x, int y);
|
||||
Color getPixel(int x, int y) override;
|
||||
|
||||
virtual void putPixel(int x, int y, const Color& color);
|
||||
void putPixel(int x, int y, const Color& color) override;
|
||||
|
||||
virtual void convertToDisplayFormat();
|
||||
void convertToDisplayFormat() override;
|
||||
|
||||
protected:
|
||||
GLuint mTextureHandle;
|
||||
unsigned int* mPixels;
|
||||
bool mAutoFree;
|
||||
int mWidth;
|
||||
int mHeight;
|
||||
protected:
|
||||
GLuint mTextureHandle;
|
||||
unsigned int* mPixels;
|
||||
bool mAutoFree;
|
||||
int mWidth;
|
||||
int mHeight;
|
||||
int mTextureWidth;
|
||||
int mTextureHeight;
|
||||
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
#endif // end GCN_OPENGLIMAGE_HPP
|
||||
|
|
|
@ -64,46 +64,46 @@
|
|||
|
||||
namespace gcn
|
||||
{
|
||||
class Image;
|
||||
class Image;
|
||||
|
||||
/**
|
||||
* OpenGL ImageLoader that loads images with SDL.
|
||||
*/
|
||||
class OpenGLSDLImageLoader : public SDLImageLoader
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* OpenGL ImageLoader that loads images with SDL.
|
||||
*/
|
||||
class OpenGLSDLImageLoader : public SDLImageLoader
|
||||
{
|
||||
public:
|
||||
|
||||
// Inherited from ImageLoader
|
||||
// Inherited from ImageLoader
|
||||
|
||||
virtual Image* load(const std::string& filename,
|
||||
bool convertToDisplayFormat = true)
|
||||
{
|
||||
SDL_Surface *loadedSurface = loadSDLSurface(filename);
|
||||
Image* load(const std::string& filename,
|
||||
bool convertToDisplayFormat = true) override
|
||||
{
|
||||
SDL_Surface* loadedSurface = loadSDLSurface(filename);
|
||||
|
||||
if (loadedSurface == NULL)
|
||||
{
|
||||
throw GCN_EXCEPTION(
|
||||
std::string("Unable to load image file: ") + filename);
|
||||
}
|
||||
if (loadedSurface == nullptr)
|
||||
{
|
||||
throw GCN_EXCEPTION(
|
||||
std::string("Unable to load image file: ") + filename);
|
||||
}
|
||||
|
||||
SDL_Surface *surface = convertToStandardFormat(loadedSurface);
|
||||
SDL_FreeSurface(loadedSurface);
|
||||
SDL_Surface* surface = convertToStandardFormat(loadedSurface);
|
||||
SDL_FreeSurface(loadedSurface);
|
||||
|
||||
if (surface == NULL)
|
||||
{
|
||||
throw GCN_EXCEPTION(
|
||||
std::string("Not enough memory to load: ") + filename);
|
||||
}
|
||||
if (surface == nullptr)
|
||||
{
|
||||
throw GCN_EXCEPTION(
|
||||
std::string("Not enough memory to load: ") + filename);
|
||||
}
|
||||
|
||||
OpenGLImage *image = new OpenGLImage((unsigned int*)surface->pixels,
|
||||
surface->w,
|
||||
surface->h,
|
||||
convertToDisplayFormat);
|
||||
SDL_FreeSurface(surface);
|
||||
OpenGLImage* image = new OpenGLImage(static_cast<unsigned int*>(surface->pixels),
|
||||
surface->w,
|
||||
surface->h,
|
||||
convertToDisplayFormat);
|
||||
SDL_FreeSurface(surface);
|
||||
|
||||
return image;
|
||||
}
|
||||
};
|
||||
return image;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#endif // end GCN_OPENGLSDLIMAGELOADER_HPP
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue