display window on screen center

This commit is contained in:
Eduardo Bart 2012-01-02 23:32:34 -02:00
parent 05230f44e4
commit 7172d2251a
7 changed files with 17 additions and 17 deletions

View File

@ -8,8 +8,14 @@ function Client.init()
if g_window.getPlatformType() == "X11-EGL" then if g_window.getPlatformType() == "X11-EGL" then
g_window.setFullscreen(true) g_window.setFullscreen(true)
else else
g_window.move({ x=220, y=220 }) local size = { width = 1024,
g_window.resize({ width=800, height=480 }) height = 768 }
g_window.resize(size)
local displaySize = g_window.getDisplaySize()
local pos = { x = (displaySize.width - size.width)/2,
y = (displaySize.height - size.height)/2 }
g_window.move(pos)
end end
g_window.setTitle('OTClient') g_window.setTitle('OTClient')

View File

@ -35,8 +35,6 @@ PopupMenuSeparator < UIWidget
PopupMenu < UIPopupMenu PopupMenu < UIPopupMenu
width: 100 width: 100
button-style: PopupMenuButton
separator-style: PopupMenuSeparator
border-image: border-image:
source: /core_styles/images/menubox.png source: /core_styles/images/menubox.png
border: 3 border: 3

View File

@ -19,7 +19,7 @@ function UIPopupMenu.display(menu, pos)
end end
function UIPopupMenu.addOption(menu, optionName, optionCallback) function UIPopupMenu.addOption(menu, optionName, optionCallback)
local optionWidget = createWidget(menu.buttonStyle, menu) local optionWidget = createWidget(menu:getStyleName() .. 'Button', menu)
local lastOptionWidget = menu:getLastChild() local lastOptionWidget = menu:getLastChild()
optionWidget.onClick = function() optionWidget.onClick = function()
optionCallback() optionCallback()
@ -29,7 +29,7 @@ function UIPopupMenu.addOption(menu, optionName, optionCallback)
end end
function UIPopupMenu.addSeparator(menu) function UIPopupMenu.addSeparator(menu)
local separatorWidget = createWidget(menu.separatorStyle, separator) local separatorWidget = createWidget(menu:getStyleName() .. 'Separator', separator)
end end
-- hooked events -- hooked events
@ -49,12 +49,3 @@ function UIPopupMenu.onKeyPress(menu, keyCode, keyText, keyboardModifiers)
end end
return false return false
end end
function UIPopupMenu.onStyleApply(menu, style)
if style['button-style'] then
menu.buttonStyle = style['button-style']
end
if style['separator-style'] then
menu.separatorStyle = style['separator-style']
end
end

View File

@ -120,6 +120,7 @@ void Application::registerLuaFunctions()
g_lua.bindClassMemberFunction<UIWidget>("getMarginLeft", &UIWidget::getMarginLeft); g_lua.bindClassMemberFunction<UIWidget>("getMarginLeft", &UIWidget::getMarginLeft);
g_lua.bindClassMemberFunction<UIWidget>("getLastFocusReason", &UIWidget::getLastFocusReason); g_lua.bindClassMemberFunction<UIWidget>("getLastFocusReason", &UIWidget::getLastFocusReason);
g_lua.bindClassMemberFunction<UIWidget>("getStyle", &UIWidget::getStyle); g_lua.bindClassMemberFunction<UIWidget>("getStyle", &UIWidget::getStyle);
g_lua.bindClassMemberFunction<UIWidget>("getStyleName", &UIWidget::getStyleName);
g_lua.bindClassMemberFunction<UIWidget>("getChildren", &UIWidget::getChildren); g_lua.bindClassMemberFunction<UIWidget>("getChildren", &UIWidget::getChildren);
g_lua.bindClassMemberFunction<UIWidget>("getFocusedChild", &UIWidget::getFocusedChild); g_lua.bindClassMemberFunction<UIWidget>("getFocusedChild", &UIWidget::getFocusedChild);
g_lua.bindClassMemberFunction<UIWidget>("getChildAfter", &UIWidget::getChildAfter); g_lua.bindClassMemberFunction<UIWidget>("getChildAfter", &UIWidget::getChildAfter);
@ -233,6 +234,7 @@ void Application::registerLuaFunctions()
g_lua.bindClassStaticFunction("g_window", "setIcon", std::bind(&PlatformWindow::setIcon, &g_window, _1)); g_lua.bindClassStaticFunction("g_window", "setIcon", std::bind(&PlatformWindow::setIcon, &g_window, _1));
g_lua.bindClassStaticFunction("g_window", "getMousePos", std::bind(&PlatformWindow::getMousePos, &g_window)); g_lua.bindClassStaticFunction("g_window", "getMousePos", std::bind(&PlatformWindow::getMousePos, &g_window));
g_lua.bindClassStaticFunction("g_window", "getSize", std::bind(&PlatformWindow::getSize, &g_window)); g_lua.bindClassStaticFunction("g_window", "getSize", std::bind(&PlatformWindow::getSize, &g_window));
g_lua.bindClassStaticFunction("g_window", "getDisplaySize", std::bind(&PlatformWindow::getDisplaySize, &g_window));
g_lua.bindClassStaticFunction("g_window", "getPlatformType", std::bind(&PlatformWindow::getPlatformType, &g_window)); g_lua.bindClassStaticFunction("g_window", "getPlatformType", std::bind(&PlatformWindow::getPlatformType, &g_window));
// Logger // Logger

View File

@ -34,7 +34,6 @@ void UIManager::init()
// creates root widget // creates root widget
m_rootWidget = UIWidget::create<UIWidget>(); m_rootWidget = UIWidget::create<UIWidget>();
m_rootWidget->setId("root"); m_rootWidget->setId("root");
m_rootWidget->resize(g_window.getSize());
m_mouseReceiver = m_rootWidget; m_mouseReceiver = m_rootWidget;
m_keyboardReceiver = m_rootWidget; m_keyboardReceiver = m_rootWidget;
} }
@ -134,8 +133,9 @@ OTMLNodePtr UIManager::getStyle(const std::string& styleName)
// styles starting with UI are automatically defined // styles starting with UI are automatically defined
if(boost::starts_with(styleName, "UI")) { if(boost::starts_with(styleName, "UI")) {
OTMLNodePtr node = OTMLNode::create(); OTMLNodePtr node = OTMLNode::create(styleName);
node->writeAt("__class", styleName); node->writeAt("__class", styleName);
m_styles[styleName] = node;
return node; return node;
} }

View File

@ -155,6 +155,7 @@ void UIWidget::setStyle(const std::string& styleName)
} }
applyStyle(styleNode); applyStyle(styleNode);
m_style = styleNode; m_style = styleNode;
assert(getStyleName() != "");
updateStyle(); updateStyle();
} }

View File

@ -26,6 +26,7 @@
#include "declarations.h" #include "declarations.h"
#include <framework/luascript/luaobject.h> #include <framework/luascript/luaobject.h>
#include <framework/graphics/declarations.h> #include <framework/graphics/declarations.h>
#include <framework/otml/otmlnode.h>
class UIWidget : public LuaObject class UIWidget : public LuaObject
{ {
@ -128,6 +129,7 @@ public:
int getMarginLeft() { return m_marginLeft; } int getMarginLeft() { return m_marginLeft; }
Fw::FocusReason getLastFocusReason() { return m_lastFocusReason; } Fw::FocusReason getLastFocusReason() { return m_lastFocusReason; }
OTMLNodePtr getStyle() { return m_style; } OTMLNodePtr getStyle() { return m_style; }
std::string getStyleName() { return m_style->tag(); }
UIWidgetList getChildren() { return m_children; } UIWidgetList getChildren() { return m_children; }
UIWidgetPtr getFocusedChild() { return m_focusedChild; } UIWidgetPtr getFocusedChild() { return m_focusedChild; }