utoolicon.pas 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // SPDX-License-Identifier: GPL-3.0-only
  2. unit UToolIcon;
  3. {$mode objfpc}{$H+}
  4. interface
  5. uses
  6. Classes, SysUtils, utool, BGRABitmapTypes, BGRABitmap, UImage;
  7. type
  8. { TCursorHotspotTool }
  9. TCursorHotspotTool = class(TReadonlyTool)
  10. protected
  11. function DoToolDown({%H-}toolDest: TBGRABitmap; pt: TPoint; {%H-}ptF: TPointF;
  12. {%H-}rightBtn: boolean): TRect; override;
  13. function GetStatusText: string; override;
  14. public
  15. function GetContextualToolbars: TContextualToolbars; override;
  16. function Render(VirtualScreen: TBGRABitmap; VirtualScreenWidth,
  17. VirtualScreenHeight: integer;
  18. BitmapToVirtualScreen: TBitmapToVirtualScreenFunction): TRect; override;
  19. end;
  20. implementation
  21. uses UGraph, UResourceStrings, LazPaintType;
  22. { TCursorHotspotTool }
  23. function TCursorHotspotTool.DoToolDown(toolDest: TBGRABitmap; pt: TPoint;
  24. ptF: TPointF; rightBtn: boolean): TRect;
  25. begin
  26. Manager.Image.CursorHotSpot := pt;
  27. result := OnlyRenderChange;
  28. end;
  29. function TCursorHotspotTool.GetStatusText: string;
  30. begin
  31. Result:= rsHotSpot + '|x = ' + IntToStr(Manager.Image.CursorHotSpot.X)+'|y = '+IntToStr(Manager.Image.CursorHotSpot.Y);
  32. end;
  33. function TCursorHotspotTool.GetContextualToolbars: TContextualToolbars;
  34. begin
  35. Result:= [];
  36. end;
  37. function TCursorHotspotTool.Render(VirtualScreen: TBGRABitmap;
  38. VirtualScreenWidth, VirtualScreenHeight: integer;
  39. BitmapToVirtualScreen: TBitmapToVirtualScreenFunction): TRect;
  40. var
  41. hotspotPos: TPointF;
  42. begin
  43. hotspotPos := BitmapToVirtualScreen(PointF(Manager.Image.CursorHotSpot.X,Manager.Image.CursorHotSpot.Y));
  44. result := NicePoint(VirtualScreen, hotspotPos.X,hotspotPos.Y);
  45. if hotspotPos.Y > virtualScreenHeight/2 then
  46. result := RectUnion(result,NiceText(VirtualScreen, round(hotspotPos.X),round(hotspotPos.Y-6), VirtualScreenWidth,VirtualScreenHeight, rsHotSpot, taCenter, tlBottom))
  47. else
  48. result := RectUnion(result,NiceText(VirtualScreen, round(hotspotPos.X),round(hotspotPos.Y+6), VirtualScreenWidth,VirtualScreenHeight, rsHotSpot, taCenter, tlTop));
  49. end;
  50. initialization
  51. RegisterTool(ptHotSpot, TCursorHotspotTool);
  52. end.