1 /*
2 * sdl_darw.c SDL video mode and full-screen
3 *
4 * Copyright (C) 2000- Fumihiko Murata <fmurata@p1.tcnet.ne.jp>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 */
21 /* $Id: sdl_mode.c,v 1.6 2003/01/04 17:01:02 chikama Exp $ */
22
23 #include "config.h"
24
25 #include <stdio.h>
26 #include <limits.h>
27 #include <SDL/SDL.h>
28
29 #include "portab.h"
30 #include "system.h"
31 #include "sdl_private.h"
32
33
34 static SDL_Rect **modes;
35
36
sdl_vm_init(void)37 void sdl_vm_init(void) {
38 modes = SDL_ListModes(NULL, SDL_FULLSCREEN | SDL_HWSURFACE);
39
40 /* Check is there are any modes available */
41 if (modes == (SDL_Rect **)0) {
42 SYSERROR("No modes available!\n");
43 }
44
45 /* Check if or resolution is restricted */
46 if (modes == (SDL_Rect **)-1){
47 NOTICE("All resolutions available.\n");
48 } else {
49 int i;
50 /* Print valid modes */
51 NOTICE("Available Modes\n");
52 for(i = 0; modes[i]; i++) {
53 NOTICE(" %d x %d\n", modes[i]->w, modes[i]->h);
54 }
55 }
56
57 }
58
search_preferable_fullscreen_mode()59 static int search_preferable_fullscreen_mode() {
60 int i, vm = 0, delta = INT_MAX;
61
62 /* ���٤Ƥ�mode�Τʤ��ǺǤ�Ŭ�ڤʥ⡼�ɤ����� */
63 for (i = 0; modes[i]; i++) {
64 if (modes[i]->w >= view_w &&
65 modes[i]->h >= view_y) {
66 int deltaw = modes[i]->w - view_w;
67 int deltah = modes[i]->h - view_h;
68 if (delta > (deltaw + deltah)) {
69 vm = i;
70 delta = deltaw + deltah;
71 }
72 }
73 }
74 return vm;
75 }
76
enter_fullscreen()77 static void enter_fullscreen() {
78 Uint32 mode = sdl_vflag;
79
80 mode |= SDL_FULLSCREEN;
81
82 sdl_display = SDL_SetVideoMode(view_w, view_h, sdl_vinfo->vfmt->BitsPerPixel, mode);
83 }
84
quit_fullscreen()85 static void quit_fullscreen() {
86
87 }
88
89
sdl_FullScreen(boolean on)90 void sdl_FullScreen(boolean on) {
91
92 if (on && !sdl_fs_on) {
93 sdl_fs_on = TRUE;
94 enter_fullscreen();
95 } else if (!on && sdl_fs_on) {
96 quit_fullscreen();
97 sdl_fs_on = FALSE;
98 }
99 }
100
101
102 /* Window���礭�����ѹ� */
sdl_setWindowSize(int x,int y,int w,int h)103 void sdl_setWindowSize(int x, int y, int w, int h) {
104 Uint32 mode = sdl_vflag;
105
106 view_x = x;
107 view_y = y;
108
109 if (w == view_w && h == view_h) return;
110
111 view_w = w;
112 view_h = h;
113
114 if (sdl_fs_on) {
115 int m = search_preferable_fullscreen_mode();
116
117 if (modes[m]->w != view_w || modes[m]->h != view_h) {
118 winoffset_x = (modes[m]->w - view_w) / 2;
119 winoffset_y = (modes[m]->h - view_h) / 2;
120 w = modes[m]->w;
121 h = modes[m]->h;
122 } else {
123 winoffset_x = winoffset_y = 0;
124 }
125
126 mode |= SDL_FULLSCREEN;
127 }
128
129 sdl_display = SDL_SetVideoMode(w, h, sdl_vinfo->vfmt->BitsPerPixel, mode);
130 ms_active = (SDL_GetAppState() & SDL_APPMOUSEFOCUS) ? TRUE : FALSE;
131 }
132