 
 
   set_context: (mode) ->
+    console.log "CALL set_context()  mode = #{mode}"
     @mode = mode
     @context = @puzzle_view.get_drawing_context(mode)
+
+
+  set_context2: (img) ->
+    console.log "CALL set_context2()  img.id = #{img.id}"
+    @context = img.getContext('2d')
 
 
   get_hex_xy: (a,b) ->

  get_drawing_context: (mode) ->
    switch mode
      when "canvas" then context = @context_canvas
      when "piece_mask"
        if @puzzle.piece
          context = @puzzle.piece.piece_mask.img.getContext('2d')
        else
          context = null
    return context



class PuzzlePiece

  constructor: (puzzle_app) ->
    console.log "PuzzlePiece constructor"
    @puzzle = puzzle_app
    @hex_box = @puzzle.hex_box
    @pattern  = new PiecePattern(this)
    console.log "    @pattern.img.id = #{@pattern.img.id}"
    @redraw = new PieceRedrawBuffer(this)
    @hexes = []
    @bounding_box = [0,0,0,0,]
