Minor fixes and add auto resize for images

This commit is contained in:
Eduardo Bart 2013-03-15 21:59:10 -03:00
parent a3a65d40ce
commit b43a196eac
6 changed files with 30 additions and 8 deletions

View File

@ -257,11 +257,14 @@ function flushLines()
for _,line in pairs(cachedLines) do
-- delete old lines if needed
if numLines > MaxLogLines then
local len = #terminalBuffer:getChildByIndex(1):getText()
terminalBuffer:getChildByIndex(1):destroy()
local firstChild = terminalBuffer:getChildByIndex(1)
if firstChild then
local len = #firstChild:getText()
firstChild:destroy()
table.remove(allLines, 1)
fulltext = string.sub(fulltext, len)
end
end
local label = g_ui.createWidget('TerminalLabel', terminalBuffer)
label:setId('terminalLabel' .. numLines)

View File

@ -110,7 +110,9 @@ function UITabBar:selectTab(tab)
tab:setOn(false)
local parent = tab:getParent()
if parent then
parent:focusChild(tab, MouseFocusReason)
end
end
function UITabBar:selectNextTab()

View File

@ -569,6 +569,7 @@ void Application::registerLuaFunctions()
g_lua.bindClassMemberFunction<UIWidget>("setImageFixedRatio", &UIWidget::setImageFixedRatio);
g_lua.bindClassMemberFunction<UIWidget>("setImageRepeated", &UIWidget::setImageRepeated);
g_lua.bindClassMemberFunction<UIWidget>("setImageSmooth", &UIWidget::setImageSmooth);
g_lua.bindClassMemberFunction<UIWidget>("setImageAutoResize", &UIWidget::setImageAutoResize);
g_lua.bindClassMemberFunction<UIWidget>("setImageBorderTop", &UIWidget::setImageBorderTop);
g_lua.bindClassMemberFunction<UIWidget>("setImageBorderRight", &UIWidget::setImageBorderRight);
g_lua.bindClassMemberFunction<UIWidget>("setImageBorderBottom", &UIWidget::setImageBorderBottom);
@ -585,6 +586,7 @@ void Application::registerLuaFunctions()
g_lua.bindClassMemberFunction<UIWidget>("getImageColor", &UIWidget::getImageColor);
g_lua.bindClassMemberFunction<UIWidget>("isImageFixedRatio", &UIWidget::isImageFixedRatio);
g_lua.bindClassMemberFunction<UIWidget>("isImageSmooth", &UIWidget::isImageSmooth);
g_lua.bindClassMemberFunction<UIWidget>("isImageAutoResize", &UIWidget::isImageAutoResize);
g_lua.bindClassMemberFunction<UIWidget>("getImageBorderTop", &UIWidget::getImageBorderTop);
g_lua.bindClassMemberFunction<UIWidget>("getImageBorderRight", &UIWidget::getImageBorderRight);
g_lua.bindClassMemberFunction<UIWidget>("getImageBorderBottom", &UIWidget::getImageBorderBottom);

View File

@ -98,9 +98,9 @@ void UIWidget::drawSelf(Fw::DrawPane drawPane)
}
drawImage(m_rect);
drawBorder(m_rect);
drawIcon(m_rect);
drawText(m_rect);
drawBorder(m_rect);
}
void UIWidget::drawChildren(const Rect& visibleRect, Fw::DrawPane drawPane)

View File

@ -419,6 +419,7 @@ protected:
stdext::boolean<false> m_imageFixedRatio;
stdext::boolean<false> m_imageRepeated;
stdext::boolean<false> m_imageSmooth;
stdext::boolean<false> m_imageAutoResize;
EdgeGroup<int> m_imageBorder;
public:
@ -435,6 +436,7 @@ public:
void setImageFixedRatio(bool fixedRatio) { m_imageFixedRatio = fixedRatio; updateImageCache(); }
void setImageRepeated(bool repeated) { m_imageRepeated = repeated; updateImageCache(); }
void setImageSmooth(bool smooth) { m_imageSmooth = smooth; }
void setImageAutoResize(bool autoResize) { m_imageAutoResize = autoResize; }
void setImageBorderTop(int border) { m_imageBorder.top = border; configureBorderImage(); }
void setImageBorderRight(int border) { m_imageBorder.right = border; configureBorderImage(); }
void setImageBorderBottom(int border) { m_imageBorder.bottom = border; configureBorderImage(); }
@ -452,6 +454,7 @@ public:
Color getImageColor() { return m_imageColor; }
bool isImageFixedRatio() { return m_imageFixedRatio; }
bool isImageSmooth() { return m_imageSmooth; }
bool isImageAutoResize() { return m_imageAutoResize; }
int getImageBorderTop() { return m_imageBorder.top; }
int getImageBorderRight() { return m_imageBorder.right; }
int getImageBorderBottom() { return m_imageBorder.bottom; }

View File

@ -68,9 +68,10 @@ void UIWidget::parseImageStyle(const OTMLNodePtr& styleNode)
setImageBorderBottom(node->value<int>());
else if(node->tag() == "image-border-left")
setImageBorderLeft(node->value<int>());
else if(node->tag() == "image-border") {
else if(node->tag() == "image-border")
setImageBorder(node->value<int>());
}
else if(node->tag() == "image-auto-resize")
setImageAutoResize(node->value<bool>());
}
}
@ -180,5 +181,16 @@ void UIWidget::setImageSource(const std::string& source)
m_imageTexture = nullptr;
else
m_imageTexture = g_textures.getTexture(source);
if(m_imageTexture && (!m_rect.isValid() || m_imageAutoResize)) {
Size size = getSize();
Size imageSize = m_imageTexture->getSize();
if(size.width() <= 0 || m_imageAutoResize)
size.setWidth(imageSize.width());
if(size.height() <= 0 || m_imageAutoResize)
size.setHeight(imageSize.height());
setSize(size);
}
m_imageMustRecache = true;
}