/Source/FR_SHAPE.PAS

http://github.com/FastReports/FreeReport · Pascal · 200 lines · 153 code · 33 blank · 14 comment · 3 complexity · edde00a03bebcf289297ccbcedd3c0fc MD5 · raw file

  1. {*****************************************}
  2. { }
  3. { FastReport v2.3 }
  4. { Checkbox Add-In Object }
  5. { }
  6. { Copyright (c) 1998-99 by Tzyganenko A. }
  7. { }
  8. {*****************************************}
  9. unit FR_Shape;
  10. interface
  11. {$I FR.inc}
  12. uses
  13. Windows, Messages, SysUtils, Classes, Graphics, FR_Class, StdCtrls,
  14. Controls, ExtCtrls, Menus;
  15. const
  16. skRectangle = 0;
  17. skRoundRectangle = 1;
  18. skEllipse = 2;
  19. skTriangle = 3;
  20. type
  21. TfrShapeObject = class(TComponent) // fake component
  22. end;
  23. TfrShapeView = class(TfrView)
  24. private
  25. procedure DrawShape;
  26. public
  27. ShapeType: Byte;
  28. constructor Create; override;
  29. procedure Assign(From: TfrView); override;
  30. procedure Draw(Canvas: TCanvas); override;
  31. procedure LoadFromStream(Stream: TStream); override;
  32. procedure SaveToStream(Stream: TStream); override;
  33. procedure SaveToFR3Stream(Stream: TStream); override;
  34. procedure DefinePopupMenu(Popup: TPopupMenu); override;
  35. end;
  36. TfrShapeForm = class(TfrObjEditorForm)
  37. GroupBox1: TGroupBox;
  38. CB1: TComboBox;
  39. Button1: TButton;
  40. Button2: TButton;
  41. Image1: TImage;
  42. procedure FormCreate(Sender: TObject);
  43. private
  44. { Private declarations }
  45. public
  46. { Public declarations }
  47. procedure ShowEditor(t: TfrView); override;
  48. end;
  49. implementation
  50. uses FR_Utils, FR_Const;
  51. {$R *.DFM}
  52. var
  53. ShapeForm: TfrShapeForm;
  54. constructor TfrShapeView.Create;
  55. begin
  56. inherited Create;
  57. Typ := gtAddIn;
  58. ShapeType := skRectangle;
  59. BaseName := 'Shape';
  60. end;
  61. procedure TfrShapeView.Assign(From: TfrView);
  62. begin
  63. inherited Assign(From);
  64. ShapeType := TfrShapeView(From).ShapeType;
  65. end;
  66. procedure TfrShapeView.DrawShape;
  67. var
  68. x1, y1, min: Integer;
  69. begin
  70. x1 := Round((SaveX + SaveDX) * ScaleX + OffsX);
  71. y1 := Round((SaveY + SaveDY) * ScaleY + OffsY);
  72. min := dx;
  73. if dy < dx then
  74. min := dy;
  75. with Canvas do
  76. begin
  77. Pen.Width := Round(FrameWidth);
  78. Pen.Color := FrameColor;
  79. Pen.Style := psSolid;
  80. Brush.Style := bsClear;
  81. Brush.Color := FillColor;
  82. case ShapeType of
  83. skRectangle:
  84. Rectangle(x, y, x1 + 1, y1 + 1);
  85. skRoundRectangle:
  86. RoundRect(x, y, x1 + 1, y1 + 1, min div 4, min div 4);
  87. skEllipse:
  88. Ellipse(x, y, x1 + 1, y1 + 1);
  89. skTriangle:
  90. begin
  91. MoveTo(x1, y1);
  92. LineTo(x, y1);
  93. LineTo(x + (x1 - x) div 2, y);
  94. LineTo(x1, y1);
  95. FloodFill(x + (x1 - x) div 2, y + (y1 - y) div 2, clNone, fsSurface);
  96. end;
  97. end;
  98. end;
  99. end;
  100. procedure TfrShapeView.Draw(Canvas: TCanvas);
  101. var
  102. FillC: Integer;
  103. begin
  104. BeginDraw(Canvas);
  105. Memo1.Assign(Memo);
  106. CalcGaps;
  107. FillC := FillColor;
  108. FillColor := clNone;
  109. FrameTyp := 0;
  110. ShowBackground;
  111. FillColor := FillC;
  112. DrawShape;
  113. RestoreCoord;
  114. end;
  115. procedure TfrShapeView.LoadFromStream(Stream: TStream);
  116. begin
  117. inherited LoadFromStream(Stream);
  118. Stream.Read(ShapeType, 1);
  119. end;
  120. procedure TfrShapeView.SaveToStream(Stream: TStream);
  121. begin
  122. inherited SaveToStream(Stream);
  123. Stream.Write(ShapeType, 1);
  124. end;
  125. procedure TfrShapeView.DefinePopupMenu(Popup: TPopupMenu);
  126. begin
  127. // no specific items in popup menu
  128. end;
  129. {------------------------------------------------------------------------}
  130. procedure TfrShapeForm.ShowEditor(t: TfrView);
  131. var
  132. i: Integer;
  133. begin
  134. CB1.Items.Clear;
  135. for i := 0 to 3 do
  136. CB1.Items.Add(LoadStr(SShape1 + i));
  137. with TfrShapeView(t) do
  138. begin
  139. CB1.ItemIndex := ShapeType;
  140. if ShowModal = mrOk then
  141. ShapeType := CB1.ItemIndex;
  142. end;
  143. end;
  144. procedure TfrShapeForm.FormCreate(Sender: TObject);
  145. begin
  146. Caption := LoadStr(frRes + 620);
  147. GroupBox1.Caption := LoadStr(frRes + 621);
  148. Button1.Caption := LoadStr(SOk);
  149. Button2.Caption := LoadStr(SCancel);
  150. end;
  151. procedure TfrShapeView.SaveToFR3Stream(Stream: TStream);
  152. procedure WriteStr(const s: String);
  153. begin
  154. Stream.Write(s[1], Length(s));
  155. end;
  156. begin
  157. inherited;
  158. WriteStr(' Shape="' + IntToStr(ShapeType) + '"');
  159. end;
  160. initialization
  161. ShapeForm := TfrShapeForm.Create(nil);
  162. frRegisterObject(TfrShapeView, ShapeForm.Image1.Picture.Bitmap,
  163. LoadStr(SInsShape), ShapeForm);
  164. finalization
  165. ShapeForm.Free;
  166. ShapeForm := nil;
  167. end.