MainUnit.pas 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. unit MainUnit;
  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 Rotation Layer Example
  23. *
  24. * The Initial Developer of the Original Code is
  25. * Alex A. Denisov
  26. *
  27. * Portions created by the Initial Developer are Copyright (C) 2000-2005
  28. * the Initial Developer. All Rights Reserved.
  29. *
  30. * Contributor(s):
  31. * Michael Hansen <[email protected]>
  32. * - 2007/03/02 - pamTransparentEdge setup, minor GUI changes, image loading
  33. *
  34. * ***** END LICENSE BLOCK ***** *)
  35. interface
  36. {$include GR32.inc}
  37. uses
  38. {$IFNDEF FPC} Windows, {$ELSE} LCLIntf, LResources, LCLType, Variants, {$ENDIF}
  39. SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, GR32,
  40. GR32_Image, GR32_RotLayer, GR32_Transforms, GR32_RangeBars, GR32_Resamplers;
  41. type
  42. TFormRotLayer = class(TForm)
  43. CbxScaled: TCheckBox;
  44. GbrAngle: TGaugeBar;
  45. GbrPositionX: TGaugeBar;
  46. GbrPositionY: TGaugeBar;
  47. GbrScale: TGaugeBar;
  48. ImgView: TImgView32;
  49. LblAngle: TLabel;
  50. LblPositionX: TLabel;
  51. LblPositionY: TLabel;
  52. LblScale: TLabel;
  53. procedure FormCreate(Sender: TObject);
  54. procedure GbrAngleChange(Sender: TObject);
  55. procedure GbrPositionChange(Sender: TObject);
  56. procedure GbrScaleChange(Sender: TObject);
  57. procedure CbxScaledClick(Sender: TObject);
  58. public
  59. L: TRotLayer;
  60. end;
  61. var
  62. FormRotLayer: TFormRotLayer;
  63. implementation
  64. {$R *.dfm}
  65. uses
  66. {$IFDEF Darwin}
  67. MacOSAll,
  68. {$ENDIF}
  69. Math,
  70. Types,
  71. GR32.ImageFormats.PNG32,
  72. GR32.ImageFormats.JPG;
  73. { TFormRotLayer }
  74. procedure TFormRotLayer.FormCreate(Sender: TObject);
  75. begin
  76. // load example image
  77. ImgView.Bitmap.LoadFromResourceName(HInstance, 'Delphi', RT_RCDATA);
  78. L := TRotLayer.Create(ImgView.Layers);
  79. L.Bitmap := TBitmap32.Create;
  80. with L.Bitmap do
  81. begin
  82. BeginUpdate;
  83. L.Bitmap.LoadFromResourceName(HInstance, 'Texture', 'PNG');
  84. TLinearResampler.Create(L.Bitmap);
  85. //ensure good looking edge, dynamic alternative to SetBorderTransparent
  86. TCustomResampler(L.Bitmap.Resampler).PixelAccessMode := pamTransparentEdge;
  87. L.BitmapCenter := FloatPoint(Width * 0.5, Height * 0.5);
  88. MasterAlpha := 200;
  89. FrameRectS(BoundsRect, $FFFFFFFF);
  90. DrawMode := dmBlend;
  91. EndUpdate;
  92. Changed;
  93. end;
  94. L.Scaled := True;
  95. L.Position := FloatPoint(100, 100);
  96. end;
  97. procedure TFormRotLayer.GbrAngleChange(Sender: TObject);
  98. begin
  99. L.Angle := GbrAngle.Position;
  100. end;
  101. procedure TFormRotLayer.GbrPositionChange(Sender: TObject);
  102. var
  103. P: TFloatPoint;
  104. begin
  105. P := L.Position;
  106. P.X := GbrPositionX.Position;
  107. P.Y := GbrPositionY.Position;
  108. L.Position := P;
  109. end;
  110. procedure TFormRotLayer.GbrScaleChange(Sender: TObject);
  111. begin
  112. ImgView.Scale := Power(10, GbrScale.Position * 0.01);
  113. end;
  114. procedure TFormRotLayer.CbxScaledClick(Sender: TObject);
  115. begin
  116. L.Scaled := not L.Scaled;
  117. end;
  118. end.