From 6f473af069b74af082076be6b319ffe13151babf Mon Sep 17 00:00:00 2001 From: wp_xxyyzz Date: Sat, 13 Oct 2018 21:13:58 +0000 Subject: [PATCH] jvcllaz: Add full color controls and dialogs git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@6684 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- components/jvcllaz/design/JvMM/JvMMReg.pas | 19 +- .../jvcllaz/design/JvMM/images/images.txt | 9 + .../JvMM/images/tjvfullcoloraxiscombo.bmp | Bin 0 -> 1654 bytes .../design/JvMM/images/tjvfullcolorcircle.bmp | Bin 0 -> 1654 bytes .../JvMM/images/tjvfullcolorcircledialog.bmp | Bin 0 -> 1654 bytes .../design/JvMM/images/tjvfullcolordialog.bmp | Bin 0 -> 1654 bytes .../design/JvMM/images/tjvfullcolorgroup.bmp | Bin 0 -> 1654 bytes .../design/JvMM/images/tjvfullcolorlabel.bmp | Bin 0 -> 1654 bytes .../design/JvMM/images/tjvfullcolorpanel.bmp | Bin 0 -> 1654 bytes .../JvMM/images/tjvfullcolorspacecombo.bmp | Bin 0 -> 1654 bytes .../JvMM/images/tjvfullcolortrackbar.bmp | Bin 0 -> 1654 bytes .../design/JvMM/jvfullcoloreditors.pas | 92 + .../design/JvMM/jvfullcolorlistform.lfm | 192 + .../design/JvMM/jvfullcolorlistform.pas | 306 ++ .../design/JvMM/jvfullcolorspaceseditors.pas | 770 ++++ components/jvcllaz/packages/JvMMLazD.lpk | 10 +- components/jvcllaz/packages/JvMMLazR.lpk | 30 +- components/jvcllaz/resource/jvmmreg.res | Bin 11928 -> 27316 bytes .../run/JvMM/jvfullcolorcircleform.lfm | 972 +++++ .../run/JvMM/jvfullcolorcircleform.pas | 1001 +++++ .../jvcllaz/run/JvMM/jvfullcolorctrls.pas | 3886 +++++++++++++++++ .../jvcllaz/run/JvMM/jvfullcolordialogs.pas | 467 ++ .../jvcllaz/run/JvMM/jvfullcolorform.lfm | 464 ++ .../jvcllaz/run/JvMM/jvfullcolorform.pas | 506 +++ .../jvcllaz/run/JvMM/jvfullcolorrotate.pas | 385 ++ .../jvcllaz/run/JvMM/jvfullcolorspaces.pas | 1651 +++++++ 26 files changed, 10757 insertions(+), 3 deletions(-) create mode 100644 components/jvcllaz/design/JvMM/images/tjvfullcoloraxiscombo.bmp create mode 100644 components/jvcllaz/design/JvMM/images/tjvfullcolorcircle.bmp create mode 100644 components/jvcllaz/design/JvMM/images/tjvfullcolorcircledialog.bmp create mode 100644 components/jvcllaz/design/JvMM/images/tjvfullcolordialog.bmp create mode 100644 components/jvcllaz/design/JvMM/images/tjvfullcolorgroup.bmp create mode 100644 components/jvcllaz/design/JvMM/images/tjvfullcolorlabel.bmp create mode 100644 components/jvcllaz/design/JvMM/images/tjvfullcolorpanel.bmp create mode 100644 components/jvcllaz/design/JvMM/images/tjvfullcolorspacecombo.bmp create mode 100644 components/jvcllaz/design/JvMM/images/tjvfullcolortrackbar.bmp create mode 100644 components/jvcllaz/design/JvMM/jvfullcoloreditors.pas create mode 100644 components/jvcllaz/design/JvMM/jvfullcolorlistform.lfm create mode 100644 components/jvcllaz/design/JvMM/jvfullcolorlistform.pas create mode 100644 components/jvcllaz/design/JvMM/jvfullcolorspaceseditors.pas create mode 100644 components/jvcllaz/run/JvMM/jvfullcolorcircleform.lfm create mode 100644 components/jvcllaz/run/JvMM/jvfullcolorcircleform.pas create mode 100644 components/jvcllaz/run/JvMM/jvfullcolorctrls.pas create mode 100644 components/jvcllaz/run/JvMM/jvfullcolordialogs.pas create mode 100644 components/jvcllaz/run/JvMM/jvfullcolorform.lfm create mode 100644 components/jvcllaz/run/JvMM/jvfullcolorform.pas create mode 100644 components/jvcllaz/run/JvMM/jvfullcolorrotate.pas create mode 100644 components/jvcllaz/run/JvMM/jvfullcolorspaces.pas diff --git a/components/jvcllaz/design/JvMM/JvMMReg.pas b/components/jvcllaz/design/JvMM/JvMMReg.pas index 4657ecbca..aa335cd87 100644 --- a/components/jvcllaz/design/JvMM/JvMMReg.pas +++ b/components/jvcllaz/design/JvMM/JvMMReg.pas @@ -18,6 +18,8 @@ uses JvDsgnConsts, JvId3v1, JvId3v2Base, JvId3v2, JvGradient, JvId3v2EditorForm, JvGradientHeaderPanel, JvSpecialProgress, + JvFullColorSpaces, JvFullColorCtrls, JvFullColorEditors, JvFullColorSpacesEditors, + JvFullColorForm, JvFullColorDialogs, JvBmpAnimator; procedure Register; @@ -26,10 +28,25 @@ begin TJvId3v1, TJvId3v2, TJvBmpAnimator, TJvGradient, TJvGradientHeaderPanel, - TJvSpecialProgress + TJvSpecialProgress, + TJvFullColorPanel, TJvFullColorTrackBar, TJvFullColorGroup, TJvFullColorLabel, + TJvFullColorSpaceCombo, TJvFullColorAxisCombo, TJvFullColorCircle, + TJvFullColorDialog, TJvFullColorCircleDialog ]); + RegisterComponentEditor(TJvID3Controller, TJvID3ControllerEditor); RegisterPropertyEditor(TypeInfo(TJvID3FileInfo), nil, '', TJvID3FileInfoEditor); + + RegisterPropertyEditor(TypeInfo(TJvFullColorSpaceID), nil, '', TJvColorIDEditor); + RegisterPropertyEditor(TypeInfo(TJvFullColor), nil, '', TJvFullColorProperty); + { + RegisterPropertyEditor(TypeInfo(TJvFullColorList), nil, '', TJvFullColorListEditor); + RegisterSelectionEditor(TJvFullColorPanel, TJvFullColorSelection); + RegisterSelectionEditor(TJvFullColorCircle, TJvFullColorSelection); + RegisterSelectionEditor(TJvFullColorLabel, TJvFullColorSelection); + RegisterSelectionEditor(TJvFullColorSpaceCombo, TJvFullColorSelection); + RegisterSelectionEditor(TJvFullColorAxisCombo, TJvFullColorSelection); + } end; end. diff --git a/components/jvcllaz/design/JvMM/images/images.txt b/components/jvcllaz/design/JvMM/images/images.txt index 865e37886..6725bac58 100644 --- a/components/jvcllaz/design/JvMM/images/images.txt +++ b/components/jvcllaz/design/JvMM/images/images.txt @@ -5,3 +5,12 @@ tjvgradientheaderpanel.bmp tjvspecialprogress.bmp tjvanimatedimage.bmp tjvbmpanimator.bmp +tjvfullcoloraxiscombo.bmp +tjvfullcolorcircle.bmp +tjvfullcolorcircledialog.bmp +tjvfullcolordialog.bmp +tjvfullcolorgroup.bmp +tjvfullcolorlabel.bmp +tjvfullcolorpanel.bmp +tjvfullcolorspacecombo.bmp +tjvfullcolortrackbar.bmp diff --git a/components/jvcllaz/design/JvMM/images/tjvfullcoloraxiscombo.bmp b/components/jvcllaz/design/JvMM/images/tjvfullcoloraxiscombo.bmp new file mode 100644 index 0000000000000000000000000000000000000000..e172ea9183f0a6ab0b93d1aaf1627952fa8ebc67 GIT binary patch literal 1654 zcmaLVF|yM@41i%h1_(2hG?Xei0bODZJ$KM4sC5(-8P1`O8O}hVBfK`rn`eG|^YRiV zgPhOWXxH|xz2Cn7crR;weJk>X*5|Va`LNdQjmW2ugFH}LtPvvoBw{4aG^MJf{**la z{wbmc2OXLyw1^25G|Ul56k5au3Il&UkSO%|xk@%T0*OM4(3Dgd9DziknWR8ra0C*C z7U3tYFgOBF06vc8l0*OM8rKyq)jzFT&W7(!;gCmeA^mrw%WP>A+DD-$;p=5(2 zkSO$cm8oQdBakTcc+I6`gCmeA^!f>`m27YX5`~sv{UM5F<&Nb@6k0+B3WFn%DD?Pj zreuR7kSO%{q^@LxBakTc_}n}s!r%xb3O%+$D%s!&BnmyYNh#Uj2qX%0)K9Dzik$F?&i8ytZ|p~seVB^w-pM4`ua4J8{KfkdIlR!$`w z9Dzik$2Kn|8yta@$I~o(#s&8inb)7p^U?yxQsVS$cNN?1_W5bVrFvXiYyEVhYqvWb z&q4k8^!!AX-?Tf>x0Ke?;ZmOtyU{T^*ZVKyslRp{cUSd^j`JnA_37U_^Wi?z#1$hL ze~#&Jcv@M&9y{?#6y|H|G8A=*_%egZgNk|8C~>a;o$G q-6i((|LU^Y+#Amay<1-%aBuvjel;PUyT&s9Ce~SUx|#jeg}cAxv2W}E literal 0 HcmV?d00001 diff --git a/components/jvcllaz/design/JvMM/images/tjvfullcolorcircle.bmp b/components/jvcllaz/design/JvMM/images/tjvfullcolorcircle.bmp new file mode 100644 index 0000000000000000000000000000000000000000..2c095ed863a00883f31889d8ce060bea7735ff9c GIT binary patch literal 1654 zcmbW#F^&{L3_wvYLI{bFgwP=;V56O}$hm`0LF}VAK%B!F5@#Ur5lCluwZpG=&n(&u zs^_(P?CR>S>iYcU>l@kHr`IAMx%#lXk+)mkUWvSaH{^!Yvb7N5ClM1kb179N^{eFf z&+j5?a8S@hp+!uf;KCe%M4?4opfK>q1BpWK&sCzq5l9qTgiA?j>1QLawWiBNe9Dzikw@+ZLM1v!cD6|Cg4^ga{JJyjXw1f&221g)K==p4> zM1v!cDD-?%SE9iYNECWLHxG$0I0A`6&sIn!8XSQ{p=XAQRmeX)P$GYS zf4?$Y5BihkcO<(S!*7+B`OA3Q`1GINoTu>kUwPi=^4#nAPt#uJ_i5c7kE?P#Uiu#n zYf^XQg%a(#z$6dP`M(NliuBxXxE5Hd!+Hu41i(5FflWfG?Xei0jc6>=(&SVL9L^x@Nf=w%y0$@9U*O;Ow7N#c5Dx@ z?|s%^}FQZ z*AEdjIJlsRLW`I{LB||{M4?4opfK>q1BpT(=T)M?5l9qTgs!B*;0PoN%|i+l21g)K zXc10ng~1U>6k1GpOi_%(5l9qzElrhZa0C*CUduKm8XSQ{q1P*MB^n%oM4{K~3MCpG zfkdI#t4t*t9Dzik*J~~%8XSQ{q30*CR-(ZXNEBLv^@k|N${piK6k0+B3WFn%DD?Vl zrbL4ykSO%}q^?ARBakTc`rJ$sVQ>TzgK{p+titkSO%p%Be(y zBakTc+UBK1gCmgg@N|$Jb-{Qdhk453FnZt^DSm!#FWTMR-OJ5t7g@S9|MbMA?T!I1 z+RF`D&imcwaCw~bSLw|h|FwR<-yb%@eb47S^`!UvImtzys+qs2=XvgTr}{O|%dxHJ z;fAZ}-{ z)5ypARd%W$7w0fDeN}(DZ^YN}FO&2~{^FyYyJLKLzH0OHZ*O=1Y}?!0`@h=Q3%CEd F@CUsiLN5RS literal 0 HcmV?d00001 diff --git a/components/jvcllaz/design/JvMM/images/tjvfullcolordialog.bmp b/components/jvcllaz/design/JvMM/images/tjvfullcolordialog.bmp new file mode 100644 index 0000000000000000000000000000000000000000..6c99f2951ebf2e3bd0164b5d3cb3b045259e7a80 GIT binary patch literal 1654 zcmcK2v2GMW41i$=p)3+54W&z-fK<6y^t^+gg4&Pb;>2^fL*f}I{0M22J?{8tC(&I5 zDe>%go_Hp^vpe(U>$hv!;`3XPPxL-MxsrEV-QI|Nct6P%rD2N@;gX1%_@ygVCH1T1 z{^xfQH8>d1M4?4YprB)pK%&qhE>IZw!vl#zKRs8;21g)KXc4-S3WFn%C^U-{C=8B3 zqR=8-(h7qkkSMg6uuM^m<_IJTJzq_gY;Xh;g`Tf%N;WtGi9*j$;z~9+0*OM;&lO5G zI0A`6&rg|3HaG%_LeI}!N;WtGi9&B%V69|>BakSx1n(cB7;o+vEm3F*6(|gjK%&rd z+f2y@M<7w?xuvdTgCmeA^xSS95@B!z5`~^eA(d=!1QLaw$E1{Oa0C*C-i}bTk`0bP zqR>*je~H522qZ@9d9+l?21g)K=y~i+$p%LtQRsOjUC9PVAW`UfTtmqQM<7w?d6ZMh z21g)K=y}Xb$p%Lt<$gWMo_WFjL{8f!r_<c!?d|b;#zmFxR$o_!c6)Ac z5yxw)TzC8BblJ}J7v*KU|9SrM9OwF&e~xo~yZf>(%W+u_^FFNSZokc6mq+S{<@fO^ zp4PK6K%Iey@&9uBJbz{Wkur4#MtzJwtn1?=^#k>Xi}^3=WB%@y`P9dH{`dUxjLSCG gbFnGs?pTi;Uc|QjyPN$#V|R0N_g9RwaP!K*A9TcANdN!< literal 0 HcmV?d00001 diff --git a/components/jvcllaz/design/JvMM/images/tjvfullcolorgroup.bmp b/components/jvcllaz/design/JvMM/images/tjvfullcolorgroup.bmp new file mode 100644 index 0000000000000000000000000000000000000000..9e8ed42da4da61fd8282916ddd479f1c91326b51 GIT binary patch literal 1654 zcmZ|NJ#H0248U=R1cXFML+O$ekSelFD71(R6bAlyAW`Vux=J)S0*OM4FqBjn9DzikDN>*? zI0A`6i|~_H7#x8_p~ZwUMKLZ%AW`V~YN|woBakTcd~H*r!4XIldTxm;(clOq3O%zMvCs&ve(Ye&hGDKTX;^Er=I-n zEw>iAxET4XtI_}bd4ETi-}>MDi+Ser>$FMe7 IrME5l3pjD})c^nh literal 0 HcmV?d00001 diff --git a/components/jvcllaz/design/JvMM/images/tjvfullcolorlabel.bmp b/components/jvcllaz/design/JvMM/images/tjvfullcolorlabel.bmp new file mode 100644 index 0000000000000000000000000000000000000000..36365e29d07b552b74996a91d59219920b6a157a GIT binary patch literal 1654 zcmajdv5pf#41i%DLI{bHhSDWZK&m7bJ@4SBp!TDDeR(VLnck<1J9)q4?TyIC50l)H8kQC!oDwkuSGrPFQh!SB zfBzIwgM)%53N2y+1s!t)5``9Vfx^Iz2NH$8{I3!XjzFT&B6KAc21g)KXkJpFFgOB< zLW^)pD-4c6qR?W(Yl>nVjzFT&b84zYgCmeA^qjUS(clOq3O$#^m1uAT5`~`26-qQX z0*OM;rA#Fn9Dzik=Q5WP4URyf(90*VR-(ZXNEBLv`G+XR%pK!M6k0+B3WFn%DD?bn zrbL4ykSO&0q^?ARBakTc{M`IWguxL=6nbujRHDHVNECW*lTxC=5l9qz*+S7uG&ll@ zLQ66K5{1DLNQ|TB)>0)J9Dzik=e9E?8XSQ{q34!#B^n%oM4{()4J8^JfkdI_R!$`v z9Dzik=Qb}T8XSR?`_ox|@LVvS$ay*Cd>%b;j1-q&hgI9}_fLZA0r9JelM@`qjI>FXTbIN z&*O|gTIac4N?f=3F@xFG`Sp@)@~gsiap)Y6{|fXs?Ror7a@<@Bukx3|?nYsEqp-VC F_zS*cNg@CM literal 0 HcmV?d00001 diff --git a/components/jvcllaz/design/JvMM/images/tjvfullcolorpanel.bmp b/components/jvcllaz/design/JvMM/images/tjvfullcolorpanel.bmp new file mode 100644 index 0000000000000000000000000000000000000000..0260cb9afe48c62fa92702de9ba9df0ed0a4da95 GIT binary patch literal 1654 zcmd7QF>V_{3_ww?v=RcOOp}sjPLR$rkv@0eDN^$&EP|YaU4Wb+1&`oXmM!J)j%_3Y z)Q7WgIpPdfJG1lU>$knE@p%^cMDOE^N#3n>+lYL4KgdLBu||k+NyJFp=}J{e{VsX< z^+QAr4hA$)Xb}@A=$IprD71(R6b62HAW`U-|5dWV5l9qTgs!B*;0PoN%}WXt21g)K zXb~=Hg~1U>6k1GpO;Ie(5l9qzEKQYca0C*C9?Lc*8ytZ|p~sfEk`0bPqR?ZzLdgb4 zAW`VCm8oQdBakTc*yd8Q!4XIldi?~}N;WtGi9$=T{t(5oa>vpVg_cl(!r%xb3OzoX zDcRr%Bnmw~sVmvw2qX$UJ~w|7VQ>Tzg&s#Cm27YX5``Yeq?BxM1QLZ_k5IId4URyf z&{C|wL}73Q5=-lGv{cCkM<7w?aqLXV21g)K=y4=n$p%LtQRs18L&*k5AW`UXlvBwD zM<7w?am-7}21g*};dGJj%nP0;a#=6AT$UbaONrah!(VZCcXxgo@mH1ZT0fl_`nP^y zK2@&!tAV%r)xi4vW&ZYld)UzSwD~Z<)~Bn1xB8aY5PM>t$9&#rx~`u`T-WCvF%ehu zU+c&1X?xl{ZXWmN{dsOl=qZp%Ddxqyfy!LA|8q5HI}V>CXU37 O=ii)v>pA~d{qP6+G^$_# literal 0 HcmV?d00001 diff --git a/components/jvcllaz/design/JvMM/images/tjvfullcolorspacecombo.bmp b/components/jvcllaz/design/JvMM/images/tjvfullcolorspacecombo.bmp new file mode 100644 index 0000000000000000000000000000000000000000..124233c5dde7284e3558886b3a54db323581f334 GIT binary patch literal 1654 zcmaLVJ#H0248U;*0S}3ihSDV`pv%Uh=MFvvwU6TBiF3F^qR9m)e1x>gi?aM@<`IbW zglB*2iQ|2ze?_Y zeiu=LgMVnE&>|*KFfm6UQD_ktC=C4JfkdIt>nhpc2qX$E!cMD%s!&BnrK@Nh#Uj2qX$Uw@|c_4URyf z&{8~qiNfFrB*y5qwN%LlM<7w?we3vF21g)K=(QzX$p%LtQRuZ@L&*k5AW`VGl~c(E zM<7w?warV(21g*}?zGF1zTo#n_Ib#@j~N)F#OcR&zikiO_W1a?ZP#-B#AL)h^#{h| zf%-PD>vN5bzU`Jlo%>la*LXf%^NudY z@o+KrDew;ylP0oKF_IWwg{rKiNj{E=WayVS-=gBYD#{!r7pX>kJ5bMqu{V!tP MC8rm6|IdZT-$Qz8>Hq)$ literal 0 HcmV?d00001 diff --git a/components/jvcllaz/design/JvMM/images/tjvfullcolortrackbar.bmp b/components/jvcllaz/design/JvMM/images/tjvfullcolortrackbar.bmp new file mode 100644 index 0000000000000000000000000000000000000000..2e29c0c4de6210c54aee518406f5baf3f00c60dd GIT binary patch literal 1654 zcmajdJ#HK^42EHP5d;BJrb)>%Cx|QW66tdXo+34m!Xn5y*agTLQt$|_*M>LmNE-hZ zk@i`RKgrsek-mNZ@m@yz`cC8vSD%+F`7m-jh3v&b#g%)vv!oVLMNECYgu2Kz-K%&qhTuLeojzFT&+@wHZa0C*C z7U3hUFgOBEvDT=K-0*OM;M^mL59Dzik=VO~v4URyf(DRkJQVotkqR{hog;EWU zK%&s|Ri;u6jzFT&^EH=J4URyf&|?d%m1=MV5`~uF`9l=jlRLJaD71tM6b45iQRumC zrc{F?kSO%rQdg?M5l9qzZZ|&?VQ>Tzg`P(tm1=MV5`~_}q?BrK1QLZFM<`mU21g)K zXepk*L}73Q5?k+iv{b1EM<7w?dF)K721g)K=y@bvsRl 0; +end; + +procedure TJvFullColorListFrm.ActionDeleteExecute(Sender: TObject); +begin + ListBoxColors.DeleteSelected; +end; + +procedure TJvFullColorListFrm.ActionDeleteUpdate(Sender: TObject); +begin + (Sender as TAction).Enabled := ListBoxColors.SelCount >= 1; +end; + +procedure TJvFullColorListFrm.ActionInsertExecute(Sender: TObject); +begin + JvFullColorDialog.Options := JvFullColorDialog.Options - [foShowApply]; + if JvFullColorDialog.Execute then + ListBoxColors.Items.InsertObject(ListBoxColors.ItemIndex, '', + TObject(JvFullColorDialog.FullColor)); +end; + +procedure TJvFullColorListFrm.ActionInsertUpdate(Sender: TObject); +begin + (Sender as TAction).Enabled := ListBoxColors.SelCount = 1; +end; + +procedure TJvFullColorListFrm.ActionModifyExecute(Sender: TObject); +begin + JvFullColorDialog.Options := JvFullColorDialog.Options + [foShowApply]; + JvFullColorDialog.FullColor := TJvFullColor(ListBoxColors.Items.Objects[ListBoxColors.ItemIndex]); + if JvFullColorDialog.Execute then + ListBoxColors.Items.Objects[ListBoxColors.ItemIndex] := TObject(JvFullColorDialog.FullColor); +end; + +procedure TJvFullColorListFrm.ActionModifyUpdate(Sender: TObject); +begin + (Sender as TAction).Enabled := ListBoxColors.SelCount = 1; +end; + +procedure TJvFullColorListFrm.ActionMoveDownExecute(Sender: TObject); +var + OldIndex: Integer; +begin + with ListBoxColors do + begin + OldIndex := ItemIndex; + Items.Move(ItemIndex, ItemIndex + 1); + Selected[OldIndex + 1] := True; + end; +end; + +procedure TJvFullColorListFrm.ActionMoveDownUpdate(Sender: TObject); +begin + with ListBoxColors do + (Sender as TAction).Enabled := (SelCount = 1) and (ItemIndex < (Items.Count - 1)); +end; + +procedure TJvFullColorListFrm.ActionMoveUpExecute(Sender: TObject); +var + OldIndex: Integer; +begin + with ListBoxColors do + begin + OldIndex := ItemIndex; + Items.Move(ItemIndex, ItemIndex - 1); + Selected[OldIndex - 1] := True; + end; +end; + +procedure TJvFullColorListFrm.ActionMoveUpUpdate(Sender: TObject); +begin + with ListBoxColors do + (Sender as TAction).Enabled := (SelCount = 1) and (ItemIndex > 0); +end; + +procedure TJvFullColorListFrm.ActionNewExecute(Sender: TObject); +begin + JvFullColorDialog.Options := JvFullColorDialog.Options - [foShowApply]; + if JvFullColorDialog.Execute then + ListBoxColors.Items.AddObject('', TObject(JvFullColorDialog.FullColor)); +end; + +procedure TJvFullColorListFrm.ActionNewUpdate(Sender: TObject); +begin + (Sender as TAction).Enabled := True; +end; + +function TJvFullColorListFrm.Execute: Boolean; +begin + Result := (ShowModal = mrOK); +end; + +function TJvFullColorListFrm.GetColorList: TJvFullColorList; +var + Index: Integer; +begin + FColorList.BeginUpdate; + FColorList.Clear; + for Index := 0 to ListBoxColors.Items.Count - 1 do + FColorList.Add(TJvFullColor(ListBoxColors.Items.Objects[Index])); + FColorList.EndUpdate; + Result := FColorList; +end; + +procedure TJvFullColorListFrm.SetColorList(const Value: TJvFullColorList); +var + I: Integer; +begin + with ListBoxColors.Items, ColorSpaceManager do + begin + BeginUpdate; + for I := 0 to Value.Count - 1 do + AddObject('', TObject(Value.Items[I])); + EndUpdate; + end; +end; + +procedure TJvFullColorListFrm.ButtonApplyClick(Sender: TObject); +begin + if Assigned(FOnApply) then + FOnApply(Self); +end; + +procedure TJvFullColorListFrm.JvFullColorDialogApply(Sender: TObject; + AFullColor: TJvFullColor); +begin + ListBoxColors.Items.Objects[ListBoxColors.ItemIndex] := TObject(JvFullColorDialog.FullColor); +end; + +procedure TJvFullColorListFrm.ListBoxColorsDrawItem(Control: TWinControl; + Index: Integer; Rect: TRect; State: TOwnerDrawState); +var + AFullColor: TJvFullColor; + AText: string; + ColorIndex: Integer; + AColor: TColor; + AColorSpace: TJvColorSpace; +begin + with TListBox(Control), Canvas do + begin + if odSelected in State then + Font.Color := clCaptionText; + + Pen.Style := psSolid; + Pen.Color := Brush.Color; + Brush.Style := bsSolid; + + Rectangle(Rect); + + AFullColor := TJvFullColor(Items.Objects[Index]); + + with ColorSpaceManager do + begin + AColorSpace := ColorSpace[GetColorSpaceID(AFullColor)]; + + if AColorSpace.ID = csDEF then + with TJvDEFColorSpace(AColorSpace) do + begin + AColor := ConvertToColor(AFullColor); + AText := Format(RsUnnamedColorFmt, [Name, AFullColor]); + for ColorIndex := 0 to ColorCount - 1 do + if AColor = ColorValue[ColorIndex] then + begin + AText := Format(RsUnnamedColorFmt, [Name, ColorName[ColorIndex], ColorPrettyName[ColorIndex]]); + Break; + end; + end + else + with AColorSpace do + AText := Format('%s: %s = $%.2x; %s = $%.2x; %s = $%.2x', + [Name, + AxisName[axIndex0], GetAxisValue(AFullColor, axIndex0), + AxisName[axIndex1], GetAxisValue(AFullColor, axIndex1), + AxisName[axIndex2], GetAxisValue(AFullColor, axIndex2)]); + + TextOut(Rect.Left + Rect.Bottom - Rect.Top + 2, Rect.Top + 2, AText); + end; + + Brush.Color := ColorSpaceManager.ConvertToColor(AFullColor); + Pen.Color := clBlack; + Rectangle(Rect.Left + 2, Rect.Top + 2, Rect.Left + Rect.Bottom - Rect.Top - 2, Rect.Bottom - 2); + end; +end; + +end. diff --git a/components/jvcllaz/design/JvMM/jvfullcolorspaceseditors.pas b/components/jvcllaz/design/JvMM/jvfullcolorspaceseditors.pas new file mode 100644 index 000000000..80204058a --- /dev/null +++ b/components/jvcllaz/design/JvMM/jvfullcolorspaceseditors.pas @@ -0,0 +1,770 @@ +{----------------------------------------------------------------------------- +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: ColorSpacesEditors.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 JvFullColorSpacesEditors; + +{$mode objfpc}{$H+} + +interface + +uses + //Windows, + Classes, Graphics, + PropEdits, + //DesignIntf, DesignEditors, DesignMenus, VCLEditors, + JvFullColorSpaces; + +type + TJvDEFFamily = (pfConstant, pfSystem); + + TJvFullColorProperty = class(TPropertyEditor) //, ICustomPropertyDrawing) + private + function GetIsColorProperty: Boolean; + procedure DialogApply(Sender: TObject; AFullColor: TJvFullColor); + public + function GetAttributes: TPropertyAttributes; override; + procedure GetProperties(Proc: TGetPropEditProc); override; //TGetPropProc); override; + procedure GetValues(Proc: TGetStrProc); override; + function GetValue: string; override; + procedure SetValue(const Value: string); override; + procedure Edit; override; + procedure EditSpace(AColorID: TJvFullColorSpaceID); + procedure SetColor(AFullColor: TJvFullColor); + // ICustomPropertyDrawing + procedure PropDrawName(ACanvas: TCanvas; const ARect: TRect; ASelected: Boolean); + procedure PropDrawValue(ACanvas: TCanvas; const ARect: TRect; ASelected: Boolean); + property IsColorProperty: Boolean read GetIsColorProperty; + end; + + TJvFullColorSpaceProperty = class(TNestedProperty) + private + FColorSpace: TJvColorSpace; + FParent: TJvFullColorProperty; + public + constructor Create(AParent: TJvFullColorProperty; AColorSpace: TJvColorSpace; + AIsColorProperty: Boolean); + (************* NOT CONVERTED *** + function GetName: string; override; + *******************************) + function GetAttributes: TPropertyAttributes; override; + function GetValue: string; override; + procedure GetProperties(Proc: TGetPropEditProc); override; //TGetPropProc); override; + procedure Edit; override; + property ColorSpace: TJvColorSpace read FColorSpace; + property Parent: TJvFullColorProperty read FParent; + end; + + TJvFullColorSpacePropertyClass = class of TJvFullColorSpaceProperty; + + TJvFullColorAxisProperty = class(TNestedProperty) //, ICustomPropertyListDrawing) + private + FAxisIndex: TJvAxisIndex; + FParent:TJvFullColorSpaceProperty; + public + constructor Create(AParent: TJvFullColorSpaceProperty; + AAxisIndex: TJvAxisIndex); + (**************** NOT CONVERTED *** + function GetName: string; override; + **********************************) + function GetAttributes: TPropertyAttributes; override; + function GetValue: string; override; + procedure SetValue(const Value: string); override; + procedure GetValues(Proc: TGetStrProc); override; + // ICustomPropertyListDrawing + procedure ListMeasureHeight(const Value: string; ACanvas: TCanvas; + var AHeight: Integer); + procedure ListMeasureWidth(const Value: string; ACanvas: TCanvas; + var AWidth: Integer); + procedure ListDrawValue(const Value: string; ACanvas: TCanvas; + const ARect: TRect; ASelected: Boolean); virtual; + property Parent: TJvFullColorSpaceProperty read FParent; + property AxisIndex: TJvAxisIndex read FAxisIndex; + end; + + TJvDEFColorSpaceProperty = class(TJvFullColorSpaceProperty) + public + procedure GetProperties(Proc: TGetPropEditProc); override; //TGetPropProc); override; + end; + + TJvDEFColorSpaceIndentProperty = class(TNestedProperty) //, ICustomPropertyListDrawing) + private + FPredefinedFamily: TJvDEFFamily; + FParent: TJvDEFColorSpaceProperty; + public + constructor Create(AParent: TJvDEFColorSpaceProperty; + APredefinedFamily: TJvDEFFamily); + (*******NOT CONVERTED *** + function GetName: string; override; + ************************) + function GetAttributes: TPropertyAttributes; override; + function GetValue: string; override; + procedure SetValue(const Value: string); override; + procedure GetValues(Proc: TGetStrProc); override; + // ICustomPropertyListDrawing + procedure ListMeasureHeight(const Value: string; ACanvas: TCanvas; + var AHeight: Integer); + procedure ListMeasureWidth(const Value: string; ACanvas: TCanvas; + var AWidth: Integer); + procedure ListDrawValue(const Value: string; ACanvas: TCanvas; + const ARect: TRect; ASelected: Boolean); virtual; + property Parent: TJvDEFColorSpaceProperty read FParent; + property PredefinedFamily: TJvDEFFamily read FPredefinedFamily; + end; + + (********************* NOT CONVERTED *** + TJvFullColorSelection = class(TSelectionEditor) + protected + procedure RequireClass(Proc: TGetStrProc; AClass: TClass); + public + procedure ExecuteVerb(Index: Integer; const List: IDesignerSelections); override; + function GetVerb(Index: Integer): string; override; + function GetVerbCount: Integer; override; + procedure RequiresUnits(Proc: TGetStrProc); override; + procedure PrepareItem(Index: Integer; const AItem: IMenuItem); override; + end; + + TJvFullColorListEditor = class(TClassProperty) + public + function GetAttributes: TPropertyAttributes; override; + procedure Edit; override; + function AllEqual: Boolean; override; + procedure FormApply(Sender: TObject); + end; +**********************) + +procedure RegisterFullColorSpaceEditor(AColorSpaceID: TJvFullColorSpaceID; + AEditorClass: TJvFullColorSpacePropertyClass); + +function FindFullColorSpaceEditor(AColorSpaceID: TJvFullColorSpaceID): TJvFullColorSpacePropertyClass; + +var + DefaultFullColorSpacePropertyClass: TJvFullColorSpacePropertyClass = TJvFullColorSpaceProperty; + +implementation + +uses + Math, SysUtils, {DesignConst, }TypInfo, Forms; +// JvFullColorDialogs, JvFullColorCtrls, JvFullColorListForm, JvJCLUtils; + +const + COLOR_PREVIEW_RECT = 16; + COLOR_PREVIEW_LINE = 1; + COLOR_PREVIEW_SIZE = COLOR_PREVIEW_RECT + 2 * COLOR_PREVIEW_LINE; + +function HexToInt(Value: string): Byte; +begin + if Value = '' then + Result := 0 + else + begin + if Length(Value) > 3 then + Value := Copy(Value, 1, 3); + Result := StrToInt(Value); + end; +end; + +procedure ColorPropertyListDrawValue(AColor: TColor; AValue: string; + ACanvas: TCanvas; ARect: TRect; ASelected: Boolean); +var + OldBrushColor: TColor; + OldPenColor: TColor; +begin + with ACanvas do + begin + OldBrushColor := Brush.Color; + OldPenColor := Pen.Color; + + Pen.Color := Brush.Color; + Rectangle(ARect); + + Brush.Color := AColor; + Pen.Color := clBlack; + Rectangle(ARect.Left + COLOR_PREVIEW_LINE, + ARect.Top + COLOR_PREVIEW_LINE, + ARect.Left + COLOR_PREVIEW_LINE + COLOR_PREVIEW_RECT, + ARect.Top + COLOR_PREVIEW_LINE + COLOR_PREVIEW_RECT); + + Pen.Color := OldPenColor; + Brush.Color := OldBrushColor; + TextOut(ARect.Left + COLOR_PREVIEW_SIZE, ARect.Top, AValue); + end; +end; + +//=== { TJvFullColorProperty } =============================================== + +procedure TJvFullColorProperty.DialogApply(Sender: TObject; AFullColor: TJvFullColor); +begin + SetColor(AFullColor); +end; + +procedure TJvFullColorProperty.Edit; +begin + if IsColorProperty then + // a dummy param + EditSpace(csRGB) + else + EditSpace(ColorSpaceManager.GetColorSpaceID(GetOrdValue)); +end; + +procedure TJvFullColorProperty.EditSpace(AColorID: TJvFullColorSpaceID); +var + LColor: TJvFullColor; +begin + (******************** NOT CONVERTED *** + with ColorSpaceManager, TJvFullColorDialog.Create(nil) do + try + if IsColorProperty then + begin + LColor := ColorSpaceManager.ConvertFromColor(TColor(GetOrdValue)); + // reset dummy param + AColorID := ColorSpaceManager.GetColorSpaceID(LColor); + end + else + LColor := TJvFullColor(GetOrdValue); + if GetColorSpaceID(LColor) <> AColorID then + LColor := ConvertToID(LColor, AColorID); + + FullColor := LColor; + Title := ''; + OnApply := DialogApply; + Options := [foFullOpen, foAllowSpaceChange, foShowNewPreview, foShowOldPreview, + foShowPredefined, foAllowVariable, foNoneAndDefault, foShowApply]; + + if Execute then + SetColor(FullColor); + finally + Free; + end; + **********************) +end; + +function TJvFullColorProperty.GetAttributes: TPropertyAttributes; +begin + Result := [paSubProperties, paDialog, paMultiSelect, paVolatileSubProperties, {paVCL,} + paRevertable]; + if IsColorProperty then + Result := Result + [paReadOnly] + else + Result := Result + [paValueList, paSortList]; +end; + +function TJvFullColorProperty.GetIsColorProperty: Boolean; +begin + Result := (GetPropType = TypeInfo(TColor)); +end; + +procedure TJvFullColorProperty.GetProperties(Proc: TGetPropEditProc); //TGetPropProc); +var + I: Integer; + CS: TJvColorSpace; +begin + with ColorSpaceManager do + for I := 0 to Count - 1 do + begin + CS := ColorSpaceByIndex[I]; + Proc(FindFullColorSpaceEditor(CS.ID).Create(Self, CS, IsColorProperty)); + end; +end; + +function TJvFullColorProperty.GetValue: string; +var + Value: TJvFullColor; +begin + Value := GetOrdValue; + + with ColorSpaceManager do + if IsColorProperty then + Result := {$IFDEF SUPPORTS_UNICODE}UTF8ToString{$ENDIF SUPPORTS_UNICODE}(GetPropType^.Name) + else + Result := Format('%s [%s]', [{$IFDEF SUPPORTS_UNICODE}UTF8ToString{$ENDIF SUPPORTS_UNICODE}(GetPropType^.Name), ColorSpace[GetColorSpaceID(Value)].ShortName]); +end; + +procedure TJvFullColorProperty.GetValues(Proc: TGetStrProc); +var + I: Integer; +begin + with ColorSpaceManager do + for I := 0 to Count - 1 do + Proc(ColorSpaceByIndex[I].ShortName); +end; + +procedure TJvFullColorProperty.PropDrawName(ACanvas: TCanvas; + const ARect: TRect; ASelected: Boolean); +begin + (**************** NOT CONVERTED *** + DefaultPropertyDrawName(Self, ACanvas, ARect); + **********************************) +end; + +procedure TJvFullColorProperty.PropDrawValue(ACanvas: TCanvas; + const ARect: TRect; ASelected: Boolean); +var + OldPenColor, OldBrushColor: TColor; + Right: Integer; +begin + with ACanvas do + begin + Rectangle(ARect); + + OldBrushColor := Brush.Color; + if IsColorProperty then + Brush.Color := GetOrdValue + else + Brush.Color := ColorSpaceManager.ConvertToColor(TJvFullColor(GetOrdValue)); + OldPenColor := Pen.Color; + Pen.Color := clBlack; + + Right := (ARect.Bottom - ARect.Top) + ARect.Left; + + Rectangle(ARect.Left + 1, ARect.Top + 1, Right - 1, ARect.Bottom - 1); + + Pen.Color := OldPenColor; + Brush.Color := OldBrushColor; + end; + (******************** NOT CONVERTED *** + DefaultPropertyDrawValue(Self, ACanvas, Rect(Right, ARect.Top, ARect.Right, ARect.Bottom)); + **************************************) +end; + +procedure TJvFullColorProperty.SetColor(AFullColor: TJvFullColor); +begin + with ColorSpaceManager do + if IsColorProperty then + SetOrdValue(Ord(ConvertToColor(AFullColor))) + else + SetOrdValue(Ord(AFullColor)); +end; + +procedure TJvFullColorProperty.SetValue(const Value: string); +var + I: Integer; + LColor: TJvFullColor; + LColorSpace: TJvColorSpace; +begin + LColor := GetOrdValue; + with ColorSpaceManager do + for I := 0 to Count - 1 do + begin + LColorSpace := ColorSpaceByIndex[I]; + if LColorSpace.ShortName = Value then + begin + LColor := ColorSpaceManager.ConvertToID(LColor, LColorSpace.ID); + SetOrdValue(Ord(LColor)); + Break; + end; + end; +end; + +//=== { TJvFullColorSpaceProperty } ========================================== + +constructor TJvFullColorSpaceProperty.Create(AParent: TJvFullColorProperty; + AColorSpace: TJvColorSpace; AIsColorProperty: Boolean); +begin + inherited Create(AParent); + FParent := AParent; + FColorSpace := AColorSpace; +end; + +procedure TJvFullColorSpaceProperty.Edit; +begin + Parent.EditSpace(ColorSpace.ID); +end; + +function TJvFullColorSpaceProperty.GetAttributes: TPropertyAttributes; +begin + Result := [paSubProperties, paDialog, paMultiSelect, paReadOnly, paVolatileSubProperties, //paVCL, + paRevertable]; +end; + +(******************* NOT CONVERTED *** +function TJvFullColorSpaceProperty.GetName: string; +begin + Result := ColorSpace.ShortName; +end; +************************************) + +procedure TJvFullColorSpaceProperty.GetProperties(Proc: TGetPropEditProc); //TGetPropProc); +var + I: TJvAxisIndex; +begin + for I := Low(TJvAxisIndex) to High(TJvAxisIndex) do + Proc(TJvFullColorAxisProperty.Create(Self, I)); +end; + +function TJvFullColorSpaceProperty.GetValue: string; +begin + Result := ColorSpace.Name; +end; + +//=== { TJvFullColorAxisProperty } =========================================== + +constructor TJvFullColorAxisProperty.Create(AParent: TJvFullColorSpaceProperty; + AAxisIndex: TJvAxisIndex); +begin + inherited Create(AParent.Parent); + FParent := AParent; + FAxisIndex := AAxisIndex; +end; + +function TJvFullColorAxisProperty.GetAttributes: TPropertyAttributes; +begin + Result := [paValueList, paMultiSelect, paRevertable]; +end; + +(******************* NOT CONVERTED *** +function TJvFullColorAxisProperty.GetName: string; +begin + Result := Parent.ColorSpace.AxisName[AxisIndex]; +end; +************************************) + +function TJvFullColorAxisProperty.GetValue: string; +begin + Result := + Format('$%.2x', [GetAxisValue(ColorSpaceManager.ConvertToID(GetOrdValue, Parent.ColorSpace.ID), AxisIndex)]); +end; + +procedure TJvFullColorAxisProperty.GetValues(Proc: TGetStrProc); +var + I: Byte; +begin + with Parent.ColorSpace do + for I := AxisMin[AxisIndex] to AxisMax[AxisIndex] do + Proc(Format('$%.2x', [I])); +end; + +procedure TJvFullColorAxisProperty.ListDrawValue(const Value: string; + ACanvas: TCanvas; const ARect: TRect; ASelected: Boolean); +var + FullColor: TJvFullColor; + LColor: TColor; +begin + FullColor := ColorSpaceManager.ConvertToID(GetOrdValue, Parent.ColorSpace.ID); + FullColor := SetAxisValue(FullColor, AxisIndex, HexToInt(Value)); + LColor := Parent.ColorSpace.ConvertToColor(FullColor); + ColorPropertyListDrawValue(LColor, Value, ACanvas, ARect, ASelected); +end; + +procedure TJvFullColorAxisProperty.ListMeasureHeight(const Value: string; + ACanvas: TCanvas; var AHeight: Integer); +begin + AHeight := Max(ACanvas.TextHeight(Value), COLOR_PREVIEW_SIZE); +end; + +procedure TJvFullColorAxisProperty.ListMeasureWidth(const Value: string; + ACanvas: TCanvas; var AWidth: Integer); +begin + AWidth := ACanvas.TextWidth(Value) + COLOR_PREVIEW_SIZE; +end; + +procedure TJvFullColorAxisProperty.SetValue(const Value: string); +var + AxisValue: Byte; + LColor: TJvFullColor; + LColorID: TJvFullColorSpaceID; +begin + AxisValue := HexToInt(Value); + LColor := TJvFullColor(GetOrdValue); + LColorID := ColorSpaceManager.GetColorSpaceID(LColor); + LColor := ColorSpaceManager.ConvertToID(LColor, Parent.ColorSpace.ID); + LColor := SetAxisValue(LColor, AxisIndex, AxisValue); + if not Parent.Parent.IsColorProperty then + SetOrdValue(Ord(ColorSpaceManager.ConvertToID(LColor, LColorID))) + else + SetOrdValue(Ord(ColorSpaceManager.ConvertToColor(LColor))); +end; + +//=== { TJvDEFColorSpaceProperty } =========================================== + +procedure TJvDEFColorSpaceProperty.GetProperties(Proc: TGetPropEditProc); //TGetPropProc); +begin + Proc(TJvDEFColorSpaceIndentProperty.Create(Self, pfConstant)); + Proc(TJvDEFColorSpaceIndentProperty.Create(Self, pfSystem)); +end; + +//=== { TJvDEFColorSpaceIndentProperty } ===================================== + +constructor TJvDEFColorSpaceIndentProperty.Create(AParent: TJvDEFColorSpaceProperty; + APredefinedFamily: TJvDEFFamily); +begin + inherited Create(AParent.Parent); + FParent := AParent; + FPredefinedFamily := APredefinedFamily; +end; + +function TJvDEFColorSpaceIndentProperty.GetAttributes: TPropertyAttributes; +begin + Result := [paValueList, paMultiSelect, paRevertable]; +end; + +(*********************** NOT CONVERTED *** +function TJvDEFColorSpaceIndentProperty.GetName: string; +begin + Result := GetEnumName(TypeInfo(TJvDEFFamily), Ord(PredefinedFamily)); + Result := Copy(Result, 3, Length(Result) - 2); +end; +****************************************) + +function TJvDEFColorSpaceIndentProperty.GetValue: string; +var + AColor: TColor; +begin + if Parent.Parent.IsColorProperty then + AColor := GetOrdValue + else + AColor := ColorSpaceManager.ConvertToColor(TJvFullColor(GetOrdValue)); + if ((AColor and JvSystemColorMask) <> 0) xor (PredefinedFamily = pfConstant) then + Result := ColorToPrettyName(AColor) + else + Result := ''; +end; + +procedure TJvDEFColorSpaceIndentProperty.GetValues(Proc: TGetStrProc); +var + I: Integer; + AColor: TColor; + CS: TJvDEFColorSpace; +begin + CS := TJvDEFColorSpace(Parent.ColorSpace); + for I := 0 to CS.ColorCount - 1 do + begin + AColor := CS.ColorValue[I]; + if ((AColor and JvSystemColorMask) <> 0) xor (PredefinedFamily = pfConstant) then + Proc(CS.ColorPrettyName[I]); + end; +end; + +procedure TJvDEFColorSpaceIndentProperty.ListDrawValue(const Value: string; + ACanvas: TCanvas; const ARect: TRect; ASelected: Boolean); +begin + ColorPropertyListDrawValue(PrettyNameToColor(Value), Value, ACanvas, ARect, ASelected); +end; + +procedure TJvDEFColorSpaceIndentProperty.ListMeasureHeight(const Value: string; + ACanvas: TCanvas; var AHeight: Integer); +begin + AHeight := Max(ACanvas.TextHeight(Value), COLOR_PREVIEW_SIZE); +end; + +procedure TJvDEFColorSpaceIndentProperty.ListMeasureWidth(const Value: string; + ACanvas: TCanvas; var AWidth: Integer); +begin + AWidth := ACanvas.TextWidth(Value) + COLOR_PREVIEW_SIZE; +end; + +procedure TJvDEFColorSpaceIndentProperty.SetValue(const Value: string); +var + I:Integer; + CS: TJvDEFColorSpace; + clPrefix: string; +begin + clPrefix := Copy(ColorToString(clBlack), 1, 2); + CS := TJvDEFColorSpace(Parent.ColorSpace); + for I := 0 to CS.ColorCount - 1 do + if (CompareText(Value, CS.ColorName[I]) = 0) or + (CompareText(Value, clPrefix + CS.ColorName[I]) = 0) or + (CompareText(Value, CS.ColorPrettyName[I]) = 0) then + begin + if Parent.Parent.IsColorProperty then + SetOrdValue(CS.ColorValue[I]) + else + if (CS.ColorValue[I] and JvSystemColorMask) <> 0 then + SetOrdValue(CS.ConvertFromColor(CS.ColorValue[I])) + else + with ColorSpaceManager do + SetOrdValue(ConvertToID(ConvertFromColor(CS.ColorValue[I]), GetColorSpaceID(GetOrdValue))); + Break; + end; +end; + +(****************** NOT CONVERTED *** +//=== { TJvColorSelection } ================================================== + +procedure TJvFullColorSelection.ExecuteVerb(Index: Integer; const List: IDesignerSelections); +begin + // No execution + inherited ExecuteVerb(Index, List); +end; + +function TJvFullColorSelection.GetVerb(Index: Integer): string; +begin + // No menu item + Result := ''; +end; + +function TJvFullColorSelection.GetVerbCount: Integer; +begin + // No menu item + Result := 0; +end; + +procedure TJvFullColorSelection.PrepareItem(Index: Integer; const AItem: IMenuItem); +begin + // No menu item + inherited PrepareItem(Index, AItem); +end; + +procedure TJvFullColorSelection.RequireClass(Proc: TGetStrProc; AClass: TClass); +var + LTypInfo: PTypeInfo; +begin + LTypInfo := AClass.ClassInfo; + if LTypInfo <> nil then + Proc({$IFDEF SUPPORTS_UNICODE}UTF8ToString{$ENDIF SUPPORTS_UNICODE}(GetTypeData(LTypInfo).UnitName)); +end; + +procedure TJvFullColorSelection.RequiresUnits(Proc: TGetStrProc); +var + I: Integer; +begin + inherited RequiresUnits(Proc); + + RequireClass(Proc, TJvColorSpace); + + with ColorSpaceManager do + for I := 0 to Count - 1 do + RequireClass(Proc, ColorSpaceByIndex[I].ClassType); +end; + +//=== { TJvFullColorListEditor } ============================================= + +function TJvFullColorListEditor.AllEqual: Boolean; +var + IndexList, IndexColor: Integer; + FullColorList: TJvFullColorList; +begin + Result := False; + if PropCount > 1 then + begin + FullColorList := TJvFullColorList.Create; + FullColorList.Assign(TJvFullColorList(GetOrdValue)); + + for IndexList := 1 to PropCount - 1 do + with TJvFullColorList(GetOrdValueAt(IndexList)) do + for IndexColor:=0 to Count - 1 do + if FullColorList.Items[IndexColor] <> Items[IndexColor] then + Exit; + end; + Result := True; +end; + +procedure TJvFullColorListEditor.Edit; +var + FullColorListForm: TJvFullColorListFrm; + FullColorList: TJvFullColorList; + IndexList, IndexColor: Integer; +begin + FullColorListForm := TJvFullColorListFrm.Create(Application); + try + FullColorList:=TJvFullColorList.Create; + try + for IndexList := 0 to PropCount - 1 do + with TJvFullColorList(GetOrdValueAt(IndexList)) do + for IndexColor := 0 to Count - 1 do + if FullColorList.IndexOf(Items[IndexColor]) = -1 then + FullColorList.Add(Items[IndexColor]); + + FullColorListForm.OnApply := FormApply; + FullColorListForm.ColorList := FullColorList; + if FullColorListForm.Execute then + FormApply(FullColorListForm); + finally + FullColorList.Free; + end; + finally + FullColorListForm.Free; + end; +end; + +procedure TJvFullColorListEditor.FormApply(Sender: TObject); +begin + SetOrdValue(Cardinal((Sender as TJvFullColorListFrm).ColorList)); +end; + +function TJvFullColorListEditor.GetAttributes: TPropertyAttributes; +begin + Result := [paDialog, paVCL, paMultiSelect]; +end; +********************) + +var + GFullColorSpaceEditorArray: array of TJvFullColorSpacePropertyClass; + +{procedure ModuleUnloadProc(HInstance: Integer); +var + Index: Integer; + AEditorClass: TJvFullColorSpacePropertyClass; +begin + for Index := High(GFullColorSpaceEditorArray) downto 0 do + begin + AEditorClass := GFullColorSpaceEditorArray[Index]; + if (AEditorClass <> nil) and (AEditorClass <> TJvFullColorSpaceProperty) and IsClassInModule(HInstance, AEditorClass) then + GFullColorSpaceEditorArray[Index] := nil; + end; +end;} + +procedure InitFullColorSpaceEditorArray; +var + ACount: Integer; + Index: Integer; +begin + ACount := (High(TJvFullColorSpaceID) - Low(TJvFullColorSpaceID) + 1) shr 2; + SetLength(GFullColorSpaceEditorArray, ACount); + for Index := 0 to High(GFullColorSpaceEditorArray) do + GFullColorSpaceEditorArray[Index] := nil; +end; + +procedure RegisterFullColorSpaceEditor(AColorSpaceID: TJvFullColorSpaceID; + AEditorClass: TJvFullColorSpacePropertyClass); +begin + if GFullColorSpaceEditorArray = nil then + begin + InitFullColorSpaceEditorArray; + //RegisterFullColorSpaceEditor(csDEF, TJvDEFColorSpaceProperty); + GFullColorSpaceEditorArray[csDEF shr 2] := TJvDEFColorSpaceProperty; + end; + + GFullColorSpaceEditorArray[AColorSpaceID shr 2] := AEditorClass; + // todo (outchy) notification for changing +end; + +function FindFullColorSpaceEditor(AColorSpaceID: TJvFullColorSpaceID): TJvFullColorSpacePropertyClass; +begin + if GFullColorSpaceEditorArray = nil then + InitFullColorSpaceEditorArray; + Result := GFullColorSpaceEditorArray[AColorSpaceID shr 2]; + if Result = nil then + Result := DefaultFullColorSpacePropertyClass; +end; + + + +//initialization +// AddModuleUnloadProc(ModuleUnloadProc); + +//finalization +// RemoveModuleUnloadProc(ModuleUnloadProc); + +end. diff --git a/components/jvcllaz/packages/JvMMLazD.lpk b/components/jvcllaz/packages/JvMMLazD.lpk index b6e4cb608..a6fe46be0 100644 --- a/components/jvcllaz/packages/JvMMLazD.lpk +++ b/components/jvcllaz/packages/JvMMLazD.lpk @@ -15,7 +15,7 @@ - + @@ -29,6 +29,14 @@ + + + + + + + + diff --git a/components/jvcllaz/packages/JvMMLazR.lpk b/components/jvcllaz/packages/JvMMLazR.lpk index c46d72286..3b8b3dddf 100644 --- a/components/jvcllaz/packages/JvMMLazR.lpk +++ b/components/jvcllaz/packages/JvMMLazR.lpk @@ -16,7 +16,7 @@ - + @@ -49,6 +49,34 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/components/jvcllaz/resource/jvmmreg.res b/components/jvcllaz/resource/jvmmreg.res index 420ba21ab7de5ca6ae3e8ee2d50314781337e099..b7c89f4e5fe81fcb5e74fe236f98cc79b4345ab7 100644 GIT binary patch delta 4962 zcmchb&2Ah;5XWnGXLlkbb09&nOrqce$^i+%A+m(nZf%^91Przk^KprkOMnv}PteDl zVJ^viA0PrQIr;&R;lKlsC&+bX$2A^ zEB<)roU06EJf7F}Y*yE`F=eF!Ue)s&6hGFK&@qx*8M!TuS9m4jczf`LqB04$P^e2~ zT&l2%LO5bsTUrYjF9@V!%W|PWk3~NokG*~H@R%PELA-=e{;wN1D`c84m1f$u&zq?T zxc{L4=8d?6Hq&90Y183ORbD}PzRUrWyp(eb%j_dhdW42W*glc{#`hC0t^OyTh7;|^ z35m9iG`ov5+o798KFQWIM;K%x$u7=|m?#9w8cecgoslVI3PCn%)@drDanW?SSmPFw zNX<1Hj6?cD5UZnjIfsi?huA>Kx(?^?5Y8@WLe{YtsBxTjbUf|IEO<<99uG1wR)?s- zU>RY2Fbl_rS{>lxami5vXQkp0OYC2PZzT?wC6;!0D{8cb z;)AvGcktOepbMO5d#{jZH;{7^DRj3&&P_5md(!K5u9NxqasN<2&P3Xdh+^ zdulM4jZ+(>l0Gq!47j>77k{`5m)=4d?Q@QUNYY#r?fKsYZrOWFf4|gnNHolU{_D;6 zxqXsV6K{m4C9{>(oaAHi!^ZZN<8QVzn0zjyURskMApS16JZSD_V0m79MVS0NpXC*J zogcL)Kc7JX4n@fU!eoNOehv%{MVR~&yaKPmd47U@c`Ni!YLu zyd9_bbNy{+AyO;#7G5r>zuiV9wJkk*MAp#r=iKO%CvozH+sIiv9AeHm4wvj!G;lAj z-FjNHTirs9UloY5j2jpXxLeaHH~ioMH@x7s#bbxy_1dCe#nY=7G9HEEpR4D;k>N<% zY(0WSmEkt4itl(#v|QI%?Z>!Pp0*i3o2}x`Ab?XiJTX>pFkFYWP|l;fp<=hrta)KSslctwZq1bgq*=CV^j z8_1KEJwJg;%B}e@U^pcWqzM&=2OrWr=NTS~dojTT*o}uPCSVT}@cD`fSa$yVdlv!)MLC!aX8o#Pjpn0yR%i9_ zXn52sdp+O*a36RCoB_u@f!(j1B;G?HVX-eSA)H$CMgiGz_ov3g* zKQQ-)18$-?Iq!mT1n}mDP`fuBHpsGExU`0;LKxmS%fjciIoI`%-tZzorSc1n zxr*3h*@zFgIXpZxv++#1w86&a5ErYV3sWWHY3tk?pUc)tuFW+xDd3uHN_)Ulgvf(|T4;pqEwqqap zD*L6}p_QicSGNJhO_zsnC3rEj#ExnpEUp$0_Lx%P;e5&bBfbTPaPnlvf_;cg$(AZS JWe!28e*vX<;=BL= delta 8 PcmdmTm2pPwh8cPQ6I%oJ diff --git a/components/jvcllaz/run/JvMM/jvfullcolorcircleform.lfm b/components/jvcllaz/run/JvMM/jvfullcolorcircleform.lfm new file mode 100644 index 000000000..8a24bc8e6 --- /dev/null +++ b/components/jvcllaz/run/JvMM/jvfullcolorcircleform.lfm @@ -0,0 +1,972 @@ +object JvFullColorCircleFrm: TJvFullColorCircleFrm + Left = 274 + Height = 573 + Top = 219 + Width = 997 + AutoSize = True + BorderStyle = bsDialog + Caption = 'Color circle configurations' + ClientHeight = 573 + ClientWidth = 997 + Color = clBtnFace + Font.Color = clWindowText + KeyPreview = True + OnCreate = FormCreate + OnShow = FormShow + LCLVersion = '2.1.0.0' + object LabelOld: TLabel + AnchorSideLeft.Control = PanelImageOld + AnchorSideTop.Control = JvColorSpaceCombo + AnchorSideTop.Side = asrBottom + Left = 72 + Height = 15 + Top = 58 + Width = 22 + BorderSpacing.Top = 8 + Caption = 'Old:' + ParentColor = False + end + object LabelNew: TLabel + AnchorSideLeft.Control = PanelImageNew + AnchorSideTop.Control = LabelOld + Left = 216 + Height = 15 + Top = 58 + Width = 27 + Caption = 'New:' + ParentColor = False + end + object LabelColorSpace: TLabel + AnchorSideLeft.Control = JvColorSpaceCombo + AnchorSideTop.Control = Owner + Left = 103 + Height = 15 + Top = 8 + Width = 66 + BorderSpacing.Top = 8 + Caption = '&Color Space:' + ParentColor = False + end + object PanelGraphics: TPanel + AnchorSideLeft.Control = PanelCommonSettings + AnchorSideLeft.Side = asrBottom + AnchorSideTop.Control = LabelColorSpace + AnchorSideRight.Control = Owner + AnchorSideRight.Side = asrBottom + AnchorSideBottom.Control = ButtonOK + AnchorSideBottom.Side = asrBottom + Left = 412 + Height = 550 + Top = 8 + Width = 577 + Anchors = [akTop, akLeft, akRight, akBottom] + BorderSpacing.Right = 8 + BevelInner = bvRaised + BevelOuter = bvLowered + Caption = 'PanelGraphics' + ClientHeight = 550 + ClientWidth = 577 + TabOrder = 5 + object LabelAxisSettings: TLabel + AnchorSideLeft.Control = JvColorAxisConfigCombo + AnchorSideTop.Control = PanelGraphics + Left = 201 + Height = 15 + Top = 10 + Width = 69 + BorderSpacing.Top = 8 + Caption = 'A&xis Settings:' + FocusControl = JvColorAxisConfigCombo + ParentColor = False + end + object JvColorCircle: TJvFullColorCircle + AnchorSideLeft.Control = Bevel10 + AnchorSideLeft.Side = asrBottom + AnchorSideTop.Control = JvColorAxisConfigCombo + AnchorSideTop.Side = asrBottom + AnchorSideRight.Control = PanelGraphics + AnchorSideRight.Side = asrBottom + AnchorSideBottom.Control = PanelGraphics + AnchorSideBottom.Side = asrBottom + Left = 100 + Height = 480 + Top = 60 + Width = 459 + Anchors = [akTop, akLeft, akRight, akBottom] + BorderSpacing.Left = 8 + BorderSpacing.Top = 8 + BorderSpacing.Right = 16 + BorderSpacing.Bottom = 8 + FullColor = 83886079 + AxisConfig = acYZX + TabOrder = 1 + OnColorChange = JvColorCircleColorChange + OnColorSpaceChange = JvColorCircleColorSpaceChange + CrossSize = 10 + CrossCenter = 3 + CrossStyle.Width = 3 + LineWidth = 0 + RedTrackBar = JvFullColorTrackBarRed + GreenTrackBar = JvFullColorTrackBarGreen + BlueTrackBar = JvFullColorTrackBarBlue + CommonTrackBar = JvFullColorTrackBarCommon + OnRedColorChange = JvColorCircleRedColorChange + OnGreenColorChange = JvColorCircleGreenColorChange + OnBlueColorChange = JvColorCircleBlueColorChange + end + object JvFullColorTrackBarCommon: TJvFullColorTrackBar + AnchorSideTop.Control = JvColorCircle + AnchorSideBottom.Control = Bevel10 + Left = 40 + Height = 237 + Top = 60 + Width = 21 + Anchors = [akTop, akLeft, akBottom] + FullColor = 83886079 + AxisConfig = acYZX + TabOrder = 2 + ArrowWidth = 10 + ColorOrientation = coInverse + Orientation = trVertical + end + object JvFullColorTrackBarBlue: TJvFullColorTrackBar + AnchorSideLeft.Control = JvFullColorTrackBarGreen + AnchorSideLeft.Side = asrBottom + AnchorSideTop.Control = Bevel10 + AnchorSideTop.Side = asrBottom + AnchorSideBottom.Control = JvFullColorTrackBarRed + AnchorSideBottom.Side = asrBottom + Left = 68 + Height = 237 + Top = 303 + Width = 21 + Anchors = [akTop, akLeft, akBottom] + BorderSpacing.Left = 8 + FullColor = 83820544 + AxisConfig = acYZX + TabOrder = 5 + ArrowColor = clBlue + ArrowWidth = 10 + ColorOrientation = coInverse + Orientation = trVertical + end + object JvFullColorTrackBarGreen: TJvFullColorTrackBar + AnchorSideLeft.Control = JvFullColorTrackBarRed + AnchorSideLeft.Side = asrBottom + AnchorSideTop.Control = Bevel10 + AnchorSideTop.Side = asrBottom + AnchorSideBottom.Control = JvFullColorTrackBarRed + AnchorSideBottom.Side = asrBottom + Left = 39 + Height = 237 + Top = 303 + Width = 21 + Anchors = [akTop, akLeft, akBottom] + BorderSpacing.Left = 8 + FullColor = 67174144 + AxisConfig = acYZX + TabOrder = 4 + ArrowColor = clLime + ArrowWidth = 10 + ColorOrientation = coInverse + Orientation = trVertical + end + object JvFullColorTrackBarRed: TJvFullColorTrackBar + AnchorSideLeft.Control = PanelGraphics + AnchorSideTop.Control = Bevel10 + AnchorSideTop.Side = asrBottom + AnchorSideBottom.Control = JvColorCircle + AnchorSideBottom.Side = asrBottom + Left = 10 + Height = 237 + Top = 303 + Width = 21 + Anchors = [akTop, akLeft, akBottom] + BorderSpacing.Left = 8 + FullColor = 67109119 + AxisConfig = acYZX + TabOrder = 3 + ArrowColor = clRed + ArrowWidth = 10 + ColorOrientation = coInverse + Orientation = trVertical + end + object JvColorAxisConfigCombo: TJvFullColorAxisCombo + AnchorSideLeft.Control = JvColorCircle + AnchorSideLeft.Side = asrCenter + AnchorSideTop.Control = LabelAxisSettings + AnchorSideTop.Side = asrBottom + Left = 201 + Height = 23 + Top = 29 + Width = 257 + Selected = acXYZ + BorderSpacing.Top = 4 + ItemHeight = 15 + TabOrder = 0 + OnChange = JvColorAxisConfigComboChange + end + object Bevel10: TBevel + AnchorSideLeft.Control = PanelGraphics + AnchorSideTop.Control = JvColorCircle + AnchorSideTop.Side = asrCenter + Left = 2 + Height = 6 + Top = 297 + Width = 90 + end + end + object PanelCommonSettings: TPanel + AnchorSideLeft.Control = Owner + AnchorSideTop.Control = PanelImageOld + AnchorSideTop.Side = asrBottom + Left = 16 + Height = 95 + Top = 211 + Width = 380 + AutoSize = True + BorderSpacing.Left = 16 + BorderSpacing.Top = 16 + BorderSpacing.Right = 16 + BevelInner = bvRaised + BevelOuter = bvLowered + ClientHeight = 95 + ClientWidth = 380 + TabOrder = 2 + object LabelComAxis0: TLabel + AnchorSideLeft.Control = SpinEditComAxis0 + AnchorSideTop.Control = PanelCommonSettings + Left = 82 + Height = 15 + Top = 16 + Width = 81 + BorderSpacing.Top = 14 + Caption = 'LabelComAxis0' + ParentColor = False + end + object LabelComAxis1: TLabel + AnchorSideLeft.Control = SpinEditComAxis1 + AnchorSideTop.Control = LabelComAxis0 + Left = 178 + Height = 15 + Top = 16 + Width = 81 + Caption = 'LabelComAxis1' + ParentColor = False + end + object LabelComAxis2: TLabel + AnchorSideLeft.Control = SpinEditComAxis2 + AnchorSideTop.Control = LabelComAxis0 + Left = 274 + Height = 15 + Top = 16 + Width = 81 + Caption = 'LabelComAxis2' + ParentColor = False + end + object LabelCommon: TLabel + AnchorSideTop.Control = SpinEditComAxis0 + AnchorSideTop.Side = asrCenter + AnchorSideRight.Control = LabelComAxis0 + Left = 20 + Height = 15 + Top = 39 + Width = 54 + Alignment = taRightJustify + Anchors = [akTop, akRight] + BorderSpacing.Left = 16 + BorderSpacing.Right = 8 + Caption = 'C&ommon:' + FocusControl = SpinEditComAxis0 + ParentColor = False + end + object SpinEditComAxis0: TSpinEdit + Tag = 48 + AnchorSideLeft.Control = Bevel2 + AnchorSideLeft.Side = asrBottom + AnchorSideTop.Control = LabelComAxis0 + AnchorSideTop.Side = asrBottom + Left = 82 + Height = 23 + Top = 35 + Width = 57 + BorderSpacing.Top = 4 + Enabled = False + OnChange = SpinEditSettingsValueChange + TabOrder = 0 + end + object SpinEditComAxis1: TSpinEdit + Tag = 49 + AnchorSideLeft.Control = Bevel3 + AnchorSideLeft.Side = asrBottom + AnchorSideTop.Control = LabelComAxis1 + AnchorSideTop.Side = asrBottom + Left = 178 + Height = 23 + Top = 35 + Width = 57 + BorderSpacing.Top = 4 + OnChange = SpinEditSettingsValueChange + TabOrder = 1 + end + object SpinEditComAxis2: TSpinEdit + Tag = 50 + AnchorSideLeft.Control = Bevel4 + AnchorSideLeft.Side = asrBottom + AnchorSideTop.Control = LabelComAxis2 + AnchorSideTop.Side = asrBottom + Left = 274 + Height = 23 + Top = 35 + Width = 57 + BorderSpacing.Top = 4 + OnChange = SpinEditSettingsValueChange + TabOrder = 2 + end + object CheckBoxCom0: TCheckBox + Tag = 48 + AnchorSideLeft.Control = SpinEditComAxis0 + AnchorSideTop.Control = SpinEditComAxis0 + AnchorSideTop.Side = asrBottom + Left = 82 + Height = 19 + Top = 62 + Width = 104 + BorderSpacing.Top = 4 + Caption = 'CheckBoxCom0' + OnClick = CheckBoxSettingsClick + TabOrder = 3 + end + object CheckBoxCom1: TCheckBox + Tag = 49 + AnchorSideLeft.Control = SpinEditComAxis1 + AnchorSideTop.Control = CheckBoxCom0 + Left = 178 + Height = 19 + Top = 62 + Width = 104 + Caption = 'CheckBoxCom1' + OnClick = CheckBoxSettingsClick + TabOrder = 4 + end + object CheckBoxCom2: TCheckBox + Tag = 50 + AnchorSideLeft.Control = SpinEditComAxis2 + AnchorSideTop.Control = CheckBoxCom0 + Left = 274 + Height = 19 + Top = 62 + Width = 104 + Caption = 'CheckBoxCom2' + OnClick = CheckBoxSettingsClick + TabOrder = 5 + end + object Bevel2: TBevel + AnchorSideLeft.Control = PanelCommonSettings + AnchorSideTop.Control = CheckBoxCom0 + AnchorSideTop.Side = asrBottom + Left = 2 + Height = 12 + Top = 81 + Width = 80 + Constraints.MinWidth = 80 + Shape = bsSpacer + end + object Bevel3: TBevel + AnchorSideLeft.Control = Bevel2 + AnchorSideLeft.Side = asrBottom + AnchorSideTop.Control = CheckBoxCom0 + AnchorSideTop.Side = asrBottom + Left = 82 + Height = 12 + Top = 81 + Width = 96 + Constraints.MinWidth = 96 + Shape = bsSpacer + end + object Bevel4: TBevel + AnchorSideLeft.Control = Bevel3 + AnchorSideLeft.Side = asrBottom + AnchorSideTop.Control = Bevel2 + Left = 178 + Height = 12 + Top = 81 + Width = 96 + Constraints.MinWidth = 96 + Shape = bsSpacer + end + object Bevel5: TBevel + AnchorSideLeft.Control = Bevel4 + AnchorSideLeft.Side = asrBottom + AnchorSideTop.Control = Bevel2 + Left = 274 + Height = 12 + Top = 81 + Width = 80 + Constraints.MinWidth = 80 + Shape = bsSpacer + end + end + object PanelAxisSettings: TPanel + AnchorSideLeft.Control = PanelCommonSettings + AnchorSideTop.Control = PanelCommonSettings + AnchorSideTop.Side = asrBottom + AnchorSideRight.Control = PanelCommonSettings + AnchorSideRight.Side = asrBottom + Left = 16 + Height = 203 + Top = 322 + Width = 380 + Anchors = [akTop, akLeft, akRight] + AutoSize = True + BorderSpacing.Top = 16 + BevelInner = bvRaised + BevelOuter = bvLowered + ClientHeight = 203 + ClientWidth = 380 + TabOrder = 4 + object LabelAxis0: TLabel + AnchorSideLeft.Control = SpinEditRedAxis0 + AnchorSideTop.Control = PanelAxisSettings + Left = 82 + Height = 15 + Top = 16 + Width = 55 + BorderSpacing.Top = 14 + Caption = 'LabelAxis0' + ParentColor = False + end + object LabelAxis1: TLabel + AnchorSideLeft.Control = SpinEditRedAxis1 + AnchorSideTop.Control = LabelAxis0 + Left = 178 + Height = 15 + Top = 16 + Width = 55 + Caption = 'LabelAxis1' + ParentColor = False + end + object LabelAxis2: TLabel + AnchorSideLeft.Control = SpinEditRedAxis2 + AnchorSideTop.Control = LabelAxis0 + Left = 274 + Height = 15 + Top = 16 + Width = 55 + Caption = 'LabelAxis2' + ParentColor = False + end + object LabelRed: TLabel + AnchorSideTop.Control = SpinEditRedAxis0 + AnchorSideTop.Side = asrCenter + AnchorSideRight.Control = SpinEditRedAxis0 + Left = 51 + Height = 15 + Top = 39 + Width = 23 + Alignment = taRightJustify + Anchors = [akTop, akRight] + BorderSpacing.Right = 8 + Caption = '&Red:' + FocusControl = SpinEditRedAxis0 + ParentBidiMode = False + ParentColor = False + end + object LabelGreen: TLabel + AnchorSideTop.Control = SpinEditGreenAxis0 + AnchorSideTop.Side = asrCenter + AnchorSideRight.Control = SpinEditRedAxis0 + Left = 40 + Height = 15 + Top = 93 + Width = 34 + Alignment = taRightJustify + Anchors = [akTop, akRight] + BorderSpacing.Right = 8 + Caption = '&Green:' + FocusControl = SpinEditGreenAxis0 + ParentColor = False + end + object LabelBlue: TLabel + AnchorSideTop.Control = SpinEditBlueAxis0 + AnchorSideTop.Side = asrCenter + AnchorSideRight.Control = SpinEditRedAxis0 + Left = 48 + Height = 15 + Top = 147 + Width = 26 + Alignment = taRightJustify + Anchors = [akTop, akRight] + BorderSpacing.Right = 8 + Caption = '&Blue:' + FocusControl = SpinEditBlueAxis0 + ParentColor = False + end + object SpinEditRedAxis0: TSpinEdit + AnchorSideLeft.Control = Bevel6 + AnchorSideLeft.Side = asrBottom + AnchorSideTop.Control = LabelAxis0 + AnchorSideTop.Side = asrBottom + Left = 82 + Height = 23 + Top = 35 + Width = 57 + BorderSpacing.Top = 4 + OnChange = SpinEditSettingsValueChange + TabOrder = 0 + end + object SpinEditGreenAxis0: TSpinEdit + Tag = 16 + AnchorSideLeft.Control = Bevel6 + AnchorSideLeft.Side = asrBottom + AnchorSideTop.Control = CheckBoxRed0 + AnchorSideTop.Side = asrBottom + Left = 82 + Height = 23 + Top = 89 + Width = 57 + BorderSpacing.Top = 8 + OnChange = SpinEditSettingsValueChange + TabOrder = 6 + end + object SpinEditBlueAxis0: TSpinEdit + Tag = 32 + AnchorSideLeft.Control = Bevel6 + AnchorSideLeft.Side = asrBottom + AnchorSideTop.Control = CheckBoxGreen0 + AnchorSideTop.Side = asrBottom + Left = 82 + Height = 23 + Top = 143 + Width = 57 + BorderSpacing.Top = 8 + OnChange = SpinEditSettingsValueChange + TabOrder = 12 + end + object SpinEditRedAxis1: TSpinEdit + Tag = 1 + AnchorSideLeft.Control = Bevel7 + AnchorSideLeft.Side = asrBottom + AnchorSideTop.Control = LabelAxis0 + AnchorSideTop.Side = asrBottom + Left = 178 + Height = 23 + Top = 35 + Width = 57 + BorderSpacing.Top = 4 + OnChange = SpinEditSettingsValueChange + TabOrder = 1 + end + object SpinEditRedAxis2: TSpinEdit + Tag = 2 + AnchorSideLeft.Control = Bevel8 + AnchorSideLeft.Side = asrBottom + AnchorSideTop.Control = LabelAxis0 + AnchorSideTop.Side = asrBottom + Left = 274 + Height = 23 + Top = 35 + Width = 57 + BorderSpacing.Top = 4 + OnChange = SpinEditSettingsValueChange + TabOrder = 2 + end + object SpinEditGreenAxis1: TSpinEdit + Tag = 17 + AnchorSideLeft.Control = Bevel7 + AnchorSideLeft.Side = asrBottom + AnchorSideTop.Control = CheckBoxRed0 + AnchorSideTop.Side = asrBottom + Left = 178 + Height = 23 + Top = 89 + Width = 57 + BorderSpacing.Top = 8 + OnChange = SpinEditSettingsValueChange + TabOrder = 7 + end + object SpinEditGreenAxis2: TSpinEdit + Tag = 18 + AnchorSideLeft.Control = Bevel8 + AnchorSideLeft.Side = asrBottom + AnchorSideTop.Control = CheckBoxRed0 + AnchorSideTop.Side = asrBottom + Left = 274 + Height = 23 + Top = 89 + Width = 57 + BorderSpacing.Top = 8 + OnChange = SpinEditSettingsValueChange + TabOrder = 8 + end + object SpinEditBlueAxis1: TSpinEdit + Tag = 33 + AnchorSideLeft.Control = Bevel7 + AnchorSideLeft.Side = asrBottom + AnchorSideTop.Control = CheckBoxGreen0 + AnchorSideTop.Side = asrBottom + Left = 178 + Height = 23 + Top = 143 + Width = 57 + BorderSpacing.Top = 8 + OnChange = SpinEditSettingsValueChange + TabOrder = 13 + end + object SpinEditBlueAxis2: TSpinEdit + Tag = 34 + AnchorSideLeft.Control = Bevel8 + AnchorSideLeft.Side = asrBottom + AnchorSideTop.Control = CheckBoxGreen0 + AnchorSideTop.Side = asrBottom + Left = 274 + Height = 23 + Top = 143 + Width = 57 + BorderSpacing.Top = 8 + OnChange = SpinEditSettingsValueChange + TabOrder = 14 + end + object CheckBoxRed0: TCheckBox + AnchorSideLeft.Control = SpinEditRedAxis0 + AnchorSideTop.Control = SpinEditRedAxis0 + AnchorSideTop.Side = asrBottom + Left = 82 + Height = 19 + Top = 62 + Width = 98 + BorderSpacing.Top = 4 + Caption = 'CheckBoxRed0' + OnClick = CheckBoxSettingsClick + TabOrder = 3 + end + object CheckBoxRed1: TCheckBox + Tag = 1 + AnchorSideLeft.Control = SpinEditRedAxis1 + AnchorSideTop.Control = SpinEditRedAxis0 + AnchorSideTop.Side = asrBottom + Left = 178 + Height = 19 + Top = 62 + Width = 98 + BorderSpacing.Top = 4 + Caption = 'CheckBoxRed1' + OnClick = CheckBoxSettingsClick + TabOrder = 4 + end + object CheckBoxRed2: TCheckBox + Tag = 2 + AnchorSideLeft.Control = SpinEditRedAxis2 + AnchorSideTop.Control = SpinEditRedAxis0 + AnchorSideTop.Side = asrBottom + Left = 274 + Height = 19 + Top = 62 + Width = 98 + BorderSpacing.Top = 4 + Caption = 'CheckBoxRed2' + OnClick = CheckBoxSettingsClick + TabOrder = 5 + end + object CheckBoxGreen0: TCheckBox + Tag = 16 + AnchorSideLeft.Control = SpinEditRedAxis0 + AnchorSideTop.Control = SpinEditGreenAxis0 + AnchorSideTop.Side = asrBottom + Left = 82 + Height = 19 + Top = 116 + Width = 109 + BorderSpacing.Top = 4 + Caption = 'CheckBoxGreen0' + OnClick = CheckBoxSettingsClick + TabOrder = 9 + end + object CheckBoxGreen1: TCheckBox + Tag = 17 + AnchorSideLeft.Control = SpinEditRedAxis1 + AnchorSideTop.Control = SpinEditGreenAxis0 + AnchorSideTop.Side = asrBottom + Left = 178 + Height = 19 + Top = 116 + Width = 109 + BorderSpacing.Top = 4 + Caption = 'CheckBoxGreen1' + OnClick = CheckBoxSettingsClick + TabOrder = 10 + end + object CheckBoxGreen2: TCheckBox + Tag = 18 + AnchorSideLeft.Control = SpinEditRedAxis2 + AnchorSideTop.Control = SpinEditGreenAxis0 + AnchorSideTop.Side = asrBottom + Left = 274 + Height = 19 + Top = 116 + Width = 109 + BorderSpacing.Top = 4 + Caption = 'CheckBoxGreen2' + OnClick = CheckBoxSettingsClick + TabOrder = 11 + end + object CheckBoxBlue0: TCheckBox + Tag = 32 + AnchorSideLeft.Control = SpinEditRedAxis0 + AnchorSideTop.Control = SpinEditBlueAxis0 + AnchorSideTop.Side = asrBottom + Left = 82 + Height = 19 + Top = 170 + Width = 101 + BorderSpacing.Top = 4 + Caption = 'CheckBoxBlue0' + OnClick = CheckBoxSettingsClick + TabOrder = 15 + end + object CheckBoxBlue1: TCheckBox + Tag = 33 + AnchorSideLeft.Control = SpinEditRedAxis1 + AnchorSideTop.Control = SpinEditBlueAxis0 + AnchorSideTop.Side = asrBottom + Left = 178 + Height = 19 + Top = 170 + Width = 101 + BorderSpacing.Top = 4 + Caption = 'CheckBoxBlue1' + OnClick = CheckBoxSettingsClick + TabOrder = 16 + end + object CheckBoxBlue2: TCheckBox + Tag = 34 + AnchorSideLeft.Control = SpinEditRedAxis2 + AnchorSideTop.Control = SpinEditBlueAxis0 + AnchorSideTop.Side = asrBottom + Left = 274 + Height = 19 + Top = 170 + Width = 101 + BorderSpacing.Top = 4 + Caption = 'CheckBoxBlue2' + OnClick = CheckBoxSettingsClick + TabOrder = 17 + end + object Bevel6: TBevel + AnchorSideLeft.Control = PanelAxisSettings + AnchorSideTop.Control = CheckBoxBlue0 + AnchorSideTop.Side = asrBottom + AnchorSideBottom.Side = asrBottom + Left = 2 + Height = 12 + Top = 189 + Width = 80 + Constraints.MinWidth = 80 + Shape = bsSpacer + end + object Bevel7: TBevel + AnchorSideLeft.Control = Bevel6 + AnchorSideLeft.Side = asrBottom + AnchorSideTop.Control = CheckBoxBlue0 + AnchorSideTop.Side = asrBottom + AnchorSideBottom.Side = asrBottom + Left = 82 + Height = 12 + Top = 189 + Width = 96 + Constraints.MinWidth = 96 + Shape = bsSpacer + end + object Bevel8: TBevel + AnchorSideLeft.Control = Bevel7 + AnchorSideLeft.Side = asrBottom + AnchorSideTop.Control = CheckBoxBlue0 + AnchorSideTop.Side = asrBottom + AnchorSideBottom.Side = asrBottom + Left = 178 + Height = 12 + Top = 189 + Width = 96 + Constraints.MinWidth = 96 + Shape = bsSpacer + end + object Bevel9: TBevel + AnchorSideLeft.Control = Bevel8 + AnchorSideLeft.Side = asrBottom + AnchorSideTop.Control = CheckBoxBlue0 + AnchorSideTop.Side = asrBottom + AnchorSideBottom.Side = asrBottom + Left = 274 + Height = 12 + Top = 189 + Width = 80 + Constraints.MinWidth = 80 + Shape = bsSpacer + end + end + object RadioButtonCommonSettings: TRadioButton + AnchorSideLeft.Control = PanelCommonSettings + AnchorSideTop.Control = PanelImageOld + AnchorSideTop.Side = asrBottom + Left = 24 + Height = 19 + Top = 203 + Width = 119 + BorderSpacing.Left = 8 + BorderSpacing.Top = 8 + Caption = 'Co&mmon Settings:' + OnClick = RadioButtonAxisClick + TabOrder = 1 + end + object RadioButtonAxisSettings: TRadioButton + AnchorSideLeft.Control = PanelAxisSettings + AnchorSideTop.Control = PanelCommonSettings + AnchorSideTop.Side = asrBottom + Left = 24 + Height = 19 + Top = 314 + Width = 89 + BorderSpacing.Left = 8 + BorderSpacing.Top = 8 + Caption = '&Axis Settings:' + OnClick = RadioButtonAxisClick + TabOrder = 3 + end + object ButtonGraphics: TButton + AnchorSideLeft.Side = asrBottom + AnchorSideTop.Control = ButtonOK + AnchorSideRight.Control = PanelAxisSettings + AnchorSideRight.Side = asrBottom + Left = 288 + Height = 25 + Top = 534 + Width = 108 + Anchors = [akTop, akRight] + AutoSize = True + BorderSpacing.Left = 8 + BorderSpacing.Top = 1 + Caption = 'ButtonGraphics' + Constraints.MinWidth = 75 + OnClick = ButtonGraphicsClick + TabOrder = 9 + end + object ButtonCancel: TButton + AnchorSideLeft.Control = ButtonOK + AnchorSideLeft.Side = asrBottom + AnchorSideTop.Control = ButtonOK + Left = 99 + Height = 25 + Top = 534 + Width = 75 + AutoSize = True + BorderSpacing.Left = 8 + BorderSpacing.Top = 1 + Cancel = True + Caption = 'Ca&ncel' + Constraints.MinWidth = 75 + ModalResult = 2 + TabOrder = 7 + end + object ButtonOK: TButton + AnchorSideLeft.Control = PanelAxisSettings + AnchorSideTop.Control = PanelAxisSettings + AnchorSideTop.Side = asrBottom + Left = 16 + Height = 25 + Top = 533 + Width = 75 + AutoSize = True + BorderSpacing.Top = 8 + BorderSpacing.Bottom = 16 + Caption = '&OK' + Constraints.MinWidth = 75 + Default = True + ModalResult = 1 + TabOrder = 6 + end + object ButtonApply: TButton + AnchorSideLeft.Control = ButtonCancel + AnchorSideLeft.Side = asrBottom + AnchorSideTop.Control = ButtonOK + Left = 182 + Height = 25 + Top = 534 + Width = 75 + BorderSpacing.Left = 8 + BorderSpacing.Top = 1 + Caption = '&Apply' + OnClick = ButtonApplyClick + TabOrder = 8 + end + object JvColorSpaceCombo: TJvFullColorSpaceCombo + AnchorSideLeft.Control = PanelCommonSettings + AnchorSideLeft.Side = asrCenter + AnchorSideTop.Control = LabelColorSpace + AnchorSideTop.Side = asrBottom + Left = 103 + Height = 23 + Top = 27 + Width = 206 + AllowVariable = False + BorderSpacing.Top = 4 + ItemHeight = 15 + TabOrder = 0 + OnChange = JvColorSpaceComboChange + end + object Bevel1: TBevel + AnchorSideLeft.Control = PanelCommonSettings + AnchorSideLeft.Side = asrCenter + Left = 196 + Height = 62 + Top = 77 + Width = 20 + end + object PanelImageOld: TPanel + AnchorSideLeft.Control = LabelOld + AnchorSideTop.Control = LabelOld + AnchorSideTop.Side = asrBottom + AnchorSideRight.Control = Bevel1 + Left = 72 + Height = 118 + Top = 77 + Width = 124 + Anchors = [akTop, akRight] + BorderSpacing.Top = 4 + BevelOuter = bvLowered + ClientHeight = 118 + ClientWidth = 124 + TabOrder = 10 + object ImageOld: TImage + Left = 3 + Height = 112 + Top = 3 + Width = 118 + Align = alClient + BorderSpacing.Around = 2 + end + end + object PanelImageNew: TPanel + AnchorSideLeft.Control = Bevel1 + AnchorSideLeft.Side = asrBottom + AnchorSideTop.Control = LabelOld + AnchorSideTop.Side = asrBottom + AnchorSideRight.Control = Bevel1 + Left = 216 + Height = 118 + Top = 77 + Width = 124 + BorderSpacing.Top = 4 + BevelOuter = bvLowered + ClientHeight = 118 + ClientWidth = 124 + TabOrder = 11 + object ImageNew: TImage + Left = 3 + Height = 112 + Top = 3 + Width = 118 + Align = alClient + BorderSpacing.Around = 2 + end + end +end diff --git a/components/jvcllaz/run/JvMM/jvfullcolorcircleform.pas b/components/jvcllaz/run/JvMM/jvfullcolorcircleform.pas new file mode 100644 index 000000000..7ee332ade --- /dev/null +++ b/components/jvcllaz/run/JvMM/jvfullcolorcircleform.pas @@ -0,0 +1,1001 @@ +{----------------------------------------------------------------------------- +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: ColorCircleFrm.pas, released on 2004-10-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 JvFullColorCircleForm; + +{$mode objfpc}{$H+} + +interface + +uses + //Windows, Messages, + SysUtils, Classes, Graphics, Controls, Forms, + ExtCtrls, StdCtrls, //Mask, + Spin, // JvSpin + JvFullColorDialogs, JvFullColorCtrls, JvFullColorSpaces, JvFullColorRotate; +// JvExMask, JvSpin, JvComponent; + +type + + { TJvFullColorCircleFrm } + + TJvFullColorCircleFrm = class(TForm) + Bevel1: TBevel; + Bevel10: TBevel; + Bevel2: TBevel; + Bevel3: TBevel; + Bevel4: TBevel; + Bevel5: TBevel; + Bevel6: TBevel; + Bevel7: TBevel; + Bevel8: TBevel; + Bevel9: TBevel; + JvColorCircle: TJvFullColorCircle; + PanelImageOld: TPanel; + PanelImageNew: TPanel; + RadioButtonCommonSettings: TRadioButton; + RadioButtonAxisSettings: TRadioButton; + PanelAxisSettings: TPanel; + PanelCommonSettings: TPanel; + ImageOld: TImage; + ImageNew: TImage; + JvFullColorTrackBarCommon: TJvFullColorTrackBar; + JvFullColorTrackBarBlue: TJvFullColorTrackBar; + JvFullColorTrackBarGreen: TJvFullColorTrackBar; + JvFullColorTrackBarRed: TJvFullColorTrackBar; + SpinEditComAxis0: TSpinEdit; //TJvSpinEdit; + SpinEditRedAxis0: TSpinEdit; //TJvSpinEdit; + SpinEditGreenAxis0: TSpinEdit; //TJvSpinEdit; + SpinEditBlueAxis0: TSpinEdit; //TJvSpinEdit; + SpinEditComAxis1: TSpinEdit; //TJvSpinEdit; + SpinEditComAxis2: TSpinEdit; //TJvSpinEdit; + SpinEditRedAxis1: TSpinEdit; //TJvSpinEdit; + SpinEditRedAxis2: TSpinEdit; //TJvSpinEdit; + SpinEditGreenAxis1: TSpinEdit; //TJvSpinEdit; + SpinEditGreenAxis2: TSpinEdit; //TJvSpinEdit; + SpinEditBlueAxis1: TSpinEdit; //TJvSpinEdit; + SpinEditBlueAxis2: TSpinEdit; //TJvSpinEdit; + LabelOld: TLabel; + LabelNew: TLabel; + LabelColorSpace: TLabel; + LabelAxisSettings: TLabel; + LabelComAxis0: TLabel; + LabelComAxis1: TLabel; + LabelComAxis2: TLabel; + LabelAxis0: TLabel; + LabelAxis1: TLabel; + LabelAxis2: TLabel; + LabelCommon: TLabel; + LabelRed: TLabel; + LabelGreen: TLabel; + LabelBlue: TLabel; + PanelGraphics: TPanel; + ButtonGraphics: TButton; + ButtonCancel: TButton; + ButtonOK: TButton; + ButtonApply: TButton; + CheckBoxCom0: TCheckBox; + CheckBoxCom1: TCheckBox; + CheckBoxCom2: TCheckBox; + CheckBoxRed0: TCheckBox; + CheckBoxRed1: TCheckBox; + CheckBoxRed2: TCheckBox; + CheckBoxGreen0: TCheckBox; + CheckBoxGreen1: TCheckBox; + CheckBoxGreen2: TCheckBox; + CheckBoxBlue0: TCheckBox; + CheckBoxBlue1: TCheckBox; + CheckBoxBlue2: TCheckBox; + JvColorSpaceCombo: TJvFullColorSpaceCombo; + JvColorAxisConfigCombo: TJvFullColorAxisCombo; + procedure ButtonGraphicsClick(Sender: TObject); + procedure ButtonApplyClick(Sender: TObject); + procedure FormCreate(Sender: TObject); + procedure FormShow(Sender: TObject); + procedure JvColorSpaceComboChange(Sender: TObject); + procedure CheckBoxSettingsClick(Sender: TObject); + procedure JvColorCircleBlueColorChange(Sender: TObject); + procedure JvColorCircleColorChange(Sender: TObject); + procedure JvColorCircleGreenColorChange(Sender: TObject); + procedure JvColorCircleRedColorChange(Sender: TObject); + procedure JvColorAxisConfigComboChange(Sender: TObject); + procedure JvColorCircleColorSpaceChange(Sender: TObject); + procedure RadioButtonAxisClick(Sender: TObject); + procedure SpinEditSettingsValueChange(Sender: TObject); + private + FExpanded: Boolean; + FUpdating: Boolean; + FExpandedWidth: Integer; + FDelta: TJvColorDelta; + FOnApply: TNotifyEvent; + FOptions: TJvFullColorCircleDialogOptions; + FRedAxis: array [TJvAxisIndex] of Byte; + FGreenAxis: array [TJvAxisIndex] of Byte; + FBlueAxis: array [TJvAxisIndex] of Byte; + FComAxis: array [TJvAxisIndex] of Byte; + FAxisMin: array [TJvAxisIndex] of Byte; + FAxisMax: array [TJvAxisIndex] of Byte; + FSpinEditComAxes: array [TJvAxisIndex] of TSpinEdit; //TJvSpinEdit; + FSpinEditRedAxes: array [TJvAxisIndex] of TSpinEdit; //TJvSpinEdit; + FSpinEditGreenAxes: array [TJvAxisIndex] of TSpinEdit; //TJvSpinEdit; + FSpinEditBlueAxes: array [TJvAxisIndex] of TSpinEdit; //TJvSpinEdit; + FLabelComAxes: array [TJvAxisIndex] of TLabel; + FLabelAxes: array [TJvAxisIndex] of TLabel; + FCheckBoxCom: array [TJvAxisIndex] of TCheckBox; + FCheckBoxRed: array [TJvAxisIndex] of TCheckBox; + FCheckBoxGreen: array [TJvAxisIndex] of TCheckBox; + FCheckBoxBlue: array [TJvAxisIndex] of TCheckBox; + FFilled: Boolean; + procedure FillInternalArrays; + protected + procedure Loaded; override; + function GetDropdownCount: Integer; + function GetRedDelta: TJvAxisDelta; + function GetGreenDelta: TJvAxisDelta; + function GetBlueDelta: TJvAxisDelta; + function GetColorID: TJvFullColorSpaceID; + procedure SetOptions(const Value: TJvFullColorCircleDialogOptions); + procedure SetRedDelta(const Value: TJvAxisDelta); + procedure SetGreenDelta(const Value: TJvAxisDelta); + procedure SetBlueDelta(const Value: TJvAxisDelta); + procedure SetColorID(const Value: TJvFullColorSpaceID); + procedure SetDelta(const Value: TJvColorDelta); + procedure SetDropdownCount(const AValue: Integer); + public + constructor Create(AOwner: TComponent); override; + destructor Destroy; override; + + procedure UpdateDeltaValue; + procedure CalcDeltaValue(ARotateColor: TJvRotateColor); + procedure UpdateColorSpace; + procedure UpdateCheckBoxStates; + procedure UpdateAxisSettings; + procedure Expand; + procedure Collapse; + + property DropdownCount: integer read GetDropdownCount write SetDropdownCount default 8; + property Expanded: Boolean read FExpanded; + property Options: TJvFullColorCircleDialogOptions read FOptions write SetOptions; + property RedDelta: TJvAxisDelta read GetRedDelta write SetRedDelta; + property GreenDelta: TJvAxisDelta read GetGreenDelta write SetGreenDelta; + property BlueDelta: TJvAxisDelta read GetBlueDelta write SetBlueDelta; + property ColorID: TJvFullColorSpaceID read GetColorID write SetColorID; + property Delta: TJvColorDelta read FDelta write SetDelta; + property OnApply: TNotifyEvent read FOnApply write FOnApply; + end; + + +implementation + +uses + TypInfo, + Math, // JclMath, // for EnsureRange + JvResources, + JvJCLUtils; // for TryStrToInt + +{$R *.lfm} + +var + GlobalLoop, GlobalRange: string; + +function AxisIndexFromTag(ATag: Integer): TJvAxisIndex; +begin + Result := TJvAxisIndex(ATag and $03); +end; + +//=== { TJvFullColorCircleForm } ============================================= + +constructor TJvFullColorCircleFrm.Create(AOwner: TComponent); +begin + inherited Create(AOwner); + FDelta := TJvColorDelta.Create; +end; + +destructor TJvFullColorCircleFrm.Destroy; +begin + FDelta.Free; + inherited Destroy; +end; + +function TJvFullColorCircleFrm.GetBlueDelta: TJvAxisDelta; +begin + Result := FDelta.AxisBlue; +end; + +function TJvFullColorCircleFrm.GetColorID: TJvFullColorSpaceID; +begin + Result := FDelta.ColorID; +end; + +function TJvFullColorCircleFrm.GetDropdownCount: Integer; +begin + Result := JvColorSpaceCombo.DropdownCount; +end; + +function TJvFullColorCircleFrm.GetGreenDelta: TJvAxisDelta; +begin + Result := FDelta.AxisGreen; +end; + +function TJvFullColorCircleFrm.GetRedDelta: TJvAxisDelta; +begin + Result := FDelta.AxisRed; +end; + +procedure TJvFullColorCircleFrm.FormCreate(Sender: TObject); +begin + Options := JvDefaultColorCircleDialogOptions - [coShowSaturation]; + JvColorAxisConfigCombo.Selected := JvColorCircle.AxisConfig; +end; + +procedure TJvFullColorCircleFrm.FillInternalArrays; +begin + if not FFilled then + begin + FSpinEditComAxes[axIndex0] := SpinEditComAxis0; + FSpinEditComAxes[axIndex1] := SpinEditComAxis1; + FSpinEditComAxes[axIndex2] := SpinEditComAxis2; + FSpinEditRedAxes[axIndex0] := SpinEditRedAxis0; + FSpinEditRedAxes[axIndex1] := SpinEditRedAxis1; + FSpinEditRedAxes[axIndex2] := SpinEditRedAxis2; + FSpinEditGreenAxes[axIndex0] := SpinEditGreenAxis0; + FSpinEditGreenAxes[axIndex1] := SpinEditGreenAxis1; + FSpinEditGreenAxes[axIndex2] := SpinEditGreenAxis2; + FSpinEditBlueAxes[axIndex0] := SpinEditBlueAxis0; + FSpinEditBlueAxes[axIndex1] := SpinEditBlueAxis1; + FSpinEditBlueAxes[axIndex2] := SpinEditBlueAxis2; + FLabelComAxes[axIndex0] := LabelComAxis0; + FLabelComAxes[axIndex1] := LabelComAxis1; + FLabelComAxes[axIndex2] := LabelComAxis2; + FLabelAxes[axIndex0] := LabelAxis0; + FLabelAxes[axIndex1] := LabelAxis1; + FLabelAxes[axIndex2] := LabelAxis2; + FCheckBoxCom[axIndex0] := CheckBoxCom0; + FCheckBoxCom[axIndex1] := CheckBoxCom1; + FCheckBoxCom[axIndex2] := CheckBoxCom2; + FCheckBoxRed[axIndex0] := CheckBoxRed0; + FCheckBoxRed[axIndex1] := CheckBoxRed1; + FCheckBoxRed[axIndex2] := CheckBoxRed2; + FCheckBoxGreen[axIndex0] := CheckBoxGreen0; + FCheckBoxGreen[axIndex1] := CheckBoxGreen1; + FCheckBoxGreen[axIndex2] := CheckBoxGreen2; + FCheckBoxBlue[axIndex0] := CheckBoxBlue0; + FCheckBoxBlue[axIndex1] := CheckBoxBlue1; + FCheckBoxBlue[axIndex2] := CheckBoxBlue2; + FFilled := True; + end; +end; + +procedure TJvFullColorCircleFrm.Loaded; +begin + inherited Loaded; + FExpandedWidth := Width; +end; + +procedure TJvFullColorCircleFrm.Collapse; +begin + Width := PanelGraphics.Left - 1; + PanelGraphics.Visible := False; + ButtonGraphics.Caption := RsCollapsedCaption; + FExpanded := False; +end; + +procedure TJvFullColorCircleFrm.Expand; +begin + Width := FExpandedWidth; + PanelGraphics.Visible := True; + ButtonGraphics.Caption := RsExpandedCaption; + FExpanded := True; +end; + +procedure TJvFullColorCircleFrm.SetOptions(const Value: TJvFullColorCircleDialogOptions); +var + I: TJvAxisIndex; + EnabledA, EnabledB: Boolean; + LVisible: Boolean; + + procedure UpdateCheckBox(ACheckBox: TCheckBox); + begin + ACheckBox.Visible := EnabledA; + ACheckBox.Checked := EnabledB; + end; + +begin + FOptions := Value; + FillInternalArrays; + + if coFullOpen in Options then + Expand + else + Collapse; + + ButtonGraphics.Enabled := not (coPreventExpand in Options); + + ButtonApply.Visible := (coShowApply in Options); + + if coShowHelp in Options then + BorderIcons := BorderIcons + [biHelp] + else + BorderIcons := BorderIcons - [biHelp]; + + EnabledA := coAllowSpaceChange in Options; + LabelColorSpace.Enabled := EnabledA; + JvColorSpaceCombo.Enabled := EnabledA; + + LVisible := coShowOldPreview in Options; + PanelImageOld.Visible := LVisible; + LabelOld.Visible := LVisible; + + LVisible := coShowNewPreview in Options; + PanelImageNew.Visible := LVisible; + LabelNew.Visible := LVisible; + + EnabledA := coShowSaturation in Options; + EnabledB := coDefaultRange in Options; + + for I := Low(TJvAxisIndex) to High(TJvAxisIndex) do + begin + UpdateCheckBox(FCheckBoxCom[I]); + UpdateCheckBox(FCheckBoxRed[I]); + UpdateCheckBox(FCheckBoxGreen[I]); + UpdateCheckBox(FCheckBoxBlue[I]); + end; + + if RadioButtonCommonSettings.Enabled and RadioButtonAxisSettings.Enabled then + RadioButtonAxisSettings.Checked := True; + + UpdateAxisSettings; + UpdateCheckBoxStates; + UpdateColorSpace; +end; + +procedure TJvFullColorCircleFrm.UpdateColorSpace; +var + I: TJvAxisIndex; + LCaption: string; + LColor: TJvFullColor; +begin + if FUpdating then + Exit; + FillInternalArrays; + + FUpdating := True; + + with JvColorSpaceCombo.SelectedSpace do + begin + SetColorID(ID); + JvColorAxisConfigCombo.ColorID := ID; + + for I := Low(TJvAxisIndex) to High(TJvAxisIndex) do + begin + LCaption := AxisName[I]; + FLabelComAxes[I].Caption := LCaption; + FLabelAxes[I].Caption := LCaption; + + FAxisMax[I] := AxisMax[I]; + FAxisMin[I] := AxisMin[I]; + FSpinEditComAxes[I].MaxValue := FAxisMax[I]; + FSpinEditComAxes[I].MinValue := -FAxisMax[I]; + FSpinEditRedAxes[I].MaxValue := FAxisMax[I]; + FSpinEditRedAxes[I].MinValue := -FAxisMax[I]; + FSpinEditGreenAxes[I].MaxValue := FAxisMax[I]; + FSpinEditGreenAxes[I].MinValue := -FAxisMax[I]; + FSpinEditBlueAxes[I].MaxValue := FAxisMax[I]; + FSpinEditBlueAxes[I].MinValue := -FAxisMax[I]; + + LColor := ConvertFromColor(clRed); + FRedAxis[I] := GetAxisValue(LColor, I); + + LColor := ConvertFromColor(clLime); + FGreenAxis[I] := GetAxisValue(LColor, I); + + LColor := ConvertFromColor(clBlue); + FBlueAxis[I] := GetAxisValue(LColor, I); + + LColor := ConvertFromColor(clDkGray); + FComAxis[I] := GetAxisValue(LColor, I); + end; + + JvColorCircle.ConvertToID(ID shl 24); + + FUpdating := False; + end; + CalcDeltaValue(rcRed); + CalcDeltaValue(rcGreen); + CalcDeltaValue(rcBlue); +end; + +procedure TJvFullColorCircleFrm.UpdateDeltaValue; +var + I: TJvAxisIndex; + ComAxis: array [TJvAxisIndex] of Integer; + LColorID: TJvFullColorSpaceID; + ARedColor, AGreenColor, ABlueColor, ACommonColor: TJvFullColor; + + function CheckRange(Value: Integer; AMin: Byte; AMax: Byte): Byte; + begin + while Value < AMin do + Inc(Value, AMax - AMin + 1); + while Value > AMax do + Dec(Value, AMax - AMin + 1); + Result := Value; + end; + +begin + if FUpdating then + Exit; + FillInternalArrays; + + FUpdating := True; + + for I := Low(TJvAxisIndex) to High(TJvAxisIndex) do + begin + ComAxis[I] := (RedDelta[I].Value + GreenDelta[I].Value + BlueDelta[I].Value) div 3; + FSpinEditRedAxes[I].Value := RedDelta[I].Value; + FSpinEditGreenAxes[I].Value := GreenDelta[I].Value; + FSpinEditBlueAxes[I].Value := BlueDelta[I].Value; + FSpinEditComAxes[I].Value := ComAxis[I]; + end; + + LColorID := JvColorSpaceCombo.ColorSpaceID; + + ACommonColor := LColorID shl 24; + ARedColor := LColorID shl 24; + AGreenColor := LColorID shl 24; + ABlueColor := LColorID shl 24; + for I := Low(TJvAxisIndex) to High(TJvAxisIndex) do + begin + ARedColor := ARedColor or + (CheckRange(RedDelta[I].Value + FRedAxis[I], FAxisMin[I], FAxisMax[I]) shl (Ord(I)*8)); + AGreenColor := AGreenColor or + (CheckRange(GreenDelta[I].Value + FGreenAxis[I], FAxisMin[I], FAxisMax[I]) shl (Ord(I)*8)); + ABlueColor := ABlueColor or + (CheckRange(BlueDelta[I].Value + FBlueAxis[I], FAxisMin[I], FAxisMax[I]) shl (Ord(I)*8)); + ACommonColor := ACommonColor or + (CheckRange(ComAxis[I] + FComAxis[I], FAxisMin[I], FAxisMax[I]) shl (Ord(I)*8)); + end; + + JvColorCircle.FullColor := ACommonColor; + JvColorCircle.RedColor := ARedColor; + JvColorCircle.GreenColor := AGreenColor; + JvColorCircle.BlueColor := ABlueColor; + + FUpdating := False; +end; + +procedure TJvFullColorCircleFrm.RadioButtonAxisClick(Sender: TObject); +begin + UpdateAxisSettings; +end; + +procedure TJvFullColorCircleFrm.UpdateAxisSettings; +var + I: TJvAxisIndex; + LColor: TColor; + EnabledA, EnabledB: Boolean; +begin + FillInternalArrays; + EnabledA := coCommon in Options; + + if not EnabledA then + RadioButtonAxisSettings.Checked := True; + + RadioButtonCommonSettings.Enabled := EnabledA; + EnabledA := EnabledA and RadioButtonCommonSettings.Checked; + PanelCommonSettings.Enabled := EnabledA; + + if EnabledA then + LColor := clWindow + else + LColor := clBtnFace; + for I := Low(TJvAxisIndex) to High(TJvAxisIndex) do + begin + FSpinEditComAxes[I].Enabled := EnabledA; + FSpinEditComAxes[I].Color := LColor; + FCheckBoxCom[I].Enabled := EnabledA; + FLabelComAxes[I].Enabled := EnabledA; + end; + LabelCommon.Enabled := EnabledA; + JvFullColorTrackBarCommon.Visible := EnabledA; + if EnabledA then + JvColorCircle.Styles := JvColorCircle.Styles + [csShowCommon] + else + JvColorCircle.Styles := JvColorCircle.Styles - [csShowCommon]; + + EnabledA := (coRed in Options) or (coBlue in Options) or (coGreen in Options); + + if not EnabledA then + RadioButtonCommonSettings.Checked := True; + + RadioButtonAxisSettings.Enabled := EnabledA; + EnabledA := EnabledA and RadioButtonAxisSettings.Checked; + PanelAxisSettings.Enabled := EnabledA; + for I := Low(TJvAxisIndex) to High(TJvAxisIndex) do + FLabelAxes[I].Enabled := EnabledA; + + EnabledB := EnabledA and (coRed in Options); + if EnabledB then + LColor := clWindow + else + LColor := clBtnFace; + LabelRed.Enabled := EnabledB; + for I := Low(TJvAxisIndex) to High(TJvAxisIndex) do + begin + FSpinEditRedAxes[I].Enabled := EnabledB; + FSpinEditRedAxes[I].Color := LColor; + FCheckBoxRed[I].Enabled := EnabledB; + end; + JvFullColorTrackBarRed.Visible := EnabledB; + + EnabledB := EnabledA and (coGreen in Options); + if EnabledB then + LColor := clWindow + else + LColor := clBtnFace; + LabelGreen.Enabled := EnabledB; + for I := Low(TJvAxisIndex) to High(TJvAxisIndex) do + begin + FSpinEditGreenAxes[I].Enabled := EnabledB; + FSpinEditGreenAxes[I].Color := LColor; + FCheckBoxGreen[I].Enabled := EnabledB; + end; + JvFullColorTrackBarGreen.Visible := EnabledB; + + EnabledB := EnabledA and (coBlue in Options); + if EnabledB then + LColor := clWindow + else + LColor := clBtnFace; + LabelBlue.Enabled := EnabledB; + for I := Low(TJvAxisIndex) to High(TJvAxisIndex) do + begin + FSpinEditBlueAxes[I].Enabled := EnabledB; + FSpinEditBlueAxes[I].Color := LColor; + FCheckBoxBlue[I].Enabled := EnabledB; + end; + JvFullColorTrackBarBlue.Visible := EnabledB; +end; + +procedure TJvFullColorCircleFrm.CheckBoxSettingsClick(Sender: TObject); +var + Idx: TJvAxisIndex; + AxisDelta: TJvAxisDelta; + SaturationMethod: TJvSaturationMethod; +begin + if FUpdating then + Exit; + + FUpdating := True; + + with Sender as TCheckBox do + begin + if Checked then + SaturationMethod := smLoop + else + SaturationMethod := smRange; + + Idx := AxisIndexFromTag(Tag); + case Tag and $30 of + $00: + begin + AxisDelta := RedDelta; + AxisDelta[Idx].SaturationMethod := SaturationMethod; + RedDelta := AxisDelta; + end; + $10: + begin + AxisDelta := GreenDelta; + AxisDelta[Idx].SaturationMethod := SaturationMethod; + GreenDelta := AxisDelta; + end; + $20: + begin + AxisDelta := BlueDelta; + AxisDelta[Idx].SaturationMethod := SaturationMethod; + BlueDelta := AxisDelta; + end; + $30: + begin + AxisDelta := RedDelta; + AxisDelta[Idx].SaturationMethod := SaturationMethod; + RedDelta := AxisDelta; + + AxisDelta := GreenDelta; + AxisDelta[Idx].SaturationMethod := SaturationMethod; + GreenDelta := AxisDelta; + + AxisDelta := BlueDelta; + AxisDelta[Idx].SaturationMethod := SaturationMethod; + BlueDelta := AxisDelta; + end; + end; + end; + + FUpdating := False; + + UpdateCheckBoxStates; +end; + +procedure TJvFullColorCircleFrm.UpdateCheckBoxStates; +var + I: TJvAxisIndex; + + procedure UpdateCheckBox(ACheckBox: TCheckBox); + var + Idx: TJvAxisIndex; + SaturationMethod: TJvSaturationMethod; + begin + SaturationMethod := smRange; + + Idx := AxisIndexFromTag(ACheckBox.Tag); + case ACheckBox.Tag and $30 of + $00: + SaturationMethod := RedDelta[Idx].SaturationMethod; + $10: + SaturationMethod := GreenDelta[Idx].SaturationMethod; + $20: + SaturationMethod := BlueDelta[Idx].SaturationMethod; + $30: + if (RedDelta[Idx].SaturationMethod = smLoop) and + (GreenDelta[Idx].SaturationMethod = smLoop) and + (BlueDelta[Idx].SaturationMethod = smLoop) then + SaturationMethod := smLoop + else + SaturationMethod := smRange; + end; + + if SaturationMethod = smLoop then + begin + ACheckBox.Caption := GlobalLoop; + ACheckBox.Checked := True; + end + else + begin + ACheckBox.Caption := GlobalRange; + ACheckBox.Checked := False; + end; + end; + +begin + if FUpdating then + Exit; + FillInternalArrays; + + FUpdating := True; + for I := Low(TJvAxisIndex) to High(TJvAxisIndex) do + begin + UpdateCheckBox(FCheckBoxCom[I]); + UpdateCheckBox(FCheckBoxRed[I]); + UpdateCheckBox(FCheckBoxGreen[I]); + UpdateCheckBox(FCheckBoxBlue[I]); + end; + FUpdating := False; +end; + +procedure TJvFullColorCircleFrm.ButtonGraphicsClick(Sender: TObject); +begin + if Expanded then + Collapse + else + Expand; +end; + +procedure TJvFullColorCircleFrm.ButtonApplyClick(Sender: TObject); +begin + if Assigned(OnApply) then + OnApply(Self); +end; + +procedure TJvFullColorCircleFrm.FormShow(Sender: TObject); +var + w, i: Integer; +begin + w := 0; + for i := 0 to JvColorSpaceCombo.Items.Count-1 do + w := Max(w, JvColorSpaceCombo.Canvas.TextWidth(JvColorSpaceCombo.Items[i])); + JvColorSpaceCombo.Width := w + 24; + + Bevel1.Shape := bsSpacer; + Bevel10.Shape := bsSpacer; + JvColorCircle.Constraints.MinWidth := JvColorCircle.Height; + + Position := poScreenCenter; +end; + +procedure TJvFullColorCircleFrm.JvColorSpaceComboChange(Sender: TObject); +begin + if not FUpdating then + UpdateColorSpace; +end; + +procedure TJvFullColorCircleFrm.SetBlueDelta(const Value: TJvAxisDelta); +begin + FDelta.AxisBlue.Assign(Value); + if not FUpdating then + begin + UpdateDeltaValue; + UpdateCheckBoxStates; + end; +end; + +procedure TJvFullColorCircleFrm.SetDelta(const Value: TJvColorDelta); +var + ChangeColorSpace:Boolean; +begin + ChangeColorSpace := Value.ColorID <> Delta.ColorID; + FDelta.Assign(Value); + if not FUpdating then + begin + if ChangeColorSpace then + begin + JvColorSpaceCombo.ColorSpaceID := Value.ColorID; + UpdateColorSpace; + end; + UpdateDeltaValue; + UpdateCheckBoxStates; + end; +end; + +procedure TJvFullColorCircleFrm.SetDropdownCount(const AValue: Integer); +begin + JvColorSpaceCombo.DropdownCount := AValue; + JvColorAxisConfigCombo.DropdownCount := AValue; +end; + +procedure TJvFullColorCircleFrm.SetGreenDelta(const Value: TJvAxisDelta); +begin + FDelta.AxisGreen.Assign(Value); + if not FUpdating then + begin + UpdateDeltaValue; + UpdateCheckBoxStates; + end; +end; + +procedure TJvFullColorCircleFrm.SetColorID( + const Value: TJvFullColorSpaceID); +begin + FDelta.ColorID := Value; + if not FUpdating then + begin + JvColorSpaceCombo.ColorSpaceID := Value; + UpdateColorSpace; + UpdateDeltaValue; + UpdateCheckBoxStates; + end; +end; + +procedure TJvFullColorCircleFrm.SetRedDelta(const Value: TJvAxisDelta); +begin + FDelta.AxisRed.Assign(Value); + if not FUpdating then + begin + UpdateDeltaValue; + UpdateCheckBoxStates; + end; +end; + +procedure TJvFullColorCircleFrm.CalcDeltaValue(ARotateColor: TJvRotateColor); +var + I: TJvAxisIndex; + AxisDelta: TJvAxisDelta; + + function GetDelta(OldValue: Integer; ColorAxisValue: Integer; + InitAxisValue, AxisMin, AxisMax: Byte): Integer; + var + AxisLength: Integer; + Offset1, Offset2, Offset3: Integer; + begin + AxisLength := AxisMax - AxisMin + 1; + Offset1 := Abs(ColorAxisValue - AxisLength - OldValue - InitAxisValue); + Offset2 := Abs(ColorAxisValue - OldValue - InitAxisValue); + Offset3 := Abs(ColorAxisValue + AxisLength - OldValue - InitAxisValue); + if (Offset1 < Offset2) and (Offset1 < Offset3) then + Result := (ColorAxisValue - AxisLength) - InitAxisValue + else + if Offset2 < Offset3 then + Result := ColorAxisValue - InitAxisValue + else + Result := (ColorAxisValue + AxisLength) - InitAxisValue; + + Result := EnsureRange(Result, -AxisLength, AxisLength); + end; + +begin + if FUpdating then + Exit; + + FUpdating := True; + AxisDelta := TJvAxisDelta.Create; + try + if ARotateColor = rcCommon then + begin + for I := Low(TJvAxisIndex) to High(TJvAxisIndex) do + begin + AxisDelta[I].Value := GetDelta(RedDelta[I].Value, GetAxisValue(JvColorCircle.FullColor, I), + FComAxis[I], FAxisMin[I], FAxisMax[I]); + AxisDelta[I].SaturationMethod := RedDelta[I].SaturationMethod; + end; + RedDelta.Assign(AxisDelta); + GreenDelta.Assign(RedDelta); + BlueDelta.Assign(RedDelta); + end + else + begin + if ARotateColor = rcRed then + begin + //RedDelta := GetDelta(RedDelta, JvColorCircle.RedColor, FRedAxis0, FRedAxis1, FRedAxis2); + for I := Low(TJvAxisIndex) to High(TJvAxisIndex) do + begin + AxisDelta[I].Value := GetDelta(RedDelta[I].Value, GetAxisValue(JvColorCircle.RedColor, I), + FRedAxis[I], FAxisMin[I], FAxisMax[I]); + AxisDelta[I].SaturationMethod := RedDelta[I].SaturationMethod; + end; + RedDelta.Assign(AxisDelta); + end; + + if ARotateColor = rcGreen then + begin + //GreenDelta := GetDelta(GreenDelta, JvColorCircle.GreenColor, FGreenAxis0, FGreenAxis1, FGreenAxis2); + for I := Low(TJvAxisIndex) to High(TJvAxisIndex) do + begin + AxisDelta[I].Value := GetDelta(GreenDelta[I].Value, GetAxisValue(JvColorCircle.GreenColor, I), + FGreenAxis[I], FAxisMin[I], FAxisMax[I]); + AxisDelta[I].SaturationMethod := GreenDelta[I].SaturationMethod; + end; + GreenDelta.Assign(AxisDelta); + end; + + if ARotateColor = rcBlue then + begin + //BlueDelta := GetDelta(BlueDelta, JvColorCircle.BlueColor, FBlueAxis0, FBlueAxis1, FBlueAxis2); + for I := Low(TJvAxisIndex) to High(TJvAxisIndex) do + begin + AxisDelta[I].Value := GetDelta(BlueDelta[I].Value, GetAxisValue(JvColorCircle.BlueColor, I), + FBlueAxis[I], FAxisMin[I], FAxisMax[I]); + AxisDelta[I].SaturationMethod := BlueDelta[I].SaturationMethod; + end; + BlueDelta.Assign(AxisDelta); + end; + end; + finally + FUpdating := False; + AxisDelta.Free; + end; + + UpdateDeltaValue; +end; + +procedure TJvFullColorCircleFrm.JvColorCircleBlueColorChange(Sender: TObject); +begin + if not FUpdating then + CalcDeltaValue(rcBlue); +end; + +procedure TJvFullColorCircleFrm.JvColorCircleColorChange(Sender: TObject); +begin + if not FUpdating then + CalcDeltaValue(rcCommon); +end; + +procedure TJvFullColorCircleFrm.JvColorCircleGreenColorChange(Sender: TObject); +begin + if not FUpdating then + CalcDeltaValue(rcGreen); +end; + +procedure TJvFullColorCircleFrm.JvColorCircleRedColorChange(Sender: TObject); +begin + if not FUpdating then + CalcDeltaValue(rcRed); +end; + +procedure TJvFullColorCircleFrm.JvColorAxisConfigComboChange(Sender: TObject); +begin + if not FUpdating then + begin + FUpdating := True; + JvColorCircle.AxisConfig := (Sender as TJvFullColorAxisCombo).Selected; + FUpdating := False; + end; +end; + +procedure TJvFullColorCircleFrm.JvColorCircleColorSpaceChange(Sender: TObject); +begin + CalcDeltaValue(rcRed); + CalcDeltaValue(rcGreen); + CalcDeltaValue(rcBlue); +end; + +procedure TJvFullColorCircleFrm.SpinEditSettingsValueChange(Sender: TObject); +var + Idx: TJvAxisIndex; + AxisDelta: TJvAxisDelta; + IntValue:Integer; + TagValue:Integer; +begin + if FUpdating then + Exit; + + with Sender as TSpinEdit do //TJvSpinEdit do + begin + if not TryStrToInt(Text,IntValue) then + Exit; + TagValue := Tag; + Idx := AxisIndexFromTag(TagValue); + end; + + FUpdating := True; + + case TagValue and $30 of + $00: + begin + AxisDelta := RedDelta; + AxisDelta[Idx].Value := IntValue; + RedDelta := AxisDelta; + end; + $10: + begin + AxisDelta := GreenDelta; + AxisDelta[Idx].Value := IntValue; + GreenDelta := AxisDelta; + end; + $20: + begin + AxisDelta := BlueDelta; + AxisDelta[Idx].Value := IntValue; + BlueDelta := AxisDelta; + end; + $30: + begin + AxisDelta := RedDelta; + AxisDelta[Idx].Value := IntValue; + RedDelta := AxisDelta; + GreenDelta := AxisDelta; + BlueDelta := AxisDelta; + end; + end; + + FUpdating := False; + + UpdateDeltaValue; +end; + +procedure InitializeStrings; +var + LTypInfo: PTypeInfo; + LString: string; +begin + LTypInfo := TypeInfo(TJvSaturationMethod); + LString := GetEnumName(LTypInfo, Integer(smLoop)); + GlobalLoop := Copy(LString, 3, Length(LString) - 2); + LString := GetEnumName(LTypInfo, Integer(smRange)); + GlobalRange := Copy(LString, 3, Length(LString) - 2); +end; + +initialization + InitializeStrings; + +end. diff --git a/components/jvcllaz/run/JvMM/jvfullcolorctrls.pas b/components/jvcllaz/run/JvMM/jvfullcolorctrls.pas new file mode 100644 index 000000000..64f1b8589 --- /dev/null +++ b/components/jvcllaz/run/JvMM/jvfullcolorctrls.pas @@ -0,0 +1,3886 @@ +{----------------------------------------------------------------------------- +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; + +{$mode objfpc}{$H+} + +interface + +uses + LCLIntf, LCLType, LMessages, + //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; + FOnColorSpaceChangeEvent: TNotifyEvent; + FOnMouseColor: TJvFullColorMouseEvent; + FColorChanging: Boolean; + FBuffer: TBitmap; + FCreating: Boolean; + FWantDrawBuffer: Boolean; + FMouseDragging: Boolean; + function GetColorSpace: TJvColorSpace; + procedure SetAxisConfig(const Value: TJvFullColorAxisConfig); + (******************* NOT CONVERTED *** + procedure WMGetDlgCode(var Msg: TLMGetDlgCode); message LM_GETDLGCODE; + *************************************) + procedure CMColorChanged(var Msg: TLMessage); message CM_COLORCHANGED; + procedure CMSysColorChange(var Msg: TLMessage); 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 Align; + property Anchors; + property AutoMouse: Boolean read FAutoMouse write FAutoMouse default True; + property BorderSpacing; + 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 FOnColorSpaceChangeEvent write FOnColorSpaceChangeEvent; + property OnMouseColor: TJvFullColorMouseEvent read FOnMouseColor write FOnMouseColor; + end; + + TJvFullColorComponent2D = class(TJvFullColorComponent) + private + FValueZAuto: Boolean; + FValueZ: Byte; + FAxisConfigChanging: Integer; + 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; + + 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; + + 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; + + 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); + + 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 BorderSpacing; + 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; + (******************* NOT CONVERTED *** + 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; + + TJvFullColorSpaceCombo = class(TCustomCombobox) //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; + (******************* NOT CONVERTED *** + property BevelEdges; + property BevelInner; + property BevelKind default bkNone; + property BevelOuter; + property Flat; + property ParentFlat; + property ImeMode; + property ImeName; + ************************************) + property Align; + property Anchors; + property BiDiMode; + property BorderSpacing; + property Color; + property Constraints; + property DragCursor; + property DragKind; + property DragMode; + property DropDownCount; + property Enabled; + property Font; + 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; + + TJvFullColorAxisCombo = class(TCustomComboBox) //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; + (******************** NOT CONVERTED *** + property BevelEdges; + property BevelInner; + property BevelKind default bkNone; + property BevelOuter; + property Flat; + property ParentFlat; + property ImeMode; + property ImeName; + *************************************) + property Align; + property Anchors; + property BiDiMode; + property BorderSpacing; + property Color; + property Constraints; + property DragCursor; + property DragKind; + property DragMode; + property DropDownCount; + property Enabled; + property Font; + 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; + + 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: TLMMouse); message LM_MOUSELEAVE; + procedure CMHintShow(var Msg: TLMessage); 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; + (****************** NOT CONVERTED *** + property BevelInner; + property BevelOuter; + property BevelEdges; + property BevelKind default bkTile; + property BevelWidth; + ***********************************) + property Align; + property Anchors; + property BorderSpacing; + 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; + + +implementation + +uses + RTLConsts, TypInfo, Forms, Math, + JvResources, JvJVCLUtils; +{ + JclMath, JclLogic, // For EnsureRange and Min/Max + 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(FOnColorSpaceChangeEvent) then + FOnColorSpaceChangeEvent(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; + +(********************* NOT CONVERTED *** +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; + +procedure TJvFullColorComponent.KeyDown(var Key: Word; Shift: TShiftState); +begin + case Key of + VK_LEFT: + KeyMove(kcLeft, 1); + VK_RIGHT: + KeyMove(kcRight, 1); + VK_UP: + KeyMove(kcUp, 1); + VK_DOWN: + KeyMove(kcDown, 1); + end; +end; + +procedure TJvFullColorComponent.CMColorChanged(var Msg: TLMessage); +begin + inherited; + WantDrawBuffer := True; +end; + +procedure TJvFullColorComponent.CMSysColorChange(var Msg: TLMessage); +begin + inherited; + WantDrawBuffer := True; +end; + +//=== { TColor2D } =========================================================== + +constructor TJvFullColorComponent2D.Create(AOwner: TComponent); +begin + inherited Create(AOwner); + FValueZ := 0; + FValueZAuto := True; + ColorSpaceChange; +end; + +procedure TJvFullColorComponent2D.AxisConfigChange; +begin + UpdateDefaultValueZ; + inherited AxisConfigChange; +end; + +procedure TJvFullColorComponent2D.ColorSpaceChange; +begin + UpdateDefaultValueZ; + inherited ColorSpaceChange; +end; + +procedure TJvFullColorComponent2D.TrackBarAxisConfigChange(Sender: TObject); +begin + if FAxisConfigChanging = 0 then +// if not FAxisCfgChanging then + begin + inc(FAxisConfigChanging); + AxisConfig := (Sender as TJvFullColorTrackBar).AxisConfig; + dec(FAxisConfigChanging); + end; +end; + +procedure TJvFullColorComponent2D.TrackBarColorChange(Sender: TObject); +begin + if FColorChanging then + Exit; + + FColorChanging := True; + FullColor := (Sender as TJvFullColorTrackBar).FullColor; + FColorChanging := False; + + if Assigned(FOnColorChange) then + FOnColorChange(Self); +end; + +function TJvFullColorComponent2D.IsValueZStored: Boolean; +begin + Result := not ValueZAuto; +end; + +procedure TJvFullColorComponent2D.SetValueZ(const Value: Byte); +begin + FValueZAuto := False; + FValueZ := Value; + WantDrawBuffer := True; +end; + +procedure TJvFullColorComponent2D.SetValueZAuto(const Value: Boolean); +begin + FValueZAuto := Value; + if Value then + UpdateDefaultValueZ; + WantDrawBuffer := True; +end; + +procedure TJvFullColorComponent2D.UpdateDefaultValueZ; +begin + if ValueZAuto then + FValueZ := ColorSpace.AxisDefault[GetIndexAxisZ(AxisConfig)]; +end; + + +//=== { TJvColorPanel } ====================================================== + +constructor TJvFullColorPanel.Create(AOwner: TComponent); +begin + inherited Create(AOwner); + FCrossSize := 5; + FCrossCenter := 1; + FReverseAxisX := False; + FReverseAxisY := False; + FPen := TPen.Create; + FPen.OnChange := @PenChange; + FColorChanging := False; +end; + +destructor TJvFullColorPanel.Destroy; +begin + ColorTrackBar := nil; + FPen.Free; + inherited Destroy; +end; + +procedure TJvFullColorPanel.CalcSize; +begin + FBuffer.Width := Max(Width - 2 * FCrossSize,0); + FBuffer.Height := Max(Height - 2 * FCrossSize,0); + inherited CalcSize; +end; + +procedure TJvFullColorPanel.DrawBuffer; +type + TColorRGBA = packed record + r,g,b,a: Byte; + end; + PColorRGBA = ^TColorRGBA; +var + AxisX, AxisY: TJvAxisIndex; + IndexX, IndexY: Integer; + MinX, MaxX, MinY, MaxY: Integer; + RangeX, RangeY: Integer; + TempColor: TJvFullColor; +// Line: PJvFullColorArray; + P: PLongInt; +begin + if (FBuffer.Width = 0) or (FBuffer.Height = 0) or (Width = 0) or (Height = 0) then + Exit; + + AxisX := GetIndexAxisX(AxisConfig); + AxisY := GetIndexAxisY(AxisConfig); + + with ColorSpace do + begin + MinX := AxisMin[AxisX]; + MaxX := AxisMax[AxisX]; + RangeX := MaxX - MinX; + MinY := AxisMin[AxisY]; + MaxY := AxisMax[AxisY]; + RangeY := MaxY - MinY; + + TempColor := SetAxisValue(fclRGBBlack, GetIndexAxisZ(AxisConfig), ValueZ); + with FBuffer do + begin + BeginUpdate; + try + Canvas.Brush.Color := Color; + Canvas.FillRect(Rect(0, 0, Width-1, Height-1)); + + for IndexY := 0 to Height-1 do + begin + P := PLongInt(RawImage.GetLineStart(IndexY)); +// Line := ScanLine[IndexY]; + if ReverseAxisY then + TempColor := SetAxisValue(TempColor, AxisY, MaxY - (RangeY * IndexY) div (Height - 1)) + else + TempColor := SetAxisValue(TempColor, AxisY, (RangeY * IndexY) div (Height - 1) + MinY); + for IndexX := 0 to Width-1 do + begin + if ReverseAxisX then + TempColor := SetAxisValue(TempColor, AxisX, MaxX - (RangeX * IndexX) div (Width - 1)) + else + TempColor := SetAxisValue(TempColor, AxisX, (RangeX * IndexX) div (Width - 1) + MinX); + // (outchy) don't remove, Bitmap colors are stocked as (MSB) 00RRGGBB (LSB) + // Delphi TColor is (MSB) 00BBGGRR (LSB) +// Line^[IndexX] := RGBToBGR(ConvertToColor(TempColor)); + P^ := RGBToBGR(ConvertToColor(TempColor)); + inc(P); + end; + end; + finally + EndUpdate; + end; + end; + end; + inherited DrawBuffer; +end; + +function TJvFullColorPanel.GetCursorPosition: TPoint; +var + AxisX, AxisY: TJvAxisIndex; + MinAxis, MaxAxis: Integer; +begin + if (FBuffer.Width = 0) or (FBuffer.Height = 0) or (Width = 0) or (Height = 0) then + begin + Result.X := 0; + Result.Y := 0; + end + else + with ColorSpaceManager, ColorSpace[GetColorSpaceID(FullColor)] do + begin + AxisX := GetIndexAxisX(AxisConfig); + MinAxis := AxisMin[AxisX]; + MaxAxis := AxisMax[AxisX]; + Result.X := GetAxisValue(FullColor, AxisX); + if ReverseAxisX then + Result.X := MaxAxis - Result.X + else + Result.X := Result.X - MinAxis; + Result.X := ((Result.X * (FBuffer.Width - 1)) div (MaxAxis-MinAxis)) + CrossSize; + + AxisY := GetIndexAxisY(AxisConfig); + MinAxis := AxisMin[AxisY]; + MaxAxis := AxisMax[AxisY]; + Result.Y := GetAxisValue(FullColor, AxisY); + if ReverseAxisY then + Result.Y := MaxAxis - Result.Y + else + Result.Y := Result.Y - MinAxis; + Result.Y := ((Result.Y * (FBuffer.Height - 1)) div (MaxAxis-MinAxis)) + CrossSize; + end; +end; + +procedure TJvFullColorPanel.InvalidateCursor; +var + ARect: TRect; + Pt: TPoint; +begin + Pt := GetCursorPosition; + ARect.Left := Pt.X - 1 - CrossSize - CrossStyle.Width; + ARect.Right := Pt.X + 1 + CrossSize + CrossStyle.Width; + ARect.Top := Pt.Y - 1 - CrossSize - CrossStyle.Width; + ARect.Bottom := Pt.Y + 1 + CrossSize + CrossStyle.Width; + InvalidateRect(Handle, @ARect, False); +end; + +procedure TJvFullColorPanel.Paint; +var + Pt: TPoint; +begin + inherited Paint; + + with Canvas do + begin + Brush.Color := Color; + Brush.Style := bsSolid; + DrawFrame(CrossSize, CrossSize); + Draw(CrossSize, CrossSize, FBuffer); + + Pen := CrossStyle; + Pt := GetCursorPosition; + MoveTo(Pt.X - CrossSize, Pt.Y); + LineTo(Pt.X - CrossCenter, Pt.Y); + MoveTo(Pt.X + CrossCenter, Pt.Y); + LineTo(Pt.X + CrossSize, Pt.Y); + + MoveTo(Pt.X, Pt.Y - CrossSize); + LineTo(Pt.X, Pt.Y - CrossCenter); + MoveTo(Pt.X, Pt.Y + CrossCenter); + LineTo(Pt.X, Pt.Y + CrossSize); + end; + DrawFocus; +end; + +procedure TJvFullColorPanel.PenChange(Sender: TObject); +begin + Invalidate; +end; + +procedure TJvFullColorPanel.SetCrossCenter(Value: Integer); +begin + if Value >= CrossSize then + Value := CrossSize - 1; + if FCrossCenter <> Value then + begin + FCrossCenter := Value; + Invalidate; + end; +end; + +procedure TJvFullColorPanel.SetCrossSize(Value: Integer); +begin + if Value < 1 then + Value := 1; + if FCrossCenter >= Value then + FCrossCenter := Value - 1; + if FCrossSize <> Value then + begin + FCrossSize := Value; + CalcSize; + end; +end; + +procedure TJvFullColorPanel.SetReverseAxisX(const Value: Boolean); +begin + if FReverseAxisX <> Value then + begin + FReverseAxisX := Value; + WantDrawBuffer := True; + end; +end; + +procedure TJvFullColorPanel.SetReverseAxisY(const Value: Boolean); +begin + if FReverseAxisY <> Value then + begin + FReverseAxisY := Value; + WantDrawBuffer := True; + end; +end; + +procedure TJvFullColorPanel.SetPen(const Value: TPen); +begin + FPen.Assign(Value); + Invalidate; +end; + +procedure TJvFullColorPanel.SetColorTrackBar(const Value: TJvFullColorTrackBar); +begin + if (Value <> nil) and (Value <> FColorTrackBar) and Value.Linked then + raise EJvFullColorError.CreateResFmt(@RsEDuplicateTrackBar, [Value.LinkerName]); + + if Assigned(FColorTrackBar) then + begin + FColorTrackBar.OnColorChange := nil; + FColorTrackBar.OnAxisConfigChange := nil; + FColorTrackBar.FreeLink; + end; + + ReplaceComponentReference(Self, Value, TComponent(FColorTrackBar)); + + if Assigned(FColorTrackBar) then + begin + FColorTrackBar.OnColorChange := @TrackBarColorChange; + FColorTrackBar.OnAxisConfigChange := @TrackBarAxisConfigChange; + FColorTrackBar.FullColor := FullColor; + FColorTrackBar.AxisConfig := AxisConfig; + FColorTrackBar.SetLink(Self); + end; +end; + +procedure TJvFullColorPanel.Notification(AComponent: TComponent; Operation: TOperation); +begin + inherited Notification(AComponent, Operation); + if (Operation = opRemove) and (AComponent = ColorTrackBar) then + ColorTrackBar := nil; +end; + +procedure TJvFullColorPanel.SetFullColor(const Value: TJvFullColor); +var + AxisX, AxisY: TJvAxisIndex; +begin + if Value <> FullColor then + begin + if Assigned(FColorTrackBar) and (not FColorChanging) then + begin + FColorChanging := True; + FColorTrackBar.FullColor := Value; + FColorChanging := False; + end; + begin + AxisX := GetIndexAxisX(AxisConfig); + AxisY := GetIndexAxisY(AxisConfig); + if (GetAxisValue(Value, AxisX) <> GetAxisValue(FullColor, AxisX)) or + (GetAxisValue(Value, AxisY) <> GetAxisValue(FullColor, AxisY)) then + begin + InvalidateCursor; + inherited SetFullColor(Value); + InvalidateCursor; + end + else + inherited SetFullColor(Value); + end; + end; +end; + +procedure TJvFullColorPanel.MouseColor(Shift: TShiftState; X, Y: Integer); +var + MinX, MaxX, MinY, MaxY: Byte; + AxisX, AxisY: TJvAxisIndex; + PosX, PosY: Integer; +begin + if ssLeft in Shift then + begin + AxisX := GetIndexAxisX(AxisConfig); + AxisY := GetIndexAxisY(AxisConfig); + with ColorSpace do + begin + MinX := AxisMin[AxisX]; + MaxX := AxisMax[AxisX]; + MinY := AxisMin[AxisY]; + MaxY := AxisMax[AxisY]; + + PosX := EnsureRange(((X - CrossSize) * (MaxX - MinX)) div (FBuffer.Width - 1), 0, MaxX - MinX); + if ReverseAxisX then + PosX := MaxX - PosX + else + PosX := PosX + MinX; + + PosY := EnsureRange(((Y - CrossSize) * (MaxY - MinY)) div (FBuffer.Height - 1), 0, MaxY - MinY); + if ReverseAxisY then + PosY := MaxY - PosY + else + PosY := PosY + MinY; + + FullColor := SetAxisValue(SetAxisValue(FullColor, AxisX, Byte(PosX)), AxisY, Byte(PosY)); + end; + end; + inherited MouseColor(Shift, X, Y); +end; + +procedure TJvFullColorPanel.AxisConfigChange; +begin + if (FColorTrackBar <> nil) and (FAxisConfigChanging = 0) then + begin + inc(FAxisConfigChanging); + FColorTrackBar.AxisConfig := AxisConfig; + dec(FAxisConfigChanging); + end; + inherited AxisConfigChange; +end; + +procedure TJvFullColorPanel.KeyMove(KeyCode: TJvKeyCode; MoveCount: Integer); +var + IndexAxisX, IndexAxisY: TJvAxisIndex; + ValueX, ValueY: Integer; +begin + IndexAxisX := GetIndexAxisX(AxisConfig); + IndexAxisY := GetIndexAxisY(AxisConfig); + ValueX := GetAxisValue(FullColor, IndexAxisX); + ValueY := GetAxisValue(FullColor, IndexAxisY); + + case KeyCode of + kcLeft: + begin + if ReverseAxisX then + MoveCount := -MoveCount; + ValueX := ValueX - MoveCount; + end; + kcRight: + begin + if ReverseAxisX then + MoveCount := -MoveCount; + ValueX := ValueX + MoveCount; + end; + kcUp: + begin + if ReverseAxisY then + MoveCount := -MoveCount; + ValueY := ValueY - MoveCount; + end; + kcDown: + begin + if ReverseAxisY then + MoveCount := -MoveCount; + ValueY := ValueY + MoveCount; + end; + end; + + with ColorSpace do + begin + ValueX := EnsureRange(ValueX, AxisMin[IndexAxisX], AxisMax[IndexAxisX]); + ValueY := EnsureRange(ValueY, AxisMin[IndexAxisY], AxisMax[IndexAxisY]); + end; + + FullColor := SetAxisValue(SetAxisValue(FullColor, IndexAxisX, ValueX), IndexAxisY, ValueY); +end; + +//=== { TJvColorCircle } ===================================================== + +constructor TJvFullColorCircle.Create(AOwner: TComponent); +begin + inherited Create(AOwner); + FCrossStyle := TPen.Create; + FCrossStyle.OnChange := @PenChanged; + FInvertRadius := False; + InvertRotation := False; + FCrossSize := 5; + FCrossCenter := 1; + FLineWidth := 1; + FRedColor := fclRGBRed; + FGreenColor := fclRGBLime; + FBlueColor := fclRGBBlue; + FDraggingColor := rcCommon; + FCrossGreenColor := clGreen; + FCrossRedColor := clMaroon; + FCrossBlueColor := clNavy; + FStyles := [csShowLines, csShowRed, csShowGreen, csShowBlue]; +end; + +destructor TJvFullColorCircle.Destroy; +begin + FCrossStyle.Free; + inherited Destroy; +end; + +procedure TJvFullColorCircle.CalcSize; +begin + FBuffer.Width := Max(Width - (2 * CrossSize),0); + FBuffer.Height := Max(Height - (2 * CrossSize),0); + inherited CalcSize; +end; + +procedure TJvFullColorCircle.DrawBuffer; +var + X, Y, Angle, RadiusInt, MaxRadius, MinRadius: Integer; + AxisRadius, AxisAngle: TJvAxisIndex; + MaxAngle, MinAngle: Integer; + AngleUnit, AngleUnitPi, XCenter, YCenter, XRelative, YRelative, + SqrXRelative, SqrYRelative, Radius: Extended; + Magic1, Magic2, Magic3: Byte; + Line: PJvFullColorArray; +// P: PLongInt; +begin + if (FBuffer.Width = 0) or (FBuffer.Height = 0) then + Exit; + + AxisRadius := GetIndexAxisX(AxisConfig); + AxisAngle := GetIndexAxisY(AxisConfig); + + with ColorSpace do + begin + MaxRadius := AxisMax[AxisRadius]; + MinRadius := AxisMin[AxisRadius]; + MaxAngle := AxisMax[AxisAngle]; + MinAngle := AxisMin[AxisAngle]; + end; + + AngleUnit := (MaxAngle - MinAngle) / 2.0 / Pi; + AngleUnitPi := (MaxAngle - MinAngle) / 2.0; + + Magic1 := ValueZ; + Magic2 := Magic1; + Magic3 := Magic1; + + with FBuffer, ColorSpace do + begin + BeginUpdate; + Canvas.Brush.Color := Color; + Canvas.FillRect(Rect(0, 0, Width, Height)); + XCenter := Width / 2.0; + YCenter := Height / 2.0; + for Y := 0 to Height - 1 do + begin + Line := ScanLine[Y]; + //P := PLongInt(RawImage.GetLineStart(Y)); + YRelative := Y - YCenter; + SqrYRelative := Sqr(YRelative / YCenter); + for X := 0 to Width - 1 do + begin + XRelative := X - XCenter; + SqrXRelative := Sqr(XRelative / XCenter); + Radius := Sqrt(SqrYRelative + SqrXRelative); + + if Radius <= 1.0 then + begin + Angle := Round(ArcTan2(YRelative, XRelative) * AngleUnit + AngleUnitPi) + MinAngle; + RadiusInt := Round(Radius * (MaxRadius - MinRadius)); + case AxisAngle of + axIndex0: + if InvertRotation then + Magic1 := MaxAngle - Angle + else + Magic1 := Angle + MinAngle; + axIndex1: + if InvertRotation then + Magic2 := MaxAngle - Angle + else + Magic2 := Angle + MinAngle; + axIndex2: + if InvertRotation then + Magic3 := MaxAngle - Angle + else + Magic3 := Angle + MinAngle; + end; + case AxisRadius of + axIndex0: + if InvertRadius then + Magic1 := MaxRadius - RadiusInt + else + Magic1 := RadiusInt + MinRadius; + axIndex1: + if InvertRadius then + Magic2 := MaxRadius - RadiusInt + else + Magic2 := RadiusInt + MinRadius; + axIndex2: + if InvertRadius then + Magic3 := MaxRadius - RadiusInt + else + Magic3 := RadiusInt + MinRadius; + end; + // (outchy) don't remove, Bitmap colors are stocked as (MSB) 00RRGGBB (LSB) + // Delphi TColor is (MSB) 00BBGGRR (LSB) + Line^[X] := RGBToBGR(ConvertToColor(Magic1 or (Magic2 shl 8) or (Magic3 shl 16))); +// P^ := RGBToBGR(ConvertToColor(Magic1 or (Magic2 shl 8) or (Magic3 shl 16))); +// inc(P); + end + else + if XRelative >= 0.0 then + Break; // end of a line + end; + end; + EndUpdate; + end; + inherited DrawBuffer; +end; + +procedure TJvFullColorCircle.Paint; + + procedure DrawCross(AFullColor: TJvFullColor; ACrossColor: TColor); + var + Point: TPoint; + begin + Point := FullColorToPosition(AFullColor); + + with Canvas do + begin + Pen := CrossStyle; + Pen.Color := ACrossColor; + + MoveTo(Point.X - CrossSize, Point.Y); // left + LineTo(Point.X - CrossCenter, Point.Y); + + MoveTo(Point.X + CrossCenter, Point.Y); // right + LineTo(Point.X + CrossSize, Point.Y); + + MoveTo(Point.X, Point.Y - CrossSize); // top + LineTo(Point.X, Point.Y - CrossCenter); + + MoveTo(Point.X, Point.Y + CrossCenter); // bottom + LineTo(Point.X, Point.Y + CrossSize); + + Pen.Mode := pmCopy; + Pen.Style := psSolid; + Pen.Width := LineWidth; + MoveTo((FBuffer.Width div 2) + CrossSize + 1,(FBuffer.Height div 2 ) + CrossSize + 1); + LineTo(Point.X, Point.Y); + end; + end; + +begin + inherited Paint; + with Canvas do + begin + Brush.Color := Color; + DrawFrame(CrossSize, CrossSize); + Draw(CrossSize, CrossSize, FBuffer); + + if csShowCommon in Styles then + DrawCross(FullColor, CrossStyle.Color) + else + begin + if csShowBlue in Styles then + DrawCross(BlueColor, CrossBlueColor); + if csShowRed in Styles then + DrawCross(RedColor, CrossRedColor); + if csShowGreen in Styles then + DrawCross(GreenColor, CrossGreenColor); + end; + end; + DrawFocus; +end; + +function TJvFullColorCircle.FullColorToPosition(AFullColor: TJvFullColor): TPoint; +var + ColorID: TJvFullColorSpaceID; + RadiusIndex, AngleIndex: TJvAxisIndex; + Radius, RadiusMax, RadiusMin, Angle, AngleMax, AngleMin: Integer; + Radius1: Integer; + FullAngle: Extended; +begin + with ColorSpaceManager do + begin + ColorID := GetColorSpaceID(AFullColor); + if ColorID <> GetColorSpaceID(AFullColor) then + AFullColor := ConvertToID(AFullColor, ColorID); + end; + + with ColorSpace do + begin + RadiusIndex := GetIndexAxisX(AxisConfig); + Radius := GetAxisValue(AFullColor, RadiusIndex); + RadiusMax := AxisMax[RadiusIndex]; + RadiusMin := AxisMin[RadiusIndex]; + + AngleIndex := GetIndexAxisY(AxisConfig); + Angle := GetAxisValue(AFullColor, AngleIndex); + AngleMax := AxisMax[AngleIndex]; + AngleMin := AxisMin[AngleIndex]; + end; + + Radius1 := RadiusMax - RadiusMin; + + if InvertRadius then + Radius := RadiusMax - Radius + else + Radius := Radius - RadiusMin; + if InvertRotation then + Angle := AngleMax - Angle + else + Angle := Angle - AngleMin; + + FullAngle := (2 * Pi * Angle) / (AngleMax - AngleMin) - Pi; + Result.X := Round(Radius * cos(FullAngle) * FBuffer.Width / (Radius1 * 2) + (FBuffer.Width / 2.0)) + CrossSize; + Result.Y := Round(Radius * sin(FullAngle) * FBuffer.Height / (Radius1 * 2) + (FBuffer.Height / 2.0)) + CrossSize; +end; + +function TJvFullColorCircle.PositionToFullColor(APoint: TPoint): TJvFullColor; +var + RadiusIndex, AngleIndex: TJvAxisIndex; + Radius, RadiusMax, RadiusMin, Angle, AngleMax, AngleMin: Integer; + XPos, YPos: Extended; +begin + if (FBuffer.Width = 0) or (FBuffer.Height = 0) then + begin + Result := fclRGBBlack; + Exit; + end; + with ColorSpace do + begin + RadiusIndex := GetIndexAxisX(AxisConfig); + RadiusMax := AxisMax[RadiusIndex]; + RadiusMin := AxisMin[RadiusIndex]; + + AngleIndex := GetIndexAxisY(AxisConfig); + AngleMax := AxisMax[AngleIndex]; + AngleMin := AxisMin[AngleIndex]; + end; + + XPos := FBuffer.Width / 2.0; + XPos := (APoint.X - CrossSize - XPos) / XPos; + YPos := FBuffer.Height / 2.0; + YPos := (APoint.Y - CrossSize - YPos) / YPos; + + Radius := Round(Sqrt(Sqr(XPos) + Sqr(YPos))*(RadiusMax - RadiusMin)); + Angle := Round((ArcTan2(YPos, XPos) + Pi) * (AngleMax - AngleMin) / 2.0 / Pi); + + if InvertRadius then + Radius := RadiusMax - Radius + else + Radius := Radius + RadiusMin; + if InvertRotation then + Angle := AngleMax - Angle + else + Angle := Angle + AngleMin; + + Radius := EnsureRange(Radius, RadiusMin, RadiusMax); + Angle := EnsureRange(Angle, AngleMin, AngleMax); + + Result := SetAxisValue( + SetAxisValue( + SetAxisValue(ColorSpace.ID shl 24, GetIndexAxisZ(AxisConfig), ValueZ), + AngleIndex, Angle), RadiusIndex, Radius); +end; + +procedure TJvFullColorCircle.MouseColor(Shift: TShiftState; X, Y: Integer); +var + LFullColor: TJvFullColor; + + function MoveColor(var AFullColor: TJvFullColor): Boolean; + var + Distance: Integer; + Point: TPoint; + begin + Point := FullColorToPosition(AFullColor); + Distance := Round(Sqrt(Sqr(X - Point.X) + Sqr(Y - Point.Y))); + if Distance < CrossSize then + begin + AFullColor := LFullColor; + Result := True; + Invalidate; + end + else + Result := False; + end; + +begin + LFullColor := PositionToFullColor(Point(X, Y)); + if csShowCommon in Styles then + begin + if (ssLeft in Shift) or + ((cs3ButtonsMouse in Styles) and (cs3ButtonsCommon in Styles)) then + FullColor := LFullColor; + end + else + if cs3ButtonsMouse in Styles then + begin + if (ssLeft in Shift) and (csShowRed in Styles) then + RedColor := LFullColor; + if (ssMiddle in Shift) and (csShowGreen in Styles) then + GreenColor := LFullColor; + if (ssRight in Shift) and (csShowBlue in Styles) then + BlueColor := LFullColor; + end + else + begin + if FDraggingColor = rcGreen then + GreenColor := LFullColor + else + if FDraggingColor = rcRed then + RedColor := LFullColor + else + if FDraggingColor = rcBlue then + BlueColor := LFullColor + else + if FDraggingColor = rcCommon then + begin + if (csShowGreen in Styles) and MoveColor(FGreenColor) then + begin + FDraggingColor := rcGreen; + if Assigned(FOnGreenColorChange) then + FOnGreenColorChange(Self); + end + else + if (csShowRed in Styles) and MoveColor(FRedColor) then + begin + FDraggingColor := rcRed; + if Assigned(FOnRedColorChange) then + FOnRedColorChange(Self); + end + else + if (csShowBlue in Styles) and MoveColor(FBlueColor) then + begin + FDraggingColor := rcBlue; + if Assigned(FOnBlueColorChange) then + FOnBlueColorChange(Self); + end; + end; + end; +end; + +procedure TJvFullColorCircle.MouseUp(Button: TMouseButton; Shift: TShiftState; + X, Y: Integer); +begin + FDraggingColor := rcCommon; + inherited MouseUp(Button, Shift, X, Y); +end; + +procedure TJvFullColorCircle.KeyMove(KeyCode: TJvKeyCode; + MoveCount: Integer); +begin + // (outchy) todo implementation but how to select a cursor ??? +end; + +procedure TJvFullColorCircle.PenChanged(Sender: TObject); +begin + WantDrawBuffer := True; +end; + +procedure TJvFullColorCircle.ConvertToID(NewFullColor: TJvFullColor); +var + ColorID: TJvFullColorSpaceID; + Change: Boolean; +begin + with ColorSpaceManager do + begin + ColorID := GetColorSpaceID(NewFullColor); + Change := ColorID <> GetColorSpaceID(FullColor); + + if Change then + begin + FFullColor := ConvertToID(FullColor, ColorID); + FRedColor := ConvertToID(RedColor, ColorID); + FGreenColor := ConvertToID(GreenColor, ColorID); + FBlueColor := ConvertToID(BlueColor, ColorID); + ColorSpaceChange; + end; + end; +end; + +procedure TJvFullColorCircle.InvalidateColors(AColor1, AColor2: TJvFullColor); +var + AxisX, AxisY: TJvAxisIndex; + APosition1, + APosition2: TPoint; + ARect: TRect; + CenterX, CenterY: Integer; +begin + AxisX := GetIndexAxisX(AxisConfig); + AxisY := GetIndexAxisY(AxisConfig); + + if (GetAxisValue(AColor1, AxisX) <> GetAxisValue(AColor2, AxisX)) or + (GetAxisValue(AColor1, AxisY) <> GetAxisValue(AColor2, AxisY)) then + begin + APosition1 := FullColorToPosition(AColor1); + APosition2 := FullColorToPosition(AColor2); + if APosition1.X < APosition2.X then + begin + ARect.Left := APosition1.X; + ARect.Right := APosition2.X; + end + else + begin + ARect.Left := APosition2.X; + ARect.Right := APosition1.X; + end; + if APosition1.Y < APosition2.Y then + begin + ARect.Top := APosition1.Y; + ARect.Bottom := APosition2.Y; + end + else + begin + ARect.Top := APosition2.Y; + ARect.Bottom := APosition1.Y; + end; + + CenterX := Width div 2; + CenterY := Height div 2; + if ARect.Left > CenterX then + ARect.Left := CenterX; + if ARect.Top > CenterY then + ARect.Top := CenterY; + if ARect.Right < CenterX then + ARect.Right := CenterX; + if ARect.Bottom < CenterY then + ARect.Bottom := CenterY; + + ARect.Left := ARect.Left - CrossStyle.Width - CrossSize; + ARect.Top := ARect.Top - CrossStyle.Width - CrossSize; + ARect.Right := ARect.Right + CrossStyle.Width + CrossSize; + ARect.Bottom := ARect.Bottom + CrossStyle.Width + CrossSize; + + InvalidateRect(Handle, @ARect, False); + end; +end; + +procedure TJvFullColorCircle.SetFullColor(const Value: TJvFullColor); +var + OldColor: TJvFullColor; +begin + ConvertToID(Value); + + OldColor := FullColor; + inherited SetFullColor(Value); + + if Assigned(FCommonColorTrackBar) and not FColorChanging then + begin + FColorChanging := True; + FCommonColorTrackBar.FullColor := Value; + FColorChanging := False; + end; + + InvalidateColors(OldColor, FullColor); + + if ColorSpaceManager.GetColorSpaceID(OldColor) <> ColorSpaceManager.GetColorSpaceID(FullColor) then + CalcSize; +end; + +procedure TJvFullColorCircle.SetBlueColor(const Value: TJvFullColor); +var + OldColor: TJvFullColor; +begin + ConvertToID(Value); + + OldColor := BlueColor; + FBlueColor := Value; + + if Assigned(FBlueColorTrackBar) and not FColorChanging then + begin + FColorChanging := True; + FBlueColorTrackBar.FullColor := Value; + FColorChanging := False; + end; + + InvalidateColors(OldColor, BlueColor); + + if Assigned(FOnBlueColorChange) then + FOnBlueColorChange(Self); +end; + +procedure TJvFullColorCircle.SetGreenColor(const Value: TJvFullColor); +var + OldColor: TJvFullColor; +begin + ConvertToID(Value); + + OldColor := GreenColor; + FGreenColor := Value; + + if Assigned(FGreenColorTrackBar) and not FColorChanging then + begin + FColorChanging := True; + FGreenColorTrackBar.FullColor := Value; + FColorChanging := False; + end; + + InvalidateColors(OldColor, GreenColor); + + if Assigned(FOnGreenColorChange) then + FOnGreenColorChange(Self); +end; + +procedure TJvFullColorCircle.SetRedColor(const Value: TJvFullColor); +var + OldColor: TJvFullColor; +begin + ConvertToID(Value); + + OldColor := RedColor; + FRedColor := Value; + + if Assigned(FRedColorTrackBar) and not FColorChanging then + begin + FColorChanging := True; + FRedColorTrackBar.FullColor := Value; + FColorChanging := False; + end; + + InvalidateColors(OldColor, RedColor); + + if Assigned(FOnRedColorChange) then + FOnRedColorChange(Self); +end; + +procedure TJvFullColorCircle.SetCrossCenter(Value: Integer); +begin + if Value < 0 then + Value := 0; + if Value >= CrossSize then + Value := CrossSize - 1; + if FCrossCenter <> Value then + begin + FCrossCenter := Value; + Invalidate; + end; +end; + +procedure TJvFullColorCircle.SetCrossSize(Value: Integer); +begin + if Value < 0 then + Value := 0; + if FCrossSize <> Value then + begin + FCrossSize := Value; + CalcSize; + end; +end; + +procedure TJvFullColorCircle.SetCrossStyle(const Value: TPen); +begin + FCrossStyle.Assign(Value); + Invalidate; +end; + +procedure TJvFullColorCircle.SetInvertRadius(const Value: Boolean); +begin + if FInvertRadius <> Value then + begin + FInvertRadius := Value; + WantDrawBuffer := True; + end; +end; + +procedure TJvFullColorCircle.SetInvertRotation(const Value: Boolean); +begin + if FInvertRotation <> Value then + begin + FInvertRotation := Value; + WantDrawBuffer := True; + end; +end; + +procedure TJvFullColorCircle.SetLineWidth(Value: Integer); +begin + if Value < 0 then + Value := 0; + if FLineWidth <> Value then + begin + FLineWidth := Value; + WantDrawBuffer := True; + end; +end; + +procedure TJvFullColorCircle.SetStyles(const Value: TJvFullColorCircleStyles); +begin + if FStyles <> Value then + begin + FStyles := Value; + WantDrawBuffer := True; + end; +end; + +procedure TJvFullColorCircle.Notification(AComponent: TComponent; + Operation: TOperation); +begin + if Operation = opRemove then + if AComponent = RedTrackBar then + RedTrackBar := nil + else + if AComponent = GreenTrackBar then + GreenTrackBar := nil + else + if AComponent = BlueTrackBar then + BlueTrackBar := nil + else + if AComponent = CommonTrackBar then + CommonTrackBar := nil; + inherited Notification(AComponent, Operation); +end; + +procedure TJvFullColorCircle.SetBlueColorTrackBar(const Value: TJvFullColorTrackBar); +begin + if (Value <> nil) and (Value <> FBlueColorTrackBar) and Value.Linked then + raise EJvFullColorError.CreateResFmt(@RsEDuplicateTrackBar, [Value.LinkerName]); + + if Assigned(FBlueColorTrackBar) then + begin + FBlueColorTrackBar.OnColorChange := nil; + FBlueColorTrackBar.OnAxisConfigChange := nil; + FBlueColorTrackBar.FreeLink; + end; + + ReplaceComponentReference(Self, Value, TComponent(FBlueColorTrackBar)); + + if Assigned(FBlueColorTrackBar) then + begin + FBlueColorTrackBar.OnColorChange := @TrackBarColorChange; + FBlueColorTrackBar.OnAxisConfigChange := @TrackBarAxisConfigChange; + FBlueColorTrackBar.FullColor := BlueColor; + FBlueColorTrackBar.AxisConfig := AxisConfig; + FBlueColorTrackBar.SetLink(Self); + end; +end; + +procedure TJvFullColorCircle.SetGreenColorTrackBar(const Value: TJvFullColorTrackBar); +begin + if (Value <> nil) and (Value <> FGreenColorTrackBar) and Value.Linked then + raise EJvFullColorError.CreateResFmt(@RsEDuplicateTrackBar, [Value.LinkerName]); + + if Assigned(FGreenColorTrackBar) then + begin + FGreenColorTrackBar.OnColorChange := nil; + FGreenColorTrackBar.OnAxisConfigChange := nil; + FGreenColorTrackBar.FreeLink; + end; + + ReplaceComponentReference(Self, Value, TComponent(FGreenColorTrackBar)); + + if Assigned(FGreenColorTrackBar) then + begin + FGreenColorTrackBar.OnColorChange := @TrackBarColorChange; + FGreenColorTrackBar.OnAxisConfigChange := @TrackBarAxisConfigChange; + FGreenColorTrackBar.FullColor := GreenColor; + FGreenColorTrackBar.AxisConfig := AxisConfig; + FGreenColorTrackBar.SetLink(Self); + end; +end; + +procedure TJvFullColorCircle.SetRedColorTrackBar(const Value: TJvFullColorTrackBar); +begin + if (Value <> nil) and (Value <> FRedColorTrackBar) and Value.Linked then + raise EJvFullColorError.CreateResFmt(@RsEDuplicateTrackBar, [Value.LinkerName]); + + if Assigned(FRedColorTrackBar) then + begin + FRedColorTrackBar.OnColorChange := nil; + FRedColorTrackBar.OnAxisConfigChange := nil; + FRedColorTrackBar.FreeLink; + end; + + ReplaceComponentReference(Self, Value, TComponent(FRedColorTrackBar)); + + if Assigned(FRedColorTrackBar) then + begin + FRedColorTrackBar.OnColorChange := @TrackBarColorChange; + FRedColorTrackBar.OnAxisConfigChange := @TrackBarAxisConfigChange; + FRedColorTrackBar.FullColor := RedColor; + FRedColorTrackBar.AxisConfig := AxisConfig; + FRedColorTrackBar.SetLink(Self); + end; +end; + +procedure TJvFullColorCircle.SetCommonColorTrackBar(const Value: TJvFullColorTrackBar); +begin + if (Value <> nil) and (Value <> FCommonColorTrackBar) and Value.Linked then + raise EJvFullColorError.CreateResFmt(@RsEDuplicateTrackBar, [Value.LinkerName]); + + if Assigned(FCommonColorTrackBar) then + begin + FCommonColorTrackBar.OnColorChange := nil; + FCommonColorTrackBar.OnAxisConfigChange := nil; + FCommonColorTrackBar.FreeLink; + end; + + ReplaceComponentReference(Self, Value, TComponent(FCommonColorTrackBar)); + + if Assigned(FCommonColorTrackBar) then + begin + FCommonColorTrackBar.OnColorChange := @TrackBarColorChange; + FCommonColorTrackBar.OnAxisConfigChange := @TrackBarAxisConfigChange; + FCommonColorTrackBar.FullColor := FullColor; + FCommonColorTrackBar.AxisConfig := AxisConfig; + FCommonColorTrackBar.SetLink(Self); + end; +end; + +procedure TJvFullColorCircle.SetCrossBlueColor(const Value: TColor); +begin + if FCrossBlueColor <> Value then + begin + FCrossBlueColor := Value; + WantDrawBuffer := True; + end; +end; + +procedure TJvFullColorCircle.SetCrossGreenColor(const Value: TColor); +begin + if FCrossGreenColor <> Value then + begin + FCrossGreenColor := Value; + WantDrawBuffer := True; + end; +end; + +procedure TJvFullColorCircle.SetCrossRedColor(const Value: TColor); +begin + if FCrossRedColor <> Value then + begin + FCrossRedColor := Value; + WantDrawBuffer := True; + end; +end; + +procedure TJvFullColorCircle.AxisConfigChange; +begin + if FAxisConfigChanging <> 0 then + Exit; + + if (FCommonColorTrackBar <> nil) and + (FCommonColorTrackBar.AxisConfig <> AxisConfig) then + begin + inc(FAxisConfigChanging); + FCommonColorTrackBar.AxisConfig := AxisConfig; + dec(FAxisConfigChanging); + end; + + if (FRedColorTrackBar <> nil) and + (FRedColorTrackBar.AxisConfig <> AxisConfig) then + begin + inc(FAxisConfigChanging); + FRedColorTrackBar.AxisConfig := AxisConfig; + dec(FAxisConfigChanging); + end; + + if (FGreenColorTrackBar <> nil) and + (FGreenColorTrackBar.AxisConfig <> AxisConfig) then + begin + inc(FAxisConfigChanging); + FGreenColorTrackBar.AxisConfig := AxisConfig; + dec(FAxisConfigChanging); + end; + + if (FBlueColorTrackBar <> nil) and + (FBlueColorTrackBar.AxisConfig <> AxisConfig) then + begin + inc(FAxisConfigChanging); + FBlueColorTrackBar.AxisConfig := AxisConfig; + dec(FAxisConfigChanging); + end; + + inherited AxisConfigChange; +end; + +procedure TJvFullColorCircle.TrackBarColorChange(Sender: TObject); +begin + if FColorChanging then + Exit; + + FColorChanging := True; + + if Sender = RedTrackBar then + RedColor := (Sender as TJvFullColorTrackBar).FullColor + else + if Sender = GreenTrackBar then + GreenColor := (Sender as TJvFullColorTrackBar).FullColor + else + if Sender = BlueTrackBar then + BlueColor := (Sender as TJvFullColorTrackBar).FullColor + else + if Sender = CommonTrackBar then + begin + FullColor := (Sender as TJvFullColorTrackBar).FullColor; + if Assigned(FOnColorChange) then + FOnColorChange(Self); + end; + + FColorChanging := False; +end; + +procedure TJvFullColorCircle.ColorSpaceChange; +begin + if CommonTrackBar <> nil then + CommonTrackBar.FullColor := FullColor; + if RedTrackBar <> nil then + RedTrackBar.FullColor := RedColor; + if GreenTrackBar <> nil then + GreenTrackBar.FullColor := GreenColor; + if BlueTrackBar <> nil then + BlueTrackBar.FullColor := BlueColor; + + inherited ColorSpaceChange; +end; + +//=== { TJvFullColorTrackBar } =============================================== + +constructor TJvFullColorTrackBar.Create(AOwner: TComponent); +begin + inherited Create(AOwner); + + FOrientation := trHorizontal; + FArrowPosition := apNormal; + FColorOrientation := coNormal; + + FArrowWidth := 9; + FArrowColor := clBlack; + FFullColorDrawing := True; + FValueXAuto := True; + FValueYAuto := True; + FLink := nil; + ColorSpaceChange; +end; + +procedure TJvFullColorTrackBar.AxisConfigChange; +begin + UpdateDefaultValueX; + UpdateDefaultValueY; + inherited AxisConfigChange; +end; + +procedure TJvFullColorTrackBar.CalcSize; +begin + case Orientation of + trHorizontal: + begin + FBuffer.Width := Max(Width - (2 * ArrowWidth),0); + FBuffer.Height := Max(Height - ArrowWidth,0); + end; + trVertical: + begin + FBuffer.Width := Max(Width - ArrowWidth,0); + FBuffer.Height := Max(Height - (2 * ArrowWidth),0); + end; + end; + inherited CalcSize; +end; + +procedure TJvFullColorTrackBar.ColorSpaceChange; +begin + UpdateDefaultValueX; + UpdateDefaultValueY; + inherited ColorSpaceChange; +end; + +procedure TJvFullColorTrackBar.DrawBuffer; +var + AxisX, AxisY, AxisZ: TJvAxisIndex; + MinZ, MaxZ, ValueZ, IndexZ: Integer; + TempColor: TJvFullColor; + GraphicRange: Integer; +begin + if (FCreating) or (Width = 0) or (Height = 0) or + (FBuffer.Width = 0) or (FBuffer.Height = 0) then + Exit; + + AxisX := GetIndexAxisX(AxisConfig); + AxisY := GetIndexAxisY(AxisConfig); + AxisZ := GetIndexAxisZ(AxisConfig); + + with ColorSpace do + begin + MinZ := AxisMin[AxisZ]; + MaxZ := AxisMax[AxisZ]; + + if FullColorDrawing then + TempColor := FullColor + else + TempColor := SetAxisValue(SetAxisValue(fclRGBBlack, AxisX, ValueX), AxisY, ValueY); + + with FBuffer.Canvas do + begin + if Orientation = trHorizontal then + GraphicRange := FBuffer.Width - 1 + else + GraphicRange := FBuffer.Height - 1; + for IndexZ := 0 to GraphicRange do + begin + if ColorOrientation = coInverse then + ValueZ := MaxZ - ((IndexZ * (MaxZ - MinZ)) div GraphicRange) + else + ValueZ := ((IndexZ * (MaxZ - MinZ)) div GraphicRange) + MinZ; + Pen.Color := ConvertToColor(SetAxisValue(TempColor, AxisZ, ValueZ)); + case Orientation of + trHorizontal: + begin + MoveTo(IndexZ, 0); + LineTo(IndexZ, Self.Height - ArrowWidth); + end; + trVertical: + begin + MoveTo(0, IndexZ); + LineTo(Self.Width - ArrowWidth, IndexZ); + end; + end; + end; + end; + end; + inherited DrawBuffer; +end; + +function TJvFullColorTrackBar.GetCursorPosition: TJvCursorPoints; +var + AxisZ: TJvAxisIndex; + PosZ, MaxAxis, MinAxis: Integer; + GraphicRange: Integer; +begin + AxisZ := GetIndexAxisZ(AxisConfig); + + with ColorSpace do + begin + MaxAxis := AxisMax[AxisZ]; + MinAxis := AxisMin[AxisZ]; + if Orientation = trHorizontal then + GraphicRange := FBuffer.Width - 1 + else + GraphicRange := FBuffer.Height - 1; + PosZ := GetAxisValue(FullColor, AxisZ); + if ColorOrientation = coInverse then + PosZ := ((MaxAxis - PosZ) * GraphicRange) div (MaxAxis - MinAxis) + else + PosZ := ((PosZ - MinAxis) * GraphicRange) div (MaxAxis - MinAxis); + Inc(PosZ, ArrowWidth); + end; + + case Orientation of + trHorizontal: + begin + Result[0].X := PosZ - ArrowWidth; + Result[1].X := PosZ; + Result[2].X := PosZ + ArrowWidth; + case ArrowPosition of + apNormal: + begin + Result[0].Y := 0; + Result[1].Y := ArrowWidth; + Result[2].Y := 0; + end; + apOpposite: + begin + Result[0].Y := Height - 1; + Result[1].Y := Height - 1 - ArrowWidth; + Result[2].Y := Height - 1; + end; + end; + end; + trVertical: + begin + Result[0].Y := PosZ - ArrowWidth; + Result[1].Y := PosZ; + Result[2].Y := PosZ + ArrowWidth; + case ArrowPosition of + apNormal: + begin + Result[0].X := 0; + Result[1].X := ArrowWidth; + Result[2].X := 0; + end; + apOpposite: + begin + Result[0].X := Width - 1; + Result[1].X := Width - 1 - ArrowWidth; + Result[2].X := Width - 1; + end; + end; + end; + end; +end; + +procedure TJvFullColorTrackBar.InvalidateCursor; +var + ARect: TRect; + CursorPoints: TJvCursorPoints; +begin + CursorPoints := GetCursorPosition; + ARect.Left := Min(CursorPoints[0].X, Min(CursorPoints[1].X, CursorPoints[2].X)); + ARect.Top := Min(CursorPoints[0].Y, Min(CursorPoints[1].Y, CursorPoints[2].Y)); + ARect.Right := Max(CursorPoints[0].X, Max(CursorPoints[1].X, CursorPoints[2].X)) + 1; + ARect.Bottom := Max(CursorPoints[0].Y, Max(CursorPoints[1].Y, CursorPoints[2].Y)) + 1; + InvalidateRect(Handle, @ARect, False); +end; + +procedure TJvFullColorTrackBar.Paint; +var + CursorPoints: TJvCursorPoints; +begin + inherited Paint; + + with Canvas do + begin + case Orientation of + trHorizontal: + case ArrowPosition of + apNormal: + begin + DrawFrame(ArrowWidth, ArrowWidth + 1); + Draw(ArrowWidth, ArrowWidth + 1, FBuffer); + end; + apOpposite: + begin + DrawFrame(ArrowWidth, 0); + Draw(ArrowWidth, 0, FBuffer); + end; + end; + trVertical: + case ArrowPosition of + apNormal: + begin + DrawFrame(ArrowWidth + 1, ArrowWidth); + Draw(ArrowWidth + 1, ArrowWidth, FBuffer); + end; + apOpposite: + begin + DrawFrame(0, ArrowWidth); + Draw(0, ArrowWidth, FBuffer); + end; + end; + end; + Brush.Color := ArrowColor; + Pen.Color := ArrowColor; + CursorPoints := GetCursorPosition; + Polygon(CursorPoints); + end; + DrawFocus; +end; + +procedure TJvFullColorTrackBar.FreeLink; +begin + FLink := nil; +end; + +function TJvFullColorTrackBar.IsValueXStored: Boolean; +begin + Result := not ValueXAuto; +end; + +function TJvFullColorTrackBar.IsValueYStored: Boolean; +begin + Result := not ValueYAuto; +end; + +procedure TJvFullColorTrackBar.KeyMove(KeyCode: TJvKeyCode; MoveCount: Integer); +var + IndexAxisZ: TJvAxisIndex; + ValueZ: Integer; +begin + IndexAxisZ := GetIndexAxisZ(AxisConfig); + ValueZ := GetAxisValue(FullColor, IndexAxisZ); + + if ColorOrientation = coInverse then + MoveCount := -MoveCount; + + case KeyCode of + kcLeft: + if Orientation = trHorizontal then + ValueZ := ValueZ - MoveCount; + kcRight: + if Orientation = trHorizontal then + ValueZ := ValueZ + MoveCount; + kcUp: + if Orientation = trVertical then + ValueZ := ValueZ - MoveCount; + kcDown: + if Orientation = trVertical then + ValueZ := ValueZ + MoveCount; + end; + + with ColorSpace do + ValueZ := EnsureRange(ValueZ, AxisMin[IndexAxisZ], AxisMax[IndexAxisZ]); + + FullColor := SetAxisValue(FullColor, IndexAxisZ, ValueZ); +end; + +function TJvFullColorTrackBar.Linked: Boolean; +begin + Result := FLink <> nil; +end; + +function TJvFullColorTrackBar.LinkerName: TComponentName; +begin + Result := FLink.Name; +end; + +procedure TJvFullColorTrackBar.MouseColor(Shift: TShiftState; X, Y: Integer); +var + MinZ, MaxZ: Byte; + AxisZ: TJvAxisIndex; + GraphicRange: Integer; + Pos: Integer; +begin + if (not (ssLeft in Shift)) or (FBuffer.Width = 0) or (FBuffer.Height = 0) or + (Width = 0) or (Height = 0) then + Exit; + if Orientation = trHorizontal then + Pos := X - ArrowWidth + else + Pos := Y - ArrowWidth; + + if Orientation = trHorizontal then + GraphicRange := FBuffer.Width - 1 + else + GraphicRange := FBuffer.Height - 1; + + AxisZ := GetIndexAxisZ(AxisConfig); + with ColorSpace do + begin + MinZ := AxisMin[AxisZ]; + MaxZ := AxisMax[AxisZ]; + + Pos := EnsureRange((Pos * (MaxZ - MinZ)) div GraphicRange, 0, MaxZ - MinZ); + if ColorOrientation = coInverse then + Pos := MaxZ - Pos + else + Pos := Pos + MinZ; + + FullColor := SetAxisValue(FullColor, AxisZ, Pos); + end; + inherited MouseColor(Shift, X, Y); +end; + +procedure TJvFullColorTrackBar.SetArrowColor(const Value: TColor); +begin + if FArrowColor <> Value then + begin + FArrowColor := Value; + Invalidate; + end; +end; + +procedure TJvFullColorTrackBar.SetArrowPosition(const Value: TJvArrowPosition); +begin + if FArrowPosition <> Value then + begin + FArrowPosition := Value; + Invalidate; + end; +end; + +procedure TJvFullColorTrackBar.SetArrowWidth(const Value: Integer); +begin + if FArrowWidth <> Value then + begin + FArrowWidth := Value; + CalcSize; + end; +end; + +procedure TJvFullColorTrackBar.SetOrientation(const Value: TTrackBarOrientation); +begin + if FOrientation <> Value then + begin + FOrientation := Value; + CalcSize; + end; +end; + +procedure TJvFullColorTrackBar.SetColorOrientation(const Value: TJvFullColorOrientation); +begin + if FColorOrientation <> Value then + begin + FColorOrientation := Value; + WantDrawBuffer := True; + end; +end; + +procedure TJvFullColorTrackBar.SetFullColor(const Value: TJvFullColor); +var + AxisZ: TJvAxisIndex; + OldValueX, OldValueY, OldValueZ, NewValueZ: Byte; +begin + if Value <> FullColor then + begin + AxisZ := GetIndexAxisZ(AxisConfig); + OldValueZ := GetAxisValue(FullColor, AxisZ); + NewValueZ := GetAxisValue(Value, AxisZ); + if NewValueZ <> OldValueZ then + InvalidateCursor; + if FullColorDrawing then + begin + OldValueX := ValueX; + OldValueY := ValueY; + inherited SetFullColor(Value); + if ValueXAuto then + UpdateDefaultValueX; + if ValueYAuto then + UpdateDefaultValueY; + if (ValueX <> OldValueX) or (ValueY <> OldValueY) then + WantDrawBuffer := True; + end + else + inherited SetFullColor(Value); + if NewValueZ <> OldValueZ then + InvalidateCursor; + end; +end; + +procedure TJvFullColorTrackBar.SetFullColorDrawing(const Value: Boolean); +begin + if FFullColorDrawing <> Value then + begin + FFullColorDrawing := Value; + WantDrawBuffer := True; + end; +end; + +procedure TJvFullColorTrackBar.SetLink(AComponent: TComponent); +begin + FLink := AComponent; +end; + +procedure TJvFullColorTrackBar.SetValueX(const Value: Byte); +begin + FValueX := Value; + FValueXAuto := False; + WantDrawBuffer := True; +end; + +procedure TJvFullColorTrackBar.SetValueXAuto(const Value: Boolean); +begin + FValueXAuto := Value; + if Value then + UpdateDefaultValueX; + WantDrawBuffer := True; +end; + +procedure TJvFullColorTrackBar.SetValueY(const Value: Byte); +begin + FValueY := Value; + FValueYAuto := False; + WantDrawBuffer := True; +end; + +procedure TJvFullColorTrackBar.SetValueYAuto(const Value: Boolean); +begin + FValueYAuto := Value; + if Value then + UpdateDefaultValueY; + WantDrawBuffer := True; +end; + +procedure TJvFullColorTrackBar.UpdateDefaultValueX; +begin + if FullColorDrawing then + FValueX := GetAxisValue(FullColor, GetIndexAxisX(AxisConfig)) + else + FValueX := ColorSpace.AxisDefault[GetIndexAxisX(AxisConfig)]; +end; + +procedure TJvFullColorTrackBar.UpdateDefaultValueY; +begin + if FullColorDrawing then + FValueY := GetAxisValue(FullColor, GetIndexAxisY(AxisConfig)) + else + FValueY := ColorSpace.AxisDefault[GetIndexAxisY(AxisConfig)]; +end; + +//=== { TJvColorLabel } ====================================================== + +constructor TJvFullColorLabel.Create(AOwner: TComponent); +begin + inherited Create(AOwner); + ControlStyle := ControlStyle - [csOpaque]; + FPen := TPen.Create; + FPen.OnChange := @GraphicChange; + FBrush := TBrush.Create; + FBrush.OnChange := @GraphicChange; + FShapeType := stRectangle; + FShapePosition := spLeft; + FSpacing := 5; + FRoundShapeWidth := 4; + FRoundShapeHeight := 4; + FShapeWidth := 16; + FShapeHeight := 16; + FLabelColor := fclDEFWindowText; + Width := 100; + Height := 25; +end; + +destructor TJvFullColorLabel.Destroy; +begin + FPen.Free; + FBrush.Free; + inherited Destroy; +end; + +procedure TJvFullColorLabel.CalcSize; +begin + Canvas.Font := Font; + if AutoSize then + begin + case ShapePosition of + spLeft..spRight: + begin + Height := Max(ShapeHeight + Pen.Width, Canvas.TextHeight(Caption)); + Width := ShapeWidth + Pen.Width + Spacing + Canvas.TextWidth(FCaption); + end; + spTop..spBottom: + begin + Height := ShapeHeight + Spacing + Pen.Width + Canvas.TextHeight(Caption); + Width := Max(ShapeWidth + Pen.Width, Canvas.TextWidth(Caption)); + end; + end; + AdjustSize; + end + else + Invalidate; +end; + +procedure TJvFullColorLabel.GraphicChange(Sender: TObject); +begin + CalcSize; + Invalidate; +end; + +procedure TJvFullColorLabel.Paint; +var + h, w: Integer; + ShapeLeft, ShapeTop, TextLeft, TextTop: Integer; +begin + h := Height; + w := Width; + with Canvas do + begin + Brush.Style := bsSolid; + Brush.Color := Parent.Brush.Color; + FillRect(0, 0, w, h); + Font := Self.Font; + Pen := Self.Pen; + Brush := Self.Brush; + Brush.Color := ColorSpaceManager.ConvertToColor(LabelColor); + inherited Paint; + case FShapePosition of + spLeft: + begin + ShapeTop := (h - FShapeHeight) div 2; + TextLeft := FShapeWidth + FSpacing; + TextTop := (h - TextHeight(FCaption)) div 2; + end; + spRight: + begin + ShapeLeft := TextWidth(FCaption) + FSpacing; + ShapeTop := (h - FShapeHeight) div 2; + TextLeft := 0; + TextTop := (h - TextHeight(FCaption)) div 2; + end; + spTop: + begin + ShapeLeft := (w - FShapeWidth) div 2; + ShapeTop := 0; + TextLeft := (w - TextWidth(FCaption)) div 2; + TextTop := FShapeHeight + FSpacing; + end; + spBottom: + begin + ShapeLeft := (w - FShapeWidth) div 2; + ShapeTop := TextHeight(FCaption) + FSpacing; + TextLeft := (w - TextWidth(FCaption)) div 2; + TextTop := 0; + end; + else + ShapeLeft := 0; + ShapeTop := 0; + TextLeft := 0; + TextTop := 0; + end; + case FShapeType of + stRectangle..stSquare: + Rectangle(ShapeLeft, ShapeTop, ShapeLeft + FShapeWidth, ShapeTop + FShapeHeight); + stRoundRect..stRoundSquare: + RoundRect(ShapeLeft, ShapeTop, ShapeLeft + FShapeWidth, ShapeTop + FShapeHeight, + RoundShapeWidth, RoundShapeHeight); + stEllipse..stCircle: + Ellipse(ShapeLeft, ShapeTop, ShapeLeft + FShapeWidth, ShapeTop + FShapeHeight); + end; + Brush.Style := bsClear; + TextOut(TextLeft, TextTop, FCaption); + end; +end; + +procedure TJvFullColorLabel.SetAutoSize(Value: Boolean); +begin + inherited SetAutoSize(Value); + CalcSize; +end; + +procedure TJvFullColorLabel.SetCaption(const Value: TCaption); +begin + if FCaption <> Value then + begin + FCaption := Value; + CalcSize; + end; +end; + +procedure TJvFullColorLabel.SetName(const Value: TComponentName); +var + Equal: Boolean; +begin + Equal := Name = FCaption; + inherited SetName(Value); + if Equal then + Caption := Name; +end; + +procedure TJvFullColorLabel.SetRoundShapeHeight(const Value: Integer); +begin + if (Value <> FRoundShapeHeight) and (Value < ShapeHeight div 2) then + begin + FRoundShapeHeight := Value; + Invalidate; + end; +end; + +procedure TJvFullColorLabel.SetRoundShapeWidth(const Value: Integer); +begin + if (Value <> FRoundShapeWidth) and (Value < ShapeWidth div 2) then + begin + FRoundShapeWidth := Value; + if FRoundShapeWidth > Value div 2 then + FRoundShapeWidth := Value div 2; + if Shape in [stSquare, stRoundSquare, stCircle] then + FShapeHeight := FShapeWidth; + Invalidate; + end; +end; + +procedure TJvFullColorLabel.SetShapeHeight(const Value: Integer); +begin + if FShapeHeight <> Value then + begin + FShapeHeight := Value; + if FRoundShapeHeight > Value div 2 then + FRoundShapeHeight := Value div 2; + if Shape in [stSquare, stRoundSquare, stCircle] then + FShapeWidth := FShapeHeight; + CalcSize; + end; +end; + +procedure TJvFullColorLabel.SetShapePosition(const Value: TJvShapePosition); +begin + if FShapePosition <> Value then + begin + FShapePosition := Value; + CalcSize; + end; +end; + +procedure TJvFullColorLabel.SetShapeType(const Value: TShapeType); +begin + if FShapeType <> Value then + begin + FShapeType := Value; + if Shape in [stSquare, stRoundSquare, stCircle] then + begin + FShapeWidth := Min(FShapeWidth, FShapeHeight); + FShapeHeight := FShapeWidth; + end; + CalcSize; + end; +end; + +procedure TJvFullColorLabel.SetShapeWidth(const Value: Integer); +begin + if FShapeWidth <> Value then + begin + FShapeWidth := Value; + if Shape in [stSquare, stRoundSquare, stCircle] then + FShapeHeight := FShapeWidth; + CalcSize; + end; +end; + +procedure TJvFullColorLabel.SetSpacing(const Value: Integer); +begin + if FSpacing <> Value then + begin + FSpacing := Value; + CalcSize; + end; +end; + +procedure TJvFullColorLabel.SetLabelColor(const Value: TJvFullColor); +begin + if FLabelColor <> Value then + begin + FLabelColor := Value; + Brush.Color := ColorSpaceManager.ConvertToColor(Value); + Invalidate; + end; +end; + +procedure TJvFullColorLabel.SetBrush(const Value: TBrush); +begin + FBrush.Assign(Value); + Invalidate; +end; + +procedure TJvFullColorLabel.SetPen(const Value: TPen); +begin + FPen.Assign(Value); + CalcSize; +end; + +//=== { TJvColorSpaceCombo } ================================================= + +constructor TJvFullColorSpaceCombo.Create(AOwner: TComponent); +begin + inherited Create(AOwner); + Style := csDropDownList; + FAllowVariable := True; + FItemFormat := cfBoth; +end; + +procedure TJvFullColorSpaceCombo.CreateWnd; +begin + inherited CreateWnd; + MakeList; +end; + +function TJvFullColorSpaceCombo.GetColorSpace: TJvColorSpace; +begin + if ItemIndex > -1 then + Result := TJvColorSpace(Self.Items.Objects[ItemIndex]) + else + Result := nil; +end; + +function TJvFullColorSpaceCombo.GetColorSpaceID: TJvFullColorSpaceID; +var + CS: TJvColorSpace; +begin + CS := SelectedSpace; + if CS <> nil then + Result := CS.ID + else + Result := csRGB; +end; + +procedure TJvFullColorSpaceCombo.MakeList; +var + Index: Integer; + LColorSpace: TJvColorSpace; + OldColorID: TJvFullColorSpaceID; + ACaption: string; +begin + OldColorID := ColorSpaceID; + with ColorSpaceManager, Items do + begin + Clear; + for Index := 0 to ColorSpaceManager.Count - 1 do + begin + LColorSpace := ColorSpaceByIndex[Index]; + if (LColorSpace.ID <> csDEF) or AllowVariable then + begin + if Assigned(FOnFormatItem) then + FOnFormatItem(Self, LColorSpace, ACaption) + else + ACaption := ColorSpaceToString(LColorSpace, ItemFormat); + AddObject(ACaption, LColorSpace); + end; + end; + end; + ColorSpaceID := OldColorID; +end; + +procedure TJvFullColorSpaceCombo.SetAllowVariable(const Value: Boolean); +begin + if FAllowVariable <> Value then + begin + FAllowVariable := Value; + MakeList; + end; +end; + +procedure TJvFullColorSpaceCombo.SetColorSpace(const Value: TJvColorSpace); +var + I: Integer; +begin + for I := 0 to Items.Count - 1 do + if Value.ID = TJvColorSpace(Items.Objects[I]).ID then + begin + ItemIndex := I; + Exit; + end; +end; + +procedure TJvFullColorSpaceCombo.SetColorSpaceID(const Value: TJvFullColorSpaceID); +begin + SetColorSpace(ColorSpaceManager.ColorSpace[Value]); +end; + +procedure TJvFullColorSpaceCombo.SetItemFormat(const Value: TJvFullColorSpaceFormat); +begin + if FItemFormat <> Value then + begin + FItemFormat := Value; + MakeList; + end; +end; + +//=== { TJvColorAxisConfigCombo } ============================================ + +constructor TJvFullColorAxisCombo.Create(AOwner: TComponent); +begin + inherited Create(AOwner); + Style := csDropDownList; + FColorID := csRGB; + FItemFormat := afComplete; +end; + +procedure TJvFullColorAxisCombo.CreateWnd; +begin + inherited CreateWnd; + MakeList; +end; + +function TJvFullColorAxisCombo.GetSelected: TJvFullColorAxisConfig; +begin + if ItemIndex = -1 then + Result := acXYZ + else + Result := TJvFullColorAxisConfig(ItemIndex); +end; + +procedure TJvFullColorAxisCombo.MakeList; +var + Index: TJvFullColorAxisConfig; + LColorSpace: TJvColorSpace; + OldItemIndex: Integer; + FormattedItem: string; +begin + OldItemIndex := ItemIndex; + LColorSpace := ColorSpaceManager.ColorSpace[ColorID]; + with Items do + begin + Clear; + for Index := Low(TJvFullColorAxisConfig) to High(TJvFullColorAxisConfig) do + begin + if Assigned(FOnFormatItem) then + FOnFormatItem(Self,Index,FormattedItem) + else + FormattedItem := AxisConfigToString(Index, ItemFormat, LColorSpace); + Add(FormattedItem); + end; + end; + if OldItemIndex > -1 then + ItemIndex := OldItemIndex + else + ItemIndex := 0; +end; + +procedure TJvFullColorAxisCombo.SetColorID(const Value: TJvFullColorSpaceID); +begin + if FColorID <> Value then + begin + FColorID := Value; + MakeList; + end; +end; + +procedure TJvFullColorAxisCombo.SetItemFormat(const Value: TJvFullColorAxisConfigFormat); +begin + if FItemFormat <> Value then + begin + FItemFormat := Value; + MakeList; + end; +end; + +procedure TJvFullColorAxisCombo.SetOnFormatItem( + const Value: TJvFullColorAxisFormatEvent); +begin + FOnFormatItem := Value; + MakeList; +end; + +procedure TJvFullColorAxisCombo.SetSelected(const Value: TJvFullColorAxisConfig); +begin + ItemIndex := Ord(Value); +end; + +//=== { TJvFullColorList } =================================================== + +constructor TJvFullColorList.Create; +begin + inherited Create; + FList := nil; + FCount := 0; + FCapacity := 0; + FAllocBy := 2; +end; + +destructor TJvFullColorList.Destroy; +begin + Clear; + inherited Destroy; +end; + +function TJvFullColorList.Add(AColor: TJvFullColor): Integer; +begin + Result := FCount; + if Result = Capacity then + Grow; + FList^[Result] := AColor; + Inc(FCount); + Change(Result, foAdded); +end; + +procedure TJvFullColorList.Assign(Source: TPersistent); +var + Index: Integer; +begin + if Source is TJvFullColorList then + with TJvFullColorList(Source) do + begin + Self.BeginUpdate; + Self.Count := Count; + for Index := 0 to Self.Count - 1 do + Self.Items[Index] := Items[Index]; + Self.EndUpdate; + Self.Change(-1, foAllChanged); + end + else + inherited Assign(Source); +end; + +procedure TJvFullColorList.Change(AIndex: Integer; + AOperation: TJvFullColorListOperation); +begin + if (UpdateCount = 0) and Assigned(FOnChange) then + FOnChange(Self, AIndex, AOperation); +end; + +procedure TJvFullColorList.Clear; +begin + Capacity := 0; + Change(-1, foAllChanged); +end; + +procedure TJvFullColorList.DefineProperties(Filer: TFiler); +begin + inherited DefineProperties(Filer); + Filer.DefineProperty('Items', @ReadItems, @WriteItems, Count > 0); +end; + +procedure TJvFullColorList.Delete(Index: Integer); +begin + if (Index < 0) or (Index >= FCount) then + EJvFullColorListError.CreateFmt(SListIndexError, [Index]); + + Dec(FCount); + if Index < Count then + Move(FList^[Index + 1], FList^[Index], (Count - Index) * SizeOf(TJvFullColor)); + + Change(Index, foDeleted); +end; + +procedure TJvFullColorList.DeleteRedundant; +begin +end; + +procedure TJvFullColorList.Exchange(Index1, Index2: Integer); +var + Tmp: TJvFullColor; +begin + if (Index1 >= Count) or (Index1 < 0) then + raise EJvFullColorListError.CreateResFmt(@SListIndexError, [Index1]); + + if (Index2 >= Count) or (Index2 < 0) then + raise EJvFullColorListError.CreateResFmt(@SListIndexError, [Index2]); + + Tmp := FList^[Index1]; + FList^[Index1] := FList^[Index2]; + FList^[Index2] := Tmp; + + Change(Index1, foChanged); + Change(Index2, foChanged); +end; + +function TJvFullColorList.GetItem(Index: Integer): TJvFullColor; +begin + if (Index >= Count) or (Index < 0) then + raise EJvFullColorListError.CreateResFmt(@SListIndexError, [Index]); + + Result := FList^[Index]; +end; + +procedure TJvFullColorList.Grow; +begin + Capacity := Capacity + AllocBy; +end; + +function TJvFullColorList.IndexOf(AColor: TJvFullColor): Integer; +begin + for Result := 0 to Count - 1 do + if FList^[Result] = AColor then + Exit; + Result := -1; +end; + +procedure TJvFullColorList.Insert(Index: Integer; AColor: TJvFullColor); +begin + if (Index > Count) or (Index < 0) then + EJvFullColorListError.CreateFmt(SListIndexError, [Index]); + + if Count = Capacity then + Grow; + + if Index < Count then + Move(FList^[Index], FList^[Index + 1], (FCount - Index) * SizeOf(TJvFullColor)); + + FList^[Index] := AColor; + Inc(FCount); + + Change(Index, foAdded); +end; + +procedure TJvFullColorList.BeginUpdate; +begin + Inc(FUpdateCount); +end; + +procedure TJvFullColorList.ReadItems(Reader: TReader); +begin + try + Reader.ReadListBegin; + BeginUpdate; + Clear; + while not Reader.EndOfList do + Add(Reader.ReadInteger); + finally + EndUpdate; + Reader.ReadListEnd; + end; +end; + +function TJvFullColorList.Remove(AColor: TJvFullColor): Integer; +begin + Result := IndexOf(AColor); + if Result >= 0 then + Delete(Result); +end; + +procedure TJvFullColorList.SetAllocBy(const Value: Integer); +begin + FAllocBy := Max(Value, 1); +end; + +procedure TJvFullColorList.SetCapacity(const Value: Integer); +begin + ReallocMem(FList, Value * SizeOf(TJvFullColor)); + FCapacity := Value; + if FCount > FCapacity then + begin + FCount := FCapacity; + Change(-1, foAllChanged); + end; +end; + +procedure TJvFullColorList.SetCount(const Value: Integer); +begin + FCount := Value; + if FCount > FCapacity then + Capacity := FCount; + Change(-1, foAllChanged); +end; + +procedure TJvFullColorList.SetItem(Index: Integer; const Value: TJvFullColor); +begin + if (Index >= Count) or (Index < 0) then + EJvFullColorListError.CreateFmt(SListIndexError, [Index]); + + FList^[Index] := Value; + Change(Index, foChanged); +end; + +procedure TJvFullColorList.EndUpdate; +begin + if FUpdateCount > 0 then + Dec(FUpdateCount); + if FUpdateCount = 0 then + Change(-1, foAllChanged); +end; + +procedure TJvFullColorList.WriteItems(Writer: TWriter); +var + I: Integer; +begin + Writer.WriteListBegin; + for I := 0 to Count - 1 do + Writer.WriteInteger(FList^[I]); + Writer.WriteListEnd; +end; + +//=== { TFullColorGroup } ==================================================== + +constructor TJvFullColorGroup.Create(AOwner: TComponent); +begin + inherited Create(AOwner); + ControlStyle := ControlStyle + [csOpaque]; + FItems := TJvFullColorList.Create; + FItems.OnChange := @ItemsChange; + FBrush := TBrush.Create; + FBrush.OnChange := @BrushChange; + FEdge := feRaised; + FSelectedEdge := feLowered; + FMouseEdge := feRaised; + FColCount := 5; + FSquareSize := 6; + FSelectedIndex := -1; + FMouseIndex := -1; + (*************** NOT CONVERTED *** + BevelKind := bkTile; + *********************************) + Width := 100; + Height := 100; +end; + +destructor TJvFullColorGroup.Destroy; +begin + FItems.Free; + FBrush.Free; + inherited Destroy; +end; + +procedure TJvFullColorGroup.CalcRects(out XPos, YPos, XInc, YInc: Integer); +var + XOffset: Integer; + YOffset: Integer; +begin + XOffset := Width - (FSquareSize * ColCount) - 2; + XInc := XOffset div ColCount; + XPos := ((XOffset - (XInc * (ColCount - 1))) div 2) + 1; + + YOffset := Height - (FSquareSize * RowCount) - 2; + YInc := YOffset div RowCount; + YPos := ((YOffset - (YInc * (RowCount - 1))) div 2) + 1; +end; + +procedure TJvFullColorGroup.ItemsChange(Sender: TObject; Index: Integer; + Operation: TJvFullColorListOperation); +begin + case Operation of + foAllChanged: + begin + FMouseIndex := -1; + FSelectedIndex := -1; + Invalidate; + end; + foDeleted: + begin + FMouseIndex := -1; + FSelectedIndex := EnsureRange(FSelectedIndex, -1, Items.Count - 1); + Invalidate; + end; + foAdded: + Invalidate; + foChanged: + InvalidateIndex(Index); + end; +end; + +procedure TJvFullColorGroup.BrushChange(Sender: TObject); +begin + Refresh; +end; + +procedure TJvFullColorGroup.InvalidateIndex(AIndex: Integer); +var + ARect: TRect; + ColIndex, RowIndex: Integer; + XPos, YPos, XInc, YInc: Integer; +begin + if AIndex <> -1 then + begin + CalcRects(XPos, YPos, XInc, YInc); + ColIndex := AIndex mod ColCount; + RowIndex := AIndex div ColCount; + ARect.Left := XPos + ColIndex * (XInc + FSquareSize); + ARect.Top := YPos + RowIndex * (YInc + FSquareSize); + ARect.Right := ARect.Left + FSquareSize + 1; + ARect.Bottom := ARect.Top + FSquareSize + 1; + InvalidateRect(Handle, @ARect, False); + end; +end; + +procedure TJvFullColorGroup.MouseLeave(var Msg: TLMMouse); +begin + FMouseIndex := -1; + Msg.Result := 1; + Refresh; +end; + +{$IFDEF RTL200_UP} +// for D2009 "Use Controls.PHintInfo" warning +type + PHintInfo = Controls.PHintInfo; +{$ENDIF RTL200_UP} + +procedure TJvFullColorGroup.CMHintShow(var Msg: TLMessage); +var + AHintInfo: PHintInfo; + Sum, XPos, YPos, XInc, YInc, Index: Integer; + ColorIndex: Integer; + AFullColor: TJvFullColor; + AColor: TColor; + AColorID: TJvFullColorSpaceID; + AColorSpace: TJvColorSpace; +begin + AHintInfo := PHintInfo(Msg.LParam); + ColorIndex := -1; + + CalcRects(XPos, YPos, XInc, YInc); + + Sum := YPos; + with AHintInfo^ do + for Index := 0 to RowCount - 1 do + begin + if CursorPos.Y < Sum then + begin + CursorRect.Top := Max(0, Sum - YInc); + CursorRect.Bottom := Sum; + Break; + end + else + if (CursorPos.Y >= Sum) and (CursorPos.Y < Sum + FSquareSize) then + begin + CursorRect.Top := Sum; + CursorRect.Bottom := Sum + FSquareSize; + ColorIndex := Index * ColCount; + Break; + end; + Inc(Sum, FSquareSize + YInc); + end; + + Sum := XPos; + with AHintInfo^ do + for Index := 0 to ColCount do + // not -1 because of last space after the colcount - 1 + begin + if CursorPos.X < Sum then + begin + CursorRect.Left := Max(0, Sum - XInc); + CursorRect.Right := Sum; + ColorIndex := -1; + Break; + end + else + if (CursorPos.X >= Sum) and (CursorPos.X < Sum + FSquareSize) then + begin + CursorRect.Left := Sum; + CursorRect.Right := Sum + FSquareSize; + if ColorIndex <> -1 then + ColorIndex := ColorIndex + Index; + Break; + end; + Inc(Sum, FSquareSize + XInc); + end; + + if ColorIndex >= Items.Count then + ColorIndex := -1; + + if ColorIndex > -1 then + with ColorSpaceManager do + begin + AFullColor := Items.Items[ColorIndex]; + AColorID := GetColorSpaceID(AFullColor); + AColorSpace := ColorSpace[AColorID]; + + if AColorSpace.ID = csDEF then + with TJvDEFColorSpace(AColorSpace) do + begin + AColor := ConvertToColor(AFullColor); + for Index := 0 to ColorCount - 1 do + if AColor = ColorValue[Index] then + begin + AHintInfo^.HintStr := Format(RsColorHintFmt1, [AFullColor, + AColorSpace.Name, AColorID, ColorName[Index], ColorPrettyName[Index]]); + Break; + end; + end + else + AHintInfo^.HintStr := Format(RsColorHintFmt2, [AFullColor, AColorSpace.Name, AColorID, + AColorSpace.AxisName[axIndex0], GetAxisValue(AFullColor, axIndex0), + AColorSpace.AxisName[axIndex1], GetAxisValue(AFullColor, axIndex1), + AColorSpace.AxisName[axIndex2], GetAxisValue(AFullColor, axIndex2)]); + + if Assigned(FOnFormatHint) then + FOnFormatHint(Self, AFullColor, AHintInfo^.HintStr); + end + else + AHintInfo^.HintStr := Hint; + + Msg.Result := 0; +end; + +procedure TJvFullColorGroup.MouseMove(Shift: TShiftState; X, Y: Integer); +var + Index: Integer; + Sum: Integer; + XPos, YPos, XInc, YInc: Integer; + ColIndex, RowIndex: Integer; +begin + inherited MouseMove(Shift, X, Y); + + CalcRects(XPos, YPos, XInc, YInc); + + Sum := XPos; + if X < XPos then + begin + InvalidateIndex(MouseIndex); + FMouseIndex := -1; + Exit; + end; + ColIndex := -1; + for Index := 0 to ColCount - 1 do + begin + if (X >= Sum) and (X < Sum + FSquareSize) then + begin + ColIndex := Index; + Break; + end; + if (X >= Sum + FSquareSize) and (X < Sum + FSquareSize + XInc) then + Break; + Inc(Sum, FSquareSize + XInc); + end; + + if ColIndex = -1 then + begin + InvalidateIndex(MouseIndex); + FMouseIndex := -1; + Exit; + end; + + Sum := YPos; + if Y < YPos then + begin + InvalidateIndex(MouseIndex); + FMouseIndex := -1; + Exit; + end; + RowIndex := -1; + for Index := 0 to RowCount - 1 do + begin + if (Y >= Sum) and (Y < Sum + FSquareSize) then + begin + RowIndex := Index; + Break; + end; + if (Y >= Sum + FSquareSize) and (Y < Sum + FSquareSize + YInc) then + Break; + Inc(Sum, FSquareSize + YInc); + end; + if RowIndex = -1 then + begin + InvalidateIndex(MouseIndex); + FMouseIndex := -1; + Exit; + end; + + InvalidateIndex(MouseIndex); + FMouseIndex := RowIndex * ColCount + ColIndex; + if MouseIndex > Items.Count - 1 then + FMouseIndex := -1; + InvalidateIndex(MouseIndex); +end; + +procedure TJvFullColorGroup.MouseDown(Button: TMouseButton; + Shift: TShiftState; X, Y: Integer); +begin + inherited MouseDown(Button, Shift, X, Y); + InvalidateIndex(SelectedIndex); + SelectedIndex := MouseIndex; + InvalidateIndex(SelectedIndex); +end; + +procedure TJvFullColorGroup.Paint; +var + Index, IndexX, IndexY, XMaj: Integer; + XOffset, YOffset, XInc, YInc: Integer; + X, Y: Integer; + lEdge: TJvFullColorEdge; + ClipRect: TRect; + + procedure BevelRect(const R: TRect; Style: TJvFullColorEdge; + FillStyle: TBrushStyle; FillColor: TColor); + var + Color1, Color2: TColor; + begin + case Style of + feLowered: + begin + Color1 := clBtnShadow; + Color2 := clBtnHighlight; + end; + feRaised: + begin + Color1 := clBtnHighlight; + Color2 := clBtnShadow; + end; + else + Color1 := clBlack; + Color2 := clBlack; + end; + + with Canvas do + begin + Brush.Color := FillColor; + Brush.Style := FillStyle; + Pen.Color := FillColor; + Pen.Style := psClear; + Rectangle(R.Left + 1, R.Top + 1, R.Right + 1, R.Bottom + 1); + + Pen.Style := psSolid; + Pen.Color := Color1; + PolyLine([Point(R.Left, R.Bottom), Point(R.Left, R.Top), + Point(R.Right, R.Top)]); + Pen.Color := Color2; + PolyLine([Point(R.Right, R.Top), Point(R.Right, R.Bottom), + Point(R.Left, R.Bottom)]); + end; + end; + +begin + inherited Paint; + CalcRects(XOffset, YOffset, XInc, YInc); + + Y := YOffset; + X := XOffset; + ClipRect := Canvas.ClipRect; + + Index := 0; + while Index < Items.Count do + begin + if Index = SelectedIndex then + lEdge := SelectedEdge + else + if Index = MouseIndex then + lEdge := MouseEdge + else + lEdge := feFlat; + + BevelRect(Rect(X, Y, X + FSquareSize, Y + FSquareSize), lEdge, Brush.Style, + ColorSpaceManager.ConvertToColor(Items[Index])); + Inc(Index); + if Index mod ColCount = 0 then + begin + X := XOffset; + Inc(Y, YInc + FSquareSize); + end + else + Inc(X, XInc + FSquareSize); + end; + + with Canvas do + begin + Brush.Style := bsSolid; + Brush.Color := Color; + Pen.Color := Color; + Y := YOffset; + for IndexY := 0 to RowCount do + begin + Rectangle( + Max(ClipRect.Left, 1), + Max(Y - YInc + 1, 1), + Min(ClipRect.Right, Self.Width - 2), + Min(Y, Self.Height - 2) + ); + X := XOffset; + for IndexX := 0 to ColCount do + begin + if IndexX + IndexY * ColCount >= Items.Count then + XMaj := FSquareSize + 1 + else + XMaj := 0; + Rectangle( + Max(X - XInc + 1, 1), + Min(Max(Y, 1), Self.Height - 2), + Min(X + XMaj, Self.Width - 2), + Min(Y + FSquareSize + 1, Self.Height - 2) + ); + Inc(X, XInc + FSquareSize); + end; + Inc(Y, YInc + FSquareSize); + end; + end; +end; + +procedure TJvFullColorGroup.SetEdge(const Value: TJvFullColorEdge); +begin + FEdge := Value; + Refresh; +end; + +procedure TJvFullColorGroup.SetMouseEdge(const Value: TJvFullColorEdge); +begin + FMouseEdge := Value; + Refresh; +end; + +procedure TJvFullColorGroup.SetSelectedEdge(const Value: TJvFullColorEdge); +begin + FSelectedEdge := Value; + Refresh; +end; + +procedure TJvFullColorGroup.SetColCount(const Value: Integer); +begin + if Value <= 0 then + FColCount := 1 + else + FColCount := Value; + Refresh; +end; + +function TJvFullColorGroup.GetRowCount: Integer; +begin + Result := Max((Items.Count + ColCount - 1) div ColCount, 1); +end; + +procedure TJvFullColorGroup.SetItems(const Value: TJvFullColorList); +begin + FItems.Assign(Value); + Invalidate; +end; + +procedure TJvFullColorGroup.SetSquareSize(const Value: Integer); +var + TempValue: Integer; +begin + if FSquareSize < 0 then + FSquareSize := -FSquareSize; + + if FSquareSize = 0 then + FSquareSize := 1; + + FSquareSize := Value; + + TempValue := (Width - 2) div ColCount; + if TempValue < FSquareSize then + FSquareSize := TempValue; + + TempValue := (Height - 2) div (Items.Count div ColCount + 1); + if TempValue < FSquareSize then + FSquareSize := TempValue; + + Refresh; +end; + +function TJvFullColorGroup.GetSelected: TJvFullColor; +begin + if SelectedIndex > -1 then + Result := Items[SelectedIndex] + else + Result := clNone; +end; + +procedure TJvFullColorGroup.SetSelected(const Value: TJvFullColor); +begin + SelectedIndex := Items.IndexOf(Value); +end; + +procedure TJvFullColorGroup.SetSelectedIndex(const Value: Integer); +begin + FSelectedIndex := EnsureRange(Value, -1, Items.Count - 1); + if Assigned(FOnChange) then + FOnChange(Self); +end; + +procedure TJvFullColorGroup.SetBrush(const Value: TBrush); +begin + FBrush.Assign(Value); +end; + +end. diff --git a/components/jvcllaz/run/JvMM/jvfullcolordialogs.pas b/components/jvcllaz/run/JvMM/jvfullcolordialogs.pas new file mode 100644 index 000000000..f549d4ca6 --- /dev/null +++ b/components/jvcllaz/run/JvMM/jvfullcolordialogs.pas @@ -0,0 +1,467 @@ +{----------------------------------------------------------------------------- +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: ColorDialogs.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 JvFullColorDialogs; + +{$mode objfpc}{$H+} + +interface + +uses + Classes, Graphics, Forms, + JvFullColorSpaces, JvFullColorRotate; + +type + TJvFullColorDialogOption = + (foFullOpen, foPreventExpand, foShowHelp, + foAllowSpaceChange, foConvertToOriginalSpace, + foShowNewPreview, foShowOldPreview, + foShowPredefined, foAllowVariable, + foNoneAndDefault, foShowApply); + TJvFullColorDialogOptions = set of TJvFullColorDialogOption; + + TJvFullColorCircleDialogOption = + (coFullOpen, coPreventExpand, + coShowHelp, coAllowSpaceChange, + coShowNewPreview, coShowOldPreview, + coCommon, coRed, coGreen, coBlue, + coShowSaturation, coDefaultRange, + coShowApply); + TJvFullColorCircleDialogOptions = set of TJvFullColorCircleDialogOption; + +const + JvDefaultFullColorDialogOptions = + [foFullOpen, foAllowSpaceChange, foAllowVariable, + foShowNewPreview, foShowOldPreview, foShowPredefined, foShowApply]; + + JvDefaultColorCircleDialogOptions = + [coFullOpen, coAllowSpaceChange, + coShowNewPreview, coShowOldPreview, + coCommon, coRed, coGreen, coBlue, + coShowSaturation, coShowApply]; + +type + TJvAxisType = (atCommon, atRed, atGreen, atBlue); + + TJvFullColorEvent = procedure(Sender: TObject; AFullColor: TJvFullColor) of object; + + TJvColorCircleEvent = procedure(Sender: TObject) of object; + + TJvFullColorDialog = class; + TJvFullColorCircleDialog = class; + + TJvFullColorDialog = class(TComponent) + private + FOptions: TJvFullColorDialogOptions; + FTitle: string; + FFullColor: TJvFullColor; + FOnApply: TJvFullColorEvent; + FForm: TForm; + FOnCloseQuery: TCloseQueryEvent; + FOnShow: TNotifyEvent; + FHelpContext: THelpContext; + FOldColorSpace: TJvFullColorSpaceID; + FDropDownCount: Integer; + function GetColor: TColor; + function GetFullColor: TJvFullColor; + procedure SetFullColor(const Value: TJvFullColor); + procedure SetHelpContext(const Value: THelpContext); + procedure SetOptions(const Value: TJvFullColorDialogOptions); + procedure SetTitle(const Value: string); + protected + procedure FormApply(Sender: TObject); + procedure FormShow(Sender: TObject); + procedure FormClose(Sender: TObject; var CloseAction: TCloseAction); + property OldColorSpace: TJvFullColorSpaceID read FOldColorSpace; + public + constructor Create(AOwner: TComponent); override; + function Execute: Boolean; + property Form: TForm read FForm; + property Color: TColor read GetColor; + published + property DropDownCount: Integer read FDropDownCount write FDropDownCount default 8; + property FullColor: TJvFullColor read GetFullColor write SetFullColor default fclRGBBlack; + property Options: TJvFullColorDialogOptions read FOptions write SetOptions default JvDefaultFullColorDialogOptions; + property Title: string read FTitle write SetTitle; + property HelpContext: THelpContext read FHelpContext write SetHelpContext default 0; + property OnApply: TJvFullColorEvent read FOnApply write FOnApply; + property OnShow: TNotifyEvent read FOnShow write FOnShow; + property OnCloseQuery: TCloseQueryEvent read FOnCloseQuery write FOnCloseQuery; + end; + + TJvFullColorCircleDialog = class(TComponent) + private + FTitle: string; + FForm: TForm; + FHelpContext: THelpContext; + FOnCloseQuery: TCloseQueryEvent; + FOnShow: TNotifyEvent; + FOptions: TJvFullColorCircleDialogOptions; + FOnApply: TJvColorCircleEvent; + FDelta: TJvColorDelta; + FDropdownCount: Integer; + procedure SetHelpContext(const Value: THelpContext); + procedure SetOptions(const Value: TJvFullColorCircleDialogOptions); + procedure SetTitle(const Value: string); + procedure SetColorID(const Value: TJvFullColorSpaceID); + procedure SetBlueDelta(const Value: TJvAxisDelta); + procedure SetGreenDelta(const Value: TJvAxisDelta); + procedure SetRedDelta(const Value: TJvAxisDelta); + function GetRedDelta: TJvAxisDelta; + function GetGreenDelta: TJvAxisDelta; + function GetBlueDelta: TJvAxisDelta; + function GetColorID: TJvFullColorSpaceID; + protected + procedure FormApply(Sender: TObject); + procedure FormShow(Sender: TObject); + procedure FormClose(Sender: TObject; var Action: TCloseAction); + public + constructor Create(AOwner: TComponent); override; + destructor Destroy; override; + + function Execute: Boolean; + property Form: TForm read FForm; + property RedDelta: TJvAxisDelta read GetRedDelta write SetRedDelta; + property GreenDelta: TJvAxisDelta read GetGreenDelta write SetGreenDelta; + property BlueDelta: TJvAxisDelta read GetBlueDelta write SetBlueDelta; + property ColorID: TJvFullColorSpaceID read GetColorID write SetColorID; + property Delta: TJvColorDelta read FDelta; + published + // (rom) set default values + property DropdownCount: Integer read FDropdownCount write FDropDownCount default 8; + property Options: TJvFullColorCircleDialogOptions + read FOptions write SetOptions default JvDefaultColorCircleDialogOptions; + property Title: string read FTitle write SetTitle; + property HelpContext: THelpContext read FHelpContext write SetHelpContext; + property OnApply: TJvColorCircleEvent read FOnApply write FOnApply; + property OnShow: TNotifyEvent read FOnShow write FOnShow; + property OnCloseQuery: TCloseQueryEvent read FOnCloseQuery write FOnCloseQuery; + end; + + +implementation + +uses + JvResources, + Controls, SysUtils, JvFullColorForm, JvFullColorCircleForm; + +//=== { TJvFullColorDialog } ================================================= + +constructor TJvFullColorDialog.Create(AOwner: TComponent); +begin + inherited Create(AOwner); + FOptions := JvDefaultFullColorDialogOptions; + FFullColor := fclRGBBlack; + FDropDownCount := 8; +end; + +function TJvFullColorDialog.Execute: Boolean; +var + NewColor: TJvFullColor; +begin + FOldColorSpace := ColorSpaceManager.GetColorSpaceID(FullColor); + + FForm := TJvFullColorFrm.Create(Application, FFullColor, FOptions); + with TJvFullColorFrm(Form) do + begin + if Title <> '' then + Caption := FTitle; + DropdownCount := FDropDownCount; + OnApply := @FormApply; + OnClose := @FormClose; + OnShow := @FormShow; + HelpContext := Self.HelpContext; + Result := (ShowModal = mrOk); + NewColor := FullColor; + end; + FreeAndNil(FForm); + + with ColorSpaceManager do + if foConvertToOriginalSpace in Options then + NewColor := ConvertToID(NewColor, OldColorSpace); + FFullColor := NewColor; +end; + +procedure TJvFullColorDialog.FormApply(Sender: TObject); +var + lColor: TJvFullColor; +begin + if Assigned(FForm) then + begin + lColor := TJvFullColorFrm(Form).FullColor; + if foConvertToOriginalSpace in Options then + lColor := ColorSpaceManager.ConvertToID(lColor, OldColorSpace); + if Assigned(FOnApply) then + FOnApply(Self, lColor); + end; +end; + +procedure TJvFullColorDialog.FormClose(Sender: TObject; + var CloseAction: TCloseAction); +var + Allow: Boolean; +begin + Allow := True; + + if Assigned(FOnCloseQuery) then + FOnCloseQuery(Self, Allow); + + if Allow then + CloseAction := caFree + else + CloseAction := caNone; +end; + +procedure TJvFullColorDialog.FormShow(Sender: TObject); +begin + if Assigned(FOnShow) then + FOnShow(Self); +end; + +function TJvFullColorDialog.GetColor: TColor; +begin + Result := ColorSpaceManager.ConvertToColor(FullColor); +end; + +function TJvFullColorDialog.GetFullColor: TJvFullColor; +begin + if Form <> nil then + FFullColor := TJvFullColorFrm(Form).FullColor; + Result := FFullColor; +end; + +procedure TJvFullColorDialog.SetFullColor(const Value: TJvFullColor); +begin + FFullColor := Value; + if Form <> nil then + TJvFullColorFrm(Form).FullColor := Value; +end; + +procedure TJvFullColorDialog.SetHelpContext(const Value: THelpContext); +begin + if FHelpContext <> Value then + begin + FHelpContext := Value; + if Assigned(FForm) then + Form.HelpContext := Value; + end; +end; + +procedure TJvFullColorDialog.SetOptions(const Value: TJvFullColorDialogOptions); +begin + if FOptions <> Value then + begin + FOptions := Value; + if Assigned(FForm) then + TJvFullColorFrm(Form).Options := Value; + end; +end; + +procedure TJvFullColorDialog.SetTitle(const Value: string); +begin + if FTitle <> Value then + begin + FTitle := Value; + if Assigned(FForm) then + Form.Caption := Value; + end; +end; + +//=== { TJvColorCircleDialog } =============================================== + +constructor TJvFullColorCircleDialog.Create(AOwner: TComponent); + procedure InitAxe (Value: TJvAxisDelta); + var + Index: TJvAxisIndex; + begin + for Index := Low(TJvAxisIndex) to High(TJvAxisIndex) do + begin + Value[Index].Value := 0; + Value[Index].SaturationMethod := smLoop; + end; + end; +begin + inherited Create(AOwner); + FOptions := JvDefaultColorCircleDialogOptions; + FDelta := TJvColorDelta.Create; + FDropdownCount := 8; + + InitAxe(FDelta.AxisRed); + InitAxe(FDelta.AxisGreen); + InitAxe(FDelta.AxisBlue); + FDelta.ColorID := csRGB; +end; + +destructor TJvFullColorCircleDialog.Destroy; +begin + FDelta.Free; + + inherited; +end; + +function TJvFullColorCircleDialog.Execute: Boolean; +begin + FForm := TJvFullColorCircleFrm.Create(Application); + with TJvFullColorCircleFrm(Form) do + begin + if Title <> '' then + Caption := Title; + DropdownCount := FDropdownCount; + Options := Self.Options; + Delta := Self.Delta; + OnApply := @FormApply; + OnClose := @FormClose; + OnShow := @FormShow; + HelpContext := Self.HelpContext; + + Result := (ShowModal = mrOk); + + Self.FDelta.AxisRed.Assign(RedDelta); + Self.FDelta.AxisGreen.Assign(GreenDelta); + Self.FDelta.AxisBlue.Assign(BlueDelta); + Self.FDelta.ColorID := ColorID; + end; + FreeAndNil(FForm); +end; + +procedure TJvFullColorCircleDialog.FormApply(Sender: TObject); +begin + if FForm<>nil then + begin + FDelta.ColorID := TJvFullColorCircleFrm(FForm).ColorID; + FDelta.AxisRed := TJvFullColorCircleFrm(FForm).RedDelta; + FDelta.AxisGreen := TJvFullColorCircleFrm(FForm).GreenDelta; + FDelta.AxisBlue := TJvFullColorCircleFrm(FForm).BlueDelta; + if Assigned(FOnApply) then + FOnApply(Self); + end; +end; + +procedure TJvFullColorCircleDialog.FormClose(Sender: TObject; var Action: TCloseAction); +var + Allow: Boolean; +begin + if FForm<>nil then + begin + FDelta.ColorID := TJvFullColorCircleFrm(FForm).ColorID; + FDelta.AxisRed := TJvFullColorCircleFrm(FForm).RedDelta; + FDelta.AxisGreen := TJvFullColorCircleFrm(FForm).GreenDelta; + FDelta.AxisBlue := TJvFullColorCircleFrm(FForm).BlueDelta; + Allow := True; + if Assigned(FOnCloseQuery) then + FOnCloseQuery(Self, Allow); + if Allow then + Action := caFree + else + Action := caNone; + end; +end; + +procedure TJvFullColorCircleDialog.FormShow(Sender: TObject); +begin + if FForm<>nil then + begin + FDelta.ColorID := TJvFullColorCircleFrm(FForm).ColorID; + FDelta.AxisRed := TJvFullColorCircleFrm(FForm).RedDelta; + FDelta.AxisGreen := TJvFullColorCircleFrm(FForm).GreenDelta; + FDelta.AxisBlue := TJvFullColorCircleFrm(FForm).BlueDelta; + if Assigned(FOnShow) then + FOnShow(Self); + end; +end; + +function TJvFullColorCircleDialog.GetBlueDelta: TJvAxisDelta; +begin + Result := FDelta.AxisBlue; +end; + +function TJvFullColorCircleDialog.GetColorID: TJvFullColorSpaceID; +begin + Result := FDelta.ColorID; +end; + +function TJvFullColorCircleDialog.GetGreenDelta: TJvAxisDelta; +begin + Result := FDelta.AxisGreen; +end; + +function TJvFullColorCircleDialog.GetRedDelta: TJvAxisDelta; +begin + Result := FDelta.AxisRed; +end; + +procedure TJvFullColorCircleDialog.SetBlueDelta(const Value: TJvAxisDelta); +begin + FDelta.AxisBlue.Assign(Value); + if FForm <> nil then + TJvFullColorCircleFrm(FForm).BlueDelta := Value; +end; + +procedure TJvFullColorCircleDialog.SetColorID( + const Value: TJvFullColorSpaceID); +begin + FDelta.ColorID := Value; + if FForm <> nil then + TJvFullColorCircleFrm(FForm).ColorID :=Value; +end; + +procedure TJvFullColorCircleDialog.SetGreenDelta( + const Value: TJvAxisDelta); +begin + FDelta.AxisGreen.Assign(Value); + if FForm <> nil then + TJvFullColorCircleFrm(FForm).GreenDelta := Value; +end; + +procedure TJvFullColorCircleDialog.SetHelpContext(const Value: THelpContext); +begin + FHelpContext := Value; + if FForm <> nil then + FForm.HelpContext := Value; +end; + +procedure TJvFullColorCircleDialog.SetOptions(const Value: TJvFullColorCircleDialogOptions); +begin + FOptions := Value; + if FForm <> nil then + TJvFullColorCircleFrm(FForm).Options := Value; +end; + +procedure TJvFullColorCircleDialog.SetRedDelta(const Value: TJvAxisDelta); +begin + FDelta.AxisRed.Assign(Value); + if FForm <> nil then + TJvFullColorCircleFrm(FForm).RedDelta := Value; +end; + +procedure TJvFullColorCircleDialog.SetTitle(const Value: string); +begin + FTitle := Value; + if FForm <> nil then + FForm.Caption := Value; +end; + + +end. diff --git a/components/jvcllaz/run/JvMM/jvfullcolorform.lfm b/components/jvcllaz/run/JvMM/jvfullcolorform.lfm new file mode 100644 index 000000000..31ed2b053 --- /dev/null +++ b/components/jvcllaz/run/JvMM/jvfullcolorform.lfm @@ -0,0 +1,464 @@ +object JvFullColorFrm: TJvFullColorFrm + Left = 373 + Height = 388 + Top = 274 + Width = 712 + ActiveControl = ColorBox + AutoSize = True + BorderIcons = [biSystemMenu] + BorderStyle = bsDialog + Caption = 'Color Spaces Editor, Choose your color' + ClientHeight = 388 + ClientWidth = 712 + Color = clBtnFace + Font.Color = clWindowText + KeyPreview = True + OnCreate = FormCreate + OnShow = FormShow + LCLVersion = '2.1.0.0' + object LabelColorSpace: TLabel + AnchorSideLeft.Control = JvColorSpaceCombo + AnchorSideTop.Control = Owner + Left = 12 + Height = 15 + Top = 8 + Width = 112 + BorderSpacing.Top = 8 + Caption = '&Current Color Space :' + ParentColor = False + end + object LabelDrawOld: TLabel + AnchorSideLeft.Side = asrBottom + AnchorSideTop.Control = JvColorSpaceCombo + AnchorSideRight.Control = LabelDrawNew + AnchorSideBottom.Control = JvColorSpaceCombo + AnchorSideBottom.Side = asrBottom + Left = 270 + Height = 23 + Top = 27 + Width = 61 + Anchors = [akTop, akRight, akBottom] + AutoSize = False + BorderSpacing.Left = 16 + Color = clBlack + ParentColor = False + Transparent = False + OnClick = LabelDrawOldClick + end + object LabelDrawNew: TLabel + AnchorSideLeft.Control = LabelDrawOld + AnchorSideLeft.Side = asrBottom + AnchorSideTop.Control = LabelDrawOld + AnchorSideRight.Control = GroupBoxSettings + AnchorSideRight.Side = asrBottom + AnchorSideBottom.Control = JvColorSpaceCombo + AnchorSideBottom.Side = asrBottom + Left = 331 + Height = 23 + Top = 27 + Width = 61 + Anchors = [akTop, akRight, akBottom] + AutoSize = False + Color = clWhite + ParentColor = False + Transparent = False + end + object LabelOld: TLabel + AnchorSideLeft.Control = LabelDrawOld + AnchorSideTop.Control = LabelColorSpace + Left = 270 + Height = 15 + Top = 8 + Width = 22 + Caption = 'Old:' + ParentColor = False + end + object LabelNew: TLabel + AnchorSideLeft.Control = LabelDrawNew + AnchorSideTop.Control = LabelColorSpace + Left = 331 + Height = 15 + Top = 8 + Width = 27 + Caption = 'New:' + ParentColor = False + end + object GroupBoxSettings: TGroupBox + AnchorSideLeft.Control = JvColorSpaceCombo + AnchorSideTop.Control = JvColorSpaceCombo + AnchorSideTop.Side = asrBottom + AnchorSideRight.Side = asrBottom + Left = 12 + Height = 246 + Top = 62 + Width = 380 + BorderSpacing.Top = 12 + BorderSpacing.Right = 16 + Caption = ' Settings ... ' + ClientHeight = 226 + ClientWidth = 376 + TabOrder = 1 + object LabelAxis0: TLabel + AnchorSideLeft.Control = GroupBoxSettings + AnchorSideTop.Control = GroupBoxSettings + Left = 16 + Height = 15 + Top = 4 + Width = 55 + Alignment = taRightJustify + BorderSpacing.Left = 16 + BorderSpacing.Top = 4 + Caption = 'LabelAxis0' + ParentColor = False + end + object LabelAxis1: TLabel + AnchorSideLeft.Control = LabelAxis0 + AnchorSideTop.Control = ScrollBarAxis0 + AnchorSideTop.Side = asrBottom + Left = 16 + Height = 15 + Top = 59 + Width = 55 + Alignment = taRightJustify + BorderSpacing.Top = 16 + Caption = 'LabelAxis1' + ParentColor = False + end + object LabelAxis2: TLabel + AnchorSideLeft.Control = LabelAxis0 + AnchorSideTop.Control = ScrollBarAxis1 + AnchorSideTop.Side = asrBottom + Left = 16 + Height = 15 + Top = 114 + Width = 55 + Alignment = taRightJustify + BorderSpacing.Top = 16 + Caption = 'LabelAxis2' + ParentColor = False + end + object LabelPredefined: TLabel + AnchorSideLeft.Control = ColorBox + AnchorSideTop.Control = ScrollBarAxis2 + AnchorSideTop.Side = asrBottom + Left = 88 + Height = 15 + Top = 169 + Width = 95 + Alignment = taRightJustify + Caption = '&Predefined colors:' + FocusControl = ColorBox + ParentColor = False + end + object ScrollBarAxis0: TScrollBar + AnchorSideLeft.Control = LabelAxis0 + AnchorSideTop.Control = LabelAxis0 + AnchorSideTop.Side = asrBottom + AnchorSideRight.Control = SpinEditAxis0 + Left = 16 + Height = 20 + Top = 23 + Width = 268 + Anchors = [akTop, akLeft, akRight] + BorderSpacing.Top = 4 + BorderSpacing.Right = 16 + LargeChange = 16 + Max = 255 + PageSize = 0 + TabOrder = 0 + OnChange = ScrollBarChange + end + object ScrollBarAxis1: TScrollBar + Tag = 1 + AnchorSideLeft.Control = LabelAxis1 + AnchorSideTop.Control = LabelAxis1 + AnchorSideTop.Side = asrBottom + AnchorSideRight.Control = ScrollBarAxis0 + AnchorSideRight.Side = asrBottom + Left = 16 + Height = 20 + Top = 78 + Width = 268 + Anchors = [akTop, akLeft, akRight] + BorderSpacing.Top = 4 + LargeChange = 16 + Max = 255 + PageSize = 0 + TabOrder = 2 + OnChange = ScrollBarChange + end + object ScrollBarAxis2: TScrollBar + Tag = 2 + AnchorSideLeft.Control = LabelAxis2 + AnchorSideTop.Control = LabelAxis2 + AnchorSideTop.Side = asrBottom + AnchorSideRight.Control = ScrollBarAxis1 + AnchorSideRight.Side = asrBottom + Left = 16 + Height = 20 + Top = 133 + Width = 268 + Anchors = [akTop, akLeft, akRight] + BorderSpacing.Top = 4 + BorderSpacing.Bottom = 16 + LargeChange = 16 + Max = 255 + PageSize = 0 + TabOrder = 4 + OnChange = ScrollBarChange + end + object SpinEditAxis0: TSpinEdit + AnchorSideTop.Control = ScrollBarAxis0 + AnchorSideTop.Side = asrCenter + AnchorSideRight.Control = GroupBoxSettings + AnchorSideRight.Side = asrBottom + Left = 300 + Height = 23 + Top = 22 + Width = 60 + Anchors = [akTop, akRight] + BorderSpacing.Right = 16 + MaxValue = 255 + OnChange = SpinEditChange + TabOrder = 1 + end + object SpinEditAxis1: TSpinEdit + Tag = 1 + AnchorSideLeft.Control = SpinEditAxis0 + AnchorSideTop.Control = ScrollBarAxis1 + AnchorSideTop.Side = asrCenter + AnchorSideRight.Control = SpinEditAxis0 + AnchorSideRight.Side = asrBottom + Left = 300 + Height = 23 + Top = 77 + Width = 60 + Anchors = [akTop, akLeft, akRight] + MaxValue = 255 + OnChange = SpinEditChange + TabOrder = 3 + end + object SpinEditAxis2: TSpinEdit + Tag = 2 + AnchorSideLeft.Control = SpinEditAxis1 + AnchorSideTop.Control = ScrollBarAxis2 + AnchorSideTop.Side = asrCenter + AnchorSideRight.Control = SpinEditAxis0 + AnchorSideRight.Side = asrBottom + Left = 300 + Height = 23 + Top = 132 + Width = 60 + Anchors = [akTop, akLeft, akRight] + MaxValue = 255 + OnChange = SpinEditChange + TabOrder = 5 + end + object ColorBox: TColorBox + AnchorSideLeft.Control = GroupBoxSettings + AnchorSideLeft.Side = asrCenter + AnchorSideTop.Control = LabelPredefined + AnchorSideTop.Side = asrBottom + Left = 88 + Height = 22 + Top = 188 + Width = 201 + Style = [cbStandardColors, cbExtendedColors, cbSystemColors, cbPrettyNames] + BorderSpacing.Top = 4 + BorderSpacing.Bottom = 16 + ItemHeight = 16 + OnSelect = ComboBoxPredefinedSelect + TabOrder = 6 + end + end + object JvFullColorGroup: TJvFullColorGroup + AnchorSideLeft.Control = GroupBoxSettings + AnchorSideLeft.Side = asrBottom + AnchorSideTop.Control = LabelColorSpace + AnchorSideRight.Control = Owner + AnchorSideRight.Side = asrBottom + AnchorSideBottom.Control = ButtonOK + AnchorSideBottom.Side = asrBottom + Left = 408 + Height = 341 + Top = 8 + Width = 296 + ColCount = 8 + SquareSize = 30 + OnChange = JvFullColorGroupChange + Anchors = [akTop, akLeft, akRight, akBottom] + BorderSpacing.Right = 8 + Constraints.MinWidth = 288 + ParentShowHint = False + ShowHint = True + end + object PanelGraphic: TPanel + AnchorSideLeft.Control = GroupBoxSettings + AnchorSideLeft.Side = asrBottom + AnchorSideTop.Control = LabelColorSpace + AnchorSideRight.Control = Owner + AnchorSideRight.Side = asrBottom + AnchorSideBottom.Control = ButtonOK + AnchorSideBottom.Side = asrBottom + Left = 408 + Height = 341 + Top = 8 + Width = 296 + Anchors = [akTop, akLeft, akRight, akBottom] + BorderSpacing.Right = 8 + BevelInner = bvRaised + BevelOuter = bvLowered + ClientHeight = 341 + ClientWidth = 296 + TabOrder = 2 + Visible = False + object LabelAxis: TLabel + AnchorSideLeft.Control = PanelGraphic + AnchorSideTop.Control = JvColorAxisConfigCombo + AnchorSideTop.Side = asrCenter + Left = 10 + Height = 15 + Top = 14 + Width = 24 + BorderSpacing.Left = 8 + Caption = '&Axis:' + ParentColor = False + end + object JvColorPanel: TJvFullColorPanel + AnchorSideLeft.Control = PanelGraphic + AnchorSideTop.Control = JvColorAxisConfigCombo + AnchorSideTop.Side = asrBottom + AnchorSideRight.Control = PanelGraphic + AnchorSideRight.Side = asrBottom + AnchorSideBottom.Control = JvFullColorTrackBar + Left = 10 + Height = 263 + Top = 37 + Width = 268 + Anchors = [akTop, akLeft, akBottom] + BorderSpacing.Left = 8 + BorderSpacing.Top = 4 + BorderSpacing.Right = 8 + BorderSpacing.Bottom = 4 + FullColor = 83886079 + TabOrder = 1 + OnColorChange = JvColorPanelColorChange + CrossSize = 10 + CrossCenter = 3 + CrossStyle.Width = 3 + ColorTrackBar = JvFullColorTrackBar + end + object JvFullColorTrackBar: TJvFullColorTrackBar + AnchorSideLeft.Control = JvColorPanel + AnchorSideRight.Control = JvColorPanel + AnchorSideRight.Side = asrBottom + AnchorSideBottom.Control = PanelGraphic + AnchorSideBottom.Side = asrBottom + Left = 10 + Height = 27 + Top = 304 + Width = 268 + BorderSpacing.Bottom = 8 + FullColor = 83886079 + TabOrder = 2 + ArrowWidth = 8 + end + object JvColorAxisConfigCombo: TJvFullColorAxisCombo + AnchorSideLeft.Control = LabelAxis + AnchorSideLeft.Side = asrBottom + AnchorSideTop.Control = PanelGraphic + AnchorSideRight.Control = PanelGraphic + AnchorSideRight.Side = asrBottom + Left = 42 + Height = 23 + Top = 10 + Width = 244 + Selected = acXYZ + Anchors = [akTop, akLeft, akRight] + BorderSpacing.Left = 8 + BorderSpacing.Top = 8 + BorderSpacing.Right = 8 + ItemHeight = 15 + TabOrder = 0 + OnChange = ComboBoxAxisChange + end + end + object ButtonGraphics: TButton + AnchorSideLeft.Side = asrBottom + AnchorSideTop.Control = ButtonOK + AnchorSideRight.Control = GroupBoxSettings + AnchorSideRight.Side = asrBottom + Left = 284 + Height = 25 + Top = 324 + Width = 108 + Anchors = [akTop, akRight] + AutoSize = True + Caption = 'ButtonGraphics' + Constraints.MinWidth = 75 + OnClick = ButtonGraphicsClick + TabOrder = 6 + end + object ButtonOK: TButton + AnchorSideLeft.Control = GroupBoxSettings + AnchorSideTop.Control = GroupBoxSettings + AnchorSideTop.Side = asrBottom + Left = 12 + Height = 25 + Top = 324 + Width = 75 + AutoSize = True + BorderSpacing.Top = 16 + BorderSpacing.Bottom = 8 + Caption = '&OK' + Constraints.MinWidth = 75 + Default = True + ModalResult = 1 + TabOrder = 3 + end + object ButtonCancel: TButton + AnchorSideLeft.Control = ButtonOK + AnchorSideLeft.Side = asrBottom + AnchorSideTop.Control = ButtonOK + Left = 95 + Height = 25 + Top = 324 + Width = 75 + BorderSpacing.Left = 8 + Cancel = True + Caption = 'Ca&ncel' + ModalResult = 2 + TabOrder = 4 + end + object ButtonApply: TButton + AnchorSideLeft.Control = ButtonCancel + AnchorSideLeft.Side = asrBottom + AnchorSideTop.Control = ButtonOK + Left = 178 + Height = 25 + Top = 324 + Width = 75 + AutoSize = True + BorderSpacing.Left = 8 + Caption = '&Apply' + Constraints.MinWidth = 75 + OnClick = ButtonApplyClick + TabOrder = 5 + end + object JvColorSpaceCombo: TJvFullColorSpaceCombo + AnchorSideLeft.Control = Owner + AnchorSideTop.Control = LabelColorSpace + AnchorSideTop.Side = asrBottom + AnchorSideRight.Side = asrBottom + Left = 12 + Height = 23 + Top = 27 + Width = 244 + BorderSpacing.Left = 12 + BorderSpacing.Top = 4 + Constraints.MinWidth = 210 + ItemHeight = 15 + TabOrder = 0 + OnSelect = JvComboBoxColorSpaceSelect + end +end diff --git a/components/jvcllaz/run/JvMM/jvfullcolorform.pas b/components/jvcllaz/run/JvMM/jvfullcolorform.pas new file mode 100644 index 000000000..5a9564a08 --- /dev/null +++ b/components/jvcllaz/run/JvMM/jvfullcolorform.pas @@ -0,0 +1,506 @@ +{----------------------------------------------------------------------------- +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: FullColorFrm.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 JvFullColorForm; + +{$mode objfpc}{$H+} + +interface + +uses + //Windows, Messages, + SysUtils, Classes, Controls, Forms, Graphics, + Dialogs, StdCtrls, ExtCtrls, Spin, //Mask, + ColorBox, // JvColorCombo + JvFullColorCtrls, JvFullColorSpaces, JvFullColorDialogs; + +//JvExMask, +//JvSpin, JvExStdCtrls, JvCombobox, JvColorCombo, JvComponent; + +type + + { TJvFullColorFrm } + + TJvFullColorFrm = class(TForm) //TJvForm) + LabelColorSpace: TLabel; + GroupBoxSettings: TGroupBox; + ScrollBarAxis0: TScrollBar; + ScrollBarAxis1: TScrollBar; + ScrollBarAxis2: TScrollBar; + SpinEditAxis0: TSpinEdit; //TJvSpinEdit; + SpinEditAxis1: TSpinEdit; //TJvSpinEdit; + SpinEditAxis2: TSpinEdit; //TJvSpinEdit; + LabelAxis0: TLabel; + LabelAxis1: TLabel; + LabelAxis2: TLabel; + LabelPredefined: TLabel; + PanelGraphic: TPanel; + JvColorPanel: TJvFullColorPanel; + JvFullColorTrackBar: TJvFullColorTrackBar; + ButtonGraphics: TButton; + ButtonOK: TButton; + ButtonCancel: TButton; + LabelDrawOld: TLabel; + LabelDrawNew: TLabel; + LabelOld: TLabel; + LabelNew: TLabel; + LabelAxis: TLabel; + ButtonApply: TButton; + JvColorAxisConfigCombo: TJvFullColorAxisCombo; + JvColorSpaceCombo: TJvFullColorSpaceCombo; + ColorBox: TColorBox; //TJvColorComboBox; + JvFullColorGroup: TJvFullColorGroup; + procedure ButtonApplyClick(Sender: TObject); + procedure ButtonGraphicsClick(Sender: TObject); + procedure ComboBoxAxisChange(Sender: TObject); + procedure ComboBoxPredefinedSelect(Sender: TObject); + procedure FormCreate(Sender: TObject); + procedure FormShow(Sender: TObject); + procedure JvColorPanelColorChange(Sender: TObject); + procedure JvComboBoxColorSpaceSelect(Sender: TObject); + procedure JvFullColorGroupChange(Sender: TObject); + procedure LabelDrawOldClick(Sender: TObject); + procedure ScrollBarChange(Sender: TObject); + procedure SpinEditChange(Sender: TObject); + private + FUpdating: Boolean; + FExpanded: Boolean; + FExpandedWidth: Integer; + FFullColor: TJvFullColor; + FOptions: TJvFullColorDialogOptions; + FOnApply: TNotifyEvent; + FScrollBarAxes: array [TJvAxisIndex] of TScrollBar; + FSpinEditAxes: array [TJvAxisIndex] of TSpinEdit; //TJvSpinEdit; + FLabelAxes: array [TJvAxisIndex] of TLabel; + FFilled: Boolean; + procedure FillInternalArrays; + function GetDropdownCount: Integer; + procedure SetDropdownCount(AValue: Integer); + protected + procedure UpdateColorValue; + procedure UpdateColorSpace; + procedure SetFullColor(const Value: TJvFullColor); + procedure SetOptions(const Value: TJvFullColorDialogOptions); + procedure Loaded; override; + property Expanded: Boolean read FExpanded; + public + constructor Create(AOwner: TComponent; AFullColor: TJvFullColor; + AOptions: TJvFullColorDialogOptions); reintroduce; + procedure Expand; + procedure Collapse; + property DropdownCount: Integer read GetDropDownCount write SetDropDownCount default 8; + property Options: TJvFullColorDialogOptions read FOptions write SetOptions; + property FullColor: TJvFullColor read FFullColor write SetFullColor; + property OnApply: TNotifyEvent read FOnApply write FOnApply; + end; + + +implementation + +uses + JvResources; + +{$R *.lfm} + +function AxisIndexFromTag(ATag: Integer): TJvAxisIndex; +begin + Result := TJvAxisIndex(ATag and $03); +end; + +constructor TJvFullColorFrm.Create(AOwner: TComponent; + AFullColor: TJvFullColor; AOptions: TJvFullColorDialogOptions); +begin + inherited Create(AOwner); + FOptions := AOptions; + FFullColor := AFullColor; +end; + +procedure TJvFullColorFrm.FormCreate(Sender: TObject); +var + CS: TJvDEFColorSpace; + Index:Integer; +begin + with ColorSpaceManager do + begin + CS := TJvDEFColorSpace(ColorSpace[csDEF]); + for Index := 0 to CS.ColorCount - 1 do + JvFullColorGroup.Items.Add(CS.ConvertFromColor(CS.ColorValue[Index])); + LabelDrawOld.Color := ConvertToColor(FullColor); + JvColorSpaceCombo.ColorSpaceID := GetColorSpaceID(FullColor); + end; + SetFullColor(FullColor); + SetOptions(Options); +end; + +procedure TJvFullColorFrm.FormShow(Sender: TObject); +begin + Position := poScreenCenter; +end; + +procedure TJvFullColorFrm.Loaded; +begin + inherited Loaded; + FExpandedWidth := Width; +end; + +procedure TJvFullColorFrm.FillInternalArrays; +begin + if not FFilled then + begin + FScrollBarAxes[axIndex0] := ScrollBarAxis0; + FScrollBarAxes[axIndex1] := ScrollBarAxis1; + FScrollBarAxes[axIndex2] := ScrollBarAxis2; + FSpinEditAxes[axIndex0] := SpinEditAxis0; + FSpinEditAxes[axIndex1] := SpinEditAxis1; + FSpinEditAxes[axIndex2] := SpinEditAxis2; + FLabelAxes[axIndex0] := LabelAxis0; + FLabelAxes[axIndex1] := LabelAxis1; + FLabelAxes[axIndex2] := LabelAxis2; + FFilled := True; + end; +end; + +procedure TJvFullColorFrm.ButtonGraphicsClick(Sender: TObject); +begin + if Expanded then + Collapse + else + Expand; +end; + +procedure TJvFullColorFrm.Collapse; +begin + Width := PanelGraphic.Left - 1; + PanelGraphic.Visible := False; + ButtonGraphics.Caption := RsCollapsedCaption; + FExpanded := False; +end; + +procedure TJvFullColorFrm.Expand; +begin + PanelGraphic.Visible := True; + Width := FExpandedWidth; + ButtonGraphics.Caption := RsExpandedCaption; + FExpanded := True; +end; + +function TJvFullColorFrm.GetDropDownCount: Integer; +begin + Result := JvColorSpaceCombo.DropdownCount; +end; + +procedure TJvFullColorFrm.SetDropdownCount(AValue: Integer); +begin + JvColorSpaceCombo.DropDownCount := AValue; + JvColorAxisConfigCombo.DropDownCount := AValue; + ColorBox.DropDownCount := AValue; +end; + +procedure TJvFullColorFrm.SpinEditChange(Sender: TObject); +var + IntValue:Integer; +begin + if FUpdating then + Exit; + FUpdating := True; + +// with Sender as TJvSpinEdit do + with Sender as TSpinEdit do + if TryStrToInt(Text,IntValue) then + FullColor := SetAxisValue(FullColor, AxisIndexFromTag(Tag), IntValue); + + FUpdating := False; + UpdateColorValue; +end; + +procedure TJvFullColorFrm.ScrollBarChange(Sender: TObject); +begin + if FUpdating then + Exit; + FUpdating := True; + with Sender as TScrollBar do + FullColor := SetAxisValue(FullColor, AxisIndexFromTag(Tag), Position); + FUpdating := False; + UpdateColorValue; +end; + +procedure TJvFullColorFrm.JvColorPanelColorChange(Sender: TObject); +begin + if FUpdating then + Exit; + FUpdating := True; + FullColor := (Sender as TJvFullColorPanel).FullColor; + FUpdating := False; + UpdateColorValue; +end; + +procedure TJvFullColorFrm.JvFullColorGroupChange(Sender: TObject); +begin + if FUpdating then + Exit; + + FUpdating := True; + with (Sender as TJvFullColorGroup), ColorSpaceManager do + if (SelectedIndex>-1) then + begin + JvColorSpaceCombo.ColorSpaceID := GetColorSpaceID(Selected); + FullColor := Selected; + end; + FUpdating := False; + + UpdateColorSpace; +end; + +procedure TJvFullColorFrm.JvComboBoxColorSpaceSelect(Sender: TObject); +begin + if FUpdating then + Exit; + FUpdating := True; + with Sender as TJvFullColorSpaceCombo do + FullColor := ColorSpaceManager.ConvertToID(FullColor, ColorSpaceID); + FUpdating := False; + UpdateColorSpace; +end; + +procedure TJvFullColorFrm.ComboBoxPredefinedSelect(Sender: TObject); +begin + if FUpdating then + Exit; + FUpdating := True; +// with Sender as TJvColorComboBox, ColorSpaceManager do + with Sender as TColorBox, ColorSpaceManager do + FullColor := ConvertToID(ConvertFromColor(Colors[ItemIndex]), + GetColorSpaceID(FullColor)); + FUpdating := False; + UpdateColorSpace; +end; + +procedure TJvFullColorFrm.ComboBoxAxisChange(Sender: TObject); +begin + JvColorPanel.AxisConfig := (Sender as TJvFullColorAxisCombo).Selected; +end; + +procedure TJvFullColorFrm.UpdateColorValue; +var + I: TJvAxisIndex; + C: TColor; + NewIndex: Integer; + ValueAxes: array [TJvAxisIndex] of Byte; + J: Integer; + LColorID: TJvFullColorSpaceID; + DefColorSpace: TJvColorSpace; +begin + if FUpdating then + Exit; + FillInternalArrays; + + FUpdating := True; + + LabelDrawNew.Color := ColorSpaceManager.ConvertToColor(FullColor); + LabelDrawNew.Update; + + LColorID := ColorSpaceManager.GetColorSpaceID(FullColor); + + if (LColorID=csDEF) then + begin + JvFullColorGroup.Selected := FullColor; + for I := Low(TJvAxisIndex) to High(TJvAxisIndex) do + begin + FScrollBarAxes[I].Enabled := False; + FScrollBarAxes[I].Position := 0; + FSpinEditAxes[I].Enabled := False; + FSpinEditAxes[I].Value := 0; + end; + end + else + begin + JvColorPanel.FullColor := FullColor; + for I := Low(TJvAxisIndex) to High(TJvAxisIndex) do + begin + FScrollBarAxes[I].Enabled := True; + FSpinEditAxes[I].Enabled := True; + ValueAxes[I] := GetAxisValue(FullColor, I); + FScrollBarAxes[I].Position := ValueAxes[I]; + FSpinEditAxes[I].Value := ValueAxes[I]; + end; + end; + + JvColorSpaceCombo.ColorSpaceID := LColorID; + + NewIndex := -1; + DefColorSpace := ColorSpaceManager.ColorSpace[csDEF]; + with ColorBox, Items, ColorSpaceManager do + begin + for J := 0 to Items.Count - 1 do + begin + C := DefColorSpace.ConvertFromColor(Colors[J]); + if ConvertToID(C, LColorID) = FullColor then + begin + NewIndex := J; + Break; + end; + end; + ItemIndex := NewIndex; + end; + + FUpdating := False; +end; + +procedure TJvFullColorFrm.UpdateColorSpace; +var + I: TJvAxisIndex; + AxisMin, AxisMax: Byte; + lColorSpace: TJvColorSpace; +begin + if FUpdating then + Exit; + FillInternalArrays; + FUpdating := True; + LColorSpace := JvColorSpaceCombo.SelectedSpace; + + AutoSize := false; + if Assigned(LColorSpace) then + begin + if (LColorSpace.ID = csDEF) then + begin + PanelGraphic.Visible := False; + JvFullColorGroup.Visible := Expanded; + for I := Low(TJvAxisIndex) to High(TJvAxisIndex) do + begin + FScrollBarAxes[I].Enabled := False; + FScrollBarAxes[I].Position := 0; + FSpinEditAxes[I].Enabled := False; + FSpinEditAxes[I].Value := 0; + end; + end + else + begin + PanelGraphic.Visible := Expanded; + JvFullColorGroup.Visible := False; + JvColorAxisConfigCombo.ColorID := LColorSpace.ID; + for I := Low(TJvAxisIndex) to High(TJvAxisIndex) do + begin + FLabelAxes[I].Caption := LColorSpace.AxisName[I]; + AxisMin := LColorSpace.AxisMin[I]; + AxisMax := LColorSpace.AxisMax[I]; + FScrollBarAxes[I].Min := AxisMin; + FScrollBarAxes[I].Max := AxisMax; + FSpinEditAxes[I].MinValue := AxisMin; + FSpinEditAxes[I].MaxValue := AxisMax; + end; + + JvColorPanel.FullColor := FullColor; + JvFullColorTrackBar.FullColor := FullColor; + end; + end; + + FUpdating := False; + UpdateColorValue; + AutoSize := true; +end; + +procedure TJvFullColorFrm.ButtonApplyClick(Sender: TObject); +begin + if Assigned(OnApply) then + OnApply(Sender); +end; + +procedure TJvFullColorFrm.SetFullColor(const Value: TJvFullColor); +begin + FFullColor := Value; + if not FUpdating then + begin + with ColorSpaceManager do + JvColorSpaceCombo.ColorSpaceID := GetColorSpaceID(Value); + UpdateColorSpace; + end; +end; + +procedure TJvFullColorFrm.SetOptions(const Value: TJvFullColorDialogOptions); +var + LVisible: Boolean; + LColor: TColor; +begin + FOptions := Value; + + if foFullOpen in Options then + Expand + else + Collapse; + + ButtonGraphics.Enabled := not (foPreventExpand in Options); + + ButtonApply.Visible := (foShowApply in Options); + + if foShowHelp in Options then + BorderIcons := BorderIcons + [biHelp] + else + BorderIcons := BorderIcons - [biHelp]; + + JvColorSpaceCombo.Enabled := foAllowSpaceChange in Options; + + LVisible := foShowOldPreview in Options; + LabelDrawOld.Visible := LVisible; + LabelOld.Visible := LVisible; + + LVisible := foShowNewPreview in Options; + LabelDrawNew.Visible := LVisible; + LabelNew.Visible := LVisible; + + LVisible := foShowPredefined in Options; + ColorBox.Visible := LVisible; + LabelPredefined.Visible := LVisible; + + JvColorSpaceCombo.AllowVariable := foAllowVariable in Options; + if foAllowVariable in Options then + // ColorBox.Options := ColorBox.Options + [coSysColors] + ColorBox.Style := ColorBox.style + [cbSystemColors] + else + // ColorBox.Options := ColorBox.Options - [coSysColors]; + ColorBox.Style := ColorBox.Style - [cbSystemColors]; + +{ if foNoneAndDefault in Options then + ColorBox.Style := ColorBox.Style + [cbIncludeNone, cbIncludeDefault] + else + ColorBox.Style := ColorBox.Style - [cbIncludeNone, cbIncludeDefault];} + + UpdateColorSpace; + + LColor := ColorSpaceManager.ConvertToColor(FullColor); + + LabelDrawNew.Color := LColor; + LabelDrawOld.Color := LColor; +end; + +procedure TJvFullColorFrm.LabelDrawOldClick(Sender: TObject); +begin + with ColorSpaceManager do + FullColor := ConvertToID( + ConvertFromColor(LabelDrawOld.Color), + GetColorSpaceID(FullColor) + ); +end; + +end. diff --git a/components/jvcllaz/run/JvMM/jvfullcolorrotate.pas b/components/jvcllaz/run/JvMM/jvfullcolorrotate.pas new file mode 100644 index 000000000..6aedbc606 --- /dev/null +++ b/components/jvcllaz/run/JvMM/jvfullcolorrotate.pas @@ -0,0 +1,385 @@ +{----------------------------------------------------------------------------- +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: ColorRotate.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 JvFullColorRotate; + +{$mode objfpc}{$H+} + +interface + +uses + //Windows, + Classes, Graphics, + JvFullColorSpaces; + +type + TJvRotateColor = (rcCommon, rcRed, rcGreen, rcBlue); + + TJvSaturationMethod = (smRange, smLoop); + + TJvRotateValueType = -255..255; + + TJvRotateValue = class(TPersistent) + private + FValue: TJvRotateValueType; + FSaturationMethod: TJvSaturationMethod; + public + constructor Create; reintroduce; + property Value: TJvRotateValueType read FValue write FValue default 0; + property SaturationMethod: TJvSaturationMethod read FSaturationMethod write FSaturationMethod default smRange; + procedure Assign(AValue: TJvRotateValue); reintroduce; + end; + + TJvAxisDelta = class(TPersistent) + private + FConstituents: array [TJvAxisIndex] of TJvRotateValue; + function GetConstituents(Index: TJvAxisIndex): TJvRotateValue; + procedure SetConstituents(Index: TJvAxisIndex; const Value: TJvRotateValue); + public + constructor Create; + destructor Destroy; override; + procedure Assign(Value: TJvAxisDelta); reintroduce; + property Constituents[Index: TJvAxisIndex]: TJvRotateValue read GetConstituents write SetConstituents; default; + end; + + TJvColorDelta = class(TPersistent) + private + FColorID: TJvFullColorSpaceID; + FAxisRed: TJvAxisDelta; + FAxisGreen: TJvAxisDelta; + FAxisBlue: TJvAxisDelta; + procedure SetAxisBlue(const Value: TJvAxisDelta); + procedure SetAxisGreen(const Value: TJvAxisDelta); + procedure SetAxisRed(const Value: TJvAxisDelta); + public + constructor Create; + destructor Destroy; override; + procedure Assign(Value: TJvColorDelta); reintroduce; + property ColorID: TJvFullColorSpaceID read FColorID write FColorID default csRGB; + property AxisRed: TJvAxisDelta read FAxisRed write SetAxisRed; + property AxisGreen: TJvAxisDelta read FAxisGreen write SetAxisGreen; + property AxisBlue: TJvAxisDelta read FAxisBlue write SetAxisBlue; + end; + +function RotateColor(AColor: TJvFullColor; AColorDelta: TJvColorDelta): TJvFullColor; +procedure RotateBitmap(SourceBitmap, DestBitmap: TBitmap; AColorDelta: TJvColorDelta); + + +implementation + +uses + JvTypes; + +function RotateColor(AColor: TJvFullColor; AColorDelta: TJvColorDelta): TJvFullColor; +var + I: TJvAxisIndex; + MinAxis: array [TJvAxisIndex] of Byte; + MaxAxis: array [TJvAxisIndex] of Byte; + ValueAxis: array [TJvAxisIndex] of SmallInt; + ColorRed, ColorGreen, ColorBlue: TColor; + MaxColorAxis:Integer; + SourceColorSpace, DeltaColorSpace: TJvColorSpace; + LColor: TColor; + + function DoRotate(AValue: TJvFullColor; AAxisDelta: TJvAxisDelta): TColor; + var + I: TJvAxisIndex; + Range: Integer; + begin + for I := Low(TJvAxisIndex) to High(TJvAxisIndex) do + begin + ValueAxis[I] := Integer(GetAxisValue(AValue, I)) + AAxisDelta[I].Value; + if AAxisDelta[I].SaturationMethod = smRange then + begin + if ValueAxis[I] > MaxAxis[I] then + ValueAxis[I] := MaxAxis[I]; + if ValueAxis[I] < MinAxis[I] then + ValueAxis[I] := MinAxis[I]; + end + else + begin + Range := MaxAxis[I] - MinAxis[I] + 1; + while ValueAxis[I] < MinAxis[I] do + Inc(ValueAxis[I], Range); + while ValueAxis[I] > MaxAxis[I] do + Dec(ValueAxis[I], Range); + end; + end; + Result := + (ValueAxis[axIndex0]) or (ValueAxis[axIndex1] shl 8) or (ValueAxis[axIndex2] shl 16); + end; + +begin + with ColorSpaceManager do + begin + SourceColorSpace := ColorSpace[GetColorSpaceID(AColor)]; + LColor := SourceColorSpace.ConvertToColor(AColor); + DeltaColorSpace := ColorSpace[AColorDelta.ColorID]; + + with DeltaColorSpace do + begin + for I := Low(TJvAxisIndex) to High(TJvAxisIndex) do + begin + MinAxis[I] := AxisMin[I]; + MaxAxis[I] := AxisMax[I]; + end; + ColorRed := ConvertToColor(DoRotate(ConvertFromColor(LColor and $000000FF), AColorDelta.AxisRed)); + ColorGreen := ConvertToColor(DoRotate(ConvertFromColor(LColor and $0000FF00), AColorDelta.AxisGreen)); + ColorBlue := ConvertToColor(DoRotate(ConvertFromColor(LColor and $00FF0000), AColorDelta.AxisBlue)); + + MaxColorAxis := 255; + for I := Low(TJvAxisIndex) to High(TJvAxisIndex) do + begin + ValueAxis[I] := (ColorRed and $FF) + (ColorGreen and $FF) + (ColorBlue and $FF); + if ValueAxis[I] > MaxColorAxis then + MaxColorAxis := ValueAxis[I]; + ColorRed := ColorRed shr 8; + ColorGreen := ColorGreen shr 8; + ColorBlue := ColorBlue shr 8; + end; + + for I := Low(TJvAxisIndex) to High(TJvAxisIndex) do + begin + ValueAxis[I] := ValueAxis[I] + 255 - MaxColorAxis; + if ValueAxis[I] < 0 then + ValueAxis[I] := 0; + end; + LColor := ValueAxis[axIndex0] or (ValueAxis[axIndex1] shl 8) or (ValueAxis[axIndex2] shl 16); + end; + Result := SourceColorSpace.ConvertFromColor(LColor); + end; +end; + +procedure RotateBitmap(SourceBitmap, DestBitmap: TBitmap; AColorDelta: TJvColorDelta); +type + TFullColorValue = array [TJvAxisIndex] of SmallInt; + PFullColorValue = ^TFullColorValue; +var + OriginalPixelFormat: TPixelFormat; + Colors: array [TJvAxisIndex,Byte] of TFullColorValue; + ColorR, ColorB, ColorG, ColorFusion: TFullColorValue; + I: TJvAxisIndex; + J: Byte; + X, Y: Integer; + MinAxis: array [TJvAxisIndex] of SmallInt; + MaxAxis: array [TJvAxisIndex] of SmallInt; + MaxColorAxis: SmallInt; + DeltaColorSpace: TJvColorSpace; + DestLine, SourceLine: PCardinal; + + procedure DoRotate(Color: TColor; AAxisDelta: TJvAxisDelta; out DestColor: TFullColorValue); + var + I: TJvAxisIndex; + Range: Integer; + FullColor: TJvFullColor; + ColorValue: TFullColorValue; + begin + FullColor := DeltaColorSpace.ConvertFromColor(Color); + for I := Low(TJvAxisIndex) to High(TJvAxisIndex) do + begin + ColorValue[I] := Integer(GetAxisValue(FullColor, I)) + AAxisDelta[I].Value; + if AAxisDelta[I].SaturationMethod = smRange then + begin + if ColorValue[I] > MaxAxis[I] then + ColorValue[I] := MaxAxis[I]; + if ColorValue[I] < MinAxis[I] then + ColorValue[I] := MinAxis[I]; + end + else + begin + Range := MaxAxis[I] - MinAxis[I] + 1; + while ColorValue[I] < MinAxis[I] do + Inc(ColorValue[I], Range); + while ColorValue[I] > MaxAxis[I] do + Dec(ColorValue[I], Range); + end; + end; + Color := DeltaColorSpace.ConvertToColor(ColorValue[axIndex0] or + (ColorValue[axIndex1] shl 8) or (ColorValue[axIndex2] shl 16)); + DestColor[axIndex0] := Color and $FF; + DestColor[axIndex1] := (Color shr 8) and $FF; + DestColor[axIndex2] := (Color shr 16) and $FF; + end; + +begin + DestBitmap.Width := SourceBitmap.Width; + DestBitmap.Height := SourceBitmap.Height; + OriginalPixelFormat := SourceBitmap.PixelFormat; + SourceBitmap.PixelFormat := pf32bit; + DestBitmap.PixelFormat := pf32bit; + with ColorSpaceManager do + begin + DeltaColorSpace := ColorSpace[AColorDelta.ColorID]; + with DeltaColorSpace do + begin + for I := Low(TJvAxisIndex) to High(TJvAxisIndex) do + begin + MinAxis[I] := AxisMin[I]; + MaxAxis[I] := AxisMax[I]; + end; + for J := Low(Byte) to High(Byte) do + begin + DoRotate(TColor(J),AColorDelta.AxisRed,Colors[axIndex0,J]); + DoRotate(TColor(J shl 8),AColorDelta.AxisGreen,Colors[axIndex1,J]); + DoRotate(TColor(J shl 16),AColorDelta.AxisBlue,Colors[axIndex2,J]); + end; + + for Y := 0 to DestBitmap.Height-1 do + begin + SourceLine := SourceBitmap.ScanLine[Y]; + DestLine := DestBitmap.ScanLine[Y]; + for X := 0 to DestBitmap.Width-1 do + begin + ColorR := Colors[axIndex0,(SourceLine^ shr 16) and $FF]; // + ColorG := Colors[axIndex1,(SourceLine^ shr 8) and $FF]; // Bitmap Color Format is + ColorB := Colors[axIndex2,(SourceLine^) and $FF]; // (MSB)0RGB(LSB) + ColorFusion[axIndex0] := ColorR[axIndex0] + ColorG[axIndex0] + ColorB[axIndex0]; + ColorFusion[axIndex1] := ColorR[axIndex1] + ColorG[axIndex1] + ColorB[axIndex1]; + ColorFusion[axIndex2] := ColorR[axIndex2] + ColorG[axIndex2] + ColorB[axIndex2]; + MaxColorAxis := 255; + if ColorFusion[axIndex0] > MaxColorAxis then + MaxColorAxis := ColorFusion[axIndex0]; + if ColorFusion[axIndex1] > MaxColorAxis then + MaxColorAxis := ColorFusion[axIndex1]; + if ColorFusion[axIndex2] > MaxColorAxis then + MaxColorAxis := ColorFusion[axIndex2]; + ColorFusion[axIndex0] := ColorFusion[axIndex0] + 255 - MaxColorAxis; + if ColorFusion[axIndex0] < 0 then + ColorFusion[axIndex0] := 0; + ColorFusion[axIndex1] := ColorFusion[axIndex1] + 255 - MaxColorAxis; + if ColorFusion[axIndex1] < 0 then + ColorFusion[axIndex1] := 0; + ColorFusion[axIndex2] := ColorFusion[axIndex2] + 255 - MaxColorAxis; + if ColorFusion[axIndex2] < 0 then + ColorFusion[axIndex2] := 0; + DestLine^ := // Bitmap Color Format is (MSB)0RGB(LSB) + (ColorFusion[axIndex0] shl 16) or (ColorFusion[axIndex1] shl 8) or (ColorFusion[axIndex2]); + Inc(SourceLine); + Inc(DestLine); + end; + end; + end; + end; + SourceBitmap.PixelFormat := OriginalPixelFormat; + DestBitmap.PixelFormat := OriginalPixelFormat; +end; + +//=== { TJvAxisDelta } ======================================================= + +constructor TJvAxisDelta.Create; +var + Index: TJvAxisIndex; +begin + inherited Create; + for Index := Low(TJvAxisIndex) to High(TJvAxisIndex) do + FConstituents[Index] := TJvRotateValue.Create; +end; + +destructor TJvAxisDelta.Destroy; +var + Index: TJvAxisIndex; +begin + for Index := Low(TJvAxisIndex) to High(TJvAxisIndex) do + FConstituents[Index].Free; + inherited Destroy; +end; + +procedure TJvAxisDelta.Assign(Value: TJvAxisDelta); +var + Index: TJvAxisIndex; +begin + for Index := Low(TJvAxisIndex) to High(TJvAxisIndex) do + FConstituents[Index].Assign(Value[Index]); +end; + +function TJvAxisDelta.GetConstituents(Index: TJvAxisIndex): TJvRotateValue; +begin + Result := FConstituents[Index]; +end; + +procedure TJvAxisDelta.SetConstituents(Index: TJvAxisIndex; + const Value: TJvRotateValue); +begin + FConstituents[Index].Assign(Value); +end; + +//=== { TJvColorDelta } ====================================================== + +constructor TJvColorDelta.Create; +begin + inherited Create; + FColorID := csRGB; + FAxisRed := TJvAxisDelta.Create; + FAxisGreen := TJvAxisDelta.Create; + FAxisBlue := TJvAxisDelta.Create; +end; + +destructor TJvColorDelta.Destroy; +begin + FAxisRed.Free; + FAxisGreen.Free; + FAxisBlue.Free; + inherited Destroy; +end; + +procedure TJvColorDelta.Assign(Value: TJvColorDelta); +begin + AxisRed.Assign(Value.AxisRed); + AxisGreen.Assign(Value.AxisGreen); + AxisBlue.Assign(Value.AxisBlue); + ColorID := Value.ColorID; +end; + +procedure TJvColorDelta.SetAxisBlue(const Value: TJvAxisDelta); +begin + FAxisBlue.Assign(Value); +end; + +procedure TJvColorDelta.SetAxisGreen(const Value: TJvAxisDelta); +begin + FAxisGreen.Assign(Value); +end; + +procedure TJvColorDelta.SetAxisRed(const Value: TJvAxisDelta); +begin + FAxisRed.Assign(Value); +end; + +//=== { TJvRotateValue } ===================================================== + +constructor TJvRotateValue.Create; +begin + FValue := 0; + FSaturationMethod := smLoop; +end; + +procedure TJvRotateValue.Assign(AValue: TJvRotateValue); +begin + FValue := AValue.Value; + FSaturationMethod := AValue.SaturationMethod; +end; + + +end. diff --git a/components/jvcllaz/run/JvMM/jvfullcolorspaces.pas b/components/jvcllaz/run/JvMM/jvfullcolorspaces.pas new file mode 100644 index 000000000..35278df27 --- /dev/null +++ b/components/jvcllaz/run/JvMM/jvfullcolorspaces.pas @@ -0,0 +1,1651 @@ +{----------------------------------------------------------------------------- +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: ColorSpaces.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$ + +// TColorBox is implemented in ExtCtrls in Delphi and BCB version 6 and + + +unit JvFullColorSpaces; + +{$mode objfpc}{$H+} + +interface + +uses + //Windows, + Classes, SysUtils, Graphics, + JvTypes; + +type + TJvAxisIndex = (axIndex0, axIndex1, axIndex2); + TJvFullColorSpaceID = type Byte; + TJvFullColor = type Cardinal; + +const + JvSystemColorMask = $80000000; + + JvSubFullColorMask = $03000000; + + JvSystemFullColorMask = $01000000; + JvSpecialFullColorMask = $03000000; + +const + csRGB = TJvFullColorSpaceID(1 shl 2); + csHLS = TJvFullColorSpaceID(2 shl 2); + csCMY = TJvFullColorSpaceID(3 shl 2); + csYUV = TJvFullColorSpaceID(4 shl 2); + csHSV = TJvFullColorSpaceID(5 shl 2); + csYIQ = TJvFullColorSpaceID(6 shl 2); + csYCC = TJvFullColorSpaceID(7 shl 2); + csXYZ = TJvFullColorSpaceID(8 shl 2); + csLAB = TJvFullColorSpaceID(9 shl 2); + csDEF = TJvFullColorSpaceID(10 shl 2); + + csID_MASK = $FC; + + csMIN = $04 and csID_MASK; + csMAX = $FF and csID_MASK; + + RGB_MIN = 0; + RGB_MAX = 255; + HLS_MIN = 0; + HLS_MAX = 240; + CMY_MIN = 0; + CMY_MAX = 255; + YUV_MIN = 16; + YUV_MAX = 235; + HSV_MIN = 0; + HSV_MAX = 240; + YIQ_MIN = 0; + YIQ_MAX = 255; + YCC_MIN = 0; + YCC_MAX = 255; + XYZ_MIN = 0; + XYZ_MAX = 255; + LAB_MIN = 0; + LAB_MAX = 255; + DEF_MIN = 0; + DEF_MAX = 255; + + fclRGBBlack = TJvFullColor((Ord(csRGB) shl 24) or $000000); + fclRGBWhite = TJvFullColor((Ord(csRGB) shl 24) or $FFFFFF); + fclRGBRed = TJvFullColor((Ord(csRGB) shl 24) or $0000FF); + fclRGBLime = TJvFullColor((Ord(csRGB) shl 24) or $00FF00); + fclRGBBlue = TJvFullColor((Ord(csRGB) shl 24) or $FF0000); + + COLOR_WINDOWTEXT = 8; + + fclDEFWindowText = TJvFullColor((Ord(csDEF) shl 24) or JvSystemFullColorMask or COLOR_WINDOWTEXT); + +type + TJvColorSpace = class(TPersistent) + private + FID: TJvFullColorSpaceID; + protected + function GetAxisName(Index: TJvAxisIndex): string; virtual; + function GetAxisMin(Index: TJvAxisIndex): Byte; virtual; + function GetAxisMax(Index: TJvAxisIndex): Byte; virtual; + function GetAxisDefault(Index: TJvAxisIndex): Byte; virtual; + function GetName: string; virtual; + function GetShortName: string; virtual; + function GetNumberOfColors: Cardinal; virtual; + public + constructor Create(ColorID: TJvFullColorSpaceID); virtual; + function ConvertFromColor(AColor: TColor): TJvFullColor; virtual; + function ConvertToColor(AColor: TJvFullColor): TColor; virtual; + property ID: TJvFullColorSpaceID read FID; + property NumberOfColors: Cardinal read GetNumberOfColors; + property Name: string read GetName; + property ShortName: string read GetShortName; + property AxisName[Index: TJvAxisIndex]: string read GetAxisName; + property AxisMin[Index: TJvAxisIndex]: Byte read GetAxisMin; + property AxisMax[Index: TJvAxisIndex]: Byte read GetAxisMax; + property AxisDefault[Index: TJvAxisIndex]: Byte read GetAxisDefault; + end; + + {TJvColorConversionMatrix = array[0..3,0..3] of Extended; // OpenGL and D3D style matrix + PJvColorConversionMatrix = ^TJvColorConversionMatrix; + TJvMatrixType = (mtFromRGB, mtToRGB); + + TJvMatrixColorSpace = class(TJvColorSpace) + protected + FToRGBMatrix, + FFromRGBMatrix: TJvColorConversionMatrix; + public + constructor Create(ColorID: TJvFullColorSpaceID; AMatrix: PJvColorConversionMatrix; + MatrixType: TJvMatrixType); reintroduce; + destructor Destroy; override; + function ConvertToID(AFullColor: TJvFullColor; NewID: TJvFullColorSpaceID; // + RGBToNewIDMatrix: PJvColorConversionMatrix): TJvFullColor; // use a call with pointer argument + function ConvertFromID(AFullColor: TJvFullColor; OldID: TJvFullColorSpaceID; // because a matrix is 160 Bytes !!! + OldIDToRGBMatrix: PJvColorConversionMatrix): TJvFullColor; // /!\ not on the stack /!\ + function ConvertFromColor(AColor: TColor): TColor; override; // + function ConvertToColor(AColor: TJvFullColor): TColor; override; + function GetToRGBMatrix: PJvColorConversionMatrix; + function GetFromRGBMatrix: PJvColorConversionMatrix; + end;} + + TJvRGBColorSpace = class(TJvColorSpace) + protected + function GetAxisName(Index: TJvAxisIndex): string; override; + function GetAxisMin(Index: TJvAxisIndex): Byte; override; + function GetAxisMax(Index: TJvAxisIndex): Byte; override; + function GetName: string; override; + function GetShortName: string; override; + function GetAxisDefault(Index: TJvAxisIndex): Byte; override; + public + function ConvertFromColor(AColor: TColor): TJvFullColor; override; + function ConvertToColor(AColor: TJvFullColor): TColor; override; + end; + + TJvHLSColorSpace = class(TJvColorSpace) + protected + function GetAxisName(Index: TJvAxisIndex): string; override; + function GetAxisMin(Index: TJvAxisIndex): Byte; override; + function GetAxisMax(Index: TJvAxisIndex): Byte; override; + function GetName: string; override; + function GetShortName: string; override; + function GetAxisDefault(Index: TJvAxisIndex): Byte; override; + public + function ConvertFromColor(AColor: TColor): TJvFullColor; override; + function ConvertToColor(AColor: TJvFullColor): TColor; override; + end; + + TJvCMYColorSpace = class(TJvColorSpace) + protected + function GetAxisName(Index: TJvAxisIndex): string; override; + function GetAxisMin(Index: TJvAxisIndex): Byte; override; + function GetAxisMax(Index: TJvAxisIndex): Byte; override; + function GetName: string; override; + function GetShortName: string; override; + function GetAxisDefault(Index: TJvAxisIndex): Byte; override; + public + function ConvertFromColor(AColor: TColor): TJvFullColor; override; + function ConvertToColor(AColor: TJvFullColor): TColor; override; + end; + + TJvYUVColorSpace = class(TJvColorSpace) + protected + function GetAxisName(Index: TJvAxisIndex): string; override; + function GetAxisMin(Index: TJvAxisIndex): Byte; override; + function GetAxisMax(Index: TJvAxisIndex): Byte; override; + function GetName: string; override; + function GetShortName: string; override; + function GetAxisDefault(Index: TJvAxisIndex): Byte; override; + public + function ConvertFromColor(AColor: TColor): TJvFullColor; override; + function ConvertToColor(AColor: TJvFullColor): TColor; override; + end; + + TJvHSVColorSpace = class(TJvColorSpace) + protected + function GetAxisName(Index: TJvAxisIndex): string; override; + function GetAxisMin(Index: TJvAxisIndex): Byte; override; + function GetAxisMax(Index: TJvAxisIndex): Byte; override; + function GetName: string; override; + function GetShortName: string; override; + function GetAxisDefault(Index: TJvAxisIndex): Byte; override; + public + function ConvertFromColor(AColor: TColor): TJvFullColor; override; + function ConvertToColor(AColor: TJvFullColor): TColor; override; + end; + + TJvYIQColorSpace = class(TJvColorSpace) + protected + function GetAxisName(Index: TJvAxisIndex): string; override; + function GetAxisMin(Index: TJvAxisIndex): Byte; override; + function GetAxisMax(Index: TJvAxisIndex): Byte; override; + function GetName: string; override; + function GetShortName: string; override; + function GetAxisDefault(Index: TJvAxisIndex): Byte; override; + public + function ConvertFromColor(AColor: TColor): TJvFullColor; override; + function ConvertToColor(AColor: TJvFullColor): TColor; override; + end; + + TJvYCCColorSpace = class(TJvColorSpace) + protected + function GetAxisName(Index: TJvAxisIndex): string; override; + function GetAxisMin(Index: TJvAxisIndex): Byte; override; + function GetAxisMax(Index: TJvAxisIndex): Byte; override; + function GetName: string; override; + function GetShortName: string; override; + function GetAxisDefault(Index: TJvAxisIndex): Byte; override; + public + function ConvertFromColor(AColor: TColor): TJvFullColor; override; + function ConvertToColor(AColor: TJvFullColor): TColor; override; + end; + + TJvXYZColorSpace = class(TJvColorSpace) + protected + function GetAxisName(Index: TJvAxisIndex): string; override; + function GetAxisMin(Index: TJvAxisIndex): Byte; override; + function GetAxisMax(Index: TJvAxisIndex): Byte; override; + function GetName: string; override; + function GetShortName: string; override; + function GetAxisDefault(Index: TJvAxisIndex): Byte; override; + public + function ConvertFromColor(AColor: TColor): TJvFullColor; override; + function ConvertToColor(AColor: TJvFullColor): TColor; override; + end; + + TJvLABColorSpace = class(TJvColorSpace) + protected + function GetAxisName(Index: TJvAxisIndex): string; override; + function GetAxisMin(Index: TJvAxisIndex): Byte; override; + function GetAxisMax(Index: TJvAxisIndex): Byte; override; + function GetName: string; override; + function GetShortName: string; override; + function GetAxisDefault(Index: TJvAxisIndex): Byte; override; + public + function ConvertFromColor(AColor: TColor): TJvFullColor; override; + function ConvertToColor(AColor: TJvFullColor): TColor; override; + end; + + TJvDEFColorSpace = class(TJvColorSpace) + private + FDelphiColors: TStringList; + procedure GetColorValuesCallBack(const S: string); + protected + function GetName: string; override; + function GetShortName: string; override; + function GetNumberOfColors: Cardinal; override; + function GetColorName(Index: Integer): string; + function GetPrettyName(Index: Integer): string; + function GetColorValue(Index: Integer): TColor; + public + constructor Create(ColorID: TJvFullColorSpaceID); override; + destructor Destroy; override; + function ConvertFromColor(AColor: TColor): TJvFullColor; override; + function ConvertToColor(AColor: TJvFullColor): TColor; override; + procedure AddCustomColor(AColor: TColor; AShortName, APrettyName: string); + procedure AddDelphiColor(Value: TColor); + property ColorCount: Cardinal read GetNumberOfColors; + property ColorName[Index: Integer]: string read GetColorName; + property ColorPrettyName[Index: Integer]: string read GetPrettyName; + property ColorValue[Index: Integer]: TColor read GetColorValue; default; + end; + + TJvColorSpaceManager = class(TPersistent) + private + FColorSpaceList: TList; + function GetCount: Integer; + function GetColorSpaceByIndex(Index: Integer): TJvColorSpace; + protected + function GetColorSpace(ID: TJvFullColorSpaceID): TJvColorSpace; virtual; + public + procedure RegisterColorSpace(NewColorSpace: TJvColorSpace); + procedure UnRegisterColorSpace(AColorSpace: TJvColorSpace); + constructor Create; + destructor Destroy; override; + function ConvertToID(AColor: TJvFullColor; DestID: TJvFullColorSpaceID): TJvFullColor; + function ConvertToColor(AColor: TJvFullColor): TColor; + function ConvertFromColor(AColor: TColor): TJvFullColor; + function GetColorSpaceID(AColor: TJvFullColor): TJvFullColorSpaceID; + + property ColorSpace[ID: TJvFullColorSpaceID]: TJvColorSpace read GetColorSpace; + property ColorSpaceByIndex[Index: Integer]: TJvColorSpace read GetColorSpaceByIndex; + property Count: Integer read GetCount; + end; + + EJvColorSpaceError = class(EJVCLException); + +function ColorSpaceManager: TJvColorSpaceManager; +function GetAxisValue(AColor: TJvFullColor; AAxis: TJvAxisIndex): Byte; +function SetAxisValue(AColor: TJvFullColor; AAxis: TJvAxisIndex; NewValue: Byte): TJvFullColor; + +procedure SplitColorParts(AColor: TJvFullColor; var Part1, Part2, Part3: Integer); +function JoinColorParts(const Part1, Part2, Part3: Integer): TJvFullColor; + +function ColorToPrettyName(Value: TColor): String; +function PrettyNameToColor(Value: String): TColor; +function RGBToBGR(Value: Cardinal): Cardinal; + + +implementation + +uses + Controls, StdCtrls, ExtCtrls, TypInfo, Math, + JvResources; + +var + GlobalColorSpaceManager: TJvColorSpaceManager = nil; + +const + HLS_MAX_HALF = HLS_MAX / 2.0; + HLS_MAX_ONE_THIRD = HLS_MAX / 3.0; + HLS_MAX_TWO_THIRDS = (HLS_MAX * 2.0) / 3.0; + HLS_MAX_SIXTH = HLS_MAX / 6.0; + HLS_MAX_TWELVETH = HLS_MAX / 12.0; + +function ColorSpaceManager: TJvColorSpaceManager; +begin + if GlobalColorSpaceManager = nil then + begin + GlobalColorSpaceManager := TJvColorSpaceManager.Create; + GlobalColorSpaceManager.RegisterColorSpace(TJvRGBColorSpace.Create(csRGB)); + GlobalColorSpaceManager.RegisterColorSpace(TJvHLSColorSpace.Create(csHLS)); + GlobalColorSpaceManager.RegisterColorSpace(TJvCMYColorSpace.Create(csCMY)); + GlobalColorSpaceManager.RegisterColorSpace(TJvYUVColorSpace.Create(csYUV)); + GlobalColorSpaceManager.RegisterColorSpace(TJvHSVColorSpace.Create(csHSV)); + GlobalColorSpaceManager.RegisterColorSpace(TJvYIQColorSpace.Create(csYIQ)); + GlobalColorSpaceManager.RegisterColorSpace(TJvYCCColorSpace.Create(csYCC)); + GlobalColorSpaceManager.RegisterColorSpace(TJvXYZColorSpace.Create(csXYZ)); + GlobalColorSpaceManager.RegisterColorSpace(TJvLABColorSpace.Create(csLAB)); + GlobalColorSpaceManager.RegisterColorSpace(TJvDEFColorSpace.Create(csDEF)); + end; + Result := GlobalColorSpaceManager; +end; + +function SetAxisValue(AColor: TJvFullColor; AAxis: TJvAxisIndex; + NewValue: Byte): TJvFullColor; +begin + case AAxis of + axIndex0: + AColor := (AColor and $FFFFFF00) or NewValue; + axIndex1: + AColor := (AColor and $FFFF00FF) or (NewValue shl 8); + axIndex2: + AColor := (AColor and $FF00FFFF) or (NewValue shl 16); + end; + Result := AColor; +end; + +function GetAxisValue(AColor: TJvFullColor; AAxis: TJvAxisIndex): Byte; +begin + case AAxis of + axIndex0: + Result := (AColor and $000000FF); + axIndex1: + Result := (AColor and $0000FF00) shr 8; + axIndex2: + Result := (AColor and $00FF0000) shr 16; + else + Result := 0; + end; +end; + +procedure SplitColorParts(AColor: TJvFullColor; var Part1, Part2, Part3: Integer); +begin + Part1 := AColor and $000000FF; + Part2 := (AColor shr 8) and $000000FF; + Part3 := (AColor shr 16) and $000000FF; +end; + +function JoinColorParts(const Part1, Part2, Part3: Integer): TJvFullColor; +begin + Result := + (Part1 and $000000FF) or + ((Part2 and $000000FF) shl 8) or + ((Part3 and $000000FF) shl 16); +end; + +function RGBToBGR(Value: Cardinal): Cardinal; +begin + Result := + ((Value and $00FF0000) shr 16) or + (Value and $0000FF00) or + ((Value and $000000FF) shl 16); +end; + +(* +function ColorToPrettyName(Value: TColor): string; +var + Index: Integer; +begin + for Index := Low(ColorValues) to High(ColorValues) do + if Value = ColorValues[Index].Value then + begin + Result := ColorValues[Index].Description; + Exit; + end; + for Index := Low(StandardColorValues) to High(StandardColorValues) do + if Value = StandardColorValues[Index].Value then + begin + Result := StandardColorValues[Index].Description; + Exit; + end; + for Index := Low(SysColorValues) to High(SysColorValues) do + if Value = SysColorValues[Index].Value then + begin + Result := SysColorValues[Index].Description; + Exit; + end; + Result := ColorToString(Value); +end; +*) + +function ColorToPrettyName(Value: TColor): String; +begin + Result := ColorToString(Value); + if pos('cl', Result) = 1 then Delete(Result, 1, 2); +end; + +function PrettyNameToColor(Value: String): TColor; +begin + Result := StringToColor('cl' + Value); +end; + + +//=== { TJvColorSpace } ====================================================== + +constructor TJvColorSpace.Create(ColorID: TJvFullColorSpaceID); +begin + inherited Create; + if (ColorID >= csMIN) and (ColorID <= csMAX) then + FID := ColorID + else + raise EJvColorSpaceError.CreateResFmt(@RsEIllegalID, [Ord(ColorID)]); +end; + +function TJvColorSpace.ConvertFromColor(AColor: TColor): TJvFullColor; +begin + Result := (AColor and $00FFFFFF) or (ID shl 24); +end; + +function TJvColorSpace.ConvertToColor(AColor: TJvFullColor): TColor; +begin + Result := AColor and $00FFFFFF; +end; + +function TJvColorSpace.GetNumberOfColors: Cardinal; +begin + Result := + (AxisMax[axIndex0] - AxisMin[axIndex0] + 1) * + (AxisMax[axIndex1] - AxisMin[axIndex1] + 1) * + (AxisMax[axIndex2] - AxisMin[axIndex2] + 1); +end; + +function TJvColorSpace.GetAxisDefault(Index: TJvAxisIndex): Byte; +begin + Result := Low(Byte); +end; + +function TJvColorSpace.GetAxisMax(Index: TJvAxisIndex): Byte; +begin + Result := High(Byte); +end; + +function TJvColorSpace.GetAxisMin(Index: TJvAxisIndex): Byte; +begin + Result := Low(Byte); +end; + +function TJvColorSpace.GetAxisName(Index: TJvAxisIndex): string; +begin + Result := RsEUnnamedAxis; +end; + +function TJvColorSpace.GetName: string; +begin + Result := RsEUnnamedSpace; +end; + +function TJvColorSpace.GetShortName: string; +begin + Result := RsEUCS; +end; + +//=== { TJvRGBColorSpace } =================================================== + +function TJvRGBColorSpace.ConvertFromColor(AColor: TColor): TJvFullColor; +begin + Result := inherited ConvertFromColor(AColor); +end; + +function TJvRGBColorSpace.ConvertToColor(AColor: TJvFullColor): TColor; +begin + Result := inherited ConvertToColor(AColor); +end; + +function TJvRGBColorSpace.GetAxisDefault(Index: TJvAxisIndex): Byte; +begin + Result := 0; +end; + +function TJvRGBColorSpace.GetAxisMax(Index: TJvAxisIndex): Byte; +begin + Result := RGB_MAX; +end; + +function TJvRGBColorSpace.GetAxisMin(Index: TJvAxisIndex): Byte; +begin + Result := RGB_MIN; +end; + +function TJvRGBColorSpace.GetAxisName(Index: TJvAxisIndex): string; +begin + case Index of + axIndex0: + Result := RsRGB_Red; + axIndex1: + Result := RsRGB_Green; + axIndex2: + Result := RsRGB_Blue; + else + Result := inherited GetAxisName(Index); + end; +end; + +function TJvRGBColorSpace.GetName: string; +begin + Result := RsRGB_FullName; +end; + +function TJvRGBColorSpace.GetShortName: string; +begin + Result := RsRGB_ShortName; +end; + +//=== { TJvHLSColorSpace } =================================================== + +function TJvHLSColorSpace.ConvertFromColor(AColor: TColor): TJvFullColor; +var + Hue, Lightness, Saturation: Double; + Red, Green, Blue: Integer; + ColorMax, ColorMin, ColorDiff, ColorSum: Double; + RedDelta, GreenDelta, BlueDelta: Extended; +begin + SplitColorParts(AColor, Red, Green, Blue); + + if Red > Green then + ColorMax := Red + else + ColorMax := Green; + if Blue > ColorMax then + ColorMax := Blue; + if Red < Green then + ColorMin := Red + else + ColorMin := Green; + if Blue < ColorMin then + ColorMin := Blue; + ColorDiff := ColorMax - ColorMin; + ColorSum := ColorMax + ColorMin; + + Lightness := (ColorSum * HLS_MAX + RGB_MAX) / (2.0 * RGB_MAX); + if ColorMax = ColorMin then + AColor := (Round(Lightness) shl 8) or (2 * HLS_MAX div 3) + else + begin + if Lightness <= HLS_MAX_HALF then + Saturation := (ColorDiff * HLS_MAX + ColorSum / 2.0) / ColorSum + else + Saturation := (ColorDiff * HLS_MAX + ((2.0 * RGB_MAX - ColorMax - ColorMin) / 2.0)) / + (2.0 * RGB_MAX - ColorMax - ColorMin); + + RedDelta := ((ColorMax - Red) * HLS_MAX_SIXTH + ColorDiff / 2.0) / ColorDiff; + GreenDelta := ((ColorMax - Green) * HLS_MAX_SIXTH + ColorDiff / 2.0) / ColorDiff; + BlueDelta := ((ColorMax - Blue) * HLS_MAX_SIXTH + ColorDiff / 2.0) / ColorDiff; + + if Red = ColorMax then + Hue := BlueDelta - GreenDelta + else + if Green = ColorMax then + Hue := HLS_MAX_ONE_THIRD + RedDelta - BlueDelta + else + Hue := 2.0 * HLS_MAX_ONE_THIRD + GreenDelta - RedDelta; + + if Hue < 0 then + Hue := Hue + HLS_MAX; + if Hue > HLS_MAX then + Hue := Hue - HLS_MAX; + + AColor := + JoinColorParts(Cardinal(Round(Hue)), Cardinal(Round(Lightness)), Cardinal(Round(Saturation))); + end; + Result := inherited ConvertFromColor(AColor); +end; + +function TJvHLSColorSpace.ConvertToColor(AColor: TJvFullColor): TColor; +var + Red, Green, Blue: Double; + Magic1, Magic2: Double; + Hue, Lightness, Saturation: Integer; + + function HueToRGB(Lightness, Saturation, Hue: Double): Integer; + var + ResultEx: Double; + begin + if Hue < 0 then + Hue := Hue + HLS_MAX; + if Hue > HLS_MAX then + Hue := Hue - HLS_MAX; + + if Hue < HLS_MAX_SIXTH then + ResultEx := Lightness + ((Saturation - Lightness) * Hue + HLS_MAX_TWELVETH) / HLS_MAX_SIXTH + else + if Hue < HLS_MAX_HALF then + ResultEx := Saturation + else + if Hue < HLS_MAX_TWO_THIRDS then + ResultEx := Lightness + ((Saturation - Lightness) * (HLS_MAX_TWO_THIRDS - Hue) + HLS_MAX_TWELVETH) / HLS_MAX_SIXTH + else + ResultEx := Lightness; + Result := Round(ResultEx); + end; + + function RoundColor(Value: Double): Integer; + begin + if Value > RGB_MAX then + Result := RGB_MAX + else + Result := Round(Value); + end; + +begin + SplitColorParts(AColor, Hue, Lightness, Saturation); + + if Saturation = 0 then + begin + Red := (Lightness * RGB_MAX) / HLS_MAX; + Green := Red; + Blue := Red; + end + else + begin + if Lightness <= HLS_MAX_HALF then + Magic2 := (Lightness * (HLS_MAX + Saturation) + HLS_MAX_HALF) / HLS_MAX + else + Magic2 := Lightness + Saturation - ((Lightness * Saturation) + HLS_MAX_HALF) / HLS_MAX; + + Magic1 := 2 * Lightness - Magic2; + + Red := (HueToRGB(Magic1, Magic2, Hue + HLS_MAX_ONE_THIRD) * RGB_MAX + HLS_MAX_HALF) / HLS_MAX; + Green := (HueToRGB(Magic1, Magic2, Hue) * RGB_MAX + HLS_MAX_HALF) / HLS_MAX; + Blue := (HueToRGB(Magic1, Magic2, Hue - HLS_MAX_ONE_THIRD) * RGB_MAX + HLS_MAX_HALF) / HLS_MAX; + end; + + Result := inherited ConvertToColor( + JoinColorParts(RoundColor(Red), RoundColor(Green), RoundColor(Blue))); +end; + +function TJvHLSColorSpace.GetAxisDefault(Index: TJvAxisIndex): Byte; +begin + Result := 120; +end; + +function TJvHLSColorSpace.GetAxisMax(Index: TJvAxisIndex): Byte; +begin + Result := HLS_MAX; +end; + +function TJvHLSColorSpace.GetAxisMin(Index: TJvAxisIndex): Byte; +begin + Result := HLS_MIN; +end; + +function TJvHLSColorSpace.GetAxisName(Index: TJvAxisIndex): string; +begin + case Index of + axIndex0: + Result := RsHLS_Hue; + axIndex1: + Result := RsHLS_Lightness; + axIndex2: + Result := RsHLS_Saturation; + else + Result := inherited GetAxisName(Index); + end; +end; + +function TJvHLSColorSpace.GetName: string; +begin + Result := RsHLS_FullName; +end; + +function TJvHLSColorSpace.GetShortName: string; +begin + Result := RsHLS_ShortName; +end; + +//=== { TJvCMYColorSpace } =================================================== + +function TJvCMYColorSpace.ConvertFromColor(AColor: TColor): TJvFullColor; +var + Red, Green, Blue: Integer; + Cyan, Magenta, Yellow: Integer; +begin + SplitColorParts(AColor, Red, Green, Blue); + + Cyan := ((RGB_MAX - Red ) * (CMY_MAX-CMY_MIN+1) div (RGB_MAX-RGB_MIN+1)) + CMY_MIN; + Magenta := ((RGB_MAX - Green) * (CMY_MAX-CMY_MIN+1) div (RGB_MAX-RGB_MIN+1)) + CMY_MIN; + Yellow := ((RGB_MAX - Blue ) * (CMY_MAX-CMY_MIN+1) div (RGB_MAX-RGB_MIN+1)) + CMY_MIN; + + Result := inherited ConvertFromColor(JoinColorParts(Cyan, Magenta, Yellow)); +end; + +function TJvCMYColorSpace.ConvertToColor(AColor: TJvFullColor): TColor; +var + Cyan, Magenta, Yellow: Integer; + Red, Green, Blue: Integer; +begin + SplitColorParts(AColor, Cyan, Magenta, Yellow); + + Red := ((CMY_MAX - Cyan ) * (RGB_MAX-RGB_MIN+1) div (CMY_MAX-CMY_MIN+1)) + RGB_MIN; + Green := ((CMY_MAX - Magenta) * (RGB_MAX-RGB_MIN+1) div (CMY_MAX-CMY_MIN+1)) + RGB_MIN; + Blue := ((CMY_MAX - Yellow ) * (RGB_MAX-RGB_MIN+1) div (CMY_MAX-CMY_MIN+1)) + RGB_MIN; + + Result := inherited ConvertToColor(JoinColorParts(Red, Green, Blue)); +end; + +function TJvCMYColorSpace.GetAxisDefault(Index: TJvAxisIndex): Byte; +begin + Result := 255; +end; + +function TJvCMYColorSpace.GetAxisMax(Index: TJvAxisIndex): Byte; +begin + Result := CMY_MAX; +end; + +function TJvCMYColorSpace.GetAxisMin(Index: TJvAxisIndex): Byte; +begin + Result := CMY_MIN; +end; + +function TJvCMYColorSpace.GetAxisName(Index: TJvAxisIndex): string; +begin + case Index of + axIndex0: + Result := RsCMY_Cyan; + axIndex1: + Result := RsCMY_Magenta; + axIndex2: + Result := RsCMY_Yellow; + else + Result := inherited GetAxisName(Index); + end; +end; + +function TJvCMYColorSpace.GetName: string; +begin + Result := RsCMY_FullName; +end; + +function TJvCMYColorSpace.GetShortName: string; +begin + Result := RsCMY_ShortName; +end; + +//=== { TJvYUVColorSpace } =================================================== + +function TJvYUVColorSpace.ConvertFromColor(AColor: TColor): TJvFullColor; +var + Y, U, V: Integer; + Red, Green, Blue: Integer; +begin + SplitColorParts(AColor, Red, Green, Blue); + + Y := Round(0.257*Red + 0.504*Green + 0.098*Blue) + 16; + V := Round(0.439*Red - 0.368*Green - 0.071*Blue) + 128; + U := Round(-0.148*Red - 0.291*Green + 0.439*Blue) + 128; + + Y := EnsureRange(Y, YUV_MIN, YUV_MAX); + U := EnsureRange(U, YUV_MIN, YUV_MAX); + V := EnsureRange(V, YUV_MIN, YUV_MAX); + + Result := inherited ConvertFromColor(JoinColorParts(Y, U, V)); +end; + +function TJvYUVColorSpace.ConvertToColor(AColor: TJvFullColor): TColor; +var + Red, Green, Blue: Integer; + Y, U, V: Integer; +begin + SplitColorParts(AColor, Y, U, V); + + Y := Y - 16; + U := U - 128; + V := V - 128; + + Red := Round(1.164*Y - 0.002*U + 1.596*V); + Green := Round(1.164*Y - 0.391*U - 0.813*V); + Blue := Round(1.164*Y + 2.018*U - 0.001*V); + + Red := EnsureRange(Red , RGB_MIN, RGB_MAX); + Green := EnsureRange(Green, RGB_MIN, RGB_MAX); + Blue := EnsureRange(Blue, RGB_MIN, RGB_MAX); + + Result := inherited ConvertToColor(JoinColorParts(Red, Green, Blue)); +end; + +function TJvYUVColorSpace.GetAxisDefault(Index: TJvAxisIndex): Byte; +begin + Result := 128; +end; + +function TJvYUVColorSpace.GetAxisMax(Index: TJvAxisIndex): Byte; +begin + Result := YUV_MAX; +end; + +function TJvYUVColorSpace.GetAxisMin(Index: TJvAxisIndex): Byte; +begin + Result := YUV_MIN; +end; + +function TJvYUVColorSpace.GetAxisName(Index: TJvAxisIndex): string; +begin + case Index of + axIndex0: + Result := RsYUV_Y; + axIndex1: + Result := RsYUV_U; + axIndex2: + Result := RsYUV_V; + else + Result := inherited GetAxisName(Index); + end; +end; + +function TJvYUVColorSpace.GetName: string; +begin + Result := RsYUV_FullName; +end; + +function TJvYUVColorSpace.GetShortName: string; +begin + Result := RsYUV_ShortName; +end; + +//=== { TJvHSVColorSpace } =================================================== + +function TJvHSVColorSpace.ConvertFromColor(AColor: TColor): TJvFullColor; +var + Hue, Saturation, Value: Integer; + Red, Green, Blue: Integer; + ColorMax, ColorMin, ColorDelta: Integer; +begin + SplitColorParts(AColor, Red, Green, Blue); + + if Red > Green then + ColorMax := Red + else + ColorMax := Green; + if Blue > ColorMax then + ColorMax := Blue; + + if Red < Green then + ColorMin := Red + else + ColorMin := Green; + if Blue < ColorMin then + ColorMin := Blue; + + ColorDelta := ColorMax - ColorMin; + Value := ColorMax; + + if Value = 0 then + Saturation := 0 + else + Saturation := (255 * ColorDelta) div Value; + + if Saturation = 0 then + Hue := 0 + else + begin + Hue := 0; + if Value = Red then + Hue := (40 * (Green - Blue) div ColorDelta); + if Value = Green then + Hue := (HSV_MAX div 3) + (40 * (Blue - Red) div ColorDelta); + if Value = Blue then + Hue := ((HSV_MAX * 2) div 3) + (40 * (Red - Green) div ColorDelta); + end; + + if Hue < 0 then + Hue := Hue + HSV_MAX; + if Hue > HSV_MAX then + Hue := Hue - HSV_MAX; + + Result := inherited ConvertFromColor(JoinColorParts(Hue, Saturation, Value)); +end; + +function TJvHSVColorSpace.ConvertToColor(AColor: TJvFullColor): TColor; +var + Hue, Saturation, Value: Integer; + Red, Green, Blue: Integer; + P, Q, T, Summ, Rest: Integer; +begin + SplitColorParts(AColor, Hue, Saturation, Value); + + if Saturation = 0 then + begin + Red := Value; + Green := Value; + Blue := Value; + end + else + begin + if Hue = HSV_MAX then + Hue := 0; + + Rest := Hue mod (HSV_MAX div 6); + Hue := Hue div (HSV_MAX div 6); + + Summ := Value * Saturation; + + P := Value - Summ div RGB_MAX; + Q := Value - (Summ * Rest) div (RGB_MAX * (HSV_MAX div 6)); + T := Value - (Summ * ((HSV_MAX div 6) - Rest)) div (RGB_MAX * (HSV_MAX div 6)); + case Hue of + 0: + begin + Red := Value; + Green := T; + Blue := P; + end; + 1: + begin + Red := Q; + Green := Value; + Blue := P; + end; + 2: + begin + Red := P; + Green := Value; + Blue := T; + end; + 3: + begin + Red := P; + Green := Q; + Blue := Value; + end; + 4: + begin + Red := T; + Green := P; + Blue := Value; + end; + else + Red := Value; + Green := P; + Blue := Q; + end; + end; + + Result := inherited ConvertToColor(JoinColorParts(Red, Green, Blue)); +end; + +function TJvHSVColorSpace.GetAxisDefault(Index: TJvAxisIndex): Byte; +begin + case Index of + axIndex0: + Result := 120; + axIndex1: + Result := 240; + else + Result := 150; + end; +end; + +function TJvHSVColorSpace.GetAxisMax(Index: TJvAxisIndex): Byte; +begin + case Index of + axIndex0: + Result := HSV_MAX; + else + Result := RGB_MAX; + end; +end; + +function TJvHSVColorSpace.GetAxisMin(Index: TJvAxisIndex): Byte; +begin + Result := HSV_MIN; +end; + +function TJvHSVColorSpace.GetAxisName(Index: TJvAxisIndex): string; +begin + case Index of + axIndex0: + Result := RsHSV_Hue; + axIndex1: + Result := RsHSV_Saturation; + axIndex2: + Result := RsHSV_Value; + else + Result := inherited GetAxisName(Index); + end; +end; + +function TJvHSVColorSpace.GetName: string; +begin + Result := RsHSV_FullName; +end; + +function TJvHSVColorSpace.GetShortName: string; +begin + Result := RsHSV_ShortName; +end; + +//=== { TJvYIQColorSpace } =================================================== + +function TJvYIQColorSpace.ConvertFromColor(AColor: TColor): TJvFullColor; +var + Y, I, Q: Integer; + Red, Green, Blue: Integer; +begin + SplitColorParts(AColor, Red, Green, Blue); + + Y := Round(0.299*Red + 0.587*Green + 0.114*Blue); + I := Round(0.596*Red - 0.275*Green - 0.321*Blue) + 128; + Q := Round(0.212*Red - 0.523*Green + 0.311*Blue) + 128; + + Y := EnsureRange(Y, YIQ_MIN, YIQ_MAX); + I := EnsureRange(I, YIQ_MIN, YIQ_MAX); + Q := EnsureRange(Q, YIQ_MIN, YIQ_MAX); + + Result := inherited ConvertFromColor(JoinColorParts(Y, I, Q)); +end; + +function TJvYIQColorSpace.ConvertToColor(AColor: TJvFullColor): TColor; +var + Red, Green, Blue: Integer; + Y, I, Q: Integer; +begin + SplitColorParts(AColor, Y, I, Q); + + //Y := Y; + I := I - 128; + Q := Q - 128; + + Red := Round(Y + 0.956*I + 0.620*Q); + Green := Round(Y - 0.272*I - 0.647*Q); + Blue := Round(Y - 1.108*I + 1.705*Q); + + Red := EnsureRange(Red , RGB_MIN, RGB_MAX); + Green := EnsureRange(Green, RGB_MIN, RGB_MAX); + Blue := EnsureRange(Blue, RGB_MIN, RGB_MAX); + + Result := inherited ConvertToColor(JoinColorParts(Red, Green, Blue)); +end; + +function TJvYIQColorSpace.GetAxisDefault(Index: TJvAxisIndex): Byte; +begin + Result := 128; +end; + +function TJvYIQColorSpace.GetAxisMax(Index: TJvAxisIndex): Byte; +begin + Result := YIQ_MAX; +end; + +function TJvYIQColorSpace.GetAxisMin(Index: TJvAxisIndex): Byte; +begin + Result := YIQ_MIN; +end; + +function TJvYIQColorSpace.GetAxisName(Index: TJvAxisIndex): string; +begin + case Index of + axIndex0: + Result := RsYIQ_Y; + axIndex1: + Result := RsYIQ_I; + axIndex2: + Result := RsYIQ_Q; + else + Result := inherited GetAxisName(Index); + end; +end; + +function TJvYIQColorSpace.GetName: string; +begin + Result := RsYIQ_FullName; +end; + +function TJvYIQColorSpace.GetShortName: string; +begin + Result := RsYIQ_ShortName; +end; + +//=== { TJvYCCColorSpace } =================================================== + +function TJvYCCColorSpace.ConvertFromColor(AColor: TColor): TJvFullColor; +var + Y, Cr, Cb: Integer; + Red, Green, Blue: Integer; +begin + SplitColorParts(AColor, Red, Green, Blue); + + Y := Round( 0.299*Red + 0.587*Green + 0.114*Blue); + Cr := Round(-0.150*Red - 0.293*Green + 0.443*Blue) + 128; + Cb := Round( 0.438*Red - 0.367*Green - 0.071*Blue) + 128; + + Y := EnsureRange(Y, YCC_MIN, YCC_MAX); + Cr := EnsureRange(Cr, YCC_MIN, YCC_MAX); + Cb := EnsureRange(Cb, YCC_MIN, YCC_MAX); + + Result := inherited ConvertFromColor(JoinColorParts(Y, Cr, Cb)); +end; + +function TJvYCCColorSpace.ConvertToColor(AColor: TJvFullColor): TColor; +var + Red, Green, Blue: Integer; + Y, Cr, Cb: Integer; +begin + SplitColorParts(AColor, Y, Cr, Cb); + + Y := Y; + Cr := Cr - 128; + Cb := Cb - 128; + + Red := Round(Y - 0.001*Cr + 1.600*Cb); + Green := Round(Y - 0.388*Cr - 0.816*Cb); + Blue := Round(Y + 2.000*Cr + 0.002*Cb); + + Red := EnsureRange(Red , RGB_MIN, RGB_MAX); + Green := EnsureRange(Green, RGB_MIN, RGB_MAX); + Blue := EnsureRange(Blue, RGB_MIN, RGB_MAX); + + Result := inherited ConvertToColor(JoinColorParts(Red, Green, Blue)); +end; + +function TJvYCCColorSpace.GetAxisDefault(Index: TJvAxisIndex): Byte; +begin + Result := 128; +end; + +function TJvYCCColorSpace.GetAxisMax(Index: TJvAxisIndex): Byte; +begin + Result := YCC_MAX; +end; + +function TJvYCCColorSpace.GetAxisMin(Index: TJvAxisIndex): Byte; +begin + Result := YCC_MIN; +end; + +function TJvYCCColorSpace.GetAxisName(Index: TJvAxisIndex): string; +begin + case Index of + axIndex0: + Result := RsYCC_Y; + axIndex1: + Result := RsYCC_Cr; + axIndex2: + Result := RsYCC_Cb; + else + Result := inherited GetAxisName(Index); + end; +end; + +function TJvYCCColorSpace.GetName: string; +begin + Result := RsYCC_FullName; +end; + +function TJvYCCColorSpace.GetShortName: string; +begin + Result := RsYCC_ShortName; +end; + +//=== { TJvXYZColorSpace } =================================================== + +function TJvXYZColorSpace.ConvertFromColor(AColor: TColor): TJvFullColor; +var + X, Y, Z: Integer; + Red, Green, Blue: Integer; +begin + SplitColorParts(AColor, Red, Green, Blue); + + X := Round( 0.618*Red + 0.177*Green + 0.205*Blue); + Y := Round( 0.299*Red + 0.587*Green + 0.114*Blue); + Z := Round( 0.056*Green + 0.944*Blue); + + X := EnsureRange(X, XYZ_MIN, XYZ_MAX); + Y := EnsureRange(Y, XYZ_MIN, XYZ_MAX); + Z := EnsureRange(Z, XYZ_MIN, XYZ_MAX); + + Result := inherited ConvertFromColor(JoinColorParts(X, Y, Z)); +end; + +function TJvXYZColorSpace.ConvertToColor(AColor: TJvFullColor): TColor; +var + Red, Green, Blue: Integer; + X, Y, Z: Integer; +begin + SplitColorParts(AColor, X, Y, Z); + + Red := Round( 1.876*X - 0.533*Y - 0.343*Z); + Green := Round(-0.967*X + 1.998*Y - 0.031*Z); + Blue := Round( 0.057*X - 0.118*Y + 1.061*Z); + + Red := EnsureRange(Red , RGB_MIN, RGB_MAX); + Green := EnsureRange(Green, RGB_MIN, RGB_MAX); + Blue := EnsureRange(Blue, RGB_MIN, RGB_MAX); + + Result := inherited ConvertToColor(JoinColorParts(Red, Green, Blue)); +end; + +function TJvXYZColorSpace.GetAxisDefault(Index: TJvAxisIndex): Byte; +begin + Result := 128; +end; + +function TJvXYZColorSpace.GetAxisMax(Index: TJvAxisIndex): Byte; +begin + Result := XYZ_MAX; +end; + +function TJvXYZColorSpace.GetAxisMin(Index: TJvAxisIndex): Byte; +begin + Result := XYZ_MIN; +end; + +function TJvXYZColorSpace.GetAxisName(Index: TJvAxisIndex): string; +begin + case Index of + axIndex0: + Result := RsXYZ_X; + axIndex1: + Result := RsXYZ_Y; + axIndex2: + Result := RsXYZ_Z; + else + Result := inherited GetAxisName(Index); + end; +end; + +function TJvXYZColorSpace.GetName: string; +begin + Result := RsXYZ_FullName; +end; + +function TJvXYZColorSpace.GetShortName: string; +begin + Result := RsXYZ_ShortName; +end; + +//=== { TJvLABColorSpace } =================================================== + +function TJvLABColorSpace.ConvertFromColor(AColor: TColor): TJvFullColor; +var + X, Y, Z: Extended; + L, A, B: Integer; + Red, Green, Blue: Integer; + + function Calc(Value: Extended): Extended; + begin + if Value > 0.008856 then + Result := Power(Value, 1.0 / 3.0) + else + Result := 7.7787 * Value + (16.0 / 116.0); + end; + +begin + SplitColorParts(AColor, Red, Green, Blue); + + X := (0.618*Red + 0.177*Green + 0.205*Blue) / XYZ_MAX; + Y := (0.299*Red + 0.587*Green + 0.114*Blue) / XYZ_MAX; + Z := ( 0.056*Green + 0.944*Blue) / XYZ_MAX; + + X := EnsureRange(X, 0.0, 1.0); + Y := EnsureRange(Y, 0.0, 1.0); + Z := EnsureRange(Z, 0.0, 1.0); + + if Y > 0.008856 then + L := Round(116.0 * Power(Y, 1.0 / 3.0) - 16.0) + else + L := Round(903.3 * Y); + A := Round(500.0 *(Calc(X) - Calc(Y)))+128; + B := Round(200.0 *(Calc(Y) - Calc(Z)))+128; + + L := EnsureRange(L, LAB_MIN, LAB_MAX); + A := EnsureRange(A, LAB_MIN, LAB_MAX); + B := EnsureRange(B, LAB_MIN, LAB_MAX); + + Result := inherited ConvertFromColor(JoinColorParts(L, A, B)); +end; + +function TJvLABColorSpace.ConvertToColor(AColor: TJvFullColor): TColor; +var + Red, Green, Blue: Integer; + X, Y, Z: Extended; + L, A, B: Integer; + + function Calc(Value: Extended): Extended; + begin + if Value > 0.207 then + Result := Power(Value, 3.0) + else + Result := ((116.0 * Value) - 16.0) / 903.3; + end; + +begin + SplitColorParts(AColor, L, A, B); + + if L > 8 then + Y := XYZ_MAX * Power((L + 16.0) / 116.0, 3.0) + else + Y := (XYZ_MAX * L) / 903.3; + X := XYZ_MAX * Calc(((A-128) / 500.0) + ((L + 16.0) / 116.0)); + Z := XYZ_MAX * Calc(((L + 16.0) / 116.0) - ((B-128) / 200.0)); + + X := EnsureRange(X, XYZ_MIN, XYZ_MAX); + Y := EnsureRange(Y, XYZ_MIN, XYZ_MAX); + Z := EnsureRange(Z, XYZ_MIN, XYZ_MAX); + + Red := Round( 1.876*X - 0.533*Y - 0.343*Z); + Green := Round(-0.967*X + 1.998*Y - 0.031*Z); + Blue := Round( 0.057*X - 0.118*Y + 1.061*Z); + + Red := EnsureRange(Red , RGB_MIN, RGB_MAX); + Green := EnsureRange(Green, RGB_MIN, RGB_MAX); + Blue := EnsureRange(Blue, RGB_MIN, RGB_MAX); + + Result := inherited ConvertToColor(JoinColorParts(Red, Green, Blue)); +end; + +function TJvLABColorSpace.GetAxisDefault(Index: TJvAxisIndex): Byte; +begin + Result := 50; +end; + +function TJvLABColorSpace.GetAxisMax(Index: TJvAxisIndex): Byte; +begin + Result := LAB_MAX; +end; + +function TJvLABColorSpace.GetAxisMin(Index: TJvAxisIndex): Byte; +begin + Result := LAB_MIN; +end; + +function TJvLABColorSpace.GetAxisName(Index: TJvAxisIndex): string; +begin + case Index of + axIndex0: + Result := RsLAB_L; + axIndex1: + Result := RsLAB_A; + axIndex2: + Result := RsLAB_B; + else + Result := inherited GetAxisName(Index); + end; +end; + +function TJvLABColorSpace.GetName: string; +begin + Result := RsLAB_FullName; +end; + +function TJvLABColorSpace.GetShortName: string; +begin + Result := RsLAB_ShortName; +end; + +//=== { TJvDEFColorSpace } =================================================== + +constructor TJvDEFColorSpace.Create(ColorID: TJvFullColorSpaceID); +begin + inherited Create(ColorID); + FDelphiColors := TStringList.Create; + // ignore duplicates + FDelphiColors.Duplicates := dupIgnore; + GetColorValues(@GetColorValuesCallBack); + AddDelphiColor(clNone); +end; + +destructor TJvDEFColorSpace.Destroy; +begin + FDelphiColors.Free; + inherited Destroy; +end; + +procedure TJvDEFColorSpace.GetColorValuesCallBack(const S: string); +var + AColor: TColor; +begin + AColor := StringToColor(S); + AddCustomColor(AColor,Copy(S,3,Length(S)-2), ColorToPrettyName(AColor)); +end; + +procedure TJvDEFColorSpace.AddDelphiColor(Value: TColor); +begin + AddCustomColor(Value,ColorToString(Value), ColorToPrettyName(Value)); +end; + +procedure TJvDEFColorSpace.AddCustomColor(AColor: TColor; + AShortName, APrettyName: string); +begin + if FDelphiColors.IndexOfObject(TObject(AColor)) = -1 then + begin + FDelphiColors.Values[AShortName] := APrettyName; + FDelphiColors.Objects[FDelphiColors.IndexOfName(AShortName)] := TObject(AColor); + end; +end; + +function TJvDEFColorSpace.ConvertFromColor(AColor: TColor): TJvFullColor; +var + I: Integer; + NewColor: TColor; +begin + NewColor := clNone; + for I := 0 to FDelphiColors.Count - 1 do + if AColor = TColor(FDelphiColors.Objects[I]) then + begin + NewColor := AColor; + Break; + end; + + Result := inherited ConvertFromColor(NewColor); + + if NewColor = clNone then + // mark it as clNone + Result := Result or JvSpecialFullColorMask + else + if NewColor = clDefault then + // mark it as clDefault + Result := Result or JvSpecialFullColorMask + else + if (NewColor and JvSystemColorMask) = JvSystemColorMask then + // mark it as predefined color + Result := Result or JvSystemFullColorMask + + else + if (NewColor and JvSystemColorMask) = 0 then + Result := ColorSpaceManager.ColorSpace[csRGB].ConvertFromColor(NewColor) + // should never happend because there should be no way ... + else + raise EJvColorSpaceError.CreateResFmt(@RsEInconvertibleColor, [Cardinal(NewColor)]); +end; + +function TJvDEFColorSpace.ConvertToColor(AColor: TJvFullColor): TColor; +begin + Result := inherited ConvertToColor(AColor); + case AColor and JvSubFullColorMask of + JvSystemFullColorMask: + Result := Cardinal(Result) or JvSystemColorMask; + JvSpecialFullColorMask: + begin + if Result = (clNone and $FFFFFF) then + Result := clNone + else + if Result = (clDefault and $FFFFFF) then + Result := clDefault + else + raise EJvColorSpaceError.CreateResFmt(@RsEInconvertibleColor, [Cardinal(AColor)]); + end; + else + raise EJvColorSpaceError.CreateResFmt(@RsEInconvertibleColor, [Cardinal(AColor)]); + end; +end; + +function TJvDEFColorSpace.GetColorName(Index: Integer): string; +begin + if (Index >= 0) and (Index < FDelphiColors.Count) then + Result := FDelphiColors.Names[Index] + else + Result := ''; +end; + +function TJvDEFColorSpace.GetPrettyName(Index: Integer): string; +begin + Result := FDelphiColors.Values[FDelphiColors.Names[Index]]; +end; + +function TJvDEFColorSpace.GetColorValue(Index: Integer): TColor; +begin + if (Index >= 0) and (Index < FDelphiColors.Count) then + Result := TColor(FDelphiColors.Objects[Index]) + else + Result := clNone; +end; + +function TJvDEFColorSpace.GetName: string; +begin + Result := RsDEF_FullName; +end; + +function TJvDEFColorSpace.GetShortName: string; +begin + Result := RsDEF_ShortName; +end; + +function TJvDEFColorSpace.GetNumberOfColors: Cardinal; +begin + Result := FDelphiColors.Count; +end; + +//=== { TJvColorSpaceManager } =============================================== + +constructor TJvColorSpaceManager.Create; +begin + inherited Create; + FColorSpaceList := TList.Create; +end; + +destructor TJvColorSpaceManager.Destroy; +var + Index: Integer; +begin + for Index := 0 to FColorSpaceList.Count - 1 do + TJvColorSpace(FColorSpaceList.Items[Index]).Free; + FColorSpaceList.Free; + inherited Destroy; +end; + +function TJvColorSpaceManager.ConvertToID(AColor: TJvFullColor; + DestID: TJvFullColorSpaceID): TJvFullColor; +var + SourceID: TJvFullColorSpaceID; + Color: TColor; +begin + SourceID := GetColorSpaceID(AColor); + if SourceID = DestID then + Result := AColor + else + begin + Color := ColorToRGB(ColorSpace[SourceID].ConvertToColor(AColor)); + Result := ColorSpace[DestID].ConvertFromColor(Color); + end; +end; + +function TJvColorSpaceManager.ConvertToColor(AColor: TJvFullColor): TColor; +begin + Result := ColorSpace[GetColorSpaceID(AColor)].ConvertToColor(AColor); +end; + +function TJvColorSpaceManager.ConvertFromColor(AColor: TColor): TJvFullColor; +var + MaskedColor:Cardinal; +begin + MaskedColor := Cardinal(AColor) and JvSystemColorMask; + if (AColor = clNone) or (AColor = clDefault) or + (MaskedColor = JvSystemColorMask) then + Result := ColorSpace[csDEF].ConvertFromColor(AColor) + else + if MaskedColor = 0 then + Result := ColorSpace[csRGB].ConvertFromColor(AColor) + else + raise EJvColorSpaceError.CreateResFmt(@RsEInconvertibleColor, [Cardinal(AColor)]); +end; + +function TJvColorSpaceManager.GetColorSpaceID(AColor: TJvFullColor): TJvFullColorSpaceID; +var + I: Integer; +begin + Result := TJvFullColorSpaceID(AColor shr 24) and csID_MASK; + for I := 0 to Count - 1 do + if ColorSpaceByIndex[I].ID = Result then + Exit; + raise EJvColorSpaceError.CreateResFmt(@RsEIllegalID, [Ord(Result)]); +end; + +function TJvColorSpaceManager.GetColorSpace(ID: TJvFullColorSpaceID): TJvColorSpace; +var + I: Integer; +begin + Result := nil; + for I := 0 to FColorSpaceList.Count - 1 do + begin + Result := TJvColorSpace(FColorSpaceList.Items[I]); + if Result.ID = ID then + Break; + end; + if Result = nil then + raise EJvColorSpaceError.CreateResFmt(@RsECSNotFound, [Ord(ID)]); +end; + +function TJvColorSpaceManager.GetCount: Integer; +begin + Result := FColorSpaceList.Count; +end; + +function TJvColorSpaceManager.GetColorSpaceByIndex(Index: Integer): TJvColorSpace; +begin + Result := TJvColorSpace(FColorSpaceList.Items[Index]); +end; + +procedure TJvColorSpaceManager.RegisterColorSpace(NewColorSpace: TJvColorSpace); +var + Index: Integer; + CS: TJvColorSpace; +begin + for Index := 0 to FColorSpaceList.Count - 1 do + begin + CS := TJvColorSpace(FColorSpaceList.Items[Index]); + if CS.ID = NewColorSpace.ID then + raise EJvColorSpaceError.CreateResFmt(@RsECSAlreadyExists, [CS.ID, CS.Name]); + end; + FColorSpaceList.Add(Pointer(NewColorSpace)); +end; + +procedure TJvColorSpaceManager.UnRegisterColorSpace(AColorSpace: TJvColorSpace); +begin + // maybe more than one instance of one class + while FColorSpaceList.Remove(AColorSpace) >= 0 do + ; +end; + +initialization + +finalization + FreeAndNil(GlobalColorSpaceManager); + +end.