// // Copyright (c) 2008-2013 the Urho3D project. // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. // #include "Precompiled.h" #include "APITemplates.h" #include "CheckBox.h" #include "Cursor.h" #include "DropDownList.h" #include "FileSelector.h" #include "Font.h" #include "LineEdit.h" #include "ListView.h" #include "ScrollBar.h" #include "Slider.h" #include "Sprite.h" #include "Text.h" #include "Text3D.h" #include "UI.h" #include "Window.h" #include "View3D.h" namespace Urho3D { static bool FontSaveXML(const String& fileName, int pointSize, bool usedGlyphs, Font* ptr) { if (fileName.Empty()) return false; File file(ptr->GetContext(), fileName, FILE_WRITE); return ptr->SaveXML(file, pointSize, usedGlyphs); } static void RegisterFont(asIScriptEngine* engine) { RegisterResource(engine, "Font"); engine->RegisterObjectMethod("Font", "bool SaveXML(File@+, int, bool arg2 = false)", asMETHOD(Font, SaveXML), asCALL_THISCALL); engine->RegisterObjectMethod("Font", "bool SaveXML(const String&in, int, bool arg2 = false)", asFUNCTION(FontSaveXML), asCALL_CDECL_OBJLAST); } static void RegisterUIElement(asIScriptEngine* engine) { engine->RegisterEnum("HorizontalAlignment"); engine->RegisterEnumValue("HorizontalAlignment", "HA_LEFT", HA_LEFT); engine->RegisterEnumValue("HorizontalAlignment", "HA_CENTER", HA_CENTER); engine->RegisterEnumValue("HorizontalAlignment", "HA_RIGHT", HA_RIGHT); engine->RegisterEnum("VerticalAlignment"); engine->RegisterEnumValue("VerticalAlignment", "VA_TOP", VA_TOP); engine->RegisterEnumValue("VerticalAlignment", "VA_CENTER", VA_CENTER); engine->RegisterEnumValue("VerticalAlignment", "VA_BOTTOM", VA_BOTTOM); engine->RegisterEnum("Corner"); engine->RegisterEnumValue("Corner", "C_TOPLEFT", C_TOPLEFT); engine->RegisterEnumValue("Corner", "C_TOPRIGHT", C_TOPRIGHT); engine->RegisterEnumValue("Corner", "C_BOTTOMLEFT", C_BOTTOMLEFT); engine->RegisterEnumValue("Corner", "C_BOTTOMRIGHT", C_BOTTOMRIGHT); engine->RegisterEnum("Orientation"); engine->RegisterEnumValue("Orientation", "O_HORIZONTAL", O_HORIZONTAL); engine->RegisterEnumValue("Orientation", "O_VERTICAL", O_VERTICAL); engine->RegisterEnum("FocusMode"); engine->RegisterEnumValue("FocusMode", "FM_NOTFOCUSABLE", FM_NOTFOCUSABLE); engine->RegisterEnumValue("FocusMode", "FM_RESETFOCUS", FM_RESETFOCUS); engine->RegisterEnumValue("FocusMode", "FM_FOCUSABLE", FM_FOCUSABLE); engine->RegisterEnumValue("FocusMode", "FM_FOCUSABLE_DEFOCUSABLE", FM_FOCUSABLE_DEFOCUSABLE); engine->RegisterEnum("LayoutMode"); engine->RegisterEnumValue("LayoutMode", "LM_FREE", LM_FREE); engine->RegisterEnumValue("LayoutMode", "LM_HORIZONTAL", LM_HORIZONTAL); engine->RegisterEnumValue("LayoutMode", "LM_VERTICAL", LM_VERTICAL); engine->RegisterEnum("TraversalMode"); engine->RegisterEnumValue("TraversalMode", "TM_BREADTH_FIRST", TM_BREADTH_FIRST); engine->RegisterEnumValue("TraversalMode", "TM_DEPTH_FIRST", TM_DEPTH_FIRST); engine->RegisterGlobalProperty("const uint DD_DISABLED", (void*)&DD_DISABLED); engine->RegisterGlobalProperty("const uint DD_SOURCE", (void*)&DD_SOURCE); engine->RegisterGlobalProperty("const uint DD_TARGET", (void*)&DD_TARGET); engine->RegisterGlobalProperty("const uint DD_SOURCE_AND_TARGET", (void*)&DD_SOURCE_AND_TARGET); RegisterUIElement(engine, "UIElement"); // Register Variant GetPtr() for UIElement engine->RegisterObjectMethod("Variant", "UIElement@+ GetUIElement() const", asFUNCTION(GetVariantPtr), asCALL_CDECL_OBJLAST); } static void RegisterBorderImage(asIScriptEngine* engine) { RegisterBorderImage(engine, "BorderImage"); } static void RegisterSprite(asIScriptEngine* engine) { RegisterUIElement(engine, "Sprite", true); engine->RegisterObjectMethod("Sprite", "void SetPosition(float, float)", asMETHODPR(Sprite, SetPosition, (float, float), void), asCALL_THISCALL); engine->RegisterObjectMethod("Sprite", "void SetHotSpot(int, int)", asMETHODPR(Sprite, SetHotSpot, (int, int), void), asCALL_THISCALL); engine->RegisterObjectMethod("Sprite", "void SetScale(float, float)", asMETHODPR(Sprite, SetScale, (float, float), void), asCALL_THISCALL); engine->RegisterObjectMethod("Sprite", "void SetScale(float)", asMETHODPR(Sprite, SetScale, (float), void), asCALL_THISCALL); engine->RegisterObjectMethod("Sprite", "void SetFullImageRect()", asMETHOD(Sprite, SetFullImageRect), asCALL_THISCALL); engine->RegisterObjectMethod("Sprite", "void set_position(const Vector2&)", asMETHODPR(Sprite, SetPosition, (const Vector2&), void), asCALL_THISCALL); engine->RegisterObjectMethod("Sprite", "const Vector2& get_position() const", asMETHODPR(Sprite, GetPosition, () const, const Vector2&), asCALL_THISCALL); engine->RegisterObjectMethod("Sprite", "void set_hotSpot(const IntVector2&)", asMETHODPR(Sprite, SetHotSpot, (const IntVector2&), void), asCALL_THISCALL); engine->RegisterObjectMethod("Sprite", "const IntVector2& get_hotSpot() const", asMETHOD(Sprite, GetHotSpot), asCALL_THISCALL); engine->RegisterObjectMethod("Sprite", "void set_scale(const Vector2&)", asMETHODPR(Sprite, SetScale, (const Vector2&), void), asCALL_THISCALL); engine->RegisterObjectMethod("Sprite", "const Vector2& get_scale() const", asMETHOD(Sprite, GetScale), asCALL_THISCALL); engine->RegisterObjectMethod("Sprite", "void set_rotation(float)", asMETHOD(Sprite, SetRotation), asCALL_THISCALL); engine->RegisterObjectMethod("Sprite", "float get_rotation() const", asMETHOD(Sprite, GetRotation), asCALL_THISCALL); engine->RegisterObjectMethod("Sprite", "void set_texture(Texture@+)", asMETHOD(Sprite, SetTexture), asCALL_THISCALL); engine->RegisterObjectMethod("Sprite", "Texture@+ get_texture() const", asMETHOD(Sprite, GetTexture), asCALL_THISCALL); engine->RegisterObjectMethod("Sprite", "void set_imageRect(const IntRect&in)", asMETHODPR(Sprite, SetImageRect, (const IntRect&), void), asCALL_THISCALL); engine->RegisterObjectMethod("Sprite", "const IntRect& get_imageRect() const", asMETHOD(Sprite, GetImageRect), asCALL_THISCALL); engine->RegisterObjectMethod("Sprite", "void set_blendMode(BlendMode)", asMETHOD(Sprite, SetBlendMode), asCALL_THISCALL); engine->RegisterObjectMethod("Sprite", "BlendMode get_blendMode() const", asMETHOD(Sprite, GetBlendMode), asCALL_THISCALL); } static void RegisterCursor(asIScriptEngine* engine) { engine->RegisterEnum("CursorShape"); engine->RegisterEnumValue("CursorShape", "CS_NORMAL", CS_NORMAL); engine->RegisterEnumValue("CursorShape", "CS_RESIZEVERTICAL", CS_RESIZEVERTICAL); engine->RegisterEnumValue("CursorShape", "CS_RESIZEDIAGONAL_TOPRIGHT", CS_RESIZEDIAGONAL_TOPRIGHT); engine->RegisterEnumValue("CursorShape", "CS_RESIZEHORIZONTAL", CS_RESIZEHORIZONTAL); engine->RegisterEnumValue("CursorShape", "CS_RESIZEDIAGONAL_TOPLEFT", CS_RESIZEDIAGONAL_TOPLEFT); engine->RegisterEnumValue("CursorShape", "CS_ACCEPTDROP", CS_ACCEPTDROP); engine->RegisterEnumValue("CursorShape", "CS_REJECTDROP", CS_REJECTDROP); engine->RegisterEnumValue("CursorShape", "CS_BUSY", CS_BUSY); RegisterBorderImage(engine, "Cursor"); engine->RegisterObjectMethod("Cursor", "void DefineShape(CursorShape, Texture@+, const IntRect&in, const IntVector2&in)", asMETHOD(Cursor, DefineShape), asCALL_THISCALL); engine->RegisterObjectMethod("Cursor", "void set_shape(CursorShape)", asMETHOD(Cursor, SetShape), asCALL_THISCALL); engine->RegisterObjectMethod("Cursor", "CursorShape get_shape() const", asMETHOD(Cursor, GetShape), asCALL_THISCALL); engine->RegisterObjectMethod("Cursor", "void set_useSystemShapes(bool)", asMETHOD(Cursor, SetUseSystemShapes), asCALL_THISCALL); engine->RegisterObjectMethod("Cursor", "bool get_useSystemShapes() const", asMETHOD(Cursor, GetUseSystemShapes), asCALL_THISCALL); } static void RegisterButton(asIScriptEngine* engine) { RegisterButton