summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
authorGuillaume Melquiond <guillaume.melquiond@gmail.com>2007-08-07 17:03:55 +0000
committerGuillaume Melquiond <guillaume.melquiond@gmail.com>2007-08-07 17:03:55 +0000
commitb2b13c21091b516b57b4bf3c91a313f019bf3579 (patch)
tree995e63ecadf1ea16c94b9d39b66a367358b5a27a /src/gui
parentc09825097c0231c57f9ac416fae0003c5d68398c (diff)
downloadmana-client-b2b13c21091b516b57b4bf3c91a313f019bf3579.tar.gz
mana-client-b2b13c21091b516b57b4bf3c91a313f019bf3579.tar.bz2
mana-client-b2b13c21091b516b57b4bf3c91a313f019bf3579.tar.xz
mana-client-b2b13c21091b516b57b4bf3c91a313f019bf3579.zip
Fixed my breakage of persistent window dimensions. Cleaned a few things along the way.
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/chat.cpp6
-rw-r--r--src/gui/debugwindow.cpp4
-rw-r--r--src/gui/equipmentwindow.cpp2
-rw-r--r--src/gui/help.cpp1
-rw-r--r--src/gui/inventorywindow.cpp26
-rw-r--r--src/gui/inventorywindow.h10
-rw-r--r--src/gui/minimap.cpp2
-rw-r--r--src/gui/popupmenu.cpp1
-rw-r--r--src/gui/skill.cpp3
-rw-r--r--src/gui/status.cpp3
-rw-r--r--src/gui/trade.cpp1
-rw-r--r--src/gui/window.cpp30
-rw-r--r--src/gui/window.h39
13 files changed, 45 insertions, 83 deletions
diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp
index 48df9efe..b5a0ec13 100644
--- a/src/gui/chat.cpp
+++ b/src/gui/chat.cpp
@@ -46,16 +46,16 @@
#include "../utils/dtor.h"
ChatWindow::ChatWindow():
- Window(""),
+ Window(),
mTmpVisible(false)
{
- setWindowName("Chat");
mItems = 0;
mItemsKeep = 20;
setResizable(true);
setDefaultSize(0, (windowContainer->getHeight() - 123), 600, 100);
- loadWindowState();
+ setTitleBarHeight(0);
+ loadWindowState("Chat");
mChatInput = new ChatInput();
mChatInput->setActionEventId("chatinput");
diff --git a/src/gui/debugwindow.cpp b/src/gui/debugwindow.cpp
index ebf7d974..11ad37c2 100644
--- a/src/gui/debugwindow.cpp
+++ b/src/gui/debugwindow.cpp
@@ -41,11 +41,9 @@
DebugWindow::DebugWindow():
Window("Debug")
{
- setWindowName("Debug");
-
setResizable(true);
setDefaultSize(0, 0, 400, 100);
- loadWindowState();
+ loadWindowState("Debug");
mFPSLabel = new gcn::Label("[0 FPS]");
mFPSLabel->setPosition(0,0);
diff --git a/src/gui/equipmentwindow.cpp b/src/gui/equipmentwindow.cpp
index 2ee57cd9..0ffba5a2 100644
--- a/src/gui/equipmentwindow.cpp
+++ b/src/gui/equipmentwindow.cpp
@@ -37,7 +37,7 @@ EquipmentWindow::EquipmentWindow(Equipment *equipment):
Window(_("Equipment")), mEquipment(equipment)
{
setDefaultSize(5, 230, 200, 120);
- loadWindowState();
+ loadWindowState("Equipment");
}
EquipmentWindow::~EquipmentWindow()
diff --git a/src/gui/help.cpp b/src/gui/help.cpp
index 0b010253..87de1e2f 100644
--- a/src/gui/help.cpp
+++ b/src/gui/help.cpp
@@ -33,7 +33,6 @@ HelpWindow::HelpWindow():
Window("Help")
{
setContentSize(455, 350);
- setWindowName("Help");
mBrowserBox = new BrowserBox();
mBrowserBox->setOpaque(false);
diff --git a/src/gui/inventorywindow.cpp b/src/gui/inventorywindow.cpp
index 2822faaa..7b199be4 100644
--- a/src/gui/inventorywindow.cpp
+++ b/src/gui/inventorywindow.cpp
@@ -81,7 +81,8 @@ InventoryWindow::InventoryWindow():
mUseButton->setSize(48, mUseButton->getHeight());
- loadWindowState();
+ loadWindowState("Inventory");
+ updateContentSize();
}
void InventoryWindow::logic()
@@ -157,17 +158,7 @@ void InventoryWindow::mouseClicked(gcn::MouseEvent &event)
}
}
-void InventoryWindow::mouseDragged(gcn::MouseEvent &event)
-{
- int tmpWidth = getWidth(), tmpHeight = getHeight();
- Window::mouseDragged(event);
- if (getWidth() != tmpWidth || getHeight() != tmpHeight)
- {
- updateWidgets();
- }
-}
-
-void InventoryWindow::updateWidgets()
+void InventoryWindow::updateContentSize()
{
gcn::Rectangle area = getChildrenArea();
int width = area.width;
@@ -213,14 +204,3 @@ Item* InventoryWindow::getItem()
return mItems->getItem();
}
-void InventoryWindow::loadWindowState()
-{
- Window::loadWindowState();
- updateWidgets();
-}
-
-void InventoryWindow::resetToDefaultSize()
-{
- Window::resetToDefaultSize();
- updateWidgets();
-}
diff --git a/src/gui/inventorywindow.h b/src/gui/inventorywindow.h
index 5ee89fef..b153bb39 100644
--- a/src/gui/inventorywindow.h
+++ b/src/gui/inventorywindow.h
@@ -59,14 +59,8 @@ class InventoryWindow : public Window, gcn::ActionListener, SelectionListener
void mouseClicked(gcn::MouseEvent &event);
- void mouseDragged(gcn::MouseEvent &event);
-
Item* getItem();
- void loadWindowState();
-
- void resetToDefaultSize();
-
/**
* Updates labels to currently selected item.
*
@@ -74,11 +68,11 @@ class InventoryWindow : public Window, gcn::ActionListener, SelectionListener
*/
void selectionChanged(const SelectionEvent &event);
+ void updateContentSize(); /**< Updates widgets size/position. */
+
private:
void updateButtons(); /**< Updates button states. */
- void updateWidgets(); /**< Updates widgets size/position. */
-
ItemContainer *mItems;
gcn::Button *mUseButton, *mDropButton;
diff --git a/src/gui/minimap.cpp b/src/gui/minimap.cpp
index 03a37e29..89e7eadd 100644
--- a/src/gui/minimap.cpp
+++ b/src/gui/minimap.cpp
@@ -36,7 +36,7 @@ Minimap::Minimap():
mMapImage(NULL)
{
setDefaultSize(5, 25, 100, 100);
- loadWindowState();
+ loadWindowState("MiniMap");
}
Minimap::~Minimap()
diff --git a/src/gui/popupmenu.cpp b/src/gui/popupmenu.cpp
index 9b1ce409..65162d35 100644
--- a/src/gui/popupmenu.cpp
+++ b/src/gui/popupmenu.cpp
@@ -55,7 +55,6 @@ PopupMenu::PopupMenu():
{
setResizable(false);
setTitleBarHeight(0);
- mShowTitle = false;
mBrowserBox = new BrowserBox();
mBrowserBox->setPosition(4, 4);
diff --git a/src/gui/skill.cpp b/src/gui/skill.cpp
index c9babda2..884b3744 100644
--- a/src/gui/skill.cpp
+++ b/src/gui/skill.cpp
@@ -63,7 +63,6 @@ const char *skill_db[] = {
SkillDialog::SkillDialog():
Window("Skills")
{
- setWindowName("Skills");
setDefaultSize(windowContainer->getWidth() - 255, 25, 240, 240);
mSkillListBox = new ListBox(this);
@@ -84,7 +83,7 @@ SkillDialog::SkillDialog():
mSkillListBox->addActionListener(this);
setLocationRelativeTo(getParent());
- loadWindowState();
+ loadWindowState("Skills");
}
SkillDialog::~SkillDialog()
diff --git a/src/gui/status.cpp b/src/gui/status.cpp
index c7cb80c3..8be019dd 100644
--- a/src/gui/status.cpp
+++ b/src/gui/status.cpp
@@ -37,11 +37,10 @@ StatusWindow::StatusWindow(LocalPlayer *player):
Window(player->getName()),
mPlayer(player)
{
- setWindowName("Status");
setResizable(true);
setDefaultSize((windowContainer->getWidth() - 365) / 2,
(windowContainer->getHeight() - 255) / 2, 365, 280);
- loadWindowState();
+ loadWindowState("Status");
// ----------------------
// Status Part
diff --git a/src/gui/trade.cpp b/src/gui/trade.cpp
index 337bd7ea..724f6d5b 100644
--- a/src/gui/trade.cpp
+++ b/src/gui/trade.cpp
@@ -50,7 +50,6 @@ TradeWindow::TradeWindow():
mMyInventory(new Inventory()),
mPartnerInventory(new Inventory())
{
- setWindowName("Trade");
setDefaultSize(115, 197, 332, 209);
mAddButton = new Button("Add", "add", this);
diff --git a/src/gui/window.cpp b/src/gui/window.cpp
index 5c39c04e..3e6e1bac 100644
--- a/src/gui/window.cpp
+++ b/src/gui/window.cpp
@@ -58,8 +58,6 @@ Window::Window(const std::string& caption, bool modal, Window *parent):
gcn::Window(caption),
mGrip(0),
mParent(parent),
- mWindowName("window"),
- mShowTitle(true),
mModal(modal),
mResizable(false),
mMouseResize(0),
@@ -122,16 +120,19 @@ Window::Window(const std::string& caption, bool modal, Window *parent):
Window::~Window()
{
logger->log("Window::~Window(\"%s\")", getCaption().c_str());
- const std::string &name = mWindowName;
- // Saving X, Y and Width and Height for resizables in the config
- config.setValue(name + "WinX", getX());
- config.setValue(name + "WinY", getY());
-
- if (mResizable)
+ std::string const &name = mConfigName;
+ if (!name.empty())
{
- config.setValue(name + "WinWidth", getWidth());
- config.setValue(name + "WinHeight", getHeight());
+ // Saving X, Y and Width and Height for resizables in the config
+ config.setValue(name + "WinX", getX());
+ config.setValue(name + "WinY", getY());
+
+ if (mResizable)
+ {
+ config.setValue(name + "WinWidth", getWidth());
+ config.setValue(name + "WinHeight", getHeight());
+ }
}
instances--;
@@ -170,7 +171,7 @@ void Window::draw(gcn::Graphics *graphics)
g->drawImageRect(0, 0, getWidth(), getHeight(), border);
// Draw title
- if (mShowTitle)
+ if (getTitleBarHeight())
{
graphics->setFont(getFont());
graphics->drawText(getCaption(), 7, 5, gcn::Graphics::LEFT);
@@ -428,13 +429,13 @@ void Window::mouseDragged(gcn::MouseEvent &event)
setDimension(newDim);
const gcn::Rectangle area = getChildrenArea();
mChrome->setSize(area.width, area.height);
+ updateContentSize();
}
}
-void
-Window::loadWindowState()
+void Window::loadWindowState(std::string const &name)
{
- const std::string &name = mWindowName;
+ mConfigName = name;
setPosition((int) config.getValue(name + "WinX", getX()),
(int) config.getValue(name + "WinY", getY()));
@@ -465,4 +466,5 @@ void Window::resetToDefaultSize()
{
setPosition(mDefaultX, mDefaultY);
setContentSize(mDefaultWidth, mDefaultHeight);
+ updateContentSize();
}
diff --git a/src/gui/window.h b/src/gui/window.h
index 03248908..1ba23fb2 100644
--- a/src/gui/window.h
+++ b/src/gui/window.h
@@ -99,6 +99,12 @@ class Window : public gcn::Window
void setContentSize(int width, int height);
/**
+ * Called when either the user or resetToDefaultSize resizes the
+ * windows, so that the windows can manage its widgets.
+ */
+ virtual void updateContentSize() {}
+
+ /**
* Sets the width of this window.
*/
void setWidth(int width);
@@ -193,39 +199,27 @@ class Window : public gcn::Window
void mouseDragged(gcn::MouseEvent &event);
/**
- * Sets the name of the window. This is not the window title.
- */
- void
- setWindowName(const std::string &name) { mWindowName = name; }
-
- /**
- * Returns the name of the window. This is not the window title.
- */
- const std::string&
- getWindowName() { return mWindowName; }
-
- /**
* Read the x, y, and width and height for resizables in the config
- * based on the name of the window.
+ * based on the given string.
* That function let the values set with set{X, Y, Height, width}()
* if no config value is found.
* Don't forget to set these default values and resizable before
* calling this function.
*/
- virtual void loadWindowState();
+ void loadWindowState(std::string const &);
/**
* Set the default win pos and size.
* (which can be different of the actual ones.)
*/
- virtual void setDefaultSize(int defaultX, int defaultY,
- int defaultWidth, int defaultHeight);
+ void setDefaultSize(int defaultX, int defaultY,
+ int defaultWidth, int defaultHeight);
/**
* Reset the win pos and size to default.
* Don't forget to set defaults first.
*/
- virtual void resetToDefaultSize();
+ void resetToDefaultSize();
enum ResizeHandles
{
@@ -235,12 +229,14 @@ class Window : public gcn::Window
LEFT = 0x08
};
- protected:
+ /** The window container windows add themselves to. */
+ static WindowContainer *windowContainer;
+
+ private:
GCContainer *mChrome; /**< Contained container */
ResizeGrip *mGrip; /**< Resize grip */
Window *mParent; /**< The parent window */
- std::string mWindowName; /**< Name of the window */
- bool mShowTitle; /**< Window has a title bar */
+ std::string mConfigName; /**< Name used for saving window-related data */
bool mModal; /**< Window is modal */
bool mResizable; /**< Window can be resized */
int mMouseResize; /**< Window is being resized */
@@ -254,9 +250,6 @@ class Window : public gcn::Window
int mDefaultWidth; /**< Default window width */
int mDefaultHeight; /**< Default window height */
- /** The window container windows add themselves to. */
- static WindowContainer *windowContainer;
-
/**
* The config listener that listens to changes relevant to all windows.
*/