trunk/src/osd/sdl/input.c
| r243368 | r243369 | |
| 1473 | 1473 | // sdlinput_get_focus_window |
| 1474 | 1474 | //============================================================ |
| 1475 | 1475 | |
| 1476 | | sdl_window_info *sdlinput_get_focus_window(running_machine &machine) |
| 1476 | sdl_window_info *sdlinput_get_focus_window() |
| 1477 | 1477 | { |
| 1478 | 1478 | if (focus_window) // only be set on SDL >= 1.3 |
| 1479 | 1479 | return focus_window; |
| r243368 | r243369 | |
| 1566 | 1566 | { |
| 1567 | 1567 | if (w->m_resize_width && w->m_resize_height && ((now - w->m_last_resize) > osd_ticks_per_second() / 10)) |
| 1568 | 1568 | { |
| 1569 | | w->window_resize(w->m_resize_width, w->m_resize_height); |
| 1569 | w->resize(w->m_resize_width, w->m_resize_height); |
| 1570 | 1570 | w->m_resize_width = 0; |
| 1571 | 1571 | w->m_resize_height = 0; |
| 1572 | 1572 | } |
| r243368 | r243369 | |
| 1576 | 1576 | |
| 1577 | 1577 | #endif |
| 1578 | 1578 | |
| 1579 | | void sdlinput_process_events_buf(running_machine &machine) |
| 1579 | void sdlinput_process_events_buf() |
| 1580 | 1580 | { |
| 1581 | 1581 | SDL_Event event; |
| 1582 | 1582 | |
| r243368 | r243369 | |
| 1944 | 1944 | machine.schedule_exit(); |
| 1945 | 1945 | break; |
| 1946 | 1946 | case SDL_VIDEORESIZE: |
| 1947 | | sdl_window_list->window_resize(event.resize.w, event.resize.h); |
| 1947 | sdl_window_list->resize(event.resize.w, event.resize.h); |
| 1948 | 1948 | break; |
| 1949 | 1949 | #else |
| 1950 | 1950 | case SDL_TEXTINPUT: |
| r243368 | r243369 | |
| 1977 | 1977 | app_has_mouse_focus = 0; |
| 1978 | 1978 | break; |
| 1979 | 1979 | case SDL_WINDOWEVENT_MOVED: |
| 1980 | | window->window_clear(); |
| 1980 | window->clear(); |
| 1981 | 1981 | focus_window = window; |
| 1982 | 1982 | break; |
| 1983 | 1983 | case SDL_WINDOWEVENT_RESIZED: |
| r243368 | r243369 | |
| 1998 | 1998 | { |
| 1999 | 1999 | //printf("event data1,data2 %d x %d %ld\n", event.window.data1, event.window.data2, sizeof(SDL_Event)); |
| 2000 | 2000 | if (event.window.data1 != window->width() || event.window.data2 != window->height()) |
| 2001 | | window->window_resize(event.window.data1, event.window.data2); |
| 2001 | window->resize(event.window.data1, event.window.data2); |
| 2002 | 2002 | } |
| 2003 | 2003 | } |
| 2004 | 2004 | focus_window = window; |
| r243368 | r243369 | |
| 2029 | 2029 | //============================================================ |
| 2030 | 2030 | |
| 2031 | 2031 | |
| 2032 | | void sdlinput_release_keys(running_machine &machine) |
| 2032 | void sdlinput_release_keys() |
| 2033 | 2033 | { |
| 2034 | 2034 | // FIXME: SDL >= 1.3 will nuke the window event buffer when |
| 2035 | 2035 | // a window is closed. This will leave keys in a pressed |
| r243368 | r243369 | |
| 2053 | 2053 | // sdlinput_should_hide_mouse |
| 2054 | 2054 | //============================================================ |
| 2055 | 2055 | |
| 2056 | | int sdlinput_should_hide_mouse(running_machine &machine) |
| 2056 | int sdlinput_should_hide_mouse() |
| 2057 | 2057 | { |
| 2058 | 2058 | // if we are paused, no |
| 2059 | 2059 | if (input_paused) |
trunk/src/osd/sdl/window.c
| r243368 | r243369 | |
| 100 | 100 | |
| 101 | 101 | struct worker_param { |
| 102 | 102 | worker_param() |
| 103 | | : m_window(NULL), m_list(NULL), m_machine(NULL), m_resize_new_width(0), m_resize_new_height(0) |
| 103 | : m_window(NULL), m_list(NULL), m_resize_new_width(0), m_resize_new_height(0) |
| 104 | 104 | { |
| 105 | 105 | } |
| 106 | | worker_param(running_machine &amachine, sdl_window_info *awindow) |
| 107 | | : m_window(awindow), m_list(NULL), m_machine(&amachine), m_resize_new_width(0), m_resize_new_height(0) |
| 106 | worker_param(sdl_window_info *awindow, render_primitive_list &alist) |
| 107 | : m_window(awindow), m_list(&alist), m_resize_new_width(0), m_resize_new_height(0) |
| 108 | 108 | { |
| 109 | 109 | } |
| 110 | | worker_param(running_machine &amachine, sdl_window_info *awindow, render_primitive_list &alist) |
| 111 | | : m_window(awindow), m_list(&alist), m_machine(&amachine), m_resize_new_width(0), m_resize_new_height(0) |
| 112 | | { |
| 113 | | } |
| 114 | 110 | worker_param(sdl_window_info *awindow, int anew_width, int anew_height) |
| 115 | | : m_window(awindow), m_list(NULL), m_machine(NULL), m_resize_new_width(anew_width), m_resize_new_height(anew_height) |
| 111 | : m_window(awindow), m_list(NULL), m_resize_new_width(anew_width), m_resize_new_height(anew_height) |
| 116 | 112 | { |
| 117 | 113 | } |
| 118 | 114 | worker_param(sdl_window_info *awindow) |
| 119 | | : m_window(awindow), m_list(NULL), m_machine(NULL), m_resize_new_width(0), m_resize_new_height(0) |
| 115 | : m_window(awindow), m_list(NULL), m_resize_new_width(0), m_resize_new_height(0) |
| 120 | 116 | { |
| 121 | 117 | } |
| 122 | | running_machine &machine() const { assert(m_machine != NULL); return *m_machine; } |
| 123 | 118 | sdl_window_info *window() const { assert(m_window != NULL); return m_window; } |
| 124 | 119 | render_primitive_list *list() const { return m_list; } |
| 125 | 120 | int new_width() const { return m_resize_new_width; } |
| r243368 | r243369 | |
| 129 | 124 | private: |
| 130 | 125 | sdl_window_info *m_window; |
| 131 | 126 | render_primitive_list *m_list; |
| 132 | | running_machine *m_machine; |
| 133 | 127 | int m_resize_new_width; |
| 134 | 128 | int m_resize_new_height; |
| 135 | 129 | }; |
| r243368 | r243369 | |
| 139 | 133 | // PROTOTYPES |
| 140 | 134 | //============================================================ |
| 141 | 135 | |
| 142 | | static void sdlwindow_update_cursor_state(running_machine &machine, sdl_window_info *window); |
| 143 | 136 | static void sdlwindow_sync(void); |
| 144 | 137 | |
| 145 | 138 | //============================================================ |
| r243368 | r243369 | |
| 353 | 346 | { |
| 354 | 347 | sdl_window_info *temp = sdl_window_list; |
| 355 | 348 | sdl_window_list = temp->m_next; |
| 356 | | temp->video_window_destroy(machine()); |
| 349 | temp->destroy(); |
| 357 | 350 | // free the window itself |
| 358 | 351 | global_free(temp); |
| 359 | 352 | } |
| r243368 | r243369 | |
| 462 | 455 | newwidth = window_width; |
| 463 | 456 | |
| 464 | 457 | if ((m_blitwidth != newwidth) || (m_blitheight != newheight)) |
| 465 | | window_clear(); |
| 458 | clear(); |
| 466 | 459 | |
| 467 | 460 | m_blitwidth = newwidth; |
| 468 | 461 | m_blitheight = newheight; |
| r243368 | r243369 | |
| 503 | 496 | |
| 504 | 497 | window->blit_surface_size(window->m_width, window->m_height); |
| 505 | 498 | |
| 506 | | window->window_clear(); |
| 499 | window->clear(); |
| 507 | 500 | |
| 508 | 501 | osd_free(wp); |
| 509 | 502 | return NULL; |
| 510 | 503 | } |
| 511 | 504 | |
| 512 | | void sdl_window_info::window_resize(INT32 width, INT32 height) |
| 505 | void sdl_window_info::resize(INT32 width, INT32 height) |
| 513 | 506 | { |
| 514 | 507 | ASSERT_MAIN_THREAD(); |
| 515 | 508 | |
| r243368 | r243369 | |
| 537 | 530 | return NULL; |
| 538 | 531 | } |
| 539 | 532 | |
| 540 | | void sdl_window_info::window_clear() |
| 533 | void sdl_window_info::clear() |
| 541 | 534 | { |
| 542 | 535 | worker_param wp; |
| 543 | 536 | |
| r243368 | r243369 | |
| 592 | 585 | #endif |
| 593 | 586 | |
| 594 | 587 | |
| 595 | | sdlinput_release_keys(wp->machine()); |
| 588 | sdlinput_release_keys(); |
| 596 | 589 | |
| 597 | 590 | // toggle the window mode |
| 598 | 591 | window->set_fullscreen(!window->fullscreen()); |
| r243368 | r243369 | |
| 602 | 595 | return NULL; |
| 603 | 596 | } |
| 604 | 597 | |
| 605 | | void sdl_window_info::toggle_full_screen(running_machine &machine) |
| 598 | void sdl_window_info::toggle_full_screen() |
| 606 | 599 | { |
| 607 | 600 | ASSERT_MAIN_THREAD(); |
| 608 | 601 | |
| 609 | | execute_async_wait(&sdlwindow_toggle_full_screen_wt, worker_param(machine, this)); |
| 602 | execute_async_wait(&sdlwindow_toggle_full_screen_wt, worker_param(this)); |
| 610 | 603 | } |
| 611 | 604 | |
| 612 | 605 | OSDWORK_CALLBACK( sdl_window_info::destroy_all_textures_wt ) |
| r243368 | r243369 | |
| 621 | 614 | return NULL; |
| 622 | 615 | } |
| 623 | 616 | |
| 624 | | void sdl_window_info::modify_prescale(running_machine &machine, int dir) |
| 617 | void sdl_window_info::modify_prescale(int dir) |
| 625 | 618 | { |
| 626 | | worker_param wp = worker_param(machine, this); |
| 619 | worker_param wp = worker_param(this); |
| 627 | 620 | int new_prescale = prescale(); |
| 628 | 621 | |
| 629 | 622 | if (dir > 0 && prescale() < 3) |
| r243368 | r243369 | |
| 647 | 640 | execute_async_wait(destroy_all_textures_wt, wp); |
| 648 | 641 | m_prescale = new_prescale; |
| 649 | 642 | } |
| 650 | | machine.ui().popup_time(1, "Prescale %d", prescale()); |
| 643 | machine().ui().popup_time(1, "Prescale %d", prescale()); |
| 651 | 644 | } |
| 652 | 645 | } |
| 653 | 646 | |
| r243368 | r243369 | |
| 656 | 649 | // (main or window thread) |
| 657 | 650 | //============================================================ |
| 658 | 651 | |
| 659 | | static void sdlwindow_update_cursor_state(running_machine &machine, sdl_window_info *window) |
| 652 | void sdl_window_info::update_cursor_state() |
| 660 | 653 | { |
| 661 | 654 | #if (USE_XINPUT) |
| 662 | 655 | // Hack for wii-lightguns: |
| r243368 | r243369 | |
| 671 | 664 | #if (SDLMAME_SDL2) |
| 672 | 665 | // do not do mouse capture if the debugger's enabled to avoid |
| 673 | 666 | // the possibility of losing control |
| 674 | | if (!(machine.debug_flags & DEBUG_FLAG_OSD_ENABLED)) |
| 667 | if (!(machine().debug_flags & DEBUG_FLAG_OSD_ENABLED)) |
| 675 | 668 | { |
| 676 | 669 | //FIXME: SDL1.3: really broken: the whole SDL code |
| 677 | 670 | // will only work correct with relative mouse movements ... |
| 678 | | if (!window->fullscreen() && !sdlinput_should_hide_mouse(machine)) |
| 671 | if (!fullscreen() && !sdlinput_should_hide_mouse()) |
| 679 | 672 | { |
| 680 | 673 | SDL_ShowCursor(SDL_ENABLE); |
| 681 | | if (SDL_GetWindowGrab(window->sdl_window() )) |
| 682 | | SDL_SetWindowGrab(window->sdl_window(), SDL_FALSE); |
| 674 | if (SDL_GetWindowGrab(sdl_window() )) |
| 675 | SDL_SetWindowGrab(sdl_window(), SDL_FALSE); |
| 683 | 676 | SDL_SetRelativeMouseMode(SDL_FALSE); |
| 684 | 677 | } |
| 685 | 678 | else |
| 686 | 679 | { |
| 687 | 680 | SDL_ShowCursor(SDL_DISABLE); |
| 688 | | if (!SDL_GetWindowGrab(window->sdl_window())) |
| 689 | | SDL_SetWindowGrab(window->sdl_window(), SDL_TRUE); |
| 681 | if (!SDL_GetWindowGrab(sdl_window())) |
| 682 | SDL_SetWindowGrab(sdl_window(), SDL_TRUE); |
| 690 | 683 | SDL_SetRelativeMouseMode(SDL_TRUE); |
| 691 | 684 | } |
| 692 | 685 | SDL_SetCursor(NULL); // Force an update in case the underlying driver has changed visibility |
| r243368 | r243369 | |
| 695 | 688 | #else |
| 696 | 689 | // do not do mouse capture if the debugger's enabled to avoid |
| 697 | 690 | // the possibility of losing control |
| 698 | | if (!(machine.debug_flags & DEBUG_FLAG_OSD_ENABLED)) |
| 691 | if (!(machine().debug_flags & DEBUG_FLAG_OSD_ENABLED)) |
| 699 | 692 | { |
| 700 | | if ( window->fullscreen() || sdlinput_should_hide_mouse(machine) ) |
| 693 | if ( fullscreen() || sdlinput_should_hide_mouse() ) |
| 701 | 694 | { |
| 702 | 695 | SDL_ShowCursor(SDL_DISABLE); |
| 703 | 696 | if (!SDL_WM_GrabInput(SDL_GRAB_QUERY)) |
| r243368 | r243369 | |
| 721 | 714 | static OSDWORK_CALLBACK( sdlwindow_update_cursor_state_wt ) |
| 722 | 715 | { |
| 723 | 716 | worker_param * wp = (worker_param *) param; |
| 724 | | //sdl_window_info * window = wp->window; |
| 717 | sdl_window_info * window = wp->window(); |
| 725 | 718 | |
| 726 | | sdlwindow_update_cursor_state(wp->machine(), wp->window()); |
| 719 | window->update_cursor_state(); |
| 727 | 720 | |
| 728 | 721 | osd_free(wp); |
| 729 | 722 | return NULL; |
| r243368 | r243369 | |
| 794 | 787 | return 0; |
| 795 | 788 | |
| 796 | 789 | error: |
| 797 | | video_window_destroy(m_machine); |
| 798 | | // free the window itself |
| 790 | destroy(); |
| 799 | 791 | return 1; |
| 800 | 792 | } |
| 801 | 793 | |
| r243368 | r243369 | |
| 832 | 824 | #endif |
| 833 | 825 | |
| 834 | 826 | // release all keys ... |
| 835 | | sdlinput_release_keys(wp->machine()); |
| 827 | sdlinput_release_keys(); |
| 836 | 828 | |
| 837 | 829 | |
| 838 | 830 | osd_free(wp); |
| 839 | 831 | return NULL; |
| 840 | 832 | } |
| 841 | 833 | |
| 842 | | void sdl_window_info::video_window_destroy(running_machine &machine) |
| 834 | void sdl_window_info::destroy() |
| 843 | 835 | { |
| 844 | 836 | sdl_window_info **prevptr; |
| 845 | 837 | |
| r243368 | r243369 | |
| 860 | 852 | } |
| 861 | 853 | |
| 862 | 854 | // free the textures etc |
| 863 | | execute_async_wait(&sdlwindow_video_window_destroy_wt, worker_param(machine, this)); |
| 855 | execute_async_wait(&sdlwindow_video_window_destroy_wt, worker_param(this)); |
| 864 | 856 | |
| 865 | 857 | // free the render target, after the textures! |
| 866 | 858 | this->machine().render().target_free(m_target); |
| r243368 | r243369 | |
| 1023 | 1015 | // (main thread) |
| 1024 | 1016 | //============================================================ |
| 1025 | 1017 | |
| 1026 | | void sdl_window_info::video_window_update(running_machine &machine) |
| 1018 | void sdl_window_info::update() |
| 1027 | 1019 | { |
| 1028 | 1020 | osd_ticks_t event_wait_ticks; |
| 1029 | 1021 | ASSERT_MAIN_THREAD(); |
| r243368 | r243369 | |
| 1031 | 1023 | // adjust the cursor state |
| 1032 | 1024 | //sdlwindow_update_cursor_state(machine, window); |
| 1033 | 1025 | |
| 1034 | | execute_async(&sdlwindow_update_cursor_state_wt, worker_param(machine, this)); |
| 1026 | execute_async(&sdlwindow_update_cursor_state_wt, worker_param(this)); |
| 1035 | 1027 | |
| 1036 | 1028 | // if we're visible and running and not in the middle of a resize, draw |
| 1037 | 1029 | if (m_target != NULL) |
| r243368 | r243369 | |
| 1054 | 1046 | else if (video_config.switchres) |
| 1055 | 1047 | { |
| 1056 | 1048 | this->pick_best_mode(&tempwidth, &tempheight); |
| 1057 | | window_resize(tempwidth, tempheight); |
| 1049 | resize(tempwidth, tempheight); |
| 1058 | 1050 | } |
| 1059 | 1051 | } |
| 1060 | 1052 | |
| r243368 | r243369 | |
| 1082 | 1074 | |
| 1083 | 1075 | // and redraw now |
| 1084 | 1076 | |
| 1085 | | execute_async(&draw_video_contents_wt, worker_param(machine, this, primlist)); |
| 1077 | execute_async(&draw_video_contents_wt, worker_param(this, primlist)); |
| 1086 | 1078 | } |
| 1087 | 1079 | } |
| 1088 | 1080 | } |
| r243368 | r243369 | |
| 1355 | 1347 | ASSERT_REDRAW_THREAD(); |
| 1356 | 1348 | |
| 1357 | 1349 | // Some configurations require events to be polled in the worker thread |
| 1358 | | sdlinput_process_events_buf(wp->machine()); |
| 1350 | sdlinput_process_events_buf(); |
| 1359 | 1351 | |
| 1360 | 1352 | window->m_primlist = wp->list(); |
| 1361 | 1353 | |