From f2580dcfebadced9d1c58625e89b4a349cab2636 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sat, 6 Apr 2019 15:28:06 +0200 Subject: [PATCH] FontEditor: Remove weird focus rects and optimize repaint while drawing. I added focus rects to these widgets because I had just started working on focus support and I was excited but it doesn't really make sense for these things to have focus rects. :^) While I was here I also optimized the repaint code to only update the edited glyph in the glyph map when editing its pixels. --- Applications/FontEditor/FontEditor.cpp | 4 ++-- Applications/FontEditor/GlyphEditorWidget.cpp | 7 +------ Applications/FontEditor/GlyphEditorWidget.h | 2 +- Applications/FontEditor/GlyphMapWidget.cpp | 14 +++++++++----- Applications/FontEditor/GlyphMapWidget.h | 2 ++ 5 files changed, 15 insertions(+), 14 deletions(-) diff --git a/Applications/FontEditor/FontEditor.cpp b/Applications/FontEditor/FontEditor.cpp index 1a0d0523db..dc23c23ca4 100644 --- a/Applications/FontEditor/FontEditor.cpp +++ b/Applications/FontEditor/FontEditor.cpp @@ -80,8 +80,8 @@ FontEditorWidget::FontEditorWidget(const String& path, RetainPtr&& edited_ demo_label_2->update(); }; - m_glyph_editor_widget->on_glyph_altered = [this, update_demo] { - m_glyph_map_widget->update(); + m_glyph_editor_widget->on_glyph_altered = [this, update_demo] (byte glyph) { + m_glyph_map_widget->update_glyph(glyph); update_demo(); }; diff --git a/Applications/FontEditor/GlyphEditorWidget.cpp b/Applications/FontEditor/GlyphEditorWidget.cpp index 2d1107f7a9..c78779587e 100644 --- a/Applications/FontEditor/GlyphEditorWidget.cpp +++ b/Applications/FontEditor/GlyphEditorWidget.cpp @@ -47,11 +47,6 @@ void GlyphEditorWidget::paint_event(GPaintEvent&) } } } - - if (is_focused()) { - painter.translate(-1, -1); - painter.draw_focus_rect(rect()); - } } void GlyphEditorWidget::mousedown_event(GMouseEvent& event) @@ -82,7 +77,7 @@ void GlyphEditorWidget::draw_at_mouse(const GMouseEvent& event) return; bitmap.set_bit_at(x, y, set); if (on_glyph_altered) - on_glyph_altered(); + on_glyph_altered(m_glyph); update(); } diff --git a/Applications/FontEditor/GlyphEditorWidget.h b/Applications/FontEditor/GlyphEditorWidget.h index 4d048742c6..9f2fae24cf 100644 --- a/Applications/FontEditor/GlyphEditorWidget.h +++ b/Applications/FontEditor/GlyphEditorWidget.h @@ -15,7 +15,7 @@ public: Font& font() { return *m_font; } const Font& font() const { return *m_font; } - Function on_glyph_altered; + Function on_glyph_altered; private: virtual void paint_event(GPaintEvent&) override; diff --git a/Applications/FontEditor/GlyphMapWidget.cpp b/Applications/FontEditor/GlyphMapWidget.cpp index 78a86dda64..23aa93b6c0 100644 --- a/Applications/FontEditor/GlyphMapWidget.cpp +++ b/Applications/FontEditor/GlyphMapWidget.cpp @@ -44,9 +44,16 @@ Rect GlyphMapWidget::get_outer_rect(byte glyph) const }; } -void GlyphMapWidget::paint_event(GPaintEvent&) +void GlyphMapWidget::update_glyph(byte glyph) +{ + update(get_outer_rect(glyph)); +} + +void GlyphMapWidget::paint_event(GPaintEvent& event) { GPainter painter(*this); + painter.add_clip_rect(event.rect()); + painter.set_font(font()); painter.fill_rect(rect(), Color::White); painter.draw_rect(rect(), Color::Black); @@ -63,16 +70,13 @@ void GlyphMapWidget::paint_event(GPaintEvent&) font().glyph_height() ); if (glyph == m_selected_glyph) { - painter.fill_rect(outer_rect, Color::Red); + painter.fill_rect(outer_rect, Color::from_rgb(0x84351a)); painter.draw_glyph(inner_rect.location(), glyph, Color::White); } else { painter.draw_glyph(inner_rect.location(), glyph, Color::Black); } } } - - if (is_focused()) - painter.draw_focus_rect(rect()); } void GlyphMapWidget::mousedown_event(GMouseEvent& event) diff --git a/Applications/FontEditor/GlyphMapWidget.h b/Applications/FontEditor/GlyphMapWidget.h index 23c85d6cf4..286d5cde83 100644 --- a/Applications/FontEditor/GlyphMapWidget.h +++ b/Applications/FontEditor/GlyphMapWidget.h @@ -20,6 +20,8 @@ public: Font& font() { return *m_font; } const Font& font() const { return *m_font; } + void update_glyph(byte); + Function on_glyph_selected; private: