Browse Source

Modified the SetStyle() and SetStyleAuto() methods of UIElement class to return a bool indicating whether the operation is successful. In Editor app, when fails to set to a requested icon type then automatically set to an 'unknown' icon type.

Wei Tjong Yao 12 years ago
parent
commit
dcf9099d1f

+ 2 - 1
Bin/Data/Scripts/Editor/EditorUI.as

@@ -975,7 +975,8 @@ void IconizeUIElement(UIElement@ element, const String&in iconType)
     }
 
     // Set the icon type
-    icon.SetStyle(iconStyle, iconType);
+    if (!icon.SetStyle(iconStyle, iconType))
+        icon.SetStyle(iconStyle, "Unknown");    // If fails then use an 'unknown' icon type
     icon.color = Color(1,1,1,1); // Reset to enabled color
 }
 

BIN
Bin/Data/Textures/EditorIcons.png


+ 4 - 0
Bin/Data/UI/EditorIcons.xml

@@ -191,4 +191,8 @@
         <attribute name="Texture" value="Texture2D;Textures/EditorIcons.png" />
         <attribute name="Image Rect" value="64 32 78 46" />
     </element>
+    <element type="Unknown">
+        <attribute name="Texture" value="Texture2D;Textures/EditorIcons.png" />
+        <attribute name="Image Rect" value="240 64 254 78" />
+    </element>
 </elements>

+ 45 - 45
Docs/ScriptAPI.dox

@@ -3276,9 +3276,9 @@ Methods:<br>
 - bool LoadChildXML(const XMLElement&, XMLFile@, bool arg2 = false)
 - bool LoadChildXML(XMLFile@, XMLFile@)
 - bool SaveXML(File@)
-- void SetStyle(const XMLElement&)
-- void SetStyle(XMLFile@, const String&)
-- void SetStyleAuto(XMLFile@)
+- bool SetStyle(const XMLElement&)
+- bool SetStyle(XMLFile@, const String&)
+- bool SetStyleAuto(XMLFile@)
 - void SetPosition(int, int)
 - void SetSize(int, int)
 - void SetMinSize(int, int)
@@ -3398,9 +3398,9 @@ Methods:<br>
 - bool LoadChildXML(const XMLElement&, XMLFile@, bool arg2 = false)
 - bool LoadChildXML(XMLFile@, XMLFile@)
 - bool SaveXML(File@)
-- void SetStyle(const XMLElement&)
-- void SetStyle(XMLFile@, const String&)
-- void SetStyleAuto(XMLFile@)
+- bool SetStyle(const XMLElement&)
+- bool SetStyle(XMLFile@, const String&)
+- bool SetStyleAuto(XMLFile@)
 - void SetPosition(int, int)
 - void SetSize(int, int)
 - void SetMinSize(int, int)
@@ -3528,9 +3528,9 @@ Methods:<br>
 - bool LoadChildXML(const XMLElement&, XMLFile@, bool arg2 = false)
 - bool LoadChildXML(XMLFile@, XMLFile@)
 - bool SaveXML(File@)
-- void SetStyle(const XMLElement&)
-- void SetStyle(XMLFile@, const String&)
-- void SetStyleAuto(XMLFile@)
+- bool SetStyle(const XMLElement&)
+- bool SetStyle(XMLFile@, const String&)
+- bool SetStyleAuto(XMLFile@)
 - void SetSize(int, int)
 - void SetMinSize(int, int)
 - void SetMaxSize(int, int)
@@ -3624,9 +3624,9 @@ Methods:<br>
 - bool LoadChildXML(const XMLElement&, XMLFile@, bool arg2 = false)
 - bool LoadChildXML(XMLFile@, XMLFile@)
 - bool SaveXML(File@)
-- void SetStyle(const XMLElement&)
-- void SetStyle(XMLFile@, const String&)
-- void SetStyleAuto(XMLFile@)
+- bool SetStyle(const XMLElement&)
+- bool SetStyle(XMLFile@, const String&)
+- bool SetStyleAuto(XMLFile@)
 - void SetPosition(int, int)
 - void SetSize(int, int)
 - void SetMinSize(int, int)
@@ -3761,9 +3761,9 @@ Methods:<br>
 - bool LoadChildXML(const XMLElement&, XMLFile@, bool arg2 = false)
 - bool LoadChildXML(XMLFile@, XMLFile@)
 - bool SaveXML(File@)
-- void SetStyle(const XMLElement&)
-- void SetStyle(XMLFile@, const String&)
-- void SetStyleAuto(XMLFile@)
+- bool SetStyle(const XMLElement&)
+- bool SetStyle(XMLFile@, const String&)
+- bool SetStyleAuto(XMLFile@)
 - void SetPosition(int, int)
 - void SetSize(int, int)
 - void SetMinSize(int, int)
@@ -3894,9 +3894,9 @@ Methods:<br>
 - bool LoadChildXML(const XMLElement&, XMLFile@, bool arg2 = false)
 - bool LoadChildXML(XMLFile@, XMLFile@)
 - bool SaveXML(File@)
-- void SetStyle(const XMLElement&)
-- void SetStyle(XMLFile@, const String&)
-- void SetStyleAuto(XMLFile@)
+- bool SetStyle(const XMLElement&)
+- bool SetStyle(XMLFile@, const String&)
+- bool SetStyleAuto(XMLFile@)
 - void SetPosition(int, int)
 - void SetSize(int, int)
 - void SetMinSize(int, int)
@@ -4026,9 +4026,9 @@ Methods:<br>
 - bool LoadChildXML(const XMLElement&, XMLFile@, bool arg2 = false)
 - bool LoadChildXML(XMLFile@, XMLFile@)
 - bool SaveXML(File@)
-- void SetStyle(const XMLElement&)
-- void SetStyle(XMLFile@, const String&)
-- void SetStyleAuto(XMLFile@)
+- bool SetStyle(const XMLElement&)
+- bool SetStyle(XMLFile@, const String&)
+- bool SetStyleAuto(XMLFile@)
 - void SetPosition(int, int)
 - void SetSize(int, int)
 - void SetMinSize(int, int)
@@ -4162,9 +4162,9 @@ Methods:<br>
 - bool LoadChildXML(const XMLElement&, XMLFile@, bool arg2 = false)
 - bool LoadChildXML(XMLFile@, XMLFile@)
 - bool SaveXML(File@)
-- void SetStyle(const XMLElement&)
-- void SetStyle(XMLFile@, const String&)
-- void SetStyleAuto(XMLFile@)
+- bool SetStyle(const XMLElement&)
+- bool SetStyle(XMLFile@, const String&)
+- bool SetStyleAuto(XMLFile@)
 - void SetPosition(int, int)
 - void SetSize(int, int)
 - void SetMinSize(int, int)
@@ -4296,9 +4296,9 @@ Methods:<br>
 - bool LoadChildXML(const XMLElement&, XMLFile@, bool arg2 = false)
 - bool LoadChildXML(XMLFile@, XMLFile@)
 - bool SaveXML(File@)
-- void SetStyle(const XMLElement&)
-- void SetStyle(XMLFile@, const String&)
-- void SetStyleAuto(XMLFile@)
+- bool SetStyle(const XMLElement&)
+- bool SetStyle(XMLFile@, const String&)
+- bool SetStyleAuto(XMLFile@)
 - void SetPosition(int, int)
 - void SetSize(int, int)
 - void SetMinSize(int, int)
@@ -4428,9 +4428,9 @@ Methods:<br>
 - bool LoadChildXML(const XMLElement&, XMLFile@, bool arg2 = false)
 - bool LoadChildXML(XMLFile@, XMLFile@)
 - bool SaveXML(File@)
-- void SetStyle(const XMLElement&)
-- void SetStyle(XMLFile@, const String&)
-- void SetStyleAuto(XMLFile@)
+- bool SetStyle(const XMLElement&)
+- bool SetStyle(XMLFile@, const String&)
+- bool SetStyleAuto(XMLFile@)
 - void SetPosition(int, int)
 - void SetSize(int, int)
 - void SetMinSize(int, int)
@@ -4589,9 +4589,9 @@ Methods:<br>
 - bool LoadChildXML(const XMLElement&, XMLFile@, bool arg2 = false)
 - bool LoadChildXML(XMLFile@, XMLFile@)
 - bool SaveXML(File@)
-- void SetStyle(const XMLElement&)
-- void SetStyle(XMLFile@, const String&)
-- void SetStyleAuto(XMLFile@)
+- bool SetStyle(const XMLElement&)
+- bool SetStyle(XMLFile@, const String&)
+- bool SetStyleAuto(XMLFile@)
 - void SetPosition(int, int)
 - void SetSize(int, int)
 - void SetMinSize(int, int)
@@ -4792,9 +4792,9 @@ Methods:<br>
 - bool LoadChildXML(const XMLElement&, XMLFile@, bool arg2 = false)
 - bool LoadChildXML(XMLFile@, XMLFile@)
 - bool SaveXML(File@)
-- void SetStyle(const XMLElement&)
-- void SetStyle(XMLFile@, const String&)
-- void SetStyleAuto(XMLFile@)
+- bool SetStyle(const XMLElement&)
+- bool SetStyle(XMLFile@, const String&)
+- bool SetStyleAuto(XMLFile@)
 - void SetPosition(int, int)
 - void SetSize(int, int)
 - void SetMinSize(int, int)
@@ -4933,9 +4933,9 @@ Methods:<br>
 - bool LoadChildXML(const XMLElement&, XMLFile@, bool arg2 = false)
 - bool LoadChildXML(XMLFile@, XMLFile@)
 - bool SaveXML(File@)
-- void SetStyle(const XMLElement&)
-- void SetStyle(XMLFile@, const String&)
-- void SetStyleAuto(XMLFile@)
+- bool SetStyle(const XMLElement&)
+- bool SetStyle(XMLFile@, const String&)
+- bool SetStyleAuto(XMLFile@)
 - void SetPosition(int, int)
 - void SetSize(int, int)
 - void SetMinSize(int, int)
@@ -5077,9 +5077,9 @@ Methods:<br>
 - bool LoadChildXML(const XMLElement&, XMLFile@, bool arg2 = false)
 - bool LoadChildXML(XMLFile@, XMLFile@)
 - bool SaveXML(File@)
-- void SetStyle(const XMLElement&)
-- void SetStyle(XMLFile@, const String&)
-- void SetStyleAuto(XMLFile@)
+- bool SetStyle(const XMLElement&)
+- bool SetStyle(XMLFile@, const String&)
+- bool SetStyleAuto(XMLFile@)
 - void SetPosition(int, int)
 - void SetSize(int, int)
 - void SetMinSize(int, int)
@@ -5233,9 +5233,9 @@ Methods:<br>
 - bool LoadChildXML(const XMLElement&, XMLFile@, bool arg2 = false)
 - bool LoadChildXML(XMLFile@, XMLFile@)
 - bool SaveXML(File@)
-- void SetStyle(const XMLElement&)
-- void SetStyle(XMLFile@, const String&)
-- void SetStyleAuto(XMLFile@)
+- bool SetStyle(const XMLElement&)
+- bool SetStyle(XMLFile@, const String&)
+- bool SetStyleAuto(XMLFile@)
 - void SetPosition(int, int)
 - void SetSize(int, int)
 - void SetMinSize(int, int)

+ 4 - 4
Engine/Engine/APITemplates.h

@@ -838,9 +838,9 @@ template <class T> void RegisterUIElement(asIScriptEngine* engine, const char* c
     engine->RegisterObjectMethod(className, "bool LoadChildXML(const XMLElement&in, XMLFile@+, bool arg2 = false)", asMETHOD(T, LoadChildXML), asCALL_THISCALL);
     engine->RegisterObjectMethod(className, "bool LoadChildXML(XMLFile@+, XMLFile@+)", asFUNCTION(UIElementLoadChildXML), asCALL_CDECL_OBJLAST);
     engine->RegisterObjectMethod(className, "bool SaveXML(File@+)", asFUNCTION(UIElementSaveXML), asCALL_CDECL_OBJLAST);
-    engine->RegisterObjectMethod(className, "void SetStyle(const XMLElement&in)", asMETHODPR(T, SetStyle, (const XMLElement&), void), asCALL_THISCALL);
-    engine->RegisterObjectMethod(className, "void SetStyle(XMLFile@+, const String&in)", asMETHODPR(T, SetStyle, (XMLFile*, const String&), void), asCALL_THISCALL);
-    engine->RegisterObjectMethod(className, "void SetStyleAuto(XMLFile@+)", asMETHODPR(T, SetStyleAuto, (XMLFile*), void), asCALL_THISCALL);
+    engine->RegisterObjectMethod(className, "bool SetStyle(const XMLElement&in)", asMETHODPR(T, SetStyle, (const XMLElement&), bool), asCALL_THISCALL);
+    engine->RegisterObjectMethod(className, "bool SetStyle(XMLFile@+, const String&in)", asMETHODPR(T, SetStyle, (XMLFile*, const String&), bool), asCALL_THISCALL);
+    engine->RegisterObjectMethod(className, "bool SetStyleAuto(XMLFile@+)", asMETHOD(T, SetStyleAuto), asCALL_THISCALL);
     if (!isSprite)
         engine->RegisterObjectMethod(className, "void SetPosition(int, int)", asMETHODPR(UIElement, SetPosition, (int, int), void), asCALL_THISCALL);
     engine->RegisterObjectMethod(className, "void SetSize(int, int)", asMETHODPR(T, SetSize, (int, int), void), asCALL_THISCALL);
@@ -879,7 +879,7 @@ template <class T> void RegisterUIElement(asIScriptEngine* engine, const char* c
         engine->RegisterObjectMethod(className, "bool IsInside(IntVector2, bool)", asMETHOD(T, IsInside), asCALL_THISCALL);
         engine->RegisterObjectMethod(className, "bool IsInsideCombined(IntVector2, bool)", asMETHOD(T, IsInsideCombined), asCALL_THISCALL);
     }
-    engine->RegisterObjectMethod(className, "void set_style(XMLFile@+)", asMETHODPR(T, SetStyleAuto, (XMLFile*), void), asCALL_THISCALL);
+    engine->RegisterObjectMethod(className, "void set_style(XMLFile@+)", asMETHOD(T, SetStyleAuto), asCALL_THISCALL);
     engine->RegisterObjectMethod(className, "void set_name(const String&in)", asMETHOD(T, SetName), asCALL_THISCALL);
     engine->RegisterObjectMethod(className, "const String& get_name() const", asMETHOD(T, GetName), asCALL_THISCALL);
     if (!isSprite)

+ 11 - 12
Engine/UI/UIElement.cpp

@@ -870,32 +870,31 @@ void UIElement::SetDragDropMode(unsigned mode)
     dragDropMode_ = mode;
 }
 
-void UIElement::SetStyle(XMLFile* file, const String& typeName)
+bool UIElement::SetStyle(XMLFile* file, const String& styleName)
 {
-    appliedStyle_ = typeName;
-    if (typeName == "none")
-        return;
+    appliedStyle_ = styleName;
+    if (styleName == "none")
+        return true;
 
     if (!file)
-        return;
+        return false;
 
-    styleXPathQuery_.SetVariable("typeName", typeName);
+    styleXPathQuery_.SetVariable("typeName", styleName);
     XMLElement styleElem = file->GetRoot().SelectSinglePrepared(styleXPathQuery_);
-    if (styleElem)
-        SetStyle(styleElem);
+    return styleElem && SetStyle(styleElem);
 }
 
-void UIElement::SetStyle(const XMLElement& element)
+bool UIElement::SetStyle(const XMLElement& element)
 {
     appliedStyle_ = element.GetAttribute("type");
 
     // Consider style attribute values as instance-level attribute default values
-    LoadXML(element, true);
+    return LoadXML(element, true);
 }
 
-void UIElement::SetStyleAuto(XMLFile* file)
+bool UIElement::SetStyleAuto(XMLFile* file)
 {
-    SetStyle(file, GetTypeName());
+    return SetStyle(file, GetTypeName());
 }
 
 void UIElement::SetDefaultStyle(XMLFile* style)

+ 6 - 6
Engine/UI/UIElement.h

@@ -252,12 +252,12 @@ public:
     void SetFocusMode(FocusMode mode);
     /// Set drag and drop flags.
     void SetDragDropMode(unsigned mode);
-    /// Set style from an XML file. Find the style element by name.
-    void SetStyle(XMLFile* file, const String& typeName);
-    /// Set style from an XML element.
-    void SetStyle(const XMLElement& element);
-    /// Set style from an XML file. Find the style element automatically.
-    void SetStyleAuto(XMLFile* file);
+    /// Set style from an XML file. Find the style element by name. Return true if the style is applied successfully.
+    bool SetStyle(XMLFile* file, const String& styleName);
+    /// Set style from an XML element. Return true if the style is applied successfully.
+    bool SetStyle(const XMLElement& element);
+    /// Set style from an XML file. Find the style element automatically. Return true if the style is applied successfully.
+    bool SetStyleAuto(XMLFile* file);
     /// Set default style for later use by children elements.
     void SetDefaultStyle(XMLFile* style);
     /// Set layout.