Compare commits

..

2 Commits

Author SHA1 Message Date
justin c041a4d174 Improve window dragging 2026-04-06 01:12:25 +01:00
justin 1f52c4b588 Work on boundaries for dragging windows 2026-04-06 00:52:09 +01:00
9 changed files with 22 additions and 20 deletions
+1 -1
View File
@@ -10,7 +10,7 @@ import Control.Lens
-- a spScreenOff of 1 is the full length of the screen
-- for eg see fromTopLeft
data ScreenPos = ScreenPos
{ _spScreenOff :: Point2
{ _spScreenOff :: Point2 -- from bottom left
, _spPixelOff :: Point2
}
makeLenses ''ScreenPos
+2 -1
View File
@@ -9,12 +9,13 @@ import Data.IntMap.Strict (IntMap)
import Dodge.Data.CardinalPoint
import Dodge.Data.ScreenPos
import Picture.Data
import Linear
data LDParams = LDP -- List display parameters
{ _ldpPos :: ScreenPos
, _ldpScale :: Float
, _ldpVerticalGap :: Float
, _ldpBorder :: Maybe (Int,Int) -- the Ints give height and width for a border
, _ldpSize :: Maybe (V2 Int)
}
data CursorDisplay
+5 -3
View File
@@ -23,10 +23,10 @@ defaultLDP =
, _ldpScale = 1
, _ldpPos =
ScreenPos
{ _spScreenOff = V2 (-0.5) 0.5 -- top left
{ _spScreenOff = V2 0 1 -- top left
, _spPixelOff = 0
}
, _ldpBorder = Nothing
, _ldpSize = Nothing
}
invDP :: LDParams
@@ -46,7 +46,9 @@ secondColumnLDP :: LDParams
secondColumnLDP = defaultLDP & ldpPos . spPixelOff .~ V2 subInvX (-20)
terminalLDP :: LDParams
terminalLDP = secondColumnLDP & ldpBorder ?~ (49, 16)
terminalLDP = secondColumnLDP & ldpSize ?~ V2 50 16
& ldpPos . spScreenOff .~ V2 0.5 0.5
& ldpPos . spPixelOff .~ V2 (-250) (-40)
subInvX :: Float
subInvX = 10 * fromIntegral topInvW + 170
+1 -1
View File
@@ -47,7 +47,7 @@ drawSelectionList ldps cfig sl =
ldpRect :: Config -> LDParams -> Maybe (Point2, Point2) -- (NW, SE)
ldpRect cfig ldp = do
(x, y) <- ldp ^? ldpBorder . _Just
V2 x y <- ldp ^? ldpSize . _Just
return $
( V2 0 0
, V2 (10 * sf * fromIntegral x) (negate $ (20 * sf + ygap) * fromIntegral y)
+1 -1
View File
@@ -27,7 +27,7 @@ drawLoadingScreen s _ cfig =
<>
translateScreenPos
cfig
(ScreenPos (V2 0 0.2) (V2 (-300) (10 * fromIntegral (length s))))
(ScreenPos (V2 0.5 0.7) (V2 (-300) (10 * fromIntegral (length s))))
(drawList $ map text s)
drawInputMenu :: String -> Config -> Picture
+3 -2
View File
@@ -7,13 +7,14 @@ import Geometry.Data
import Picture.Base
fromTopLeft :: Point2 -> ScreenPos
fromTopLeft (V2 x y) = ScreenPos (V2 (-0.5) 0.5) (V2 x (- y))
fromTopLeft (V2 x y) = ScreenPos (V2 0 1) (V2 x (- y))
translateScreenPos :: Config -> ScreenPos -> Picture -> Picture
translateScreenPos cfig = uncurryV translate . screenPosAbs cfig
-- returns distance from center in pixels
screenPosAbs :: Config -> ScreenPos -> Point2
screenPosAbs cfig sp = sp ^. spScreenOff * V2 w h + sp ^. spPixelOff
screenPosAbs cfig sp = (sp ^. spScreenOff - 0.5) * V2 w h + sp ^. spPixelOff
where
w = fromIntegral $ cfig ^. windowX
h = fromIntegral $ cfig ^. windowY
+1 -1
View File
@@ -14,5 +14,5 @@ getAvailableListLines ldps cfig = floor ((dToBot - vgap) / itmHeight)
itmHeight = 20 * ldps ^. ldpScale + vgap
winy = fromIntegral $ cfig ^. windowY
dToBot =
winy / 2 + winy * (ldps ^. ldpPos . spScreenOff . _y)
winy * (ldps ^. ldpPos . spScreenOff . _y)
+ (ldps ^. ldpPos . spPixelOff . _y)
+7 -9
View File
@@ -132,15 +132,13 @@ updateMouseHeldInGame cfig w = case w ^. input . mouseContext of
setPixelOffsetBounded :: Config -> Point2 -> LDParams -> LDParams
setPixelOffsetBounded cfig (V2 x y) ldp = ldp & ldpPos . spPixelOff .~ V2 x' y'
where
-- (V2 xmin ymax, V2 xmax ymin) = ldpRect cfig ldp
h = fromIntegral $ cfig ^. windowX
w = fromIntegral $ cfig ^. windowY
V2 ax ay = -V2 w h + ldp ^. ldpPos . spScreenOff * V2 w h
x' = min w $ max 1 x
y' = y
boundPixelOffset :: Config -> Point2 -> Point2 -> Point2 -> Point2
boundPixelOffset cfig nw se p = p
h = fromIntegral $ cfig ^. windowY
w = fromIntegral $ cfig ^. windowX
x' = min (w - (w*a + 1+10*ldp ^?! ldpSize . _Just . _x . to fromIntegral))
$ max (1 - w * a) x
y' = min (h-(h*b + 40))
$ max (1+20*(ldp^.ldpVerticalGap + ldp^?!ldpSize._Just._y.to fromIntegral)-h*b) y
V2 a b = ldp ^. ldpPos . spScreenOff
--leftHeldPosShift :: World -> Point2
--leftHeldPosShift w = fromMaybe 0 $ do
+1 -1
View File
@@ -90,7 +90,7 @@ ldpSelection cfig ldp (V2 _ y)
ygap = ldp ^. ldpVerticalGap
yoff = ygap + 20 * ldp ^. ldpScale
top :: Float
top = fromIntegral winy * (ldp ^. ldpPos . spScreenOff . _y) + ldp ^. ldpPos . spPixelOff . _y
top = fromIntegral winy * (ldp ^. ldpPos . spScreenOff . _y - 0.5) + ldp ^. ldpPos . spPixelOff . _y
yupper = floor $ (top - (y + ygap)) / yoff
ylower = ceiling ((top - y) / yoff) - 1