/
JvgUtils.pas
2218 lines (2008 loc) · 63.7 KB
/
JvgUtils.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
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
{-----------------------------------------------------------------------------
The contents of this file are subject to the Mozilla Public License
Version 1.1 (the "License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL/MPL-1.1.html
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either expressed or implied. See the License for
the specific language governing rights and limitations under the License.
The Original Code is: JvgUtils.PAS, released on 2003-01-15.
The Initial Developer of the Original Code is Andrey V. Chudin, [chudin@yandex.ru]
Portions created by Andrey V. Chudin are Copyright (C) 2003 Andrey V. Chudin.
All Rights Reserved.
Contributor(s):
Michael Beck [mbeck@bigfoot.com].
Last Modified: 2003-01-15
You may retrieve the latest version of this file at the Project JEDI's JVCL home page,
located at http://jvcl.sourceforge.net
Known Issues:
-----------------------------------------------------------------------------}
{$I JVCL.INC}
unit JvgUtils;
interface
uses Windows, Messages, Graphics, ExtCtrls, SysUtils, Classes, Controls, Forms,
JvgTypes, JvgCommClasses, Jvg3DColors, mmsystem;
function Min(i1, i2: integer): integer;
function Max(i1, i2: integer): integer;
function MinSingle(r1, r2: Single): Single;
function MaxSingle(r1, r2: Single): Single;
function IsEven(i: integer): boolean;
function SantimsToPixels(DC: HDC; Value: single; IsHosiz: boolean): integer;
procedure SwapInt(var i1, i2: integer);
function Spaces(count: integer): string;
function DupStr(const str: string; Count: integer): string;
function DupChar(C: Char; Count: integer): string;
procedure Msg(msg: string);
function IsPointInRect(P: TPoint; R: TRect): boolean;
function RectW(R: TRect): integer;
function RectH(R: TRect): integer;
function IncColor(lColor: LongInt; bOffset: byte): LongInt;
function DecColor(lColor: LongInt; bOffset: byte): LongInt;
function IsItAFilledBitmap(Bmp: TBitmap): boolean;
procedure DrawTextInRectWithAlign(DC: HDC; r: TRect; Text: string;
HAlign: TglHorAlign; VAlign: TglVertAlign;
Style: TglTextStyle; Fnt: TFont;
FLAGS: UINT);
procedure DrawTextInRect(DC: HDC; r: TRect; Text: string;
Style: TglTextStyle; Fnt: TFont; FLAGS: UINT);
procedure ExtTextOutExt(DC: HDC;
x, y: integer;
r: TRect;
Text: string;
Style: TglTextStyle;
fDelineated, fSupress3D: boolean;
FontColor, DelinColor, HighlightColor, ShadowColor: TColor;
Illumination: TJvgIllumination;
Gradient: TJvgGradient;
Font: TFont);
procedure DrawBox(DC: HDC; var r: TRect; Style: TglBoxStyle;
BackgrColor: LongInt; fTransparent: boolean);
function DrawBoxEx(DC: HDC; rect: TRect; Borders: TglSides;
BevelInner, BevelOuter: TPanelBevel;
Bold: boolean; BackgrColor: LongInt;
fTransparent: boolean): TRect;
procedure GradientBox(DC: HDC; r: TRect; Gradient: TJvgGradient;
PenStyle, PenWidth: integer);
procedure ChangeBitmapColor(Bitmap: TBitmap;
FromColor, ToColor: TColor);
procedure DrawBitmapExt(DC: HDC; { DC - background & result}
SourceBitmap: TBitmap;
r: TRect;
x, y: integer; //...x,y _in_ rect!
BitmapOption: TglWallpaperOption;
DrawState: TglDrawState;
fTransparent: boolean;
TransparentColor: TColor;
DisabledMaskColor: TColor);
procedure CreateBitmapExt(DC: HDC; { DC - background & result}
SourceBitmap: TBitmap;
r: TRect;
x, y: integer; //...x,y _in_ rect!
BitmapOption: TglWallpaperOption;
DrawState: TglDrawState;
fTransparent: boolean;
TransparentColor: TColor;
DisabledMaskColor: TColor);
procedure BringParentWindowToTop(Wnd: TWinControl);
function GetParentForm(Control: TControl): TForm;
procedure GetWindowImageFrom(Control: TWinControl; X, Y: integer; fDrawSelf, fDrawChildWindows: boolean; DC: HDC);
procedure GetWindowImage(Control: TWinControl; fDrawSelf, fDrawChildWindows: boolean; DC: HDC);
procedure GetParentImageRect(Control: TControl; Rect: TRect; DC: HDC);
function CreateRotatedFont(F: TFont; Escapement: Integer): hFont;
function FindMainWindow(sWndClass, sWndTitle: string): HWND;
procedure CalcShadowAndHighlightColors(BaseColor: TColor; Colors: TJvgLabelColors);
function CalcMathString(sExpression: string): single;
function IIF(fExpression: boolean; IfTrue, IfFalse: variant): variant;
{$IFDEF COMPILER5_UP}overload;
{$ENDIF}
{$IFDEF COMPILER5_UP}function IIF(fExpression: boolean; const IfTrue, IfFalse: string): string; overload;
{$ENDIF}
function GetTransparentColor(Bitmap: TBitmap; AutoTrColor: TglAutoTransparentColor): TColor;
procedure TypeStringOnKeyboard(S: string);
//function NextStringGridCell( Grid: TStringGrid ): boolean;
procedure DrawTextExtAligned(Canvas: TCanvas; const Text: string; R: TRect; Alignment: TglAlignment; WordWrap: boolean);
procedure LoadComponentFromTextFile(Component: TComponent; FileName: string);
procedure SaveComponentToTextFile(Component: TComponent; FileName: string);
function ComponentToString(Component: TComponent): string;
procedure StringToComponent(Component: TComponent; const Value: string);
function PlayWaveResource(sResName: string): boolean;
function UserName: string;
function ComputerName: string;
function CreateIniFileName: string;
function ExpandString(const str: string; len: integer): string;
{$IFDEF COMPILER5_UP}
function Transliterate(const Str: string; RusToLat: boolean): string;
{$ENDIF}
function IsSmallFonts: boolean;
function SystemColorDepth: integer;
function GetFileType(const FileName: string): TglFileType;
function FindControlAtPt(Control: TWinControl; pt: TPoint; MinClass: TClass): TControl;
function StrPosExt(const Str1, Str2: PChar; Str2Len: DWORD): PChar; assembler;
{$IFDEF glDEBUG}
function DeleteObject(p1: HGDIOBJ): BOOL; stdcall;
{$ENDIF}
implementation
uses shlobj;
{ debug func }
{$IFDEF glDEBUG}
function DeleteObject(p1: HGDIOBJ): BOOL; stdcall;
begin
Result := Windows.DeleteObject(p1);
if Result = false then
raise Exception.Create('leak');
end;
{$ENDIF}
//_________________________________________________________________\\
function Min(i1, i2: integer): integer;
begin
if i1 < i2 then
Result := i1
else
Result := i2;
end;
function Max(i1, i2: integer): integer;
begin
if i1 > i2 then
Result := i1
else
Result := i2;
end;
function MinSingle(r1, r2: Single): Single;
begin
if r1 < r2 then
Result := r1
else
Result := r2;
end;
function MaxSingle(r1, r2: Single): Single;
begin
if r1 > r2 then
Result := r1
else
Result := r2;
end;
{ Ïðîâåðêà öåëîãî ÷èñëà íà ÷åòíîñòü }
function IsEven(i: integer): boolean;
begin
Result := i / 2 = i div 2;
end;
{ Îáìåí çíà÷åíèé }
procedure SwapInt(var i1, i2: integer);
var
i_: integer;
begin
i_ := i1;
i1 := i2;
i2 := i_;
end;
//_________________________________________________________________\\
{ Ñîçäàíèå ñòðîêè èç çàäàíîãî ÷èñëà ïðîáåëîâ }
function Spaces(Count: integer): string;
var
i: word;
begin
Result := ''; //if Count<=0 then exit;
for i := 1 to Count do
Result := Result + ' ';
end;
//_________________________________________________________________\\
{ Ñîçäàíèå ñòðîêè èç çàäàíîãî ÷èñëà ñèìâîëîâ }
function DupChar(C: Char; Count: integer): string;
var
i: word;
begin
Result := '';
for i := 1 to Count do
Result := Result + C;
end;
//_________________________________________________________________\\
{ Ñîçäàíèå ñòðîêè èç çàäàíîãî ÷èñëà ñòðîê }
function DupStr(const str: string; Count: integer): string;
var
i: word;
begin
Result := '';
for i := 1 to Count do
Result := Result + str;
end;
//_________________________________________________________________\\
{ Ìîäàëüíîå îêíî ñ èêîíêîé èíôîðìàöèè è îäíîé êíîïêîé ÎÊ }
procedure Msg(msg: string);
begin
MessageBox(Application.Handle, PChar(msg), '',
MB_APPLMODAL or MB_ICONINFORMATION or MB_OK);
end;
//_________________________________________________________________\\
{ Ïðîâåðêà âõîæäåíèÿ òî÷êè â ïðèìîóãîëüíèê. ãðàíèöû íå ñ÷èòàþòñÿ }
function IsPointInRect(P: TPoint; R: TRect): boolean;
begin
Result := (P.x > R.Left) and (P.x < R.Right) and (P.y > R.Top) and (P.y < R.Bottom);
end;
{ Äëèíà ïðèìîóãîëüíèêà }
function RectW(R: TRect): integer;
begin
Result := R.Right - R.Left;
end;
{ Âûñîòà ïðèìîóãîëüíèêà }
function RectH(R: TRect): integer;
begin
Result := R.Bottom - R.Top;
end;
//_________________________________________________________________\\
{ Óâåëè÷èâàåò ñîñòàâëÿþùèå öâåòà íà çàäàííîå ñìåùåíèå }
function IncColor(lColor: LongInt; bOffset: byte): LongInt;
var
R, G, B: byte;
begin
if lColor < 0 then lColor := GetSysColor(lColor and $FF);
R := min(255, GetRValue(lColor) + bOffset);
G := min(255, GetGValue(lColor) + bOffset);
B := min(255, GetBValue(lColor) + bOffset);
Result := RGB(R, G, B);
end;
//_________________________________________________________________\\
{ Óìåíüøàåò ñîñòàâëÿþùèå öâåòà íà çàäàííîå ñìåùåíèå }
function DecColor(lColor: LongInt; bOffset: byte): LongInt;
var
R, G, B: byte;
begin
if lColor < 0 then lColor := GetSysColor(lColor and $FF);
R := max(0, GetRValue(lColor) - bOffset);
G := max(0, GetGValue(lColor) - bOffset);
B := max(0, GetBValue(lColor) - bOffset);
Result := RGB(R, G, B);
end;
//_________________________________________________________________\\
{ Ïåðåâîäèò ñàíòèìåòðà â ïèêñåëè }
function SantimsToPixels(DC: HDC; Value: single; IsHosiz: boolean): integer;
const
LOGPIXELS: array[boolean] of integer = (LOGPIXELSY, LOGPIXELSX);
begin
Result := round(Value * GetDeviceCaps(DC, LOGPIXELS[IsHosiz]) * 1.541 * 2.54 / 10);
end;
//_________________________________________________________________\\
{ Ïðîâåðÿåò ñîçäàí ëè îáúåêè bitmap è èìååò ëè îí ðàçìåð }
function IsItAFilledBitmap(Bmp: TBitmap): boolean;
begin
with Bmp do
Result := Assigned(bmp) and (Width <> 0) and (Height <> 0);
end;
//_________________________________________________________________\\
{
Âûâîäèò òåêñò ñ âûðàâíèâàíèåì, ñ çàäàííûì ñòèëåì è çàäàíûì øðèôòîì.
DC - handle of canvas
HAlign, VAlign - Âûðàâíèâàíèå ïî øèðèíå è âûñîòå
Style - ñòèëü (âäàâëåííûé, ñ òåíüþ etc)
FLAGS - äîï. ïàðàìåòðû äëÿ Windows.DrawText
}
procedure DrawTextInRectWithAlign(DC: HDC; r: TRect; Text: string;
HAlign: TglHorAlign; VAlign: TglVertAlign;
Style: TglTextStyle; Fnt: TFont;
FLAGS: UINT);
begin
case HAlign of
fhaLeft: FLAGS := FLAGS or DT_LEFT;
fhaCenter: FLAGS := FLAGS or DT_CENTER;
fhaRight: FLAGS := FLAGS or DT_RIGHT;
end;
case VAlign of
fvaTop: FLAGS := FLAGS or DT_TOP;
fvaCenter: FLAGS := FLAGS or DT_VCENTER;
fvaBottom: FLAGS := FLAGS or DT_BOTTOM;
end;
DrawTextInRect(DC, r, Text, Style, Fnt, FLAGS);
end;
//_________________________________________________________________\\
{
Âûâîäèò òåêñò ñ âûðàâíèâàíèåì, ñ çàäàííûì ñòèëåì è çàäàíûì øðèôòîì.
DC - handle of canvas
Style - ñòèëü (âäàâëåííûé, ñ òåíüþ etc)
FLAGS - ïàðàìåòðû äëÿ Windows.DrawText
}
procedure DrawTextInRect(DC: HDC; r: TRect; Text: string; Style: TglTextStyle; Fnt: TFont; FLAGS: UINT);
var
iOldBkMode: integer;
OldFont: Windows.HFont;
FontColor: TColor;
ShadowColor_, HighlightColor_: TColor;
begin
if not Assigned(Fnt) then exit;
if FLAGS = 0 then FLAGS := DT_LEFT or DT_VCENTER or DT_SINGLELINE;
iOldBkMode := SetBkMode(DC, integer(Transparent));
FontColor := Fnt.Color;
ShadowColor_ := clBtnShadow;
HighlightColor_ := clBtnHighlight;
OldFont := SelectObject(DC, Fnt.Handle);
case Style of
fstRaised:
begin
SetTextColor(DC, ColorToRGB(HighlightColor_));
OffsetRect(r, -1, -1);
DrawText(DC, PChar(Text), length(Text), r, FLAGS);
SetTextColor(DC, ColorToRGB(ShadowColor_));
OffsetRect(r, 2, 2);
DrawText(DC, PChar(Text), length(Text), r, FLAGS);
SetTextColor(DC, ColorToRGB(FontColor));
OffsetRect(r, -1, -1);
DrawText(DC, PChar(Text), length(Text), r, FLAGS);
end;
fstRecessed:
begin
SetTextColor(DC, ColorToRGB(ShadowColor_));
OffsetRect(r, -1, -1);
DrawText(DC, PChar(Text), length(Text), r, FLAGS);
SetTextColor(DC, ColorToRGB(HighlightColor_));
OffsetRect(r, 2, 2);
DrawText(DC, PChar(Text), length(Text), r, FLAGS);
SetTextColor(DC, ColorToRGB(FontColor));
OffsetRect(r, -1, -1);
DrawText(DC, PChar(Text), length(Text), r, FLAGS);
end;
fstPushed:
begin
SetTextColor(DC, ColorToRGB(HighlightColor_));
DrawText(DC, PChar(Text), length(Text), r, FLAGS);
SetTextColor(DC, ColorToRGB(ShadowColor_));
OffsetRect(r, -1, -1);
DrawText(DC, PChar(Text), length(Text), r, FLAGS);
end;
fstShadow:
begin
SetTextColor(DC, ColorToRGB(ShadowColor_));
OffsetRect(r, 2, 2);
DrawText(DC, PChar(Text), length(Text), r, FLAGS);
SetTextColor(DC, ColorToRGB(FontColor));
OffsetRect(r, -2, -2);
DrawText(DC, PChar(Text), length(Text), r, FLAGS);
end;
else
begin
SetTextColor(DC, ColorToRGB(FontColor));
DrawText(DC, PChar(Text), length(Text), r, FLAGS);
end;
end;
SelectObject(DC, OldFont);
SetBkMode(DC, iOldBkMode);
end;
//_________________________________________________________________\\
{
Âûâîäèò òåêñò ñ çàäàííûì ñòèëåì, ñ îïöèåé êîíòóðà è çàäàíèåì öâåòîâ îòðèñîâêè 3D ýôôåêòîâ.
DC - handle of canvas
Style - ñòèëü (âäàâëåííûé, ñ òåíüþ etc)
fDelineated - êîíòóð öâåòà DelinColor
FontColor, DelinColor, HighlightColor, ShadowColor - öâåòà øðèôòà è 3D ýôôåêòîâ
Illumination - íå èñïîëüçóåòñÿ
Gradient - ãðàäèåíò äëÿ çàëèâêè áóêâ òåêñòà
}
procedure ExtTextOutExt(DC: HDC;
x, y: integer;
r: TRect;
Text: string;
Style: TglTextStyle;
fDelineated, fSupress3D: boolean;
FontColor, DelinColor, HighlightColor, ShadowColor: TColor;
Illumination: TJvgIllumination;
Gradient: TJvgGradient;
Font: TFont);
var
iOldBkMode, x_, y_, i, ShadowDepth: integer;
OldFont: Windows.HFont;
//...local proc
procedure DrawMain(fDelineated: boolean; s_: integer);
begin
if fDelineated then
begin
if not fSupress3D then
begin
SetTextColor(DC, ColorToRGB(DelinColor));
ExtTextOut(DC, x + s_, y + s_, ETO_CLIPPED, @r, PChar(Text), Length(Text), nil);
ExtTextOut(DC, x + 2 + s_, y + 2 + s_, ETO_CLIPPED, @r, PChar(Text), Length(Text), nil);
ExtTextOut(DC, x + s_, y + s_ + 2, ETO_CLIPPED, @r, PChar(Text), Length(Text), nil);
ExtTextOut(DC, x + s_ + 2, y + s_, ETO_CLIPPED, @r, PChar(Text), Length(Text), nil);
end;
SetTextColor(DC, ColorToRGB(FontColor));
if Assigned(Gradient) then
Gradient.TextOut(DC, Text, r, x + s_ + 1, y + s_ + 1)
else
ExtTextOut(DC, x + s_ + 1, y + s_ + 1, ETO_CLIPPED, @r, PChar(Text), Length(Text), nil);
end
else
begin
SetTextColor(DC, ColorToRGB(FontColor));
if Assigned(Gradient) then
Gradient.TextOut(DC, Text, r, x + s_, y + s_)
else
ExtTextOut(DC, x + s_, y + s_, ETO_CLIPPED, @r, PChar(Text), Length(Text), nil);
end;
end;
begin
if (not Assigned(Font)) then exit;
OldFont := SelectObject(DC, Font.Handle);
iOldBkMode := SetBkMode(DC, TRANSPARENT);
if fDelineated then
begin
x_ := 4;
y_ := 4;
end
else
begin
x_ := 2;
y_ := 2;
end;
if Style = fstNone then
begin
x_ := x_ div 2 - 1;
y_ := y_ div 2 - 1;
end;
if Style = fstShadow then
begin
x_ := x_ div 2 - 1;
y_ := y_ div 2 - 1;
end;
if Assigned(Illumination) then
ShadowDepth := Illumination.ShadowDepth
else
ShadowDepth := 2;
case Style of
fstRaised:
begin
if not fSupress3D then
begin
SetTextColor(DC, ColorToRGB(HighlightColor));
ExtTextOut(DC, x, y, ETO_CLIPPED, @r, PChar(Text), Length(Text), nil);
SetTextColor(DC, ColorToRGB(ShadowColor));
ExtTextOut(DC, x + x_, y + y_, ETO_CLIPPED, @r, PChar(Text), Length(Text), nil);
end;
DrawMain(fDelineated, 1);
end;
fstRecessed:
begin
if not fSupress3D then
begin
SetTextColor(DC, ColorToRGB(ShadowColor));
ExtTextOut(DC, x, y, ETO_CLIPPED, @r, PChar(Text), Length(Text), nil);
SetTextColor(DC, ColorToRGB(HighlightColor));
ExtTextOut(DC, x + x_, y + y_, ETO_CLIPPED, @r, PChar(Text), Length(Text), nil);
end;
DrawMain(fDelineated, 1);
end;
fstPushed:
begin
SetTextColor(DC, ColorToRGB(HighlightColor));
ExtTextOut(DC, x + 1, y + 1, ETO_CLIPPED, @r, PChar(Text), Length(Text), nil);
SetTextColor(DC, ColorToRGB(ShadowColor));
ExtTextOut(DC, x, y, ETO_CLIPPED, @r, PChar(Text), Length(Text), nil);
end;
fstShadow:
begin
if not fSupress3D then
begin
SetTextColor(DC, ColorToRGB(ShadowColor));
ExtTextOut(DC, x + x_ + ShadowDepth, y + y_ + ShadowDepth, ETO_CLIPPED, @r, PChar(Text), Length(Text), nil);
end;
DrawMain(fDelineated, 0);
end;
fstVolumetric:
begin
if not fSupress3D then
begin
SetTextColor(DC, ColorToRGB(ShadowColor));
for i := 1 to ShadowDepth do
ExtTextOut(DC, x + i, y + i, ETO_CLIPPED, @r, PChar(Text), Length(Text), nil);
end;
DrawMain(fDelineated, 0);
end;
else
begin
DrawMain(fDelineated, 0);
// SetTextColor( DC , ColorToRGB(FontColor) );
// ExtTextOut( DC, x, y, ETO_CLIPPED, @r, PChar(Text), Length(Text), nil);
end;
end;
SelectObject(DC, OldFont);
SetBkMode(DC, iOldBkMode);
end;
//_________________________________________________________________\\
{
Ðèñóåò ïðÿìîóãîëüíèê ñ çàäàíûì 3D ñòèëåì.
DC - handle of canvas
Style - ñòèëü (fbsFlat, fbsCtl3D, fbsStatusControl, fbsRecessed, fbsRaised, fbsRaisedFrame, fbsRecessedFrame)
BackgrColor- öâåò ôîíà, åñëè fTransparent = false
}
procedure DrawBox(DC: HDC; var r: TRect; Style: TglBoxStyle;
BackgrColor: LongInt; fTransparent: boolean);
const
FBorderWidth = 1;
begin
case Style of
fbsFlat: //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
begin
end;
fbsCtl3D: //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
begin
r.top := r.top + 2;
r.left := r.left + 2;
r.right := r.right - 2;
r.bottom := r.bottom - 1;
// Frame3D(Canvas, r,clBtnShadow,clBtnHighlight,1);
end;
// fbsStatusControl:
fbsRaised: //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
begin
InflateRect(r, -2, -2);
DrawEdge(DC, r, BDR_RAISEDOUTER, BF_BOTTOMRIGHT); // black
Dec(r.Bottom);
Dec(r.Right);
DrawEdge(DC, r, BDR_RAISEDINNER, BF_TOPLEFT); // btnhilite
Inc(r.Top);
Inc(r.Left);
DrawEdge(DC, r, BDR_RAISEDINNER, BF_BOTTOMRIGHT or BF_MIDDLE); // btnshadow
end;
fbsRecessed: //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
begin
r.bottom := r.bottom - 1;
DrawEdge(DC, r, BDR_SUNKENINNER, BF_TOPLEFT); // black
DrawEdge(DC, r, BDR_SUNKENOUTER, BF_BOTTOMRIGHT); // btnhilite
Dec(r.Bottom);
Dec(r.Right);
Inc(r.Top);
Inc(r.Left);
DrawEdge(DC, r, BDR_SUNKENOUTER, BF_TOPLEFT or BF_MIDDLE); // btnshadow
inc(r.top);
inc(r.left);
end;
fbsRaisedFrame: //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
begin
DrawEdge(DC, r, BDR_RAISEDOUTER, BF_BOTTOMRIGHT); // black
Dec(r.Bottom);
Dec(r.Right);
DrawEdge(DC, r, BDR_RAISEDINNER, BF_TOPLEFT); // btnhilite
Inc(r.Top);
Inc(r.Left);
DrawEdge(DC, r, BDR_RAISEDINNER, BF_BOTTOMRIGHT or BF_MIDDLE); // btnshadow
InflateRect(r, -FBorderWidth, -FBorderWidth);
DrawEdge(DC, r, BDR_SUNKENINNER, BF_TOPLEFT); // black
DrawEdge(DC, r, BDR_SUNKENOUTER, BF_BOTTOMRIGHT); // btnhilite
Dec(r.Bottom);
Dec(r.Right);
Inc(r.Top);
Inc(r.Left);
DrawEdge(DC, r, BDR_SUNKENOUTER, BF_TOPLEFT or BF_MIDDLE); // btnshadow
inc(r.top);
inc(r.left);
end;
fbsRecessedFrame: //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
begin
DrawEdge(DC, r, BDR_SUNKENINNER, BF_TOPLEFT); // black
DrawEdge(DC, r, BDR_SUNKENOUTER, BF_BOTTOMRIGHT); // btnhilite
Dec(r.Bottom);
Dec(r.Right);
Inc(r.Top);
Inc(r.Left);
DrawEdge(DC, r, BDR_SUNKENOUTER, BF_TOPLEFT or BF_MIDDLE); // btnshadow
inc(r.top);
inc(r.left);
InflateRect(r, -FBorderWidth, -FBorderWidth);
DrawEdge(DC, r, BDR_RAISEDOUTER, BF_BOTTOMRIGHT); // black
Dec(r.Bottom);
Dec(r.Right);
DrawEdge(DC, r, BDR_RAISEDINNER, BF_TOPLEFT); // btnhilite
Inc(r.Top);
Inc(r.Left);
DrawEdge(DC, r, BDR_RAISEDINNER, BF_BOTTOMRIGHT or BF_MIDDLE); // btnshadow
end;
end;
end;
//_________________________________________________________________\\
{
Ðèñóåò ïðÿìîóãîëüíèê ñ çàäàíûì 3D ñòèëåì è ñ óêàçàíèåì ñòîðîí.
DC - handle of canvas
Borders - ñòîðîíû äëÿ îòðèñîâêè
BevelInner, BevelOuter - ñòèëè ñòîðîí
Bold - òîëñòàÿ ðàìêà
BackgrColor- öâåò ôîíà, åñëè fTransparent = false
}
function DrawBoxEx(DC: HDC; rect: TRect; Borders: TglSides;
BevelInner, BevelOuter: TPanelBevel;
Bold: boolean; BackgrColor: LongInt;
fTransparent: boolean): TRect;
var
i: word;
BPen, LPen, SPen, OldPen: HPEN;
hBackgrBrush, hOldBrush: HBRUSH;
r, r_: TRect;
BColor, HColor, SColor: LongInt;
LOGOLDPEN: TLOGPEN;
PenWidth: UINT;
procedure SetDefColors;
begin
BColor := GetSysColor(COLOR_3DDKSHADOW);
HColor := GetSysColor(COLOR_3DHILIGHT);
SColor := GetSysColor(COLOR_3DSHADOW);
end;
procedure DrawBevel(Bevel: TPanelBevel); //____________LOCAL PROC_
begin
if fsdLeft in Borders then
begin
case Bevel of
bvRaised:
begin
SelectObject(DC, LPen);
MoveToEx(DC, r.left, r.top, nil);
LineTo(DC, r.left, r.bottom + 1);
inc(r_.left);
//.if Bold then inc(r_.left);
end;
bvLowered:
begin
if Bold then
begin
SelectObject(DC, BPen);
MoveToEx(DC, r.left, r.top, nil);
LineTo(DC, r.left, r.bottom);
inc(r_.left);
SelectObject(DC, SPen);
if fsdBottom in Borders then
i := 0
else
i := 1;
MoveToEx(DC, r.left + 1, r.top + 1, nil);
LineTo(DC, r.left + 1, r.bottom + i);
//SetPixel(DC, r.left, r.bottom-1, SColor);
inc(r_.left);
end
else
begin
SelectObject(DC, SPen);
MoveToEx(DC, r.left, r.top, nil);
LineTo(DC, r.left, r.bottom);
inc(r_.left);
end;
end;
{$IFDEF COMPILER4_UP}
bvSpace:
begin
SelectObject(DC, SPen);
MoveToEx(DC, r.left, r.top, nil);
LineTo(DC, r.left, r.bottom);
inc(r_.left);
end;
{$ENDIF}
end; //........{ . END CASE . }
end;
if fsdTop in Borders then
begin
case Bevel of
bvRaised:
begin
SelectObject(DC, LPen);
MoveToEx(DC, r.left, r.top, nil);
LineTo(DC, r.right, r.top);
inc(r_.top);
//.if Bold then inc(r_.top);
end;
bvLowered:
begin
if Bold then
begin
SelectObject(DC, BPen);
MoveToEx(DC, r.left, r.top, nil);
LineTo(DC, r.right, r.top);
inc(r_.top);
SelectObject(DC, SPen);
MoveToEx(DC, r.left + 1, r.top + 1, nil);
LineTo(DC, r.right, r.top + 1);
//SetPixel(DC, r.right-1, r.top+1, SColor);
inc(r_.top);
end
else
begin
SelectObject(DC, SPen);
MoveToEx(DC, r.left, r.top, nil);
LineTo(DC, r.right, r.top);
inc(r_.top);
end;
end;
{$IFDEF COMPILER4_UP}
bvSpace:
begin
SelectObject(DC, SPen);
MoveToEx(DC, r.left, r.top, nil);
LineTo(DC, r.right, r.top);
inc(r_.top);
end;
{$ENDIF}
end; //........{ . END CASE . }
end;
if fsdRight in Borders then
begin
case Bevel of
bvRaised:
begin
if Bold then
begin
SelectObject(DC, BPen);
MoveToEx(DC, r.right, r.top, nil);
LineTo(DC, r.right, r.bottom + 1);
dec(r_.right);
SelectObject(DC, SPen);
MoveToEx(DC, r.right - 1, r.top + 1, nil);
LineTo(DC, r.right - 1, r.bottom + 1);
//SetPixel(DC, r.right-1, r.bottom-1, SColor);
dec(r_.right);
end
else
begin
SelectObject(DC, SPen);
MoveToEx(DC, r.right, r.top, nil);
LineTo(DC, r.right, r.bottom + 1);
dec(r_.right);
end;
end;
bvLowered:
begin
SelectObject(DC, LPen);
MoveToEx(DC, r.right, r.top, nil);
LineTo(DC, r.right, r.bottom);
dec(r_.right);
//. if Bold then dec(r_.right);
end;
{$IFDEF COMPILER4_UP}
bvSpace:
begin
SelectObject(DC, SPen);
MoveToEx(DC, r.right, r.top, nil);
LineTo(DC, r.right, r.bottom);
dec(r_.right);
end;
{$ENDIF}
end; //........{ . END CASE . }
end;
if fsdBottom in Borders then
begin
case Bevel of
bvRaised:
begin
if Bold then
begin
SelectObject(DC, BPen);
if fsdLeft in Borders then
i := 1
else
i := 0;
MoveToEx(DC, r.left {+1}, r.bottom, nil);
LineTo(DC, r.right, r.bottom);
dec(r_.bottom);
SelectObject(DC, SPen);
MoveToEx(DC, r.left + i {+i}, r.bottom - 1, nil);
LineTo(DC, r.right, r.bottom - 1);
//SetPixel(DC, r.right-1+i, r.bottom-1, SColor);
dec(r_.bottom);
end
else
begin
SelectObject(DC, SPen);
MoveToEx(DC, r.left, r.bottom, nil);
LineTo(DC, r.right, r.bottom);
dec(r_.bottom);
end;
end;
bvLowered:
begin
SelectObject(DC, LPen);
// if Borders.Left then i:=1 else i:=0;
MoveToEx(DC, r.left, r.bottom {-1}, nil);
LineTo(DC, r.right + 1, r.bottom {-1});
dec(r_.bottom);
//. if Bold then dec(r_.bottom);
//dec(r_.bottom);
end;
{$IFDEF COMPILER4_UP}
bvSpace:
begin
SelectObject(DC, SPen);
MoveToEx(DC, r.left, r.bottom {-1}, nil);
LineTo(DC, r.right + 1, r.bottom {-1});
dec(r_.bottom);
end;
{$ENDIF}
end; //........{ . END CASE . }
end;
end; //_______________________________________LOCAL END_
begin //_________________________________________MAIN_
try
if Assigned(glGlobalData.lp3DColors) then
with TJvg3DColors(glGlobalData.lp3DColors) do
begin
BColor := ColorToRGB(DkShadow);
HColor := ColorToRGB(Highlight);
SColor := ColorToRGB(Shadow);
end
else
SetDefColors;
except
end;
LPen := CreatePen(PS_SOLID, 1, HColor); //.
OldPen := SelectObject(DC, LPen); //..
DeleteObject(SelectObject(DC, OldPen)); //...get OldPen
FillChar(LOGOLDPEN, sizeof(LOGOLDPEN), 0);
GetObject(OldPen, sizeof(LOGOLDPEN), @LOGOLDPEN);
if LOGOLDPEN.lopnWidth.x = 0 then
PenWidth := 1
else
PenWidth := LOGOLDPEN.lopnWidth.x;
BPen := CreatePen(LOGOLDPEN.lopnStyle, PenWidth, BColor);
LPen := CreatePen(LOGOLDPEN.lopnStyle, PenWidth, HColor);
SPen := CreatePen(LOGOLDPEN.lopnStyle, PenWidth, SColor);
SelectObject(DC, LPen);
r_ := rect;
r := rect;
if BevelOuter <> bvNone then DrawBevel(BevelOuter);
r := r_;
// if (BevelOuter = bvRaised)and(BevelInner = bvLowered)and Bold then
// begin dec(r.top); dec(r.left); end;
if BevelInner <> bvNone then DrawBevel(BevelInner);
SelectObject(DC, OldPen);
DeleteObject(BPen);
DeleteObject(LPen);
DeleteObject(SPen);
if not fTransparent then
begin
hBackgrBrush := CreateSolidBrush(ColorToRGB(BackgrColor));
hOldBrush := SelectObject(DC, hBackgrBrush);
r := r_; {dec(r.top);dec(r.left);}
inc(r.right);
inc(r.bottom);
FillRect(DC, r, hBackgrBrush);
DeleteObject(SelectObject(DC, hOldBrush));
end;
Result := r_;
end;
//_________________________________________________________________\\
{
Ðèñóåò ãðàäèåíò TJvgGradient
}
procedure GradientBox(DC: HDC; r: TRect; Gradient: TJvgGradient; PenStyle, PenWidth: integer);
begin
Gradient.Draw(DC, r, PenStyle, PenWidth);
end;
//_________________________________________________________________\\
{
Çàìåíÿåò öâåò ó áèòìàïà
}
procedure ChangeBitmapColor(Bitmap: TBitmap;
FromColor, ToColor: TColor);
var
IWidth, IHeight: Integer;
DRect, SRect: TRect;
MonoBMP, OldBMP: HBitmap;
MonoDC: HDC;
const
ROP_DSPDxax = $00E20746;
begin
if (Bitmap.Width or Bitmap.Height) = 0 then Exit;
IWidth := Bitmap.Width;
IHeight := Bitmap.Height;
DRect := Rect(0, 0, IWidth, IHeight);
SRect := DRect;
MonoDC := CreateCompatibleDC(Bitmap.Canvas.handle);
MonoBMP := CreateBitmap(IWidth, IHeight, 1, 1, nil);
OldBMP := SelectObject(MonoDC, MonoBMP);
try
with Bitmap.Canvas do { Convert FromColor to ToColor }
begin
Bitmap.Canvas.Brush.Color := FromColor;
{copy Bitmap to MonoBmp}
BitBlt(MonoDC, 0, 0, IWidth, IHeight, Handle, 0, 0, cmSrcCopy);
Brush.Color := ToColor;