 
 
   draw_pattern: () -> # [(temp) - test/diagnostic method]
-    # FIXME the fill_hex methods are being refactored to take a context/image/canvas parameter telling it WHAT to draw on.
+    # FIXME the fill_hex methods are being refactored to take a
+    #  context/image/canvas parameter telling it WHAT to draw on.
+    #  If we use this method again we will have to adjust it accordingly.
     n = 0
     for row in [1..10]
       for col in [1..24]


class HexDraw

  constructor: () ->
    @canvas = document.getElementById("puzzle-widget")
    @context = @canvas.getContext("2d")
    @colors = ["#cc5050","#5050cc","#50cccc","#50cc50","#cccc50","#cc50cc","#000000"]


  fillhex_ab: (a,b,c_no) ->
    x = 113+a*14
    y = 27+b*20
    y = y-9 if (a%2 == 0)
    @fillhex_xy(x,y,c_no)


  fillhex_ab_xy: (a,b,x,y,c_no) ->  # {temp method ???}
    xx = x+(a-1)*14
    yy = y+(b-1)*20
    yy = yy-9 if (a%2 == 0)
    @fillhex_xy(xx,yy,c_no)


  # TODO Change this to draw on any image (like PieceMask)
  fillhex_xy: (x,y,c_no) ->
    @context.fillStyle = @colors[c_no]
    @context.beginPath()
    @context.moveTo(x,y)


  constructor: (piece) ->
    @piece = piece
    @hex_draw = @piece.puzzle.hex_draw
    @img = document.createElement('canvas')
    @img.id = "piece-mask"


  draw_pattern: () ->
    @img.width = @piece.box.width
    @img.height = @piece.box.height
    @hexes = @piece.hexes
    @hex_draw.set_context("canvas")
#    @hex_draw.set_context("piece_mask")
    for hx in @hexes
      aa = hx[0]
      bb = hx[1]
      @hex_draw.fill_hex_ab_xy(aa,bb,6,9,3)



class PieceImage

  constructor: (puzzle_piece) ->

    @piece = puzzle_piece
    @puzzle = @piece.puzzle
#    @img = @puzzle.puzzle_view.piece_mask
    @img = document.createElement('canvas')
    @img.id = "piece-mask"
    @img.width = @piece.box.width
    @img.height = @piece.box.height
    @piece_image_context = @img.getContext("2d")


# FIXME Nothing references this method yet.
draw_piece:  (a,b) ->
    # TODO I think the books said there are more than one kind of image object.
    @pc_img = document.getElementById("piece")
    if @grid_model.in_range(a,b)
      xy = @grid_model.get_xy(a,b)
