diff options
| -rw-r--r-- | Spear/App.hs | 2 | ||||
| -rw-r--r-- | Spear/Window.hs | 62 |
2 files changed, 34 insertions, 30 deletions
diff --git a/Spear/App.hs b/Spear/App.hs index e85c46b..6473e1b 100644 --- a/Spear/App.hs +++ b/Spear/App.hs | |||
| @@ -175,7 +175,7 @@ loop :: App s -> Window -> Game (AppState s) () | |||
| 175 | loop app window = do | 175 | loop app window = do |
| 176 | -- For convenience, trigger an initial resize followed by a render of the | 176 | -- For convenience, trigger an initial resize followed by a render of the |
| 177 | -- application's initial state. | 177 | -- application's initial state. |
| 178 | (width, height) <- getWindowSize window | 178 | (width, height) <- getFramebufferSize window |
| 179 | resizeApp app (ResizeEvent width height) | 179 | resizeApp app (ResizeEvent width height) |
| 180 | renderApp app | 180 | renderApp app |
| 181 | 181 | ||
diff --git a/Spear/Window.hs b/Spear/Window.hs index a873362..2e30c0b 100644 --- a/Spear/Window.hs +++ b/Spear/Window.hs | |||
| @@ -1,32 +1,32 @@ | |||
| 1 | module Spear.Window | 1 | module Spear.Window |
| 2 | ( -- * Setup | 2 | ( |
| 3 | Dimensions, | 3 | -- * Setup |
| 4 | WindowTitle, | 4 | Dimensions |
| 5 | 5 | , WindowTitle | |
| 6 | -- * Window | 6 | -- * Window |
| 7 | Window, | 7 | , Window |
| 8 | Width, | 8 | , Width |
| 9 | Height, | 9 | , Height |
| 10 | WindowEvent(..), | 10 | , WindowEvent(..) |
| 11 | withWindow, | 11 | , withWindow |
| 12 | pollWindowEvents, | 12 | , pollWindowEvents |
| 13 | shouldWindowClose, | 13 | , shouldWindowClose |
| 14 | swapBuffers, | 14 | , swapBuffers |
| 15 | getWindowSize, | 15 | , getWindowSize |
| 16 | 16 | , getFramebufferSize | |
| 17 | -- * Input | 17 | -- * Input |
| 18 | pollInputEvents, | 18 | , pollInputEvents |
| 19 | whenKeyDown, | 19 | , whenKeyDown |
| 20 | whenKeyUp, | 20 | , whenKeyUp |
| 21 | processKeys, | 21 | , processKeys |
| 22 | processButtons, | 22 | , processButtons |
| 23 | InputEvent(..), | 23 | , InputEvent(..) |
| 24 | Key(..), | 24 | , Key(..) |
| 25 | MouseButton(..), | 25 | , MouseButton(..) |
| 26 | MouseProp(..), | 26 | , MouseProp(..) |
| 27 | MousePos, | 27 | , MousePos |
| 28 | MouseDelta, | 28 | , MouseDelta |
| 29 | ) | 29 | ) |
| 30 | where | 30 | where |
| 31 | 31 | ||
| 32 | import Spear.Game | 32 | import Spear.Game |
| @@ -78,7 +78,7 @@ data Window = Window | |||
| 78 | 78 | ||
| 79 | 79 | ||
| 80 | withWindow :: MonadIO io => Dimensions -> WindowTitle -> (Window -> IO a) -> io a | 80 | withWindow :: MonadIO io => Dimensions -> WindowTitle -> (Window -> IO a) -> io a |
| 81 | withWindow dim@(w, h) windowTitle run = liftIO $ do | 81 | withWindow dim windowTitle run = liftIO $ do |
| 82 | window <- do | 82 | window <- do |
| 83 | success <- GLFW.init | 83 | success <- GLFW.init |
| 84 | unless success $ throw (WindowException "GLFW.initialize failed") | 84 | unless success $ throw (WindowException "GLFW.initialize failed") |
| @@ -149,6 +149,10 @@ swapBuffers = liftIO . GLFW.swapBuffers . glfwWindow | |||
| 149 | getWindowSize :: MonadIO io => Window -> io (Width, Height) | 149 | getWindowSize :: MonadIO io => Window -> io (Width, Height) |
| 150 | getWindowSize = liftIO . GLFW.getWindowSize . glfwWindow | 150 | getWindowSize = liftIO . GLFW.getWindowSize . glfwWindow |
| 151 | 151 | ||
| 152 | -- | Get the window's framebuffer size. | ||
| 153 | getFramebufferSize :: MonadIO io => Window -> io (Width, Height) | ||
| 154 | getFramebufferSize = liftIO . GLFW.getFramebufferSize . glfwWindow | ||
| 155 | |||
| 152 | getRequest :: MVar Bool -> IO Bool | 156 | getRequest :: MVar Bool -> IO Bool |
| 153 | getRequest mvar = | 157 | getRequest mvar = |
| 154 | tryTakeMVar mvar >>= \x -> return $ fromMaybe False x | 158 | tryTakeMVar mvar >>= \x -> return $ fromMaybe False x |
