pingus-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Pingus-CVS] [pingus] push by address@hidden - Implemented SDL2 text/uni


From: pingus
Subject: [Pingus-CVS] [pingus] push by address@hidden - Implemented SDL2 text/unicode handling on 2014-07-27 19:17 GMT
Date: Sun, 27 Jul 2014 19:18:06 +0000

Revision: 805afaf0678e
Author:   Ingo Ruhnke <address@hidden>
Date:     Sun Jul 27 19:17:47 2014 UTC
Log:      Implemented SDL2 text/unicode handling

http://code.google.com/p/pingus/source/detail?r=805afaf0678e

Modified:
 /src/editor/inputbox.cpp
 /src/editor/inputbox.hpp
 /src/engine/gui/component.hpp
 /src/engine/gui/group_component.cpp
 /src/engine/gui/group_component.hpp
 /src/engine/gui/gui_manager.cpp
 /src/engine/input/control.hpp
 /src/engine/input/controller.cpp
 /src/engine/input/controller.hpp
 /src/engine/input/event.hpp
 /src/engine/input/sdl_driver.cpp
 /src/engine/screen/gui_screen.cpp

=======================================
--- /src/editor/inputbox.cpp    Sat Jul 26 19:58:06 2014 UTC
+++ /src/editor/inputbox.cpp    Sun Jul 27 19:17:47 2014 UTC
@@ -71,16 +71,13 @@
     on_change(text);
     on_enter(text);
   }
-  else
-  {
-#ifdef OLD_SDL1
-    if (ev.keysym.unicode)
-    {
-      text += UTF8::encode_utf8(ev.keysym.unicode);
-      on_change(text);
-    }
-#endif
-  }
+}
+
+void
+Inputbox::on_text_input(const Input::TextInputEvent& ev)
+{
+  text += ev.text;
+  on_change(text);
 }

 } // namespace Editor
=======================================
--- /src/editor/inputbox.hpp    Sat Jul 26 18:49:11 2014 UTC
+++ /src/editor/inputbox.hpp    Sun Jul 27 19:17:47 2014 UTC
@@ -37,6 +37,7 @@
   void set_text(const std::string& text);
   std::string get_text() const { return text; }
   void on_key_pressed(const Input::KeyboardEvent& ev);
+  void on_text_input(const Input::TextInputEvent& ev);

   void update_layout() {}

=======================================
--- /src/engine/gui/component.hpp       Wed Sep  7 11:00:46 2011 UTC
+++ /src/engine/gui/component.hpp       Sun Jul 27 19:17:47 2014 UTC
@@ -86,6 +86,8 @@
   /** Emitted whenever a keyboard character is pressed.  Only certain
       components should implement this */
   virtual void on_key_pressed(const Input::KeyboardEvent& ev) {}
+
+  virtual void on_text_input(const Input::TextInputEvent& ev) {}

   GroupComponent* get_parent() const;
   void set_parent(GroupComponent* p);
=======================================
--- /src/engine/gui/group_component.cpp Wed Sep  7 11:00:46 2011 UTC
+++ /src/engine/gui/group_component.cpp Sun Jul 27 19:17:47 2014 UTC
@@ -186,6 +186,17 @@
   else if (mouse_over_comp)
     mouse_over_comp->on_key_pressed(ev);
 }
+
+void
+GroupComponent::on_text_input(const Input::TextInputEvent& ev)
+{
+  if (grabbed_comp)
+    grabbed_comp->on_text_input(ev);
+  else if (focused_comp)
+    focused_comp->on_text_input(ev);
+  else if (mouse_over_comp)
+    mouse_over_comp->on_text_input(ev);
+}

 void
 GroupComponent::on_pointer_move(int x, int y)
=======================================
--- /src/engine/gui/group_component.hpp Tue Oct 11 15:42:27 2011 UTC
+++ /src/engine/gui/group_component.hpp Sun Jul 27 19:17:47 2014 UTC
@@ -62,6 +62,8 @@

   void on_key_pressed(const Input::KeyboardEvent& ev);

+  void on_text_input(const Input::TextInputEvent& ev);
+
   void on_pointer_enter();
   void on_pointer_leave();

=======================================
--- /src/engine/gui/gui_manager.cpp     Sun Jul 27 03:58:39 2014 UTC
+++ /src/engine/gui/gui_manager.cpp     Sun Jul 27 19:17:47 2014 UTC
@@ -78,6 +78,10 @@
       // AxisEvents can be ignored in the GUI, they are handled elsewhere
       log_debug("GUIManager: AxisEvent: %1%", event.axis.dir);
       break;
+
+    case Input::TEXT_INPUT_EVENT_TYPE:
+      on_text_input(event.text);
+      break;

     case Input::KEYBOARD_EVENT_TYPE:
       if (event.keyboard.state)
=======================================
--- /src/engine/input/control.hpp       Wed Sep  7 11:00:46 2011 UTC
+++ /src/engine/input/control.hpp       Sun Jul 27 19:17:47 2014 UTC
@@ -415,7 +415,7 @@
 class Keyboard : public Control
 {
 protected:
-  SDL_KeyboardEvent m_ev;
+  SDL_Event m_ev;

 public:
   Keyboard(Control* parent_) :
@@ -423,8 +423,8 @@
     m_ev()
   {}

- void send_char(const SDL_KeyboardEvent& ev) { m_ev = ev; notify_parent(); }
-  SDL_KeyboardEvent get_ev() { return m_ev; }
+  void send_event(const SDL_Event& ev) { m_ev = ev; notify_parent(); }
+  SDL_Event get_ev() { return m_ev; }

 private:
   Keyboard(const Keyboard&);
@@ -476,7 +476,21 @@
   {}

   virtual void notify_parent() {
-    controller->add_keyboard_event(m_ev);
+    switch(m_ev.type)
+    {
+      case SDL_KEYUP:
+      case SDL_KEYDOWN:
+        controller->add_keyboard_event(m_ev.key);
+        break;
+
+      case SDL_TEXTINPUT:
+        controller->add_text_input_event(m_ev.text);
+        break;
+
+      default:
+        log_error("unexpected SDL_Event: %1%", m_ev.type);
+        break;
+    }
   }

 private:
=======================================
--- /src/engine/input/controller.cpp    Sun Jul 27 03:58:39 2014 UTC
+++ /src/engine/input/controller.cpp    Sun Jul 27 19:17:47 2014 UTC
@@ -256,6 +256,12 @@
 {
   events.push_back(makeKeyboardEvent(ev));
 }
+
+void
+Controller::add_text_input_event(const SDL_TextInputEvent& ev)
+{
+  events.push_back(makeTextInputEvent(ev));
+}

 void
 Controller::clear_events()
=======================================
--- /src/engine/input/controller.hpp    Tue Sep 20 22:44:32 2011 UTC
+++ /src/engine/input/controller.hpp    Sun Jul 27 19:17:47 2014 UTC
@@ -68,6 +68,7 @@
   void add_pointer_event(int id, float x, float y);
   void add_scroller_event(int id, float xrel, float yrel);
   void add_keyboard_event(const SDL_KeyboardEvent& ev);
+  void add_text_input_event(const SDL_TextInputEvent& ev);

   void add_axis(int id, ControllerAxis* axis);
   void add_button(int id, ControllerButton* button);
=======================================
--- /src/engine/input/event.hpp Sat Jul 26 19:58:06 2014 UTC
+++ /src/engine/input/event.hpp Sun Jul 27 19:17:47 2014 UTC
@@ -29,7 +29,8 @@
                  POINTER_EVENT_TYPE,
                  AXIS_EVENT_TYPE,
                  SCROLLER_EVENT_TYPE,
-                 KEYBOARD_EVENT_TYPE };
+                 KEYBOARD_EVENT_TYPE,
+                 TEXT_INPUT_EVENT_TYPE };

 enum EventName {
   // Buttons
@@ -101,16 +102,22 @@
   SDL_Keysym keysym;
 };

+struct TextInputEvent
+{
+  char text[sizeof(SDL_TextInputEvent::text)];
+};
+
 struct Event
 {
   EventType type;

   union {
-    ButtonEvent   button;
-    PointerEvent  pointer;
-    AxisEvent     axis;
-    ScrollEvent   scroll;
+    ButtonEvent button;
+    PointerEvent pointer;
+    AxisEvent axis;
+    ScrollEvent scroll;
     KeyboardEvent keyboard;
+    TextInputEvent text;
   };
 };

@@ -172,6 +179,16 @@

   return event;
 }
+
+inline Event makeTextInputEvent(const SDL_TextInputEvent& ev)
+{
+  Event event;
+
+  event.type = TEXT_INPUT_EVENT_TYPE;
+  memcpy(event.text.text, ev.text, sizeof(SDL_TextInputEvent::text));
+
+  return event;
+}

 } // namespace Input

=======================================
--- /src/engine/input/sdl_driver.cpp    Sat Jul 26 21:37:49 2014 UTC
+++ /src/engine/input/sdl_driver.cpp    Sun Jul 27 19:17:47 2014 UTC
@@ -240,6 +240,22 @@
         }
         break;

+      case SDL_MOUSEWHEEL:
+ log_error("mousewheel not implemented: %1% %2%", event.wheel.which, event.wheel.x, event.wheel.y);
+        break;
+
+      case SDL_TEXTINPUT:
+        if (keyboard_binding)
+        {
+          keyboard_binding->send_event(event);
+        }
+        break;
+
+      case SDL_TEXTEDITING:
+        log_error("textediting not implemented: %1% %2% '%3%'",
+                  event.edit.start, event.edit.length, event.edit.text);
+        break;
+
       case SDL_MOUSEBUTTONDOWN:
       case SDL_MOUSEBUTTONUP:
for(std::vector<MouseButtonBinding>::iterator i = mouse_button_bindings.begin();
@@ -271,7 +287,7 @@
       case SDL_KEYUP:
         // keyboard events
         if (keyboard_binding)
-          keyboard_binding->send_char(event.key);
+          keyboard_binding->send_event(event);

         // global event hacks
         if (event.key.state == SDL_PRESSED)
=======================================
--- /src/engine/screen/gui_screen.cpp   Sun Jul 27 03:58:39 2014 UTC
+++ /src/engine/screen/gui_screen.cpp   Sun Jul 27 19:17:47 2014 UTC
@@ -87,6 +87,12 @@
     }
     break;

+    case Input::TEXT_INPUT_EVENT_TYPE:
+    {
+
+    }
+    break;
+
     default:
       log_error("unhandled event type: %1%", event.type);
       break;



reply via email to

[Prev in Thread] Current Thread [Next in Thread]