diff --git a/binaries/data/mods/official/gui/gui.dtd b/binaries/data/mods/official/gui/gui.dtd index 55728af0d3..283f25caaa 100755 --- a/binaries/data/mods/official/gui/gui.dtd +++ b/binaries/data/mods/official/gui/gui.dtd @@ -32,6 +32,7 @@ font CDATA #IMPLIED fov-wedge-color CDATA #IMPLIED hotkey CDATA #IMPLIED + icon-id CDATA #IMPLIED input-initvalue-destroyed-at-focus %bool; #IMPLIED rectcolor-selected CDATA #IMPLIED scrollbar %bool; #IMPLIED @@ -148,6 +149,7 @@ size CDATA #IMPLIED texture-size CDATA #IMPLIED real-texture-placement CDATA #IMPLIED + icon-size CDATA #IMPLIED backcolor CDATA #IMPLIED bordercolor CDATA #IMPLIED border %bool; #IMPLIED diff --git a/source/gui/CButton.cpp b/source/gui/CButton.cpp index e042e96402..ec2e16fe02 100755 --- a/source/gui/CButton.cpp +++ b/source/gui/CButton.cpp @@ -24,6 +24,7 @@ CButton::CButton() AddSetting(GUIST_CGUISpriteInstance, "sprite-over"); AddSetting(GUIST_CGUISpriteInstance, "sprite-pressed"); AddSetting(GUIST_CGUISpriteInstance, "sprite-disabled"); + AddSetting(GUIST_int, "icon-id"); AddSetting(GUIST_EAlign, "text-align"); AddSetting(GUIST_EVAlign, "text-valign"); AddSetting(GUIST_CColor, "textcolor"); @@ -125,18 +126,21 @@ void CButton::Draw() float bz = GetBufferedZ(); CGUISpriteInstance *sprite, *sprite_over, *sprite_pressed, *sprite_disabled; + int icon_id; GUI::GetSettingPointer(this, "sprite", sprite); GUI::GetSettingPointer(this, "sprite-over", sprite_over); GUI::GetSettingPointer(this, "sprite-pressed", sprite_pressed); GUI::GetSettingPointer(this, "sprite-disabled", sprite_disabled); + GUI::GetSetting(this, "icon-id", icon_id); DrawButton(m_CachedActualSize, bz, *sprite, *sprite_over, *sprite_pressed, - *sprite_disabled); + *sprite_disabled, + icon_id); CColor color = ChooseColor(); IGUITextOwner::Draw(0, color, m_TextPos, bz+0.1f); diff --git a/source/gui/CCheckBox.cpp b/source/gui/CCheckBox.cpp index 0eab50ec51..126aabcc69 100755 --- a/source/gui/CCheckBox.cpp +++ b/source/gui/CCheckBox.cpp @@ -145,7 +145,8 @@ void CCheckBox::Draw() *sprite, *sprite_over, *sprite_pressed, - *sprite_disabled); + *sprite_disabled, + 0); CColor color = ChooseColor(); diff --git a/source/gui/CGUI.cpp b/source/gui/CGUI.cpp index f616c1384e..742a1dc485 100755 --- a/source/gui/CGUI.cpp +++ b/source/gui/CGUI.cpp @@ -408,6 +408,7 @@ void CGUI::Draw() } void CGUI::DrawSprite(CGUISpriteInstance& Sprite, + int IconID, const float &Z, const CRect &Rect, const CRect &Clipping) @@ -421,7 +422,7 @@ void CGUI::DrawSprite(CGUISpriteInstance& Sprite, glPushMatrix(); glTranslatef(0.0f, 0.0f, Z); - Sprite.Draw(Rect, m_Sprites); + Sprite.Draw(Rect, IconID, m_Sprites); glPopMatrix(); @@ -877,7 +878,7 @@ void CGUI::DrawText(SGUIText &Text, const CColor &DefaultColor, it!=Text.m_SpriteCalls.end(); ++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 @@ -1419,7 +1420,6 @@ void CGUI::Xeromyces_ReadImage(XMBElement Element, CXeromyces* pFile, CGUISprite CStr attr_name (pFile->getAttributeString(attr.Name)); CStr attr_value (attr.Value); - // This is the only attribute we want if (attr_name == "texture") { CStr TexFilename ("art/textures/ui/"); @@ -1432,9 +1432,7 @@ void CGUI::Xeromyces_ReadImage(XMBElement Element, CXeromyces* pFile, CGUISprite { CClientArea ca; if (!GUI::ParseString(attr_value, ca)) - { ReportParseError("Error parsing '%s' (\"%s\")", attr_name.c_str(), attr_value.c_str()); - } else image.m_Size = ca; } else @@ -1442,9 +1440,7 @@ void CGUI::Xeromyces_ReadImage(XMBElement Element, CXeromyces* pFile, CGUISprite { CClientArea ca; if (!GUI::ParseString(attr_value, ca)) - { ReportParseError("Error parsing '%s' (\"%s\")", attr_name.c_str(), attr_value.c_str()); - } else image.m_TextureSize = ca; } else @@ -1452,19 +1448,23 @@ void CGUI::Xeromyces_ReadImage(XMBElement Element, CXeromyces* pFile, CGUISprite { CRect rect; if (!GUI::ParseString(attr_value, rect)) - { - ReportParseError("TODO"); - } + ReportParseError("Error parsing '%s' (\"%s\")", attr_name.c_str(), attr_value.c_str()); else image.m_TexturePlacementInFile = rect; } else + if (attr_name == "icon-size") + { + CSize size; + if (!GUI::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") { float z_level; if (!GUI::ParseString(attr_value, z_level)) - { ReportParseError("Error parsing '%s' (\"%s\")", attr_name.c_str(), attr_value.c_str()); - } else image.m_DeltaZ = z_level/100.f; } else @@ -1472,9 +1472,7 @@ void CGUI::Xeromyces_ReadImage(XMBElement Element, CXeromyces* pFile, CGUISprite { CColor color; if (!GUI::ParseString(attr_value, color)) - { ReportParseError("Error parsing '%s' (\"%s\")", attr_name.c_str(), attr_value.c_str()); - } else image.m_BackColor = color; } else @@ -1482,9 +1480,7 @@ void CGUI::Xeromyces_ReadImage(XMBElement Element, CXeromyces* pFile, CGUISprite { CColor color; if (!GUI::ParseString(attr_value, color)) - { ReportParseError("Error parsing '%s' (\"%s\")", attr_name.c_str(), attr_value.c_str()); - } else image.m_BorderColor = color; } else @@ -1492,9 +1488,7 @@ void CGUI::Xeromyces_ReadImage(XMBElement Element, CXeromyces* pFile, CGUISprite { bool b; if (!GUI::ParseString(attr_value, b)) - { ReportParseError("Error parsing '%s' (\"%s\")", attr_name.c_str(), attr_value.c_str()); - } else image.m_Border = b; } // We don't need no else when we're using DTDs. diff --git a/source/gui/CGUI.h b/source/gui/CGUI.h index 02935ba15a..a328bcde97 100755 --- a/source/gui/CGUI.h +++ b/source/gui/CGUI.h @@ -108,11 +108,13 @@ public: * * @param Sprite Object refering to the sprite (which also caches * 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 Rect Position and Size * @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()); /** diff --git a/source/gui/CGUIScrollBarVertical.cpp b/source/gui/CGUIScrollBarVertical.cpp index 10c66e1f43..f36aa4f5ab 100755 --- a/source/gui/CGUIScrollBarVertical.cpp +++ b/source/gui/CGUIScrollBarVertical.cpp @@ -38,11 +38,13 @@ void CGUIScrollBarVertical::Draw() CRect outline = GetOuterRect(); // Draw background - GetGUI()->DrawSprite(GetStyle()->m_SpriteBackVertical, m_Z+0.1f, - CRect( outline.left, - outline.top+(m_UseEdgeButtons?GetStyle()->m_Width:0), - outline.right, - outline.bottom-(m_UseEdgeButtons?GetStyle()->m_Width:0)) + GetGUI()->DrawSprite(GetStyle()->m_SpriteBackVertical, + 0, + m_Z+0.1f, + CRect(outline.left, + outline.top+(m_UseEdgeButtons?GetStyle()->m_Width:0), + outline.right, + outline.bottom-(m_UseEdgeButtons?GetStyle()->m_Width:0)) ); if (m_UseEdgeButtons) @@ -72,36 +74,41 @@ void CGUIScrollBarVertical::Draw() // Draw top button GetGUI()->DrawSprite(*button_top, - m_Z+0.2f, - CRect(outline.left, - outline.top, - outline.right, + 0, + m_Z+0.2f, + CRect(outline.left, + outline.top, + outline.right, outline.top+GetStyle()->m_Width) ); // Draw bottom button - GetGUI()->DrawSprite(*button_bottom, - m_Z+0.2f, - CRect(outline.left, - outline.bottom-GetStyle()->m_Width, - outline.right, + GetGUI()->DrawSprite(*button_bottom, + 0, + m_Z+0.2f, + CRect(outline.left, + outline.bottom-GetStyle()->m_Width, + outline.right, outline.bottom) ); } // Draw bar if (m_BarPressed) - GetGUI()->DrawSprite(GUI<>::FallBackSprite(GetStyle()->m_SpriteBarVerticalPressed, GetStyle()->m_SpriteBarVertical), - m_Z+0.2f, + GetGUI()->DrawSprite(GUI<>::FallBackSprite(GetStyle()->m_SpriteBarVerticalPressed, GetStyle()->m_SpriteBarVertical), + 0, + m_Z+0.2f, GetBarRect()); else if (m_BarHovered) - GetGUI()->DrawSprite(GUI<>::FallBackSprite(GetStyle()->m_SpriteBarVerticalOver, GetStyle()->m_SpriteBarVertical), - m_Z+0.2f, + GetGUI()->DrawSprite(GUI<>::FallBackSprite(GetStyle()->m_SpriteBarVerticalOver, GetStyle()->m_SpriteBarVertical), + 0, + m_Z+0.2f, GetBarRect()); else - GetGUI()->DrawSprite(GetStyle()->m_SpriteBarVertical, - m_Z+0.2f, + GetGUI()->DrawSprite(GetStyle()->m_SpriteBarVertical, + 0, + m_Z+0.2f, GetBarRect()); } } diff --git a/source/gui/CGUISprite.cpp b/source/gui/CGUISprite.cpp index c7876e6bc5..cf9bd45003 100755 --- a/source/gui/CGUISprite.cpp +++ b/source/gui/CGUISprite.cpp @@ -17,12 +17,13 @@ CGUISpriteInstance &CGUISpriteInstance::operator=(CStr SpriteName) return *this; } -void CGUISpriteInstance::Draw(CRect Size, std::map &Sprites) +void CGUISpriteInstance::Draw(CRect Size, int IconID, std::map &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_CachedIconID = IconID; } GUIRenderer::Draw(m_DrawCallCache); } diff --git a/source/gui/CGUISprite.h b/source/gui/CGUISprite.h index 9eeddc07ff..5ae77ba191 100755 --- a/source/gui/CGUISprite.h +++ b/source/gui/CGUISprite.h @@ -73,7 +73,7 @@ struct SGUIImage // 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. - // Equal to CPos(0,0) for non-icon textures. + // Equal to CSize(0,0) for non-icon textures. CSize m_IconSize; // Color @@ -130,7 +130,7 @@ public: CGUISpriteInstance(); CGUISpriteInstance(CStr SpriteName); CGUISpriteInstance &operator=(CStr SpriteName); - void Draw(CRect Size, std::map &Sprites); + void Draw(CRect Size, int IconID, std::map &Sprites); void Invalidate(); bool IsEmpty() const; CStr GetName() { return m_SpriteName; } @@ -140,9 +140,10 @@ private: // Stored drawing calls, for more efficient rendering GUIRenderer::DrawCalls m_DrawCallCache; - // Size of previously rendered sprite; the cache is invalidated - // whenever this changes. + // Relevant details of previously rendered sprite; the cache is invalidated + // whenever any of these values changes. CRect m_CachedSize; + int m_CachedIconID; }; #endif diff --git a/source/gui/CImage.cpp b/source/gui/CImage.cpp index 03234cb506..471db17103 100755 --- a/source/gui/CImage.cpp +++ b/source/gui/CImage.cpp @@ -18,6 +18,7 @@ using namespace std; CImage::CImage() { AddSetting(GUIST_CGUISpriteInstance, "sprite"); + AddSetting(GUIST_int, "icon-id"); } CImage::~CImage() @@ -31,8 +32,10 @@ void CImage::Draw() float bz = GetBufferedZ(); CGUISpriteInstance *sprite; + int icon_id; GUI::GetSettingPointer(this, "sprite", sprite); + GUI::GetSetting(this, "icon-id", icon_id); - GetGUI()->DrawSprite(*sprite, bz, m_CachedActualSize); + GetGUI()->DrawSprite(*sprite, icon_id, bz, m_CachedActualSize); } } diff --git a/source/gui/CInput.cpp b/source/gui/CInput.cpp index fef7198c2c..7133f27a77 100755 --- a/source/gui/CInput.cpp +++ b/source/gui/CInput.cpp @@ -31,6 +31,7 @@ CInput::CInput() : m_iBufferPos(0) AddSetting(GUIST_bool, "scrollbar"); AddSetting(GUIST_CStr, "scrollbar-style"); AddSetting(GUIST_CGUISpriteInstance, "sprite"); + AddSetting(GUIST_int, "icon-id"); AddSetting(GUIST_CColor, "textcolor"); // TODO Gee: (2004-08-14) // Add a setting for buffer zone @@ -341,9 +342,11 @@ void CInput::Draw() if (GetGUI()) { CGUISpriteInstance *sprite; + int icon_id; GUI::GetSettingPointer(this, "sprite", sprite); + GUI::GetSetting(this, "icon-id", icon_id); - GetGUI()->DrawSprite(*sprite, bz, m_CachedActualSize); + GetGUI()->DrawSprite(*sprite, icon_id, bz, m_CachedActualSize); float scroll=0.f; if (scrollbar) diff --git a/source/gui/CProgressBar.cpp b/source/gui/CProgressBar.cpp index 5353b6d1e6..d078c58fe0 100755 --- a/source/gui/CProgressBar.cpp +++ b/source/gui/CProgressBar.cpp @@ -59,17 +59,19 @@ void CProgressBar::Draw() float bz = GetBufferedZ(); CGUISpriteInstance *sprite_background, *sprite_bar; + int icon_id; float value; GUI::GetSettingPointer(this, "sprite-background", sprite_background); GUI::GetSettingPointer(this, "sprite-bar", sprite_bar); + GUI::GetSetting(this, "icon-id", icon_id); GUI::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) CRect bar_size(m_CachedActualSize.left, m_CachedActualSize.top, 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); } } diff --git a/source/gui/CText.cpp b/source/gui/CText.cpp index db2de3ba28..6a26f459c9 100755 --- a/source/gui/CText.cpp +++ b/source/gui/CText.cpp @@ -26,6 +26,7 @@ CText::CText() AddSetting(GUIST_bool, "scrollbar"); AddSetting(GUIST_CStr, "scrollbar-style"); AddSetting(GUIST_CGUISpriteInstance, "sprite"); + AddSetting(GUIST_int, "icon-id"); AddSetting(GUIST_CColor, "textcolor"); // TODO Gee: (2004-08-14) // Add a setting for buffer zone @@ -162,9 +163,11 @@ void CText::Draw() if (GetGUI()) { CGUISpriteInstance *sprite; + int icon_id; GUI::GetSettingPointer(this, "sprite", sprite); + GUI::GetSetting(this, "icon-id", icon_id); - GetGUI()->DrawSprite(*sprite, bz, m_CachedActualSize); + GetGUI()->DrawSprite(*sprite, icon_id, bz, m_CachedActualSize); float scroll=0.f; if (scrollbar) diff --git a/source/gui/GUI.h b/source/gui/GUI.h index a185ac56f1..134c05de9c 100755 --- a/source/gui/GUI.h +++ b/source/gui/GUI.h @@ -17,14 +17,6 @@ gee@pyro.nu #ifndef GUI_H #define GUI_H -//-------------------------------------------------------- -// Compiler specific -//-------------------------------------------------------- -// Important that we do this before is included -#ifdef _MSC_VER -# pragma warning(disable:4786) -#endif - //-------------------------------------------------------- // Includes //-------------------------------------------------------- @@ -47,7 +39,6 @@ gee@pyro.nu #include "IGUITextOwner.h" #include "IGUIScrollBar.h" #include "CGUIScrollBarVertical.h" -#include "CGUISprite.h" #include "CGUI.h" #endif diff --git a/source/gui/GUIRenderer.cpp b/source/gui/GUIRenderer.cpp index 8e857c72f5..5f065807a3 100644 --- a/source/gui/GUIRenderer.cpp +++ b/source/gui/GUIRenderer.cpp @@ -42,8 +42,11 @@ Handle_rfcnt_tex& Handle_rfcnt_tex::operator=(Handle h_) // Functions to perform drawing-related actions: -void GUIRenderer::UpdateDrawCallCache(DrawCalls &Calls, CStr &SpriteName, CRect &Size, std::map &Sprites) +void GUIRenderer::UpdateDrawCallCache(DrawCalls &Calls, CStr &SpriteName, CRect &Size, int IconID, std::map &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(); std::map::iterator it (Sprites.find(SpriteName)); @@ -69,8 +72,8 @@ void GUIRenderer::UpdateDrawCallCache(DrawCalls &Calls, CStr &SpriteName, CRect { SDrawCall Call; - CRect real = cit->m_Size.GetClientArea(Size); - Call.m_Vertices = real; + CRect ObjectSize = cit->m_Size.GetClientArea(Size); + Call.m_Vertices = ObjectSize; if (cit->m_TextureName.Length()) { @@ -90,40 +93,69 @@ void GUIRenderer::UpdateDrawCallCache(DrawCalls &Calls, CStr &SpriteName, CRect Call.m_TexHandle = h; - int fmt, t_w, t_h; - tex_info(h, &t_w, &t_h, &fmt, NULL, NULL); - Call.m_EnableBlending = (fmt == GL_RGBA || fmt == GL_BGRA); + int TexFormat, t_w, t_h; + tex_info(h, &t_w, &t_h, &TexFormat, NULL, NULL); + float TexWidth = (float)t_w, TexHeight = (float)t_h; + + // TODO: Detect the presence of an alpha channel in a nicer way + Call.m_EnableBlending = (TexFormat == GL_RGBA || TexFormat == GL_BGRA); - // Get the screen position/size of a single tiling of the texture - CRect TexSize = cit->m_TextureSize.GetClientArea(real); + // 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. - CRect TexCoords; + // Get the screen's position/size for the block + CRect BlockScreen = cit->m_TextureSize.GetClientArea(ObjectSize); - TexCoords.left = (TexSize.left - real.left) / TexSize.GetWidth(); - TexCoords.right = TexCoords.left + real.GetWidth() / TexSize.GetWidth(); - - // 'Bottom' is actually the top in screen-space (I think), - // because the GUI puts (0,0) at the top-left - TexCoords.bottom = (TexSize.bottom - real.bottom) / TexSize.GetHeight(); - TexCoords.top = TexCoords.bottom + real.GetHeight() / TexSize.GetHeight(); + // Get the texture's position/size for the block: + CRect BlockTex; + // "real-texture-placement" overrides everything 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 - // to be able to use the unchanged width/height - float width = TexCoords.GetWidth(), - height = TexCoords.GetHeight(); - - 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; + int cols = t_w / (int)cit->m_IconSize.cx; + int col = IconID % cols; + int row = IconID / cols; + BlockTex = CRect(cit->m_IconSize.cx*col, cit->m_IconSize.cy*row, + cit->m_IconSize.cx*(col+1), cit->m_IconSize.cy*(row+1)); } + // 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; } else @@ -142,6 +174,8 @@ void GUIRenderer::UpdateDrawCallCache(DrawCalls &Calls, CStr &SpriteName, CRect 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 for (DrawCalls::const_iterator cit = Calls.begin(); cit != Calls.end(); ++cit) diff --git a/source/gui/GUIRenderer.h b/source/gui/GUIRenderer.h index d4e15522ae..e70ac2c6d9 100644 --- a/source/gui/GUIRenderer.h +++ b/source/gui/GUIRenderer.h @@ -39,7 +39,7 @@ namespace GUIRenderer namespace GUIRenderer { - void UpdateDrawCallCache(DrawCalls &Calls, CStr &SpriteName, CRect& Size, std::map &Sprites); + void UpdateDrawCallCache(DrawCalls &Calls, CStr &SpriteName, CRect& Size, int IconID, std::map &Sprites); void Draw(DrawCalls &Calls); } diff --git a/source/gui/GUIutil.cpp b/source/gui/GUIutil.cpp index ca308a1c30..96cf02f3d8 100755 --- a/source/gui/GUIutil.cpp +++ b/source/gui/GUIutil.cpp @@ -257,7 +257,7 @@ bool CClientArea::SetClientArea(const CStr& Value) // Setup parser to parse the value - // One of the for values: + // One of the four values: // will give outputs like (in argument): // (200) <== no percent, just the first $value // (200) (percent) <== just the percent @@ -271,6 +271,7 @@ bool CClientArea::SetClientArea(const CStr& Value) one_value + "$arg(delim)" + 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 = "_[-_$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; 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") for (int i=0, valuenr=0; i<(int)line.GetArgCount(); ++i) @@ -482,6 +483,7 @@ PS_RESULT GUI::SetSetting(IGUIObject *pObject, const CStr& Setting, const T & return PS_OK; } +// Instantiate templated functions: #define TYPE(T) \ template PS_RESULT GUI::GetSettingPointer(const IGUIObject *pObject, const CStr& Setting, T* &Value); \ template PS_RESULT GUI::GetSetting(const IGUIObject *pObject, const CStr& Setting, T &Value); \ diff --git a/source/gui/IGUIButtonBehavior.cpp b/source/gui/IGUIButtonBehavior.cpp index 6345f33211..096a756701 100755 --- a/source/gui/IGUIButtonBehavior.cpp +++ b/source/gui/IGUIButtonBehavior.cpp @@ -91,7 +91,8 @@ void IGUIButtonBehavior::DrawButton(const CRect &rect, CGUISpriteInstance& sprite, CGUISpriteInstance& sprite_over, CGUISpriteInstance& sprite_pressed, - CGUISpriteInstance& sprite_disabled) + CGUISpriteInstance& sprite_disabled, + int icon_id) { if (GetGUI()) { @@ -100,16 +101,16 @@ void IGUIButtonBehavior::DrawButton(const CRect &rect, if (!enabled) { - GetGUI()->DrawSprite(GUI<>::FallBackSprite(sprite_disabled, sprite), z, rect); + GetGUI()->DrawSprite(GUI<>::FallBackSprite(sprite_disabled, sprite), icon_id, z, rect); } else if (m_MouseHovering) { if (m_Pressed) - GetGUI()->DrawSprite(GUI<>::FallBackSprite(sprite_pressed, sprite), z, rect); + GetGUI()->DrawSprite(GUI<>::FallBackSprite(sprite_pressed, sprite), icon_id, z, rect); 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); } } diff --git a/source/gui/IGUIButtonBehavior.h b/source/gui/IGUIButtonBehavior.h index f15f544010..54afca0e61 100755 --- a/source/gui/IGUIButtonBehavior.h +++ b/source/gui/IGUIButtonBehavior.h @@ -73,13 +73,16 @@ public: * @param sprite_over Sprite drawn when m_MouseHovering is true * @param sprite_pressed Sprite drawn when m_Pressed is true * @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, const float &z, CGUISpriteInstance& sprite, CGUISpriteInstance& sprite_over, CGUISpriteInstance& sprite_pressed, - CGUISpriteInstance& sprite_disabled); + CGUISpriteInstance& sprite_disabled, + int icon_id); /** * Choosing which color of the following according to diff --git a/source/ps/Overlay.cpp b/source/ps/Overlay.cpp index df8bae17c2..a943a7f28b 100755 --- a/source/ps/Overlay.cpp +++ b/source/ps/Overlay.cpp @@ -220,6 +220,11 @@ bool CRect::PointInside(const CPos &point) const 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) diff --git a/source/ps/Overlay.h b/source/ps/Overlay.h index 44960cceed..32b3b22bb7 100755 --- a/source/ps/Overlay.h +++ b/source/ps/Overlay.h @@ -120,6 +120,8 @@ public: */ bool PointInside(const CPos &point) const; + CRect Scale(float x, float y) const; + /** * Returning CPos representing each corner. */