Window resize operations moved to event callbacks
This commit is contained in:
parent
f5d757a9a5
commit
3ee17cfd2b
9 changed files with 57 additions and 30 deletions
|
|
@ -92,10 +92,12 @@ bool GUIHolder::load_theme(const std::filesystem::path& configPath, const std::s
|
|||
}
|
||||
|
||||
void GUIHolder::update() {
|
||||
gui.io.deltaTime = main.deltaTime;
|
||||
}
|
||||
|
||||
void GUIHolder::window_update() {
|
||||
calculate_final_gui_scale();
|
||||
gui.update_window({0, 0}, main.window.size.cast<float>(), final_gui_scale());
|
||||
gui.io.deltaTime = main.deltaTime;
|
||||
gui.layout_if_necessary();
|
||||
}
|
||||
|
||||
float GUIHolder::final_gui_scale() {
|
||||
|
|
@ -136,13 +138,9 @@ void GUIHolder::input_key_callback(const InputManager::KeyCallbackArgs& key) {
|
|||
}
|
||||
|
||||
void GUIHolder::input_text_key_callback() {
|
||||
gui.run_post_callback_func();
|
||||
gui.layout_if_necessary();
|
||||
}
|
||||
|
||||
void GUIHolder::input_text_input_callback() {
|
||||
gui.run_post_callback_func();
|
||||
gui.layout_if_necessary();
|
||||
}
|
||||
|
||||
void GUIHolder::input_mouse_button_callback(const InputManager::MouseButtonCallbackArgs& button) {
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ class GUIHolder {
|
|||
bool load_theme(const std::filesystem::path& configPath, const std::string& themeName);
|
||||
|
||||
void update();
|
||||
void window_update();
|
||||
void draw(SkCanvas* canvas, bool skiaAA);
|
||||
|
||||
void input_paste_callback(const CustomEvents::PasteEventData& paste);
|
||||
|
|
@ -30,6 +31,7 @@ class GUIHolder {
|
|||
void input_mouse_wheel_callback(const InputManager::MouseWheelCallbackArgs& wheel);
|
||||
void input_finger_touch_callback(const InputManager::FingerTouchCallbackArgs& touch);
|
||||
void input_finger_motion_callback(const InputManager::FingerMotionCallbackArgs& motion);
|
||||
|
||||
void post_callback();
|
||||
|
||||
float final_gui_scale();
|
||||
|
|
|
|||
|
|
@ -227,7 +227,7 @@ void GUIManager::update_window(const Vector2f& windowPos, const Vector2f& window
|
|||
if(io.windowPos != windowPos || io.windowSize != windowSize || io.guiScaleMultiplier != guiScaleMultiplier)
|
||||
set_to_layout();
|
||||
io.windowPos = windowPos;
|
||||
io.windowSize = windowSize;
|
||||
io.windowSize = windowSize / guiScaleMultiplier;
|
||||
io.guiScaleMultiplier = guiScaleMultiplier;
|
||||
}
|
||||
|
||||
|
|
@ -369,17 +369,17 @@ void GUIManager::input_key_callback(const InputManager::KeyCallbackArgs& key) {
|
|||
}
|
||||
|
||||
void GUIManager::input_mouse_button_callback(InputManager::MouseButtonCallbackArgs button) {
|
||||
button.pos *= io.guiScaleMultiplier;
|
||||
button.pos /= io.guiScaleMultiplier;
|
||||
mouse_callback(button.pos, [&button] (ElementContainer* e) { e->elem->input_mouse_button_callback(button); });
|
||||
}
|
||||
|
||||
void GUIManager::input_mouse_motion_callback(InputManager::MouseMotionCallbackArgs motion) {
|
||||
motion.pos *= io.guiScaleMultiplier;
|
||||
motion.pos /= io.guiScaleMultiplier;
|
||||
mouse_callback(motion.pos, [&motion] (ElementContainer* e) { e->elem->input_mouse_motion_callback(motion); });
|
||||
}
|
||||
|
||||
void GUIManager::input_mouse_wheel_callback(InputManager::MouseWheelCallbackArgs wheel) {
|
||||
wheel.mousePos *= io.guiScaleMultiplier;
|
||||
wheel.mousePos /= io.guiScaleMultiplier;
|
||||
mouse_callback(wheel.mousePos, [&wheel] (ElementContainer* e) { e->elem->input_mouse_wheel_callback(wheel); });
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -828,6 +828,19 @@ void InputManager::backend_touch_finger_motion_update(const SDL_TouchFingerEvent
|
|||
isTouchDevice = true;
|
||||
}
|
||||
|
||||
void InputManager::backend_window_resize_update(const SDL_WindowEvent& e) {
|
||||
WindowResizeCallbackArgs w;
|
||||
w.size = {e.data1, e.data2};
|
||||
w.density = main.window.density;
|
||||
main.input_window_resize_callback(w);
|
||||
}
|
||||
|
||||
void InputManager::backend_window_scale_update(const SDL_WindowEvent& e) {
|
||||
WindowScaleCallbackArgs w;
|
||||
w.scale = main.window.scale;
|
||||
main.input_window_scale_callback(w);
|
||||
}
|
||||
|
||||
void InputManager::backend_key_down_update(const SDL_KeyboardEvent& e) {
|
||||
auto kPress = e.key;
|
||||
auto kMod = e.mod;
|
||||
|
|
|
|||
|
|
@ -282,6 +282,8 @@ struct InputManager {
|
|||
void backend_touch_finger_down_update(const SDL_TouchFingerEvent& e);
|
||||
void backend_touch_finger_up_update(const SDL_TouchFingerEvent& e);
|
||||
void backend_touch_finger_motion_update(const SDL_TouchFingerEvent& e);
|
||||
void backend_window_resize_update(const SDL_WindowEvent& e);
|
||||
void backend_window_scale_update(const SDL_WindowEvent& e);
|
||||
|
||||
void set_clipboard_str(std::string_view s);
|
||||
void set_clipboard_plain_and_richtext_pair(const std::pair<std::string, RichText::TextData>& plainAndRichtextPair);
|
||||
|
|
@ -398,6 +400,15 @@ struct InputManager {
|
|||
size_t fingerDownCount;
|
||||
};
|
||||
|
||||
struct WindowResizeCallbackArgs {
|
||||
Vector2i size;
|
||||
float density;
|
||||
};
|
||||
|
||||
struct WindowScaleCallbackArgs {
|
||||
float scale;
|
||||
};
|
||||
|
||||
MainProgram& main;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -441,6 +441,16 @@ void MainProgram::input_finger_touch_callback(const InputManager::FingerTouchCal
|
|||
void MainProgram::input_finger_motion_callback(const InputManager::FingerMotionCallbackArgs& motion) {
|
||||
}
|
||||
|
||||
void MainProgram::input_window_resize_callback(const InputManager::WindowResizeCallbackArgs& w) {
|
||||
g.window_update();
|
||||
post_callback();
|
||||
}
|
||||
|
||||
void MainProgram::input_window_scale_callback(const InputManager::WindowScaleCallbackArgs& w) {
|
||||
g.window_update();
|
||||
post_callback();
|
||||
}
|
||||
|
||||
void MainProgram::close_set_to_close_tabs() {
|
||||
if(!tabsToClose.empty()) {
|
||||
std::erase_if(worlds, [&](auto& w) {
|
||||
|
|
|
|||
|
|
@ -137,6 +137,8 @@ class MainProgram {
|
|||
void input_multi_finger_motion_callback(const InputManager::MultiFingerMotionCallbackArgs& motion);
|
||||
void input_finger_touch_callback(const InputManager::FingerTouchCallbackArgs& touch);
|
||||
void input_finger_motion_callback(const InputManager::FingerMotionCallbackArgs& motion);
|
||||
void input_window_resize_callback(const InputManager::WindowResizeCallbackArgs& w);
|
||||
void input_window_scale_callback(const InputManager::WindowScaleCallbackArgs& w);
|
||||
|
||||
void create_new_tab(const CustomEvents::OpenInfiniPaintFileEventData& openFile);
|
||||
void set_tab_to_close(World* world);
|
||||
|
|
|
|||
|
|
@ -1784,7 +1784,10 @@ void Toolbar::general_settings_inner_gui() {
|
|||
checkbox_boolean_field(gui, "disable graphics driver workarounds", "Disable graphics driver workarounds (enabling or disabling this might fix some graphical glitches, requires restart)", &main.conf.disableGraphicsDriverWorkarounds);
|
||||
#endif
|
||||
input_scalar_field(gui, "jump transition time", "Jump transition time", &main.conf.jumpTransitionTime, 0.01f, 1000.0f, {.decimalPrecision = 2});
|
||||
input_scalar_field(gui, "Max GUI Scale", "Max GUI Scale", &main.conf.guiScale, 0.5f, 5.0f, {.decimalPrecision = 1});
|
||||
input_scalar_field(gui, "Max GUI Scale", "Max GUI Scale", &main.conf.guiScale, 0.5f, 5.0f, {
|
||||
.decimalPrecision = 1,
|
||||
.onEdit = [&] { main.g.window_update(); }
|
||||
});
|
||||
text_label(gui, "Anti-aliasing:");
|
||||
radio_button_selector(gui, "Antialiasing selector", &main.conf.antialiasing, {
|
||||
{"None", GlobalConfig::AntiAliasing::NONE},
|
||||
|
|
|
|||
26
src/main.cpp
26
src/main.cpp
|
|
@ -638,8 +638,6 @@ SDL_AppResult SDL_AppIterate(void *appstate) {
|
|||
#ifdef NDEBUG
|
||||
try {
|
||||
#endif
|
||||
mS.m->update_scale_and_density();
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
if(emscriptenFilesystemReadReady && !emscriptenFilesystemLoadConfigDone) {
|
||||
mS.m->load_config();
|
||||
|
|
@ -718,6 +716,13 @@ SDL_AppResult SDL_AppEvent(void *appstate, SDL_Event *event) {
|
|||
mS.m->window.writtenSize.y() = event->window.data2;
|
||||
}
|
||||
resize_window(mS);
|
||||
mS.m->update_scale_and_density();
|
||||
mS.m->input.backend_window_resize_update(event->window);
|
||||
get_refresh_rate(mS);
|
||||
break;
|
||||
case SDL_EVENT_WINDOW_DISPLAY_SCALE_CHANGED:
|
||||
mS.m->update_scale_and_density();
|
||||
mS.m->input.backend_window_scale_update(event->window);
|
||||
get_refresh_rate(mS);
|
||||
break;
|
||||
case SDL_EVENT_WINDOW_MAXIMIZED:
|
||||
|
|
@ -729,7 +734,6 @@ SDL_AppResult SDL_AppEvent(void *appstate, SDL_Event *event) {
|
|||
get_refresh_rate(mS);
|
||||
break;
|
||||
case SDL_EVENT_MOUSE_MOTION:
|
||||
mS.m->update_scale_and_density();
|
||||
#ifdef _WIN32
|
||||
if(!mS.m->toolbar.tabletOptions.ignoreMouseMovementWhenPenInProximity || !mS.m->input.pen.inProximity)
|
||||
#endif
|
||||
|
|
@ -738,15 +742,12 @@ SDL_AppResult SDL_AppEvent(void *appstate, SDL_Event *event) {
|
|||
}
|
||||
break;
|
||||
case SDL_EVENT_MOUSE_BUTTON_UP:
|
||||
mS.m->update_scale_and_density();
|
||||
mS.m->input.backend_mouse_button_up_update(event->button);
|
||||
break;
|
||||
case SDL_EVENT_MOUSE_BUTTON_DOWN:
|
||||
mS.m->update_scale_and_density();
|
||||
mS.m->input.backend_mouse_button_down_update(event->button);
|
||||
break;
|
||||
case SDL_EVENT_MOUSE_WHEEL:
|
||||
mS.m->update_scale_and_density();
|
||||
mS.m->input.backend_mouse_wheel_update(event->wheel);
|
||||
break;
|
||||
case SDL_EVENT_KEY_DOWN:
|
||||
|
|
@ -759,11 +760,9 @@ SDL_AppResult SDL_AppEvent(void *appstate, SDL_Event *event) {
|
|||
mS.m->input.backend_input_text_event(event->text.text);
|
||||
break;
|
||||
case SDL_EVENT_DROP_FILE:
|
||||
mS.m->update_scale_and_density();
|
||||
mS.m->input.backend_drop_file_event(event->drop);
|
||||
break;
|
||||
case SDL_EVENT_DROP_TEXT:
|
||||
mS.m->update_scale_and_density();
|
||||
mS.m->input.backend_drop_text_event(event->drop);
|
||||
break;
|
||||
case SDL_EVENT_PEN_PROXIMITY_IN: {
|
||||
|
|
@ -775,49 +774,38 @@ SDL_AppResult SDL_AppEvent(void *appstate, SDL_Event *event) {
|
|||
break;
|
||||
}
|
||||
case SDL_EVENT_PEN_MOTION: {
|
||||
mS.m->update_scale_and_density();
|
||||
mS.m->input.backend_pen_motion_update(event->pmotion);
|
||||
//mS.m->input.pen.isEraser = event->pmotion.pen_state & SDL_PEN_INPUT_ERASER_TIP;
|
||||
//mS.m->input.mouse.set_pos({event->pmotion.x * mS.m->window.density, event->pmotion.y * mS.m->window.density});
|
||||
break;
|
||||
}
|
||||
case SDL_EVENT_PEN_AXIS: {
|
||||
mS.m->update_scale_and_density();
|
||||
mS.m->input.backend_pen_axis_update(event->paxis);
|
||||
break;
|
||||
}
|
||||
case SDL_EVENT_PEN_DOWN: {
|
||||
mS.m->update_scale_and_density();
|
||||
mS.m->input.backend_pen_touch_down_update(event->ptouch);
|
||||
break;
|
||||
}
|
||||
case SDL_EVENT_PEN_UP: {
|
||||
mS.m->update_scale_and_density();
|
||||
mS.m->input.backend_pen_touch_up_update(event->ptouch);
|
||||
break;
|
||||
}
|
||||
case SDL_EVENT_PEN_BUTTON_UP: {
|
||||
mS.m->update_scale_and_density();
|
||||
mS.m->input.backend_pen_button_up_update(event->pbutton);
|
||||
break;
|
||||
}
|
||||
case SDL_EVENT_PEN_BUTTON_DOWN: {
|
||||
mS.m->update_scale_and_density();
|
||||
mS.m->input.backend_pen_button_down_update(event->pbutton);
|
||||
break;
|
||||
}
|
||||
case SDL_EVENT_FINGER_DOWN: {
|
||||
mS.m->update_scale_and_density();
|
||||
mS.m->input.backend_touch_finger_down_update(event->tfinger);
|
||||
break;
|
||||
}
|
||||
case SDL_EVENT_FINGER_UP: {
|
||||
mS.m->update_scale_and_density();
|
||||
mS.m->input.backend_touch_finger_up_update(event->tfinger);
|
||||
break;
|
||||
}
|
||||
case SDL_EVENT_FINGER_MOTION: {
|
||||
mS.m->update_scale_and_density();
|
||||
mS.m->input.backend_touch_finger_motion_update(event->tfinger);
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue