File: GraphicsPen.hs

package info (click to toggle)
hugs 1.4.199801-1
  • links: PTS
  • area: non-free
  • in suites: slink
  • size: 7,220 kB
  • ctags: 5,609
  • sloc: ansic: 32,083; haskell: 12,143; yacc: 949; perl: 823; sh: 602; makefile: 236
file content (60 lines) | stat: -rw-r--r-- 1,652 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
module GraphicsPen(
	Style(..),
	Pen,
	mkPen, withPen,
	createPen, deletePen
	) where

import GraphicsTypes
import GraphicsUtilities( bracket, bracket_ )
import qualified Win32

----------------------------------------------------------------
-- The interface
----------------------------------------------------------------

newtype Pen = Pen Win32.HPEN

data Style
  = Solid 
  | Dash	  -- "-------"
  | Dot		  -- "......."	
  | DashDot	  -- "_._._._"	
  | DashDotDot	  -- "_.._.._"	
  | Null
  | InsideFrame

withPen   :: Pen -> Picture -> Picture
mkPen     :: Style -> Int -> RGB -> (Pen -> Picture) -> Picture
createPen :: Style -> Int -> RGB -> IO Pen
deletePen :: Pen -> IO ()

----------------------------------------------------------------
-- The implementation
----------------------------------------------------------------

style :: Style -> Win32.PenStyle
style Solid       = Win32.pS_SOLID       
style Dash	  = Win32.pS_DASH        
style Dot	  = Win32.pS_DOT         
style DashDot	  = Win32.pS_DASHDOT     
style DashDotDot  = Win32.pS_DASHDOTDOT  
style Null	  = Win32.pS_NULL        
style InsideFrame = Win32.pS_INSIDEFRAME 

mkPen sty width c p = \ hdc -> 
  bracket (createPen sty width c) deletePen $ \ pen -> 
  p pen hdc

withPen (Pen pen) p = \ hdc ->
  bracket_ (Win32.selectPen hdc pen) (Win32.selectPen hdc) (p hdc)

createPen sty width (RGB r g b) = 
  Win32.createPen (style sty) (fromInt width) (Win32.rgb r g b) >>= return . Pen

deletePen (Pen pen) = 
  Win32.deletePen pen

----------------------------------------------------------------
-- The end
----------------------------------------------------------------