samples/05_mouse/03_mouse_move_paint_app/app/main.rb
# Sets the definition of a grid box and handles user input to fill in or clear grid boxes.
Sets the definition of a grid box and handles user input to fill in or clear grid boxes.
Sets the definition of a grid box and handles user input to fill in or clear grid boxes .
def search_lines (point, input_type)
    point.x -= state.paint_grid["x"] 
    point.y -= state.paint_grid["y"] 
    point.x = (point.x / state.paint_grid["dist_x"]).floor * state.paint_grid["dist_x"]
    point.y = (point.y / state.paint_grid["dist_y"]).floor * state.paint_grid["dist_y"]
    point.x += state.paint_grid["x"]
    point.y += state.paint_grid["y"]
    grid_box = [ point.x.floor, point.y.floor, state.paint_grid["dist_x"].ceil, state.paint_grid["dist_y"].ceil ]
    if input_type == :click 
      if state.filled_squares.include? grid_box 
        state.filled_squares.delete grid_box 
      else
        state.filled_squares << grid_box 
      end
    elsif input_type == :drag 
      unless state.filled_squares.include? grid_box 
        state.filled_squares << grid_box 
      end
    end
  end
def search_lines ( point , input_type ) point . x -= state . paint_grid [ "x" ] point . y -= state . paint_grid [ "y" ] point . x = ( point . x / state . paint_grid [ "dist_x" ] ) . floor * state . paint_grid [ "dist_x" ] point . y = ( point . y / state . paint_grid [ "dist_y" ] ) . floor * state . paint_grid [ "dist_y" ] point . x += state . paint_grid [ "x" ] point . y += state . paint_grid [ "y" ] grid_box = [ point . x . floor , point . y . floor , state . paint_grid [ "dist_x" ] . ceil , state . paint_grid [ "dist_y" ] . ceil ] if input_type == :click if state . filled_squares . include? grid_box state . filled_squares . delete grid_box else state . filled_squares << grid_box end elsif input_type == :drag unless state . filled_squares . include? grid_box state . filled_squares << grid_box end end end
Sets the definition of a grid box and handles user input to fill in or clear grid boxes.
Sets the definition of a grid box and handles user input to fill in or clear grid boxes .
# subtracts the value assigned to the "x" key in the paint_grid hash # subtracts the value assigned to the "y" key in the paint_grid hash # Remove code following the .floor and see what happens when you try to fill in grid squares # Sets definition of a grid box, meaning its x, y, width, and height. # Floor is called on the point.x and point.y variables. # Ceil method is called on values of the distance hash keys, setting the width and height of a box. # if user clicks their mouse # if grid box is already filled in # box is cleared and removed from filled_squares # otherwise, box is filled in and added to filled_squares # if user drags mouse # unless the grid box dragged over is already filled in # the box is filled in and added to filled_squares
point
input_type