GR32.Paint.ToolContext.pas 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. unit GR32.Paint.ToolContext;
  2. (* ***** BEGIN LICENSE BLOCK *****
  3. * Version: MPL 1.1 or LGPL 2.1 with linking exception
  4. *
  5. * The contents of this file are subject to the Mozilla Public License Version
  6. * 1.1 (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. * http://www.mozilla.org/MPL/
  9. *
  10. * Software distributed under the License is distributed on an "AS IS" basis,
  11. * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  12. * for the specific language governing rights and limitations under the
  13. * License.
  14. *
  15. * Alternatively, the contents of this file may be used under the terms of the
  16. * Free Pascal modified version of the GNU Lesser General Public License
  17. * Version 2.1 (the "FPC modified LGPL License"), in which case the provisions
  18. * of this license are applicable instead of those above.
  19. * Please see the file LICENSE.txt for additional information concerning this
  20. * license.
  21. *
  22. * The Original Code is Paint tools for Graphics32
  23. *
  24. * The Initial Developer of the Original Code is
  25. * Anders Melander, [email protected]
  26. *
  27. * Portions created by the Initial Developer are Copyright (C) 2008-2025
  28. * the Initial Developer. All Rights Reserved.
  29. *
  30. * ***** END LICENSE BLOCK ***** *)
  31. interface
  32. {$INCLUDE GR32.inc}
  33. uses
  34. Classes,
  35. Controls,
  36. GR32,
  37. GR32.Paint.Host.API,
  38. GR32.Paint.Tool.API;
  39. //------------------------------------------------------------------------------
  40. //
  41. // TBitmap32PaintToolContext
  42. //
  43. //------------------------------------------------------------------------------
  44. // Minimal, example implementation of IBitmap32PaintToolContext
  45. //------------------------------------------------------------------------------
  46. type
  47. TBitmap32PaintToolContext = class(TInterfacedObject, IBitmap32PaintToolContext)
  48. private
  49. FPaintHost: IBitmap32PaintHost;
  50. FPaintTool: IBitmap32PaintTool;
  51. FBuffer: TBitmap32;
  52. FMouseParams: TBitmap32PaintToolMouseParams;
  53. private
  54. // IBitmap32PaintToolContext
  55. function GetPaintTool: IBitmap32PaintTool;
  56. function GetBuffer: TBitmap32;
  57. function GetMouseParams: PBitmap32PaintToolMouseParams;
  58. procedure Update(const ViewPortPos: TPoint; SnapMouse: boolean);
  59. public
  60. constructor Create(const APaintHost: IBitmap32PaintHost; const APaintTool: IBitmap32PaintTool; ABuffer: TBitmap32);
  61. end;
  62. //------------------------------------------------------------------------------
  63. //------------------------------------------------------------------------------
  64. //------------------------------------------------------------------------------
  65. implementation
  66. uses
  67. Types;
  68. //------------------------------------------------------------------------------
  69. //
  70. // TBitmap32PaintToolContext
  71. //
  72. //------------------------------------------------------------------------------
  73. constructor TBitmap32PaintToolContext.Create(const APaintHost: IBitmap32PaintHost; const APaintTool: IBitmap32PaintTool; ABuffer: TBitmap32);
  74. begin
  75. inherited Create;
  76. FPaintHost := APaintHost;
  77. FPaintTool := APaintTool;
  78. FBuffer := ABuffer;
  79. FMouseParams := Default(TBitmap32PaintToolMouseParams);
  80. end;
  81. function TBitmap32PaintToolContext.GetPaintTool: IBitmap32PaintTool;
  82. begin
  83. Result := FPaintTool;
  84. end;
  85. function TBitmap32PaintToolContext.GetBuffer: TBitmap32;
  86. begin
  87. Result := FBuffer;
  88. end;
  89. function TBitmap32PaintToolContext.GetMouseParams: PBitmap32PaintToolMouseParams;
  90. begin
  91. Result := @FMouseParams;
  92. end;
  93. procedure TBitmap32PaintToolContext.Update(const ViewPortPos: TPoint; SnapMouse: boolean);
  94. begin
  95. FMouseParams.ViewPortPos := ViewPortPos;
  96. FMouseParams.ScreenPos := FPaintHost.ViewPortToScreen(ViewPortPos);
  97. FMouseParams.BitmapPosFloat := FPaintHost.ViewPortToBitmap(FloatPoint(ViewPortPos));
  98. // If SnapMouse=True then we only return the snapped coordinates
  99. FMouseParams.BitmapPos := FPaintHost.ViewPortToBitmap(ViewPortPos, SnapMouse);
  100. FMouseParams.BitmapPosSnap := FPaintHost.ViewPortToBitmap(ViewPortPos, True);
  101. end;
  102. //------------------------------------------------------------------------------
  103. end.