mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 09:02:43 +00:00 
			
		
		
		
	LibDraw+LibGUI: Move radio button painting into StylePainter
This will allow WindowServer to draw radio buttons :^)
This commit is contained in:
		
							parent
							
								
									6c549959c6
								
							
						
					
					
						commit
						cc8c26c39b
					
				
					 3 changed files with 30 additions and 21 deletions
				
			
		|  | @ -1,3 +1,4 @@ | ||||||
|  | #include <LibDraw/GraphicsBitmap.h> | ||||||
| #include <LibDraw/Painter.h> | #include <LibDraw/Painter.h> | ||||||
| #include <LibDraw/Palette.h> | #include <LibDraw/Palette.h> | ||||||
| #include <LibDraw/StylePainter.h> | #include <LibDraw/StylePainter.h> | ||||||
|  | @ -257,3 +258,28 @@ void StylePainter::paint_progress_bar(Painter& painter, const Rect& rect, const | ||||||
|     if (!text.is_null()) |     if (!text.is_null()) | ||||||
|         painter.draw_text(rect.translated(0, 0), text, TextAlignment::Center, palette.base_text()); |         painter.draw_text(rect.translated(0, 0), text, TextAlignment::Center, palette.base_text()); | ||||||
| } | } | ||||||
|  | 
 | ||||||
|  | static RefPtr<GraphicsBitmap> s_unfilled_circle_bitmap; | ||||||
|  | static RefPtr<GraphicsBitmap> s_filled_circle_bitmap; | ||||||
|  | static RefPtr<GraphicsBitmap> s_changing_filled_circle_bitmap; | ||||||
|  | static RefPtr<GraphicsBitmap> s_changing_unfilled_circle_bitmap; | ||||||
|  | 
 | ||||||
|  | static const GraphicsBitmap& circle_bitmap(bool checked, bool changing) | ||||||
|  | { | ||||||
|  |     if (changing) | ||||||
|  |         return checked ? *s_changing_filled_circle_bitmap : *s_changing_unfilled_circle_bitmap; | ||||||
|  |     return checked ? *s_filled_circle_bitmap : *s_unfilled_circle_bitmap; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | void StylePainter::paint_radio_button(Painter& painter, const Rect& rect, const Palette&, bool is_checked, bool is_being_pressed) | ||||||
|  | { | ||||||
|  |     if (!s_unfilled_circle_bitmap) { | ||||||
|  |         s_unfilled_circle_bitmap = GraphicsBitmap::load_from_file("/res/icons/unfilled-radio-circle.png"); | ||||||
|  |         s_filled_circle_bitmap = GraphicsBitmap::load_from_file("/res/icons/filled-radio-circle.png"); | ||||||
|  |         s_changing_filled_circle_bitmap = GraphicsBitmap::load_from_file("/res/icons/changing-filled-radio-circle.png"); | ||||||
|  |         s_changing_unfilled_circle_bitmap = GraphicsBitmap::load_from_file("/res/icons/changing-unfilled-radio-circle.png"); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     auto& bitmap = circle_bitmap(is_checked, is_being_pressed); | ||||||
|  |     painter.blit(rect.location(), bitmap, bitmap.rect()); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | @ -32,4 +32,5 @@ public: | ||||||
|     static void paint_frame(Painter&, const Rect&, const Palette&, FrameShape, FrameShadow, int thickness, bool skip_vertical_lines = false); |     static void paint_frame(Painter&, const Rect&, const Palette&, FrameShape, FrameShadow, int thickness, bool skip_vertical_lines = false); | ||||||
|     static void paint_window_frame(Painter&, const Rect&, const Palette&); |     static void paint_window_frame(Painter&, const Rect&, const Palette&); | ||||||
|     static void paint_progress_bar(Painter&, const Rect&, const Palette&, int min, int max, int value, const StringView& text = {}); |     static void paint_progress_bar(Painter&, const Rect&, const Palette&, int min, int max, int value, const StringView& text = {}); | ||||||
|  |     static void paint_radio_button(Painter&, const Rect&, const Palette&, bool is_checked, bool is_being_pressed); | ||||||
| }; | }; | ||||||
|  |  | ||||||
|  | @ -1,12 +1,8 @@ | ||||||
| #include <LibDraw/GraphicsBitmap.h> | #include <LibDraw/GraphicsBitmap.h> | ||||||
|  | #include <LibDraw/StylePainter.h> | ||||||
| #include <LibGUI/GPainter.h> | #include <LibGUI/GPainter.h> | ||||||
| #include <LibGUI/GRadioButton.h> | #include <LibGUI/GRadioButton.h> | ||||||
| 
 | 
 | ||||||
| static RefPtr<GraphicsBitmap> s_unfilled_circle_bitmap; |  | ||||||
| static RefPtr<GraphicsBitmap> s_filled_circle_bitmap; |  | ||||||
| static RefPtr<GraphicsBitmap> s_changing_filled_circle_bitmap; |  | ||||||
| static RefPtr<GraphicsBitmap> s_changing_unfilled_circle_bitmap; |  | ||||||
| 
 |  | ||||||
| GRadioButton::GRadioButton(GWidget* parent) | GRadioButton::GRadioButton(GWidget* parent) | ||||||
|     : GRadioButton({}, parent) |     : GRadioButton({}, parent) | ||||||
| { | { | ||||||
|  | @ -15,12 +11,6 @@ GRadioButton::GRadioButton(GWidget* parent) | ||||||
| GRadioButton::GRadioButton(const StringView& text, GWidget* parent) | GRadioButton::GRadioButton(const StringView& text, GWidget* parent) | ||||||
|     : GAbstractButton(text, parent) |     : GAbstractButton(text, parent) | ||||||
| { | { | ||||||
|     if (!s_unfilled_circle_bitmap) { |  | ||||||
|         s_unfilled_circle_bitmap = GraphicsBitmap::load_from_file("/res/icons/unfilled-radio-circle.png"); |  | ||||||
|         s_filled_circle_bitmap = GraphicsBitmap::load_from_file("/res/icons/filled-radio-circle.png"); |  | ||||||
|         s_changing_filled_circle_bitmap = GraphicsBitmap::load_from_file("/res/icons/changing-filled-radio-circle.png"); |  | ||||||
|         s_changing_unfilled_circle_bitmap = GraphicsBitmap::load_from_file("/res/icons/changing-unfilled-radio-circle.png"); |  | ||||||
|     } |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| GRadioButton::~GRadioButton() | GRadioButton::~GRadioButton() | ||||||
|  | @ -29,14 +19,7 @@ GRadioButton::~GRadioButton() | ||||||
| 
 | 
 | ||||||
| Size GRadioButton::circle_size() | Size GRadioButton::circle_size() | ||||||
| { | { | ||||||
|     return s_unfilled_circle_bitmap->size(); |     return { 12, 12 }; | ||||||
| } |  | ||||||
| 
 |  | ||||||
| static const GraphicsBitmap& circle_bitmap(bool checked, bool changing) |  | ||||||
| { |  | ||||||
|     if (changing) |  | ||||||
|         return checked ? *s_changing_filled_circle_bitmap : *s_changing_unfilled_circle_bitmap; |  | ||||||
|     return checked ? *s_filled_circle_bitmap : *s_unfilled_circle_bitmap; |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void GRadioButton::paint_event(GPaintEvent& event) | void GRadioButton::paint_event(GPaintEvent& event) | ||||||
|  | @ -47,8 +30,7 @@ void GRadioButton::paint_event(GPaintEvent& event) | ||||||
|     Rect circle_rect { { 2, 0 }, circle_size() }; |     Rect circle_rect { { 2, 0 }, circle_size() }; | ||||||
|     circle_rect.center_vertically_within(rect()); |     circle_rect.center_vertically_within(rect()); | ||||||
| 
 | 
 | ||||||
|     auto& bitmap = circle_bitmap(is_checked(), is_being_pressed()); |     StylePainter::paint_radio_button(painter, circle_rect, palette(), is_checked(), is_being_pressed()); | ||||||
|     painter.blit(circle_rect.location(), bitmap, bitmap.rect()); |  | ||||||
| 
 | 
 | ||||||
|     Rect text_rect { circle_rect.right() + 4, 0, font().width(text()), font().glyph_height() }; |     Rect text_rect { circle_rect.right() + 4, 0, font().width(text()), font().glyph_height() }; | ||||||
|     text_rect.center_vertically_within(rect()); |     text_rect.center_vertically_within(rect()); | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Andreas Kling
						Andreas Kling