⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sdl.c.svn-base

📁 我们自己开发的一个OSEK操作系统!不知道可不可以?
💻 SVN-BASE
📖 第 1 页 / 共 2 页
字号:
/* * QEMU SDL display driver * * Copyright (c) 2003 Fabrice Bellard * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */#include "qemu-common.h"#include "console.h"#include "sysemu.h"#include <SDL.h>#ifndef _WIN32#include <signal.h>#endifstatic SDL_Surface *screen;static int gui_grab; /* if true, all keyboard/mouse events are grabbed */static int last_vm_running;static int gui_saved_grab;static int gui_fullscreen;static int gui_noframe;static int gui_key_modifier_pressed;static int gui_keysym;static int gui_fullscreen_initial_grab;static int gui_grab_code = KMOD_LALT | KMOD_LCTRL;static uint8_t modifiers_state[256];static int width, height;static SDL_Cursor *sdl_cursor_normal;static SDL_Cursor *sdl_cursor_hidden;static int absolute_enabled = 0;static int guest_cursor = 0;static int guest_x, guest_y;static SDL_Cursor *guest_sprite = 0;static void sdl_update(DisplayState *ds, int x, int y, int w, int h){    //    printf("updating x=%d y=%d w=%d h=%d\n", x, y, w, h);    SDL_UpdateRect(screen, x, y, w, h);}static void sdl_resize(DisplayState *ds, int w, int h){    int flags;    //    printf("resizing to %d %d\n", w, h);    flags = SDL_HWSURFACE|SDL_ASYNCBLIT|SDL_HWACCEL;    if (gui_fullscreen)        flags |= SDL_FULLSCREEN;    if (gui_noframe)        flags |= SDL_NOFRAME;    width = w;    height = h; again:    screen = SDL_SetVideoMode(w, h, 0, flags);    if (!screen) {        fprintf(stderr, "Could not open SDL display\n");        exit(1);    }    if (!screen->pixels && (flags & SDL_HWSURFACE) && (flags & SDL_FULLSCREEN)) {        flags &= ~SDL_HWSURFACE;        goto again;    }    if (!screen->pixels) {        fprintf(stderr, "Could not open SDL display\n");        exit(1);    }    ds->data = screen->pixels;    ds->linesize = screen->pitch;    ds->depth = screen->format->BitsPerPixel;    if (screen->format->Bshift > screen->format->Rshift) {        ds->bgr = 1;    } else {        ds->bgr = 0;    }    ds->width = w;    ds->height = h;}/* generic keyboard conversion */#include "sdl_keysym.h"#include "keymaps.c"static kbd_layout_t *kbd_layout = NULL;static uint8_t sdl_keyevent_to_keycode_generic(const SDL_KeyboardEvent *ev){    int keysym;    /* workaround for X11+SDL bug with AltGR */    keysym = ev->keysym.sym;    if (keysym == 0 && ev->keysym.scancode == 113)        keysym = SDLK_MODE;    /* For Japanese key '\' and '|' */    if (keysym == 92 && ev->keysym.scancode == 133) {        keysym = 0xa5;    }    return keysym2scancode(kbd_layout, keysym);}/* specific keyboard conversions from scan codes */#if defined(_WIN32)static uint8_t sdl_keyevent_to_keycode(const SDL_KeyboardEvent *ev){    return ev->keysym.scancode;}#elsestatic uint8_t sdl_keyevent_to_keycode(const SDL_KeyboardEvent *ev){    int keycode;    keycode = ev->keysym.scancode;    if (keycode < 9) {        keycode = 0;    } else if (keycode < 97) {        keycode -= 8; /* just an offset */    } else if (keycode < 212) {        /* use conversion table */        keycode = _translate_keycode(keycode - 97);    } else {        keycode = 0;    }    return keycode;}#endifstatic void reset_keys(void){    int i;    for(i = 0; i < 256; i++) {        if (modifiers_state[i]) {            if (i & 0x80)                kbd_put_keycode(0xe0);            kbd_put_keycode(i | 0x80);            modifiers_state[i] = 0;        }    }}static void sdl_process_key(SDL_KeyboardEvent *ev){    int keycode, v;    if (ev->keysym.sym == SDLK_PAUSE) {        /* specific case */        v = 0;        if (ev->type == SDL_KEYUP)            v |= 0x80;        kbd_put_keycode(0xe1);        kbd_put_keycode(0x1d | v);        kbd_put_keycode(0x45 | v);        return;    }    if (kbd_layout) {        keycode = sdl_keyevent_to_keycode_generic(ev);    } else {        keycode = sdl_keyevent_to_keycode(ev);    }    switch(keycode) {    case 0x00:        /* sent when leaving window: reset the modifiers state */        reset_keys();        return;    case 0x2a:                          /* Left Shift */    case 0x36:                          /* Right Shift */    case 0x1d:                          /* Left CTRL */    case 0x9d:                          /* Right CTRL */    case 0x38:                          /* Left ALT */    case 0xb8:                         /* Right ALT */        if (ev->type == SDL_KEYUP)            modifiers_state[keycode] = 0;        else            modifiers_state[keycode] = 1;        break;    case 0x45: /* num lock */    case 0x3a: /* caps lock */        /* SDL does not send the key up event, so we generate it */        kbd_put_keycode(keycode);        kbd_put_keycode(keycode | 0x80);        return;    }    /* now send the key code */    if (keycode & 0x80)        kbd_put_keycode(0xe0);    if (ev->type == SDL_KEYUP)        kbd_put_keycode(keycode | 0x80);    else        kbd_put_keycode(keycode & 0x7f);}static void sdl_update_caption(void){    char buf[1024];    const char *status = "";    if (!vm_running)        status = " [Stopped]";    else if (gui_grab) {        if (!alt_grab)            status = " - Press Ctrl-Alt to exit grab";        else            status = " - Press Ctrl-Alt-Shift to exit grab";    }    if (qemu_name)        snprintf(buf, sizeof(buf), "QEMU (%s)%s", qemu_name, status);    else        snprintf(buf, sizeof(buf), "QEMU%s", status);    SDL_WM_SetCaption(buf, "QEMU");}static void sdl_hide_cursor(void){    if (!cursor_hide)        return;    if (kbd_mouse_is_absolute()) {        SDL_ShowCursor(1);        SDL_SetCursor(sdl_cursor_hidden);    } else {        SDL_ShowCursor(0);    }}static void sdl_show_cursor(void){    if (!cursor_hide)        return;    if (!kbd_mouse_is_absolute()) {        SDL_ShowCursor(1);        if (guest_cursor &&                (gui_grab || kbd_mouse_is_absolute() || absolute_enabled))            SDL_SetCursor(guest_sprite);        else            SDL_SetCursor(sdl_cursor_normal);    }}static void sdl_grab_start(void){    if (guest_cursor) {        SDL_SetCursor(guest_sprite);        SDL_WarpMouse(guest_x, guest_y);    } else        sdl_hide_cursor();    SDL_WM_GrabInput(SDL_GRAB_ON);    /* dummy read to avoid moving the mouse */    SDL_GetRelativeMouseState(NULL, NULL);    gui_grab = 1;    sdl_update_caption();}static void sdl_grab_end(void){    SDL_WM_GrabInput(SDL_GRAB_OFF);    gui_grab = 0;    sdl_show_cursor();    sdl_update_caption();}static void sdl_send_mouse_event(int dz){    int dx, dy, state, buttons;    state = SDL_GetRelativeMouseState(&dx, &dy);    buttons = 0;    if (state & SDL_BUTTON(SDL_BUTTON_LEFT))        buttons |= MOUSE_EVENT_LBUTTON;    if (state & SDL_BUTTON(SDL_BUTTON_RIGHT))        buttons |= MOUSE_EVENT_RBUTTON;    if (state & SDL_BUTTON(SDL_BUTTON_MIDDLE))        buttons |= MOUSE_EVENT_MBUTTON;    if (kbd_mouse_is_absolute()) {	if (!absolute_enabled) {	    sdl_hide_cursor();	    if (gui_grab) {		sdl_grab_end();	    }	    absolute_enabled = 1;	}	SDL_GetMouseState(&dx, &dy);	dx = dx * 0x7FFF / width;	dy = dy * 0x7FFF / height;    } else if (absolute_enabled) {	sdl_show_cursor();	absolute_enabled = 0;    } else if (guest_cursor) {        SDL_GetMouseState(&dx, &dy);        dx -= guest_x;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -