{-# LANGUAGE CPP, TemplateHaskell #-}
-----------------------------------------------------------------------------
--
-- Module      :  Main
-- Copyright   :  John Lång
-- License     :  The MIT License
--
-- Maintainer  :
-- Stability   :
-- Portability :
--
-- |
--
-----------------------------------------------------------------------------

module Main (
    main
) where

import Control.Monad (unless)
import Data.List (stripPrefix)
import System.Exit (exitFailure)
import Test.QuickCheck.All (quickCheckAll)

import Graphics.UI.WX

{-
-- Simple function to create a hello message.
hello s = "Hello " ++ s

-- Tell QuickCheck that if you strip "Hello " from the start of
-- hello s you will be left with s (for any s).
prop_hello s = stripPrefix "Hello " (hello s) == Just s

-- Hello World

exeMain = do
    putStrLn (hello "World")

-- Entry point for unit tests.
testMain = do
    allPass <- $quickCheckAll -- Run QuickCheck on all prop_ functions
    unless allPass exitFailure

-- This is a clunky, but portable, way to use the same Main module file
-- for both an application and for unit tests.
-- MAIN_FUNCTION is preprocessor macro set to exeMain or testMain.
-- That way we can use the same file for both an application and for tests.
#ifndef MAIN_FUNCTION
#define MAIN_FUNCTION exeMain
#endif
main = MAIN_FUNCTION
-}

main :: IO ()
main = start gui

gui :: IO ()
gui = do
      frame [text := "Hello World!"]
      return ()

{-
import System.IO
import Codec.Picture
import Complex
import ReadArgs

a = 4.0
n = 255
main :: IO ()
main = do
       (width, height) <- readArgs
       writePng "test.png" (generateImage pixelRenderer width height)

pixelRenderer :: (Integral a1, Integral a2) => a1 -> a2 -> PixelRGB8
pixelRenderer x y = let (fx, fy, fz) = colorFunction x y
                              in PixelRGB8 fx fy fz

colorFunction :: (Integral a1, Integral a2, Num b1, Num b2, Num b3) =>
    a1 -> a2 -> (b1, b2, b3)
colorFunction x y = (fromIntegral w, fromIntegral 0, fromIntegral 0)
    where w = mandelbrot $ Complex ((fromIntegral x) / 1000.0) ((fromIntegral y) / 1000.0)

mandelbrot :: Complex -> Int
mandelbrot c = length $ takeWhile (\(m, z) -> (re . abs) z < a && m < n) $
               zip [1,2..] $ iterate f $ Complex 0 0
    where f z = z * z + c
-}
