//--------------------------------------------------------------------------- #include #pragma hdrstop #include "PCMY.h" #pragma package(smart_init) //--------------------------------------------------------------------------- // ValidCtrCheck is used to assure that the components created do not have // any pure virtual functions. // static inline void ValidCtrCheck(TPCMY *) { new TPCMY(NULL); } //--------------------------------------------------------------------------- ///// Private Method ///////////////////////////////////////////////////// //--------------------------------------------------------------------------- void __fastcall TPCMY::CalculatePosition() { if (FKind == Horizontal) { FUnit = Height / 8; FCRect = Rect(5, 0, Width - 5, 2*FUnit); FMRect = Rect(5, 3*FUnit, Width - 5, 5*FUnit); FYRect = Rect(5, 6*FUnit, Width - 5, 8*FUnit); FRange = Width - 10; } else { FUnit = Width / 8; FCRect = Rect(0, 5, 2*FUnit, Height - 5); FMRect = Rect(3*FUnit, 5, 5*FUnit, Height - 5); FYRect = Rect(6*FUnit, 5, 8*FUnit, Height - 5); FRange = Height - 10; } } //--------------------------------------------------------------------------- void __fastcall TPCMY::SetColor(TColor Value) { if (FColor != Value) { FColor = Value; FCyan = 255 - GetRValue(FColor); cstr = AnsiString(GetPercentage(FCyan)) + "\%"; FMagenta = 255 - GetGValue(FColor); mstr = AnsiString(GetPercentage(FMagenta)) + "\%"; FYellow = 255 - GetBValue(FColor); ystr = AnsiString(GetPercentage(FYellow)) + "\%"; Refresh(); if (FOnColorChange) FOnColorChange(this); if (FOnCyanChange) FOnCyanChange(this); if (FOnMagentaChange) FOnMagentaChange(this); if (FOnYellowChange) FOnYellowChange(this); } } //--------------------------------------------------------------------------- void __fastcall TPCMY::SetCyan(int Value) { if (FCyan != Value) { if (FCyan >= 0 && FCyan <= 255) { FCyan = Value; cstr = AnsiString(GetPercentage(Value + 0.5)) + "\%"; ChangeColor(); CyanPaint(); if (FOnCyanChange) FOnCyanChange(this); } } } //--------------------------------------------------------------------------- void __fastcall TPCMY::SetMagenta(int Value) { if (FMagenta != Value) { if (FMagenta >= 0 && FMagenta <= 255) { FMagenta = Value; mstr = AnsiString(GetPercentage(Value + 0.5)) + "\%"; ChangeColor(); MagentaPaint(); if (FOnMagentaChange) FOnMagentaChange(this); } } } //--------------------------------------------------------------------------- void __fastcall TPCMY::SetYellow(int Value) { if (FYellow != Value) { if (FYellow >= 0 && FMagenta <= 255) { FYellow = Value; ystr = AnsiString(GetPercentage(Value + 0.5)) + "\%"; ChangeColor(); YellowPaint(); if (FOnYellowChange) FOnYellowChange(this); } } } //--------------------------------------------------------------------------- void __fastcall TPCMY::SetCMYKind(TKindCMY Value) { if (FKind != Value) { FKind = Value; Refresh(); } } //--------------------------------------------------------------------------- int __fastcall TPCMY::GetLength(int Value) { return (Value * FRange / 255) + 5; } //--------------------------------------------------------------------------- int __fastcall TPCMY::GetPercentage(int Value) { return (Value * 100 / 255) + 0.5; } //--------------------------------------------------------------------------- void __fastcall TPCMY::CyanMove(POINT p) { int x; if (bCyan) { if (FKind == Horizontal) { x = p.x - 5; if (x<0) x = 0; else if (x > FRange) x = FRange; FCyan = (x*255 / FRange); } else { x = p.y - 5; if (x<0) x = 0; else if (x > FRange) x = FRange; FCyan = ((FRange-x)*255 / FRange); } cstr = AnsiString(GetPercentage(FCyan)) + "\%"; ChangeColor(); CyanPaint(); } } //--------------------------------------------------------------------------- void __fastcall TPCMY::MagentaMove(POINT p) { int x; if (bMagenta) { if (FKind == Horizontal) { x = p.x - 5; if (x<0) x = 0; else if (x > FRange) x = FRange; FMagenta = (x*255 / FRange); } else { x = p.y - 5; if (x<0) x = 0; else if (x > FRange) x = FRange; FMagenta = ((FRange - x)*255 / FRange); } mstr = AnsiString(GetPercentage(FMagenta)) + "\%"; ChangeColor(); MagentaPaint(); } } //--------------------------------------------------------------------------- void __fastcall TPCMY::YellowMove(POINT p) { int x; if (bYellow) { if (FKind == Horizontal) { x = p.x - 5; if (x<0) x = 0; else if (x > FRange) x = FRange; FYellow = (x*255 / FRange); } else { x = p.y - 5; if (x<0) x = 0; else if (x > FRange) x = FRange; FYellow = ((FRange-x)*255 / FRange); } ystr = AnsiString(GetPercentage(FYellow)) + "\%"; ChangeColor(); YellowPaint(); } } //--------------------------------------------------------------------------- void __fastcall TPCMY::ChangeColor() { FColor = (TColor)((255-FCyan) | (255-FMagenta)<<8 | (255-FYellow)<<16); if (FOnColorChange) FOnColorChange(this); } //--------------------------------------------------------------------------- void __fastcall TPCMY::CyanPaint() { int len = GetLength(FCyan); int x, y; TextBmp->Canvas->Font = this->Font; if (FKind == Horizontal) { Canvas->Brush->Color = clAqua; Canvas->Rectangle(FCRect.left, FCRect.top, len, FCRect.bottom); Canvas->Brush->Color = clWhite; if (len == 5) Canvas->Rectangle(len, FCRect.top, FRange + 5, FCRect.bottom); else Canvas->Rectangle(len - 1, FCRect.top, FRange + 5, FCRect.bottom); TextBmp->Canvas->TextRect(Rect(0, 0, TextBmp->Width, TextBmp->Height), 0, 0, cstr); Canvas->CopyMode = cmSrcAnd; x = (FRange-Canvas->TextWidth(cstr))/2; y = (2*FUnit-10)/2; Canvas->CopyRect(Rect(x, y, x+TextBmp->Width, y+TextBmp->Height), TextBmp->Canvas, Rect(0, 0, TextBmp->Width, TextBmp->Height)); } else { Canvas->Brush->Color = clWhite; Canvas->Rectangle(FCRect.left, FCRect.top, FCRect.right, Height - len); Canvas->Brush->Color = clAqua; if ((Height - len) == 5) Canvas->Rectangle(FCRect.left, Height - len, FCRect.right, FCRect.bottom); else Canvas->Rectangle(FCRect.left, Height - len -1, FCRect.right, FCRect.bottom); TextBmp->Canvas->TextRect(Rect(0, 0, TextBmp->Width, TextBmp->Height), 0, 0, cstr); Canvas->CopyMode = cmSrcAnd; x = (2*FUnit-Canvas->TextWidth(cstr))/2; y = (FRange-10)/2; Canvas->CopyRect(Rect(x, y, x+TextBmp->Width, y+TextBmp->Height), TextBmp->Canvas, Rect(0, 0, TextBmp->Width, TextBmp->Height)); } } //--------------------------------------------------------------------------- void __fastcall TPCMY::MagentaPaint() { int len = GetLength(FMagenta); int x, y; TextBmp->Canvas->Font = this->Font; if (FKind == Horizontal) { Canvas->Brush->Color = clFuchsia; Canvas->Rectangle(FMRect.left, FMRect.top, len, FMRect.bottom); Canvas->Brush->Color = clWhite; if (len == 5) Canvas->Rectangle(len, FMRect.top, FRange + 5, FMRect.bottom); else Canvas->Rectangle(len-1, FMRect.top, FRange + 5, FMRect.bottom); TextBmp->Canvas->TextRect(Rect(0, 0, TextBmp->Width, TextBmp->Height), 0, 0, mstr); Canvas->CopyMode = cmSrcAnd; x = (FRange-Canvas->TextWidth(mstr))/2; y = 3*FUnit+(2*FUnit-10)/2; Canvas->CopyRect(Rect(x, y, x+TextBmp->Width, y+TextBmp->Height), TextBmp->Canvas, Rect(0, 0, TextBmp->Width, TextBmp->Height)); } else { Canvas->Brush->Color = clWhite; Canvas->Rectangle(FMRect.left, FMRect.top, FMRect.right, Height - len); Canvas->Brush->Color = clFuchsia; if ((Height - len) == 5) Canvas->Rectangle(FMRect.left, Height - len, FMRect.right, FMRect.bottom); else Canvas->Rectangle(FMRect.left, Height - len - 1, FMRect.right, FMRect.bottom); TextBmp->Canvas->TextRect(Rect(0, 0, TextBmp->Width, TextBmp->Height), 0, 0, mstr); Canvas->CopyMode = cmSrcAnd; x = 3*FUnit+(2*FUnit-Canvas->TextWidth(mstr))/2; y = (FRange-10)/2; Canvas->CopyRect(Rect(x, y, x+TextBmp->Width, y+TextBmp->Height), TextBmp->Canvas, Rect(0, 0, TextBmp->Width, TextBmp->Height)); } } //--------------------------------------------------------------------------- void __fastcall TPCMY::YellowPaint() { int len = GetLength(FYellow); int x, y; TextBmp->Canvas->Font = this->Font; if (FKind == Horizontal) { Canvas->Brush->Color = clYellow; Canvas->Rectangle(FYRect.left, FYRect.top, len, FYRect.bottom); Canvas->Brush->Color = clWhite; if (len == 5) Canvas->Rectangle(len, FYRect.top, FRange+5, FYRect.bottom); else Canvas->Rectangle(len-1, FYRect.top, FRange+5, FYRect.bottom); TextBmp->Canvas->TextRect(Rect(0, 0, TextBmp->Width, TextBmp->Height), 0, 0, ystr); Canvas->CopyMode = cmSrcAnd; x = (FRange-Canvas->TextWidth(ystr))/2; y = 6*FUnit+(2*FUnit-10)/2; Canvas->CopyRect(Rect(x, y, x+TextBmp->Width, y+TextBmp->Height), TextBmp->Canvas, Rect(0, 0, TextBmp->Width, TextBmp->Height)); } else { Canvas->Brush->Color = clWhite; Canvas->Rectangle(FYRect.left, FYRect.top, FYRect.right, Height - len); Canvas->Brush->Color = clYellow; if ((Height - len) == 5) Canvas->Rectangle(FYRect.left, Height - len, FYRect.right, FYRect.bottom); else Canvas->Rectangle(FYRect.left, Height - len - 1, FYRect.right, FYRect.bottom); TextBmp->Canvas->TextRect(Rect(0, 0, TextBmp->Width, TextBmp->Height), 0, 0, ystr); Canvas->CopyMode = cmSrcAnd; x = 6*FUnit+(2*FUnit-Canvas->TextWidth(ystr))/2; y = (FRange-10)/2; Canvas->CopyRect(Rect(x, y, x+TextBmp->Width, y+TextBmp->Height), TextBmp->Canvas, Rect(0, 0, TextBmp->Width, TextBmp->Height)); } } //--------------------------------------------------------------------------- bool __fastcall TPCMY::PointInRect(RECT rect, POINT p) { return ((rect.left <= p.x) && (rect.right >= p.x) && (rect.top <= p.y) && (rect.bottom >= p.y)); } //--------------------------------------------------------------------------- ///// Protected Method ///////////////////////////////////////////////////// //--------------------------------------------------------------------------- void __fastcall TPCMY::Paint() { CalculatePosition(); Canvas->Pen->Color = clBlack; CyanPaint(); MagentaPaint(); YellowPaint(); } //--------------------------------------------------------------------------- ///// Public Method ///////////////////////////////////////////////////// //--------------------------------------------------------------------------- __fastcall TPCMY::TPCMY(TComponent* Owner) : TGraphicControl(Owner) { bCyan = bMagenta = bYellow = false; Width = 300; Height = 150; FCyan = 0; FMagenta = 0; FYellow = 0; cstr = "0%"; mstr = "0%"; ystr = "0%"; TextBmp = new Graphics::TBitmap; TextBmp->PixelFormat = pf24bit; TextBmp->Width = TextBmp->Canvas->TextWidth("100 %"); TextBmp->Height = TextBmp->Canvas->TextHeight("100 %"); TextBmp->Canvas->Brush->Color = clWhite; TextBmp->Canvas->FillRect(Rect(0, 0, TextBmp->Width, TextBmp->Height)); } //--------------------------------------------------------------------------- __fastcall TPCMY::~TPCMY() { delete TextBmp; } //--------------------------------------------------------------------------- void __fastcall TPCMY::WMLBUTTONDOWN(TMessage &msg) { POINT p = Point(msg.LParamLo, msg.LParamHi); if (PointInRect(FCRect, p)) { bCyan = true; bMagenta = false; bYellow = false; } else if (PointInRect(FMRect, p)) { bCyan = false; bMagenta = true; bYellow = false; } else if (PointInRect(FYRect, p)) { bCyan = false; bMagenta = false; bYellow = true; } } //--------------------------------------------------------------------------- void __fastcall TPCMY::WMMOUSEMOVE(TMessage &msg) { POINT p = Point(msg.LParamLo, msg.LParamHi); if (FKind == Horizontal) { if (p.x < 5) p.x = 5; else if (p.x > (FRange + 5)) p.x = FRange + 5; } else { if (p.y < 5) p.y = 5; else if (p.y > (FRange + 5)) p.y = FRange + 5; } if (PointInRect(FCRect, p)) { CyanMove(p); if (FOnCyanChange) FOnCyanChange(this); } else if (PointInRect(FMRect, p)) { MagentaMove(p); if (FOnMagentaChange) FOnMagentaChange(this); } else if (PointInRect(FYRect, p)) { YellowMove(p); if (FOnYellowChange) FOnYellowChange(this); } } //--------------------------------------------------------------------------- void __fastcall TPCMY::WMLBUTTONUP(TMessage &msg) { bCyan = false; bMagenta = false; bYellow = false; } //--------------------------------------------------------------------------- namespace Pcmy { void __fastcall PACKAGE Register() { TComponentClass classes[1] = {__classid(TPCMY)}; RegisterComponents("Texpia", classes, 0); } } //---------------------------------------------------------------------------