Program runs with moved code
This commit is contained in:
parent
ea35397326
commit
f3fde56dcf
9 changed files with 61 additions and 48 deletions
|
|
@ -94,7 +94,7 @@ void DrawingProgram::input_mouse_button_callback(const InputManager::MouseButton
|
|||
if(world.main.toolbar.rightClickPopupLocation)
|
||||
world.main.toolbar.rightClickPopupLocation = std::nullopt;
|
||||
else
|
||||
world.main.toolbar.rightClickPopupLocation = world.main.input.mouse.pos / world.main.toolbar.final_gui_scale();
|
||||
world.main.toolbar.rightClickPopupLocation = world.main.input.mouse.pos / world.main.g.final_gui_scale();
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
|
@ -401,11 +401,11 @@ void DrawingProgram::selection_action_menu(Vector2f popupPos) {
|
|||
text_label_light(gui, "Selection menu");
|
||||
popup_menu_action_button("Paste", "Paste", [&] {
|
||||
selection.deselect_all();
|
||||
selection.paste_clipboard(popupPos * t.final_gui_scale());
|
||||
selection.paste_clipboard(popupPos * world.main.g.final_gui_scale());
|
||||
});
|
||||
popup_menu_action_button("Paste Image", "Paste Image", [&] {
|
||||
selection.deselect_all();
|
||||
selection.paste_image(popupPos * t.final_gui_scale());
|
||||
selection.paste_image(popupPos * world.main.g.final_gui_scale());
|
||||
});
|
||||
if(selection.is_something_selected()) {
|
||||
popup_menu_action_button("Copy", "Copy", [&] {
|
||||
|
|
@ -669,7 +669,7 @@ CanvasComponentContainer::ObjInfo* DrawingProgram::add_file_to_canvas_by_data(co
|
|||
}
|
||||
|
||||
float DrawingProgram::drag_point_radius() {
|
||||
return 8.0f * world.main.toolbar.final_gui_scale();
|
||||
return 8.0f * world.main.g.final_gui_scale();
|
||||
}
|
||||
|
||||
void DrawingProgram::draw_drag_circle(SkCanvas* canvas, const Vector2f& sPos, const SkColor4f& c, const DrawData& drawData, float radiusMultiplier) {
|
||||
|
|
|
|||
|
|
@ -743,7 +743,7 @@ void DrawingProgramSelection::rebuild_cam_space() {
|
|||
}
|
||||
|
||||
Vector2f DrawingProgramSelection::get_rotation_point_pos_from_angle(double angle) {
|
||||
return Vector2f{rotateData.centerHandlePoint + ROTATION_POINTS_DISTANCE * drawP.world.main.toolbar.final_gui_scale() * Vector2f{std::cos(angle), std::sin(angle)}};
|
||||
return Vector2f{rotateData.centerHandlePoint + ROTATION_POINTS_DISTANCE * drawP.world.main.g.final_gui_scale() * Vector2f{std::cos(angle), std::sin(angle)}};
|
||||
}
|
||||
|
||||
void DrawingProgramSelection::draw_components(SkCanvas* canvas, const DrawData& drawData) {
|
||||
|
|
|
|||
|
|
@ -1,10 +1,20 @@
|
|||
#include "GUIHolder.hpp"
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include "MainProgram.hpp"
|
||||
|
||||
#include <include/core/SkStream.h>
|
||||
|
||||
GUIHolder::GUIHolder() {
|
||||
GUIHolder::GUIHolder(MainProgram& m):
|
||||
main(m)
|
||||
{
|
||||
gui.io.textTypeface = main.fonts->map["Roboto"];
|
||||
gui.io.fonts = main.fonts;
|
||||
gui.io.layoutRun = [&] {
|
||||
main.toolbar.layout_run();
|
||||
};
|
||||
gui.io.input = &main.input;
|
||||
|
||||
// NOTE: On windows, when the native file picker is open, any call to MakeFromFile fails
|
||||
// So, it's better to load the icons at the beginning of the program so that the icon loading doesn't fail later
|
||||
load_icons_at("data/icons");
|
||||
|
|
@ -82,9 +92,31 @@ bool GUIHolder::load_theme(const std::filesystem::path& configPath, const std::s
|
|||
}
|
||||
|
||||
void GUIHolder::update() {
|
||||
gui.io.windowSize = main.window.size.cast<float>();
|
||||
gui.io.windowPos = {0, 0};
|
||||
calculate_final_gui_scale();
|
||||
gui.layout_if_necessary();
|
||||
}
|
||||
|
||||
void GUIHolder::draw(SkCanvas* canvas) {
|
||||
float GUIHolder::final_gui_scale() {
|
||||
return finalCalculatedGuiScale;
|
||||
}
|
||||
|
||||
void GUIHolder::calculate_final_gui_scale() {
|
||||
Vector2f maxWindowSizeBeforeForcedFit = final_gui_scale_not_fit() * Vector2f{700.0f, 700.0f};
|
||||
Vector2f fitRatio = {main.window.size.x() / maxWindowSizeBeforeForcedFit.x(), main.window.size.y() / maxWindowSizeBeforeForcedFit.y()};
|
||||
finalCalculatedGuiScale = final_gui_scale_not_fit() * std::min(std::min(fitRatio.x(), fitRatio.y()), 1.0f);
|
||||
}
|
||||
|
||||
float GUIHolder::final_gui_scale_not_fit() {
|
||||
return main.conf.guiScale * main.get_scale_and_density_factor_gui();
|
||||
}
|
||||
|
||||
void GUIHolder::draw(SkCanvas* canvas, bool skiaAA) {
|
||||
canvas->save();
|
||||
canvas->scale(final_gui_scale(), final_gui_scale());
|
||||
gui.draw(canvas, skiaAA);
|
||||
canvas->restore();
|
||||
}
|
||||
|
||||
void GUIHolder::input_key_callback(const InputManager::KeyCallbackArgs& key) {
|
||||
|
|
|
|||
|
|
@ -2,9 +2,11 @@
|
|||
|
||||
#include "GUIStuff/GUIManager.hpp"
|
||||
|
||||
class MainProgram;
|
||||
|
||||
class GUIHolder {
|
||||
public:
|
||||
GUIHolder();
|
||||
GUIHolder(MainProgram& m);
|
||||
|
||||
GUIStuff::GUIManager gui;
|
||||
|
||||
|
|
@ -14,11 +16,20 @@ class GUIHolder {
|
|||
bool load_theme(const std::filesystem::path& configPath, const std::string& themeName);
|
||||
|
||||
void update();
|
||||
void draw(SkCanvas* canvas);
|
||||
void draw(SkCanvas* canvas, bool skiaAA);
|
||||
void input_key_callback(const InputManager::KeyCallbackArgs& key);
|
||||
void input_mouse_button_callback(const InputManager::MouseButtonCallbackArgs& button);
|
||||
void input_mouse_motion_callback(const InputManager::MouseMotionCallbackArgs& motion);
|
||||
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);
|
||||
|
||||
float final_gui_scale();
|
||||
private:
|
||||
void calculate_final_gui_scale();
|
||||
float final_gui_scale_not_fit();
|
||||
|
||||
float finalCalculatedGuiScale;
|
||||
|
||||
MainProgram& main;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -38,7 +38,8 @@
|
|||
MainProgram::MainProgram():
|
||||
input(*this),
|
||||
fonts(std::make_shared<FontData>()),
|
||||
toolbar(*this)
|
||||
toolbar(*this),
|
||||
g(*this)
|
||||
{
|
||||
Logger::get().add_log("WORLDFATAL", [&](const std::string& text) {
|
||||
*logFile << "[WORLDFATAL] " << text << std::endl;
|
||||
|
|
@ -99,7 +100,7 @@ void MainProgram::update() {
|
|||
w->unfocus_update();
|
||||
}
|
||||
|
||||
toolbar.update(); // GUI should be setup after the world data has been fully updated for this frame, so that the GUI reflects the current state of the world data
|
||||
g.update();
|
||||
|
||||
NetLibrary::update();
|
||||
|
||||
|
|
@ -290,6 +291,8 @@ void MainProgram::draw(SkCanvas* canvas, std::shared_ptr<World> worldToDraw, con
|
|||
DrawData drawDataCopy = drawData;
|
||||
drawDataCopy.skiaAA = conf.antialiasing == GlobalConfig::AntiAliasing::SKIA;
|
||||
worldToDraw->draw(canvas, drawDataCopy);
|
||||
if(drawGui)
|
||||
g.draw(canvas, drawDataCopy.skiaAA);
|
||||
}
|
||||
|
||||
sk_sp<SkSurface> MainProgram::create_native_surface(Vector2i resolution, bool isMSAA) {
|
||||
|
|
|
|||
|
|
@ -73,6 +73,7 @@ class MainProgram {
|
|||
std::shared_ptr<FontData> fonts;
|
||||
TimePoint deltaTime;
|
||||
Toolbar toolbar;
|
||||
GUIHolder g;
|
||||
std::shared_ptr<World> world;
|
||||
ToolConfiguration toolConfig;
|
||||
|
||||
|
|
@ -116,7 +117,6 @@ class MainProgram {
|
|||
size_t worldIndex = 0;
|
||||
std::vector<std::shared_ptr<World>> worlds;
|
||||
|
||||
GUIHolder g;
|
||||
GlobalConfig conf;
|
||||
|
||||
void input_drop_file_callback(const InputManager::DropCallbackArgs& drop);
|
||||
|
|
|
|||
|
|
@ -202,16 +202,6 @@ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR I
|
|||
)";
|
||||
}
|
||||
|
||||
void Toolbar::update() {
|
||||
auto& gui = main.g.gui;
|
||||
auto& io = gui.io;
|
||||
|
||||
calculate_final_gui_scale();
|
||||
io.windowSize = main.window.size.cast<float>();
|
||||
io.windowPos = {0, 0};
|
||||
gui.layout_if_necessary();
|
||||
}
|
||||
|
||||
void Toolbar::layout_run() {
|
||||
auto& gui = main.g.gui;
|
||||
auto& io = gui.io;
|
||||
|
|
@ -281,8 +271,6 @@ void Toolbar::layout_run() {
|
|||
|
||||
if(!optionsMenuOpen || generalSettingsOptions != GSETTINGS_KEYBINDS)
|
||||
keybindWaiting = std::nullopt;
|
||||
|
||||
calculate_final_gui_scale();
|
||||
}
|
||||
|
||||
bool Toolbar::app_close_requested() {
|
||||
|
|
@ -2179,17 +2167,3 @@ void Toolbar::file_picker_gui() {
|
|||
});
|
||||
});
|
||||
}
|
||||
|
||||
float Toolbar::final_gui_scale() {
|
||||
return finalCalculatedGuiScale;
|
||||
}
|
||||
|
||||
void Toolbar::calculate_final_gui_scale() {
|
||||
Vector2f maxWindowSizeBeforeForcedFit = final_gui_scale_not_fit() * Vector2f{700.0f, 700.0f};
|
||||
Vector2f fitRatio = {main.window.size.x() / maxWindowSizeBeforeForcedFit.x(), main.window.size.y() / maxWindowSizeBeforeForcedFit.y()};
|
||||
finalCalculatedGuiScale = final_gui_scale_not_fit() * std::min(std::min(fitRatio.x(), fitRatio.y()), 1.0f);
|
||||
}
|
||||
|
||||
float Toolbar::final_gui_scale_not_fit() {
|
||||
return main.conf.guiScale * main.get_scale_and_density_factor_gui();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,7 +40,6 @@ class Toolbar {
|
|||
std::string chatMessageInput;
|
||||
|
||||
Toolbar(MainProgram& initMain);
|
||||
void update();
|
||||
void layout_run();
|
||||
void color_selector_left(Vector4f* color);
|
||||
void color_selector_right(Vector4f* color);
|
||||
|
|
@ -63,14 +62,8 @@ class Toolbar {
|
|||
|
||||
std::optional<Vector2f> rightClickPopupLocation;
|
||||
|
||||
|
||||
float final_gui_scale();
|
||||
|
||||
bool app_close_requested();
|
||||
private:
|
||||
void calculate_final_gui_scale();
|
||||
float final_gui_scale_not_fit();
|
||||
|
||||
static void sdl_open_file_dialog_callback(void* userData, const char * const * fileList, int filter);
|
||||
|
||||
void text_button_wide(const char* id, const char* str, const std::function<void()>& onClick);
|
||||
|
|
|
|||
|
|
@ -353,12 +353,12 @@ void WorldGrid::draw_coordinates(SkCanvas* canvas, const DrawData& drawData, Vec
|
|||
|
||||
const WorldVec& worldWindowTopLeftClipPos = coordinatesAxisOnBounds ? bounds.value().min : drawData.cam.c.pos;
|
||||
SCollision::AABB<float> boundsCamSpace;
|
||||
float coordFontSize = drawData.main->toolbar.final_gui_scale() * drawData.main->g.gui.io.fontSize;
|
||||
float coordFontSize = drawData.main->g.final_gui_scale() * drawData.main->g.gui.io.fontSize;
|
||||
|
||||
if(coordinatesAxisOnBounds)
|
||||
boundsCamSpace = SCollision::AABB<float>(drawData.cam.c.to_space(bounds.value().min), drawData.cam.c.to_space(bounds.value().max));
|
||||
else {
|
||||
float toolbarXLength = drawData.main->drawGui ? drawData.main->toolbar.final_gui_scale() * (50.0f + drawData.main->g.gui.io.theme->padding1 * 3.0f) : 0.0f;
|
||||
float toolbarXLength = drawData.main->drawGui ? drawData.main->g.final_gui_scale() * (50.0f + drawData.main->g.gui.io.theme->padding1 * 3.0f) : 0.0f;
|
||||
boundsCamSpace = SCollision::AABB<float>({toolbarXLength + axisOffset.x(), 0.0f}, {drawData.cam.viewingArea.x(), drawData.cam.viewingArea.y() - axisOffset.y()});
|
||||
if(boundsCamSpace.width() < 100.0f || boundsCamSpace.height() < 100.0f)
|
||||
return;
|
||||
|
|
@ -434,7 +434,7 @@ void WorldGrid::draw_coordinates(SkCanvas* canvas, const DrawData& drawData, Vec
|
|||
|
||||
bool labelsTooClose = false;
|
||||
for(size_t i = 1; i < xAxisLabels.size(); i++) {
|
||||
if(xAxisLabels[i - 1].mainPos + xAxisLabels[i - 1].totalLength >= xAxisLabels[i].mainPos - 10.0f * drawData.main->toolbar.final_gui_scale()) {
|
||||
if(xAxisLabels[i - 1].mainPos + xAxisLabels[i - 1].totalLength >= xAxisLabels[i].mainPos - 10.0f * drawData.main->g.final_gui_scale()) {
|
||||
divWorldSize *= WorldScalar(2);
|
||||
gridCoordDivSize *= WorldScalar(2);
|
||||
calculateCoordMultipliers();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue