diff options
Diffstat (limited to 'axis.hs')
-rw-r--r-- | axis.hs | 37 |
1 files changed, 18 insertions, 19 deletions
@@ -92,6 +92,10 @@ main = | |||
92 | --SDL.Primitive.filledCircle videoSurface (fromIntegral x) (fromIntegral y) (fromIntegral axis_key_size) blue >>= return | 92 | --SDL.Primitive.filledCircle videoSurface (fromIntegral x) (fromIntegral y) (fromIntegral axis_key_size) blue >>= return |
93 | drawHexagonSDL videoSurface (fromIntegral x) (fromIntegral y) (fromIntegral axis_key_size) blue >>= return | 93 | drawHexagonSDL videoSurface (fromIntegral x) (fromIntegral y) (fromIntegral axis_key_size) blue >>= return |
94 | 94 | ||
95 | forM_ [0 .. length axis_key_locations - 1] $ \i -> do | ||
96 | let (centerx, centery) = axis_key_locations !! i | ||
97 | centerText videoSurface centerx centery font (show i) | ||
98 | |||
95 | _ <- SDL.updateRect videoSurface videoClipRect -- draw it all! | 99 | _ <- SDL.updateRect videoSurface videoClipRect -- draw it all! |
96 | 100 | ||
97 | let framerate = 30 | 101 | let framerate = 30 |
@@ -110,14 +114,6 @@ drawHexagonSDL videoSurface centerx centery radius pixel = do | |||
110 | map (\i -> (r * cos(pi/3 * (i)), r * sin(pi/3 * (i)))) $ map fromIntegral [0 .. 5] | 114 | map (\i -> (r * cos(pi/3 * (i)), r * sin(pi/3 * (i)))) $ map fromIntegral [0 .. 5] |
111 | --filledPolygon :: Surface -> [(Int16, Int16)] -> Pixel -> IO Bool | 115 | --filledPolygon :: Surface -> [(Int16, Int16)] -> Pixel -> IO Bool |
112 | SDL.Primitive.polygon videoSurface points pixel >>= return | 116 | SDL.Primitive.polygon videoSurface points pixel >>= return |
113 | |||
114 | let pixelFormat = SDL.surfaceGetPixelFormat videoSurface | ||
115 | blue <- SDL.mapRGB pixelFormat 0 255 255 -- why is it blue??? | ||
116 | SDL.Primitive.filledCircle videoSurface (fromIntegral centerx) (fromIntegral centery) 10 blue >>= return | ||
117 | SDL.Primitive.filledCircle videoSurface 0 0 10 blue >>= return | ||
118 | |||
119 | font <- SDL.TTF.openFont "LiberationMono-Bold.ttf" 30 | ||
120 | centerText videoSurface centerx centery font "OK!" | ||
121 | return () | 117 | return () |
122 | 118 | ||
123 | centerText videoSurface x y font text = do | 119 | centerText videoSurface x y font text = do |
@@ -132,26 +128,29 @@ centerText videoSurface x y font text = do | |||
132 | getKeyLocations (SDL.Rect offx offy totalw totalh) = | 128 | getKeyLocations (SDL.Rect offx offy totalw totalh) = |
133 | let (key_height, key_width, xys) = getKeyLocationsAbs | 129 | let (key_height, key_width, xys) = getKeyLocationsAbs |
134 | 130 | ||
131 | screenw = fromIntegral(totalw) | ||
132 | screenh = fromIntegral(totalh) | ||
133 | |||
135 | kb_rows = length xys | 134 | kb_rows = length xys |
136 | kb_cols = length (head xys) | 135 | kb_cols = length (head xys) |
137 | 136 | ||
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 | 137 | -- there are 14 keys (13 steps) from the far left to the far right of the axis; if the radius is 1 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) | 138 | -- thus the keyboard is radius * ((numkeys - 1) * 1.5 + 2) |
140 | keyboard_width = (fromIntegral(kb_cols - 1) * 1.5 + 2) * key_width | 139 | keyboard_width = (fromIntegral(kb_cols - 1) * 1.5 + 2) * key_width / 2 |
141 | keyboard_height = fromIntegral(kb_rows + 1) * key_height -- half of the keyboard is offset down one key | 140 | keyboard_height = fromIntegral(kb_rows + 1) * key_height -- half of the keyboard is offset down one key |
142 | 141 | ||
143 | fit_width = fromIntegral(totalh) / fromIntegral(totalw) > keyboard_height / keyboard_width | 142 | fit_width = screenh / screenw > keyboard_height / keyboard_width |
144 | scale = if fit_width | 143 | scale = if fit_width |
145 | then fromIntegral(totalw) / keyboard_width | 144 | then screenw / keyboard_width |
146 | else fromIntegral(totalh) / keyboard_height | 145 | else screenh / keyboard_height |
147 | 146 | ||
148 | kh = key_height * scale | 147 | kh = key_height * scale |
149 | kw = key_width * scale | 148 | kw = key_width * scale |
150 | 149 | ||
151 | centerx = (fromIntegral(totalw) - keyboard_width * scale) / 2 | 150 | centerx = (screenw - keyboard_width * scale) / 2 |
152 | centery = (fromIntegral(totalh) - keyboard_height * scale) / 2 | 151 | centery = (screenh - keyboard_height * scale) / 2 |
153 | in | 152 | in |
154 | (floor(kw * 15/16), map (\(x, y) -> (floor(scale * x + centerx + kw), floor(scale * y + centery + kh/2))) $ concat xys) | 153 | (floor(kw/2 * 15/16), map (\(x, y) -> (floor(scale * x + centerx + kw/2), floor(scale * y + centery + kh/2))) $ concat xys) |
155 | 154 | ||
156 | getKeyLocationsAbs = | 155 | getKeyLocationsAbs = |
157 | let kb_rows = 7 :: Double | 156 | let kb_rows = 7 :: Double |
@@ -161,12 +160,12 @@ getKeyLocationsAbs = | |||
161 | -- or else it is 2*sqrt(3) to move up | 160 | -- or else it is 2*sqrt(3) to move up |
162 | 161 | ||
163 | kw = 1 :: Double | 162 | kw = 1 :: Double |
164 | kh = kw * sqrt(3) -- hexagon ratio | 163 | kh = kw/2 * sqrt(3) -- hexagon ratio |
165 | 164 | ||
166 | xys = | 165 | xys = |
167 | map (\y -> map (\i -> ( | 166 | map (\y -> map (\i -> ( |
168 | 167 | ||
169 | fromInteger(i) * kw * 3 / 2, | 168 | fromInteger(i) * kw * 3 / 4, |
170 | 169 | ||
171 | y + kh / 2 * fromInteger(i `mod` 2) + | 170 | y + kh / 2 * fromInteger(i `mod` 2) + |
172 | 171 | ||