-
Notifications
You must be signed in to change notification settings - Fork 4
/
wmouse.pas
294 lines (257 loc) · 7.69 KB
/
wmouse.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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
unit wmouse;
{$mode objfpc}
interface
uses
Classes, SysUtils,LazFileUtils,rmxgfcore,rwxgf,gwbasic;
Function WriteMShapeToCode(x,y,LanType,imageid : word;filename:string):word;
Function WriteMShapeToFile(x,y : word;filename:string):word;
function GetMouseShapeSize : longint;
Function WriteMShapeCodeToBuffer(var data :BufferRec;x,y,Lan,imageId : word; imagename:string):word;
Function WriteMShapeToBuffer(x,y : word;var F : File):word;
implementation
type
MouseShapeType = array[1..32] of Word;
function GetMouseShapeSize : longint;
begin
GetMouseShapeSize:=sizeof(MouseShapeType);
end;
function bin2dec (s : string) : longint;
var
tmp : longint;
p : byte;
begin
tmp := 0;
for p := 1 to length(s) do
begin
inc(tmp,longint(ord(s[length(s)])-48) shl pred(p));
dec(s[0]);
end;
bin2dec := tmp;
end;
//the width and height will always 16x16 - we just need the starting x,y cords
Procedure CreateMouseShape(x,y : integer; Var MouseShape : MouseShapeType);
Var
i,j : integer;
MImage,MMask : String[16];
count : integer;
pixColor : integer;
begin
count:=1;
For j:=1 to 16 do
begin
MImage :='1111111111111111';
MMask :='0000000000000000';
For i:=1 to 16 do
begin
pixColor:=GetPixel(x+i-1,y+j-1);
If pixColor = 0 then // 0 is black
begin
MImage[i]:='0';
MMask[i]:='0';
end
else if pixColor=3 then //3 is white
begin
MImage[i]:='0';
MMask[i]:='1';
end
else if pixColor=2 then // 2 pink / tranparent
begin
MImage[i]:='1';
MMask[i]:='0';
end
else
begin // 1 is cyan XOR the bits on this part of the mouse shape
MImage[i]:='1';
MMask[i]:='1';
end;
end;
MouseShape[Count]:=Bin2Dec(MImage);
MouseShape[Count+16]:=Bin2Dec(MMask);
Inc(count);
end;
end;
Function GetMouseShapeLineStr(x, y : word) : string;
var
pixColor : integer;
TextImage : String[16];
i : integer;
begin
TextImage:=' ';
for i:=1 to 16 do
begin
pixColor:=GetPixel(x+i-1,y);
If pixColor = 0 then // 0 is black
begin
TextImage[i]:='*';
end
else if pixColor=3 then //3 is white
begin
TextImage[i]:='#';
end
else if pixColor=2 then // 2 pink / tranparent
begin
TextImage[i]:=' ';
end
else
begin // 1 is cyan XOR the bits on this part of the mouse shape
TextImage[i]:='X';
end;
end;
GetMouseShapeLineStr:=TextImage;
end;
Function WriteBasicMShapeCodeToBuffer(var data :BufferRec;x,y,Lan : word; imagename:string):word;
var
Size : longword;
BWriter : BitPlaneWriterProc;
MShape : MouseShapeType;
MSData : array[1..64] of byte;
i : integer;
begin
CreateMouseShape(x,y,MShape);
if Lan = GWLan then BWriter:=@BitplaneWriterGWBasicCode else BWriter:=@BitplaneWriterBasicCode;
Size:=GetMouseShapeSize;
{$I-}
BWriter(0,data,0); //init the data record
data.ArraySize:=size;
for i:=0 to 15 do
begin
writeln(data.ftext,LineCountToStr(Lan),#39,' ',GetMouseShapeLineStr(x,y+i));
end;
writeln(data.ftext,LineCountToStr(Lan),#39,' BASIC, Size= ', Size div 2,' Width= 16 Height= 16');
writeln(data.ftext,LineCountToStr(Lan),#39,' DOS Mouse Shape ');
writeln(data.ftext,LineCountToStr(Lan),#39,' ',Imagename);
Move(MShape,MSData,sizeof(MSData));
for i:=1 to 64 do
begin
BWriter(MSData[i],data,1);
end;
BWriter(0,data,2); //flush it
// writeln(data.ftext);
{$I+}
WriteBasicMShapeCodeToBuffer:=IORESULT;
end;
Function WritePascalMShapeCodeToBuffer(var data :BufferRec;x,y,Lan,imageId : word; imagename:string):word;
var
Size : longword;
BWriter : BitPlaneWriterProc;
MShape : MouseShapeType;
MSData : array[1..64] of byte;
i : integer;
begin
CreateMouseShape(x,y,MShape);
BWriter:=@BitplaneWriterPascalCode;
Size:=GetMouseShapeSize;
{$I-}
BWriter(0,data,0); //init the data record
data.ArraySize:=size;
for i:=0 to 15 do
begin
writeln(data.ftext,'(* ',GetMouseShapeLineStr(x,y+i),' *)');
end;
writeln(data.ftext,'(*',' Pascal, Size= ', Size ,' Width= 16 Height= 16 ','*)');
writeln(data.ftext,'(*',' DOS Mouse Shape ','*)');
writeln(data.ftext,' ',Imagename,'_Size = ',size,';');
writeln(data.ftext,' ',Imagename,'_Width = 16',';');
writeln(data.ftext,' ',Imagename,'_Height = 16',';');
writeln(data.ftext,' ',Imagename,'_Colors = 4',';');
writeln(data.ftext,' ',Imagename,'_Id = ',imageId,';');
writeln(data.ftext,' ',Imagename, ' : array[0..',size-1,'] of byte = (');
Move(MShape,MSData,sizeof(MSData));
for i:=1 to 64 do
begin
BWriter(MSData[i],data,1);
end;
BWriter(0,data,2); //flush it
// writeln(data.ftext);
{$I+}
WritePascalMShapeCodeToBuffer:=IORESULT;
end;
Function WriteCMShapeCodeToBuffer(var data :BufferRec;x,y,Lan,imageId : word; imagename:string):word;
var
Size : longword;
BWriter : BitPlaneWriterProc;
MShape : MouseShapeType;
MSData : array[1..64] of byte;
i : integer;
begin
CreateMouseShape(x,y,MShape);
BWriter:=@BitplaneWriterCCode;
Size:=GetMouseShapeSize;
{$I-}
BWriter(0,data,0); //init the data record
data.ArraySize:=size;
for i:=0 to 15 do
begin
writeln(data.ftext,'/* ',GetMouseShapeLineStr(x,y+i),' */');
end;
writeln(data.ftext,'/*',' C, Size= ', Size ,' Width= 16 Height= 16 ','*/');
writeln(data.ftext,'/*',' DOS Mouse Shape ','*/');
writeln(data.ftext,' #define ',Imagename,'_Size ',size);
writeln(data.ftext,' #define ',Imagename,'_Width ',16);
writeln(data.ftext,' #define ',Imagename,'_Height ',16);
writeln(data.ftext,' #define ',Imagename,'_Colors ',4);
Writeln(data.ftext,' #define ',ImageName,'_Id ',imageId);
writeln(data.ftext,' ','char ',Imagename, '[',size,'] = {');
Move(MShape,MSData,sizeof(MSData));
for i:=1 to 64 do
begin
BWriter(MSData[i],data,1);
end;
BWriter(0,data,2); //flush it
// writeln(data.ftext);
{$I+}
WriteCMShapeCodeToBuffer:=IORESULT;
end;
Function WriteMShapeCodeToBuffer(var data :BufferRec;x,y,Lan,imageId : word; imagename:string):word;
begin
case Lan of TPLan,QPLan,FPLan: WriteMShapeCodeToBuffer:=WritePascalMShapeCodeToBuffer(data,x,y,Lan,Imageid,imagename);
TCLan,QCLan: WriteMShapeCodeToBuffer:=WriteCMShapeCodeToBuffer(data,x,y,Lan,imageId,imagename);
GWLan,QBLan,FBinQBModeLan,PBLan: WriteMShapeCodeToBuffer:=WriteBasicMShapeCodeToBuffer(data,x,y,Lan,imagename);
end;
end;
//write a single file
Function WriteMShapeToCode(x,y,LanType,imageId : word;filename:string):word;
var
data : BufferRec;
imagename : String;
begin
SetCoreActive; // we are getting data from core object RMCoreBase
SetGWStartLineNumber(1000);
assign(data.fText,filename);
{$I-}
rewrite(data.fText);
Imagename:=ExtractFileName(ExtractFileNameWithoutExt(filename));
case LanType of
TPLan,QPLan,FPLan: WritePascalMShapeCodeToBuffer(data,x,y,LanType,imageid,imagename);
TCLan,QCLan: WriteCMShapeCodeToBuffer(data,x,y,LanType,imageid,imagename);
GWLan,QBLan,FBinQBModeLan,PBLan: WriteBasicMShapeCodeToBuffer(data,x,y,LanType,imagename);
end;
close(data.fText);
{$I+}
WriteMShapeToCode:=IOResult;
end;
Function WriteMShapeToBuffer(x,y : word;var F : File):word;
var
MShape : MouseShapeType;
begin
CreateMouseShape(x,y,MShape);
{$I-}
Blockwrite(F,MShape,sizeof(MShape));
{$I+}
WriteMShapeToBuffer:=IOResult;
end;
Function WriteMShapeToFile(x,y : word;filename:string):word;
var
F : File;
MShape : MouseShapeType;
begin
CreateMouseShape(x,y,MShape);
Assign(F,filename);
{$I-}
Rewrite(F,1);
Blockwrite(F,MShape,sizeof(MShape));
Close(F);
{$I+}
WriteMShapeToFile:=IOResult;
end;
end.