0 | {- Tian Z (ecburx@burx.vip) -}
  1 |
  2 | module IdrisGL.SDL.SDL_gfx
  3 |
  4 | import IdrisGL.DataType
  5 | import IdrisGL.Color
  6 |
  7 | {-
  8 |     FFI
  9 | -}
 10 |
 11 | frgn : String -> String
 12 | frgn func = "C:" ++ func ++ ",sdl_gfx"
 13 |
 14 | -- Pixel
 15 |
 16 | %foreign frgn "pixel"
 17 | prim_pixel : AnyPtr
 18 |            -> Int -> Int
 19 |            -> Int -> Int -> Int -> Int
 20 |            -> PrimIO ()
 21 |
 22 | ||| Draw a pixel.
 23 | export
 24 | pixel : HasIO io => Renderer -> Coordinate -> Color -> io ()
 25 | pixel (MkRenderer ren) (MkCoor x y) color
 26 |     = let (r,g,b,a) = rgbaOfColor color in
 27 |       primIO $ prim_pixel ren x y r g b a
 28 |
 29 | -- Line
 30 |
 31 | %foreign frgn "thickLine"
 32 | prim_thickLine : AnyPtr
 33 |           -> Int -> Int -> Int -> Int
 34 |           -> Int -> Int -> Int -> Int
 35 |           -> Int
 36 |           -> PrimIO ()
 37 |
 38 | ||| Draw a line with given thickness.
 39 | ||| @ width Thickness.
 40 | export
 41 | thickLine : HasIO io => Renderer
 42 |                      -> Coordinate -> Coordinate -> Color
 43 |                      -> (width : Int)
 44 |                      -> io ()
 45 | thickLine (MkRenderer ren) (MkCoor x1 y1) (MkCoor x2 y2) color width
 46 |     = let (r,g,b,a) = rgbaOfColor color in
 47 |       primIO $ prim_thickLine ren x1 y1 x2 y2 r g b a width
 48 |
 49 | --
 50 |
 51 | %foreign frgn "aaline"
 52 | prim_aaline : AnyPtr
 53 |           -> Int -> Int -> Int -> Int
 54 |           -> Int -> Int -> Int -> Int
 55 |           -> PrimIO ()
 56 |
 57 | ||| Draw an anti-aliased line.
 58 | export
 59 | aaline : HasIO io => Renderer -> Coordinate -> Coordinate -> Color -> io ()
 60 | aaline (MkRenderer ren) (MkCoor x1 y1) (MkCoor x2 y2) color
 61 |     = let (r,g,b,a) = rgbaOfColor color in
 62 |       primIO $ prim_aaline ren x1 y1 x2 y2 r g b a
 63 |
 64 | -- Rectangle
 65 |
 66 | %foreign frgn "rect"
 67 | prim_rect : AnyPtr
 68 |           -> Int -> Int -> Int -> Int
 69 |           -> Int -> Int -> Int -> Int
 70 |           -> PrimIO ()
 71 |
 72 | ||| Draw a rectangle.
 73 | export
 74 | rectangle : HasIO io => Renderer -> Rect -> Color -> io ()
 75 | rectangle (MkRenderer ren) (MkRect x y w h) color
 76 |     = let (r,g,b,a) = rgbaOfColor color in
 77 |       primIO $ prim_rect ren x y w h r g b a
 78 |
 79 | --
 80 |
 81 | %foreign frgn "roundedRect"
 82 | prim_roundedRect : AnyPtr
 83 |                  -> Int -> Int -> Int -> Int
 84 |                  -> Int -> Int -> Int -> Int
 85 |                  -> Int
 86 |                  -> PrimIO ()
 87 |
 88 | ||| Draw a rounded-corner rectangle.
 89 | ||| @ rad The radius of the corner arc.
 90 | export
 91 | roundedRect : HasIO io => Renderer -> Rect -> Color -> (rad : Int) -> io ()
 92 | roundedRect (MkRenderer ren) (MkRect x y w h) color rad
 93 |     = let (r,g,b,a) = rgbaOfColor color in
 94 |       primIO $ prim_roundedRect ren x y w h r g b a rad
 95 |
 96 | --
 97 |
 98 | %foreign frgn "filledRect"
 99 | prim_filledRect : AnyPtr
100 |                 -> Int -> Int -> Int -> Int
101 |                 -> Int -> Int -> Int -> Int
102 |                 -> PrimIO ()
103 |
104 | ||| Draw a rectangle filled with the given color.
105 | export
106 | filledRect : HasIO io => Renderer -> Rect -> Color -> io ()
107 | filledRect (MkRenderer ren) (MkRect x y w h) color
108 |     = let (r,g,b,a) = rgbaOfColor color in
109 |       primIO $ prim_filledRect ren x y w h r g b a
110 |
111 | --
112 |
113 | %foreign frgn "roundedFilledRect"
114 | prim_roundedFilledRect : AnyPtr
115 |                        -> Int -> Int -> Int -> Int
116 |                        -> Int -> Int -> Int -> Int
117 |                        -> Int
118 |                        -> PrimIO ()
119 |
120 | ||| Draw a rounded-corner rectangle filled with the given color.
121 | ||| @ rad The radius of the corner arc.
122 | export
123 | roundedFilledRect : HasIO io => Renderer -> Rect -> Color -> (rad : Int) -> io ()
124 | roundedFilledRect (MkRenderer ren) (MkRect x y w h) color rad
125 |     = let (r,g,b,a) = rgbaOfColor color in
126 |       primIO $ prim_roundedFilledRect ren x y w h r g b a rad
127 |
128 | -- Circle
129 |
130 | %foreign frgn "circle"
131 | prim_circle : AnyPtr
132 |             -> Int -> Int
133 |             -> Int -> Int -> Int -> Int
134 |             -> Int
135 |             -> PrimIO ()
136 |
137 | ||| Draw a circle.
138 | ||| @ rad Radius in pixels of the circle.
139 | export
140 | circle : HasIO io => Renderer -> Coordinate -> Color -> (rad : Int) -> io ()
141 | circle (MkRenderer ren) (MkCoor x y) color rad
142 |     = let (r,g,b,a) = rgbaOfColor color in
143 |       primIO $ prim_circle ren x y r g b a rad
144 |
145 | --
146 |
147 | %foreign frgn "aaCircle"
148 | prim_aaCircle : AnyPtr
149 |             -> Int -> Int
150 |             -> Int -> Int -> Int -> Int
151 |             -> Int
152 |             -> PrimIO ()
153 |
154 | ||| Draw an anti-aliased circle.
155 | ||| @ rad Radius in pixels of the circle.
156 | export
157 | aaCircle : HasIO io => Renderer -> Coordinate -> Color -> Int -> io ()
158 | aaCircle (MkRenderer ren) (MkCoor x y) color rad
159 |     = let (r,g,b,a) = rgbaOfColor color in
160 |       primIO $ prim_aaCircle ren x y r g b a rad
161 |
162 | --
163 |
164 | %foreign frgn "filledCircle"
165 | prim_filledCircle : AnyPtr
166 |             -> Int -> Int
167 |             -> Int -> Int -> Int -> Int
168 |             -> Int
169 |             -> PrimIO ()
170 |
171 | ||| Draw a circle filled with given color.
172 | ||| @ rad Radius in pixels of the circle.
173 | export
174 | filledCircle : HasIO io => Renderer -> Coordinate -> Color -> Int -> io ()
175 | filledCircle (MkRenderer ren) (MkCoor x y) color rad
176 |     = let (r,g,b,a) = rgbaOfColor color in
177 |       primIO $ prim_filledCircle ren x y r g b a rad
178 |
179 | --
180 |
181 | %foreign frgn "thickCircle"
182 | prim_thickCircle : AnyPtr
183 |                 -> Int -> Int
184 |                 -> Int -> Int -> Int -> Int
185 |                 -> Int -> Int
186 |                 -> PrimIO ()
187 |
188 | ||| Draw a circle with the given radius and thickness.
189 | ||| @ rad   Radius in pixels of the circle.
190 | ||| @ width Thickness.
191 | export
192 | thickCircle : HasIO io => Renderer -> Coordinate -> Color -> (rad : Int) -> (width : Int) -> io ()
193 | thickCircle (MkRenderer ren) (MkCoor x y) color rad width
194 |     = let (r,g,b,a) = rgbaOfColor color in
195 |       primIO $ prim_thickCircle ren x y r g b a rad width
196 |
197 | -- Arc
198 |
199 | %foreign frgn "arc"
200 | prim_arc : AnyPtr
201 |          -> Int -> Int
202 |          -> Int -> Int -> Int -> Int
203 |          -> Int -> Int -> Int
204 |          -> PrimIO ()
205 |
206 | ||| Draw a circular arc drawn counter-clockwise between two angles (in degrees).
207 | ||| @ rad   Radius in pixels of the circle.
208 | ||| @ start The angle of start point.
209 | ||| @ end   The angle of end point.
210 | export
211 | arc : HasIO io => Renderer
212 |                -> Coordinate -> Color
213 |                -> (rad : Int) -> (start : Int) -> (end : Int)
214 |                -> io ()
215 | arc (MkRenderer ren) (MkCoor x y) color rad start end
216 |     = let (r,g,b,a) = rgbaOfColor color in
217 |       primIO $ prim_arc ren x y r g b a rad start end
218 |
219 | -- Ellipse
220 |
221 | %foreign frgn "ellipse"
222 | prim_ellipse : AnyPtr
223 |              -> Int -> Int -> Int -> Int
224 |              -> Int -> Int -> Int -> Int
225 |              -> PrimIO ()
226 |
227 | ||| Draw an ellipse.
228 | ||| @ rx Horizontal radius in pixels of the ellipse.
229 | ||| @ ry Vertical radius in pixels of the ellipse.
230 | export
231 | ellipse : HasIO io => Renderer -> Coordinate
232 |                    -> (rx : Int) -> (ry : Int) -> Color
233 |                    -> io ()
234 | ellipse (MkRenderer ren) (MkCoor x y) rx ry color
235 |     = let (r,g,b,a) = rgbaOfColor color in
236 |       primIO $ prim_ellipse ren x y rx ry r g b a
237 |
238 | --
239 |
240 | %foreign frgn "filledEllipse"
241 | prim_filledEllipse : AnyPtr
242 |              -> Int -> Int -> Int -> Int
243 |              -> Int -> Int -> Int -> Int
244 |              -> PrimIO ()
245 |
246 | ||| Draw an ellipse filled with given color.
247 | ||| @ rx Horizontal radius in pixels of the ellipse.
248 | ||| @ ry Vertical radius in pixels of the ellipse.
249 | export
250 | filledEllipse : HasIO io => Renderer -> Coordinate
251 |                    -> (rx : Int) -> (ry : Int) -> Color
252 |                    -> io ()
253 | filledEllipse (MkRenderer ren) (MkCoor x y) rx ry color
254 |     = let (r,g,b,a) = rgbaOfColor color in
255 |       primIO $ prim_filledEllipse ren x y rx ry r g b a
256 |
257 | --
258 |
259 | %foreign frgn "aaellipse"
260 | prim_aaellipse : AnyPtr
261 |              -> Int -> Int -> Int -> Int
262 |              -> Int -> Int -> Int -> Int
263 |              -> PrimIO ()
264 |
265 | ||| Draw an anti-aliased ellipse.
266 | ||| @ rx Horizontal radius in pixels of the ellipse.
267 | ||| @ ry Vertical radius in pixels of the ellipse.
268 | export
269 | aaellipse : HasIO io => Renderer -> Coordinate
270 |                      -> (rx : Int) -> (ry : Int) -> Color
271 |                      -> io ()
272 | aaellipse (MkRenderer ren) (MkCoor x y) rx ry color
273 |     = let (r,g,b,a) = rgbaOfColor color in
274 |       primIO $ prim_aaellipse ren x y rx ry r g b a
275 |
276 | -- Pie
277 |
278 | %foreign frgn "pie"
279 | prim_pie : AnyPtr
280 |          -> Int -> Int
281 |          -> Int -> Int -> Int -> Int
282 |          -> Int -> Int -> Int
283 |          -> PrimIO ()
284 |
285 | %foreign frgn "filledPie"
286 | prim_filledPie : AnyPtr
287 |          -> Int -> Int
288 |          -> Int -> Int -> Int -> Int
289 |          -> Int -> Int -> Int
290 |          -> PrimIO ()
291 |
292 | ||| Draw a pie.
293 | ||| @ rad   Radius in pixels of the circle.
294 | ||| @ start The angle of start point.
295 | ||| @ end   The angle of end point.
296 | export
297 | pie : HasIO io => Renderer -> Coordinate -> Color
298 |                -> (rad : Int) -> (start : Int) -> (end : Int)
299 |                -> io ()
300 | pie (MkRenderer ren) (MkCoor x y) color rad start end
301 |     = let (r,g,b,a) = rgbaOfColor color in
302 |       primIO $ prim_pie ren x y r g b a rad start end
303 |
304 | ||| Draw a filled pie.
305 | ||| @ rad   Radius in pixels of the circle.
306 | ||| @ start The angle of start point.
307 | ||| @ end   The angle of end point.
308 | export
309 | filledPie : HasIO io => Renderer -> Coordinate -> Color
310 |                -> (rad : Int) -> (start : Int) -> (end : Int)
311 |                -> io ()
312 | filledPie (MkRenderer ren) (MkCoor x y) color rad start end
313 |     = let (r,g,b,a) = rgbaOfColor color in
314 |       primIO $ prim_filledPie ren x y r g b a rad start end
315 |
316 |
317 | -- Trigon
318 |
319 | %foreign frgn "trigon"
320 | prim_trigon : AnyPtr
321 |             -> Int -> Int -> Int -> Int -> Int -> Int
322 |             -> Int -> Int -> Int -> Int
323 |             -> PrimIO ()
324 |
325 | ||| Draw a trigon.
326 | export
327 | trigon : HasIO io => Renderer -> Coordinate -> Coordinate -> Coordinate -> Color -> io ()
328 | trigon (MkRenderer ren) (MkCoor x1 y1) (MkCoor x2 y2) (MkCoor x3 y3) color
329 |     = let (r,g,b,a) = rgbaOfColor color in
330 |       primIO $ prim_trigon ren x1 y1 x2 y2 x3 y3 r g b a
331 |
332 | --
333 |
334 | %foreign frgn "filledTrigon"
335 | prim_filledTrigon : AnyPtr
336 |             -> Int -> Int -> Int -> Int -> Int -> Int
337 |             -> Int -> Int -> Int -> Int
338 |             -> PrimIO ()
339 |
340 | ||| Draw a trigon filled with given color.
341 | export
342 | filledTrigon : HasIO io => Renderer -> Coordinate -> Coordinate -> Coordinate -> Color -> io ()
343 | filledTrigon (MkRenderer ren) (MkCoor x1 y1) (MkCoor x2 y2) (MkCoor x3 y3) color
344 |     = let (r,g,b,a) = rgbaOfColor color in
345 |       primIO $ prim_filledTrigon ren x1 y1 x2 y2 x3 y3 r g b a
346 |
347 | --
348 |
349 | %foreign frgn "aatrigon"
350 | prim_aatrigon : AnyPtr
351 |             -> Int -> Int -> Int -> Int -> Int -> Int
352 |             -> Int -> Int -> Int -> Int
353 |             -> PrimIO ()
354 |
355 | ||| Draw an anti-aliased trigon.
356 | export
357 | aatrigon : HasIO io => Renderer -> Coordinate -> Coordinate -> Coordinate -> Color -> io ()
358 | aatrigon (MkRenderer ren) (MkCoor x1 y1) (MkCoor x2 y2) (MkCoor x3 y3) color
359 |     = let (r,g,b,a) = rgbaOfColor color in
360 |       primIO $ prim_aatrigon ren x1 y1 x2 y2 x3 y3 r g b a
361 |