summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog3
-rw-r--r--src/gui/inttextbox.cpp22
-rw-r--r--src/gui/inttextbox.h4
-rw-r--r--src/gui/item_amount.cpp61
4 files changed, 47 insertions, 43 deletions
diff --git a/ChangeLog b/ChangeLog
index 76e6ecea..0782f0f9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,9 @@
2007-11-14 Guillaume Melquiond <guillaume.melquiond@gmail.com>
* src/gui/chat.cpp: Fixed up and down arrows in chat box.
+ * src/gui/inttextbox.h, src/gui/inttextbox.cpp: Changed to textfield so
+ that it is visibly editable.
+ * src/gui/item_amount.cpp: Converted to layout handler.
2007-11-13 Eugenio Favalli <elvenprogrammer@gmail.com>
diff --git a/src/gui/inttextbox.cpp b/src/gui/inttextbox.cpp
index 2a09f255..5ae3dd93 100644
--- a/src/gui/inttextbox.cpp
+++ b/src/gui/inttextbox.cpp
@@ -23,7 +23,7 @@
#include "inttextbox.h"
-#include <guichan/key.hpp>
+#include "sdlinput.h"
#include "../utils/tostring.h"
@@ -37,17 +37,21 @@ IntTextBox::keyPressed(gcn::KeyEvent &event)
{
const gcn::Key &key = event.getKey();
- if (key.isNumber() || key.getValue() == gcn::Key::BACKSPACE
- || key.getValue() == gcn::Key::DELETE)
+ if (key.getValue() == Key::BACKSPACE ||
+ key.getValue() == Key::DELETE)
{
- gcn::TextBox::keyPressed(event);
+ setText(std::string());
+ event.consume();
}
- std::stringstream s(gcn::TextBox::getText());
+ if (!key.isNumber()) return;
+ TextField::keyPressed(event);
+
+ std::istringstream s(getText());
int i;
s >> i;
- if (gcn::TextBox::getText() != "")
- setInt(i);
+ setInt(i);
+ generateAction();
}
void IntTextBox::setRange(int min, int max)
@@ -58,9 +62,7 @@ void IntTextBox::setRange(int min, int max)
int IntTextBox::getInt()
{
- if (gcn::TextBox::getText() == "")
- return 0;
- return mValue;
+ return getText().empty() ? mMin : mValue;
}
void IntTextBox::setInt(int i)
diff --git a/src/gui/inttextbox.h b/src/gui/inttextbox.h
index b5d339ac..219c6018 100644
--- a/src/gui/inttextbox.h
+++ b/src/gui/inttextbox.h
@@ -24,12 +24,12 @@
#ifndef INTTEXTBOX_H
#define INTTEXTBOX_H
-#include "textbox.h"
+#include "textfield.h"
/**
* TextBox which only accepts numbers as input.
*/
-class IntTextBox : public TextBox
+class IntTextBox : public TextField
{
public:
/**
diff --git a/src/gui/item_amount.cpp b/src/gui/item_amount.cpp
index 33a45fe7..6f1c8ae6 100644
--- a/src/gui/item_amount.cpp
+++ b/src/gui/item_amount.cpp
@@ -28,6 +28,8 @@
#include "slider.h"
#include "trade.h"
+#include "widgets/layout.h"
+
#include "../item.h"
#include "../localplayer.h"
@@ -38,47 +40,45 @@ ItemAmountWindow::ItemAmountWindow(int usage, Window *parent, Item *item,
Window("", true, parent),
mItem(item)
{
- // New labels
- mItemAmountTextBox = new IntTextBox(1);
-
- // New buttons
- Button *minusButton = new Button("-", "Minus", this);
- Button *plusButton = new Button("+", "Plus", this);
- Button *okButton = new Button(_("Ok"), "Drop", this);
- Button *cancelButton = new Button(_("Cancel"), "Cancel", this);
- if (!maxRange) {
+ if (!maxRange)
+ {
maxRange = mItem->getQuantity();
}
- mItemAmountSlide = new Slider(1.0, maxRange);
+ // Integer field
+ mItemAmountTextBox = new IntTextBox(1);
mItemAmountTextBox->setRange(1, maxRange);
- mItemAmountSlide->setDimension(gcn::Rectangle(5, 120, 180, 10));
+ mItemAmountTextBox->setWidth(30);
+ mItemAmountTextBox->setActionEventId("Dummy");
+ mItemAmountTextBox->addActionListener(this);
- // Set button events Id
+ // Slider
+ mItemAmountSlide = new Slider(1.0, maxRange);
+ mItemAmountSlide->setHeight(10);
mItemAmountSlide->setActionEventId("Slide");
+ mItemAmountSlide->addActionListener(this);
- // Set position
- mItemAmountTextBox->setPosition(35, 10);
- mItemAmountTextBox->setSize(24, 16);
- plusButton->setPosition(60, 5);
- minusButton->setPosition(10, 5);
- mItemAmountSlide->setPosition(10, 35);
- okButton->setPosition(10, 50);
- cancelButton->setPosition(60, 50);
-
- // Assemble
- add(mItemAmountTextBox);
- add(plusButton);
- add(minusButton);
- add(mItemAmountSlide);
- add(okButton);
- add(cancelButton);
+ // Buttons
+ Button *minusButton = new Button("-", "Minus", this);
+ minusButton->setSize(20, 20);
+ Button *plusButton = new Button("+", "Plus", this);
+ plusButton->setSize(20, 20);
+ Button *okButton = new Button(_("Ok"), "Drop", this);
+ Button *cancelButton = new Button(_("Cancel"), "Cancel", this);
- mItemAmountSlide->addActionListener(this);
+ // Set positions
+ place(0, 0, minusButton);
+ place(1, 0, mItemAmountTextBox).setPadding(2);
+ place(2, 0, plusButton);
+ place(0, 1, mItemAmountSlide, 6);
+ place(4, 2, okButton);
+ place(5, 2, cancelButton);
+ reflowLayout(250, 0);
resetAmount();
- switch (usage) {
+ switch (usage)
+ {
case AMOUNT_TRADE_ADD:
setCaption(_("Select amount of items to trade."));
okButton->setActionEventId("AddTrade");
@@ -95,7 +95,6 @@ ItemAmountWindow::ItemAmountWindow(int usage, Window *parent, Item *item,
break;
}
- setContentSize(200, 80);
setLocationRelativeTo(getParentWindow());
setVisible(true);
}