diff options
author | Graeme Geldenhuys <graeme@mastermaths.co.za> | 2010-04-29 10:56:45 +0200 |
---|---|---|
committer | Graeme Geldenhuys <graeme@mastermaths.co.za> | 2010-04-29 10:56:45 +0200 |
commit | 2bc72af1ccadad45bbc07b81cb22fe1b7ec01252 (patch) | |
tree | a0f45bacdebafed40ddcab872d4292966e5a0024 | |
parent | 8c67847e50cb1b2f9fd5ffdc59f2309ab05bd4a5 (diff) | |
download | fpGUI-2bc72af1ccadad45bbc07b81cb22fe1b7ec01252.tar.xz |
TRGBTriple conflicts with a declaration in the Windows unit.
* I introduced a new record type TFPColor (same as the declaration
in the FPImage unit. I also introduced new conversion functions
that work with TFPColor.
* I marked the TRGBTriple type as deprecated.
* I replaced all TRGBTriple usage with TFPColor.
-rw-r--r-- | src/corelib/fpg_base.pas | 68 | ||||
-rw-r--r-- | src/corelib/fpg_wuline.pas | 6 | ||||
-rw-r--r-- | src/gui/colordialog.inc | 8 | ||||
-rw-r--r-- | src/gui/fpg_colormapping.pas | 8 | ||||
-rw-r--r-- | src/gui/fpg_gauge.pas | 14 |
5 files changed, 65 insertions, 39 deletions
diff --git a/src/corelib/fpg_base.pas b/src/corelib/fpg_base.pas index b3595300..08075076 100644 --- a/src/corelib/fpg_base.pas +++ b/src/corelib/fpg_base.pas @@ -40,6 +40,14 @@ type Green: word; Blue: word; Alpha: word; + end deprecated; + + // Same declaration as in FPImage unit, but we don't use FPImage yet, so declare it here + TFPColor = record + Red: word; + Green: word; + Blue: word; + Alpha: word; end; TWindowType = (wtChild, wtWindow, wtModalForm, wtPopup); @@ -600,8 +608,10 @@ function KeycodeToText(AKey: Word; AShiftState: TShiftState): string; function CheckClipboardKey(AKey: Word; AShiftstate: TShiftState): TClipboardKeyType; { Color } -function fpgColorToRGBTriple(const AColor: TfpgColor): TRGBTriple; -function RGBTripleTofpgColor(const AColor: TRGBTriple): TfpgColor; +function fpgColorToRGBTriple(const AColor: TfpgColor): TRGBTriple; deprecated; +function fpgColorToFPColor(const AColor: TfpgColor): TFPColor; +function RGBTripleTofpgColor(const AColor: TRGBTriple): TfpgColor; deprecated; +function FPColorTofpgColor(const AColor: TFPColor): TfpgColor; function fpgGetRed(const AColor: TfpgColor): word; function fpgGetGreen(const AColor: TfpgColor): word; function fpgGetBlue(const AColor: TfpgColor): word; @@ -806,7 +816,7 @@ begin end { if/else } end; -function fpgColorToRGBTriple(const AColor: TfpgColor): TRGBTriple; +function fpgColorToRGBTriple(const AColor: TfpgColor): TRGBTriple; deprecated; begin with Result do begin @@ -817,7 +827,23 @@ begin end end; -function RGBTripleTofpgColor(const AColor: TRGBTriple): TfpgColor; +function fpgColorToFPColor(const AColor: TfpgColor): TFPColor; +begin + with Result do + begin + Red := fpgGetRed(AColor); + Green := fpgGetGreen(AColor); + Blue := fpgGetBlue(AColor); +// Alpha := fpgGetAlpha(AColor); + end +end; + +function RGBTripleTofpgColor(const AColor: TRGBTriple): TfpgColor; deprecated; +begin + Result := AColor.Blue or (AColor.Green shl 8) or (AColor.Red shl 16);// or (AColor.Alpha shl 32); +end; + +function FPColorTofpgColor(const AColor: TFPColor): TfpgColor; begin Result := AColor.Blue or (AColor.Green shl 8) or (AColor.Red shl 16);// or (AColor.Alpha shl 32); end; @@ -860,16 +886,16 @@ end; function fpgGetAvgColor(const AColor1, AColor2: TfpgColor): TfpgColor; var - c1, c2: TRGBTriple; - avg: TRGBTriple; + c1, c2: TFPColor; + avg: TFPColor; begin - c1 := fpgColorToRGBTriple(AColor1); - c2 := fpgColorToRGBTriple(AColor2); + c1 := fpgColorToFPColor(AColor1); + c2 := fpgColorToFPColor(AColor2); avg.Red := c1.Red + (c2.Red - c1.Red) div 2; avg.Green := c1.Green + (c2.Green - c1.Green) div 2; avg.Blue := c1.Blue + (c2.Blue - c1.Blue) div 2; avg.Alpha := c1.Alpha + (c2.Alpha - c1.Alpha) div 2; - Result := RGBTripleTofpgColor(avg); + Result := FPColorTofpgColor(avg); end; function PtInRect(const ARect: TfpgRect; const APoint: TPoint): Boolean; @@ -1455,15 +1481,15 @@ end; procedure TfpgCanvasBase.GradientFill(ARect: TfpgRect; AStart, AStop: TfpgColor; ADirection: TGradientDirection); var - RGBStart: TRGBTriple; - RGBStop: TRGBTriple; + RGBStart: TFPColor; + RGBStop: TFPColor; RDiff, GDiff, BDiff: Integer; count: Integer; i: Integer; - newcolor: TRGBTriple; + newcolor: TFPColor; begin - RGBStart := fpgColorToRGBTriple(fpgColorToRGB(AStart)); - RGBStop := fpgColorToRGBTriple(fpgColorToRGB(AStop)); + RGBStart := fpgColorToFPColor(fpgColorToRGB(AStart)); + RGBStop := fpgColorToFPColor(fpgColorToRGB(AStop)); if ADirection = gdVertical then count := ARect.Bottom - ARect.Top @@ -1480,7 +1506,7 @@ begin newcolor.Red := RGBStart.Red + (i * RDiff) div count; newcolor.Green := RGBStart.Green + (i * GDiff) div count; newcolor.Blue := RGBStart.Blue + (i * BDiff) div count; - SetColor(RGBTripleTofpgColor(newcolor)); + SetColor(FPColorTofpgColor(newcolor)); // We have to overshoot by 1 pixel as DrawLine paints 1 pixel short (by design) if ADirection = gdHorizontal then @@ -1689,7 +1715,7 @@ var contributions: array[0..10] of TfpgInterpolationContribution; dif, w, gamma, a: double; c: TfpgColor; - rgb: TRGBTriple; + rgb: TFPColor; begin for x := 0 to Width - 1 do begin @@ -1733,7 +1759,7 @@ begin with contributions[r] do begin c := image.colors[place, y]; - rgb := fpgColorToRGBTriple(c); + rgb := fpgColorToFPColor(c); a := weight; // * rgb.Alpha / $FFFF; re := re + a * rgb.Red; gr := gr + a * rgb.Green; @@ -1747,7 +1773,7 @@ begin blue := ColorRound(bl); // alpha := ColorRound(gamma * $FFFF); end; - tempimage.colors[x, y] := RGBTripleTofpgColor(rgb); + tempimage.colors[x, y] := FPColorTofpgColor(rgb); end; end; end; @@ -1760,7 +1786,7 @@ var contributions: array[0..10] of TfpgInterpolationContribution; dif, w, gamma, a: double; c: TfpgColor; - rgb: TRGBTriple; + rgb: TFPColor; begin for y := 0 to Height - 1 do begin @@ -1804,7 +1830,7 @@ begin with contributions[r] do begin c := tempimage.colors[x, place]; - rgb := fpgColorToRGBTriple(c); + rgb := fpgColorToFPColor(c); a := weight;// * rgb.alpha / $FFFF; re := re + a * rgb.red; gr := gr + a * rgb.green; @@ -1818,7 +1844,7 @@ begin blue := ColorRound(bl); // alpha := ColorRound(gamma * $FFFF); end; - Canvas.Pixels[x + dx, y + dy] := RGBTripleTofpgColor(rgb); + Canvas.Pixels[x + dx, y + dy] := FPColorTofpgColor(rgb); end; end; end; diff --git a/src/corelib/fpg_wuline.pas b/src/corelib/fpg_wuline.pas index a67714f1..cfed0a73 100644 --- a/src/corelib/fpg_wuline.pas +++ b/src/corelib/fpg_wuline.pas @@ -44,7 +44,7 @@ type // Blend a pixel with the current colour procedure AlphaBlendPixel(ACanvas: TfpgCanvas; X, Y: integer; R, G, B: word; ARatio: Double); var - LBack, LNew: TRGBTriple; + LBack, LNew: TFPColor; LMinusRatio: Double; begin if (X < 0) or (X > TCanvasHack(ACanvas).FWindow.Width - 1) or (Y < 0) or @@ -52,11 +52,11 @@ begin Exit; // clipping LMinusRatio := 1 - ARatio; - LBack := fpgColorToRGBTriple(ACanvas.Pixels[X, Y]); + LBack := fpgColorToFPColor(ACanvas.Pixels[X, Y]); LNew.Blue := round(B*ARatio + LBack.Blue*LMinusRatio); LNew.Green := round(G*ARatio + LBack.Green*LMinusRatio); LNew.Red := round(R*ARatio + LBack.Red*LMinusRatio); - ACanvas.Pixels[X, Y] := RGBTripleTofpgColor(LNew); + ACanvas.Pixels[X, Y] := FPColorTofpgColor(LNew); end; // Draw a anti-aliased line diff --git a/src/gui/colordialog.inc b/src/gui/colordialog.inc index 6f7576be..5fd30d96 100644 --- a/src/gui/colordialog.inc +++ b/src/gui/colordialog.inc @@ -101,25 +101,25 @@ end; procedure TfpgColorSelectDialog.RGBChanged(Sender: TObject); var - rgb: TRGBTriple; + rgb: TFPColor; c: TfpgColor; begin FViaRGB := True; // prevent recursive updates rgb.Red := edR.Value; rgb.Green := edG.Value; rgb.Blue := edB.Value; - c := RGBTripleTofpgColor(rgb); + c := FPColorTofpgColor(rgb); ColorWheel.SetSelectedColor(c); // This will trigger ColorWheel and ValueBar OnChange event FViaRGB := False; end; procedure TfpgColorSelectDialog.UpdateRGBComponents; var - rgb: TRGBTriple; + rgb: TFPColor; c: TfpgColor; begin c := ValueBar.SelectedColor; - rgb := fpgColorToRGBTriple(c); + rgb := fpgColorToFPColor(c); edR.Value := rgb.Red; edG.Value := rgb.Green; edB.Value := rgb.Blue; diff --git a/src/gui/fpg_colormapping.pas b/src/gui/fpg_colormapping.pas index d5a412c3..b915bd93 100644 --- a/src/gui/fpg_colormapping.pas +++ b/src/gui/fpg_colormapping.pas @@ -45,9 +45,9 @@ var r, g, b: longint; hi, lo: longint; d: longint; - rgb: TRGBTriple; + rgb: TFPColor; begin - rgb := fpgColorToRGBTriple(C); + rgb := fpgColorToFPColor(C); r := rgb.Red; g := rgb.Green; b := rgb.Blue; @@ -78,7 +78,7 @@ end; function HSVToRGB(const H: longint; const S, V: double): TfpgColor; var r, g, b: longint; - rgb: TRGBTriple; + rgb: TFPColor; begin if (h < 0) or (h > 1535) or (S < 0) or (S > 1) or (V < 0) or (V > 1) then begin @@ -130,7 +130,7 @@ begin rgb.Red := r; rgb.Green := g; rgb.Blue := b; - Result := RGBTripleTofpgColor(rgb); + Result := FPColorTofpgColor(rgb); end; diff --git a/src/gui/fpg_gauge.pas b/src/gui/fpg_gauge.pas index 2236e912..37a154c6 100644 --- a/src/gui/fpg_gauge.pas +++ b/src/gui/fpg_gauge.pas @@ -115,22 +115,22 @@ uses to be moved in CanvasBase? } procedure FillArcGradient(canvas: TfpgCanvas; X,Y,W,H: TfpgCoord; a1,a2: double; Astart,Astop: TfpgColor); var - RGBStart: TRGBTriple; - RGBStop: TRGBTriple; + RGBStart: TFPColor; + RGBStop: TFPColor; RDiff, GDiff, BDiff: Integer; count: Integer; i: Integer; - newcolor: TRGBTriple; + newcolor: TFPColor; begin - if Astart = Astop then + if Astart = Astop then begin { No gradient, just solid color} canvas.SetColor(Astart); canvas.FillArc(X, Y, W, H, a1, a2); Exit; //==> end; - RGBStart := fpgColorToRGBTriple(fpgColorToRGB(AStart)); - RGBStop := fpgColorToRGBTriple(fpgColorToRGB(AStop)); + RGBStart := fpgColorToFPColor(fpgColorToRGB(AStart)); + RGBStop := fpgColorToFPColor(fpgColorToRGB(AStop)); count := min(H,W); count := count div 2; @@ -156,7 +156,7 @@ begin newcolor.Red := RGBStart.Red + (i * RDiff) div count; newcolor.Green := RGBStart.Green + (i * GDiff) div count; newcolor.Blue := RGBStart.Blue + (i * BDiff) div count; - canvas.SetColor(RGBTripleTofpgColor(newcolor)); + canvas.SetColor(FPColorTofpgColor(newcolor)); canvas.DrawArc(X, Y, W, H, a1, a2); end; end; |