DriverSDL: Fix.
authorRadek Brich <radek.brich@devl.cz>
Thu, 10 Jan 2013 00:03:34 +0100
changeset 61 15088f62c4ac
parent 60 fccca2a60492
child 62 2f61931520c9
DriverSDL: Fix.
sdlterm/src/sdlterm.cc
sdlterm/src/sdlterm.h
tuikit/driver_sdl.py
--- a/sdlterm/src/sdlterm.cc	Wed Jan 09 22:32:15 2013 +0100
+++ b/sdlterm/src/sdlterm.cc	Thu Jan 10 00:03:34 2013 +0100
@@ -372,6 +372,7 @@
 bool Terminal::wait_event(Event &event, Uint32 timeout)
 {
     static SDL_Event sdl_event;
+    bool event_ready = false;
 
     // use timer to simulate SDL_WaitEventTimeout, which is not available in SDL 1.2
     SDL_TimerID timer_id = NULL;
@@ -380,36 +381,34 @@
         timer_id = SDL_AddTimer(timeout, _wait_event_callback, NULL);
     }
 
-    while (SDL_WaitEvent(&sdl_event))
+    while (SDL_WaitEvent(&sdl_event) && !event_ready)
     {
-        if (timer_id)
-        {
-            if (sdl_event.type == SDL_USEREVENT && sdl_event.user.code == 1)
-            {
-                // timeout
-                return false;
-            }
-            // some event came before timeout...
-            SDL_RemoveTimer(timer_id);
-            timer_id = NULL;
-        }
         switch (sdl_event.type)
         {
             case SDL_USEREVENT:
+                // timeout
+                if (sdl_event.user.code == 1)
+                {
+                    SDL_RemoveTimer(timer_id);
+                    return false;
+                }
                 // toggle blink
                 if (sdl_event.user.code == 2)
                 {
                     _screen.toggle_blink();
                 }
                 break; // continue loop
+
             case SDL_QUIT:
                 event.type = Event::QUIT;
-                return true;
+                event_ready = true;
+                break;
 
             case SDL_VIDEORESIZE:
                 event.type = Event::RESIZE;
                 _screen.resize(sdl_event.resize.w, sdl_event.resize.h);
-                return true;
+                event_ready = true;
+                break;
 
             case SDL_VIDEOEXPOSE:
                 _screen.redraw();
@@ -433,7 +432,8 @@
                     if (!event.key.unicode)
                         break; // continue loop (unknown key)
                 }
-                return true;
+                event_ready = true;
+                break;
             }
 
             case SDL_MOUSEBUTTONDOWN:
@@ -449,7 +449,8 @@
                     event.type = Event::MOUSEWHEEL;
                 }
                 _mousemove_last_x = -1;
-                return true;
+                event_ready = true;
+                break;
 
             case SDL_MOUSEMOTION:
                 if (sdl_event.motion.state == 0)
@@ -462,7 +463,8 @@
                 {
                     _mousemove_last_x = event.mouse.x;
                     _mousemove_last_y = event.mouse.y;
-                    return true;
+                    event_ready = true;
+                    break;
                 }
                 break; // continue loop when mouse position did not change
 
@@ -470,7 +472,22 @@
                 break; // continue loop
         }
     }
-    throw SDLTermError(std::string("SDL_WaitEvent: ") + SDL_GetError());
+
+    // remove timer when other event came before timeout
+    if (timeout)
+    {
+        SDL_RemoveTimer(timer_id);
+    }
+
+    // ok or error?
+    if (event_ready)
+    {
+        return true;
+    }
+    else
+    {
+        throw SDLTermError(std::string("SDL_WaitEvent: ") + SDL_GetError());
+    }
 }
 
 
--- a/sdlterm/src/sdlterm.h	Wed Jan 09 22:32:15 2013 +0100
+++ b/sdlterm/src/sdlterm.h	Thu Jan 10 00:03:34 2013 +0100
@@ -199,7 +199,7 @@
     void putch(int x, int y, Uint32 ch) { _screen.putch(x, y, ch, _attr); };
     void commit();
 
-    Uint32 prepare_attr(Uint8 fg, Uint8 bg, Uint8 style) { return (Uint32)fg | (Uint32)bg << 8 | (Uint32)style << 24; };
+    Uint32 prepare_attr(Uint8 fg, Uint8 bg, Uint32 style) { return (Uint32)fg | (Uint32)bg << 8 | (style & 0xFF000000); };
     void set_attr(Uint32 value) { _attr = value; };
 
     void show_cursor(int x, int y) { _cursor_x = x; _cursor_y = y; _cursor_visible = true; };
--- a/tuikit/driver_sdl.py	Wed Jan 09 22:32:15 2013 +0100
+++ b/tuikit/driver_sdl.py	Thu Jan 10 00:03:34 2013 +0100
@@ -40,10 +40,10 @@
     }
 
     style_map = {
-        'bold'      : 1 << 0,  # bold font
-        'underline' : 1 << 1,  # underline text
-        'standout'  : 1 << 2,  # inverse bg/fg
-        'blink'     : 1 << 3,  # blinking text
+        'bold'      : 1 << 24,  # bold font
+        'underline' : 1 << 25,  # underline text
+        'standout'  : 1 << 26,  # inverse bg/fg
+        'blink'     : 1 << 27,  # blinking text
         'dim'       : 0,
     }