File: GraphicsBrush.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 (49 lines) | stat: -rw-r--r-- 1,453 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
module GraphicsBrush(
	Brush,
	mkBrush, withBrush,
	createBrush, deleteBrush
	-- blackBrush, whiteBrush,
	) where

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

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

newtype Brush = MkBrush Win32.HBRUSH

mkBrush     :: RGB   -> (Brush -> Picture) -> Picture
withBrush   :: Brush -> Picture -> Picture

createBrush :: RGB   -> IO Brush
deleteBrush :: Brush -> IO ()

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

createBrush (RGB r g b) = 
  Win32.createSolidBrush (Win32.rgb r g b) >>= return . MkBrush
deleteBrush (MkBrush b) = 
  Win32.deleteBrush b

mkBrush rgb p = \ hdc ->
  bracket (createBrush rgb) deleteBrush $ \ brush ->
  p brush hdc

withBrush (MkBrush brush) p = \ hdc ->
   bracket_ (Win32.selectBrush hdc brush) (Win32.selectBrush hdc) (p hdc)

----------------------------------------------------------------
-- 
-- -- special cases - these should _never_ be deleted
-- blackBrush :: IO Brush
-- whiteBrush :: IO Brush
-- 
-- blackBrush = Win32.getStockBrush Win32.bLACK_BRUSH >>= return . MkBrush
-- whiteBrush = Win32.getStockBrush Win32.wHITE_BRUSH >>= return . MkBrush
-- 
----------------------------------------------------------------