GR32.Paint.Host.API.pas 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. unit GR32.Paint.Host.API;
  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_Layers,
  38. GR32.Paint.Tool.API;
  39. //------------------------------------------------------------------------------
  40. //
  41. // Paint tool settings
  42. //
  43. //------------------------------------------------------------------------------
  44. // Not presently implemented.
  45. // Moved to GR32.Paint.Settings.API
  46. //------------------------------------------------------------------------------
  47. type
  48. ISettingValues = interface
  49. end;
  50. //------------------------------------------------------------------------------
  51. //
  52. // IBitmap32PaintHost
  53. //
  54. //------------------------------------------------------------------------------
  55. // Handles coordinate space conversion, colors, layers, cursor, etc.
  56. //------------------------------------------------------------------------------
  57. // Provides the paint tools with an interface to the host application environment.
  58. //------------------------------------------------------------------------------
  59. type
  60. IBitmap32PaintHost = interface
  61. ['{D51C1D86-A06D-4E3C-95B4-9F70ADD7A9DF}']
  62. function GetPaintLayer: TBitmapLayer;
  63. procedure SetPaintLayer(const Value: TBitmapLayer);
  64. property PaintLayer: TBitmapLayer read GetPaintLayer write SetPaintLayer;
  65. // TODO : Move to PaintController
  66. function GetColorPrimary: TColor32;
  67. procedure SetColorPrimary(const Value: TColor32);
  68. function GetColorSecondary: TColor32;
  69. procedure SetColorSecondary(const Value: TColor32);
  70. property ColorPrimary: TColor32 read GetColorPrimary write SetColorPrimary;
  71. property ColorSecondary: TColor32 read GetColorSecondary write SetColorSecondary;
  72. function GetMagnification: Single;
  73. procedure SetMagnification(const Value: Single);
  74. property Magnification: Single read GetMagnification write SetMagnification;
  75. function ViewPortToScreen(const APoint: TPoint): TPoint;
  76. function ScreenToViewPort(const APoint: TPoint): TPoint;
  77. function ViewPortToBitmap(const APoint: TPoint; SnapToNearest: boolean = True): TPoint; overload;
  78. function ViewPortToBitmap(const APoint: TFloatPoint): TFloatPoint; overload;
  79. function BitmapToViewPort(const APoint: TPoint): TPoint;
  80. function GetToolSettings(const AToolKey: string): ISettingValues;
  81. // CreateToolContext creates a new tool context object.
  82. // It is the responsibility of the caller to initialize and maintain the returned object with context values.
  83. function CreateToolContext(const APaintTool: IBitmap32PaintTool): IBitmap32PaintToolContext;
  84. // Changed: Called from tools. Used for undo management.
  85. procedure Changed(const Action: string);
  86. end;
  87. //------------------------------------------------------------------------------
  88. //
  89. // Optional host features
  90. //
  91. //------------------------------------------------------------------------------
  92. type
  93. (*
  94. Cursor management:
  95. Controller.SetPaintTool
  96. If existing tool <> nil:
  97. - Host.ShowToolCursor(False, False)
  98. If new tool <> nil:
  99. - PaintTool.GetCursor
  100. - Host.SetToolVectorCursor
  101. - Host.SetToolCursor
  102. - Host.ShowToolCursor(True, False)
  103. Controller.MouseEnter
  104. - Host.ShowToolCursor(True, True)
  105. Controller.MouseExit
  106. - Host.ShowToolCursor(False, True)
  107. Controller.MouseMove
  108. - Host.MoveToolVectorCursor
  109. *)
  110. IBitmap32PaintFeatureCursor = interface
  111. ['{04D7D5D7-4367-4250-942E-314C2BAD8D7A}']
  112. // If TransientChange is True, ShowToolCursor controls transient cursor
  113. // visibility. This is mainly used to temporarily hide the tool vector
  114. // cursor when the mouse cursor moves out of the host control.
  115. // If TransientChange is False, ShowToolCursor controls the platform
  116. // hardware cursor. It does not change the visiblity of the cursor but
  117. // instead controls if the cursor is the tool cursor (SHow=True) or the
  118. // default cursor (Show=False).
  119. procedure ShowToolCursor(Show, ATransientChange: Boolean);
  120. // Set the current tool cursor.
  121. // If the crDefault cursor is specified then the host TImage32 cursor
  122. // will be used instead.
  123. procedure SetToolCursor(NewCursor: TCursor);
  124. end;
  125. // Complex cursors
  126. IBitmap32PaintFeatureVectorCursor = interface
  127. ['{06CEC909-5267-4537-8F2E-F9D31EAF99CA}']
  128. // SetToolVectorCursor: Called from IBitmap32PaintTool.GetCursor to set complex cursors.
  129. function SetToolVectorCursor(const Polygon: TArrayOfFixedPoint; const Hotspot: TPoint; Color: TColor32 = clTrBlack32; const StipplePattern: TArrayOfColor32 = []): boolean;
  130. procedure MoveToolVectorCursor(const APos: TPoint);
  131. end;
  132. //------------------------------------------------------------------------------
  133. //------------------------------------------------------------------------------
  134. //------------------------------------------------------------------------------
  135. implementation
  136. //------------------------------------------------------------------------------
  137. end.