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 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253
| unit TTU1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Buttons, ExtCtrls;
type
TForm1 = class(TForm)
Panel1: TPanel;
BitBtn1: TBitBtn;
BitBtn2: TBitBtn;
FontDialog1: TFontDialog;
BitBtn3: TBitBtn;
PaintBox1: TPaintBox;
procedure FormCreate(Sender: TObject);
procedure FormPaint(Sender: TObject);
procedure BitBtn1Click(Sender: TObject);
procedure BitBtn2Click(Sender: TObject);
procedure FormResize(Sender: TObject);
procedure BitBtn3Click(Sender: TObject);
private
{ Déclarations privées }
public
{ Déclarations publiques }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
var
Couleur : array [1..40] of TColor;
Shadow : Boolean;
zsin : array[0..360] of single;
zcos : array[0..360] of single;
Procedure Initsincos;
const
k = pi/180;
var
i : integer;
Begin
For i := 0 TO 360 do
begin
zsin[i] := sin(i*k);
zcos[i] := cos(i*k);
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
var
rr, gg, bb : word;
i : integer;
begin
Initsincos;
With fontdialog1.font do
begin
height := -24; // négatif pour delphi
name := 'Arial';
end;
Paintbox1.canvas.font := fontdialog1.font;
{ création de 40 couleurs de l'arc en ciel 1..40 en proportions 8 * 5 }
for i := 0 to 7 do
begin {Red To Yellow}
rr := 255;
bb := 128;
gg := (255 * i) div 7;
couleur[1+i] := rgb(rr, gg, bb);
{ Yellow To Green}
gg := 255;
bb := 156;
rr := 255 - (255*i) div 7;
couleur[8+i] := rgb(rr,gg, bb);
{ Green To Cyan}
rr := 128;
gg := 255;
bb := (255 * i) div 7;
couleur[16+i] := rgb(rr,gg, bb);
{ Cyan To Blue}
rr := 156;
bb := 255;
gg := 255 - (255 * i) div 7;
couleur[24+i] := rgb(rr,gg, bb);
{ Blue To Magenta}
gg := 128;
bb := 255;
rr := (255 * i) div 7;
couleur[32+i] := rgb(rr,gg, bb);
end;
Shadow := true;
end;
procedure TForm1.Formpaint(Sender: TObject);
const
Libel = ' Rotation';
var
radius1, radius2 : integer; // rayons des cercles
Ombrex, Ombrey : integer; // décalages des ombres
d, d2 : integer; // angle en degrés
x0, y0 : integer; // centre de la fiche
x, y : integer; // position affichages relative au centre
i, j : integer; // incices
dx, dy : integer; // correction 1/2 hauteur du texte pour centrage textout
chiffre : string; // chiffre à afficher
inverse : boolean;
myLogfont: TLOGFONT; { zone de stockage information fonte }
OldFontHandle, { ancien Handle de la fonte }
NewFontHandle: HFONT; { Hanle temporaire de la fonte }
begin
Paintbox1.canvas.font := Fontdialog1.font;
Radius1 := 100;
Ombrex := 2;
Ombrey := 2;
X0 := Paintbox1.width div 2;
y0 := Paintbox1.height div 2;
with paintbox1.canvas do
begin
brush.style := bsclear;
Ellipse(x0-Radius1, y0-Radius1, x0 +Radius1, y0+ Radius1);
end;
i := 0; // numéros
d := 0; // évolution de l'angle 0 à 360 par pas de 10
Repeat
// pour compliquer, le texte entre 90°et 270 exclus sera dirigé
// vers l'intérieur, autrement il sera dirigé vers l'extérieur
IF (d > 90) and (d < 270) then
begin
d2 := d+180;
if d2 > 360 then d2 := d2 - 360; // à cause des tableaux zsin et zcos
if d2 < 0 then d2 := d2 + 360;
inverse := true;
end
else
begin
d2 := d;
inverse := false;
end;
{ Récupération infos sur la fonte courante }
GetObject(paintbox1.canvas.Font.Handle, SizeOf(mylogfont), Addr(mylogfont));
{ Modification de l'angle exprimé en dixièmes de degrés }
Mylogfont.lfEscapement := d2 * 10;
Mylogfont.lfOrientation := 0;
{ Creation du handle servant à la nouvelle fonte }
NewFontHandle := CreateFontIndirect(mylogfont);
{ Sélection et sauvegarde de l'objet handle }
OldFontHandle := SelectObject(paintbox1.canvas.Handle, NewFontHandle);
// Le décalage du textout est ici la hauteur du texte
// voir sa position pour angle 0 cercle trigonométrique
dx := paintbox1.canvas.textheight('T') div 2;
dy := paintbox1.canvas.textwidth(libel);
IF inverse then
begin
radius1 := 100 + dy + paintbox1.canvas.textwidth(' ');
dx := (- dx *3) div 2;
end
else radius1 := 100;
x := Round( Radius1 * zcos[d] - dx * zsin[d]);
y := Round( Radius1 * -zsin[d] - dx * zcos[d]);
if Shadow then
begin
settextcolor(Paintbox1.canvas.handle, clblack);
paintbox1.canvas.TextOut(x0+x+ombrex, y0+y+ombrey, Libel);
end;
settextcolor(paintbox1.canvas.Handle, couleur[1+ i mod 35]);
Paintbox1.canvas.TextOut(x0+x, y0+y, Libel); // affichage
// ***** nombres à l'intérieur et graduations
IF d = 0 then
begin
radius2 := radius1 - (dx+2) * 2;
Paintbox1.Canvas.Ellipse(x0-Radius2, y0-Radius2, x0 +Radius2, y0+ Radius2);
end;
radius1 := 98;
{ Restauration ancienne fonte courante}
NewFontHandle := SelectObject(paintbox1.canvas.Handle,OldFontHandle);
{ Suppression de la fonte temporaire }
DeleteObject(NewFontHandle);
{ Récupération infos sur la fonte courante }
GetObject(paintbox1.canvas.Font.Handle, SizeOf(mylogfont), Addr(mylogfont));
{ Modification de l'angle exprimé en dixièmes de degrés }
Mylogfont.lfEscapement := -900+ d *10; // angle - 9O °
Mylogfont.lfOrientation := 0;
{ Creation du handle servant à la nouvelle fonte }
NewFontHandle := CreateFontIndirect(mylogfont);
{ Sélection et sauvegarde de l'objet handle }
OldFontHandle := SelectObject(Paintbox1.canvas.Handle, NewFontHandle);
x := Round((Radius1+2)* zcos[d]);
y := Round((Radius1+2)* -zsin[d]);
with Paintbox1.canvas do
begin
pen.color := clblack;
brush.style := bssolid;
IF d mod 90 = 0 then brush.color := clred else brush.color := clwhite;
ellipse(x0+x-3, y0+y-3, x0+x+3, y0+y+3); // graduations
brush.style := bsclear;
end;
chiffre := inttostr(i mod 10); // le chiffre des unités seulement
// le décalage du textout est ici la demi largeur
dx := paintbox1.canvas.textwidth(chiffre) div 2;
x := Round(Radius1* zcos[d] - dx * zsin[d]);
y := Round(Radius1* -zsin[d] - dx * zcos[d]) ;
if Shadow then
begin
settextcolor(Paintbox1.canvas.Handle, clwhite);
Paintbox1.canvas.TextOut(x0+x+ombrex, y0+y+ombrey, chiffre);
end;
settextcolor(Paintbox1.canvas.Handle, clblack);
Paintbox1.canvas.TextOut(x0+x, y0+y, chiffre);
{ Restauration ancienne fonte courante}
NewFontHandle := SelectObject(Paintbox1.canvas.Handle,OldFontHandle);
{ Suppression de la fonte temporaire }
DeleteObject(NewFontHandle);
inc(i);
Inc(d, 10);
UNTIL d = 360;
end;
procedure TForm1.BitBtn1Click(Sender: TObject);
begin
// résultat sélection de fonte
IF fontdialog1.execute then
begin
Paintbox1.canvas.font := Fontdialog1.font;
Paintbox1.Invalidate; // force la fiche à se repeindre
end;
end;
procedure TForm1.BitBtn2Click(Sender: TObject);
begin
close;
end;
procedure TForm1.FormResize(Sender: TObject);
begin
Paintbox1.invalidate;
end;
procedure TForm1.BitBtn3Click(Sender: TObject);
begin
IF shadow then shadow := false else shadow := true;
Paintbox1.invalidate;
end;
end. |
Partager