 	CONTEXT.fill()
 clearAll = () ->
 	CONTEXT.clearRect(0, 0, CANVAS_WIDTH, CANVAS_HEIGHT)
+
+# jQuery button things
+enableButtonIf = (selector, bool) ->
+	$(selector).prop('disabled', !bool)
+
 # High-level things
 markAllActive = (c = "blue") ->
 	clearAll()
+	# Mark all selected points
 	for p in active_points
 		fillCircle(p, color=c, r=5)
 		drawCircle(p, color=c, r=30)
 	$("span#active_points").html(active_points.toString())
+
+	# Decide whether "Check", Done button enabled
+	enableButtonIf("#check_button", active_points.length > 0)
+	enableButtonIf("#done_button", (active_points.length == 0) &&
+		(diagram.unfound_tuples.length != diagram.tuples.length))
+
 # }}}
-# Click and game handler {{{
+# Click handler {{{
 toggle = (p) ->
 	if not (p in active_points)
 		active_points.push(p)

		tempAddClass "#check_button", "button_red"
		diagram.mistakes += 1

onDoneButtonClick = (e) ->
	if diagram.unfound_tuples.length == 0
		startNextDiagram
		tempAddClass "#done_button", "button_green"
	else
		tempAddClass "#done_button", "button_red"
		diagram.mistakes += 1


startNextDiagram = () ->
	console.log("Next diagram")

# }}}
# Start Game {{{
startGame = () ->
	CANVAS = $("<canvas></canvas>")
	CANVAS.attr "height", CANVAS_HEIGHT

	markAllActive()

onDiagramClick = (e) ->
	o = new Point("", e.pageX-this.offsetLeft, e.pageY-this.offsetTop)
		# where user clicked
	# Grab the closest point to the click
	diagram.flat_points.sort( (p,q) -> dist(o,p)-dist(o,q) )
	p = diagram.flat_points[0]
