A lightweight programming environment for desktop and mobile devices
on.mouse_press = function(x,y, mouse_button)
	-- == menu area
	-- some hysteresis right after a button has been pressed
	if Active_button then return end
	if mouse_press_consumed_by_any_button(Global_state, x,y, mouse_button) then
		Button_pressed = true
		return
	end
	-- == settings area
	if mouse_press_consumed_by_any_slider(Global_state, x,y) then
		return
	end
	if Show_menu == 'settings' then
		if on_area(Settings_menu_area, x,y) then
			-- nothing atm in settings menu that isn't a button or slider
		else
			Show_menu = nil
			-- On mobile devices, we can't depend on on.save_settings() triggering on quit.
			-- So save settings every time we close the settings menu.
			love.filesystem.write('config', json.encode(settings()))
		end
		return
	end
	-- == main area
	Show_menu = nil
	if Show_code then
		if on_editor_scrollbar(Current_pane.editor_state, x,y) then
			Current_pane.editor_state.scrollbar_drag = true
			local sbtopy = compute_scrollbar_topy(Current_pane.editor_state)
			Current_pane.editor_state.scrollbar_offset = y - sbtopy
		elseif on_editor_scrollbar_area(Current_pane.editor_state, x,y) then
			-- nothing
		elseif x < Current_pane.editor_state.right + 15 - 5 and y < Current_pane.editor_state.bottom + 5 + 10 - 5 then
			love.keyboard.setTextInput(true)
			edit.mouse_press(Current_pane.editor_state, x,y, mouse_button)
		elseif on_editor_scrollbar(Current_pane.output_editor_state, x,y) then
			Current_pane.output_editor_state.scrollbar_drag = true
			local sbtopy = compute_scrollbar_topy(Current_pane.output_editor_state)
			Current_pane.output_editor_state.scrollbar_offset = y - sbtopy
		elseif on_editor_scrollbar_area(Current_pane.output_editor_state, x,y) then
			-- nothing
		end
	else
		-- editors hidden
		if car.mouse_press then
			call_protected(car.mouse_press, x,y, mouse_button)
		end
		if car.mousepressed then
			call_protected(car.mousepressed, x,y, mouse_button)
		end
	end
end