diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/client.cpp | 16 | ||||
-rw-r--r-- | src/client.h | 6 | ||||
-rw-r--r-- | src/gui/serverdialog.cpp | 10 | ||||
-rw-r--r-- | src/gui/serverdialog.h | 2 | ||||
-rw-r--r-- | src/gui/worldselectdialog.cpp | 10 | ||||
-rw-r--r-- | src/gui/worldselectdialog.h | 2 |
6 files changed, 46 insertions, 0 deletions
diff --git a/src/client.cpp b/src/client.cpp index 66a1f28c..975e3e05 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -172,6 +172,22 @@ int get_elapsed_time(int start_time) * MILLISECONDS_IN_A_TICK; } +bool isDoubleClick(int selected) +{ + const Uint32 maximumDelay = 500; + static Uint32 lastTime = 0; + static int lastSelected = -1; + + if (selected == lastSelected && lastTime + maximumDelay >= SDL_GetTicks()) + { + lastTime = 0; + return true; + } + + lastTime = SDL_GetTicks(); + lastSelected = selected; + return false; +} // This anonymous namespace hides whatever is inside from other modules. namespace { diff --git a/src/client.h b/src/client.h index aa650abe..429deb34 100644 --- a/src/client.h +++ b/src/client.h @@ -68,6 +68,12 @@ extern LoginData loginData; int get_elapsed_time(int start_time); /** + * Returns if this call and the last call were done for the same + * selected index and within a short time. + */ +bool isDoubleClick(int selected); + +/** * All client states. */ enum State { diff --git a/src/gui/serverdialog.cpp b/src/gui/serverdialog.cpp index e377042a..d1eece56 100644 --- a/src/gui/serverdialog.cpp +++ b/src/gui/serverdialog.cpp @@ -430,6 +430,16 @@ void ServerDialog::valueChanged(const gcn::SelectionEvent &) mDeleteButton->setEnabled(myServer.save); } +void ServerDialog::mouseClicked(gcn::MouseEvent &mouseEvent) +{ + if (mouseEvent.getSource() == mServersList && + isDoubleClick(mServersList->getSelected())) + { + action(gcn::ActionEvent(mConnectButton, + mConnectButton->getActionEventId())); + } +} + void ServerDialog::logic() { { diff --git a/src/gui/serverdialog.h b/src/gui/serverdialog.h index aae8b2e0..1eea6c92 100644 --- a/src/gui/serverdialog.h +++ b/src/gui/serverdialog.h @@ -135,6 +135,8 @@ class ServerDialog : public Window, */ void valueChanged(const gcn::SelectionEvent &event); + void mouseClicked(gcn::MouseEvent &mouseEvent); + void logic(); protected: diff --git a/src/gui/worldselectdialog.cpp b/src/gui/worldselectdialog.cpp index 3219b83d..3207f394 100644 --- a/src/gui/worldselectdialog.cpp +++ b/src/gui/worldselectdialog.cpp @@ -137,3 +137,13 @@ void WorldSelectDialog::keyPressed(gcn::KeyEvent &keyEvent) action(gcn::ActionEvent(NULL, mChooseWorld->getActionEventId())); } } + +void WorldSelectDialog::mouseClicked(gcn::MouseEvent &mouseEvent) +{ + if (mouseEvent.getSource() == mWorldList && + isDoubleClick(mWorldList->getSelected())) + { + action(gcn::ActionEvent(mChooseWorld, + mChooseWorld->getActionEventId())); + } +} diff --git a/src/gui/worldselectdialog.h b/src/gui/worldselectdialog.h index 2d4f0189..b51110b4 100644 --- a/src/gui/worldselectdialog.h +++ b/src/gui/worldselectdialog.h @@ -62,6 +62,8 @@ class WorldSelectDialog : public Window, public gcn::ActionListener, void keyPressed(gcn::KeyEvent &keyEvent); + void mouseClicked(gcn::MouseEvent &mouseEvent); + private: WorldListModel *mWorldListModel; gcn::ListBox *mWorldList; |