Fixed allSelectorsSent because a simpler implementation was overriding the original.
[cslatevm.git] / src / ui / form.slate
bloba6cc1b82d7d075b2662cb4e4845f4d7b0f0d89ae
1 "A bitmap image - analogous to Smalltalks Form"
2 "The Utah Raster Toolkit has some example code for handling the fact
3 that the composition operators work on channel values of 0-1 and the
4 bitmaps use 0-0xFF."
5 "The colour channels in Forms are premultiplied by the alpha"
6 "They're stored as 0-0xFF octets in a ByteArray"
7 "TODO: The storage should be dependant on the type of Form"
8 "TODO: 32 & 24 bit Forms should use Word32Arrays (or whatever)"
9 "TODO: Sort out Forms with other than 8bits per channel"
11 "Bitmaps have a platform independant format"
12 Graphics define: #Bitmap &parents: {WordArray BigEndian} &slots: {
13   #memory -> MemoryArea.
16 w@(Bitmap traits) new &capacity: size
18   w newFrom: (w memory newSize: (size * 4) abs) enable &bytesPerWord: 4
21 w@(Bitmap traits) enable
22 [w memory enable].
24 w@(Bitmap traits) disable
25 [w memory disable].
27 "Graphics define: #Pixmap &parents: {WordArray}."
29 Graphics define: #Form &parents: {Cloneable} &slots: {
30   #width -> 0. #height -> 0.
31   #depth -> 0. #repeat -> 0.
32   #offset -> Point origin. "Centre of the Form"
33   #clipRect -> (Rectangle origin: Point origin extent: Point origin).
34   #colorMap. "ColorMap used to write into this Form"
35   #bits -> Bitmap.
38 "Forms mostly intended for masks and alpha channels"
39 "Graphics define: #FormAlpha8 &parents: {Form}."
40 "Graphics define: #FormAlpha1 &parents: {Form}."
42 f@(Form traits) extent: extent@(Point traits) depth: bitsPerPixel
43 "Creates a new blank Form with size extent and depth bitsPerPixel"
45   "TODO: should be 'f copy', but copy is currently broken. Fix copy."
46   Form copy `>> [setExtent: extent depth: bitsPerPixel. ]
49 a@(Form traits) bits: w@(Bitmap traits)
51   (a bits isSameAs: w)
52     ifTrue: [a bits disable].
53   a atSlotNamed: #bits := w
56 a@(Form traits) setExtent: extent@(Point traits) depth: bitsPerPixel
58  a close.
59  a width := extent x as: Integer.
60  a height := extent y as: Integer.
61  a depth := bitsPerPixel.
62  a bits := a bits new &capacity: a bitSize.
63  a
66 a@(Form traits) close
68   a bits ifNotNil: [a bits close. a bits := Nil]
71 a@(Form traits) bitSize
72 "Size of needed Bitmap"
73 [| pixelsPerWord |
74   a depth `defaultsTo: 1.
75   pixelsPerWord := 32 // a depth.
76   a width + pixelsPerWord - 1 // pixelsPerWord * a height
77 ].  
79 a@(Form traits) extent 
80 [a width <> a height].