| 73 | } |
| 74 | |
| 75 | void SpinButton::HandleMouseButtonEvent( sf::Mouse::Button button, bool press, int x, int y ) { |
| 76 | float border_width( Context::Get().GetEngine().GetProperty<float>( "BorderWidth", shared_from_this() ) ); |
| 77 | float stepper_aspect_ratio( Context::Get().GetEngine().GetProperty<float>( "StepperAspectRatio", shared_from_this() ) ); |
| 78 | |
| 79 | if( button != sf::Mouse::Button::Left ) { |
| 80 | return; |
| 81 | } |
| 82 | |
| 83 | auto stepper_height = ( GetAllocation().size.y / 2.f ) - border_width; |
| 84 | auto stepper_width = ( GetAllocation().size.y / 2.f ) * stepper_aspect_ratio; |
| 85 | |
| 86 | if( press ) { |
| 87 | // Top stepper. |
| 88 | sf::FloatRect rect; |
| 89 | rect.position.x = GetAllocation().position.x + GetAllocation().size.x - border_width - stepper_width; |
| 90 | rect.position.y = GetAllocation().position.y + border_width; |
| 91 | rect.size = {stepper_width, stepper_height}; |
| 92 | |
| 93 | if( rect.contains( sf::Vector2f( sf::Vector2( x, y ) ) ) ) { |
| 94 | GrabFocus( Widget::Ptr() ); |
| 95 | |
| 96 | m_adjustment->Increment(); |
| 97 | |
| 98 | m_elapsed_time = 0.f; |
| 99 | m_increase_pressed = true; |
| 100 | m_repeat_wait = true; |
| 101 | |
| 102 | Invalidate(); |
| 103 | return; |
| 104 | } |
| 105 | |
| 106 | // Bottom stepper. |
| 107 | rect.position.y = GetAllocation().position.y + border_width + stepper_height; |
| 108 | |
| 109 | if( rect.contains( sf::Vector2f( sf::Vector2( x, y ) ) ) ) { |
| 110 | GrabFocus( Widget::Ptr() ); |
| 111 | |
| 112 | m_adjustment->Decrement(); |
| 113 | |
| 114 | m_elapsed_time = 0.f; |
| 115 | m_decrease_pressed = true; |
| 116 | m_repeat_wait = true; |
| 117 | |
| 118 | Invalidate(); |
| 119 | return; |
| 120 | } |
| 121 | } |
| 122 | else { |
| 123 | if( m_decrease_pressed || m_increase_pressed ) { |
| 124 | Invalidate(); |
| 125 | } |
| 126 | |
| 127 | m_decrease_pressed = false; |
| 128 | m_increase_pressed = false; |
| 129 | } |
| 130 | |
| 131 | Entry::HandleMouseButtonEvent( button, press, x, y ); |
| 132 | } |