From 555e68e24f2bb7d38f7ce52ce9a43198c0ccedec Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Wed, 4 Feb 2009 11:46:03 -0700 Subject: Went through the gui folder and revised the include statements to not include anything not needed by that specific widget or window. This appears to have cleaned up system performance a bit on my current setup, where it went from idling on 45% in game with opengl down to 30% now. Also moved iptostring to the tostring header, as importing all of network.h is a little overkill to use that function, and it goes along with the basic functions that are in that header file anyways. TODO: find out a way to get rid of warnings when a class doesn't use this function. Signed-off-by: Ira Rice --- src/gui/npcintegerdialog.cpp | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) (limited to 'src/gui/npcintegerdialog.cpp') diff --git a/src/gui/npcintegerdialog.cpp b/src/gui/npcintegerdialog.cpp index 65a1a7f1..4444e04b 100644 --- a/src/gui/npcintegerdialog.cpp +++ b/src/gui/npcintegerdialog.cpp @@ -19,20 +19,15 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "npcintegerdialog.h" - -#include -#include - #include "button.h" #include "inttextfield.h" +#include "npcintegerdialog.h" + +#include "widgets/layout.h" #include "../npc.h" #include "../utils/gettext.h" -#include "../utils/tostring.h" - -#include "widgets/layout.h" NpcIntegerDialog::NpcIntegerDialog(): Window(_("NPC Number Request")) -- cgit v1.2.3-70-g09d2 From b0a8b8607962081e87716ab0dfbca2439953f420 Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Wed, 4 Feb 2009 22:13:12 -0700 Subject: Modified the NPC string and integer classes to automatically take focus to the input fields. Now the only NPC dialog which isn't completely navigatable by the keyboard alone is the NPC list dialog (seems to have regressed slightly recently). Signed-off-by: Ira Rice --- src/gui/npcintegerdialog.cpp | 16 ++++++++++++---- src/gui/npcintegerdialog.h | 14 +++++++++++--- src/gui/npcstringdialog.cpp | 6 ++++++ src/gui/npcstringdialog.h | 6 +++++- src/net/npchandler.cpp | 2 ++ 5 files changed, 36 insertions(+), 8 deletions(-) (limited to 'src/gui/npcintegerdialog.cpp') diff --git a/src/gui/npcintegerdialog.cpp b/src/gui/npcintegerdialog.cpp index 4444e04b..c58fc460 100644 --- a/src/gui/npcintegerdialog.cpp +++ b/src/gui/npcintegerdialog.cpp @@ -32,9 +32,10 @@ NpcIntegerDialog::NpcIntegerDialog(): Window(_("NPC Number Request")) { + mValueField = new IntTextField(); + mDecButton = new Button("-", "decvalue", this); mIncButton = new Button("+", "incvalue", this); - mValueField = new IntTextField(); okButton = new Button(_("OK"), "ok", this); cancelButton = new Button(_("Cancel"), "cancel", this); resetButton = new Button(_("Reset"), "reset", this); @@ -56,9 +57,6 @@ NpcIntegerDialog::NpcIntegerDialog(): reflowLayout(175, 0); setLocationRelativeTo(getParent()); - - mValueField->setActionEventId("valuefield"); - mValueField->addKeyListener(this); } void NpcIntegerDialog::setRange(const int min, const int max) @@ -105,3 +103,13 @@ void NpcIntegerDialog::action(const gcn::ActionEvent &event) mValueField->reset(); } } + +bool NpcIntegerDialog::isInputFocused() +{ + return mValueField->isFocused(); +} + +void NpcIntegerDialog::requestFocus() +{ + mValueField->requestFocus(); +} diff --git a/src/gui/npcintegerdialog.h b/src/gui/npcintegerdialog.h index b9ce70be..10ec60b9 100644 --- a/src/gui/npcintegerdialog.h +++ b/src/gui/npcintegerdialog.h @@ -23,7 +23,6 @@ #define GUI_NPCINTEGERDIALOG_H #include -#include #include "window.h" @@ -34,8 +33,7 @@ class IntTextField; * * \ingroup Interface */ -class NpcIntegerDialog : public Window, public gcn::ActionListener, - public gcn::KeyListener +class NpcIntegerDialog : public Window, public gcn::ActionListener { public: /** @@ -63,6 +61,16 @@ class NpcIntegerDialog : public Window, public gcn::ActionListener, */ void setRange(const int min, const int max); + /** + * Checks whether NpcStringDialog is Focused or not. + */ + bool isInputFocused(); + + /** + * Requests the textfield to take focus for input. + */ + void requestFocus(); + private: gcn::Button *mDecButton; gcn::Button *mIncButton; diff --git a/src/gui/npcstringdialog.cpp b/src/gui/npcstringdialog.cpp index 468326d6..718c416f 100644 --- a/src/gui/npcstringdialog.cpp +++ b/src/gui/npcstringdialog.cpp @@ -33,6 +33,7 @@ NpcStringDialog::NpcStringDialog(): Window(_("NPC Text Request")) { mValueField = new TextField(""); + okButton = new Button(_("OK"), "ok", this); cancelButton = new Button(_("Cancel"), "cancel", this); @@ -71,3 +72,8 @@ bool NpcStringDialog::isInputFocused() { return mValueField->isFocused(); } + +void NpcStringDialog::requestFocus() +{ + mValueField->requestFocus(); +} diff --git a/src/gui/npcstringdialog.h b/src/gui/npcstringdialog.h index aa39764d..1933e0f1 100644 --- a/src/gui/npcstringdialog.h +++ b/src/gui/npcstringdialog.h @@ -23,7 +23,6 @@ #define GUI_NPCSTRINGDIALOG_H #include -#include #include "window.h" @@ -64,6 +63,11 @@ class NpcStringDialog : public Window, public gcn::ActionListener */ bool isInputFocused(); + /** + * Requests the textfield to take focus for input. + */ + void requestFocus(); + private: gcn::TextField *mValueField; gcn::Button *okButton; diff --git a/src/net/npchandler.cpp b/src/net/npchandler.cpp index 82b07d41..4e17a27e 100644 --- a/src/net/npchandler.cpp +++ b/src/net/npchandler.cpp @@ -92,6 +92,7 @@ void NPCHandler::handleMessage(MessageIn *msg) current_npc = dynamic_cast(beingManager->findBeing(id)); npcIntegerDialog->setRange(0, 2147483647); npcIntegerDialog->setVisible(true); + npcIntegerDialog->requestFocus(); break; case SMSG_NPC_STR_INPUT: @@ -100,6 +101,7 @@ void NPCHandler::handleMessage(MessageIn *msg) current_npc = dynamic_cast(beingManager->findBeing(id)); npcStringDialog->setValue(""); npcStringDialog->setVisible(true); + npcStringDialog->requestFocus(); break; } } -- cgit v1.2.3-70-g09d2