2003-11-03 17:22:45 +01:00
|
|
|
/*
|
|
|
|
A GUI Sprite
|
|
|
|
by Gustav Larsson
|
|
|
|
gee@pyro.nu
|
|
|
|
|
|
|
|
--Overview--
|
|
|
|
|
|
|
|
A GUI Sprite, which is actually a collage of several
|
|
|
|
sprites.
|
|
|
|
|
|
|
|
--Usage--
|
|
|
|
|
|
|
|
Used internally and declared in XML files, read documentations
|
|
|
|
on how.
|
|
|
|
|
|
|
|
--More info--
|
|
|
|
|
|
|
|
Check GUI.h
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef CGUISprite_H
|
|
|
|
#define CGUISprite_H
|
|
|
|
|
|
|
|
//--------------------------------------------------------
|
|
|
|
// Includes / Compiler directives
|
|
|
|
//--------------------------------------------------------
|
2004-12-15 22:24:46 +01:00
|
|
|
#include "GUIutil.h"
|
|
|
|
|
2004-05-29 06:06:50 +02:00
|
|
|
#include "Overlay.h"
|
2004-09-19 13:38:54 +02:00
|
|
|
#include "lib/res/ogl_tex.h"
|
2003-11-03 17:22:45 +01:00
|
|
|
|
|
|
|
//--------------------------------------------------------
|
|
|
|
// Macros
|
|
|
|
//--------------------------------------------------------
|
|
|
|
|
|
|
|
//--------------------------------------------------------
|
|
|
|
// Types
|
|
|
|
//--------------------------------------------------------
|
|
|
|
|
|
|
|
//--------------------------------------------------------
|
|
|
|
// Error declarations
|
|
|
|
//--------------------------------------------------------
|
|
|
|
|
|
|
|
//--------------------------------------------------------
|
|
|
|
// Declarations
|
|
|
|
//--------------------------------------------------------
|
|
|
|
|
2003-11-18 11:00:57 +01:00
|
|
|
/**
|
|
|
|
* @author Gustav Larsson
|
|
|
|
*
|
|
|
|
* A CGUISprite is actually a collage of several <b>real</b>
|
|
|
|
* sprites, this struct represents is such real sprite.
|
|
|
|
*/
|
2003-11-03 17:22:45 +01:00
|
|
|
struct SGUIImage
|
|
|
|
{
|
2004-12-15 22:24:46 +01:00
|
|
|
SGUIImage() : m_Border(false), m_DeltaZ(0.f) {}
|
2004-07-14 00:48:53 +02:00
|
|
|
|
2004-12-15 22:24:46 +01:00
|
|
|
// Filename of the texture
|
2004-07-10 22:33:42 +02:00
|
|
|
CStr m_TextureName;
|
2003-11-03 17:22:45 +01:00
|
|
|
|
2004-12-15 22:24:46 +01:00
|
|
|
// Image placement (relative to object)
|
2003-12-01 08:06:55 +01:00
|
|
|
CClientArea m_Size;
|
2003-11-03 17:22:45 +01:00
|
|
|
|
2004-12-15 22:24:46 +01:00
|
|
|
// Texture placement (relative to image placement)
|
2003-12-01 08:06:55 +01:00
|
|
|
CClientArea m_TextureSize;
|
2003-11-03 17:22:45 +01:00
|
|
|
|
2004-09-02 05:02:32 +02:00
|
|
|
// Because OpenGL wants textures in squares with a power of 2 (64x64, 256x256)
|
2004-12-15 22:24:46 +01:00
|
|
|
// it's sometimes tedious to adjust this. So this value simulates which area
|
2004-09-02 05:02:32 +02:00
|
|
|
// is the real texture
|
|
|
|
CRect m_TexturePlacementInFile;
|
|
|
|
|
2004-12-15 22:24:46 +01:00
|
|
|
// For textures that contain a collection of icons (e.g. unit portraits), this
|
|
|
|
// will be set to the size of one icon. An object's icon-id will determine
|
|
|
|
// which part of the texture is used.
|
2004-12-17 17:20:08 +01:00
|
|
|
// Equal to CSize(0,0) for non-icon textures.
|
2004-12-15 22:24:46 +01:00
|
|
|
CSize m_IconSize;
|
|
|
|
|
2003-12-01 08:06:55 +01:00
|
|
|
// Color
|
|
|
|
CColor m_BackColor;
|
|
|
|
CColor m_BorderColor;
|
2003-11-24 03:18:41 +01:00
|
|
|
|
2003-12-01 08:06:55 +01:00
|
|
|
// 0 or 1 pixel border is the only option
|
|
|
|
bool m_Border;
|
2004-05-29 06:06:50 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Z value modification of the image.
|
|
|
|
* Inputted in XML as x-level, although it just an easier and safer
|
|
|
|
* way of declaring delta-z.
|
|
|
|
*/
|
|
|
|
float m_DeltaZ;
|
2003-11-03 17:22:45 +01:00
|
|
|
};
|
|
|
|
|
2003-11-18 11:00:57 +01:00
|
|
|
/**
|
|
|
|
* @author Gustav Larsson
|
|
|
|
*
|
|
|
|
* The GUI sprite, is actually several real sprites (images)
|
|
|
|
* like a collage. View the section <sprites> in the GUI
|
|
|
|
* TDD for more information.
|
2003-12-01 08:06:55 +01:00
|
|
|
*
|
|
|
|
* Drawing routine is located in CGUI
|
|
|
|
*
|
|
|
|
* @see CGUI#DrawSprite
|
2003-11-18 11:00:57 +01:00
|
|
|
*/
|
2003-11-03 17:22:45 +01:00
|
|
|
class CGUISprite
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CGUISprite() {}
|
|
|
|
virtual ~CGUISprite() {}
|
|
|
|
|
2003-11-18 11:00:57 +01:00
|
|
|
/**
|
|
|
|
* Adds an image to the sprite collage.
|
|
|
|
*
|
|
|
|
* @param image Adds this image to the sprite collage.
|
|
|
|
*/
|
2003-11-03 17:22:45 +01:00
|
|
|
void AddImage(const SGUIImage &image) { m_Images.push_back(image); }
|
|
|
|
|
2003-11-18 11:00:57 +01:00
|
|
|
/// List of images
|
2003-12-01 08:06:55 +01:00
|
|
|
std::vector<SGUIImage> m_Images;
|
2003-11-03 17:22:45 +01:00
|
|
|
};
|
|
|
|
|
2004-12-15 22:24:46 +01:00
|
|
|
#include "GUIRenderer.h"
|
|
|
|
|
|
|
|
// An instance of a sprite, usually stored in IGUIObjects - basically a string
|
|
|
|
// giving the sprite's name, but with some extra data to cache rendering
|
|
|
|
// calculations between draw calls.
|
|
|
|
class CGUISpriteInstance
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CGUISpriteInstance();
|
|
|
|
CGUISpriteInstance(CStr SpriteName);
|
|
|
|
CGUISpriteInstance &operator=(CStr SpriteName);
|
2004-12-17 17:20:08 +01:00
|
|
|
void Draw(CRect Size, int IconID, std::map<CStr, CGUISprite> &Sprites);
|
2004-12-15 22:24:46 +01:00
|
|
|
void Invalidate();
|
|
|
|
bool IsEmpty() const;
|
|
|
|
CStr GetName() { return m_SpriteName; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
CStr m_SpriteName;
|
|
|
|
|
|
|
|
// Stored drawing calls, for more efficient rendering
|
|
|
|
GUIRenderer::DrawCalls m_DrawCallCache;
|
2004-12-17 17:20:08 +01:00
|
|
|
// Relevant details of previously rendered sprite; the cache is invalidated
|
|
|
|
// whenever any of these values changes.
|
2004-12-15 22:24:46 +01:00
|
|
|
CRect m_CachedSize;
|
2004-12-17 17:20:08 +01:00
|
|
|
int m_CachedIconID;
|
2004-12-15 22:24:46 +01:00
|
|
|
};
|
|
|
|
|
2003-11-24 18:13:37 +01:00
|
|
|
#endif
|