| 131 | } |
| 132 | |
| 133 | void Window::HandleMouseButtonEvent( sf::Mouse::Button button, bool press, int x, int y ) { |
| 134 | if( button != sf::Mouse::Button::Left ) { |
| 135 | return; |
| 136 | } |
| 137 | |
| 138 | if( !press ) { |
| 139 | m_dragging = false; |
| 140 | m_resizing = false; |
| 141 | return; |
| 142 | } |
| 143 | |
| 144 | unsigned int title_font_size( Context::Get().GetEngine().GetProperty<unsigned int>( "FontSize", shared_from_this() ) ); |
| 145 | const sf::Font& title_font( *Context::Get().GetEngine().GetResourceManager().GetFont( Context::Get().GetEngine().GetProperty<std::string>( "FontName", shared_from_this() ) ) ); |
| 146 | float title_height( |
| 147 | Context::Get().GetEngine().GetFontLineHeight( title_font, title_font_size ) + |
| 148 | 2 * Context::Get().GetEngine().GetProperty<float>( "TitlePadding", shared_from_this() ) |
| 149 | ); |
| 150 | |
| 151 | // Check for mouse being inside the title area. |
| 152 | sf::FloatRect area( |
| 153 | GetAllocation().position, |
| 154 | { GetAllocation().size.x, title_height } |
| 155 | ); |
| 156 | |
| 157 | if( area.contains( sf::Vector2f( sf::Vector2( x, y ) ) ) ) { |
| 158 | if( HasStyle( TITLEBAR ) && !m_dragging ) { |
| 159 | if( HasStyle( CLOSE ) ) { |
| 160 | auto close_height( Context::Get().GetEngine().GetProperty<float>( "CloseHeight", shared_from_this() ) ); |
| 161 | |
| 162 | auto button_margin = ( title_height - close_height ) / 2.f; |
| 163 | |
| 164 | auto close_rect = sf::FloatRect( |
| 165 | { GetAllocation().position.x + GetAllocation().size.x - button_margin - close_height, GetAllocation().position.y + button_margin }, |
| 166 | { close_height, close_height } |
| 167 | ); |
| 168 | |
| 169 | if( close_rect.contains( sf::Vector2f( sf::Vector2( x, y ) ) ) ) { |
| 170 | GetSignals().Emit( OnCloseButton ); |
| 171 | return; |
| 172 | } |
| 173 | } |
| 174 | |
| 175 | m_dragging = true; |
| 176 | m_resizing = false; |
| 177 | |
| 178 | m_drag_offset = sf::Vector2f( |
| 179 | static_cast<float>( x ) - GetAllocation().position.x, |
| 180 | static_cast<float>( y ) - GetAllocation().position.y |
| 181 | ); |
| 182 | } |
| 183 | } |
| 184 | else { |
| 185 | float handle_size( Context::Get().GetEngine().GetProperty<float>( "HandleSize", shared_from_this() ) ); |
| 186 | |
| 187 | area.position.x = GetAllocation().position.x + GetAllocation().size.x - handle_size; |
| 188 | area.position.y = GetAllocation().position.y + GetAllocation().size.y - handle_size; |
| 189 | area.size.x = handle_size; |
| 190 | area.size.y = handle_size; |
nothing calls this directly
no test coverage detected