mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 22:27:35 +00:00
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.
This commit is contained in:
parent
ac6c7d3e19
commit
f2580dcfeb
5 changed files with 15 additions and 14 deletions
|
@ -80,8 +80,8 @@ FontEditorWidget::FontEditorWidget(const String& path, RetainPtr<Font>&& edited_
|
||||||
demo_label_2->update();
|
demo_label_2->update();
|
||||||
};
|
};
|
||||||
|
|
||||||
m_glyph_editor_widget->on_glyph_altered = [this, update_demo] {
|
m_glyph_editor_widget->on_glyph_altered = [this, update_demo] (byte glyph) {
|
||||||
m_glyph_map_widget->update();
|
m_glyph_map_widget->update_glyph(glyph);
|
||||||
update_demo();
|
update_demo();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -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)
|
void GlyphEditorWidget::mousedown_event(GMouseEvent& event)
|
||||||
|
@ -82,7 +77,7 @@ void GlyphEditorWidget::draw_at_mouse(const GMouseEvent& event)
|
||||||
return;
|
return;
|
||||||
bitmap.set_bit_at(x, y, set);
|
bitmap.set_bit_at(x, y, set);
|
||||||
if (on_glyph_altered)
|
if (on_glyph_altered)
|
||||||
on_glyph_altered();
|
on_glyph_altered(m_glyph);
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,7 @@ public:
|
||||||
Font& font() { return *m_font; }
|
Font& font() { return *m_font; }
|
||||||
const Font& font() const { return *m_font; }
|
const Font& font() const { return *m_font; }
|
||||||
|
|
||||||
Function<void()> on_glyph_altered;
|
Function<void(byte)> on_glyph_altered;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
virtual void paint_event(GPaintEvent&) override;
|
virtual void paint_event(GPaintEvent&) override;
|
||||||
|
|
|
@ -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);
|
GPainter painter(*this);
|
||||||
|
painter.add_clip_rect(event.rect());
|
||||||
|
|
||||||
painter.set_font(font());
|
painter.set_font(font());
|
||||||
painter.fill_rect(rect(), Color::White);
|
painter.fill_rect(rect(), Color::White);
|
||||||
painter.draw_rect(rect(), Color::Black);
|
painter.draw_rect(rect(), Color::Black);
|
||||||
|
@ -63,16 +70,13 @@ void GlyphMapWidget::paint_event(GPaintEvent&)
|
||||||
font().glyph_height()
|
font().glyph_height()
|
||||||
);
|
);
|
||||||
if (glyph == m_selected_glyph) {
|
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);
|
painter.draw_glyph(inner_rect.location(), glyph, Color::White);
|
||||||
} else {
|
} else {
|
||||||
painter.draw_glyph(inner_rect.location(), glyph, Color::Black);
|
painter.draw_glyph(inner_rect.location(), glyph, Color::Black);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_focused())
|
|
||||||
painter.draw_focus_rect(rect());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GlyphMapWidget::mousedown_event(GMouseEvent& event)
|
void GlyphMapWidget::mousedown_event(GMouseEvent& event)
|
||||||
|
|
|
@ -20,6 +20,8 @@ public:
|
||||||
Font& font() { return *m_font; }
|
Font& font() { return *m_font; }
|
||||||
const Font& font() const { return *m_font; }
|
const Font& font() const { return *m_font; }
|
||||||
|
|
||||||
|
void update_glyph(byte);
|
||||||
|
|
||||||
Function<void(byte)> on_glyph_selected;
|
Function<void(byte)> on_glyph_selected;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue