src/video/cybergfx/SDL_cgxmodes.c
branchSDL-1.3
changeset 1668 4da1ee79c9af
parent 1662 782fd950bd46
equal deleted inserted replaced
1667:1fddae038bc8 1668:4da1ee79c9af
    31 #include "SDL_cgxmodes_c.h"
    31 #include "SDL_cgxmodes_c.h"
    32 
    32 
    33 #define CGX_DEBUG
    33 #define CGX_DEBUG
    34 
    34 
    35 static void
    35 static void
    36 set_best_resolution (_THIS, int width, int height)
    36 set_best_resolution(_THIS, int width, int height)
    37 {
    37 {
    38     Uint32 idok;
    38     Uint32 idok;
    39     int depth = 8;
    39     int depth = 8;
    40 
    40 
    41     if (SDL_Display)
    41     if (SDL_Display)
    42         depth =
    42         depth =
    43             GetCyberMapAttr (SDL_Display->RastPort.BitMap, CYBRMATTR_DEPTH);
    43             GetCyberMapAttr(SDL_Display->RastPort.BitMap, CYBRMATTR_DEPTH);
    44 
    44 
    45     idok = BestCModeIDTags (CYBRBIDTG_NominalWidth, width,
    45     idok = BestCModeIDTags(CYBRBIDTG_NominalWidth, width,
    46                             CYBRBIDTG_NominalHeight, height,
    46                            CYBRBIDTG_NominalHeight, height,
    47                             CYBRBIDTG_Depth, depth, TAG_DONE);
    47                            CYBRBIDTG_Depth, depth, TAG_DONE);
    48 
    48 
    49     if (idok != INVALID_ID) {
    49     if (idok != INVALID_ID) {
    50         if (SDL_Display) {
    50         if (SDL_Display) {
    51             if (currently_fullscreen)
    51             if (currently_fullscreen)
    52                 CloseScreen (SDL_Display);
    52                 CloseScreen(SDL_Display);
    53             else
    53             else
    54                 UnlockPubScreen (NULL, SDL_Display);
    54                 UnlockPubScreen(NULL, SDL_Display);
    55         }
    55         }
    56         SDL_Display = GFX_Display =
    56         SDL_Display = GFX_Display =
    57             OpenScreenTags (NULL, SA_Width, width, SA_Height, height,
    57             OpenScreenTags(NULL, SA_Width, width, SA_Height, height,
    58                             SA_Depth, depth, SA_DisplayID, idok,
    58                            SA_Depth, depth, SA_DisplayID, idok,
    59                             SA_ShowTitle, FALSE, TAG_DONE);
    59                            SA_ShowTitle, FALSE, TAG_DONE);
    60     }
    60     }
    61 }
    61 }
    62 
    62 
    63 static void
    63 static void
    64 get_real_resolution (_THIS, int *w, int *h)
    64 get_real_resolution(_THIS, int *w, int *h)
    65 {
    65 {
    66     *w = /*SDL_Display->Width */ SDL_Window->Width - SDL_Window->BorderLeft -
    66     *w = /*SDL_Display->Width */ SDL_Window->Width - SDL_Window->BorderLeft -
    67         SDL_Window->BorderRight;
    67         SDL_Window->BorderRight;
    68     *h = /*SDL_Display->Height */ SDL_Window->Height -
    68     *h = /*SDL_Display->Height */ SDL_Window->Height -
    69         SDL_Window->BorderBottom - SDL_Window->BorderTop;
    69         SDL_Window->BorderBottom - SDL_Window->BorderTop;
    70 }
    70 }
    71 
    71 
    72 static void
    72 static void
    73 move_cursor_to (_THIS, int x, int y)
    73 move_cursor_to(_THIS, int x, int y)
    74 {
    74 {
    75 /*    XWarpPointer(SDL_Display, None, SDL_Root, 0, 0, 0, 0, x, y); */
    75 /*    XWarpPointer(SDL_Display, None, SDL_Root, 0, 0, 0, 0, x, y); */
    76 
    76 
    77 /* DA FARE! */
    77 /* DA FARE! */
    78 }
    78 }
    79 
    79 
    80 static void
    80 static void
    81 add_visual (_THIS, int depth, int class)
    81 add_visual(_THIS, int depth, int class)
    82 {
    82 {
    83     Uint32 tID;
    83     Uint32 tID;
    84 
    84 
    85     tID = BestCModeIDTags (CYBRBIDTG_Depth, depth,
    85     tID = BestCModeIDTags(CYBRBIDTG_Depth, depth,
    86                            CYBRBIDTG_NominalWidth, 640,
    86                           CYBRBIDTG_NominalWidth, 640,
    87                            CYBRBIDTG_NominalHeight, 480, TAG_DONE);
    87                           CYBRBIDTG_NominalHeight, 480, TAG_DONE);
    88 
    88 
    89     if (tID != INVALID_ID) {
    89     if (tID != INVALID_ID) {
    90         int n = this->hidden->nvisuals;
    90         int n = this->hidden->nvisuals;
    91 
    91 
    92         this->hidden->visuals[n].depth = depth;
    92         this->hidden->visuals[n].depth = depth;
    93         this->hidden->visuals[n].visual = tID;
    93         this->hidden->visuals[n].visual = tID;
    94         this->hidden->visuals[n].bpp = GetCyberIDAttr (CYBRIDATTR_BPPIX, tID);
    94         this->hidden->visuals[n].bpp = GetCyberIDAttr(CYBRIDATTR_BPPIX, tID);
    95         this->hidden->nvisuals++;
    95         this->hidden->nvisuals++;
    96     }
    96     }
    97 }
    97 }
    98 
    98 
    99 #define TrueColor 1
    99 #define TrueColor 1
   100 #define PseudoColor 2
   100 #define PseudoColor 2
   101 
   101 
   102 int
   102 int
   103 CGX_GetVideoModes (_THIS)
   103 CGX_GetVideoModes(_THIS)
   104 {
   104 {
   105     int i;
   105     int i;
   106     ULONG nextid;
   106     ULONG nextid;
   107     int nmodes = 0;
   107     int nmodes = 0;
   108 
   108 
   109     SDL_modelist = NULL;
   109     SDL_modelist = NULL;
   110 
   110 
   111     nextid = NextDisplayInfo (INVALID_ID);
   111     nextid = NextDisplayInfo(INVALID_ID);
   112 
   112 
   113     while (nextid != INVALID_ID) {
   113     while (nextid != INVALID_ID) {
   114         if (IsCyberModeID (nextid)) {
   114         if (IsCyberModeID(nextid)) {
   115             DisplayInfoHandle h;
   115             DisplayInfoHandle h;
   116 
   116 
   117             if (h = FindDisplayInfo (nextid)) {
   117             if (h = FindDisplayInfo(nextid)) {
   118                 struct DimensionInfo info;
   118                 struct DimensionInfo info;
   119 
   119 
   120                 if (GetDisplayInfoData
   120                 if (GetDisplayInfoData
   121                     (h, (char *) &info, sizeof (struct DimensionInfo),
   121                     (h, (char *) &info, sizeof(struct DimensionInfo),
   122                      DTAG_DIMS, NULL)) {
   122                      DTAG_DIMS, NULL)) {
   123                     int ok = 0;
   123                     int ok = 0;
   124 
   124 
   125                     for (i = 0; i < nmodes; i++) {
   125                     for (i = 0; i < nmodes; i++) {
   126                         if (SDL_modelist[i]->w == (info.Nominal.MaxX + 1)
   126                         if (SDL_modelist[i]->w == (info.Nominal.MaxX + 1)
   130 
   130 
   131                     if (!ok) {
   131                     if (!ok) {
   132                         nmodes++;
   132                         nmodes++;
   133 
   133 
   134                         SDL_modelist =
   134                         SDL_modelist =
   135                             (SDL_Rect **) SDL_realloc (SDL_modelist,
   135                             (SDL_Rect **) SDL_realloc(SDL_modelist,
   136                                                        (nmodes +
   136                                                       (nmodes +
   137                                                         1) *
   137                                                        1) *
   138                                                        sizeof (SDL_Rect *));
   138                                                       sizeof(SDL_Rect *));
   139                         SDL_modelist[nmodes] = NULL;
   139                         SDL_modelist[nmodes] = NULL;
   140 
   140 
   141                         if (SDL_modelist) {
   141                         if (SDL_modelist) {
   142                             SDL_modelist[nmodes - 1] = (SDL_Rect *)
   142                             SDL_modelist[nmodes - 1] = (SDL_Rect *)
   143                                 SDL_malloc (sizeof (SDL_Rect));
   143                                 SDL_malloc(sizeof(SDL_Rect));
   144 
   144 
   145                             if (SDL_modelist[nmodes - 1] == NULL)
   145                             if (SDL_modelist[nmodes - 1] == NULL)
   146                                 break;
   146                                 break;
   147 
   147 
   148                             SDL_modelist[nmodes - 1]->x = 0;
   148                             SDL_modelist[nmodes - 1]->x = 0;
   154                         }
   154                         }
   155                     }
   155                     }
   156                 }
   156                 }
   157             }
   157             }
   158         }
   158         }
   159         nextid = NextDisplayInfo (nextid);
   159         nextid = NextDisplayInfo(nextid);
   160     }
   160     }
   161 
   161 
   162 
   162 
   163     this->hidden->nvisuals = 0;
   163     this->hidden->nvisuals = 0;
   164     /* Search for the visuals in deepest-first order, so that the first
   164     /* Search for the visuals in deepest-first order, so that the first
   165        will be the richest one */
   165        will be the richest one */
   166     add_visual (this, 32, TrueColor);
   166     add_visual(this, 32, TrueColor);
   167     add_visual (this, 24, TrueColor);
   167     add_visual(this, 24, TrueColor);
   168     add_visual (this, 16, TrueColor);
   168     add_visual(this, 16, TrueColor);
   169     add_visual (this, 15, TrueColor);
   169     add_visual(this, 15, TrueColor);
   170     add_visual (this, 8, PseudoColor);
   170     add_visual(this, 8, PseudoColor);
   171 
   171 
   172     if (this->hidden->nvisuals == 0) {
   172     if (this->hidden->nvisuals == 0) {
   173         SDL_SetError ("Found no sufficiently capable CGX visuals");
   173         SDL_SetError("Found no sufficiently capable CGX visuals");
   174         return -1;
   174         return -1;
   175     }
   175     }
   176 
   176 
   177     if (SDL_modelist == NULL) {
   177     if (SDL_modelist == NULL) {
   178         SDL_modelist =
   178         SDL_modelist = (SDL_Rect **) SDL_malloc((1 + 1) * sizeof(SDL_Rect *));
   179             (SDL_Rect **) SDL_malloc ((1 + 1) * sizeof (SDL_Rect *));
       
   180         i = 0;
   179         i = 0;
   181         if (SDL_modelist) {
   180         if (SDL_modelist) {
   182             SDL_modelist[i] = (SDL_Rect *) SDL_malloc (sizeof (SDL_Rect));
   181             SDL_modelist[i] = (SDL_Rect *) SDL_malloc(sizeof(SDL_Rect));
   183             if (SDL_modelist[i]) {
   182             if (SDL_modelist[i]) {
   184                 SDL_modelist[i]->x = 0;
   183                 SDL_modelist[i]->x = 0;
   185                 SDL_modelist[i]->y = 0;
   184                 SDL_modelist[i]->y = 0;
   186                 SDL_modelist[i]->w = SDL_Display->Width;
   185                 SDL_modelist[i]->w = SDL_Display->Width;
   187                 SDL_modelist[i]->h = SDL_Display->Height;
   186                 SDL_modelist[i]->h = SDL_Display->Height;
   189             }
   188             }
   190             SDL_modelist[i] = NULL;
   189             SDL_modelist[i] = NULL;
   191         }
   190         }
   192     }
   191     }
   193 
   192 
   194     D (if (SDL_modelist) {
   193     D(if (SDL_modelist) {
   195        bug ("CGX video mode list: (%ld)\n", nmodes);
   194       bug("CGX video mode list: (%ld)\n", nmodes);
   196        for (i = 0; SDL_modelist[i]; ++i) {
   195       for (i = 0; SDL_modelist[i]; ++i) {
   197        bug ("\t%ld x %ld\n", SDL_modelist[i]->w, SDL_modelist[i]->h);}
   196       bug("\t%ld x %ld\n", SDL_modelist[i]->w, SDL_modelist[i]->h);}
   198        }
   197       }
   199     );
   198     );
   200 
   199 
   201     D ( {
   200     D( {
   202        bug ("CGX visuals list: (%ld)\n", this->hidden->nvisuals);
   201       bug("CGX visuals list: (%ld)\n", this->hidden->nvisuals);
   203        for (i = 0; i < this->hidden->nvisuals; i++)
   202       for (i = 0; i < this->hidden->nvisuals; i++)
   204        bug ("\t%lx - depth: %ld bpp: %ld\n",
   203       bug("\t%lx - depth: %ld bpp: %ld\n",
   205             this->hidden->visuals[i].visual,
   204           this->hidden->visuals[i].visual,
   206             this->hidden->visuals[i].depth, this->hidden->visuals[i].bpp);}
   205           this->hidden->visuals[i].depth, this->hidden->visuals[i].bpp);}
   207     );
   206     );
   208     return 0;
   207     return 0;
   209 }
   208 }
   210 
   209 
   211 int
   210 int
   212 CGX_SupportedVisual (_THIS, SDL_PixelFormat * format)
   211 CGX_SupportedVisual(_THIS, SDL_PixelFormat * format)
   213 {
   212 {
   214     int i;
   213     int i;
   215     for (i = 0; i < this->hidden->nvisuals; i++) {
   214     for (i = 0; i < this->hidden->nvisuals; i++) {
   216         if (this->hidden->visuals[i].depth == format->BitsPerPixel)     // Era bpp
   215         if (this->hidden->visuals[i].depth == format->BitsPerPixel)     // Era bpp
   217             return 1;
   216             return 1;
   218     }
   217     }
   219     return 0;
   218     return 0;
   220 }
   219 }
   221 
   220 
   222 SDL_Rect **
   221 SDL_Rect **
   223 CGX_ListModes (_THIS, SDL_PixelFormat * format, Uint32 flags)
   222 CGX_ListModes(_THIS, SDL_PixelFormat * format, Uint32 flags)
   224 {
   223 {
   225     if (CGX_SupportedVisual (this, format)) {
   224     if (CGX_SupportedVisual(this, format)) {
   226         if (flags & SDL_FULLSCREEN) {
   225         if (flags & SDL_FULLSCREEN) {
   227             return (SDL_modelist);
   226             return (SDL_modelist);
   228         } else {
   227         } else {
   229             return ((SDL_Rect **) - 1);
   228             return ((SDL_Rect **) - 1);
   230         }
   229         }
   232         return ((SDL_Rect **) 0);
   231         return ((SDL_Rect **) 0);
   233     }
   232     }
   234 }
   233 }
   235 
   234 
   236 void
   235 void
   237 CGX_FreeVideoModes (_THIS)
   236 CGX_FreeVideoModes(_THIS)
   238 {
   237 {
   239     int i;
   238     int i;
   240 
   239 
   241     if (SDL_modelist) {
   240     if (SDL_modelist) {
   242         for (i = 0; SDL_modelist[i]; ++i) {
   241         for (i = 0; SDL_modelist[i]; ++i) {
   243             SDL_free (SDL_modelist[i]);
   242             SDL_free(SDL_modelist[i]);
   244         }
   243         }
   245         SDL_free (SDL_modelist);
   244         SDL_free(SDL_modelist);
   246         SDL_modelist = NULL;
   245         SDL_modelist = NULL;
   247     }
   246     }
   248 }
   247 }
   249 
   248 
   250 int
   249 int
   251 CGX_ResizeFullScreen (_THIS)
   250 CGX_ResizeFullScreen(_THIS)
   252 {
   251 {
   253     int x, y;
   252     int x, y;
   254     int real_w, real_h;
   253     int real_w, real_h;
   255 
   254 
   256     if (currently_fullscreen) {
   255     if (currently_fullscreen) {
   258     }
   257     }
   259     return (1);
   258     return (1);
   260 }
   259 }
   261 
   260 
   262 void
   261 void
   263 _QueueEnterFullScreen (_THIS)
   262 _QueueEnterFullScreen(_THIS)
   264 {
   263 {
   265 }
   264 }
   266 
   265 
   267 int
   266 int
   268 CGX_EnterFullScreen (_THIS)
   267 CGX_EnterFullScreen(_THIS)
   269 {
   268 {
   270     int okay;
   269     int okay;
   271     Uint32 saved_flags;
   270     Uint32 saved_flags;
   272 
   271 
   273     okay = 1;
   272     okay = 1;
   275 
   274 
   276     if (!currently_fullscreen) {
   275     if (!currently_fullscreen) {
   277         int real_w, real_h;
   276         int real_w, real_h;
   278 
   277 
   279         /* Map the fullscreen window to blank the screen */
   278         /* Map the fullscreen window to blank the screen */
   280         get_real_resolution (this, &real_w, &real_h);
   279         get_real_resolution(this, &real_w, &real_h);
   281 
   280 
   282         CGX_DestroyWindow (this, this->screen);
   281         CGX_DestroyWindow(this, this->screen);
   283         set_best_resolution (this, real_w, real_h);
   282         set_best_resolution(this, real_w, real_h);
   284 
   283 
   285         currently_fullscreen = 1;
   284         currently_fullscreen = 1;
   286         this->screen->flags = saved_flags;
   285         this->screen->flags = saved_flags;
   287 
   286 
   288         CGX_CreateWindow (this, this->screen, real_w, real_h,
   287         CGX_CreateWindow(this, this->screen, real_w, real_h,
   289                           GetCyberMapAttr (SDL_Display->RastPort.BitMap,
   288                          GetCyberMapAttr(SDL_Display->RastPort.BitMap,
   290                                            CYBRMATTR_DEPTH),
   289                                          CYBRMATTR_DEPTH),
   291                           this->screen->flags);
   290                          this->screen->flags);
   292 
   291 
   293         /* Set the new resolution */
   292         /* Set the new resolution */
   294         okay = CGX_ResizeFullScreen (this);
   293         okay = CGX_ResizeFullScreen(this);
   295         if (!okay) {
   294         if (!okay) {
   296             CGX_LeaveFullScreen (this);
   295             CGX_LeaveFullScreen(this);
   297         }
   296         }
   298         /* Set the colormap */
   297         /* Set the colormap */
   299 /*
   298 /*
   300 		if ( SDL_XColorMap ) {
   299 		if ( SDL_XColorMap ) {
   301 			XInstallColormap(SDL_Display, SDL_XColorMap);
   300 			XInstallColormap(SDL_Display, SDL_XColorMap);
   305 //    CGX_GrabInputNoLock(this, this->input_grab | SDL_GRAB_FULLSCREEN);
   304 //    CGX_GrabInputNoLock(this, this->input_grab | SDL_GRAB_FULLSCREEN);
   306     return (okay);
   305     return (okay);
   307 }
   306 }
   308 
   307 
   309 int
   308 int
   310 CGX_LeaveFullScreen (_THIS)
   309 CGX_LeaveFullScreen(_THIS)
   311 {
   310 {
   312     if (currently_fullscreen) {
   311     if (currently_fullscreen) {
   313         int width, height;
   312         int width, height;
   314         if (SDL_Window) {
   313         if (SDL_Window) {
   315             CloseWindow (SDL_Window);
   314             CloseWindow(SDL_Window);
   316             SDL_Window = NULL;
   315             SDL_Window = NULL;
   317         }
   316         }
   318         CloseScreen (SDL_Display);
   317         CloseScreen(SDL_Display);
   319 
   318 
   320         GFX_Display = SDL_Display = LockPubScreen (NULL);
   319         GFX_Display = SDL_Display = LockPubScreen(NULL);
   321 
   320 
   322         currently_fullscreen = 0;
   321         currently_fullscreen = 0;
   323 
   322 
   324         CGX_CreateWindow (this, this->screen, this->screen->w,
   323         CGX_CreateWindow(this, this->screen, this->screen->w,
   325                           this->screen->h,
   324                          this->screen->h,
   326                           GetCyberMapAttr (SDL_Display->RastPort.BitMap,
   325                          GetCyberMapAttr(SDL_Display->RastPort.BitMap,
   327                                            CYBRMATTR_DEPTH),
   326                                          CYBRMATTR_DEPTH),
   328                           this->screen->flags);
   327                          this->screen->flags);
   329         CGX_ResizeImage (this, this->screen, 0L);
   328         CGX_ResizeImage(this, this->screen, 0L);
   330     }
   329     }
   331 
   330 
   332     return (0);
   331     return (0);
   333 }
   332 }
   334 
   333