MCPcopy Create free account
hub / github.com/TankOs/SFGUI / HandleMouseButtonEvent

Method HandleMouseButtonEvent

src/SFGUI/ComboBox.cpp:275–348  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

273}
274
275void ComboBox::HandleMouseButtonEvent( sf::Mouse::Button button, bool press, int x, int y ) {
276 if( ( x == std::numeric_limits<int>::min() ) || ( y == std::numeric_limits<int>::min() ) ) {
277 return;
278 }
279
280 if( GetState() == State::ACTIVE ) {
281 if( m_scrollbar ) {
282 ReleaseModal();
283 m_scrollbar->SetActiveWidget();
284
285 if ( press ) {
286 sf::Event::MouseButtonPressed event;
287 event.button = button;
288 event.position.x = x - static_cast<int>( GetAllocation().position.x );
289 event.position.y = y - static_cast<int>( GetAllocation().position.y );
290 m_scrollbar->HandleEvent( event );
291 }
292 else {
293 sf::Event::MouseButtonReleased event;
294 event.button = button;
295 event.position.x = x - static_cast<int>( GetAllocation().position.x );
296 event.position.y = y - static_cast<int>( GetAllocation().position.y );
297 m_scrollbar->HandleEvent( event );
298 }
299
300 SetActiveWidget();
301 GrabModal();
302
303 auto scrollbar_allocation = m_scrollbar->GetAllocation();
304 scrollbar_allocation.position += GetAllocation().position;
305
306 if( scrollbar_allocation.contains( sf::Vector2f( sf::Vector2( x, y ) ) ) ) {
307 return;
308 }
309 }
310
311 if( !press || ( button != sf::Mouse::Button::Left ) ) {
312 return;
313 }
314
315 auto emit_select = false;
316
317 if( m_highlighted_item != NONE ) {
318 m_active_item = m_highlighted_item;
319 emit_select = true;
320 }
321
322 m_highlighted_item = NONE;
323
324 if( IsMouseInWidget() ) {
325 SetState( State::PRELIGHT );
326 }
327 else {
328 SetState( State::NORMAL );
329 }
330
331 Invalidate();
332

Callers

nothing calls this directly

Calls 3

EmitMethod · 0.80
SetActiveWidgetMethod · 0.45
HandleEventMethod · 0.45

Tested by

no test coverage detected