summaryrefslogtreecommitdiff
path: root/examples/gui/wulinetest/wuline_test.lpr
blob: a726d84385f70cb465641989a66cca6c249acac8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
program wuline_test;

{$mode objfpc}{$H+}

uses
  {$IFDEF UNIX}{$IFDEF UseCThreads}
  cthreads,
  {$ENDIF}{$ENDIF}
  Classes, SysUtils,
  fpg_base, fpg_main, fpg_form, fpg_button, math,
  fpg_imgfmt_bmp, fpg_wuline, fpg_panel, fpg_radiobutton;

type

  { TMainForm }

  TMainForm = class(TfpgForm)
  private
    {@VFD_HEAD_BEGIN: MainForm}
    btnQuit: TfpgButton;
    pnlName1: TfpgBevel;
    rbSpokes: TfpgRadioButton;
    rbLines: TfpgRadioButton;
    rbSpiral: TfpgRadioButton;
    {@VFD_HEAD_END: MainForm}
    procedure   btnQuitClicked(Sender: TObject);
    procedure   DrawSpokes(phase: double);
    procedure   DrawSpiral;
    procedure   DrawLines;
    procedure   RadioButtonChanged(Sender: TObject);
  protected
    procedure   HandlePaint; override;
  public
    procedure   AfterCreate; override;
  end;

{@VFD_NEWFORM_DECL}

{ TMainForm }

procedure TMainForm.RadioButtonChanged(Sender: TObject);
begin
  RePaint;
end;

procedure TMainForm.HandlePaint;
begin
  inherited HandlePaint;

  if rbSpokes.Checked then
    DrawSpokes(0)
  else if rbLines.Checked then
    DrawLines
  else if rbSpiral.Checked then
    DrawSpiral;
end;

procedure TMainForm.btnQuitClicked(Sender: TObject);
begin
  Close;
end;

// Generates spokes. Animates them using phase.
procedure TMainForm.DrawSpokes(phase: double);
var
  x1, y1, x2, y2: integer;
  theta: double;
begin
  theta := phase;
  while theta < (360+phase) do
  begin
		x1 := trunc(100.0*cos(theta*3.14/180.0)+355.0);
		y1 := trunc(-100.0*sin(theta*3.14/180.0)+155.0);

		x2 := trunc(20.0*cos(theta*3.14/180.0)+355.0);
		y2 := trunc(-20.0*sin(theta*3.14/180.0)+155.0);

		WuLine(Canvas, Point(x1, y1), Point(x2, y2), clBlack);
		Canvas.DrawLine(x2-240, y2, x1-240, y1);

    theta := theta + 10;
  end;
end;

procedure TMainForm.DrawSpiral;
var
  Theta: double;
  X1, Y1, X2, Y2: integer;
begin
  X1 := 300;
  Y1 := 100;
  Theta := 0;

  while Theta < 15 * 3.1415926535 do
  begin
    X2 := trunc(X1 + Cos(Theta) * Theta);
    Y2 := trunc(Y1 + Sin(Theta) * Theta);
    WuLine(Canvas, Point(X1, Y1), Point(X2, Y2), clBlack);
    Theta := Theta + 0.2;
    X1 := X2;
    Y1 := Y2;
  end;

end;

procedure TMainForm.DrawLines;
begin
  WuLine(Canvas, Point(10, 35), Point(280, 180), clBlack);
  Canvas.SetColor(clBlack);
  Canvas.DrawLine(10, 45, 280, 190);
end;

procedure TMainForm.AfterCreate;
begin
  {@VFD_BODY_BEGIN: MainForm}
  Name := 'MainForm';
  SetPosition(278, 186, 600, 312);
  WindowTitle := 'fpGUI Wu Anti-Aliased Line test';
  WindowPosition := wpScreenCenter;
  Sizeable := False;

  btnQuit := TfpgButton.Create(self);
  with btnQuit do
  begin
    Name := 'btnQuit';
    SetPosition(500, 280, 90, 24);
    Anchors := [anRight,anBottom];
    Text := 'Quit';
    FontDesc := '#Label1';
    ImageName := '';
    OnClick := @btnQuitClicked;
  end;

  pnlName1 := TfpgBevel.Create(self);
  with pnlName1 do
  begin
    Name := 'pnlName1';
    SetPosition(436, 8, 156, 76);
  end;

  rbSpokes := TfpgRadioButton.Create(pnlName1);
  with rbSpokes do
  begin
    Name := 'rbSpokes';
    SetPosition(12, 28, 120, 19);
    FontDesc := '#Label1';
    GroupIndex := 1;
    TabOrder := 2;
    Text := 'Spokes';
    OnChange := @RadioButtonChanged;
  end;

  rbLines := TfpgRadioButton.Create(pnlName1);
  with rbLines do
  begin
    Name := 'rbLines';
    SetPosition(12, 8, 120, 19);
    Checked := True;
    FontDesc := '#Label1';
    GroupIndex := 1;
    TabOrder := 1;
    Text := 'Lines';
    OnChange := @RadioButtonChanged;
  end;

  rbSpiral := TfpgRadioButton.Create(pnlName1);
  with rbSpiral do
  begin
    Name := 'rbSpiral';
    SetPosition(12, 48, 120, 19);
    FontDesc := '#Label1';
    GroupIndex := 1;
    TabOrder := 3;
    Text := 'Spiral';
    OnChange := @RadioButtonChanged;
  end;

  {@VFD_BODY_END: MainForm}
end;


{@VFD_NEWFORM_IMPL}



procedure MainProc;
var
  frm: TMainForm;
begin
  fpgApplication.Initialize;
  frm := TMainForm.Create(nil);
  try
    frm.Show;
    fpgApplication.Run;
  finally
    frm.Free;
  end;
end;


begin
  MainProc;
end.