summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/browserbox.cpp3
-rw-r--r--src/gui/confirm_dialog.cpp18
-rw-r--r--src/gui/debugwindow.cpp27
-rw-r--r--src/gui/emotecontainer.cpp5
-rw-r--r--src/gui/emoteshortcutcontainer.cpp34
-rw-r--r--src/gui/equipmentwindow.cpp3
-rw-r--r--src/gui/inventorywindow.cpp3
-rw-r--r--src/gui/itemcontainer.cpp40
-rw-r--r--src/gui/itemlinkhandler.cpp8
-rw-r--r--src/gui/itempopup.cpp3
-rw-r--r--src/gui/itemshortcutcontainer.cpp73
-rw-r--r--src/gui/listbox.cpp2
-rw-r--r--src/gui/menuwindow.cpp1
-rw-r--r--src/gui/minimap.cpp3
-rw-r--r--src/gui/ok_dialog.cpp15
-rw-r--r--src/gui/playerbox.cpp3
-rw-r--r--src/gui/progressbar.h1
-rw-r--r--src/gui/radiobutton.cpp3
-rw-r--r--src/gui/scrollarea.cpp6
-rw-r--r--src/gui/shoplistbox.cpp2
-rw-r--r--src/gui/shortcutcontainer.cpp32
-rw-r--r--src/gui/speechbubble.cpp10
-rw-r--r--src/gui/speechbubble.h3
-rw-r--r--src/gui/status.cpp3
-rw-r--r--src/gui/table.cpp2
-rw-r--r--src/gui/textfield.cpp6
-rw-r--r--src/gui/trade.cpp1
-rw-r--r--src/gui/viewport.cpp35
-rw-r--r--src/gui/viewport.h24
-rw-r--r--src/gui/widgets/dropdown.cpp22
-rw-r--r--src/gui/widgets/tab.cpp8
-rw-r--r--src/gui/widgets/tabbedarea.cpp17
-rw-r--r--src/gui/window.cpp3
33 files changed, 215 insertions, 204 deletions
diff --git a/src/gui/browserbox.cpp b/src/gui/browserbox.cpp
index 18fa2ad4..b8f58dbb 100644
--- a/src/gui/browserbox.cpp
+++ b/src/gui/browserbox.cpp
@@ -244,6 +244,9 @@ void BrowserBox::mouseMoved(gcn::MouseEvent &event)
void BrowserBox::draw(gcn::Graphics *graphics)
{
+ if (!isVisible())
+ return;
+
if (mOpaque)
{
graphics->setColor(gcn::Color(BGCOLOR));
diff --git a/src/gui/confirm_dialog.cpp b/src/gui/confirm_dialog.cpp
index 2287a195..2bc330c0 100644
--- a/src/gui/confirm_dialog.cpp
+++ b/src/gui/confirm_dialog.cpp
@@ -24,6 +24,7 @@
#include "button.h"
#include "confirm_dialog.h"
+#include "gui.h"
#include "scrollarea.h"
#include "textbox.h"
@@ -50,14 +51,16 @@ ConfirmDialog::ConfirmDialog(const std::string &title, const std::string &msg,
int numRows = mTextBox->getNumberOfRows();
int width = getFont()->getWidth(title);
int inWidth = yesButton->getWidth() + noButton->getWidth() + 5;
+ const int fontHeight = getFont()->getHeight();
if (numRows > 1)
{
- // 15 == height of each line of text (based on font heights)
+ // fontHeight == height of each line of text (based on font heights)
// 14 == row top + bottom graphic pixel heights
- setContentSize(mTextBox->getMinWidth() + 15, 15 + (numRows * 15) + noButton->getHeight());
+ setContentSize(mTextBox->getMinWidth() + fontHeight, ((numRows + 1) *
+ fontHeight) + noButton->getHeight());
mTextArea->setDimension(gcn::Rectangle(4, 5, mTextBox->getMinWidth() + 5,
- 3 + (numRows * 14)));
+ 3 + (numRows * fontHeight)));
}
else
{
@@ -65,16 +68,17 @@ ConfirmDialog::ConfirmDialog(const std::string &title, const std::string &msg,
width = getFont()->getWidth(msg);
if (width < inWidth)
width = inWidth;
- setContentSize(width + 15, 30 + noButton->getHeight());
+ setContentSize(width + fontHeight, (2 * fontHeight) +
+ noButton->getHeight());
mTextArea->setDimension(gcn::Rectangle(4, 5, width + 5, 17));
}
yesButton->setPosition(
(mTextBox->getMinWidth() - inWidth) / 2,
- (numRows * 14) + noButton->getHeight() - 8);
+ ((numRows - 1) * fontHeight) + noButton->getHeight() + 2);
noButton->setPosition(
yesButton->getX() + yesButton->getWidth() + 5,
- (numRows * 14) + noButton->getHeight() - 8);
+ ((numRows - 1) * fontHeight) + noButton->getHeight() + 2);
add(mTextArea);
add(yesButton);
@@ -105,7 +109,5 @@ void ConfirmDialog::action(const gcn::ActionEvent &event)
// Can we receive anything else anyway?
if (event.getId() == "yes" || event.getId() == "no")
- {
scheduleDelete();
- }
}
diff --git a/src/gui/debugwindow.cpp b/src/gui/debugwindow.cpp
index 68b70817..1e199314 100644
--- a/src/gui/debugwindow.cpp
+++ b/src/gui/debugwindow.cpp
@@ -20,8 +20,6 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#include <SDL_mouse.h>
-
#include <guichan/widgets/label.hpp>
#include "debugwindow.h"
@@ -55,28 +53,27 @@ DebugWindow::DebugWindow():
place(0, 0, mFPSLabel);
place(3, 0, mTileMouseLabel);
- place(0, 1, mMusicFileLabel, 2);
+ place(0, 1, mMusicFileLabel, 3);
place(3, 1, mParticleCountLabel);
- place(0, 2, mMapLabel, 2);
- place(0, 3, mMiniMapLabel, 2);
+ place(0, 2, mMapLabel, 4);
+ place(0, 3, mMiniMapLabel, 4);
reflowLayout(375, 0);
}
void DebugWindow::logic()
{
+ if (!isVisible())
+ return;
+
// Get the current mouse position
- int mouseX, mouseY;
- SDL_GetMouseState(&mouseX, &mouseY);
- int mouseTileX = (mouseX + viewport->getCameraX()) / 32;
- int mouseTileY = (mouseY + viewport->getCameraY()) / 32;
+ int mouseTileX = (viewport->getMouseX() + viewport->getCameraX()) / 32;
+ int mouseTileY = (viewport->getMouseY() + viewport->getCameraY()) / 32;
mFPSLabel->setCaption(toString(fps) + " FPS");
- mFPSLabel->adjustSize();
- mTileMouseLabel->setCaption("Mouse: " +
- toString(mouseTileX) + ", " + toString(mouseTileY));
- mTileMouseLabel->adjustSize();
+ mTileMouseLabel->setCaption("Tile: (" + toString(mouseTileX) + ", " +
+ toString(mouseTileY) + ")");
Map *currentMap = engine->getCurrentMap();
if (currentMap)
@@ -84,20 +81,16 @@ void DebugWindow::logic()
const std::string music =
"Music: " + currentMap->getProperty("music");
mMusicFileLabel->setCaption(music);
- mMusicFileLabel->adjustSize();
const std::string minimap =
"MiniMap: " + currentMap->getProperty("minimap");
mMiniMapLabel->setCaption(minimap);
- mMiniMapLabel->adjustSize();
const std::string map =
"Map: " + currentMap->getProperty("_filename");
mMapLabel->setCaption(map);
- mMapLabel->adjustSize();
}
mParticleCountLabel->setCaption("Particle count: " +
toString(Particle::particleCount));
- mParticleCountLabel->adjustSize();
}
diff --git a/src/gui/emotecontainer.cpp b/src/gui/emotecontainer.cpp
index c4cace55..9764ab9c 100644
--- a/src/gui/emotecontainer.cpp
+++ b/src/gui/emotecontainer.cpp
@@ -79,13 +79,14 @@ EmoteContainer::~EmoteContainer()
void EmoteContainer::draw(gcn::Graphics *graphics)
{
+ if (!isVisible())
+ return;
+
int columns = getWidth() / gridWidth;
// Have at least 1 column
if (columns < 1)
- {
columns = 1;
- }
for (int i = 0; i < mMaxEmote ; i++)
{
diff --git a/src/gui/emoteshortcutcontainer.cpp b/src/gui/emoteshortcutcontainer.cpp
index e828df8b..f4cef106 100644
--- a/src/gui/emoteshortcutcontainer.cpp
+++ b/src/gui/emoteshortcutcontainer.cpp
@@ -76,6 +76,15 @@ EmoteShortcutContainer::~EmoteShortcutContainer()
void EmoteShortcutContainer::draw(gcn::Graphics *graphics)
{
+ if (!isVisible())
+ return;
+
+ if (config.getValue("guialpha", 0.8) != mAlpha)
+ {
+ mAlpha = config.getValue("guialpha", 0.8);
+ mBackgroundImg->setAlpha(mAlpha);
+ }
+
Graphics *g = static_cast<Graphics*>(graphics);
graphics->setFont(getFont());
@@ -95,7 +104,8 @@ void EmoteShortcutContainer::draw(gcn::Graphics *graphics)
if (emoteShortcut->getEmote(i))
{
- mEmoteImg[emoteShortcut->getEmote(i) - 1]->draw(g, emoteX + 2, emoteY + 10);
+ mEmoteImg[emoteShortcut->getEmote(i) - 1]->draw(g, emoteX + 2,
+ emoteY + 10);
}
}
@@ -112,12 +122,6 @@ void EmoteShortcutContainer::draw(gcn::Graphics *graphics)
sprite->draw(g, tPosX, tPosY);
}
}
-
- if (config.getValue("guialpha", 0.8) != mAlpha)
- {
- mAlpha = config.getValue("guialpha", 0.8);
- mBackgroundImg->setAlpha(mAlpha);
- }
}
void EmoteShortcutContainer::mouseDragged(gcn::MouseEvent &event)
@@ -130,9 +134,7 @@ void EmoteShortcutContainer::mouseDragged(gcn::MouseEvent &event)
const int emoteId = emoteShortcut->getEmote(index);
if (index == -1)
- {
return;
- }
if (emoteId)
{
@@ -153,19 +155,17 @@ void EmoteShortcutContainer::mousePressed(gcn::MouseEvent &event)
const int index = getIndexFromGrid(event.getX(), event.getY());
if (index == -1)
- {
- return;
- }
+ return;
// Stores the selected emote if there is one.
if (emoteShortcut->isEmoteSelected())
{
- emoteShortcut->setEmote(index);
- emoteShortcut->setEmoteSelected(0);
+ emoteShortcut->setEmote(index);
+ emoteShortcut->setEmoteSelected(0);
}
else if (emoteShortcut->getEmote(index))
{
- mEmoteClicked = true;
+ mEmoteClicked = true;
}
}
@@ -176,9 +176,7 @@ void EmoteShortcutContainer::mouseReleased(gcn::MouseEvent &event)
const int index = getIndexFromGrid(event.getX(), event.getY());
if (emoteShortcut->isEmoteSelected())
- {
emoteShortcut->setEmoteSelected(0);
- }
if (index == -1)
{
@@ -197,9 +195,7 @@ void EmoteShortcutContainer::mouseReleased(gcn::MouseEvent &event)
}
if (mEmoteClicked)
- {
mEmoteClicked = false;
- }
}
}
diff --git a/src/gui/equipmentwindow.cpp b/src/gui/equipmentwindow.cpp
index 6be55e1c..27ea38ff 100644
--- a/src/gui/equipmentwindow.cpp
+++ b/src/gui/equipmentwindow.cpp
@@ -99,6 +99,9 @@ EquipmentWindow::~EquipmentWindow()
void EquipmentWindow::draw(gcn::Graphics *graphics)
{
+ if (!isVisible())
+ return;
+
// Draw window graphics
Window::draw(graphics);
diff --git a/src/gui/inventorywindow.cpp b/src/gui/inventorywindow.cpp
index 347c36ac..226b3178 100644
--- a/src/gui/inventorywindow.cpp
+++ b/src/gui/inventorywindow.cpp
@@ -113,6 +113,9 @@ InventoryWindow::~InventoryWindow()
void InventoryWindow::logic()
{
+ if (!isVisible())
+ return;
+
Window::logic();
// It would be nicer if this update could be event based, needs some
diff --git a/src/gui/itemcontainer.cpp b/src/gui/itemcontainer.cpp
index 79aeb227..02d6e66d 100644
--- a/src/gui/itemcontainer.cpp
+++ b/src/gui/itemcontainer.cpp
@@ -20,13 +20,12 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#include <SDL_mouse.h>
-
#include <guichan/mouseinput.hpp>
#include <guichan/selectionlistener.hpp>
#include "itemcontainer.h"
#include "itempopup.h"
+#include "viewport.h"
#include "../graphics.h"
#include "../inventory.h"
@@ -72,6 +71,9 @@ ItemContainer::~ItemContainer()
void ItemContainer::logic()
{
+ if (!isVisible())
+ return;
+
gcn::Widget::logic();
int i = mInventory->getLastUsedSlot() - 1; // Count from 0, usage from 2
@@ -85,18 +87,19 @@ void ItemContainer::logic()
void ItemContainer::draw(gcn::Graphics *graphics)
{
+ if (!isVisible())
+ return;
+
int columns = getWidth() / gridWidth;
// Have at least 1 column
if (columns < 1)
- {
columns = 1;
- }
/*
- * mOffset is used to compensate for some weirdness that eAthena inherited from
- * Ragnarok Online. Inventory slots and cart slots are +2 from their actual index,
- * while storage slots are +1.
+ * mOffset is used to compensate for some weirdness that eAthena inherited
+ * from Ragnarok Online. Inventory slots and cart slots are +2 from their
+ * actual index, while storage slots are +1.
*/
for (int i = mOffset; i < mInventory->getSize(); i++)
{
@@ -105,31 +108,25 @@ void ItemContainer::draw(gcn::Graphics *graphics)
if (!item || item->getQuantity() <= 0)
continue;
- int itemX = ((i - 2) % columns) * gridWidth;
- int itemY = ((i - 2) / columns) * gridHeight;
+ int itemX = ((i - mOffset) % columns) * gridWidth;
+ int itemY = ((i - mOffset) / columns) * gridHeight;
// Draw selection image below selected item
if (mSelectedItemIndex == i)
- {
- static_cast<Graphics*>(graphics)->drawImage(
- mSelImg, itemX, itemY);
- }
+ static_cast<Graphics*>(graphics)->drawImage(mSelImg, itemX, itemY);
// Draw item icon
Image* image = item->getImage();
+
if (image)
- {
- static_cast<Graphics*>(graphics)->drawImage(
- image, itemX, itemY);
- }
+ static_cast<Graphics*>(graphics)->drawImage(image, itemX, itemY);
// Draw item caption
graphics->setFont(getFont());
graphics->setColor(0x000000);
graphics->drawText(
(item->isEquipped() ? "Eq." : toString(item->getQuantity())),
- itemX + gridWidth / 2,
- itemY + gridHeight - 11,
+ itemX + gridWidth / 2, itemY + gridHeight - 11,
gcn::Graphics::CENTER);
}
}
@@ -258,12 +255,9 @@ void ItemContainer::mouseMoved(gcn::MouseEvent &event)
if (item)
{
- int mouseX, mouseY;
- SDL_GetMouseState(&mouseX, &mouseY);
-
mItemPopup->setItem(item->getInfo());
mItemPopup->setOpaque(false);
- mItemPopup->view(mouseX, mouseY);
+ mItemPopup->view(viewport->getMouseX(), viewport->getMouseY());
}
else
{
diff --git a/src/gui/itemlinkhandler.cpp b/src/gui/itemlinkhandler.cpp
index 4a64d53f..06263ce2 100644
--- a/src/gui/itemlinkhandler.cpp
+++ b/src/gui/itemlinkhandler.cpp
@@ -23,10 +23,9 @@
#include <sstream>
#include <string>
-#include <SDL_mouse.h>
-
#include "itemlinkhandler.h"
#include "itempopup.h"
+#include "viewport.h"
#include "../resources/iteminfo.h"
#include "../resources/itemdb.h"
@@ -50,15 +49,12 @@ void ItemLinkHandler::handleLink(const std::string &link)
if (id > 0)
{
const ItemInfo &iteminfo = ItemDB::get(id);
- int mouseX, mouseY;
-
- SDL_GetMouseState(&mouseX, &mouseY);
mItemPopup->setItem(iteminfo);
if (mItemPopup->isVisible())
mItemPopup->setVisible(false);
else
- mItemPopup->view(mouseX, mouseY);
+ mItemPopup->view(viewport->getMouseX(), viewport->getMouseY());
}
}
diff --git a/src/gui/itempopup.cpp b/src/gui/itempopup.cpp
index 88afcd5b..0f7e2d11 100644
--- a/src/gui/itempopup.cpp
+++ b/src/gui/itempopup.cpp
@@ -104,6 +104,9 @@ ItemPopup::~ItemPopup()
void ItemPopup::setItem(const ItemInfo &item)
{
+ if (item.getName() == mItemName->getCaption())
+ return;
+
mItemName->setCaption(item.getName());
mItemName->setForegroundColor(getColor(item.getType()));
mItemName->setWidth(boldFont->getWidth(item.getName()));
diff --git a/src/gui/itemshortcutcontainer.cpp b/src/gui/itemshortcutcontainer.cpp
index 10ced157..e7a9afbe 100644
--- a/src/gui/itemshortcutcontainer.cpp
+++ b/src/gui/itemshortcutcontainer.cpp
@@ -19,7 +19,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#include <SDL_mouse.h>
#include "itemshortcutcontainer.h"
#include "itempopup.h"
@@ -67,6 +66,9 @@ ItemShortcutContainer::~ItemShortcutContainer()
void ItemShortcutContainer::logic()
{
+ if (!isVisible())
+ return;
+
gcn::Widget::logic();
int i = itemShortcut->getItemCount();
@@ -80,6 +82,15 @@ void ItemShortcutContainer::logic()
void ItemShortcutContainer::draw(gcn::Graphics *graphics)
{
+ if (!isVisible())
+ return;
+
+ if (config.getValue("guialpha", 0.8) != mAlpha)
+ {
+ mAlpha = config.getValue("guialpha", 0.8);
+ mBackgroundImg->setAlpha(mAlpha);
+ }
+
Graphics *g = static_cast<Graphics*>(graphics);
graphics->setFont(getFont());
@@ -102,23 +113,23 @@ void ItemShortcutContainer::draw(gcn::Graphics *graphics)
Item *item =
player_node->getInventory()->findItem(itemShortcut->getItem(i));
- if (item) {
+
+ if (item)
+ {
// Draw item icon.
- const std::string label =
- item->isEquipped() ? "Eq." : toString(item->getQuantity());
Image* image = item->getImage();
- if (image) {
+
+ if (image)
+ {
const std::string label =
item->isEquipped() ? "Eq." : toString(item->getQuantity());
g->drawImage(image, itemX, itemY);
- g->drawText(
- label,
- itemX + mBoxWidth / 2,
- itemY + mBoxHeight - 14,
- gcn::Graphics::CENTER);
+ g->drawText(label, itemX + mBoxWidth / 2,
+ itemY + mBoxHeight - 14, gcn::Graphics::CENTER);
}
}
}
+
if (mItemMoved)
{
// Draw the item image being dragged by the cursor.
@@ -129,18 +140,11 @@ void ItemShortcutContainer::draw(gcn::Graphics *graphics)
const int tPosY = mCursorPosY - (image->getHeight() / 2);
g->drawImage(image, tPosX, tPosY);
- g->drawText(
- toString(mItemMoved->getQuantity()),
- tPosX + mBoxWidth / 2,
- tPosY + mBoxHeight - 14,
- gcn::Graphics::CENTER);
+ g->drawText(toString(mItemMoved->getQuantity()),
+ tPosX + mBoxWidth / 2, tPosY + mBoxHeight - 14,
+ gcn::Graphics::CENTER);
}
}
-
- if (config.getValue("guialpha", 0.8) != mAlpha)
- {
- mBackgroundImg->setAlpha(config.getValue("guialpha", 0.8));
- }
}
void ItemShortcutContainer::mouseDragged(gcn::MouseEvent &event)
@@ -152,10 +156,7 @@ void ItemShortcutContainer::mouseDragged(gcn::MouseEvent &event)
const int index = getIndexFromGrid(event.getX(), event.getY());
const int itemId = itemShortcut->getItem(index);
- if (index == -1)
- return;
-
- if (itemId < 0)
+ if (index == -1 || itemId < 0)
return;
Item *item = player_node->getInventory()->findItem(itemId);
@@ -166,7 +167,8 @@ void ItemShortcutContainer::mouseDragged(gcn::MouseEvent &event)
itemShortcut->removeItem(index);
}
}
- if (mItemMoved) {
+ if (mItemMoved)
+ {
mCursorPosX = event.getX();
mCursorPosY = event.getY();
}
@@ -176,6 +178,7 @@ void ItemShortcutContainer::mouseDragged(gcn::MouseEvent &event)
void ItemShortcutContainer::mousePressed(gcn::MouseEvent &event)
{
const int index = getIndexFromGrid(event.getX(), event.getY());
+
if (index == -1)
return;
@@ -199,12 +202,9 @@ void ItemShortcutContainer::mousePressed(gcn::MouseEvent &event)
if (!item)
return;
- /* Convert relative to the window coordinates to absolute screen
- * coordinates.
- */
- int mx, my;
- SDL_GetMouseState(&mx, &my);
- viewport->showPopup(mx, my, item);
+ // Convert relative to the window coordinates to absolute screen
+ // coordinates.
+ viewport->showPopup(viewport->getMouseX(), viewport->getMouseY(), item);
}
}
@@ -230,6 +230,7 @@ void ItemShortcutContainer::mouseReleased(gcn::MouseEvent &event)
{
itemShortcut->useItem(index);
}
+
if (mItemClicked)
mItemClicked = false;
}
@@ -241,22 +242,16 @@ void ItemShortcutContainer::mouseMoved(gcn::MouseEvent &event)
const int index = getIndexFromGrid(event.getX(), event.getY());
const int itemId = itemShortcut->getItem(index);
- if (index == -1)
- return;
-
- if (itemId < 0)
+ if (index == -1 || itemId < 0)
return;
Item *item = player_node->getInventory()->findItem(itemId);
if (item)
{
- int mouseX, mouseY;
- SDL_GetMouseState(&mouseX, &mouseY);
-
mItemPopup->setItem(item->getInfo());
mItemPopup->setOpaque(false);
- mItemPopup->view(mouseX, mouseY);
+ mItemPopup->view(viewport->getMouseX(), viewport->getMouseY());
}
else
{
diff --git a/src/gui/listbox.cpp b/src/gui/listbox.cpp
index 45d14884..6d5c0ca8 100644
--- a/src/gui/listbox.cpp
+++ b/src/gui/listbox.cpp
@@ -39,7 +39,7 @@ ListBox::ListBox(gcn::ListModel *listModel):
void ListBox::draw(gcn::Graphics *graphics)
{
- if (!mListModel)
+ if (!mListModel || !isVisible())
return;
if (config.getValue("guialpha", 0.8) != mAlpha)
diff --git a/src/gui/menuwindow.cpp b/src/gui/menuwindow.cpp
index 65bd7082..8a695865 100644
--- a/src/gui/menuwindow.cpp
+++ b/src/gui/menuwindow.cpp
@@ -90,7 +90,6 @@ void MenuWindow::draw(gcn::Graphics *graphics)
drawChildren(graphics);
}
-
void MenuWindowListener::action(const gcn::ActionEvent &event)
{
Window *window = NULL;
diff --git a/src/gui/minimap.cpp b/src/gui/minimap.cpp
index 80c95dd7..2a97b949 100644
--- a/src/gui/minimap.cpp
+++ b/src/gui/minimap.cpp
@@ -113,6 +113,9 @@ void Minimap::draw(gcn::Graphics *graphics)
{
setVisible(mShow);
+ if (!isVisible())
+ return;
+
Window::draw(graphics);
if (!mShow)
diff --git a/src/gui/ok_dialog.cpp b/src/gui/ok_dialog.cpp
index 23c4d465..9621b389 100644
--- a/src/gui/ok_dialog.cpp
+++ b/src/gui/ok_dialog.cpp
@@ -23,6 +23,7 @@
#include <guichan/font.hpp>
#include "button.h"
+#include "gui.h"
#include "ok_dialog.h"
#include "scrollarea.h"
#include "textbox.h"
@@ -47,14 +48,15 @@ OkDialog::OkDialog(const std::string &title, const std::string &msg,
mTextBox->setTextWrapped(msg, 260);
int numRows = mTextBox->getNumberOfRows();
+ const int fontHeight = getFont()->getHeight();
if (numRows > 1)
{
- // 15 == height of each line of text (based on font heights)
// 14 == row top + bottom graphic pixel heights
- setContentSize(mTextBox->getMinWidth() + 15, 15 + (numRows * 15) + okButton->getHeight());
+ setContentSize(mTextBox->getMinWidth() + fontHeight, ((numRows + 1) *
+ fontHeight) + okButton->getHeight());
mTextArea->setDimension(gcn::Rectangle(4, 5, mTextBox->getMinWidth() + 5,
- 3 + (numRows * 14)));
+ 3 + (numRows * fontHeight)));
}
else
{
@@ -63,12 +65,12 @@ OkDialog::OkDialog(const std::string &title, const std::string &msg,
width = getFont()->getWidth(msg);
if (width < okButton->getWidth())
width = okButton->getWidth();
- setContentSize(width + 15, 30 + okButton->getHeight());
+ setContentSize(width + fontHeight, 30 + okButton->getHeight());
mTextArea->setDimension(gcn::Rectangle(4, 5, width + 5, 17));
}
okButton->setPosition((mTextBox->getMinWidth() - okButton->getWidth()) / 2,
- (numRows * 14) + okButton->getHeight() - 8);
+ ((numRows - 1) * fontHeight) + okButton->getHeight() + 2);
add(mTextArea);
add(okButton);
@@ -93,7 +95,6 @@ void OkDialog::action(const gcn::ActionEvent &event)
}
// Can we receive anything else anyway?
- if (event.getId() == "ok") {
+ if (event.getId() == "ok")
scheduleDelete();
- }
}
diff --git a/src/gui/playerbox.cpp b/src/gui/playerbox.cpp
index e7ee3afe..2a6cdb20 100644
--- a/src/gui/playerbox.cpp
+++ b/src/gui/playerbox.cpp
@@ -79,6 +79,9 @@ PlayerBox::~PlayerBox()
void PlayerBox::draw(gcn::Graphics *graphics)
{
+ if (!isVisible())
+ return;
+
if (mPlayer)
{
// Draw character
diff --git a/src/gui/progressbar.h b/src/gui/progressbar.h
index ff146745..3c88f3a3 100644
--- a/src/gui/progressbar.h
+++ b/src/gui/progressbar.h
@@ -108,6 +108,7 @@ class ProgressBar : public gcn::Widget
Uint8 mRed, mGreen, mBlue;
Uint8 mRedToGo, mGreenToGo, mBlueToGo;
std::string mText;
+ bool mUpdated;
static ImageRect mBorder;
static int mInstances;
diff --git a/src/gui/radiobutton.cpp b/src/gui/radiobutton.cpp
index a8ab61c4..c839238b 100644
--- a/src/gui/radiobutton.cpp
+++ b/src/gui/radiobutton.cpp
@@ -70,6 +70,9 @@ RadioButton::~RadioButton()
void RadioButton::drawBox(gcn::Graphics* graphics)
{
+ if (!isVisible())
+ return;
+
if (config.getValue("guialpha", 0.8) != mAlpha)
{
mAlpha = config.getValue("guialpha", 0.8);
diff --git a/src/gui/scrollarea.cpp b/src/gui/scrollarea.cpp
index d655ad52..43b27f23 100644
--- a/src/gui/scrollarea.cpp
+++ b/src/gui/scrollarea.cpp
@@ -149,6 +149,9 @@ void ScrollArea::init()
void ScrollArea::logic()
{
+ if (!isVisible())
+ return;
+
gcn::ScrollArea::logic();
gcn::Widget *content = getContent();
@@ -171,6 +174,9 @@ void ScrollArea::logic()
void ScrollArea::draw(gcn::Graphics *graphics)
{
+ if (!isVisible())
+ return;
+
if (mVBarVisible)
{
drawUpButton(graphics);
diff --git a/src/gui/shoplistbox.cpp b/src/gui/shoplistbox.cpp
index 6e70e022..776f26bc 100644
--- a/src/gui/shoplistbox.cpp
+++ b/src/gui/shoplistbox.cpp
@@ -58,7 +58,7 @@ void ShopListBox::setPlayersMoney(int money)
void ShopListBox::draw(gcn::Graphics *gcnGraphics)
{
- if (!mListModel)
+ if (!mListModel || !isVisible())
return;
if (config.getValue("guialpha", 0.8) != mAlpha)
diff --git a/src/gui/shortcutcontainer.cpp b/src/gui/shortcutcontainer.cpp
index 13ff042d..50ec9d06 100644
--- a/src/gui/shortcutcontainer.cpp
+++ b/src/gui/shortcutcontainer.cpp
@@ -39,34 +39,28 @@ ShortcutContainer::ShortcutContainer():
void ShortcutContainer::widgetResized(const gcn::Event &event)
{
mGridWidth = getWidth() / mBoxWidth;
+
if (mGridWidth < 1)
- {
mGridWidth = 1;
- }
-
- setHeight((mMaxItems / mGridWidth +
- (mMaxItems % mGridWidth > 0 ? 1 : 0)) * mBoxHeight);
mGridHeight = getHeight() / mBoxHeight;
+
if (mGridHeight < 1)
- {
mGridHeight = 1;
- }
+
+ setHeight((mMaxItems / mGridWidth +
+ (mMaxItems % mGridWidth > 0 ? 1 : 0)) * mBoxHeight);
}
int ShortcutContainer::getIndexFromGrid(int pointX, int pointY) const
{
- const gcn::Rectangle tRect = gcn::Rectangle(
- 0, 0, mGridWidth * mBoxWidth, mGridHeight * mBoxHeight);
- if (!tRect.isPointInRect(pointX, pointY))
- {
- return -1;
- }
- const int index = ((pointY / mBoxHeight) * mGridWidth) +
- pointX / mBoxWidth;
- if (index >= mMaxItems)
- {
- return -1;
- }
+ const gcn::Rectangle tRect = gcn::Rectangle(0, 0, mGridWidth * mBoxWidth,
+ mGridHeight * mBoxHeight);
+
+ int index = ((pointY / mBoxHeight) * mGridWidth) + pointX / mBoxWidth;
+
+ if (!tRect.isPointInRect(pointX, pointY) || index >= mMaxItems)
+ index = -1;
+
return index;
}
diff --git a/src/gui/speechbubble.cpp b/src/gui/speechbubble.cpp
index 209f964b..d54bf9ad 100644
--- a/src/gui/speechbubble.cpp
+++ b/src/gui/speechbubble.cpp
@@ -32,7 +32,8 @@
#include "../utils/gettext.h"
SpeechBubble::SpeechBubble():
- Window(_("Speech"), false, NULL, "graphics/gui/speechbubble.xml")
+ Window(_("Speech"), false, NULL, "graphics/gui/speechbubble.xml"),
+ mText("")
{
setContentSize(140, 46);
setShowTitle(false);
@@ -67,10 +68,13 @@ void SpeechBubble::setCaption(const std::string &name, const gcn::Color &color)
mCaption->setForegroundColor(color);
}
-void SpeechBubble::setText(std::string mText, bool showName)
+void SpeechBubble::setText(std::string text, bool showName)
{
+ if ((text == mText) && (mCaption->getWidth() <= mSpeechBox->getMinWidth()))
+ return;
+
int width = mCaption->getWidth();
- mSpeechBox->setTextWrapped(mText, 130 > width ? 130 : width);
+ mSpeechBox->setTextWrapped(text, 130 > width ? 130 : width);
const int fontHeight = getFont()->getHeight();
const int numRows = showName ? mSpeechBox->getNumberOfRows() + 1 :
diff --git a/src/gui/speechbubble.h b/src/gui/speechbubble.h
index dce421ec..6b03cc85 100644
--- a/src/gui/speechbubble.h
+++ b/src/gui/speechbubble.h
@@ -35,11 +35,12 @@ class SpeechBubble : public Window
void setCaption(const std::string &name,
const gcn::Color &color = 0x000000);
- void setText(std::string mText, bool showName = true);
+ void setText(std::string text, bool showName = true);
void setLocation(int x, int y);
unsigned int getNumRows();
private:
+ std::string mText;
gcn::Label *mCaption;
TextBox *mSpeechBox;
ScrollArea *mSpeechArea;
diff --git a/src/gui/status.cpp b/src/gui/status.cpp
index 49af3ae2..6419eabb 100644
--- a/src/gui/status.cpp
+++ b/src/gui/status.cpp
@@ -272,6 +272,9 @@ void StatusWindow::update()
void StatusWindow::draw(gcn::Graphics *g)
{
+ if (!isVisible())
+ return;
+
update();
Window::draw(g);
diff --git a/src/gui/table.cpp b/src/gui/table.cpp
index 29a33b7a..b2571495 100644
--- a/src/gui/table.cpp
+++ b/src/gui/table.cpp
@@ -265,7 +265,7 @@ void GuiTable::installActionListeners(void)
// -- widget ops
void GuiTable::draw(gcn::Graphics* graphics)
{
- if (!mModel)
+ if (!mModel || !isVisible())
return;
if (config.getValue("guialpha", 0.8) != mAlpha)
diff --git a/src/gui/textfield.cpp b/src/gui/textfield.cpp
index ed83622d..054bc405 100644
--- a/src/gui/textfield.cpp
+++ b/src/gui/textfield.cpp
@@ -84,7 +84,11 @@ TextField::~TextField()
void TextField::draw(gcn::Graphics *graphics)
{
- if (isFocused()) {
+ if (!isVisible())
+ return;
+
+ if (isFocused())
+ {
drawCaret(graphics,
getFont()->getWidth(mText.substr(0, mCaretPosition)) -
mXScroll);
diff --git a/src/gui/trade.cpp b/src/gui/trade.cpp
index ba2e2462..a12b94ed 100644
--- a/src/gui/trade.cpp
+++ b/src/gui/trade.cpp
@@ -117,7 +117,6 @@ void TradeWindow::widgetResized(const gcn::Event &event)
Window::widgetResized(event);
}
-
void TradeWindow::addMoney(int amount)
{
mMoneyLabel->setCaption(strprintf(_("You get %d GP."), amount));
diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp
index f655888c..56274573 100644
--- a/src/gui/viewport.cpp
+++ b/src/gui/viewport.cpp
@@ -43,6 +43,8 @@ extern volatile int tick_time;
Viewport::Viewport():
mMap(0),
+ mMouseX(0),
+ mMouseY(0),
mPixelViewX(0.0f),
mPixelViewY(0.0f),
mTileViewX(0),
@@ -148,18 +150,14 @@ void Viewport::draw(gcn::Graphics *gcnGraphics)
int viewYmax = (mMap->getHeight() * 32) - graphics->getHeight();
if (mMap)
{
- if (mPixelViewX < 0) {
+ if (mPixelViewX < 0)
mPixelViewX = 0;
- }
- if (mPixelViewY < 0) {
+ if (mPixelViewY < 0)
mPixelViewY = 0;
- }
- if (mPixelViewX > viewXmax) {
+ if (mPixelViewX > viewXmax)
mPixelViewX = viewXmax;
- }
- if (mPixelViewY > viewYmax) {
+ if (mPixelViewY > viewYmax)
mPixelViewY = viewYmax;
- }
}
mTileViewX = (int) (mPixelViewX + 16) / 32;
@@ -175,11 +173,10 @@ void Viewport::draw(gcn::Graphics *gcnGraphics)
if (mShowDebugPath)
{
// Get the current mouse position
- int mouseX, mouseY;
- SDL_GetMouseState(&mouseX, &mouseY);
+ SDL_GetMouseState(&mMouseX, &mMouseY);
- int mouseTileX = mouseX / 32 + mTileViewX;
- int mouseTileY = mouseY / 32 + mTileViewY;
+ int mouseTileX = mMouseX / 32 + mTileViewX;
+ int mouseTileY = mMouseY / 32 + mTileViewY;
Path debugPath = mMap->findPath(player_node->mX, player_node->mY,
mouseTileX, mouseTileY);
@@ -204,7 +201,6 @@ void Viewport::draw(gcn::Graphics *gcnGraphics)
player_node->setName(player_node->getName());
}
-
// Draw text
if (textManager)
{
@@ -215,8 +211,8 @@ void Viewport::draw(gcn::Graphics *gcnGraphics)
Beings &beings = beingManager->getAll();
for (BeingIterator i = beings.begin(); i != beings.end(); i++)
{
- (*i)->drawSpeech(-(int) mPixelViewX, -(int) mPixelViewY);
- (*i)->drawEmotion(graphics, -(int) mPixelViewX, -(int) mPixelViewY);
+ (*i)->drawSpeech((int) mPixelViewX, (int) mPixelViewY);
+ (*i)->drawEmotion(graphics, (int) mPixelViewX, (int) mPixelViewY);
}
// Draw contained widgets
@@ -230,14 +226,13 @@ void Viewport::logic()
if (!mMap || !player_node)
return;
- int mouseX, mouseY;
- Uint8 button = SDL_GetMouseState(&mouseX, &mouseY);
+ Uint8 button = SDL_GetMouseState(&mMouseX, &mMouseY);
if (mPlayerFollowMouse && button & SDL_BUTTON(1) &&
mWalkTime != player_node->mWalkTime)
{
- player_node->setDestination(mouseX / 32 + mTileViewX,
- mouseY / 32 + mTileViewY);
+ player_node->setDestination(mMouseX / 32 + mTileViewX,
+ mMouseY / 32 + mTileViewY);
mWalkTime = player_node->mWalkTime;
}
}
@@ -343,9 +338,7 @@ void Viewport::mousePressed(gcn::MouseEvent &event)
Being *target = beingManager->findBeingByPixel(x, y);
if (target)
- {
player_node->setTarget(target);
- }
}
}
diff --git a/src/gui/viewport.h b/src/gui/viewport.h
index a131d162..12fdb187 100644
--- a/src/gui/viewport.h
+++ b/src/gui/viewport.h
@@ -116,29 +116,41 @@ class Viewport : public WindowContainer, public gcn::MouseListener,
int getCameraY() const { return (int) mPixelViewY; }
/**
+ * Returns mouse x in pixels.
+ */
+ int getMouseX() const { return mMouseX; }
+
+ /**
+ * Returns mouse y in pixels.
+ */
+ int getMouseY() const { return mMouseY; }
+
+ /**
* Changes viewpoint by relative pixel coordinates.
*/
void scrollBy(float x, float y) { mPixelViewX += x; mPixelViewY += y; }
private:
- Map *mMap; /**< The current map. */
+ Map *mMap; /**< The current map. */
int mScrollRadius;
int mScrollLaziness;
int mScrollCenterOffsetX;
int mScrollCenterOffsetY;
- float mPixelViewX; /**< Current viewpoint in pixels. */
- float mPixelViewY; /**< Current viewpoint in pixels. */
+ int mMouseX; /**< Current mouse position in pixels. */
+ int mMouseY; /**< Current mouse position in pixels. */
+ float mPixelViewX; /**< Current viewpoint in pixels. */
+ float mPixelViewY; /**< Current viewpoint in pixels. */
int mTileViewX; /**< Current viewpoint in tiles. */
int mTileViewY; /**< Current viewpoint in tiles. */
- bool mShowDebugPath; /**< Show a path from player to pointer. */
+ bool mShowDebugPath; /**< Show a path from player to pointer. */
bool mPlayerFollowMouse;
int mWalkTime;
- PopupMenu *mPopupMenu; /**< Popup menu. */
+ PopupMenu *mPopupMenu; /**< Popup menu. */
};
-extern Viewport *viewport; /**< The viewport */
+extern Viewport *viewport; /**< The viewport */
#endif
diff --git a/src/gui/widgets/dropdown.cpp b/src/gui/widgets/dropdown.cpp
index ed4d260b..9fcf173c 100644
--- a/src/gui/widgets/dropdown.cpp
+++ b/src/gui/widgets/dropdown.cpp
@@ -75,12 +75,15 @@ DropDown::DropDown(gcn::ListModel *listModel, gcn::ScrollArea *scrollArea,
int gridy[4] = {0, 3, 28, 31};
int a = 0, x, y;
- for (y = 0; y < 3; y++) {
- for (x = 0; x < 3; x++) {
- skin.grid[a] = boxBorder->getSubImage(
- gridx[x], gridy[y],
- gridx[x + 1] - gridx[x] + 1,
- gridy[y + 1] - gridy[y] + 1);
+ for (y = 0; y < 3; y++)
+ {
+ for (x = 0; x < 3; x++)
+ {
+ skin.grid[a] = boxBorder->getSubImage(gridx[x], gridy[y],
+ gridx[x + 1] -
+ gridx[x] + 1,
+ gridy[y + 1] -
+ gridy[y] + 1);
skin.grid[a]->setAlpha(mAlpha);
a++;
}
@@ -109,16 +112,15 @@ DropDown::~DropDown()
void DropDown::draw(gcn::Graphics* graphics)
{
+ if (!isVisible())
+ return;
+
int h;
if (mDroppedDown)
- {
h = mFoldedUpHeight;
- }
else
- {
h = getHeight();
- }
if (config.getValue("guialpha", 0.8) != mAlpha)
{
diff --git a/src/gui/widgets/tab.cpp b/src/gui/widgets/tab.cpp
index 263e5bbd..97f6010c 100644
--- a/src/gui/widgets/tab.cpp
+++ b/src/gui/widgets/tab.cpp
@@ -36,7 +36,7 @@
int Tab::mInstances = 0;
float Tab::mAlpha = config.getValue("guialpha", 0.8);
-enum{
+enum {
TAB_STANDARD, // 0
TAB_HIGHLIGHTED, // 1
TAB_SELECTED, // 2
@@ -95,8 +95,10 @@ void Tab::init()
{
tab[mode] = resman->getImage(data[mode].file);
a = 0;
- for (y = 0; y < 3; y++) {
- for (x = 0; x < 3; x++) {
+ for (y = 0; y < 3; y++)
+ {
+ for (x = 0; x < 3; x++)
+ {
tabImg[mode].grid[a] = tab[mode]->getSubImage(
data[x].gridX, data[y].gridY,
data[x + 1].gridX - data[x].gridX + 1,
diff --git a/src/gui/widgets/tabbedarea.cpp b/src/gui/widgets/tabbedarea.cpp
index aaa3463f..2c454b69 100644
--- a/src/gui/widgets/tabbedarea.cpp
+++ b/src/gui/widgets/tabbedarea.cpp
@@ -41,9 +41,8 @@ Tab* TabbedArea::getTab(const std::string &name)
while (itr != itr_end)
{
if ((*itr).first->getCaption() == name)
- {
return static_cast<Tab*>((*itr).first);
- }
+
++itr;
}
return NULL;
@@ -52,9 +51,7 @@ Tab* TabbedArea::getTab(const std::string &name)
void TabbedArea::draw(gcn::Graphics *graphics)
{
if (mTabs.empty())
- {
return;
- }
drawChildren(graphics);
}
@@ -65,9 +62,8 @@ gcn::Widget* TabbedArea::getWidget(const std::string &name)
while (itr != itr_end)
{
if ((*itr).first->getCaption() == name)
- {
return (*itr).second;
- }
+
++itr;
}
@@ -92,9 +88,7 @@ void TabbedArea::addTab(Tab *tab, gcn::Widget *widget)
mTabs.push_back(std::pair<Tab*, gcn::Widget*>(tab, widget));
if (!mSelectedTab)
- {
setSelectedTab(tab);
- }
adjustTabPositions();
adjustSize();
@@ -108,15 +102,10 @@ void TabbedArea::removeTab(Tab *tab)
{
int index = getSelectedTabIndex();
- if (index == (int)mTabs.size() - 1
- && mTabs.size() == 1)
- {
+ if (index == (int)mTabs.size() - 1 && mTabs.size() == 1)
tabIndexToBeSelected = -1;
- }
else
- {
tabIndexToBeSelected = index - 1;
- }
}
TabContainer::iterator iter;
diff --git a/src/gui/window.cpp b/src/gui/window.cpp
index 516b4138..e285c3c4 100644
--- a/src/gui/window.cpp
+++ b/src/gui/window.cpp
@@ -169,6 +169,9 @@ void Window::setWindowContainer(WindowContainer *wc)
void Window::draw(gcn::Graphics *graphics)
{
+ if (!isVisible())
+ return;
+
Graphics *g = static_cast<Graphics*>(graphics);
g->drawImageRect(0, 0, getWidth(), getHeight(), border);