48
51
static int keep_aspect_ratio, true_aspect_ratio, aspect_ratio;
49
52
static int ui_setup_finished = 0;
57
static HMENU old_menu;
59
static DWORD old_style;
60
static float old_refreshrate;
67
} DirectDrawDeviceList;
51
78
static DirectDrawDeviceList *devices = NULL;
52
79
static DirectDrawModeList *modes = NULL;
55
82
void fullscreen_setup_finished(void)
65
void fullscreen_devices_and_modes_free(void)
67
DirectDrawModeList *m1, *m2;
68
DirectDrawDeviceList *d1, *d2;
88
92
int fullscreen_get_nesting_level(void)
90
94
return fullscreen_nesting_level;
93
97
static void fullscreen_set_res_from_current_display(void)
95
100
int bitdepth, width, height, refreshrate;
97
102
if (video_dx9_enabled()) {
98
fullscreen_get_current_display_dx9(&bitdepth, &width, &height, &refreshrate);
100
fullscreen_get_current_display_ddraw(&bitdepth, &width, &height, &refreshrate);
105
if (S_OK == IDirect3D9_GetAdapterDisplayMode(d3d, D3DADAPTER_DEFAULT , &mode)) {
108
height = mode.Height;
109
refreshrate = mode.RefreshRate;
111
/* provide defaults if GetDisplayMode fails for some reason */
112
log_debug("fullscreen_get_current_display_dx9 failed to get mode!");
103
120
resources_set_int("FullscreenBitdepth", bitdepth);
104
121
resources_set_int("FullscreenWidth", width);
105
122
resources_set_int("FullscreenHeight", height);
106
123
resources_set_int("FullscreenRefreshRate", refreshrate);
109
127
/* check if the fullscreen resource values are valid */
143
static void fullscreen_getmodes_dx9(void)
145
int adapter, numAdapter, mode, numAdapterModes;
146
D3DADAPTER_IDENTIFIER9 d3didentifier;
147
D3DDISPLAYMODE displayMode;
148
DirectDrawDeviceList *new_device;
149
DirectDrawDeviceList *search_device;
150
DirectDrawModeList *new_mode;
151
DirectDrawModeList *search_mode;
154
while (D3D_OK == IDirect3D9_GetAdapterIdentifier(d3d, numAdapter, 0, &d3didentifier)) {
155
new_device = lib_malloc(sizeof(DirectDrawDeviceList));
156
new_device->next = NULL;
157
new_device->desc = util_concat(d3didentifier.DeviceName, " - ", d3didentifier.Description, NULL);
158
if (devices == NULL) {
159
devices = new_device;
161
search_device = devices;
162
while (search_device->next != NULL) {
163
search_device = search_device->next;
165
search_device->next = new_device;
170
for (adapter = 0; adapter < numAdapter; adapter++) {
171
numAdapterModes = IDirect3D9_GetAdapterModeCount(d3d, adapter, D3DFMT_X8R8G8B8);
173
for (mode = 0; mode < numAdapterModes; mode++) {
174
if (S_OK == IDirect3D9_EnumAdapterModes(d3d, adapter, D3DFMT_X8R8G8B8, mode, &displayMode)) {
175
new_mode = lib_malloc(sizeof(DirectDrawModeList));
176
new_mode->next = NULL;
177
new_mode->devicenumber = adapter;
178
new_mode->width = displayMode.Width;
179
new_mode->height = displayMode.Height;
180
new_mode->bitdepth = 32;
181
new_mode->refreshrate = displayMode.RefreshRate;
187
while (search_mode->next != NULL) {
188
search_mode = search_mode->next;
190
search_mode->next = new_mode;
124
198
void fullscreen_getmodes(void)
126
201
if (video_dx9_enabled()) {
127
fullscreen_use_devices_dx9(&devices, &modes);
129
fullscreen_use_devices_ddraw(&devices, &modes);
202
if (devices == NULL) {
203
fullscreen_getmodes_dx9();
132
208
/* Use current display parameters if resources are not valid */
133
209
if (fullscrn_res_valid() < 0) {
138
214
void ui_fullscreen_init(void)
140
fullscreen_getmodes_ddraw();
141
217
if (video_dx9_enabled()) {
142
218
fullscreen_getmodes_dx9();
146
223
void ui_fullscreen_shutdown(void)
148
226
if (video_dx9_available()) {
149
fullscreen_use_devices_dx9(&devices, &modes);
150
fullscreen_devices_and_modes_free();
227
DirectDrawModeList *m1, *m2;
228
DirectDrawDeviceList *d1, *d2;
230
if (devices == NULL) {
231
fullscreen_getmodes_dx9();
152
fullscreen_use_devices_ddraw(&devices, &modes);
153
fullscreen_devices_and_modes_free();
156
254
void GetCurrentModeParameters(int *device, int *width, int *height, int *bitdepth, int *refreshrate)
181
279
fullscreen_set_res_from_current_display();
184
283
if (video_dx9_enabled()) {
185
SwitchToFullscreenModeDx9(hwnd);
187
SwitchToFullscreenModeDDraw(hwnd);
286
c = video_canvas_for_hwnd(hwnd);
289
statusbar_destroy(hwnd);
291
/* Remove Window stuff that prevents fullscreen display */
292
old_style = GetWindowLong(hwnd, GWL_STYLE);
293
GetWindowRect(hwnd, &old_rect);
294
SetWindowLong(hwnd, GWL_STYLE, old_style & ~WS_SYSMENU & ~WS_CAPTION);
295
old_menu = GetMenu(hwnd);
299
video_device_release_dx9(c);
300
ui_set_render_window(c, 1);
301
video_device_create_dx9(c, 1);
302
video_canvas_reset_dx9(c);
303
video_canvas_refresh_all(c);
191
308
void SwitchToWindowedMode(HWND hwnd)
195
312
if (!ui_setup_finished)
198
316
if (video_dx9_enabled()) {
199
SwitchToWindowedModeDx9(hwnd);
201
SwitchToWindowedModeDDraw(hwnd);
319
c = video_canvas_for_hwnd(hwnd);
321
video_device_release_dx9(c);
323
/* Create statusbar here to get correct dimensions for client window */
324
statusbar_create(hwnd);
325
ui_set_render_window(c, 0);
327
LockWindowUpdate(hwnd);
328
SetWindowLong(hwnd, GWL_STYLE, old_style);
330
SetMenu(hwnd,old_menu);
332
SetWindowPos(hwnd, HWND_NOTOPMOST, old_rect.left, old_rect.top, old_rect.right - old_rect.left, old_rect.bottom - old_rect.top, SWP_NOCOPYBITS);
334
LockWindowUpdate(NULL);
336
video_device_create_dx9(c, 0);
337
video_canvas_reset_dx9(c);
338
video_canvas_refresh_all(c);
340
c->refreshrate = old_refreshrate;
203
343
resources_get_int("AlwaysOnTop", &alwaysontop);
204
344
ui_set_alwaysontop(alwaysontop);
298
438
int fullscreen_height = 0;
299
439
int fullscreen_refreshrate = 0;
301
442
static void validate_mode(int *device, int *width, int *height, int *bitdepth, int *rate)
303
444
DirectDrawModeList *mode;
617
761
uilib_set_element_width(hwnd, IDC_FULLSCREEN_DEVICE, size + distance);
620
765
validate_mode(&fullscreen_device, &fullscreen_width, &fullscreen_height, &fullscreen_bitdepth, &fullscreen_refreshrate);
621
766
setting_hwnd = GetDlgItem(hwnd, IDC_FULLSCREEN_DEVICE);
622
767
SendMessage(setting_hwnd, CB_RESETCONTENT, 0, 0);
656
801
value = value->next;
658
803
SendMessage(setting_hwnd, CB_SETCURSEL, (WPARAM)GetIndexFromList(refresh_rates, fullscreen_refreshrate), 0);
659
805
EnableWindow(GetDlgItem(hwnd, IDC_TOGGLE_VIDEO_VBLANK_SYNC), !video_dx9_enabled());
660
806
CheckDlgButton(hwnd, IDC_TOGGLE_VIDEO_VBLANK_SYNC, vblank_sync ? BST_CHECKED : BST_UNCHECKED);
661
807
CheckDlgButton(hwnd, IDC_TOGGLE_VIDEO_DX_PRIMARY, dx_primary ? BST_CHECKED : BST_UNCHECKED);
662
808
EnableWindow(GetDlgItem(hwnd, IDC_TOGGLE_KEEP_ASPECT_RATIO), video_dx9_enabled());
663
CheckDlgButton(hwnd, IDC_TOGGLE_KEEP_ASPECT_RATIO, keep_aspect_ratio ? BST_CHECKED : BST_UNCHECKED);
664
CheckDlgButton(hwnd, IDC_TOGGLE_TRUE_ASPECT_RATIO, true_aspect_ratio ? BST_CHECKED : BST_UNCHECKED);
665
enable_aspect_ratio(hwnd);
667
fval = ((double)aspect_ratio) / 1000.0;
668
_stprintf(newval, TEXT("%.3f"), (float)fval);
669
SetDlgItemText(hwnd, IDC_ASPECT_RATIO, newval);
671
fval = canvas->geometry->pixel_aspect_ratio;
672
_stprintf(newval, TEXT("%.3f"), (float)fval);
673
SetDlgItemText(hwnd, IDC_GEOMETRY_ASPECT_RATIO, newval);
809
if (video_dx9_enabled()) {
810
CheckDlgButton(hwnd, IDC_TOGGLE_KEEP_ASPECT_RATIO, keep_aspect_ratio ? BST_CHECKED : BST_UNCHECKED);
811
CheckDlgButton(hwnd, IDC_TOGGLE_TRUE_ASPECT_RATIO, true_aspect_ratio ? BST_CHECKED : BST_UNCHECKED);
812
enable_aspect_ratio(hwnd);
814
fval = ((double)aspect_ratio) / 1000.0;
815
_stprintf(newval, TEXT("%.3f"), (float)fval);
816
SetDlgItemText(hwnd, IDC_ASPECT_RATIO, newval);
818
fval = canvas->geometry->pixel_aspect_ratio;
819
_stprintf(newval, TEXT("%.3f"), (float)fval);
820
SetDlgItemText(hwnd, IDC_GEOMETRY_ASPECT_RATIO, newval);
676
824
static void fullscreen_dialog_end(void)
682
830
resources_set_int("FullScreenRefreshRate", fullscreen_refreshrate);
683
831
resources_set_int("VBLANKSync", vblank_sync);
684
832
resources_set_int("DXPrimarySurfaceRendering", dx_primary);
685
resources_set_int("TrueAspectRatio", true_aspect_ratio);
686
resources_set_int("KeepAspectRatio", keep_aspect_ratio);
687
resources_set_int("AspectRatio", aspect_ratio);
688
fullscrn_invalidate_refreshrate();
833
if (video_dx9_enabled()) {
834
resources_set_int("TrueAspectRatio", true_aspect_ratio);
835
resources_set_int("KeepAspectRatio", keep_aspect_ratio);
836
resources_set_int("AspectRatio", aspect_ratio);
691
840
static void fullscreen_dialog_init(HWND hwnd)
697
846
resources_get_int("FullscreenRefreshRate", &fullscreen_refreshrate);
698
847
resources_get_int("VBLANKSync", &vblank_sync);
699
848
resources_get_int("DXPrimarySurfaceRendering", &dx_primary);
700
resources_get_int("KeepAspectRatio", &keep_aspect_ratio);
701
resources_get_int("TrueAspectRatio", &true_aspect_ratio);
702
resources_get_int("AspectRatio", &aspect_ratio);
849
if (video_dx9_enabled()) {
850
resources_get_int("KeepAspectRatio", &keep_aspect_ratio);
851
resources_get_int("TrueAspectRatio", &true_aspect_ratio);
852
resources_get_int("AspectRatio", &aspect_ratio);
703
854
init_fullscreen_dialog(hwnd);
706
857
INT_PTR CALLBACK dialog_fullscreen_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
718
871
if (((NMHDR FAR *)lparam)->code == (UINT)PSN_APPLY) {
719
GetDlgItemText(hwnd, IDC_ASPECT_RATIO, s, 100);
720
_stscanf(s, TEXT("%f"), &tf);
721
aspect_ratio = (int)(tf * 1000.0 + 0.5);
722
if (aspect_ratio < 500) {
723
ui_error(translate_text(IDS_VAL_F_FOR_S_OUT_RANGE_USE_F), tf, translate_text(IDS_TOGGLE_KEEP_ASPECT_RATIO), 0.5f);
726
if (aspect_ratio > 2000) {
727
ui_error(translate_text(IDS_VAL_F_FOR_S_OUT_RANGE_USE_F), tf, translate_text(IDS_TOGGLE_KEEP_ASPECT_RATIO), 2.0f);
872
if (video_dx9_enabled()) {
873
GetDlgItemText(hwnd, IDC_ASPECT_RATIO, s, 100);
874
_stscanf(s, TEXT("%f"), &tf);
875
aspect_ratio = (int)(tf * 1000.0 + 0.5);
876
if (aspect_ratio < 500) {
877
ui_error(translate_text(IDS_VAL_F_FOR_S_OUT_RANGE_USE_F), tf, translate_text(IDS_TOGGLE_KEEP_ASPECT_RATIO), 0.5f);
880
if (aspect_ratio > 2000) {
881
ui_error(translate_text(IDS_VAL_F_FOR_S_OUT_RANGE_USE_F), tf, translate_text(IDS_TOGGLE_KEEP_ASPECT_RATIO), 2.0f);
730
885
fullscreen_dialog_end();
731
886
SetWindowLongPtr(hwnd, DWLP_MSGRESULT, FALSE);
736
891
notifycode = HIWORD(wparam);
737
892
item = LOWORD(wparam);
738
894
if (notifycode == CBN_SELENDOK) {
739
895
if (item == IDC_FULLSCREEN_DEVICE) {
740
896
fullscreen_device = (int)SendMessage(GetDlgItem(hwnd, IDC_FULLSCREEN_DEVICE), CB_GETCURSEL, 0, 0);