module RubikFace where
import Graphics.UI.GLUT
import Graphics.Rendering.OpenGL

import Squares
import PointsForRendering
frame width height border = do
  let bh = border/2
  let wh = width/2-bh
  let hh = height/2-bh

  preservingMatrix $ do
    translate $Vector3 0 hh (0::GLfloat)
    myRect width  border
  preservingMatrix $ do
    translate $Vector3 0 (-hh) (0::GLfloat)
    myRect width  border
  preservingMatrix $ do
    translate $Vector3 (-wh) 0 (0::GLfloat)
    myRect  border height 
  preservingMatrix $ do
    translate $Vector3 wh 0 (0::GLfloat)
    myRect  border height 
originField width color = do
  let frameWidth = width/10
  currentColor $= Color4 0 0 0 1
  frame width width frameWidth
  let sc = 18/20::GLfloat
  currentColor $= color
  square (width-frameWidth)
renderArea :: GLfloat -> [[Color4 GLfloat]] -> IO ()
renderArea width css
 = do
    let cs  = concat css
        cps = zip cs $ areaFields width
    mapM_  (\(c,f)-> f(originField width c)) cps

areaFields width = 
  [makeSquare x y |x<-[1,0,-1],y<-[1,0,-1]]
    where 
      makeSquare xn yn = \f -> preservingMatrix $ do
       let
         x = xn*width
         y = yn*width
       translate $Vector3 x y 0
       f

red     = Color4 1 0 0 (1::GLfloat)
green   = Color4 0 1 0 (1::GLfloat)
blue    = Color4 0 0 1 (1::GLfloat)
yellow  = Color4 1 1 0 (1::GLfloat)
white   = Color4 1 1 1 (1::GLfloat)
black   = Color4 0 0 0 (1::GLfloat)
