void EmuWindow::TouchMoved(unsigned framebuffer_x, unsigned framebuffer_y) { if (!touch_state->touch_pressed) return; if (!IsWithinTouchscreen(framebuffer_layout, framebuffer_x, framebuffer_y)) std::tie(framebuffer_x, framebuffer_y) = ClipToTouchScreen(framebuffer_x, framebuffer_y); TouchPressed(framebuffer_x, framebuffer_y); }
void EmuWindow_SDL2::OnMouseButton(u32 button, u8 state, s32 x, s32 y) { if (button != SDL_BUTTON_LEFT) return; if (state == SDL_PRESSED) { TouchPressed((unsigned)std::max(x, 0), (unsigned)std::max(y, 0)); } else { TouchReleased(); } }
void EmuWindow_GLFW::OnMouseButtonEvent(GLFWwindow* win, int button, int action, int mods) { if (button == GLFW_MOUSE_BUTTON_LEFT) { auto emu_window = GetEmuWindow(win); auto layout = emu_window->GetFramebufferLayout(); double x, y; glfwGetCursorPos(win, &x, &y); if (action == GLFW_PRESS) emu_window->TouchPressed(static_cast<unsigned>(x), static_cast<unsigned>(y)); else if (action == GLFW_RELEASE) emu_window->TouchReleased(); } }
/* ================== iphoneBuildTiccmd Use touch and tilt controls to set up a doom ticcmd_t ================== */ static void iphoneBuildTiccmd(ticcmd_t* cmd) { memset(cmd,0,sizeof*cmd); // cmd->consistancy = consistancy[consoleplayer][maketic & BACKUPTICMASK]; if ( menuState != IPM_GAME ) { // if in the menus, always generate an empty event return; } // the respawn button triggers a use if ( respawnActive ) { cmd->buttons |= BT_USE; respawnActive = false; } if ( gamestate != GS_LEVEL ) { // at intermissions, all taps equal attack // FIXME: better latched value if ( numTouches == numPrevTouches + 1 ) { cmd->buttons |= BT_ATTACK; } return; } // don't allow movement control use during automap if ( automapmode & am_active ) { return; } // don't built a tic when dead, other than the respawn use if ( players[consoleplayer].playerstate == PST_DEAD ) { return; } //------------------------ // No controls during weapon-select screen //------------------------ boolean weaponCycle = false; if ( drawWeaponSelect ) { // if the weaponSelect overlay is up, continue tracking held touches // until the are released for ( ibutton_t *hud = (ibutton_t *)&huds ; hud != (ibutton_t *)(&huds+1) ; hud++ ) { if ( hud->touch || hud == &huds.weaponSelect ) { UpdateHudTouch( hud ); } } // Re-tapping in the weapon select area will cycle to the next weapon. // The action happens on initial touch. touch_t *t = huds.weaponSelect.touch; if ( t && t->down && t->stateCount == 1 ) { drawWeaponSelect = false; t->stateCount++; // ensure it won't bring it back up weaponCycle = true; } else { return; } } //------------------------ // gameplay controls //------------------------ // update all the hud touch states if ( menuState == IPM_GAME ) { UpdateHudTouch( &huds.forwardStick ); UpdateHudTouch( &huds.sideStick ); UpdateHudTouch( &huds.turnStick ); UpdateHudTouch( &huds.turnRotor ); UpdateHudTouch( &huds.weaponSelect ); } // tap in the lower center for weapon switch touch_t *t = huds.weaponSelect.touch; if ( t && t->down && t->stateCount == 1 ) { drawWeaponSelect = true; } // hack to let a single touch control both hud elements on combo sticks // This is dependent on the order in the structure, and probably not a good // way to do things. if ( huds.sideStick.x == huds.forwardStick.x && huds.sideStick.y == huds.forwardStick.y ) { huds.sideStick.touch = huds.forwardStick.touch; huds.sideStick.downX = huds.forwardStick.downX; huds.sideStick.downY = huds.forwardStick.downY; } if ( huds.turnStick.x == huds.forwardStick.x && huds.turnStick.y == huds.forwardStick.y ) { huds.turnStick.touch = huds.forwardStick.touch; huds.turnStick.downX = huds.forwardStick.downX; huds.turnStick.downY = huds.forwardStick.downY; } // the fire button doesn't grab touches { int x = huds.fire.x - ( huds.fire.drawWidth >> 1 ); int y = huds.fire.y - ( huds.fire.drawHeight >> 1 ); int w = huds.fire.drawWidth << 1; int h = huds.fire.drawHeight << 1; if ( AnyTouchInBounds( x, y, w, h ) ) { cmd->buttons |= BT_ATTACK; huds.fire.buttonFlags |= BF_DRAW_ACTIVE; // draw with color } else { huds.fire.buttonFlags &= ~BF_DRAW_ACTIVE; } } int forwardmove; int sidemove; // the edge of the drawn control should give the maximum // legal doom movement speed huds.forwardStick.scale = stickMove->value / 128.0f; huds.sideStick.scale = stickMove->value / 128.0f; forwardmove = -TURBOTHRESHOLD * AxisHit( &huds.forwardStick ); sidemove = TURBOTHRESHOLD * AxisHit( &huds.sideStick ); huds.turnStick.scale = stickTurn->value / 128.0f; cmd->angleturn = -1500.0f * AxisHit( &huds.turnStick ); // rotary wheel cmd->angleturn -= rotorTurn->value * RotorControl( &huds.turnRotor ); // accelerometer tilting sidemove += tiltMove->value * DeadBandAdjust( tilt, tiltDeadBand->value ); cmd->angleturn -= tiltTurn->value * DeadBandAdjust( tilt, tiltDeadBand->value ); // clamp movements cmd->forwardmove = ClampMove( forwardmove ); cmd->sidemove = ClampMove( sidemove ); // tap in the upper center for use if ( TouchPressed( 140, 0, 240, 200 ) ) { cmd->buttons |= BT_USE; } // auto-use if the game thread found a usable line in front of the player if ( autoUse->value && autoUseActive ) { if ( cmd->buttons & BT_USE ) { // Allow a tap to briefly cancel the auto-use, which works around // some issues with incorrectly started auto-uses preventing // a real door from opening. cmd->buttons &= ~BT_USE; } else { cmd->buttons |= BT_USE; } } if ( weaponSelected != -1 ) { cmd->buttons |= BT_CHANGE; cmd->buttons |= weaponSelected<<BT_WEAPONSHIFT; weaponSelected = -1; } else { // auto-cycle weapons when firing on empty if ( players[consoleplayer].attackdown && !P_CheckAmmo(&players[consoleplayer]) ) { weaponCycle = true; } // weapon switch int newweapon = wp_nochange; if ( weaponCycle ) { // witch to next weapon when out of ammo newweapon = P_SwitchWeapon(&players[consoleplayer]); } if (newweapon != wp_nochange) { cmd->buttons |= BT_CHANGE; cmd->buttons |= newweapon<<BT_WEAPONSHIFT; } } }