Align by buttons

This commit is contained in:
Filip Sykala - NTB T15p 2023-05-26 09:23:09 +02:00
parent d2a605ee2e
commit 1e2943b942
8 changed files with 301 additions and 34 deletions

View File

@ -0,0 +1,7 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width="16px" height="16px">
<path fill="#ED6B21" d="m 7,14 c 0,0 0,1 1,1 1,0 1,-1 1,-1 V 2 C 9,2 9,1 8,1 7,1 7,2 7,2 Z"/>
<path fill="#808080" d="M 3,3 H 13 V 4 H 3 Z" />
<path fill="#808080" d="m 3.5,9 h 9 v 1 h -9 z" />
<path fill="#808080" d="m 5.5,6 h 5 v 1 h -5 z" />
<path fill="#808080" d="m 4,12 h 8 v 1 H 4 Z" />
</svg>

After

Width:  |  Height:  |  Size: 389 B

View File

@ -0,0 +1,7 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width="16px" height="16px">
<path fill="#ED6B21" d="m 1,14 c 0,0 0,1 1,1 1,0 1,-1 1,-1 V 2 C 3,2 3,1 2,1 1,1 1,2 1,2 Z" />
<path fill="#808080" d="M 2,3 H 12 V 4 H 2 Z" />
<path fill="#808080" d="m 2,9 h 9 v 1 H 2 Z" />
<path fill="#808080" d="M 2,6 H 7 V 7 H 2 Z" />
<path fill="#808080" d="m 2,12 h 8 v 1 H 2 Z" />
</svg>

After

Width:  |  Height:  |  Size: 383 B

View File

@ -0,0 +1,7 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width="16px" height="16px">
<path fill="#ED6B21" d="m 15,14 c 0,0 0,1 -1,1 -1,0 -1,-1 -1,-1 V 2 c 0,0 0,-1 1,-1 1,0 1,1 1,1 z" />
<path fill="#808080" d="M 14,3 H 4 v 1 h 10 z" />
<path fill="#808080" d="M 14,9 H 5 v 1 h 9 z" />
<path fill="#808080" d="M 14,6 H 9 v 1 h 5 z" />
<path fill="#808080" d="M 14,12 H 6 v 1 h 8 z" />
</svg>

After

Width:  |  Height:  |  Size: 395 B

View File

@ -0,0 +1,60 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
viewBox="0 0 16 16"
width="16px"
height="16px"
version="1.1"
id="svg12"
sodipodi:docname="vertic_bottom.svg"
inkscape:version="1.2 (dc2aedaf03, 2022-05-15)"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns="http://www.w3.org/2000/svg"
xmlns:svg="http://www.w3.org/2000/svg">
<defs
id="defs16" />
<sodipodi:namedview
id="namedview14"
pagecolor="#ffffff"
bordercolor="#000000"
borderopacity="0.25"
inkscape:showpageshadow="2"
inkscape:pageopacity="0.0"
inkscape:pagecheckerboard="0"
inkscape:deskcolor="#d1d1d1"
showgrid="true"
inkscape:zoom="41.7193"
inkscape:cx="12.356391"
inkscape:cy="8.5092511"
inkscape:window-width="1920"
inkscape:window-height="1129"
inkscape:window-x="1912"
inkscape:window-y="-8"
inkscape:window-maximized="1"
inkscape:current-layer="svg12">
<inkscape:grid
type="xygrid"
id="grid299" />
</sodipodi:namedview>
<path
fill="#ed6b21"
d="M 2,11 C 2,11 1,11 1,12.5 1,14 2,14 2,14 h 12 c 0,0 1,0 1,-1.5 C 15,11 14,11 14,11 Z"
id="path2"
style="stroke-width:1.22474" />
<path
fill="#808080"
d="M 3,3 H 13 V 4 H 3 Z"
id="path4" />
<path
fill="#808080"
d="M 3,6 H 13 V 7 H 3 Z"
id="path301" />
<path
fill="#808080"
d="m 3,9 h 10 v 1 H 3 Z"
id="path303" />
<path
fill="#808080"
d="m 3,12 h 10 v 1 H 3 Z"
id="path305" />
</svg>

After

Width:  |  Height:  |  Size: 1.6 KiB

View File

@ -0,0 +1,60 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
viewBox="0 0 16 16"
width="16px"
height="16px"
version="1.1"
id="svg12"
sodipodi:docname="vertic_center.svg"
inkscape:version="1.2 (dc2aedaf03, 2022-05-15)"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns="http://www.w3.org/2000/svg"
xmlns:svg="http://www.w3.org/2000/svg">
<defs
id="defs16" />
<sodipodi:namedview
id="namedview14"
pagecolor="#ffffff"
bordercolor="#000000"
borderopacity="0.25"
inkscape:showpageshadow="2"
inkscape:pageopacity="0.0"
inkscape:pagecheckerboard="0"
inkscape:deskcolor="#d1d1d1"
showgrid="true"
inkscape:zoom="41.7193"
inkscape:cx="12.356391"
inkscape:cy="8.5092511"
inkscape:window-width="1920"
inkscape:window-height="1129"
inkscape:window-x="1912"
inkscape:window-y="-8"
inkscape:window-maximized="1"
inkscape:current-layer="svg12">
<inkscape:grid
type="xygrid"
id="grid299" />
</sodipodi:namedview>
<path
fill="#ed6b21"
d="m 2,6.5 c 0,0 -1,0 -1,1.5 0,1.5 1,1.5 1,1.5 h 12 c 0,0 1,0 1,-1.5 0,-1.5 -1,-1.5 -1,-1.5 z"
id="path2"
style="stroke-width:1.22474" />
<path
fill="#808080"
d="M 3,3 H 13 V 4 H 3 Z"
id="path4" />
<path
fill="#808080"
d="M 3,6 H 13 V 7 H 3 Z"
id="path301" />
<path
fill="#808080"
d="m 3,9 h 10 v 1 H 3 Z"
id="path303" />
<path
fill="#808080"
d="m 3,12 h 10 v 1 H 3 Z"
id="path305" />
</svg>

After

Width:  |  Height:  |  Size: 1.6 KiB

View File

@ -0,0 +1,60 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
viewBox="0 0 16 16"
width="16px"
height="16px"
version="1.1"
id="svg12"
sodipodi:docname="vertic_top.svg"
inkscape:version="1.2 (dc2aedaf03, 2022-05-15)"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns="http://www.w3.org/2000/svg"
xmlns:svg="http://www.w3.org/2000/svg">
<defs
id="defs16" />
<sodipodi:namedview
id="namedview14"
pagecolor="#ffffff"
bordercolor="#000000"
borderopacity="0.25"
inkscape:showpageshadow="2"
inkscape:pageopacity="0.0"
inkscape:pagecheckerboard="0"
inkscape:deskcolor="#d1d1d1"
showgrid="true"
inkscape:zoom="41.7193"
inkscape:cx="12.356391"
inkscape:cy="8.5092511"
inkscape:window-width="1920"
inkscape:window-height="1129"
inkscape:window-x="1912"
inkscape:window-y="-8"
inkscape:window-maximized="1"
inkscape:current-layer="svg12">
<inkscape:grid
type="xygrid"
id="grid299" />
</sodipodi:namedview>
<path
fill="#ed6b21"
d="M 2,2 C 2,2 1,2 1,3.5 1,5 2,5 2,5 H 14 C 14,5 15,5 15,3.5 15,2 14,2 14,2 Z"
id="path2"
style="stroke-width:1.22474" />
<path
fill="#808080"
d="M 3,3 H 13 V 4 H 3 Z"
id="path4" />
<path
fill="#808080"
d="M 3,6 H 13 V 7 H 3 Z"
id="path301" />
<path
fill="#808080"
d="m 3,9 h 10 v 1 H 3 Z"
id="path303" />
<path
fill="#808080"
d="m 3,12 h 10 v 1 H 3 Z"
id="path305" />
</svg>

After

Width:  |  Height:  |  Size: 1.6 KiB

View File

@ -233,6 +233,12 @@ enum class IconType : unsigned {
lock_bold,
unlock,
unlock_bold,
align_horizontal_left,
align_horizontal_center,
align_horizontal_right,
align_vertical_top,
align_vertical_center,
align_vertical_bottom,
// automatic calc of icon's count
_count
};
@ -2278,14 +2284,12 @@ void GLGizmoEmboss::draw_model_type()
Plater::TakeSnapshot snapshot(plater, _L("Change Text Type"), UndoRedo::SnapshotType::GizmoAction);
m_volume->set_type(*new_type);
// Update volume position when switch from part or into part
const FontProp& prop = m_volume->text_configuration->style.prop;
if (prop.use_surface || prop.per_glyph) {
// move inside
bool is_volume_move_inside = (type == part);
bool is_volume_move_outside = (*new_type == part);
if (is_volume_move_inside || is_volume_move_outside) process();
}
// move inside
bool is_volume_move_inside = (type == part);
bool is_volume_move_outside = (*new_type == part);
// Update volume position when switch (from part) or (into part)
if ((is_volume_move_inside || is_volume_move_outside))
process();
// inspiration in ObjectList::change_part_type()
// how to view correct side panel with objects
@ -3059,6 +3063,39 @@ void GLGizmoEmboss::do_rotate(float relative_z_angle)
m_parent.do_rotate(snapshot_name);
}
namespace{
bool is_left( FontProp::Align align){ return align == FontProp::Align::bottom_left || align == FontProp::Align::center_left || align == FontProp::Align::top_left; }
bool is_center_h(FontProp::Align align){ return align == FontProp::Align::bottom_center || align == FontProp::Align::center_center || align == FontProp::Align::top_center; }
bool is_right( FontProp::Align align){ return align == FontProp::Align::bottom_right || align == FontProp::Align::center_right || align == FontProp::Align::top_right; }
bool is_top( FontProp::Align align){ return align == FontProp::Align::top_left || align == FontProp::Align::top_center || align == FontProp::Align::top_right; }
bool is_center_v(FontProp::Align align){ return align == FontProp::Align::center_left || align == FontProp::Align::center_center || align == FontProp::Align::center_right; }
bool is_bottom( FontProp::Align align){ return align == FontProp::Align::bottom_left || align == FontProp::Align::bottom_center || align == FontProp::Align::bottom_right; }
void to_left(FontProp::Align &align){
align = (align == FontProp::Align::bottom_right || align == FontProp::Align::bottom_center) ? FontProp::Align::bottom_left :
(align == FontProp::Align::center_right || align == FontProp::Align::center_center) ? FontProp::Align::center_left :
FontProp::Align::top_left;}
void to_center_h(FontProp::Align &align){
align = (align == FontProp::Align::bottom_right || align == FontProp::Align::bottom_left) ? FontProp::Align::bottom_center :
(align == FontProp::Align::center_right || align == FontProp::Align::center_left) ? FontProp::Align::center_center :
FontProp::Align::top_center;}
void to_right(FontProp::Align &align){
align = (align == FontProp::Align::bottom_left || align == FontProp::Align::bottom_center) ? FontProp::Align::bottom_right :
(align == FontProp::Align::center_left || align == FontProp::Align::center_center) ? FontProp::Align::center_right :
FontProp::Align::top_right;}
void to_top(FontProp::Align &align){
align = (align == FontProp::Align::bottom_left || align == FontProp::Align::center_left) ? FontProp::Align::top_left :
(align == FontProp::Align::bottom_right || align == FontProp::Align::center_right) ? FontProp::Align::top_right :
FontProp::Align::top_center;}
void to_center_v(FontProp::Align &align){
align = (align == FontProp::Align::bottom_left || align == FontProp::Align::top_left) ? FontProp::Align::center_left :
(align == FontProp::Align::bottom_right || align == FontProp::Align::top_right) ? FontProp::Align::center_right :
FontProp::Align::center_center;}
void to_bottom(FontProp::Align &align){
align = (align == FontProp::Align::top_left || align == FontProp::Align::center_left) ? FontProp::Align::bottom_left :
(align == FontProp::Align::top_right || align == FontProp::Align::center_right) ? FontProp::Align::bottom_right :
FontProp::Align::bottom_center;}
}
void GLGizmoEmboss::draw_advanced()
{
const auto &ff = m_style_manager.get_font_file_with_cache();
@ -3149,36 +3186,58 @@ void GLGizmoEmboss::draw_advanced()
ImGui::SetTooltip("TEST PURPOSE ONLY\nMove base line (up/down) for allign letters");
m_imgui->disabled_end(); // !per_glyph
int selected_align = static_cast<int>(font_prop.align);
int def_align_data = !stored_style ? 0 : static_cast<int>(stored_style->prop.align);
int * def_align = stored_style ? &def_align_data : nullptr;
const FontProp::Align * def_align = stored_style ? &stored_style->prop.align : nullptr;
float undo_offset = ImGui::GetStyle().FramePadding.x;
auto draw = [&selected_align, gui_cfg = m_gui_cfg]() {
// order must match align enum
const char* align_names[] = { "first_line_center",
"first_line_left",
"first_line_right",
"center_center",
"center_left",
"center_right",
"top_center",
"top_left",
"top_right",
"bottom_center",
"bottom_left",
"bottom_right"};
//auto draw = [&selected_align, gui_cfg = m_gui_cfg]() {
// // order must match align enum
// const char* align_names[] = { "first_line_center",
// "first_line_left",
// "first_line_right",
// "center_center",
// "center_left",
// "center_right",
// "top_center",
// "top_left",
// "top_right",
// "bottom_center",
// "bottom_left",
// "bottom_right"};
// ImGui::SameLine(gui_cfg->advanced_input_offset);
// ImGui::SetNextItemWidth(gui_cfg->input_width);
// return ImGui::Combo("##text_alignment", &selected_align, align_names, IM_ARRAYSIZE(align_names));
//};
auto draw_align = [&align = font_prop.align, gui_cfg = m_gui_cfg, &icons = m_icons]() {
bool is_change = false;
ImGui::SameLine(gui_cfg->advanced_input_offset);
ImGui::SetNextItemWidth(gui_cfg->input_width);
return ImGui::Combo("##text_alignment", &selected_align, align_names, IM_ARRAYSIZE(align_names));
if (is_left(align)) Slic3r::GUI::draw(get_icon(icons, IconType::align_horizontal_left, IconState::hovered));
else if (draw_button(icons, IconType::align_horizontal_left)) { to_left(align); is_change = true; }
ImGui::SameLine();
if (is_center_h(align)) Slic3r::GUI::draw(get_icon(icons, IconType::align_horizontal_center, IconState::hovered));
else if (draw_button(icons, IconType::align_horizontal_center)) { to_center_h(align); is_change = true; }
ImGui::SameLine();
if (is_right(align)) Slic3r::GUI::draw(get_icon(icons, IconType::align_horizontal_right, IconState::hovered));
else if (draw_button(icons, IconType::align_horizontal_right)) { to_right(align); is_change = true; }
ImGui::SameLine();
if (is_top(align)) Slic3r::GUI::draw(get_icon(icons, IconType::align_vertical_top, IconState::hovered));
else if (draw_button(icons, IconType::align_vertical_top)) { to_top(align); is_change = true; }
ImGui::SameLine();
if (is_center_v(align)) Slic3r::GUI::draw(get_icon(icons, IconType::align_vertical_center, IconState::hovered));
else if (draw_button(icons, IconType::align_vertical_center)) { to_center_v(align); is_change = true; }
ImGui::SameLine();
if (is_bottom(align)) Slic3r::GUI::draw(get_icon(icons, IconType::align_vertical_bottom, IconState::hovered));
else if (draw_button(icons, IconType::align_vertical_bottom)) { to_bottom(align); is_change = true; }
return is_change;
};
if (revertible(tr.alignment, selected_align, def_align, _u8L("Revert alignment."), undo_offset, draw)){
font_prop.align = static_cast<FontProp::Align>(selected_align);
if (revertible(tr.alignment, font_prop.align, def_align, _u8L("Revert alignment."), undo_offset, draw_align)) {
if (font_prop.per_glyph)
reinit_text_lines(m_text_lines.get_lines().size());
// TODO: move with text in finalize to not change position
process();
}
// TRN EmbossGizmo: font units
std::string units = _u8L("points");
std::string units_fmt = "%.0f " + units;
@ -3634,7 +3693,13 @@ void GLGizmoEmboss::init_icons()
"lock_closed.svg", // lock,
"lock_closed_f.svg",// lock_bold,
"lock_open.svg", // unlock,
"lock_open_f.svg" // unlock_bold,
"lock_open_f.svg", // unlock_bold,
"align_horizontal_left.svg",
"align_horizontal_center.svg",
"align_horizontal_right.svg",
"align_vertical_top.svg",
"align_vertical_center.svg",
"align_vertical_bottom.svg"
};
assert(filenames.size() == static_cast<size_t>(IconType::_count));
std::string path = resources_dir() + "/icons/";

View File

@ -610,9 +610,10 @@ TriangleMesh priv::try_create_mesh(DataBase &input, Fnc was_canceled)
// NOTE: SHAPE_SCALE is applied in ProjectZ
double scale = get_shape_scale(prop, ff) / SHAPE_SCALE;
double depth = prop.emboss / scale;
auto projectZ = std::make_unique<ProjectZ>(depth);
//auto scaled = std::make_unique<ProjectScale>(std::move(projectZ), scale);
ProjectTransform project(std::move(projectZ), Eigen::Translation<double, 3>(0., 0., -prop.emboss / 2) * Eigen::Scaling(scale));
auto projectZ = std::make_unique<ProjectZ>(depth);
float offset = input.is_outside ? -SAFE_SURFACE_OFFSET : (SAFE_SURFACE_OFFSET - prop.emboss);
Transform3d tr = Eigen::Translation<double, 3>(0., 0.,static_cast<double>(offset)) * Eigen::Scaling(scale);
ProjectTransform project(std::move(projectZ), tr);
if (was_canceled()) return {};
return TriangleMesh(polygons2model(shapes, project));
}