summaryrefslogtreecommitdiff
path: root/axis.hs
diff options
context:
space:
mode:
Diffstat (limited to 'axis.hs')
-rw-r--r--axis.hs65
1 files changed, 51 insertions, 14 deletions
diff --git a/axis.hs b/axis.hs
index c14c0a7..a51b846 100644
--- a/axis.hs
+++ b/axis.hs
@@ -15,7 +15,7 @@ import Graphics.UI.SDL.Keysym as SDL.Keysym
15import Graphics.UI.SDL.Primitives as SDL.Primitive 15import Graphics.UI.SDL.Primitives as SDL.Primitive
16import Data.Int (Int16) 16import Data.Int (Int16)
17import qualified System.Exit as Exit 17import qualified System.Exit as Exit
18import Data.List (elemIndex, elemIndices) 18import Data.List (elemIndex, elemIndices, filter)
19import GHC.Word 19import GHC.Word
20import Data.Bits 20import Data.Bits
21 21
@@ -35,18 +35,11 @@ netwireIsCool =
35smartShowPitch p = showPitch p -- TODO: use flat for Eb, Bb; use unicode flat/sharp chars 35smartShowPitch p = showPitch p -- TODO: use flat for Eb, Bb; use unicode flat/sharp chars
36 36
37_USE_HEXAGONS = False 37_USE_HEXAGONS = False
38 38_COLORIZE_BY_CHANNEL = False
39_drawHexircle f v x y s c =
40 if _USE_HEXAGONS
41 then _drawHexagonSDL f v x y s c
42 else (if f then SDL.Primitive.filledCircle else SDL.Primitive.circle) v x y (s * 7 `div` 9) c
43
44drawHexircle = _drawHexircle False
45drawFilledHexircle = _drawHexircle True
46 39
47_AXIS_ROWS = 7 + 4 40_AXIS_ROWS = 7 + 4
48_AXIS_UNIQUE_COLS = 7 41_AXIS_UNIQUE_COLS = 7
49_AXIS_COLS_REPEAT = 1 42_AXIS_COLS_REPEAT = 2
50_AXIS_TOP_PITCH = 81 + (7 * (_AXIS_ROWS - 7) `div` 2) 43_AXIS_TOP_PITCH = 81 + (7 * (_AXIS_ROWS - 7) `div` 2)
51_AXIS_BOTTOM_PITCH = 81 - (7 * _AXIS_ROWS) - 3 44_AXIS_BOTTOM_PITCH = 81 - (7 * _AXIS_ROWS) - 3
52 45
@@ -54,8 +47,39 @@ _KEY_COLOR = (SDL.Color 0 0 255)
54_KEY_BG_COLOR = (SDL.Color 0 0 0) 47_KEY_BG_COLOR = (SDL.Color 0 0 0)
55_KEY_TEXT_COLOR = (SDL.Color 128 128 0) 48_KEY_TEXT_COLOR = (SDL.Color 128 128 0)
56 49
57_KEY_COLOR_PIXEL = let (SDL.Color r g b) = _KEY_COLOR in (rgbColor r g b) 50_KEY_COLOR_PIXEL = colorToPixel _KEY_COLOR
58_KEY_BG_COLOR_PIXEL = let (SDL.Color r g b) = _KEY_BG_COLOR in (rgbColor r g b) 51_KEY_BG_COLOR_PIXEL = colorToPixel _KEY_BG_COLOR
52
53{-
54http://en.wikipedia.org/wiki/Enhanced_Graphics_Adapter
55 0 – black (#000000) 000000 0
56 1 – blue (#0000AA) 000001 1
57 2 – green (#00AA00) 000010 2
58 3 – cyan (#00AAAA) 000011 3
59 4 – red (#AA0000) 000100 4
60 5 – magenta (#AA00AA) 000101 5
61 6 – brown (#AA5500) 010100 20
62 7 – white / light gray (#AAAAAA) 000111 7
63 8 – dark gray / bright black (#555555) 111000 56
64 9 – bright blue (#5555FF) 111001 57
6510 – bright green (#55FF55) 111010 58
6611 – bright cyan (#55FFFF) 111011 59
6712 – bright red (#FF5555) 111100 60
6813 – bright magenta (#FF55FF) 111101 61
6914 – bright yellow (#FFFF55) 111110 62
7015 – bright white (#FFFFFF) 111111 63
71-}
72
73_CGA = [(SDL.Color 0x00 0x00 0x00), (SDL.Color 0x00 0x00 0xAA), (SDL.Color 0x00 0xAA 0x00), (SDL.Color 0x00 0xAA 0xAA), (SDL.Color 0xAA 0x00 0x00), (SDL.Color 0xAA 0x00 0xAA), (SDL.Color 0xAA 0x55 0x00), (SDL.Color 0xAA 0xAA 0xAA), (SDL.Color 0x55 0x55 0x55), (SDL.Color 0x55 0x55 0xFF), (SDL.Color 0x55 0xFF 0x55), (SDL.Color 0x55 0xFF 0xFF), (SDL.Color 0xFF 0x55 0x55), (SDL.Color 0xFF 0x55 0xFF), (SDL.Color 0xFF 0xFF 0x55), (SDL.Color 0xFF 0xFF 0xFF)]
74
75_drawHexircle f v x y s c =
76 if _USE_HEXAGONS
77 then _drawHexagonSDL f v x y s c
78 else (if f then SDL.Primitive.filledCircle else SDL.Primitive.circle) v x y (s * 7 `div` 9) c
79
80drawHexircle = _drawHexircle False
81drawFilledHexircle = _drawHexircle True
82colorToPixel x = let (SDL.Color r g b) = x in rgbColor r g b
59 83
60drawKeys pitches videoSurface font axis_key_locations axis_key_size = do 84drawKeys pitches videoSurface font axis_key_locations axis_key_size = do
61 85
@@ -68,14 +92,27 @@ drawKeys pitches videoSurface font axis_key_locations axis_key_size = do
68reallyEraseKeys = eraseKeys_ True 92reallyEraseKeys = eraseKeys_ True
69eraseKeys = eraseKeys_ False 93eraseKeys = eraseKeys_ False
70 94
95
71smartDrawKeys really drawSet eraseSet videoSurface font axis_key_locations axis_key_size = do 96smartDrawKeys really drawSet eraseSet videoSurface font axis_key_locations axis_key_size = do
72 97
73 let drawList = map (\ (_, n) -> unPitch n) $ Set.toList drawSet 98 let drawList = map (\ (_, n) -> unPitch n) $ Set.toList drawSet
74 let eraseList = map (\ (_, n) -> unPitch n) $ Set.toList eraseSet 99 let eraseList = map (\ (_, n) -> unPitch n) $ filter (\ (c, _) -> unChannel c /= 9) $ Set.toList eraseSet
75 100
76 drawKeys drawList videoSurface font axis_key_locations axis_key_size
77 eraseKeys_ really eraseList videoSurface font axis_key_locations axis_key_size 101 eraseKeys_ really eraseList videoSurface font axis_key_locations axis_key_size
78 102
103 forM_ (Set.toList drawSet) $ \ (c, n) -> do
104 let pitch = unPitch n
105 let chann = unChannel c
106 let color = if _COLORIZE_BY_CHANNEL
107 then _CGA !! (((fromIntegral chann) + 2) `mod` 16)
108 else _KEY_COLOR
109 Control.Monad.when(chann /= 9) $ -- TODO: do this elsewhere
110 forM_ (elemIndices pitch pitchIndex) $ \idx -> do
111 let (x, y) = axis_key_locations !! idx
112 drawFilledHexircle videoSurface (fromIntegral x) (fromIntegral y) (fromIntegral axis_key_size) (colorToPixel color)
113 drawHexircle videoSurface (fromIntegral x) (fromIntegral y) (fromIntegral axis_key_size) _KEY_COLOR_PIXEL
114 centerText videoSurface x y font _KEY_TEXT_COLOR color (smartShowPitch pitch)
115
79eraseKeys_ really pitches videoSurface font axis_key_locations axis_key_size = do 116eraseKeys_ really pitches videoSurface font axis_key_locations axis_key_size = do
80 117
81 forM_ pitches $ \pitch -> do 118 forM_ pitches $ \pitch -> do