mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 08:32:43 +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:
		
							parent
							
								
									ffcbe8f0de
								
							
						
					
					
						commit
						274b41e47c
					
				
					 3 changed files with 14 additions and 14 deletions
				
			
		|  | @ -1057,7 +1057,7 @@ void Terminal::paint_event(GPaintEvent& event) | |||
|     if (m_visual_beep_timer.is_active()) | ||||
|         painter.fill_rect(frame_inner_rect(), Color::Red); | ||||
|     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(); | ||||
| 
 | ||||
|     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()) | ||||
|             painter.fill_rect(row_rect(row), Color::Red); | ||||
|         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) { | ||||
|             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) | ||||
|  | @ -1075,7 +1075,7 @@ void Terminal::paint_event(GPaintEvent& event) | |||
|             auto character_rect = glyph_rect(row, column); | ||||
|             if (!has_only_one_background_color || should_reverse_fill_for_cursor_or_selection) { | ||||
|                 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 == ' ') | ||||
|                 continue; | ||||
|  | @ -1144,12 +1144,13 @@ void Terminal::update_cursor() | |||
|     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; | ||||
|     window()->set_has_alpha_channel(opacity < 1); | ||||
|     m_opacity = opacity; | ||||
| 
 | ||||
|     window()->set_has_alpha_channel(new_opacity < 255); | ||||
|     m_opacity = new_opacity; | ||||
|     force_repaint(); | ||||
| } | ||||
| 
 | ||||
|  |  | |||
|  | @ -68,7 +68,7 @@ public: | |||
| 
 | ||||
|     void apply_size_increments_to_window(GWindow&); | ||||
| 
 | ||||
|     void set_opacity(float); | ||||
|     void set_opacity(byte); | ||||
|     float opacity() { return m_opacity; }; | ||||
|     bool should_beep() { return m_should_beep; } | ||||
|     void set_should_beep(bool sb) { m_should_beep = sb; }; | ||||
|  | @ -258,7 +258,7 @@ private: | |||
| 
 | ||||
|     CNotifier m_notifier; | ||||
| 
 | ||||
|     float m_opacity { 1 }; | ||||
|     byte m_opacity { 255 }; | ||||
|     bool m_needs_background_fill { true }; | ||||
|     bool m_cursor_blink_state { true }; | ||||
| 
 | ||||
|  |  | |||
|  | @ -119,12 +119,11 @@ GWindow* create_settings_window(Terminal& terminal, RefPtr<CConfigFile> config) | |||
|     slider->set_background_color(Color::LightGray); | ||||
| 
 | ||||
|     slider->on_value_changed = [&terminal, &config](int value) { | ||||
|         float opacity = value / 100.0; | ||||
|         terminal.set_opacity(opacity); | ||||
|         terminal.set_opacity(value); | ||||
|     }; | ||||
| 
 | ||||
|     slider->set_range(0, 100); | ||||
|     slider->set_value(terminal.opacity() * 100.0); | ||||
|     slider->set_range(0, 255); | ||||
|     slider->set_value(terminal.opacity()); | ||||
| 
 | ||||
|     return window; | ||||
| } | ||||
|  | @ -162,7 +161,7 @@ int main(int argc, char** argv) | |||
|     WeakPtr<GWindow> settings_window; | ||||
| 
 | ||||
|     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>(); | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Andreas Kling
						Andreas Kling