| 93 | } |
| 94 | |
| 95 | void Scrollbar::HandleMouseButtonEvent( sf::Mouse::Button button, bool press, int x, int y ) { |
| 96 | if( button != sf::Mouse::Button::Left ) { |
| 97 | return; |
| 98 | } |
| 99 | |
| 100 | if( press ) { |
| 101 | auto slider_rect = GetSliderRect(); |
| 102 | slider_rect.position += GetAllocation().position; |
| 103 | |
| 104 | if( slider_rect.contains( sf::Vector2f( sf::Vector2( x, y ) ) ) ) { |
| 105 | m_dragging = true; |
| 106 | |
| 107 | if( GetOrientation() == Orientation::HORIZONTAL ) { |
| 108 | auto slider_mid = slider_rect.getCenter().x; |
| 109 | m_slider_click_offset = static_cast<float>( x ) + GetAllocation().position.x - slider_mid; |
| 110 | } |
| 111 | else { |
| 112 | auto slider_mid = slider_rect.getCenter().y; |
| 113 | m_slider_click_offset = static_cast<float>( y ) + GetAllocation().position.y - slider_mid; |
| 114 | } |
| 115 | |
| 116 | return; |
| 117 | } |
| 118 | |
| 119 | if( GetOrientation() == Orientation::HORIZONTAL ) { |
| 120 | auto stepper_length = GetAllocation().size.y; |
| 121 | |
| 122 | sf::FloatRect decrease_stepper_rect( GetAllocation().position, {stepper_length, GetAllocation().size.y} ); |
| 123 | sf::FloatRect increase_stepper_rect( { GetAllocation().position.x + GetAllocation().size.x - stepper_length, GetAllocation().position.y }, { stepper_length, GetAllocation().size.y } ); |
| 124 | |
| 125 | if( decrease_stepper_rect.contains( sf::Vector2f( sf::Vector2( x, y ) ) ) ) { |
| 126 | m_decrease_pressed = true; |
| 127 | GetAdjustment()->Decrement(); |
| 128 | m_elapsed_time = 0.f; |
| 129 | m_repeat_wait = true; |
| 130 | Invalidate(); |
| 131 | return; |
| 132 | } |
| 133 | |
| 134 | if( increase_stepper_rect.contains( sf::Vector2f( sf::Vector2( x, y ) ) ) ) { |
| 135 | m_increase_pressed = true; |
| 136 | GetAdjustment()->Increment(); |
| 137 | m_elapsed_time = 0.f; |
| 138 | m_repeat_wait = true; |
| 139 | Invalidate(); |
| 140 | return; |
| 141 | } |
| 142 | } |
| 143 | else { |
| 144 | auto stepper_length = GetAllocation().size.x; |
| 145 | |
| 146 | sf::FloatRect decrease_stepper_rect( GetAllocation().position, {GetAllocation().size.x, stepper_length} ); |
| 147 | sf::FloatRect increase_stepper_rect( { GetAllocation().position.x, GetAllocation().position.y + GetAllocation().size.y - stepper_length }, { GetAllocation().size.x, stepper_length } ); |
| 148 | |
| 149 | if( decrease_stepper_rect.contains( sf::Vector2f( sf::Vector2( x, y ) ) ) ) { |
| 150 | m_decrease_pressed = true; |
| 151 | GetAdjustment()->Decrement(); |
| 152 | m_elapsed_time = 0.f; |
nothing calls this directly
no test coverage detected