Changeset 317 for GraphicTest/UMainForm.pas
- Timestamp:
- Feb 1, 2012, 3:02:33 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GraphicTest/UMainForm.pas
r212 r317 20 20 21 21 TMainForm = class(TForm) 22 ButtonStop: TButton; 22 23 ButtonBenchmark: TButton; 23 ButtonStart: TButton; 24 ButtonStop: TButton; 25 ComboBox1: TComboBox; 24 ButtonSingleTest: TButton; 26 25 FloatSpinEdit1: TFloatSpinEdit; 27 26 Image1: TImage; 28 27 Label1: TLabel; 29 28 Label2: TLabel; 30 Label3: TLabel; 31 Label4: TLabel; 32 Label5: TLabel; 33 ListView1: TListView; 29 ListViewMethods: TListView; 34 30 PageControl1: TPageControl; 35 31 PaintBox1: TPaintBox; … … 39 35 Timer1: TTimer; 40 36 procedure ButtonBenchmarkClick(Sender: TObject); 41 procedure ButtonS tartClick(Sender: TObject);37 procedure ButtonSingleTestClick(Sender: TObject); 42 38 procedure ButtonStopClick(Sender: TObject); 43 39 procedure FormClose(Sender: TObject; var CloseAction: TCloseAction); 44 40 procedure FormCreate(Sender: TObject); 45 41 procedure FormDestroy(Sender: TObject); 42 procedure FormShow(Sender: TObject); 43 procedure ListViewMethodsData(Sender: TObject; Item: TListItem); 44 procedure ListViewMethodsSelectItem(Sender: TObject; Item: TListItem; 45 Selected: Boolean); 46 46 procedure Timer1Timer(Sender: TObject); 47 47 private … … 50 50 TextureData: Pointer; 51 51 MethodIndex: Integer; 52 SingleTestActive: Boolean; 53 AllTestActive: Boolean; 52 54 procedure OpenGLControl1Resize(Sender: TObject); 53 55 procedure InitGL; 56 procedure UpdateMethodList; 57 procedure UpdateInterface; 54 58 public 55 59 DrawMethods: TObjectList; // TObjectList<TDrawMethod> … … 86 90 Bitmap.PixelFormat := pf24bit; 87 91 Image1.Picture.Bitmap.SetSize(TFastBitmap(Scenes[0]).Size.X, TFastBitmap(Scenes[0]).Size.Y); 92 Image1.Picture.Bitmap.PixelFormat := pf32bit; 88 93 Bitmap.SetSize(TFastBitmap(Scenes[0]).Size.X, TFastBitmap(Scenes[0]).Size.Y); 89 94 … … 100 105 101 106 DrawMethods := TObjectList.Create; 102 ComboBox1.Clear;103 107 for I := 0 to High(DrawMethodClasses) do begin 104 108 NewDrawMethod := DrawMethodClasses[I].Create; … … 109 113 NewDrawMethod.Init; 110 114 DrawMethods.Add(NewDrawMethod); 111 ComboBox1.Items.Add(NewDrawMethod.Caption); 112 end; 113 ComboBox1.ItemIndex := DrawMethods.Count - 1; 114 end; 115 116 procedure TMainForm.ButtonStartClick(Sender: TObject); 117 begin 118 MethodIndex := ComboBox1.ItemIndex; 119 ButtonStop.Enabled := True; 120 ButtonStart.Enabled := False; 121 Timer1.Enabled := True; 122 if MethodIndex >= 0 then 123 with TDrawMethod(DrawMethods[MethodIndex]) do begin 124 PageControl1.TabIndex := Integer(PaintObject); 125 Application.ProcessMessages; 126 repeat 127 DrawFrameTiming(TFastBitmap(Scenes[SceneIndex])); 128 SceneIndex := (SceneIndex + 1) mod Scenes.Count; 115 end; 116 end; 117 118 procedure TMainForm.ButtonSingleTestClick(Sender: TObject); 119 begin 120 try 121 SingleTestActive := True; 122 UpdateInterface; 123 Timer1.Enabled := True; 124 MethodIndex := ListViewMethods.Selected.Index; 125 Timer1.Enabled := True; 126 if MethodIndex >= 0 then 127 with TDrawMethod(DrawMethods[MethodIndex]) do begin 128 PageControl1.TabIndex := Integer(PaintObject); 129 129 Application.ProcessMessages; 130 until not ButtonStop.Enabled; 131 end; 132 ButtonStopClick(Self); 130 repeat 131 DrawFrameTiming(TFastBitmap(Scenes[SceneIndex])); 132 SceneIndex := (SceneIndex + 1) mod Scenes.Count; 133 Application.ProcessMessages; 134 until not SingleTestActive; 135 end; 136 finally 137 Timer1.Enabled := False; 138 SingleTestActive := False; 139 UpdateInterface; 140 end; 133 141 end; 134 142 135 143 procedure TMainForm.ButtonBenchmarkClick(Sender: TObject); 136 144 var 137 NewItem: TListItem;138 145 I: Integer; 139 146 C: Integer; 140 147 StartTime: TDateTime; 141 148 begin 142 Timer1.Enabled := True;143 with ListView1, Items do144 149 try 145 //BeginUpdate; 146 Clear; 150 AllTestActive := True; 151 UpdateInterface; 152 Timer1.Enabled := True; 153 with ListViewMethods, Items do 147 154 for I := 0 to DrawMethods.Count - 1 do 148 155 with TDrawMethod(DrawMethods[I]) do begin … … 154 161 SceneIndex := (SceneIndex + 1) mod Scenes.Count; 155 162 Application.ProcessMessages; 156 until (NowPrecise - StartTime) > OneSecond * FloatSpinEdit1.Value; 157 NewItem := Add; 158 NewItem.Caption := Caption; 159 NewItem.SubItems.Add(FloatToStr(RoundTo(FrameDuration / OneMillisecond, -3))); 160 NewItem.SubItems.Add(FloatToStr(RoundTo(1 / (FrameDuration / OneSecond), -3))); 163 until ((NowPrecise - StartTime) > OneSecond * FloatSpinEdit1.Value) or not AllTestActive; 161 164 end; 162 165 finally 163 //EndUpdate; 166 Timer1.Enabled := False; 167 AllTestActive := False; 168 UpdateInterface; 164 169 end; 165 170 end; … … 167 172 procedure TMainForm.ButtonStopClick(Sender: TObject); 168 173 begin 169 ButtonStart.Enabled := True;170 ButtonStop.Enabled:= False;174 SingleTestActive := False; 175 AllTestActive := False; 171 176 end; 172 177 … … 184 189 end; 185 190 191 procedure TMainForm.FormShow(Sender: TObject); 192 begin 193 UpdateMethodList; 194 UpdateInterface; 195 end; 196 197 procedure TMainForm.ListViewMethodsData(Sender: TObject; Item: TListItem); 198 begin 199 if (Item.Index >= 0) and (Item.Index < DrawMethods.Count) then 200 with TDrawMethod(DrawMethods[Item.Index]) do begin 201 Item.Caption := Caption; 202 if FrameDuration > 0 then 203 Item.SubItems.Add(FloatToStr(RoundTo(1 / (FrameDuration / OneSecond), -3))) 204 else Item.SubItems.Add('0'); 205 Item.SubItems.Add(FloatToStr(RoundTo(FrameDuration / OneMillisecond, -3)) + ' ms'); 206 end; 207 end; 208 209 procedure TMainForm.ListViewMethodsSelectItem(Sender: TObject; Item: TListItem; 210 Selected: Boolean); 211 begin 212 UpdateInterface; 213 end; 214 186 215 procedure TMainForm.Timer1Timer(Sender: TObject); 187 216 begin 188 if (MethodIndex >= 0) then 189 with TDrawMethod(DrawMethods[MethodIndex]) do begin 190 if (FrameDuration > 0) then 191 Label2.Caption := FloatToStr(RoundTo(1 / (FrameDuration / OneSecond), -3)) 192 else Label2.Caption := '0'; 193 Label4.Caption := FloatToStr(RoundTo(FrameDuration / OneMillisecond, -3)) + ' ms'; 194 end; 217 UpdateMethodList; 195 218 end; 196 219 … … 220 243 end; 221 244 245 procedure TMainForm.UpdateMethodList; 246 begin 247 ListViewMethods.Items.Count := DrawMethods.Count; 248 ListViewMethods.Refresh; 249 end; 250 251 procedure TMainForm.UpdateInterface; 252 begin 253 ButtonSingleTest.Enabled := not SingleTestActive and not AllTestActive and Assigned(ListViewMethods.Selected); 254 ButtonBenchmark.Enabled := not AllTestActive and not SingleTestActive; 255 ButtonStop.Enabled := SingleTestActive or AllTestActive; 256 end; 257 222 258 end. 223 259
Note:
See TracChangeset
for help on using the changeset viewer.