samples/05_mouse/03_mouse_move_paint_app/app/main.rb
def check_click
    if inputs.mouse.down #is mouse up or down?
      state.mouse_held = true # mouse is being held down
    elsif inputs.mouse.up # if mouse is up
    state.mouse_held = false # mouse is not being held down or dragged
      state.mouse_dragging = false
    end

    if state.mouse_held &&    # mouse needs to be down
      !inputs.mouse.click &&     # must not be first click
      ((inputs.mouse.previous_click.point.x - inputs.mouse.position.x).abs > 15) # Need to move 15 pixels before "drag"
      state.mouse_dragging = true
    end

    # If the user clicks their mouse inside the grid, the search_lines method is called with a click input type.
    if ((inputs.mouse.click) && (inputs.mouse.click.point.inside_rect? state.grid_border))
      search_lines(inputs.mouse.click.point, :click)

    # If the user drags their mouse inside the grid, the search_lines method is called with a drag input type.
    elsif ((state.mouse_dragging) && (inputs.mouse.position.inside_rect? state.grid_border))
      search_lines(inputs.mouse.position, :drag)
    end
  end
# Checks if the user is keeping the mouse pressed down and sets the mouse_hold variable accordingly using boolean values.
# If the mouse is up, the user cannot drag the mouse.
Checks if the user is keeping the mouse pressed down and sets the mouse_hold variable accordingly using boolean values.
If the mouse is up, the user cannot drag the mouse.
Checks if the user is keeping the mouse pressed down and sets the mouse_hold variable accordingly using boolean values . If the mouse is up the user cannot drag the mouse .
def check_click
    if inputs.mouse.down 
      state.mouse_held = true 
    elsif inputs.mouse.up 
    state.mouse_held = false 
      state.mouse_dragging = false
    end
    if state.mouse_held &&    
      !inputs.mouse.click &&     
      ((inputs.mouse.previous_click.point.x - inputs.mouse.position.x).abs > 15) 
      state.mouse_dragging = true
    end
    if ((inputs.mouse.click) && (inputs.mouse.click.point.inside_rect? state.grid_border))
      search_lines(inputs.mouse.click.point, :click)
    elsif ((state.mouse_dragging) && (inputs.mouse.position.inside_rect? state.grid_border))
      search_lines(inputs.mouse.position, :drag)
    end
  end
def check_click if inputs . mouse . down state . mouse_held = true elsif inputs . mouse . up state . mouse_held = false state . mouse_dragging = false end if state . mouse_held && ! inputs . mouse . click && ( ( inputs . mouse . previous_click . point . x - inputs . mouse . position . x ) . abs > 15 ) state . mouse_dragging = true end if ( ( inputs . mouse . click ) && ( inputs . mouse . click . point . inside_rect? state . grid_border ) ) search_lines ( inputs . mouse . click . point , :click ) elsif ( ( state . mouse_dragging ) && ( inputs . mouse . position . inside_rect? state . grid_border ) ) search_lines ( inputs . mouse . position , :drag ) end end
Checks if the user is keeping the mouse pressed down and sets the mouse_hold variable accordingly using boolean values.
Checks if the user is keeping the mouse pressed down and sets the mouse_hold variable accordingly using boolean values .
#is mouse up or down? # mouse is being held down # if mouse is up # mouse is not being held down or dragged # mouse needs to be down # must not be first click # Need to move 15 pixels before "drag" # If the user clicks their mouse inside the grid, the search_lines method is called with a click input type. # If the user drags their mouse inside the grid, the search_lines method is called with a drag input type.