/
JvFullColorCtrls.pas
3868 lines (3461 loc) · 106 KB
/
JvFullColorCtrls.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: ColorCtrls.pas, released on 2004-09-11.
The Initial Developer of the Original Code is Florent Ouchet [ouchet dott florent att laposte dott net]
Portions created by Florent Ouchet are Copyright (C) 2004 Florent Ouchet.
All Rights Reserved.
Contributor(s): -
You may retrieve the latest version of this file at the Project JEDI's JVCL home page,
located at http://jvcl.delphi-jedi.org
Known Issues:
-----------------------------------------------------------------------------}
// $Id$
unit JvFullColorCtrls;
{$I jvcl.inc}
interface
uses
{$IFDEF UNITVERSIONING}
JclUnitVersioning,
{$ENDIF UNITVERSIONING}
Windows, Messages, SysUtils, Classes, Controls, Graphics,
ComCtrls, StdCtrls, ExtCtrls, Types,
JvJCLUtils, JvTypes, JvCombobox, JvFullColorSpaces, JvFullColorRotate;
type
TJvFullColorAxisConfig = (acXYZ, acXZY, acYXZ, acYZX, acZXY, acZYX);
TJvFullColorOrientation = (coNormal, coInverse);
TJvArrowPosition = (apNormal, apOpposite);
type
TJvKeyCode = (kcLeft, kcRight, kcUp, kcDown);
TJvFullColorMouseEvent = procedure(Sender: TObject; ColorX, ColorY: Byte) of object;
TJvFullColorComponent = class;
TJvFullColorPanel = class;
TJvFullColorCircle = class;
TJvFullColorTrackBar = class;
EJvFullColorError = class(EJVCLException);
TJvFullColorComponent = class(TCustomControl)
private
FAutoMouse: Boolean;
FFullColor: TJvFullColor;
FAxisConfig: TJvFullColorAxisConfig;
FOnColorChange: TNotifyEvent;
FOnAxisConfigChange: TNotifyEvent;
FOnColorSpaceChange: TNotifyEvent;
FOnMouseColor: TJvFullColorMouseEvent;
FColorChanging: Boolean;
FBuffer: TBitmap;
FCreating: Boolean;
FWantDrawBuffer: Boolean;
FMouseDragging: Boolean;
function GetColorSpace: TJvColorSpace;
procedure SetAxisConfig(const Value: TJvFullColorAxisConfig);
procedure WMGetDlgCode(var Msg: TWMGetDlgCode); message WM_GETDLGCODE;
procedure CMColorChanged(var Msg: TMessage); message CM_COLORCHANGED;
procedure CMSysColorChange(var Msg: TMessage); message CM_SYSCOLORCHANGE;
procedure SetWantDrawBuffer(Value: Boolean);
protected
procedure Paint; override;
procedure KeyDown(var Key: Word; Shift: TShiftState); override;
procedure DoEnter; override;
procedure DoExit; override;
procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
procedure MouseMove(Shift: TShiftState; X, Y: Integer); override;
procedure MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
procedure DrawFocus;
procedure DrawFrame(X, Y: Integer);
procedure SetFullColor(const Value: TJvFullColor); virtual;
procedure MouseColor(Shift: TShiftState; X, Y: Integer); virtual;
procedure AxisConfigChange; virtual;
procedure DrawBuffer; virtual;
procedure ColorSpaceChange; virtual;
procedure CalcSize; virtual;
procedure KeyMove(KeyCode: TJvKeyCode; MoveCount: Integer); virtual;
procedure InvalidateCursor; virtual; abstract;
property WantDrawBuffer: Boolean read FWantDrawBuffer write SetWantDrawBuffer;
property MouseDragging: Boolean read FMouseDragging;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure SetBounds(ALeft, ATop, AWidth, AHeight: Integer); override;
property ColorSpace: TJvColorSpace read GetColorSpace;
published
property AutoMouse: Boolean read FAutoMouse write FAutoMouse default True;
property FullColor: TJvFullColor read FFullColor write SetFullColor;
property AxisConfig: TJvFullColorAxisConfig read FAxisConfig write SetAxisConfig default acXYZ;
property OnMouseMove;
property OnMouseDown;
property OnMouseUp;
property Color;
property ParentColor;
property TabOrder;
property TabStop default True;
property OnColorChange: TNotifyEvent read FOnColorChange write FOnColorChange;
property OnAxisConfigChange: TNotifyEvent read FOnAxisConfigChange write FOnAxisConfigChange;
property OnColorSpaceChange: TNotifyEvent read FOnColorSpaceChange write FOnColorSpaceChange;
property OnMouseColor: TJvFullColorMouseEvent read FOnMouseColor write FOnMouseColor;
end;
TJvFullColorComponent2D = class(TJvFullColorComponent)
private
FValueZAuto: Boolean;
FValueZ: Byte;
FAxisConfigChanging: Boolean;
procedure SetValueZ(const Value: Byte);
procedure SetValueZAuto(const Value: Boolean);
procedure UpdateDefaultValueZ;
function IsValueZStored: Boolean;
protected
procedure AxisConfigChange; override;
procedure ColorSpaceChange; override;
procedure TrackBarColorChange(Sender: TObject); virtual;
procedure TrackBarAxisConfigChange(Sender: TObject); virtual;
public
constructor Create(AOwner: TComponent); override;
published
property ValueZAuto: Boolean read FValueZAuto write SetValueZAuto stored False;
property ValueZ: Byte read FValueZ write SetValueZ stored IsValueZStored default 0;
end;
{$IFDEF RTL230_UP}
[ComponentPlatformsAttribute(pidWin32 or pidWin64)]
{$ENDIF RTL230_UP}
TJvFullColorPanel = class(TJvFullColorComponent2D)
private
FReverseAxisY: Boolean;
FReverseAxisX: Boolean;
FCrossSize: Integer;
FPen: TPen;
FCrossCenter: Integer;
FColorTrackBar: TJvFullColorTrackBar;
FAxisConfigChanging: Boolean;
procedure SetReverseAxisX(const Value: Boolean);
procedure SetReverseAxisY(const Value: Boolean);
procedure SetCrossSize(Value: Integer);
procedure SetCrossCenter(Value: Integer);
procedure SetPen(const Value: TPen);
procedure SetColorTrackBar(const Value: TJvFullColorTrackBar);
protected
procedure PenChange(Sender: TObject);
procedure MouseColor(Shift: TShiftState; X, Y: Integer); override;
procedure Notification(AComponent: TComponent; Operation: TOperation); override;
procedure SetFullColor(const Value: TJvFullColor); override;
procedure DrawBuffer; override;
procedure CalcSize; override;
procedure AxisConfigChange; override;
procedure KeyMove(KeyCode: TJvKeyCode; MoveCount: Integer); override;
procedure InvalidateCursor; override;
function GetCursorPosition: TPoint;
procedure Paint; override;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
published
property ReverseAxisX: Boolean read FReverseAxisX write SetReverseAxisX default False;
property ReverseAxisY: Boolean read FReverseAxisY write SetReverseAxisY default False;
property CrossSize: Integer read FCrossSize write SetCrossSize default 5;
property CrossCenter: Integer read FCrossCenter write SetCrossCenter default 1;
property CrossStyle: TPen read FPen write SetPen;
property ColorTrackBar: TJvFullColorTrackBar read FColorTrackBar write SetColorTrackBar;
end;
TJvFullColorCircleStyle = (csShowLines, csShowCommon, csShowRed, csShowGreen,
csShowBlue, cs3ButtonsMouse, cs3ButtonsCommon);
TJvFullColorCircleStyles = set of TJvFullColorCircleStyle;
{$IFDEF RTL230_UP}
[ComponentPlatformsAttribute(pidWin32 or pidWin64)]
{$ENDIF RTL230_UP}
TJvFullColorCircle = class(TJvFullColorComponent2D)
private
FStyles: TJvFullColorCircleStyles;
FGreenColor: TJvFullColor;
FBlueColor: TJvFullColor;
FRedColor: TJvFullColor;
FInvertRotation: Boolean;
FInvertRadius: Boolean;
FCrossCenter: Integer;
FCrossSize: Integer;
FCrossStyle: TPen;
FLineWidth: Integer;
FDraggingColor: TJvRotateColor;
FOnRedColorChange: TNotifyEvent;
FOnBlueColorChange: TNotifyEvent;
FOnGreenColorChange: TNotifyEvent;
FOnColorSpaceChange: TNotifyEvent;
FBlueColorTrackBar: TJvFullColorTrackBar;
FGreenColorTrackBar: TJvFullColorTrackBar;
FRedColorTrackBar: TJvFullColorTrackBar;
FCommonColorTrackBar: TJvFullColorTrackBar;
FCrossRedColor: TColor;
FCrossBlueColor: TColor;
FCrossGreenColor: TColor;
procedure SetBlueColor(const Value: TJvFullColor);
procedure SetGreenColor(const Value: TJvFullColor);
procedure SetRedColor(const Value: TJvFullColor);
procedure SetStyles(const Value: TJvFullColorCircleStyles);
procedure SetInvertRadius(const Value: Boolean);
procedure SetInvertRotation(const Value: Boolean);
procedure SetCrossCenter(Value: Integer);
procedure SetCrossSize(Value: Integer);
procedure SetCrossStyle(const Value: TPen);
procedure SetLineWidth(Value: Integer);
procedure SetBlueColorTrackBar(const Value: TJvFullColorTrackBar);
procedure SetGreenColorTrackBar(const Value: TJvFullColorTrackBar);
procedure SetRedColorTrackBar(const Value: TJvFullColorTrackBar);
procedure SetCommonColorTrackBar(const Value: TJvFullColorTrackBar);
procedure SetCrossBlueColor(const Value: TColor);
procedure SetCrossGreenColor(const Value: TColor);
procedure SetCrossRedColor(const Value: TColor);
protected
procedure AxisConfigChange; override;
procedure ColorSpaceChange; override;
procedure Paint; override;
procedure InvalidateColors(AColor1, AColor2: TJvFullColor);
procedure PenChanged(Sender: TObject);
procedure DrawBuffer; override;
procedure CalcSize; override;
procedure SetFullColor(const Value: TJvFullColor); override;
procedure MouseUp(Button: TMouseButton; Shift: TShiftState;
X, Y: Integer); override;
procedure MouseColor(Shift: TShiftState;
X, Y: Integer); override;
procedure KeyMove(KeyCode: TJvKeyCode; MoveCount: Integer); override;
procedure Notification(AComponent: TComponent; Operation: TOperation); override;
procedure TrackBarColorChange(Sender: TObject); override;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure ConvertToID(NewFullColor: TJvFullColor);
function FullColorToPosition(AFullColor: TJvFullColor): TPoint;
function PositionToFullColor(APoint: TPoint): TJvFullColor;
published
property Color;
property ParentColor;
property InvertRadius: Boolean read FInvertRadius write SetInvertRadius default False;
property InvertRotation: Boolean read FInvertRotation write SetInvertRotation default False;
property RedColor: TJvFullColor read FRedColor write SetRedColor default fclRGBRed;
property GreenColor: TJvFullColor read FGreenColor write SetGreenColor default fclRGBLime;
property BlueColor: TJvFullColor read FBlueColor write SetBlueColor default fclRGBBlue;
property Styles: TJvFullColorCircleStyles read FStyles write SetStyles
default [csShowLines, csShowRed, csShowGreen, csShowBlue];
property CrossSize: Integer read FCrossSize write SetCrossSize default 5;
property CrossCenter: Integer read FCrossCenter write SetCrossCenter default 1;
property CrossStyle: TPen read FCrossStyle write SetCrossStyle;
property CrossRedColor: TColor read FCrossRedColor write SetCrossRedColor default clMaroon;
property CrossGreenColor: TColor read FCrossGreenColor write SetCrossGreenColor default clGreen;
property CrossBlueColor: TColor read FCrossBlueColor write SetCrossBlueColor default clNavy;
property LineWidth: Integer read FLineWidth write SetLineWidth default 1;
property RedTrackBar: TJvFullColorTrackBar read FRedColorTrackBar write SetRedColorTrackBar;
property GreenTrackBar: TJvFullColorTrackBar read FGreenColorTrackBar write SetGreenColorTrackBar;
property BlueTrackBar: TJvFullColorTrackBar read FBlueColorTrackBar write SetBlueColorTrackBar;
property CommonTrackBar: TJvFullColorTrackBar read FCommonColorTrackBar write SetCommonColorTrackBar;
property OnRedColorChange: TNotifyEvent read FOnRedColorChange write FOnRedColorChange;
property OnGreenColorChange: TNotifyEvent read FOnGreenColorChange write FOnGreenColorChange;
property OnBlueColorChange: TNotifyEvent read FOnBlueColorChange write FOnBlueColorChange;
property OnColorSpaceChange: TNotifyEvent read FOnColorSpaceChange write FOnColorSpaceChange;
end;
TJvCursorPoints = array [0..2] of TPoint;
{$IFDEF RTL230_UP}
[ComponentPlatformsAttribute(pidWin32 or pidWin64)]
{$ENDIF RTL230_UP}
TJvFullColorTrackBar = class(TJvFullColorComponent)
private
FArrowPosition: TJvArrowPosition;
FColorOrientation: TJvFullColorOrientation;
FOrientation: TTrackBarOrientation;
FFullColorDrawing: Boolean;
FArrowWidth: Integer;
FArrowColor: TColor;
FValueYAuto: Boolean;
FValueXAuto: Boolean;
FValueY: Byte;
FValueX: Byte;
FLink: TComponent;
procedure SetArrowPosition(const Value: TJvArrowPosition);
procedure SetColorOrientation(const Value: TJvFullColorOrientation);
procedure SetOrientation(const Value: TTrackBarOrientation);
procedure SetArrowWidth(const Value: Integer);
procedure SetArrowColor(const Value: TColor);
function IsValueXStored: Boolean;
function IsValueYStored: Boolean;
procedure SetValueX(const Value: Byte);
procedure SetValueXAuto(const Value: Boolean);
procedure SetValueY(const Value: Byte);
procedure SetValueYAuto(const Value: Boolean);
procedure UpdateDefaultValueX;
procedure UpdateDefaultValueY;
procedure SetFullColorDrawing(const Value: Boolean);
protected
procedure MouseColor(Shift: TShiftState; X, Y: Integer); override;
procedure SetFullColor(const Value: TJvFullColor); override;
procedure CalcSize; override;
procedure DrawBuffer; override;
procedure ColorSpaceChange; override;
procedure AxisConfigChange; override;
procedure KeyMove(KeyCode: TJvKeyCode; MoveCount: Integer); override;
procedure InvalidateCursor; override;
procedure Paint; override;
function GetCursorPosition: TJvCursorPoints;
public
constructor Create(AOwner: TComponent); override;
function Linked: Boolean;
function LinkerName: TComponentName;
procedure SetLink(AComponent: TComponent);
procedure FreeLink;
published
property ArrowColor: TColor read FArrowColor write SetArrowColor default clBlack;
property ArrowWidth: Integer read FArrowWidth write SetArrowWidth default 9;
property ArrowPosition: TJvArrowPosition read FArrowPosition write SetArrowPosition default apNormal;
property ColorOrientation: TJvFullColorOrientation read FColorOrientation write SetColorOrientation
default coNormal;
property Orientation: TTrackBarOrientation read FOrientation write SetOrientation default trHorizontal;
property ValueX: Byte read FValueX write SetValueX stored IsValueXStored;
property ValueXAuto: Boolean read FValueXAuto write SetValueXAuto stored False;
property ValueY: Byte read FValueY write SetValueY stored IsValueYStored;
property ValueYAuto: Boolean read FValueYAuto write SetValueYAuto stored False;
property FullColorDrawing: Boolean read FFullColorDrawing write SetFullColorDrawing default True;
end;
TJvShapePosition = (spLeft, spRight, spTop, spBottom);
{$IFDEF RTL230_UP}
[ComponentPlatformsAttribute(pidWin32 or pidWin64)]
{$ENDIF RTL230_UP}
TJvFullColorLabel = class(TGraphicControl)
private
FBrush: TBrush;
FPen: TPen;
FCaption: TCaption;
FShapeType: TShapeType;
FShapeWidth: Integer;
FShapeHeight: Integer;
FShapePosition: TJvShapePosition;
FSpacing: Integer;
FRoundShapeWidth: Integer;
FRoundShapeHeight: Integer;
FLabelColor: TJvFullColor;
procedure SetCaption(const Value: TCaption);
procedure SetShapeType(const Value: TShapeType);
procedure SetShapeHeight(const Value: Integer);
procedure SetShapePosition(const Value: TJvShapePosition);
procedure SetShapeWidth(const Value: Integer);
procedure SetSpacing(const Value: Integer);
procedure SetRoundShapeHeight(const Value: Integer);
procedure SetRoundShapeWidth(const Value: Integer);
procedure SetLabelColor(const Value: TJvFullColor);
procedure SetBrush(const Value: TBrush);
procedure SetPen(const Value: TPen);
protected
procedure Paint; override;
procedure CalcSize;
procedure SetAutoSize(Value: Boolean); override;
procedure GraphicChange(Sender: TObject);
procedure SetName(const Value: TComponentName); override;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
published
property LabelColor: TJvFullColor read FLabelColor write SetLabelColor default fclDEFWindowText;
property Pen: TPen read FPen write SetPen;
property Brush: TBrush read FBrush write SetBrush;
property Shape: TShapeType read FShapeType write SetShapeType default stRectangle;
property Caption: TCaption read FCaption write SetCaption;
property ShapeWidth: Integer read FShapeWidth write SetShapeWidth default 16;
property ShapeHeight: Integer read FShapeHeight write SetShapeHeight default 16;
property ShapePosition: TJvShapePosition read FShapePosition write SetShapePosition default spLeft;
property Spacing: Integer read FSpacing write SetSpacing default 5;
property RoundShapeWidth: Integer read FRoundShapeWidth write SetRoundShapeWidth default 4;
property RoundShapeHeight: Integer read FRoundShapeHeight write SetRoundShapeHeight default 4;
property Align;
property Anchors;
property AutoSize;
property BiDiMode;
property Color nodefault;
property Constraints;
property DragCursor;
property DragKind;
property DragMode;
property Enabled;
property Font;
property ParentBiDiMode;
property ParentColor;
property ParentFont;
property ParentShowHint;
property PopupMenu;
property ShowHint;
property Visible;
property OnCanResize;
property OnClick;
property OnConstrainedResize;
property OnContextPopup;
property OnDblClick;
property OnDragDrop;
property OnDragOver;
property OnEndDock;
property OnEndDrag;
property OnMouseDown;
property OnMouseMove;
property OnMouseUp;
property OnMouseWheel;
property OnMouseWheelDown;
property OnMouseWheelUp;
property OnResize;
property OnStartDock;
property OnStartDrag;
end;
TJvFullColorSpaceFormat = (cfName, cfShortName, cfBoth);
TJvFullColorSpaceFormatEvent = procedure(Sender: TObject; AColorSpace: TJvColorSpace;
out ACaption: string) of object;
{$IFDEF RTL230_UP}
[ComponentPlatformsAttribute(pidWin32 or pidWin64)]
{$ENDIF RTL230_UP}
TJvFullColorSpaceCombo = class(TJvCustomComboBox)
private
FAllowVariable: Boolean;
FItemFormat: TJvFullColorSpaceFormat;
FOnFormatItem: TJvFullColorSpaceFormatEvent;
function GetColorSpace: TJvColorSpace;
procedure SetAllowVariable(const Value: Boolean);
procedure SetColorSpace(const Value: TJvColorSpace);
procedure SetColorSpaceID(const Value: TJvFullColorSpaceID);
function GetColorSpaceID: TJvFullColorSpaceID;
procedure SetItemFormat(const Value: TJvFullColorSpaceFormat);
protected
procedure CreateWnd; override;
public
constructor Create(AOwner: TComponent); override;
property SelectedSpace: TJvColorSpace read GetColorSpace write SetColorSpace;
procedure MakeList; virtual;
published
property AllowVariable: Boolean read FAllowVariable write SetAllowVariable default True;
property ColorSpaceID: TJvFullColorSpaceID read GetColorSpaceID write SetColorSpaceID default csRGB;
property ItemFormat: TJvFullColorSpaceFormat read FItemFormat write SetItemFormat default cfBoth;
property OnFormatItem: TJvFullColorSpaceFormatEvent read FOnFormatItem write FOnFormatItem;
property AutoDropDown;
property BevelEdges;
property BevelInner;
property BevelKind default bkNone;
property BevelOuter;
property Anchors;
property BiDiMode;
property Color;
property Constraints;
property DragCursor;
property DragKind;
property DragMode;
property DropDownCount;
property Enabled;
property Flat;
property ParentFlat;
property Font;
property ImeMode;
property ImeName;
property ItemHeight;
property ParentBiDiMode;
property ParentColor;
property ParentFont;
property ParentShowHint;
property PopupMenu;
property ShowHint;
property Sorted;
property TabOrder;
property TabStop;
property Visible;
property OnChange;
property OnClick;
property OnCloseUp;
property OnContextPopup;
property OnDblClick;
property OnDragDrop;
property OnDragOver;
property OnDrawItem;
property OnDropDown;
property OnEndDock;
property OnEndDrag;
property OnEnter;
property OnExit;
property OnKeyDown;
property OnKeyPress;
property OnKeyUp;
property OnMeasureItem;
property OnSelect;
property OnStartDock;
property OnStartDrag;
end;
TJvFullColorAxisConfigFormat = (afShort, afIndent, afComplete);
TJvFullColorAxisFormatEvent = procedure(Sender: TObject; AAxisConfig: TJvFullColorAxisConfig;
out ACaption: string) of object;
{$IFDEF RTL230_UP}
[ComponentPlatformsAttribute(pidWin32 or pidWin64)]
{$ENDIF RTL230_UP}
TJvFullColorAxisCombo = class(TJvCustomComboBox)
private
FItemFormat: TJvFullColorAxisConfigFormat;
FColorID: TJvFullColorSpaceID;
FOnFormatItem: TJvFullColorAxisFormatEvent;
procedure SetItemFormat(const Value: TJvFullColorAxisConfigFormat);
procedure SetSelected(const Value: TJvFullColorAxisConfig);
procedure SetColorID(const Value: TJvFullColorSpaceID);
function GetSelected: TJvFullColorAxisConfig;
procedure SetOnFormatItem(const Value: TJvFullColorAxisFormatEvent);
protected
procedure MakeList; virtual;
procedure CreateWnd; override;
public
constructor Create(AOwner: TComponent); override;
published
property ItemFormat: TJvFullColorAxisConfigFormat read FItemFormat write SetItemFormat default afComplete;
property Selected: TJvFullColorAxisConfig read GetSelected write SetSelected;
property ColorID: TJvFullColorSpaceID read FColorID write SetColorID default csRGB;
property OnFormatItem: TJvFullColorAxisFormatEvent read FOnFormatItem write SetOnFormatItem;
property AutoDropDown;
property BevelEdges;
property BevelInner;
property BevelKind default bkNone;
property BevelOuter;
property Anchors;
property BiDiMode;
property Color;
property Constraints;
property DragCursor;
property DragKind;
property DragMode;
property DropDownCount;
property Enabled;
property Flat;
property ParentFlat;
property Font;
property ImeMode;
property ImeName;
property ItemHeight;
property ParentBiDiMode;
property ParentColor;
property ParentFont;
property ParentShowHint;
property PopupMenu;
property ShowHint;
property Sorted;
property TabOrder;
property TabStop;
property Visible;
property OnChange;
property OnClick;
property OnCloseUp;
property OnContextPopup;
property OnDblClick;
property OnDragDrop;
property OnDragOver;
property OnDrawItem;
property OnDropDown;
property OnEndDock;
property OnEndDrag;
property OnEnter;
property OnExit;
property OnKeyDown;
property OnKeyPress;
property OnKeyUp;
property OnMeasureItem;
property OnSelect;
property OnStartDock;
property OnStartDrag;
end;
TJvFullColorArray = array [0..{$IFDEF RTL230_UP}MaxInt div 16{$ELSE}MaxListSize{$ENDIF RTL230_UP} - 1] of TJvFullColor;
PJvFullColorArray = ^TJvFullColorArray;
TJvFullColorListOperation = (foAllChanged, foDeleted, foAdded, foChanged);
TJvFullColorListEvent = procedure(Sender: TObject; Index: Integer;
Operation: TJvFullColorListOperation) of object;
EJvFullColorListError = class(Exception);
TJvFullColorList = class(TPersistent)
private
FCapacity: Integer;
FCount: Integer;
FList: PJvFullColorArray;
FOnChange: TJvFullColorListEvent;
FUpdateCount: Integer;
FAllocBy: Integer;
procedure SetCapacity(const Value: Integer);
procedure SetCount(const Value: Integer);
procedure SetAllocBy(const Value: Integer);
protected
procedure Grow;
function GetItem(Index: Integer): TJvFullColor;
procedure SetItem(Index: Integer; const Value: TJvFullColor);
procedure DefineProperties(Filer: TFiler); override;
procedure WriteItems(Writer: TWriter);
procedure ReadItems(Reader: TReader);
procedure Change(AIndex: Integer; AOperation: TJvFullColorListOperation);
public
constructor Create;
destructor Destroy; override;
function Add(AColor: TJvFullColor): Integer;
procedure Assign(Source: TPersistent); override;
procedure Clear;
function Remove(AColor: TJvFullColor): Integer;
procedure Delete(Index: Integer);
procedure Exchange(Index1, Index2: Integer);
procedure Insert(Index: Integer; AColor: TJvFullColor);
function IndexOf(AColor: TJvFullColor): Integer;
procedure DeleteRedundant;
procedure BeginUpdate;
procedure EndUpdate;
property AllocBy: Integer read FAllocBy write SetAllocBy;
property Items[Index: Integer]: TJvFullColor read GetItem write SetItem; default;
property List: PJvFullColorArray read FList;
property Capacity: Integer read FCapacity write SetCapacity;
property Count: Integer read FCount write SetCount;
property UpdateCount: Integer read FUpdateCount;
property OnChange: TJvFullColorListEvent read FOnChange write FOnChange;
end;
TJvFullColorEdge = (feRaised, feLowered, feFlat);
TJvFormatHintEvent = procedure(Sender: TObject; HintColor: TJvFullColor;
var HintText: string) of object;
{$IFDEF RTL230_UP}
[ComponentPlatformsAttribute(pidWin32 or pidWin64)]
{$ENDIF RTL230_UP}
TJvFullColorGroup = class(TCustomControl)
private
FItems: TJvFullColorList;
FColCount: Integer;
FEdge: TJvFullColorEdge;
FSelectedEdge: TJvFullColorEdge;
FMouseEdge: TJvFullColorEdge;
FSquareSize: Integer;
FMouseIndex: Integer;
FSelectedIndex: Integer;
FBrush: TBrush;
FOnChange: TNotifyEvent;
FOnFormatHint: TJvFormatHintEvent;
procedure SetItems(const Value: TJvFullColorList);
procedure SetColCount(const Value: Integer);
function GetRowCount: Integer;
procedure SetEdge(const Value: TJvFullColorEdge);
procedure SetMouseEdge(const Value: TJvFullColorEdge);
procedure SetSelectedEdge(const Value: TJvFullColorEdge);
procedure SetSquareSize(const Value: Integer);
function GetSelected: TJvFullColor;
procedure SetSelected(const Value: TJvFullColor);
procedure SetSelectedIndex(const Value: Integer);
procedure SetBrush(const Value: TBrush);
procedure MouseLeave(var Msg: TWMMouse); message WM_MOUSELEAVE;
procedure CMHintShow(var Msg: TMessage); message CM_HINTSHOW;
protected
procedure Paint; override;
procedure ItemsChange(Sender: TObject; Index: Integer;
Operation: TJvFullColorListOperation);
procedure BrushChange(Sender: TObject);
procedure MouseDown(Button: TMouseButton; Shift: TShiftState;
X, Y: Integer); override;
procedure MouseMove(Shift: TShiftState; X, Y: Integer); override;
procedure CalcRects(out XPos, YPos, XInc, YInc: Integer);
procedure InvalidateIndex(AIndex: Integer);
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
property MouseIndex: Integer read FMouseIndex;
property SelectedIndex: Integer read FSelectedIndex write SetSelectedIndex;
property Selected: TJvFullColor read GetSelected write SetSelected;
property RowCount: Integer read GetRowCount;
published
property Items: TJvFullColorList read FItems write SetItems;
property ColCount: Integer read FColCount write SetColCount default 4;
property Edge: TJvFullColorEdge read FEdge write SetEdge default feRaised;
property SelectedEdge: TJvFullColorEdge read FSelectedEdge write SetSelectedEdge default feLowered;
property MouseEdge: TJvFullColorEdge read FMouseEdge write SetMouseEdge default feRaised;
property SquareSize: Integer read FSquareSize write SetSquareSize default 6;
property Brush: TBrush read FBrush write SetBrush;
property OnChange: TNotifyEvent read FOnChange write FOnChange;
property OnFormatHint: TJvFormatHintEvent read FOnFormatHint write FOnFormatHint;
property Align;
property Anchors;
property BevelInner;
property BevelOuter;
property BevelEdges;
property BevelKind default bkTile;
property BevelWidth;
property BorderWidth;
property Color;
property Constraints;
property Hint;
property ParentShowHint;
property ParentColor;
property ShowHint;
property Visible;
end;
function GetIndexAxis(AxisConfig: TJvFullColorAxisConfig; AxisID: TJvAxisIndex): TJvAxisIndex;
function GetIndexAxisX(AxisConfig: TJvFullColorAxisConfig): TJvAxisIndex;
function GetIndexAxisY(AxisConfig: TJvFullColorAxisConfig): TJvAxisIndex;
function GetIndexAxisZ(AxisConfig: TJvFullColorAxisConfig): TJvAxisIndex;
function ColorSpaceToString(AColorSpace: TJvColorSpace;
ItemFormat: TJvFullColorSpaceFormat): string;
function AxisConfigToString(AxisConfig: TJvFullColorAxisConfig;
ItemFormat: TJvFullColorAxisConfigFormat; AColorSpace: TJvColorSpace): string;
{$IFDEF UNITVERSIONING}
const
UnitVersioning: TUnitVersionInfo = (
RCSfile: '$URL$';
Revision: '$Revision$';
Date: '$Date$';
LogPath: 'JVCL\run'
);
{$ENDIF UNITVERSIONING}
implementation
uses
RTLConsts, TypInfo, Forms,
JclMath, JclLogic, // For EnsureRange and Min/Max
{$IFDEF HAS_UNIT_SYSTEM_UITYPES}
System.UITypes,
{$ENDIF}
JvResources, JvConsts, JvJVCLUtils;
type
TJvFullColorAxisConfigs = array [TJvAxisIndex] of TJvAxisIndex;
const
TabAxisConfigs: array [TJvFullColorAxisConfig] of TJvFullColorAxisConfigs =
((axIndex0, axIndex1, axIndex2),
(axIndex0, axIndex2, axIndex1),
(axIndex1, axIndex0, axIndex2),
(axIndex2, axIndex0, axIndex1),
(axIndex1, axIndex2, axIndex0),
(axIndex2, axIndex1, axIndex0));
function ColorSpaceToString(AColorSpace: TJvColorSpace; ItemFormat: TJvFullColorSpaceFormat): string;
begin
case ItemFormat of
cfName:
Result := AColorSpace.Name;
cfShortName:
Result := AColorSpace.ShortName;
else
Result := Format('%s (%s)', [AColorSpace.Name, AColorSpace.ShortName]);
end;
end;
function AxisConfigToString(AxisConfig: TJvFullColorAxisConfig;
ItemFormat: TJvFullColorAxisConfigFormat; AColorSpace: TJvColorSpace): string;
var
Str: string;
AxisConfigs: TJvFullColorAxisConfigs;
begin
Str := GetEnumName(TypeInfo(TJvFullColorAxisConfig), Ord(AxisConfig));
case ItemFormat of
afShort:
Result := Copy(Str, 3, Length(Str) - 2);
afIndent:
Result := Str;
else
AxisConfigs := TabAxisConfigs[AxisConfig];
Result := Format('[%s] = %s ; [%s] = %s ; [%s] = %s',
[Str[3], AColorSpace.AxisName[axIndex0], Str[4],
AColorSpace.AxisName[axIndex1], Str[5], AColorSpace.AxisName[axIndex2]]);
end;
end;
function GetIndexAxis(AxisConfig: TJvFullColorAxisConfig; AxisID: TJvAxisIndex): TJvAxisIndex;
begin
Result := TabAxisConfigs[AxisConfig][AxisID];
end;
function GetIndexAxisX(AxisConfig: TJvFullColorAxisConfig): TJvAxisIndex;
begin
Result := TabAxisConfigs[AxisConfig][axIndex0];
end;
function GetIndexAxisY(AxisConfig: TJvFullColorAxisConfig): TJvAxisIndex;
begin
Result := TabAxisConfigs[AxisConfig][axIndex1];
end;
function GetIndexAxisZ(AxisConfig: TJvFullColorAxisConfig): TJvAxisIndex;
begin
Result := TabAxisConfigs[AxisConfig][axIndex2];
end;
//=== { TJvColorComponent } ==================================================
constructor TJvFullColorComponent.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FBuffer := TBitmap.Create;
FBuffer.PixelFormat := pf32Bit;
FAutoMouse := True;
FAxisConfig := acXYZ;
FFullColor := fclRGBWhite;
TabStop := True;
ControlStyle := [csSetCaption, csOpaque];
Width := 100;
Height := 100;
end;
destructor TJvFullColorComponent.Destroy;
begin
FBuffer.Free;
inherited Destroy;
end;
procedure TJvFullColorComponent.SetBounds(ALeft, ATop, AWidth,
AHeight: Integer);
begin
inherited SetBounds(ALeft, ATop, AWidth, AHeight);
CalcSize;
end;
procedure TJvFullColorComponent.CalcSize;
begin
WantDrawBuffer := True;
end;
procedure TJvFullColorComponent.DrawBuffer;
begin
Invalidate;
end;
procedure TJvFullColorComponent.Paint;
begin
if WantDrawBuffer then
DrawBuffer;
WantDrawBuffer := False;
inherited Paint;
end;
procedure TJvFullColorComponent.DrawFocus;
begin
if Focused and not (csDesigning in ComponentState) then
with Canvas do
begin
Pen.Color := Color;
Brush.Color := Color;
DrawFocusRect(ClientRect);
end;
end;
procedure TJvFullColorComponent.DrawFrame(X, Y: Integer);
begin
Canvas.Brush.Color := Color;
Canvas.FillRect(Rect(0, 0, Width, Y));
Canvas.FillRect(Rect(0, Y + FBuffer.Height, Width, Height));
Canvas.FillRect(Rect(0, Y, X, Y + FBuffer.Height));
Canvas.FillRect(Rect(X + FBuffer.Width, Y, Width, Y + FBuffer.Height));
end;
procedure TJvFullColorComponent.SetFullColor(const Value: TJvFullColor);
var
NewColorID: TJvFullColorSpaceID;
OldColorID: TJvFullColorSpaceID;
OldColor: TJvFullColor;
begin
if Value <> FullColor then
begin
OldColor := FFullColor;
NewColorID := ColorSpaceManager.GetColorSpaceID(Value);
if NewColorID = csDEF then
raise EJvFullColorError.CreateResFmt(@RsEUnsupportedColorSpace, [NewColorID]);
OldColorID := ColorSpaceManager.GetColorSpaceID(OldColor);
FFullColor := Value;
if OldColorID <> ColorSpaceManager.GetColorSpaceID(FFullColor) then
ColorSpaceChange;
if Assigned(FOnColorChange) then
FOnColorChange(Self);
end;
end;
procedure TJvFullColorComponent.MouseColor(Shift: TShiftState; X, Y: Integer);
begin
if Assigned(FOnMouseColor) then
FOnMouseColor(Self, X, Y);
end;
procedure TJvFullColorComponent.MouseDown(Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
SetFocus;
try
if AutoMouse and (Shift * [ssLeft, ssMiddle, ssRight] <> []) then
begin
FMouseDragging := True;
MouseColor(Shift, X, Y);
end;
inherited MouseDown(Button, Shift, X, Y);
finally
SetCapture(Handle);
end;
end;
procedure TJvFullColorComponent.MouseMove(Shift: TShiftState; X, Y: Integer);
begin
if MouseDragging and AutoMouse and (Shift * [ssLeft, ssMiddle, ssRight] <> []) then
MouseColor(Shift, X, Y);
inherited MouseMove(Shift, X, Y);
end;
procedure TJvFullColorComponent.MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
try
FMouseDragging := False;
inherited MouseUp(Button, Shift, X, Y);
finally
ReleaseCapture;
end;
end;
procedure TJvFullColorComponent.SetAxisConfig(const Value: TJvFullColorAxisConfig);
begin
if FAxisConfig <> Value then
begin
FAxisConfig := Value;
AxisConfigChange;
end;
end;
procedure TJvFullColorComponent.ColorSpaceChange;
begin
CalcSize;
if Assigned(FOnColorSpaceChange) then
FOnColorSpaceChange(Self);
end;
function TJvFullColorComponent.GetColorSpace: TJvColorSpace;
begin
with ColorSpaceManager do
Result := ColorSpace[GetColorSpaceID(FullColor)];
end;
procedure TJvFullColorComponent.AxisConfigChange;
begin
CalcSize;
if Assigned(FOnAxisConfigChange) then
FOnAxisConfigChange(Self);
end;
procedure TJvFullColorComponent.SetWantDrawBuffer(Value: Boolean);
begin
FWantDrawBuffer := Value;
if Value and (Width <> 0) and (Height <> 0) then
Invalidate;
end;
procedure TJvFullColorComponent.WMGetDlgCode(var Msg: TWMGetDlgCode);
begin
inherited;
Msg.Result := DLGC_WANTARROWS;
end;
procedure TJvFullColorComponent.DoEnter;
begin
inherited DoEnter;
Invalidate;
end;
procedure TJvFullColorComponent.DoExit;
begin
inherited DoExit;
Invalidate;
end;
procedure TJvFullColorComponent.KeyMove(KeyCode: TJvKeyCode; MoveCount: Integer);
begin
Invalidate;
end;