| 
									
										
										
										
											2019-02-09 11:19:38 +01:00
										 |  |  | #pragma once
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <AK/Function.h>
 | 
					
						
							| 
									
										
										
										
											2019-06-07 10:43:10 +02:00
										 |  |  | #include <LibCore/CTimer.h>
 | 
					
						
							| 
									
										
										
										
											2019-05-28 11:53:16 +02:00
										 |  |  | #include <LibGUI/GWidget.h>
 | 
					
						
							| 
									
										
										
										
											2019-02-09 11:19:38 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | class GScrollBar final : public GWidget { | 
					
						
							|  |  |  | public: | 
					
						
							| 
									
										
										
										
											2019-02-10 11:57:19 +01:00
										 |  |  |     explicit GScrollBar(Orientation, GWidget* parent); | 
					
						
							| 
									
										
										
										
											2019-02-09 11:19:38 +01:00
										 |  |  |     virtual ~GScrollBar() override; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-10 11:57:19 +01:00
										 |  |  |     Orientation orientation() const { return m_orientation; } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-09 11:19:38 +01:00
										 |  |  |     int value() const { return m_value; } | 
					
						
							|  |  |  |     int min() const { return m_min; } | 
					
						
							|  |  |  |     int max() const { return m_max; } | 
					
						
							|  |  |  |     int step() const { return m_step; } | 
					
						
							|  |  |  |     int big_step() const { return m_big_step; } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-19 01:05:59 +02:00
										 |  |  |     void set_min(int min) { set_range(min, max()); } | 
					
						
							|  |  |  |     void set_max(int max) { set_range(min(), max); } | 
					
						
							| 
									
										
										
										
											2019-02-09 11:19:38 +01:00
										 |  |  |     void set_range(int min, int max); | 
					
						
							|  |  |  |     void set_value(int value); | 
					
						
							|  |  |  |     void set_step(int step) { m_step = step; } | 
					
						
							|  |  |  |     void set_big_step(int big_step) { m_big_step = big_step; } | 
					
						
							| 
									
										
										
										
											2019-02-10 07:11:01 +01:00
										 |  |  |     bool has_scrubber() const; | 
					
						
							| 
									
										
										
										
											2019-02-09 11:19:38 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     Function<void(int)> on_change; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-16 12:57:04 +01:00
										 |  |  |     virtual const char* class_name() const override { return "GScrollBar"; } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-07 17:13:23 +02:00
										 |  |  |     enum Component { | 
					
						
							| 
									
										
										
										
											2019-04-06 13:55:56 +02:00
										 |  |  |         Invalid, | 
					
						
							|  |  |  |         DecrementButton, | 
					
						
							|  |  |  |         IncrementButton, | 
					
						
							|  |  |  |         Gutter, | 
					
						
							|  |  |  |         Scrubber, | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-09 11:19:38 +01:00
										 |  |  | private: | 
					
						
							|  |  |  |     virtual void paint_event(GPaintEvent&) override; | 
					
						
							|  |  |  |     virtual void mousedown_event(GMouseEvent&) override; | 
					
						
							| 
									
										
										
										
											2019-02-10 06:51:01 +01:00
										 |  |  |     virtual void mouseup_event(GMouseEvent&) override; | 
					
						
							|  |  |  |     virtual void mousemove_event(GMouseEvent&) override; | 
					
						
							| 
									
										
										
										
											2019-04-10 16:56:55 +02:00
										 |  |  |     virtual void leave_event(CEvent&) override; | 
					
						
							| 
									
										
										
										
											2019-05-25 13:40:57 +02:00
										 |  |  |     virtual void change_event(GEvent&) override; | 
					
						
							| 
									
										
										
										
											2019-02-09 11:19:38 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-01 02:46:36 -05:00
										 |  |  |     int default_button_size() const { return 16; } | 
					
						
							|  |  |  |     int button_size() const { return length(orientation()) <= (default_button_size() * 2) ? length(orientation()) / 2 : default_button_size(); } | 
					
						
							| 
									
										
										
										
											2019-04-11 13:16:43 +02:00
										 |  |  |     int button_width() const { return orientation() == Orientation::Vertical ? width() : button_size(); } | 
					
						
							|  |  |  |     int button_height() const { return orientation() == Orientation::Horizontal ? height() : button_size(); } | 
					
						
							| 
									
										
										
										
											2019-06-07 10:56:30 +02:00
										 |  |  |     Rect decrement_button_rect() const; | 
					
						
							|  |  |  |     Rect increment_button_rect() const; | 
					
						
							|  |  |  |     Rect decrement_gutter_rect() const; | 
					
						
							|  |  |  |     Rect increment_gutter_rect() const; | 
					
						
							| 
									
										
										
										
											2019-02-09 11:19:38 +01:00
										 |  |  |     Rect scrubber_rect() const; | 
					
						
							| 
									
										
										
										
											2019-03-29 02:51:19 +01:00
										 |  |  |     int scrubber_size() const; | 
					
						
							| 
									
										
										
										
											2019-02-10 06:51:01 +01:00
										 |  |  |     int scrubbable_range_in_pixels() const; | 
					
						
							| 
									
										
										
										
											2019-06-07 10:43:10 +02:00
										 |  |  |     void on_automatic_scrolling_timer_fired(); | 
					
						
							|  |  |  |     void set_automatic_scrolling_active(bool); | 
					
						
							| 
									
										
										
										
											2019-02-09 11:19:38 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     int m_min { 0 }; | 
					
						
							|  |  |  |     int m_max { 0 }; | 
					
						
							|  |  |  |     int m_value { 0 }; | 
					
						
							|  |  |  |     int m_step { 1 }; | 
					
						
							|  |  |  |     int m_big_step { 5 }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-10 06:51:01 +01:00
										 |  |  |     bool m_scrubbing { false }; | 
					
						
							|  |  |  |     int m_scrub_start_value { 0 }; | 
					
						
							|  |  |  |     Point m_scrub_origin; | 
					
						
							| 
									
										
										
										
											2019-02-10 11:57:19 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     Orientation m_orientation { Orientation::Vertical }; | 
					
						
							| 
									
										
										
										
											2019-04-06 13:55:56 +02:00
										 |  |  |     Component m_hovered_component { Component::Invalid }; | 
					
						
							| 
									
										
										
										
											2019-06-07 10:43:10 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-07 17:13:23 +02:00
										 |  |  |     enum class AutomaticScrollingDirection { | 
					
						
							| 
									
										
										
										
											2019-06-07 10:43:10 +02:00
										 |  |  |         None = 0, | 
					
						
							|  |  |  |         Decrement, | 
					
						
							|  |  |  |         Increment, | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     AutomaticScrollingDirection m_automatic_scrolling_direction { AutomaticScrollingDirection::None }; | 
					
						
							|  |  |  |     CTimer m_automatic_scrolling_timer; | 
					
						
							| 
									
										
										
										
											2019-02-10 06:51:01 +01:00
										 |  |  | }; |