2015-08-21 19:08:41 +02:00
|
|
|
/* Copyright (C) 2015 Wildfire Games.
|
2009-04-18 19:00:33 +02:00
|
|
|
* This file is part of 0 A.D.
|
|
|
|
*
|
|
|
|
* 0 A.D. is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* 0 A.D. is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2003-11-03 17:22:45 +01:00
|
|
|
/*
|
|
|
|
A GUI Sprite
|
|
|
|
|
|
|
|
--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
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2007-05-07 18:33:24 +02:00
|
|
|
#ifndef INCLUDED_CGUISPRITE
|
|
|
|
#define INCLUDED_CGUISPRITE
|
2003-11-03 17:22:45 +01:00
|
|
|
|
2006-01-29 19:23:47 +01:00
|
|
|
#include "GUIbase.h"
|
2004-12-15 22:24:46 +01:00
|
|
|
|
2005-08-12 19:06:53 +02:00
|
|
|
#include "lib/res/graphics/ogl_tex.h"
|
2003-11-03 17:22:45 +01:00
|
|
|
|
2004-12-18 14:32:00 +01:00
|
|
|
struct SGUIImageEffects
|
|
|
|
{
|
2004-12-19 13:20:04 +01:00
|
|
|
SGUIImageEffects() : m_Greyscale(false) {}
|
2004-12-18 14:32:00 +01:00
|
|
|
CColor m_AddColor;
|
2004-12-19 13:20:04 +01:00
|
|
|
bool m_Greyscale;
|
2004-12-18 14:32:00 +01:00
|
|
|
};
|
|
|
|
|
2003-11-18 11:00:57 +01:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
{
|
2015-08-21 19:08:41 +02:00
|
|
|
NONCOPYABLE(SGUIImage);
|
|
|
|
public:
|
2011-08-20 19:17:53 +02:00
|
|
|
SGUIImage() :
|
|
|
|
m_FixedHAspectRatio(0.f), m_RoundCoordinates(true), m_WrapMode(GL_REPEAT),
|
|
|
|
m_Effects(NULL), m_Border(false), m_DeltaZ(0.f)
|
|
|
|
{
|
|
|
|
}
|
2015-08-21 19:08:41 +02:00
|
|
|
|
2014-01-03 21:19:43 +01:00
|
|
|
~SGUIImage()
|
|
|
|
{
|
|
|
|
delete m_Effects;
|
|
|
|
}
|
2004-07-14 00:48:53 +02:00
|
|
|
|
2004-12-15 22:24:46 +01:00
|
|
|
// Filename of the texture
|
2009-11-03 22:46:35 +01:00
|
|
|
VfsPath 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
|
2004-12-18 14:32:00 +01:00
|
|
|
// will be set to the size of one icon. An object's cell-id will determine
|
2004-12-15 22:24:46 +01:00
|
|
|
// which part of the texture is used.
|
2004-12-18 14:32:00 +01:00
|
|
|
// Equal to CSize(0,0) for non-celled textures.
|
|
|
|
CSize m_CellSize;
|
|
|
|
|
2011-08-20 19:17:53 +02:00
|
|
|
/**
|
|
|
|
* If non-zero, then the image's width will be adjusted when rendering so that
|
|
|
|
* the width:height ratio equals this value.
|
|
|
|
*/
|
|
|
|
float m_FixedHAspectRatio;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* If true, the image's coordinates will be rounded to integer pixels when
|
|
|
|
* rendering, to avoid blurry filtering.
|
|
|
|
*/
|
|
|
|
bool m_RoundCoordinates;
|
|
|
|
|
|
|
|
/**
|
2012-02-08 21:43:38 +01:00
|
|
|
* Texture wrapping mode (GL_REPEAT, GL_CLAMP_TO_EDGE, etc)
|
2011-08-20 19:17:53 +02:00
|
|
|
*/
|
|
|
|
GLint m_WrapMode;
|
|
|
|
|
2015-03-16 00:59:48 +01:00
|
|
|
// Visual effects (e.g. color modulation)
|
2004-12-18 14:32:00 +01:00
|
|
|
SGUIImageEffects* m_Effects;
|
2004-12-15 22:24:46 +01:00
|
|
|
|
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;
|
2014-01-03 21:19:43 +01:00
|
|
|
};
|
2004-12-18 14:32:00 +01:00
|
|
|
|
2003-11-18 11:00:57 +01:00
|
|
|
/**
|
|
|
|
* The GUI sprite, is actually several real sprites (images)
|
2010-07-29 17:55:41 +02:00
|
|
|
* like a collage. View the section \<sprites\> in the GUI
|
2003-11-18 11:00:57 +01:00
|
|
|
* 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
|
|
|
|
{
|
2015-08-21 19:08:41 +02:00
|
|
|
NONCOPYABLE(CGUISprite);
|
2003-11-03 17:22:45 +01:00
|
|
|
public:
|
|
|
|
CGUISprite() {}
|
2014-01-03 21:19:43 +01:00
|
|
|
virtual ~CGUISprite();
|
2003-11-03 17:22:45 +01:00
|
|
|
|
2003-11-18 11:00:57 +01:00
|
|
|
/**
|
|
|
|
* Adds an image to the sprite collage.
|
|
|
|
*
|
|
|
|
* @param image Adds this image to the sprite collage.
|
|
|
|
*/
|
2014-01-03 21:19:43 +01:00
|
|
|
void AddImage(SGUIImage*);
|
2003-11-03 17:22:45 +01:00
|
|
|
|
2003-11-18 11:00:57 +01:00
|
|
|
/// List of images
|
2014-01-03 21:19:43 +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();
|
2006-07-20 16:37:58 +02:00
|
|
|
CGUISpriteInstance(const CStr& SpriteName);
|
2015-08-21 19:08:41 +02:00
|
|
|
CGUISpriteInstance(const CGUISpriteInstance& Sprite);
|
|
|
|
CGUISpriteInstance& operator=(const CStr& SpriteName);
|
2014-01-03 21:19:43 +01:00
|
|
|
void Draw(CRect Size, int CellID, std::map<CStr, CGUISprite*>& Sprites, float Z) const;
|
2004-12-15 22:24:46 +01:00
|
|
|
void Invalidate();
|
|
|
|
bool IsEmpty() const;
|
2006-07-20 16:37:58 +02:00
|
|
|
const CStr& GetName() { return m_SpriteName; }
|
2004-12-15 22:24:46 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
CStr m_SpriteName;
|
|
|
|
|
|
|
|
// Stored drawing calls, for more efficient rendering
|
2009-07-28 18:59:19 +02:00
|
|
|
mutable 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.
|
2009-07-28 18:59:19 +02:00
|
|
|
mutable CRect m_CachedSize;
|
|
|
|
mutable int m_CachedCellID;
|
2004-12-15 22:24:46 +01:00
|
|
|
};
|
|
|
|
|
2015-08-21 19:08:41 +02:00
|
|
|
#endif // INCLUDED_CGUISPRITE
|