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

19
modules/about/about.lua Normal file
View File

@ -0,0 +1,19 @@
About = {}
-- private variables
local about
-- public functions
function About.create()
about = UI.loadAndDisplay("/about/about.otui")
UI.root:lockChild(about)
end
function About.destroy()
about:destroy()
about = nil
end
function About.openWebpage()
displayErrorBox("Error", "Not implemented yet")
end

13
modules/about/about.otmod Normal file
View File

@ -0,0 +1,13 @@
Module
name: about
description: Create the about window
author: OTClient team
website: https://github.com/edubart/otclient
autoLoad: true
dependencies:
- core
onLoad: |
require 'about'
return true

61
modules/about/about.otui Normal file
View File

@ -0,0 +1,61 @@
MainWindow
id: about
title: Info
size: 244 221
FlatPanel
size: 208 129
anchors.left: parent.left
anchors.top: parent.top
margin.top: 32
margin.left: 18
Label
align: center
text: |-
OTClient
Version 0.2.0
Created by edubart
anchors.horizontalCenter: parent.horizontalCenter
anchors.top: parent.top
margin.top: 20
HorizontalSeparator
size: 190 2
anchors.left: parent.left
anchors.top: parent.top
margin.top: 83
margin.left: 9
Label
text: Official Website
anchors.left: parent.left
anchors.bottom: parent.bottom
margin.bottom: 14
margin.left: 9
Button
text: Github Page
size: 88 24
anchors.right: parent.right
anchors.bottom: parent.bottom
margin.bottom: 9
margin.right: 9
onClick: About.openWebpage()
HorizontalSeparator
anchors.left: parent.left
anchors.right: parent.right
anchors.bottom: parent.bottom
margin.bottom: 40
margin.left: 13
margin.right: 13
Button
text: Ok
size: 46 24
anchors.left: parent.left
anchors.top: parent.top
margin.top: 191
margin.left: 188
onClick: About.destroy()

Binary file not shown.

After

Width:  |  Height:  |  Size: 37 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 37 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 35 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.3 KiB

After

Width:  |  Height:  |  Size: 4.8 KiB

View File

@ -1,23 +1,28 @@
Panel < UIWidget Panel < UIWidget
phantom: true phantom: true
RectPanel < UIWidget
image: /core_styles/images/empty_rect.png
FlatPanel < Panel FlatPanel < Panel
border-image: border-image:
source: /core_styles/images/panel_flat.png source: /core_styles/images/panel_flat.png
border: 4 border: 4
TopPanel < Panel TopPanel < Panel
height: 34 height: 36
image: image:
source: /core_styles/images/top_panel.png source: /core_styles/images/top_panel.png
repeated: true repeated: true
RoundedPanel < Panel InterfacePanel < Panel
background-color: #ffffffdd focusable: false
border-image: border-image:
source: /core_styles/images/panel_rounded.png source: /core_styles/images/interface_panel.png
border: 4 border: 4
MapPanel < UIMap
RectPanel < UIWidget map margin: 4
image: /core_styles/images/empty_rect.png border-image:
source: /core_styles/images/map_panel.png
border: 4

View File

@ -91,12 +91,15 @@ end
function CharacterList.destroy() function CharacterList.destroy()
CharacterList.hide() CharacterList.hide()
EnterGame.show() if not Game.isOnline then
EnterGame.show()
end
end end
function CharacterList.show() function CharacterList.show()
if not loadBox then if not loadBox then
charactersWindow:show() charactersWindow:show()
charactersWindow:focus()
end end
end end

View File

@ -43,6 +43,7 @@ end
function EnterGame.show() function EnterGame.show()
enterGame:show() enterGame:show()
enterGame:focus()
end end
function EnterGame.hide() function EnterGame.hide()

View File

@ -1,6 +1,4 @@
require 'textmessage' require 'textmessage'
require 'skill'
require 'vip'
-- private functions -- private functions
local function onGameKeyPress(self, keyCode, keyChar, keyboardModifiers) local function onGameKeyPress(self, keyCode, keyChar, keyboardModifiers)
@ -16,28 +14,37 @@ local function onGameKeyPress(self, keyCode, keyChar, keyboardModifiers)
return false return false
end end
local function createMainInterface() -- public functions
function Game.create()
Game.gameUi = loadUI('/game/ui/gameinterface.otui', UI.root) Game.gameUi = loadUI('/game/ui/gameinterface.otui', UI.root)
Game.gameMapUi = Game.gameUi:getChildById('gameMap') Game.gameMapUi = Game.gameUi:getChildById('gameMap')
Game.gameUi.onKeyPress = onGameKeyPress Game.gameUi.onKeyPress = onGameKeyPress
createTextInterface() TextMessage.create()
createVipWindow()
end end
function Game.destroy()
local function destroyMainInterface()
if Game.gameUi then if Game.gameUi then
Game.gameUi:destroy() Game.gameUi:destroy()
Game.gameUi = nil Game.gameUi = nil
end end
end end
-- public functions function Game.show()
Game.gameUi:show()
Game.gameUi:focus()
Game.gameMapUi:focus()
end
function Game.hide()
Game.gameUi:hide()
end
-- hooked events
function Game.onLogin() function Game.onLogin()
Background.hide() Background.hide()
CharacterList.destroyLoadBox() CharacterList.destroyLoadBox()
createMainInterface() Game.show()
end end
function Game.onLoginError(message) function Game.onLoginError(message)
@ -53,7 +60,7 @@ function Game.onConnectionError(message)
end end
function Game.onLogout() function Game.onLogout()
Game.hide()
Background.show() Background.show()
CharacterList.show() CharacterList.show()
destroyMainInterface()
end end

View File

@ -3,7 +3,6 @@ Module
description: Create the game interface, where the ingame stuff starts description: Create the game interface, where the ingame stuff starts
author: OTClient team author: OTClient team
website: https://github.com/edubart/otclient website: https://github.com/edubart/otclient
version: 0.2
autoLoad: true autoLoad: true
dependencies: dependencies:
- core - core
@ -14,4 +13,7 @@ Module
onLoad: | onLoad: |
require 'game' require 'game'
require 'textmessage'
Game.create()
Game.hide()
return true return true

View File

@ -1,37 +1,41 @@
importStyles('/game/ui/textmessage.otui') TextMessage = {}
-- require styles
importStyles '/game/ui/textmessage.otui'
-- private variables
local bottomLabelWidget, centerLabelWidget local bottomLabelWidget, centerLabelWidget
local messageTypes = { local messageTypes = {
first = 12, first = 12,
{ type = 'MessageOrange', color = '#C87832', showOnConsole = true, showOnWindow = false }, { type = 'MessageOrange', color = '#C87832', showOnConsole = true, showOnWindow = false },
{ type = 'MessageOrange', color = '#C87832', showOnConsole = true, showOnWindow = false }, { type = 'MessageOrange', color = '#C87832', showOnConsole = true, showOnWindow = false },
{ type = 'MessageRed', color = '#C83200', showOnConsole = true, showOnWindow = true, windowLocation = 'CenterLabel' }, { type = 'MessageRed', color = '#C83200', showOnConsole = true, showOnWindow = true, windowLocation = 'CenterLabel' },
{ type = 'MessageWhite', color = '#FFFFFF', showOnConsole = true, showOnWindow = true, windowLocation = 'CenterLabel' }, { type = 'MessageWhite', color = '#FFFFFF', showOnConsole = true, showOnWindow = true, windowLocation = 'CenterLabel' },
{ type = 'MessageWhite', color = '#FFFFFF', showOnConsole = true, showOnWindow = true, windowLocation = 'BottomLabel' }, { type = 'MessageWhite', color = '#FFFFFF', showOnConsole = true, showOnWindow = true, windowLocation = 'BottomLabel' },
{ type = 'MessageWhite', color = '#FFFFFF', showOnConsole = true, showOnWindow = true, windowLocation = 'BottomLabel' }, { type = 'MessageWhite', color = '#FFFFFF', showOnConsole = true, showOnWindow = true, windowLocation = 'BottomLabel' },
{ type = 'MessageGreen', color = '#3FBE32', showOnConsole = true, showOnWindow = true, windowLocation = 'CenterLabel' }, { type = 'MessageGreen', color = '#3FBE32', showOnConsole = true, showOnWindow = true, windowLocation = 'CenterLabel' },
{ type = 'MessageWhite', color = '#FFFFFF', showOnConsole = false, showOnWindow = true, windowLocation = 'BottomLabel' }, { type = 'MessageWhite', color = '#FFFFFF', showOnConsole = false, showOnWindow = true, windowLocation = 'BottomLabel' },
{ type = 'MessageBlue', color = '#3264C8', showOnConsole = true, showOnWindow = false }, { type = 'MessageBlue', color = '#3264C8', showOnConsole = true, showOnWindow = false },
{ type = 'MessageRed', color = '#C83200', showOnConsole = true, showOnWindow = false } { type = 'MessageRed', color = '#C83200', showOnConsole = true, showOnWindow = false }
} }
function createTextInterface() -- public functions
function TextMessage.create()
bottomLabelWidget = UILabel.create() bottomLabelWidget = UILabel.create()
Game.gameMapUi:addChild(bottomLabelWidget) Game.gameMapUi:addChild(bottomLabelWidget)
centerLabelWidget = UILabel.create() centerLabelWidget = UILabel.create()
Game.gameMapUi:addChild(centerLabelWidget) Game.gameMapUi:addChild(centerLabelWidget)
end end
-- hooked events
function Game.onTextMessage(type, message) function Game.onTextMessage(type, message)
local messageType = messageTypes[type - messageTypes.first] local messageType = messageTypes[type - messageTypes.first]
if messageType.showOnConsole then if messageType.showOnConsole then
-- TODO -- TODO
end end
if messageType.showOnWindow then if messageType.showOnWindow then
local label local label
if messageType.windowLocation == 'BottomLabel' then if messageType.windowLocation == 'BottomLabel' then
@ -39,18 +43,16 @@ function Game.onTextMessage(type, message)
elseif messageType.windowLocation == 'CenterLabel' then elseif messageType.windowLocation == 'CenterLabel' then
label = centerLabelWidget label = centerLabelWidget
end end
label:setVisible(true) label:setVisible(true)
label:setForegroundColor(messageType.color) label:setForegroundColor(messageType.color)
label:setText(message) label:setText(message)
label:setStyle(messageType.windowLocation) label:setStyle(messageType.windowLocation)
time = #message * 75 time = #message * 75
scheduleEvent(function() scheduleEvent(function()
label:setVisible(false) label:setVisible(false)
end, time) end, time)
end end
end end

View File

@ -2,9 +2,24 @@ UIWidget
id: gameRootInterface id: gameRootInterface
anchors.fill: parent anchors.fill: parent
anchors.top: topMenu.bottom anchors.top: topMenu.bottom
margin.top: 1
UIMap InterfacePanel
id: rightPanel
width: 200
anchors.right: parent.right
anchors.top: parent.top
anchors.bottom: parent.bottom
InterfacePanel
id: bottomPanel
height: 140
anchors.left: parent.left
anchors.right: rightPanel.left
anchors.bottom: parent.bottom
MapPanel
id: gameMap id: gameMap
anchors.fill:parent anchors.left: parent.left
margin.right: 200 anchors.right: rightPanel.left
anchors.top: parent.top
anchors.bottom: bottomPanel.top

View File

@ -0,0 +1,19 @@
Options = {}
-- private variables
local options
-- public functions
function Options.create()
options = UI.loadAndDisplay("/options/options.otui")
UI.root:lockChild(options)
end
function Options.destroy()
options:destroy()
options = nil
end
function Options.openWebpage()
displayErrorBox("Error", "Not implemented yet")
end

View File

@ -0,0 +1,13 @@
Module
name: options
description: Create the options window
author: OTClient team
website: https://github.com/edubart/otclient
autoLoad: true
dependencies:
- core
onLoad: |
require 'options'
return true

View File

@ -0,0 +1,116 @@
MainWindow
id: optionsWindow
title: Options
size: 286 262
// general
Button
text: General
anchors.left: parent.left
anchors.top: parent.top
margin.left: 18
margin.top: 32
onClick: displayErrorBox("Error", "Not implemented yet")
Label
text: |-
Change general
game options
anchors.left: prev.right
anchors.top: prev.top
margin.left: 10
margin.top: -2
// graphics
Button
text: Graphics
anchors.left: parent.left
anchors.top: parent.top
margin.left: 18
margin.top: 65
onClick: displayErrorBox("Error", "Not implemented yet")
Label
text: |-
Change graphics and
performance settings
anchors.left: prev.right
anchors.top: prev.top
margin.left: 10
margin.top: -2
// console
Button
text: Console
anchors.left: parent.left
anchors.top: parent.top
margin.left: 18
margin.top: 98
onClick: displayErrorBox("Error", "Not implemented yet")
Label
text: Customise the console
anchors.left: prev.right
anchors.top: prev.top
margin.left: 10
margin.top: -2
// hotkeys
Button
text: Hotkeys
anchors.left: parent.left
anchors.top: parent.top
margin.left: 18
margin.top: 131
onClick: displayErrorBox("Error", "Not implemented yet")
Label
text: Edit your hotkey texts
anchors.left: prev.right
anchors.top: prev.top
margin.left: 10
margin.top: -2
HorizontalSeparator
anchors.left: parent.left
anchors.right: parent.right
anchors.bottom: parent.bottom
margin.bottom: 97
margin.left: 18
margin.right: 18
// motd
Button
text: Motd
anchors.left: parent.left
anchors.bottom: parent.bottom
margin.left: 18
margin.bottom: 60
onClick: displayErrorBox("Error", "Not implemented yet")
Label
text: |-
Show the most recent
Message of the Day
anchors.left: prev.right
anchors.top: prev.top
margin.left: 10
margin.top: -2
HorizontalSeparator
anchors.left: parent.left
anchors.right: parent.right
anchors.bottom: parent.bottom
margin.bottom: 40
margin.left: 13
margin.right: 13
// ok button
Button
text: Ok
width: 64
anchors.right: parent.right
anchors.bottom: parent.bottom
margin.right: 10
margin.bottom: 10
onClick: Options.destroy()

View File

@ -1,32 +1,30 @@
skillWindow = nil skillWindow = nil
local skills = {"Fist Fighting", "Club Fighting", "Sword Fighting", "Axe Fighting", "Distance Fighting", "Shielding", "Fishing"} local skills = {"Fist Fighting", "Club Fighting", "Sword Fighting", "Axe Fighting", "Distance Fighting", "Shielding", "Fishing"}
function csw() function csw()
skillWindow = loadUI("/game/ui/skillwindow.otui", UI.root) skillWindow = loadUI("/game/ui/skillwindow.otui", UI.root)
local skillPanel = skillWindow:getChildById('skillPanel') local skillPanel = skillWindow:getChildById('skillPanel')
-- create first widget cause of layout -- create first widget cause of layout
local widget = UIWidget.create() local widget = UIWidget.create()
skillPanel:addChild(widget) skillPanel:addChild(widget)
widget:setStyle('SkillFirstWidget') widget:setStyle('SkillFirstWidget')
-- create skills -- create skills
for i=1,#skills,1 do for i=1,#skills,1 do
local nameLabel = UILabel.create() local nameLabel = UILabel.create()
skillPanel:addChild(nameLabel) skillPanel:addChild(nameLabel)
nameLabel:setStyle('SkillNameLabel') nameLabel:setStyle('SkillNameLabel')
nameLabel:setText(skills[i]) nameLabel:setText(skills[i])
local levelLabel = UILabel.create() local levelLabel = UILabel.create()
skillPanel:addChild(levelLabel) skillPanel:addChild(levelLabel)
levelLabel:setStyle('SkillLevelLabel') levelLabel:setStyle('SkillLevelLabel')
levelLabel:setId('skillLevelId' .. i) levelLabel:setId('skillLevelId' .. i)
levelLabel:setText('10') levelLabel:setText('10')
local percentPanel = UIWidget.create() local percentPanel = UIWidget.create()
skillPanel:addChild(percentPanel) skillPanel:addChild(percentPanel)
percentPanel:setStyle('SkillPercentPanel') percentPanel:setStyle('SkillPercentPanel')
@ -36,5 +34,4 @@ end
function Game.setSkill(id, level, percent) function Game.setSkill(id, level, percent)
local skillPanel = skillWindow:getChildById('skillPanel') local skillPanel = skillWindow:getChildById('skillPanel')
local levelLabel = skillPanel:getChildById('skillLevel' .. id) local levelLabel = skillPanel:getChildById('skillLevel' .. id)
end end

View File

View File

@ -44,4 +44,4 @@ Window
margin.top: 19 margin.top: 19
margin.bottom: 3 margin.bottom: 3
margin.left: 3 margin.left: 3
margin.right: 3 margin.right: 3

View File

@ -11,6 +11,7 @@ TopPanel
anchors.left: parent.left anchors.left: parent.left
margin.top: 3 margin.top: 3
margin.left: 6 margin.left: 6
onClick: Options.create()
UIWidget UIWidget
size: 16 16 size: 16 16
@ -22,7 +23,12 @@ TopPanel
anchors.top: prev.top anchors.top: prev.top
anchors.left: prev.right anchors.left: prev.right
margin.left: 6 margin.left: 6
onClick: EnterGame.show() onClick: |
if Game.isOnline() then
CharacterList.show()
else
EnterGame.show()
end
UIWidget UIWidget
size: 16 16 size: 16 16
@ -46,4 +52,17 @@ TopPanel
size: 16 16 size: 16 16
image: /core_styles/icons/logout.png image: /core_styles/icons/logout.png
anchors.centerIn: parent anchors.centerIn: parent
phantom: true
TopButton
anchors.top: parent.top
anchors.right: prev.left
margin.top: 3
margin.right: 6
onClick: About.create()
UIWidget
size: 16 16
image: /core_styles/icons/about.png
anchors.centerIn: parent
phantom: true phantom: true

View File

@ -6,31 +6,31 @@ end
function Game.onAddVip(id, name, online) function Game.onAddVip(id, name, online)
local vipList = vipWindow:getChildById('vipList') local vipList = vipWindow:getChildById('vipList')
local label = UILabel.create() local label = UILabel.create()
vipList:addChild(label) vipList:addChild(label)
label:setId('vip' .. id) label:setId('vip' .. id)
label:setText(name) label:setText(name)
label:setStyle('VipListLabel') label:setStyle('VipListLabel')
if online then if online then
label:setForegroundColor('#00ff00') label:setForegroundColor('#00ff00')
else else
label:setForegroundColor('#ff0000') label:setForegroundColor('#ff0000')
end end
label.vipOnline = online label.vipOnline = online
end end
function Game.onVipStateChange(id, online) function Game.onVipStateChange(id, online)
local vipList = vipWindow:getChildById('vipList') local vipList = vipWindow:getChildById('vipList')
local label = vipList:getChildById('vip' .. id) local label = vipList:getChildById('vip' .. id)
if online then if online then
label:setForegroundColor('#00ff00') label:setForegroundColor('#00ff00')
else else
label:setForegroundColor('#ff0000') label:setForegroundColor('#ff0000')
end end
label.vipOnline = online label.vipOnline = online
end end

View File

View File

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

View File

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

View File

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

View File

@ -148,7 +148,7 @@ void OTClient::run()
render(); render();
// render fps // 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 // render end
g_graphics.endRender(); g_graphics.endRender();

View File

@ -23,6 +23,8 @@
#include "uimap.h" #include "uimap.h"
#include <otclient/core/map.h> #include <otclient/core/map.h>
#include <otclient/core/game.h> #include <otclient/core/game.h>
#include <framework/otml/otml.h>
#include <framework/graphics/graphics.h>
void UIMap::setup() void UIMap::setup()
{ {
@ -31,10 +33,15 @@ void UIMap::setup()
void UIMap::render() void UIMap::render()
{ {
if(g_game.isOnline()) renderSelf();
g_map.draw(m_rect);
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) 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); 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) bool UIMap::onMousePress(const Point& mousePos, Fw::MouseButton button)
{ {
return UIWidget::onMousePress(mousePos, 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) 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); Size mapSize(15*32, 11*32);
mapSize.scale(mapRect.size(), Fw::KeepAspectRatio); mapSize.scale(mapRect.size(), Fw::KeepAspectRatio);
mapRect.setSize(mapSize); m_mapRect.setSize(mapSize);
if(mapRect != newRect) m_mapRect.moveCenter(newRect.center());
setRect(mapRect);
} }

View File

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