src/interactions.cpp
/***********************************************************
* Interaction between BackgroundGrid and MouseMarker
* -> Handles snapping of mouse to grid nodes
***********************************************************/
Interaction between BackgroundGrid and MouseMarker
> Handles snapping of mouse to grid nodes
Interaction between BackgroundGrid and MouseMarker > Handles snapping of mouse to grid nodes
void interaction(const WorldSpace&     world, 
                 const BackgroundGrid& grid,
                 MouseMarker&          mouse)
{
  Vec2 marker_pos = GetMousePosition();
  world.screen_to_world( marker_pos, marker_pos ); 
  const Vec2 delta = grid.delta();
  int i = (marker_pos.x + 0.5 * delta.x) / delta.x;
  int j = (marker_pos.y + 0.5 * delta.y) / delta.y;
  marker_pos.x = i * delta.x;
  marker_pos.y = j * delta.y;
  const Vec2 lower = grid.lower_bound();
  const Vec2 upper = grid.upper_bound();
  marker_pos.x = std::max( marker_pos.x, lower.x );
  marker_pos.x = std::min( marker_pos.x, upper.x );
  marker_pos.y = std::max( marker_pos.y, lower.y );
  marker_pos.y = std::min( marker_pos.y, upper.y );
  world.world_to_screen( marker_pos, marker_pos );
  mouse.marker_position( marker_pos );
}
void interaction ( const WorldSpace & world , const BackgroundGrid & grid , MouseMarker & mouse ) { Vec2 marker_pos = GetMousePosition ( ) ; world . screen_to_world ( marker_pos , marker_pos ) ; const Vec2 delta = grid . delta ( ) ; int i = ( marker_pos . x + 0.5 * delta . x ) / delta . x ; int j = ( marker_pos . y + 0.5 * delta . y ) / delta . y ; marker_pos . x = i * delta . x ; marker_pos . y = j * delta . y ; const Vec2 lower = grid . lower_bound ( ) ; const Vec2 upper = grid . upper_bound ( ) ; marker_pos . x = std :: max ( marker_pos . x , lower . x ) ; marker_pos . x = std :: min ( marker_pos . x , upper . x ) ; marker_pos . y = std :: max ( marker_pos . y , lower . y ) ; marker_pos . y = std :: min ( marker_pos . y , upper . y ) ; world . world_to_screen ( marker_pos , marker_pos ) ; mouse . marker_position ( marker_pos ) ; }
Interaction between BackgroundGrid and MouseMarker
> Handles snapping of mouse to grid nodes
Interaction between BackgroundGrid and MouseMarker > Handles snapping of mouse to grid nodes
// Clip to grid minima & maxima