Added text decoration modifiers, and icon toggle buttons for text modifiers
This commit is contained in:
parent
bc8bd93e3b
commit
644655544c
19 changed files with 373 additions and 51 deletions
|
|
@ -19,32 +19,65 @@ bool TextBoxEditTool::edit_gui(const std::shared_ptr<DrawComponent>& comp) {
|
|||
t.gui.push_id("edit tool text");
|
||||
t.gui.text_label_centered("Edit Text");
|
||||
|
||||
bool isBold = std::static_pointer_cast<WeightTextStyleModifier>(modsAtStartOfSelection[TextStyleModifier::ModifierType::WEIGHT])->get_weight() == SkFontStyle::Weight::kBold_Weight;
|
||||
if(t.gui.text_button_wide("Bold button", "Bold", isBold)) {
|
||||
auto boldMod = std::make_shared<WeightTextStyleModifier>();
|
||||
boldMod->set_weight(isBold ? SkFontStyle::Weight::kNormal_Weight : SkFontStyle::Weight::kBold_Weight);
|
||||
a->textBox->set_text_style_modifier_between(a->cursor->selectionBeginPos, a->cursor->selectionEndPos, boldMod);
|
||||
}
|
||||
bool isItalic = std::static_pointer_cast<SlantTextStyleModifier>(modsAtStartOfSelection[TextStyleModifier::ModifierType::SLANT])->get_slant() == SkFontStyle::Slant::kItalic_Slant;
|
||||
if(t.gui.text_button_wide("Italic button", "Italic", isItalic)) {
|
||||
auto italicMod = std::make_shared<SlantTextStyleModifier>();
|
||||
italicMod->set_slant(isItalic ? SkFontStyle::Slant::kUpright_Slant : SkFontStyle::Slant::kItalic_Slant);
|
||||
a->textBox->set_text_style_modifier_between(a->cursor->selectionBeginPos, a->cursor->selectionEndPos, italicMod);
|
||||
}
|
||||
t.gui.left_to_right_line_centered_layout([&]() {
|
||||
bool isBold = std::static_pointer_cast<WeightTextStyleModifier>(modsAtStartOfSelection[TextStyleModifier::ModifierType::WEIGHT])->get_weight() == SkFontStyle::Weight::kBold_Weight;
|
||||
if(t.gui.svg_icon_button("Bold button", "data/icons/RemixIcon/bold.svg", isBold)) {
|
||||
auto boldMod = std::make_shared<WeightTextStyleModifier>();
|
||||
boldMod->set_weight(isBold ? SkFontStyle::Weight::kNormal_Weight : SkFontStyle::Weight::kBold_Weight);
|
||||
a->textBox->set_text_style_modifier_between(a->cursor->selectionBeginPos, a->cursor->selectionEndPos, boldMod);
|
||||
}
|
||||
|
||||
bool isItalic = std::static_pointer_cast<SlantTextStyleModifier>(modsAtStartOfSelection[TextStyleModifier::ModifierType::SLANT])->get_slant() == SkFontStyle::Slant::kItalic_Slant;
|
||||
if(t.gui.svg_icon_button("Italic button", "data/icons/RemixIcon/italic.svg", isItalic)) {
|
||||
auto italicMod = std::make_shared<SlantTextStyleModifier>();
|
||||
italicMod->set_slant(isItalic ? SkFontStyle::Slant::kUpright_Slant : SkFontStyle::Slant::kItalic_Slant);
|
||||
a->textBox->set_text_style_modifier_between(a->cursor->selectionBeginPos, a->cursor->selectionEndPos, italicMod);
|
||||
}
|
||||
|
||||
uint8_t currentDecorationValue = std::static_pointer_cast<DecorationTextStyleModifier>(modsAtStartOfSelection[TextStyleModifier::ModifierType::DECORATION])->decorationValue;
|
||||
bool isUnderlined = currentDecorationValue & skia::textlayout::TextDecoration::kUnderline;
|
||||
if(t.gui.svg_icon_button("Underline button", "data/icons/RemixIcon/underline.svg", isUnderlined)) {
|
||||
auto decorationMod = std::make_shared<DecorationTextStyleModifier>();
|
||||
decorationMod->decorationValue = isUnderlined ? (currentDecorationValue & ~static_cast<uint8_t>(skia::textlayout::TextDecoration::kUnderline)) : currentDecorationValue | static_cast<uint8_t>(skia::textlayout::TextDecoration::kUnderline);
|
||||
a->textBox->set_text_style_modifier_between(a->cursor->selectionBeginPos, a->cursor->selectionEndPos, decorationMod);
|
||||
}
|
||||
|
||||
bool isLinethrough = currentDecorationValue & skia::textlayout::TextDecoration::kLineThrough;
|
||||
if(t.gui.svg_icon_button("Strikethrough button", "data/icons/RemixIcon/strikethrough.svg", isLinethrough)) {
|
||||
auto decorationMod = std::make_shared<DecorationTextStyleModifier>();
|
||||
decorationMod->decorationValue = isLinethrough ? (currentDecorationValue & ~static_cast<uint8_t>(skia::textlayout::TextDecoration::kLineThrough)) : currentDecorationValue | static_cast<uint8_t>(skia::textlayout::TextDecoration::kLineThrough);
|
||||
a->textBox->set_text_style_modifier_between(a->cursor->selectionBeginPos, a->cursor->selectionEndPos, decorationMod);
|
||||
}
|
||||
|
||||
bool isOverline = currentDecorationValue & skia::textlayout::TextDecoration::kOverline;
|
||||
if(t.gui.svg_icon_button("Overline button", "data/icons/RemixIcon/overline.svg", isOverline)) {
|
||||
auto decorationMod = std::make_shared<DecorationTextStyleModifier>();
|
||||
decorationMod->decorationValue = isOverline ? (currentDecorationValue & ~static_cast<uint8_t>(skia::textlayout::TextDecoration::kOverline)) : currentDecorationValue | static_cast<uint8_t>(skia::textlayout::TextDecoration::kOverline);
|
||||
a->textBox->set_text_style_modifier_between(a->cursor->selectionBeginPos, a->cursor->selectionEndPos, decorationMod);
|
||||
}
|
||||
});
|
||||
|
||||
newFontSize = std::static_pointer_cast<SizeTextStyleModifier>(modsAtStartOfSelection[TextStyleModifier::ModifierType::SIZE])->size;
|
||||
if(t.gui.slider_scalar_field<uint32_t>("Font Size Slider", "Font Size", &newFontSize, 3, 100)) {
|
||||
auto sizeMod = std::make_shared<SizeTextStyleModifier>();
|
||||
sizeMod->size = newFontSize;
|
||||
a->textBox->set_text_style_modifier_between(a->cursor->selectionBeginPos, a->cursor->selectionEndPos, sizeMod);
|
||||
}
|
||||
t.gui.left_to_right_line_layout([&]() {
|
||||
CLAY({.layout = {.sizing = {.width = CLAY_SIZING_FIXED(40), .height = CLAY_SIZING_FIXED(40)}}}) {
|
||||
if(t.gui.color_button("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) && t.isUpdatingColorRight) {
|
||||
auto colorMod = std::make_shared<ColorTextStyleModifier>();
|
||||
colorMod->color = newTextColor;
|
||||
a->textBox->set_text_style_modifier_between(a->cursor->selectionBeginPos, a->cursor->selectionEndPos, colorMod);
|
||||
}
|
||||
newTextColor = std::static_pointer_cast<ColorTextStyleModifier>(modsAtStartOfSelection[TextStyleModifier::ModifierType::COLOR])->color;
|
||||
|
||||
//t.gui.left_to_right_line_layout([&]() {
|
||||
// CLAY({.layout = {.sizing = {.width = CLAY_SIZING_FIXED(40), .height = CLAY_SIZING_FIXED(40)}}}) {
|
||||
// if(t.gui.color_button("Text Color", &a->d.textColor, &a->d.textColor == t.colorRight))
|
||||
// t.color_selector_right(&a->d.textColor == t.colorRight ? nullptr : &a->d.textColor);
|
||||
// }
|
||||
// t.gui.text_label("Text Color");
|
||||
//});
|
||||
t.gui.pop_id();
|
||||
|
||||
if(a->textBox->inputChangedTextBox)
|
||||
|
|
|
|||
|
|
@ -19,7 +19,9 @@ class TextBoxEditTool : public DrawingProgramEditToolBase {
|
|||
DrawTextBox::Data textboxData;
|
||||
RichTextBox::RichTextData richText;
|
||||
};
|
||||
uint32_t newFontSize;
|
||||
|
||||
uint32_t newFontSize = 15;
|
||||
Vector4f newTextColor{1.0f, 1.0f, 1.0f, 1.0f};
|
||||
|
||||
void set_mods_at_selection(const std::shared_ptr<DrawTextBox>& a);
|
||||
TextStyleModifier::ModifierMap modsAtStartOfSelection;
|
||||
|
|
|
|||
|
|
@ -21,7 +21,6 @@ void TextBoxTool::gui_toolbox() {
|
|||
Toolbar& t = drawP.world.main.toolbar;
|
||||
t.gui.push_id("textbox tool");
|
||||
t.gui.text_label_centered("Textbox");
|
||||
t.gui.slider_scalar_field("Text Relative Size", "Text Size", &controls.textRelativeSize, 5.0f, 100.0f);
|
||||
t.gui.pop_id();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -21,7 +21,6 @@ class TextBoxTool : public DrawingProgramToolBase {
|
|||
void commit();
|
||||
|
||||
struct TextBoxControls {
|
||||
float textRelativeSize = 20.0f;
|
||||
Vector2f startAt;
|
||||
Vector2f endAt;
|
||||
int drawStage = 0;
|
||||
|
|
|
|||
|
|
@ -11,12 +11,14 @@ namespace GUIStuff {
|
|||
|
||||
template <typename T> class ColorPicker : public Element {
|
||||
public:
|
||||
void update(UpdateInputData& io, T* newData, bool newSelectAlpha, const std::function<void()>& elemUpdate) {
|
||||
bool update(UpdateInputData& io, T* newData, bool newSelectAlpha, const std::function<void()>& elemUpdate) {
|
||||
bool isChanged = false;
|
||||
|
||||
T* data = newData;
|
||||
selectAlpha = newSelectAlpha;
|
||||
|
||||
if(!data)
|
||||
return;
|
||||
return false;
|
||||
|
||||
force_update_colorpicker(data);
|
||||
|
||||
|
|
@ -39,6 +41,7 @@ template <typename T> class ColorPicker : public Element {
|
|||
Vector2f alphaBarDim = get_alpha_bar_dim();
|
||||
modifyingAlpha = SCollision::collide(SCollision::AABB<float>(alphaBarPos, alphaBarPos + alphaBarDim), io.mouse.pos);
|
||||
}
|
||||
isChanged = true;
|
||||
}
|
||||
if(selection.held && modifyingSv) {
|
||||
float svSelectionAreaSize = bb.width() - (BAR_GAP + BAR_WIDTH);
|
||||
|
|
@ -46,18 +49,21 @@ template <typename T> class ColorPicker : public Element {
|
|||
savedHsv.y() = newSv.x();
|
||||
savedHsv.z() = 1.0f - newSv.y();
|
||||
set_hsv(data, savedHsv);
|
||||
isChanged = true;
|
||||
}
|
||||
if(selection.held && modifyingHue) {
|
||||
Vector2f huePos = get_hue_bar_pos();
|
||||
Vector2f hueDim = get_hue_bar_dim();
|
||||
savedHsv.x() = (1.0f - std::clamp((io.mouse.pos.y() - huePos.y()) / hueDim.y(), 0.0f, 1.0f)) * 360.0f;
|
||||
set_hsv(data, savedHsv);
|
||||
isChanged = true;
|
||||
}
|
||||
if(selection.held && modifyingAlpha) {
|
||||
Vector2f alphaPos = get_alpha_bar_pos();
|
||||
Vector2f alphaDim = get_alpha_bar_dim();
|
||||
(*data)[3] = std::clamp((io.mouse.pos.x() - alphaPos.x()) / alphaDim.x(), 0.0f, 1.0f);
|
||||
oldData = *data;
|
||||
isChanged = true;
|
||||
}
|
||||
if(!selection.held) {
|
||||
modifyingSv = false;
|
||||
|
|
@ -67,6 +73,8 @@ template <typename T> class ColorPicker : public Element {
|
|||
if(elemUpdate)
|
||||
elemUpdate();
|
||||
}
|
||||
|
||||
return isChanged;
|
||||
}
|
||||
|
||||
virtual void clay_draw(SkCanvas* canvas, UpdateInputData& io, Clay_RenderCommand* command) {
|
||||
|
|
|
|||
|
|
@ -26,6 +26,8 @@ void SVGIcon::update(UpdateInputData& io, const std::string& newSvgPath, bool ne
|
|||
else {
|
||||
io.svgData[newSvgPath] = newSvgDom;
|
||||
svgDom = newSvgDom;
|
||||
if(svgDom->containerSize().width() == 0 || svgDom->containerSize().height() == 0)
|
||||
svgDom->setContainerSize({1000, 1000});
|
||||
}
|
||||
}
|
||||
else
|
||||
|
|
|
|||
|
|
@ -275,6 +275,18 @@ void GUIManager::left_to_right_line_layout(const std::function<void()>& elemUpda
|
|||
left_to_right_layout(CLAY_SIZING_GROW(0), CLAY_SIZING_FIT(0), elemUpdate);
|
||||
}
|
||||
|
||||
void GUIManager::left_to_right_line_centered_layout(const std::function<void()>& elemUpdate) {
|
||||
CLAY({.layout = {
|
||||
.sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_FIT(0) },
|
||||
.childGap = io->theme->childGap1,
|
||||
.childAlignment = {.x = CLAY_ALIGN_X_CENTER, .y = CLAY_ALIGN_Y_CENTER},
|
||||
.layoutDirection = CLAY_LEFT_TO_RIGHT,
|
||||
}
|
||||
}) {
|
||||
elemUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
void GUIManager::text_label_size(const std::string& val, float modifier) {
|
||||
CLAY_TEXT(strArena.std_str_to_clay_str(val), CLAY_TEXT_CONFIG({.textColor = convert_vec4<Clay_Color>(io->theme->frontColor1), .fontSize = static_cast<uint16_t>(io->fontSize * modifier)}));
|
||||
}
|
||||
|
|
@ -360,9 +372,9 @@ bool GUIManager::radio_button_field(const std::string& id, const std::string& na
|
|||
return toRet;
|
||||
}
|
||||
|
||||
void GUIManager::input_color_component_255(const std::string& id, float* val, const std::function<void(SelectionHelper&)>& elemUpdate) {
|
||||
bool GUIManager::input_color_component_255(const std::string& id, float* val, const std::function<void(SelectionHelper&)>& elemUpdate) {
|
||||
push_id(id);
|
||||
insert_element<TextBox<float>>()->update(*io, val,
|
||||
bool isUpdating = insert_element<TextBox<float>>()->update(*io, val,
|
||||
[&](const std::string& str) {
|
||||
int roundTo255;
|
||||
std::stringstream ss;
|
||||
|
|
@ -377,6 +389,7 @@ void GUIManager::input_color_component_255(const std::string& id, float* val, co
|
|||
return ss.str();
|
||||
}, true, false, elemUpdate);
|
||||
pop_id();
|
||||
return isUpdating;
|
||||
}
|
||||
|
||||
void GUIManager::input_text(const std::string& id, std::string* val, const std::function<void(SelectionHelper&)>& elemUpdate) {
|
||||
|
|
|
|||
|
|
@ -72,6 +72,7 @@ class GUIManager {
|
|||
void top_to_bottom_window_popup_layout(Clay_SizingAxis x, Clay_SizingAxis y, const std::function<void()>& elemUpdate);
|
||||
void left_to_right_layout(Clay_SizingAxis x, Clay_SizingAxis y, const std::function<void()>& elemUpdate);
|
||||
void left_to_right_line_layout(const std::function<void()>& elemUpdate);
|
||||
void left_to_right_line_centered_layout(const std::function<void()>& elemUpdate);
|
||||
|
||||
bool selectable_button(const std::string& id, const std::function<void(SelectionHelper&, bool)>& elemUpdate, GUIStuff::SelectableButton::DrawType drawType, bool isSelected);
|
||||
|
||||
|
|
@ -82,7 +83,7 @@ class GUIManager {
|
|||
void scroll_bar_area(const std::string& uniqueId, const std::function<void(float scrollContentHeight, float containerHeight, float scrollAmount)>& elemUpdate);
|
||||
void scroll_bar_many_entries_area(const std::string& uniqueId, float entryHeight, size_t entryCount, const std::function<void(size_t elementIndex, bool listHovered)>& entryUpdate, const std::function<void(float scrollContentHeight, float containerHeight, float scrollAmount)>& elemUpdate = nullptr);
|
||||
|
||||
void input_color_component_255(const std::string& id, float* val, const std::function<void(SelectionHelper&)>& elemUpdate = nullptr);
|
||||
bool input_color_component_255(const std::string& id, float* val, const std::function<void(SelectionHelper&)>& elemUpdate = nullptr);
|
||||
void input_text(const std::string& id, std::string* val, const std::function<void(SelectionHelper&)>& elemUpdate = nullptr);
|
||||
|
||||
bool radio_button(const std::string& id, bool val, const std::function<void()>& elemUpdate = nullptr);
|
||||
|
|
@ -162,18 +163,20 @@ class GUIManager {
|
|||
|
||||
bool input_scalar(const std::string& id, uint8_t* val, uint8_t min, uint8_t max, int decimalPrecision, const std::function<void(SelectionHelper&)>& elemUpdate);
|
||||
|
||||
template <typename TContainer, typename T> void input_scalar_fields(const std::string& id, const std::string& name, TContainer* val, size_t elemCount, T min, T max, int decimalPrecision = 0, const std::function<void(SelectionHelper&)>& elemUpdate = nullptr) {
|
||||
template <typename TContainer, typename T> bool input_scalar_fields(const std::string& id, const std::string& name, TContainer* val, size_t elemCount, T min, T max, int decimalPrecision = 0, const std::function<void(SelectionHelper&)>& elemUpdate = nullptr) {
|
||||
bool isUpdating = false;
|
||||
push_id(id);
|
||||
left_to_right_line_layout([&]() {
|
||||
text_label(name);
|
||||
for(size_t i = 0; i < elemCount; i++)
|
||||
input_scalar<T>(std::to_string(i), &(*val)[i], min, max, decimalPrecision, elemUpdate);
|
||||
isUpdating |= input_scalar<T>(std::to_string(i), &(*val)[i], min, max, decimalPrecision, elemUpdate);
|
||||
});
|
||||
pop_id();
|
||||
return isUpdating;
|
||||
}
|
||||
|
||||
template <typename T> void input_color_hex(const std::string& id, T* val, bool selectAlpha, const std::function<void(SelectionHelper&)>& elemUpdate = nullptr) {
|
||||
input_generic<T>(id, val,
|
||||
template <typename T> bool input_color_hex(const std::string& id, T* val, bool selectAlpha, const std::function<void(SelectionHelper&)>& elemUpdate = nullptr) {
|
||||
return input_generic<T>(id, val,
|
||||
[&](const std::string& str) {
|
||||
T def = {0.0f, 0.0f, 0.0f, 1.0f};
|
||||
unsigned startIndex = 0;
|
||||
|
|
@ -209,10 +212,11 @@ class GUIManager {
|
|||
true, false, elemUpdate);
|
||||
}
|
||||
|
||||
template <typename T> void color_picker(const std::string& id, T* val, bool selectAlpha, const std::function<void()>& elemUpdate = nullptr) {
|
||||
template <typename T> bool color_picker(const std::string& id, T* val, bool selectAlpha, const std::function<void()>& elemUpdate = nullptr) {
|
||||
push_id(id);
|
||||
insert_element<ColorPicker<T>>()->update(*io, val, selectAlpha, elemUpdate);
|
||||
bool isUpdating = insert_element<ColorPicker<T>>()->update(*io, val, selectAlpha, elemUpdate);
|
||||
pop_id();
|
||||
return isUpdating;
|
||||
}
|
||||
|
||||
template <typename T> bool slider_scalar(const std::string& id, T* val, T min, T max, const std::function<void()>& elemUpdate = nullptr) {
|
||||
|
|
@ -264,7 +268,8 @@ class GUIManager {
|
|||
}, GUIStuff::SelectableButton::DrawType::TRANSPARENT_BORDER, isSelected);
|
||||
}
|
||||
|
||||
template <typename T> void color_picker_button(const std::string& id, T* val, bool selectAlpha, const std::function<void()>& elemUpdate = nullptr) {
|
||||
template <typename T> bool color_picker_button(const std::string& id, T* val, bool selectAlpha, const std::function<void()>& elemUpdate = nullptr) {
|
||||
bool isUpdating = false;
|
||||
push_id(id);
|
||||
bool& isOpen = insert_any_with_id<bool>(0, false);
|
||||
bool clicked;
|
||||
|
|
@ -275,41 +280,46 @@ class GUIManager {
|
|||
isOpen = true;
|
||||
if(isOpen) {
|
||||
top_to_bottom_window_popup_layout(CLAY_SIZING_FIT(300), CLAY_SIZING_FIT(0), [&]() {
|
||||
color_picker_items("c", val, selectAlpha);
|
||||
isUpdating = color_picker_items("c", val, selectAlpha);
|
||||
if(io->mouse.leftClick && !Clay_Hovered() && !clicked)
|
||||
isOpen = false;
|
||||
});
|
||||
}
|
||||
pop_id();
|
||||
return isUpdating;
|
||||
}
|
||||
|
||||
template <typename T> void color_picker_items(const std::string& id, T* val, bool selectAlpha) {
|
||||
template <typename T> bool color_picker_items(const std::string& id, T* val, bool selectAlpha) {
|
||||
bool isUpdating = false;
|
||||
push_id(id);
|
||||
color_picker("c", val, selectAlpha);
|
||||
isUpdating |= color_picker("c", val, selectAlpha);
|
||||
left_to_right_line_layout([&]() {
|
||||
text_label("R");
|
||||
input_color_component_255("r", &(*val)[0]);
|
||||
isUpdating |= input_color_component_255("r", &(*val)[0]);
|
||||
text_label("G");
|
||||
input_color_component_255("g", &(*val)[1]);
|
||||
isUpdating |= input_color_component_255("g", &(*val)[1]);
|
||||
text_label("B");
|
||||
input_color_component_255("b", &(*val)[2]);
|
||||
isUpdating |= input_color_component_255("b", &(*val)[2]);
|
||||
if(selectAlpha) {
|
||||
text_label("A");
|
||||
input_color_component_255("a", &(*val)[3]);
|
||||
isUpdating |= input_color_component_255("a", &(*val)[3]);
|
||||
}
|
||||
});
|
||||
left_to_right_line_layout([&]() {
|
||||
text_label("Hex");
|
||||
input_color_hex("h", val, selectAlpha);
|
||||
isUpdating |= input_color_hex("h", val, selectAlpha);
|
||||
});
|
||||
pop_id();
|
||||
return isUpdating;
|
||||
}
|
||||
|
||||
template <typename T> void color_picker_button_field(const std::string& id, const std::string& name, T* val, bool selectAlpha, const std::function<void()>& elemUpdate = nullptr) {
|
||||
template <typename T> bool color_picker_button_field(const std::string& id, const std::string& name, T* val, bool selectAlpha, const std::function<void()>& elemUpdate = nullptr) {
|
||||
bool isUpdating = false;
|
||||
left_to_right_line_layout([&]() {
|
||||
color_picker_button(id, val, selectAlpha, elemUpdate);
|
||||
isUpdating = color_picker_button(id, val, selectAlpha, elemUpdate);
|
||||
text_label(name);
|
||||
});
|
||||
return isUpdating;
|
||||
}
|
||||
|
||||
private:
|
||||
|
|
|
|||
|
|
@ -610,7 +610,7 @@ RichTextBox::TextPosition RichTextBox::move(Movement movement, TextPosition pos,
|
|||
|
||||
void RichTextBox::set_width(float newWidth) {
|
||||
if(width != newWidth) {
|
||||
width = newWidth;
|
||||
width = std::max(newWidth, 4.0f);
|
||||
inputChangedTextBox = true;
|
||||
needsRebuild = true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
#include <Helpers/ConvertVec.hpp>
|
||||
#include <Helpers/Serializers.hpp>
|
||||
#include <include/core/SkFontStyle.h>
|
||||
#include <modules/skparagraph/include/TextStyle.h>
|
||||
|
||||
#define WEIGHT_VALUE_MODIFIER 100
|
||||
|
||||
|
|
@ -17,6 +18,8 @@ std::shared_ptr<TextStyleModifier> TextStyleModifier::allocate_modifier(Modifier
|
|||
return std::make_shared<WeightTextStyleModifier>();
|
||||
case ModifierType::SLANT:
|
||||
return std::make_shared<SlantTextStyleModifier>();
|
||||
case ModifierType::DECORATION:
|
||||
return std::make_shared<DecorationTextStyleModifier>();
|
||||
case ModifierType::FONT_FAMILIES:
|
||||
return std::make_shared<FontFamiliesTextStyleModifier>();
|
||||
case ModifierType::COUNT:
|
||||
|
|
@ -42,6 +45,10 @@ const TextStyleModifier::ModifierMap& TextStyleModifier::get_default_modifiers()
|
|||
auto slantMod = std::make_shared<SlantTextStyleModifier>();
|
||||
slantMod->set_slant(SkFontStyle::kUpright_Slant);
|
||||
defaultMods[ModifierType::SLANT] = slantMod;
|
||||
|
||||
auto decorationMod = std::make_shared<DecorationTextStyleModifier>();
|
||||
decorationMod->decorationValue = skia::textlayout::TextDecoration::kNoDecoration;
|
||||
defaultMods[ModifierType::DECORATION] = decorationMod;
|
||||
}
|
||||
return defaultMods;
|
||||
}
|
||||
|
|
@ -130,6 +137,7 @@ void ColorTextStyleModifier::load(cereal::PortableBinaryInputArchive& a) {
|
|||
|
||||
void ColorTextStyleModifier::modify_text_style(skia::textlayout::TextStyle& style) const {
|
||||
style.setForegroundPaint(SkPaint{convert_vec4<SkColor4f>(color)});
|
||||
style.setDecorationColor(convert_vec4<SkColor4f>(color).toSkColor());
|
||||
}
|
||||
|
||||
bool ColorTextStyleModifier::equivalent_data(TextStyleModifier& modifier) const {
|
||||
|
|
@ -179,3 +187,25 @@ void FontFamiliesTextStyleModifier::modify_text_style(skia::textlayout::TextStyl
|
|||
bool FontFamiliesTextStyleModifier::equivalent_data(TextStyleModifier& modifier) const {
|
||||
return families == static_cast<FontFamiliesTextStyleModifier&>(modifier).families;
|
||||
}
|
||||
|
||||
|
||||
|
||||
TextStyleModifier::ModifierType DecorationTextStyleModifier::get_type() const {
|
||||
return ModifierType::DECORATION;
|
||||
}
|
||||
|
||||
void DecorationTextStyleModifier::save(cereal::PortableBinaryOutputArchive& a) const {
|
||||
a(decorationValue);
|
||||
}
|
||||
|
||||
void DecorationTextStyleModifier::load(cereal::PortableBinaryInputArchive& a) {
|
||||
a(decorationValue);
|
||||
}
|
||||
|
||||
void DecorationTextStyleModifier::modify_text_style(skia::textlayout::TextStyle& style) const {
|
||||
style.setDecoration(static_cast<skia::textlayout::TextDecoration>(decorationValue));
|
||||
}
|
||||
|
||||
bool DecorationTextStyleModifier::equivalent_data(TextStyleModifier& modifier) const {
|
||||
return decorationValue == static_cast<DecorationTextStyleModifier&>(modifier).decorationValue;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ class TextStyleModifier {
|
|||
COLOR,
|
||||
WEIGHT,
|
||||
SLANT,
|
||||
DECORATION,
|
||||
FONT_FAMILIES,
|
||||
|
||||
COUNT
|
||||
|
|
@ -33,6 +34,17 @@ class TextStyleModifier {
|
|||
virtual bool equivalent_data(TextStyleModifier& modifier) const = 0;
|
||||
};
|
||||
|
||||
class DecorationTextStyleModifier : public TextStyleModifier {
|
||||
public:
|
||||
virtual ModifierType get_type() const override;
|
||||
virtual void save(cereal::PortableBinaryOutputArchive& a) const override;
|
||||
virtual void load(cereal::PortableBinaryInputArchive& a) override;
|
||||
virtual void modify_text_style(skia::textlayout::TextStyle& style) const override;
|
||||
uint8_t decorationValue;
|
||||
private:
|
||||
virtual bool equivalent_data(TextStyleModifier& modifier) const override;
|
||||
};
|
||||
|
||||
class WeightTextStyleModifier : public TextStyleModifier {
|
||||
public:
|
||||
virtual ModifierType get_type() const override;
|
||||
|
|
|
|||
|
|
@ -1012,6 +1012,7 @@ void Toolbar::drawing_program_gui() {
|
|||
},
|
||||
}) {
|
||||
main.world->drawProg.toolbar_gui();
|
||||
isUpdatingColorLeft = isUpdatingColorRight = false;
|
||||
if(colorLeft) {
|
||||
CLAY({
|
||||
.layout = {
|
||||
|
|
@ -1025,9 +1026,9 @@ void Toolbar::drawing_program_gui() {
|
|||
.cornerRadius = CLAY_CORNER_RADIUS(io->theme->windowCorners1)
|
||||
}) {
|
||||
gui.obstructing_window();
|
||||
gui.color_picker_items("colorpickerleft", colorLeft, true);
|
||||
isUpdatingColorLeft |= gui.color_picker_items("colorpickerleft", colorLeft, true);
|
||||
bool hoveringOnDropdown = false;
|
||||
color_palette("colorpickerleftpalette", colorLeft, hoveringOnDropdown);
|
||||
isUpdatingColorLeft |= color_palette("colorpickerleftpalette", colorLeft, hoveringOnDropdown);
|
||||
if(!Clay_Hovered() && !justAssignedColorLeft && !hoveringOnDropdown && io->mouse.leftClick)
|
||||
colorLeft = nullptr;
|
||||
}
|
||||
|
|
@ -1050,9 +1051,9 @@ void Toolbar::drawing_program_gui() {
|
|||
.cornerRadius = CLAY_CORNER_RADIUS(io->theme->windowCorners1)
|
||||
}) {
|
||||
gui.obstructing_window();
|
||||
gui.color_picker_items("colorpickerright", colorRight, true);
|
||||
isUpdatingColorRight |= gui.color_picker_items("colorpickerright", colorRight, true);
|
||||
bool hoveringOnDropdown = false;
|
||||
color_palette("colorpickerrightpalette", colorRight, hoveringOnDropdown);
|
||||
isUpdatingColorRight |= color_palette("colorpickerrightpalette", colorRight, hoveringOnDropdown);
|
||||
if(!Clay_Hovered() && !justAssignedColorRight && !hoveringOnDropdown && io->mouse.leftClick)
|
||||
colorRight = nullptr;
|
||||
}
|
||||
|
|
@ -1061,7 +1062,8 @@ void Toolbar::drawing_program_gui() {
|
|||
}
|
||||
}
|
||||
|
||||
void Toolbar::color_palette(const std::string& id, Vector4f* color, bool& hoveringOnDropdown) {
|
||||
bool Toolbar::color_palette(const std::string& id, Vector4f* color, bool& hoveringOnDropdown) {
|
||||
bool isUpdating = false;
|
||||
gui.push_id(id);
|
||||
auto& palette = paletteData.palettes[paletteData.selectedPalette].colors;
|
||||
size_t i = 0;
|
||||
|
|
@ -1089,6 +1091,7 @@ void Toolbar::color_palette(const std::string& id, Vector4f* color, bool& hoveri
|
|||
color->x() = newC.x();
|
||||
color->y() = newC.y();
|
||||
color->z() = newC.z();
|
||||
isUpdating = true;
|
||||
}
|
||||
if(paletteData.selectedColor == (int)i && (newC.x() != color->x() || newC.y() != color->y() || newC.z() != color->z()))
|
||||
paletteData.selectedColor = -1;
|
||||
|
|
@ -1154,6 +1157,8 @@ void Toolbar::color_palette(const std::string& id, Vector4f* color, bool& hoveri
|
|||
}
|
||||
}
|
||||
gui.pop_id();
|
||||
|
||||
return isUpdating;
|
||||
}
|
||||
|
||||
void Toolbar::performance_metrics() {
|
||||
|
|
|
|||
|
|
@ -80,6 +80,9 @@ class Toolbar {
|
|||
|
||||
Vector4f* colorLeft = nullptr;
|
||||
Vector4f* colorRight = nullptr;
|
||||
bool isUpdatingColorLeft = false;
|
||||
bool isUpdatingColorRight = false;
|
||||
|
||||
std::optional<Vector2f> paintPopupLocation;
|
||||
|
||||
bool flipZoomToolDirection = false;
|
||||
|
|
@ -103,7 +106,7 @@ class Toolbar {
|
|||
void options_menu();
|
||||
void file_picker_gui();
|
||||
void performance_metrics();
|
||||
void color_palette(const std::string& id, Vector4f* color, bool& hoveringOnDropdown);
|
||||
bool color_palette(const std::string& id, Vector4f* color, bool& hoveringOnDropdown);
|
||||
void open_world_file(int conType, const std::string& netSource, const std::string& serverLocalID);
|
||||
void load_default_palette();
|
||||
void load_default_theme();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue