summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/gui/inventorywindow.cpp2
-rw-r--r--src/gui/npc_text.cpp41
-rw-r--r--src/gui/npc_text.h18
-rw-r--r--src/gui/npclistdialog.cpp35
-rw-r--r--src/gui/npclistdialog.h17
5 files changed, 98 insertions, 15 deletions
diff --git a/src/gui/inventorywindow.cpp b/src/gui/inventorywindow.cpp
index 5add1d4f..936416d1 100644
--- a/src/gui/inventorywindow.cpp
+++ b/src/gui/inventorywindow.cpp
@@ -48,7 +48,6 @@ InventoryWindow::InventoryWindow():
setResizable(true);
setCloseButton(true);
setMinWidth(240);
- setMinHeight(172);
// If you adjust these defaults, don't forget to adjust the trade window's.
setDefaultSize(115, 25, 322, 172);
@@ -200,7 +199,6 @@ void InventoryWindow::draw()
// Update weight information
mWeightLabel->setTextWrapped(mWeight);
mWeightLabel->setMinWidth(width - 16);
- mWeightLabel->setWidth(width - 16);
mUseButton->setPosition(8, height - 8 - mUseButton->getHeight());
mDropButton->setPosition(8 + mUseButton->getWidth() + 5,
diff --git a/src/gui/npc_text.cpp b/src/gui/npc_text.cpp
index 8324a196..d74b3ddd 100644
--- a/src/gui/npc_text.cpp
+++ b/src/gui/npc_text.cpp
@@ -25,8 +25,6 @@
#include <string>
-#include "scrollarea.h"
-#include "button.h"
#include "textbox.h"
#include "../npc.h"
@@ -34,11 +32,16 @@
NpcTextDialog::NpcTextDialog():
Window("NPC")
{
+ setResizable(true);
+
+ setMinWidth(200);
+ setMinHeight(150);
+
mTextBox = new TextBox;
mTextBox->setEditable(false);
- gcn::ScrollArea *scrollArea = new ScrollArea(mTextBox);
- gcn::Button *okButton = new Button("OK", "ok", this);
+ scrollArea = new ScrollArea(mTextBox);
+ okButton = new Button("OK", "ok", this);
setContentSize(260, 175);
scrollArea->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER);
@@ -58,15 +61,37 @@ NpcTextDialog::NpcTextDialog():
void
NpcTextDialog::setText(const std::string &text)
{
- mTextBox->setMinWidth(230);
- mTextBox->setTextWrapped(text);
+ mText = text;
+ draw();
}
void
NpcTextDialog::addText(const std::string &text)
{
- mTextBox->setMinWidth(230);
- mTextBox->setTextWrapped(mTextBox->getText() + text + "\n");
+ mText = mTextBox->getText() + text + "\n";
+ draw();
+}
+
+void NpcTextDialog::widgetResized(const gcn::Event &event)
+{
+ Window::widgetResized(event);
+ draw();
+}
+
+void NpcTextDialog::draw()
+{
+ const gcn::Rectangle &area = getChildrenArea();
+ const int width = area.width;
+ const int height = area.height;
+
+ mTextBox->setMinWidth(width - 30);
+ mTextBox->setTextWrapped(mText);
+
+ scrollArea->setDimension(gcn::Rectangle(
+ 5, 5, width - 10, height - 15 - okButton->getHeight()));
+ okButton->setPosition(
+ width - 5 - okButton->getWidth(),
+ height - 5 - okButton->getHeight());
}
void
diff --git a/src/gui/npc_text.h b/src/gui/npc_text.h
index c9f13454..3773950a 100644
--- a/src/gui/npc_text.h
+++ b/src/gui/npc_text.h
@@ -27,6 +27,8 @@
#include <iosfwd>
#include <guichan/actionlistener.hpp>
+#include "scrollarea.h"
+#include "button.h"
#include "window.h"
#include "../guichanfwd.h"
@@ -49,6 +51,18 @@ class NpcTextDialog : public Window, public gcn::ActionListener
NpcTextDialog();
/**
+ * Called when resizing the window
+ *
+ * @param event The calling event
+ */
+ void widgetResized(const gcn::Event &event);
+
+ /**
+ * Redraws the window
+ */
+ void draw();
+
+ /**
* Called when receiving actions from the widgets.
*/
void
@@ -72,7 +86,11 @@ class NpcTextDialog : public Window, public gcn::ActionListener
addText(const std::string &string);
private:
+ gcn::Button *okButton;
+ gcn::ScrollArea *scrollArea;
TextBox *mTextBox;
+
+ std::string mText;
};
#endif
diff --git a/src/gui/npclistdialog.cpp b/src/gui/npclistdialog.cpp
index e6523583..3203ba84 100644
--- a/src/gui/npclistdialog.cpp
+++ b/src/gui/npclistdialog.cpp
@@ -25,8 +25,6 @@
#include <sstream>
-#include "button.h"
-#include "scrollarea.h"
#include "listbox.h"
#include "../npc.h"
@@ -34,10 +32,15 @@
NpcListDialog::NpcListDialog():
Window("NPC")
{
+ setResizable(true);
+
+ setMinWidth(200);
+ setMinHeight(150);
+
mItemList = new ListBox(this);
- ScrollArea *scrollArea = new ScrollArea(mItemList);
- Button *okButton = new Button("OK", "ok", this);
- Button *cancelButton = new Button("Cancel", "cancel", this);
+ scrollArea = new ScrollArea(mItemList);
+ okButton = new Button("OK", "ok", this);
+ cancelButton = new Button("Cancel", "cancel", this);
setContentSize(260, 175);
scrollArea->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER);
@@ -90,6 +93,28 @@ NpcListDialog::reset()
mItems.clear();
}
+void NpcListDialog::widgetResized(const gcn::Event &event)
+{
+ Window::widgetResized(event);
+ draw();
+}
+
+void NpcListDialog::draw()
+{
+ const gcn::Rectangle &area = getChildrenArea();
+ const int width = area.width;
+ const int height = area.height;
+
+ scrollArea->setDimension(gcn::Rectangle(
+ 5, 5, width - 10, height - 15 - okButton->getHeight()));
+ cancelButton->setPosition(
+ width - 5 - cancelButton->getWidth(),
+ height - 5 - cancelButton->getHeight());
+ okButton->setPosition(
+ cancelButton->getX() - 5 - okButton->getWidth(),
+ cancelButton->getY());
+}
+
void
NpcListDialog::action(const gcn::ActionEvent &event)
{
diff --git a/src/gui/npclistdialog.h b/src/gui/npclistdialog.h
index a96fd766..4e9d4b3b 100644
--- a/src/gui/npclistdialog.h
+++ b/src/gui/npclistdialog.h
@@ -30,6 +30,8 @@
#include <guichan/actionlistener.hpp>
#include <guichan/listmodel.hpp>
+#include "button.h"
+#include "scrollarea.h"
#include "window.h"
#include "../guichanfwd.h"
@@ -51,6 +53,18 @@ class NpcListDialog : public Window, public gcn::ActionListener,
NpcListDialog();
/**
+ * Called when resizing the window
+ *
+ * @param event The calling event
+ */
+ void widgetResized(const gcn::Event &event);
+
+ /**
+ * Redraws the window
+ */
+ void draw();
+
+ /**
* Called when receiving actions from the widgets.
*/
void
@@ -84,6 +98,9 @@ class NpcListDialog : public Window, public gcn::ActionListener,
private:
gcn::ListBox *mItemList;
+ ScrollArea *scrollArea;
+ Button *okButton;
+ Button *cancelButton;
std::vector<std::string> mItems;
};