1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-30 06:25:12 +00:00

Terminal: Changex internal opacity representation to byte instead of float.

This lets us avoid some math during paint events.
Patch contributed by "pd"
This commit is contained in:
Andreas Kling 2019-06-28 21:41:13 +02:00
parent ffcbe8f0de
commit 274b41e47c
3 changed files with 14 additions and 14 deletions

View file

@ -1057,7 +1057,7 @@ void Terminal::paint_event(GPaintEvent& event)
if (m_visual_beep_timer.is_active()) if (m_visual_beep_timer.is_active())
painter.fill_rect(frame_inner_rect(), Color::Red); painter.fill_rect(frame_inner_rect(), Color::Red);
else else
painter.fill_rect(frame_inner_rect(), Color(Color::Black).with_alpha(255 * m_opacity)); painter.fill_rect(frame_inner_rect(), Color(Color::Black).with_alpha(m_opacity));
invalidate_cursor(); invalidate_cursor();
for (word row = 0; row < m_rows; ++row) { for (word row = 0; row < m_rows; ++row) {
@ -1066,7 +1066,7 @@ void Terminal::paint_event(GPaintEvent& event)
if (m_visual_beep_timer.is_active()) if (m_visual_beep_timer.is_active())
painter.fill_rect(row_rect(row), Color::Red); painter.fill_rect(row_rect(row), Color::Red);
else if (has_only_one_background_color) else if (has_only_one_background_color)
painter.fill_rect(row_rect(row), lookup_color(line.attributes[0].background_color).with_alpha(255 * m_opacity)); painter.fill_rect(row_rect(row), lookup_color(line.attributes[0].background_color).with_alpha(m_opacity));
for (word column = 0; column < m_columns; ++column) { for (word column = 0; column < m_columns; ++column) {
char ch = line.characters[column]; char ch = line.characters[column];
bool should_reverse_fill_for_cursor_or_selection = (m_cursor_blink_state && m_in_active_window && row == m_cursor_row && column == m_cursor_column) bool should_reverse_fill_for_cursor_or_selection = (m_cursor_blink_state && m_in_active_window && row == m_cursor_row && column == m_cursor_column)
@ -1075,7 +1075,7 @@ void Terminal::paint_event(GPaintEvent& event)
auto character_rect = glyph_rect(row, column); auto character_rect = glyph_rect(row, column);
if (!has_only_one_background_color || should_reverse_fill_for_cursor_or_selection) { if (!has_only_one_background_color || should_reverse_fill_for_cursor_or_selection) {
auto cell_rect = character_rect.inflated(0, m_line_spacing); auto cell_rect = character_rect.inflated(0, m_line_spacing);
painter.fill_rect(cell_rect, lookup_color(should_reverse_fill_for_cursor_or_selection ? attribute.foreground_color : attribute.background_color).with_alpha(255 * m_opacity)); painter.fill_rect(cell_rect, lookup_color(should_reverse_fill_for_cursor_or_selection ? attribute.foreground_color : attribute.background_color).with_alpha(m_opacity));
} }
if (ch == ' ') if (ch == ' ')
continue; continue;
@ -1144,12 +1144,13 @@ void Terminal::update_cursor()
flush_dirty_lines(); flush_dirty_lines();
} }
void Terminal::set_opacity(float opacity) void Terminal::set_opacity(byte new_opacity)
{ {
if (m_opacity == opacity) if (m_opacity == new_opacity)
return; return;
window()->set_has_alpha_channel(opacity < 1);
m_opacity = opacity; window()->set_has_alpha_channel(new_opacity < 255);
m_opacity = new_opacity;
force_repaint(); force_repaint();
} }

View file

@ -68,7 +68,7 @@ public:
void apply_size_increments_to_window(GWindow&); void apply_size_increments_to_window(GWindow&);
void set_opacity(float); void set_opacity(byte);
float opacity() { return m_opacity; }; float opacity() { return m_opacity; };
bool should_beep() { return m_should_beep; } bool should_beep() { return m_should_beep; }
void set_should_beep(bool sb) { m_should_beep = sb; }; void set_should_beep(bool sb) { m_should_beep = sb; };
@ -258,7 +258,7 @@ private:
CNotifier m_notifier; CNotifier m_notifier;
float m_opacity { 1 }; byte m_opacity { 255 };
bool m_needs_background_fill { true }; bool m_needs_background_fill { true };
bool m_cursor_blink_state { true }; bool m_cursor_blink_state { true };

View file

@ -119,12 +119,11 @@ GWindow* create_settings_window(Terminal& terminal, RefPtr<CConfigFile> config)
slider->set_background_color(Color::LightGray); slider->set_background_color(Color::LightGray);
slider->on_value_changed = [&terminal, &config](int value) { slider->on_value_changed = [&terminal, &config](int value) {
float opacity = value / 100.0; terminal.set_opacity(value);
terminal.set_opacity(opacity);
}; };
slider->set_range(0, 100); slider->set_range(0, 255);
slider->set_value(terminal.opacity() * 100.0); slider->set_value(terminal.opacity());
return window; return window;
} }
@ -162,7 +161,7 @@ int main(int argc, char** argv)
WeakPtr<GWindow> settings_window; WeakPtr<GWindow> settings_window;
auto new_opacity = config->read_num_entry("Window", "Opacity", 255); auto new_opacity = config->read_num_entry("Window", "Opacity", 255);
terminal.set_opacity((float)new_opacity / 255.0); terminal.set_opacity(new_opacity);
auto menubar = make<GMenuBar>(); auto menubar = make<GMenuBar>();