diff options
Diffstat (limited to 'axis.hs')
-rw-r--r-- | axis.hs | 65 |
1 files changed, 35 insertions, 30 deletions
@@ -51,6 +51,7 @@ main = | |||
51 | -- _ <- SDL.setRelativeMouseMode True -- SDL2. Should I use it? | 51 | -- _ <- SDL.setRelativeMouseMode True -- SDL2. Should I use it? |
52 | 52 | ||
53 | let (axis_key_size, axis_key_locations) = getKeyLocations videoClipRect | 53 | let (axis_key_size, axis_key_locations) = getKeyLocations videoClipRect |
54 | print getKeyLocationsAbs | ||
54 | print axis_key_locations | 55 | print axis_key_locations |
55 | 56 | ||
56 | putStrLn "Initialized." | 57 | putStrLn "Initialized." |
@@ -129,49 +130,53 @@ centerText videoSurface x y font text = do | |||
129 | 130 | ||
130 | 131 | ||
131 | getKeyLocations (SDL.Rect offx offy totalw totalh) = | 132 | getKeyLocations (SDL.Rect offx offy totalw totalh) = |
132 | let (kb_rows, kb_cols) = (7, 14) :: (Int, Int) | 133 | let (key_height, key_width, xys) = getKeyLocationsAbs |
133 | -- the edges of the hexagon are equal in length to its "radius" | ||
134 | -- if the radius is 1, then horizontal movement is 1.5 and vertical movement is sqrt(3) from one center to the next | ||
135 | -- or else it is 2*sqrt(3) to move up | ||
136 | -- 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 | ||
137 | -- thus the keyboard is radius * (numkeys * 1.5 + 1) | ||
138 | key_width = 2000 | ||
139 | key_height = key_width * toRational(sqrt(3)) -- hexagon ratio | ||
140 | keyboard_width = (toRational(kb_cols) * 1.5) * key_width | ||
141 | keyboard_height = (toRational(kb_rows) + 2) * key_height -- half of the keyboard is offset down one key | ||
142 | 134 | ||
143 | fit_width = toRational(totalh) / toRational(totalw) > keyboard_height / keyboard_width | 135 | kb_rows = length xys |
136 | kb_cols = length (head xys) | ||
144 | 137 | ||
138 | -- 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 | ||
139 | -- thus the keyboard is radius * (numkeys - 1) * 1.5 + 1) | ||
140 | keyboard_width = (fromIntegral(kb_cols - 1) * 1.5 + 2) * key_width | ||
141 | keyboard_height = fromIntegral(kb_rows + 1) * key_height -- half of the keyboard is offset down one key | ||
142 | |||
143 | fit_width = fromIntegral(totalh) / fromIntegral(totalw) > keyboard_height / keyboard_width | ||
145 | scale = if fit_width | 144 | scale = if fit_width |
146 | then toRational(totalw) / keyboard_width | 145 | then fromIntegral(totalw) / keyboard_width |
147 | else toRational(totalh) / keyboard_height | 146 | else fromIntegral(totalh) / keyboard_height |
148 | 147 | ||
149 | centerx = floor(toRational(totalw) - keyboard_width * scale) `div` 2 | 148 | kh = key_height * scale |
150 | centery = floor(toRational(totalh) - keyboard_height * scale) `div` 2 | 149 | kw = key_width * scale |
151 | 150 | ||
152 | kh = floor(key_height * scale) | 151 | centerx = (fromIntegral(totalw) - keyboard_width * scale) / 2 |
153 | kw = floor(key_width * scale) | 152 | centery = (fromIntegral(totalh) - keyboard_height * scale) / 2 |
154 | scaled_horiz_offset = floor(scale * 0.5 * key_width) | 153 | in |
154 | (floor(kw * 15/16), map (\(x, y) -> (floor(scale * x + centerx + kw), floor(scale * y + centery + kh/2))) $ concat xys) | ||
155 | |||
156 | getKeyLocationsAbs = | ||
157 | let kb_rows = 7 :: Double | ||
158 | kb_cols = 14 :: Double | ||
159 | -- the edges of the hexagon are equal in length to its "radius" | ||
160 | -- if the radius is 1, then horizontal movement is 1.5 and vertical movement is sqrt(3) from one center to the next | ||
161 | -- or else it is 2*sqrt(3) to move up | ||
155 | 162 | ||
156 | radius = kw * 31 `div` 32 | 163 | kw = 1 :: Double |
157 | --radius = kw | 164 | kh = kw * sqrt(3) -- hexagon ratio |
158 | 165 | ||
159 | xys = | 166 | xys = |
160 | map (\(x, y) -> (x + centerx + kw, y + centery + kh)) $ | ||
161 | concat $ | ||
162 | map (\y -> map (\i -> ( | 167 | map (\y -> map (\i -> ( |
163 | 168 | ||
164 | i * kw * 3 `div` 2, | 169 | fromInteger(i) * kw * 3 / 2, |
165 | 170 | ||
166 | y + kh `div` 2 * (i `mod` 2) + | 171 | y + kh / 2 * fromInteger(i `mod` 2) + |
167 | 172 | ||
168 | (if (i >= kb_cols `div` 2) then kh * ((i+1) `mod` 2) else 0) | 173 | (if (fromInteger(i) >= kb_cols / 2) then kh * fromInteger((i+1) `mod` 2) else 0) |
169 | 174 | ||
170 | )) [0 .. kb_cols - 1]) $ | 175 | )) [0 .. round(kb_cols) - 1]) $ |
171 | map (\i -> kh * i) | 176 | map (\i -> kh * fromIntegral(i)) |
172 | [0..kb_rows - 1] | 177 | [0..round(kb_rows) - 1] |
173 | in | 178 | in |
174 | (radius, xys) | 179 | (kh, kw, xys) |
175 | 180 | ||
176 | -- clear a band the width of the videoClipRect and print the text within it, centered | 181 | -- clear a band the width of the videoClipRect and print the text within it, centered |
177 | textBand videoSurface videoClipRect (SDL.Rect _ y _ h) font text = do | 182 | textBand videoSurface videoClipRect (SDL.Rect _ y _ h) font text = do |