diff options
| author | Akshay Nair <phenax5@gmail.com> | 2024-12-21 13:19:48 +0530 |
|---|---|---|
| committer | Akshay Nair <phenax5@gmail.com> | 2024-12-21 13:19:56 +0530 |
| commit | a2a8e8dd046678816c3797cb894b20abfe84e360 (patch) | |
| tree | 0b40288086b055b0a13f3a5621b836eca1d7b2c5 /src/Chelleport/Draw.hs | |
| parent | d8667213fa49242701db4bf592754ab87749efa5 (diff) | |
| download | chelleport-a2a8e8dd046678816c3797cb894b20abfe84e360.tar.gz chelleport-a2a8e8dd046678816c3797cb894b20abfe84e360.zip | |
Fix issue with pointer coordinates + Add mouse press/release actions
Diffstat (limited to '')
| -rw-r--r-- | src/Chelleport/Draw.hs | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/src/Chelleport/Draw.hs b/src/Chelleport/Draw.hs index 2fdb311..cba040a 100644 --- a/src/Chelleport/Draw.hs +++ b/src/Chelleport/Draw.hs @@ -16,7 +16,8 @@ class (Monad m) => MonadDraw m where drawText :: (CInt, CInt) -> SDL.V4 Word8 -> Text -> m (CInt, CInt) drawCircle :: Int -> (CInt, CInt) -> m () setDrawColor :: SDL.V4 Word8 -> m () - windowSize :: m (SDL.V2 CInt) + windowSize :: m (CInt, CInt) + windowPosition :: m (CInt, CInt) instance (MonadIO m) => MonadDraw (AppM m) where drawLine (x1, y1) (x2, y2) = do @@ -56,23 +57,29 @@ instance (MonadIO m) => MonadDraw (AppM m) where let points = Vector.generate renderedPoints (SDL.P . toPointOnCircle) SDL.drawPoints renderer points - windowSize = ask >>= SDL.get . SDL.windowSize . ctxWindow + windowSize = do + SDL.V2 x y <- ask >>= SDL.get . SDL.windowSize . ctxWindow + pure (x, y) + + windowPosition = do + SDL.V2 x y <- ask >>= SDL.getWindowAbsolutePosition . ctxWindow + pure (x, y) cellSize :: (MonadDraw m) => State -> m (CInt, CInt) cellSize (State {stateGrid}) = do - (SDL.V2 width height) <- windowSize + (width, height) <- windowSize let wcell = width `div` intToCInt (length $ head stateGrid) let hcell = height `div` intToCInt (length stateGrid) pure (wcell, hcell) drawHorizontalLine :: (MonadDraw m) => CInt -> m () drawHorizontalLine y = do - (SDL.V2 width _) <- windowSize + (width, _) <- windowSize drawLine (0, y) (width, y) drawVerticalLine :: (MonadDraw m) => CInt -> m () drawVerticalLine x = do - (SDL.V2 _width height) <- windowSize + (_, height) <- windowSize drawLine (x, 0) (x, height) colorWhite :: SDL.V4 Word8 |
