master
Eduardo Bart 13 years ago
parent 3c72c844d2
commit d31d32bf82

@ -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)

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

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

@ -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);

@ -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);

@ -8,23 +8,30 @@ 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);
for(const OTMLNodePtr& node : styleNode->children()) {
if(node->tag() == "text")
setText(node->value());
else if(node->tag() == "align")
setAlign(fw::translateAlignment(styleNode->value()));
}
}
void UILabel::render()
{
UIWidget::render();
m_font->renderText(m_text, m_rect, m_align, m_foregroundColor);
}
if(styleNode->hasChildAt("align"))
m_align = fw::translateAlignment(styleNode->valueAt("align"));
void UILabel::setText(const std::string& text)
{
m_text = text;
// auto resize if needed
if(!m_text.empty() && !m_rect.isValid()) {
// 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());
@ -33,12 +40,6 @@ void UILabel::onStyleApply(const OTMLNodePtr& styleNode)
}
}
void UILabel::render()
{
UIWidget::render();
m_font->renderText(m_text, m_rect, m_align, m_foregroundColor);
}
void UILabel::resizeToText()
{
resize(m_font->calculateTextRectSize(m_text));

@ -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; }

@ -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

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

@ -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<UIListItem> m_items;
std::deque<UIListItem> m_items;
};
#endif

@ -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)

@ -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") {

Loading…
Cancel
Save