fpimgcanv.pp 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. protected
  18. FImage : TFPCustomImage;
  19. procedure SetColor (x,y:integer; const AValue:TFPColor); override;
  20. function GetColor (x,y:integer) : TFPColor; override;
  21. procedure SetHeight (AValue : integer); override;
  22. function GetHeight : integer; override;
  23. procedure SetWidth (AValue : integer); override;
  24. function GetWidth : integer; override;
  25. public
  26. constructor create (AnImage : TFPCustomImage);
  27. destructor destroy; override;
  28. property Image : TFPCustomImage read FImage write FImage;
  29. end;
  30. implementation
  31. uses clipping;
  32. constructor TFPImageCanvas.create (AnImage : TFPCustomImage);
  33. begin
  34. inherited Create;
  35. FImage := AnImage;
  36. end;
  37. destructor TFPImageCanvas.destroy;
  38. begin
  39. inherited destroy;
  40. end;
  41. procedure TFPImageCanvas.SetColor (x,y:integer; const AValue:TFPColor);
  42. begin
  43. if (x >= 0) and (x < width) and (y >= 0) and (y < height) then
  44. if not clipping or PointInside (x,y, ClipRect) then
  45. FImage.Colors[x,y] := AValue;
  46. end;
  47. function TFPImageCanvas.GetColor (x,y:integer) : TFPColor;
  48. begin
  49. if (x >= 0) and (x < width) and (y >= 0) and (y < height) then
  50. result := FImage.Colors[x,y]
  51. else
  52. result := colTransparent;
  53. end;
  54. procedure TFPImageCanvas.SetHeight (AValue : integer);
  55. begin
  56. FImage.Height := AValue;
  57. end;
  58. function TFPImageCanvas.GetHeight : integer;
  59. begin
  60. result := FImage.Height;
  61. end;
  62. procedure TFPImageCanvas.SetWidth (AValue : integer);
  63. begin
  64. FImage.Width := AValue;
  65. end;
  66. function TFPImageCanvas.GetWidth : integer;
  67. begin
  68. result := FImage.Width;
  69. end;
  70. end.