-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUBMLAYER.PAS
149 lines (126 loc) · 3.29 KB
/
UBMLAYER.PAS
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
{
ubmlayer Unit
A layer is used to represent a bitmap within the context of a composition
2022 LRT
}
unit
ubmlayer;
interface
uses
consts, utils, uexc, uclasses, types, locale, uobject, ubitmap;
const
C_DEFAULT_TRANSPARENT_COLOR = 0;
type
PBitmapLayer = ^TBitmapLayer;
TBitmapLayer = object (TObject)
public
constructor initWithBitmap(bitmap: PBitmap);
destructor done; virtual;
procedure setPosition(x, y: integer);
procedure getPosition(var x, y: integer);
procedure setChanged(value: boolean);
procedure setHidden(value: boolean);
procedure setTransparent(state: boolean; color: TColor);
function getBitmap: PBitmap;
function getPixel(absX, absY: word): TColor;
function isValidPixel(absX, absY: word): boolean;
function isHidden: boolean;
function isChanged: boolean;
function getClassName: string; virtual;
function getClassId: word; virtual;
private
_bitmap: PBitmap;
_x, _y: integer;
_w, _h: word;
_hidden: boolean;
_changed: boolean;
_transparentColor: TColor;
_isTransparent: boolean;
end;
implementation
{ TBitmapLayer public }
constructor TBitmapLayer.initWithBitmap(bitmap: PBitmap);
begin
inherited init;
_bitmap := bitmap;
_bitmap^.retain;
_x := 0;
_y := 0;
_w := bitmap^.getWidth;
_h := bitmap^.getHeight;
_changed := false;
_hidden := false;
_transparentColor := C_DEFAULT_TRANSPARENT_COLOR;
_isTransparent := false;
end;
destructor TBitmapLayer.done;
begin
_bitmap^.release;
inherited done;
end;
procedure TBitmapLayer.setPosition(x, y: integer);
begin
_x := x;
_y := y;
end;
procedure TBitmapLayer.getPosition(var x, y: integer);
begin
x := _x;
y := _y;
end;
procedure TBitmapLayer.setChanged(value: boolean);
begin
_changed := value;
end;
procedure TBitmapLayer.setHidden(value: boolean);
begin
_hidden := value;
end;
function TBitmapLayer.isHidden: boolean;
begin
isHidden := _hidden;
end;
function TBitmapLayer.getBitmap: PBitmap;
begin
getBitmap := _bitmap;
end;
function TBitmapLayer.getPixel(absX, absY: word): TColor;
begin
getPixel := _bitmap^.getPixel(absX - _x, absY - _y);
end;
function TBitmapLayer.isValidPixel(absX, absY: word): boolean;
var
maxX, maxY: integer;
x, y: word;
begin
x := absX - _x;
y := absY - _y;
maxX := _x + _w - 1;
maxY := _y + _h - 1;
isValidPixel :=
(not _isTransparent or (_bitmap^.getPixel(x, y) <> _transparentColor)) and
(absX >= _x) and
(absX <= maxX) and
(absY >= _y) and
(absY <= maxY);
end;
function TBitmapLayer.isChanged: boolean;
begin
isChanged := _changed;
end;
procedure TBitmapLayer.setTransparent(state: boolean; color: TColor);
begin
_isTransparent := state;
_transparentColor := color;
end;
function TBitmapLayer.getClassName: string;
begin
getClassName := 'TBitmapLayer';
end;
function TBitmapLayer.getClassId: word;
begin
getClassId := C_CLASS_ID_BitmapLayer;
end;
{ TBitmapLayer private }
{ Other }
end.