iOS/libraries/allegro/allegro/src/modesel.c
/* gfx_mode_select_filter:
 *  Extended version of the graphics mode selection dialog, which allows the 
 *  user to select the color depth as well as the resolution and hardware 
 *  driver. An optional filter can be passed to check whether a particular
 *  entry should be displayed or not. Initial values for the selections may be
 *  given at the addresses passed to the function, and the user's selection
 *  will be stored at those addresses if the dialog is OK'd. Initial values
 *  at the addresses passed to the function may be set to 0 or -1 to indicate
 *  not to search for the values but to default to the first entries in each 
 *  selection list.
 *  In the case of an error, *card is set to GFX_NONE and FALSE is returned.
 *  In the case that the filter filtered out all of the modes, *card is set to
 *  GFX_NONE and TRUE is returned.
 */
Extended version of the graphics mode selection dialog, which allows the
user to select the color depth as well as the resolution and hardware
driver. An optional filter can be passed to check whether a particular
entry should be displayed or not. Initial values for the selections may be
given at the addresses passed to the function, and the user's selection
will be stored at those addresses if the dialog is OK'd. Initial values
at the addresses passed to the function may be set to 0 or -1 to indicate
not to search for the values but to default to the first entries in each
selection list.
In the case of an error, *card is set to GFX_NONE and FALSE is returned.
In the case that the filter filtered out all of the modes, *card is set to
GFX_NONE and TRUE is returned.
Extended version of the graphics mode selection dialog which allows the user to select the color depth as well as the resolution and hardware driver . An optional filter can be passed to check whether a particular entry should be displayed or not . Initial values for the selections may be given at the addresses passed to the function and the user ' s selection will be stored at those addresses if the dialog is OK ' d . Initial values at the addresses passed to the function may be set to 0 or - 1 to indicate not to search for the values but to default to the first entries in each selection list . In the case of an error * card is set to GFX_NONE and FALSE is returned . In the case that the filter filtered out all of the modes * card is set to GFX_NONE and TRUE is returned .
int gfx_mode_select_filter(int *card, int *w, int *h, int *color_depth, FILTER_FUNCTION filter)
{
   int i, ret, what_driver, what_mode, what_bpp, extd;
   MODE_LIST* mode_iter;
   ASSERT(card);
   ASSERT(w);
   ASSERT(h);
   clear_keybuf();
   extd = color_depth ? TRUE : FALSE;
   while (gui_mouse_b());
   what_dialog = extd ? gfx_mode_ex_dialog : gfx_mode_dialog;
   what_dialog[GFX_TITLE].dp = (void*)get_config_text("Graphics Mode");
   what_dialog[GFX_OK].dp = (void*)get_config_text("OK");
   what_dialog[GFX_CANCEL].dp = (void*)get_config_text("Cancel");
   ret = create_driver_list(filter);
   if (ret == -1) {
      *card = GFX_NONE;
      return FALSE;
   }
   if (!driver_count) {
      *card = GFX_NONE;
      return TRUE;
   }
   what_driver = 0;
   if (!((*card == 0) || (*card == -1))) {
      for (i = 0 ; i < driver_count ; ++i) {
         if (driver_list[i].id == *card) {
            what_driver = i;
         }
      }
   }
   what_dialog[GFX_DRIVERLIST].d1 = what_driver;
   what_dialog[GFX_CHANGEPROC].d1 = what_driver;
   what_mode = 0;
   mode_iter = &(driver_list[what_driver].mode_list[0]);
   if (!(((*w == 0) || (*w == -1)) || ((*h == 0) || (*h == -1)))) {
      for (i = 0 ; i < driver_list[what_driver].mode_count ; ++i) {
         if ((mode_iter->w == *w) && (mode_iter->h == *h)) {
            what_mode = i;
            break;
         }
         ++mode_iter;
      }
   }
   what_dialog[GFX_MODELIST].d1 = what_mode;
   what_dialog[GFX_CHANGEPROC].d2 = what_mode;
   if (extd) {
      what_bpp = 0;
      if (!((*color_depth == 0) || (*color_depth == -1))) {
         what_bpp = bpp_index_for_mode(*color_depth , what_driver , what_mode);
         if (what_bpp < 0) {what_bpp = 0;} 
      }
      what_dialog[GFX_DEPTHLIST].d1 = what_bpp;
   }
   centre_dialog(what_dialog);
   set_dialog_color(what_dialog, gui_fg_color, gui_bg_color);
   ret = popup_dialog(what_dialog, GFX_DRIVERLIST);
   what_driver = what_dialog[GFX_DRIVERLIST].d1;
   what_mode = what_dialog[GFX_MODELIST].d1;
   if (extd)
      what_bpp = what_dialog[GFX_DEPTHLIST].d1;
   else
      what_bpp = 0;
   if (ret != GFX_CANCEL) {
      *card = driver_list[what_driver].id;
      *w = driver_list[what_driver].mode_list[what_mode].w;
      *h = driver_list[what_driver].mode_list[what_mode].h;
      if (extd) {
         *color_depth = bpp_value_for_mode(what_bpp, what_driver, what_mode);
      }
   }
   destroy_driver_list();
   if (ret == GFX_CANCEL)
      return FALSE;
   else 
      return TRUE;
}
int gfx_mode_select_filter ( int * card , int * w , int * h , int * color_depth , FILTER_FUNCTION filter ) { int i , ret , what_driver , what_mode , what_bpp , extd ; MODE_LIST * mode_iter ; ASSERT ( card ) ; ASSERT ( w ) ; ASSERT ( h ) ; clear_keybuf ( ) ; extd = color_depth ? TRUE : FALSE ; while ( gui_mouse_b ( ) ) ; what_dialog = extd ? gfx_mode_ex_dialog : gfx_mode_dialog ; what_dialog [ GFX_TITLE ] . dp = ( void * ) get_config_text ( " " ) ; what_dialog [ GFX_OK ] . dp = ( void * ) get_config_text ( " " ) ; what_dialog [ GFX_CANCEL ] . dp = ( void * ) get_config_text ( " " ) ; ret = create_driver_list ( filter ) ; if ( ret == -1 ) { * card = GFX_NONE ; return FALSE ; } if ( ! driver_count ) { * card = GFX_NONE ; return TRUE ; } what_driver = 0 ; if ( ! ( ( * card == 0 ) || ( * card == -1 ) ) ) { for ( i = 0 ; i < driver_count ; ++ i ) { if ( driver_list [ i ] . id == * card ) { what_driver = i ; } } } what_dialog [ GFX_DRIVERLIST ] . d1 = what_driver ; what_dialog [ GFX_CHANGEPROC ] . d1 = what_driver ; what_mode = 0 ; mode_iter = & ( driver_list [ what_driver ] . mode_list [ 0 ] ) ; if ( ! ( ( ( * w == 0 ) || ( * w == -1 ) ) || ( ( * h == 0 ) || ( * h == -1 ) ) ) ) { for ( i = 0 ; i < driver_list [ what_driver ] . mode_count ; ++ i ) { if ( ( mode_iter -> w == * w ) && ( mode_iter -> h == * h ) ) { what_mode = i ; break ; } ++ mode_iter ; } } what_dialog [ GFX_MODELIST ] . d1 = what_mode ; what_dialog [ GFX_CHANGEPROC ] . d2 = what_mode ; if ( extd ) { what_bpp = 0 ; if ( ! ( ( * color_depth == 0 ) || ( * color_depth == -1 ) ) ) { what_bpp = bpp_index_for_mode ( * color_depth , what_driver , what_mode ) ; if ( what_bpp < 0 ) { what_bpp = 0 ; } } what_dialog [ GFX_DEPTHLIST ] . d1 = what_bpp ; } centre_dialog ( what_dialog ) ; set_dialog_color ( what_dialog , gui_fg_color , gui_bg_color ) ; ret = popup_dialog ( what_dialog , GFX_DRIVERLIST ) ; what_driver = what_dialog [ GFX_DRIVERLIST ] . d1 ; what_mode = what_dialog [ GFX_MODELIST ] . d1 ; if ( extd ) what_bpp = what_dialog [ GFX_DEPTHLIST ] . d1 ; else what_bpp = 0 ; if ( ret != GFX_CANCEL ) { * card = driver_list [ what_driver ] . id ; * w = driver_list [ what_driver ] . mode_list [ what_mode ] . w ; * h = driver_list [ what_driver ] . mode_list [ what_mode ] . h ; if ( extd ) { * color_depth = bpp_value_for_mode ( what_bpp , what_driver , what_mode ) ; } } destroy_driver_list ( ) ; if ( ret == GFX_CANCEL ) return FALSE ; else return TRUE ; }
gfx_mode_select_filter:
  Extended version of the graphics mode selection dialog, which allows the
  user to select the color depth as well as the resolution and hardware
  driver.
gfx_mode_select_filter : Extended version of the graphics mode selection dialog which allows the user to select the color depth as well as the resolution and hardware driver .
/* The data stored at the addresses passed to this function is used to
    * search for initial selections in the dialog lists. If the requested
    * entries are not found, default to the first selection in each list in
    * order of the driver, the mode w/h, and also the color depth when in
    * extended mode (called directly or from gfx_mode_select_ex).
    */ /* Check for the user suggested driver first */ /* Default to first entry if not found */ /* Don't search for initial values if *card is 0 or -1 */ /* Check for suggested resolution dimensions second */ /* Default to first entry if not found */ /* Don't search for initial values if *w or *h is 0 or -1 */ /* Check for suggested color depth when in extended mode */ /* Don't search for initial values if *color_depth is 0 or -1 */ /* Default to first entry if not found */