diff options
author | Andrew Cady <d@jerkface.net> | 2014-01-18 08:49:54 -0500 |
---|---|---|
committer | Andrew Cady <d@jerkface.net> | 2014-01-18 08:50:13 -0500 |
commit | 403b5ff7df30daf799eb18bef65efe015e853292 (patch) | |
tree | 7a65b0a07b6c29e79f7d95229df229ad1ad1c3e4 | |
parent | 4429a9397e5e5fefe307be2a19fcd17585d1ee6f (diff) |
color the keyboard axis-style
the borders on keys have been disabled
-rw-r--r-- | axis.hs | 46 |
1 files changed, 32 insertions, 14 deletions
@@ -45,12 +45,14 @@ _AXIS_TOP_PITCH = 81 + (7 * (_AXIS_ROWS - 7) `div` 2) | |||
45 | _AXIS_BOTTOM_PITCH = 81 - (7 * _AXIS_ROWS) - 3 | 45 | _AXIS_BOTTOM_PITCH = 81 - (7 * _AXIS_ROWS) - 3 |
46 | _OCTAVE_SQUASH = False -- it's terrible, because it draws the octave in the wrong shape | 46 | _OCTAVE_SQUASH = False -- it's terrible, because it draws the octave in the wrong shape |
47 | 47 | ||
48 | _KEY_COLOR = (SDL.Color 0 0 255) | 48 | --_KEY_BORDER_COLOR = (SDL.Color 0 0 255) |
49 | _KEY_BG_COLOR = (SDL.Color 0 0 0) | 49 | _KEY_BORDER_COLOR = (SDL.Color 0 0 0) |
50 | _KEY_ON_COLOR = (SDL.Color 0xAA 0x00 0xFF) | ||
51 | _KB_BG_COLOR = (SDL.Color 0 0 0) | ||
50 | _KEY_TEXT_COLOR = (SDL.Color 128 128 0) | 52 | _KEY_TEXT_COLOR = (SDL.Color 128 128 0) |
51 | 53 | ||
52 | _KEY_COLOR_PIXEL = colorToPixel _KEY_COLOR | 54 | _KEY_BORDER_COLOR_PIXEL = colorToPixel _KEY_BORDER_COLOR |
53 | _KEY_BG_COLOR_PIXEL = colorToPixel _KEY_BG_COLOR | 55 | _KB_BG_COLOR_PIXEL = colorToPixel _KB_BG_COLOR |
54 | 56 | ||
55 | {- | 57 | {- |
56 | http://en.wikipedia.org/wiki/Enhanced_Graphics_Adapter | 58 | http://en.wikipedia.org/wiki/Enhanced_Graphics_Adapter |
@@ -72,7 +74,7 @@ http://en.wikipedia.org/wiki/Enhanced_Graphics_Adapter | |||
72 | 15 – bright white (#FFFFFF) 111111 63 | 74 | 15 – bright white (#FFFFFF) 111111 63 |
73 | -} | 75 | -} |
74 | 76 | ||
75 | _CGA = [--(SDL.Color 0x00 0x00 0x00), --black | 77 | _CGA = [ (SDL.Color 0x00 0x00 0x00), --black |
76 | (SDL.Color 0x00 0x00 0xAA), --blue | 78 | (SDL.Color 0x00 0x00 0xAA), --blue |
77 | (SDL.Color 0x00 0xAA 0x00), --green | 79 | (SDL.Color 0x00 0xAA 0x00), --green |
78 | (SDL.Color 0x00 0xAA 0xAA), --cyan | 80 | (SDL.Color 0x00 0xAA 0xAA), --cyan |
@@ -89,6 +91,8 @@ _CGA = [--(SDL.Color 0x00 0x00 0x00), --black | |||
89 | (SDL.Color 0xFF 0xFF 0x55), --bright yellow | 91 | (SDL.Color 0xFF 0xFF 0x55), --bright yellow |
90 | (SDL.Color 0xFF 0xFF 0xFF)] --bright white | 92 | (SDL.Color 0xFF 0xFF 0xFF)] --bright white |
91 | 93 | ||
94 | _CHAN_TO_COLOR = _KEY_ON_COLOR : (tail _CGA) | ||
95 | |||
92 | _drawHexircle f v x y s c = | 96 | _drawHexircle f v x y s c = |
93 | if _USE_HEXAGONS | 97 | if _USE_HEXAGONS |
94 | then _drawHexagonSDL f v x y s c | 98 | then _drawHexagonSDL f v x y s c |
@@ -98,29 +102,43 @@ drawHexircle = _drawHexircle False | |||
98 | drawFilledHexircle = _drawHexircle True | 102 | drawFilledHexircle = _drawHexircle True |
99 | colorToPixel x = let (SDL.Color r g b) = x in rgbColor r g b | 103 | colorToPixel x = let (SDL.Color r g b) = x in rgbColor r g b |
100 | 104 | ||
105 | inMajorC pclass = not (pclass == 1 || pclass == 3 || pclass == 6 || pclass == 8 || pclass == 10) | ||
106 | |||
107 | -- TODO: color schemes with per-key {bg, border, hilightcolor, textcolor} | ||
108 | -- TODO: try hilighting like in the app, where only part of the key is colored | ||
109 | -- TODO: idea: for the channels, draw a dot. offset the dot from the center of the key at an angle determined by the channel number | ||
110 | |||
111 | pitchToColor p = | ||
112 | case p `mod` 12 of | ||
113 | 2 -> (SDL.Color 0xD0 0xD0 0xFF) -- D | ||
114 | 8 -> _CGA !! 1 -- G# | ||
115 | x | inMajorC x -> (SDL.Color 0xE0 0xE0 0xE0) -- _CGA !! 7 | ||
116 | _ -> _CGA !! 8 | ||
117 | |||
101 | smartDrawKeys reallyErase drawSet eraseSet videoSurface font axis_key_locations axis_key_size = do | 118 | smartDrawKeys reallyErase drawSet eraseSet videoSurface font axis_key_locations axis_key_size = do |
102 | 119 | ||
103 | let drawList = filter (\ (c, _) -> unChannel c /= 9) $ Set.toList drawSet | 120 | let drawList = filter (\ (c, _) -> unChannel c /= 9) $ Set.toList drawSet |
104 | let eraseList = filter (\ (c, _) -> unChannel c /= 9) $ Set.toList eraseSet | 121 | eraseList = filter (\ (c, _) -> unChannel c /= 9) $ Set.toList eraseSet |
105 | 122 | ||
106 | forM_ [(eraseList, True), (drawList, False)] $ \ (ls, erase) -> do | 123 | forM_ [(eraseList, True), (drawList, False)] $ \ (ls, erase) -> do |
107 | forM_ ls $ \ (c, n) -> do | 124 | forM_ ls $ \ (c, n) -> do |
108 | let text = smartShowPitch (unPitch n) | 125 | let text = smartShowPitch (unPitch n) |
109 | let pitch = if _OCTAVE_SQUASH then (unPitch n) `mod` 12 + 12 * 6 else (unPitch n) | 126 | pitch = if _OCTAVE_SQUASH then (unPitch n) `mod` 12 + 12 * 6 else (unPitch n) |
110 | let chann = unChannel c | 127 | chann = unChannel c |
111 | let fillColor = if _COLORIZE_BY_CHANNEL | 128 | onColor = if _COLORIZE_BY_CHANNEL |
112 | then _CGA !! (((fromIntegral chann) + 2) `mod` 16) | 129 | then _CHAN_TO_COLOR !! ((fromIntegral chann) `mod` 16) |
113 | else _KEY_COLOR | 130 | else _KEY_ON_COLOR |
131 | offColor = pitchToColor pitch | ||
114 | forM_ (elemIndices pitch pitchIndex) $ \idx -> do | 132 | forM_ (elemIndices pitch pitchIndex) $ \idx -> do |
115 | drawKey idx videoSurface font axis_key_locations axis_key_size | 133 | drawKey idx videoSurface font axis_key_locations axis_key_size |
116 | (if erase then _KEY_BG_COLOR else fillColor) -- TODO: rename KEY_BG_COLOR as CANVAS_BG_COLOR | 134 | (if erase then (if reallyErase then _KB_BG_COLOR else offColor) else onColor) |
117 | (if reallyErase then _KEY_BG_COLOR_PIXEL else _KEY_COLOR_PIXEL) | 135 | (if reallyErase then _KB_BG_COLOR_PIXEL else _KEY_BORDER_COLOR_PIXEL) |
118 | (if erase then Nothing else (Just text)) | 136 | (if erase then Nothing else (Just text)) |
119 | 137 | ||
120 | drawKey idx videoSurface font axis_key_locations axis_key_size fillColor borderColor text = do | 138 | drawKey idx videoSurface font axis_key_locations axis_key_size fillColor borderColor text = do |
121 | let (x, y) = axis_key_locations !! idx | 139 | let (x, y) = axis_key_locations !! idx |
122 | drawFilledHexircle videoSurface (fromIntegral x) (fromIntegral y) (fromIntegral axis_key_size) (colorToPixel fillColor) | 140 | drawFilledHexircle videoSurface (fromIntegral x) (fromIntegral y) (fromIntegral axis_key_size) (colorToPixel fillColor) |
123 | drawHexircle videoSurface (fromIntegral x) (fromIntegral y) (fromIntegral axis_key_size) borderColor | 141 | --drawHexircle videoSurface (fromIntegral x) (fromIntegral y) (fromIntegral axis_key_size) borderColor |
124 | case text of | 142 | case text of |
125 | (Just t) -> centerText videoSurface x y font _KEY_TEXT_COLOR fillColor t | 143 | (Just t) -> centerText videoSurface x y font _KEY_TEXT_COLOR fillColor t |
126 | _ -> return () | 144 | _ -> return () |