Handle expose events.
authorTimo Korvola <tkorvola@iki.fi>
Wed, 28 Mar 2018 18:37:51 +0000 (21:37 +0300)
committerTimo Korvola <tkorvola@iki.fi>
Wed, 28 Mar 2018 18:37:51 +0000 (21:37 +0300)
Expose events are handled even in os_tick.

src/sdl/sf_frotz.h
src/sdl/sf_sound.c
src/sdl/sf_video.c

index 727ff68868ad462baa1b00d8d4fdc5babdda470c..d95cb229b6065037a1d81917d5c1649f82464ccb 100644 (file)
@@ -233,7 +233,7 @@ void sf_poptextsettings(void);
 
 void sf_chline( int x, int y, ulong c, int n);
 void sf_cvline( int x, int y, ulong c, int n);
-void sf_flushdisplay(void);
+bool sf_flushdisplay(void);
 void sf_getclip( int *x, int *y, int *w, int *h);
 void sf_rect( unsigned long color, int x, int y, int w, int h);
 void sf_setclip( int x, int y, int w, int h);
index 626493e8e5b4fd7b9f09712d9eaf9b98251bdf4f..2268aed868b6fc829d49ca8cb1853a0182391eaf 100644 (file)
@@ -405,15 +405,5 @@ void sf_checksound()
        }
   }
 
-void os_tick()
-  {
-  sf_checksound();
-  if (SFticked)
-       {
-       SFticked = false;
-       sf_flushdisplay();
-       }
-  }
-
 ///////////////////////////////////////
 
index f1ca7f1795d04d775da8da74fd20ab0aa0878aa4..b1bfc91292b15db761d7b98bbb905c5780ad2432 100644 (file)
@@ -342,11 +342,18 @@ static void scroll( int x, int y, int w, int h, int n)
     }
   }
 
-void sf_flushdisplay()
-  {
-  if (dirty) myGrefresh();
-  dirty = 0;
-  }
+/**
+ * Update the display if contents have changed.
+ * Return whether contents had changed, i.e., display was updated.
+ */
+bool sf_flushdisplay() {
+    if (dirty) {
+        myGrefresh();
+        dirty = 0;
+        return true;
+    } else
+        return false;
+}
 
 /*
  * os_scroll_area
@@ -586,6 +593,14 @@ static zword decode_utf8(char *str)
     return res;
 }
 
+static void handle_window_event(SDL_Event *e)
+{
+    switch (e->window.event) {
+    case SDL_WINDOWEVENT_EXPOSED:
+        SDL_RenderPresent(renderer);
+    }
+}
+
 static zword goodzkey( SDL_Event *e, int allowed)
 {
     SDL_Keycode c;
@@ -678,9 +693,10 @@ static zword goodzkey( SDL_Event *e, int allowed)
             return res;
         else
             return 0;
-    default:
-        return 0;
+    case SDL_WINDOWEVENT:
+        handle_window_event(e);
     }
+    return 0;
 }
 
 zword sf_read_key( int timeout, bool cursor, bool allowed, bool text)
@@ -1136,3 +1152,16 @@ static void sf_quitconf()
        }
   }
 
+void os_tick() {
+    sf_checksound();
+    if (SFticked) {
+        SFticked = false;
+        if (!sf_flushdisplay()) {
+            SDL_Event ev;
+            SDL_PumpEvents();
+            while (SDL_PeepEvents(&ev, 1, SDL_GETEVENT,
+                                  SDL_WINDOWEVENT, SDL_WINDOWEVENT) > 0)
+                handle_window_event(&ev);
+        }
+    }
+}