forked from dim-s/soulengine
-
Notifications
You must be signed in to change notification settings - Fork 2
/
mdsUtils.pas
148 lines (125 loc) · 3.58 KB
/
mdsUtils.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
unit mdsUtils;
interface
uses Windows, Messages, SysUtils, Classes, Graphics, ZendTypes, ImgList, CommCtrl;
function Min(A, B: longint): longint;
function Max(A, B: longint): longint;
function BtnHighlight: TColor;
function GetLightColor(Color: TColor; Light: byte): TColor;
function GetShadeColor(Color: TColor; Shade: byte): TColor;
procedure GetBmpFromImgList(ABmp: TBitmap; AImgList: TCustomImageList;
ImageIndex: integer);
procedure DrawMonoBmp(ACanvas: TCanvas; MonoBmp: TBitmap;
AMonoColor: TColor; ALeft, ATop: integer);
procedure DoDrawMonoBmp(ACanvas: TCanvas; AMonoColor: TColor;
ALeft, ATop: integer);
function AddSlashes(const S: string): string;
function AddSlashesA(const S: zend_ustr): zend_ustr;
var
FMonoBitmap: TBitmap;
implementation
type
TRGB = packed record
R, G, B: byte;
end;
function AddSlashes(const S: string): string;
begin
Result := StringReplace(S, '\', '\\', [rfReplaceAll]);
Result := StringReplace(Result, '''', '\''', [rfReplaceAll]);
Result := StringReplace(Result, '<?', '''."<".chr(' + IntToStr(Ord('?')) +
').''', [rfReplaceAll]);
end;
function AddSlashesA(const S: zend_ustr): zend_ustr;
begin
Result := zend_ustr(StringReplace(
StringReplace(
StringReplace(String(S), '\', '\\', [rfReplaceAll])
, '''', '\''', [rfReplaceAll]), '<?', '''."<".chr(' + IntToStr(Ord('?')) +
').''', [rfReplaceAll]));
end;
function Min(A, B: longint): longint;
begin
if A < B then
Result := A
else
Result := B;
end;
function Max(A, B: longint): longint;
begin
if A < B then
Result := B
else
Result := A;
end;
function GetRGB(Color: TColor): TRGB;
var
iColor: TColor;
begin
iColor := ColorToRGB(Color);
Result.R := GetRValue(iColor);
Result.G := GetGValue(iColor);
Result.B := GetBValue(iColor);
end;
function BtnHighlight: TColor;
begin
Result := GetLightColor(clBtnFace, 50);
end;
function GetLightColor(Color: TColor; Light: byte): TColor;
var
fFrom: TRGB;
begin
FFrom := GetRGB(Color);
Result := RGB(Round(FFrom.R + (255 - FFrom.R) * (Light / 100)),
Round(FFrom.G + (255 - FFrom.G) * (Light / 100)),
Round(FFrom.B + (255 - FFrom.B) * (Light / 100)));
end;
function GetShadeColor(Color: TColor; Shade: byte): TColor;
var
fFrom: TRGB;
begin
FFrom := GetRGB(Color);
Result := RGB(Max(0, FFrom.R - Shade), Max(0, FFrom.G - Shade),
Max(0, FFrom.B - Shade));
end;
procedure GetBmpFromImgList(ABmp: TBitmap; AImgList: TCustomImageList;
ImageIndex: integer);
begin
with ABmp do
begin
Width := AImgList.Width;
Height := AImgList.Height;
Canvas.Brush.Color := clWhite;
Canvas.FillRect(Rect(0, 0, Width, Height));
ImageList_DrawEx(AImgList.Handle, ImageIndex,
Canvas.Handle, 0, 0, 0, 0, CLR_DEFAULT, 0, ILD_NORMAL);
end;
end;
procedure DrawMonoBmp(ACanvas: TCanvas; MonoBmp: TBitmap;
AMonoColor: TColor; ALeft, ATop: integer);
const
ROP_DSPDxax = $00E20746;
{<-- ñêîïèðîâàíî èç ImgList.TCustomImageList.DoDraw()}
var
crBack, crText: TColorRef;
begin
with ACanvas do
begin
Brush.Color := AMonoColor;
crText := Windows.SetTextColor(Handle, clWhite);
crBack := Windows.SetBkColor(Handle, clBlack);
BitBlt(Handle, ALeft, ATop, MonoBmp.Width, MonoBmp.Height,
MonoBmp.Canvas.Handle, 0, 0, ROP_DSPDxax);
Windows.SetTextColor(Handle, crText);
Windows.SetBkColor(Handle, crBack);
end;
end;
procedure DoDrawMonoBmp(ACanvas: TCanvas; AMonoColor: TColor;
ALeft, ATop: integer);
begin
DrawMonoBmp(ACanvas, FMonoBitmap, AMonoColor, ALeft, ATop);
end;
initialization
FMonoBitmap := TBitmap.Create;
FMonoBitmap.Monochrome := True;
finalization
FMonoBitmap.Free;
end.