mirror of
https://github.com/edubart/otclient.git
synced 2025-10-19 05:53:26 +02:00
fixed ratio image drawing support
This commit is contained in:
@@ -31,7 +31,7 @@ UILineEdit::UILineEdit()
|
||||
m_align = Fw::AlignLeftCenter;
|
||||
m_cursorPos = 0;
|
||||
m_startRenderPos = 0;
|
||||
m_textHorizontalMargin = 3;
|
||||
m_textHorizontalMargin = 0;
|
||||
m_textHidden = false;
|
||||
blinkCursor();
|
||||
}
|
||||
@@ -381,6 +381,8 @@ void UILineEdit::onStyleApply(const OTMLNodePtr& styleNode)
|
||||
setCursorPos(m_text.length());
|
||||
} else if(node->tag() == "text hidden") {
|
||||
setTextHidden(node->value<bool>());
|
||||
} else if(node->tag() == "text margin") {
|
||||
m_textHorizontalMargin = node->value<int>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -102,7 +102,7 @@ void UIWidget::render()
|
||||
child->render();
|
||||
|
||||
// debug draw box
|
||||
//g_graphics.bindColor(Color::green);
|
||||
//g_graphics.bindColor(Fw::green);
|
||||
//g_graphics.drawBoundingRect(child->getRect());
|
||||
//g_fonts.getDefaultFont()->renderText(child->getId(), child->getPosition() + Point(2, 0), Color::red);
|
||||
|
||||
@@ -709,7 +709,9 @@ void UIWidget::onStyleApply(const OTMLNodePtr& styleNode)
|
||||
for(const OTMLNodePtr& node : styleNode->children()) {
|
||||
// background image
|
||||
if(node->tag() == "image") {
|
||||
setImage(Image::loadFromOTML(node));
|
||||
ImagePtr image = ImagePtr(new Image);
|
||||
image->loadFromOTML(node);
|
||||
setImage(image);
|
||||
}
|
||||
else if(node->tag() == "border-image") {
|
||||
setImage(BorderImage::loadFromOTML(node));
|
||||
|
@@ -31,39 +31,29 @@ void UIWindow::setup()
|
||||
UIWidget::setup();
|
||||
m_moving = false;
|
||||
m_headHeight = 0;
|
||||
m_headMargin = 0;
|
||||
m_titleAlign = Fw::AlignCenter;
|
||||
}
|
||||
|
||||
void UIWindow::render()
|
||||
{
|
||||
// draw window head
|
||||
Rect headRect = getRect();
|
||||
headRect.setHeight(m_headHeight);
|
||||
|
||||
if(m_headImage && m_headHeight > 0) {
|
||||
g_graphics.bindColor(m_backgroundColor);
|
||||
m_headImage->draw(headRect);
|
||||
|
||||
// draw window head text
|
||||
Rect headTextRect = headRect;
|
||||
if(m_titleAlign & Fw::AlignLeft)
|
||||
headTextRect.addLeft(-m_headMargin);
|
||||
else if(m_titleAlign & Fw::AlignRight)
|
||||
headTextRect.addRight(-m_headMargin);
|
||||
m_font->renderText(m_title, headTextRect, m_titleAlign, m_foregroundColor);
|
||||
}
|
||||
|
||||
// draw window body
|
||||
Rect bodyRect = getRect();
|
||||
bodyRect.setTop(headRect.bottom() + 1);
|
||||
if(m_bodyImage) {
|
||||
g_graphics.bindColor(m_backgroundColor);
|
||||
m_bodyImage->draw(bodyRect);
|
||||
}
|
||||
|
||||
// render children
|
||||
UIWidget::render();
|
||||
|
||||
// draw window head
|
||||
|
||||
// draw window head text
|
||||
Rect headTextRect = m_rect;
|
||||
headTextRect.addTop(-m_headOffset.y);
|
||||
headTextRect.setHeight(m_headHeight);
|
||||
if(m_titleAlign & Fw::AlignLeft)
|
||||
headTextRect.addLeft(-m_headOffset.x);
|
||||
else if(m_titleAlign & Fw::AlignRight)
|
||||
headTextRect.addRight(-m_headOffset.x);
|
||||
else {
|
||||
headTextRect.addLeft(-m_headOffset.x);
|
||||
headTextRect.addRight(-m_headOffset.x);
|
||||
}
|
||||
m_font->renderText(m_title, headTextRect, m_titleAlign, m_foregroundColor);
|
||||
}
|
||||
|
||||
void UIWindow::onStyleApply(const OTMLNodePtr& styleNode)
|
||||
@@ -71,20 +61,14 @@ void UIWindow::onStyleApply(const OTMLNodePtr& styleNode)
|
||||
UIWidget::onStyleApply(styleNode);
|
||||
|
||||
for(OTMLNodePtr node : styleNode->children()) {
|
||||
if(node->tag() == "head") {
|
||||
if(OTMLNodePtr cnode = node->get("border-image"))
|
||||
m_headImage = BorderImage::loadFromOTML(cnode);
|
||||
m_headHeight = node->valueAt("height", m_headImage->getDefaultSize().height());
|
||||
m_headMargin = node->valueAt("margin", 0);
|
||||
m_titleAlign = Fw::translateAlignment(node->valueAt("text align", std::string("center")));
|
||||
}
|
||||
else if(node->tag() == "body") {
|
||||
if(OTMLNodePtr cnode = node->get("border-image"))
|
||||
m_bodyImage = BorderImage::loadFromOTML(cnode);
|
||||
}
|
||||
else if(node->tag() == "title") {
|
||||
if(node->tag() == "head height")
|
||||
m_headHeight = node->value<int>();
|
||||
else if(node->tag() == "head offset")
|
||||
m_headOffset = node->value<Point>();
|
||||
else if(node->tag() == "title")
|
||||
setTitle(node->value());
|
||||
}
|
||||
else if(node->tag() == "head text align")
|
||||
m_titleAlign = Fw::translateAlignment(node->value());
|
||||
else if(node->tag() == "onEnter") {
|
||||
g_lua.loadFunction(node->value(), "@" + node->source() + "[" + node->tag() + "]");
|
||||
luaSetField(node->tag());
|
||||
|
@@ -52,7 +52,7 @@ private:
|
||||
BorderImagePtr m_headImage;
|
||||
ImagePtr m_bodyImage;
|
||||
int m_headHeight;
|
||||
int m_headMargin;
|
||||
Point m_headOffset;
|
||||
Fw::AlignmentFlag m_titleAlign;
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user