From 9c17ab1e6f2d9334c11c34d46b302149a80f5bee Mon Sep 17 00:00:00 2001 From: tombo Date: Thu, 14 Jun 2007 12:08:41 +0000 Subject: [PATCH] Carbon intf: implemented setting pixel color of TCanvas git-svn-id: trunk@11322 - --- lcl/interfaces/carbon/carboncanvas.pp | 27 +++++++++++++++++++++++++- lcl/interfaces/carbon/carbonobject.inc | 7 ++++--- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/lcl/interfaces/carbon/carboncanvas.pp b/lcl/interfaces/carbon/carboncanvas.pp index 3ac25d3982..b4af670a95 100644 --- a/lcl/interfaces/carbon/carboncanvas.pp +++ b/lcl/interfaces/carbon/carboncanvas.pp @@ -31,7 +31,7 @@ uses // carbon bindings FPCMacOSAll, // LCL - LCLProc, LCLType, Graphics, Controls, Forms, + LCLProc, LCLType, Graphics, GraphType, Controls, Forms, // LCL Carbon CarbonDef, CarbonGDIObjects; @@ -115,6 +115,7 @@ type procedure Polygon(Points: PPoint; NumPts: Integer; Winding: boolean); procedure Polyline(Points: PPoint; NumPts: Integer); procedure Rectangle(X1, Y1, X2, Y2: Integer); + procedure SetPixel(X, Y: Integer; AColor: TGraphicsColor); function StretchDraw(X, Y, Width, Height: Integer; SrcDC: TCarbonBitmapContext; XSrc, YSrc, SrcWidth, SrcHeight: Integer; Rop: DWORD): Boolean; public @@ -1167,6 +1168,30 @@ begin CGContextDrawPath(CGContext, kCGPathFillStroke); end; +{------------------------------------------------------------------------------ + Method: TCarbonDeviceContext.SetPixel + Params: X, Y - Position + AColor - New color for specified position + + Sets the color of the specified pixel on the canvas + ------------------------------------------------------------------------------} +procedure TCarbonDeviceContext.SetPixel(X, Y: Integer; AColor: TGraphicsColor); +var + R, G, B: Byte; +begin + CGContextSaveGState(CGContext); + try + // apply color to fill + CGContextSetBlendMode(CGContext, kCGBlendModeNormal); + RedGreenBlue(ColorToRGB(AColor), R, G, B); + CGContextSetRGBFillColor(CGContext, R / 255, G / 255, B / 255, 1.0); + + CGContextFillRect(CGContext, GetCGRect(X, Y, X + 1, Y + 1)); + finally + CGContextRestoreGState(CGContext); + end; +end; + {------------------------------------------------------------------------------ Method: StretchMaskBlt Params: X, Y - Left/top corner of the destination rectangle diff --git a/lcl/interfaces/carbon/carbonobject.inc b/lcl/interfaces/carbon/carbonobject.inc index 471e09a7e4..3da1f5b0b1 100644 --- a/lcl/interfaces/carbon/carbonobject.inc +++ b/lcl/interfaces/carbon/carbonobject.inc @@ -707,7 +707,6 @@ end; AColor - New color for specified position Sets the color of the specified pixel on the canvas - Not implemented! ------------------------------------------------------------------------------} procedure TCarbonWidgetSet.DCSetPixel(CanvasHandle: HDC; X, Y: integer; AColor: TGraphicsColor); @@ -715,8 +714,10 @@ begin {$IFDEF VerboseObject} DebugLn('TCarbonWidgetSet.DCSetPixel DC: ' + DbgS(CanvasHandle) + ' X: ' + DbgS(X) + ' Y: ' + DbgS(Y) + 'Color: ' + DbgS(AColor)); {$ENDIF} - - DebugLn('TCarbonWidgetSet.DCSetPixel TODO'); + + if not CheckDC(CanvasHandle, 'DCSetPixel') then Exit; + + TCarbonDeviceContext(CanvasHandle).SetPixel(X, Y, AColor); end; {------------------------------------------------------------------------------