diff options
Diffstat (limited to 'src/Chelleport')
| -rw-r--r-- | src/Chelleport/Config.hs | 2 | ||||
| -rw-r--r-- | src/Chelleport/Context.hs | 1 | ||||
| -rw-r--r-- | src/Chelleport/KeySequence.hs | 43 | ||||
| -rw-r--r-- | src/Chelleport/Types.hs | 4 |
4 files changed, 31 insertions, 19 deletions
diff --git a/src/Chelleport/Config.hs b/src/Chelleport/Config.hs index 65b7077..d8b4132 100644 --- a/src/Chelleport/Config.hs +++ b/src/Chelleport/Config.hs @@ -35,7 +35,7 @@ colorFineGrainGrid :: Color colorFineGrainGrid = SDL.V4 55 52 65 100 windowOpacity :: CFloat -windowOpacity = 0.4 +windowOpacity = 0.5 fontSize :: Int fontSize = 24 diff --git a/src/Chelleport/Context.hs b/src/Chelleport/Context.hs index b721812..45c90d4 100644 --- a/src/Chelleport/Context.hs +++ b/src/Chelleport/Context.hs @@ -7,7 +7,6 @@ import Chelleport.Config import Chelleport.Types import Data.ByteString (ByteString) import Data.FileEmbed (embedFileRelative) -import Foreign.C (CFloat) import qualified Graphics.X11 as X11 import SDL (($=)) import qualified SDL diff --git a/src/Chelleport/KeySequence.hs b/src/Chelleport/KeySequence.hs index dc5f603..9f1f26a 100644 --- a/src/Chelleport/KeySequence.hs +++ b/src/Chelleport/KeySequence.hs @@ -3,8 +3,9 @@ module Chelleport.KeySequence where import Chelleport.Types (KeyGrid, KeySequence) import Chelleport.Utils (findWithIndex, uniq) import Control.Monad (guard) -import Data.List (isPrefixOf) +import Data.List (elemIndex, isPrefixOf) import qualified Data.Map as Map +import Data.Maybe (fromMaybe, isJust) import qualified SDL nextChars :: KeySequence -> KeyGrid -> Maybe [Char] @@ -23,7 +24,7 @@ findMatchPosition keySequence = findWithIndex searchRows 0 searchInRow = guard . (== keySequence) isValidKey :: SDL.Keycode -> Bool -isValidKey = (`Map.member` keycodeMapping) +isValidKey = (`Map.member` keycodeCharMapping) -- Linear Congruential Generator lcg :: Int -> Int @@ -51,10 +52,10 @@ generateGrid seed (rows, columns) hintKeys ] toKeyChar :: SDL.Keycode -> Maybe Char -toKeyChar = (`Map.lookup` keycodeMapping) +toKeyChar = (`Map.lookup` keycodeCharMapping) -keycodeMapping :: Map.Map SDL.Keycode Char -keycodeMapping = +keycodeCharMapping :: Map.Map SDL.Keycode Char +keycodeCharMapping = Map.fromList [ (SDL.KeycodeA, 'A'), (SDL.KeycodeB, 'B'), @@ -81,15 +82,25 @@ keycodeMapping = (SDL.KeycodeW, 'W'), (SDL.KeycodeX, 'X'), (SDL.KeycodeY, 'Y'), - (SDL.KeycodeZ, 'Z'), - (SDL.Keycode0, '0'), - (SDL.Keycode1, '1'), - (SDL.Keycode2, '2'), - (SDL.Keycode3, '3'), - (SDL.Keycode4, '4'), - (SDL.Keycode5, '5'), - (SDL.Keycode6, '6'), - (SDL.Keycode7, '7'), - (SDL.Keycode8, '8'), - (SDL.Keycode9, '9') + (SDL.KeycodeZ, 'Z') ] + +keycodeToInt :: SDL.Keycode -> Maybe Int +keycodeToInt = (`elemIndex` digitKeycodes) + +isKeycodeDigit :: SDL.Keycode -> Bool +isKeycodeDigit = isJust . keycodeToInt + +digitKeycodes :: [SDL.Keycode] +digitKeycodes = + [ SDL.Keycode0, + SDL.Keycode1, + SDL.Keycode2, + SDL.Keycode3, + SDL.Keycode4, + SDL.Keycode5, + SDL.Keycode6, + SDL.Keycode7, + SDL.Keycode8, + SDL.Keycode9 + ] diff --git a/src/Chelleport/Types.hs b/src/Chelleport/Types.hs index b114189..3c52909 100644 --- a/src/Chelleport/Types.hs +++ b/src/Chelleport/Types.hs @@ -19,7 +19,8 @@ data State = State stateKeySequence :: KeySequence, stateIsMatched :: Bool, stateIsShiftPressed :: Bool, - stateIsDragging :: Bool + stateIsDragging :: Bool, + stateRepetition :: Int } deriving (Show, Eq) @@ -35,6 +36,7 @@ data AppAction | ShutdownApp | TriggerMouseClick MouseButtonType | UpdateShiftState Bool + | UpdateRepetition Int deriving (Show, Eq) data DrawContext = DrawContext |
