static void qemulator_setup( QEmulator* emulator ) { AndroidOptions* opts = emulator->opts; if ( !emulator->window && !opts->no_window ) { SkinLayout* layout = emulator->layout; double scale = get_default_scale(emulator->opts); static const SkinWindowFuncs skin_window_funcs = { .key_event = &qemulator_window_key_event, .mouse_event = &qemulator_window_mouse_event, .generic_event = &qemulator_window_generic_event, .opengles_show = &android_showOpenglesWindow, .opengles_hide = &android_hideOpenglesWindow, .opengles_redraw = &android_redrawOpenglesWindow, }; emulator->window = skin_window_create(layout, emulator->win_x, emulator->win_y, scale, 0, &skin_window_funcs); if (emulator->window == NULL) return; { SkinTrackBall* ball; SkinTrackBallParameters params; params.diameter = 30; params.ring = 2; params.ball_color = 0xffe0e0e0; params.dot_color = 0xff202020; params.ring_color = 0xff000000; params.event_func = &qemulator_trackball_event; ball = skin_trackball_create( ¶ms ); emulator->trackball = ball; skin_window_set_trackball( emulator->window, ball ); emulator->lcd_brightness = 128; /* 50% */ skin_window_set_lcd_brightness( emulator->window, emulator->lcd_brightness ); } if ( emulator->onion != NULL ) skin_window_set_onion( emulator->window, emulator->onion, emulator->onion_rotation, emulator->onion_alpha ); qemulator_set_title(emulator); skin_window_enable_touch ( emulator->window, !androidHwConfig_isScreenNoTouch(android_hw)); skin_window_enable_dpad ( emulator->window, android_hw->hw_dPad != 0 ); skin_window_enable_qwerty( emulator->window, android_hw->hw_keyboard != 0 ); skin_window_enable_trackball( emulator->window, android_hw->hw_trackBall != 0 ); }
SkinUI* skin_ui_create(SkinFile* layout_file, const char* initial_orientation, const SkinUIFuncs* ui_funcs, const SkinUIParams* ui_params) { SkinUI* ui; ANEW0(ui); ui->layout_file = layout_file; ui->layout = skin_file_select_layout(layout_file->layouts, initial_orientation); ui->ui_funcs = ui_funcs; ui->ui_params = ui_params[0]; ui->keyboard = skin_keyboard_create(ui->ui_params.keyboard_charmap, ui->ui_params.keyboard_raw_keys, ui_funcs->keyboard_flush); ui->window = NULL; skin_keyboard_enable(ui->keyboard, 1); skin_keyboard_on_command(ui->keyboard, _skin_ui_handle_key_command, ui); ui->window = skin_window_create(ui->layout, ui->ui_params.window_x, ui->ui_params.window_y, ui->ui_params.window_scale, 0, ui->ui_funcs->window_funcs); if (!ui->window) { skin_ui_free(ui); return NULL; } if (ui->ui_params.enable_trackball) { ui->trackball = skin_trackball_create(ui->ui_funcs->trackball_params); skin_window_set_trackball(ui->window, ui->trackball); } ui->lcd_brightness = 128; /* 50% */ skin_window_set_lcd_brightness(ui->window, ui->lcd_brightness ); if (ui->onion) { skin_window_set_onion(ui->window, ui->onion, ui->onion_rotation, ui->onion_alpha); } skin_ui_reset_title(ui); skin_window_enable_touch(ui->window, ui->ui_params.enable_touch); skin_window_enable_dpad(ui->window, ui->ui_params.enable_dpad); skin_window_enable_qwerty(ui->window, ui->ui_params.enable_keyboard); skin_window_enable_trackball(ui->window, ui->ui_params.enable_trackball); return ui; }
static void qemulator_setup( QEmulator* emulator ) { AndroidOptions* opts = emulator->opts; if ( !emulator->window && !opts->no_window ) { SkinLayout* layout = emulator->layout; double scale = get_default_scale(emulator->opts); emulator->window = skin_window_create( layout, emulator->win_x, emulator->win_y, scale, 0); if (emulator->window == NULL) return; { SkinTrackBall* ball; SkinTrackBallParameters params; params.diameter = 30; params.ring = 2; params.ball_color = 0xffe0e0e0; params.dot_color = 0xff202020; params.ring_color = 0xff000000; ball = skin_trackball_create( ¶ms ); emulator->trackball = ball; skin_window_set_trackball( emulator->window, ball ); emulator->lcd_brightness = 128; skin_window_set_lcd_brightness( emulator->window, emulator->lcd_brightness ); } if ( emulator->onion != NULL ) skin_window_set_onion( emulator->window, emulator->onion, emulator->onion_rotation, emulator->onion_alpha ); qemulator_set_title(emulator); skin_window_enable_touch ( emulator->window, !androidHwConfig_isScreenNoTouch(android_hw)); skin_window_enable_dpad ( emulator->window, android_hw->hw_dPad != 0 ); skin_window_enable_qwerty( emulator->window, android_hw->hw_keyboard != 0 ); skin_window_enable_trackball( emulator->window, android_hw->hw_trackBall != 0 ); } uicmd_set_brightness_change_callback(qemulator_light_brightness, emulator); }
void skin_ui_set_onion(SkinUI* ui, SkinImage* onion, SkinRotation onion_rotation, int onion_alpha) { if (onion) { skin_image_ref(onion); } skin_image_unref(&ui->onion); ui->onion = onion; ui->onion_rotation = onion_rotation; ui->onion_alpha = onion_alpha; if (ui->window) { skin_window_set_onion(ui->window, onion, onion_rotation, onion_alpha); } }
static void handle_key_command( void* opaque, SkinKeyCommand command, int down ) { static const struct { SkinKeyCommand cmd; AndroidKeyCode kcode; } keycodes[] = { { SKIN_KEY_COMMAND_BUTTON_CALL, kKeyCodeCall }, { SKIN_KEY_COMMAND_BUTTON_HOME, kKeyCodeHome }, { SKIN_KEY_COMMAND_BUTTON_BACK, kKeyCodeBack }, { SKIN_KEY_COMMAND_BUTTON_HANGUP, kKeyCodeEndCall }, { SKIN_KEY_COMMAND_BUTTON_POWER, kKeyCodePower }, { SKIN_KEY_COMMAND_BUTTON_SEARCH, kKeyCodeSearch }, { SKIN_KEY_COMMAND_BUTTON_MENU, kKeyCodeMenu }, { SKIN_KEY_COMMAND_BUTTON_DPAD_UP, kKeyCodeDpadUp }, { SKIN_KEY_COMMAND_BUTTON_DPAD_LEFT, kKeyCodeDpadLeft }, { SKIN_KEY_COMMAND_BUTTON_DPAD_RIGHT, kKeyCodeDpadRight }, { SKIN_KEY_COMMAND_BUTTON_DPAD_DOWN, kKeyCodeDpadDown }, { SKIN_KEY_COMMAND_BUTTON_DPAD_CENTER, kKeyCodeDpadCenter }, { SKIN_KEY_COMMAND_BUTTON_VOLUME_UP, kKeyCodeVolumeUp }, { SKIN_KEY_COMMAND_BUTTON_VOLUME_DOWN, kKeyCodeVolumeDown }, { SKIN_KEY_COMMAND_BUTTON_CAMERA, kKeyCodeCamera }, { SKIN_KEY_COMMAND_BUTTON_TV, kKeyCodeTV }, { SKIN_KEY_COMMAND_BUTTON_EPG, kKeyCodeEPG }, { SKIN_KEY_COMMAND_BUTTON_DVR, kKeyCodeDVR }, { SKIN_KEY_COMMAND_BUTTON_PREV, kKeyCodePrevious }, { SKIN_KEY_COMMAND_BUTTON_NEXT, kKeyCodeNext }, { SKIN_KEY_COMMAND_BUTTON_PLAY, kKeyCodePlay }, { SKIN_KEY_COMMAND_BUTTON_PAUSE, kKeyCodePause }, { SKIN_KEY_COMMAND_BUTTON_STOP, kKeyCodeStop }, { SKIN_KEY_COMMAND_BUTTON_REWIND, kKeyCodeRewind }, { SKIN_KEY_COMMAND_BUTTON_FFWD, kKeyCodeFastForward }, { SKIN_KEY_COMMAND_BUTTON_BOOKMARKS, kKeyCodeBookmarks }, { SKIN_KEY_COMMAND_BUTTON_WINDOW, kKeyCodeCycleWindows }, { SKIN_KEY_COMMAND_BUTTON_CHANNELUP, kKeyCodeChannelUp }, { SKIN_KEY_COMMAND_BUTTON_CHANNELDOWN, kKeyCodeChannelDown }, { SKIN_KEY_COMMAND_NONE, 0 } }; int nn; #ifdef CONFIG_TRACE static int tracing = 0; #endif QEmulator* emulator = opaque; for (nn = 0; keycodes[nn].kcode != 0; nn++) { if (command == keycodes[nn].cmd) { unsigned code = keycodes[nn].kcode; if (down) code |= 0x200; user_event_keycode( code ); return; } } if (command == SKIN_KEY_COMMAND_SHOW_TRACKBALL) { emulator->show_trackball = (down != 0); skin_window_show_trackball( emulator->window, emulator->show_trackball ); return; } if (down == 0) return; switch (command) { case SKIN_KEY_COMMAND_TOGGLE_NETWORK: { corecmd_toggle_network(); D( "network is now %s", corecmd_is_network_disabled() ? "disconnected" : "connected" ); } break; case SKIN_KEY_COMMAND_TOGGLE_FULLSCREEN: if (emulator->window) { skin_window_toggle_fullscreen(emulator->window); } break; case SKIN_KEY_COMMAND_TOGGLE_TRACING: { #ifdef CONFIG_TRACE tracing = !tracing; corecmd_trace_control(tracing); #endif } break; case SKIN_KEY_COMMAND_TOGGLE_TRACKBALL: emulator->show_trackball = !emulator->show_trackball; skin_window_show_trackball( emulator->window, emulator->show_trackball ); qemulator_set_title(emulator); break; case SKIN_KEY_COMMAND_ONION_ALPHA_UP: case SKIN_KEY_COMMAND_ONION_ALPHA_DOWN: if (emulator->onion) { int alpha = emulator->onion_alpha; if (command == SKIN_KEY_COMMAND_ONION_ALPHA_UP) alpha += 16; else alpha -= 16; if (alpha > 256) alpha = 256; else if (alpha < 0) alpha = 0; emulator->onion_alpha = alpha; skin_window_set_onion( emulator->window, emulator->onion, emulator->onion_rotation, alpha ); skin_window_redraw( emulator->window, NULL ); } break; case SKIN_KEY_COMMAND_CHANGE_LAYOUT_PREV: case SKIN_KEY_COMMAND_CHANGE_LAYOUT_NEXT: { SkinLayout* layout = NULL; if (command == SKIN_KEY_COMMAND_CHANGE_LAYOUT_NEXT) { layout = emulator->layout->next; if (layout == NULL) layout = emulator->layout_file->layouts; } else if (command == SKIN_KEY_COMMAND_CHANGE_LAYOUT_PREV) { layout = emulator->layout_file->layouts; while (layout->next && layout->next != emulator->layout) layout = layout->next; } if (layout != NULL) { SkinRotation rotation; emulator->layout = layout; skin_window_reset( emulator->window, layout ); rotation = skin_layout_get_dpad_rotation( layout ); if (emulator->keyboard) skin_keyboard_set_rotation( emulator->keyboard, rotation ); if (emulator->trackball) { skin_trackball_set_rotation( emulator->trackball, rotation ); skin_window_set_trackball( emulator->window, emulator->trackball ); skin_window_show_trackball( emulator->window, emulator->show_trackball ); } skin_window_set_lcd_brightness( emulator->window, emulator->lcd_brightness ); qframebuffer_invalidate_all(); qframebuffer_check_updates(); } } break; default: ; } }
/* used to respond to a given keyboard command shortcut */ static void _skin_ui_handle_key_command(void* opaque, SkinKeyCommand command, int down) { SkinUI* ui = opaque; static const struct { SkinKeyCommand cmd; SkinKeyCode kcode; } keycodes[] = { { SKIN_KEY_COMMAND_BUTTON_CALL, kKeyCodeCall }, { SKIN_KEY_COMMAND_BUTTON_HOME, kKeyCodeHome }, { SKIN_KEY_COMMAND_BUTTON_BACK, kKeyCodeBack }, { SKIN_KEY_COMMAND_BUTTON_HANGUP, kKeyCodeEndCall }, { SKIN_KEY_COMMAND_BUTTON_POWER, kKeyCodePower }, { SKIN_KEY_COMMAND_BUTTON_SEARCH, kKeyCodeSearch }, { SKIN_KEY_COMMAND_BUTTON_MENU, kKeyCodeMenu }, { SKIN_KEY_COMMAND_BUTTON_DPAD_UP, kKeyCodeDpadUp }, { SKIN_KEY_COMMAND_BUTTON_DPAD_LEFT, kKeyCodeDpadLeft }, { SKIN_KEY_COMMAND_BUTTON_DPAD_RIGHT, kKeyCodeDpadRight }, { SKIN_KEY_COMMAND_BUTTON_DPAD_DOWN, kKeyCodeDpadDown }, { SKIN_KEY_COMMAND_BUTTON_DPAD_CENTER, kKeyCodeDpadCenter }, { SKIN_KEY_COMMAND_BUTTON_VOLUME_UP, kKeyCodeVolumeUp }, { SKIN_KEY_COMMAND_BUTTON_VOLUME_DOWN, kKeyCodeVolumeDown }, { SKIN_KEY_COMMAND_BUTTON_CAMERA, kKeyCodeCamera }, { SKIN_KEY_COMMAND_BUTTON_TV, kKeyCodeTV }, { SKIN_KEY_COMMAND_BUTTON_EPG, kKeyCodeEPG }, { SKIN_KEY_COMMAND_BUTTON_DVR, kKeyCodeDVR }, { SKIN_KEY_COMMAND_BUTTON_PREV, kKeyCodePrevious }, { SKIN_KEY_COMMAND_BUTTON_NEXT, kKeyCodeNext }, { SKIN_KEY_COMMAND_BUTTON_PLAY, kKeyCodePlay }, { SKIN_KEY_COMMAND_BUTTON_PAUSE, kKeyCodePause }, { SKIN_KEY_COMMAND_BUTTON_STOP, kKeyCodeStop }, { SKIN_KEY_COMMAND_BUTTON_REWIND, kKeyCodeRewind }, { SKIN_KEY_COMMAND_BUTTON_FFWD, kKeyCodeFastForward }, { SKIN_KEY_COMMAND_BUTTON_BOOKMARKS, kKeyCodeBookmarks }, { SKIN_KEY_COMMAND_BUTTON_WINDOW, kKeyCodeCycleWindows }, { SKIN_KEY_COMMAND_BUTTON_CHANNELUP, kKeyCodeChannelUp }, { SKIN_KEY_COMMAND_BUTTON_CHANNELDOWN, kKeyCodeChannelDown }, { SKIN_KEY_COMMAND_NONE, 0 } }; int nn; for (nn = 0; keycodes[nn].kcode != 0; nn++) { if (command == keycodes[nn].cmd) { unsigned code = keycodes[nn].kcode; ui->ui_funcs->keyboard_event(NULL, code, down); return; } } // for the show-trackball command, handle down events to enable, and // up events to disable if (command == SKIN_KEY_COMMAND_SHOW_TRACKBALL) { ui->show_trackball = (down != 0); skin_window_show_trackball(ui->window, ui->show_trackball); return; } // only handle down events for the rest if (down == 0) return; switch (command) { case SKIN_KEY_COMMAND_TOGGLE_NETWORK: { bool enabled = ui->ui_funcs->network_toggle(); D( "network is now %s", enabled ? "connected" : "disconnected"); } break; case SKIN_KEY_COMMAND_TOGGLE_FULLSCREEN: if (ui->window) { skin_window_toggle_fullscreen(ui->window); } break; case SKIN_KEY_COMMAND_TOGGLE_TRACKBALL: ui->show_trackball = !ui->show_trackball; skin_window_show_trackball(ui->window, ui->show_trackball); skin_ui_reset_title(ui); break; case SKIN_KEY_COMMAND_ONION_ALPHA_UP: case SKIN_KEY_COMMAND_ONION_ALPHA_DOWN: if (ui->onion) { int alpha = ui->onion_alpha; if (command == SKIN_KEY_COMMAND_ONION_ALPHA_UP) alpha += 16; else alpha -= 16; if (alpha > 256) alpha = 256; else if (alpha < 0) alpha = 0; ui->onion_alpha = alpha; skin_window_set_onion(ui->window, ui->onion, ui->onion_rotation, ui->onion_alpha); skin_window_redraw(ui->window, NULL); //dprint( "onion alpha set to %d (%.f %%)", alpha, alpha/2.56 ); } break; case SKIN_KEY_COMMAND_CHANGE_LAYOUT_PREV: case SKIN_KEY_COMMAND_CHANGE_LAYOUT_NEXT: { SkinLayout* layout = NULL; if (command == SKIN_KEY_COMMAND_CHANGE_LAYOUT_NEXT) { layout = ui->layout->next; if (layout == NULL) layout = ui->layout_file->layouts; } else if (command == SKIN_KEY_COMMAND_CHANGE_LAYOUT_PREV) { layout = ui->layout_file->layouts; while (layout->next && layout->next != ui->layout) layout = layout->next; } if (layout != NULL) { ui->layout = layout; skin_window_reset(ui->window, layout); SkinRotation rotation = skin_layout_get_dpad_rotation(layout); if (ui->keyboard) skin_keyboard_set_rotation(ui->keyboard, rotation); if (ui->trackball) { skin_trackball_set_rotation(ui->trackball, rotation); skin_window_set_trackball(ui->window, ui->trackball); skin_window_show_trackball(ui->window, ui->show_trackball); } skin_window_set_lcd_brightness(ui->window, ui->lcd_brightness); ui->ui_funcs->framebuffer_invalidate(); } } break; default: /* XXX: TODO ? */ ; } }