aboutsummaryrefslogtreecommitdiff
path: root/osrgn.icl
blob: 9af1a2412ec10fca2e65f9480843bdc292497016 (plain) (blame)
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
implementation module osrgn

import	StdBool, StdInt, StdList
from	ostypes import :: OSRect{..}
import	pictCCall_12, rgnCCall_12

::	OSRgnHandle
	:==	Int
::	OSPointH
	:==	Int

//	Region creation and disposal operations.
osnewrgn :: !*OSToolbox -> (!OSRgnHandle,!*OSToolbox)
osnewrgn tb
	= winCreateRectRgn 0 0 1 1 tb

osnewrectrgn :: !OSRect !*OSToolbox -> (!OSRgnHandle,!*OSToolbox)
osnewrectrgn {rleft,rtop,rright,rbottom} tb
	= winCreateRectRgn rleft rtop rright rbottom tb

osdisposergn :: !OSRgnHandle !*OSToolbox -> *OSToolbox
osdisposergn osrgn tb
	= winDeleteObject osrgn tb


//	Setting the shape of a Region.
osrectrgn :: !OSRect !OSRgnHandle !*OSToolbox -> (!OSRgnHandle,!*OSToolbox)
osrectrgn {rleft,rtop,rright,rbottom} osrgn tb
	= winSetRgnToRect rleft rtop rright rbottom osrgn tb

ospolyrgn :: !(!Int,!Int) ![(Int,Int)] !OSRgnHandle !*OSToolbox -> (!OSRgnHandle,!*OSToolbox)
ospolyrgn base shape osrgn tb
	# (osrgn,tb)		= winCombineRgn osrgn osrgn osrgn RGN_DIFF tb
	| len==0
		= (osrgn,tb)
	| otherwise
		# (shapeH,tb)	= winAllocPolyShape len tb
		# tb			= setpolyshape shapeH 0 base shape tb
		# (prgn,tb)		= winCreatePolygonRgn shapeH len WINDING tb
		# (osrgn,tb)	= winCombineRgn osrgn prgn prgn RGN_COPY tb
		# tb			= winDeleteObject prgn tb
		# tb			= winFreePolyShape shapeH tb
		= (osrgn,tb)
where
	len					= length shape
	
	setpolyshape :: !OSPointH !Int !(!Int,!Int) ![(Int,Int)] !*OSToolbox -> *OSToolbox
	setpolyshape shapeH i (x,y) [(vx,vy):vs] tb
		# tb	= winSetPolyPoint i x y shapeH tb
		# tb	= setpolyshape shapeH (i+1) (x+vx,y+vy) vs tb
		= tb
	setpolyshape _ _ _ _ tb
		= tb


//	Combining the shapes of two Regions into a new Region.
ossectrgn :: !OSRgnHandle !OSRgnHandle !*OSToolbox -> (!OSRgnHandle,!*OSToolbox)
ossectrgn rgn1 rgn2 tb
	# (rrgn,tb)	= winCreateRectRgn 0 0 1 1 tb
	# (rrgn,tb)	= winCombineRgn rrgn rgn1 rgn2 RGN_AND tb
	= (rrgn,tb)

osunionrgn :: !OSRgnHandle !OSRgnHandle !*OSToolbox -> (!OSRgnHandle,!*OSToolbox)
osunionrgn rgn1 rgn2 tb
	# (rrgn,tb)	= winCreateRectRgn 0 0 1 1 tb
	# (rrgn,tb)	= winCombineRgn rrgn rgn1 rgn2 RGN_OR tb
	= (rrgn,tb)

osdiffrgn :: !OSRgnHandle !OSRgnHandle !*OSToolbox -> (!OSRgnHandle,!*OSToolbox)
osdiffrgn rgn1 rgn2 tb
	# (rrgn,tb)	= winCreateRectRgn 0 0 1 1 tb
	# (rrgn,tb)	= winCombineRgn rrgn rgn1 rgn2 RGN_DIFF tb
	= (rrgn,tb)


//	Region property access functions.
osgetrgnbox	:: !OSRgnHandle !*OSToolbox -> (!Bool,!OSRect,!*OSToolbox)
osgetrgnbox rgn tb
	# (l,t, r,b, isRect,_,tb)	= winGetRgnBox rgn tb
	= (isRect,{rleft=l,rtop=t,rright=r,rbottom=b}, tb)

osisemptyrgn:: !OSRgnHandle !*OSToolbox -> (!Bool,!*OSToolbox)
osisemptyrgn rgn tb
	# (_,_,_,_,_,isempty,tb)	= winGetRgnBox rgn tb
	= (isempty,tb)