From 3fef16ce1c958d136ebf2ca2675e67c8d46d0153 Mon Sep 17 00:00:00 2001 From: Andrew Cady Date: Thu, 16 Jan 2014 16:54:09 -0500 Subject: fix the pixel edges --- axis.hs | 65 +++++++++++++++++++++++++++++++++++------------------------------ 1 file changed, 35 insertions(+), 30 deletions(-) (limited to 'axis.hs') diff --git a/axis.hs b/axis.hs index 6774ef5..ac62624 100644 --- a/axis.hs +++ b/axis.hs @@ -51,6 +51,7 @@ main = -- _ <- SDL.setRelativeMouseMode True -- SDL2. Should I use it? let (axis_key_size, axis_key_locations) = getKeyLocations videoClipRect + print getKeyLocationsAbs print axis_key_locations putStrLn "Initialized." @@ -129,49 +130,53 @@ centerText videoSurface x y font text = do getKeyLocations (SDL.Rect offx offy totalw totalh) = - let (kb_rows, kb_cols) = (7, 14) :: (Int, Int) - -- the edges of the hexagon are equal in length to its "radius" - -- if the radius is 1, then horizontal movement is 1.5 and vertical movement is sqrt(3) from one center to the next - -- or else it is 2*sqrt(3) to move up - -- there are 14 keys (13 steps) from the far left to the far right of the axis, each step is 1.5 horizontal, plus 2 to fill to the edges - -- thus the keyboard is radius * (numkeys * 1.5 + 1) - key_width = 2000 - key_height = key_width * toRational(sqrt(3)) -- hexagon ratio - keyboard_width = (toRational(kb_cols) * 1.5) * key_width - keyboard_height = (toRational(kb_rows) + 2) * key_height -- half of the keyboard is offset down one key + let (key_height, key_width, xys) = getKeyLocationsAbs - fit_width = toRational(totalh) / toRational(totalw) > keyboard_height / keyboard_width + kb_rows = length xys + kb_cols = length (head xys) + -- there are 14 keys (13 steps) from the far left to the far right of the axis, each step is 1.5 horizontal, plus 2 halfs to fill to the edges + -- thus the keyboard is radius * (numkeys - 1) * 1.5 + 1) + keyboard_width = (fromIntegral(kb_cols - 1) * 1.5 + 2) * key_width + keyboard_height = fromIntegral(kb_rows + 1) * key_height -- half of the keyboard is offset down one key + + fit_width = fromIntegral(totalh) / fromIntegral(totalw) > keyboard_height / keyboard_width scale = if fit_width - then toRational(totalw) / keyboard_width - else toRational(totalh) / keyboard_height + then fromIntegral(totalw) / keyboard_width + else fromIntegral(totalh) / keyboard_height - centerx = floor(toRational(totalw) - keyboard_width * scale) `div` 2 - centery = floor(toRational(totalh) - keyboard_height * scale) `div` 2 + kh = key_height * scale + kw = key_width * scale - kh = floor(key_height * scale) - kw = floor(key_width * scale) - scaled_horiz_offset = floor(scale * 0.5 * key_width) + centerx = (fromIntegral(totalw) - keyboard_width * scale) / 2 + centery = (fromIntegral(totalh) - keyboard_height * scale) / 2 + in + (floor(kw * 15/16), map (\(x, y) -> (floor(scale * x + centerx + kw), floor(scale * y + centery + kh/2))) $ concat xys) + +getKeyLocationsAbs = + let kb_rows = 7 :: Double + kb_cols = 14 :: Double + -- the edges of the hexagon are equal in length to its "radius" + -- if the radius is 1, then horizontal movement is 1.5 and vertical movement is sqrt(3) from one center to the next + -- or else it is 2*sqrt(3) to move up - radius = kw * 31 `div` 32 - --radius = kw + kw = 1 :: Double + kh = kw * sqrt(3) -- hexagon ratio - xys = - map (\(x, y) -> (x + centerx + kw, y + centery + kh)) $ - concat $ + xys = map (\y -> map (\i -> ( - i * kw * 3 `div` 2, + fromInteger(i) * kw * 3 / 2, - y + kh `div` 2 * (i `mod` 2) + + y + kh / 2 * fromInteger(i `mod` 2) + - (if (i >= kb_cols `div` 2) then kh * ((i+1) `mod` 2) else 0) + (if (fromInteger(i) >= kb_cols / 2) then kh * fromInteger((i+1) `mod` 2) else 0) - )) [0 .. kb_cols - 1]) $ - map (\i -> kh * i) - [0..kb_rows - 1] + )) [0 .. round(kb_cols) - 1]) $ + map (\i -> kh * fromIntegral(i)) + [0..round(kb_rows) - 1] in - (radius, xys) + (kh, kw, xys) -- clear a band the width of the videoClipRect and print the text within it, centered textBand videoSurface videoClipRect (SDL.Rect _ y _ h) font text = do -- cgit v1.2.3