samples/02_input_basics/03_mouse_point_to_rect/app/main.rb
# This is useful to determine if a click occurred in a rect
This is useful to determine if a click occurred in a rect
This is useful to determine if a click occurred in a rect
def tick args
  tick_instructions args, "Sample app shows how to determing if a click happened inside a rectangle."
  x = 460
  args.outputs.labels << small_label(args, x, 15, "Click inside the blue box maybe ---->")
  box = { x: 785, y: 370, w: 50, h: 50, r: 0, g: 0, b: 170 }
  args.outputs.borders << box
  if args.inputs.mouse.click
    args.state.last_mouse_click = args.inputs.mouse.click
  end
  if args.state.last_mouse_click
    if args.state.last_mouse_click.point.inside_rect? box
      args.outputs.labels << small_label(args, x, 16, "Mouse click happened *inside* the box.")
    else
      args.outputs.labels << small_label(args, x, 16, "Mouse click happened *outside* the box.")
    end
  else
    args.outputs.labels << small_label(args, x, 16, "Mouse click has not occurred yet.")
  end
end
def tick args tick_instructions args , "Sample app shows how to determing if a click happened inside a rectangle." x = 460 args . outputs . labels << small_label ( args , x , 15 , "Click inside the blue box maybe ---->" ) box = { x : 785 , y : 370 , w : 50 , h : 50 , r : 0 , g : 0 , b : 170 } args . outputs . borders << box if args . inputs . mouse . click args . state . last_mouse_click = args . inputs . mouse . click end if args . state . last_mouse_click if args . state . last_mouse_click . point . inside_rect? box args . outputs . labels << small_label ( args , x , 16 , "Mouse click happened *inside* the box." ) else args . outputs . labels << small_label ( args , x , 16 , "Mouse click happened *outside* the box." ) end else args . outputs . labels << small_label ( args , x , 16 , "Mouse click has not occurred yet." ) end end
This is useful to determine if a click occurred in a rect
This is useful to determine if a click occurred in a rect
# Saves the most recent click into args.state # Unlike the other components of args, # args.state does not reset every tick.
args