Re: [AD] modesel patch

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


On Sun, Feb 09, 2003 at 11:11:22AM +0100, Eric Botcazou wrote:
> The feature is fine and I'd be glad to have it in the next versions. However, 
> your patches don't apply cleanly because of a fix I applied a few days ago 
> both on the trunk and the branch.
> 
> Would you mind adapting the patch against the 4.1.9 to the CVS snapshot that 
> was generated yesterday? I'll backport the result to the 4.0.x branch 
> myself.

Sure, I have the patch here.

Magnus Henoch
--- allegro/src/modesel.c	Sat Feb  1 05:05:27 2003
+++ allegro-modesel/src/modesel.c	Sun Feb  9 12:13:30 2003
@@ -146,32 +146,101 @@
 #define GFX_MODELIST       6
 #define GFX_DEPTHLIST      7
 
+/* bpp_index_to_bpp:
+ *  Returns the real bpp value of the nth depth of mode
+ *  what_mode of driver what_driver.
+ */
+static int bpp_index_to_bpp(int n, int what_driver, int what_mode)
+{
+   int i, j;
+   j = -1;
+   for (i=0; i < BPP_TOTAL; i++) {
+      if (driver_list[what_driver].mode_list[what_mode].bpp[i]) {
+         j++;
+         if (j == n) switch (i) {
+            case BPP_08: return 8;
+            case BPP_15: return 15;
+            case BPP_16: return 16;
+            case BPP_24: return 24;
+            case BPP_32: return 32;
+         }
+      }
+   }
+
+   /* this should never happen */
+   ASSERT(0);
+   return -1;
+}
+
+/* bpp_to_bpp_index:
+ *  Returns the index in the depth list of mode what_mode
+ *  of driver what_driver corresponding to the given
+ *  depth, or -1 if there is no such depth.
+ */
+static int bpp_to_bpp_index(int depth, int what_driver, int what_mode)
+{
+   int i, what_bpp = -1;
+   for (i=0; i < BPP_TOTAL; i++) {
+      if (driver_list[what_driver].mode_list[what_mode].bpp[i]) {
+         what_bpp++;
+         switch (depth) {
+            case  8: if (i == BPP_08) return what_bpp;
+            case 15: if (i == BPP_15) return what_bpp;
+            case 16: if (i == BPP_16) return what_bpp;
+            case 24: if (i == BPP_24) return what_bpp;
+            case 32: if (i == BPP_32) return what_bpp;
+         }
+      }
+   }
+
+   return -1;
+}
 
 
 /* change_proc:
  *  Stores the current driver in d1 and graphics mode in d2;
  *  if a new driver is selected in the listbox, it changes the
- *  w/h and cdepth listboxes so that they redraw and they
- *  lose their selections. likewise if a new w/h is selected the
- *  cdepth listbox is updated.
+ *  w/h and cdepth listboxes so that they redraw. selections are
+ *  kept if supported by the new driver. likewise if a new w/h
+ *  is selected the cdepth listbox is updated.
  */
 static int change_proc(int msg, DIALOG *d, int c)
 {
+   int width, height, depth = 0;
+
    ASSERT(d);
    
    if (msg != MSG_IDLE)
       return D_O_K;
 
+   width = driver_list[d->d1].mode_list[d->d2].w;
+   height = driver_list[d->d1].mode_list[d->d2].h;
+   if (what_dialog == gfx_mode_ex_dialog) {
+     depth = bpp_index_to_bpp(what_dialog[GFX_DEPTHLIST].d1, d->d1, d->d2);
+   }
+ 
    if (what_dialog[GFX_DRIVERLIST].d1 != d->d1) {
+      int i;
+
       d->d1 = what_dialog[GFX_DRIVERLIST].d1;
-      d->d2 = what_dialog[GFX_MODELIST].d1;
       what_dialog[GFX_MODELIST].d1 = 0;
+      for (i = 0; i < driver_list[d->d1].mode_count; i++) {
+         if (driver_list[d->d1].mode_list[i].w == width &&
+             driver_list[d->d1].mode_list[i].h == height) {
+           what_dialog[GFX_MODELIST].d1 = i;
+           break;
+         }
+      }
+      d->d2 = what_dialog[GFX_MODELIST].d1;
       what_dialog[GFX_MODELIST].d2 = 0;
 
       object_message(&what_dialog[GFX_MODELIST], MSG_DRAW, 0);
 
       if (what_dialog == gfx_mode_ex_dialog) {
-         what_dialog[GFX_DEPTHLIST].d1 = 0;
+         what_dialog[GFX_DEPTHLIST].d1 = bpp_to_bpp_index(depth, d->d1, d->d2);
+         if (what_dialog[GFX_DEPTHLIST].d1 == -1)
+            what_dialog[GFX_DEPTHLIST].d1 = 0;
+
          object_message(&what_dialog[GFX_DEPTHLIST], MSG_DRAW, 0);
       }
    }
@@ -180,7 +249,10 @@
       d->d2 = what_dialog[GFX_MODELIST].d1;
 
       if (what_dialog == gfx_mode_ex_dialog) {
-         what_dialog[GFX_DEPTHLIST].d1 = 0;
+         what_dialog[GFX_DEPTHLIST].d1 = bpp_to_bpp_index(depth, d->d1, d->d2);
+         if (what_dialog[GFX_DEPTHLIST].d1 == -1)
+            what_dialog[GFX_DEPTHLIST].d1 = 0;
+
          object_message(&what_dialog[GFX_DEPTHLIST], MSG_DRAW, 0);
       }
    }
@@ -485,7 +557,7 @@
  */
 int gfx_mode_select_ex(int *card, int *w, int *h, int *color_depth)
 {
-   int i, j, ret, what_driver, what_mode, what_bpp, extd;
+   int i, ret, what_driver, what_mode, what_bpp, extd;
    ASSERT(card);
    ASSERT(w);
    ASSERT(h);
@@ -539,18 +611,9 @@
       what_dialog[GFX_DEPTHLIST].d1 = 0;
       what_bpp = -1;
 
-      for (i=0; i < BPP_TOTAL; i++) {
-         if (driver_list[what_driver].mode_list[what_mode].bpp[i]) {
-            what_bpp++;
-            switch (i) {
-               case BPP_08: if (*color_depth == 8)  what_dialog[GFX_DEPTHLIST].d1 = what_bpp; break;
-               case BPP_15: if (*color_depth == 15) what_dialog[GFX_DEPTHLIST].d1 = what_bpp; break;
-               case BPP_16: if (*color_depth == 16) what_dialog[GFX_DEPTHLIST].d1 = what_bpp; break;
-               case BPP_24: if (*color_depth == 24) what_dialog[GFX_DEPTHLIST].d1 = what_bpp; break;
-               case BPP_32: if (*color_depth == 32) what_dialog[GFX_DEPTHLIST].d1 = what_bpp; break;
-            }
-         }
-      }
+      what_bpp = bpp_to_bpp_index(*color_depth, what_driver, what_mode);
+  
+      gfx_mode_ex_dialog[GFX_DEPTHLIST].d1 = what_bpp;
    }
 
    centre_dialog(what_dialog);
@@ -571,19 +634,7 @@
    *h = driver_list[what_driver].mode_list[what_mode].h;
 
    if (extd) {
-      j = -1;
-      for (i=0; i < BPP_TOTAL; i++) {
-         if (driver_list[what_driver].mode_list[what_mode].bpp[i]) {
-            j++;
-            if (j == what_bpp) switch (i) {
-               case BPP_08: *color_depth = 8;  break;
-               case BPP_15: *color_depth = 15; break;
-               case BPP_16: *color_depth = 16; break;
-               case BPP_24: *color_depth = 24; break;
-               case BPP_32: *color_depth = 32; break;
-            }
-         }
-      }
+      *color_depth = bpp_index_to_bpp(what_bpp, what_driver, what_mode);
    }
 
    destroy_driver_list();


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