src/interactions.cpp
/***********************************************************
* Interaction between WorldSpace and MouseMarker
* -> Handles panning and zooming
***********************************************************/
Interaction between WorldSpace and MouseMarker
> Handles panning and zooming
Interaction between WorldSpace and MouseMarker > Handles panning and zooming
void interaction(WorldSpace& world, MouseMarker& mouse)
{ 
  Vec2 mpos_s  = mouse.screen_position();
  Vec2 mpos_w1 = mpos_s / world.scale();
  const Vec2 zoom = world.zoom();
  if ( IsKeyDown( KEY_Q ) ) 
    world.scale_multiply( zoom.x );
  if ( IsKeyDown( KEY_A ) ) 
    world.scale_multiply( zoom.y );
  Vec2 mpos_w2 = mpos_s / world.scale();
  world.offset_add( mpos_w1 - mpos_w2 );
  if ( IsMouseButtonPressed( MOUSE_BUTTON_LEFT ) )
    world.pan( mpos_w1 );
  if ( IsMouseButtonDown( MOUSE_BUTTON_LEFT ) )
  {
    const Vec2 pan_start = world.pan();
    Vec2 dxy = pan_start - mpos_w1;
    world.offset_add( dxy );
    world.pan( mpos_w1 );
  }
}
void interaction ( WorldSpace & world , MouseMarker & mouse ) { Vec2 mpos_s = mouse . screen_position ( ) ; Vec2 mpos_w1 = mpos_s / world . scale ( ) ; const Vec2 zoom = world . zoom ( ) ; if ( IsKeyDown ( KEY_Q ) ) world . scale_multiply ( zoom . x ) ; if ( IsKeyDown ( KEY_A ) ) world . scale_multiply ( zoom . y ) ; Vec2 mpos_w2 = mpos_s / world . scale ( ) ; world . offset_add ( mpos_w1 - mpos_w2 ) ; if ( IsMouseButtonPressed ( MOUSE_BUTTON_LEFT ) ) world . pan ( mpos_w1 ) ; if ( IsMouseButtonDown ( MOUSE_BUTTON_LEFT ) ) { const Vec2 pan_start = world . pan ( ) ; Vec2 dxy = pan_start - mpos_w1 ; world . offset_add ( dxy ) ; world . pan ( mpos_w1 ) ; } }
Interaction between WorldSpace and MouseMarker
> Handles panning and zooming
Interaction between WorldSpace and MouseMarker > Handles panning and zooming
// Handle zooming // Handle panning