1
0
forked from 0ad/0ad

Fixed things that use a colour rather than a texture (e.g. the progress bars). Also fixed the completely broken 'caching' system that recalculated everything every single frame. Also made it give linker errors if I ever make that mistake again.

This was SVN commit r1518.
This commit is contained in:
Ykkrosh 2004-12-17 00:05:37 +00:00
parent 0f7f23d774
commit 8f4f8e240f
13 changed files with 221 additions and 166 deletions

View File

@ -124,19 +124,19 @@ 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;
GUI<CGUISpriteInstance>::GetSetting(this, "sprite", sprite); GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite", sprite);
GUI<CGUISpriteInstance>::GetSetting(this, "sprite-over", sprite_over); GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite-over", sprite_over);
GUI<CGUISpriteInstance>::GetSetting(this, "sprite-pressed", sprite_pressed); GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite-pressed", sprite_pressed);
GUI<CGUISpriteInstance>::GetSetting(this, "sprite-disabled", sprite_disabled); GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite-disabled", sprite_disabled);
DrawButton(m_CachedActualSize, DrawButton(m_CachedActualSize,
bz, bz,
sprite, *sprite,
sprite_over, *sprite_over,
sprite_pressed, *sprite_pressed,
sprite_disabled); *sprite_disabled);
CColor color = ChooseColor(); CColor color = ChooseColor();
IGUITextOwner::Draw(0, color, m_TextPos, bz+0.1f); IGUITextOwner::Draw(0, color, m_TextPos, bz+0.1f);

View File

@ -123,29 +123,29 @@ void CCheckBox::Draw()
bool checked; bool checked;
GUI<bool>::GetSetting(this, "checked", checked); GUI<bool>::GetSetting(this, "checked", checked);
CGUISpriteInstance sprite, sprite_over, sprite_pressed, sprite_disabled; CGUISpriteInstance *sprite, *sprite_over, *sprite_pressed, *sprite_disabled;
if (checked) if (checked)
{ {
GUI<CGUISpriteInstance>::GetSetting(this, "sprite2", sprite); GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite2", sprite);
GUI<CGUISpriteInstance>::GetSetting(this, "sprite2-over", sprite_over); GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite2-over", sprite_over);
GUI<CGUISpriteInstance>::GetSetting(this, "sprite2-pressed", sprite_pressed); GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite2-pressed", sprite_pressed);
GUI<CGUISpriteInstance>::GetSetting(this, "sprite2-disabled", sprite_disabled); GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite2-disabled", sprite_disabled);
} }
else else
{ {
GUI<CGUISpriteInstance>::GetSetting(this, "sprite", sprite); GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite", sprite);
GUI<CGUISpriteInstance>::GetSetting(this, "sprite-over", sprite_over); GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite-over", sprite_over);
GUI<CGUISpriteInstance>::GetSetting(this, "sprite-pressed", sprite_pressed); GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite-pressed", sprite_pressed);
GUI<CGUISpriteInstance>::GetSetting(this, "sprite-disabled", sprite_disabled); GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite-disabled", sprite_disabled);
} }
DrawButton( rect, DrawButton(rect,
bz, bz,
sprite, *sprite,
sprite_over, *sprite_over,
sprite_pressed, *sprite_pressed,
sprite_disabled); *sprite_disabled);
CColor color = ChooseColor(); CColor color = ChooseColor();

View File

@ -48,30 +48,30 @@ void CGUIScrollBarVertical::Draw()
if (m_UseEdgeButtons) if (m_UseEdgeButtons)
{ {
// Get Appropriate sprites // Get Appropriate sprites
CGUISpriteInstance button_top, button_bottom; CGUISpriteInstance *button_top, *button_bottom;
// figure out what sprite to use for top button // figure out what sprite to use for top button
if (m_ButtonMinusHovered) if (m_ButtonMinusHovered)
{ {
if (m_ButtonMinusPressed) if (m_ButtonMinusPressed)
button_top = GUI<>::FallBackSprite(GetStyle()->m_SpriteButtonTopPressed, GetStyle()->m_SpriteButtonTop); button_top = &GUI<>::FallBackSprite(GetStyle()->m_SpriteButtonTopPressed, GetStyle()->m_SpriteButtonTop);
else else
button_top = GUI<>::FallBackSprite(GetStyle()->m_SpriteButtonTopOver, GetStyle()->m_SpriteButtonTop); button_top = &GUI<>::FallBackSprite(GetStyle()->m_SpriteButtonTopOver, GetStyle()->m_SpriteButtonTop);
} }
else button_top = GetStyle()->m_SpriteButtonTop; else button_top = &GetStyle()->m_SpriteButtonTop;
// figure out what sprite to use for top button // figure out what sprite to use for top button
if (m_ButtonPlusHovered) if (m_ButtonPlusHovered)
{ {
if (m_ButtonPlusPressed) if (m_ButtonPlusPressed)
button_bottom = GUI<>::FallBackSprite(GetStyle()->m_SpriteButtonBottomPressed, GetStyle()->m_SpriteButtonBottom); button_bottom = &GUI<>::FallBackSprite(GetStyle()->m_SpriteButtonBottomPressed, GetStyle()->m_SpriteButtonBottom);
else else
button_bottom = GUI<>::FallBackSprite(GetStyle()->m_SpriteButtonBottomOver, GetStyle()->m_SpriteButtonBottom); button_bottom = &GUI<>::FallBackSprite(GetStyle()->m_SpriteButtonBottomOver, GetStyle()->m_SpriteButtonBottom);
} }
else button_bottom = GetStyle()->m_SpriteButtonBottom; else button_bottom = &GetStyle()->m_SpriteButtonBottom;
// Draw top button // Draw top button
GetGUI()->DrawSprite(button_top, GetGUI()->DrawSprite(*button_top,
m_Z+0.2f, m_Z+0.2f,
CRect(outline.left, CRect(outline.left,
outline.top, outline.top,
@ -80,7 +80,7 @@ void CGUIScrollBarVertical::Draw()
); );
// Draw bottom button // Draw bottom button
GetGUI()->DrawSprite(button_bottom, GetGUI()->DrawSprite(*button_bottom,
m_Z+0.2f, m_Z+0.2f,
CRect(outline.left, CRect(outline.left,
outline.bottom-GetStyle()->m_Width, outline.bottom-GetStyle()->m_Width,

View File

@ -30,9 +30,9 @@ void CImage::Draw()
{ {
float bz = GetBufferedZ(); float bz = GetBufferedZ();
CGUISpriteInstance sprite; CGUISpriteInstance *sprite;
GUI<CGUISpriteInstance>::GetSetting(this, "sprite", sprite); GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite", sprite);
GetGUI()->DrawSprite(sprite, bz, m_CachedActualSize); GetGUI()->DrawSprite(*sprite, bz, m_CachedActualSize);
} }
} }

View File

@ -340,10 +340,10 @@ void CInput::Draw()
if (GetGUI()) if (GetGUI())
{ {
CGUISpriteInstance sprite; CGUISpriteInstance *sprite;
GUI<CGUISpriteInstance>::GetSetting(this, "sprite", sprite); GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite", sprite);
GetGUI()->DrawSprite(sprite, bz, m_CachedActualSize); GetGUI()->DrawSprite(*sprite, bz, m_CachedActualSize);
float scroll=0.f; float scroll=0.f;
if (scrollbar) if (scrollbar)

View File

@ -58,18 +58,18 @@ void CProgressBar::Draw()
{ {
float bz = GetBufferedZ(); float bz = GetBufferedZ();
CGUISpriteInstance sprite_background, sprite_bar; CGUISpriteInstance *sprite_background, *sprite_bar;
float value; float value;
GUI<CGUISpriteInstance>::GetSetting(this, "sprite-background", sprite_background); GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite-background", sprite_background);
GUI<CGUISpriteInstance>::GetSetting(this, "sprite-bar", sprite_bar); GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite-bar", sprite_bar);
GUI<float>::GetSetting(this, "caption", value); GUI<float>::GetSetting(this, "caption", value);
GetGUI()->DrawSprite(sprite_background, bz, m_CachedActualSize); GetGUI()->DrawSprite(*sprite_background, 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, bz+0.01f, bar_size);
} }
} }

View File

@ -161,10 +161,10 @@ void CText::Draw()
if (GetGUI()) if (GetGUI())
{ {
CGUISpriteInstance sprite; CGUISpriteInstance *sprite;
GUI<CGUISpriteInstance>::GetSetting(this, "sprite", sprite); GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite", sprite);
GetGUI()->DrawSprite(sprite, bz, m_CachedActualSize); GetGUI()->DrawSprite(*sprite, bz, m_CachedActualSize);
float scroll=0.f; float scroll=0.f;
if (scrollbar) if (scrollbar)

View File

@ -68,6 +68,10 @@ void GUIRenderer::UpdateDrawCallCache(DrawCalls &Calls, CStr &SpriteName, CRect
for (cit = it->second.m_Images.begin(); cit != it->second.m_Images.end(); ++cit) for (cit = it->second.m_Images.begin(); cit != it->second.m_Images.end(); ++cit)
{ {
SDrawCall Call; SDrawCall Call;
CRect real = cit->m_Size.GetClientArea(Size);
Call.m_Vertices = real;
if (cit->m_TextureName.Length()) if (cit->m_TextureName.Length())
{ {
Handle h = tex_load(cit->m_TextureName); Handle h = tex_load(cit->m_TextureName);
@ -90,8 +94,6 @@ void GUIRenderer::UpdateDrawCallCache(DrawCalls &Calls, CStr &SpriteName, CRect
tex_info(h, &t_w, &t_h, &fmt, NULL, NULL); tex_info(h, &t_w, &t_h, &fmt, NULL, NULL);
Call.m_EnableBlending = (fmt == GL_RGBA || fmt == GL_BGRA); Call.m_EnableBlending = (fmt == GL_RGBA || fmt == GL_BGRA);
CRect real = cit->m_Size.GetClientArea(Size);
// Get the screen position/size of a single tiling of the texture // Get the screen position/size of a single tiling of the texture
CRect TexSize = cit->m_TextureSize.GetClientArea(real); CRect TexSize = cit->m_TextureSize.GetClientArea(real);
@ -123,11 +125,11 @@ void GUIRenderer::UpdateDrawCallCache(DrawCalls &Calls, CStr &SpriteName, CRect
} }
Call.m_TexCoords = TexCoords; Call.m_TexCoords = TexCoords;
Call.m_Vertices = real;
} }
else else
{ {
Call.m_TexHandle = 0; Call.m_TexHandle = 0;
Call.m_EnableBlending = !(fabs(cit->m_BackColor.a - 1.0f) < 0.0000001f);
} }
Call.m_BackColor = cit->m_BackColor; Call.m_BackColor = cit->m_BackColor;
@ -151,10 +153,6 @@ void GUIRenderer::Draw(DrawCalls &Calls)
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND); glEnable(GL_BLEND);
} }
else
{
glDisable(GL_BLEND);
}
if (cit->m_TexHandle.h) if (cit->m_TexHandle.h)
{ {
@ -181,11 +179,10 @@ void GUIRenderer::Draw(DrawCalls &Calls)
glEnd(); glEnd();
glDisable(GL_TEXTURE_2D);
} }
else else
{ {
glDisable(GL_TEXTURE_2D);
glBegin(GL_QUADS); glBegin(GL_QUADS);
glVertex3f(cit->m_Vertices.right, cit->m_Vertices.bottom, cit->m_DeltaZ); glVertex3f(cit->m_Vertices.right, cit->m_Vertices.bottom, cit->m_DeltaZ);
@ -206,5 +203,11 @@ void GUIRenderer::Draw(DrawCalls &Calls)
glEnd(); glEnd();
} }
} }
if (cit->m_EnableBlending)
{
glDisable(GL_BLEND);
}
} }
} }

44
source/gui/GUItypes.h Normal file
View File

@ -0,0 +1,44 @@
// This file is used by all bits of GUI code that need to repeat some code
// for a variety of types (to avoid duplicating the list of types). Just do
// #define TYPE(T) your_code_involving_T;
// #include "GUItypes.h"
// #undef TYPE
//
// If you want to exclude a particular type, define e.g. GUITYPE_IGNORE_CStr
// File generated by:
// perl -e"print qq{#ifndef GUITYPE_IGNORE_$_\nTYPE($_)\n#endif\n} for qw(bool int float CColor CClientArea CGUIString CGUISpriteInstance CStr CStrW EAlign EVAlign)"
#ifndef GUITYPE_IGNORE_bool
TYPE(bool)
#endif
#ifndef GUITYPE_IGNORE_int
TYPE(int)
#endif
#ifndef GUITYPE_IGNORE_float
TYPE(float)
#endif
#ifndef GUITYPE_IGNORE_CColor
TYPE(CColor)
#endif
#ifndef GUITYPE_IGNORE_CClientArea
TYPE(CClientArea)
#endif
#ifndef GUITYPE_IGNORE_CGUIString
TYPE(CGUIString)
#endif
#ifndef GUITYPE_IGNORE_CGUISpriteInstance
TYPE(CGUISpriteInstance)
#endif
#ifndef GUITYPE_IGNORE_CStr
TYPE(CStr)
#endif
#ifndef GUITYPE_IGNORE_CStrW
TYPE(CStrW)
#endif
#ifndef GUITYPE_IGNORE_EAlign
TYPE(EAlign)
#endif
#ifndef GUITYPE_IGNORE_EVAlign
TYPE(EVAlign)
#endif

View File

@ -191,6 +191,14 @@ bool __ParseString<CGUIString>(const CStr& Value, CGUIString &Output)
return true; return true;
} }
template <>
bool __ParseString<CStr>(const CStr& Value, CStr &Output)
{
// Do very little.
Output = Value;
return true;
}
template <> template <>
bool __ParseString<CStrW>(const CStr& Value, CStrW &Output) bool __ParseString<CStrW>(const CStr& Value, CStrW &Output)
{ {
@ -387,6 +395,7 @@ void CInternalCGUIAccessorBase::HandleMessage(IGUIObject *pObject, const SGUIMes
} }
#ifndef NDEBUG #ifndef NDEBUG
#define TYPE(T) \ #define TYPE(T) \
template<> void CheckType<T>(const IGUIObject* obj, const CStr& setting) { \ template<> void CheckType<T>(const IGUIObject* obj, const CStr& setting) { \
@ -396,16 +405,93 @@ void CInternalCGUIAccessorBase::HandleMessage(IGUIObject *pObject, const SGUIMes
throw "EXCESSIVELY FATAL ERROR: Inconsistent types in GUI"; /* TODO: better reporting */ \ throw "EXCESSIVELY FATAL ERROR: Inconsistent types in GUI"; /* TODO: better reporting */ \
} \ } \
} }
TYPE(bool) #include "GUItypes.h"
TYPE(int)
TYPE(float)
TYPE(CClientArea)
TYPE(CStr)
TYPE(CStrW)
TYPE(CColor)
TYPE(CGUIString)
TYPE(CGUISpriteInstance)
TYPE(EAlign)
TYPE(EVAlign)
#undef TYPE #undef TYPE
#endif #endif
//--------------------------------------------------------------------
template <typename T>
PS_RESULT GUI<T>::GetSettingPointer(const IGUIObject *pObject, const CStr& Setting, T* &Value)
{
if (pObject == NULL)
return PS_OBJECT_FAIL;
if (!pObject->SettingExists(Setting))
return PS_SETTING_FAIL;
if (!pObject->m_Settings.find(Setting)->second.m_pSetting)
return PS_FAIL;
#ifndef NDEBUG
CheckType<T>(pObject, Setting);
#endif
// Get value
Value = (T*)pObject->m_Settings.find(Setting)->second.m_pSetting;
return PS_OK;
}
template <typename T>
PS_RESULT GUI<T>::GetSetting(const IGUIObject *pObject, const CStr& Setting, T &Value)
{
T* v;
PS_RESULT ret = GetSettingPointer(pObject, Setting, v);
if (ret == PS_OK)
Value = *v;
return ret;
}
template <typename T>
PS_RESULT GUI<T>::SetSetting(IGUIObject *pObject, const CStr& Setting, const T &Value)
{
if (pObject == NULL)
return PS_OBJECT_FAIL;
if (!pObject->SettingExists(Setting))
return PS_SETTING_FAIL;
#ifndef NDEBUG
CheckType<T>(pObject, Setting);
#endif
// Set value
*(T*)pObject->m_Settings[Setting].m_pSetting = Value;
//
// Some settings needs special attention at change
//
// If setting was "size", we need to re-cache itself and all children
if (Setting == CStr("size"))
{
RecurseObject(0, pObject, &IGUIObject::UpdateCachedSize);
}
else
if (Setting == CStr("hidden"))
{
// Hiding an object requires us to reset it and all children
QueryResetting(pObject);
//RecurseObject(0, pObject, IGUIObject::ResetStates);
}
HandleMessage(pObject, SGUIMessage(GUIM_SETTINGS_UPDATED, Setting));
return PS_OK;
}
#define TYPE(T) \
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>::SetSetting(IGUIObject *pObject, const CStr& Setting, const T &Value);
#define GUITYPE_IGNORE_CGUISpriteInstance
#include "GUItypes.h"
// Don't instantiate GetSetting<CGUISpriteInstance> - this will cause linker errors if
// you attempt to retrieve a sprite using GetSetting, since that copies the sprite
// and will mess up the caching performed by DrawSprite. You have to use GetSettingPointer
// instead. (This is mainly useful to stop me accidentally using the wrong function.)
template PS_RESULT GUI<CGUISpriteInstance>::GetSettingPointer(const IGUIObject *pObject, const CStr& Setting, CGUISpriteInstance* &Value);
template PS_RESULT GUI<CGUISpriteInstance>::SetSetting(IGUIObject *pObject, const CStr& Setting, const CGUISpriteInstance &Value);

View File

@ -147,6 +147,11 @@ class GUI : public CInternalCGUIAccessorBase
friend class CInternalCGUIAccessorBase; friend class CInternalCGUIAccessorBase;
public: public:
// Like GetSetting (below), but doesn't make a copy of the value
// (so it can be modified later)
static PS_RESULT GetSettingPointer(const IGUIObject *pObject, const CStr& Setting, T* &Value);
/** /**
* Retrieves a setting by name from object pointer * Retrieves a setting by name from object pointer
* *
@ -154,26 +159,7 @@ public:
* @param Setting Setting by name * @param Setting Setting by name
* @param Value Stores value here, note type T! * @param Value Stores value here, note type T!
*/ */
static PS_RESULT GetSetting(const IGUIObject *pObject, const CStr& Setting, T &Value) static PS_RESULT GetSetting(const IGUIObject *pObject, const CStr& Setting, T &Value);
{
if (pObject == NULL)
return PS_OBJECT_FAIL;
if (!pObject->SettingExists(Setting))
return PS_SETTING_FAIL;
if (!pObject->m_Settings.find(Setting)->second.m_pSetting)
return PS_FAIL;
#ifndef NDEBUG
CheckType<T>(pObject, Setting);
#endif
// Get value
Value = *(T*)pObject->m_Settings.find(Setting)->second.m_pSetting;
return PS_OK;
}
/** /**
* Sets a value by name using a real datatype as input. * Sets a value by name using a real datatype as input.
@ -185,42 +171,7 @@ public:
* @param Setting Setting by name * @param Setting Setting by name
* @param Value Sets value to this, note type T! * @param Value Sets value to this, note type T!
*/ */
static PS_RESULT SetSetting(IGUIObject *pObject, const CStr& Setting, const T &Value) static PS_RESULT SetSetting(IGUIObject *pObject, const CStr& Setting, const T &Value);
{
if (pObject == NULL)
return PS_OBJECT_FAIL;
if (!pObject->SettingExists(Setting))
return PS_SETTING_FAIL;
#ifndef NDEBUG
CheckType<T>(pObject, Setting);
#endif
// Set value
*(T*)pObject->m_Settings[Setting].m_pSetting = Value;
//
// Some settings needs special attention at change
//
// If setting was "size", we need to re-cache itself and all children
if (Setting == CStr("size"))
{
RecurseObject(0, pObject, &IGUIObject::UpdateCachedSize);
}
else
if (Setting == CStr("hidden"))
{
// Hiding an object requires us to reset it and all children
QueryResetting(pObject);
//RecurseObject(0, pObject, IGUIObject::ResetStates);
}
HandleMessage(pObject, SGUIMessage(GUIM_SETTINGS_UPDATED, Setting));
return PS_OK;
}
#ifdef g_GUI #ifdef g_GUI
/** /**

View File

@ -56,22 +56,12 @@ IGUIObject::IGUIObject() :
IGUIObject::~IGUIObject() IGUIObject::~IGUIObject()
{ {
// delete() needs to know the type of the variable - never delete a void* // delete() needs to know the type of the variable - never delete a void*
#define TYPE(t) case GUIST_##t: delete (t*)it->second.m_pSetting; break #define TYPE(t) case GUIST_##t: delete (t*)it->second.m_pSetting; break;
map<CStr, SGUISetting>::iterator it; map<CStr, SGUISetting>::iterator it;
for (it = m_Settings.begin(); it != m_Settings.end(); ++it) for (it = m_Settings.begin(); it != m_Settings.end(); ++it)
switch (it->second.m_Type) switch (it->second.m_Type)
{ {
TYPE(bool); #include "GUItypes.h"
TYPE(int);
TYPE(float);
TYPE(CColor);
TYPE(CClientArea);
TYPE(CGUIString);
TYPE(CGUISpriteInstance);
TYPE(CStr);
TYPE(CStrW);
TYPE(EAlign);
TYPE(EVAlign);
default: default:
debug_warn("Invalid setting type"); debug_warn("Invalid setting type");
} }
@ -146,7 +136,7 @@ void IGUIObject::Destroy()
} }
// Notice if using this, the naming convention of GUIST_ should be strict. // Notice if using this, the naming convention of GUIST_ should be strict.
#define CASE_TYPE(type) \ #define TYPE(type) \
case GUIST_##type: \ case GUIST_##type: \
m_Settings[Name].m_pSetting = new type(); \ m_Settings[Name].m_pSetting = new type(); \
break; break;
@ -163,23 +153,15 @@ void IGUIObject::AddSetting(const EGUISettingType &Type, const CStr& Name)
switch (Type) switch (Type)
{ {
// Construct the setting. // Construct the setting.
CASE_TYPE(bool) #include "GUItypes.h"
CASE_TYPE(int)
CASE_TYPE(float)
CASE_TYPE(CClientArea)
CASE_TYPE(CStr)
CASE_TYPE(CStrW)
CASE_TYPE(CColor)
CASE_TYPE(CGUIString)
CASE_TYPE(CGUISpriteInstance)
CASE_TYPE(EAlign)
CASE_TYPE(EVAlign)
default: default:
debug_warn("IGUIObject::AddSetting failed, type not recognized!"); debug_warn("IGUIObject::AddSetting failed, type not recognized!");
break; break;
} }
} }
#undef TYPE
bool IGUIObject::MouseOver() bool IGUIObject::MouseOver()
{ {
@ -234,7 +216,7 @@ bool IGUIObject::SettingExists(const CStr& Setting) const
return (m_Settings.count(Setting) >= 1); return (m_Settings.count(Setting) >= 1);
} }
#define ADD_TYPE(type) \ #define TYPE(type) \
else \ else \
if (set.m_Type == GUIST_##type) \ if (set.m_Type == GUIST_##type) \
{ \ { \
@ -255,20 +237,9 @@ PS_RESULT IGUIObject::SetSetting(const CStr& Setting, const CStr& Value)
// Get setting // Get setting
SGUISetting set = m_Settings[Setting]; SGUISetting set = m_Settings[Setting];
if (set.m_Type == GUIST_CStr) if (0);
{ // else...
GUI<CStr>::SetSetting(this, Setting, Value); #include "GUItypes.h"
}
ADD_TYPE(CStrW)
ADD_TYPE(bool)
ADD_TYPE(float)
ADD_TYPE(int)
ADD_TYPE(CColor)
ADD_TYPE(CClientArea)
ADD_TYPE(CGUIString)
ADD_TYPE(CGUISpriteInstance)
ADD_TYPE(EAlign)
ADD_TYPE(EVAlign)
else else
{ {
return PS_FAIL; return PS_FAIL;
@ -276,7 +247,7 @@ PS_RESULT IGUIObject::SetSetting(const CStr& Setting, const CStr& Value)
return PS_OK; return PS_OK;
} }
#undef ADD_TYPE #undef TYPE
PS_RESULT IGUIObject::GetSettingType(const CStr& Setting, EGUISettingType &Type) const PS_RESULT IGUIObject::GetSettingType(const CStr& Setting, EGUISettingType &Type) const

View File

@ -186,9 +186,9 @@ JSBool JSI_IGUIObject::getProperty(JSContext* cx, JSObject* obj, jsval id, jsval
case GUIST_CGUISpriteInstance: case GUIST_CGUISpriteInstance:
{ {
CGUISpriteInstance value; CGUISpriteInstance *value;
GUI<CGUISpriteInstance>::GetSetting(e, propName, value); GUI<CGUISpriteInstance>::GetSettingPointer(e, propName, value);
*vp = STRING_TO_JSVAL(JS_NewStringCopyZ(cx, value.GetName())); *vp = STRING_TO_JSVAL(JS_NewStringCopyZ(cx, value->GetName()));
break; break;
} }