From 2da4098d4155537638b9228e0c2f0f7905d9e2d7 Mon Sep 17 00:00:00 2001 From: justin Date: Sun, 10 Apr 2022 10:17:03 +0100 Subject: [PATCH] Add file --- src/Dodge/Base/Coordinate.hs | 38 ++++++++++++++++++++++++++++++++++++ src/Dodge/Base/WinScale.hs | 11 +++++++++++ src/Dodge/Render/InfoBox.hs | 15 ++++++++++++++ 3 files changed, 64 insertions(+) create mode 100644 src/Dodge/Base/Coordinate.hs create mode 100644 src/Dodge/Base/WinScale.hs create mode 100644 src/Dodge/Render/InfoBox.hs diff --git a/src/Dodge/Base/Coordinate.hs b/src/Dodge/Base/Coordinate.hs new file mode 100644 index 000000000..97c1df32a --- /dev/null +++ b/src/Dodge/Base/Coordinate.hs @@ -0,0 +1,38 @@ +module Dodge.Base.Coordinate where +import Dodge.Data +import Dodge.Base.WinScale + +import Geometry +{- | Transform coordinates from world position to screen coordinates. -} +worldPosToScreenNorm :: Configuration -> World -> Point2 -> Point2 +worldPosToScreenNorm cfig w = doWindowScale cfig . doRotate . doZoom . doTranslate + where + doTranslate p = p -.- _cameraCenter w + doZoom p = _cameraZoom w *.* p + doRotate p = rotateV (negate $ _cameraRot w) p +{- | Transform world coordinates to scaled screen coordinates. + - These have to be according to the size of the window to get actual screen positions. + - This allows for line thicknesses etc to correspond to pixel sizes.-} +worldPosToScreen :: World -> Point2 -> Point2 +worldPosToScreen w = doRotate . doZoom . doTranslate + where + doTranslate p = p -.- _cameraCenter w + doZoom p = _cameraZoom w *.* p + doRotate p = rotateV (negate $ _cameraRot w) p +{- | Transform coordinates from the map position to screen +coordinates. -} +cartePosToScreen :: Configuration -> World -> Point2 -> Point2 +cartePosToScreen cfig w = doWindowScale cfig . doRotate . doZoom . doTranslate + where + doTranslate p = p -.- _carteCenter (_hud w) + doZoom p = _carteZoom (_hud w) *.* p + doRotate p = rotateV (negate $ _carteRot (_hud w)) p +crToMousePosOffset :: Creature -> World -> (Point2,Float) +crToMousePosOffset cr w = (mouseWorldPos w -.- _crPos cr,0) +{- | The mouse position in world coordinates. -} +mouseWorldPos :: World -> Point2 +mouseWorldPos w = _cameraCenter w +.+ (1/_cameraZoom w) *.* rotateV (_cameraRot w) (_mousePos w) +{- | The mouse position in map coordinates -} +mouseCartePos :: World -> Point2 +mouseCartePos w = _carteCenter (_hud w) +.+ (1/_carteZoom (_hud w)) + *.* rotateV (_carteRot (_hud w)) (_mousePos w) diff --git a/src/Dodge/Base/WinScale.hs b/src/Dodge/Base/WinScale.hs new file mode 100644 index 000000000..671ef5632 --- /dev/null +++ b/src/Dodge/Base/WinScale.hs @@ -0,0 +1,11 @@ +module Dodge.Base.WinScale where +import Dodge.Config.Data +import Geometry +import Picture + +winScale :: Configuration -> Picture -> Picture +{-# INLINE winScale #-} +winScale cfig = scale (2 / _windowX cfig) (2 / _windowY cfig) + +doWindowScale :: Configuration -> Point2 -> Point2 +doWindowScale cfig (V2 x y) = V2 ( x * 2 / _windowX cfig) ( y * 2 / _windowY cfig) diff --git a/src/Dodge/Render/InfoBox.hs b/src/Dodge/Render/InfoBox.hs new file mode 100644 index 000000000..46bf2e7c5 --- /dev/null +++ b/src/Dodge/Render/InfoBox.hs @@ -0,0 +1,15 @@ +module Dodge.Render.InfoBox where +import Dodge.Data +--import Dodge.Base.Window +--import Dodge.Base.WinScale +import Dodge.Render.Connectors +import Dodge.Render.List +import Dodge.Base.Coordinate +import Picture +import Geometry +--import Control.Monad +--import Data.Maybe + +renderInfoListAt :: Float -> Float -> Configuration -> World -> (Point2,[String]) -> Picture +renderInfoListAt x y cfig w (p,ss) = renderListAt x y cfig (zip ss (repeat white)) + <> zConnect (V2 x y) (worldPosToScreenNorm cfig w p)