fpimgcanv.pp 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 2003 by the Free Pascal development team
  4. Image Canvas - canvas which draws on an image.
  5. See the file COPYING.FPC, included in this distribution,
  6. for details about the copyright.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. **********************************************************************}
  11. {$mode objfpc}{$h+}
  12. unit FPImgCanv;
  13. interface
  14. uses FPPixlCanv, FPImage, classes;
  15. type
  16. TFPImageCanvas = class (TFPPixelCanvas)
  17. private
  18. FImage : TFPCustomImage;
  19. protected
  20. procedure SetColor (x,y:integer; const AValue:TFPColor); override;
  21. function GetColor (x,y:integer) : TFPColor; override;
  22. procedure SetHeight (AValue : integer); override;
  23. function GetHeight : integer; override;
  24. procedure SetWidth (AValue : integer); override;
  25. function GetWidth : integer; override;
  26. public
  27. constructor create (AnImage : TFPCustomImage);
  28. destructor destroy; override;
  29. property Image : TFPCustomImage read FImage write FImage;
  30. end;
  31. implementation
  32. uses clipping;
  33. constructor TFPImageCanvas.create (AnImage : TFPCustomImage);
  34. begin
  35. inherited Create;
  36. FImage := AnImage;
  37. end;
  38. destructor TFPImageCanvas.destroy;
  39. begin
  40. inherited destroy;
  41. end;
  42. procedure TFPImageCanvas.SetColor (x,y:integer; const AValue:TFPColor);
  43. begin
  44. if (x >= 0) and (x < width) and (y >= 0) and (y < height) then
  45. if not clipping or PointInside (x,y, ClipRect) then
  46. FImage.Colors[x,y] := AValue;
  47. end;
  48. function TFPImageCanvas.GetColor (x,y:integer) : TFPColor;
  49. begin
  50. if (x >= 0) and (x < width) and (y >= 0) and (y < height) then
  51. result := FImage.Colors[x,y]
  52. else
  53. result := colTransparent;
  54. end;
  55. procedure TFPImageCanvas.SetHeight (AValue : integer);
  56. begin
  57. FImage.Height := AValue;
  58. end;
  59. function TFPImageCanvas.GetHeight : integer;
  60. begin
  61. result := FImage.Height;
  62. end;
  63. procedure TFPImageCanvas.SetWidth (AValue : integer);
  64. begin
  65. FImage.Width := AValue;
  66. end;
  67. function TFPImageCanvas.GetWidth : integer;
  68. begin
  69. result := FImage.Width;
  70. end;
  71. end.