From 9613cab22070d4a1c08df24e789737aeefe847c8 Mon Sep 17 00:00:00 2001 From: Andrew Cady Date: Fri, 4 Apr 2014 23:36:41 -0400 Subject: allow up to 9 visual repetitions of the keyboard why not? nothing else to bind those keys to yet --- axis.hs | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) (limited to 'axis.hs') diff --git a/axis.hs b/axis.hs index fe8a2e6..f4a2032 100644 --- a/axis.hs +++ b/axis.hs @@ -19,6 +19,7 @@ import Data.List (elemIndex, elemIndices, filter, groupBy, length, reverse, sort import GHC.Word import Data.Bits import qualified Sound.ALSA.Sequencer.Event as Event +import qualified Graphics.UI.SDL.Utilities as SDL.Util netwireIsCool :: (Monad m) => Wire (Timed NominalDiffTime ()) () m a String netwireIsCool = @@ -171,6 +172,11 @@ data LoopState = LoopState { repeatCols :: Integer } deriving (Show) +_SDL_DIGITS = Set.fromList [SDL.SDLK_1, SDL.SDLK_2, SDL.SDLK_3, SDL.SDLK_4, SDL.SDLK_5, SDL.SDLK_6, SDL.SDLK_7, SDL.SDLK_8, SDL.SDLK_9, SDL.SDLK_0] +firstDigitDown :: Set.Set SDL.Keysym.SDLKey -> Maybe Integer +firstDigitDown k = if Set.null digitsDown then Nothing else Just $ (-48 +) $ fromIntegral $ SDL.Util.fromEnum $ Set.findMin digitsDown + where digitsDown = Set.intersection _SDL_DIGITS k + main = withAlsaInit $ \h public private q publicAddr privateAddr -> do cmdlineAlsaConnect h public -- fail early if bad command lines @@ -208,7 +214,7 @@ main = (ds, s') <- stepSession s (ex, w') <- stepWire w ds (Right x) let x' = either (const "") id ex - let colsRepeat' = if (keyDown SDL.SDLK_1 keysDown') then 1 else if (keyDown SDL.SDLK_2 keysDown') then 2 else colsRepeat + let colsRepeat' = case firstDigitDown keysDown' of Nothing -> colsRepeat; (Just 0) -> colsRepeat; (Just n) -> n; let restartVideo = resolution' /= resolution || colsRepeat' /= colsRepeat @@ -344,17 +350,19 @@ getKeyLocationsAbs colsRepeat = kh = kw/2 * sqrt(3) -- hexagon ratio xys = - map (\y -> map (\i -> ( - - fromInteger(i) * kw * 3 / 4, - - y + kh / 2 * fromInteger(i `mod` 2) + - - (if (fromInteger(i) >= _AXIS_UNIQUE_COLS) then kh * fromInteger((i+1) `mod` 2) else 0) - - )) [0 .. round(kb_cols) - 1]) $ - map (\i -> kh * fromIntegral(i)) - [0..round(kb_rows) - 1] + map (\y -> map (\i -> + + let repetition = i `div` fromIntegral(_AXIS_UNIQUE_COLS) + odd = 1 == i `mod` 2 + dropBy = if odd then kh / 2 + kh * fromInteger(repetition `div` 2) + else kh * fromInteger((repetition + 1) `div` 2) + in + ( + fromInteger(i) * kw * 3 / 4, + y + dropBy + )) [0 .. round(kb_cols) - 1]) $ + map (\i -> kh * fromIntegral(i)) + [0..round(kb_rows) - 1] in (kh, kw, xys) -- cgit v1.2.3