From 5fa3f62d0d6d9cbffeef0f6a2497aae023dbadcf Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Sun, 8 Mar 2009 18:40:48 -0600 Subject: Add an interface for eAthena's storage system --- src/gui/window.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'src/gui/window.h') diff --git a/src/gui/window.h b/src/gui/window.h index 0a0f4be9..a4f56e05 100644 --- a/src/gui/window.h +++ b/src/gui/window.h @@ -63,7 +63,7 @@ class Window : public gcn::Window, gcn::WidgetListener * @param skin The location where the window's skin XML can be found. */ Window(const std::string &caption = "Window", bool modal = false, - Window *parent = NULL, const std::string &skin = "graphics/gui/gui.xml"); + Window *parent = NULL, const std::string &skin = "graphics/gui/gui.xml"); /** * Destructor. Deletes all the added widgets. @@ -153,8 +153,7 @@ class Window : public gcn::Window, gcn::WidgetListener /** * Sets flag to show a title or not. */ - void setShowTitle(bool flag) - { mShowTitle = flag; } + void setShowTitle(bool flag) { mShowTitle = flag; } /** * Sets whether the window is sticky. A sticky window will not have -- cgit v1.2.3-70-g09d2 From 40883938ceb60b0999f9b693dadbe2239e83f139 Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Mon, 9 Mar 2009 01:23:14 -0600 Subject: Got rid of an ugly and unified interface breaking cancel button in favor of adding overridable close functionality to the Window class. Now, if you need a close button, but need to do something different, or in addition to the Window close functionality, you can override it and do that action. Signed-off-by: Ira Rice --- src/gui/storagewindow.cpp | 9 ++------- src/gui/storagewindow.h | 2 +- src/gui/window.cpp | 7 ++++++- src/gui/window.h | 2 ++ src/inventory.cpp | 2 +- 5 files changed, 12 insertions(+), 10 deletions(-) (limited to 'src/gui/window.h') diff --git a/src/gui/storagewindow.cpp b/src/gui/storagewindow.cpp index 856f9166..d3bc7ef8 100644 --- a/src/gui/storagewindow.cpp +++ b/src/gui/storagewindow.cpp @@ -59,11 +59,11 @@ StorageWindow::StorageWindow(Network *network, int invSize): { setWindowName("Storage"); setResizable(true); + setCloseButton(true); // If you adjust these defaults, don't forget to adjust the trade window's. setDefaultSize(115, 25, 375, 300); - mCancelButton = new Button(_("Close"), "close", this); mStoreButton = new Button(_("Store"), "store", this); mRetrieveButton = new Button(_("Retrieve"), "retrieve", this); @@ -85,7 +85,6 @@ StorageWindow::StorageWindow(Network *network, int invSize): place(0, 0, mSlotsLabel).setPadding(3); place(1, 0, mSlotsBar, 3); place(0, 1, mInvenScroll, 4, 4); - place(0, 5, mCancelButton); place(2, 5, mStoreButton); place(3, 5, mRetrieveButton); @@ -121,11 +120,7 @@ void StorageWindow::logic() void StorageWindow::action(const gcn::ActionEvent &event) { - if (event.getId() == "close") - { - close(); - } - else if (event.getId() == "store") + if (event.getId() == "store") { Item *item = inventoryWindow->getSelectedItem(); diff --git a/src/gui/storagewindow.h b/src/gui/storagewindow.h index 23142ac1..86451bfe 100644 --- a/src/gui/storagewindow.h +++ b/src/gui/storagewindow.h @@ -88,7 +88,7 @@ class StorageWindow : public Window, gcn::ActionListener, gcn::SelectionListener std::string mSlots; std::string mUsedSlots; - gcn::Button *mCancelButton, *mStoreButton, *mRetrieveButton; + gcn::Button *mStoreButton, *mRetrieveButton; gcn::ScrollArea *mInvenScroll; gcn::Label *mSlotsLabel; diff --git a/src/gui/window.cpp b/src/gui/window.cpp index 0869368d..2b422f86 100644 --- a/src/gui/window.cpp +++ b/src/gui/window.cpp @@ -328,7 +328,7 @@ void Window::mousePressed(gcn::MouseEvent &event) if (closeButtonRect.isPointInRect(x, y)) { - setVisible(false); + close(); } } @@ -337,6 +337,11 @@ void Window::mousePressed(gcn::MouseEvent &event) } } +void Window::close() +{ + setVisible(false); +} + void Window::mouseReleased(gcn::MouseEvent &event) { if (mGrip && mouseResize) diff --git a/src/gui/window.h b/src/gui/window.h index a4f56e05..3a92ac17 100644 --- a/src/gui/window.h +++ b/src/gui/window.h @@ -276,6 +276,8 @@ class Window : public gcn::Window, gcn::WidgetListener */ ContainerPlacer getPlacer(int x, int y); + virtual void close(); + protected: /** The window container windows add themselves to. */ static WindowContainer *windowContainer; diff --git a/src/inventory.cpp b/src/inventory.cpp index d72e0e4a..3d1a4786 100644 --- a/src/inventory.cpp +++ b/src/inventory.cpp @@ -128,7 +128,7 @@ bool Inventory::contains(Item *item) const int Inventory::getFreeSlot() const { - Item **i = std::find_if(mItems, mItems + mSize, + Item **i = std::find_if(mItems + mOffset, mItems + mSize, std::not1(SlotUsed())); return (i == mItems + mSize) ? -1 : (i - mItems); } -- cgit v1.2.3-70-g09d2 From 443a10db52e909c4c2a33543795ec8837547e973 Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Tue, 10 Mar 2009 08:11:48 -0600 Subject: Made it so that when windows load previous states, they are never smaller than the minimum width and height (a check that should have been enforced in the first place), as well as modified the NPC list and text dialogs to remember where they were when they were moved or resized last. Signed-off-by: Ira Rice --- src/gui/npc_text.cpp | 11 +++++++++-- src/gui/npc_text.h | 13 +++++++++++++ src/gui/npclistdialog.cpp | 6 +++++- src/gui/npclistdialog.h | 3 ++- src/gui/window.cpp | 41 +++++++++++++++++++++++++---------------- src/gui/window.h | 6 ++++++ src/net/npchandler.cpp | 3 +-- 7 files changed, 61 insertions(+), 22 deletions(-) (limited to 'src/gui/window.h') diff --git a/src/gui/npc_text.cpp b/src/gui/npc_text.cpp index ec8a4b6e..58aa0c5e 100644 --- a/src/gui/npc_text.cpp +++ b/src/gui/npc_text.cpp @@ -35,10 +35,10 @@ #include "../utils/gettext.h" NpcTextDialog::NpcTextDialog(Network *network): - Window(_("NPC")), mNetwork(network) + Window("NPC"), mNetwork(network) { + setWindowName(_("NPC")); setResizable(true); - setCloseButton(true); setMinWidth(200); setMinHeight(150); @@ -89,6 +89,7 @@ void NpcTextDialog::action(const gcn::ActionEvent &event) { clearText(); setVisible(false); + saveWindowState(); if (current_npc) nextDialog(); @@ -118,3 +119,9 @@ void NpcTextDialog::widgetResized(const gcn::Event &event) setText(mText); } +void NpcTextDialog::requestFocus() +{ + loadWindowState(); + setVisible(true); +} + diff --git a/src/gui/npc_text.h b/src/gui/npc_text.h index 615902db..f01e3602 100644 --- a/src/gui/npc_text.h +++ b/src/gui/npc_text.h @@ -74,10 +74,23 @@ class NpcTextDialog : public Window, public gcn::ActionListener */ void addText(const std::string &string); + /** + * Notifies the server that the client has performed a next action. + */ void nextDialog(int npcID = current_npc); + /** + * Notifies the server that the client has performed a close action. + */ void closeDialog(int npcID = current_npc); + /** + * Initializes window width to the last known setting. Since the dialog + * doesn't need any extra focus outside of what it's given in the Game + * class, this is all it does for now. + */ + void requestFocus(); + /** * Called when resizing the window. * diff --git a/src/gui/npclistdialog.cpp b/src/gui/npclistdialog.cpp index c639411d..f049cba7 100644 --- a/src/gui/npclistdialog.cpp +++ b/src/gui/npclistdialog.cpp @@ -37,8 +37,9 @@ #include "../utils/gettext.h" NpcListDialog::NpcListDialog(Network *network): - Window(_("NPC")), mNetwork(network) + Window("NPC"), mNetwork(network) { + setWindowName(_("NPC")); setResizable(true); setMinWidth(200); @@ -114,6 +115,7 @@ void NpcListDialog::action(const gcn::ActionEvent &event) if (choice) { setVisible(false); + saveWindowState(); reset(); MessageOut outMsg(mNetwork); @@ -129,4 +131,6 @@ void NpcListDialog::requestFocus() { mItemList->requestFocus(); mItemList->setSelected(0); + loadWindowState(); + setVisible(true); } diff --git a/src/gui/npclistdialog.h b/src/gui/npclistdialog.h index 0a0e9813..e3cf375b 100644 --- a/src/gui/npclistdialog.h +++ b/src/gui/npclistdialog.h @@ -76,7 +76,8 @@ class NpcListDialog : public Window, public gcn::ActionListener, void reset(); /** - * Requests the listbox to take focus for input. + * Requests the listbox to take focus for input and sets window width + * to the last known setting. */ void requestFocus(); diff --git a/src/gui/window.cpp b/src/gui/window.cpp index 2b422f86..8faf63a0 100644 --- a/src/gui/window.cpp +++ b/src/gui/window.cpp @@ -118,21 +118,8 @@ Window::Window(const std::string& caption, bool modal, Window *parent, const std 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 - if (!name.empty()) - { - config.setValue(name + "WinX", getX()); - config.setValue(name + "WinY", getY()); - config.setValue(name + "Visible", isVisible()); - - if (mGrip) - { - config.setValue(name + "WinWidth", getWidth()); - config.setValue(name + "WinHeight", getHeight()); - } - } + saveWindowState(); delete mLayout; @@ -478,8 +465,13 @@ void Window::loadWindowState() if (mGrip) { - setSize((int) config.getValue(name + "WinWidth", mDefaultWidth), - (int) config.getValue(name + "WinHeight", mDefaultHeight)); + const int width = (int) config.getValue(name + "WinWidth", + mDefaultWidth); + const int height = (int) config.getValue(name + "WinHeight", + mDefaultHeight); + + setSize(width < getMinWidth() ? getMinWidth() : width, + height < getMinHeight() ? getMinHeight() : height); } else { @@ -487,6 +479,23 @@ void Window::loadWindowState() } } +void Window::saveWindowState() +{ + // Saving X, Y and Width and Height for resizables in the config + if (!mWindowName.empty()) + { + config.setValue(mWindowName + "WinX", getX()); + config.setValue(mWindowName + "WinY", getY()); + config.setValue(mWindowName + "Visible", isVisible()); + + if (mGrip) + { + config.setValue(mWindowName + "WinWidth", getWidth()); + config.setValue(mWindowName + "WinHeight", getHeight()); + } + } +} + void Window::setDefaultSize(int defaultX, int defaultY, int defaultWidth, int defaultHeight) { diff --git a/src/gui/window.h b/src/gui/window.h index 3a92ac17..bf15dedb 100644 --- a/src/gui/window.h +++ b/src/gui/window.h @@ -233,6 +233,12 @@ class Window : public gcn::Window, gcn::WidgetListener */ void loadWindowState(); + /** + * Saves the window state so that when the window is reloaded, it'll + * maintain its previous state and location. + */ + void saveWindowState(); + /** * Set the default win pos and size. * (which can be different of the actual ones.) diff --git a/src/net/npchandler.cpp b/src/net/npchandler.cpp index 41af4467..60a77af1 100644 --- a/src/net/npchandler.cpp +++ b/src/net/npchandler.cpp @@ -60,7 +60,6 @@ void NPCHandler::handleMessage(MessageIn *msg) current_npc = msg->readInt32(); player_node->setAction(LocalPlayer::STAND); npcListDialog->parseItems(msg->readString(msg->getLength() - 8)); - npcListDialog->setVisible(true); npcListDialog->requestFocus(); break; @@ -69,7 +68,7 @@ void NPCHandler::handleMessage(MessageIn *msg) current_npc = msg->readInt32(); player_node->setAction(LocalPlayer::STAND); npcTextDialog->addText(msg->readString(msg->getLength() - 8)); - npcTextDialog->setVisible(true); + npcTextDialog->requestFocus(); break; case SMSG_NPC_CLOSE: -- cgit v1.2.3-70-g09d2 From 58ee835c3763e7bf088fa6c7e31dda1d687589cc Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Tue, 10 Mar 2009 11:50:27 -0600 Subject: Extended window layout to take relative positions, as well as offsets to that position. This makes it so that when resolutions are changed, the default locations stay relative to the window's position, and not the 800x600 screen resolution. Signed-off-by: Ira Rice --- src/graphics.cpp | 30 ++++++-------- src/graphics.h | 13 ++++++ src/gui/buy.cpp | 3 +- src/gui/buysell.cpp | 1 - src/gui/chat.cpp | 2 +- src/gui/debugwindow.cpp | 2 +- src/gui/emotewindow.cpp | 2 +- src/gui/equipmentwindow.cpp | 2 +- src/gui/inventorywindow.cpp | 3 +- src/gui/npc_text.cpp | 3 +- src/gui/npcintegerdialog.cpp | 7 +++- src/gui/npclistdialog.cpp | 3 +- src/gui/npcstringdialog.cpp | 7 +++- src/gui/recorder.cpp | 8 ++-- src/gui/sell.cpp | 3 +- src/gui/shortcutwindow.cpp | 13 ++---- src/gui/skill.cpp | 2 +- src/gui/status.cpp | 3 +- src/gui/storagewindow.cpp | 3 +- src/gui/trade.cpp | 2 +- src/gui/window.cpp | 99 ++++++++++++++++++++++++++++++++++++++++++++ src/gui/window.h | 16 ++++++- src/openglgraphics.cpp | 42 ++++++++++--------- 23 files changed, 194 insertions(+), 75 deletions(-) (limited to 'src/gui/window.h') diff --git a/src/graphics.cpp b/src/graphics.cpp index 3c507f4b..48fd1340 100644 --- a/src/graphics.cpp +++ b/src/graphics.cpp @@ -50,30 +50,25 @@ bool Graphics::setVideoMode(int w, int h, int bpp, bool fs, bool hwaccel) mFullscreen = fs; mHWAccel = hwaccel; - if (fs) { + if (fs) displayFlags |= SDL_FULLSCREEN; - } - if (hwaccel) { + if (hwaccel) displayFlags |= SDL_HWSURFACE | SDL_DOUBLEBUF; - } else { + else displayFlags |= SDL_SWSURFACE; - } mScreen = SDL_SetVideoMode(w, h, bpp, displayFlags); - if (!mScreen) { + if (!mScreen) return false; - } char videoDriverName[64]; - if (SDL_VideoDriverName(videoDriverName, 64)) { + if (SDL_VideoDriverName(videoDriverName, 64)) logger->log("Using video driver: %s", videoDriverName); - } - else { + else logger->log("Using video driver: unknown"); - } const SDL_VideoInfo *vi = SDL_GetVideoInfo(); @@ -104,9 +99,8 @@ bool Graphics::setVideoMode(int w, int h, int bpp, bool fs, bool hwaccel) bool Graphics::setFullscreen(bool fs) { - if (mFullscreen == fs) { + if (mFullscreen == fs) return true; - } return setVideoMode(mScreen->w, mScreen->h, mScreen->format->BitsPerPixel, fs, mHWAccel); @@ -128,7 +122,7 @@ bool Graphics::drawImage(Image *image, int x, int y) } bool Graphics::drawImage(Image *image, int srcX, int srcY, int dstX, int dstY, - int width, int height, bool) + int width, int height, bool) { // Check that preconditions for blitting are met. if (!mScreen || !image || !image->mImage) return false; @@ -150,7 +144,7 @@ bool Graphics::drawImage(Image *image, int srcX, int srcY, int dstX, int dstY, } void Graphics::drawImage(gcn::Image const *image, int srcX, int srcY, - int dstX, int dstY, int width, int height) + int dstX, int dstY, int width, int height) { ProxyImage const *srcImage = dynamic_cast< ProxyImage const * >(image); @@ -167,8 +161,10 @@ void Graphics::drawImagePattern(Image *image, int x, int y, int w, int h) int px = 0; // X position on pattern plane int py = 0; // Y position on pattern plane - while (py < h) { - while (px < w) { + while (py < h) + { + while (px < w) + { int dw = (px + iw >= w) ? w - px : iw; int dh = (py + ih >= h) ? h - py : ih; drawImage(image, 0, 0, x + px, y + py, dw, dh); diff --git a/src/graphics.h b/src/graphics.h index 3ad3b85c..ec0b5e9c 100644 --- a/src/graphics.h +++ b/src/graphics.h @@ -49,6 +49,19 @@ struct SDL_Surface; */ struct ImageRect { + enum ImagePosition + { + UPPER_LEFT = 0, + UPPER_CENTER = 1, + UPPER_RIGHT = 2, + LEFT = 3, + CENTER = 4, + RIGHT = 5, + LOWER_LEFT = 6, + LOWER_CENTER = 7, + LOWER_RIGHT = 8, + }; + Image *grid[9]; }; diff --git a/src/gui/buy.cpp b/src/gui/buy.cpp index 5a57dcc6..2b5aeeb7 100644 --- a/src/gui/buy.cpp +++ b/src/gui/buy.cpp @@ -47,7 +47,7 @@ BuyDialog::BuyDialog(Network *network): setResizable(true); setMinWidth(260); setMinHeight(230); - setDefaultSize(0, 0, 260, 230); + setDefaultSize(260, 230, ImageRect::CENTER); mShopItems = new ShopItems; @@ -90,7 +90,6 @@ BuyDialog::BuyDialog(Network *network): layout.setRowHeight(0, Layout::AUTO_SET); loadWindowState(); - setLocationRelativeTo(getParent()); } BuyDialog::~BuyDialog() diff --git a/src/gui/buysell.cpp b/src/gui/buysell.cpp index dc7deef6..f7684670 100644 --- a/src/gui/buysell.cpp +++ b/src/gui/buysell.cpp @@ -50,7 +50,6 @@ BuySellDialog::BuySellDialog(Network *network): buyButton->requestFocus(); setContentSize(x, 2 * y + buyButton->getHeight()); - setLocationRelativeTo(getParent()); requestFocus(); } diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp index 5cf8b739..098d4e46 100644 --- a/src/gui/chat.cpp +++ b/src/gui/chat.cpp @@ -55,7 +55,7 @@ Window(""), mNetwork(network), mTmpVisible(false) setWindowName(_("Chat")); setResizable(true); - setDefaultSize(0, windowContainer->getHeight() - 123, 600, 123); + setDefaultSize(600, 123, ImageRect::LOWER_LEFT); setMinWidth(150); setMinHeight(90); diff --git a/src/gui/debugwindow.cpp b/src/gui/debugwindow.cpp index dafd604a..71855977 100644 --- a/src/gui/debugwindow.cpp +++ b/src/gui/debugwindow.cpp @@ -41,7 +41,7 @@ DebugWindow::DebugWindow(): setResizable(true); setCloseButton(true); - setDefaultSize(0, 0, 400, 60); + setDefaultSize(400, 60, ImageRect::CENTER); mFPSLabel = new gcn::Label("0 FPS"); mMusicFileLabel = new gcn::Label("Music: "); diff --git a/src/gui/emotewindow.cpp b/src/gui/emotewindow.cpp index 30129941..77168993 100644 --- a/src/gui/emotewindow.cpp +++ b/src/gui/emotewindow.cpp @@ -40,7 +40,7 @@ EmoteWindow::EmoteWindow(): setCloseButton(true); setMinWidth(80); setMinHeight(130); - setDefaultSize(115, 25, 322, 200); + setDefaultSize(322, 200, ImageRect::CENTER); mUseButton = new Button(_("Use"), "use", this); diff --git a/src/gui/equipmentwindow.cpp b/src/gui/equipmentwindow.cpp index 27ea38ff..0d2097f8 100644 --- a/src/gui/equipmentwindow.cpp +++ b/src/gui/equipmentwindow.cpp @@ -71,7 +71,7 @@ EquipmentWindow::EquipmentWindow(): setWindowName("Equipment"); setCloseButton(true); - setDefaultSize(5, 195, 180, 300); + setDefaultSize(180, 300, ImageRect::CENTER); loadWindowState(); mUnequip = new Button(_("Unequip"), "unequip", this); diff --git a/src/gui/inventorywindow.cpp b/src/gui/inventorywindow.cpp index 226b3178..7e75411e 100644 --- a/src/gui/inventorywindow.cpp +++ b/src/gui/inventorywindow.cpp @@ -57,7 +57,7 @@ InventoryWindow::InventoryWindow(int invSize): setCloseButton(true); // If you adjust these defaults, don't forget to adjust the trade window's. - setDefaultSize(115, 25, 375, 300); + setDefaultSize(375, 300, ImageRect::CENTER); std::string longestUseString = getFont()->getWidth(_("Equip")) > getFont()->getWidth(_("Use")) ? @@ -103,7 +103,6 @@ InventoryWindow::InventoryWindow(int invSize): layout.setRowHeight(0, mDropButton->getHeight()); loadWindowState(); - setLocationRelativeTo(getParent()); } InventoryWindow::~InventoryWindow() diff --git a/src/gui/npc_text.cpp b/src/gui/npc_text.cpp index 58aa0c5e..f524f8ea 100644 --- a/src/gui/npc_text.cpp +++ b/src/gui/npc_text.cpp @@ -43,7 +43,7 @@ NpcTextDialog::NpcTextDialog(Network *network): setMinWidth(200); setMinHeight(150); - setDefaultSize(0, 0, 260, 200); + setDefaultSize(260, 200, ImageRect::CENTER); mTextBox = new TextBox; mTextBox->setEditable(false); @@ -63,7 +63,6 @@ NpcTextDialog::NpcTextDialog(Network *network): layout.setRowHeight(0, Layout::AUTO_SET); loadWindowState(); - setLocationRelativeTo(getParent()); } void NpcTextDialog::setText(const std::string &text) diff --git a/src/gui/npcintegerdialog.cpp b/src/gui/npcintegerdialog.cpp index 132a7608..5b3e05aa 100644 --- a/src/gui/npcintegerdialog.cpp +++ b/src/gui/npcintegerdialog.cpp @@ -37,6 +37,9 @@ NpcIntegerDialog::NpcIntegerDialog(Network *network): Window(_("NPC Number Request")), mNetwork(network) { mValueField = new IntTextField(); + setWindowName("NPCInput"); + + setDefaultSize(175, 75, ImageRect::CENTER); mDecButton = new Button("-", "decvalue", this); mIncButton = new Button("+", "incvalue", this); @@ -58,9 +61,9 @@ NpcIntegerDialog::NpcIntegerDialog(Network *network): place(0, 0, resetButton); place(2, 0, cancelButton); place(3, 0, okButton); - reflowLayout(175, 0); + //reflowLayout(175, 0); - setLocationRelativeTo(getParent()); + loadWindowState(); } void NpcIntegerDialog::setRange(const int min, const int max) diff --git a/src/gui/npclistdialog.cpp b/src/gui/npclistdialog.cpp index f049cba7..505912ac 100644 --- a/src/gui/npclistdialog.cpp +++ b/src/gui/npclistdialog.cpp @@ -45,7 +45,7 @@ NpcListDialog::NpcListDialog(Network *network): setMinWidth(200); setMinHeight(150); - setDefaultSize(0, 0, 260, 200); + setDefaultSize(260, 200, ImageRect::CENTER); mItemList = new ListBox(this); mItemList->setWrappingEnabled(true); @@ -66,7 +66,6 @@ NpcListDialog::NpcListDialog(Network *network): layout.setRowHeight(0, Layout::AUTO_SET); loadWindowState(); - setLocationRelativeTo(getParent()); } int NpcListDialog::getNumberOfElements() diff --git a/src/gui/npcstringdialog.cpp b/src/gui/npcstringdialog.cpp index f2c7434c..58a5c0c8 100644 --- a/src/gui/npcstringdialog.cpp +++ b/src/gui/npcstringdialog.cpp @@ -36,17 +36,20 @@ NpcStringDialog::NpcStringDialog(Network *network): Window(_("NPC Text Request")), mNetwork(network) { + setWindowName("NPCInput"); mValueField = new TextField(""); + setDefaultSize(175, 75, ImageRect::CENTER); + okButton = new Button(_("OK"), "ok", this); cancelButton = new Button(_("Cancel"), "cancel", this); place(0, 0, mValueField, 3); place(1, 1, cancelButton); place(2, 1, okButton); - reflowLayout(175, 0); + //reflowLayout(175, 0); - setLocationRelativeTo(getParent()); + loadWindowState(); } std::string NpcStringDialog::getValue() diff --git a/src/gui/recorder.cpp b/src/gui/recorder.cpp index ff8825ef..9320e020 100644 --- a/src/gui/recorder.cpp +++ b/src/gui/recorder.cpp @@ -40,9 +40,11 @@ Recorder::Recorder(ChatWindow *chat, const std::string &title, mChat = chat; Button *button = new Button(buttonTxt, "activate", this); - setDefaultSize(0, windowContainer->getHeight() - 123 - button->getHeight() - - offsetY, button->getWidth() + offsetX, button->getHeight() + - offsetY); + + // 123 is the default chat window height. If you change this in Chat, please + // change it here as well + setDefaultSize(button->getWidth() + offsetX, button->getHeight() + + offsetY, ImageRect::LOWER_LEFT, 0, 123); place(0, 0, button); diff --git a/src/gui/sell.cpp b/src/gui/sell.cpp index 154d1a57..397e29a6 100644 --- a/src/gui/sell.cpp +++ b/src/gui/sell.cpp @@ -48,7 +48,7 @@ SellDialog::SellDialog(Network *network): setResizable(true); setMinWidth(260); setMinHeight(230); - setDefaultSize(0, 0, 260, 230); + setDefaultSize(260, 230, ImageRect::CENTER); // Create a ShopItems instance, that is aware of duplicate entries. mShopItems = new ShopItems(true); @@ -94,7 +94,6 @@ SellDialog::SellDialog(Network *network): layout.setRowHeight(0, Layout::AUTO_SET); loadWindowState(); - setLocationRelativeTo(getParent()); } SellDialog::~SellDialog() diff --git a/src/gui/shortcutwindow.cpp b/src/gui/shortcutwindow.cpp index ee32ca70..c2df1f9c 100644 --- a/src/gui/shortcutwindow.cpp +++ b/src/gui/shortcutwindow.cpp @@ -40,22 +40,17 @@ ShortcutWindow::ShortcutWindow(const char *title, ShortcutContainer *content) mItems = content; - mInstances++; - const int border = SCROLL_PADDING * 2 + getPadding() * 2; setMinWidth(mItems->getBoxWidth() + border); setMinHeight(mItems->getBoxHeight() + border); setMaxWidth(mItems->getBoxWidth() * mItems->getMaxItems() + border); setMaxHeight(mItems->getBoxHeight() * mItems->getMaxItems() + border); - const int width = (int) config.getValue("screenwidth", 800); - const int height = (int) config.getValue("screenheight", 600); + setDefaultSize(mItems->getBoxWidth() + border, (mItems->getBoxHeight() * + mItems->getMaxItems()) + border, ImageRect::LOWER_RIGHT, + mInstances * mItems->getBoxWidth(), 0); - setDefaultSize(width - (mInstances * mItems->getBoxWidth()) - - (mInstances * border), height - (mItems->getBoxHeight() * - mItems->getMaxItems()) - border, mItems->getBoxWidth() + - border, (mItems->getBoxHeight() * mItems->getMaxItems()) + - border); + mInstances++; mScrollArea = new ScrollArea(mItems); mScrollArea->setPosition(SCROLL_PADDING, SCROLL_PADDING); diff --git a/src/gui/skill.cpp b/src/gui/skill.cpp index 42ac4d86..a8250fce 100644 --- a/src/gui/skill.cpp +++ b/src/gui/skill.cpp @@ -135,7 +135,7 @@ SkillDialog::SkillDialog(): setWindowName(_("Skills")); setCloseButton(true); - setDefaultSize(windowContainer->getWidth() - 260, 25, 255, 260); + setDefaultSize(255, 260, ImageRect::CENTER); setMinHeight(50 + mTableModel->getHeight()); setMinWidth(200); diff --git a/src/gui/status.cpp b/src/gui/status.cpp index 6419eabb..e534edb8 100644 --- a/src/gui/status.cpp +++ b/src/gui/status.cpp @@ -41,8 +41,7 @@ StatusWindow::StatusWindow(LocalPlayer *player): { setWindowName(_("Status")); setCloseButton(true); - setDefaultSize((windowContainer->getWidth() - 365) / 2, - (windowContainer->getHeight() - 255) / 2, 400, 345); + setDefaultSize(400, 345, ImageRect::CENTER); // ---------------------- // Status Part diff --git a/src/gui/storagewindow.cpp b/src/gui/storagewindow.cpp index d3bc7ef8..ca7a547f 100644 --- a/src/gui/storagewindow.cpp +++ b/src/gui/storagewindow.cpp @@ -62,7 +62,7 @@ StorageWindow::StorageWindow(Network *network, int invSize): setCloseButton(true); // If you adjust these defaults, don't forget to adjust the trade window's. - setDefaultSize(115, 25, 375, 300); + setDefaultSize(375, 300, ImageRect::CENTER); mStoreButton = new Button(_("Store"), "store", this); mRetrieveButton = new Button(_("Retrieve"), "retrieve", this); @@ -92,7 +92,6 @@ StorageWindow::StorageWindow(Network *network, int invSize): layout.setRowHeight(0, mStoreButton->getHeight()); loadWindowState(); - setLocationRelativeTo(getParent()); } StorageWindow::~StorageWindow() diff --git a/src/gui/trade.cpp b/src/gui/trade.cpp index 76795688..a28ff0f9 100644 --- a/src/gui/trade.cpp +++ b/src/gui/trade.cpp @@ -53,7 +53,7 @@ TradeWindow::TradeWindow(Network *network): mPartnerInventory(new Inventory(INVENTORY_SIZE, 2)) { setWindowName(_("Trade")); - setDefaultSize(115, 227, 342, 209); + setDefaultSize(342, 209, ImageRect::CENTER); setResizable(true); setMinWidth(342); diff --git a/src/gui/window.cpp b/src/gui/window.cpp index 5253dd2e..f1316b4c 100644 --- a/src/gui/window.cpp +++ b/src/gui/window.cpp @@ -220,6 +220,53 @@ void Window::setLocationRelativeTo(gcn::Widget *widget) getY() + (wy + (widget->getHeight() - getHeight()) / 2 - y)); } +void Window::setLocationRelativeTo(ImageRect::ImagePosition position) +{ + int x = 0, y = 0; + + if (position == ImageRect::UPPER_LEFT) + { + } + else if (position == ImageRect::UPPER_CENTER) + { + x = (windowContainer->getWidth() - getWidth()) / 2; + } + else if (position == ImageRect::UPPER_RIGHT) + { + x = windowContainer->getWidth() - getWidth(); + } + else if (position == ImageRect::LEFT) + { + y = (windowContainer->getHeight() - getHeight()) / 2; + } + else if (position == ImageRect::CENTER) + { + x = (windowContainer->getWidth() - getWidth()) / 2; + y = (windowContainer->getHeight() - getHeight()) / 2; + } + else if (position == ImageRect::RIGHT) + { + x = windowContainer->getWidth() - getWidth(); + y = (windowContainer->getHeight() - getHeight()) / 2; + } + else if (position == ImageRect::LOWER_LEFT) + { + y = windowContainer->getHeight() - getHeight(); + } + else if (position == ImageRect::LOWER_CENTER) + { + x = (windowContainer->getWidth() - getWidth()) / 2; + y = windowContainer->getHeight() - getHeight(); + } + else if (position == ImageRect::LOWER_RIGHT) + { + x = windowContainer->getWidth() - getWidth(); + y = windowContainer->getHeight() - getHeight(); + } + + setPosition(x, y); +} + void Window::setMinWidth(unsigned int width) { mMinWinWidth = width; @@ -540,6 +587,58 @@ void Window::setDefaultSize(int defaultX, int defaultY, mDefaultHeight = defaultHeight; } +void Window::setDefaultSize(int defaultWidth, int defaultHeight, + ImageRect::ImagePosition position, + int offsetX, int offsetY) +{ + int x = 0, y = 0; + + if (position == ImageRect::UPPER_LEFT) + { + } + else if (position == ImageRect::UPPER_CENTER) + { + x = (windowContainer->getWidth() - defaultWidth) / 2; + } + else if (position == ImageRect::UPPER_RIGHT) + { + x = windowContainer->getWidth() - defaultWidth; + } + else if (position == ImageRect::LEFT) + { + y = (windowContainer->getHeight() - defaultHeight) / 2; + } + else if (position == ImageRect::CENTER) + { + x = (windowContainer->getWidth() - defaultWidth) / 2; + y = (windowContainer->getHeight() - defaultHeight) / 2; + } + else if (position == ImageRect::RIGHT) + { + x = windowContainer->getWidth() - defaultWidth; + y = (windowContainer->getHeight() - defaultHeight) / 2; + } + else if (position == ImageRect::LOWER_LEFT) + { + y = windowContainer->getHeight() - defaultHeight; + } + else if (position == ImageRect::LOWER_CENTER) + { + x = (windowContainer->getWidth() - defaultWidth) / 2; + y = windowContainer->getHeight() - defaultHeight; + } + else if (position == ImageRect::LOWER_RIGHT) + { + x = windowContainer->getWidth() - defaultWidth; + y = windowContainer->getHeight() - defaultHeight; + } + + mDefaultX = x - offsetX; + mDefaultY = y - offsetY; + mDefaultWidth = defaultWidth; + mDefaultHeight = defaultHeight; +} + void Window::resetToDefaultSize() { setPosition(mDefaultX, mDefaultY); diff --git a/src/gui/window.h b/src/gui/window.h index bf15dedb..c24bde76 100644 --- a/src/gui/window.h +++ b/src/gui/window.h @@ -34,7 +34,6 @@ class ConfigListener; class GCContainer; class ContainerPlacer; class Image; -class ImageRect; class Layout; class LayoutCell; class ResizeGrip; @@ -90,6 +89,11 @@ class Window : public gcn::Window, gcn::WidgetListener */ void setLocationRelativeTo(gcn::Widget *widget); + /** + * Sets the location relative to the given enumerated position. + */ + void setLocationRelativeTo(ImageRect::ImagePosition position); + /** * Sets whether or not the window can be resized. */ @@ -246,6 +250,16 @@ class Window : public gcn::Window, gcn::WidgetListener void setDefaultSize(int defaultX, int defaultY, int defaultWidth, int defaultHeight); + /** + * Set the default win pos and size. + * (which can be different of the actual ones.) + * This version of setDefaultSize sets the window's position based + * on a relative enumerated position, rather than a coordinate position. + */ + void setDefaultSize(int defaultWidth, int defaultHeight, + ImageRect::ImagePosition position, + int offsetx = 0, int offsetY = 0); + /** * Reset the win pos and size to default. Don't forget to set defaults * first. diff --git a/src/openglgraphics.cpp b/src/openglgraphics.cpp index 71ab2fe3..9bd3ab2f 100644 --- a/src/openglgraphics.cpp +++ b/src/openglgraphics.cpp @@ -63,18 +63,17 @@ bool OpenGLGraphics::setVideoMode(int w, int h, int bpp, bool fs, bool hwaccel) mFullscreen = fs; mHWAccel = hwaccel; - if (fs) { + if (fs) displayFlags |= SDL_FULLSCREEN; - } SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); - if (!(mScreen = SDL_SetVideoMode(w, h, bpp, displayFlags))) { + if (!(mScreen = SDL_SetVideoMode(w, h, bpp, displayFlags))) return false; - } #ifdef __APPLE__ - if (mSync) { + if (mSync) + { const GLint VBL = 1; CGLSetParameter(CGLGetCurrentContext(), kCGLCPSwapInterval, &VBL); } @@ -158,9 +157,7 @@ bool OpenGLGraphics::drawImage(Image *image, int srcX, int srcY, glEnd(); if (!useColor) - { glColor4ub(mColor.r, mColor.g, mColor.b, mColor.a); - } return true; } @@ -206,9 +203,8 @@ SDL_Surface* OpenGLGraphics::getScreenshot() w, h, 24, 0xff0000, 0x00ff00, 0x0000ff, 0x000000); - if (SDL_MUSTLOCK(screenshot)) { + if (SDL_MUSTLOCK(screenshot)) SDL_LockSurface(screenshot); - } // Grap the pixel buffer and write it to the SDL surface glPixelStorei(GL_PACK_ALIGNMENT, 1); @@ -230,9 +226,8 @@ SDL_Surface* OpenGLGraphics::getScreenshot() free(buf); - if (SDL_MUSTLOCK(screenshot)) { + if (SDL_MUSTLOCK(screenshot)) SDL_UnlockSurface(screenshot); - } return screenshot; } @@ -242,7 +237,8 @@ bool OpenGLGraphics::pushClipArea(gcn::Rectangle area) int transX = 0; int transY = 0; - if (!mClipStack.empty()) { + if (!mClipStack.empty()) + { transX = -mClipStack.top().xOffset; transY = -mClipStack.top().yOffset; } @@ -267,9 +263,7 @@ void OpenGLGraphics::popClipArea() gcn::Graphics::popClipArea(); if (mClipStack.empty()) - { return; - } glPopMatrix(); glScissor(mClipStack.top().x, @@ -325,8 +319,10 @@ void OpenGLGraphics::setTargetPlane(int width, int height) void OpenGLGraphics::setTexturingAndBlending(bool enable) { - if (enable) { - if (!mTexture) { + if (enable) + { + if (!mTexture) + { glEnable(Image::mTextureType); mTexture = true; } @@ -336,16 +332,22 @@ void OpenGLGraphics::setTexturingAndBlending(bool enable) glEnable(GL_BLEND); mAlpha = true; } - } else { - if (mAlpha && !mColorAlpha) { + } + else + { + if (mAlpha && !mColorAlpha) + { glDisable(GL_BLEND); mAlpha = false; - } else if (!mAlpha && mColorAlpha) { + } + else if (!mAlpha && mColorAlpha) + { glEnable(GL_BLEND); mAlpha = true; } - if (mTexture) { + if (mTexture) + { glDisable(Image::mTextureType); mTexture = false; } -- cgit v1.2.3-70-g09d2 From 0540c611b48fd8dee14066b13755138192b7084b Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Tue, 10 Mar 2009 12:09:53 -0600 Subject: Allow for offsets for the enumerated position version of setLocationRelativeTo as well. Signed-off-by: Ira Rice --- src/gui/window.cpp | 31 +++++++++++++++---------------- src/gui/window.h | 3 ++- 2 files changed, 17 insertions(+), 17 deletions(-) (limited to 'src/gui/window.h') diff --git a/src/gui/window.cpp b/src/gui/window.cpp index f1316b4c..bf1ec01c 100644 --- a/src/gui/window.cpp +++ b/src/gui/window.cpp @@ -220,51 +220,50 @@ void Window::setLocationRelativeTo(gcn::Widget *widget) getY() + (wy + (widget->getHeight() - getHeight()) / 2 - y)); } -void Window::setLocationRelativeTo(ImageRect::ImagePosition position) +void Window::setLocationRelativeTo(ImageRect::ImagePosition position, + int offsetX, int offsetY) { - int x = 0, y = 0; - if (position == ImageRect::UPPER_LEFT) { } else if (position == ImageRect::UPPER_CENTER) { - x = (windowContainer->getWidth() - getWidth()) / 2; + offsetX += (windowContainer->getWidth() - getWidth()) / 2; } else if (position == ImageRect::UPPER_RIGHT) { - x = windowContainer->getWidth() - getWidth(); + offsetX += windowContainer->getWidth() - getWidth(); } else if (position == ImageRect::LEFT) { - y = (windowContainer->getHeight() - getHeight()) / 2; + offsetY += (windowContainer->getHeight() - getHeight()) / 2; } else if (position == ImageRect::CENTER) { - x = (windowContainer->getWidth() - getWidth()) / 2; - y = (windowContainer->getHeight() - getHeight()) / 2; + offsetX += (windowContainer->getWidth() - getWidth()) / 2; + offsetY += (windowContainer->getHeight() - getHeight()) / 2; } else if (position == ImageRect::RIGHT) { - x = windowContainer->getWidth() - getWidth(); - y = (windowContainer->getHeight() - getHeight()) / 2; + offsetX += windowContainer->getWidth() - getWidth(); + offsetY += (windowContainer->getHeight() - getHeight()) / 2; } else if (position == ImageRect::LOWER_LEFT) { - y = windowContainer->getHeight() - getHeight(); + offsetY += windowContainer->getHeight() - getHeight(); } else if (position == ImageRect::LOWER_CENTER) { - x = (windowContainer->getWidth() - getWidth()) / 2; - y = windowContainer->getHeight() - getHeight(); + offsetX += (windowContainer->getWidth() - getWidth()) / 2; + offsetY += windowContainer->getHeight() - getHeight(); } else if (position == ImageRect::LOWER_RIGHT) { - x = windowContainer->getWidth() - getWidth(); - y = windowContainer->getHeight() - getHeight(); + offsetX += windowContainer->getWidth() - getWidth(); + offsetY += windowContainer->getHeight() - getHeight(); } - setPosition(x, y); + setPosition(offsetX, offsetY); } void Window::setMinWidth(unsigned int width) diff --git a/src/gui/window.h b/src/gui/window.h index c24bde76..4fc6c862 100644 --- a/src/gui/window.h +++ b/src/gui/window.h @@ -92,7 +92,8 @@ class Window : public gcn::Window, gcn::WidgetListener /** * Sets the location relative to the given enumerated position. */ - void setLocationRelativeTo(ImageRect::ImagePosition position); + void setLocationRelativeTo(ImageRect::ImagePosition position, + int offsetX = 0, int offsetY = 0); /** * Sets whether or not the window can be resized. -- cgit v1.2.3-70-g09d2 From 265172dc1e7b97611c485752dc10345545c4e296 Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Tue, 10 Mar 2009 17:33:32 -0600 Subject: Introduced in a Skin holder class, to reduce the amount of needed XML skin loads. Signed-off-by: Ira Rice --- src/gui/window.cpp | 97 +++++++++++++++++++++++++++++++++--------------------- src/gui/window.h | 35 ++++++++++++++++++-- 2 files changed, 91 insertions(+), 41 deletions(-) (limited to 'src/gui/window.h') diff --git a/src/gui/window.cpp b/src/gui/window.cpp index bf1ec01c..0e91b68d 100644 --- a/src/gui/window.cpp +++ b/src/gui/window.cpp @@ -40,15 +40,15 @@ #include "../resources/image.h" #include "../resources/resourcemanager.h" +#include "../utils/dtor.h" #include "../utils/xml.h" ConfigListener *Window::windowConfigListener = 0; WindowContainer *Window::windowContainer = 0; int Window::instances = 0; int Window::mouseResize = 0; -//ImageRect Window::border; -Image *Window::closeImage = NULL; bool Window::mAlphaChanged = false; +Window::Skins mSkins; class WindowConfigListener : public ConfigListener { @@ -58,6 +58,24 @@ class WindowConfigListener : public ConfigListener } }; +Skin::Skin(): + closeImage(NULL), + instances(0) +{ +} + +Skin::~Skin() +{ + // Clean up static resources + for (int i = 0; i < 9; i++) + { + delete border.grid[i]; + border.grid[i] = NULL; + } + + closeImage->decRef(); +} + Window::Window(const std::string& caption, bool modal, Window *parent, const std::string& skin): gcn::Window(caption), mGrip(0), @@ -71,8 +89,7 @@ Window::Window(const std::string& caption, bool modal, Window *parent, const std mMinWinWidth(100), mMinWinHeight(40), mMaxWinWidth(INT_MAX), - mMaxWinHeight(INT_MAX), - mSkin(skin) + mMaxWinHeight(INT_MAX) { logger->log("Window::Window(\"%s\")", caption.c_str()); @@ -82,7 +99,7 @@ Window::Window(const std::string& caption, bool modal, Window *parent, const std } // Loads the skin - loadSkin(mSkin); + loadSkin(skin); setGuiAlpha(); @@ -132,20 +149,14 @@ Window::~Window() instances--; - // Clean up static resources - for (int i = 0; i < 9; i++) - { - delete border.grid[i]; - border.grid[i] = NULL; - } + mSkin->instances--; if (instances == 0) { config.removeListener("guialpha", windowConfigListener); delete windowConfigListener; windowConfigListener = NULL; - - closeImage->decRef(); + delete_all(mSkins); } } @@ -161,7 +172,7 @@ void Window::draw(gcn::Graphics *graphics) Graphics *g = static_cast(graphics); - g->drawImageRect(0, 0, getWidth(), getHeight(), border); + g->drawImageRect(0, 0, getWidth(), getHeight(), mSkin->border); // Draw title if (mShowTitle) @@ -174,8 +185,8 @@ void Window::draw(gcn::Graphics *graphics) // Draw Close Button if (mCloseButton) { - g->drawImage(closeImage, - getWidth() - closeImage->getWidth() - getPadding(), + g->drawImage(mSkin->closeImage, + getWidth() - mSkin->closeImage->getWidth() - getPadding(), getPadding() ); } @@ -183,10 +194,10 @@ void Window::draw(gcn::Graphics *graphics) // Update window alpha values if (mAlphaChanged) { - for_each(border.grid, border.grid + 9, + for_each(mSkin->border.grid, mSkin->border.grid + 9, std::bind2nd(std::mem_fun(&Image::setAlpha), config.getValue("guialpha", 0.8))); - closeImage->setAlpha(config.getValue("guialpha", 0.8)); + mSkin->closeImage->setAlpha(config.getValue("guialpha", 0.8)); } drawChildren(graphics); } @@ -365,10 +376,10 @@ void Window::mousePressed(gcn::MouseEvent &event) if (mCloseButton) { gcn::Rectangle closeButtonRect( - getWidth() - closeImage->getWidth() - getPadding(), + getWidth() - mSkin->closeImage->getWidth() - getPadding(), getPadding(), - closeImage->getWidth(), - closeImage->getHeight()); + mSkin->closeImage->getWidth(), + mSkin->closeImage->getHeight()); if (closeButtonRect.isPointInRect(x, y)) { @@ -679,7 +690,7 @@ void Window::setGuiAlpha() for (int i = 0; i < 9; i++) { //logger->log("Window::setGuiAlpha: Border Image (%i)", i); - border.grid[i]->setAlpha(config.getValue("guialpha", 0.8)); + mSkin->border.grid[i]->setAlpha(config.getValue("guialpha", 0.8)); } mAlphaChanged = false; @@ -687,14 +698,24 @@ void Window::setGuiAlpha() void Window::loadSkin(const std::string &filename) { + SkinIterator skinIterator = mSkins.find(filename); + + if (mSkins.end() != skinIterator) + { + skinIterator->second->instances++; + mSkin = skinIterator->second; + return; + } + const std::string windowId = Window::getId(); + mSkin = new Skin(); + ResourceManager *resman = ResourceManager::getInstance(); logger->log("Loading Window Skin '%s'.", filename.c_str()); logger->log("Loading Window ID '%s'.", windowId.c_str()); - if (filename.empty()) logger->error("Window::loadSkin(): Invalid File Name."); @@ -706,16 +727,15 @@ void Window::loadSkin(const std::string &filename) xmlNodePtr rootNode = doc.rootNode(); if (!rootNode || !xmlStrEqual(rootNode->name, BAD_CAST "skinset")) - { logger->error("Widget Skinning error"); - } std::string skinSetImage; skinSetImage = XML::getProperty(rootNode, "image", ""); Image *dBorders = NULL; if (!skinSetImage.empty()) { - logger->log("Window::loadSkin(): defines '%s' as a skin image.", skinSetImage.c_str()); + logger->log("Window::loadSkin(): defines " + "'%s' as a skin image.", skinSetImage.c_str()); dBorders = resman->getImage("graphics/gui/" + skinSetImage); } else @@ -735,8 +755,8 @@ void Window::loadSkin(const std::string &filename) { // Iterate through 's // LEEOR / TODO: - // We need to make provisions to load in a CloseButton image. For now it - // can just be hard-coded. + // We need to make provisions to load in a CloseButton image. For + // now it can just be hard-coded. for_each_xml_child_node(partNode, widgetNode) { if (!xmlStrEqual(partNode->name, BAD_CAST "part")) @@ -751,27 +771,27 @@ void Window::loadSkin(const std::string &filename) const int height = XML::getProperty(partNode, "height", 1); if (partType == "top-left-corner") - border.grid[0] = dBorders->getSubImage(xPos, yPos, width, height); + mSkin->border.grid[0] = dBorders->getSubImage(xPos, yPos, width, height); else if (partType == "top-edge") - border.grid[1] = dBorders->getSubImage(xPos, yPos, width, height); + mSkin->border.grid[1] = dBorders->getSubImage(xPos, yPos, width, height); else if (partType == "top-right-corner") - border.grid[2] = dBorders->getSubImage(xPos, yPos, width, height); + mSkin->border.grid[2] = dBorders->getSubImage(xPos, yPos, width, height); // MIDDLE ROW else if (partType == "left-edge") - border.grid[3] = dBorders->getSubImage(xPos, yPos, width, height); + mSkin->border.grid[3] = dBorders->getSubImage(xPos, yPos, width, height); else if (partType == "bg-quad") - border.grid[4] = dBorders->getSubImage(xPos, yPos, width, height); + mSkin->border.grid[4] = dBorders->getSubImage(xPos, yPos, width, height); else if (partType == "right-edge") - border.grid[5] = dBorders->getSubImage(xPos, yPos, width, height); + mSkin->border.grid[5] = dBorders->getSubImage(xPos, yPos, width, height); // BOTTOM ROW else if (partType == "bottom-left-corner") - border.grid[6] = dBorders->getSubImage(xPos, yPos, width, height); + mSkin->border.grid[6] = dBorders->getSubImage(xPos, yPos, width, height); else if (partType == "bottom-edge") - border.grid[7] = dBorders->getSubImage(xPos, yPos, width, height); + mSkin->border.grid[7] = dBorders->getSubImage(xPos, yPos, width, height); else if (partType == "bottom-right-corner") - border.grid[8] = dBorders->getSubImage(xPos, yPos, width, height); + mSkin->border.grid[8] = dBorders->getSubImage(xPos, yPos, width, height); // Part is of an uknown type. else @@ -789,7 +809,8 @@ void Window::loadSkin(const std::string &filename) logger->log("Finished loading Window Skin."); // Hard-coded for now until we update the above code to look for window buttons. - closeImage = resman->getImage("graphics/gui/close_button.png"); + mSkin->closeImage = resman->getImage("graphics/gui/close_button.png"); + mSkins[filename] = mSkin; } Layout &Window::getLayout() diff --git a/src/gui/window.h b/src/gui/window.h index 4fc6c862..c5660c58 100644 --- a/src/gui/window.h +++ b/src/gui/window.h @@ -23,6 +23,8 @@ #ifndef WINDOW_H #define WINDOW_H +#include + #include #include @@ -39,6 +41,18 @@ class LayoutCell; class ResizeGrip; class WindowContainer; +class Skin +{ + public: + Skin(); + ~Skin(); + + std::string mName; /**< Name of the skin to use */ + ImageRect border; /**< The window border and background */ + Image *closeImage; /**< Close Button Image */ + int instances; +}; + /** * A window. This window can be dragged around and has a title bar. Windows are * invisible by default. @@ -297,7 +311,23 @@ class Window : public gcn::Window, gcn::WidgetListener */ ContainerPlacer getPlacer(int x, int y); + /** + * Overrideable functionality for when the window is to close. This + * allows for class implementations to clean up or do certain actions + * on window close they couldn't do otherwise. + */ virtual void close(); + + /** + * Map containing all window skins + */ + typedef std::map Skins; + + /** + * Iterator for window skins + */ + typedef Skins::iterator SkinIterator; + protected: /** The window container windows add themselves to. */ @@ -341,7 +371,6 @@ class Window : public gcn::Window, gcn::WidgetListener int mDefaultY; /**< Default window Y position */ int mDefaultWidth; /**< Default window width */ int mDefaultHeight; /**< Default window height */ - std::string mSkin; /**< Name of the skin to use */ /** * The config listener that listens to changes relevant to all windows. @@ -350,8 +379,8 @@ class Window : public gcn::Window, gcn::WidgetListener static int mouseResize; /**< Active resize handles */ static int instances; /**< Number of Window instances */ - ImageRect border; /**< The window border and background */ - static Image *closeImage; /**< Close Button Image */ + + Skin* mSkin; /**< Skin in use by this window */ /** * The width of the resize border. Is independent of the actual window -- cgit v1.2.3-70-g09d2 From 2a6b52f6467bfb4babb2a33205752f58554b651b Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Wed, 11 Mar 2009 14:38:26 -0600 Subject: Moved the Skin class outside of the Window class, in order to allow other widget containers to use skins as well, and to make it easier to extend later. Signed-off-by: Ira Rice --- aethyra.cbp | 2 + src/CMakeLists.txt | 2 + src/Makefile.am | 2 + src/game.cpp | 1 - src/gui/gui.cpp | 1 + src/gui/skin.cpp | 174 +++++++++++++++++++++++++++++++++++++++++++++++++++++ src/gui/skin.h | 67 +++++++++++++++++++++ src/gui/window.cpp | 156 +++-------------------------------------------- src/gui/window.h | 33 +--------- src/main.cpp | 54 +++++++++-------- 10 files changed, 288 insertions(+), 204 deletions(-) create mode 100644 src/gui/skin.cpp create mode 100644 src/gui/skin.h (limited to 'src/gui/window.h') diff --git a/aethyra.cbp b/aethyra.cbp index 46034040..6bae4561 100644 --- a/aethyra.cbp +++ b/aethyra.cbp @@ -236,6 +236,8 @@ + + diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index c7003946..171ec7ff 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -185,6 +185,8 @@ SET(SRCS gui/shortcutcontainer.h gui/skill.cpp gui/skill.h + gui/skin.cpp + gui/skin.h gui/slider.cpp gui/slider.h gui/speechbubble.cpp diff --git a/src/Makefile.am b/src/Makefile.am index 963e41fb..440c020e 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -135,6 +135,8 @@ aethyra_SOURCES = gui/widgets/dropdown.cpp \ gui/shortcutcontainer.h \ gui/skill.cpp \ gui/skill.h \ + gui/skin.cpp \ + gui/skin.h \ gui/slider.cpp \ gui/slider.h \ gui/speechbubble.cpp \ diff --git a/src/game.cpp b/src/game.cpp index 13be3663..3b621acd 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -345,7 +345,6 @@ Game::~Game() destroyGuiWindows(); delete beingManager; - delete player_node; delete floorItemManager; delete joystick; delete particleEngine; diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index 85a33218..2c0ddee9 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -27,6 +27,7 @@ #include "focushandler.h" #include "gui.h" #include "sdlinput.h" +#include "skin.h" #include "truetypefont.h" #include "viewport.h" #include "window.h" diff --git a/src/gui/skin.cpp b/src/gui/skin.cpp new file mode 100644 index 00000000..e9d081e9 --- /dev/null +++ b/src/gui/skin.cpp @@ -0,0 +1,174 @@ +/* + * Aethyra + * Copyright (C) 2009 Aethyra Development Team + * + * This file is part of Aethyra. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "skin.h" + +#include "../log.h" + +#include "../resources/image.h" +#include "../resources/resourcemanager.h" + +#include "../utils/dtor.h" +#include "../utils/xml.h" + +SkinLoader* skinLoader = NULL; + +Skin::Skin(): + closeImage(NULL), + instances(0) +{ +} + +Skin::~Skin() +{ + // Clean up static resources + for (int i = 0; i < 9; i++) + { + delete border.grid[i]; + border.grid[i] = NULL; + } + + closeImage->decRef(); +} + +Skin* SkinLoader::load(const std::string &filename) +{ + SkinIterator skinIterator = mSkins.find(filename); + + if (mSkins.end() != skinIterator) + { + skinIterator->second->instances++; + return skinIterator->second; + } + + Skin* skin = new Skin(); + + ResourceManager *resman = ResourceManager::getInstance(); + + logger->log("Loading Skin '%s'.", filename.c_str()); + + if (filename.empty()) + logger->error("SkinLoader::load(): Invalid File Name."); + + // TODO: + // If there is an error loading the specified file, we should try to revert + // to a 'default' skin file. Only if the 'default' skin file can't be loaded + // should we have a terminating error. + XML::Document doc(filename); + xmlNodePtr rootNode = doc.rootNode(); + + if (!rootNode || !xmlStrEqual(rootNode->name, BAD_CAST "skinset")) + logger->error("Widget Skinning error"); + + std::string skinSetImage; + skinSetImage = XML::getProperty(rootNode, "image", ""); + Image *dBorders = NULL; + if (!skinSetImage.empty()) + { + logger->log("SkinLoader::load(): defines " + "'%s' as a skin image.", skinSetImage.c_str()); + dBorders = resman->getImage("graphics/gui/" + skinSetImage); + } + else + { + logger->error("SkinLoader::load(): Skinset does not define an image!"); + } + + //iterate 's + for_each_xml_child_node(widgetNode, rootNode) + { + if (!xmlStrEqual(widgetNode->name, BAD_CAST "widget")) + continue; + + std::string widgetType; + widgetType = XML::getProperty(widgetNode, "type", "unknown"); + if (widgetType == "Window") + { + // Iterate through 's + // LEEOR / TODO: + // We need to make provisions to load in a CloseButton image. For + // now it can just be hard-coded. + for_each_xml_child_node(partNode, widgetNode) + { + if (!xmlStrEqual(partNode->name, BAD_CAST "part")) + continue; + + std::string partType; + partType = XML::getProperty(partNode, "type", "unknown"); + // TOP ROW + const int xPos = XML::getProperty(partNode, "xpos", 0); + const int yPos = XML::getProperty(partNode, "ypos", 0); + const int width = XML::getProperty(partNode, "width", 1); + const int height = XML::getProperty(partNode, "height", 1); + + if (partType == "top-left-corner") + skin->border.grid[0] = dBorders->getSubImage(xPos, yPos, width, height); + else if (partType == "top-edge") + skin->border.grid[1] = dBorders->getSubImage(xPos, yPos, width, height); + else if (partType == "top-right-corner") + skin->border.grid[2] = dBorders->getSubImage(xPos, yPos, width, height); + + // MIDDLE ROW + else if (partType == "left-edge") + skin->border.grid[3] = dBorders->getSubImage(xPos, yPos, width, height); + else if (partType == "bg-quad") + skin->border.grid[4] = dBorders->getSubImage(xPos, yPos, width, height); + else if (partType == "right-edge") + skin->border.grid[5] = dBorders->getSubImage(xPos, yPos, width, height); + + // BOTTOM ROW + else if (partType == "bottom-left-corner") + skin->border.grid[6] = dBorders->getSubImage(xPos, yPos, width, height); + else if (partType == "bottom-edge") + skin->border.grid[7] = dBorders->getSubImage(xPos, yPos, width, height); + else if (partType == "bottom-right-corner") + skin->border.grid[8] = dBorders->getSubImage(xPos, yPos, width, height); + + // Part is of an uknown type. + else + logger->log("SkinLoader::load(): Unknown Part Type '%s'", partType.c_str()); + } + } + // Widget is of an uknown type. + else + { + logger->log("SkinLoader::load(): Unknown Widget Type '%s'", widgetType.c_str()); + } + } + dBorders->decRef(); + + logger->log("Finished loading Skin."); + + // Hard-coded for now until we update the above code to look for window buttons. + skin->closeImage = resman->getImage("graphics/gui/close_button.png"); + mSkins[filename] = skin; + return skin; +} + +SkinLoader::SkinLoader() +{ +} + +SkinLoader::~SkinLoader() +{ + delete_all(mSkins); +} + diff --git a/src/gui/skin.h b/src/gui/skin.h new file mode 100644 index 00000000..6dddb4a8 --- /dev/null +++ b/src/gui/skin.h @@ -0,0 +1,67 @@ +/* + * Aethyra + * Copyright (C) 2009 Aethyra Development Team + * + * This file is part of Aethyra. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef SKIN_H +#define SKIN_H + +#include +#include + +#include "../graphics.h" + +class Image; + +class Skin +{ + public: + Skin(); + ~Skin(); + + std::string mName; /**< Name of the skin to use */ + ImageRect border; /**< The window border and background */ + Image *closeImage; /**< Close Button Image */ + int instances; +}; + +// Map containing all window skins +typedef std::map Skins; + +// Iterator for window skins +typedef Skins::iterator SkinIterator; + +class SkinLoader +{ + public: + SkinLoader(); + ~SkinLoader(); + + /** + * Loads a skin + */ + Skin* load(const std::string &filename); + + private: + Skins mSkins; +}; + +extern SkinLoader* skinLoader; + +#endif diff --git a/src/gui/window.cpp b/src/gui/window.cpp index 0e91b68d..def81c53 100644 --- a/src/gui/window.cpp +++ b/src/gui/window.cpp @@ -27,6 +27,7 @@ #include #include "gui.h" +#include "skin.h" #include "window.h" #include "windowcontainer.h" @@ -38,17 +39,12 @@ #include "../log.h" #include "../resources/image.h" -#include "../resources/resourcemanager.h" - -#include "../utils/dtor.h" -#include "../utils/xml.h" ConfigListener *Window::windowConfigListener = 0; WindowContainer *Window::windowContainer = 0; int Window::instances = 0; int Window::mouseResize = 0; bool Window::mAlphaChanged = false; -Window::Skins mSkins; class WindowConfigListener : public ConfigListener { @@ -58,24 +54,6 @@ class WindowConfigListener : public ConfigListener } }; -Skin::Skin(): - closeImage(NULL), - instances(0) -{ -} - -Skin::~Skin() -{ - // Clean up static resources - for (int i = 0; i < 9; i++) - { - delete border.grid[i]; - border.grid[i] = NULL; - } - - closeImage->decRef(); -} - Window::Window(const std::string& caption, bool modal, Window *parent, const std::string& skin): gcn::Window(caption), mGrip(0), @@ -94,17 +72,11 @@ Window::Window(const std::string& caption, bool modal, Window *parent, const std logger->log("Window::Window(\"%s\")", caption.c_str()); if (!windowContainer) - { throw GCN_EXCEPTION("Window::Window(): no windowContainer set"); - } - - // Loads the skin - loadSkin(skin); - - setGuiAlpha(); if (instances == 0) { + skinLoader = new SkinLoader(); windowConfigListener = new WindowConfigListener(); // Send GUI alpha changed for initialization windowConfigListener->optionChanged("guialpha"); @@ -117,6 +89,11 @@ Window::Window(const std::string& caption, bool modal, Window *parent, const std setPadding(3); setTitleBarHeight(20); + // Loads the skin + mSkin = skinLoader->load(skin); + + setGuiAlpha(); + // Add this window to the window container windowContainer->add(this); @@ -153,10 +130,10 @@ Window::~Window() if (instances == 0) { + delete skinLoader; config.removeListener("guialpha", windowConfigListener); delete windowConfigListener; windowConfigListener = NULL; - delete_all(mSkins); } } @@ -696,123 +673,6 @@ void Window::setGuiAlpha() mAlphaChanged = false; } -void Window::loadSkin(const std::string &filename) -{ - SkinIterator skinIterator = mSkins.find(filename); - - if (mSkins.end() != skinIterator) - { - skinIterator->second->instances++; - mSkin = skinIterator->second; - return; - } - - const std::string windowId = Window::getId(); - - mSkin = new Skin(); - - ResourceManager *resman = ResourceManager::getInstance(); - - logger->log("Loading Window Skin '%s'.", filename.c_str()); - logger->log("Loading Window ID '%s'.", windowId.c_str()); - - if (filename.empty()) - logger->error("Window::loadSkin(): Invalid File Name."); - - // TODO: - // If there is an error loading the specified file, we should try to revert - // to a 'default' skin file. Only if the 'default' skin file can't be loaded - // should we have a terminating error. - XML::Document doc(filename); - xmlNodePtr rootNode = doc.rootNode(); - - if (!rootNode || !xmlStrEqual(rootNode->name, BAD_CAST "skinset")) - logger->error("Widget Skinning error"); - - std::string skinSetImage; - skinSetImage = XML::getProperty(rootNode, "image", ""); - Image *dBorders = NULL; - if (!skinSetImage.empty()) - { - logger->log("Window::loadSkin(): defines " - "'%s' as a skin image.", skinSetImage.c_str()); - dBorders = resman->getImage("graphics/gui/" + skinSetImage); - } - else - { - logger->error("Window::loadSkin(): Skinset does not define an image!"); - } - - //iterate 's - for_each_xml_child_node(widgetNode, rootNode) - { - if (!xmlStrEqual(widgetNode->name, BAD_CAST "widget")) - continue; - - std::string widgetType; - widgetType = XML::getProperty(widgetNode, "type", "unknown"); - if (widgetType == "Window") - { - // Iterate through 's - // LEEOR / TODO: - // We need to make provisions to load in a CloseButton image. For - // now it can just be hard-coded. - for_each_xml_child_node(partNode, widgetNode) - { - if (!xmlStrEqual(partNode->name, BAD_CAST "part")) - continue; - - std::string partType; - partType = XML::getProperty(partNode, "type", "unknown"); - // TOP ROW - const int xPos = XML::getProperty(partNode, "xpos", 0); - const int yPos = XML::getProperty(partNode, "ypos", 0); - const int width = XML::getProperty(partNode, "width", 1); - const int height = XML::getProperty(partNode, "height", 1); - - if (partType == "top-left-corner") - mSkin->border.grid[0] = dBorders->getSubImage(xPos, yPos, width, height); - else if (partType == "top-edge") - mSkin->border.grid[1] = dBorders->getSubImage(xPos, yPos, width, height); - else if (partType == "top-right-corner") - mSkin->border.grid[2] = dBorders->getSubImage(xPos, yPos, width, height); - - // MIDDLE ROW - else if (partType == "left-edge") - mSkin->border.grid[3] = dBorders->getSubImage(xPos, yPos, width, height); - else if (partType == "bg-quad") - mSkin->border.grid[4] = dBorders->getSubImage(xPos, yPos, width, height); - else if (partType == "right-edge") - mSkin->border.grid[5] = dBorders->getSubImage(xPos, yPos, width, height); - - // BOTTOM ROW - else if (partType == "bottom-left-corner") - mSkin->border.grid[6] = dBorders->getSubImage(xPos, yPos, width, height); - else if (partType == "bottom-edge") - mSkin->border.grid[7] = dBorders->getSubImage(xPos, yPos, width, height); - else if (partType == "bottom-right-corner") - mSkin->border.grid[8] = dBorders->getSubImage(xPos, yPos, width, height); - - // Part is of an uknown type. - else - logger->log("Window::loadSkin(): Unknown Part Type '%s'", partType.c_str()); - } - } - // Widget is of an uknown type. - else - { - logger->log("Window::loadSkin(): Unknown Widget Type '%s'", widgetType.c_str()); - } - } - dBorders->decRef(); - - logger->log("Finished loading Window Skin."); - - // Hard-coded for now until we update the above code to look for window buttons. - mSkin->closeImage = resman->getImage("graphics/gui/close_button.png"); - mSkins[filename] = mSkin; -} - Layout &Window::getLayout() { if (!mLayout) mLayout = new Layout; diff --git a/src/gui/window.h b/src/gui/window.h index c5660c58..7ae7ebba 100644 --- a/src/gui/window.h +++ b/src/gui/window.h @@ -23,8 +23,6 @@ #ifndef WINDOW_H #define WINDOW_H -#include - #include #include @@ -35,24 +33,13 @@ class ConfigListener; class GCContainer; class ContainerPlacer; -class Image; class Layout; class LayoutCell; class ResizeGrip; +class Skin; +class SkinLoader; class WindowContainer; -class Skin -{ - public: - Skin(); - ~Skin(); - - std::string mName; /**< Name of the skin to use */ - ImageRect border; /**< The window border and background */ - Image *closeImage; /**< Close Button Image */ - int instances; -}; - /** * A window. This window can be dragged around and has a title bar. Windows are * invisible by default. @@ -296,11 +283,6 @@ class Window : public gcn::Window, gcn::WidgetListener */ void reflowLayout(int w = 0, int h = 0); - /** - * Loads a window skin - */ - void loadSkin(const std::string &filename); - /** * Adds a widget to the window and sets it at given cell. */ @@ -317,17 +299,6 @@ class Window : public gcn::Window, gcn::WidgetListener * on window close they couldn't do otherwise. */ virtual void close(); - - /** - * Map containing all window skins - */ - typedef std::map Skins; - - /** - * Iterator for window skins - */ - typedef Skins::iterator SkinIterator; - protected: /** The window container windows add themselves to. */ diff --git a/src/main.cpp b/src/main.cpp index 9e7c91c0..a7032fb1 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -437,16 +437,18 @@ void init_engine(const Options &options) state = LOGIN_STATE; /**< Initial game state */ // Initialize sound engine - try { - if (config.getValue("sound", 0) == 1) { + try + { + if (config.getValue("sound", 0) == 1) sound.init(); - } + sound.setSfxVolume((int) config.getValue("sfxVolume", defaultSfxVolume)); sound.setMusicVolume((int) config.getValue("musicVolume", defaultMusicVolume)); } - catch (const char *err) { + catch (const char *err) + { state = ERROR_STATE; errorMessage = err; logger->log("Warning: %s", err); @@ -830,17 +832,18 @@ int main(int argc, char *argv[]) while (state != EXIT_STATE) { // Handle SDL events - while (SDL_PollEvent(&event)) { - switch (event.type) { + while (SDL_PollEvent(&event)) + { + switch (event.type) + { case SDL_QUIT: state = EXIT_STATE; break; case SDL_KEYDOWN: if (event.key.keysym.sym == SDLK_ESCAPE) - { state = EXIT_STATE; - } + break; } @@ -855,11 +858,10 @@ int main(int argc, char *argv[]) { state = ERROR_STATE; - if (!network->getError().empty()) { + if (!network->getError().empty()) errorMessage = network->getError(); - } else { + else errorMessage = _("Got disconnected from server!"); - } } if (progressBar->isVisible()) @@ -882,7 +884,8 @@ int main(int argc, char *argv[]) gui->draw(); graphics->updateScreen(); - if (state != oldstate) { + if (state != oldstate) + { switch (oldstate) { case UPDATE_STATE: @@ -913,12 +916,14 @@ int main(int argc, char *argv[]) oldstate = state; if (currentDialog && state != ACCOUNT_STATE && - state != CHAR_CONNECT_STATE) { + state != CHAR_CONNECT_STATE) + { delete currentDialog; currentDialog = NULL; } - switch (state) { + switch (state) + { case LOADDATA_STATE: logger->log("State: LOADDATA"); @@ -941,10 +946,13 @@ int main(int argc, char *argv[]) case LOGIN_STATE: logger->log("State: LOGIN"); - if (!loginData.password.empty()) { + if (!loginData.password.empty()) + { loginData.registerLogin = false; state = ACCOUNT_STATE; - } else { + } + else + { currentDialog = new LoginDialog(&loginData); positionDialog(currentDialog, screenWidth, screenHeight); @@ -1029,9 +1037,12 @@ int main(int argc, char *argv[]) break; case UPDATE_STATE: - if (options.skipUpdate) { + if (options.skipUpdate) + { state = LOADDATA_STATE; - } else { + } + else + { // Determine which source to use for the update host if (!options.updateHost.empty()) updateHost = options.updateHost; @@ -1109,9 +1120,8 @@ int main(int argc, char *argv[]) SDLNet_Quit(); if (nullFile) - { fclose(nullFile); - } + logger->log("State: EXIT"); exit_engine(); PHYSFS_deinit(); @@ -1123,16 +1133,12 @@ void SetupListener::action(const gcn::ActionEvent &event) Window *window = NULL; if (event.getId() == "Setup") - { window = setupWindow; - } if (window) { window->setVisible(!window->isVisible()); if (window->isVisible()) - { window->requestMoveToTop(); - } } } -- cgit v1.2.3-70-g09d2 From c2ae6d9cea9fc3d861e73d4cf7eca5284519758e Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Wed, 11 Mar 2009 18:06:30 -0600 Subject: Added a new Popup class, which overall is functionally similar to the Window class, but stripped down to the bare essential functionality to just draw and position them. This means no resizing, no close buttons, no ability to move them, etc. This should help reduce the overhead in drawing speech bubbles, as well as other popup type dialogs, but is also not a drop in replacement for the Window class as well. Signed-off-by: Ira Rice --- aethyra.cbp | 2 + src/CMakeLists.txt | 2 + src/Makefile.am | 2 + src/game.cpp | 4 +- src/gui/itempopup.cpp | 13 +-- src/gui/itempopup.h | 4 +- src/gui/itemshortcutcontainer.cpp | 2 +- src/gui/menuwindow.cpp | 13 +-- src/gui/menuwindow.h | 4 +- src/gui/ministatus.cpp | 15 +-- src/gui/ministatus.h | 4 +- src/gui/popup.cpp | 211 ++++++++++++++++++++++++++++++++++++++ src/gui/popup.h | 196 +++++++++++++++++++++++++++++++++++ src/gui/popupmenu.cpp | 10 +- src/gui/speechbubble.cpp | 5 +- src/gui/speechbubble.h | 4 +- src/gui/window.cpp | 61 ++++++----- src/gui/window.h | 4 - src/gui/windowcontainer.cpp | 2 + src/gui/windowcontainer.h | 7 ++ 20 files changed, 479 insertions(+), 86 deletions(-) create mode 100644 src/gui/popup.cpp create mode 100644 src/gui/popup.h (limited to 'src/gui/window.h') diff --git a/aethyra.cbp b/aethyra.cbp index 6bae4561..aa1737b7 100644 --- a/aethyra.cbp +++ b/aethyra.cbp @@ -195,6 +195,8 @@ + + diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 171ec7ff..9fdca23a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -144,6 +144,8 @@ SET(SRCS gui/passwordfield.h gui/playerbox.cpp gui/playerbox.h + gui/popup.cpp + gui/popup.h gui/popupmenu.cpp gui/popupmenu.h gui/progressbar.cpp diff --git a/src/Makefile.am b/src/Makefile.am index 440c020e..c4265dec 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -94,6 +94,8 @@ aethyra_SOURCES = gui/widgets/dropdown.cpp \ gui/passwordfield.h \ gui/playerbox.cpp \ gui/playerbox.h \ + gui/popup.cpp \ + gui/popup.h \ gui/popupmenu.cpp \ gui/popupmenu.h \ gui/progressbar.cpp \ diff --git a/src/game.cpp b/src/game.cpp index 3b621acd..47f4ffd2 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -220,12 +220,12 @@ void createGuiWindows(Network *network) chatWindow->setVisible((bool) config.getValue( chatWindow->getWindowName() + "Visible", true)); miniStatusWindow->setVisible((bool) config.getValue( - miniStatusWindow->getWindowName() + "Visible", true)); + miniStatusWindow->getPopupName() + "Visible", true)); buyDialog->setVisible(false); sellDialog->setVisible(false); tradeWindow->setVisible(false); menuWindow->setVisible((bool) config.getValue( - menuWindow->getWindowName() + "Visible", true)); + menuWindow->getPopupName() + "Visible", true)); itemShortcutWindow->setVisible((bool) config.getValue( itemShortcutWindow->getWindowName() + "Visible", true)); emoteShortcutWindow->setVisible((bool) config.getValue( diff --git a/src/gui/itempopup.cpp b/src/gui/itempopup.cpp index 0f7e2d11..ebbc6af3 100644 --- a/src/gui/itempopup.cpp +++ b/src/gui/itempopup.cpp @@ -29,9 +29,8 @@ #include "itempopup.h" #include "scrollarea.h" #include "textbox.h" -#include "windowcontainer.h" -#include "widgets/layout.h" +#include "../graphics.h" #include "../resources/iteminfo.h" @@ -39,12 +38,8 @@ #include "../utils/stringutils.h" ItemPopup::ItemPopup(): - Window() + Popup() { - setResizable(false); - setShowTitle(false); - setTitleBarHeight(0); - // Item Name mItemName = new gcn::Label("Label"); mItemName->setFont(boldFont); @@ -208,8 +203,8 @@ unsigned int ItemPopup::getNumRows() void ItemPopup::view(int x, int y) { - if (windowContainer->getWidth() < (x + getWidth() + 5)) - x = windowContainer->getWidth() - getWidth(); + if (graphics->getWidth() < (x + getWidth() + 5)) + x = graphics->getWidth() - getWidth(); if ((y - getHeight() - 10) < 0) y = 0; else diff --git a/src/gui/itempopup.h b/src/gui/itempopup.h index a91d8c6f..97da4cbb 100644 --- a/src/gui/itempopup.h +++ b/src/gui/itempopup.h @@ -24,13 +24,13 @@ #ifndef ITEMPOPUP_H #define ITEMPOPUP_H -#include "window.h" +#include "popup.h" class ItemInfo; class ScrollArea; class TextBox; -class ItemPopup : public Window +class ItemPopup : public Popup { public: ItemPopup(); diff --git a/src/gui/itemshortcutcontainer.cpp b/src/gui/itemshortcutcontainer.cpp index cb709227..c1baca76 100644 --- a/src/gui/itemshortcutcontainer.cpp +++ b/src/gui/itemshortcutcontainer.cpp @@ -231,7 +231,7 @@ void ItemShortcutContainer::mouseMoved(gcn::MouseEvent &event) Item *item = player_node->getInventory()->findItem(itemId); - if (item && inventoryWindow->isVisible()) + if (item) { mItemPopup->setItem(item->getInfo()); mItemPopup->setOpaque(false); diff --git a/src/gui/menuwindow.cpp b/src/gui/menuwindow.cpp index 8a695865..e1be908b 100644 --- a/src/gui/menuwindow.cpp +++ b/src/gui/menuwindow.cpp @@ -26,7 +26,9 @@ #include "button.h" #include "menuwindow.h" -#include "windowcontainer.h" +#include "window.h" + +#include "../graphics.h" #include "../utils/gettext.h" @@ -50,13 +52,8 @@ namespace { } MenuWindow::MenuWindow(): - Window("") + Popup("Menu") { - setResizable(false); - setWindowName("Menu"); - setMovable(false); - setTitleBarHeight(0); - // Buttons static const char *buttonNames[] = { @@ -81,7 +78,7 @@ MenuWindow::MenuWindow(): h = btn->getHeight(); } - setPosition(windowContainer->getWidth() - x - 3, 3); + setPosition(graphics->getWidth() - x - 3, 3); setContentSize(x - 3, h); } diff --git a/src/gui/menuwindow.h b/src/gui/menuwindow.h index f70a332e..e8dc0b2e 100644 --- a/src/gui/menuwindow.h +++ b/src/gui/menuwindow.h @@ -23,14 +23,14 @@ #ifndef MENU_H #define MENU_H -#include "window.h" +#include "popup.h" /** * The Button Menu. * * \ingroup Interface */ -class MenuWindow : public Window +class MenuWindow : public Popup { public: /** diff --git a/src/gui/ministatus.cpp b/src/gui/ministatus.cpp index 6537b48e..18b9d714 100644 --- a/src/gui/ministatus.cpp +++ b/src/gui/ministatus.cpp @@ -31,13 +31,8 @@ #include "../utils/stringutils.h" MiniStatusWindow::MiniStatusWindow(): - Window("") + Popup("MiniStatus") { - setWindowName("MiniStatus"); - setResizable(false); - setMovable(false); - setTitleBarHeight(0); - mHpBar = new ProgressBar(1.0f, 100, 20, 0, 171, 34); mMpBar = new ProgressBar(1.0f, 100, 20, 26, 102, 230); mXpBar = new ProgressBar(1.0f, 100, 20, 143, 192, 211); @@ -52,25 +47,17 @@ MiniStatusWindow::MiniStatusWindow(): setContentSize(mXpBar->getX() + mXpBar->getWidth(), mXpBar->getY() + mXpBar->getHeight()); - setDefaultSize(0, 0, getWidth(), getHeight()); - loadWindowState(); } void MiniStatusWindow::update() { // HP Bar coloration if (player_node->mHp < int(player_node->mMaxHp / 3)) - { mHpBar->setColor(223, 32, 32); // Red - } else if (player_node->mHp < int((player_node->mMaxHp / 3) * 2)) - { mHpBar->setColor(230, 171, 34); // Orange - } else - { mHpBar->setColor(0, 171, 34); // Green - } float xp = (float) player_node->getXp() / player_node->mXpForNextLevel; diff --git a/src/gui/ministatus.h b/src/gui/ministatus.h index 33ee548d..b3fc58fc 100644 --- a/src/gui/ministatus.h +++ b/src/gui/ministatus.h @@ -23,7 +23,7 @@ #ifndef MINISTATUS_H #define MINISTATUS_H -#include "window.h" +#include "popup.h" class ProgressBar; @@ -32,7 +32,7 @@ class ProgressBar; * * \ingroup Interface */ -class MiniStatusWindow : public Window +class MiniStatusWindow : public Popup { public: /** diff --git a/src/gui/popup.cpp b/src/gui/popup.cpp new file mode 100644 index 00000000..906f7a2e --- /dev/null +++ b/src/gui/popup.cpp @@ -0,0 +1,211 @@ +/* + * Aethyra + * Copyright (C) 2009 Aethyra Development Team + * + * This file is part of Aethyra based on original code + * from The Mana World. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include +#include +#include + +#include + +#include "gui.h" +#include "skin.h" +#include "popup.h" +#include "window.h" +#include "windowcontainer.h" + +#include "../configlistener.h" +#include "../configuration.h" +#include "../log.h" + +#include "../resources/image.h" + +ConfigListener *Popup::popupConfigListener = 0; +int Popup::instances = 0; +bool Popup::mAlphaChanged = false; + +class PopupConfigListener : public ConfigListener +{ + void optionChanged(const std::string &) + { + Popup::mAlphaChanged = true; + } +}; + +Popup::Popup(const std::string& name, Window *parent, + const std::string& skin): + mParent(parent), + mPopupName(name), + mMinWidth(100), + mMinHeight(40), + mMaxWidth(INT_MAX), + mMaxHeight(INT_MAX) +{ + logger->log("Popup::Popup(\"%s\")", name.c_str()); + + if (!windowContainer) + throw GCN_EXCEPTION("Popup::Popup(): no windowContainer set"); + + if (instances == 0) + { + popupConfigListener = new PopupConfigListener(); + // Send GUI alpha changed for initialization + popupConfigListener->optionChanged("guialpha"); + config.addListener("guialpha", popupConfigListener); + } + + setPadding(3); + + instances++; + + // Loads the skin + mSkin = skinLoader->load(skin); + + setGuiAlpha(); + + // Add this window to the window container + windowContainer->add(this); + + // Popups are invisible by default + setVisible(false); + + addWidgetListener(this); +} + +Popup::~Popup() +{ + logger->log("Popup::~Popup(\"%s\")", mPopupName.c_str()); + + while (!mWidgets.empty()) + { + gcn::Widget *w = mWidgets.front(); + remove(w); + delete(w); + } + + instances--; + + mSkin->instances--; + + if (instances == 0) + { + config.removeListener("guialpha", popupConfigListener); + delete popupConfigListener; + popupConfigListener = NULL; + } +} + +void Popup::setWindowContainer(WindowContainer *wc) +{ + windowContainer = wc; +} + +void Popup::draw(gcn::Graphics *graphics) +{ + if (!isVisible()) + return; + + Graphics *g = static_cast(graphics); + + g->drawImageRect(0, 0, getWidth(), getHeight(), mSkin->border); + + // Update Popup alpha values + if (mAlphaChanged) + { + for_each(mSkin->border.grid, mSkin->border.grid + 9, + std::bind2nd(std::mem_fun(&Image::setAlpha), + config.getValue("guialpha", 0.8))); + } + drawChildren(graphics); +} + +gcn::Rectangle Popup::getChildrenArea() +{ + return gcn::Rectangle(getPadding(), 0, getWidth() - getPadding() * 2, + getHeight() - getPadding() * 2); +} + +void Popup::setContentSize(int width, int height) +{ + width += 2 * getPadding(); + height += 2 * getPadding(); + + if (getMinWidth() > width) + width = getMinWidth(); + else if (getMaxWidth() < width) + width = getMaxWidth(); + if (getMinHeight() > height) + height = getMinHeight(); + else if (getMaxHeight() < height) + height = getMaxHeight(); + + setSize(width, height); +} + +void Popup::setLocationRelativeTo(gcn::Widget *widget) +{ + int wx, wy; + int x, y; + + widget->getAbsolutePosition(wx, wy); + getAbsolutePosition(x, y); + + setPosition(getX() + (wx + (widget->getWidth() - getWidth()) / 2 - x), + getY() + (wy + (widget->getHeight() - getHeight()) / 2 - y)); +} + +void Popup::setMinWidth(unsigned int width) +{ + mMinWidth = width; +} + +void Popup::setMinHeight(unsigned int height) +{ + mMinHeight = height; +} + +void Popup::setMaxWidth(unsigned int width) +{ + mMaxWidth = width; +} + +void Popup::setMaxHeight(unsigned int height) +{ + mMaxHeight = height; +} + +void Popup::scheduleDelete() +{ + windowContainer->scheduleDelete(this); +} + +void Popup::setGuiAlpha() +{ + //logger->log("Popup::setGuiAlpha: Alpha Value %f", config.getValue("guialpha", 0.8)); + for (int i = 0; i < 9; i++) + { + //logger->log("Popup::setGuiAlpha: Border Image (%i)", i); + mSkin->border.grid[i]->setAlpha(config.getValue("guialpha", 0.8)); + } + + mAlphaChanged = false; +} + diff --git a/src/gui/popup.h b/src/gui/popup.h new file mode 100644 index 00000000..0f7eebbf --- /dev/null +++ b/src/gui/popup.h @@ -0,0 +1,196 @@ +/* + * Aethyra + * Copyright (C) 2009 Aethyra Development Team + * + * This file is part of Aethyra based on original code + * from The Mana World. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef POPUP_H +#define POPUP_H + +#include + +#include + +#include "../graphics.h" +#include "../guichanfwd.h" + +class ConfigListener; +class Skin; +class SkinLoader; +class Window; +class WindowContainer; + +/** + * A rather reduced down version of the Window class that is particularly suited + * for + * + * \ingroup GUI + */ +class Popup : public gcn::Container, gcn::WidgetListener +{ + public: + friend class PopupConfigListener; + + /** + * Constructor. Initializes the title to the given text and hooks + * itself into the popup container. + * + * @param name A human readable name for the popup. Only useful for + * debugging purposes. + * @param parent The parent Window. This is the Window standing above + * this one in the Window hiearchy. When reordering, + * a Popup will never go below its parent Window. + * @param skin The location where the Popup's skin XML can be found. + */ + Popup(const std::string& name = "", Window *parent = NULL, + const std::string &skin = "graphics/gui/gui.xml"); + + /** + * Destructor. Deletes all the added widgets. + */ + ~Popup(); + + /** + * Sets the window container to be used by new popups. + */ + static void setWindowContainer(WindowContainer *windowContainer); + + /** + * Draws the popup. + */ + void draw(gcn::Graphics *graphics); + + /** + * Sets the size of this popup. + */ + void setContentSize(int width, int height); + + /** + * Sets the location relative to the given widget. + */ + void setLocationRelativeTo(gcn::Widget *widget); + + /** + * Sets the minimum width of the popup. + */ + void setMinWidth(unsigned int width); + + /** + * Sets the minimum height of the popup. + */ + void setMinHeight(unsigned int height); + + /** + * Sets the maximum width of the popup. + */ + void setMaxWidth(unsigned int width); + + /** + * Sets the minimum height of the popup. + */ + void setMaxHeight(unsigned int height); + + /** + * Gets the minimum width of the popup. + */ + int getMinWidth() { return mMinWidth; } + + /** + * Gets the minimum height of the popup. + */ + int getMinHeight() { return mMinHeight; } + + /** + * Gets the maximum width of the popup. + */ + int getMaxWidth() { return mMaxWidth; } + + /** + * Gets the minimum height of the popup. + */ + int getMaxHeight() { return mMaxHeight; } + + /** + * Gets the padding of the popup. The padding is the distance between + * the popup border and the content. + * + * @return The padding of the popup. + * @see setPadding + */ + unsigned int getPadding() const { return mPadding; } + + /** + * Sets the padding of the popup. The padding is the distance between the + * popup border and the content. + * + * @param padding The padding of the popup. + * @see getPadding + */ + void setPadding(unsigned int padding) { mPadding = padding; } + + /** + * Returns the parent Window. + * + * @return The parent Window or NULL if there is none. + */ + Window* getParentWindow() { return mParent; } + + /** + * Sets the name of the popup. This is only useful for debug purposes. + */ + void setPopupName(const std::string &name) { mPopupName = name; } + + /** + * Returns the name of the popup. This is only useful for debug purposes. + */ + const std::string& getPopupName() { return mPopupName; } + + /** + * Schedule this popup for deletion. It will be deleted at the start + * of the next logic update. + */ + void scheduleDelete(); + + // Inherited from BasicContainer + + virtual gcn::Rectangle getChildrenArea(); + + private: + void setGuiAlpha(); + + Window *mParent; /**< The parent Window (if there is one) */ + std::string mPopupName; /**< Name of the Popup */ + static bool mAlphaChanged; /**< Whether the alpha percent was changed */ + int mMinWidth; /**< Minimum Popup width */ + int mMinHeight; /**< Minimum Popup height */ + int mMaxWidth; /**< Maximum Popup width */ + int mMaxHeight; /**< Maximum Popup height */ + unsigned int mPadding; /**< Holds the padding of the window. */ + + /** + * The config listener that listens to changes relevant to all Popups. + */ + static ConfigListener *popupConfigListener; + + static int instances; /**< Number of Popup instances */ + + Skin* mSkin; /**< Skin in use by this Popup */ +}; + +#endif diff --git a/src/gui/popupmenu.cpp b/src/gui/popupmenu.cpp index cead20ed..02be3055 100644 --- a/src/gui/popupmenu.cpp +++ b/src/gui/popupmenu.cpp @@ -27,11 +27,11 @@ #include "inventorywindow.h" #include "item_amount.h" #include "popupmenu.h" -#include "windowcontainer.h" #include "../being.h" #include "../beingmanager.h" #include "../floor_item.h" +#include "../graphics.h" #include "../item.h" #include "../localplayer.h" #include "../npc.h" @@ -292,10 +292,10 @@ void PopupMenu::showPopup(int x, int y, Item *item) void PopupMenu::showPopup(int x, int y) { setContentSize(mBrowserBox->getWidth() + 8, mBrowserBox->getHeight() + 8); - if (windowContainer->getWidth() < (x + getWidth() + 5)) - x = windowContainer->getWidth() - getWidth(); - if (windowContainer->getHeight() < (y + getHeight() + 5)) - y = windowContainer->getHeight() - getHeight(); + if (graphics->getWidth() < (x + getWidth() + 5)) + x = graphics->getWidth() - getWidth(); + if (graphics->getHeight() < (y + getHeight() + 5)) + y = graphics->getHeight() - getHeight(); setPosition(x, y); setVisible(true); requestMoveToTop(); diff --git a/src/gui/speechbubble.cpp b/src/gui/speechbubble.cpp index dcb03dca..0b18209e 100644 --- a/src/gui/speechbubble.cpp +++ b/src/gui/speechbubble.cpp @@ -32,13 +32,10 @@ #include "../utils/gettext.h" SpeechBubble::SpeechBubble(): - Window(_("Speech"), false, NULL, "graphics/gui/speechbubble.xml"), + Popup("Speech", NULL, "graphics/gui/speechbubble.xml"), mText("") { setContentSize(140, 46); - setShowTitle(false); - setTitleBarHeight(0); - setMinWidth(29); setMinHeight(29); diff --git a/src/gui/speechbubble.h b/src/gui/speechbubble.h index 6b03cc85..a1a597c1 100644 --- a/src/gui/speechbubble.h +++ b/src/gui/speechbubble.h @@ -23,12 +23,12 @@ #ifndef SPEECHBUBBLE_H #define SPEECHBUBBLE_H -#include "window.h" +#include "popup.h" class ScrollArea; class TextBox; -class SpeechBubble : public Window +class SpeechBubble : public Popup { public: SpeechBubble(); diff --git a/src/gui/window.cpp b/src/gui/window.cpp index def81c53..76c19751 100644 --- a/src/gui/window.cpp +++ b/src/gui/window.cpp @@ -41,7 +41,6 @@ #include "../resources/image.h" ConfigListener *Window::windowConfigListener = 0; -WindowContainer *Window::windowContainer = 0; int Window::instances = 0; int Window::mouseResize = 0; bool Window::mAlphaChanged = false; @@ -216,39 +215,39 @@ void Window::setLocationRelativeTo(ImageRect::ImagePosition position, } else if (position == ImageRect::UPPER_CENTER) { - offsetX += (windowContainer->getWidth() - getWidth()) / 2; + offsetX += (graphics->getWidth() - getWidth()) / 2; } else if (position == ImageRect::UPPER_RIGHT) { - offsetX += windowContainer->getWidth() - getWidth(); + offsetX += graphics->getWidth() - getWidth(); } else if (position == ImageRect::LEFT) { - offsetY += (windowContainer->getHeight() - getHeight()) / 2; + offsetY += (graphics->getHeight() - getHeight()) / 2; } else if (position == ImageRect::CENTER) { - offsetX += (windowContainer->getWidth() - getWidth()) / 2; - offsetY += (windowContainer->getHeight() - getHeight()) / 2; + offsetX += (graphics->getWidth() - getWidth()) / 2; + offsetY += (graphics->getHeight() - getHeight()) / 2; } else if (position == ImageRect::RIGHT) { - offsetX += windowContainer->getWidth() - getWidth(); - offsetY += (windowContainer->getHeight() - getHeight()) / 2; + offsetX += graphics->getWidth() - getWidth(); + offsetY += (graphics->getHeight() - getHeight()) / 2; } else if (position == ImageRect::LOWER_LEFT) { - offsetY += windowContainer->getHeight() - getHeight(); + offsetY += graphics->getHeight() - getHeight(); } else if (position == ImageRect::LOWER_CENTER) { - offsetX += (windowContainer->getWidth() - getWidth()) / 2; - offsetY += windowContainer->getHeight() - getHeight(); + offsetX += (graphics->getWidth() - getWidth()) / 2; + offsetY += graphics->getHeight() - getHeight(); } else if (position == ImageRect::LOWER_RIGHT) { - offsetX += windowContainer->getWidth() - getWidth(); - offsetY += windowContainer->getHeight() - getHeight(); + offsetX += graphics->getWidth() - getWidth(); + offsetY += graphics->getHeight() - getHeight(); } setPosition(offsetX, offsetY); @@ -429,8 +428,8 @@ void Window::mouseDragged(gcn::MouseEvent &event) { int newX = std::max(0, getX()); int newY = std::max(0, getY()); - newX = std::min(windowContainer->getWidth() - getWidth(), newX); - newY = std::min(windowContainer->getHeight() - getHeight(), newY); + newX = std::min(graphics->getWidth() - getWidth(), newX); + newY = std::min(graphics->getHeight() - getHeight(), newY); setPosition(newX, newY); } @@ -475,13 +474,13 @@ void Window::mouseDragged(gcn::MouseEvent &event) newDim.height += newDim.y; newDim.y = 0; } - if (newDim.x + newDim.width > windowContainer->getWidth()) + if (newDim.x + newDim.width > graphics->getWidth()) { - newDim.width = windowContainer->getWidth() - newDim.x; + newDim.width = graphics->getWidth() - newDim.x; } - if (newDim.y + newDim.height > windowContainer->getHeight()) + if (newDim.y + newDim.height > graphics->getHeight()) { - newDim.height = windowContainer->getHeight() - newDim.y; + newDim.height = graphics->getHeight() - newDim.y; } // Update mouse offset when dragging bottom or right border @@ -585,39 +584,39 @@ void Window::setDefaultSize(int defaultWidth, int defaultHeight, } else if (position == ImageRect::UPPER_CENTER) { - x = (windowContainer->getWidth() - defaultWidth) / 2; + x = (graphics->getWidth() - defaultWidth) / 2; } else if (position == ImageRect::UPPER_RIGHT) { - x = windowContainer->getWidth() - defaultWidth; + x = graphics->getWidth() - defaultWidth; } else if (position == ImageRect::LEFT) { - y = (windowContainer->getHeight() - defaultHeight) / 2; + y = (graphics->getHeight() - defaultHeight) / 2; } else if (position == ImageRect::CENTER) { - x = (windowContainer->getWidth() - defaultWidth) / 2; - y = (windowContainer->getHeight() - defaultHeight) / 2; + x = (graphics->getWidth() - defaultWidth) / 2; + y = (graphics->getHeight() - defaultHeight) / 2; } else if (position == ImageRect::RIGHT) { - x = windowContainer->getWidth() - defaultWidth; - y = (windowContainer->getHeight() - defaultHeight) / 2; + x = graphics->getWidth() - defaultWidth; + y = (graphics->getHeight() - defaultHeight) / 2; } else if (position == ImageRect::LOWER_LEFT) { - y = windowContainer->getHeight() - defaultHeight; + y = graphics->getHeight() - defaultHeight; } else if (position == ImageRect::LOWER_CENTER) { - x = (windowContainer->getWidth() - defaultWidth) / 2; - y = windowContainer->getHeight() - defaultHeight; + x = (graphics->getWidth() - defaultWidth) / 2; + y = graphics->getHeight() - defaultHeight; } else if (position == ImageRect::LOWER_RIGHT) { - x = windowContainer->getWidth() - defaultWidth; - y = windowContainer->getHeight() - defaultHeight; + x = graphics->getWidth() - defaultWidth; + y = graphics->getHeight() - defaultHeight; } mDefaultX = x - offsetX; diff --git a/src/gui/window.h b/src/gui/window.h index 7ae7ebba..d573d85f 100644 --- a/src/gui/window.h +++ b/src/gui/window.h @@ -300,10 +300,6 @@ class Window : public gcn::Window, gcn::WidgetListener */ virtual void close(); - protected: - /** The window container windows add themselves to. */ - static WindowContainer *windowContainer; - private: enum ResizeHandles { diff --git a/src/gui/windowcontainer.cpp b/src/gui/windowcontainer.cpp index 0aa61965..ad86a253 100644 --- a/src/gui/windowcontainer.cpp +++ b/src/gui/windowcontainer.cpp @@ -24,6 +24,8 @@ #include "../utils/dtor.h" +WindowContainer *windowContainer = NULL; + void WindowContainer::logic() { delete_all(mDeathList); diff --git a/src/gui/windowcontainer.h b/src/gui/windowcontainer.h index 09f34cf5..23b221cf 100644 --- a/src/gui/windowcontainer.h +++ b/src/gui/windowcontainer.h @@ -46,6 +46,11 @@ class WindowContainer : public gcn::Container */ void scheduleDelete(gcn::Widget *widget); + /** + * Get the number of widget instances + */ + int getNumberOfInstances() { return mDeathList.size(); } + private: /** * List of widgets that are scheduled to be deleted. @@ -55,4 +60,6 @@ class WindowContainer : public gcn::Container Widgets mDeathList; }; +extern WindowContainer* windowContainer; + #endif -- cgit v1.2.3-70-g09d2 From 20ad38045482254b9875ee80de44a9b6f9367d2d Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Sat, 14 Mar 2009 14:28:26 -0600 Subject: Exposed the progress bar colors to the color management tab. Signed-off-by: Ira Rice --- src/gui/palette.cpp | 1 + src/gui/palette.h | 1 + src/gui/progressbar.cpp | 13 ++++++++++--- src/gui/setup_colors.cpp | 27 ++++++++++++++++++--------- src/gui/textrenderer.h | 7 +++---- src/gui/widgets/textpreview.cpp | 10 +++++++++- src/gui/widgets/textpreview.h | 11 +++++++++++ src/gui/window.cpp | 6 ++++++ src/gui/window.h | 5 +++++ src/text.cpp | 2 +- src/textparticle.cpp | 2 +- 11 files changed, 66 insertions(+), 19 deletions(-) (limited to 'src/gui/window.h') diff --git a/src/gui/palette.cpp b/src/gui/palette.cpp index c155cfe2..a3d654be 100644 --- a/src/gui/palette.cpp +++ b/src/gui/palette.cpp @@ -84,6 +84,7 @@ Palette::Palette() : addColor(TEXT, 0x000000, STATIC, _("Text")); addColor(SHADOW, 0x000000, STATIC, indent + _("Text Shadow")); addColor(OUTLINE, 0x000000, STATIC, indent + _("Text Outline")); + addColor(PROGRESS_BAR, 0xffffff, STATIC, indent + _("Progress Bar Labels")); addColor(BACKGROUND, 0xffffff, STATIC, _("Background")); diff --git a/src/gui/palette.h b/src/gui/palette.h index 4d8f7f11..f0a3d541 100644 --- a/src/gui/palette.h +++ b/src/gui/palette.h @@ -51,6 +51,7 @@ class Palette : public gcn::ListModel ENTRY(TEXT)\ ENTRY(SHADOW)\ ENTRY(OUTLINE)\ + ENTRY(PROGRESS_BAR)\ ENTRY(BACKGROUND)\ ENTRY(HIGHLIGHT)\ ENTRY(TAB_HIGHLIGHT)\ diff --git a/src/gui/progressbar.cpp b/src/gui/progressbar.cpp index bec86bb1..025e0ec5 100644 --- a/src/gui/progressbar.cpp +++ b/src/gui/progressbar.cpp @@ -23,6 +23,7 @@ #include #include "gui.h" +#include "palette.h" #include "progressbar.h" #include "../configuration.h" @@ -133,18 +134,24 @@ void ProgressBar::draw(gcn::Graphics *graphics) const int textX = getWidth() / 2; const int textY = (getHeight() - f->getHeight()) / 2; + gcn::Color tempColor = guiPalette->getColor(Palette::OUTLINE); + graphics->setFont(f); - graphics->setColor(gcn::Color(0, 0, 0, alpha)); + graphics->setColor(gcn::Color((int) tempColor.r, (int) tempColor.g, + (int) tempColor.b, alpha)); graphics->drawText(mText, textX + 1, textY, gcn::Graphics::CENTER); graphics->drawText(mText, textX, textY - 1, gcn::Graphics::CENTER); graphics->drawText(mText, textX, textY + 1, gcn::Graphics::CENTER); graphics->drawText(mText, textX - 1, textY, gcn::Graphics::CENTER); - graphics->setColor(gcn::Color(255, 255, 255, alpha)); + tempColor = guiPalette->getColor(Palette::PROGRESS_BAR); + + graphics->setColor(gcn::Color((int) tempColor.r, (int) tempColor.g, + (int) tempColor.b, alpha)); graphics->drawText(mText, textX, textY, gcn::Graphics::CENTER); - graphics->setColor(gcn::Color(0, 0, 0)); + graphics->setColor(guiPalette->getColor(Palette::TEXT)); } } diff --git a/src/gui/setup_colors.cpp b/src/gui/setup_colors.cpp index 09c6a3a9..b7c408d1 100644 --- a/src/gui/setup_colors.cpp +++ b/src/gui/setup_colors.cpp @@ -177,12 +177,12 @@ void Setup_Colors::action(const gcn::ActionEvent &event) mPreview->clearRows(); mPreviewBox->setContent(mTextPreview); mTextPreview->setFont(gui->getFont()); - mTextPreview->setTextColor( - &guiPalette->getColor(Palette::TEXT)); + mTextPreview->setTextColor(&guiPalette->getColor(Palette::TEXT)); mTextPreview->setTextBGColor(NULL); - mTextPreview->setOpaque(false); + mTextPreview->setOpaque(false); mTextPreview->setShadow(true); mTextPreview->setOutline(true); + mTextPreview->useTextAlpha(false); switch (type) { @@ -190,10 +190,16 @@ void Setup_Colors::action(const gcn::ActionEvent &event) case Palette::SHADOW: case Palette::OUTLINE: mTextPreview->setFont(gui->getFont()); - mTextPreview->setOutline(true); mTextPreview->setShadow(type == Palette::SHADOW); mTextPreview->setOutline(type == Palette::OUTLINE); break; + case Palette::PROGRESS_BAR: + mTextPreview->useTextAlpha(true); + mTextPreview->setFont(boldFont); + mTextPreview->setTextColor(col); + mTextPreview->setOutline(true); + mTextPreview->setShadow(false); + break; case Palette::TAB_HIGHLIGHT: mTextPreview->setFont(gui->getFont()); mTextPreview->setTextColor(col); @@ -201,8 +207,13 @@ void Setup_Colors::action(const gcn::ActionEvent &event) mTextPreview->setShadow(false); break; case Palette::BACKGROUND: - case Palette::HIGHLIGHT: case Palette::SHOP_WARNING: + mTextPreview->setBGColor(col); + mTextPreview->setOpaque(true); + mTextPreview->setOutline(false); + mTextPreview->setShadow(false); + break; + case Palette::HIGHLIGHT: mTextPreview->setTextBGColor(col); mTextPreview->setOutline(false); mTextPreview->setShadow(false); @@ -221,13 +232,10 @@ void Setup_Colors::action(const gcn::ActionEvent &event) mPreview->clearRows(); if (ch == '<') - { msg = toString("@@|") + rawmsg + "@@"; - } else - { msg = "##" + toString(ch) + rawmsg; - } + mPreview->addRow(msg); break; case Palette::UNKNOWN_ITEM: @@ -246,6 +254,7 @@ void Setup_Colors::action(const gcn::ActionEvent &event) mTextPreview->setFont(boldFont); mTextPreview->setOutline(false); mTextPreview->setShadow(false); + break; case Palette::PARTICLE: case Palette::EXP_INFO: case Palette::PICKUP_INFO: diff --git a/src/gui/textrenderer.h b/src/gui/textrenderer.h index 599e85a3..c0f5a0e9 100644 --- a/src/gui/textrenderer.h +++ b/src/gui/textrenderer.h @@ -37,7 +37,7 @@ class TextRenderer */ static inline void renderText(gcn::Graphics *graphics, const std::string& text, int x, int y, gcn::Graphics::Alignment align, - const gcn::Color* color, gcn::Font *font, bool outline = false, + const gcn::Color color, gcn::Font *font, bool outline = false, bool shadow = false, int alpha = 255) { graphics->setFont(font); @@ -45,8 +45,7 @@ class TextRenderer // Text shadow if (shadow) { - graphics->setColor(guiPalette->getColor(Palette::SHADOW, - alpha / 2)); + graphics->setColor(guiPalette->getColor(Palette::SHADOW, alpha / 2)); if (outline) { graphics->drawText(text, x + 2, y + 2, align); @@ -73,7 +72,7 @@ class TextRenderer graphics->drawText(text, x, y - 1, align); } - graphics->setColor(*color); + graphics->setColor(color); graphics->drawText(text, x, y, align); } }; diff --git a/src/gui/widgets/textpreview.cpp b/src/gui/widgets/textpreview.cpp index e34bb5cb..5408eebe 100644 --- a/src/gui/widgets/textpreview.cpp +++ b/src/gui/widgets/textpreview.cpp @@ -35,6 +35,7 @@ float TextPreview::mAlpha = config.getValue("guialpha", 0.8); TextPreview::TextPreview(const std::string* text) { mText = text; + mTextAlpha = false; mFont = gui->getFont(); mTextColor = &guiPalette->getColor(Palette::TEXT); mTextBGColor = NULL; @@ -47,6 +48,11 @@ void TextPreview::draw(gcn::Graphics* graphics) if (config.getValue("guialpha", 0.8) != mAlpha) mAlpha = config.getValue("guialpha", 0.8); + int alpha = (int) (mAlpha * 255.0f); + + if (!mTextAlpha) + alpha = 255; + if (mOpaque) { graphics->setColor(gcn::Color((int) mBGColor->r, @@ -69,5 +75,7 @@ void TextPreview::draw(gcn::Graphics* graphics) } TextRenderer::renderText(graphics, *mText, 2, 2, gcn::Graphics::LEFT, - mTextColor, mFont, mOutline, mShadow); + gcn::Color(mTextColor->r, mTextColor->g, + mTextColor->b, alpha), + mFont, mOutline, mShadow, alpha); } diff --git a/src/gui/widgets/textpreview.h b/src/gui/widgets/textpreview.h index a73eb638..8e116262 100644 --- a/src/gui/widgets/textpreview.h +++ b/src/gui/widgets/textpreview.h @@ -44,6 +44,16 @@ class TextPreview : public gcn::Widget mTextColor = color; } + /** + * Sets the text to use the set alpha value. + * + * @param alpha whether to use alpha values for the text or not + */ + inline void useTextAlpha(bool alpha) + { + mTextAlpha = alpha; + } + /** * Sets the color the text background is drawn in. This is only the * rectangle directly behind the text, not to full widget. @@ -123,6 +133,7 @@ class TextPreview : public gcn::Widget const gcn::Color* mBGColor; const gcn::Color* mTextBGColor; static float mAlpha; + bool mTextAlpha; bool mOpaque; bool mShadow; bool mOutline; diff --git a/src/gui/window.cpp b/src/gui/window.cpp index 144357ca..e6e79b45 100644 --- a/src/gui/window.cpp +++ b/src/gui/window.cpp @@ -675,6 +675,12 @@ void Window::setGuiAlpha() mAlphaChanged = false; } +int Window::getGuiAlpha() +{ + float alpha = config.getValue("guialpha", 0.8); + return (int) (alpha * 255.0f); +} + Layout &Window::getLayout() { if (!mLayout) mLayout = new Layout; diff --git a/src/gui/window.h b/src/gui/window.h index d573d85f..e04fcfc3 100644 --- a/src/gui/window.h +++ b/src/gui/window.h @@ -300,6 +300,11 @@ class Window : public gcn::Window, gcn::WidgetListener */ virtual void close(); + /** + * Gets the alpha value used by the window, in a GUIChan usable format. + */ + int getGuiAlpha(); + private: enum ResizeHandles { diff --git a/src/text.cpp b/src/text.cpp index 420eeb8b..4e697f15 100644 --- a/src/text.cpp +++ b/src/text.cpp @@ -81,7 +81,7 @@ void Text::draw(gcn::Graphics *graphics, int xOff, int yOff) TextRenderer::renderText(graphics, mText, mX - xOff, mY - yOff, gcn::Graphics::LEFT, - mColor, boldFont, true); + *mColor, boldFont, true); } FlashText::FlashText(const std::string &text, int x, int y, diff --git a/src/textparticle.cpp b/src/textparticle.cpp index 865c6764..957d67c0 100644 --- a/src/textparticle.cpp +++ b/src/textparticle.cpp @@ -61,5 +61,5 @@ void TextParticle::draw(Graphics *graphics, int offsetX, int offsetY) const TextRenderer::renderText(graphics, mText, screenX, screenY, gcn::Graphics::CENTER, - mColor, mTextFont, mOutline, false, (int) alpha); + *mColor, mTextFont, mOutline, false, (int) alpha); } -- cgit v1.2.3-70-g09d2 From a9b1eccdd2c719f86475c6ce01d4b8eea7dede6c Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Sun, 15 Mar 2009 13:56:40 -0600 Subject: Overrode the reset window function in the chat window to also reset the position of the recorder, as well as fixed resetting the help window, and exposing the buy/sell window to being resettable, as well as remembering its previous position. All windows should now be covered by the reset button on the setup pane. Signed-off-by: Ira Rice --- src/gui/buysell.cpp | 5 +++-- src/gui/buysell.h | 2 ++ src/gui/chat.cpp | 6 ++++++ src/gui/chat.h | 6 ++++++ src/gui/help.cpp | 13 +++++++------ src/gui/setup.cpp | 2 ++ src/gui/window.h | 2 +- 7 files changed, 27 insertions(+), 9 deletions(-) (limited to 'src/gui/window.h') diff --git a/src/gui/buysell.cpp b/src/gui/buysell.cpp index 2022b040..4ac06220 100644 --- a/src/gui/buysell.cpp +++ b/src/gui/buysell.cpp @@ -49,9 +49,10 @@ BuySellDialog::BuySellDialog(Network *network): } buyButton->requestFocus(); - setContentSize(x, 2 * y + buyButton->getHeight()); + setDefaultSize(x + getPadding(), (2 * y + buyButton->getHeight() + + getTitleBarHeight()), ImageRect::CENTER); - setLocationRelativeTo(ImageRect::CENTER); + loadWindowState(); requestFocus(); } diff --git a/src/gui/buysell.h b/src/gui/buysell.h index 747066a7..0842c0e1 100644 --- a/src/gui/buysell.h +++ b/src/gui/buysell.h @@ -54,4 +54,6 @@ class BuySellDialog : public Window, public gcn::ActionListener Network *mNetwork; }; +extern BuySellDialog *buySellDialog; + #endif diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp index 44e08052..5ff9ed46 100644 --- a/src/gui/chat.cpp +++ b/src/gui/chat.cpp @@ -113,6 +113,12 @@ ChatWindow::~ChatWindow() delete mParty; } +void ChatWindow::resetToDefaultSize() +{ + mRecorder->resetToDefaultSize(); + Window::resetToDefaultSize(); +} + void ChatWindow::chatLog(std::string line, int own, bool ignoreRecord) { // Trim whitespace diff --git a/src/gui/chat.h b/src/gui/chat.h index 28408b93..8b710dc8 100644 --- a/src/gui/chat.h +++ b/src/gui/chat.h @@ -119,6 +119,12 @@ class ChatWindow : public Window, public gcn::ActionListener, */ ~ChatWindow(); + /** + * Reset the chat window and recorder window attached to it to their + * default positions. + */ + void resetToDefaultSize(); + /** * Adds a line of text to our message list. Parameters: * diff --git a/src/gui/help.cpp b/src/gui/help.cpp index fec39199..0974abf7 100644 --- a/src/gui/help.cpp +++ b/src/gui/help.cpp @@ -40,16 +40,17 @@ HelpWindow::HelpWindow(): setWindowName(_("Help")); setResizable(true); + setDefaultSize(500, 400, ImageRect::CENTER); + mBrowserBox = new BrowserBox(); mBrowserBox->setOpaque(false); mScrollArea = new ScrollArea(mBrowserBox); Button *okButton = new Button(_("Close"), "close", this); - mScrollArea->setDimension(gcn::Rectangle( - 5, 5, 445, 335 - okButton->getHeight())); - okButton->setPosition( - 450 - okButton->getWidth(), - 345 - okButton->getHeight()); + mScrollArea->setDimension(gcn::Rectangle(5, 5, 445, + 335 - okButton->getHeight())); + okButton->setPosition(450 - okButton->getWidth(), + 345 - okButton->getHeight()); mBrowserBox->setLinkHandler(this); @@ -59,7 +60,7 @@ HelpWindow::HelpWindow(): Layout &layout = getLayout(); layout.setRowHeight(0, Layout::AUTO_SET); - setLocationRelativeTo(getParent()); + loadWindowState(); } void HelpWindow::action(const gcn::ActionEvent &event) diff --git a/src/gui/setup.cpp b/src/gui/setup.cpp index dc232296..ca6b4010 100644 --- a/src/gui/setup.cpp +++ b/src/gui/setup.cpp @@ -38,6 +38,7 @@ extern Window *chatWindow; extern Window *statusWindow; extern Window *buyDialog; extern Window *sellDialog; +extern Window *buySellDialog; extern Window *inventoryWindow; extern Window *emoteWindow; extern Window *npcTextDialog; @@ -140,6 +141,7 @@ void Setup::action(const gcn::ActionEvent &event) statusWindow->resetToDefaultSize(); buyDialog->resetToDefaultSize(); sellDialog->resetToDefaultSize(); + buySellDialog->resetToDefaultSize(); inventoryWindow->resetToDefaultSize(); emoteWindow->resetToDefaultSize(); npcTextDialog->resetToDefaultSize(); diff --git a/src/gui/window.h b/src/gui/window.h index e04fcfc3..518e1ec2 100644 --- a/src/gui/window.h +++ b/src/gui/window.h @@ -266,7 +266,7 @@ class Window : public gcn::Window, gcn::WidgetListener * Reset the win pos and size to default. Don't forget to set defaults * first. */ - void resetToDefaultSize(); + virtual void resetToDefaultSize(); /** * Gets the layout handler for this window. -- cgit v1.2.3-70-g09d2