2019-07-09 02:18:48 +02:00
|
|
|
/* Copyright (C) 2019 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, which is actually a collage of several
|
|
|
|
sprites.
|
|
|
|
*/
|
|
|
|
|
2007-05-07 18:33:24 +02:00
|
|
|
#ifndef INCLUDED_CGUISPRITE
|
|
|
|
#define INCLUDED_CGUISPRITE
|
2003-11-03 17:22:45 +01:00
|
|
|
|
2019-08-20 12:51:29 +02:00
|
|
|
#include "gui/GUIRenderer.h"
|
2019-10-02 11:44:00 +02:00
|
|
|
#include "gui/SettingTypes/CGUISize.h"
|
2020-11-21 12:20:29 +01:00
|
|
|
#include "gui/SettingTypes/CGUIColor.h"
|
|
|
|
#include "lib/ogl.h"
|
|
|
|
#include "lib/file/vfs/vfs_path.h"
|
|
|
|
#include "ps/CStr.h"
|
2003-11-03 17:22:45 +01:00
|
|
|
|
2019-09-20 15:11:18 +02:00
|
|
|
#include <map>
|
2019-08-17 13:52:57 +02:00
|
|
|
#include <memory>
|
2019-09-20 15:11:18 +02:00
|
|
|
#include <vector>
|
2019-08-17 13:52:57 +02:00
|
|
|
|
2004-12-18 14:32:00 +01:00
|
|
|
struct SGUIImageEffects
|
|
|
|
{
|
2004-12-19 13:20:04 +01:00
|
|
|
SGUIImageEffects() : m_Greyscale(false) {}
|
2019-07-26 20:57:28 +02:00
|
|
|
CGUIColor m_AddColor;
|
|
|
|
CGUIColor m_SolidColor;
|
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() :
|
2019-10-01 17:06:13 +02:00
|
|
|
m_FixedHAspectRatio(0.f),
|
|
|
|
m_RoundCoordinates(true),
|
|
|
|
m_WrapMode(GL_REPEAT),
|
|
|
|
m_Effects(),
|
|
|
|
m_Border(false),
|
|
|
|
m_DeltaZ(0.f),
|
|
|
|
m_Size(CGUISize::Full()),
|
|
|
|
m_TextureSize(CGUISize::Full())
|
2014-01-03 21:19:43 +01:00
|
|
|
{
|
|
|
|
}
|
2004-07-14 00:48:53 +02:00
|
|
|
|
2004-12-15 22:24:46 +01:00
|
|
|
// Filename of the texture
|
2019-09-23 01:28:25 +02: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)
|
2019-10-01 17:06:13 +02:00
|
|
|
CGUISize m_Size;
|
2003-11-03 17:22:45 +01:00
|
|
|
|
2004-12-15 22:24:46 +01:00
|
|
|
// Texture placement (relative to image placement)
|
2019-10-01 17:06:13 +02:00
|
|
|
CGUISize 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
|
2019-09-23 01:28:25 +02:00
|
|
|
CRect m_TexturePlacementInFile;
|
2004-09-02 05:02:32 +02:00
|
|
|
|
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.
|
2019-09-23 01:28:25 +02:00
|
|
|
CSize m_CellSize;
|
2004-12-18 14:32:00 +01:00
|
|
|
|
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.
|
|
|
|
*/
|
2019-09-23 01:28:25 +02:00
|
|
|
float m_FixedHAspectRatio;
|
2011-08-20 19:17:53 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* If true, the image's coordinates will be rounded to integer pixels when
|
|
|
|
* rendering, to avoid blurry filtering.
|
|
|
|
*/
|
2019-09-23 01:28:25 +02:00
|
|
|
bool m_RoundCoordinates;
|
2011-08-20 19:17:53 +02:00
|
|
|
|
|
|
|
/**
|
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
|
|
|
*/
|
2019-09-23 01:28:25 +02:00
|
|
|
GLint m_WrapMode;
|
2011-08-20 19:17:53 +02:00
|
|
|
|
2015-03-16 00:59:48 +01:00
|
|
|
// Visual effects (e.g. color modulation)
|
2019-08-17 13:52:57 +02:00
|
|
|
std::shared_ptr<SGUIImageEffects> m_Effects;
|
2004-12-15 22:24:46 +01:00
|
|
|
|
2003-12-01 08:06:55 +01:00
|
|
|
// Color
|
2019-07-26 20:57:28 +02:00
|
|
|
CGUIColor m_BackColor;
|
|
|
|
CGUIColor 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
|
2019-09-23 01:28:25 +02:00
|
|
|
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.
|
|
|
|
*/
|
2019-09-23 01:28:25 +02:00
|
|
|
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
|
|
|
// 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
|
|
|
|
{
|
MOVABLE idiom, const CGUI struct maps, in place move construction instead of copying temporaries during CGUI XML loading and GenerateText.
Introduce MOVABLE idiom indicating that a class can use move semantics.
Make values of CGUI struct maps holding XML data const to ensure at the
root that the data is not modified.
Use NONCOPYABLE and MOVABLE for SGUIIcon and SGUIStyle to enforce the
non-copy policy on the compiler level (until someone changes the GUI
design to make modifications needed).
As indicated by that:
Replace copy operations by in place move operations for these CGUI
struct maps in the CGUI Xeromyces XML loading functions.
Replace copy operations by const references for CSize and SGUIIcon in
CGUIString::GenerateTextCall and CGUI::GenerateText.
This avoids copying of non primitive members, such as the strings and
containers of strings.
Further related cleanup to be kept separated for auditability.
Differential Revision: https://code.wildfiregames.com/D2163
Few comments on IRC by: wraitii, Itms
Tested on: gcc 9, Jenkins, partially VS2015
Refs #1984,
NONCOPYABLE CGUISpriteInstances: 0a7d0ecdde, 8f4f8e240f, c19f3608a5
NONCOPYABLE Image, Sprite: fb8032043b
NONCOPYABLE GUI page: 94c57085e9
NONCOPYABLE GUIManager: 7c2e9027c2
NONCOPYABLE macro: 16ccae10cd
This was SVN commit r22637.
2019-08-09 19:25:55 +02:00
|
|
|
public:
|
2019-07-29 00:40:58 +02:00
|
|
|
NONCOPYABLE(CGUISpriteInstance);
|
MOVABLE idiom, const CGUI struct maps, in place move construction instead of copying temporaries during CGUI XML loading and GenerateText.
Introduce MOVABLE idiom indicating that a class can use move semantics.
Make values of CGUI struct maps holding XML data const to ensure at the
root that the data is not modified.
Use NONCOPYABLE and MOVABLE for SGUIIcon and SGUIStyle to enforce the
non-copy policy on the compiler level (until someone changes the GUI
design to make modifications needed).
As indicated by that:
Replace copy operations by in place move operations for these CGUI
struct maps in the CGUI Xeromyces XML loading functions.
Replace copy operations by const references for CSize and SGUIIcon in
CGUIString::GenerateTextCall and CGUI::GenerateText.
This avoids copying of non primitive members, such as the strings and
containers of strings.
Further related cleanup to be kept separated for auditability.
Differential Revision: https://code.wildfiregames.com/D2163
Few comments on IRC by: wraitii, Itms
Tested on: gcc 9, Jenkins, partially VS2015
Refs #1984,
NONCOPYABLE CGUISpriteInstances: 0a7d0ecdde, 8f4f8e240f, c19f3608a5
NONCOPYABLE Image, Sprite: fb8032043b
NONCOPYABLE GUI page: 94c57085e9
NONCOPYABLE GUIManager: 7c2e9027c2
NONCOPYABLE macro: 16ccae10cd
This was SVN commit r22637.
2019-08-09 19:25:55 +02:00
|
|
|
MOVABLE(CGUISpriteInstance);
|
2019-07-29 00:40:58 +02:00
|
|
|
|
2004-12-15 22:24:46 +01:00
|
|
|
CGUISpriteInstance();
|
2006-07-20 16:37:58 +02:00
|
|
|
CGUISpriteInstance(const CStr& SpriteName);
|
2019-07-29 00:40:58 +02:00
|
|
|
|
2019-08-21 12:12:33 +02:00
|
|
|
void Draw(CGUI& pGUI, const CRect& Size, int CellID, std::map<CStr, const CGUISprite*>& Sprites, float Z) const;
|
2019-08-18 17:17:49 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Whether this Sprite has no texture name set.
|
|
|
|
*/
|
|
|
|
operator bool() const { return !m_SpriteName.empty(); };
|
|
|
|
|
|
|
|
/**
|
2019-08-20 12:51:29 +02:00
|
|
|
* Returns this sprite if it has been set, otherwise the given fallback sprite.
|
2019-08-18 17:17:49 +02:00
|
|
|
*/
|
|
|
|
const CGUISpriteInstance& operator||(const CGUISpriteInstance& fallback) const
|
|
|
|
{
|
|
|
|
if (*this)
|
|
|
|
return *this;
|
|
|
|
return fallback;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the sprite texture name.
|
|
|
|
*/
|
2019-07-29 00:40:58 +02:00
|
|
|
const CStr& GetName() const { return m_SpriteName; }
|
2019-08-18 17:17:49 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Changes the texture name.
|
|
|
|
* Use as rarely as possible, because it clears the draw cache.
|
|
|
|
*/
|
2019-07-29 00:40:58 +02:00
|
|
|
void SetName(const CStr& 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
|