mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 14:47:34 +00:00
FontEditor: Consolidate GlyphEditor's flip_{horizontally,vertically}
This commit is contained in:
parent
d867871bda
commit
894b41ef4d
3 changed files with 7 additions and 29 deletions
|
@ -215,40 +215,19 @@ void GlyphEditorWidget::rotate_90(Gfx::RotationDirection direction)
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GlyphEditorWidget::flip_vertically()
|
void GlyphEditorWidget::flip(Gfx::Orientation orientation)
|
||||||
{
|
{
|
||||||
if (on_undo_event)
|
if (on_undo_event)
|
||||||
on_undo_event();
|
on_undo_event();
|
||||||
|
|
||||||
auto bitmap = font().raw_glyph(m_glyph).glyph_bitmap();
|
auto bitmap = font().raw_glyph(m_glyph).glyph_bitmap();
|
||||||
auto matrix = glyph_as_matrix(bitmap);
|
auto matrix = glyph_as_matrix(bitmap);
|
||||||
|
auto vertical = orientation == Gfx::Orientation::Vertical;
|
||||||
|
|
||||||
for (int y = 0; y < bitmap.height(); y++) {
|
for (int y = 0; y < bitmap.height(); y++) {
|
||||||
for (int x = 0; x < bitmap.width(); x++) {
|
for (int x = 0; x < bitmap.width(); x++) {
|
||||||
int source_x = x;
|
int source_x = vertical ? x : bitmap.width() - 1 - x;
|
||||||
int source_y = bitmap.height() - 1 - y;
|
int source_y = vertical ? bitmap.height() - 1 - y : y;
|
||||||
bool value = matrix[source_y][source_x];
|
|
||||||
bitmap.set_bit_at(x, y, value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (on_glyph_altered)
|
|
||||||
on_glyph_altered(m_glyph);
|
|
||||||
update();
|
|
||||||
}
|
|
||||||
|
|
||||||
void GlyphEditorWidget::flip_horizontally()
|
|
||||||
{
|
|
||||||
if (on_undo_event)
|
|
||||||
on_undo_event();
|
|
||||||
|
|
||||||
auto bitmap = font().raw_glyph(m_glyph).glyph_bitmap();
|
|
||||||
auto matrix = glyph_as_matrix(bitmap);
|
|
||||||
|
|
||||||
for (int y = 0; y < bitmap.height(); y++) {
|
|
||||||
for (int x = 0; x < bitmap.width(); x++) {
|
|
||||||
int source_x = bitmap.width() - 1 - x;
|
|
||||||
int source_y = y;
|
|
||||||
bool value = matrix[source_y][source_x];
|
bool value = matrix[source_y][source_x];
|
||||||
bitmap.set_bit_at(x, y, value);
|
bitmap.set_bit_at(x, y, value);
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,8 +28,7 @@ public:
|
||||||
bool is_glyph_empty();
|
bool is_glyph_empty();
|
||||||
|
|
||||||
void rotate_90(Gfx::RotationDirection);
|
void rotate_90(Gfx::RotationDirection);
|
||||||
void flip_vertically();
|
void flip(Gfx::Orientation);
|
||||||
void flip_horizontally();
|
|
||||||
|
|
||||||
int preferred_width() const;
|
int preferred_width() const;
|
||||||
int preferred_height() const;
|
int preferred_height() const;
|
||||||
|
|
|
@ -283,11 +283,11 @@ ErrorOr<void> MainWidget::create_actions()
|
||||||
});
|
});
|
||||||
|
|
||||||
m_flip_horizontal_action = GUI::Action::create("Flip Horizontally", { Mod_Ctrl | Mod_Shift, Key_Q }, TRY(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/edit-flip-horizontal.png"sv)), [&](auto&) {
|
m_flip_horizontal_action = GUI::Action::create("Flip Horizontally", { Mod_Ctrl | Mod_Shift, Key_Q }, TRY(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/edit-flip-horizontal.png"sv)), [&](auto&) {
|
||||||
m_glyph_editor_widget->flip_horizontally();
|
m_glyph_editor_widget->flip(Gfx::Orientation::Horizontal);
|
||||||
});
|
});
|
||||||
|
|
||||||
m_flip_vertical_action = GUI::Action::create("Flip Vertically", { Mod_Ctrl | Mod_Shift, Key_W }, TRY(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/edit-flip-vertical.png"sv)), [&](auto&) {
|
m_flip_vertical_action = GUI::Action::create("Flip Vertically", { Mod_Ctrl | Mod_Shift, Key_W }, TRY(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/edit-flip-vertical.png"sv)), [&](auto&) {
|
||||||
m_glyph_editor_widget->flip_vertically();
|
m_glyph_editor_widget->flip(Gfx::Orientation::Vertical);
|
||||||
});
|
});
|
||||||
|
|
||||||
m_copy_text_action = GUI::Action::create("Copy as Te&xt", { Mod_Ctrl, Key_T }, TRY(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/edit-copy.png"sv)), [&](auto&) {
|
m_copy_text_action = GUI::Action::create("Copy as Te&xt", { Mod_Ctrl, Key_T }, TRY(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/edit-copy.png"sv)), [&](auto&) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue