Revision 8db9bae9 ui/sdl.c
b/ui/sdl.c | ||
---|---|---|
35 | 35 |
#include "sdl_zoom.h" |
36 | 36 |
|
37 | 37 |
static DisplayChangeListener *dcl; |
38 |
static DisplaySurface *surface; |
|
38 | 39 |
static SDL_Surface *real_screen; |
39 | 40 |
static SDL_Surface *guest_screen = NULL; |
40 | 41 |
static int gui_grab; /* if true, all keyboard/mouse events are grabbed */ |
... | ... | |
60 | 61 |
static Notifier mouse_mode_notifier; |
61 | 62 |
|
62 | 63 |
static void sdl_update(DisplayChangeListener *dcl, |
63 |
DisplayState *ds,
|
|
64 |
DisplayState *dontuse,
|
|
64 | 65 |
int x, int y, int w, int h) |
65 | 66 |
{ |
66 | 67 |
// printf("updating x=%d y=%d w=%d h=%d\n", x, y, w, h); |
... | ... | |
83 | 84 |
SDL_UpdateRect(real_screen, rec.x, rec.y, rec.w, rec.h); |
84 | 85 |
} |
85 | 86 |
|
86 |
static void sdl_setdata(DisplayChangeListener *dcl, |
|
87 |
DisplayState *ds) |
|
88 |
{ |
|
89 |
if (guest_screen != NULL) SDL_FreeSurface(guest_screen); |
|
90 |
|
|
91 |
guest_screen = SDL_CreateRGBSurfaceFrom(ds_get_data(ds), ds_get_width(ds), ds_get_height(ds), |
|
92 |
ds_get_bits_per_pixel(ds), ds_get_linesize(ds), |
|
93 |
ds->surface->pf.rmask, ds->surface->pf.gmask, |
|
94 |
ds->surface->pf.bmask, ds->surface->pf.amask); |
|
95 |
} |
|
96 |
|
|
97 | 87 |
static void do_sdl_resize(int width, int height, int bpp) |
98 | 88 |
{ |
99 | 89 |
int flags; |
... | ... | |
118 | 108 |
} |
119 | 109 |
|
120 | 110 |
static void sdl_switch(DisplayChangeListener *dcl, |
121 |
DisplayState *ds,
|
|
122 |
DisplaySurface *surface) |
|
111 |
DisplayState *dontuse,
|
|
112 |
DisplaySurface *new_surface)
|
|
123 | 113 |
{ |
114 |
|
|
115 |
/* temporary hack: allows to call sdl_switch to handle scaling changes */ |
|
116 |
if (new_surface) { |
|
117 |
surface = new_surface; |
|
118 |
} |
|
119 |
|
|
124 | 120 |
if (!scaling_active) { |
125 |
do_sdl_resize(ds_get_width(ds), ds_get_height(ds), 0); |
|
126 |
} else if (real_screen->format->BitsPerPixel != ds_get_bits_per_pixel(ds)) { |
|
121 |
do_sdl_resize(surface_width(surface), surface_height(surface), 0); |
|
122 |
} else if (real_screen->format->BitsPerPixel != |
|
123 |
surface_bits_per_pixel(surface)) { |
|
127 | 124 |
do_sdl_resize(real_screen->w, real_screen->h, |
128 |
ds_get_bits_per_pixel(ds));
|
|
125 |
surface_bits_per_pixel(surface));
|
|
129 | 126 |
} |
130 |
sdl_setdata(dcl, ds); |
|
127 |
|
|
128 |
if (guest_screen != NULL) { |
|
129 |
SDL_FreeSurface(guest_screen); |
|
130 |
} |
|
131 |
guest_screen = SDL_CreateRGBSurfaceFrom |
|
132 |
(surface_data(surface), |
|
133 |
surface_width(surface), surface_height(surface), |
|
134 |
surface_bits_per_pixel(surface), surface_stride(surface), |
|
135 |
surface->pf.rmask, surface->pf.gmask, |
|
136 |
surface->pf.bmask, surface->pf.amask); |
|
131 | 137 |
} |
132 | 138 |
|
133 | 139 |
/* generic keyboard conversion */ |
... | ... | |
450 | 456 |
kbd_mouse_event(dx, dy, dz, buttons); |
451 | 457 |
} |
452 | 458 |
|
453 |
static void sdl_scale(DisplayState *ds, int width, int height)
|
|
459 |
static void sdl_scale(int width, int height) |
|
454 | 460 |
{ |
455 | 461 |
int bpp = real_screen->format->BitsPerPixel; |
456 | 462 |
|
... | ... | |
461 | 467 |
scaling_active = 1; |
462 | 468 |
} |
463 | 469 |
|
464 |
static void toggle_full_screen(DisplayState *ds)
|
|
470 |
static void toggle_full_screen(void)
|
|
465 | 471 |
{ |
472 |
int width = surface_width(surface); |
|
473 |
int height = surface_height(surface); |
|
474 |
int bpp = surface_bits_per_pixel(surface); |
|
475 |
|
|
466 | 476 |
gui_fullscreen = !gui_fullscreen; |
467 | 477 |
if (gui_fullscreen) { |
468 | 478 |
gui_saved_width = real_screen->w; |
469 | 479 |
gui_saved_height = real_screen->h; |
470 | 480 |
gui_saved_scaling = scaling_active; |
471 | 481 |
|
472 |
do_sdl_resize(ds_get_width(ds), ds_get_height(ds), |
|
473 |
ds_get_bits_per_pixel(ds)); |
|
482 |
do_sdl_resize(width, height, bpp); |
|
474 | 483 |
scaling_active = 0; |
475 | 484 |
|
476 | 485 |
gui_saved_grab = gui_grab; |
477 | 486 |
sdl_grab_start(); |
478 | 487 |
} else { |
479 | 488 |
if (gui_saved_scaling) { |
480 |
sdl_scale(ds, gui_saved_width, gui_saved_height);
|
|
489 |
sdl_scale(gui_saved_width, gui_saved_height); |
|
481 | 490 |
} else { |
482 |
do_sdl_resize(ds_get_width(ds), ds_get_height(ds), 0);
|
|
491 |
do_sdl_resize(width, height, 0);
|
|
483 | 492 |
} |
484 | 493 |
if (!gui_saved_grab || !is_graphic_console()) { |
485 | 494 |
sdl_grab_end(); |
... | ... | |
489 | 498 |
vga_hw_update(); |
490 | 499 |
} |
491 | 500 |
|
492 |
static void handle_keydown(DisplayState *ds, SDL_Event *ev)
|
|
501 |
static void handle_keydown(SDL_Event *ev) |
|
493 | 502 |
{ |
494 | 503 |
int mod_state; |
495 | 504 |
int keycode; |
... | ... | |
508 | 517 |
keycode = sdl_keyevent_to_keycode(&ev->key); |
509 | 518 |
switch (keycode) { |
510 | 519 |
case 0x21: /* 'f' key on US keyboard */ |
511 |
toggle_full_screen(ds);
|
|
520 |
toggle_full_screen(); |
|
512 | 521 |
gui_keysym = 1; |
513 | 522 |
break; |
514 | 523 |
case 0x16: /* 'u' key on US keyboard */ |
515 | 524 |
if (scaling_active) { |
516 | 525 |
scaling_active = 0; |
517 |
sdl_switch(dcl, ds, ds->surface);
|
|
526 |
sdl_switch(dcl, NULL, NULL);
|
|
518 | 527 |
vga_hw_invalidate(); |
519 | 528 |
vga_hw_update(); |
520 | 529 |
} |
... | ... | |
545 | 554 |
if (!gui_fullscreen) { |
546 | 555 |
int width = MAX(real_screen->w + (keycode == 0x1b ? 50 : -50), |
547 | 556 |
160); |
548 |
int height = (ds_get_height(ds) * width) / ds_get_width(ds); |
|
557 |
int height = (surface_height(surface) * width) / |
|
558 |
surface_width(surface); |
|
549 | 559 |
|
550 |
sdl_scale(ds, width, height);
|
|
560 |
sdl_scale(width, height); |
|
551 | 561 |
vga_hw_invalidate(); |
552 | 562 |
vga_hw_update(); |
553 | 563 |
gui_keysym = 1; |
... | ... | |
634 | 644 |
} |
635 | 645 |
} |
636 | 646 |
|
637 |
static void handle_keyup(DisplayState *ds, SDL_Event *ev)
|
|
647 |
static void handle_keyup(SDL_Event *ev) |
|
638 | 648 |
{ |
639 | 649 |
int mod_state; |
640 | 650 |
|
... | ... | |
666 | 676 |
} |
667 | 677 |
} |
668 | 678 |
|
669 |
static void handle_mousemotion(DisplayState *ds, SDL_Event *ev)
|
|
679 |
static void handle_mousemotion(SDL_Event *ev) |
|
670 | 680 |
{ |
671 | 681 |
int max_x, max_y; |
672 | 682 |
|
... | ... | |
690 | 700 |
} |
691 | 701 |
} |
692 | 702 |
|
693 |
static void handle_mousebutton(DisplayState *ds, SDL_Event *ev)
|
|
703 |
static void handle_mousebutton(SDL_Event *ev) |
|
694 | 704 |
{ |
695 | 705 |
int buttonstate = SDL_GetMouseState(NULL, NULL); |
696 | 706 |
SDL_MouseButtonEvent *bev; |
... | ... | |
726 | 736 |
} |
727 | 737 |
} |
728 | 738 |
|
729 |
static void handle_activation(DisplayState *ds, SDL_Event *ev)
|
|
739 |
static void handle_activation(SDL_Event *ev) |
|
730 | 740 |
{ |
731 | 741 |
#ifdef _WIN32 |
732 | 742 |
/* Disable grab if the window no longer has the focus |
... | ... | |
754 | 764 |
} |
755 | 765 |
|
756 | 766 |
static void sdl_refresh(DisplayChangeListener *dcl, |
757 |
DisplayState *ds)
|
|
767 |
DisplayState *dontuse)
|
|
758 | 768 |
{ |
759 | 769 |
SDL_Event ev1, *ev = &ev1; |
760 | 770 |
|
... | ... | |
769 | 779 |
while (SDL_PollEvent(ev)) { |
770 | 780 |
switch (ev->type) { |
771 | 781 |
case SDL_VIDEOEXPOSE: |
772 |
sdl_update(dcl, ds, 0, 0, real_screen->w, real_screen->h);
|
|
782 |
sdl_update(dcl, dontuse, 0, 0, real_screen->w, real_screen->h);
|
|
773 | 783 |
break; |
774 | 784 |
case SDL_KEYDOWN: |
775 |
handle_keydown(ds, ev);
|
|
785 |
handle_keydown(ev); |
|
776 | 786 |
break; |
777 | 787 |
case SDL_KEYUP: |
778 |
handle_keyup(ds, ev);
|
|
788 |
handle_keyup(ev); |
|
779 | 789 |
break; |
780 | 790 |
case SDL_QUIT: |
781 | 791 |
if (!no_quit) { |
... | ... | |
784 | 794 |
} |
785 | 795 |
break; |
786 | 796 |
case SDL_MOUSEMOTION: |
787 |
handle_mousemotion(ds, ev);
|
|
797 |
handle_mousemotion(ev); |
|
788 | 798 |
break; |
789 | 799 |
case SDL_MOUSEBUTTONDOWN: |
790 | 800 |
case SDL_MOUSEBUTTONUP: |
791 |
handle_mousebutton(ds, ev);
|
|
801 |
handle_mousebutton(ev); |
|
792 | 802 |
break; |
793 | 803 |
case SDL_ACTIVEEVENT: |
794 |
handle_activation(ds, ev);
|
|
804 |
handle_activation(ev); |
|
795 | 805 |
break; |
796 | 806 |
case SDL_VIDEORESIZE: |
797 |
sdl_scale(ds, ev->resize.w, ev->resize.h);
|
|
807 |
sdl_scale(ev->resize.w, ev->resize.h); |
|
798 | 808 |
vga_hw_invalidate(); |
799 | 809 |
vga_hw_update(); |
800 | 810 |
break; |
Also available in: Unified diff