Ignore:
Timestamp:
Nov 22, 2012, 12:28:54 PM (12 years ago)
Author:
chronos
Message:
  • Modified: Draw frame moved to separated form without TPageControl. Each draw method is responsible for creating own TWinControl visual control.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • GraphicTest/UMainForm.pas

    r442 r443  
    88  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ComCtrls,
    99  ExtCtrls, StdCtrls, DateUtils, UPlatform, LCLType, IntfGraphics, fpImage,
    10   Math, GraphType, Contnrs, LclIntf, Spin, UFastBitmap, UDrawMethod
    11   {$IFDEF opengl}, GL, OpenGLContext{$ENDIF};
     10  Math, GraphType, Contnrs, LclIntf, Spin, UFastBitmap, UDrawMethod;
    1211
    1312const
     
    2423    ButtonSingleTest: TButton;
    2524    FloatSpinEdit1: TFloatSpinEdit;
    26     Image1: TImage;
    2725    Label1: TLabel;
    2826    Label2: TLabel;
    2927    ListViewMethods: TListView;
    30     PageControl1: TPageControl;
    31     PaintBox1: TPaintBox;
    32     TabSheet1: TTabSheet;
    33     TabSheet2: TTabSheet;
    34     TabSheet3: TTabSheet;
    3528    Timer1: TTimer;
    3629    procedure ButtonBenchmarkClick(Sender: TObject);
    3730    procedure ButtonSingleTestClick(Sender: TObject);
    3831    procedure ButtonStopClick(Sender: TObject);
    39     procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
    4032    procedure FormCreate(Sender: TObject);
    4133    procedure FormDestroy(Sender: TObject);
    4234    procedure FormShow(Sender: TObject);
     35    procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
    4336    procedure ListViewMethodsData(Sender: TObject; Item: TListItem);
    4437    procedure ListViewMethodsSelectItem(Sender: TObject; Item: TListItem;
     
    4639    procedure Timer1Timer(Sender: TObject);
    4740  private
    48     {$IFDEF opengl}
    49     OpenGLControl1: TOpenGLControl;
    50     TextureId: GLuint;
    51     TextureData: Pointer;
    52     {$ENDIF}
    5341    MethodIndex: Integer;
    5442    SingleTestActive: Boolean;
    5543    AllTestActive: Boolean;
    56     procedure OpenGLControl1Resize(Sender: TObject);
    57     {$IFDEF opengl}
    58     procedure InitGL;
    59     {$ENDIF}
    6044    procedure UpdateMethodList;
    6145    procedure UpdateInterface;
    6246  public
     47    FrameSize: TPoint;
    6348    DrawMethods: TObjectList; // TObjectList<TDrawMethod>
    64     Bitmap: TBitmap;
    6549    Scenes: TObjectList; // TObjectList<TFastBitmap>
    6650    SceneIndex: Integer;
     
    7357
    7458{$R *.lfm}
     59
     60uses
     61  UDrawForm;
     62
    7563
    7664{ TMainForm }
     
    8270  I: Integer;
    8371begin
    84   TabSheet1.DoubleBuffered := True;
     72  FrameSize := Point(320, 240);
    8573  Randomize;
    8674  Scenes := TObjectList.Create;
    8775  for I := 0 to SceneFrameCount - 1 do begin
    8876    NewScene := TFastBitmap.Create;
    89     NewScene.Size := Point(320, 240);
     77    NewScene.Size := FrameSize;
    9078    NewScene.RandomImage;
    9179    Scenes.Add(NewScene);
    9280  end;
    93   Bitmap := TBitmap.Create;
    94   Bitmap.PixelFormat := pf24bit;
    95   Image1.Picture.Bitmap.SetSize(TFastBitmap(Scenes[0]).Size.X, TFastBitmap(Scenes[0]).Size.Y);
    96   Image1.Picture.Bitmap.PixelFormat := pf24bit;
    97   Bitmap.SetSize(TFastBitmap(Scenes[0]).Size.X, TFastBitmap(Scenes[0]).Size.Y);
    98 
    99   {$IFDEF opengl}
    100   OpenGLControl1 := TOpenGLControl.Create(Self);
    101   with OpenGLControl1 do begin
    102     Name := 'OpenGLControl1';
    103     Parent := TabSheet3;
    104     SetBounds(0, 0, 320, 240);
    105     InitGL;
    106     //OnPaint := OpenGLControl1Paint;
    107     OnResize := OpenGLControl1Resize;
    108   end;
    109   GetMem(TextureData, OpenGLControl1.Width * OpenGLControl1.Height * SizeOf(Integer));
    110   {$ENDIF}
    11181
    11282  DrawMethods := TObjectList.Create;
    11383  for I := 0 to High(DrawMethodClasses) do begin
    11484    NewDrawMethod := DrawMethodClasses[I].Create;
    115     NewDrawMethod.Bitmap := Image1.Picture.Bitmap;
    116     NewDrawMethod.PaintBox := PaintBox1;
    117     {$IFDEF opengl}
    118     NewDrawMethod.OpenGLBitmap := TextureData;
    119     NewDrawMethod.OpenGLControl := OpenGLControl1;
    120     {$ENDIF}
    121     NewDrawMethod.Init;
    12285    DrawMethods.Add(NewDrawMethod);
    12386  end;
     
    13699    if MethodIndex >= 0 then
    137100    with TDrawMethod(DrawMethods[MethodIndex]) do begin
    138       PageControl1.TabIndex := Integer(PaintObject);
     101      Init(DrawForm, FrameSize);
    139102      Application.ProcessMessages;
    140103      repeat
     
    145108        StepDuration := NowPrecise - StepStartTime;
    146109      until not SingleTestActive;
     110      Done;
    147111    end;
    148112  finally
     
    156120var
    157121  I: Integer;
    158   C: Integer;
    159122  StartTime: TDateTime;
    160123  StepStartTime: TDateTime;
     
    167130    for I := 0 to DrawMethods.Count - 1 do
    168131    with TDrawMethod(DrawMethods[I]) do begin
     132      Init(DrawForm, FrameSize);
    169133      MethodIndex := I;
    170       PageControl1.TabIndex := Integer(PaintObject);
    171134      StartTime := NowPrecise;
    172135      repeat
     
    177140        StepDuration := NowPrecise - StepStartTime;
    178141      until ((NowPrecise - StartTime) > OneSecond * FloatSpinEdit1.Value) or not AllTestActive;
     142      Done;
    179143    end;
    180144  finally
     
    199163begin
    200164  ListViewMethods.Clear;
    201   {$IFDEF opengl}FreeMem(TextureData, OpenGLControl1.Width * OpenGLControl1.Height);{$ENDIF}
    202165  FreeAndNil(DrawMethods);
    203166  FreeAndNil(Scenes);
    204   FreeAndNil(Bitmap);
    205167end;
    206168
     
    209171  UpdateMethodList;
    210172  UpdateInterface;
     173  DrawForm.Show;
    211174end;
    212175
     
    238201end;
    239202
    240 procedure TMainForm.OpenGLControl1Resize(Sender: TObject);
    241 begin
    242   {$IFDEF opengl}
    243   glViewport(0, 0, OpenGLControl1.Width, OpenGLControl1.Height);
    244   {$ENDIF}
    245 end;
    246 
    247 {$IFDEF opengl}
    248 procedure TMainForm.InitGL;
    249 begin
    250   glMatrixMode(GL_PROJECTION);
    251   glLoadIdentity;
    252   glOrtho(0, OpenGLControl1.Width, OpenGLControl1.Height, 0, 0, 1);
    253 //  glOrtho(0, 1, 1, 0, 0, 1);
    254   glMatrixMode(GL_MODELVIEW);
    255   glLoadIdentity();
    256   glDisable(GL_DEPTH_TEST);
    257   glViewport(0, 0, OpenGLControl1.Width, OpenGLControl1.Height);
    258   //gluPerspective( 45.0, (GLfloat)(OpenGLControl1.Width)/(GLfloat)(OpenGLControl1.Height), 0.1f, 500.0 );
    259 
    260     //glFrustum (-1.0, 1.0, -1.0, 1.0, 1.5, 20.0);
    261     //glTranslatef (0.0, 0.0,-3.0);
    262   //  glClearColor(0.0, 0.0, 0.0, 1.0);
    263 
    264   glGenTextures(1, @TextureId);
    265   glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
    266 end;
    267 {$ENDIF}
    268 
    269203procedure TMainForm.UpdateMethodList;
    270204begin
Note: See TracChangeset for help on using the changeset viewer.