summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Cady <d@jerkface.net>2014-04-04 23:36:41 -0400
committerAndrew Cady <d@jerkface.net>2014-04-04 23:36:46 -0400
commit9613cab22070d4a1c08df24e789737aeefe847c8 (patch)
tree5945790a9cd47a6714fe3cb24f37325a39c5f422
parent07f596faff2c5b70f799669c479354b46ce12a20 (diff)
allow up to 9 visual repetitions of the keyboard
why not? nothing else to bind those keys to yet
-rw-r--r--axis.hs32
1 files changed, 20 insertions, 12 deletions
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
19import GHC.Word 19import GHC.Word
20import Data.Bits 20import Data.Bits
21import qualified Sound.ALSA.Sequencer.Event as Event 21import qualified Sound.ALSA.Sequencer.Event as Event
22import qualified Graphics.UI.SDL.Utilities as SDL.Util
22 23
23netwireIsCool :: (Monad m) => Wire (Timed NominalDiffTime ()) () m a String 24netwireIsCool :: (Monad m) => Wire (Timed NominalDiffTime ()) () m a String
24netwireIsCool = 25netwireIsCool =
@@ -171,6 +172,11 @@ data LoopState = LoopState {
171 repeatCols :: Integer 172 repeatCols :: Integer
172} deriving (Show) 173} deriving (Show)
173 174
175_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]
176firstDigitDown :: Set.Set SDL.Keysym.SDLKey -> Maybe Integer
177firstDigitDown k = if Set.null digitsDown then Nothing else Just $ (-48 +) $ fromIntegral $ SDL.Util.fromEnum $ Set.findMin digitsDown
178 where digitsDown = Set.intersection _SDL_DIGITS k
179
174main = 180main =
175 withAlsaInit $ \h public private q publicAddr privateAddr -> do 181 withAlsaInit $ \h public private q publicAddr privateAddr -> do
176 cmdlineAlsaConnect h public -- fail early if bad command lines 182 cmdlineAlsaConnect h public -- fail early if bad command lines
@@ -208,7 +214,7 @@ main =
208 (ds, s') <- stepSession s 214 (ds, s') <- stepSession s
209 (ex, w') <- stepWire w ds (Right x) 215 (ex, w') <- stepWire w ds (Right x)
210 let x' = either (const "") id ex 216 let x' = either (const "") id ex
211 let colsRepeat' = if (keyDown SDL.SDLK_1 keysDown') then 1 else if (keyDown SDL.SDLK_2 keysDown') then 2 else colsRepeat 217 let colsRepeat' = case firstDigitDown keysDown' of Nothing -> colsRepeat; (Just 0) -> colsRepeat; (Just n) -> n;
212 218
213 let restartVideo = resolution' /= resolution || colsRepeat' /= colsRepeat 219 let restartVideo = resolution' /= resolution || colsRepeat' /= colsRepeat
214 220
@@ -344,17 +350,19 @@ getKeyLocationsAbs colsRepeat =
344 kh = kw/2 * sqrt(3) -- hexagon ratio 350 kh = kw/2 * sqrt(3) -- hexagon ratio
345 351
346 xys = 352 xys =
347 map (\y -> map (\i -> ( 353 map (\y -> map (\i ->
348 354
349 fromInteger(i) * kw * 3 / 4, 355 let repetition = i `div` fromIntegral(_AXIS_UNIQUE_COLS)
350 356 odd = 1 == i `mod` 2
351 y + kh / 2 * fromInteger(i `mod` 2) + 357 dropBy = if odd then kh / 2 + kh * fromInteger(repetition `div` 2)
352 358 else kh * fromInteger((repetition + 1) `div` 2)
353 (if (fromInteger(i) >= _AXIS_UNIQUE_COLS) then kh * fromInteger((i+1) `mod` 2) else 0) 359 in
354 360 (
355 )) [0 .. round(kb_cols) - 1]) $ 361 fromInteger(i) * kw * 3 / 4,
356 map (\i -> kh * fromIntegral(i)) 362 y + dropBy
357 [0..round(kb_rows) - 1] 363 )) [0 .. round(kb_cols) - 1]) $
364 map (\i -> kh * fromIntegral(i))
365 [0..round(kb_rows) - 1]
358 in 366 in
359 (kh, kw, xys) 367 (kh, kw, xys)
360 368