diff --git a/engine/includes/components/textrender.h b/engine/includes/components/textrender.h index f4195d5f9..bb6797581 100644 --- a/engine/includes/components/textrender.h +++ b/engine/includes/components/textrender.h @@ -55,8 +55,6 @@ class ENGINE_EXPORT TextRender : public Renderable { bool kerning() const; void setKerning(const bool kerning); - static Vector2 cursorPosition(Font *font, int size, const TString &text, bool kerning, const Vector2 &boundaries); - private: Mesh *meshToDraw(int instance) override; diff --git a/engine/includes/pipelinecontext.h b/engine/includes/pipelinecontext.h index 508c7cb25..69f22a13c 100644 --- a/engine/includes/pipelinecontext.h +++ b/engine/includes/pipelinecontext.h @@ -87,6 +87,8 @@ class ENGINE_EXPORT PipelineContext : public Object { static Mesh *defaultPlane(); static Mesh *defaultCube(); + static Texture *whiteTexture(); + private: void analizeGraph(); diff --git a/engine/includes/resources/font.h b/engine/includes/resources/font.h index f2e60aa7b..706d4fa46 100644 --- a/engine/includes/resources/font.h +++ b/engine/includes/resources/font.h @@ -42,7 +42,7 @@ class ENGINE_EXPORT Font : public Sprite { float lineHeight() const; - float cursorWidth() const; + float textWidth(const TString &text, int size, bool kerning); void composeMesh(Mesh *mesh, const TString &text, int size, int alignment, bool kerning, bool wrap, const Vector2 &boundaries); @@ -69,7 +69,6 @@ class ENGINE_EXPORT Font : public Sprite { float m_spaceWidth; float m_lineHeight; - float m_cursorWidth; bool m_useKerning; diff --git a/engine/src/components/component.cpp b/engine/src/components/component.cpp index bb52a5d04..86f17980b 100644 --- a/engine/src/components/component.cpp +++ b/engine/src/components/component.cpp @@ -44,6 +44,9 @@ Actor *Component::actor() const { Scene *Component::scene() const { return actor()->scene(); } +/*! + Returns a World which the Component is attached to. +*/ World *Component::world() const { Scene *scene = Component::scene(); if(scene) { diff --git a/engine/src/components/textrender.cpp b/engine/src/components/textrender.cpp index e42ad6324..466c505a8 100644 --- a/engine/src/components/textrender.cpp +++ b/engine/src/components/textrender.cpp @@ -240,69 +240,6 @@ AABBox TextRender::localBound() const { return Renderable::localBound(); } -/*! - \fn Vector2 TextRender::cursorPosition(Font *font, int size, const std::string &text, bool kerning, const Vector2 &boundaries) - - Returns the cursor position for rendering \a text with specified \a font and \a size. - Developer can also enable \a kerning and specify a \a boundaries for the text. -*/ -Vector2 TextRender::cursorPosition(Font *font, int size, const TString &text, bool kerning, const Vector2 &boundaries) { - if(font) { - float spaceWidth = font->spaceWidth() * size; - float spaceLine = font->lineHeight() * size; - float cursorMid = font->cursorWidth() * 0.5f * size; - - TString data = Engine::translate(text); - font->requestCharacters(data); - - Vector2 pos(0.0, boundaries.y - size); - - uint32_t length = font->length(data); - if(length) { - std::u32string u32 = data.toUtf32(); - - uint32_t previous = 0; - uint32_t it = 0; - - for(uint32_t i = 0; i < length; i++) { - uint32_t ch = u32[i]; - switch(ch) { - case ' ': { - pos += Vector2(spaceWidth, 0.0f); - } break; - case '\t': { - pos += Vector2(spaceWidth * 4, 0.0f); - } break; - case '\r': break; - case '\n': { - pos = Vector2(0.0f, pos.y - spaceLine); - } break; - default: { - if(kerning) { - pos.x += font->requestKerning(ch, previous); - } - uint32_t index = font->atlasIndex(ch); - - Mesh *glyph = font->shape(index); - if(glyph == nullptr) { - continue; - } - Vector3Vector &shape = glyph->vertices(); - - pos += Vector2(shape[2].x * size, 0.0f); - it++; - } break; - } - previous = ch; - } - } - pos.x -= cursorMid; - - return pos; - } - - return Vector2(); -} /*! \internal */ diff --git a/engine/src/editor/editorplatform.cpp b/engine/src/editor/editorplatform.cpp index 5a897f054..4be1ffb5b 100644 --- a/engine/src/editor/editorplatform.cpp +++ b/engine/src/editor/editorplatform.cpp @@ -146,8 +146,6 @@ EditorPlatform &EditorPlatform::instance() { static EditorPlatform *instance = nullptr; if(instance == nullptr) { instance = new EditorPlatform; - - Engine::setPlatformAdaptor(instance); } return *instance; diff --git a/engine/src/pipelinecontext.cpp b/engine/src/pipelinecontext.cpp index baee026b7..5f4e43602 100644 --- a/engine/src/pipelinecontext.cpp +++ b/engine/src/pipelinecontext.cpp @@ -311,6 +311,23 @@ Mesh *PipelineContext::defaultCube() { } return cube; } +/*! + Return the white texture used in rendering. +*/ +Texture *PipelineContext::whiteTexture() { + static Texture *white = nullptr; + if(white == nullptr) { + white = Engine::objectCreate("white"); + white->setFormat(Texture::RGBA8); + + Texture::Surface surface; + surface.push_back({255, 255, 255, 255}); + + white->addSurface(surface); + white->setDirty(); + } + return white; +} /*! Sets the rendering \a pipeline for the context, creating and linking associated rendering tasks. */ diff --git a/engine/src/resources/font.cpp b/engine/src/resources/font.cpp index 6f289aae0..2cc0f7967 100644 --- a/engine/src/resources/font.cpp +++ b/engine/src/resources/font.cpp @@ -107,7 +107,6 @@ Font::Font() : m_scale(DF_GLYPH_SIZE), m_spaceWidth(0.0f), m_lineHeight(0.0f), - m_cursorWidth(0.0f), m_useKerning(false) { FT_Init_FreeType( &library ); @@ -203,8 +202,7 @@ int Font::requestKerning(int glyph, int previous) const { Returns the number of \a characters in the string. */ int Font::length(const TString &characters) const { - std::u32string u32 = characters.toUtf32(); - return u32.length(); + return characters.toUtf32().length(); } /*! Returns visual width of space character for the font in world units. @@ -218,11 +216,50 @@ float Font::spaceWidth() const { float Font::lineHeight() const { return m_lineHeight; } -/*! - Returns visual width of the cursor for the font in world units. -*/ -float Font::cursorWidth() const { - return m_cursorWidth; + +float Font::textWidth(const TString &text, int size, bool kerning) { + TString data = Engine::translate(text); + requestCharacters(data); + + float pos = 0; + + uint32_t length = Font::length(data); + if(length) { + std::u32string u32 = data.toUtf32(); + + uint32_t previous = 0; + uint32_t it = 0; + + for(uint32_t i = 0; i < length; i++) { + uint32_t ch = u32[i]; + switch(ch) { + case ' ': { + pos += m_spaceWidth * size; + } break; + case '\t': { + pos += m_spaceWidth * size * 4; + } break; + default: { + if(kerning) { + pos += requestKerning(ch, previous); + } + uint32_t index = atlasIndex(ch); + + Mesh *glyph = shape(index); + if(glyph == nullptr) { + continue; + } + Vector3Vector &shape = glyph->vertices(); + + pos += shape[2].x * size; + it++; + } break; + } + previous = ch; + } + } + + return pos; } void Font::composeMesh(Mesh *mesh, const TString &text, int size, int alignment, bool kerning, bool wrap, const Vector2 &boundaries) { @@ -391,12 +428,6 @@ void Font::loadUserData(const VariantMap &data) { if(!error) { m_lineHeight = static_cast(face->glyph->metrics.height) / m_scale / 32.0f; } - - error = FT_Load_Glyph( face, FT_Get_Char_Index( face, '|' ), FT_LOAD_DEFAULT ); - if(!error) { - m_cursorWidth = static_cast(face->glyph->advance.x) / m_scale / 64.0f; - } - } } } diff --git a/modules/editor/grapheditor/editor/graph/graphcontroller.cpp b/modules/editor/grapheditor/editor/graph/graphcontroller.cpp index a4cd4afae..a22e3d91e 100644 --- a/modules/editor/grapheditor/editor/graph/graphcontroller.cpp +++ b/modules/editor/grapheditor/editor/graph/graphcontroller.cpp @@ -242,7 +242,7 @@ void GraphController::update() { Qt::CursorShape shape = Qt::ArrowCursor; for(auto node : m_graph->nodes()) { NodeWidget *widget = static_cast(node->widget()); - RectTransform *rect = widget->rectTransform(); + RectTransform *rect = widget->title()->rectTransform(); if(rect->isHovered(mousePosition.x, mousePosition.y)) { hovered = widget; } @@ -365,8 +365,10 @@ void GraphController::update() { } } - beginDrag(); - m_dragWidget = hovered; + if(Widget::focusWidget() == hovered) { + beginDrag(); + m_dragWidget = hovered; + } } else { m_view->rubberBand()->setEnabled(true); m_view->rubberBand()->raise(); diff --git a/modules/uikit/includes/components/abstractbutton.h b/modules/uikit/includes/components/abstractbutton.h index 7f05f19a3..a5af406b1 100644 --- a/modules/uikit/includes/components/abstractbutton.h +++ b/modules/uikit/includes/components/abstractbutton.h @@ -15,13 +15,10 @@ class UIKIT_EXPORT AbstractButton : public Widget { A_PROPERTY(bool, checkable, AbstractButton::isCheckable, AbstractButton::setCheckable), A_PROPERTY(bool, checked, AbstractButton::isChecked, AbstractButton::setChecked), A_PROPERTY(bool, exclusive, AbstractButton::isExclusive, AbstractButton::setExclusive), + A_PROPERTYEX(Vector4, color, AbstractButton::color, AbstractButton::setColor, "editor=Color"), A_PROPERTYEX(Frame *, background, AbstractButton::background, AbstractButton::setBackground, "editor=Component"), A_PROPERTYEX(Label *, label, AbstractButton::label, AbstractButton::setLabel, "editor=Component"), - A_PROPERTYEX(Image *, icon, AbstractButton::icon, AbstractButton::setIcon, "editor=Component"), - A_PROPERTY(float, fadeDuration, AbstractButton::fadeDuration, AbstractButton::setFadeDuration), - A_PROPERTYEX(Vector4, highlightedColor, AbstractButton::highlightedColor, AbstractButton::setHighlightedColor, "editor=Color"), - A_PROPERTYEX(Vector4, normalColor, AbstractButton::normalColor, AbstractButton::setNormalColor, "editor=Color"), - A_PROPERTYEX(Vector4, pressedColor, AbstractButton::pressedColor, AbstractButton::setPressedColor, "editor=Color") + A_PROPERTYEX(Image *, icon, AbstractButton::icon, AbstractButton::setIcon, "editor=Component") ) A_METHODS( A_SIGNAL(AbstractButton::pressed), @@ -45,19 +42,16 @@ class UIKIT_EXPORT AbstractButton : public Widget { void setIcon(Image *image); Vector2 iconSize() const; - void setIconSize(Vector2 size); + void setIconSize(const Vector2 &size); - float fadeDuration() const; - void setFadeDuration(float duration); + Vector4 color() const; + void setColor(const Vector4 &color); Vector4 highlightedColor() const; - void setHighlightedColor(const Vector4 color); - - Vector4 normalColor() const; - void setNormalColor(const Vector4 color); + void setHighlightedColor(const Vector4 &color); Vector4 pressedColor() const; - void setPressedColor(const Vector4 color); + void setPressedColor(const Vector4 &color); bool isCheckable() const; void setCheckable(bool checkable); @@ -71,6 +65,7 @@ class UIKIT_EXPORT AbstractButton : public Widget { bool isMirrored() const; virtual void setMirrored(bool mirrored); +public: // signals void pressed(); void clicked(); diff --git a/modules/uikit/includes/components/abstractslider.h b/modules/uikit/includes/components/abstractslider.h new file mode 100644 index 000000000..1f3f09088 --- /dev/null +++ b/modules/uikit/includes/components/abstractslider.h @@ -0,0 +1,74 @@ +#ifndef ABSTRACTSLIDER_H +#define ABSTRACTSLIDER_H + +#include "widget.h" + +class Frame; + +class UIKIT_EXPORT AbstractSlider : public Widget { + A_OBJECT(AbstractSlider, Widget, General) + + A_PROPERTIES( + A_PROPERTYEX(int, orientation, AbstractSlider::orientation, AbstractSlider::setOrientation, "enum=Orientation"), + A_PROPERTY(int, value, AbstractSlider::value, AbstractSlider::setValue), + A_PROPERTY(int, minimum, AbstractSlider::minimum, AbstractSlider::setMinimum), + A_PROPERTY(int, maximum, AbstractSlider::maximum, AbstractSlider::setMaximum), + A_PROPERTYEX(Widget *, knob, AbstractSlider::knob, AbstractSlider::setKnob, "editor=Component") + ) + A_METHODS( + A_SIGNAL(AbstractSlider::pressed), + A_SIGNAL(AbstractSlider::valueChanged) + ) + A_ENUMS( + A_ENUM(Orientation, + A_VALUE(Horizontal), + A_VALUE(Vertical) + ) + ) + +public: + enum Orientation { + Horizontal, + Vertical + }; + +public: + AbstractSlider(); + + int orientation() const; + virtual void setOrientation(int orientation); + + int value() const; + virtual void setValue(int value); + + int minimum() const; + virtual void setMinimum(int minimum); + + int maximum() const; + virtual void setMaximum(int maximum); + + Widget *knob() const; + void setKnob(Widget *handle); + +public: // signals + void pressed(); + + void valueChanged(int value); + +protected: + void update() override; + +protected: + int m_value; + int m_minimum; + int m_maximum; + + float m_currentFade; + + int m_orientation; + + bool m_hovered; + +}; + +#endif // ABSTRACTSLIDER_H diff --git a/modules/uikit/includes/components/floatinput.h b/modules/uikit/includes/components/floatinput.h index a902d813a..c448fc5df 100644 --- a/modules/uikit/includes/components/floatinput.h +++ b/modules/uikit/includes/components/floatinput.h @@ -3,7 +3,7 @@ #include "widget.h" -class TextInput; +class LineEdit; class Button; class UIKIT_EXPORT FloatInput : public Widget { @@ -17,7 +17,7 @@ class UIKIT_EXPORT FloatInput : public Widget { A_PROPERTY(Vector4, corners, FloatInput::corners, FloatInput::setCorners), A_PROPERTYEX(Button, increaseButton, FloatInput::increaseButton, FloatInput::setIncreaseButton, "editor=Component"), A_PROPERTYEX(Button, decreaseButton, FloatInput::decreaseButton, FloatInput::setDecreaseButton, "editor=Component"), - A_PROPERTYEX(TextInput, input, FloatInput::input, FloatInput::setInput, "editor=Component") + A_PROPERTYEX(LineEdit, input, FloatInput::input, FloatInput::setInput, "editor=Component") ) A_METHODS( A_SLOT(FloatInput::onIncrease), @@ -49,8 +49,8 @@ class UIKIT_EXPORT FloatInput : public Widget { Button *decreaseButton() const; void setDecreaseButton(Button *button); - TextInput *input() const; - void setInput(TextInput *input); + LineEdit *input() const; + void setInput(LineEdit *input); protected: // slots void onIncrease(); diff --git a/modules/uikit/includes/components/frame.h b/modules/uikit/includes/components/frame.h index a37adfe54..016f72898 100644 --- a/modules/uikit/includes/components/frame.h +++ b/modules/uikit/includes/components/frame.h @@ -24,24 +24,24 @@ class UIKIT_EXPORT Frame : public Widget { Frame(); Vector4 corners() const; - void setCorners(Vector4 corners); + void setCorners(const Vector4 &corners); Vector4 color() const; - void setColor(const Vector4 color); + void setColor(const Vector4 &color); Vector4 topColor() const; - void setTopColor(Vector4 color); + void setTopColor(const Vector4 &color); Vector4 rightColor() const; - void setRightColor(Vector4 color); + void setRightColor(const Vector4 &color); Vector4 bottomColor() const; - void setBottomColor(Vector4 color); + void setBottomColor(const Vector4 &color); Vector4 leftColor() const; - void setLeftColor(Vector4 color); + void setLeftColor(const Vector4 &color); - void setBorderColor(Vector4 color); + void setBorderColor(const Vector4 &color); protected: void boundChanged(const Vector2 &size) override; diff --git a/modules/uikit/includes/components/lineedit.h b/modules/uikit/includes/components/lineedit.h new file mode 100644 index 000000000..ff4fa18ec --- /dev/null +++ b/modules/uikit/includes/components/lineedit.h @@ -0,0 +1,80 @@ +#ifndef LINEEDIT_H +#define LINEEDIT_H + +#include "frame.h" + +class Label; + +class UIKIT_EXPORT LineEdit : public Frame { + A_OBJECT(LineEdit, Frame, Components/UI) + + A_PROPERTIES( + A_PROPERTY(TString, text, LineEdit::text, LineEdit::setText), + A_PROPERTYEX(Vector4, textColor, LineEdit::textColor, LineEdit::setTextColor, "editor=Color"), + A_PROPERTYEX(Label *, textComponent, LineEdit::textComponent, LineEdit::setTextComponent, "editor=Component") + ) + A_METHODS( + A_SIGNAL(LineEdit::focusIn), + A_SIGNAL(LineEdit::focusOut), + A_SIGNAL(LineEdit::editingFinished) + ) + A_NOENUMS() + +public: + LineEdit(); + + TString text() const; + void setText(const TString &text); + + Vector4 textColor() const; + void setTextColor(const Vector4 &color); + + Label *textComponent() const; + void setTextComponent(Label *label); + +public: // signals + void focusIn(); + void focusOut(); + + void editingFinished(); + +protected: + void update() override; + + void composeComponent() override; + + void recalcCursor(); + +private: + void drawSub(CommandBuffer &buffer) override; + +private: + TString m_text; + + Vector4 m_normalColor; + Vector4 m_highlightedColor; + Vector4 m_pressedColor; + + Vector4 m_textColor; + + Matrix4 m_cursorTransform; + + Mesh *m_cursor; + + MaterialInstance *m_cursorMaterial; + + int32_t m_cursorPosition; + + float m_fadeDuration; + float m_currentFade; + float m_cursorBlinkRate; + float m_cursorBlinkCurrent; + float m_cursorRepeatHold; + + bool m_hovered; + bool m_focused; + bool m_cursorVisible; + +}; + +#endif // LINEEDIT_H diff --git a/modules/uikit/includes/components/progressbar.h b/modules/uikit/includes/components/progressbar.h index 704fe32c1..4dda83b47 100644 --- a/modules/uikit/includes/components/progressbar.h +++ b/modules/uikit/includes/components/progressbar.h @@ -7,6 +7,7 @@ class UIKIT_EXPORT ProgressBar : public Widget { A_OBJECT(ProgressBar, Widget, Components/UI) A_PROPERTIES( + A_PROPERTYEX(int, orientation, ProgressBar::orientation, ProgressBar::setOrientation, "enum=Orientation"), A_PROPERTY(float, from, ProgressBar::from, ProgressBar::setFrom), A_PROPERTY(float, to, ProgressBar::to, ProgressBar::setTo), A_PROPERTY(float, value, ProgressBar::value, ProgressBar::setValue), @@ -16,11 +17,25 @@ class UIKIT_EXPORT ProgressBar : public Widget { A_PROPERTYEX(Frame *, chunk, ProgressBar::chunk, ProgressBar::setChunk, "editor=Component") ) A_NOMETHODS() - A_NOENUMS() + A_ENUMS( + A_ENUM(Orientation, + A_VALUE(Horizontal), + A_VALUE(Vertical) + ) + ) + +public: + enum Orientation { + Horizontal, + Vertical + }; public: ProgressBar(); + int orientation() const; + void setOrientation(int orientation); + float from() const; void setFrom(float value); @@ -51,6 +66,8 @@ class UIKIT_EXPORT ProgressBar : public Widget { Vector4 m_backgroundColor; Vector4 m_progressColor; + int m_orientation; + float m_from; float m_to; float m_value; diff --git a/modules/uikit/includes/components/recttransform.h b/modules/uikit/includes/components/recttransform.h index 65d8e6ba2..605494f1c 100644 --- a/modules/uikit/includes/components/recttransform.h +++ b/modules/uikit/includes/components/recttransform.h @@ -81,6 +81,8 @@ class UIKIT_EXPORT RectTransform : public Transform { Vector2 sizeHint() const; + Vector4 scissorArea() const; + private: friend class Layout; diff --git a/modules/uikit/includes/components/slider.h b/modules/uikit/includes/components/slider.h new file mode 100644 index 000000000..c2b01b15b --- /dev/null +++ b/modules/uikit/includes/components/slider.h @@ -0,0 +1,35 @@ +#ifndef SLIDER_H +#define SLIDER_H + +#include "abstractslider.h" + +class ProgressBar; + +class UIKIT_EXPORT Slider : public AbstractSlider { + A_OBJECT(Slider, AbstractSlider, Components/UI) + +public: + Slider(); + + ProgressBar *background() const; + void setBackground(ProgressBar *background); + + void setValue(int value) override; + void setMinimum(int value) override; + void setMaximum(int value) override; + + void setOrientation(int value) override; + +private: + void update() override; + + void composeComponent() override; + +private: + Vector4 m_normalColor; + + Vector4 m_highlightedColor; + +}; + +#endif // SLIDER_H diff --git a/modules/uikit/includes/components/textinput.h b/modules/uikit/includes/components/textinput.h deleted file mode 100644 index 41101e4cf..000000000 --- a/modules/uikit/includes/components/textinput.h +++ /dev/null @@ -1,87 +0,0 @@ -#ifndef TEXTINPUT_H -#define TEXTINPUT_H - -#include "widget.h" - -class Label; -class Frame; - -class UIKIT_EXPORT TextInput : public Widget { - A_OBJECT(TextInput, Widget, Components/UI) - - A_PROPERTIES( - A_PROPERTY(TString, text, TextInput::text, TextInput::setText), - A_PROPERTYEX(Vector4, textColor, TextInput::textColor, TextInput::setTextColor, "editor=Color"), - A_PROPERTYEX(Vector4, backgroundColor, TextInput::backgroundColor, TextInput::setBackgroundColor, "editor=Color"), - A_PROPERTYEX(Vector4, hoverColor, TextInput::hoverColor, TextInput::setHoverColor, "editor=Color"), - A_PROPERTYEX(Vector4, pressedColor, TextInput::pressedColor, TextInput::setPressedColor, "editor=Color"), - A_PROPERTYEX(Label *, textComponent, TextInput::textComponent, TextInput::setTextComponent, "editor=Component"), - A_PROPERTYEX(Frame *, background, TextInput::background, TextInput::setBackground, "editor=Component") - ) - A_METHODS( - A_SIGNAL(TextInput::focusIn), - A_SIGNAL(TextInput::focusOut), - A_SIGNAL(TextInput::editingFinished) - ) - A_NOENUMS() - -public: - TextInput(); - - TString text() const; - void setText(const TString text); - - Vector4 textColor() const; - void setTextColor(Vector4 color); - - Vector4 backgroundColor() const; - void setBackgroundColor(Vector4 color); - - Vector4 hoverColor() const; - void setHoverColor(Vector4 color); - - Vector4 pressedColor() const; - void setPressedColor(Vector4 color); - - Frame *background() const; - void setBackground(Frame *frame); - - Label *textComponent() const; - void setTextComponent(Label *label); - - Label *textCursor() const; - void setTextCursor(Label *cursor); - -public: // signals - void focusIn(); - void focusOut(); - - void editingFinished(); - -protected: - void update() override; - - void composeComponent() override; - - void recalcCursor(); - -private: - Vector4 m_normalColor; - Vector4 m_highlightedColor; - Vector4 m_pressedColor; - - Vector4 m_textColor; - - int32_t m_cursorPosition; - - float m_fadeDuration; - float m_currentFade; - float m_cursorBlinkRate; - float m_cursorBlinkCurrent; - - bool m_hovered; - bool m_focused; - -}; - -#endif // TEXTINPUT_H diff --git a/modules/uikit/includes/components/widget.h b/modules/uikit/includes/components/widget.h index aae0db427..0a9818f89 100644 --- a/modules/uikit/includes/components/widget.h +++ b/modules/uikit/includes/components/widget.h @@ -28,7 +28,7 @@ class UIKIT_EXPORT Widget : public NativeBehaviour { void addClass(const TString &name); Widget *parentWidget() const; - std::list childWidgets() const; + std::list &childWidgets(); RectTransform *rectTransform() const; @@ -44,6 +44,8 @@ class UIKIT_EXPORT Widget : public NativeBehaviour { protected: virtual void draw(CommandBuffer &buffer); + virtual void drawSub(CommandBuffer &buffer); + virtual void boundChanged(const Vector2 &size); virtual void applyStyle(); @@ -63,7 +65,7 @@ class UIKIT_EXPORT Widget : public NativeBehaviour { Vector4 styleBlock4Length(const TString &property, const Vector4 &value, bool &pixels); Widget *subWidget(const TString &name) const; - void setSubWidget(const TString &name, Widget *widget); + void setSubWidget(Widget *widget); static void setFocusWidget(Widget *widget); @@ -75,7 +77,9 @@ class UIKIT_EXPORT Widget : public NativeBehaviour { protected: std::map> m_styleRules; - std::map m_subWidgets; + std::list m_subWidgets; + + std::list m_childWidgets; private: friend class GuiLayer; diff --git a/modules/uikit/src/components/abstractbutton.cpp b/modules/uikit/src/components/abstractbutton.cpp index ede5897ff..e18941a19 100644 --- a/modules/uikit/src/components/abstractbutton.cpp +++ b/modules/uikit/src/components/abstractbutton.cpp @@ -14,7 +14,7 @@ #include #include -namespace { +namespace { const char *gBackground("background"); const char *gLabel("label"); const char *gIcon("icon"); @@ -24,6 +24,7 @@ namespace { const char *gLabelClass("Label"); const float gCorner = 4.0f; + const float gFadeDuration = 0.2f; } /*! \class AbstractButton @@ -42,7 +43,6 @@ AbstractButton::AbstractButton() : m_pressedColor(Vector4(0.7f, 0.7f, 0.7f, 1.0f)), m_textColor(Vector4(1.0f, 1.0f, 1.0f, 1.0f)), m_iconSize(16.0f), - m_fadeDuration(0.2f), m_currentFade(1.0f), m_hovered(false), m_mirrored(false), @@ -80,7 +80,7 @@ Frame *AbstractButton::background() const { Sets the background \a frame of the button. */ void AbstractButton::setBackground(Frame *frame) { - setSubWidget(gBackground, frame); + setSubWidget(frame); if(frame) { frame->setColor(m_normalColor); @@ -96,7 +96,7 @@ Label *AbstractButton::label() const { Sets the \a label associated with the button. */ void AbstractButton::setLabel(Label *label) { - setSubWidget(gLabel, label); + setSubWidget(label); } /*! Returns the icon associated with the button. @@ -108,7 +108,7 @@ Image *AbstractButton::icon() const { Sets the icon \a image associated with the button. */ void AbstractButton::setIcon(Image *image) { - setSubWidget(gIcon, image); + setSubWidget(image); if(image) { RectTransform *rect = image->rectTransform(); @@ -127,7 +127,7 @@ Vector2 AbstractButton::iconSize() const { /*! Sets the \a size of the icon. */ -void AbstractButton::setIconSize(Vector2 size) { +void AbstractButton::setIconSize(const Vector2 &size) { m_iconSize = size; Image *img = icon(); if(img) { @@ -135,16 +135,20 @@ void AbstractButton::setIconSize(Vector2 size) { } } /*! - Returns the fade duration used for visual effects. + Returns the normal color of the button. */ -float AbstractButton::fadeDuration() const { - return m_fadeDuration; +Vector4 AbstractButton::color() const { + return m_normalColor; } /*! - Sets the fade \a duration used for visual effects. + Sets the normal \a color of the button. */ -void AbstractButton::setFadeDuration(float duration) { - m_fadeDuration = duration; +void AbstractButton::setColor(const Vector4 &color) { + m_normalColor = color; + Frame *back = background(); + if(back) { + back->setColor(m_normalColor); + } } /*! Returns the color used when the button is highlighted. @@ -155,25 +159,9 @@ Vector4 AbstractButton::highlightedColor() const { /*! Sets the \a color used when the button is highlighted. */ -void AbstractButton::setHighlightedColor(const Vector4 color) { +void AbstractButton::setHighlightedColor(const Vector4 &color) { m_highlightedColor = color; } -/*! - Returns the normal color of the button. -*/ -Vector4 AbstractButton::normalColor() const { - return m_normalColor; -} -/*! - Sets the normal \a color of the button. -*/ -void AbstractButton::setNormalColor(const Vector4 color) { - m_normalColor = color; - Frame *back = background(); - if(back) { - back->setColor(m_normalColor); - } -} /*! Returns the color used when the button is pressed. */ @@ -183,7 +171,7 @@ Vector4 AbstractButton::pressedColor() const { /*! Sets the \a color used when the button is pressed. */ -void AbstractButton::setPressedColor(const Vector4 color) { +void AbstractButton::setPressedColor(const Vector4 &color) { m_pressedColor = color; } /*! @@ -298,7 +286,7 @@ void AbstractButton::applyStyle() { // Background color auto it = m_styleRules.find("background-color"); if(it != m_styleRules.end()) { - setNormalColor(StyleSheet::toColor(it->second.second)); + setColor(StyleSheet::toColor(it->second.second)); } } /*! @@ -326,14 +314,14 @@ void AbstractButton::composeComponent() { Widget::composeComponent(); // Add background - Actor *background = Engine::composeActor(gFrameClass, "Background", actor()); + Actor *background = Engine::composeActor(gFrameClass, gBackground, actor()); Frame *frame = background->getComponent(); frame->setCorners(Vector4(gCorner)); setBackground(frame); // Add label - Actor *text = Engine::composeActor(gLabelClass, gLabelClass, actor()); + Actor *text = Engine::composeActor(gLabelClass, gLabel, actor()); Label *label = text->getComponent