More GUI code moved to events, code now compiles but application doesn't run
This commit is contained in:
parent
3566b7e563
commit
b4c35124c3
37 changed files with 913 additions and 879 deletions
|
|
@ -4,25 +4,26 @@
|
|||
#include "../../../MainProgram.hpp"
|
||||
#include "../EditTool.hpp"
|
||||
|
||||
#include "../../../GUIStuff/ElementHelpers/TextLabelHelpers.hpp"
|
||||
#include "../../../GUIStuff/ElementHelpers/LayoutHelpers.hpp"
|
||||
|
||||
BrushEditTool::BrushEditTool(DrawingProgram& initDrawP):
|
||||
DrawingProgramEditToolBase(initDrawP)
|
||||
{}
|
||||
|
||||
bool BrushEditTool::edit_gui(CanvasComponentContainer::ObjInfo* comp) {
|
||||
auto& a = static_cast<BrushStrokeCanvasComponent&>(comp->obj->get_comp());
|
||||
void BrushEditTool::edit_gui(CanvasComponentContainer::ObjInfo* comp) {
|
||||
using namespace GUIStuff;
|
||||
using namespace ElementHelpers;
|
||||
|
||||
Toolbar& t = drawP.world.main.toolbar;
|
||||
t.gui.push_id("edit tool brush");
|
||||
t.gui.text_label_centered("Edit Brush Stroke");
|
||||
t.gui.left_to_right_line_layout([&]() {
|
||||
if(t.gui.color_button_big("Outline Color", &a.d.color, &a.d.color == t.colorRight))
|
||||
t.color_selector_right(&a.d.color == t.colorRight ? nullptr : &a.d.color);
|
||||
t.gui.text_label("Outline Color");
|
||||
text_label_centered(t.gui, "Edit Brush Stroke");
|
||||
left_to_right_line_layout(t.gui, [&]() {
|
||||
//if(t.gui.color_button_big("Outline Color", &a.d.color, &a.d.color == t.colorRight))
|
||||
// t.color_selector_right(&a.d.color == t.colorRight ? nullptr : &a.d.color);
|
||||
text_label(t.gui, "Outline Color");
|
||||
});
|
||||
t.gui.pop_id();
|
||||
|
||||
bool editHappened = a.d.color != oldColor;
|
||||
oldColor = a.d.color;
|
||||
return editHappened;
|
||||
}
|
||||
|
||||
void BrushEditTool::edit_start(EditTool& editTool, CanvasComponentContainer::ObjInfo* comp, std::any& prevData) {
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ class BrushEditTool : public DrawingProgramEditToolBase {
|
|||
virtual void edit_start(EditTool& editTool, CanvasComponentContainer::ObjInfo* comp, std::any& prevData) override;
|
||||
virtual void commit_edit_updates(CanvasComponentContainer::ObjInfo* comp, std::any& prevData) override;
|
||||
virtual bool edit_update(CanvasComponentContainer::ObjInfo* comp) override;
|
||||
virtual bool edit_gui(CanvasComponentContainer::ObjInfo* comp) override;
|
||||
virtual void edit_gui(CanvasComponentContainer::ObjInfo* comp) override;
|
||||
private:
|
||||
Vector4f oldColor;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -5,10 +5,9 @@ DrawingProgramEditToolBase::DrawingProgramEditToolBase(DrawingProgram& initDrawP
|
|||
drawP(initDrawP)
|
||||
{}
|
||||
|
||||
bool DrawingProgramEditToolBase::right_click_popup_gui(CanvasComponentContainer::ObjInfo* comp, Vector2f popupPos) {
|
||||
void DrawingProgramEditToolBase::right_click_popup_gui(CanvasComponentContainer::ObjInfo* comp, Vector2f popupPos) {
|
||||
Toolbar& t = drawP.world.main.toolbar;
|
||||
t.paint_popup(popupPos);
|
||||
return true;
|
||||
}
|
||||
|
||||
void DrawingProgramEditToolBase::input_key_callback(CanvasComponentContainer::ObjInfo* comp, const InputManager::KeyCallbackArgs& key) {}
|
||||
|
|
|
|||
|
|
@ -12,8 +12,8 @@ class DrawingProgramEditToolBase {
|
|||
virtual void edit_start(EditTool& editTool, CanvasComponentContainer::ObjInfo* compContainer, std::any& prevData) = 0;
|
||||
virtual void commit_edit_updates(CanvasComponentContainer::ObjInfo* compContainer, std::any& prevData) = 0;
|
||||
virtual bool edit_update(CanvasComponentContainer::ObjInfo* compContainer) = 0;
|
||||
virtual bool edit_gui(CanvasComponentContainer::ObjInfo* compContainer) = 0;
|
||||
virtual bool right_click_popup_gui(CanvasComponentContainer::ObjInfo* comp, Vector2f popupPos);
|
||||
virtual void edit_gui(CanvasComponentContainer::ObjInfo* compContainer) = 0;
|
||||
virtual void right_click_popup_gui(CanvasComponentContainer::ObjInfo* comp, Vector2f popupPos);
|
||||
virtual void input_key_callback(CanvasComponentContainer::ObjInfo* comp, const InputManager::KeyCallbackArgs& key);
|
||||
virtual void input_mouse_button_on_canvas_callback(CanvasComponentContainer::ObjInfo* comp, const InputManager::MouseButtonCallbackArgs& button, bool isDraggingPoint);
|
||||
virtual void input_mouse_motion_callback(CanvasComponentContainer::ObjInfo* comp, const InputManager::MouseMotionCallbackArgs& motion, bool isDraggingPoint);
|
||||
|
|
|
|||
|
|
@ -7,39 +7,45 @@
|
|||
#include <memory>
|
||||
#include "../EditTool.hpp"
|
||||
|
||||
#include "../../../GUIStuff/ElementHelpers/TextLabelHelpers.hpp"
|
||||
#include "../../../GUIStuff/ElementHelpers/RadioButtonHelpers.hpp"
|
||||
#include "../../../GUIStuff/ElementHelpers/LayoutHelpers.hpp"
|
||||
#include "../../../GUIStuff/ElementHelpers/NumberSliderHelpers.hpp"
|
||||
|
||||
EllipseDrawEditTool::EllipseDrawEditTool(DrawingProgram& initDrawP):
|
||||
DrawingProgramEditToolBase(initDrawP)
|
||||
{}
|
||||
|
||||
bool EllipseDrawEditTool::edit_gui(CanvasComponentContainer::ObjInfo* comp) {
|
||||
void EllipseDrawEditTool::edit_gui(CanvasComponentContainer::ObjInfo* comp) {
|
||||
using namespace GUIStuff;
|
||||
using namespace ElementHelpers;
|
||||
|
||||
auto& a = static_cast<EllipseCanvasComponent&>(comp->obj->get_comp());
|
||||
|
||||
Toolbar& t = drawP.world.main.toolbar;
|
||||
t.gui.push_id("edit tool ellipse");
|
||||
t.gui.text_label_centered("Edit Ellipse");
|
||||
if(t.gui.radio_button_field("fillonly", "Fill only", a.d.fillStrokeMode == 0)) a.d.fillStrokeMode = 0;
|
||||
if(t.gui.radio_button_field("outlineonly", "Outline only", a.d.fillStrokeMode == 1)) a.d.fillStrokeMode = 1;
|
||||
if(t.gui.radio_button_field("filloutline", "Fill and Outline", a.d.fillStrokeMode == 2)) a.d.fillStrokeMode = 2;
|
||||
text_label_centered(t.gui, "Edit Ellipse");
|
||||
radio_button_selector(t.gui, "Fill selector", &a.d.fillStrokeMode, {
|
||||
{"Fill only", 0},
|
||||
{"Outline only", 1},
|
||||
{"Fill and outline", 2}
|
||||
});
|
||||
if(a.d.fillStrokeMode == 0 || a.d.fillStrokeMode == 2) {
|
||||
t.gui.left_to_right_line_layout([&]() {
|
||||
if(t.gui.color_button_big("Fill Color", &a.d.fillColor, &a.d.fillColor == t.colorRight))
|
||||
t.color_selector_right(&a.d.fillColor == t.colorRight ? nullptr : &a.d.fillColor);
|
||||
t.gui.text_label("Fill Color");
|
||||
left_to_right_line_layout(t.gui, [&] {
|
||||
//if(t.gui.color_button_big("Fill Color", &a.d.fillColor, &a.d.fillColor == t.colorRight))
|
||||
// t.color_selector_right(&a.d.fillColor == t.colorRight ? nullptr : &a.d.fillColor);
|
||||
text_label(t.gui, "Fill Color");
|
||||
});
|
||||
}
|
||||
if(a.d.fillStrokeMode == 1 || a.d.fillStrokeMode == 2) {
|
||||
t.gui.slider_scalar_field("relstrokewidth", "Outline Size", &a.d.strokeWidth, 3.0f, 40.0f);
|
||||
t.gui.left_to_right_line_layout([&]() {
|
||||
if(t.gui.color_button_big("Outline Color", &a.d.strokeColor, &a.d.strokeColor == t.colorRight))
|
||||
t.color_selector_right(&a.d.strokeColor == t.colorRight ? nullptr : &a.d.strokeColor);
|
||||
t.gui.text_label("Outline Color");
|
||||
slider_scalar_field(t.gui, "relstrokewidth", "Outline Size", &a.d.strokeWidth, 3.0f, 40.0f);
|
||||
left_to_right_line_layout(t.gui, [&] {
|
||||
//if(t.gui.color_button_big("Outline Color", &a.d.strokeColor, &a.d.strokeColor == t.colorRight))
|
||||
// t.color_selector_right(&a.d.strokeColor == t.colorRight ? nullptr : &a.d.strokeColor);
|
||||
text_label(t.gui, "Outline Color");
|
||||
});
|
||||
}
|
||||
t.gui.pop_id();
|
||||
|
||||
bool editHappened = (!oldData.has_value()) || (a.d != oldData);
|
||||
oldData = a.d;
|
||||
return editHappened;
|
||||
}
|
||||
|
||||
void EllipseDrawEditTool::edit_start(EditTool& editTool, CanvasComponentContainer::ObjInfo* comp, std::any& prevData) {
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ class EllipseDrawEditTool : public DrawingProgramEditToolBase {
|
|||
virtual void edit_start(EditTool& editTool, CanvasComponentContainer::ObjInfo* comp, std::any& prevData) override;
|
||||
virtual void commit_edit_updates(CanvasComponentContainer::ObjInfo* comp, std::any& prevData) override;
|
||||
virtual bool edit_update(CanvasComponentContainer::ObjInfo* comp) override;
|
||||
virtual bool edit_gui(CanvasComponentContainer::ObjInfo* comp) override;
|
||||
virtual void edit_gui(CanvasComponentContainer::ObjInfo* comp) override;
|
||||
private:
|
||||
void commit();
|
||||
|
||||
|
|
|
|||
|
|
@ -10,6 +10,9 @@
|
|||
#include "Eigen/Geometry"
|
||||
#include <fstream>
|
||||
|
||||
#include "../../../GUIStuff/ElementHelpers/TextLabelHelpers.hpp"
|
||||
#include "../../../GUIStuff/ElementHelpers/ButtonHelpers.hpp"
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
#include <EmscriptenHelpers/emscripten_browser_file.h>
|
||||
#endif
|
||||
|
|
@ -42,30 +45,35 @@ bool ImageEditTool::edit_update(CanvasComponentContainer::ObjInfo* comp) {
|
|||
return true;
|
||||
}
|
||||
|
||||
bool ImageEditTool::edit_gui(CanvasComponentContainer::ObjInfo* comp) {
|
||||
void ImageEditTool::edit_gui(CanvasComponentContainer::ObjInfo* comp) {
|
||||
using namespace GUIStuff;
|
||||
using namespace ElementHelpers;
|
||||
|
||||
ImageCanvasComponent& a = static_cast<ImageCanvasComponent&>(comp->obj->get_comp());
|
||||
Toolbar& t = drawP.world.main.toolbar;
|
||||
t.gui.push_id("edit tool image");
|
||||
t.gui.text_label_centered("File Properties");
|
||||
text_label_centered(t.gui, "File Properties");
|
||||
auto resourceData = drawP.world.netObjMan.get_obj_temporary_ref_from_id<ResourceData>(a.d.imageID);
|
||||
|
||||
if(resourceData) {
|
||||
t.gui.text_label("Name: " + resourceData->name);
|
||||
if(t.gui.text_button_wide("file download", "Download file")) {
|
||||
#ifdef __EMSCRIPTEN__
|
||||
emscripten_browser_file::download(
|
||||
resourceData->name,
|
||||
"application/octet-binary",
|
||||
*resourceData->data
|
||||
);
|
||||
#endif
|
||||
t.open_file_selector("Download File", {{"Any File", "*"}}, [resourceData](const std::filesystem::path& p, const auto& e) {
|
||||
SDL_SaveFile(p.c_str(), resourceData->data->c_str(), resourceData->data->size());
|
||||
}, resourceData->name, true);
|
||||
}
|
||||
text_label(t.gui, "Name: " + resourceData->name);
|
||||
text_button(t.gui, "file download", "Download file", {
|
||||
.wide = true,
|
||||
.onClick = [&] {
|
||||
#ifdef __EMSCRIPTEN__
|
||||
emscripten_browser_file::download(
|
||||
resourceData->name,
|
||||
"application/octet-binary",
|
||||
*resourceData->data
|
||||
);
|
||||
#endif
|
||||
t.open_file_selector("Download File", {{"Any File", "*"}}, [resourceData](const std::filesystem::path& p, const auto& e) {
|
||||
SDL_SaveFile(p.c_str(), resourceData->data->c_str(), resourceData->data->size());
|
||||
}, resourceData->name, true);
|
||||
}
|
||||
});
|
||||
}
|
||||
else
|
||||
t.gui.text_label_centered("Loading resource...");
|
||||
text_label_centered(t.gui, "Loading resource...");
|
||||
t.gui.pop_id();
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,5 +10,5 @@ class ImageEditTool : public DrawingProgramEditToolBase {
|
|||
virtual void edit_start(EditTool& editTool, CanvasComponentContainer::ObjInfo* comp, std::any& prevData) override;
|
||||
virtual void commit_edit_updates(CanvasComponentContainer::ObjInfo* comp, std::any& prevData) override;
|
||||
virtual bool edit_update(CanvasComponentContainer::ObjInfo* comp) override;
|
||||
virtual bool edit_gui(CanvasComponentContainer::ObjInfo* comp) override;
|
||||
virtual void edit_gui(CanvasComponentContainer::ObjInfo* comp) override;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -5,39 +5,44 @@
|
|||
#include <memory>
|
||||
#include "../EditTool.hpp"
|
||||
|
||||
#include "../../../GUIStuff/ElementHelpers/NumberSliderHelpers.hpp"
|
||||
#include "../../../GUIStuff/ElementHelpers/TextLabelHelpers.hpp"
|
||||
#include "../../../GUIStuff/ElementHelpers/RadioButtonHelpers.hpp"
|
||||
|
||||
RectDrawEditTool::RectDrawEditTool(DrawingProgram& initDrawP):
|
||||
DrawingProgramEditToolBase(initDrawP)
|
||||
{}
|
||||
|
||||
bool RectDrawEditTool::edit_gui(CanvasComponentContainer::ObjInfo* comp) {
|
||||
void RectDrawEditTool::edit_gui(CanvasComponentContainer::ObjInfo* comp) {
|
||||
using namespace GUIStuff;
|
||||
using namespace ElementHelpers;
|
||||
|
||||
auto& a = static_cast<RectangleCanvasComponent&>(comp->obj->get_comp());
|
||||
Toolbar& t = drawP.world.main.toolbar;
|
||||
t.gui.push_id("edit tool rectangle");
|
||||
t.gui.text_label_centered("Edit Rectangle");
|
||||
t.gui.slider_scalar_field("relradiuswidth", "Corner Radius", &a.d.cornerRadius, 0.0f, 40.0f);
|
||||
if(t.gui.radio_button_field("fillonly", "Fill only", a.d.fillStrokeMode == 0)) a.d.fillStrokeMode = 0;
|
||||
if(t.gui.radio_button_field("outlineonly", "Outline only", a.d.fillStrokeMode == 1)) a.d.fillStrokeMode = 1;
|
||||
if(t.gui.radio_button_field("filloutline", "Fill and Outline", a.d.fillStrokeMode == 2)) a.d.fillStrokeMode = 2;
|
||||
text_label_centered(t.gui, "Edit Rectangle");
|
||||
slider_scalar_field(t.gui, "relradiuswidth", "Corner Radius", &a.d.cornerRadius, 0.0f, 40.0f);
|
||||
radio_button_selector(t.gui, "Fill selector", &a.d.fillStrokeMode, {
|
||||
{"Fill only", 0},
|
||||
{"Outline only", 1},
|
||||
{"Fill and outline", 2}
|
||||
});
|
||||
if(a.d.fillStrokeMode == 0 || a.d.fillStrokeMode == 2) {
|
||||
t.gui.left_to_right_line_layout([&]() {
|
||||
if(t.gui.color_button_big("Fill Color", &a.d.fillColor, &a.d.fillColor == t.colorRight))
|
||||
t.color_selector_right(&a.d.fillColor == t.colorRight ? nullptr : &a.d.fillColor);
|
||||
t.gui.text_label("Fill Color");
|
||||
left_to_right_line_layout(t.gui, [&] {
|
||||
//if(t.gui.color_button_big("Fill Color", &a.d.fillColor, &a.d.fillColor == t.colorRight))
|
||||
// t.color_selector_right(&a.d.fillColor == t.colorRight ? nullptr : &a.d.fillColor);
|
||||
text_label(t.gui, "Fill Color");
|
||||
});
|
||||
}
|
||||
if(a.d.fillStrokeMode == 1 || a.d.fillStrokeMode == 2) {
|
||||
t.gui.slider_scalar_field("relstrokewidth", "Outline Size", &a.d.strokeWidth, 3.0f, 40.0f);
|
||||
t.gui.left_to_right_line_layout([&]() {
|
||||
if(t.gui.color_button_big("Outline Color", &a.d.strokeColor, &a.d.strokeColor == t.colorRight))
|
||||
t.color_selector_right(&a.d.strokeColor == t.colorRight ? nullptr : &a.d.strokeColor);
|
||||
t.gui.text_label("Outline Color");
|
||||
slider_scalar_field(t.gui, "relstrokewidth", "Outline Size", &a.d.strokeWidth, 3.0f, 40.0f);
|
||||
left_to_right_line_layout(t.gui, [&] {
|
||||
//if(t.gui.color_button_big("Outline Color", &a.d.strokeColor, &a.d.strokeColor == t.colorRight))
|
||||
// t.color_selector_right(&a.d.strokeColor == t.colorRight ? nullptr : &a.d.strokeColor);
|
||||
text_label(t.gui, "Outline Color");
|
||||
});
|
||||
}
|
||||
t.gui.pop_id();
|
||||
|
||||
bool editHappened = (!oldData.has_value()) || (a.d != oldData);
|
||||
oldData = a.d;
|
||||
return editHappened;
|
||||
}
|
||||
|
||||
void RectDrawEditTool::edit_start(EditTool& editTool, CanvasComponentContainer::ObjInfo* comp, std::any& prevData) {
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ class RectDrawEditTool : public DrawingProgramEditToolBase {
|
|||
virtual void edit_start(EditTool& editTool, CanvasComponentContainer::ObjInfo* comp, std::any& prevData) override;
|
||||
virtual void commit_edit_updates(CanvasComponentContainer::ObjInfo* comp, std::any& prevData) override;
|
||||
virtual bool edit_update(CanvasComponentContainer::ObjInfo* comp) override;
|
||||
virtual bool edit_gui(CanvasComponentContainer::ObjInfo* comp) override;
|
||||
virtual void edit_gui(CanvasComponentContainer::ObjInfo* comp) override;
|
||||
private:
|
||||
std::optional<RectangleCanvasComponent::Data> oldData;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -14,142 +14,149 @@
|
|||
#include <memory>
|
||||
#include "../EditTool.hpp"
|
||||
|
||||
#include "../../../GUIStuff/ElementHelpers/TextLabelHelpers.hpp"
|
||||
#include "../../../GUIStuff/ElementHelpers/LayoutHelpers.hpp"
|
||||
#include "../../../GUIStuff/Elements/PositionAdjustingPopupMenu.hpp"
|
||||
|
||||
using namespace RichText;
|
||||
|
||||
TextBoxEditTool::TextBoxEditTool(DrawingProgram& initDrawP):
|
||||
DrawingProgramEditToolBase(initDrawP)
|
||||
{}
|
||||
|
||||
bool TextBoxEditTool::edit_gui(CanvasComponentContainer::ObjInfo* comp) {
|
||||
void TextBoxEditTool::edit_gui(CanvasComponentContainer::ObjInfo* comp) {
|
||||
using namespace GUIStuff;
|
||||
using namespace ElementHelpers;
|
||||
|
||||
auto& a = static_cast<TextBoxCanvasComponent&>(comp->obj->get_comp());
|
||||
Toolbar& t = drawP.world.main.toolbar;
|
||||
|
||||
auto& currentMods = *currentModsPtr;
|
||||
|
||||
t.gui.push_id("edit tool text");
|
||||
t.gui.text_label_centered("Edit Text");
|
||||
text_label_centered(t.gui, "Edit Text");
|
||||
|
||||
t.gui.left_to_right_line_layout([&]() {
|
||||
t.gui.text_label("Font");
|
||||
if(t.gui.font_picker("font picker", &newFontName)) {
|
||||
currentMods[TextStyleModifier::ModifierType::FONT_FAMILIES] = std::make_shared<FontFamiliesTextStyleModifier>(std::vector<SkString>{SkString{newFontName.c_str(), newFontName.size()}});
|
||||
add_undo_if_selecting_area(a, [&]() {a.textBox->set_text_style_modifier_between(a.cursor->selectionBeginPos, a.cursor->selectionEndPos, currentMods[TextStyleModifier::ModifierType::FONT_FAMILIES]);});
|
||||
}
|
||||
left_to_right_line_layout(t.gui, [&] {
|
||||
text_label(t.gui, "Font");
|
||||
//if(t.gui.font_picker("font picker", &newFontName)) {
|
||||
// currentMods[TextStyleModifier::ModifierType::FONT_FAMILIES] = std::make_shared<FontFamiliesTextStyleModifier>(std::vector<SkString>{SkString{newFontName.c_str(), newFontName.size()}});
|
||||
// add_undo_if_selecting_area(a, [&]() {a.textBox->set_text_style_modifier_between(a.cursor->selectionBeginPos, a.cursor->selectionEndPos, currentMods[TextStyleModifier::ModifierType::FONT_FAMILIES]);});
|
||||
//}
|
||||
});
|
||||
|
||||
t.gui.left_to_right_line_centered_layout([&]() {
|
||||
if(t.gui.svg_icon_button("Bold button", "data/icons/RemixIcon/bold.svg", newIsBold)) {
|
||||
newIsBold = !newIsBold;
|
||||
currentMods[TextStyleModifier::ModifierType::WEIGHT] = std::make_shared<WeightTextStyleModifier>(newIsBold ? SkFontStyle::Weight::kBold_Weight : SkFontStyle::Weight::kNormal_Weight);
|
||||
add_undo_if_selecting_area(a, [&]() {a.textBox->set_text_style_modifier_between(a.cursor->selectionBeginPos, a.cursor->selectionEndPos, currentMods[TextStyleModifier::ModifierType::WEIGHT]);});
|
||||
}
|
||||
//left_to_right_line_centered_layout(t.gui, [&] {
|
||||
// if(svg_icon_button("Bold button", "data/icons/RemixIcon/bold.svg", newIsBold)) {
|
||||
// newIsBold = !newIsBold;
|
||||
// currentMods[TextStyleModifier::ModifierType::WEIGHT] = std::make_shared<WeightTextStyleModifier>(newIsBold ? SkFontStyle::Weight::kBold_Weight : SkFontStyle::Weight::kNormal_Weight);
|
||||
// add_undo_if_selecting_area(a, [&]() {a.textBox->set_text_style_modifier_between(a.cursor->selectionBeginPos, a.cursor->selectionEndPos, currentMods[TextStyleModifier::ModifierType::WEIGHT]);});
|
||||
// }
|
||||
|
||||
if(t.gui.svg_icon_button("Italic button", "data/icons/RemixIcon/italic.svg", newIsItalic)) {
|
||||
newIsItalic = !newIsItalic;
|
||||
currentMods[TextStyleModifier::ModifierType::SLANT] = std::make_shared<SlantTextStyleModifier>(newIsItalic ? SkFontStyle::Slant::kItalic_Slant : SkFontStyle::Slant::kUpright_Slant);
|
||||
add_undo_if_selecting_area(a, [&]() {a.textBox->set_text_style_modifier_between(a.cursor->selectionBeginPos, a.cursor->selectionEndPos, currentMods[TextStyleModifier::ModifierType::SLANT]);});
|
||||
}
|
||||
// if(t.gui.svg_icon_button("Italic button", "data/icons/RemixIcon/italic.svg", newIsItalic)) {
|
||||
// newIsItalic = !newIsItalic;
|
||||
// currentMods[TextStyleModifier::ModifierType::SLANT] = std::make_shared<SlantTextStyleModifier>(newIsItalic ? SkFontStyle::Slant::kItalic_Slant : SkFontStyle::Slant::kUpright_Slant);
|
||||
// add_undo_if_selecting_area(a, [&]() {a.textBox->set_text_style_modifier_between(a.cursor->selectionBeginPos, a.cursor->selectionEndPos, currentMods[TextStyleModifier::ModifierType::SLANT]);});
|
||||
// }
|
||||
|
||||
bool decorationEdited = false;
|
||||
if(t.gui.svg_icon_button("Underline button", "data/icons/RemixIcon/underline.svg", newIsUnderlined)) {
|
||||
newIsUnderlined = !newIsUnderlined;
|
||||
decorationEdited = true;
|
||||
}
|
||||
if(t.gui.svg_icon_button("Strikethrough button", "data/icons/RemixIcon/strikethrough.svg", newIsLinethrough)) {
|
||||
newIsLinethrough = !newIsLinethrough;
|
||||
decorationEdited = true;
|
||||
}
|
||||
if(t.gui.svg_icon_button("Overline button", "data/icons/RemixIcon/overline.svg", newIsOverline)) {
|
||||
newIsOverline = !newIsOverline;
|
||||
decorationEdited = true;
|
||||
}
|
||||
if(decorationEdited) {
|
||||
currentMods[TextStyleModifier::ModifierType::DECORATION] = std::make_shared<DecorationTextStyleModifier>(get_new_decoration_value());
|
||||
add_undo_if_selecting_area(a, [&]() {a.textBox->set_text_style_modifier_between(a.cursor->selectionBeginPos, a.cursor->selectionEndPos, currentMods[TextStyleModifier::ModifierType::DECORATION]);});
|
||||
}
|
||||
});
|
||||
// bool decorationEdited = false;
|
||||
// if(t.gui.svg_icon_button("Underline button", "data/icons/RemixIcon/underline.svg", newIsUnderlined)) {
|
||||
// newIsUnderlined = !newIsUnderlined;
|
||||
// decorationEdited = true;
|
||||
// }
|
||||
// if(t.gui.svg_icon_button("Strikethrough button", "data/icons/RemixIcon/strikethrough.svg", newIsLinethrough)) {
|
||||
// newIsLinethrough = !newIsLinethrough;
|
||||
// decorationEdited = true;
|
||||
// }
|
||||
// if(t.gui.svg_icon_button("Overline button", "data/icons/RemixIcon/overline.svg", newIsOverline)) {
|
||||
// newIsOverline = !newIsOverline;
|
||||
// decorationEdited = true;
|
||||
// }
|
||||
// if(decorationEdited) {
|
||||
// currentMods[TextStyleModifier::ModifierType::DECORATION] = std::make_shared<DecorationTextStyleModifier>(get_new_decoration_value());
|
||||
// add_undo_if_selecting_area(a, [&]() {a.textBox->set_text_style_modifier_between(a.cursor->selectionBeginPos, a.cursor->selectionEndPos, currentMods[TextStyleModifier::ModifierType::DECORATION]);});
|
||||
// }
|
||||
//});
|
||||
|
||||
t.gui.left_to_right_line_centered_layout([&]() {
|
||||
if(t.gui.svg_icon_button("Align left button", "data/icons/RemixIcon/align-left.svg", currentPStyle.textAlignment == skia::textlayout::TextAlign::kLeft))
|
||||
add_undo([&](){a.textBox->set_text_alignment_between(a.cursor->selectionBeginPos.fParagraphIndex, a.cursor->selectionEndPos.fParagraphIndex, skia::textlayout::TextAlign::kLeft);});
|
||||
if(t.gui.svg_icon_button("Align center button", "data/icons/RemixIcon/align-center.svg", currentPStyle.textAlignment == skia::textlayout::TextAlign::kCenter))
|
||||
add_undo([&](){a.textBox->set_text_alignment_between(a.cursor->selectionBeginPos.fParagraphIndex, a.cursor->selectionEndPos.fParagraphIndex, skia::textlayout::TextAlign::kCenter);});
|
||||
if(t.gui.svg_icon_button("Align right button", "data/icons/RemixIcon/align-right.svg", currentPStyle.textAlignment == skia::textlayout::TextAlign::kRight))
|
||||
add_undo([&](){a.textBox->set_text_alignment_between(a.cursor->selectionBeginPos.fParagraphIndex, a.cursor->selectionEndPos.fParagraphIndex, skia::textlayout::TextAlign::kRight);});
|
||||
if(t.gui.svg_icon_button("Align justify button", "data/icons/RemixIcon/align-justify.svg", currentPStyle.textAlignment == skia::textlayout::TextAlign::kJustify))
|
||||
add_undo([&](){a.textBox->set_text_alignment_between(a.cursor->selectionBeginPos.fParagraphIndex, a.cursor->selectionEndPos.fParagraphIndex, skia::textlayout::TextAlign::kJustify);});
|
||||
if(t.gui.svg_icon_button("Text direction left", "data/icons/RemixIcon/text-direction-l.svg", currentPStyle.textDirection == skia::textlayout::TextDirection::kLtr))
|
||||
add_undo([&](){a.textBox->set_text_direction_between(a.cursor->selectionBeginPos.fParagraphIndex, a.cursor->selectionEndPos.fParagraphIndex, skia::textlayout::TextDirection::kLtr);});
|
||||
if(t.gui.svg_icon_button("Text direction right", "data/icons/RemixIcon/text-direction-r.svg", currentPStyle.textDirection == skia::textlayout::TextDirection::kRtl))
|
||||
add_undo([&](){a.textBox->set_text_direction_between(a.cursor->selectionBeginPos.fParagraphIndex, a.cursor->selectionEndPos.fParagraphIndex, skia::textlayout::TextDirection::kRtl);});
|
||||
});
|
||||
//t.gui.left_to_right_line_centered_layout([&]() {
|
||||
// if(t.gui.svg_icon_button("Align left button", "data/icons/RemixIcon/align-left.svg", currentPStyle.textAlignment == skia::textlayout::TextAlign::kLeft))
|
||||
// add_undo([&](){a.textBox->set_text_alignment_between(a.cursor->selectionBeginPos.fParagraphIndex, a.cursor->selectionEndPos.fParagraphIndex, skia::textlayout::TextAlign::kLeft);});
|
||||
// if(t.gui.svg_icon_button("Align center button", "data/icons/RemixIcon/align-center.svg", currentPStyle.textAlignment == skia::textlayout::TextAlign::kCenter))
|
||||
// add_undo([&](){a.textBox->set_text_alignment_between(a.cursor->selectionBeginPos.fParagraphIndex, a.cursor->selectionEndPos.fParagraphIndex, skia::textlayout::TextAlign::kCenter);});
|
||||
// if(t.gui.svg_icon_button("Align right button", "data/icons/RemixIcon/align-right.svg", currentPStyle.textAlignment == skia::textlayout::TextAlign::kRight))
|
||||
// add_undo([&](){a.textBox->set_text_alignment_between(a.cursor->selectionBeginPos.fParagraphIndex, a.cursor->selectionEndPos.fParagraphIndex, skia::textlayout::TextAlign::kRight);});
|
||||
// if(t.gui.svg_icon_button("Align justify button", "data/icons/RemixIcon/align-justify.svg", currentPStyle.textAlignment == skia::textlayout::TextAlign::kJustify))
|
||||
// add_undo([&](){a.textBox->set_text_alignment_between(a.cursor->selectionBeginPos.fParagraphIndex, a.cursor->selectionEndPos.fParagraphIndex, skia::textlayout::TextAlign::kJustify);});
|
||||
// if(t.gui.svg_icon_button("Text direction left", "data/icons/RemixIcon/text-direction-l.svg", currentPStyle.textDirection == skia::textlayout::TextDirection::kLtr))
|
||||
// add_undo([&](){a.textBox->set_text_direction_between(a.cursor->selectionBeginPos.fParagraphIndex, a.cursor->selectionEndPos.fParagraphIndex, skia::textlayout::TextDirection::kLtr);});
|
||||
// if(t.gui.svg_icon_button("Text direction right", "data/icons/RemixIcon/text-direction-r.svg", currentPStyle.textDirection == skia::textlayout::TextDirection::kRtl))
|
||||
// add_undo([&](){a.textBox->set_text_direction_between(a.cursor->selectionBeginPos.fParagraphIndex, a.cursor->selectionEndPos.fParagraphIndex, skia::textlayout::TextDirection::kRtl);});
|
||||
//});
|
||||
|
||||
if(t.gui.slider_scalar_field<uint32_t>("Font Size Slider", "Font Size", &newFontSize, 3, 100)) {
|
||||
hold_undo_data("Font Size", a);
|
||||
currentMods[TextStyleModifier::ModifierType::SIZE] = std::make_shared<SizeTextStyleModifier>(newFontSize);
|
||||
a.textBox->set_text_style_modifier_between(a.cursor->selectionBeginPos, a.cursor->selectionEndPos, currentMods[TextStyleModifier::ModifierType::SIZE]);
|
||||
}
|
||||
else
|
||||
release_undo_data("Font Size");
|
||||
//if(t.gui.slider_scalar_field<uint32_t>("Font Size Slider", "Font Size", &newFontSize, 3, 100)) {
|
||||
// hold_undo_data("Font Size", a);
|
||||
// currentMods[TextStyleModifier::ModifierType::SIZE] = std::make_shared<SizeTextStyleModifier>(newFontSize);
|
||||
// a.textBox->set_text_style_modifier_between(a.cursor->selectionBeginPos, a.cursor->selectionEndPos, currentMods[TextStyleModifier::ModifierType::SIZE]);
|
||||
//}
|
||||
//else
|
||||
// release_undo_data("Font Size");
|
||||
|
||||
// Text color
|
||||
t.gui.left_to_right_line_layout([&]() {
|
||||
if(t.gui.color_button_big("Text Color", &newTextColor, &newTextColor == t.colorRight))
|
||||
t.color_selector_right(&newTextColor == t.colorRight ? nullptr : &newTextColor);
|
||||
t.gui.text_label("Text Color");
|
||||
});
|
||||
//// Text color
|
||||
//t.gui.left_to_right_line_layout([&]() {
|
||||
// if(t.gui.color_button_big("Text Color", &newTextColor, &newTextColor == t.colorRight))
|
||||
// t.color_selector_right(&newTextColor == t.colorRight ? nullptr : &newTextColor);
|
||||
// t.gui.text_label("Text Color");
|
||||
//});
|
||||
|
||||
if(&newTextColor == t.colorRight)
|
||||
hold_undo_data("Text Color", a);
|
||||
else
|
||||
release_undo_data("Text Color");
|
||||
//if(&newTextColor == t.colorRight)
|
||||
// hold_undo_data("Text Color", a);
|
||||
//else
|
||||
// release_undo_data("Text Color");
|
||||
|
||||
if((&newTextColor == t.colorRight) && t.isUpdatingColorRight) {
|
||||
currentMods[TextStyleModifier::ModifierType::COLOR] = std::make_shared<ColorTextStyleModifier>(newTextColor);
|
||||
a.textBox->set_text_style_modifier_between(a.cursor->selectionBeginPos, a.cursor->selectionEndPos, currentMods[TextStyleModifier::ModifierType::COLOR]);
|
||||
}
|
||||
//if((&newTextColor == t.colorRight) && t.isUpdatingColorRight) {
|
||||
// currentMods[TextStyleModifier::ModifierType::COLOR] = std::make_shared<ColorTextStyleModifier>(newTextColor);
|
||||
// a.textBox->set_text_style_modifier_between(a.cursor->selectionBeginPos, a.cursor->selectionEndPos, currentMods[TextStyleModifier::ModifierType::COLOR]);
|
||||
//}
|
||||
|
||||
|
||||
|
||||
// Highlight color
|
||||
t.gui.left_to_right_line_layout([&]() {
|
||||
if(t.gui.color_button_big("Highlight Color", &newHighlightColor, &newHighlightColor == t.colorRight)) {
|
||||
if(newHighlightColor.w() == 0.0f) { // Make highlight appear when the button is pressed
|
||||
newHighlightColor.w() = 1.0f;
|
||||
currentMods[TextStyleModifier::ModifierType::HIGHLIGHT_COLOR] = std::make_shared<HighlightColorTextStyleModifier>(newHighlightColor);
|
||||
add_undo_if_selecting_area(a, [&]() {a.textBox->set_text_style_modifier_between(a.cursor->selectionBeginPos, a.cursor->selectionEndPos, currentMods[TextStyleModifier::ModifierType::HIGHLIGHT_COLOR]);});
|
||||
}
|
||||
t.color_selector_right(&newHighlightColor == t.colorRight ? nullptr : &newHighlightColor);
|
||||
}
|
||||
if(newHighlightColor.w() != 0.0f) {
|
||||
if(t.gui.svg_icon_button("Remove Highlight Color", "data/icons/close.svg")) {
|
||||
newHighlightColor = {0.0f, 0.0f, 0.0f, 0.0f};
|
||||
currentMods[TextStyleModifier::ModifierType::HIGHLIGHT_COLOR] = std::make_shared<HighlightColorTextStyleModifier>(newHighlightColor);
|
||||
add_undo_if_selecting_area(a, [&]() {a.textBox->set_text_style_modifier_between(a.cursor->selectionBeginPos, a.cursor->selectionEndPos, currentMods[TextStyleModifier::ModifierType::HIGHLIGHT_COLOR]);});
|
||||
}
|
||||
}
|
||||
t.gui.text_label("Highlight Color");
|
||||
});
|
||||
//// Highlight color
|
||||
//t.gui.left_to_right_line_layout([&]() {
|
||||
// if(t.gui.color_button_big("Highlight Color", &newHighlightColor, &newHighlightColor == t.colorRight)) {
|
||||
// if(newHighlightColor.w() == 0.0f) { // Make highlight appear when the button is pressed
|
||||
// newHighlightColor.w() = 1.0f;
|
||||
// currentMods[TextStyleModifier::ModifierType::HIGHLIGHT_COLOR] = std::make_shared<HighlightColorTextStyleModifier>(newHighlightColor);
|
||||
// add_undo_if_selecting_area(a, [&]() {a.textBox->set_text_style_modifier_between(a.cursor->selectionBeginPos, a.cursor->selectionEndPos, currentMods[TextStyleModifier::ModifierType::HIGHLIGHT_COLOR]);});
|
||||
// }
|
||||
// t.color_selector_right(&newHighlightColor == t.colorRight ? nullptr : &newHighlightColor);
|
||||
// }
|
||||
// if(newHighlightColor.w() != 0.0f) {
|
||||
// if(t.gui.svg_icon_button("Remove Highlight Color", "data/icons/close.svg")) {
|
||||
// newHighlightColor = {0.0f, 0.0f, 0.0f, 0.0f};
|
||||
// currentMods[TextStyleModifier::ModifierType::HIGHLIGHT_COLOR] = std::make_shared<HighlightColorTextStyleModifier>(newHighlightColor);
|
||||
// add_undo_if_selecting_area(a, [&]() {a.textBox->set_text_style_modifier_between(a.cursor->selectionBeginPos, a.cursor->selectionEndPos, currentMods[TextStyleModifier::ModifierType::HIGHLIGHT_COLOR]);});
|
||||
// }
|
||||
// }
|
||||
// t.gui.text_label("Highlight Color");
|
||||
//});
|
||||
|
||||
if(&newHighlightColor == t.colorRight)
|
||||
hold_undo_data("Highlight Color", a);
|
||||
else
|
||||
release_undo_data("Highlight Color");
|
||||
//if(&newHighlightColor == t.colorRight)
|
||||
// hold_undo_data("Highlight Color", a);
|
||||
//else
|
||||
// release_undo_data("Highlight Color");
|
||||
|
||||
if((&newHighlightColor == t.colorRight) && t.isUpdatingColorRight) {
|
||||
currentMods[TextStyleModifier::ModifierType::HIGHLIGHT_COLOR] = std::make_shared<HighlightColorTextStyleModifier>(newHighlightColor);
|
||||
a.textBox->set_text_style_modifier_between(a.cursor->selectionBeginPos, a.cursor->selectionEndPos, currentMods[TextStyleModifier::ModifierType::HIGHLIGHT_COLOR]);
|
||||
}
|
||||
//if((&newHighlightColor == t.colorRight) && t.isUpdatingColorRight) {
|
||||
// currentMods[TextStyleModifier::ModifierType::HIGHLIGHT_COLOR] = std::make_shared<HighlightColorTextStyleModifier>(newHighlightColor);
|
||||
// a.textBox->set_text_style_modifier_between(a.cursor->selectionBeginPos, a.cursor->selectionEndPos, currentMods[TextStyleModifier::ModifierType::HIGHLIGHT_COLOR]);
|
||||
//}
|
||||
|
||||
t.gui.pop_id();
|
||||
//t.gui.pop_id();
|
||||
|
||||
if(a.textBox->inputChangedTextBox)
|
||||
set_styles_at_selection(a);
|
||||
//if(a.textBox->inputChangedTextBox)
|
||||
// set_styles_at_selection(a);
|
||||
|
||||
// NOTE: There should be a system that periodically sends updates even if no changes are made, since unreliable channels can drop update data
|
||||
bool oldInputChangedTextBox = a.textBox->inputChangedTextBox;
|
||||
a.textBox->inputChangedTextBox = false;
|
||||
return oldInputChangedTextBox;
|
||||
//// NOTE: There should be a system that periodically sends updates even if no changes are made, since unreliable channels can drop update data
|
||||
//bool oldInputChangedTextBox = a.textBox->inputChangedTextBox;
|
||||
//a.textBox->inputChangedTextBox = false;
|
||||
//return oldInputChangedTextBox;
|
||||
}
|
||||
|
||||
void TextBoxEditTool::input_key_callback(CanvasComponentContainer::ObjInfo* comp, const InputManager::KeyCallbackArgs& key) {
|
||||
|
|
@ -188,35 +195,33 @@ void TextBoxEditTool::input_mouse_motion_callback(CanvasComponentContainer::ObjI
|
|||
}
|
||||
}
|
||||
|
||||
bool TextBoxEditTool::right_click_popup_gui(CanvasComponentContainer::ObjInfo* comp, Vector2f popupPos) {
|
||||
void TextBoxEditTool::right_click_popup_gui(CanvasComponentContainer::ObjInfo* comp, Vector2f popupPos) {
|
||||
using namespace GUIStuff;
|
||||
using namespace ElementHelpers;
|
||||
|
||||
Toolbar& t = drawP.world.main.toolbar;
|
||||
bool shouldClose = false;
|
||||
auto& a = static_cast<TextBoxCanvasComponent&>(comp->obj->get_comp());
|
||||
t.gui.list_popup_menu("Text popup menu", popupPos, [&]() {
|
||||
t.gui.text_label_light("Text menu");
|
||||
|
||||
t.gui.element<PositionAdjustingPopupMenu>("Text popup menu", popupPos, [&, popupPos] {
|
||||
text_label_light(t.gui, "Text menu");
|
||||
InputManager& input = drawP.world.main.input;
|
||||
if(t.gui.text_button_left_transparent("Paste", "Paste")) {
|
||||
drawP.popup_menu_action_button("Paste", "Paste", [&] {
|
||||
input.call_text_paste(true);
|
||||
shouldClose = true;
|
||||
}
|
||||
if(t.gui.text_button_left_transparent("Paste without formatting", "Paste without formatting")) {
|
||||
});
|
||||
drawP.popup_menu_action_button("Paste without formatting", "Paste without formatting", [&] {
|
||||
input.call_text_paste(false);
|
||||
shouldClose = true;
|
||||
}
|
||||
});
|
||||
if(a.cursor->selectionBeginPos != a.cursor->selectionEndPos) {
|
||||
if(t.gui.text_button_left_transparent("Copy", "Copy")) {
|
||||
drawP.popup_menu_action_button("Copy", "Copy", [&] {
|
||||
input.set_clipboard_plain_and_richtext_pair(a.textBox->process_copy(*a.cursor));
|
||||
shouldClose = true;
|
||||
}
|
||||
if(t.gui.text_button_left_transparent("Cut", "Cut")) {
|
||||
});
|
||||
drawP.popup_menu_action_button("Cut", "Cut", [&] {
|
||||
input.text.do_textbox_operation_with_undo([&]() {
|
||||
input.set_clipboard_plain_and_richtext_pair(a.textBox->process_cut(*a.cursor));
|
||||
});
|
||||
shouldClose = true;
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
return !shouldClose;
|
||||
}
|
||||
|
||||
void TextBoxEditTool::hold_undo_data(const std::string& undoName, TextBoxCanvasComponent& a) {
|
||||
|
|
|
|||
|
|
@ -13,8 +13,8 @@ class TextBoxEditTool : public DrawingProgramEditToolBase {
|
|||
virtual void edit_start(EditTool& editTool,CanvasComponentContainer::ObjInfo* comp, std::any& prevData) override;
|
||||
virtual void commit_edit_updates(CanvasComponentContainer::ObjInfo* comp, std::any& prevData) override;
|
||||
virtual bool edit_update(CanvasComponentContainer::ObjInfo* comp) override;
|
||||
virtual bool edit_gui(CanvasComponentContainer::ObjInfo* comp) override;
|
||||
virtual bool right_click_popup_gui(CanvasComponentContainer::ObjInfo* comp, Vector2f popupPos) override;
|
||||
virtual void edit_gui(CanvasComponentContainer::ObjInfo* comp) override;
|
||||
virtual void right_click_popup_gui(CanvasComponentContainer::ObjInfo* comp, Vector2f popupPos) override;
|
||||
|
||||
virtual void input_key_callback(CanvasComponentContainer::ObjInfo* comp, const InputManager::KeyCallbackArgs& key) override;
|
||||
virtual void input_mouse_button_on_canvas_callback(CanvasComponentContainer::ObjInfo* comp, const InputManager::MouseButtonCallbackArgs& button, bool isDraggingPoint) override;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue