Android back button callback added

This commit is contained in:
Yousef Khadadeh 2026-04-27 17:20:16 +03:00
parent cfe250979a
commit 45dbde5da5
10 changed files with 39 additions and 6 deletions

View file

@ -843,6 +843,13 @@ void InputManager::backend_key_down_update(const SDL_KeyboardEvent& e) {
auto kPress = e.key; auto kPress = e.key;
auto kMod = e.mod; auto kMod = e.mod;
#ifdef __ANDROID__
if(kPress == SDLK_AC_BACK) {
main.input_global_back_button_callback();
return;
}
#endif
if(kPress != SDLK_LSHIFT && kPress != SDLK_RSHIFT && kPress != SDLK_LCTRL && kPress != SDLK_RCTRL && if(kPress != SDLK_LSHIFT && kPress != SDLK_RSHIFT && kPress != SDLK_LCTRL && kPress != SDLK_RCTRL &&
kPress != SDLK_LGUI && kPress != SDLK_RGUI && kPress != SDLK_LGUI && kPress != SDLK_RGUI &&
kPress != SDLK_LALT && kPress != SDLK_RALT) { kPress != SDLK_LALT && kPress != SDLK_RALT) {

View file

@ -284,6 +284,11 @@ void MainProgram::input_paste_callback(const CustomEvents::PasteEvent& paste) {
post_callback(); post_callback();
} }
void MainProgram::input_global_back_button_callback() {
screen->input_global_back_button_callback();
post_callback();
}
bool MainProgram::input_keybind_callback(const Vector2ui32& newKey) { bool MainProgram::input_keybind_callback(const Vector2ui32& newKey) {
if(keybindWaiting.has_value()) { if(keybindWaiting.has_value()) {
unsigned v = keybindWaiting.value(); unsigned v = keybindWaiting.value();

View file

@ -135,6 +135,7 @@ class MainProgram {
void input_open_infinipaint_file_callback(const CustomEvents::OpenInfiniPaintFileEvent& openFile); void input_open_infinipaint_file_callback(const CustomEvents::OpenInfiniPaintFileEvent& openFile);
void input_paste_callback(const CustomEvents::PasteEvent& paste); void input_paste_callback(const CustomEvents::PasteEvent& paste);
void input_global_back_button_callback();
bool input_keybind_callback(const Vector2ui32& newKey); bool input_keybind_callback(const Vector2ui32& newKey);
void input_drop_file_callback(const InputManager::DropCallbackArgs& drop); void input_drop_file_callback(const InputManager::DropCallbackArgs& drop);
void input_drop_text_callback(const InputManager::DropCallbackArgs& drop); void input_drop_text_callback(const InputManager::DropCallbackArgs& drop);

View file

@ -672,16 +672,16 @@ void FileSelectScreen::file_view() {
Vector2f iconSize{0.0f, 0.0f}; Vector2f iconSize{0.0f, 0.0f};
switch(fileViewType) { switch(fileViewType) {
case FileViewType::LARGE_GRID: case FileViewType::LARGE_GRID:
entrySize = {200.0f, 220.0f}; entrySize = {170.0f, 190.0f};
iconSize = {150.0f, 150.0f}; iconSize = {130.0f, 130.0f};
break; break;
case FileViewType::MEDIUM_GRID: case FileViewType::MEDIUM_GRID:
entrySize = {170.0f, 190.0f}; entrySize = {140.0f, 160.0f};
iconSize = {120.0f, 120.0f}; iconSize = {100.0f, 100.0f};
break; break;
case FileViewType::SMALL_GRID: case FileViewType::SMALL_GRID:
entrySize = {140.0f, 160.0f}; entrySize = {110.0f, 130.0f};
iconSize = {90.0f, 90.0f}; iconSize = {70.0f, 70.0f};
break; break;
default: default:
break; break;
@ -741,6 +741,14 @@ void FileSelectScreen::input_open_infinipaint_file_callback(const CustomEvents::
main.screen = std::make_unique<PhoneDrawingProgramScreen>(main); main.screen = std::make_unique<PhoneDrawingProgramScreen>(main);
} }
void FileSelectScreen::input_global_back_button_callback() {
if(!mainMenuOpenAnim->is_at_start())
mainMenuOpenAnim->animation_trigger_reverse();
else if(editMode)
editMode = false;
main.g.gui.set_to_layout();
}
void FileSelectScreen::draw(SkCanvas* canvas) { void FileSelectScreen::draw(SkCanvas* canvas) {
canvas->clear(main.g.gui.io.theme->backColor0); canvas->clear(main.g.gui.io.theme->backColor0);
} }

View file

@ -9,6 +9,7 @@ class FileSelectScreen : public Screen {
virtual void gui_layout_run() override; virtual void gui_layout_run() override;
virtual void draw(SkCanvas* canvas) override; virtual void draw(SkCanvas* canvas) override;
virtual void input_open_infinipaint_file_callback(const CustomEvents::OpenInfiniPaintFileEvent& openFile) override; virtual void input_open_infinipaint_file_callback(const CustomEvents::OpenInfiniPaintFileEvent& openFile) override;
virtual void input_global_back_button_callback() override;
struct TrashInfo { struct TrashInfo {
struct TrashFile { struct TrashFile {

View file

@ -65,3 +65,10 @@ void PhoneDrawingProgramScreen::top_toolbar() {
} }
}); });
} }
void PhoneDrawingProgramScreen::input_global_back_button_callback() {
main.world->save_to_file(main.world->filePath);
main.set_tab_to_close(main.world.get());
main.screen = std::make_unique<FileSelectScreen>(main);
main.g.gui.set_to_layout();
}

View file

@ -7,6 +7,7 @@ class PhoneDrawingProgramScreen : public DrawingProgramScreen {
PhoneDrawingProgramScreen(MainProgram& m); PhoneDrawingProgramScreen(MainProgram& m);
virtual void update() override; virtual void update() override;
virtual void gui_layout_run() override; virtual void gui_layout_run() override;
virtual void input_global_back_button_callback() override;
private: private:
void top_toolbar(); void top_toolbar();
void main_display(); void main_display();

View file

@ -10,6 +10,7 @@ bool Screen::app_close_requested() { return true; }
void Screen::input_add_file_to_canvas_callback(const CustomEvents::AddFileToCanvasEvent& addFile) {} void Screen::input_add_file_to_canvas_callback(const CustomEvents::AddFileToCanvasEvent& addFile) {}
void Screen::input_open_infinipaint_file_callback(const CustomEvents::OpenInfiniPaintFileEvent& openFile) {} void Screen::input_open_infinipaint_file_callback(const CustomEvents::OpenInfiniPaintFileEvent& openFile) {}
void Screen::input_paste_callback(const CustomEvents::PasteEvent& paste) {} void Screen::input_paste_callback(const CustomEvents::PasteEvent& paste) {}
void Screen::input_global_back_button_callback() {}
void Screen::input_drop_file_callback(const InputManager::DropCallbackArgs& drop) {} void Screen::input_drop_file_callback(const InputManager::DropCallbackArgs& drop) {}
void Screen::input_drop_text_callback(const InputManager::DropCallbackArgs& drop) {} void Screen::input_drop_text_callback(const InputManager::DropCallbackArgs& drop) {}
void Screen::input_key_callback(const InputManager::KeyCallbackArgs& key) {} void Screen::input_key_callback(const InputManager::KeyCallbackArgs& key) {}

View file

@ -12,6 +12,7 @@ class Screen {
virtual void input_add_file_to_canvas_callback(const CustomEvents::AddFileToCanvasEvent& addFile); virtual void input_add_file_to_canvas_callback(const CustomEvents::AddFileToCanvasEvent& addFile);
virtual void input_open_infinipaint_file_callback(const CustomEvents::OpenInfiniPaintFileEvent& openFile); virtual void input_open_infinipaint_file_callback(const CustomEvents::OpenInfiniPaintFileEvent& openFile);
virtual void input_paste_callback(const CustomEvents::PasteEvent& paste); virtual void input_paste_callback(const CustomEvents::PasteEvent& paste);
virtual void input_global_back_button_callback();
virtual void input_drop_file_callback(const InputManager::DropCallbackArgs& drop); virtual void input_drop_file_callback(const InputManager::DropCallbackArgs& drop);
virtual void input_drop_text_callback(const InputManager::DropCallbackArgs& drop); virtual void input_drop_text_callback(const InputManager::DropCallbackArgs& drop);
virtual void input_key_callback(const InputManager::KeyCallbackArgs& key); virtual void input_key_callback(const InputManager::KeyCallbackArgs& key);

View file

@ -204,6 +204,7 @@ void initialize_sdl(MainStruct& mS, int wWidth, int wHeight) {
SDL_SetHint(SDL_HINT_PEN_MOUSE_EVENTS, "0"); SDL_SetHint(SDL_HINT_PEN_MOUSE_EVENTS, "0");
SDL_SetHint(SDL_HINT_MOUSE_TOUCH_EVENTS, "0"); SDL_SetHint(SDL_HINT_MOUSE_TOUCH_EVENTS, "0");
SDL_SetHint(SDL_HINT_TOUCH_MOUSE_EVENTS, "0"); SDL_SetHint(SDL_HINT_TOUCH_MOUSE_EVENTS, "0");
SDL_SetHint(SDL_HINT_ANDROID_TRAP_BACK_BUTTON, "1");
SDL_SetHint(SDL_HINT_EMSCRIPTEN_KEYBOARD_ELEMENT, "#canvas"); // Ensures that SDL only grabs input when browser is focused on canvas SDL_SetHint(SDL_HINT_EMSCRIPTEN_KEYBOARD_ELEMENT, "#canvas"); // Ensures that SDL only grabs input when browser is focused on canvas
if(!SDL_Init(SDL_INIT_VIDEO)) if(!SDL_Init(SDL_INIT_VIDEO))