void CSDL_Ext::stopTextInput() { if (SDL_IsTextInputActive() == SDL_TRUE) { SDL_StopTextInput(); } }
void Loop::processEvents() { SDL_Event e; while (SDL_PollEvent(&e) != 0) { //User requests quit if (e.type == SDL_QUIT) { mIsQuit = true; } //Events if text input not active if (!SDL_IsTextInputActive()) { handleMouseEvents(e); if (e.type == SDL_KEYDOWN) { handleKeyboardEvents(e); } } //Text input active else { handleTextInputEvents(e); } } }
void CSDL_Ext::startTextInput(SDL_Rect * where) { if (SDL_IsTextInputActive() == SDL_FALSE) { SDL_StartTextInput(); } SDL_SetTextInputRect(where); }
bool WindowManager::isKeyboardVisible() { #ifdef USE_SDL2 return SDL_IsTextInputActive(); #else return mKeyboardHeight > 1; #endif }
void TextBox::OnFocusAcquired() { assert(SDL_IsTextInputActive() == SDL_FALSE); m_caret.StartAnimation(); SetBorderColor(SDLColor(64, 64, 128, 0)); auto loc = GetLocation(); SDL_SetTextInputRect(&loc); SDL_StartTextInput(); }
/** * Get any keys that are currently being typed. Output in Aski. * If phone, pops up keyboard if not already up. If nothing is being typed, * returns 0. */ uint8_t jl_ct_typing_get(jlgr_t *jlgr) { if(!SDL_IsTextInputActive()) SDL_StartTextInput(); uint8_t rtn = jlgr->main.ct.text_input[jlgr->main.ct.read_cursor]; if(jl_ct_key_pressed(jlgr, SDL_SCANCODE_BACKSPACE) == 1) return '\b'; if(jl_ct_key_pressed(jlgr, SDL_SCANCODE_DELETE) == 1) return '\02'; if(jl_ct_key_pressed(jlgr, SDL_SCANCODE_RETURN) == 1) return '\n'; if(!rtn) return 0; jlgr->main.ct.read_cursor++; return rtn; }
bool InputEventController::OnKeyPressed(const SDL_KeyboardEvent& arg) { SDL_Keycode kc = arg.keysym.sym; auto textInputActive = SDL_IsTextInputActive(); if (textInputActive) { SDL_Keycode nkc = kc; // Map numpad enter to the "normal" enter so action subscribers don't need to // check for both. if (nkc == SDLK_KP_ENTER) nkc = SDLK_RETURN; switch (nkc) { case SDLK_BACKSPACE: case SDLK_RETURN: // For now, key_t values are mapped directly to SDL keycodes for // convenience. (*actions.ui.control)(static_cast<TextControl::key_t>(nkc)); break; } } // make left and right modifiers equal if (kc == SDLK_RSHIFT) kc = SDLK_LSHIFT; else if (kc == SDLK_RCTRL) kc = SDLK_LCTRL; else if (kc == SDLK_RGUI) kc = SDLK_LGUI; // Hotkeys are fired in addition to the normal bound action, but we don't // want to interfere with text input. if (!textInputActive) { auto iter = hotkeys.find(kc); if (iter != hotkeys.end()) { (*(iter->second))(1); } } auto hash = HashKeyboardEvent(kc); // Flip the meaning of menuNext if shift is held down. if (IsMapActive(ActionMapId::MENU) && hash == actions.ui.menuNext->GetPrimaryTrigger() && (SDL_GetModState() & KMOD_SHIFT)) { hash = actions.ui.menuPrev->GetPrimaryTrigger(); } HandleEvent(hash, 1); return true; }
void loop() { SDL_Event event; /* Check for events */ /*SDL_WaitEvent(&event); emscripten does not like waiting*/ while (SDL_PollEvent(&event)) { switch (event.type) { case SDL_KEYDOWN: case SDL_KEYUP: PrintKey(&event.key.keysym, (event.key.state == SDL_PRESSED) ? SDL_TRUE : SDL_FALSE, (event.key.repeat) ? SDL_TRUE : SDL_FALSE); break; case SDL_TEXTEDITING: PrintText("EDIT", event.text.text); break; case SDL_TEXTINPUT: PrintText("INPUT", event.text.text); break; case SDL_MOUSEBUTTONDOWN: /* Left button quits the app, other buttons toggles text input */ if (event.button.button == SDL_BUTTON_LEFT) { done = 1; } else { if (SDL_IsTextInputActive()) { SDL_Log("Stopping text input\n"); SDL_StopTextInput(); } else { SDL_Log("Starting text input\n"); SDL_StartTextInput(); } } break; case SDL_QUIT: done = 1; break; default: break; } } #ifdef __EMSCRIPTEN__ if (done) { emscripten_cancel_main_loop(); } #endif }
bool InputEventController::OnKeyReleased(const SDL_KeyboardEvent& arg) { if (SDL_IsTextInputActive()) return true; // make left and right modifiers equal SDL_Keycode kc = arg.keysym.sym; if (kc == SDLK_RSHIFT) kc = SDLK_LSHIFT; else if (kc == SDLK_RCTRL) kc = SDLK_LCTRL; else if (kc == SDLK_RGUI) kc = SDLK_LGUI; // value will be 0 (since the key was released) HandleEvent(HashKeyboardEvent(kc), 0); return true; }
int main(int argc, char *argv[]) { int index; /* index of last key we pushed in the bitmap font */ SDL_Window *window; SDL_Event event; /* last event received */ SDL_Keymod mod; /* key modifiers of last key we pushed */ SDL_Scancode scancode; /* scancode of last key we pushed */ if (SDL_Init(SDL_INIT_VIDEO) < 0) { printf("Error initializing SDL: %s", SDL_GetError()); } /* create window */ window = SDL_CreateWindow("iPhone keyboard test", 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0); /* create renderer */ renderer = SDL_CreateRenderer(window, -1, 0); /* load up our font */ loadFont(); /* draw the background, we'll just paint over it */ SDL_SetRenderDrawColor(renderer, bg_color.r, bg_color.g, bg_color.b, bg_color.a); SDL_RenderFillRect(renderer, NULL); SDL_RenderPresent(renderer); int done = 0; /* loop till we get SDL_Quit */ while (SDL_WaitEvent(&event)) { switch (event.type) { case SDL_QUIT: done = 1; break; case SDL_KEYDOWN: index = keyToIndex(event.key.keysym); scancode = event.key.keysym.scancode; mod = event.key.keysym.mod; if (scancode == SDL_SCANCODE_DELETE) { /* if user hit delete, delete the last character */ backspace(); lastCharWasColon = 0; } else if (lastCharWasColon && scancode == SDL_SCANCODE_0 && (mod & KMOD_SHIFT)) { /* if our last key was a colon and this one is a close paren, the make a hoppy face */ backspace(); drawIndex(32); /* index for happy face */ numChars++; drawCursor(); lastCharWasColon = 0; } else if (index != -1) { /* if we aren't doing a happy face, then just draw the normal character */ drawIndex(index); numChars++; drawCursor(); lastCharWasColon = (event.key.keysym.scancode == SDL_SCANCODE_SEMICOLON && (event.key.keysym.mod & KMOD_SHIFT)); } /* check if the key was a colon */ /* draw our updates to the screen */ SDL_RenderPresent(renderer); break; case SDL_MOUSEBUTTONUP: /* mouse up toggles onscreen keyboard visibility */ if (SDL_IsTextInputActive()) { SDL_StopTextInput(); } else { SDL_StartTextInput(); } break; } } cleanup(); return 0; }
void TextInputWidget::drawAt( Drawer & drawer, MenuWidget * parent, int x, int y, Align align ) { if ( !show ) { return; } if ( active && !SDL_IsTextInputActive() ) { SDL_StartTextInput(); } // Choose correct style Style * currentStyle = getCurrentStyle(); if ( this->textCache == nullptr ) { this->prepare( drawer, *currentStyle ); lastStyle = style; } else { if ( currentStyle != lastStyle || textChanged ) { prepare( drawer, *currentStyle ); lastStyle = currentStyle; } } // draw if ( currentStyle == nullptr ) { SDL_Point alignedPos = this->getAlignedPos( x, y, align ); lastPos = alignedPos; this->textCache->drawAt( alignedPos ); } else { SDL_Point alignedPos = this->getAlignedPos( x, y, align ); SDL_Rect size = { alignedPos.x, alignedPos.y, this->getWidth(), this->getHeight() }; lastPos = alignedPos; drawer.setClipRect( size ); // draw background currentStyle->drawBackground( drawer, size ); // draw text DirSize padding = style->getPadding(); SDL_Point innerPos = { alignedPos.x + padding.left, alignedPos.y + padding.top }; int innerWidth = style->getWidth() - padding.left - padding.right; drawer.setClipRect( { innerPos.x, innerPos.y, innerWidth, style->getHeight() } ); innerPos.y += ( style->getHeight() - padding.top - padding.bottom - textCache->getHeight() ) / 2; int width = drawer.getTextSize( this->text.substr( 0, this->cursorPosition ), style->getFontSize(), style->getFontStyle() ).w + 1; int offset = 0; if ( width > innerWidth ) { offset = width - innerWidth; } if ( text != "" ) this->textCache->drawAt( innerPos.x - offset, innerPos.y ); if ( active ) { drawer.setDrawingColor( style->getFontColor() ); drawer.drawLine( { width + innerPos.x - offset - 1, innerPos.y - 2 }, { width + innerPos.x - offset - 1, innerPos.y + textCache->getHeight() + 2 } ); } drawer.setClipRect( size ); // draw border SDL_Rect border = size; drawer.setDrawingColor( currentStyle->getBorderColor() ); for ( int i = 0; i < currentStyle->getBorderThickness(); i++ ) { drawer.drawRect( border ); border.x++; border.y++; border.w -= 2; border.h -= 2; } drawer.cancelClipRect(); } }
inline bool is_text_input_active() noexcept { return SDL_IsTextInputActive() == SDL_TRUE; }
void loop() { SDL_Event event; // Get the stage as it will receive most events. Loom2D::Stage *stage = Loom2D::Stage::smMainStage; /* Check for events */ while (SDL_PollEvent(&event)) { if (event.type == SDL_QUIT) { // Terminate execution. gLoomExecutionDone = 1; continue; } // Bail on the rest if no stage! if(!stage) continue; // Adjust coordinates for mouse events to work properly on high dpi screens. if(event.type == SDL_MOUSEMOTION || event.type == SDL_MOUSEBUTTONDOWN || event.type == SDL_MOUSEBUTTONUP) { if (SDL_GetWindowFlags(gSDLWindow) & SDL_WINDOW_ALLOW_HIGHDPI) { // We work in drawable space but OS gives us these events in // window coords - so scale. Usually it's an integer scale. int winW, winH; SDL_GetWindowSize(gSDLWindow, &winW, &winH); int drawableW, drawableH; SDL_GL_GetDrawableSize(gSDLWindow, &drawableW, &drawableH); if(event.type == SDL_MOUSEMOTION) { event.motion.x *= drawableW / winW; event.motion.y *= drawableH / winH; } else { event.button.x *= drawableW / winW; event.button.y *= drawableH / winH; } } } if(event.type == SDL_KEYDOWN) { SDL_Keysym key = event.key.keysym; // Handle a key! stage->_KeyDownDelegate.pushArgument(key.scancode); stage->_KeyDownDelegate.pushArgument(key.sym); stage->_KeyDownDelegate.pushArgument(key.mod); stage->_KeyDownDelegate.invoke(); //lmLog(coreLogGroup, "keydown %d %d", key.sym, SDLK_BACKSPACE); if (SDL_IsTextInputActive() && key.mod == KMOD_NONE && key.sym == SDLK_BACKSPACE) IMEDelegateDispatcher::shared()->dispatchDeleteBackward(); if (key.mod & KMOD_CTRL && key.sym == SDLK_v) { char* clipboard = SDL_GetClipboardText(); IMEDelegateDispatcher::shared()->dispatchInsertText(clipboard, strlen(clipboard)); SDL_free(clipboard); } } else if(event.type == SDL_KEYUP) { stage->_KeyUpDelegate.pushArgument(event.key.keysym.scancode); stage->_KeyUpDelegate.pushArgument(event.key.keysym.sym); stage->_KeyUpDelegate.pushArgument(event.key.keysym.mod); stage->_KeyUpDelegate.invoke(); } else if(event.type == SDL_FINGERDOWN) { if (!stage->fingerEnabled) continue; stage->_TouchBeganDelegate.pushArgument((int)event.tfinger.fingerId); stage->_TouchBeganDelegate.pushArgument(event.tfinger.x*stage->stageWidth); stage->_TouchBeganDelegate.pushArgument(event.tfinger.y*stage->stageHeight); stage->_TouchBeganDelegate.invoke(); } else if(event.type == SDL_FINGERUP) { if (!stage->fingerEnabled) continue; stage->_TouchEndedDelegate.pushArgument((int)event.tfinger.fingerId); stage->_TouchEndedDelegate.pushArgument(event.tfinger.x*stage->stageWidth); stage->_TouchEndedDelegate.pushArgument(event.tfinger.y*stage->stageHeight); stage->_TouchEndedDelegate.invoke(); } else if(event.type == SDL_FINGERMOTION) { if (!stage->fingerEnabled) continue; stage->_TouchMovedDelegate.pushArgument((int)event.tfinger.fingerId); stage->_TouchMovedDelegate.pushArgument(event.tfinger.x*stage->stageWidth); stage->_TouchMovedDelegate.pushArgument(event.tfinger.y*stage->stageHeight); stage->_TouchMovedDelegate.pushArgument(SDL_BUTTON_LEFT); stage->_TouchMovedDelegate.invoke(); } else if(event.type == SDL_MOUSEBUTTONDOWN) { if (!stage->mouseEnabled) continue; stage->_TouchBeganDelegate.pushArgument((int)event.button.which); stage->_TouchBeganDelegate.pushArgument(event.button.x); stage->_TouchBeganDelegate.pushArgument(event.button.y); stage->_TouchBeganDelegate.invoke(); } else if(event.type == SDL_MOUSEBUTTONUP) { if (!stage->mouseEnabled) continue; stage->_TouchEndedDelegate.pushArgument((int)event.button.which); stage->_TouchEndedDelegate.pushArgument(event.button.x); stage->_TouchEndedDelegate.pushArgument(event.button.y); stage->_TouchEndedDelegate.invoke(); } else if(event.type == SDL_MOUSEMOTION) { if (!stage->mouseEnabled) continue; stage->_TouchMovedDelegate.pushArgument((int)event.motion.which); stage->_TouchMovedDelegate.pushArgument(event.motion.x); stage->_TouchMovedDelegate.pushArgument(event.motion.y); stage->_TouchMovedDelegate.pushArgument((int)event.motion.state); stage->_TouchMovedDelegate.invoke(); } else if(event.type == SDL_MOUSEWHEEL) { stage->_ScrollWheelYMovedDelegate.pushArgument(event.wheel.y); stage->_ScrollWheelYMovedDelegate.invoke(); } else if (event.type == SDL_WINDOWEVENT && (event.window.event == SDL_WINDOWEVENT_RESIZED || event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED)) { int winWidth = event.window.data1, winHeight = event.window.data2; SDL_GL_GetDrawableSize(gSDLWindow, &winWidth, &winHeight); stage->noteNativeSize(winWidth, winHeight); GFX::Graphics::setNativeSize(winWidth, winHeight); } else if (event.type == SDL_TEXTINPUT) { IMEDelegateDispatcher::shared()->dispatchInsertText(event.text.text, strlen(event.text.text)); } else if (event.type == SDL_TEXTEDITING) { IMEDelegateDispatcher::shared()->dispatchShowComposition(event.text.text, strlen(event.text.text), event.edit.start, event.edit.length); } else if (event.type == SDL_CONTROLLERBUTTONDOWN) { //lmLogInfo(coreLogGroup, "Controller Button Down %d %d %d", event.cbutton.which, event.cbutton.button); LoomGameController::getGameController(LoomGameController::getControllerIndex(event.cbutton.which))->buttonDown(event); } else if (event.type == SDL_CONTROLLERBUTTONUP) { //lmLogInfo(coreLogGroup, "Controller Button Up %d %d %d", event.cbutton.which, event.cbutton.button); LoomGameController::getGameController(LoomGameController::getControllerIndex(event.cbutton.which))->buttonUp(event); } else if (event.type == SDL_CONTROLLERAXISMOTION) { //lmLog(coreLogGroup, "Controller [%d] triggered axis event.", LoomGameController::indexOfDevice(event.caxis.which)); LoomGameController::getGameController(LoomGameController::getControllerIndex(event.cbutton.which))->axisMove(event); } else if (event.type == SDL_CONTROLLERDEVICEADDED) { int addedDevice = LoomGameController::addDevice(event.cdevice.which); if (addedDevice != -1) { stage->_GameControllerAddedDelegate.pushArgument(addedDevice); stage->_GameControllerAddedDelegate.invoke(); } } else if (event.type == SDL_CONTROLLERDEVICEREMOVED) { int removedDevice = LoomGameController::removeDevice(event.cdevice.which); if (removedDevice != -1) { stage->_GameControllerRemovedDelegate.pushArgument(removedDevice); stage->_GameControllerRemovedDelegate.invoke(); } } else if (event.type == SDL_WINDOWEVENT) { if (event.window.event == SDL_WINDOWEVENT_FOCUS_GAINED) { const NativeDelegate* activated = LoomApplication::getApplicationActivatedDelegate(); activated->invoke(); } else if (event.window.event == SDL_WINDOWEVENT_FOCUS_LOST) { const NativeDelegate* deactivated = LoomApplication::getApplicationDeactivatedDelegate(); deactivated->invoke(); } } } /* Tick and render Loom. */ loom_tick(); }
bool window::is_text_input_active() { return SDL_IsTextInputActive(); }
bool Keyboard::hasTextInput() const { return SDL_IsTextInputActive() != SDL_FALSE; }
void Input::stopTextInput() { if (SDL_IsTextInputActive()) SDL_StopTextInput(); input_box = NULL; }
bool InputManager::parseEvent(const SDL_Event& ev, Window* window) { bool causedEvent = false; switch(ev.type) { case SDL_JOYAXISMOTION: //if it switched boundaries if((abs(ev.jaxis.value) > DEADZONE) != (abs(mPrevAxisValues[ev.jaxis.which][ev.jaxis.axis]) > DEADZONE)) { int normValue; if(abs(ev.jaxis.value) <= DEADZONE) normValue = 0; else if(ev.jaxis.value > 0) normValue = 1; else normValue = -1; window->input(getInputConfigByDevice(ev.jaxis.which), Input(ev.jaxis.which, TYPE_AXIS, ev.jaxis.axis, normValue, false)); causedEvent = true; } mPrevAxisValues[ev.jaxis.which][ev.jaxis.axis] = ev.jaxis.value; return causedEvent; case SDL_JOYBUTTONDOWN: case SDL_JOYBUTTONUP: window->input(getInputConfigByDevice(ev.jbutton.which), Input(ev.jbutton.which, TYPE_BUTTON, ev.jbutton.button, ev.jbutton.state == SDL_PRESSED, false)); return true; case SDL_JOYHATMOTION: window->input(getInputConfigByDevice(ev.jhat.which), Input(ev.jhat.which, TYPE_HAT, ev.jhat.hat, ev.jhat.value, false)); return true; case SDL_KEYDOWN: if(ev.key.keysym.sym == SDLK_BACKSPACE && SDL_IsTextInputActive()) { window->textInput("\b"); } if(ev.key.repeat) return false; if(ev.key.keysym.sym == SDLK_F4) { SDL_Event* quit = new SDL_Event(); quit->type = SDL_QUIT; SDL_PushEvent(quit); return false; } window->input(getInputConfigByDevice(DEVICE_KEYBOARD), Input(DEVICE_KEYBOARD, TYPE_KEY, ev.key.keysym.sym, 1, false)); return true; case SDL_KEYUP: window->input(getInputConfigByDevice(DEVICE_KEYBOARD), Input(DEVICE_KEYBOARD, TYPE_KEY, ev.key.keysym.sym, 0, false)); return true; case SDL_TEXTINPUT: window->textInput(ev.text.text); break; case SDL_JOYDEVICEADDED: addJoystickByDeviceIndex(ev.jdevice.which); // ev.jdevice.which is a device index return true; case SDL_JOYDEVICEREMOVED: removeJoystickByJoystickID(ev.jdevice.which); // ev.jdevice.which is an SDL_JoystickID (instance ID) return false; } return false; }
SDL_bool Android_IsScreenKeyboardShown(_THIS, SDL_Window * window) { return SDL_IsTextInputActive(); }
bool SDL2EventHandler::textInputMode() const { return SDL_IsTextInputActive(); }
bool SDLWindow::GetEnableTextEvents () { return SDL_IsTextInputActive (); }
// Input text methods for GUI void Input::startTextInput(UIinputBox* u) { if (!SDL_IsTextInputActive()) SDL_StartTextInput(); input_box = u; }