Work on mouse selection in menus

This commit is contained in:
2022-11-03 14:16:28 +00:00
parent e6e5427f44
commit 6e7cd14f49
7 changed files with 133 additions and 96 deletions
+42 -29
View File
@@ -1,28 +1,29 @@
module Dodge.Render.List where
import ListHelp
import Dodge.Data.SelectionList
import Data.Foldable
import Data.Maybe
import Dodge.Base.WinScale
import Dodge.Base.Window
import Dodge.Data.Config
import Dodge.Data.CardinalPoint
import Geometry
import Picture
import Data.Set (Set)
import qualified Data.Set as Set
import Dodge.Base.WinScale
import Dodge.Base.Window
import Dodge.Data.CardinalPoint
import Dodge.Data.Config
import Dodge.Data.SelectionList
import Geometry
import ListHelp
import Picture
drawSelectionList :: Configuration -> SelectionList -> Picture
drawSelectionList cfig sl = listPicturesAtScaleOff
(_slVerticalGap sl)
(_slScale sl)
(_slPosX sl)
(_slPosY sl)
cfig
(_slOffset sl)
(concatMap _siPictures (_slItems sl))
<> drawSelectionCursor cfig sl
drawSelectionList cfig sl =
listPicturesAtScaleOff
(_slVerticalGap sl)
(_slScale sl)
(_slPosX sl)
(_slPosY sl)
cfig
(_slOffset sl)
(concatMap _siPictures (_slItems sl))
<> drawSelectionCursor cfig sl
drawSelectionCursor :: Configuration -> SelectionList -> Picture
drawSelectionCursor cfig sl = fromMaybe mempty $ do
@@ -55,19 +56,28 @@ stackPicturesAt :: Float -> Float -> Configuration -> [Picture] -> Picture
stackPicturesAt tx ty cfig = stackPicturesAtOff tx ty cfig 0
stackPicturesAtOff :: Float -> Float -> Configuration -> Int -> [Picture] -> Picture
stackPicturesAtOff tx ty cfig i = mconcat . zipWith (listTextPictureAt tx ty cfig) [i, i-1 ..]
stackPicturesAtOff tx ty cfig i = mconcat . zipWith (listTextPictureAt tx ty cfig) [i, i -1 ..]
-- displays a cursor that should match up to list text pictures
-- the width of a character appears to be 9(?!)
-- this is probably because it is 8 pixels plus one for the border
listCursorChooseBorderScale ::
Float ->
Float -> Set CardinalPoint -> Float -> Float -> Configuration -> Int -> Color -> Int -> Int -> Picture
Float ->
Set CardinalPoint ->
Float ->
Float ->
Configuration ->
Int ->
Color ->
Int ->
Int ->
Picture
listCursorChooseBorderScale ygap s borders xoff yoff cfig yint col cursxsize cursysize =
winScale cfig
. translate
(6 + xoff - halfWidth cfig)
(halfHeight cfig + 12.5 - (20 * fromIntegral yint + yoff + 20 + hgt + ygap))
(15 - (9 * s) + xoff - halfWidth cfig)
(halfHeight cfig + negate (yoff - s * 12.5) - ((s * 10 + ygap) * (fromIntegral yint + 1)))
. color col
$ chooseCursorBorders (s * wth) (s * hgt) borders
where
@@ -96,22 +106,25 @@ listCursorChooseBorder borders xoff yoff cfig yint col cursxsize cursysize =
chooseCursorBorders :: Float -> Float -> Set CardinalPoint -> Picture
chooseCursorBorders wth hgt = fold . Set.map (line . toLine)
where
toLine North = [V2 0 hgt, V2 wth hgt]
toLine East = [V2 wth hgt, V2 wth 0]
toLine South = [V2 wth 0, V2 0 0]
toLine West = [V2 0 0, V2 0 hgt]
top = 0
bot = - hgt
lef = 0
toLine North = [V2 lef top, V2 wth top]
toLine East = [V2 wth top, V2 wth bot]
toLine South = [V2 wth bot, V2 lef bot]
toLine West = [V2 lef bot, V2 lef top]
listCursorNS :: Float -> Float -> Configuration -> Int -> Color -> Int -> Int -> Picture
listCursorNS = listCursorChooseBorder (Set.fromList [North,South])
listCursorNS = listCursorChooseBorder (Set.fromList [North, South])
listCursorNES :: Float -> Float -> Configuration -> Int -> Color -> Int -> Int -> Picture
listCursorNES = listCursorChooseBorder (Set.fromList [North,South,East])
listCursorNES = listCursorChooseBorder (Set.fromList [North, South, East])
listCursorNESW :: Float -> Float -> Configuration -> Int -> Color -> Int -> Int -> Picture
listCursorNESW = listCursorChooseBorder (Set.fromList [North,South,East,West])
listCursorNESW = listCursorChooseBorder (Set.fromList [North, South, East, West])
listCursorNSW :: Float -> Float -> Configuration -> Int -> Color -> Int -> Int -> Picture
listCursorNSW = listCursorChooseBorder (Set.fromList [North,South,West])
listCursorNSW = listCursorChooseBorder (Set.fromList [North, South, West])
fillScreenText :: Configuration -> String -> Picture
fillScreenText cfig str =