Re: [AD] Runtime Gfx Mode Info - Submission for A4.3.11+

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


>The attached diff shows the changes I would make.

Okay, so I also need to make sure I :
Place the colon directly after comment labels and case labels,
put a function's opening brace on the next line,
place an else statement on it's own line after the closing brace of the if bracket,
give function description comments a two space indent after the asterisk,
and leave variables uninitialized if they receive an assignment later?

I updated the patch to reflect the changes in the functions and formatting, along with updated allegro._tx entries, and attached it.

In C "void f();" declares a function which takes any number of
arguments, not none.
Okay, that's good to know. I'm just used to C++'s convention is all.

Like this (">" for level of quoting).  Your email client should do it
automatically.
Did the very first quote work? For the last two quotes I used right click and 'paste as quotation' in Thunderbird.

It looks pretty good to me.  Let's see what others have to say.
Alright, sounds good.

On a side note, I've been thinking about a change to the way gfx_mode_select* requires that you pass in the default values for card, w, h, and color_depth. The restriction could be removed by adding a parameter indicating whether to use default values, or it could be removed by having zero stored in the parameters passed to the function where no default value should be used. What do you think? The way it is, users basically have to know beforehand which values would be on the list and to pick a set of them, but if they want to use gfx_mode_select_filter with a dynamic filter, they might not always be able to guess what would be left for the available modes. If the gfx_mode_select* functions just set the selections to the first entry in the list when default values weren't passed in that should be fine right?




Index: docs/src/allegro._tx
===================================================================
--- docs/src/allegro._tx	(revision 11621)
+++ docs/src/allegro._tx	(working copy)
@@ -4389,6 +4389,52 @@
    it is a fullscreen mode. You should not call this function if you are not
    in graphics mode.
 
+@@int @get_gfx_mode_type(int graphics_card);
+@xref gfx_mode_select_filter, get_gfx_mode, set_gfx_mode, is_windowed_mode
+@shortdesc Retrieves type information for a specific graphics card.
+   This function lets you determine the types of operating modes that a
+   specific graphics card driver operates in. It will tell you whether it is
+   a windowed, fullscreen, definitely windowed or fullscreen, and/or a magic
+   driver.
+   
+   The value returned is a bitfield consisting of these fields :
+   GFX_TYPE_UNKNOWN
+   GFX_TYPE_WINDOWED
+   GFX_TYPE_FULLSCREEN
+   GFX_TYPE_DEFINITE
+   GFX_TYPE_MAGIC
+   
+   The return value will only be equivalent to GFX_TYPE_UNKNOWN when it is
+   a driver unrecognized on that platform, or it is a bogus value. Test for
+   the other types by using a bitwise AND. If the driver is windowed or
+   fullscreen, it will also have the definite flag set. 
+   For example, get_gfx_mode_type(GFX_AUTODETECT_WINDOWED) would have the
+   flags GFX_TYPE_WINDOWED, GFX_TYPE_DEFINITE, and GFX_TYPE_MAGIC set.
+   
+   Allegro needs to be initialized first.
+   
+   Example :
+<codeblock>
+   /* Accept the use of only windowed drivers in our selection dialog */
+   int accept_windowed(int card , int w , int h , int color_depth) {
+      if (get_gfx_mode_type(card) & GFX_TYPE_WINDOWED) {return 0;}
+      return 1;
+   }
+   /* In main : */
+   gfx_mode_select_filter(&card , &w , &h , &color_depth , accept_windowed);
+<endblock>
+@retval Bitfield describing graphics mode type.
+
+@@int @get_gfx_mode();
+@xref set_gfx_mode, is_windowed_mode
+@shortdesc Returns the id of the current graphics driver.
+   This function will let you determine which graphics driver is currently
+   set by allegro. If no graphics driver is set, it will return GFX_NONE.
+   
+@retval
+   The id of the current graphics driver if there is one, or
+   GFX_NONE if none is set.
+
 @@extern int @gfx_capabilities;
 @xref screen, create_video_bitmap, scroll_screen, request_scroll, show_mouse
 @xref enable_triple_buffer
Index: include/allegro/gfx.h
===================================================================
--- include/allegro/gfx.h	(revision 11621)
+++ include/allegro/gfx.h	(working copy)
@@ -428,7 +428,17 @@
 AL_FUNC(void, vsync, (void));
 
 
+/* Bitfield for relaying graphics driver type information */
+#define GFX_TYPE_UNKNOWN     0
+#define GFX_TYPE_WINDOWED    1
+#define GFX_TYPE_FULLSCREEN  2
+#define GFX_TYPE_DEFINITE    4
+#define GFX_TYPE_MAGIC       8
 
+AL_FUNC(int , get_gfx_mode_type , (int graphics_card));
+AL_FUNC(int , get_gfx_mode , (void));
+
+
 #define SWITCH_NONE           0
 #define SWITCH_PAUSE          1
 #define SWITCH_AMNESIA        2
Index: src/graphics.c
===================================================================
--- src/graphics.c	(revision 11621)
+++ src/graphics.c	(working copy)
@@ -1750,3 +1750,76 @@
 }
 
 
+
+/* get_gfx_mode_type:
+ *  Evaluates the type of the graphics driver card
+ *  and tells you whether it is a windowed, fullscreen,
+ *  definitely windowed or fullscreen, and/or a magic driver.
+ *  See gfx.h for the GFX_TYPE_* defines.
+ */
+int get_gfx_mode_type(int graphics_card)
+{
+   int gfx_type = GFX_TYPE_UNKNOWN;
+   _DRIVER_INFO* gfx_driver_info;
+   GFX_DRIVER*   gfx_driver_entry;
+
+   ASSERT(system_driver);
+
+   /* Ask the system driver for a list of graphics hardware drivers */
+   if (system_driver->gfx_drivers) {
+      gfx_driver_info = system_driver->gfx_drivers();
+   }
+   else {
+      gfx_driver_info = _gfx_driver_list;
+   }
+
+   ASSERT(gfx_driver_info);
+
+   while(gfx_driver_info->driver) {
+      if (gfx_driver_info->id == graphics_card) {
+         gfx_driver_entry = (GFX_DRIVER*)gfx_driver_info->driver;
+         if (gfx_driver_entry->windowed) {
+            gfx_type |= (GFX_TYPE_WINDOWED   | GFX_TYPE_DEFINITE);
+         }
+         else {
+            gfx_type |= (GFX_TYPE_FULLSCREEN | GFX_TYPE_DEFINITE);
+         }
+         break;
+      }
+      ++gfx_driver_info;
+   }
+
+   switch (graphics_card) {
+      case GFX_AUTODETECT:
+         gfx_type |= GFX_TYPE_MAGIC;
+         break;
+      case GFX_AUTODETECT_FULLSCREEN:
+         gfx_type |= (GFX_TYPE_MAGIC | GFX_TYPE_FULLSCREEN | GFX_TYPE_DEFINITE);
+         break;
+      case GFX_AUTODETECT_WINDOWED:
+         gfx_type |= (GFX_TYPE_MAGIC | GFX_TYPE_WINDOWED   | GFX_TYPE_DEFINITE);
+         break;
+      case GFX_SAFE:
+         gfx_type |= GFX_TYPE_MAGIC;
+         break;
+      case GFX_TEXT:
+         gfx_type |= GFX_TYPE_MAGIC;
+         break;
+   }
+   return gfx_type;
+}
+
+
+
+/* get_gfx_mode:
+ *  Tells you which graphics mode is currently set.
+ *  Useful for determining the actual driver that
+ *  GFX_AUTODETECT* or GFX_SAFE set successfully.
+ */
+int get_gfx_mode(void) {
+   if (!gfx_driver) {return GFX_NONE;}
+   return gfx_driver->id;
+}
+
+
+


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