Shoes.app :width => 800, :height => 540, :resizable => false do

	@is_drawing = false
	@tools = [:line, :arrow, :star, :rect, :oval]
	@current_tool = :line
		
	stack do
		background black, :height => 40
		flow :margin => 10 do 
			caption "Sketchers", :stroke => white, :margin_right => 25
			@tools.each do |tool|
				button(tool.to_s) { @current_tool = tool }
			end
			button("stroke color") do
				new_color = ask_color("Pick a Color")
				@canvas.stroke new_color
				@canvas.fill new_color
			end
			button("bg color") do
				@canvas.background ask_color("Pick a Color")
			end
			button("clear") do
				@canvas.clear
				@canvas.background white
			end
		end
	end
	
	@canvas = stack :margin_top => 5, :width => 800, :height => 500 do
		background white
	end
	
	@canvas.click do
		if @is_drawing == false
			start_drawing
			@is_drawing = true
		end
	end
	
	@canvas.release do
		if @is_drawing == true
			@canvas.motion nil
			@is_drawing = false
		end
	end
	
	def start_drawing
		x, y = nil, nil
		@canvas.motion do |new_x, new_y|
			if x and y and (x != new_x or y != new_y)
				@canvas.append do
					case @current_tool
						when :line
							line x, y, new_x, new_y
						when :arrow
							arrow x, y, 10
						when :star
							star x/2, y/2, 5, 10, 50
						when :rect
							rect x, y, 10, 10
						when :oval
							oval x, y, 10, 10
					end
				end
			end
			x, y = new_x, new_y
		end
	end
	
end
