summaryrefslogtreecommitdiffstats
path: root/src/GLDriver.hs
diff options
context:
space:
mode:
authorMatthias Schiffer <matthias@gamezock.de>2010-03-09 03:49:15 +0100
committerMatthias Schiffer <matthias@gamezock.de>2010-03-09 03:49:15 +0100
commit7327695ca3d9aee5da1d0bc98572d877dd8c8546 (patch)
treee733714968ae0a041f76b213ffe31cca70ada6fb /src/GLDriver.hs
parent2bb85618366681c7c97f8b36cc85a18c45beb924 (diff)
downloadhtanks-7327695ca3d9aee5da1d0bc98572d877dd8c8546.tar
htanks-7327695ca3d9aee5da1d0bc98572d877dd8c8546.zip
Moved source files to src directory
Diffstat (limited to 'src/GLDriver.hs')
-rw-r--r--src/GLDriver.hs67
1 files changed, 67 insertions, 0 deletions
diff --git a/src/GLDriver.hs b/src/GLDriver.hs
new file mode 100644
index 0000000..7340075
--- /dev/null
+++ b/src/GLDriver.hs
@@ -0,0 +1,67 @@
+{-# LANGUAGE ExistentialQuantification, DeriveDataTypeable #-}
+
+module GLDriver ( Driver(..)
+ , SomeDriver(..)
+ , Event
+ , SomeEvent(..)
+ , fromEvent
+ , QuitEvent(..)
+ , Key(..)
+ , KeyPressEvent(..)
+ , KeyReleaseEvent(..)
+ , MouseMotionEvent(..)
+ , MousePressEvent(..)
+ ) where
+
+import Data.Typeable
+
+
+class Driver a where
+ initialized :: a -> Bool
+
+ initGL :: a -> IO a
+ deinitGL :: a -> IO ()
+
+ swapBuffers :: a -> IO ()
+
+ nextEvent :: a -> IO (a, Maybe SomeEvent)
+
+data SomeDriver = forall d. Driver d => SomeDriver d
+
+instance Driver SomeDriver where
+ initialized (SomeDriver d) = initialized d
+ initGL (SomeDriver d) = initGL d >>= return . SomeDriver
+ deinitGL (SomeDriver d) = deinitGL d
+ swapBuffers (SomeDriver d) = swapBuffers d
+ nextEvent (SomeDriver d) = nextEvent d >>= \(gl, ev) -> return (SomeDriver gl, ev)
+
+
+class (Typeable a, Show a) => Event a
+
+data SomeEvent = forall a. Event a => SomeEvent a
+instance Show SomeEvent where
+ show (SomeEvent a) = show a
+
+fromEvent :: Event a => SomeEvent -> Maybe a
+fromEvent (SomeEvent a) = cast a
+
+
+data QuitEvent = QuitEvent deriving (Typeable, Show)
+instance Event QuitEvent
+
+
+data Key = KeyLeft | KeyRight | KeyUp | KeyDown
+ deriving (Eq, Ord, Show)
+
+data KeyPressEvent = KeyPressEvent Key deriving (Typeable, Show)
+instance Event KeyPressEvent
+
+data KeyReleaseEvent = KeyReleaseEvent Key deriving (Typeable, Show)
+instance Event KeyReleaseEvent
+
+
+data MouseMotionEvent = MouseMotionEvent Float Float deriving (Typeable, Show)
+instance Event MouseMotionEvent
+
+data MousePressEvent = MousePressEvent Float Float deriving (Typeable, Show)
+instance Event MousePressEvent