]> git.localhorst.tv Git - blank.git/blobdiff - src/standalone/MasterState.cpp
better handling of focus and input
[blank.git] / src / standalone / MasterState.cpp
index 91ee4826682fbdaca890b76d3c1c8bb0c3ab4929..9cc154387e3f6becb55bf756b5df29606514f2fd 100644 (file)
@@ -67,26 +67,37 @@ MasterState::~MasterState() {
 void MasterState::OnResume() {
        if (spawn_index.MissingChunks() > 0) {
                env.state.Push(&preload);
-       }
-       if (config.input.mouse) {
-               env.window.GrabMouse();
+               return;
        }
        if (spawn_player) {
                // TODO: spawn
                spawn_player = false;
        }
        hud.KeepMessages(false);
+       OnFocus();
 }
 
 void MasterState::OnPause() {
+       OnBlur();
+}
+
+void MasterState::OnFocus() {
+       if (config.input.mouse) {
+               env.window.GrabMouse();
+       }
+       interface.Unlock();
+}
+
+void MasterState::OnBlur() {
        env.window.ReleaseMouse();
+       interface.Lock();
 }
 
 
 void MasterState::Handle(const SDL_Event &event) {
        switch (event.type) {
                case SDL_KEYDOWN:
-                       // TODO: move to interface?
+                       // TODO: move to interface
                        if (event.key.keysym.sym == SDLK_RETURN) {
                                env.state.Push(&chat);
                                hud.KeepMessages(true);
@@ -196,7 +207,9 @@ void MasterState::Exit() {
 }
 
 void MasterState::OnLineSubmit(const std::string &line) {
-       hud.PostMessage(line);
+       if (!line.empty()) {
+               hud.PostMessage(line);
+       }
 }
 
 }