~akkartik/carousel.love

3293f3e13900bcc5475ba6edb7c6516d4d1614bd — Kartik K. Agaram a month ago 7232de5
some keyboard shortcuts on non-mobile devices

Hopefully this is easy to remember from left to right:
- run is F1
- stop is F2
- hide/show is F3
- save is F4
- load is F5

There are also tooltips to introduce these shortcuts to newcomers.

Most of the shortcuts are only enabled when code is visible. In keeping
with existing conventions for mouse events, we leave most event handlers
for the script when code is hidden. The only exception is 'F3' to show
code. So if you want to use a shortcut 'k' when code is hidden, you have
to instead use 'F3 k F3'.

This is all tentative and open to change. But I'll probably grow more
reluctant to change the shortcuts in a few weeks or months.
M 0012-on.draw => 0012-on.draw +1 -0
@@ 24,4 24,5 @@ on.draw = function()
	end
	draw_menu()
	draw_next_frames_of_animations()
	draw_button_tooltips(Global_state)
end
\ No newline at end of file

M 0051-run_button => 0051-run_button +1 -1
@@ 1,5 1,5 @@
run_button = function(x, y)
	styled_button('run', x,y, press_run_button)
	styled_button('run', x,y, press_run_button, not Is_mobile and Show_code and 'F1')
	local w = Font:getWidth('run')+10
	return x+w+10, y
end
\ No newline at end of file

M 0059-previous_pane_button => 0059-previous_pane_button +3 -0
@@ 5,5 5,8 @@ previous_pane_button = function()
			love.graphics.polygon('fill', Menu_left+5, App.screen.height/2, Menu_left+25, App.screen.height/2-10, Menu_left+25, App.screen.height/2+10)
		end,
		onpress1 = press_previous_pane_button,
		tooltip = function(x,y)
			show_tooltip(x,y+20, not Is_mobile and Show_code and 'ctrl+left')
		end,
	})
end
\ No newline at end of file

M 0060-next_pane_button => 0060-next_pane_button +4 -0
@@ 5,5 5,9 @@ next_pane_button = function(r)
			love.graphics.polygon('fill', r-25, App.screen.height/2-10, r-25, App.screen.height/2+10,  r-5, App.screen.height/2)
		end,
		onpress1 = press_next_pane_button,
		tooltip = function(x,y)
			local w = App.width('ctrl+right')
			show_tooltip(x-w-10,y+20, not Is_mobile and Show_code and 'ctrl+right')
		end,
	})
end
\ No newline at end of file

M 0064-show_code_button => 0064-show_code_button +1 -1
@@ 1,3 1,3 @@
show_code_button = function(x, y, r)
	return overflowable_button('show', x, y, r, press_show_button)
	return overflowable_button('show', x, y, r, press_show_button, nil, not Is_mobile and 'F3')
end
\ No newline at end of file

M 0065-hide_code_button => 0065-hide_code_button +1 -1
@@ 1,3 1,3 @@
hide_code_button = function(x, y, r)
	return overflowable_button('hide', x, y, r, press_hide_button)
	return overflowable_button('hide', x, y, r, press_hide_button, nil, not Is_mobile and 'F3')
end
\ No newline at end of file

M 0106-stop_button => 0106-stop_button +1 -1
@@ 1,5 1,5 @@
stop_button = function(x, y)
	styled_button('stop', x,y, press_stop_button)
	styled_button('stop', x,y, press_stop_button, not Is_mobile and Show_code and 'F2')
	local w = Font:getWidth('stop')+10
	return x+w+10, y
end
\ No newline at end of file

M 0116-save_button => 0116-save_button +1 -1
@@ 1,3 1,3 @@
save_button = function(x, y, r)
	return overflowable_button('save', x, y, r, press_save_button)
	return overflowable_button('save', x, y, r, press_save_button, --[[final button?]] false, not Is_mobile and Show_code and 'F4')
end
\ No newline at end of file

M 0117-load_button => 0117-load_button +1 -16
@@ 1,19 1,4 @@
load_button = function(x, y, r)
	return overflowable_button('load', x, y, r,
		function()
			Show_menu = nil
			Show_file_dialog = true
			File_dialog_callback = function(filename)
				if filename == '' then
					-- clear filename
					Current_pane.filename = nil
					return
				end
				Current_pane.filename = filename
				one_time_load()
				-- Load new filename in future sessions.
				-- On mobile devices, we can't depend on on.save_settings() triggering on quit.
				love.filesystem.write('config', json.encode(settings()))
			end
		end)
		press_load_button, --[[final button?]] false, not Is_mobile and Show_code and 'F5')
end
\ No newline at end of file

M 0118-overflowable_button => 0118-overflowable_button +3 -3
@@ 1,6 1,6 @@
-- draw a button in the menu if possible
-- if not, stash it behind an overflow ('>>') button
overflowable_button = function(name, x, y, r, onpress1, final_button)
overflowable_button = function(name, x, y, r, onpress1, final_button, tooltip_text)
	local w = Font:getWidth(name)+10
	local x2, y2 = maybe_draw_overflow_button(x, y, w, r, final_button)
	if Overflow_button then


@@ 11,10 11,10 @@ overflowable_button = function(name, x, y, r, onpress1, final_button)
			y = y2
		end
	end
	styled_button(name, x,y, onpress1)
	styled_button(name, x,y, onpress1, tooltip_text)
	if Overflow_button then
		return x, y+Line_height
	else
		return x+w+10, y
	end
end
end
\ No newline at end of file

M 0124-styled_button => 0124-styled_button +5 -2
@@ 1,4 1,4 @@
styled_button = function(name, x, y, onpress1)
styled_button = function(name, x, y, onpress1, tooltip_text)
	local w = Font:getWidth(name)+10
	button(Global_state, name, {x=x, y=y, w=w, h=Line_height, bg={r=0.6, g=0.8, b=0.6},
		icon = function(p)


@@ 17,5 17,8 @@ styled_button = function(name, x, y, onpress1)
				expire=Current_time+0.1,
			}
		end,
		tooltip = function(x,y)
			show_tooltip(x,y+20, tooltip_text)
		end,
	})
end
end
\ No newline at end of file

M 0167-press_next_pane_button => 0167-press_next_pane_button +1 -0
@@ 1,5 1,6 @@
press_next_pane_button = function()
	Show_menu = nil
	if Current_pane_index >= #Panes then return end
	Current_pane.car = car
	Current_pane_index = Current_pane_index+1
	Current_pane = Panes[Current_pane_index]

M 0168-press_previous_pane_button => 0168-press_previous_pane_button +1 -0
@@ 1,5 1,6 @@
press_previous_pane_button = function()
	Show_menu = nil
	if Current_pane_index <=1 then return end
	Current_pane.car = car
	Current_pane_index = Current_pane_index-1
	Current_pane = Panes[Current_pane_index]

A 0172-Tooltip_background => 0172-Tooltip_background +1 -0
@@ 0,0 1,1 @@
Tooltip_background = {r=0.8, g=0.8, b=0.8}
\ No newline at end of file

A 0173-Tooltip_foreground => 0173-Tooltip_foreground +1 -0
@@ 0,0 1,1 @@
Tooltip_foreground = {r=0, g=0, b=0}
\ No newline at end of file

A 0174-Is_mobile => 0174-Is_mobile +1 -0
@@ 0,0 1,1 @@
Is_mobile = (OS == 'Android' or OS == 'iOS')
\ No newline at end of file

A 0175-show_tooltip => 0175-show_tooltip +8 -0
@@ 0,0 1,8 @@
show_tooltip = function(x,y, tooltip_text)
	if not tooltip_text then return end
	App.color(Tooltip_background)
	local w = App.width(tooltip_text)
	love.graphics.rectangle('fill', x,y, w+10, Line_height+10, 2,2)
	App.color(Tooltip_foreground)
	love.graphics.print(tooltip_text, x+5, y+5)
end
\ No newline at end of file

M button.lua => button.lua +12 -0
@@ 33,3 33,15 @@ function mouse_press_consumed_by_any_button(State, x, y, mouse_button)
  end
  return button_pressed and consume_press
end

function draw_button_tooltips(State)
  if App.mouse_down(1) then return end
  local x,y = love.mouse.getPosition()
  for _,ev in ipairs(State.button_handlers) do
    if ev.tooltip then
      if x>ev.x and x<ev.x+ev.w and y>ev.y and y<ev.y+ev.h then
        ev.tooltip(x,y)
      end
    end
  end
end