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