-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRackCtls.pas
2662 lines (2476 loc) · 71.6 KB
/
RackCtls.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
{%encoding ISO-8859-1}
unit RackCtls;
{ RackControls:
TLEDButton, TButtonPanel, TScrewPanel, TLEDDisplay, TLEDMeter
(C)opyright 2004 Version 1.20
Autor : Simon Reinhardt
eMail : [email protected]
Internet : http://www.picsoft.de
RackControls ist eine Komponentensammlung zur Erstellung von
Audiorack-ähnlichen Oberflächen. Diese Komponenten sind
Public Domain, das Urheberrecht liegt aber beim Autor.
Die Komponente TLEDDisplay ist eine Weiterentwicklung
der Komponente TLCDDisplay von Luis Iglesias:
Änderungen, die bei LEDDisplay nachfolgende Nullen bei LeadingZeros=False doch zeichnet
Ergänzt von Wolfgang Kleinrath
Eigenschaft FSingleLED ergänzt von U. Conrad
Lazarus adaptation: Luca Olivetti <[email protected]>
}
interface
{$I SRDefine.inc}
uses
{$IFDEF SR_LAZARUS} LCLType, LCLIntf, LResources, LMessages, Buttons,
{$ELSE}
{$IFDEF SR_Win32} Windows, {$ELSE} WinTypes, WinProcs, Menus, Messages, {$ENDIF}
{$ENDIF}
Classes, Graphics, Controls, ExtCtrls, SysUtils, Forms;
type
{$IFNDEF SR_LAZARUS}
TBorderStyle = (bsNone, bsSingle);
{$ENDIF}
TButtonDirection = (bdBottomUp, bdLeftUp, bdNone, bdRightUp, bdTopUp);
TContrast = 0..9;
TDecSeparator = (dsApostrophe, dsComma, dsDoublePoint, dsHyphen, dsNone, dsPoint, dsSemicolon);
TLEDStates = (lsOff, lsOn);
TMeterDirection = (mdDown, mdLeft, mdRight, mdUp);
TNumGlyphs = 0..4;
TScrewSize = 1..8;
TSegmentStyle = (ssRectangular, ssBeveled);
TTextPosition = (tpAbove, tpBelow, tpNone, tpOnButton);
TLEDMeter = class;
TLEDMeterColors = class(TPersistent)
private
FBorder,
FSection1,
FSection2,
FSection3 : TColor;
FOwner : TLEDMeter;
procedure SetBorder(NewValue: TColor);
procedure SetSection1(NewValue: TColor);
procedure SetSection2(NewValue: TColor);
procedure SetSection3(NewValue: TColor);
public
constructor Create(AOwner: TComponent);
procedure Assign(Source : TPersistent); override;
published
property Border: TColor read FBorder write SetBorder;
property Section1: TColor read FSection1 write SetSection1;
property Section2: TColor read FSection2 write SetSection2;
property Section3: TColor read FSection3 write SetSection3;
end;
TLEDButton = class(TGraphicControl)
private
FBeveled: boolean;
FBorderStyle: TBorderStyle;
FButtonDirection: TButtonDirection;
FColor: TColor;
FColorHighlight: TColor;
FColorLED: TColor;
FColorLEDOff: TColor;
FColorShadow: TColor;
FDepth: integer;
FDown: boolean;
FFont: TFont;
FGlyph: {$IFDEF SR_LAZARUS} TButtonGlyph {$ELSE} TBitmap {$ENDIF};
FLEDContrast: TContrast;
{$IFNDEF SR_LAZARUS}
FNumGlyphs: TNumGlyphs;
{$ENDIF}
FShowLED: boolean;
FStateOn: boolean;
FSwitching: boolean;
FTextPosition: TTextPosition;
{$IFNDEF SR_LAZARUS}
FMouseDown: boolean;
FOnClick: TNotifyEvent;
{$ENDIF}
protected
procedure Paint; override;
procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
override;
procedure MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
override;
{$IFDEF SR_LAZARUS}
procedure MouseLeave; override;
{$ENDIF}
procedure SetBeveled(newValue: boolean);
procedure SetBorderStyle(newBorderStyle: TBorderStyle);
procedure SetButtonDirection(NewDirection: TButtonDirection);
procedure SetColor(newColor: TColor); {$IFDEF SR_LAZARUS}override;{$ENDIF}
procedure SetColorLED(newColor: TColor);
procedure SetDepth(newValue: integer);
procedure SetFont(newFont: TFont);
{$IFDEF SR_LAZARUS}
function GetGlyph: TBitmap;
function GetNumGlyphs: TNumGlyphs;
{$ENDIF}
procedure SetGlyph(newGlyph: TBitmap);
procedure SetLEDContrast(newContrast: TContrast);
procedure SetNumGlyphs(newNumGlyphs: TNumGlyphs);
procedure SetShowLED(newValue: boolean);
procedure SetStateOn(newValue: boolean);
procedure SetTextPosition(newValue: TTextPosition);
procedure DrawBorder(Dest:TRect);
procedure DrawCaption(Dest:TRect);
procedure DrawGlyph(Dest:TRect);
procedure DrawLED(var Dest:TRect);
{$IFDEF SR_LAZARUS}
function DialogChar(var Message: TLMKey):boolean;override;
procedure TextChanged;override;
{$ENDIF}
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
{$IFNDEF SR_LAZARUS}
procedure CMTextChanged(var msg: TMessage);message CM_TEXTCHANGED;
procedure CMDialogChar(var Message: TCMDialogChar);message CM_DIALOGCHAR;
{$ENDIF}
published
{$IFDEF SR_Delphi5_Up}
property Action;
property Anchors;
{$ENDIF}
property Beveled: boolean read FBeveled write SetBeveled;
property BorderStyle: TBorderStyle read FBorderStyle write SetBorderStyle;
property ButtonDirection: TButtonDirection read FButtonDirection write SetButtonDirection;
property Caption;
property Color: TColor read FColor write SetColor default clGray;
property ColorLED: TColor read FColorLED write SetColorLED;
property Depth: integer read FDepth write SetDepth;
property Enabled;
property Font: TFont read FFont write SetFont;
property Glyph: TBitmap read {$IFDEF SR_LAZARUS} GetGlyph {$ELSE} FGlyph {$ENDIF} write SetGlyph;
property LEDContrast: TContrast read FLEDContrast write SetLEDContrast;
property NumGlyphs: TNumGlyphs read {$IFDEF SR_LAZARUS} GetNumGlyphs {$ELSE} FNumGlyphs {$ENDIF} write SetNumGlyphs default 1;
property ParentFont;
property ParentShowHint;
{$IFDEF SR_Delphi3_Up}
property PopupMenu;
{$ENDIF}
property ShowHint;
property ShowLED: boolean read FShowLED write SetShowLED;
property StateOn: boolean read FStateOn write SetStateOn;
property Switching: boolean read FSwitching write FSwitching default true;
property TextPosition: TTextPosition read FTextPosition write SetTextPosition default tpNone;
property Visible;
property OnClick;
property OnDblClick;
property OnMouseDown;
property OnMouseMove;
property OnMouseUp;
end;
{$IFDEF SR_LAZARUS}
//Lazarus already has a TButtonPanel in its standard components collection
TLedButtonPanel = class(TCustomPanel)
{$ELSE}
TButtonPanel = class(TCustomPanel)
{$ENDIF}
private
FBeveled: boolean;
FBorderStyle: TBorderStyle;
FColor: TColor;
FColorHighlight: TColor;
FColorShadow: TColor;
FDepth: integer;
FPanelDirection: TButtonDirection;
FShowLED: boolean;
protected
procedure Paint; override;
procedure SetBeveled(newValue: boolean);
procedure SetBorderStyle(newBorderStyle: TBorderStyle); {$IFDEF SR_LAZARUS}override;{$ENDIF}
procedure SetColor(newColor: TColor); {$IFDEF SR_LAZARUS}override;{$ENDIF}
procedure SetDepth(newValue: integer);
procedure SetPanelDirection(NewDirection: TButtonDirection);
procedure SetShowLED(newValue: boolean);
procedure DrawBorder(Dest:TRect);
procedure DrawCaption(Dest:TRect);
procedure DrawLED(var Dest:TRect);
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
published
property Align;
property Alignment;
{$IFDEF SR_Delphi5_Up}
property Anchors;
{$ENDIF}
property Beveled: boolean read FBeveled write SetBeveled;
property BorderStyle: TBorderStyle read FBorderStyle write SetBorderStyle;
property Caption;
property Color: TColor read FColor write SetColor default clGray;
{$IFNDEF SR_LAZARUS}
property Ctl3D;
{$ENDIF}
property Depth: integer read FDepth write SetDepth;
property DragCursor;
property DragMode;
property Enabled;
{$IFDEF SR_Delphi3_Up}
property FullRepaint;
{$ENDIF}
property Font;
{$IFNDEF SR_LAZARUS}
property Locked;
{$ENDIF}
property PanelDirection: TButtonDirection read FPanelDirection write SetPanelDirection;
property ParentColor;
{$IFNDEF SR_LAZARUS}
property ParentCtl3D;
{$ENDIF}
property ParentFont;
property ParentShowHint;
property PopupMenu;
property ShowHint;
property ShowLED: boolean read FShowLED write SetShowLED;
property TabOrder;
property TabStop;
property Visible;
property OnClick;
property OnDblClick;
property OnDragDrop;
property OnDragOver;
property OnEndDrag;
property OnEnter;
property OnExit;
property OnMouseDown;
property OnMouseMove;
property OnMouseUp;
property OnResize;
{$IFDEF SR_Delphi3_Up}
property OnStartDrag;
{$ENDIF}
end;
TScrewPanel = class(TCustomPanel)
private
FColor: TColor;
FColorHighlight: TColor;
FColorShadow: TColor;
FMargin: integer;
FScrewSize: TScrewSize;
FShowScrews: boolean;
protected
procedure Paint; override;
procedure SetColor(newColor: TColor); {$IFDEF SR_LAZARUS}override;{$ENDIF}
procedure SetMargin(newValue: integer);
procedure SetScrewSize(newValue: TScrewSize);
procedure SetShowScrews(newValue: boolean);
procedure DrawScrew(X,Y:integer);
procedure DrawBevel(ARect:TRect;Raised:boolean);
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
published
property Align;
property Alignment;
{$IFDEF SR_Delphi5_Up}
property Anchors;
{$ENDIF}
property BevelInner;
property BevelOuter;
property BevelWidth;
property BorderWidth;
property BorderStyle;
property Caption;
property Color: TColor read FColor write SetColor;
{$IFNDEF SR_LAZARUS}
property Ctl3D;
{$ENDIF}
property DragCursor;
property DragMode;
property Enabled;
{$IFDEF SR_Delphi3_Up}
property FullRepaint;
{$ENDIF}
property Font;
{$IFNDEF SR_LAZARUS}
property Locked;
{$ENDIF}
property Margin: integer read FMargin write SetMargin;
property ParentColor;
{$IFNDEF SR_LAZARUS}
property ParentCtl3D;
{$ENDIF}
property ParentFont;
property ParentShowHint;
property PopupMenu;
property ScrewSize: TScrewSize read FScrewSize write SetScrewSize;
property ShowHint;
property ShowScrews: boolean read FShowScrews write SetShowScrews;
property TabOrder;
property TabStop;
property Visible;
property OnClick;
property OnDblClick;
property OnDragDrop;
property OnDragOver;
property OnEndDrag;
property OnEnter;
property OnExit;
property OnMouseDown;
property OnMouseMove;
property OnMouseUp;
property OnResize;
{$IFDEF SR_Delphi3_Up}
property OnStartDrag;
{$ENDIF}
end;
{ TLEDDisplay }
TLEDDisplay = class(TGraphicControl)
private
FBevelStyle : TPanelBevel;
FBorderStyle : TBorderStyle;
FColorBackGround,
FColorLED : TColor;
FDecSeparator : TDecSeparator;
FDigit : array [0..15] of TBitmap;
FDigitHeight : integer;
FDigitShapeColor : TColor;
FDigitWidth : integer;
FDrawDigitShapes : boolean;
FFractionDigits : integer;
FLEDContrast : TContrast;
FSegmentOffColor : TColor;
FLineWidth,
FNumDigits : integer;
FLeadingZeros : boolean;
FSegCl : array [0..15, 1..7] of TColor;
FSegmentStyle : TSegmentStyle;
FHex : boolean;
FValue : extended;
FOnChange : TNotifyEvent;
procedure SetBevelStyle (newValue: TPanelBevel);
procedure SetBorderStyle (newValue: TBorderStyle);
procedure SetColorBackGround (newValue: TColor);
procedure SetColorLED (newValue: TColor);
procedure SetDecSeparator (newValue: TDecSeparator);
procedure SetDigitHeight (newValue: integer);
procedure SetDigitWidth (newValue: integer);
procedure SetDrawDigitShapes(newValue: boolean);
procedure SetFractionDigits (newValue: integer);
procedure SetLeadingZeros (newValue: boolean);
procedure SetLEDContrast(newContrast: TContrast);
procedure SetLineWidth (newValue: integer);
procedure SetNumDigits (newValue: integer);
procedure SetSegmentStyle (newValue: TSegmentStyle);
procedure SetValue (newValue: extended);
procedure SetHex (newValue: boolean);
procedure CreateDigitBitmaps;
procedure AssignColors (seg: integer; s1,s2,s3,s4,s5,s6,s7: Boolean);
protected
procedure Paint; override;
procedure Change; dynamic;
public
constructor Create (AOwner: TComponent); override;
destructor Destroy; override;
published
{$IFDEF SR_Delphi5_Up}
property Anchors;
{$ENDIF}
property BevelStyle: TPanelBevel read FBevelStyle write SetBevelStyle;
property BorderStyle: TBorderStyle read FBorderStyle write SetBorderStyle;
property ColorBackGround: TColor read FColorBackGround write setColorBackGround default clOlive;
property ColorLED: TColor read FColorLED write setColorLED default cllime;
property DecSeparator: TDecSeparator read FDecSeparator write setDecSeparator default dsComma;
property DigitHeight: integer read FDigitHeight write setDigitHeight default 30;
property DigitWidth: integer read FDigitWidth write setDigitWidth default 20;
property DigitLineWidth: integer read FLineWidth write setLineWidth default 3;
property DrawDigitShapes: boolean read FDrawDigitShapes write SetDrawDigitShapes default true;
property FractionDigits: integer read FFractionDigits write setFractionDigits default 0;
property Height default 36;
property LeadingZeros: boolean read FLeadingZeros write setLeadingZeros default true;
property LEDContrast: TContrast read FLEDContrast write SetLEDContrast;
property NumDigits: integer read FNumDigits write setNumDigits default 6;
property SegmentStyle: TSegmentStyle read FSegmentStyle write setSegmentStyle default ssBeveled;
property Hex: boolean read FHex write SetHex default false;
property Value: extended read FValue write setValue;
property Visible;
property Width default 168;
property OnChange: TNotifyEvent read FOnChange write FOnChange;
property OnClick;
property OnDblClick;
property OnDragDrop;
property OnDragOver;
property OnEndDrag;
property OnMouseDown;
property OnMouseMove;
property OnMouseUp;
end;
TLEDMeter = class(TGraphicControl)
private
FBevelStyle : TPanelBevel;
FColors : TLEDMeterColors;
FColor1Off,
FColor2Off,
FColor3Off : TColor;
FDirection : TMeterDirection;
FFallbackDelay : byte;
FFallbackTimer : TTimer;
FLEDContrast : TContrast;
FLEDPosition,
FMax,FMin,
FNumDigits,
FPeakPosition : integer;
FPeakShowTime : TDateTime;
FPeakHoldTime : byte;
FPosition,
FSection2Value,
FSection3Value : integer;
FSingleLED : boolean;
FOnChange : TNotifyEvent;
procedure CalculateOffColors;
procedure SetBevelStyle(newVal : TPanelBevel);
procedure SetColors(newVal: TLEDMeterColors);
procedure SetDirection(newVal : TMeterdirection);
procedure SetFallbackDelay(newVal : byte);
procedure SetLEDContrast(newContrast: TContrast);
procedure SetMax(newVal : integer);
procedure SetMin(newVal : integer);
procedure SetNumDigits(newVal : integer);
procedure SetPosition(newVal : integer);
procedure SetSingleLED(newVal : boolean);
procedure SetSection2Value(newVal : integer);
procedure SetSection3Value(newVal : integer);
protected
procedure Paint;override;
procedure Change; dynamic;
function GetLEDColor(const AIndex,YellowIdx,RedIdx:integer;const LEDState:TLEDStates):TColor;
procedure TimerExpired(Sender: TObject);
public
constructor Create(AOwner : TComponent);override;
destructor Destroy ; override;
published
{$IFDEF SR_Delphi5_Up}
property Anchors;
{$ENDIF}
property BevelStyle: TPanelBevel read FBevelStyle write SetBevelStyle;
property Colors : TLEDMeterColors read FColors write SetColors;
property Cursor;
property Direction: TMeterDirection read FDirection write SetDirection default mdRight;
property DragCursor;
property DragMode;
property FallbackDelay: byte read FFallbackDelay write SetFallbackDelay;
property LEDContrast: TContrast read FLEDContrast write SetLEDContrast;
property Max: integer read FMax write SetMax;
property Min: integer read FMin write SetMin;
property NumDigits: integer read FNumDigits write SetNumDigits;
property PeakHoldTime: byte read FPeakHoldTime write FPeakHoldTime;
property Position: integer read FPosition write SetPosition;
property SingleLED: boolean read FSingleLED write SetSingleLED;
property Section2Value: integer read FSection2Value write SetSection2Value;
property Section3Value: integer read FSection3Value write SetSection3Value;
property Visible;
property OnChange: TNotifyEvent read FOnChange write FOnChange;
property OnClick;
property OnDblClick;
property OnDragDrop;
property OnDragOver;
property OnEndDrag;
property OnMouseDown;
property OnMouseMove;
property OnMouseUp;
end;
procedure Register;
implementation
{$IFDEF SR_LAZARUS}
uses rrColors;
{$ELSE}
{$IFDEF SR_Delphi2_Up}
{$R *.D32}
uses rrColors {$IFNDEF SR_Delphi5_Up}, SRUtils{$ENDIF};
{$ELSE}
{$R *.D16}
uses SRUtils;
{$ENDIF}
{$ENDIF}
const
DefaultWidth = 45;
DefaultHeight = 45;
DefaultDepth = 3;
FHLContrast = 5;
FShContrast = 4;
FShapeContrast = 3;
function IsAccellerator(VK: Word; const Str: string): Boolean;
var P : Integer;
begin
P:=Pos('&', Str);
Result:=(P <> 0) and (P < Length(Str)) and
(Upcase(Str[P + 1])=Upcase(Char(VK)));
end; {IsAccellerator}
{$IFDEF SR_Delphi1}
function ChangeBrightness(Color:TColor;Percentage:longint):TColor;
var RGBColor : longint;
Red,Green,Blue : byte;
NewR,NewG,NewB : longint;
Overflow : longint;
begin
RGBColor:=ColorToRGB(Color);
Overflow:=0;
{ Rot }
Red:=GetRValue(RGBColor);
NewR:=Red+(Percentage*Red div 100);
if NewR>255 then begin
Overflow:=NewR-255;
NewG:=Overflow;
NewB:=Overflow;
end
else begin
NewG:=0;
NewB:=0;
end;
{ Grün }
Green:=GetGValue(RGBColor);
NewG:=NewG+Green+(Percentage*Green div 100);
if NewG>255 then begin
Overflow:=NewG-255;
NewR:=NewR+Overflow;
NewB:=Overflow;
end;
{ Blau }
Blue:=GetBValue(RGBColor);
NewB:=NewB+Blue+(Percentage*Blue div 100);
if NewB>255 then begin
Overflow:=NewB-255;
if NewG<=255 then
NewR:=NewR+Overflow;
end;
if NewR>255 then
NewR:=255;
if NewG>255 then
NewG:=255;
if NewB>255 then
NewB:=255;
if NewR<0 then
NewR:=0;
if NewG<0 then
NewG:=0;
if NewB<0 then
NewB:=0;
Result:=NewR+(NewG shl 8)+(NewB shl 16);
end; {ChangeBrightness}
{$ENDIF}
function GetIntermediateColor(Color1,Color2:TColor;AContrast:integer):TColor;
{$IFDEF SR_Delphi2_Up}
var YR,YG,YB,SR,
SG,SB,DR,DG,DB,
StartClr,EndClr : integer;
{$ENDIF}
begin
{$IFDEF SR_Delphi1}
Result:=ChangeBrightness(Color1, -100 div 10*AContrast);
{$ELSE}
StartClr:=ColorToRGB(Color1);
{$IFDEF SR_LAZARUS}
YR := Red(StartClr);
YG := Green(StartClr);
YB := Blue(StartClr);
{$ELSE}
YR := GetRValue(StartClr);
YG := GetGValue(StartClr);
YB := GetBValue(StartClr);
{$ENDIF}
SR := YR;
SG := YG;
SB := YB;
EndClr:=ColorToRGB(Color2);
{$IFDEF SR_LAZARUS}
DR := Red(EndClr)-SR;
DG := Green(EndClr)-SG;
DB := Blue(EndClr)-SB;
{$ELSE}
DR := GetRValue(EndClr)-SR;
DG := GetGValue(EndClr)-SG;
DB := GetBValue(EndClr)-SB;
{$ENDIF}
YR := SR + round(DR / 9 * AContrast);
YG := SG + round(DG / 9 * AContrast);
YB := SB + round(DB / 9 * AContrast);
{$IFDEF SR_LAZARUS}
Result := RGBToColor( YR, YG, YB);
{$ELSE}
Result := RGB( YR, YG, YB);
{$ENDIF}
{$ENDIF}
end; {GetIntermediateColor}
function GetOffColor(const OnColor:TColor;const AContrast:TContrast):TColor;
var Dummy : TCOlor;
begin
{$IFDEF SR_Delphi1}
Result:=ChangeBrightness(OnColor, -100 div 10*AContrast);
{$ELSE}
Get3DColors(OnColor, Dummy, Result,(10-AContrast)/10,(10-AContrast)/10);
{$ENDIF}
end; {CalculateOffColor}
procedure AssignBevelColors(FaceColor:TColor;var HighlightColor,ShadowColor:TColor;HLContrast,ShContrast:integer);
begin
{$IFDEF SR_Delphi1}
HighlightColor:=ChangeBrightness(FaceColor,100 div 10*HLContrast);
ShadowColor:=ChangeBrightness(FaceColor,-100 div 10*ShContrast);
{$ELSE}
Get3DColors(FaceColor,HighlightColor,ShadowColor,(10-HLContrast)/10,(10-ShContrast)/10);
{$ENDIF}
end; {AssignBevelColors}
{ Klasse TLEDMeterColors }
constructor TLEDMeterColors.Create(AOwner: TComponent);
begin
inherited Create;
if AOwner is TLEDMeter then
FOwner := TLEDMeter(AOwner)
else
FOwner:=nil;
FBorder:=clBlack;
FSection1:=clLime;
FSection2:=clYellow;
FSection3:=clRed;
end;
procedure TLEDMeterColors.Assign(Source: TPersistent);
begin
Border:=TLEDMeterColors(Source).Border;
Section1:=TLEDMeterColors(Source).Section1;
Section2:=TLEDMeterColors(Source).Section2;
Section3:=TLEDMeterColors(Source).Section3;
end;
procedure TLEDMeterColors.SetBorder(NewValue: TColor);
begin
if NewValue<>FBorder then begin
FBorder:=NewValue;
if Assigned(FOwner) then
FOwner.Invalidate;
end;
end;
procedure TLEDMeterColors.SetSection1(NewValue: TColor);
begin
if NewValue<>FSection1 then begin
FSection1:=NewValue;
if Assigned(FOwner) then
FOwner.CalculateOffColors;
end;
end;
procedure TLEDMeterColors.SetSection2(NewValue: TColor);
begin
if NewValue<>FSection2 then begin
FSection2:=NewValue;
if Assigned(FOwner) then
FOwner.CalculateOffColors;
end;
end;
procedure TLEDMeterColors.SetSection3(NewValue: TColor);
begin
if NewValue<>FSection3 then begin
FSection3:=NewValue;
if Assigned(FOwner) then
FOwner.CalculateOffColors;
end;
end;
{ Komponente TLEDButton }
constructor TLEDButton.Create(AOwner: TComponent);
var Dummy : TColor;
begin
inherited Create(AOwner);
{ Vorgabewerte setzen }
FBeveled:=true;
FBorderStyle:=bsSingle;
FButtonDirection:=bdBottomUp;
Color:=clGray;
AssignBevelColors(Color,FColorHighlight,FColorShadow,FHLContrast,FShContrast);
FColorLED:=clBlue;
FLEDContrast:=6;
AssignBevelColors(FColorLED,Dummy,FColorLEDOff,FLEDContrast,FLEDContrast);
FDepth:=DefaultDepth;
FDown:=false;
FFont:=TFont.Create;
{$IFDEF SR_LAZARUS}
FGlyph:=TButtonGlyph.Create;
{$ELSE}
FGlyph:=TBitmap.Create;
FNumGlyphs:=1;
{$ENDIF}
FShowLED:=true;
FStateOn:=false;
FSwitching:=true;
FTextPosition:=tpNone;
Height:=DefaultHeight;
Width:=DefaultWidth;
{$IFNDEF SR_LAZARUS}
FMouseDown:=False;
{$ENDIF}
end;
destructor TLEDButton.Destroy;
begin
FFont.Free;
FGlyph.Free;
inherited Destroy;
end;
procedure TLEDButton.SetBeveled(NewValue: boolean);
begin
if FBeveled<>NewValue then begin
FBeveled:=NewValue;
Invalidate;
end;
end;
procedure TLEDButton.SetBorderStyle(NewBorderStyle: TBorderStyle);
begin
if FBorderStyle<>NewBorderStyle then begin
FBorderStyle:=NewBorderStyle;
Invalidate;
end;
end;
procedure TLEDButton.SetButtonDirection(NewDirection: TButtonDirection);
begin
if FButtonDirection<>NewDirection then begin
FButtonDirection:=NewDirection;
Invalidate;
end;
end;
procedure TLEDButton.SetColor(newColor: TColor);
begin
if FColor<>newColor then begin
{$IFDEF SR_LAZARUS}
inherited SetColor(newColor);
{$ENDIF}
FColor:=newColor;
AssignBevelColors(FColor,FColorHighlight,FColorShadow,FHLContrast,FShContrast);
Invalidate;
end;
end;
procedure TLEDButton.SetColorLED(newColor: TColor);
var Dummy : TColor;
begin
if FColorLED<>newColor then begin
FColorLED:=newColor;
AssignBevelColors(FColorLED,Dummy,FColorLEDOff,FLEDContrast,FLEDContrast);
Invalidate;
end;
end;
procedure TLEDButton.SetDepth(newValue: integer);
begin
if FDepth<>newValue then begin
FDepth:=newValue;
Invalidate;
end;
end;
procedure TLEDButton.SetFont(newFont: TFont);
begin
FFont.Assign(NewFont);
Invalidate;
end;
{$IFDEF SR_LAZARUS}
procedure TLEDButton.SetGlyph(newGlyph: TBitmap);
begin
fGlyph.Glyph:=newGlyph;
Invalidate;
end;
function TLEDButton.GetGlyph:TBitmap;
begin
result:=fGlyph.Glyph;
end;
{$ELSE}
procedure TLEDButton.SetGlyph(newGlyph: TBitmap);
begin
if(Assigned(FGlyph)) then begin
FGlyph.Assign(newGlyph);
if (csDesigning in ComponentState) then begin
{ Glyph 1: Normal, 2: Disabled, 3: Down;
Muß die Ausmaße (Height * NumGlyphs) = Width haben}
if (newGlyph.width mod newGlyph.height = 0) then
FNumGlyphs:= newGlyph.width div newGlyph.height
else
FNumGlyphs:= 1;
end;
Invalidate;
end;
end;
{$ENDIF}
procedure TLEDButton.SetLEDContrast(newContrast: TContrast);
var Dummy : TColor;
begin
if (FLEDContrast<>newContrast) and (newContrast>=0) and (newContrast<10) then begin
FLEDContrast:=newContrast;
AssignBevelColors(FColorLED,Dummy,FColorLEDOff,FLEDContrast,FLEDContrast);
Invalidate;
end;
end;
{$IFDEF SR_LAZARUS}
function TLEDButton.GetNumGlyphs:TNumGlyphs;
begin
result:=FGlyph.NumGlyphs;
end;
procedure TLEDButton.SetNumGlyphs(newNumGlyphs: TNumGlyphs);
begin
if newNumGlyphs < 0 then newNumGlyphs := 1;
if newNumGlyphs > High(TNumGlyphs) then newNumGlyphs := High(TNumGlyphs);
if newNumGlyphs <> fGlyph.NumGlyphs then
Begin
fGlyph.NumGlyphs := newNumGlyphs;
Invalidate;
end;
end;
{$ELSE}
procedure TLEDButton.SetNumGlyphs(newNumGlyphs: TNumGlyphs);
begin
if FNumGlyphs<>newNumGlyphs then begin
FNumGlyphs:=newNumGlyphs;
Invalidate;
end;
end;
{$ENDIF}
procedure TLEDButton.SetShowLED(newValue: boolean);
begin
if FShowLED<>newValue then begin
FShowLED:=newValue;
Invalidate;
end;
end;
procedure TLEDButton.SetStateOn(newValue: boolean);
begin
if FStateOn<>newValue then begin
FStateOn:=newValue;
Invalidate;
end;
end;
procedure TLEDButton.SetTextPosition(newValue: TTextPosition);
begin
if FTextPosition<>newValue then begin
FTextPosition:=newValue;
Invalidate;
end;
end;
procedure TLEDButton.DrawBorder(Dest:TRect);
var i : integer;
begin
Dest:=GetClientRect;
if FTextPosition=tpAbove then
Dest.Top:=Dest.Top+Canvas.TextWidth('W')+2;
if FTextPosition=tpBelow then
Dest.Bottom:=Dest.Bottom-Canvas.TextWidth('W')-2;
with Canvas do begin
if FBorderStyle=bsSingle then begin
Brush.Color:=clWindowFrame;
FrameRect(Dest);
InflateRect(Dest,-1,-1);
end;
Pen.Width:=1;
if FButtonDirection=bdBottomUp then begin
Pen.Color:=FColorHighlight;
{ oben }
MoveTo(Dest.Right-1,Dest.Top);
LineTo(Dest.Left,Dest.Top);
{ links }
if not FBeveled then begin
MoveTo(Dest.Left,Dest.Top);
LineTo(Dest.Left,Dest.Bottom-1);
end
else
for i:=0 to FDepth do begin
MoveTo(Dest.Left,Dest.Top);
if FDown then
LineTo(Dest.Left+(i div 2),Dest.Bottom-1)
else
LineTo(Dest.Left+i,Dest.Bottom-i-1);
end;
Pen.Color:=FColorShadow;
{ rechts }
if not FBeveled then begin
MoveTo(Dest.Right-1,Dest.Top);
LineTo(Dest.Right-1,Dest.Bottom);
end
else
for i:=0 to FDepth do begin
MoveTo(Dest.Right-1,Dest.Top);
if FDown then
LineTo(Dest.Right-(i div 2)-1,Dest.Bottom-1)
else
LineTo(Dest.Right-i-1,Dest.Bottom-i-1);
end;
{ unten }
if FDown then begin
MoveTo(Dest.Left,Dest.Bottom-1);
LineTo(Dest.Right-1,Dest.Bottom-1);
end
else
for i:=0 to FDepth do begin
if not FBeveled then begin
MoveTo(Dest.Left,Dest.Bottom-i-1);
LineTo(Dest.Right-1,Dest.Bottom-i-1);
end
else begin
MoveTo(Dest.Left+i,Dest.Bottom-i-1);
LineTo(Dest.Right-i-1,Dest.Bottom-i-1);
end;
end;