GUI icon-sheets
This was SVN commit r1519.
This commit is contained in:
parent
8f4f8e240f
commit
6526301cfe
@ -32,6 +32,7 @@
|
|||||||
font CDATA #IMPLIED
|
font CDATA #IMPLIED
|
||||||
fov-wedge-color CDATA #IMPLIED
|
fov-wedge-color CDATA #IMPLIED
|
||||||
hotkey CDATA #IMPLIED
|
hotkey CDATA #IMPLIED
|
||||||
|
icon-id CDATA #IMPLIED
|
||||||
input-initvalue-destroyed-at-focus %bool; #IMPLIED
|
input-initvalue-destroyed-at-focus %bool; #IMPLIED
|
||||||
rectcolor-selected CDATA #IMPLIED
|
rectcolor-selected CDATA #IMPLIED
|
||||||
scrollbar %bool; #IMPLIED
|
scrollbar %bool; #IMPLIED
|
||||||
@ -148,6 +149,7 @@
|
|||||||
size CDATA #IMPLIED
|
size CDATA #IMPLIED
|
||||||
texture-size CDATA #IMPLIED
|
texture-size CDATA #IMPLIED
|
||||||
real-texture-placement CDATA #IMPLIED
|
real-texture-placement CDATA #IMPLIED
|
||||||
|
icon-size CDATA #IMPLIED
|
||||||
backcolor CDATA #IMPLIED
|
backcolor CDATA #IMPLIED
|
||||||
bordercolor CDATA #IMPLIED
|
bordercolor CDATA #IMPLIED
|
||||||
border %bool; #IMPLIED
|
border %bool; #IMPLIED
|
||||||
|
@ -24,6 +24,7 @@ CButton::CButton()
|
|||||||
AddSetting(GUIST_CGUISpriteInstance, "sprite-over");
|
AddSetting(GUIST_CGUISpriteInstance, "sprite-over");
|
||||||
AddSetting(GUIST_CGUISpriteInstance, "sprite-pressed");
|
AddSetting(GUIST_CGUISpriteInstance, "sprite-pressed");
|
||||||
AddSetting(GUIST_CGUISpriteInstance, "sprite-disabled");
|
AddSetting(GUIST_CGUISpriteInstance, "sprite-disabled");
|
||||||
|
AddSetting(GUIST_int, "icon-id");
|
||||||
AddSetting(GUIST_EAlign, "text-align");
|
AddSetting(GUIST_EAlign, "text-align");
|
||||||
AddSetting(GUIST_EVAlign, "text-valign");
|
AddSetting(GUIST_EVAlign, "text-valign");
|
||||||
AddSetting(GUIST_CColor, "textcolor");
|
AddSetting(GUIST_CColor, "textcolor");
|
||||||
@ -125,18 +126,21 @@ void CButton::Draw()
|
|||||||
float bz = GetBufferedZ();
|
float bz = GetBufferedZ();
|
||||||
|
|
||||||
CGUISpriteInstance *sprite, *sprite_over, *sprite_pressed, *sprite_disabled;
|
CGUISpriteInstance *sprite, *sprite_over, *sprite_pressed, *sprite_disabled;
|
||||||
|
int icon_id;
|
||||||
|
|
||||||
GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite", sprite);
|
GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite", sprite);
|
||||||
GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite-over", sprite_over);
|
GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite-over", sprite_over);
|
||||||
GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite-pressed", sprite_pressed);
|
GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite-pressed", sprite_pressed);
|
||||||
GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite-disabled", sprite_disabled);
|
GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite-disabled", sprite_disabled);
|
||||||
|
GUI<int>::GetSetting(this, "icon-id", icon_id);
|
||||||
|
|
||||||
DrawButton(m_CachedActualSize,
|
DrawButton(m_CachedActualSize,
|
||||||
bz,
|
bz,
|
||||||
*sprite,
|
*sprite,
|
||||||
*sprite_over,
|
*sprite_over,
|
||||||
*sprite_pressed,
|
*sprite_pressed,
|
||||||
*sprite_disabled);
|
*sprite_disabled,
|
||||||
|
icon_id);
|
||||||
|
|
||||||
CColor color = ChooseColor();
|
CColor color = ChooseColor();
|
||||||
IGUITextOwner::Draw(0, color, m_TextPos, bz+0.1f);
|
IGUITextOwner::Draw(0, color, m_TextPos, bz+0.1f);
|
||||||
|
@ -145,7 +145,8 @@ void CCheckBox::Draw()
|
|||||||
*sprite,
|
*sprite,
|
||||||
*sprite_over,
|
*sprite_over,
|
||||||
*sprite_pressed,
|
*sprite_pressed,
|
||||||
*sprite_disabled);
|
*sprite_disabled,
|
||||||
|
0);
|
||||||
|
|
||||||
CColor color = ChooseColor();
|
CColor color = ChooseColor();
|
||||||
|
|
||||||
|
@ -408,6 +408,7 @@ void CGUI::Draw()
|
|||||||
}
|
}
|
||||||
|
|
||||||
void CGUI::DrawSprite(CGUISpriteInstance& Sprite,
|
void CGUI::DrawSprite(CGUISpriteInstance& Sprite,
|
||||||
|
int IconID,
|
||||||
const float &Z,
|
const float &Z,
|
||||||
const CRect &Rect,
|
const CRect &Rect,
|
||||||
const CRect &Clipping)
|
const CRect &Clipping)
|
||||||
@ -421,7 +422,7 @@ void CGUI::DrawSprite(CGUISpriteInstance& Sprite,
|
|||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
glTranslatef(0.0f, 0.0f, Z);
|
glTranslatef(0.0f, 0.0f, Z);
|
||||||
|
|
||||||
Sprite.Draw(Rect, m_Sprites);
|
Sprite.Draw(Rect, IconID, m_Sprites);
|
||||||
|
|
||||||
glPopMatrix();
|
glPopMatrix();
|
||||||
|
|
||||||
@ -877,7 +878,7 @@ void CGUI::DrawText(SGUIText &Text, const CColor &DefaultColor,
|
|||||||
it!=Text.m_SpriteCalls.end();
|
it!=Text.m_SpriteCalls.end();
|
||||||
++it)
|
++it)
|
||||||
{
|
{
|
||||||
DrawSprite(it->m_Sprite, z, it->m_Area + pos);
|
DrawSprite(it->m_Sprite, 0, z, it->m_Area + pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO To whom it may concern: Thing were not reset, so
|
// TODO To whom it may concern: Thing were not reset, so
|
||||||
@ -1419,7 +1420,6 @@ void CGUI::Xeromyces_ReadImage(XMBElement Element, CXeromyces* pFile, CGUISprite
|
|||||||
CStr attr_name (pFile->getAttributeString(attr.Name));
|
CStr attr_name (pFile->getAttributeString(attr.Name));
|
||||||
CStr attr_value (attr.Value);
|
CStr attr_value (attr.Value);
|
||||||
|
|
||||||
// This is the only attribute we want
|
|
||||||
if (attr_name == "texture")
|
if (attr_name == "texture")
|
||||||
{
|
{
|
||||||
CStr TexFilename ("art/textures/ui/");
|
CStr TexFilename ("art/textures/ui/");
|
||||||
@ -1432,9 +1432,7 @@ void CGUI::Xeromyces_ReadImage(XMBElement Element, CXeromyces* pFile, CGUISprite
|
|||||||
{
|
{
|
||||||
CClientArea ca;
|
CClientArea ca;
|
||||||
if (!GUI<CClientArea>::ParseString(attr_value, ca))
|
if (!GUI<CClientArea>::ParseString(attr_value, ca))
|
||||||
{
|
|
||||||
ReportParseError("Error parsing '%s' (\"%s\")", attr_name.c_str(), attr_value.c_str());
|
ReportParseError("Error parsing '%s' (\"%s\")", attr_name.c_str(), attr_value.c_str());
|
||||||
}
|
|
||||||
else image.m_Size = ca;
|
else image.m_Size = ca;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -1442,9 +1440,7 @@ void CGUI::Xeromyces_ReadImage(XMBElement Element, CXeromyces* pFile, CGUISprite
|
|||||||
{
|
{
|
||||||
CClientArea ca;
|
CClientArea ca;
|
||||||
if (!GUI<CClientArea>::ParseString(attr_value, ca))
|
if (!GUI<CClientArea>::ParseString(attr_value, ca))
|
||||||
{
|
|
||||||
ReportParseError("Error parsing '%s' (\"%s\")", attr_name.c_str(), attr_value.c_str());
|
ReportParseError("Error parsing '%s' (\"%s\")", attr_name.c_str(), attr_value.c_str());
|
||||||
}
|
|
||||||
else image.m_TextureSize = ca;
|
else image.m_TextureSize = ca;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -1452,19 +1448,23 @@ void CGUI::Xeromyces_ReadImage(XMBElement Element, CXeromyces* pFile, CGUISprite
|
|||||||
{
|
{
|
||||||
CRect rect;
|
CRect rect;
|
||||||
if (!GUI<CRect>::ParseString(attr_value, rect))
|
if (!GUI<CRect>::ParseString(attr_value, rect))
|
||||||
{
|
ReportParseError("Error parsing '%s' (\"%s\")", attr_name.c_str(), attr_value.c_str());
|
||||||
ReportParseError("TODO");
|
|
||||||
}
|
|
||||||
else image.m_TexturePlacementInFile = rect;
|
else image.m_TexturePlacementInFile = rect;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
if (attr_name == "icon-size")
|
||||||
|
{
|
||||||
|
CSize size;
|
||||||
|
if (!GUI<CSize>::ParseString(attr_value, size))
|
||||||
|
ReportParseError("Error parsing '%s' (\"%s\")", attr_name.c_str(), attr_value.c_str());
|
||||||
|
else image.m_IconSize = size;
|
||||||
|
}
|
||||||
|
else
|
||||||
if (attr_name == "z-level")
|
if (attr_name == "z-level")
|
||||||
{
|
{
|
||||||
float z_level;
|
float z_level;
|
||||||
if (!GUI<float>::ParseString(attr_value, z_level))
|
if (!GUI<float>::ParseString(attr_value, z_level))
|
||||||
{
|
|
||||||
ReportParseError("Error parsing '%s' (\"%s\")", attr_name.c_str(), attr_value.c_str());
|
ReportParseError("Error parsing '%s' (\"%s\")", attr_name.c_str(), attr_value.c_str());
|
||||||
}
|
|
||||||
else image.m_DeltaZ = z_level/100.f;
|
else image.m_DeltaZ = z_level/100.f;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -1472,9 +1472,7 @@ void CGUI::Xeromyces_ReadImage(XMBElement Element, CXeromyces* pFile, CGUISprite
|
|||||||
{
|
{
|
||||||
CColor color;
|
CColor color;
|
||||||
if (!GUI<CColor>::ParseString(attr_value, color))
|
if (!GUI<CColor>::ParseString(attr_value, color))
|
||||||
{
|
|
||||||
ReportParseError("Error parsing '%s' (\"%s\")", attr_name.c_str(), attr_value.c_str());
|
ReportParseError("Error parsing '%s' (\"%s\")", attr_name.c_str(), attr_value.c_str());
|
||||||
}
|
|
||||||
else image.m_BackColor = color;
|
else image.m_BackColor = color;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -1482,9 +1480,7 @@ void CGUI::Xeromyces_ReadImage(XMBElement Element, CXeromyces* pFile, CGUISprite
|
|||||||
{
|
{
|
||||||
CColor color;
|
CColor color;
|
||||||
if (!GUI<CColor>::ParseString(attr_value, color))
|
if (!GUI<CColor>::ParseString(attr_value, color))
|
||||||
{
|
|
||||||
ReportParseError("Error parsing '%s' (\"%s\")", attr_name.c_str(), attr_value.c_str());
|
ReportParseError("Error parsing '%s' (\"%s\")", attr_name.c_str(), attr_value.c_str());
|
||||||
}
|
|
||||||
else image.m_BorderColor = color;
|
else image.m_BorderColor = color;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -1492,9 +1488,7 @@ void CGUI::Xeromyces_ReadImage(XMBElement Element, CXeromyces* pFile, CGUISprite
|
|||||||
{
|
{
|
||||||
bool b;
|
bool b;
|
||||||
if (!GUI<bool>::ParseString(attr_value, b))
|
if (!GUI<bool>::ParseString(attr_value, b))
|
||||||
{
|
|
||||||
ReportParseError("Error parsing '%s' (\"%s\")", attr_name.c_str(), attr_value.c_str());
|
ReportParseError("Error parsing '%s' (\"%s\")", attr_name.c_str(), attr_value.c_str());
|
||||||
}
|
|
||||||
else image.m_Border = b;
|
else image.m_Border = b;
|
||||||
}
|
}
|
||||||
// We don't need no else when we're using DTDs.
|
// We don't need no else when we're using DTDs.
|
||||||
|
@ -108,11 +108,13 @@ public:
|
|||||||
*
|
*
|
||||||
* @param Sprite Object refering to the sprite (which also caches
|
* @param Sprite Object refering to the sprite (which also caches
|
||||||
* calculations for faster rendering)
|
* calculations for faster rendering)
|
||||||
|
* @param IconID Number of the icon to use. (Ignored if this sprite doesn't
|
||||||
|
* have any images with "icon-size")
|
||||||
* @param Z Drawing order, depth value
|
* @param Z Drawing order, depth value
|
||||||
* @param Rect Position and Size
|
* @param Rect Position and Size
|
||||||
* @param Clipping The sprite shouldn't be drawn outside this rectangle
|
* @param Clipping The sprite shouldn't be drawn outside this rectangle
|
||||||
*/
|
*/
|
||||||
void DrawSprite(CGUISpriteInstance& Sprite, const float &Z,
|
void DrawSprite(CGUISpriteInstance& Sprite, int IconID, const float &Z,
|
||||||
const CRect &Rect, const CRect &Clipping=CRect());
|
const CRect &Rect, const CRect &Clipping=CRect());
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -38,8 +38,10 @@ void CGUIScrollBarVertical::Draw()
|
|||||||
CRect outline = GetOuterRect();
|
CRect outline = GetOuterRect();
|
||||||
|
|
||||||
// Draw background
|
// Draw background
|
||||||
GetGUI()->DrawSprite(GetStyle()->m_SpriteBackVertical, m_Z+0.1f,
|
GetGUI()->DrawSprite(GetStyle()->m_SpriteBackVertical,
|
||||||
CRect( outline.left,
|
0,
|
||||||
|
m_Z+0.1f,
|
||||||
|
CRect(outline.left,
|
||||||
outline.top+(m_UseEdgeButtons?GetStyle()->m_Width:0),
|
outline.top+(m_UseEdgeButtons?GetStyle()->m_Width:0),
|
||||||
outline.right,
|
outline.right,
|
||||||
outline.bottom-(m_UseEdgeButtons?GetStyle()->m_Width:0))
|
outline.bottom-(m_UseEdgeButtons?GetStyle()->m_Width:0))
|
||||||
@ -72,6 +74,7 @@ void CGUIScrollBarVertical::Draw()
|
|||||||
|
|
||||||
// Draw top button
|
// Draw top button
|
||||||
GetGUI()->DrawSprite(*button_top,
|
GetGUI()->DrawSprite(*button_top,
|
||||||
|
0,
|
||||||
m_Z+0.2f,
|
m_Z+0.2f,
|
||||||
CRect(outline.left,
|
CRect(outline.left,
|
||||||
outline.top,
|
outline.top,
|
||||||
@ -81,6 +84,7 @@ void CGUIScrollBarVertical::Draw()
|
|||||||
|
|
||||||
// Draw bottom button
|
// Draw bottom button
|
||||||
GetGUI()->DrawSprite(*button_bottom,
|
GetGUI()->DrawSprite(*button_bottom,
|
||||||
|
0,
|
||||||
m_Z+0.2f,
|
m_Z+0.2f,
|
||||||
CRect(outline.left,
|
CRect(outline.left,
|
||||||
outline.bottom-GetStyle()->m_Width,
|
outline.bottom-GetStyle()->m_Width,
|
||||||
@ -92,15 +96,18 @@ void CGUIScrollBarVertical::Draw()
|
|||||||
// Draw bar
|
// Draw bar
|
||||||
if (m_BarPressed)
|
if (m_BarPressed)
|
||||||
GetGUI()->DrawSprite(GUI<>::FallBackSprite(GetStyle()->m_SpriteBarVerticalPressed, GetStyle()->m_SpriteBarVertical),
|
GetGUI()->DrawSprite(GUI<>::FallBackSprite(GetStyle()->m_SpriteBarVerticalPressed, GetStyle()->m_SpriteBarVertical),
|
||||||
|
0,
|
||||||
m_Z+0.2f,
|
m_Z+0.2f,
|
||||||
GetBarRect());
|
GetBarRect());
|
||||||
else
|
else
|
||||||
if (m_BarHovered)
|
if (m_BarHovered)
|
||||||
GetGUI()->DrawSprite(GUI<>::FallBackSprite(GetStyle()->m_SpriteBarVerticalOver, GetStyle()->m_SpriteBarVertical),
|
GetGUI()->DrawSprite(GUI<>::FallBackSprite(GetStyle()->m_SpriteBarVerticalOver, GetStyle()->m_SpriteBarVertical),
|
||||||
|
0,
|
||||||
m_Z+0.2f,
|
m_Z+0.2f,
|
||||||
GetBarRect());
|
GetBarRect());
|
||||||
else
|
else
|
||||||
GetGUI()->DrawSprite(GetStyle()->m_SpriteBarVertical,
|
GetGUI()->DrawSprite(GetStyle()->m_SpriteBarVertical,
|
||||||
|
0,
|
||||||
m_Z+0.2f,
|
m_Z+0.2f,
|
||||||
GetBarRect());
|
GetBarRect());
|
||||||
}
|
}
|
||||||
|
@ -17,12 +17,13 @@ CGUISpriteInstance &CGUISpriteInstance::operator=(CStr SpriteName)
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CGUISpriteInstance::Draw(CRect Size, std::map<CStr, CGUISprite> &Sprites)
|
void CGUISpriteInstance::Draw(CRect Size, int IconID, std::map<CStr, CGUISprite> &Sprites)
|
||||||
{
|
{
|
||||||
if (m_CachedSize != Size)
|
if (m_CachedSize != Size || m_CachedIconID != IconID)
|
||||||
{
|
{
|
||||||
GUIRenderer::UpdateDrawCallCache(m_DrawCallCache, m_SpriteName, Size, Sprites);
|
GUIRenderer::UpdateDrawCallCache(m_DrawCallCache, m_SpriteName, Size, IconID, Sprites);
|
||||||
m_CachedSize = Size;
|
m_CachedSize = Size;
|
||||||
|
m_CachedIconID = IconID;
|
||||||
}
|
}
|
||||||
GUIRenderer::Draw(m_DrawCallCache);
|
GUIRenderer::Draw(m_DrawCallCache);
|
||||||
}
|
}
|
||||||
|
@ -73,7 +73,7 @@ struct SGUIImage
|
|||||||
// For textures that contain a collection of icons (e.g. unit portraits), this
|
// 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
|
// will be set to the size of one icon. An object's icon-id will determine
|
||||||
// which part of the texture is used.
|
// which part of the texture is used.
|
||||||
// Equal to CPos(0,0) for non-icon textures.
|
// Equal to CSize(0,0) for non-icon textures.
|
||||||
CSize m_IconSize;
|
CSize m_IconSize;
|
||||||
|
|
||||||
// Color
|
// Color
|
||||||
@ -130,7 +130,7 @@ public:
|
|||||||
CGUISpriteInstance();
|
CGUISpriteInstance();
|
||||||
CGUISpriteInstance(CStr SpriteName);
|
CGUISpriteInstance(CStr SpriteName);
|
||||||
CGUISpriteInstance &operator=(CStr SpriteName);
|
CGUISpriteInstance &operator=(CStr SpriteName);
|
||||||
void Draw(CRect Size, std::map<CStr, CGUISprite> &Sprites);
|
void Draw(CRect Size, int IconID, std::map<CStr, CGUISprite> &Sprites);
|
||||||
void Invalidate();
|
void Invalidate();
|
||||||
bool IsEmpty() const;
|
bool IsEmpty() const;
|
||||||
CStr GetName() { return m_SpriteName; }
|
CStr GetName() { return m_SpriteName; }
|
||||||
@ -140,9 +140,10 @@ private:
|
|||||||
|
|
||||||
// Stored drawing calls, for more efficient rendering
|
// Stored drawing calls, for more efficient rendering
|
||||||
GUIRenderer::DrawCalls m_DrawCallCache;
|
GUIRenderer::DrawCalls m_DrawCallCache;
|
||||||
// Size of previously rendered sprite; the cache is invalidated
|
// Relevant details of previously rendered sprite; the cache is invalidated
|
||||||
// whenever this changes.
|
// whenever any of these values changes.
|
||||||
CRect m_CachedSize;
|
CRect m_CachedSize;
|
||||||
|
int m_CachedIconID;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -18,6 +18,7 @@ using namespace std;
|
|||||||
CImage::CImage()
|
CImage::CImage()
|
||||||
{
|
{
|
||||||
AddSetting(GUIST_CGUISpriteInstance, "sprite");
|
AddSetting(GUIST_CGUISpriteInstance, "sprite");
|
||||||
|
AddSetting(GUIST_int, "icon-id");
|
||||||
}
|
}
|
||||||
|
|
||||||
CImage::~CImage()
|
CImage::~CImage()
|
||||||
@ -31,8 +32,10 @@ void CImage::Draw()
|
|||||||
float bz = GetBufferedZ();
|
float bz = GetBufferedZ();
|
||||||
|
|
||||||
CGUISpriteInstance *sprite;
|
CGUISpriteInstance *sprite;
|
||||||
|
int icon_id;
|
||||||
GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite", sprite);
|
GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite", sprite);
|
||||||
|
GUI<int>::GetSetting(this, "icon-id", icon_id);
|
||||||
|
|
||||||
GetGUI()->DrawSprite(*sprite, bz, m_CachedActualSize);
|
GetGUI()->DrawSprite(*sprite, icon_id, bz, m_CachedActualSize);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -31,6 +31,7 @@ CInput::CInput() : m_iBufferPos(0)
|
|||||||
AddSetting(GUIST_bool, "scrollbar");
|
AddSetting(GUIST_bool, "scrollbar");
|
||||||
AddSetting(GUIST_CStr, "scrollbar-style");
|
AddSetting(GUIST_CStr, "scrollbar-style");
|
||||||
AddSetting(GUIST_CGUISpriteInstance, "sprite");
|
AddSetting(GUIST_CGUISpriteInstance, "sprite");
|
||||||
|
AddSetting(GUIST_int, "icon-id");
|
||||||
AddSetting(GUIST_CColor, "textcolor");
|
AddSetting(GUIST_CColor, "textcolor");
|
||||||
// TODO Gee: (2004-08-14)
|
// TODO Gee: (2004-08-14)
|
||||||
// Add a setting for buffer zone
|
// Add a setting for buffer zone
|
||||||
@ -341,9 +342,11 @@ void CInput::Draw()
|
|||||||
if (GetGUI())
|
if (GetGUI())
|
||||||
{
|
{
|
||||||
CGUISpriteInstance *sprite;
|
CGUISpriteInstance *sprite;
|
||||||
|
int icon_id;
|
||||||
GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite", sprite);
|
GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite", sprite);
|
||||||
|
GUI<int>::GetSetting(this, "icon-id", icon_id);
|
||||||
|
|
||||||
GetGUI()->DrawSprite(*sprite, bz, m_CachedActualSize);
|
GetGUI()->DrawSprite(*sprite, icon_id, bz, m_CachedActualSize);
|
||||||
|
|
||||||
float scroll=0.f;
|
float scroll=0.f;
|
||||||
if (scrollbar)
|
if (scrollbar)
|
||||||
|
@ -59,17 +59,19 @@ void CProgressBar::Draw()
|
|||||||
float bz = GetBufferedZ();
|
float bz = GetBufferedZ();
|
||||||
|
|
||||||
CGUISpriteInstance *sprite_background, *sprite_bar;
|
CGUISpriteInstance *sprite_background, *sprite_bar;
|
||||||
|
int icon_id;
|
||||||
float value;
|
float value;
|
||||||
GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite-background", sprite_background);
|
GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite-background", sprite_background);
|
||||||
GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite-bar", sprite_bar);
|
GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite-bar", sprite_bar);
|
||||||
|
GUI<int>::GetSetting(this, "icon-id", icon_id);
|
||||||
GUI<float>::GetSetting(this, "caption", value);
|
GUI<float>::GetSetting(this, "caption", value);
|
||||||
|
|
||||||
GetGUI()->DrawSprite(*sprite_background, bz, m_CachedActualSize);
|
GetGUI()->DrawSprite(*sprite_background, icon_id, bz, m_CachedActualSize);
|
||||||
|
|
||||||
|
|
||||||
// Get size of bar (notice it is drawn slightly closer, to appear above the background)
|
// Get size of bar (notice it is drawn slightly closer, to appear above the background)
|
||||||
CRect bar_size(m_CachedActualSize.left, m_CachedActualSize.top,
|
CRect bar_size(m_CachedActualSize.left, m_CachedActualSize.top,
|
||||||
m_CachedActualSize.left+m_CachedActualSize.GetWidth()*(value/100.f), m_CachedActualSize.bottom);
|
m_CachedActualSize.left+m_CachedActualSize.GetWidth()*(value/100.f), m_CachedActualSize.bottom);
|
||||||
GetGUI()->DrawSprite(*sprite_bar, bz+0.01f, bar_size);
|
GetGUI()->DrawSprite(*sprite_bar, icon_id, bz+0.01f, bar_size);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,6 +26,7 @@ CText::CText()
|
|||||||
AddSetting(GUIST_bool, "scrollbar");
|
AddSetting(GUIST_bool, "scrollbar");
|
||||||
AddSetting(GUIST_CStr, "scrollbar-style");
|
AddSetting(GUIST_CStr, "scrollbar-style");
|
||||||
AddSetting(GUIST_CGUISpriteInstance, "sprite");
|
AddSetting(GUIST_CGUISpriteInstance, "sprite");
|
||||||
|
AddSetting(GUIST_int, "icon-id");
|
||||||
AddSetting(GUIST_CColor, "textcolor");
|
AddSetting(GUIST_CColor, "textcolor");
|
||||||
// TODO Gee: (2004-08-14)
|
// TODO Gee: (2004-08-14)
|
||||||
// Add a setting for buffer zone
|
// Add a setting for buffer zone
|
||||||
@ -162,9 +163,11 @@ void CText::Draw()
|
|||||||
if (GetGUI())
|
if (GetGUI())
|
||||||
{
|
{
|
||||||
CGUISpriteInstance *sprite;
|
CGUISpriteInstance *sprite;
|
||||||
|
int icon_id;
|
||||||
GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite", sprite);
|
GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite", sprite);
|
||||||
|
GUI<int>::GetSetting(this, "icon-id", icon_id);
|
||||||
|
|
||||||
GetGUI()->DrawSprite(*sprite, bz, m_CachedActualSize);
|
GetGUI()->DrawSprite(*sprite, icon_id, bz, m_CachedActualSize);
|
||||||
|
|
||||||
float scroll=0.f;
|
float scroll=0.f;
|
||||||
if (scrollbar)
|
if (scrollbar)
|
||||||
|
@ -17,14 +17,6 @@ gee@pyro.nu
|
|||||||
#ifndef GUI_H
|
#ifndef GUI_H
|
||||||
#define GUI_H
|
#define GUI_H
|
||||||
|
|
||||||
//--------------------------------------------------------
|
|
||||||
// Compiler specific
|
|
||||||
//--------------------------------------------------------
|
|
||||||
// Important that we do this before <map> is included
|
|
||||||
#ifdef _MSC_VER
|
|
||||||
# pragma warning(disable:4786)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
//--------------------------------------------------------
|
//--------------------------------------------------------
|
||||||
// Includes
|
// Includes
|
||||||
//--------------------------------------------------------
|
//--------------------------------------------------------
|
||||||
@ -47,7 +39,6 @@ gee@pyro.nu
|
|||||||
#include "IGUITextOwner.h"
|
#include "IGUITextOwner.h"
|
||||||
#include "IGUIScrollBar.h"
|
#include "IGUIScrollBar.h"
|
||||||
#include "CGUIScrollBarVertical.h"
|
#include "CGUIScrollBarVertical.h"
|
||||||
#include "CGUISprite.h"
|
|
||||||
#include "CGUI.h"
|
#include "CGUI.h"
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -42,8 +42,11 @@ Handle_rfcnt_tex& Handle_rfcnt_tex::operator=(Handle h_)
|
|||||||
|
|
||||||
// Functions to perform drawing-related actions:
|
// Functions to perform drawing-related actions:
|
||||||
|
|
||||||
void GUIRenderer::UpdateDrawCallCache(DrawCalls &Calls, CStr &SpriteName, CRect &Size, std::map<CStr, CGUISprite> &Sprites)
|
void GUIRenderer::UpdateDrawCallCache(DrawCalls &Calls, CStr &SpriteName, CRect &Size, int IconID, std::map<CStr, CGUISprite> &Sprites)
|
||||||
{
|
{
|
||||||
|
// This is called only when something has changed (like the size of the
|
||||||
|
// sprite), so it doesn't need to be particularly efficient.
|
||||||
|
|
||||||
Calls.clear();
|
Calls.clear();
|
||||||
|
|
||||||
std::map<CStr, CGUISprite>::iterator it (Sprites.find(SpriteName));
|
std::map<CStr, CGUISprite>::iterator it (Sprites.find(SpriteName));
|
||||||
@ -69,8 +72,8 @@ void GUIRenderer::UpdateDrawCallCache(DrawCalls &Calls, CStr &SpriteName, CRect
|
|||||||
{
|
{
|
||||||
SDrawCall Call;
|
SDrawCall Call;
|
||||||
|
|
||||||
CRect real = cit->m_Size.GetClientArea(Size);
|
CRect ObjectSize = cit->m_Size.GetClientArea(Size);
|
||||||
Call.m_Vertices = real;
|
Call.m_Vertices = ObjectSize;
|
||||||
|
|
||||||
if (cit->m_TextureName.Length())
|
if (cit->m_TextureName.Length())
|
||||||
{
|
{
|
||||||
@ -90,40 +93,69 @@ void GUIRenderer::UpdateDrawCallCache(DrawCalls &Calls, CStr &SpriteName, CRect
|
|||||||
|
|
||||||
Call.m_TexHandle = h;
|
Call.m_TexHandle = h;
|
||||||
|
|
||||||
int fmt, t_w, t_h;
|
int TexFormat, t_w, t_h;
|
||||||
tex_info(h, &t_w, &t_h, &fmt, NULL, NULL);
|
tex_info(h, &t_w, &t_h, &TexFormat, NULL, NULL);
|
||||||
Call.m_EnableBlending = (fmt == GL_RGBA || fmt == GL_BGRA);
|
float TexWidth = (float)t_w, TexHeight = (float)t_h;
|
||||||
|
|
||||||
// Get the screen position/size of a single tiling of the texture
|
// TODO: Detect the presence of an alpha channel in a nicer way
|
||||||
CRect TexSize = cit->m_TextureSize.GetClientArea(real);
|
Call.m_EnableBlending = (TexFormat == GL_RGBA || TexFormat == GL_BGRA);
|
||||||
|
|
||||||
CRect TexCoords;
|
// Textures are positioned by defining a rectangular block of the
|
||||||
|
// texture (usually the whole texture), and a rectangular block on
|
||||||
|
// the screen. The texture is positioned to make those blocks line up.
|
||||||
|
|
||||||
TexCoords.left = (TexSize.left - real.left) / TexSize.GetWidth();
|
// Get the screen's position/size for the block
|
||||||
TexCoords.right = TexCoords.left + real.GetWidth() / TexSize.GetWidth();
|
CRect BlockScreen = cit->m_TextureSize.GetClientArea(ObjectSize);
|
||||||
|
|
||||||
// 'Bottom' is actually the top in screen-space (I think),
|
// Get the texture's position/size for the block:
|
||||||
// because the GUI puts (0,0) at the top-left
|
CRect BlockTex;
|
||||||
TexCoords.bottom = (TexSize.bottom - real.bottom) / TexSize.GetHeight();
|
|
||||||
TexCoords.top = TexCoords.bottom + real.GetHeight() / TexSize.GetHeight();
|
|
||||||
|
|
||||||
|
// "real-texture-placement" overrides everything
|
||||||
if (cit->m_TexturePlacementInFile != CRect())
|
if (cit->m_TexturePlacementInFile != CRect())
|
||||||
|
BlockTex = cit->m_TexturePlacementInFile;
|
||||||
|
|
||||||
|
// Check whether this sprite has "icon-size" set
|
||||||
|
else if (cit->m_IconSize != CSize())
|
||||||
{
|
{
|
||||||
// Save the width/height, because we'll change the values one at a time and need
|
int cols = t_w / (int)cit->m_IconSize.cx;
|
||||||
// to be able to use the unchanged width/height
|
int col = IconID % cols;
|
||||||
float width = TexCoords.GetWidth(),
|
int row = IconID / cols;
|
||||||
height = TexCoords.GetHeight();
|
BlockTex = CRect(cit->m_IconSize.cx*col, cit->m_IconSize.cy*row,
|
||||||
|
cit->m_IconSize.cx*(col+1), cit->m_IconSize.cy*(row+1));
|
||||||
float fTW=(float)t_w, fTH=(float)t_h;
|
|
||||||
|
|
||||||
// notice left done after right, so that left is still unchanged, that is important.
|
|
||||||
TexCoords.right = TexCoords.left + width * cit->m_TexturePlacementInFile.right/fTW;
|
|
||||||
TexCoords.left += width * cit->m_TexturePlacementInFile.left/fTW;
|
|
||||||
|
|
||||||
TexCoords.bottom = TexCoords.top + height * cit->m_TexturePlacementInFile.bottom/fTH;
|
|
||||||
TexCoords.top += height * cit->m_TexturePlacementInFile.top/fTH;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Use the whole texture
|
||||||
|
else
|
||||||
|
BlockTex = CRect(0, 0, TexWidth, TexHeight);
|
||||||
|
|
||||||
|
|
||||||
|
// When rendering, BlockTex will be transformed onto BlockScreen.
|
||||||
|
// Also, TexCoords will be transformed onto ObjectSize (giving the
|
||||||
|
// UV coords at each vertex of the object). We know everything
|
||||||
|
// except for TexCoords, so calculate it:
|
||||||
|
|
||||||
|
CPos translation (BlockTex.TopLeft()-BlockScreen.TopLeft());
|
||||||
|
float ScaleW = BlockTex.GetWidth()/BlockScreen.GetWidth();
|
||||||
|
float ScaleH = BlockTex.GetHeight()/BlockScreen.GetHeight();
|
||||||
|
|
||||||
|
CRect TexCoords (
|
||||||
|
// Resize (translating to/from the origin, so the
|
||||||
|
// topleft corner stays in the same place)
|
||||||
|
(ObjectSize-ObjectSize.TopLeft())
|
||||||
|
.Scale(ScaleW, ScaleH)
|
||||||
|
+ ObjectSize.TopLeft()
|
||||||
|
// Translate from BlockTex to BlockScreen
|
||||||
|
+ translation
|
||||||
|
);
|
||||||
|
|
||||||
|
// The tex coords need to be scaled so that (texwidth,texheight) is
|
||||||
|
// mapped onto (1,1)
|
||||||
|
TexCoords.left /= TexWidth;
|
||||||
|
TexCoords.right /= TexWidth;
|
||||||
|
// and flip it vertically, because of some confusion between coordinate systems
|
||||||
|
TexCoords.top /= -TexHeight;
|
||||||
|
TexCoords.bottom /= -TexHeight;
|
||||||
|
|
||||||
Call.m_TexCoords = TexCoords;
|
Call.m_TexCoords = TexCoords;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -142,6 +174,8 @@ void GUIRenderer::UpdateDrawCallCache(DrawCalls &Calls, CStr &SpriteName, CRect
|
|||||||
|
|
||||||
void GUIRenderer::Draw(DrawCalls &Calls)
|
void GUIRenderer::Draw(DrawCalls &Calls)
|
||||||
{
|
{
|
||||||
|
// Called every frame, to draw the object (based on cached calculations)
|
||||||
|
|
||||||
|
|
||||||
// Iterate through each DrawCall, and execute whatever drawing code is being called
|
// Iterate through each DrawCall, and execute whatever drawing code is being called
|
||||||
for (DrawCalls::const_iterator cit = Calls.begin(); cit != Calls.end(); ++cit)
|
for (DrawCalls::const_iterator cit = Calls.begin(); cit != Calls.end(); ++cit)
|
||||||
|
@ -39,7 +39,7 @@ namespace GUIRenderer
|
|||||||
|
|
||||||
namespace GUIRenderer
|
namespace GUIRenderer
|
||||||
{
|
{
|
||||||
void UpdateDrawCallCache(DrawCalls &Calls, CStr &SpriteName, CRect& Size, std::map<CStr, CGUISprite> &Sprites);
|
void UpdateDrawCallCache(DrawCalls &Calls, CStr &SpriteName, CRect& Size, int IconID, std::map<CStr, CGUISprite> &Sprites);
|
||||||
|
|
||||||
void Draw(DrawCalls &Calls);
|
void Draw(DrawCalls &Calls);
|
||||||
}
|
}
|
||||||
|
@ -257,7 +257,7 @@ bool CClientArea::SetClientArea(const CStr& Value)
|
|||||||
|
|
||||||
// Setup parser to parse the value
|
// Setup parser to parse the value
|
||||||
|
|
||||||
// One of the for values:
|
// One of the four values:
|
||||||
// will give outputs like (in argument):
|
// will give outputs like (in argument):
|
||||||
// (200) <== no percent, just the first $value
|
// (200) <== no percent, just the first $value
|
||||||
// (200) (percent) <== just the percent
|
// (200) (percent) <== just the percent
|
||||||
@ -271,6 +271,7 @@ bool CClientArea::SetClientArea(const CStr& Value)
|
|||||||
one_value + "$arg(delim)" +
|
one_value + "$arg(delim)" +
|
||||||
one_value + "$arg(delim)_"; // it's easier to just end with another delimiter
|
one_value + "$arg(delim)_"; // it's easier to just end with another delimiter
|
||||||
*/
|
*/
|
||||||
|
// Don't use the above strings, because they make this code go very slowly
|
||||||
const char* four_values =
|
const char* four_values =
|
||||||
"_[-_$arg(_minus)]$value[$arg(percent)%_[+_$value]_[-_$arg(_minus)$value]_]" "$arg(delim)"
|
"_[-_$arg(_minus)]$value[$arg(percent)%_[+_$value]_[-_$arg(_minus)$value]_]" "$arg(delim)"
|
||||||
"_[-_$arg(_minus)]$value[$arg(percent)%_[+_$value]_[-_$arg(_minus)$value]_]" "$arg(delim)"
|
"_[-_$arg(_minus)]$value[$arg(percent)%_[+_$value]_[-_$arg(_minus)$value]_]" "$arg(delim)"
|
||||||
@ -286,7 +287,7 @@ bool CClientArea::SetClientArea(const CStr& Value)
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
int arg_count[4]; // argument counts for the four values
|
int arg_count[4]; // argument counts for the four values
|
||||||
int arg_start[4] = {0,0,0,0}; // location of first argument, [0] is alwasy 0
|
int arg_start[4] = {0,0,0,0}; // location of first argument, [0] is always 0
|
||||||
|
|
||||||
// Divide into the four piles (delimiter is an argument named "delim")
|
// Divide into the four piles (delimiter is an argument named "delim")
|
||||||
for (int i=0, valuenr=0; i<(int)line.GetArgCount(); ++i)
|
for (int i=0, valuenr=0; i<(int)line.GetArgCount(); ++i)
|
||||||
@ -482,6 +483,7 @@ PS_RESULT GUI<T>::SetSetting(IGUIObject *pObject, const CStr& Setting, const T &
|
|||||||
return PS_OK;
|
return PS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Instantiate templated functions:
|
||||||
#define TYPE(T) \
|
#define TYPE(T) \
|
||||||
template PS_RESULT GUI<T>::GetSettingPointer(const IGUIObject *pObject, const CStr& Setting, T* &Value); \
|
template PS_RESULT GUI<T>::GetSettingPointer(const IGUIObject *pObject, const CStr& Setting, T* &Value); \
|
||||||
template PS_RESULT GUI<T>::GetSetting(const IGUIObject *pObject, const CStr& Setting, T &Value); \
|
template PS_RESULT GUI<T>::GetSetting(const IGUIObject *pObject, const CStr& Setting, T &Value); \
|
||||||
|
@ -91,7 +91,8 @@ void IGUIButtonBehavior::DrawButton(const CRect &rect,
|
|||||||
CGUISpriteInstance& sprite,
|
CGUISpriteInstance& sprite,
|
||||||
CGUISpriteInstance& sprite_over,
|
CGUISpriteInstance& sprite_over,
|
||||||
CGUISpriteInstance& sprite_pressed,
|
CGUISpriteInstance& sprite_pressed,
|
||||||
CGUISpriteInstance& sprite_disabled)
|
CGUISpriteInstance& sprite_disabled,
|
||||||
|
int icon_id)
|
||||||
{
|
{
|
||||||
if (GetGUI())
|
if (GetGUI())
|
||||||
{
|
{
|
||||||
@ -100,16 +101,16 @@ void IGUIButtonBehavior::DrawButton(const CRect &rect,
|
|||||||
|
|
||||||
if (!enabled)
|
if (!enabled)
|
||||||
{
|
{
|
||||||
GetGUI()->DrawSprite(GUI<>::FallBackSprite(sprite_disabled, sprite), z, rect);
|
GetGUI()->DrawSprite(GUI<>::FallBackSprite(sprite_disabled, sprite), icon_id, z, rect);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
if (m_MouseHovering)
|
if (m_MouseHovering)
|
||||||
{
|
{
|
||||||
if (m_Pressed)
|
if (m_Pressed)
|
||||||
GetGUI()->DrawSprite(GUI<>::FallBackSprite(sprite_pressed, sprite), z, rect);
|
GetGUI()->DrawSprite(GUI<>::FallBackSprite(sprite_pressed, sprite), icon_id, z, rect);
|
||||||
else
|
else
|
||||||
GetGUI()->DrawSprite(GUI<>::FallBackSprite(sprite_over, sprite), z, rect);
|
GetGUI()->DrawSprite(GUI<>::FallBackSprite(sprite_over, sprite), icon_id, z, rect);
|
||||||
}
|
}
|
||||||
else GetGUI()->DrawSprite(sprite, z, rect);
|
else GetGUI()->DrawSprite(sprite, icon_id, z, rect);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -73,13 +73,16 @@ public:
|
|||||||
* @param sprite_over Sprite drawn when m_MouseHovering is true
|
* @param sprite_over Sprite drawn when m_MouseHovering is true
|
||||||
* @param sprite_pressed Sprite drawn when m_Pressed is true
|
* @param sprite_pressed Sprite drawn when m_Pressed is true
|
||||||
* @param sprite_disabled Sprite drawn when "enabled" is false
|
* @param sprite_disabled Sprite drawn when "enabled" is false
|
||||||
|
* @param icon_id Identifies the icon to be used (if the sprite contains
|
||||||
|
* icon-using images)
|
||||||
*/
|
*/
|
||||||
void DrawButton(const CRect &rect,
|
void DrawButton(const CRect &rect,
|
||||||
const float &z,
|
const float &z,
|
||||||
CGUISpriteInstance& sprite,
|
CGUISpriteInstance& sprite,
|
||||||
CGUISpriteInstance& sprite_over,
|
CGUISpriteInstance& sprite_over,
|
||||||
CGUISpriteInstance& sprite_pressed,
|
CGUISpriteInstance& sprite_pressed,
|
||||||
CGUISpriteInstance& sprite_disabled);
|
CGUISpriteInstance& sprite_disabled,
|
||||||
|
int icon_id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Choosing which color of the following according to
|
* Choosing which color of the following according to
|
||||||
|
@ -220,6 +220,11 @@ bool CRect::PointInside(const CPos &point) const
|
|||||||
point.y <= bottom);
|
point.y <= bottom);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CRect CRect::Scale(float x, float y) const
|
||||||
|
{
|
||||||
|
return CRect(left*x, top*y, right*x, bottom*y);
|
||||||
|
}
|
||||||
|
|
||||||
/*************************************************************************/
|
/*************************************************************************/
|
||||||
|
|
||||||
CPos::CPos() : x(0.f), y(0.f)
|
CPos::CPos() : x(0.f), y(0.f)
|
||||||
|
@ -120,6 +120,8 @@ public:
|
|||||||
*/
|
*/
|
||||||
bool PointInside(const CPos &point) const;
|
bool PointInside(const CPos &point) const;
|
||||||
|
|
||||||
|
CRect Scale(float x, float y) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returning CPos representing each corner.
|
* Returning CPos representing each corner.
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user