~ubuntu-branches/debian/sid/mame/sid

« back to all changes in this revision

Viewing changes to src/osd/windows/window.c

  • Committer: Bazaar Package Importer
  • Author(s): Jordi Mallach, Emmanuel Kasper, Félix Arreola Rodríguez, Jordi Mallach
  • Date: 2011-05-11 21:06:50 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20110511210650-jizvh8a6x117y9hr
Tags: 0.142-1
[ Emmanuel Kasper ]
* New upstream release
* Set NOWERROR=1 to allow compiling with gcc-4.6
* Remove fix_powerpc_build.patch, as upstream has taken it in this release
* Add gnome-video-arcade front end as a suggested package

[ Félix Arreola Rodríguez ]
* Add kfreebsd-build.patch to quilt series, to fix build on kfreebsd

[ Jordi Mallach ]
* Remove unneeded and bogus addition of --with-quilt to the dh invocation.
* Add Cesare Falco (long time Ubuntu maintainer) to Uploaders, and wrap
  them into multiple lines.

Show diffs side-by-side

added added

removed removed

Lines of Context:
69
69
#include "config.h"
70
70
#include "winutf8.h"
71
71
 
72
 
#ifdef MESS
73
 
#include "menu.h"
74
 
#endif /* MESS */
75
 
 
76
 
extern int drawnone_init(win_draw_callbacks *callbacks);
77
 
extern int drawgdi_init(win_draw_callbacks *callbacks);
78
 
extern int drawdd_init(win_draw_callbacks *callbacks);
79
 
extern int drawd3d_init(win_draw_callbacks *callbacks);
 
72
extern int drawnone_init(running_machine &machine, win_draw_callbacks *callbacks);
 
73
extern int drawgdi_init(running_machine &machine, win_draw_callbacks *callbacks);
 
74
extern int drawdd_init(running_machine &machine, win_draw_callbacks *callbacks);
 
75
extern int drawd3d_init(running_machine &machine, win_draw_callbacks *callbacks);
80
76
 
81
77
 
82
78
//============================================================
223
219
//  (main thread)
224
220
//============================================================
225
221
 
226
 
void winwindow_init(running_machine *machine)
 
222
void winwindow_init(running_machine &machine)
227
223
{
228
224
        size_t temp;
229
225
 
230
226
        // determine if we are using multithreading or not
231
 
        multithreading_enabled = options_get_bool(machine->options(), WINOPTION_MULTITHREADING);
 
227
        multithreading_enabled = downcast<windows_options &>(machine.options()).multithreading();
232
228
 
233
229
        // get the main thread ID before anything else
234
230
        main_threadid = GetCurrentThreadId();
235
231
 
236
232
        // ensure we get called on the way out
237
 
        machine->add_notifier(MACHINE_NOTIFY_EXIT, winwindow_exit);
 
233
        machine.add_notifier(MACHINE_NOTIFY_EXIT, winwindow_exit);
238
234
 
239
235
        // set up window class and register it
240
236
        create_window_class();
272
268
        // initialize the drawers
273
269
        if (video_config.mode == VIDEO_MODE_D3D)
274
270
        {
275
 
                if (drawd3d_init(&draw))
 
271
                if (drawd3d_init(machine, &draw))
276
272
                        video_config.mode = VIDEO_MODE_GDI;
277
273
        }
278
274
        if (video_config.mode == VIDEO_MODE_DDRAW)
279
275
        {
280
 
                if (drawdd_init(&draw))
 
276
                if (drawdd_init(machine, &draw))
281
277
                        video_config.mode = VIDEO_MODE_GDI;
282
278
        }
283
279
        if (video_config.mode == VIDEO_MODE_GDI)
284
 
                drawgdi_init(&draw);
 
280
                drawgdi_init(machine, &draw);
285
281
        if (video_config.mode == VIDEO_MODE_NONE)
286
 
                drawnone_init(&draw);
 
282
                drawnone_init(machine, &draw);
287
283
 
288
284
        // set up the window list
289
285
        last_window_ptr = &win_window_list;
343
339
//  (main thread)
344
340
//============================================================
345
341
 
346
 
void winwindow_process_events_periodic(running_machine *machine)
 
342
void winwindow_process_events_periodic(running_machine &machine)
347
343
{
348
344
        DWORD currticks = GetTickCount();
349
345
 
379
375
//  (main thread)
380
376
//============================================================
381
377
 
382
 
void winwindow_process_events(running_machine *machine, int ingame)
 
378
void winwindow_process_events(running_machine &machine, int ingame)
383
379
{
384
380
        MSG message;
385
381
 
386
382
        assert(GetCurrentThreadId() == main_threadid);
387
383
 
388
384
        // if we're running, disable some parts of the debugger
389
 
        if (ingame && (machine->debug_flags & DEBUG_FLAG_OSD_ENABLED) != 0)
 
385
        if (ingame && (machine.debug_flags & DEBUG_FLAG_OSD_ENABLED) != 0)
390
386
                debugwin_update_during_game(machine);
391
387
 
392
388
        // remember the last time we did this
466
462
//  (main thread)
467
463
//============================================================
468
464
 
469
 
void winwindow_dispatch_message(running_machine *machine, MSG *message)
 
465
void winwindow_dispatch_message(running_machine &machine, MSG *message)
470
466
{
471
467
        assert(GetCurrentThreadId() == main_threadid);
472
468
 
475
471
        {
476
472
                // special case for quit
477
473
                case WM_QUIT:
478
 
                        machine->schedule_exit();
 
474
                        machine.schedule_exit();
479
475
                        break;
480
476
 
481
477
                // temporary pause from the window thread
515
511
 
516
512
        // if we are in debug mode, never go full screen
517
513
        for (window = win_window_list; window != NULL; window = window->next)
518
 
                if (window->machine->debug_flags & DEBUG_FLAG_OSD_ENABLED)
 
514
                if (window->machine().debug_flags & DEBUG_FLAG_OSD_ENABLED)
519
515
                        return;
520
516
 
521
517
        // toggle the window mode
553
549
//  (main thread)
554
550
//============================================================
555
551
 
556
 
void winwindow_update_cursor_state(running_machine *machine)
 
552
void winwindow_update_cursor_state(running_machine &machine)
557
553
{
558
554
        static POINT saved_cursor_pos = { -1, -1 };
559
555
 
565
561
        //   2. we also hide the cursor in full screen mode and when the window doesn't have a menu
566
562
        //   3. we also hide the cursor in windowed mode if we're not paused and
567
563
        //      the input system requests it
568
 
        if (winwindow_has_focus() && ((!video_config.windowed && !win_has_menu(win_window_list)) || (!machine->paused() && wininput_should_hide_mouse())))
 
564
        if (winwindow_has_focus() && ((!video_config.windowed && !win_has_menu(win_window_list)) || (!machine.paused() && wininput_should_hide_mouse())))
569
565
        {
570
566
                win_window_info *window = win_window_list;
571
567
                RECT bounds;
606
602
//  (main thread)
607
603
//============================================================
608
604
 
609
 
void winwindow_video_window_create(running_machine *machine, int index, win_monitor_info *monitor, const win_window_config *config)
 
605
void winwindow_video_window_create(running_machine &machine, int index, win_monitor_info *monitor, const win_window_config *config)
610
606
{
611
607
        win_window_info *window, *win;
612
 
        char option[20];
613
608
 
614
609
        assert(GetCurrentThreadId() == main_threadid);
615
610
 
620
615
        window->refresh = config->refresh;
621
616
        window->monitor = monitor;
622
617
        window->fullscreen = !video_config.windowed;
623
 
        window->machine = machine;
 
618
        window->m_machine = &machine;
624
619
 
625
620
        // see if we are safe for fullscreen
626
621
        window->fullscreen_safe = TRUE;
636
631
        window->render_lock = osd_lock_alloc();
637
632
 
638
633
        // load the layout
639
 
        window->target = machine->render().target_alloc();
 
634
        window->target = machine.render().target_alloc();
640
635
 
641
636
        // set the specific view
642
 
        sprintf(option, "view%d", index);
643
 
        set_starting_view(index, window, options_get_string(machine->options(), option));
 
637
        windows_options &options = downcast<windows_options &>(machine.options());
 
638
        set_starting_view(index, window, options.view(index));
644
639
 
645
640
        // remember the current values in case they change
646
641
        window->targetview = window->target->view();
649
644
 
650
645
        // make the window title
651
646
        if (video_config.numscreens == 1)
652
 
                sprintf(window->title, APPNAME ": %s [%s]", machine->gamedrv->description, machine->gamedrv->name);
 
647
                sprintf(window->title, APPNAME ": %s [%s]", machine.system().description, machine.system().name);
653
648
        else
654
 
                sprintf(window->title, APPNAME ": %s [%s] - Screen %d", machine->gamedrv->description, machine->gamedrv->name, index);
 
649
                sprintf(window->title, APPNAME ": %s [%s] - Screen %d", machine.system().description, machine.system().name, index);
655
650
 
656
651
        // set the initial maximized state
657
 
        window->startmaximized = options_get_bool(machine->options(), WINOPTION_MAXIMIZE);
 
652
        window->startmaximized = options.maximize();
658
653
 
659
654
        // finish the window creation on the window thread
660
655
        if (multithreading_enabled)
700
695
                SendMessage(window->hwnd, WM_USER_SELF_TERMINATE, 0, 0);
701
696
 
702
697
        // free the render target
703
 
        window->machine->render().target_free(window->target);
 
698
        window->machine().render().target_free(window->target);
704
699
 
705
700
        // free the lock
706
701
        osd_lock_free(window->render_lock);
753
748
                mtlog_add("winwindow_video_window_update: try lock");
754
749
 
755
750
                // only block if we're throttled
756
 
                if (window->machine->video().throttled() || timeGetTime() - last_update_time > 250)
 
751
                if (window->machine().video().throttled() || timeGetTime() - last_update_time > 250)
757
752
                        osd_lock_acquire(window->render_lock);
758
753
                else
759
754
                        got_lock = osd_lock_try(window->render_lock);
834
829
                // initialize the description of the window class
835
830
                wc.lpszClassName        = TEXT("MAME");
836
831
                wc.hInstance            = GetModuleHandle(NULL);
837
 
#ifdef MESS
838
 
                wc.lpfnWndProc          = win_mess_window_proc;
839
 
#else
840
 
                wc.lpfnWndProc          = winwindow_video_window_proc;
841
 
#endif
 
832
                wc.lpfnWndProc          = winwindow_video_window_proc_ui;
842
833
                wc.hCursor                      = LoadCursor(NULL, IDC_ARROW);
843
834
                wc.hIcon                        = LoadIcon(NULL, IDI_APPLICATION);
844
835
 
858
849
 
859
850
static void set_starting_view(int index, win_window_info *window, const char *view)
860
851
{
861
 
        const char *defview = options_get_string(mame_options(), WINOPTION_VIEW);
 
852
        const char *defview = downcast<windows_options &>(window->machine().options()).view();
862
853
        int viewindex;
863
854
 
864
855
        assert(GetCurrentThreadId() == main_threadid);
881
872
//  (main thread)
882
873
//============================================================
883
874
 
884
 
void winwindow_ui_pause_from_main_thread(running_machine *machine, int pause)
 
875
void winwindow_ui_pause_from_main_thread(running_machine &machine, int pause)
885
876
{
886
877
        int old_temp_pause = ui_temp_pause;
887
878
 
894
885
                if (ui_temp_pause++ == 0)
895
886
                {
896
887
                        // only call mame_pause if we weren't already paused due to some external reason
897
 
                        ui_temp_was_paused = machine->paused();
 
888
                        ui_temp_was_paused = machine.paused();
898
889
                        if (!ui_temp_was_paused)
899
 
                                machine->pause();
 
890
                                machine.pause();
900
891
 
901
892
                        SetEvent(ui_pause_event);
902
893
                }
910
901
                {
911
902
                        // but only do it if we were the ones who initiated it
912
903
                        if (!ui_temp_was_paused)
913
 
                                machine->resume();
 
904
                                machine.resume();
914
905
 
915
906
                        ResetEvent(ui_pause_event);
916
907
                }
927
918
//  (window thread)
928
919
//============================================================
929
920
 
930
 
void winwindow_ui_pause_from_window_thread(running_machine *machine, int pause)
 
921
void winwindow_ui_pause_from_window_thread(running_machine &machine, int pause)
931
922
{
932
923
        assert(GetCurrentThreadId() == window_threadid);
933
924
 
976
967
//  winwindow_ui_is_paused
977
968
//============================================================
978
969
 
979
 
int winwindow_ui_is_paused(running_machine *machine)
 
970
int winwindow_ui_is_paused(running_machine &machine)
980
971
{
981
 
        return machine->paused() && ui_temp_was_paused;
 
972
        return machine.paused() && ui_temp_was_paused;
982
973
}
983
974
 
984
975
 
1129
1120
        monitorbounds = window->monitor->info.rcMonitor;
1130
1121
 
1131
1122
        // create the window menu if needed
1132
 
#if HAS_WINDOW_MENU
1133
 
        if (win_create_menu(window->machine, &menu))
1134
 
                return 1;
1135
 
#endif
 
1123
        if (downcast<windows_options &>(window->machine().options()).menu())
 
1124
        {
 
1125
                if (win_create_menu(window->machine(), &menu))
 
1126
                        return 1;
 
1127
        }
1136
1128
 
1137
1129
        // create the window, but don't show it yet
1138
1130
        window->hwnd = win_create_window_ex_utf8(
1224
1216
 
1225
1217
                // non-client paint: punt if full screen
1226
1218
                case WM_NCPAINT:
1227
 
                        if (!window->fullscreen || HAS_WINDOW_MENU)
 
1219
                        if (!window->fullscreen || win_has_menu(window))
1228
1220
                                return DefWindowProc(wnd, message, wparam, lparam);
1229
1221
                        break;
1230
1222
 
1240
1232
 
1241
1233
                // input events
1242
1234
                case WM_MOUSEMOVE:
1243
 
                        ui_input_push_mouse_move_event(window->machine, window->target, GET_X_LPARAM(lparam), GET_Y_LPARAM(lparam));
 
1235
                        ui_input_push_mouse_move_event(window->machine(), window->target, GET_X_LPARAM(lparam), GET_Y_LPARAM(lparam));
1244
1236
                        break;
1245
1237
 
1246
1238
                case WM_MOUSELEAVE:
1247
 
                        ui_input_push_mouse_leave_event(window->machine, window->target);
 
1239
                        ui_input_push_mouse_leave_event(window->machine(), window->target);
1248
1240
                        break;
1249
1241
 
1250
1242
                case WM_LBUTTONDOWN:
1251
1243
                {
1252
1244
                        DWORD ticks = GetTickCount();
1253
 
                        ui_input_push_mouse_down_event(window->machine, window->target, GET_X_LPARAM(lparam), GET_Y_LPARAM(lparam));
 
1245
                        ui_input_push_mouse_down_event(window->machine(), window->target, GET_X_LPARAM(lparam), GET_Y_LPARAM(lparam));
1254
1246
 
1255
1247
                        // check for a double-click
1256
1248
                        if (ticks - window->lastclicktime < GetDoubleClickTime() &&
1258
1250
                                GET_Y_LPARAM(lparam) >= window->lastclicky - 4 && GET_Y_LPARAM(lparam) <= window->lastclicky + 4)
1259
1251
                        {
1260
1252
                                window->lastclicktime = 0;
1261
 
                                ui_input_push_mouse_double_click_event(window->machine, window->target, GET_X_LPARAM(lparam), GET_Y_LPARAM(lparam));
 
1253
                                ui_input_push_mouse_double_click_event(window->machine(), window->target, GET_X_LPARAM(lparam), GET_Y_LPARAM(lparam));
1262
1254
                        }
1263
1255
                        else
1264
1256
                        {
1270
1262
                }
1271
1263
 
1272
1264
                case WM_LBUTTONUP:
1273
 
                        ui_input_push_mouse_up_event(window->machine, window->target, GET_X_LPARAM(lparam), GET_Y_LPARAM(lparam));
 
1265
                        ui_input_push_mouse_up_event(window->machine(), window->target, GET_X_LPARAM(lparam), GET_Y_LPARAM(lparam));
1274
1266
                        break;
1275
1267
 
1276
1268
                case WM_CHAR:
1277
 
                        ui_input_push_char_event(window->machine, window->target, (unicode_char) wparam);
 
1269
                        ui_input_push_char_event(window->machine(), window->target, (unicode_char) wparam);
1278
1270
                        break;
1279
1271
 
1280
1272
                // pause the system when we start a menu or resize
1281
1273
                case WM_ENTERSIZEMOVE:
1282
1274
                        window->resize_state = RESIZE_STATE_RESIZING;
1283
1275
                case WM_ENTERMENULOOP:
1284
 
                        winwindow_ui_pause_from_window_thread(window->machine, TRUE);
 
1276
                        winwindow_ui_pause_from_window_thread(window->machine(), TRUE);
1285
1277
                        break;
1286
1278
 
1287
1279
                // unpause the system when we stop a menu or resize and force a redraw
1288
1280
                case WM_EXITSIZEMOVE:
1289
1281
                        window->resize_state = RESIZE_STATE_PENDING;
1290
1282
                case WM_EXITMENULOOP:
1291
 
                        winwindow_ui_pause_from_window_thread(window->machine, FALSE);
 
1283
                        winwindow_ui_pause_from_window_thread(window->machine(), FALSE);
1292
1284
                        InvalidateRect(wnd, NULL, FALSE);
1293
1285
                        break;
1294
1286
 
1344
1336
                        if (multithreading_enabled)
1345
1337
                                PostThreadMessage(main_threadid, WM_QUIT, 0, 0);
1346
1338
                        else
1347
 
                                window->machine->schedule_exit();
 
1339
                                window->machine().schedule_exit();
1348
1340
                        break;
1349
1341
 
1350
1342
                // destroy: clean up all attached rendering bits and NULL out our hwnd