diff --git a/src/kekengine/cpp/ui/uielements.cpp b/src/kekengine/cpp/ui/uielements.cpp index 6a875f5..3e518e7 100644 --- a/src/kekengine/cpp/ui/uielements.cpp +++ b/src/kekengine/cpp/ui/uielements.cpp @@ -90,21 +90,6 @@ void TextElement::draw(UIPoint screenPos, glm::mat4 projection) { } } -UIWindow::UIWindow(UIValue x, UIValue y) - : UIElement(x, y) { - addChild(new TextElement(x, y)); -} - -UIWindow::~UIWindow() { -} - -UIElementType UIWindow::getType() { - return UIElementType::WINDOW; -} - -void UIWindow::draw(UIPoint screenPos, glm::mat4 projection) { -} - static float rectangleVerts[] = { 0.0f, 1.0f, @@ -345,4 +330,62 @@ void TextFieldElement::setText(std::string text) { this->cursorPos = 0; updateText(Unicode::convertStdToU32(text)); } + +UIWindowTitleBar::UIWindowTitleBar(UIValue height) + : RectangleElement(uiPx(0), uiPx(0), uiPw(1), height) { + this->color = Colors::GRAY; + this->draggable = true; + + text = new TextElement(x, uiPh(0.5)); + text->setText("Window title"); + text->textMode = TextMode::ORIGIN; + text->origin = Origin::LEFT_CENTER; + addChild(text); + + closeButton = new ButtonElement(uiPw(1) - uiPx(30), uiPx(0), uiPx(30), uiPh(1)); + closeButton->text->setText("X"); + closeButton->color = Colors::RED; + closeButton->hoverColor = Colors::RED.darker(); + addChild(closeButton); +} + +void UIWindowTitleBar::dragEnter(UIPoint pos, UIPoint screenPos) { + // TODO +} + +void UIWindowTitleBar::drag(UIPoint pos, UIPoint screenPos) { + // TODO +} + +void UIWindowTitleBar::dragExit(UIPoint pos, UIPoint screenPos) { + // TODO +} + +UIWindow::UIWindow(UIValue x, UIValue y, UIValue w, UIValue h) + : UIElement(x, y) { + this->w = w; + this->h = h; + + this->background = new RectangleElement(x, y, w, h); + background->color = Colors::GRAY.darker(); + addChild(background); + + this->titleBar = new UIWindowTitleBar(uiPx(25)); + addChild(titleBar); +} + +UIWindow::~UIWindow() { +} + +UIElementType UIWindow::getType() { + return UIElementType::WINDOW; +} + +UIBounds UIWindow::getBounds() { + return offsetUIBounds(uiToScreen(w), uiToScreen(h), origin); +} + +void UIWindow::draw(UIPoint screenPos, glm::mat4 projection) { +} + } diff --git a/src/kekengine/include/uielements.h b/src/kekengine/include/uielements.h index 5f704ba..c4f2799 100644 --- a/src/kekengine/include/uielements.h +++ b/src/kekengine/include/uielements.h @@ -6,17 +6,6 @@ namespace kek { -class UIWindow: public UIElement { - - UIWindow(UIValue x, UIValue y); - - virtual ~UIWindow(); - - virtual UIElementType getType(); - - virtual void draw(UIPoint screenPos, glm::mat4 projection); -}; - enum class TextMode { // Draw with y as baseline, disables vertical offset from the origin position specified using setOrigin() BASELINE, @@ -135,4 +124,36 @@ class TextFieldElement: public RectangleElement { void setText(std::string text); }; +class UIWindowTitleBar: public RectangleElement { + + public: + TextElement *text; + ButtonElement *closeButton; + + UIWindowTitleBar(UIValue height); + + virtual void dragEnter(UIPoint pos, UIPoint screenPos); + virtual void drag(UIPoint pos, UIPoint screenPos); + virtual void dragExit(UIPoint pos, UIPoint screenPos); +}; + +class UIWindow: public UIElement { + + public: + RectangleElement *background; + UIWindowTitleBar *titleBar; + + UIValue w, h; + + UIWindow(UIValue x, UIValue y, UIValue w, UIValue h); + + virtual ~UIWindow(); + + virtual UIElementType getType(); + + virtual UIBounds getBounds(); + + virtual void draw(UIPoint screenPos, glm::mat4 projection); +}; + } diff --git a/src/kekgame/cpp/kekgame.cpp b/src/kekgame/cpp/kekgame.cpp index c1f75a9..32d1736 100644 --- a/src/kekgame/cpp/kekgame.cpp +++ b/src/kekgame/cpp/kekgame.cpp @@ -172,6 +172,9 @@ int main(int argc, char **argv) { rect2->addChild(box); rect2->addChild(text); + UIWindow *window = new UIWindow(uiPx(0), uiPx(0), uiPx(720), uiPx(480)); + UI::addElement(window); + if(Engine::start() != KEK_SUCCESS) return 1; return 0; }