diff --git a/CMakeLists.txt b/CMakeLists.txt index 6710b2e9..eecc3423 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -130,6 +130,7 @@ SET(SOURCES src/framework/ui/uiwindow.cpp src/framework/ui/uianchor.cpp src/framework/ui/uilist.cpp + #src/framework/ui/uianchorable.cpp ) IF(WIN32) diff --git a/modules/core_ui/core_ui.otmod b/modules/core_ui/core_ui.otmod index 818c8c32..ca794f1f 100644 --- a/modules/core_ui/core_ui.otmod +++ b/modules/core_ui/core_ui.otmod @@ -14,5 +14,6 @@ Module importStyles('separators.otui') importStyles('lineedits.otui') importStyles('windows.otui') + importStyles('listboxes.otui') return true diff --git a/src/framework/platform/x11platform.cpp b/src/framework/platform/x11platform.cpp index 365cccf5..203f7e5b 100644 --- a/src/framework/platform/x11platform.cpp +++ b/src/framework/platform/x11platform.cpp @@ -335,16 +335,16 @@ void Platform::poll() ) { //logDebug("char: ", buf[0], " code: ", (uint)buf[0]); inputEvent.keychar = buf[0]; + dump << int((uchar)buf[0]); } + } else { + //event.xkey.state &= ~(ShiftMask | LockMask); + len = XLookupString(&event.xkey, buf, sizeof(buf), &keysym, 0); + + if(len > 0 && (uchar)inputEvent.keychar >= 32) + inputEvent.keychar = (len > 0) ? buf[0] : 0; } - // unmask Shift/Lock to get expected results - event.xkey.state &= ~(ShiftMask | LockMask); - len = XLookupString(&event.xkey, buf, sizeof(buf), &keysym, 0); - - if(inputEvent.keychar == 0) - inputEvent.keychar = (len > 0) ? buf[0] : 0; - if(x11.keyMap.find(keysym) != x11.keyMap.end()) inputEvent.keycode = x11.keyMap[keysym]; else diff --git a/src/framework/ui/uibutton.cpp b/src/framework/ui/uibutton.cpp index 48cd3426..3111339e 100644 --- a/src/framework/ui/uibutton.cpp +++ b/src/framework/ui/uibutton.cpp @@ -14,12 +14,6 @@ UIButton::UIButton() m_onClick = [this]() { this->callLuaField("onClick"); }; } -UIButtonPtr UIButton::create() -{ - UIButtonPtr button(new UIButton); - return button; -} - void UIButton::onStyleApply(const OTMLNodePtr& styleNode) { UIWidget::onStyleApply(styleNode); diff --git a/src/framework/ui/uibutton.h b/src/framework/ui/uibutton.h index 56e3c3da..13fe9beb 100644 --- a/src/framework/ui/uibutton.h +++ b/src/framework/ui/uibutton.h @@ -21,7 +21,7 @@ class UIButton : public UIWidget public: UIButton(); - static UIButtonPtr create(); + static UIButtonPtr create() { return UIButtonPtr(new UIButton); } virtual void onStyleApply(const OTMLNodePtr& styleNode); void loadStateStyle(ButtonStateStyle& stateStyle, const OTMLNodePtr& stateStyleNode); diff --git a/src/framework/ui/uilabel.cpp b/src/framework/ui/uilabel.cpp index c1dd88df..ffa1f945 100644 --- a/src/framework/ui/uilabel.cpp +++ b/src/framework/ui/uilabel.cpp @@ -8,28 +8,15 @@ UILabel::UILabel() m_focusable = false; } -UILabelPtr UILabel::create() -{ - UILabelPtr label(new UILabel); - return label; -} - void UILabel::onStyleApply(const OTMLNodePtr& styleNode) { UIWidget::onStyleApply(styleNode); - m_text = styleNode->valueAt("text", m_text); - - if(styleNode->hasChildAt("align")) - m_align = fw::translateAlignment(styleNode->valueAt("align")); - - // auto resize if needed - if(!m_text.empty() && !m_rect.isValid()) { - Size textSize = m_font->calculateTextRectSize(m_text); - if(m_rect.width() <= 0) - m_rect.setWidth(textSize.width()); - if(m_rect.height() <= 0) - m_rect.setHeight(textSize.height()); + for(const OTMLNodePtr& node : styleNode->children()) { + if(node->tag() == "text") + setText(node->value()); + else if(node->tag() == "align") + setAlign(fw::translateAlignment(styleNode->value())); } } @@ -39,6 +26,20 @@ void UILabel::render() m_font->renderText(m_text, m_rect, m_align, m_foregroundColor); } +void UILabel::setText(const std::string& text) +{ + m_text = text; + + // auto resize if the current rect is invalid + if(!m_rect.isValid()) { + Size textSize = m_font->calculateTextRectSize(m_text); + if(m_rect.width() <= 0) + m_rect.setWidth(textSize.width()); + if(m_rect.height() <= 0) + m_rect.setHeight(textSize.height()); + } +} + void UILabel::resizeToText() { resize(m_font->calculateTextRectSize(m_text)); diff --git a/src/framework/ui/uilabel.h b/src/framework/ui/uilabel.h index 9da251d9..9c96a63c 100644 --- a/src/framework/ui/uilabel.h +++ b/src/framework/ui/uilabel.h @@ -8,14 +8,14 @@ class UILabel : public UIWidget public: UILabel(); - static UILabelPtr create(); + static UILabelPtr create() { return UILabelPtr(new UILabel); } virtual void onStyleApply(const OTMLNodePtr& styleNode); virtual void render(); void resizeToText(); - void setText(const std::string& text) { m_text = text; } + void setText(const std::string& text); void setAlign(AlignmentFlag align) { m_align = align; } std::string getText() const { return m_text; } diff --git a/src/framework/ui/uilineedit.cpp b/src/framework/ui/uilineedit.cpp index f7b9135c..830b60a5 100644 --- a/src/framework/ui/uilineedit.cpp +++ b/src/framework/ui/uilineedit.cpp @@ -15,19 +15,10 @@ UILineEdit::UILineEdit() m_onAction = [this]() { this->callLuaField("onAction"); }; } -UILineEditPtr UILineEdit::create() -{ - UILineEditPtr lineEdit(new UILineEdit); - return lineEdit; -} - void UILineEdit::render() { UIWidget::render(); - if(!m_rect.isValid()) - return; - //TODO: text rendering could be much optimized by using vertex buffer or caching the render into a texture int textLength = m_text.length(); @@ -39,8 +30,8 @@ void UILineEdit::render() // render cursor if(isExplicitlyEnabled() && hasFocus() && m_cursorPos >= 0) { assert(m_cursorPos <= textLength); - // draw every 330ms - const int delay = 330; + // draw every 333ms + const int delay = 333; int ticks = g_platform.getTicks(); if(ticks - m_cursorTicks <= delay) { Rect cursorRect; @@ -61,7 +52,7 @@ void UILineEdit::update() int textLength = m_text.length(); // prevent glitches - if(!m_rect.isValid()) + if(m_rect.isEmpty()) return; // map glyphs positions diff --git a/src/framework/ui/uilineedit.h b/src/framework/ui/uilineedit.h index 75617e8e..6f5ea135 100644 --- a/src/framework/ui/uilineedit.h +++ b/src/framework/ui/uilineedit.h @@ -8,7 +8,7 @@ class UILineEdit : public UIWidget public: UILineEdit(); - static UILineEditPtr create(); + static UILineEditPtr create() { return UILineEditPtr(new UILineEdit); } virtual void render(); diff --git a/src/framework/ui/uilist.h b/src/framework/ui/uilist.h index ad4d6653..3d4c8a4e 100644 --- a/src/framework/ui/uilist.h +++ b/src/framework/ui/uilist.h @@ -20,6 +20,12 @@ public: private: std::string m_text; boost::any m_data; + int height; + /* + Image m_image; + Color m_backgroundColor; + Color m_foregroundColor; + */ }; class UIList : public UIWidget @@ -62,7 +68,7 @@ protected: //onCurrentTextChange //onItemClicked - std::list m_items; + std::deque m_items; }; #endif diff --git a/src/framework/ui/uimanager.cpp b/src/framework/ui/uimanager.cpp index d845d61f..7a2c0e1b 100644 --- a/src/framework/ui/uimanager.cpp +++ b/src/framework/ui/uimanager.cpp @@ -30,7 +30,7 @@ void UIManager::render() void UIManager::resize(const Size& size) { if(m_rootWidget) - m_rootWidget->resize(size); + m_rootWidget->resize(g_graphics.getScreenSize()); } void UIManager::inputEvent(const PlatformEvent& event) diff --git a/src/framework/ui/uiwidget.cpp b/src/framework/ui/uiwidget.cpp index 4e70c968..b51b85e5 100644 --- a/src/framework/ui/uiwidget.cpp +++ b/src/framework/ui/uiwidget.cpp @@ -104,7 +104,8 @@ void UIWidget::render() // draw children for(const UIWidgetPtr& child : m_children) { - if(child->isExplicitlyVisible()) { + // render only visible children with a valid rect + if(child->isExplicitlyVisible() && child->getRect().isValid()) { // store current graphics opacity int oldOpacity = g_graphics.getOpacity(); @@ -112,7 +113,6 @@ void UIWidget::render() if(child->getOpacity() < oldOpacity) g_graphics.setOpacity(child->getOpacity()); - // bind child color child->render(); // debug draw box @@ -810,7 +810,6 @@ void UIWidget::onStyleApply(const OTMLNodePtr& styleNode) // id if(node->tag() == "id") { setId(node->value()); - //logTraceDebug(m_id); } // background image else if(node->tag() == "image") {