home *** CD-ROM | disk | FTP | other *** search
/ Chip 2005 November / CDVD1105.ISO / Software / Freeware / programare / graphics32 / Examples / Clx / RenderText_Ex / MainUnit.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  2004-07-15  |  3.4 KB  |  140 lines

  1. unit MainUnit;
  2.  
  3. (* ***** BEGIN LICENSE BLOCK *****
  4.  * Version: MPL 1.1
  5.  *
  6.  * The contents of this file are subject to the Mozilla Public License Version
  7.  * 1.1 (the "License"); you may not use this file except in compliance with
  8.  * the License. You may obtain a copy of the License at
  9.  * http://www.mozilla.org/MPL/
  10.  *
  11.  * Software distributed under the License is distributed on an "AS IS" basis,
  12.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  13.  * for the specific language governing rights and limitations under the
  14.  * License.
  15.  *
  16.  * The Original Code is Graphics32
  17.  *
  18.  * The Initial Developer of the Original Code is
  19.  * Alex A. Denisov
  20.  *
  21.  * Portions created by the Initial Developer are Copyright (C) 2000-2004
  22.  * the Initial Developer. All Rights Reserved.
  23.  *
  24.  * Contributor(s):
  25.  *
  26.  * ***** END LICENSE BLOCK ***** *)
  27.  
  28. interface
  29.  
  30. uses
  31.   {$IFDEF LINUX}Libc,{$ENDIF}
  32.   {$IFDEF MSWINDOWS}Windows, {$ENDIF}
  33.   SysUtils, Classes, QGraphics, QControls, QForms, QDialogs,
  34.   QStdCtrls, QExtCtrls, GR32, GR32_Image, QButtons;
  35.  
  36. type
  37.   TForm1 = class(TForm)
  38.     Image: TImage32;
  39.     Panel1: TPanel;
  40.     Edit1: TEdit;
  41.     Label1: TLabel;
  42.     Button1: TButton;
  43.     Label2: TLabel;
  44.     SpeedButton1: TSpeedButton;
  45.     SpeedButton2: TSpeedButton;
  46.     SpeedButton3: TSpeedButton;
  47.     SpeedButton4: TSpeedButton;
  48.     SpeedButton5: TSpeedButton;
  49.     Label3: TLabel;
  50.     procedure Edit1Change(Sender: TObject);
  51.     procedure FormCreate(Sender: TObject);
  52.     procedure ImageResize(Sender: TObject);
  53.     procedure Button1Click(Sender: TObject);
  54.     procedure SpeedButton1Click(Sender: TObject);
  55.   public
  56.     AALevel: Integer;
  57.     procedure Draw;
  58.   end;
  59.  
  60. var
  61.   Form1: TForm1;
  62.  
  63. implementation
  64.  
  65. {$R *.xfm}
  66.  
  67. procedure TForm1.Draw;
  68. begin
  69.   Image.Bitmap.Clear;
  70.   Image.Bitmap.RenderText(10, 10, Edit1.Text, AALevel, $FFFFFFFF);
  71. end;
  72.  
  73. procedure TForm1.Edit1Change(Sender: TObject);
  74. begin
  75.   Draw;
  76. end;
  77.  
  78. procedure TForm1.FormCreate(Sender: TObject);
  79. begin
  80.   Image.SetupBitmap;
  81.   with Image.Bitmap.Font do
  82.   begin
  83.     Name := 'Tahoma';
  84.     Size := 20;
  85.     Style := [fsBold, fsItalic];
  86.   end;
  87. end;
  88.  
  89. procedure TForm1.ImageResize(Sender: TObject);
  90. begin
  91.   Image.SetupBitmap;
  92.   Draw;
  93. end;
  94.  
  95. procedure TForm1.Button1Click(Sender: TObject);
  96. var
  97.   I: Integer;
  98.   tStart, tStop: {$IFDEF MSWINDOWS}Cardinal{$ELSE}timespec{$ENDIF};
  99.   tResult: Double;
  100. begin
  101.   {$IFDEF MSWINDOWS}
  102.   tStart := GetTickCount;
  103.   {$ELSE}
  104.   if clock_gettime(CLOCK_REALTIME, tStart) = -1 then
  105.     raise Exception.Create('Could not get time.');
  106.   {$ENDIF}
  107.  
  108.   Screen.Cursor := crHourGlass;
  109.   with Image.Bitmap do
  110.     for I := 0 to 100 do
  111.       RenderText(
  112.         Random(Width - 40),
  113.         Random(Height - 40),
  114.         IntToStr(Random(100)),
  115.         AALevel,
  116.         Color32(Random(255), Random(255), Random(255), Random(255)));
  117.   Screen.Cursor := crDefault;
  118.  
  119.   {$IFDEF MSWINDOWS}
  120.   tStop := GetTickCount;
  121.   tResult := (tStop - tStart) / 1000;
  122.   {$ELSE}
  123.   if clock_gettime(CLOCK_REALTIME, tStop) = -1 then
  124.     raise Exception.Create('Could not get time.');
  125.  
  126.   tResult := (tStop.tv_sec - tStart.tv_sec) +
  127.              (tStop.tv_nsec - tStart.tv_nsec) / 1000000000;
  128.   {$ENDIF}
  129.  
  130.   Label3.Caption := FloatToStr(tResult) + 's';
  131. end;
  132.  
  133. procedure TForm1.SpeedButton1Click(Sender: TObject);
  134. begin
  135.   AALevel := TControl(Sender).Tag;
  136.   Draw;
  137. end;
  138.  
  139. end.
  140.