// // Copyright (c) 2008-2017 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 "../AngelScript/APITemplates.h" #include "../Input/Input.h" #include "../UI/CheckBox.h" #include "../UI/DropDownList.h" #include "../UI/FileSelector.h" #include "../UI/Font.h" #include "../UI/LineEdit.h" #include "../UI/ListView.h" #include "../UI/MessageBox.h" #include "../UI/ProgressBar.h" #include "../UI/ScrollBar.h" #include "../UI/Slider.h" #include "../UI/Sprite.h" #include "../UI/Text.h" #include "../UI/Text3D.h" #include "../UI/ToolTip.h" #include "../UI/UI.h" #include "../UI/View3D.h" #include "../DebugNew.h" namespace Urho3D { static bool FontSaveXMLVectorBuffer(VectorBuffer& buffer, int pointSize, bool usedGlyphs, const String& indentation, Font* ptr) { return ptr->SaveXML(buffer, pointSize, usedGlyphs, indentation); } static bool FontSaveXML(const String& fileName, int pointSize, bool usedGlyphs, const String& indentation, Font* ptr) { if (fileName.Empty()) return false; File file(ptr->GetContext(), fileName, FILE_WRITE); return ptr->SaveXML(file, pointSize, usedGlyphs, indentation); } static bool FontSaveXMLFile(File* file, int pointSize, bool usedGlyphs, const String& indentation, Font* ptr) { return ptr->SaveXML(*file, pointSize, usedGlyphs, indentation); } static void RegisterFont(asIScriptEngine* engine) { engine->RegisterEnum("FontType"); engine->RegisterEnumValue("FontType", "FONT_NONE", FONT_NONE); engine->RegisterEnumValue("FontType", "FONT_FREETYPE", FONT_FREETYPE); engine->RegisterEnumValue("FontType", "FONT_BITMAP", FONT_BITMAP); RegisterResource(engine, "Font"); engine->RegisterObjectMethod("Font", "bool SaveXML(File@+, int, bool usedGlyphs = false, const String&in indentation = \"\t\")", asFUNCTION(FontSaveXMLFile), asCALL_CDECL_OBJLAST); engine->RegisterObjectMethod("Font", "bool SaveXML(VectorBuffer&, int, bool usedGlyphs = false, const String&in indentation = \"\t\")", asFUNCTION(FontSaveXMLVectorBuffer), asCALL_CDECL_OBJLAST); engine->RegisterObjectMethod("Font", "bool SaveXML(const String&in, int, bool usedGlyphs = false, const String&in indentation = \"\t\")", asFUNCTION(FontSaveXML), asCALL_CDECL_OBJLAST); engine->RegisterObjectMethod("Font", "IntVector2 GetTotalGlyphOffset(float) const", asMETHOD(Font, GetTotalGlyphOffset), asCALL_THISCALL); engine->RegisterObjectMethod("Font", "void set_absoluteGlyphOffset(const IntVector2&)", asMETHOD(Font, SetAbsoluteGlyphOffset), asCALL_THISCALL); engine->RegisterObjectMethod("Font", "const IntVector2& get_absoluteGlyphOffset() const", asMETHOD(Font, GetAbsoluteGlyphOffset), asCALL_THISCALL); engine->RegisterObjectMethod("Font", "void set_scaledGlyphOffset(const Vector2&)", asMETHOD(Font, SetScaledGlyphOffset), asCALL_THISCALL); engine->RegisterObjectMethod("Font", "const Vector2& get_scaledGlyphOffset() const", asMETHOD(Font, GetScaledGlyphOffset), asCALL_THISCALL); engine->RegisterObjectMethod("Font", "FontType get_fontType() const", asMETHOD(Font, GetFontType), asCALL_THISCALL); } 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->RegisterEnumValue("HorizontalAlignment", "HA_CUSTOM", HA_CUSTOM); 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->RegisterEnumValue("VerticalAlignment", "VA_CUSTOM", VA_CUSTOM); 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 TouchState touchedElement property now engine->RegisterObjectMethod("TouchState", "UIElement@+ get_touchedElement()", asMETHOD(TouchState, GetTouchedElement), asCALL_THISCALL); } 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_IBEAM", CS_IBEAM); engine->RegisterEnumValue("CursorShape", "CS_CROSS", CS_CROSS); 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_RESIZE_ALL", CS_RESIZE_ALL); engine->RegisterEnumValue("CursorShape", "CS_ACCEPTDROP", CS_ACCEPTDROP); engine->RegisterEnumValue("CursorShape", "CS_REJECTDROP", CS_REJECTDROP); engine->RegisterEnumValue("CursorShape", "CS_BUSY", CS_BUSY); engine->RegisterEnumValue("CursorShape", "CS_BUSY_ARROW", CS_BUSY_ARROW); RegisterBorderImage(engine, "Cursor"); engine->RegisterObjectMethod("Cursor", "void DefineShape(const String&in, Texture@+, const IntRect&in, const IntVector2&in)", asMETHODPR(Cursor, DefineShape, (CursorShape, Image*, const IntRect&, const IntVector2&), void), asCALL_THISCALL); engine->RegisterObjectMethod("Cursor", "void DefineShape(CursorShape, Texture@+, const IntRect&in, const IntVector2&in)", asMETHODPR(Cursor, DefineShape, (const String&, Image*, const IntRect&, const IntVector2&), void), asCALL_THISCALL); engine->RegisterObjectMethod("Cursor", "void SetShape(const String&in)", asMETHODPR(Cursor, SetShape, (const String&), void), asCALL_THISCALL); engine->RegisterObjectMethod("Cursor", "void SetShape(CursorShape)", asMETHODPR(Cursor, SetShape, (CursorShape), void), asCALL_THISCALL); engine->RegisterObjectMethod("Cursor", "void set_shape(const String&in)", asMETHODPR(Cursor, SetShape, (const String&), void), asCALL_THISCALL); engine->RegisterObjectMethod("Cursor", "const String& 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