changeset 33998:ca20e4098c1d

Preserve x and y position of a double-size window if possible. Only change position in an evDoubleSize event if necessary. Do so by "dragging" the window towards the upper left if it no longer fits into the screen. Add a new function wsMoveWindowWithin() to accomplish this.
author ib
date Thu, 08 Sep 2011 15:31:25 +0000
parents 68633e7c5e1e
children 3cf824f66821
files gui/ui/main.c gui/wm/ws.c gui/wm/ws.h
diffstat 3 files changed, 37 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/gui/ui/main.c	Thu Sep 08 14:00:12 2011 +0000
+++ b/gui/ui/main.c	Thu Sep 08 15:31:25 2011 +0000
@@ -350,9 +350,7 @@
             uiFullScreen();
            }
           wsResizeWindow( &guiApp.subWindow, guiInfo.VideoWidth * 2, guiInfo.VideoHeight * 2 );
-          wsMoveWindow( &guiApp.subWindow, True,
-                        ( wsMaxX - guiInfo.VideoWidth*2  )/2 + wsOrgX,
-                        ( wsMaxY - guiInfo.VideoHeight*2 )/2 + wsOrgY  );
+          wsMoveWindowWithin( &guiApp.subWindow, False, guiApp.sub.x, guiApp.sub.y );
           btnSet( evFullScreen,btnReleased );
          }
         break;
--- a/gui/wm/ws.c	Thu Sep 08 14:00:12 2011 +0000
+++ b/gui/wm/ws.c	Thu Sep 08 15:31:25 2011 +0000
@@ -1085,6 +1085,41 @@
         win->ReSize(win->X, win->Y, win->Width, win->Height);
 }
 
+/**
+ * @brief Move the window to the x and y position, but if it no longer fits
+ *        into the screen, reposition it towards the upper left.
+ *
+ * @param win pointer to a ws window structure
+ * @param abs flag whether the position is real/absolute (True) or mock (False)
+ * @param x x position of the window (real/absolute or mock)
+ * @param y y position of the window (real/absolute or mock)
+ */
+void wsMoveWindowWithin(wsTWindow *win, Bool abs, int x, int y)
+{
+    Bool fitting = True;
+
+    wsMoveWindow(win, abs, x, y);
+
+    if (win->X + win->Width + 1 > wsMaxX) {
+        fitting = False;
+        win->X  = wsMaxX - win->Width;
+
+        if (win->X < 0)
+            win->X = 0;
+    }
+
+    if (win->Y + win->Height + 1 > wsMaxY) {
+        fitting = False;
+        win->Y  = wsMaxY - win->Height;
+
+        if (win->Y < 0)
+            win->Y = 0;
+    }
+
+    if (!fitting)
+        wsMoveWindow(win, True, win->X, win->Y);
+}
+
 // ----------------------------------------------------------------------------------------------
 //    Resize window to sx, sy.
 // ----------------------------------------------------------------------------------------------
--- a/gui/wm/ws.h	Thu Sep 08 14:00:12 2011 +0000
+++ b/gui/wm/ws.h	Thu Sep 08 15:31:25 2011 +0000
@@ -230,6 +230,7 @@
 void wsCreateWindow(wsTWindow *win, int X, int Y, int wX, int hY, int bW, int cV, unsigned char D, char *label);
 void wsDestroyWindow(wsTWindow *win);
 void wsMoveWindow(wsTWindow *win, Bool abs, int x, int y);
+void wsMoveWindowWithin(wsTWindow *win, Bool abs, int x, int y);
 void wsResizeWindow(wsTWindow *win, int sx, int sy);
 void wsIconify(wsTWindow win);
 void wsRaiseWindowTop(Display *dsp, Window win);