-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathColPicker.ctl
More file actions
2303 lines (2157 loc) · 80.8 KB
/
ColPicker.ctl
File metadata and controls
2303 lines (2157 loc) · 80.8 KB
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
VERSION 5.00
Begin VB.UserControl ColPicker
Appearance = 0 'Flat
BackColor = &H80000005&
ClientHeight = 7650
ClientLeft = 0
ClientTop = 0
ClientWidth = 2880
LockControls = -1 'True
ScaleHeight = 510
ScaleMode = 3 'Pixel
ScaleWidth = 192
ToolboxBitmap = "ColPicker.ctx":0000
Begin VB.Timer tmrKeyboard
Interval = 500
Left = 3270
Top = 7275
End
Begin VB.CheckBox chkAccel
Appearance = 0 'Flat
BackColor = &H80000005&
Caption = "Accelerate display"
Enabled = 0 'False
ForeColor = &H80000008&
Height = 252
Left = 45
TabIndex = 38
Top = 3330
Value = 1 'Checked
Visible = 0 'False
Width = 1776
End
Begin VB.CheckBox chkWebSafe
Appearance = 0 'Flat
BackColor = &H80000005&
Caption = "Web colors only"
ForeColor = &H80000008&
Height = 264
Left = 45
TabIndex = 37
Top = 3060
Width = 1632
End
Begin VB.Frame fraNumeric
Appearance = 0 'Flat
BackColor = &H80000005&
Caption = "Components"
ForeColor = &H80000008&
Height = 3090
Left = 45
TabIndex = 4
Top = 3585
Width = 2715
Begin VB.OptionButton optHue
Appearance = 0 'Flat
BackColor = &H80000005&
Caption = "&H"
ForeColor = &H80000008&
Height = 252
Left = 120
TabIndex = 33
Top = 360
Value = -1 'True
Width = 492
End
Begin VB.OptionButton optSat
Appearance = 0 'Flat
BackColor = &H80000005&
Caption = "&S"
ForeColor = &H80000008&
Height = 252
Left = 120
TabIndex = 32
Top = 720
Width = 492
End
Begin VB.OptionButton optBri
Appearance = 0 'Flat
BackColor = &H80000005&
Caption = "&B"
ForeColor = &H80000008&
Height = 252
Left = 120
TabIndex = 31
Top = 1080
Width = 492
End
Begin VB.OptionButton optRed
Appearance = 0 'Flat
BackColor = &H80000005&
Caption = "&R"
ForeColor = &H80000008&
Height = 252
Left = 1500
TabIndex = 30
Top = 360
Width = 492
End
Begin VB.OptionButton optBlue
Appearance = 0 'Flat
BackColor = &H80000005&
Caption = "&B"
ForeColor = &H80000008&
Height = 252
Left = 1500
TabIndex = 29
Top = 1080
Width = 492
End
Begin VB.OptionButton optGreen
Appearance = 0 'Flat
BackColor = &H80000005&
Caption = "&G"
ForeColor = &H80000008&
Height = 252
Left = 1500
TabIndex = 28
Top = 720
Width = 492
End
Begin VB.TextBox txtHue
Alignment = 1 'Right Justify
Appearance = 0 'Flat
Height = 252
Left = 615
MaxLength = 6
TabIndex = 27
Top = 360
Width = 432
End
Begin VB.TextBox txtSat
Alignment = 1 'Right Justify
Appearance = 0 'Flat
Height = 252
Left = 615
MaxLength = 6
TabIndex = 26
Top = 720
Width = 432
End
Begin VB.TextBox txtBri
Alignment = 1 'Right Justify
Appearance = 0 'Flat
Height = 252
Left = 615
MaxLength = 6
TabIndex = 25
Top = 1080
Width = 432
End
Begin VB.TextBox txtRed
Alignment = 1 'Right Justify
Appearance = 0 'Flat
Height = 252
Left = 1995
MaxLength = 6
TabIndex = 24
Top = 360
Width = 432
End
Begin VB.TextBox txtGreen
Alignment = 1 'Right Justify
Appearance = 0 'Flat
Height = 252
Left = 1995
MaxLength = 6
TabIndex = 23
Top = 720
Width = 432
End
Begin VB.TextBox txtBlue
Alignment = 1 'Right Justify
Appearance = 0 'Flat
Height = 252
Left = 1995
MaxLength = 6
TabIndex = 22
Top = 1080
Width = 432
End
Begin VB.PictureBox picAdditional
Appearance = 0 'Flat
BackColor = &H80000005&
BorderStyle = 0 'None
ForeColor = &H80000008&
Height = 1512
Left = 60
ScaleHeight = 1515
ScaleWidth = 2595
TabIndex = 5
Top = 1395
Width = 2592
Begin VB.TextBox txtBlack
Alignment = 1 'Right Justify
Appearance = 0 'Flat
Height = 252
Left = 1920
Locked = -1 'True
MaxLength = 3
TabIndex = 13
Top = 1140
Width = 615
End
Begin VB.TextBox txtYellow
Alignment = 1 'Right Justify
Appearance = 0 'Flat
Height = 252
Left = 1920
Locked = -1 'True
MaxLength = 3
TabIndex = 12
Top = 780
Width = 615
End
Begin VB.TextBox txtMagenta
Alignment = 1 'Right Justify
Appearance = 0 'Flat
Height = 252
Left = 1920
Locked = -1 'True
MaxLength = 3
TabIndex = 11
Top = 420
Width = 615
End
Begin VB.TextBox txtCyan
Alignment = 1 'Right Justify
Appearance = 0 'Flat
Height = 252
Left = 1920
Locked = -1 'True
MaxLength = 3
TabIndex = 10
Top = 60
Width = 615
End
Begin VB.TextBox txtLabB
Alignment = 1 'Right Justify
Appearance = 0 'Flat
Height = 252
Left = 540
Locked = -1 'True
MaxLength = 6
TabIndex = 9
Top = 780
Width = 615
End
Begin VB.TextBox txtLabA
Alignment = 1 'Right Justify
Appearance = 0 'Flat
Height = 252
Left = 540
Locked = -1 'True
MaxLength = 6
TabIndex = 8
Top = 420
Width = 615
End
Begin VB.TextBox txtLabLuminance
Alignment = 1 'Right Justify
Appearance = 0 'Flat
Height = 252
Left = 540
Locked = -1 'True
MaxLength = 6
TabIndex = 7
Top = 60
Width = 615
End
Begin VB.TextBox txtNewColor
Alignment = 2 'Center
Appearance = 0 'Flat
Height = 252
Left = 540
Locked = -1 'True
TabIndex = 6
TabStop = 0 'False
Top = 1200
Width = 855
End
Begin VB.Label Label10
Appearance = 0 'Flat
BackColor = &H80000005&
Caption = "K:"
ForeColor = &H80000008&
Height = 252
Left = 1680
TabIndex = 21
Top = 1140
Width = 372
End
Begin VB.Label Label9
Appearance = 0 'Flat
BackColor = &H80000005&
Caption = "Y:"
ForeColor = &H80000008&
Height = 252
Left = 1680
TabIndex = 20
Top = 780
Width = 372
End
Begin VB.Label Label8
Appearance = 0 'Flat
BackColor = &H80000005&
Caption = "M:"
ForeColor = &H80000008&
Height = 252
Left = 1680
TabIndex = 19
Top = 420
Width = 372
End
Begin VB.Label Label7
Appearance = 0 'Flat
BackColor = &H80000005&
Caption = "C:"
ForeColor = &H80000008&
Height = 252
Left = 1680
TabIndex = 18
Top = 60
Width = 372
End
Begin VB.Label Label6
Appearance = 0 'Flat
BackColor = &H80000005&
Caption = "b:"
ForeColor = &H80000008&
Height = 252
Left = 300
TabIndex = 17
Top = 780
Width = 372
End
Begin VB.Label Label5
Appearance = 0 'Flat
BackColor = &H80000005&
Caption = "a:"
ForeColor = &H80000008&
Height = 252
Left = 300
TabIndex = 16
Top = 420
Width = 372
End
Begin VB.Label Label4
Appearance = 0 'Flat
BackColor = &H80000005&
Caption = "L:"
ForeColor = &H80000008&
Height = 255
Left = 300
TabIndex = 15
Top = 75
Width = 375
End
Begin VB.Label Label3
Appearance = 0 'Flat
BackColor = &H80000005&
Caption = "#"
ForeColor = &H80000008&
Height = 252
Left = 300
TabIndex = 14
Top = 1200
Width = 252
End
End
Begin jsplus.ctxUpDown updBlue
Height = 270
Left = 2430
Top = 1080
Width = 165
_ExtentX = 291
_ExtentY = 476
End
Begin jsplus.ctxUpDown updBri
Height = 270
Left = 1050
Top = 1065
Width = 165
_ExtentX = 291
_ExtentY = 476
End
Begin jsplus.ctxUpDown updGreen
Height = 270
Left = 2430
Top = 720
Width = 165
_ExtentX = 291
_ExtentY = 476
End
Begin jsplus.ctxUpDown updSat
Height = 270
Left = 1050
Top = 705
Width = 165
_ExtentX = 291
_ExtentY = 476
End
Begin jsplus.ctxUpDown updRed
Height = 270
Left = 2430
Top = 360
Width = 165
_ExtentX = 291
_ExtentY = 476
End
Begin jsplus.ctxUpDown updHue
Height = 270
Left = 1050
Top = 345
Width = 165
_ExtentX = 291
_ExtentY = 476
End
Begin VB.Label lblH
Appearance = 0 'Flat
BackColor = &H80000005&
Caption = "°"
BeginProperty Font
Name = "Arial"
Size = 9.75
Charset = 204
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H80000008&
Height = 255
Left = 1260
TabIndex = 36
Top = 360
Width = 255
End
Begin VB.Label Label1
Appearance = 0 'Flat
BackColor = &H80000005&
Caption = "%"
ForeColor = &H80000008&
Height = 255
Left = 1260
TabIndex = 35
Top = 720
Width = 255
End
Begin VB.Label Label2
Appearance = 0 'Flat
BackColor = &H80000005&
Caption = "%"
ForeColor = &H80000008&
Height = 255
Left = 1260
TabIndex = 34
Top = 1080
Width = 255
End
End
Begin VB.Frame fraColors
Appearance = 0 'Flat
BackColor = &H80000005&
Caption = "Reference"
ForeColor = &H80000008&
Height = 825
Left = 45
TabIndex = 0
Top = 6690
Width = 2715
Begin VB.PictureBox picReference
Appearance = 0 'Flat
AutoRedraw = -1 'True
BackColor = &H80000005&
BorderStyle = 0 'None
ForeColor = &H80000008&
Height = 555
Left = 45
ScaleHeight = 37
ScaleMode = 3 'Pixel
ScaleWidth = 174
TabIndex = 1
TabStop = 0 'False
Top = 195
Width = 2610
Begin VB.Label labNew
Alignment = 2 'Center
Appearance = 0 'Flat
BackColor = &H000080FF&
ForeColor = &H80000008&
Height = 255
Left = -15
TabIndex = 3
Top = 240
Width = 795
End
Begin VB.Label labOld
Alignment = 2 'Center
Appearance = 0 'Flat
BackColor = &H000000FF&
ForeColor = &H80000008&
Height = 255
Left = -270
TabIndex = 2
Top = -15
Width = 810
End
End
End
Begin VB.Image imgRect
Height = 3000
Left = 60
MousePointer = 2 'Cross
Top = 30
Width = 2040
End
Begin VB.Image imgBar
Height = 3000
Left = 2205
MousePointer = 2 'Cross
Top = 30
Width = 240
End
End
Attribute VB_Name = "ColPicker"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit
'--- set to 1 NOT to compile accelerated gradients for win98/2k
#Const NO_ACCELERATED_GRADIENTS = 0
'=========================================================================
' UDTs and Enums
'=========================================================================
Private Enum UcsRgbColorIdx
ucsRgbRed
ucsRgbGreen
ucsRgbBlue
End Enum
Private Type UcsHsbColor
Hue As Double
Sat As Double
Bri As Double
End Type
Private Type UcsXyzColor
x As Double
y As Double
Z As Double
End Type
Private Type UcsLabColor
l As Double
a As Double
b As Double
End Type
Private Type UcsRgbQuad
r As Byte
G As Byte
b As Byte
a As Byte
End Type
Private Type UcsRgbTriple
b As Byte
G As Byte
r As Byte
End Type
Private Type UcsColorGraphicsCache
imgRect As StdPicture
imgBar As StdPicture
bWebSafe As Boolean
rgbColor As UcsRgbQuad
hsbColor As UcsHsbColor
End Type
'=========================================================================
' API
'=========================================================================
'--- for GetSystemMetrics
Private Const SM_CYCAPTION As Long = 4
Private Const SM_CYDLGFRAME As Long = 8
Private Const SM_CXDLGFRAME As Long = 7
'--- for SetStretchBltMode
Private Const HALFTONE As Long = 4
'--- for GradientFill
Private Const GRADIENT_FILL_RECT_H As Long = 0
Private Const GRADIENT_FILL_RECT_V As Long = 1
Private Const GRADIENT_FILL_TRIANGLE As Long = 2
Private Declare Function OleTranslateColor Lib "oleaut32.dll" (ByVal lOleColor As Long, ByVal lHPalette As Long, lColorRef As Any) As Long
Private Declare Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
Private Declare Function GetClientRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Private Declare Function InvalidateRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT, ByVal bErase As Long) As Long
Private Declare Function SetStretchBltMode Lib "gdi32" (ByVal hdc As Long, ByVal nStretchMode As Long) As Long
Private Declare Function GradientFill Lib "Msimg32.dll" (ByVal hdc As Long, pVertex As TRIVERTEX, ByVal dwNumVertex As Long, pMesh As GRADIENT_TRIANGLE, ByVal dwNumMesh As Long, ByVal dwMode As Long) As Long
Private Declare Function GradientFillRect Lib "Msimg32.dll" Alias "GradientFill" (ByVal hdc As Long, pVertex As TRIVERTEX, ByVal dwNumVertex As Long, pMesh As GRADIENT_RECT, ByVal dwNumMesh As Long, ByVal dwMode As Long) As Long
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Type GRADIENT_TRIANGLE
Vertex1 As Long
Vertex2 As Long
Vertex3 As Long
End Type
Private Type GRADIENT_RECT
UpperLeft As Long
LowerRight As Long
End Type
Private Type TRIVERTEX
x As Long
y As Long
Red As Integer
Green As Integer
blue As Integer
Alpha As Integer
End Type
'=========================================================================
' Constants and member variables
'=========================================================================
'--- integer math precision constants
Private Const PREC_BRI As Long = 8
Private Const PREC_BRI_255 As Long = PREC_BRI * 255
Private Const PREC_SAT As Long = 8
Private Const PREC_SAT_255 As Long = PREC_SAT * 255
Private Const PREC_SAT_BRI_255 As Long = PREC_SAT * PREC_BRI * 255
Private Const PREC_HUE As Long = 256
Private Const PREC_HUE_255 As Long = PREC_HUE * 255
Private Const PREC_HUE_SAT_255 As Long = PREC_HUE * PREC_SAT * 255
Private Const PREC_HUE_BRI_255 As Long = PREC_HUE * PREC_BRI * 255
Private Const PREC_HUE_SAT_BRI_255 As Long = PREC_HUE * PREC_SAT * PREC_BRI * 255
'--- color rect and color bar sizes
Private Const BAR_WIDTH As Long = 16
'--- these used to be constants
Private RECT_WIDTH_STEP As Long ' = 23
Private RECT_WIDTH As Long ' = 6 * RECT_WIDTH_STEP ' 258
Private RECT_HEIGHT As Long
Private BAR_HEIGHT As Long ' = RECT_HEIGHT
'--- keyboard input (timer) type
Private Const STR_TIMER_FROM_RGB As String = "rgb"
Private Const STR_TIMER_FROM_HSB As String = "hsb"
'--- misc
Private Const MASK_COLOR As Long = &HFF00FF
Private Const GRID_SIZE As Long = 5
Private Const LAB_CORELDRAW_NORMALIZE As Double = 2
Private m_bOk As Boolean
Private m_clrCurrent As Ole_Color
Private m_clrOriginal As Ole_Color
Private m_hsbCurrent As UcsHsbColor
Private m_hsbPrevious As UcsHsbColor
Private m_oHueCache As UcsColorGraphicsCache
Private m_oSaturationCache As UcsColorGraphicsCache
Private m_oBrightnessCache As UcsColorGraphicsCache
Private m_oRedCache As UcsColorGraphicsCache
Private m_oGreenCache As UcsColorGraphicsCache
Private m_oBlueCache As UcsColorGraphicsCache
Private m_imgRect As StdPicture
Private m_imgBar As StdPicture
Private m_aWebSafe(0 To 255) As Byte
Private m_bWebSafeOnly As Boolean
Private m_bBarPressed As Boolean
Private m_bRectPressed As Boolean
Private m_bInSet As Boolean
Private m_imgBarSelector As StdPicture
Private m_bAccelerateSupported As Boolean
Private m_dblTimer As Double
Private m_sNumericHeight As Single
'=========================================================================
' Properties
'=========================================================================
Property Get Color() As Ole_Color
Color = m_clrCurrent
End Property
Property Let Color(ByVal clrValue As Ole_Color)
Dim rgbColor As UcsRgbQuad
'Dim cmykColor As UcsRgbQuad
'Dim labColor As UcsHsbColor
'--- do web colors conversion
CopyMemory rgbColor, clrValue, 4
If m_bWebSafeOnly Then
With rgbColor
.r = m_aWebSafe(.r)
.G = m_aWebSafe(.G)
.b = m_aWebSafe(.b)
End With
CopyMemory clrValue, rgbColor, 4
End If
'--- if anything changed
If clrValue <> m_clrCurrent _
Or Not pvIsEqualHsb(m_hsbPrevious, m_hsbCurrent) Then
'--- save current color (and hsb representation)
m_clrCurrent = clrValue
m_hsbPrevious = m_hsbCurrent
'--- modify UI
labNew.BackColor = clrValue
'--- prevent textbox's events from controling color
m_bInSet = True
'--- RGB
With rgbColor
pvSetText txtRed, .r
pvSetText txtGreen, .G
pvSetText txtBlue, .b
End With
'--- RGB -> HSB
With m_hsbCurrent
If .Hue < 0 Then
m_hsbCurrent = pvRGBToHSB(clrValue)
End If
pvSetText txtHue, CLng(.Hue)
pvSetText txtSat, CLng(.Sat)
pvSetText txtBri, CLng(.Bri)
End With
'--- RGB -> CMYK
With pvRGBToCMYK(clrValue)
pvSetText txtCyan, .r
pvSetText txtMagenta, .G
pvSetText txtYellow, .b
pvSetText txtBlack, .a
End With
'--- RGB -> XYZ -> L*a*b*
With pvXYZToLAB(pvRGBToXYZ(clrValue))
pvSetText txtLabLuminance, Format(.l, "0.0")
pvSetText txtLabA, Format(.a, "0.0")
pvSetText txtLabB, Format(.b, "0.0")
End With
'--- RGB -> Web
pvSetText txtNewColor, pvHex(rgbColor.r) & pvHex(rgbColor.G) & pvHex(rgbColor.b)
'--- end of prevention
m_bInSet = False
'--- set current graphics depending on current view
If optHue Then
pvSetHueCurrent pvInitHsb(m_hsbCurrent.Hue, 100, 100), m_bWebSafeOnly
ElseIf optSat Then
pvSetSaturationCurrent m_hsbCurrent, m_bWebSafeOnly
ElseIf optBri Then
pvSetBrightnessCurrent m_hsbCurrent, m_bWebSafeOnly
ElseIf optRed Then
pvSetRedCurrent rgbColor, m_bWebSafeOnly
ElseIf optGreen Then
pvSetGreenCurrent rgbColor, m_bWebSafeOnly
ElseIf optBlue Then
pvSetBlueCurrent rgbColor, m_bWebSafeOnly
End If
End If
End Property
'=========================================================================
' Methods
'=========================================================================
Public Function Init( _
ByVal clrColor As Ole_Color, _
clrNew As Ole_Color) As Boolean
'--- retval: true - confirmed and clrNew is the new color, false - canceled
On Error GoTo EH
'--- translate input color
If clrColor = -1 Then
clrColor = 0
Else
OleTranslateColor clrColor, 0, clrColor
End If
'--- local vars
m_hsbCurrent.Hue = -1
labOld.BackColor = clrColor
m_clrOriginal = clrColor
Color = clrColor
'--- UI handling
pvRefresh
m_bOk = False
'Show vbModal
If m_bOk Then
'--- confirmed ok
clrNew = Color
'--- success
Init = True
End If
Exit Function
EH:
MsgBox "Error: " & Error, vbCritical
End Function
Private Sub pvSetHueCurrent( _
hsbColor As UcsHsbColor, _
ByVal bWebSafe As Boolean)
With m_oHueCache
If Not pvIsEqualHsb(.hsbColor, hsbColor) _
Or .bWebSafe <> bWebSafe _
Or Not pvCheckDimensions(.imgRect, RECT_WIDTH, RECT_HEIGHT) Then
#If NO_ACCELERATED_GRADIENTS = 0 Then
If Not bWebSafe And m_bAccelerateSupported Then
Set .imgRect = pvCreateRectHueAccel(hsbColor)
Else
Set .imgRect = pvCreateRectHue(hsbColor)
End If
#Else
Set .imgRect = pvCreateRectHue(hsbColor)
#End If
End If
If .bWebSafe <> bWebSafe _
Or Not pvCheckDimensions(.imgBar, BAR_WIDTH, BAR_HEIGHT) Then
Set .imgBar = pvCreateBarHue()
End If
.hsbColor = hsbColor
.bWebSafe = m_bWebSafeOnly
Set m_imgRect = .imgRect
Set m_imgBar = .imgBar
End With
End Sub
Private Sub pvSetSaturationCurrent( _
hsbColor As UcsHsbColor, _
ByVal bWebSafe As Boolean)
With m_oSaturationCache
If .hsbColor.Sat <> hsbColor.Sat _
Or .bWebSafe <> bWebSafe _
Or Not pvCheckDimensions(.imgRect, RECT_WIDTH, RECT_HEIGHT) Then
#If NO_ACCELERATED_GRADIENTS = 0 Then
If Not bWebSafe And m_bAccelerateSupported Then
Set .imgRect = pvCreateRectSaturationAccel(hsbColor.Sat)
Else
Set .imgRect = pvCreateRectSaturation(hsbColor.Sat)
End If
#Else
Set .imgRect = pvCreateRectSaturation(hsbColor.Sat)
#End If
End If
If .hsbColor.Hue <> hsbColor.Hue _
Or .hsbColor.Bri <> hsbColor.Bri _
Or .bWebSafe <> bWebSafe _
Or Not pvCheckDimensions(.imgBar, BAR_WIDTH, BAR_HEIGHT) Then
Set .imgBar = pvCreateBarSaturation(hsbColor.Hue, hsbColor.Bri)
End If
.hsbColor = hsbColor
.bWebSafe = m_bWebSafeOnly
Set m_imgRect = .imgRect
Set m_imgBar = .imgBar
End With
End Sub
Private Sub pvSetBrightnessCurrent( _
hsbColor As UcsHsbColor, _
ByVal bWebSafe As Boolean)
With m_oBrightnessCache
If .hsbColor.Bri <> hsbColor.Bri _
Or .bWebSafe <> bWebSafe _
Or Not pvCheckDimensions(.imgRect, RECT_WIDTH, RECT_HEIGHT) Then
#If NO_ACCELERATED_GRADIENTS = 0 Then
If Not bWebSafe And m_bAccelerateSupported Then
Set .imgRect = pvCreateRectBrightnessAccel(hsbColor.Bri)
Else
Set .imgRect = pvCreateRectBrightness(hsbColor.Bri)
End If
#Else
Set .imgRect = pvCreateRectBrightness(hsbColor.Bri)
#End If
End If
If .hsbColor.Hue <> hsbColor.Hue _
Or .hsbColor.Sat <> hsbColor.Sat _
Or .bWebSafe <> bWebSafe _
Or Not pvCheckDimensions(.imgBar, BAR_WIDTH, BAR_HEIGHT) Then
Set .imgBar = pvCreateBarBrightness(hsbColor.Hue, hsbColor.Sat)
End If
.hsbColor = hsbColor
.bWebSafe = m_bWebSafeOnly
Set m_imgRect = .imgRect
Set m_imgBar = .imgBar
End With
End Sub
Private Sub pvSetRedCurrent( _
rgbColor As UcsRgbQuad, _
ByVal bWebSafe As Boolean)
With m_oRedCache
If .rgbColor.r <> rgbColor.r _
Or .bWebSafe <> bWebSafe _
Or Not pvCheckDimensions(.imgRect, RECT_WIDTH, RECT_HEIGHT) Then
#If NO_ACCELERATED_GRADIENTS = 0 Then
If Not bWebSafe And m_bAccelerateSupported Then
Set .imgRect = pvCreateRectRGBAccel(rgbColor.r, ucsRgbRed)
Else
Set .imgRect = pvCreateRectRGB(rgbColor.r, ucsRgbRed)
End If
#Else
Set .imgRect = pvCreateRectRGB(rgbColor.r, ucsRgbRed)
#End If
End If
If .bWebSafe <> bWebSafe _
Or Not pvCheckDimensions(.imgBar, BAR_WIDTH, BAR_HEIGHT) Then
Set .imgBar = pvCreateBarRGB(ucsRgbRed)
End If
.rgbColor = rgbColor
.bWebSafe = m_bWebSafeOnly
Set m_imgRect = .imgRect
Set m_imgBar = .imgBar
End With
End Sub
Private Sub pvSetGreenCurrent( _
rgbColor As UcsRgbQuad, _
ByVal bWebSafe As Boolean)
With m_oGreenCache
If .rgbColor.G <> rgbColor.G _
Or .bWebSafe <> bWebSafe _
Or Not pvCheckDimensions(.imgRect, RECT_WIDTH, RECT_HEIGHT) Then
#If NO_ACCELERATED_GRADIENTS = 0 Then
If Not bWebSafe And m_bAccelerateSupported Then
Set .imgRect = pvCreateRectRGBAccel(rgbColor.G, ucsRgbGreen)
Else
Set .imgRect = pvCreateRectRGB(rgbColor.G, ucsRgbGreen)
End If
#Else
Set .imgRect = pvCreateRectRGB(rgbColor.G, ucsRgbGreen)
#End If
End If
If .bWebSafe <> bWebSafe _
Or Not pvCheckDimensions(.imgBar, BAR_WIDTH, BAR_HEIGHT) Then
Set .imgBar = pvCreateBarRGB(ucsRgbGreen)
End If
.rgbColor = rgbColor
.bWebSafe = m_bWebSafeOnly
Set m_imgRect = .imgRect
Set m_imgBar = .imgBar
End With
End Sub
Private Sub pvSetBlueCurrent( _
rgbColor As UcsRgbQuad, _
ByVal bWebSafe As Boolean)
With m_oBlueCache
If .rgbColor.b <> rgbColor.b _
Or .bWebSafe <> bWebSafe _
Or Not pvCheckDimensions(.imgRect, RECT_WIDTH, RECT_HEIGHT) Then
#If NO_ACCELERATED_GRADIENTS = 0 Then
If Not bWebSafe And m_bAccelerateSupported Then
Set .imgRect = pvCreateRectRGBAccel(rgbColor.b, ucsRgbBlue)
Else
Set .imgRect = pvCreateRectRGB(rgbColor.b, ucsRgbBlue)
End If
#Else
Set .imgRect = pvCreateRectRGB(rgbColor.b, ucsRgbBlue)
#End If
End If
If .bWebSafe <> bWebSafe _
Or Not pvCheckDimensions(.imgBar, BAR_WIDTH, BAR_HEIGHT) Then
Set .imgBar = pvCreateBarRGB(ucsRgbBlue)
End If
.rgbColor = rgbColor
.bWebSafe = m_bWebSafeOnly
Set m_imgRect = .imgRect
Set m_imgBar = .imgBar
End With
End Sub
Private Function pvCreateRectHue(hsbColor As UcsHsbColor) As StdPicture
'--- based on a submission to PSC by Saifudheen A.A.
Dim lX As Long
Dim lY As Long
Dim rgbColor As UcsRgbQuad
Dim lRedBri As Long
Dim lGreenBri As Long
Dim lBlueBri As Long
Dim lRedSat As Long
Dim lGreenSat As Long
Dim lBlueSat As Long
Dim lIdx As Long
Dim clrColor As Ole_Color
Dim lArea As Long
On Error GoTo EH
ReDim rgbLine(0 To RECT_WIDTH) As UcsRgbTriple
'--- include padding
ReDim aBits(0 To pvPadScanline(RECT_WIDTH * 3) * RECT_HEIGHT) As Byte
m_dblTimer = Timer: 'Debug.Print "pvCreateRectHue "; m_dblTimer;
clrColor = pvHSBToRGB(hsbColor)
Call OleTranslateColor(clrColor, 0, rgbColor)