-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUSBITMAP.PAS
139 lines (118 loc) · 3.1 KB
/
USBITMAP.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
{
usbitmap Unit
A subbitmap is a portion of another bitmap, like a window into it
2022 LRT
}
unit
usbitmap;
interface
uses
consts, utils, uexc, uclasses, types, locale, uobject, ubitmap;
type
PSubBitmap = ^TSubBitmap;
TSubBitmap = object (TBitmap)
public
constructor initWithBitmap(bitmap: PBitmap; width, height: word);
constructor initWithSize(width, height: word);
destructor done; virtual;
procedure setPixel(x, y: word; color: TColor); virtual;
procedure clear(color: TColor); virtual;
function getPixel(x, y: word): TColor; virtual;
function getColorCount: longint; virtual;
function getBitsPerPixel: byte; virtual;
procedure move(x, y: word);
procedure rmove(x, y: integer);
procedure setBitmap(bitmap: PBitmap);
function getClassName: string; virtual;
function getClassId: word; virtual;
private
_bitmap: PBitmap;
_x, _y: word;
_bmWidth, _bmHeight: word;
end;
implementation
{ TSubBitmap public }
constructor TSubBitmap.initWithBitmap(bitmap: PBitmap; width, height: word);
begin
inherited initWithSize(width, height);
_bitmap := nil;
setBitmap(bitmap);
_x := 0;
_y := 0;
end;
constructor TSubBitmap.initWithSize(width, height: word);
begin
inherited initWithSize(width, height);
_bitmap := nil;
_x := 0;
_y := 0;
end;
destructor TSubBitmap.done;
begin
if _bitmap <> nil then _bitmap^.release;
inherited done;
end;
procedure TSubBitmap.setPixel(x, y: word; color: TColor);
var
px, py: word;
begin
px := _x + x;
py := _y + y;
if (px >= _bmWidth) or (py >= _bmHeight) then exit;
_bitmap^.setPixel(px, py, color);
end;
procedure TSubBitmap.clear(color: TColor);
begin
end;
function TSubBitmap.getPixel(x, y: word): TColor;
var
px, py: word;
begin
px := _x + x;
py := _y + y;
if (px >= _bmWidth) or (py >= _bmHeight) then
getPixel := 0
else
getPixel := _bitmap^.getPixel(px, py);
end;
function TSubBitmap.getColorCount: longint;
begin
getColorCount := _bitmap^.getColorCount;
end;
function TSubBitmap.getBitsPerPixel: byte;
begin
getBitsPerPixel := _bitmap^.getBitsPerPixel;
end;
procedure TSubBitmap.move(x, y: word);
begin
_x := x;
_y := y;
end;
procedure TSubBitmap.rmove(x, y: integer);
var
ix, iy: word;
begin
ix := _x + x;
iy := _y + y;
if ix < 0 then _x := 0 else _x := ix;
if iy < 0 then _y := 0 else _y := iy;
end;
procedure TSubBitmap.setBitmap(bitmap: PBitmap);
begin
if _bitmap <> nil then _bitmap^.release;
_bitmap := bitmap;
_bitmap^.retain;
_bmWidth := _bitmap^.getWidth;
_bmHeight := _bitmap^.getHeight;
end;
function TSubBitmap.getClassName: string;
begin
getClassName := 'TSubBitmap';
end;
function TSubBitmap.getClassId: word;
begin
getClassId := C_CLASS_ID_SubBitmap;
end;
{ TSubBitmap private }
{ Other }
end.