Re: [AD] 4.9.2 win/wwnd.c bug?

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


On 2008-01-29, AJ <aj@xxxxxxxxxx> wrote:
> /4.9.2/src/win/wwnd.c   line  670 
> 
> #ifdef ALLEGRO_COLORCONV_ALIGNED_WIDTH
>       last_wnd_x &= 0xfffffffc;
> #endif
> 
> 1. makes presumptions about sizeof(type)
> 
> 2. rounds toward zero..  yet zero is of no significance.
> 
> .. in the windows desktop co-ord system  zero is of no significance, it 
> might be in the middle of several monitors.
> if the value is less than zero, it moves right,  if the value is more 
> than zero, it moves left.

Um, what?

For what it's worth, that line is pretty old.  Probably didn't take into
account multiple monitors.

----------------------------------------------------------------------
r2884 (orig r2883):  ebotcazou | 2003-01-15 03:51:09 +1100

Made it so that the window is centered at startup under Windows

----------------------------------------------------------------------
--- mirror/allegro/allegro/trunk/src/win/wwnd.c (revision 2883)
+++ mirror/allegro/allegro/trunk/src/win/wwnd.c (revision 2884)
@@ -40,8 +40,8 @@ int wnd_width = 0;
 int wnd_height = 0;
 int wnd_sysmenu = FALSE;
 
-static int last_wnd_x = 32;
-static int last_wnd_y = 32;
+static int last_wnd_x = -1;
+static int last_wnd_y = -1;
 
 /* graphics */
 WIN_GFX_DRIVER *win_gfx_driver;
@@ -571,9 +571,25 @@ void restore_window_style(void)
  */
 int adjust_window(int w, int h)
 {
-   RECT win_size = {last_wnd_x, last_wnd_y, last_wnd_x+w, last_wnd_y+h };
+   RECT working_area, win_size;
 
    if (!user_wnd) {
+      if (last_wnd_x < 0) {
+         /* first window placement: try to center it */
+         SystemParametersInfo(SPI_GETWORKAREA, 0, &working_area, 0);
+         last_wnd_x = (working_area.left + working_area.right - w)/2;
+         last_wnd_y = (working_area.top + working_area.bottom - h)/2;
+
+#ifdef ALLEGRO_COLORCONV_ALIGNED_WIDTH
+         last_wnd_x &= 0xfffffffc;
+#endif
+      }
+
+      win_size.left = last_wnd_x;
+      win_size.top = last_wnd_y;
+      win_size.right = last_wnd_x+w;
+      win_size.bottom = last_wnd_y+h;
+
       /* retrieve the size of the decorated window */
       AdjustWindowRect(&win_size, GetWindowLong(allegro_wnd, GWL_STYLE), FALSE);
    





Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/