0 | {- Tian Z (ecburx@burx.vip) -}
 1 |
 2 | ||| Loads pictures using SDL bindings.
 3 | module IdrisGL.Picture
 4 |
 5 | import IdrisGL.DataType
 6 | import IdrisGL.Color
 7 | import IdrisGL.SDL.SDL_render
 8 | import IdrisGL.SDL.SDL_surface
 9 | import IdrisGL.SDL.SDL_image
10 | import IdrisGL.SDL.SDL_gfx
11 | import IdrisGL.SDL.SDL_ttf
12 | import IdrisGL.SDL.SDL_mixer
13 |
14 | ||| Loads pictures using SDL bindings.
15 | |||
16 | ||| @ pic Picture.
17 | ||| @ ren Renderer.
18 | ||| @ win Window.
19 | export
20 | loadPicture : (pic : Picture)
21 |            -> (ren : Renderer)
22 |            -> (win : Win)
23 |            -> IO ()
24 | loadPicture Blank                      _   _   =  pure ()
25 |
26 | loadPicture (Pictures [])              _   _   =  pure ()
27 | loadPicture (Pictures (x::xs))         ren win =  do
28 |   loadPicture                                     x ren win
29 |   loadPicture                                     (Pictures xs) ren win
30 |
31 | loadPicture (Rotate degree center pic) ren win =  do
32 |   texture                                      <- createTargetTexture win ren
33 |   setRenderTarget                                 ren texture
34 |   setRenderDrawColor                              ren transparent
35 |   renderClear                                     ren
36 |   loadPicture                                     pic ren win
37 |   resetRenderTarget                               ren
38 |   renderCopyExWin                                 win ren texture degree center FLIP_NONE
39 |
40 | loadPicture (Bitmap      path rect)                  ren _   = loadBMP ren path rect
41 | loadPicture (Image       path rect)                  ren _   = loadIMG ren path rect
42 |
43 | loadPicture (Pixel       coordinate   color)               ren _   = pixel             ren coordinate color
44 | loadPicture (ThickLine   start  end   color   thick)       ren _   = thickLine         ren start end color thick
45 | loadPicture (Line        start  end   color)               ren _   = aaline            ren start end color
46 | loadPicture (Rectangle   rect   color True)                ren _   = filledRect        ren rect   color
47 | loadPicture (Rectangle   rect   color False)               ren _   = rectangle         ren rect   color
48 | loadPicture (R_Rectangle rect   color True   rad)          ren _   = roundedFilledRect ren rect   color rad
49 | loadPicture (R_Rectangle rect   color False  rad)          ren _   = roundedRect       ren rect   color rad
50 | loadPicture (Circle      center color True   rad)          ren _   = filledCircle      ren center color rad
51 | loadPicture (Circle      center color False  rad)          ren _   = aaCircle          ren center color rad
52 | loadPicture (ThickCircle center color rad thick)           ren _   = thickCircle       ren center color rad thick
53 | loadPicture (Arc         center color rad start end)       ren _   = arc               ren center color rad start end
54 | loadPicture (Pie         center color rad start end True)  ren _   = filledPie         ren center color rad start end
55 | loadPicture (Pie         center color rad start end False) ren _   = pie               ren center color rad start end
56 | loadPicture (Ellipse     center rx ry color    True)       ren _   = filledEllipse     ren center rx ry color
57 | loadPicture (Ellipse     center rx ry color   False)       ren _   = aaellipse         ren center rx ry color
58 | loadPicture (Trigon      p1  p2 p3    color    True)       ren _   = filledTrigon      ren p1  p2 p3 color
59 | loadPicture (Trigon      p1  p2 p3    color   False)       ren _   = aatrigon          ren p1  p2 p3 color
60 |
61 | loadPicture (Polygon Nil      _    _)                      _   _   = pure ()
62 | loadPicture (Polygon (p::ps) color False)                  ren win = polygon ren p (p::ps) color
63 |   where polygon : Renderer -> Coordinate -> List Coordinate -> Color -> IO ()
64 |         polygon       ren   fp (p1::p2::ps) color            = do
65 |           loadPicture (Line p1  p2          color) ren win
66 |           polygon     ren   fp (p2::ps)     color
67 |         polygon       ren   fp [pn]         color            = loadPicture (Line pn fp color) ren win
68 |         polygon       _     _  []           _                = pure ()
69 | loadPicture (Polygon (p::ps) color True)             ren win = polygon ren p p (p::ps) color
70 |   where polygon : Renderer -> Coordinate -> Coordinate -> List Coordinate -> Color -> IO ()
71 |         polygon       ren     fp lp (p1::p2::ps) color       = do      -- FIXME: unexpected line color while alpha (rgba) is less than 255
72 |           loadPicture (Trigon fp p1  p2          color True) ren win
73 |           polygon     ren     fp p1 (p2::ps)     color
74 |         polygon       _       _  _   _           _           = pure ()
75 |
76 | loadPicture (Text        text size font p color)                               ren _ =
77 |   drawText           ren text size font p color
78 | loadPicture (SolidText   text size font p color         style hinting kerning) ren _ =
79 |   drawSolidText      ren text size font style kerning hinting p color
80 | loadPicture (BlendedText text size font p color         style hinting kerning) ren _ =
81 |   drawBlendedText    ren text size font style kerning hinting p color
82 | loadPicture (ShadedText  text size font p color1 color2 style hinting kerning) ren _ =
83 |   drawShadedText     ren text size font style kerning hinting p color1 color2
84 |