{-# LANGUAGE OverloadedStrings #-}

module Main where

import Model.Movement
import Model.Object
import Model.Mechanics

import Render

import SDL


import SDL
import Linear (V2(..), V4(..))
import Linear.Affine
import Control.Monad (unless)

main :: IO ()
main = do
  initializeAll
  window <- createWindow "My SDL Application" defaultWindow
  renderer <- createRenderer window (-1) defaultRenderer
  appLoop renderer

appLoop :: Renderer -> IO ()
appLoop renderer = do
  events <- pollEvents
  let eventIsQPress event =
        case eventPayload event of
          KeyboardEvent keyboardEvent ->
            keyboardEventKeyMotion keyboardEvent == Pressed &&
            keysymKeycode (keyboardEventKeysym keyboardEvent) == KeycodeQ
          _ -> False
      qPressed = not (null (filter eventIsQPress events))
  
  -- background
  rendererDrawColor renderer $= V4 255 255 255 255    
  clear renderer

  -- No need for this present:
  --   it will make window blinking.
  --present renderer

  -- Choosing black color with no opacity.
  rendererDrawColor renderer $= V4 0 0 0 255

  -- Rectangle 10x100
  drawLine renderer (P (V2 10 10)) (P (V2 10 100))
  drawLine renderer (P (V2 10 10)) (P (V2 100 10))
  drawLine renderer (P (V2 10 100)) (P (V2 100 100))
  drawLine renderer (P (V2 100 10)) (P (V2 100 100))

  present renderer

  unless qPressed (appLoop renderer)




{-testObjects =
    [Object (Circle (pnt 0 0) 3) (vel 0 0) (acc 0 0)
    ,Object (Circle (pnt 7 6) 2) (vel 0 0) (acc 0 0)]
-}
-- Auxilliary --
{-
allPairs :: [a] -> [(a,a)]
allPairs xs =
    let ts = List.tail $ List.tails xs
    in List.concat $ List.foldl (\ accum val -> List.zip xs val : accum) [] ts-}
