mirror of
https://github.com/holub/mame
synced 2025-05-31 01:51:46 +03:00
Fix font loading in sdlmame. BDF files are just loaded as TTF by TTF_OpenFont. Load is now protected by a magic check.
Also fixed a bug in SDL1.3 keyboard mapping and changed SDL1.3 code to be compatible with recent 1.3 API changes. [Couriersud]
This commit is contained in:
parent
ca8edd4cd8
commit
9861df0600
@ -577,12 +577,10 @@ static int draw13_window_create(sdl_window_info *window, int width, int height)
|
||||
SDL_WINDOW_BORDERLESS | SDL_WINDOW_INPUT_FOCUS | SDL_WINDOW_FULLSCREEN : SDL_WINDOW_RESIZABLE);
|
||||
|
||||
// create the SDL window
|
||||
SDL_SelectVideoDisplay(window->monitor->handle);
|
||||
|
||||
if (window->fullscreen && video_config.switchres)
|
||||
{
|
||||
SDL_DisplayMode mode;
|
||||
SDL_GetCurrentDisplayMode(&mode);
|
||||
SDL_GetCurrentDisplayMode(window->monitor->handle, &mode);
|
||||
mode.w = width;
|
||||
mode.h = height;
|
||||
if (window->refresh)
|
||||
@ -612,7 +610,7 @@ static int draw13_window_create(sdl_window_info *window, int width, int height)
|
||||
else
|
||||
SDL_SetWindowDisplayMode(window->sdl_window, NULL); // Use desktop
|
||||
|
||||
window->sdl_window = SDL_CreateWindow(window->title, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
|
||||
window->sdl_window = SDL_CreateWindow(window->title, SDL_WINDOWPOS_UNDEFINED_DISPLAY(window->monitor->handle), SDL_WINDOWPOS_UNDEFINED,
|
||||
width, height, sdl->extra_flags);
|
||||
|
||||
// create renderer
|
||||
|
@ -556,12 +556,11 @@ static int drawogl_window_create(sdl_window_info *window, int width, int height)
|
||||
//load_gl_lib(*window->machine);
|
||||
|
||||
// create the SDL window
|
||||
SDL_SelectVideoDisplay(window->monitor->handle);
|
||||
|
||||
if (window->fullscreen && video_config.switchres)
|
||||
{
|
||||
SDL_DisplayMode mode;
|
||||
SDL_GetCurrentDisplayMode(&mode);
|
||||
SDL_GetCurrentDisplayMode(window->monitor->handle, &mode);
|
||||
mode.w = width;
|
||||
mode.h = height;
|
||||
if (window->refresh)
|
||||
@ -571,7 +570,7 @@ static int drawogl_window_create(sdl_window_info *window, int width, int height)
|
||||
else
|
||||
SDL_SetWindowDisplayMode(window->sdl_window, NULL); // Use desktop
|
||||
|
||||
window->sdl_window = SDL_CreateWindow(window->title, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
|
||||
window->sdl_window = SDL_CreateWindow(window->title, SDL_WINDOWPOS_UNDEFINED_DISPLAY(window->monitor->handle), SDL_WINDOWPOS_UNDEFINED,
|
||||
width, height, sdl->extra_flags);
|
||||
|
||||
if (!window->sdl_window )
|
||||
|
@ -263,7 +263,7 @@ static void setup_texture(sdl_window_info *window, int tempwidth, int tempheight
|
||||
UINT32 fmt;
|
||||
|
||||
// Determine preferred pixelformat and set up yuv if necessary
|
||||
SDL_GetCurrentDisplayMode(&mode);
|
||||
SDL_GetCurrentDisplayMode(window->monitor->handle, &mode);
|
||||
|
||||
if (sdl->yuv_bitmap)
|
||||
{
|
||||
@ -414,12 +414,10 @@ static int drawsdl_window_create(sdl_window_info *window, int width, int height)
|
||||
SDL_WINDOW_BORDERLESS | SDL_WINDOW_INPUT_FOCUS | SDL_WINDOW_MOUSE_FOCUS
|
||||
| SDL_WINDOW_INPUT_GRABBED : SDL_WINDOW_RESIZABLE);
|
||||
|
||||
SDL_SelectVideoDisplay(window->monitor->handle);
|
||||
|
||||
if (window->fullscreen && video_config.switchres)
|
||||
{
|
||||
SDL_DisplayMode mode;
|
||||
SDL_GetCurrentDisplayMode(&mode);
|
||||
SDL_GetCurrentDisplayMode(window->monitor->handle, &mode);
|
||||
mode.w = width;
|
||||
mode.h = height;
|
||||
if (window->refresh)
|
||||
@ -433,13 +431,13 @@ static int drawsdl_window_create(sdl_window_info *window, int width, int height)
|
||||
width, height, sdl->extra_flags);
|
||||
SDL_ShowWindow(window->sdl_window);
|
||||
|
||||
SDL_SetWindowFullscreen(window->sdl_window, window->fullscreen);
|
||||
SDL_SetWindowFullscreen(window->sdl_window, (SDL_bool) window->fullscreen);
|
||||
SDL_GetWindowSize(window->sdl_window, &window->width, &window->height);
|
||||
SDL_RaiseWindow(window->sdl_window);
|
||||
|
||||
/* FIXME: Bug in SDL 1.3 */
|
||||
if (window->fullscreen)
|
||||
SDL_SetWindowGrab(window->sdl_window, 1);
|
||||
SDL_SetWindowGrab(window->sdl_window, SDL_TRUE);
|
||||
|
||||
// create a texture
|
||||
|
||||
|
@ -642,7 +642,7 @@ static void devmap_init(running_machine *machine, device_map_t *devmap, const ch
|
||||
if (dev_name && *dev_name && strcmp(dev_name,SDLOPTVAL_AUTO))
|
||||
{
|
||||
devmap->map[dev].name = remove_spaces(machine, dev_name);
|
||||
mame_printf_verbose("%s: Logical id %d: %s\n", label, dev + 1, joy_map.map[dev].name);
|
||||
mame_printf_verbose("%s: Logical id %d: %s\n", label, dev + 1, devmap->map[dev].name);
|
||||
devmap->initialized = 1;
|
||||
}
|
||||
}
|
||||
@ -1002,7 +1002,7 @@ static kt_table * sdlinput_read_keymap(running_machine *machine)
|
||||
// sdlinput_register_keyboards
|
||||
//============================================================
|
||||
|
||||
#if (!SDL13_POST_HG4464 && SDL_VERSION_ATLEAST(1,3,0))
|
||||
#if ((1 ||!SDL13_POST_HG4464) && SDL_VERSION_ATLEAST(1,3,0))
|
||||
static void sdlinput_register_keyboards(running_machine *machine)
|
||||
{
|
||||
int physical_keyboard;
|
||||
@ -1015,8 +1015,9 @@ static void sdlinput_register_keyboards(running_machine *machine)
|
||||
|
||||
for (physical_keyboard = 0; physical_keyboard < SDL_GetNumKeyboards(); physical_keyboard++)
|
||||
{
|
||||
char defname[90];
|
||||
snprintf(defname, sizeof(defname)-1, "Keyboard #%d", physical_keyboard + 1);
|
||||
//char defname[90];
|
||||
//snprintf(defname, sizeof(defname)-1, "Keyboard #%d", physical_keyboard + 1);
|
||||
char *defname = remove_spaces(machine, SDL_GetKeyboardName(SDL_GetKeyboard(physical_keyboard) ));
|
||||
|
||||
devmap_register(&keyboard_map, physical_keyboard, defname);
|
||||
}
|
||||
@ -1081,7 +1082,7 @@ static void sdlinput_register_keyboards(running_machine *machine)
|
||||
snprintf(defname, sizeof(defname)-1, "%s", key_trans_table[keynum].ui_name);
|
||||
|
||||
// add the item to the device
|
||||
// printf("Keynum %d => sdl key %d\n", keynum, OSD_SDL_INDEX(key_trans_table[keynum].sdl_key));
|
||||
// printf("Keynum %d => sdl key %d\n", keynum, OSD_SDL_INDEX(key_trans_table[keynum].sdl_key));
|
||||
input_device_item_add(devinfo->device, defname, &devinfo->keyboard.state[OSD_SDL_INDEX(key_trans_table[keynum].sdl_key)], itemid, generic_button_get_state);
|
||||
}
|
||||
|
||||
@ -1306,7 +1307,7 @@ void sdlinput_poll(running_machine *machine)
|
||||
switch(event.type) {
|
||||
case SDL_KEYDOWN:
|
||||
devinfo = generic_device_find_index( keyboard_list, keyboard_map.logical[event.key.which]);
|
||||
// printf("Key down %d %d %s => %d %s (scrlock keycode is %d)\n", event.key.which, event.key.keysym.scancode, devinfo->name, OSD_SDL_INDEX_KEYSYM(&event.key.keysym), sdl_key_trans_table[event.key.keysym.scancode].mame_key_name, KEYCODE_SCRLOCK);
|
||||
//printf("Key down %d %d %s => %d %s (scrlock keycode is %d)\n", event.key.which, event.key.keysym.scancode, devinfo->name, OSD_SDL_INDEX_KEYSYM(&event.key.keysym), sdl_key_trans_table[event.key.keysym.scancode].mame_key_name, KEYCODE_SCRLOCK);
|
||||
devinfo->keyboard.state[OSD_SDL_INDEX_KEYSYM(&event.key.keysym)] = 0x80;
|
||||
#if (!SDL_VERSION_ATLEAST(1,3,0))
|
||||
ui_input_push_char_event(machine, sdl_window_list->target, (unicode_char) event.key.keysym.unicode);
|
||||
|
@ -490,7 +490,7 @@ static void defines_verbose(void)
|
||||
static void osd_sdl_info(void)
|
||||
{
|
||||
#if SDL_VERSION_ATLEAST(1,3,0)
|
||||
int i, cur, num = SDL_GetNumVideoDrivers();
|
||||
int i, num = SDL_GetNumVideoDrivers();
|
||||
|
||||
mame_printf_verbose("Available videodrivers: ");
|
||||
for (i=0;i<num;i++)
|
||||
@ -501,17 +501,15 @@ static void osd_sdl_info(void)
|
||||
mame_printf_verbose("\n");
|
||||
mame_printf_verbose("Current Videodriver: %s\n", SDL_GetCurrentVideoDriver());
|
||||
num = SDL_GetNumVideoDisplays();
|
||||
cur = SDL_GetCurrentVideoDisplay();
|
||||
for (i=0;i<num;i++)
|
||||
{
|
||||
SDL_DisplayMode mode;
|
||||
int j;
|
||||
|
||||
SDL_SelectVideoDisplay(i);
|
||||
mame_printf_verbose("\tDisplay #%d\n", i);
|
||||
if (SDL_GetDesktopDisplayMode(&mode));
|
||||
if (SDL_GetDesktopDisplayMode(i, &mode));
|
||||
mame_printf_verbose("\t\tDesktop Mode: %dx%d-%d@%d\n", mode.w, mode.h, SDL_BITSPERPIXEL(mode.format), mode.refresh_rate);
|
||||
if (SDL_GetCurrentDisplayMode(&mode));
|
||||
if (SDL_GetCurrentDisplayMode(i, &mode));
|
||||
mame_printf_verbose("\t\tCurrent Display Mode: %dx%d-%d@%d\n", mode.w, mode.h, SDL_BITSPERPIXEL(mode.format), mode.refresh_rate);
|
||||
mame_printf_verbose("\t\tRenderdrivers:\n");
|
||||
for (j=0; j<SDL_GetNumRenderDrivers(); j++)
|
||||
@ -521,7 +519,6 @@ static void osd_sdl_info(void)
|
||||
mame_printf_verbose("\t\t\t%10s (%dx%d)\n", info.name, info.max_texture_width, info.max_texture_height);
|
||||
}
|
||||
}
|
||||
SDL_SelectVideoDisplay(cur);
|
||||
|
||||
mame_printf_verbose("Available audio drivers: \n");
|
||||
num = SDL_GetNumAudioDrivers();
|
||||
@ -829,6 +826,20 @@ bitmap_t *sdl_osd_interface::font_get_bitmap(osd_font font, unicode_char chnum,
|
||||
}
|
||||
#else // UNIX but not OSX
|
||||
|
||||
static TTF_Font * TTF_OpenFont_Magic(astring name, int fsize)
|
||||
{
|
||||
emu_file file(OPEN_FLAG_READ);
|
||||
if (file.open(name) == FILERR_NONE)
|
||||
{
|
||||
unsigned char buffer[5] = { 0xff, 0xff, 0xff, 0xff, 0xff };
|
||||
unsigned char magic[5] = { 0x00, 0x01, 0x00, 0x00, 0x00 };
|
||||
file.read(buffer,5);
|
||||
if (memcmp(buffer, magic, 5))
|
||||
return NULL;
|
||||
}
|
||||
return TTF_OpenFont(name.cstr(), POINT_SIZE);
|
||||
}
|
||||
|
||||
static TTF_Font *search_font_config(astring name, bool bold, bool italic, bool underline, bool &bakedstyles)
|
||||
{
|
||||
TTF_Font *font = (TTF_Font *)NULL;
|
||||
@ -882,7 +893,10 @@ static TTF_Font *search_font_config(astring name, bool bold, bool italic, bool u
|
||||
}
|
||||
|
||||
mame_printf_verbose("Matching font: %s\n", val.u.s);
|
||||
font = TTF_OpenFont((const char*)val.u.s, POINT_SIZE);
|
||||
{
|
||||
astring match_name((const char*)val.u.s);
|
||||
font = TTF_OpenFont_Magic(match_name, POINT_SIZE);
|
||||
}
|
||||
|
||||
if (font)
|
||||
{
|
||||
@ -916,7 +930,10 @@ static TTF_Font *search_font_config(astring name, bool bold, bool italic, bool u
|
||||
}
|
||||
|
||||
mame_printf_verbose("Matching unstyled font: %s\n", val.u.s);
|
||||
font = TTF_OpenFont((const char*)val.u.s, POINT_SIZE);
|
||||
{
|
||||
astring match_name((const char*)val.u.s);
|
||||
font = TTF_OpenFont_Magic(match_name, POINT_SIZE);
|
||||
}
|
||||
|
||||
if (font)
|
||||
{
|
||||
@ -956,7 +973,7 @@ osd_font sdl_osd_interface::font_open(const char *_name, int &height)
|
||||
bool strike = (name.replace(0, "[S]", "") + name.replace(0, "[s]", "") > 0);
|
||||
|
||||
// first up, try it as a filename
|
||||
font = TTF_OpenFont(name.cstr(), POINT_SIZE);
|
||||
font = TTF_OpenFont_Magic(name, POINT_SIZE);
|
||||
|
||||
// if no success, try the font path
|
||||
|
||||
@ -967,7 +984,7 @@ osd_font sdl_osd_interface::font_open(const char *_name, int &height)
|
||||
if (file.open(name) == FILERR_NONE)
|
||||
{
|
||||
astring full_name = file.fullpath();
|
||||
font = TTF_OpenFont(full_name.cstr(), POINT_SIZE);
|
||||
font = TTF_OpenFont_Magic(full_name, POINT_SIZE);
|
||||
if (font)
|
||||
mame_printf_verbose("Found font %s\n", full_name.cstr());
|
||||
}
|
||||
|
@ -166,8 +166,7 @@ void sdlvideo_monitor_refresh(sdl_monitor_info *monitor)
|
||||
#if (SDL_VERSION_ATLEAST(1,3,0))
|
||||
SDL_DisplayMode dmode;
|
||||
|
||||
SDL_SelectVideoDisplay(monitor->handle);
|
||||
SDL_GetDesktopDisplayMode(&dmode);
|
||||
SDL_GetDesktopDisplayMode(monitor->handle, &dmode);
|
||||
monitor->monitor_width = dmode.w;
|
||||
monitor->monitor_height = dmode.h;
|
||||
monitor->center_width = dmode.w;
|
||||
@ -448,10 +447,9 @@ static void init_monitors(void)
|
||||
|
||||
#if (SDL_VERSION_ATLEAST(1,3,0))
|
||||
{
|
||||
int i, temp;
|
||||
int i;
|
||||
|
||||
mame_printf_verbose("Enter init_monitors\n");
|
||||
temp = SDL_GetCurrentVideoDisplay();
|
||||
|
||||
for (i = 0; i < SDL_GetNumVideoDisplays(); i++)
|
||||
{
|
||||
@ -463,8 +461,7 @@ static void init_monitors(void)
|
||||
|
||||
snprintf(monitor->monitor_device, sizeof(monitor->monitor_device)-1, "%s%d", SDLOPTION_SCREEN,i);
|
||||
|
||||
SDL_SelectVideoDisplay(i);
|
||||
SDL_GetDesktopDisplayMode(&dmode);
|
||||
SDL_GetDesktopDisplayMode(i, &dmode);
|
||||
monitor->monitor_width = dmode.w;
|
||||
monitor->monitor_height = dmode.h;
|
||||
monitor->center_width = dmode.w;
|
||||
@ -482,7 +479,6 @@ static void init_monitors(void)
|
||||
*tailptr = monitor;
|
||||
tailptr = &monitor->next;
|
||||
}
|
||||
SDL_SelectVideoDisplay(temp);
|
||||
}
|
||||
mame_printf_verbose("Leave init_monitors\n");
|
||||
#elif defined(SDLMAME_WIN32)
|
||||
|
@ -606,13 +606,13 @@ static void sdlwindow_update_cursor_state(running_machine *machine, sdl_window_i
|
||||
{
|
||||
SDL_ShowCursor(SDL_ENABLE);
|
||||
if (SDL_GetWindowGrab(window->sdl_window ))
|
||||
SDL_SetWindowGrab(window->sdl_window, 0);
|
||||
SDL_SetWindowGrab(window->sdl_window, SDL_FALSE);
|
||||
}
|
||||
else
|
||||
{
|
||||
SDL_ShowCursor(SDL_DISABLE);
|
||||
if (!SDL_GetWindowGrab(window->sdl_window))
|
||||
SDL_SetWindowGrab(window->sdl_window, 1);
|
||||
SDL_SetWindowGrab(window->sdl_window, SDL_TRUE);
|
||||
}
|
||||
SDL_SetCursor(NULL); // Force an update in case the underlying driver has changed visibility
|
||||
}
|
||||
@ -818,7 +818,7 @@ static void pick_best_mode(sdl_window_info *window, int *fswidth, int *fsheight)
|
||||
minimum_height -= 4;
|
||||
}
|
||||
|
||||
num = SDL_GetNumDisplayModes();
|
||||
num = SDL_GetNumDisplayModes(window->monitor->handle);
|
||||
|
||||
if (num == 0)
|
||||
{
|
||||
@ -830,7 +830,7 @@ static void pick_best_mode(sdl_window_info *window, int *fswidth, int *fsheight)
|
||||
for (i = 0; i < num; ++i)
|
||||
{
|
||||
SDL_DisplayMode mode;
|
||||
SDL_GetDisplayMode(i, &mode);
|
||||
SDL_GetDisplayMode(window->monitor->handle, i, &mode);
|
||||
|
||||
// compute initial score based on difference between target and current
|
||||
size_score = 1.0f / (1.0f + fabsf((INT32)mode.w - target_width) + fabsf((INT32)mode.h - target_height));
|
||||
|
Loading…
Reference in New Issue
Block a user