samples/05_mouse/03_mouse_move_paint_app/app/main.rb
# Creates and outputs a "Clear" button on the screen using a label and a border.
# If the button is clicked, the filled squares are cleared, making the filled_squares collection empty.
Creates and outputs a "Clear" button on the screen using a label and a border.
If the button is clicked, the filled squares are cleared, making the filled_squares collection empty.
Creates and outputs a " Clear " button on the screen using a label and a border . If the button is clicked the filled squares are cleared making the filled_squares collection empty .
def draw_buttons
    x, y, w, h = 390, 50, 240, 50
    state.clear_button        ||= state.new_entity(:button_with_fade)
    state.clear_button.label  ||= [x + w.half, y + h.half + 10, "Clear", 0, 1] 
    state.clear_button.border ||= [x, y, w, h]
    if inputs.mouse.click && inputs.mouse.click.point.inside_rect?(state.clear_button.border)
      state.clear_button.clicked_at = inputs.mouse.click.created_at 
      state.filled_squares.clear
      inputs.mouse.previous_click = nil
    end
    outputs.labels << state.clear_button.label
    outputs.borders << state.clear_button.border
    if state.clear_button.clicked_at
      outputs.solids << [x, y, w, h, 0, 180, 80, 255 * state.clear_button.clicked_at.ease(0.25.seconds, :flip)]
    end
  end
def draw_buttons x , y , w , h = 390 , 50 , 240 , 50 state . clear_button ||= state . new_entity ( :button_with_fade ) state . clear_button . label ||= [ x + w . half , y + h . half + 10 , "Clear" , 0 , 1 ] state . clear_button . border ||= [ x , y , w , h ] if inputs . mouse . click && inputs . mouse . click . point . inside_rect? ( state . clear_button . border ) state . clear_button . clicked_at = inputs . mouse . click . created_at state . filled_squares . clear inputs . mouse . previous_click = nil end outputs . labels << state . clear_button . label outputs . borders << state . clear_button . border if state . clear_button . clicked_at outputs . solids << [ x , y , w , h , 0 , 180 , 80 , 255 * state . clear_button . clicked_at . ease ( 0.25 . seconds , :flip ) ] end end
Creates and outputs a "Clear" button on the screen using a label and a border.
Creates and outputs a " Clear " button on the screen using a label and a border .
# The x and y positions are set to display the label in the center of the button. # Try changing the first two parameters to simply x, y and see what happens to the text placement! # placed in center of border # If the mouse is clicked inside the borders of the clear button, # the filled_squares collection is emptied and the squares are cleared. # time (frame) the click occurred # When the clear button is clicked, the color of the button changes # and the transparency changes, as well. If you change the time from # 0.25.seconds to 1.25.seconds or more, the change will last longer.