changes..

This commit is contained in:
Eduardo Bart 2011-08-23 12:09:50 -03:00
parent 3c72c844d2
commit d31d32bf82
12 changed files with 45 additions and 52 deletions

View File

@ -130,6 +130,7 @@ SET(SOURCES
src/framework/ui/uiwindow.cpp src/framework/ui/uiwindow.cpp
src/framework/ui/uianchor.cpp src/framework/ui/uianchor.cpp
src/framework/ui/uilist.cpp src/framework/ui/uilist.cpp
#src/framework/ui/uianchorable.cpp
) )
IF(WIN32) IF(WIN32)

View File

@ -14,5 +14,6 @@ Module
importStyles('separators.otui') importStyles('separators.otui')
importStyles('lineedits.otui') importStyles('lineedits.otui')
importStyles('windows.otui') importStyles('windows.otui')
importStyles('listboxes.otui')
return true return true

View File

@ -335,15 +335,15 @@ void Platform::poll()
) { ) {
//logDebug("char: ", buf[0], " code: ", (uint)buf[0]); //logDebug("char: ", buf[0], " code: ", (uint)buf[0]);
inputEvent.keychar = buf[0]; inputEvent.keychar = buf[0];
dump << int((uchar)buf[0]);
} }
} } else {
//event.xkey.state &= ~(ShiftMask | LockMask);
// unmask Shift/Lock to get expected results
event.xkey.state &= ~(ShiftMask | LockMask);
len = XLookupString(&event.xkey, buf, sizeof(buf), &keysym, 0); len = XLookupString(&event.xkey, buf, sizeof(buf), &keysym, 0);
if(inputEvent.keychar == 0) if(len > 0 && (uchar)inputEvent.keychar >= 32)
inputEvent.keychar = (len > 0) ? buf[0] : 0; inputEvent.keychar = (len > 0) ? buf[0] : 0;
}
if(x11.keyMap.find(keysym) != x11.keyMap.end()) if(x11.keyMap.find(keysym) != x11.keyMap.end())
inputEvent.keycode = x11.keyMap[keysym]; inputEvent.keycode = x11.keyMap[keysym];

View File

@ -14,12 +14,6 @@ UIButton::UIButton()
m_onClick = [this]() { this->callLuaField("onClick"); }; m_onClick = [this]() { this->callLuaField("onClick"); };
} }
UIButtonPtr UIButton::create()
{
UIButtonPtr button(new UIButton);
return button;
}
void UIButton::onStyleApply(const OTMLNodePtr& styleNode) void UIButton::onStyleApply(const OTMLNodePtr& styleNode)
{ {
UIWidget::onStyleApply(styleNode); UIWidget::onStyleApply(styleNode);

View File

@ -21,7 +21,7 @@ class UIButton : public UIWidget
public: public:
UIButton(); UIButton();
static UIButtonPtr create(); static UIButtonPtr create() { return UIButtonPtr(new UIButton); }
virtual void onStyleApply(const OTMLNodePtr& styleNode); virtual void onStyleApply(const OTMLNodePtr& styleNode);
void loadStateStyle(ButtonStateStyle& stateStyle, const OTMLNodePtr& stateStyleNode); void loadStateStyle(ButtonStateStyle& stateStyle, const OTMLNodePtr& stateStyleNode);

View File

@ -8,28 +8,15 @@ UILabel::UILabel()
m_focusable = false; m_focusable = false;
} }
UILabelPtr UILabel::create()
{
UILabelPtr label(new UILabel);
return label;
}
void UILabel::onStyleApply(const OTMLNodePtr& styleNode) void UILabel::onStyleApply(const OTMLNodePtr& styleNode)
{ {
UIWidget::onStyleApply(styleNode); UIWidget::onStyleApply(styleNode);
m_text = styleNode->valueAt("text", m_text); for(const OTMLNodePtr& node : styleNode->children()) {
if(node->tag() == "text")
if(styleNode->hasChildAt("align")) setText(node->value());
m_align = fw::translateAlignment(styleNode->valueAt("align")); else if(node->tag() == "align")
setAlign(fw::translateAlignment(styleNode->value()));
// 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());
} }
} }
@ -39,6 +26,20 @@ void UILabel::render()
m_font->renderText(m_text, m_rect, m_align, m_foregroundColor); 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() void UILabel::resizeToText()
{ {
resize(m_font->calculateTextRectSize(m_text)); resize(m_font->calculateTextRectSize(m_text));

View File

@ -8,14 +8,14 @@ class UILabel : public UIWidget
public: public:
UILabel(); UILabel();
static UILabelPtr create(); static UILabelPtr create() { return UILabelPtr(new UILabel); }
virtual void onStyleApply(const OTMLNodePtr& styleNode); virtual void onStyleApply(const OTMLNodePtr& styleNode);
virtual void render(); virtual void render();
void resizeToText(); void resizeToText();
void setText(const std::string& text) { m_text = text; } void setText(const std::string& text);
void setAlign(AlignmentFlag align) { m_align = align; } void setAlign(AlignmentFlag align) { m_align = align; }
std::string getText() const { return m_text; } std::string getText() const { return m_text; }

View File

@ -15,19 +15,10 @@ UILineEdit::UILineEdit()
m_onAction = [this]() { this->callLuaField("onAction"); }; m_onAction = [this]() { this->callLuaField("onAction"); };
} }
UILineEditPtr UILineEdit::create()
{
UILineEditPtr lineEdit(new UILineEdit);
return lineEdit;
}
void UILineEdit::render() void UILineEdit::render()
{ {
UIWidget::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 //TODO: text rendering could be much optimized by using vertex buffer or caching the render into a texture
int textLength = m_text.length(); int textLength = m_text.length();
@ -39,8 +30,8 @@ void UILineEdit::render()
// render cursor // render cursor
if(isExplicitlyEnabled() && hasFocus() && m_cursorPos >= 0) { if(isExplicitlyEnabled() && hasFocus() && m_cursorPos >= 0) {
assert(m_cursorPos <= textLength); assert(m_cursorPos <= textLength);
// draw every 330ms // draw every 333ms
const int delay = 330; const int delay = 333;
int ticks = g_platform.getTicks(); int ticks = g_platform.getTicks();
if(ticks - m_cursorTicks <= delay) { if(ticks - m_cursorTicks <= delay) {
Rect cursorRect; Rect cursorRect;
@ -61,7 +52,7 @@ void UILineEdit::update()
int textLength = m_text.length(); int textLength = m_text.length();
// prevent glitches // prevent glitches
if(!m_rect.isValid()) if(m_rect.isEmpty())
return; return;
// map glyphs positions // map glyphs positions

View File

@ -8,7 +8,7 @@ class UILineEdit : public UIWidget
public: public:
UILineEdit(); UILineEdit();
static UILineEditPtr create(); static UILineEditPtr create() { return UILineEditPtr(new UILineEdit); }
virtual void render(); virtual void render();

View File

@ -20,6 +20,12 @@ public:
private: private:
std::string m_text; std::string m_text;
boost::any m_data; boost::any m_data;
int height;
/*
Image m_image;
Color m_backgroundColor;
Color m_foregroundColor;
*/
}; };
class UIList : public UIWidget class UIList : public UIWidget
@ -62,7 +68,7 @@ protected:
//onCurrentTextChange //onCurrentTextChange
//onItemClicked //onItemClicked
std::list<UIListItem> m_items; std::deque<UIListItem> m_items;
}; };
#endif #endif

View File

@ -30,7 +30,7 @@ void UIManager::render()
void UIManager::resize(const Size& size) void UIManager::resize(const Size& size)
{ {
if(m_rootWidget) if(m_rootWidget)
m_rootWidget->resize(size); m_rootWidget->resize(g_graphics.getScreenSize());
} }
void UIManager::inputEvent(const PlatformEvent& event) void UIManager::inputEvent(const PlatformEvent& event)

View File

@ -104,7 +104,8 @@ void UIWidget::render()
// draw children // draw children
for(const UIWidgetPtr& child : m_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 // store current graphics opacity
int oldOpacity = g_graphics.getOpacity(); int oldOpacity = g_graphics.getOpacity();
@ -112,7 +113,6 @@ void UIWidget::render()
if(child->getOpacity() < oldOpacity) if(child->getOpacity() < oldOpacity)
g_graphics.setOpacity(child->getOpacity()); g_graphics.setOpacity(child->getOpacity());
// bind child color
child->render(); child->render();
// debug draw box // debug draw box
@ -810,7 +810,6 @@ void UIWidget::onStyleApply(const OTMLNodePtr& styleNode)
// id // id
if(node->tag() == "id") { if(node->tag() == "id") {
setId(node->value()); setId(node->value());
//logTraceDebug(m_id);
} }
// background image // background image
else if(node->tag() == "image") { else if(node->tag() == "image") {