Fixed screenshot tool
This commit is contained in:
parent
695393392f
commit
26c9be8318
5 changed files with 52 additions and 20 deletions
|
|
@ -61,11 +61,25 @@ void ScreenshotTool::gui_toolbox() {
|
|||
auto& screenshotConfig = drawP.world.main.toolConfig.screenshot;
|
||||
gui.new_id("screenshot tool", [&] {
|
||||
text_label_centered(gui, "Screenshot");
|
||||
auto oldImgSize = controls.imageSize;
|
||||
if(controls.selectionMode == ScreenshotControls::SelectionMode::NO_SELECTION)
|
||||
text_label(gui, "Select an area on the canvas...");
|
||||
if(controls.selectionMode != ScreenshotControls::SelectionMode::NO_SELECTION && screenshotConfig.selectedType != SCREENSHOT_SVG)
|
||||
input_scalars_field(gui, "Image Size", "Image Size", &controls.imageSize, 2, 0, 999999999);
|
||||
if(controls.selectionMode != ScreenshotControls::SelectionMode::NO_SELECTION && screenshotConfig.selectedType != SCREENSHOT_SVG) {
|
||||
input_scalars_field(gui, "Image Size", "Image Size", &controls.imageSize, 2, 0, 999999999, {
|
||||
.onEdit = [&] (size_t i) {
|
||||
if(i == 0) {
|
||||
screenshotConfig.setDimensionSize = controls.imageSize.x();
|
||||
screenshotConfig.setDimensionIsX = true;
|
||||
controls.imageSize.y() = controls.imageSize.x() * (controls.rectY2 - controls.rectY1) / (controls.rectX2 - controls.rectX1);
|
||||
}
|
||||
else {
|
||||
screenshotConfig.setDimensionSize = controls.imageSize.y();
|
||||
screenshotConfig.setDimensionIsX = false;
|
||||
controls.imageSize.x() = controls.imageSize.y() * (controls.rectX2 - controls.rectX1) / (controls.rectY2 - controls.rectY1);
|
||||
}
|
||||
gui.set_to_layout();
|
||||
}
|
||||
});
|
||||
}
|
||||
if(controls.selectionMode == ScreenshotControls::SelectionMode::SELECTION_EXISTS) {
|
||||
left_to_right_line_layout(gui, [&]() {
|
||||
text_label(gui, "Image Type");
|
||||
|
|
@ -77,16 +91,6 @@ void ScreenshotTool::gui_toolbox() {
|
|||
text_label(gui, "Note: Screenshot will ignore blend\nmodes and layer alpha");
|
||||
if(screenshotConfig.selectedType != 0)
|
||||
checkbox_boolean_field(gui, "Transparent Background", "Transparent Background", &controls.transparentBackground);
|
||||
if(controls.imageSize.x() != oldImgSize.x()) {
|
||||
screenshotConfig.setDimensionSize = controls.imageSize.x();
|
||||
screenshotConfig.setDimensionIsX = true;
|
||||
controls.imageSize.y() = controls.imageSize.x() * (controls.rectY2 - controls.rectY1) / (controls.rectX2 - controls.rectX1);
|
||||
}
|
||||
else if(controls.imageSize.y() != oldImgSize.y()) {
|
||||
screenshotConfig.setDimensionSize = controls.imageSize.y();
|
||||
screenshotConfig.setDimensionIsX = false;
|
||||
controls.imageSize.x() = controls.imageSize.y() * (controls.rectX2 - controls.rectX1) / (controls.rectY2 - controls.rectY1);
|
||||
}
|
||||
text_button(gui, "Take Screenshot", "Take Screenshot", {
|
||||
.wide = true,
|
||||
.onClick = [&] {
|
||||
|
|
@ -141,6 +145,7 @@ void ScreenshotTool::input_mouse_button_on_canvas_callback(const InputManager::M
|
|||
controls.coords = drawP.world.drawData.cam.c;
|
||||
controls.dragType = 0;
|
||||
controls.selectionMode = ScreenshotControls::SelectionMode::DRAGGING_BORDER;
|
||||
drawP.world.main.g.gui.set_to_layout();
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
@ -148,6 +153,7 @@ void ScreenshotTool::input_mouse_button_on_canvas_callback(const InputManager::M
|
|||
if(!button.down && dragging_border_update(button.pos)) {
|
||||
controls.selectionMode = ScreenshotControls::SelectionMode::SELECTION_EXISTS;
|
||||
commit_rect();
|
||||
drawP.world.main.g.gui.set_to_layout();
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
@ -172,6 +178,7 @@ void ScreenshotTool::input_mouse_button_on_canvas_callback(const InputManager::M
|
|||
}
|
||||
else
|
||||
controls.selectionMode = ScreenshotControls::SelectionMode::DRAGGING_BORDER;
|
||||
drawP.world.main.g.gui.set_to_layout();
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
@ -179,6 +186,7 @@ void ScreenshotTool::input_mouse_button_on_canvas_callback(const InputManager::M
|
|||
if(!button.down && dragging_border_update(button.pos)) {
|
||||
controls.selectionMode = ScreenshotControls::SelectionMode::SELECTION_EXISTS;
|
||||
commit_rect();
|
||||
drawP.world.main.g.gui.set_to_layout();
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
@ -193,6 +201,7 @@ void ScreenshotTool::input_mouse_motion_callback(const InputManager::MouseMotion
|
|||
}
|
||||
case ScreenshotControls::SelectionMode::DRAGGING_BORDER: {
|
||||
dragging_border_update(motion.pos);
|
||||
drawP.world.main.g.gui.set_to_layout();
|
||||
break;
|
||||
}
|
||||
case ScreenshotControls::SelectionMode::SELECTION_EXISTS: {
|
||||
|
|
|
|||
|
|
@ -36,6 +36,16 @@ struct TextBoxScalarOptions {
|
|||
std::function<void()> onDeselect;
|
||||
};
|
||||
|
||||
struct TextBoxScalarsOptions {
|
||||
int decimalPrecision = 0;
|
||||
bool updateEveryEdit = false;
|
||||
bool immutable = false;
|
||||
std::function<void(size_t)> onEnter;
|
||||
std::function<void(size_t)> onEdit;
|
||||
std::function<void(size_t)> onSelect;
|
||||
std::function<void(size_t)> onDeselect;
|
||||
};
|
||||
|
||||
struct TextBoxPathOptions {
|
||||
std::filesystem::file_type fileTypeRestriction;
|
||||
bool updateEveryEdit = false;
|
||||
|
|
@ -105,12 +115,21 @@ template <typename T> void input_scalar(GUIManager& gui, const char* id, T* val,
|
|||
|
||||
template <> void input_scalar<uint8_t>(GUIManager& gui, const char* id, uint8_t* val, uint8_t minVal, uint8_t maxVal, const TextBoxScalarOptions& options);
|
||||
|
||||
template <typename TContainer, typename T> void input_scalars_field(GUIManager& gui, const char* id, std::string_view name, TContainer* val, size_t elemCount, T minVal, T maxVal, const TextBoxScalarOptions& options = {}) {
|
||||
template <typename TContainer, typename T> void input_scalars_field(GUIManager& gui, const char* id, std::string_view name, TContainer* val, size_t elemCount, T minVal, T maxVal, const TextBoxScalarsOptions& options = {}) {
|
||||
gui.new_id(id, [&] {
|
||||
left_to_right_line_layout(gui, [&]() {
|
||||
text_label(gui, name);
|
||||
for(size_t i = 0; i < elemCount; i++)
|
||||
gui.new_id(i, [&] { input_scalar<T>(gui, "field", &(*val)[i], minVal, maxVal, options); });
|
||||
for(size_t i = 0; i < elemCount; i++) {
|
||||
gui.new_id(i, [&] { input_scalar<T>(gui, "field", &(*val)[i], minVal, maxVal, TextBoxScalarOptions {
|
||||
.decimalPrecision = options.decimalPrecision,
|
||||
.updateEveryEdit = options.updateEveryEdit,
|
||||
.immutable = options.immutable,
|
||||
.onEnter = [f = options.onEnter, i] { if(f) f(i); },
|
||||
.onEdit = [f = options.onEdit, i] { if(f) f(i); },
|
||||
.onSelect = [f = options.onSelect, i] { if(f) f(i); },
|
||||
.onDeselect = [f = options.onDeselect, i] { if(f) f(i); },
|
||||
}); });
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -123,7 +123,7 @@ template <typename T> class DropDown : public Element {
|
|||
gui.set_post_callback_func([&, i] {
|
||||
*d = i;
|
||||
isOpen = false;
|
||||
opts.onClick();
|
||||
if(opts.onClick) opts.onClick();
|
||||
});
|
||||
gui.set_to_layout();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -291,7 +291,7 @@ 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)
|
||||
if(!drawData.takingScreenshot)
|
||||
g.draw(canvas, drawDataCopy.skiaAA);
|
||||
}
|
||||
|
||||
|
|
@ -364,8 +364,10 @@ void MainProgram::input_drop_text_callback(const InputManager::DropCallbackArgs&
|
|||
void MainProgram::input_key_callback(const InputManager::KeyCallbackArgs& key) {
|
||||
switch(key.key) {
|
||||
case InputManager::KEY_NOGUI: {
|
||||
if(key.down && !key.repeat)
|
||||
if(key.down && !key.repeat) {
|
||||
drawGui = !drawGui;
|
||||
g.gui.set_to_layout();
|
||||
}
|
||||
break;
|
||||
}
|
||||
case InputManager::KEY_FULLSCREEN: {
|
||||
|
|
|
|||
|
|
@ -295,6 +295,9 @@ void Toolbar::layout_run() {
|
|||
close_popup_gui();
|
||||
}
|
||||
|
||||
if(!main.world->clientStillConnecting)
|
||||
main.world->drawProg.right_click_popup_gui();
|
||||
|
||||
// Make sure theyre set to null in case drawing_program_gui wasn't called
|
||||
colorLeftJustEnabled = nullptr;
|
||||
colorLeftJustDisabled = false;
|
||||
|
|
@ -1218,7 +1221,6 @@ void Toolbar::drawing_program_gui() {
|
|||
color_picker_window("Drawing program gui color picker right", &colorRight, &colorRightJustDisabled, colorRightData);
|
||||
|
||||
main.world->drawProg.tool_options_gui();
|
||||
main.world->drawProg.right_click_popup_gui();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue