create in game interface panels and renable about and options windows

This commit is contained in:
Eduardo Bart
2011-11-03 07:59:11 -02:00
parent b05bb7818d
commit b345a6d783
30 changed files with 400 additions and 70 deletions

View File

@@ -71,6 +71,7 @@ void LuaInterface::registerFunctions()
g_lua.bindClassMemberFunction<UIWidget>("show", &UIWidget::show);
g_lua.bindClassMemberFunction<UIWidget>("lock", &UIWidget::lock);
g_lua.bindClassMemberFunction<UIWidget>("unlock", &UIWidget::unlock);
g_lua.bindClassMemberFunction<UIWidget>("focus", &UIWidget::focus);
g_lua.bindClassMemberFunction<UIWidget>("getChildren", &UIWidget::getChildren);
g_lua.bindClassMemberFunction<UIWidget>("getChildById", &UIWidget::getChildById);
g_lua.bindClassMemberFunction<UIWidget>("getChildByIndex", &UIWidget::getChildByIndex);

View File

@@ -82,13 +82,22 @@ void UIWidget::destroy()
}
void UIWidget::render()
{
renderSelf();
renderChildren();
}
void UIWidget::renderSelf()
{
// draw background
if(m_image) {
g_graphics.bindColor(m_backgroundColor);
m_image->draw(m_rect);
}
}
void UIWidget::renderChildren()
{
// draw children
for(const UIWidgetPtr& child : m_children) {
// render only visible children with a valid rect
@@ -191,6 +200,12 @@ void UIWidget::unlock()
parent->unlockChild(asUIWidget());
}
void UIWidget::focus()
{
if(UIWidgetPtr parent = getParent())
parent->focusChild(asUIWidget(), Fw::ActiveFocusReason);
}
bool UIWidget::isVisible()
{
if(!m_visible)

View File

@@ -40,6 +40,8 @@ public:
virtual void setup();
virtual void render();
void renderSelf();
void renderChildren();
void setVisible(bool visible);
void setEnabled(bool enabled) { m_enabled = enabled; updateState(Fw::DisabledState); }
@@ -76,6 +78,7 @@ public:
void enable() { setEnabled(true); }
void lock();
void unlock();
void focus();
bool isActive() const { return hasState(Fw::ActiveState); }
bool isEnabled() const { return !hasState(Fw::DisabledState); }

View File

@@ -148,7 +148,7 @@ void OTClient::run()
render();
// render fps
defaultFont->renderText(fpsText, Point(g_graphics.getScreenSize().width() - fpsTextSize.width() - 10, 34));
defaultFont->renderText(fpsText, Point(g_graphics.getScreenSize().width() - fpsTextSize.width() - 10, 38));
// render end
g_graphics.endRender();

View File

@@ -23,6 +23,8 @@
#include "uimap.h"
#include <otclient/core/map.h>
#include <otclient/core/game.h>
#include <framework/otml/otml.h>
#include <framework/graphics/graphics.h>
void UIMap::setup()
{
@@ -31,10 +33,15 @@ void UIMap::setup()
void UIMap::render()
{
if(g_game.isOnline())
g_map.draw(m_rect);
renderSelf();
UIWidget::render();
if(g_game.isOnline()) {
g_graphics.bindColor(Fw::black);
g_graphics.drawBoundingRect(m_mapRect.expanded(1));
g_map.draw(m_mapRect);
}
renderChildren();
}
bool UIMap::onKeyPress(uchar keyCode, char keyChar, int keyboardModifiers)
@@ -83,6 +90,16 @@ bool UIMap::onKeyPress(uchar keyCode, char keyChar, int keyboardModifiers)
return UIWidget::onKeyPress(keyCode, keyChar, keyboardModifiers);
}
void UIMap::onStyleApply(const OTMLNodePtr& styleNode)
{
for(OTMLNodePtr node : styleNode->children()) {
if(node->tag() == "map margin")
m_mapMargin = node->value<int>();
}
UIWidget::onStyleApply(styleNode);
}
bool UIMap::onMousePress(const Point& mousePos, Fw::MouseButton button)
{
return UIWidget::onMousePress(mousePos, button);
@@ -90,10 +107,9 @@ bool UIMap::onMousePress(const Point& mousePos, Fw::MouseButton button)
void UIMap::onGeometryUpdate(const Rect& oldRect, const Rect& newRect)
{
Rect mapRect = newRect;
Rect mapRect = newRect.expanded(-m_mapMargin-1);
Size mapSize(15*32, 11*32);
mapSize.scale(mapRect.size(), Fw::KeepAspectRatio);
mapRect.setSize(mapSize);
if(mapRect != newRect)
setRect(mapRect);
m_mapRect.setSize(mapSize);
m_mapRect.moveCenter(newRect.center());
}

View File

@@ -33,11 +33,14 @@ public:
void render();
protected:
virtual void onStyleApply(const OTMLNodePtr& styleNode);
virtual bool onKeyPress(uchar keyCode, char keyChar, int keyboardModifiers);
virtual bool onMousePress(const Point& mousePos, Fw::MouseButton button);
virtual void onGeometryUpdate(const Rect& oldRect, const Rect& newRect);
private:
int m_mapMargin;
Rect m_mapRect;
};
#endif