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 254 255 256 257 258 259 260 261 262 263
|
unit Domino;
interface
uses
WinTypes,
Messages,
Classes,
Graphics,
Controls;
Type
TDomino = class(TGraphicControl) // plus simple pour gérer l'affichage
private
FDefColor, FSelColor, FDefBorderColor, FSelBorderColor : TColor;
FImage : TBitmap;
FRoundX, FRoundY : Byte;
FSelected : Boolean;
FWidth3D : Byte;
FOnMouseDown : TMouseEvent;
procedure ChangeDefBorderColor(Val : TColor);
procedure ChangeDefColor(Val : TColor);
procedure ChangeImage(Val : TBitmap);
procedure ChangeRoundX(Val : Byte);
procedure ChangeRoundY(Val : Byte);
procedure ChangeSelBorderColor(Val : TColor);
procedure ChangeSelColor(Val : TColor);
procedure ChangeSelected(Val : Boolean);
procedure ChangeWidth3D(Val : Byte);
protected
public
constructor Create(AOwner : TComponent); override;
destructor Destroy; override;
procedure Paint; override;
procedure LMBDown(var msg : TMessage); message WM_LBUTTONDOWN;
procedure RMBDown(var msg : TMessage); message WM_RBUTTONDOWN;
published
property DefBorderColor : TColor read FDefBorderColor write ChangeDefBorderColor;
property DefColor : TColor read FDefColor write ChangeDefColor;
property Image : TBitmap read FImage write ChangeImage;
property RoundX : Byte read FRoundX write ChangeRoundX;
property RoundY : Byte read FRoundY write ChangeRoundY;
property SelColor : TColor read FSelColor write ChangeSelColor;
property SelBorderColor : TColor read FSelBorderColor write ChangeSelBorderColor;
property Selected : Boolean read FSelected write ChangeSelected;
property Width3D : Byte read FWidth3D write ChangeWidth3D;
property OnMouseDown : TMouseEvent read FOnMouseDown write FOnMouseDown;
end;
procedure Register;
implementation
constructor TDomino.Create(AOwner : TComponent);
begin
inherited;
FImage:=TBitmap.Create;
FRoundX:=3; FRoundY:=3;
Height:=71;
Width:=51;
Width3D:=6;
FDefColor:=clOlive; FSelColor:=clFuchsia;
FDefBorderColor:=FDefColor; FSelBorderColor:=FSelColor;
FSelected:=False;
end;
destructor TDomino.Destroy;
begin
FImage.Free;
inherited Destroy;
end;
procedure TDomino.Paint;
var Q : Array[1..8] of TPoint;
P : Array[1..10] of TPoint;
i : Byte;
RectDraw : TRect;
begin
inherited;
with Canvas do begin
Pen.Width:=1;
Pen.Color:=clBlack;
Brush.Style:=bsSolid;
If FSelected Then Brush.Color:=FSelColor
Else Brush.Color:=FDefColor;
Q[1]:=Point(0, RoundY); // forme principale
Q[2]:=Point(RoundX, 0);
Q[3]:=Point(Width - Width3D - RoundX - 1, 0);
Q[4]:=Point(Width - Width3D - 1, RoundY);
Q[5]:=Point(Width - Width3D - 1, Height - Width3D - RoundY - 1);
Q[6]:=Point(Width - Width3D - RoundX - 1, Height - Width3D - 1);
Q[7]:=Point(RoundX, Height - Width3D - 1);
Q[8]:=Point(0, Height - Width3D - RoundY - 1);
Polygon(Q);
// Là j'attaque le relief... j'écrirai le commentaire quand
// je serai en forme ....
If FSelected Then Brush.Color:=FSelBorderColor
Else Brush.Color:=FDefBorderColor;
i:=1; // RoundY/RoundX représente le coef directeur de Q8-Im(Q8)
If ((RoundX=0) or (RoundY/RoundX>1)) Then P[i]:=Q[7]
Else begin
P[i]:=Q[8];
Inc(i);
P[i]:=Point(Q[8].x + Width3D, Q[8].y + Width3D);
end;
Inc(i);
P[i]:=Point(Q[7].x + Width3D, Q[7].y + Width3D);
Inc(i);
P[i]:=Point(Q[6].x + Width3D, Q[6].y + Width3D);
Inc(i);
P[i]:=Point(Q[5].x + Width3D, Q[5].y + Width3D);
Inc(i);
P[i]:=Point(Q[4].x + Width3D, Q[4].y + Width3D);
If ((RoundY=0) or (RoundY/RoundX>1)) Then begin
P[6]:=Point(Q[3].x + Width3D, Q[3].y + Width3D);
P[7]:=Q[3];
end Else P[7]:=Q[4];
Dec(i);
P[8]:=Q[i];
P[9]:=Q[i + 1];
P[10]:=Q[i + 2];
Polygon(P);
// dessine l'image sur le domino
If FImage=nil Then Exit;
with RectDraw do begin
Left:=RoundX;
Top:=RoundY;
Right:=Width - Width3D - 1 - RoundX;
Bottom:=Height - Width3D - 1 -RoundY;
end;
StretchDraw(RectDraw, FImage);
end;
end;
procedure TDomino.LMBDown(var Msg : TMessage);
// je ne récupère pas la touche [Alt]
var Shift : TShiftState;
begin
inherited;
Shift:=[];
with Msg do begin
If WParam>=MK_MBUTTON Then begin
Shift:=[ssMiddle];
WParam:=WParam - MK_MBUTTON;
end;
If WParam>=MK_CONTROL Then begin
Shift:=[ssMiddle];
WParam:=WParam - MK_CONTROL;
end;
If WParam>=MK_SHIFT Then begin
Shift:=[ssMiddle];
WParam:=WParam - MK_SHIFT;
end;
If WParam>=MK_RBUTTON Then begin
Shift:=[ssMiddle];
WParam:=WParam - MK_RBUTTON;
end;
If WParam>=MK_LBUTTON Then begin
Shift:=[ssMiddle];
WParam:=WParam - MK_LBUTTON;
end;
If Assigned(FOnMouseDown) Then
FOnMouseDown(Self, mbLeft, Shift, LoWord(LParam), HiWord(LParam));
end;
end;
procedure TDomino.RMBDown(var Msg : TMessage);
// je ne récupère pas la touche [Alt]
var Shift : TShiftState;
begin
inherited;
Shift:=[];
with Msg do begin
If WParam>=MK_MBUTTON Then begin
Shift:=[ssMiddle];
WParam:=WParam - MK_MBUTTON;
end;
If WParam>=MK_CONTROL Then begin
Shift:=[ssMiddle];
WParam:=WParam - MK_CONTROL;
end;
If WParam>=MK_SHIFT Then begin
Shift:=[ssMiddle];
WParam:=WParam - MK_SHIFT;
end;
If WParam>=MK_RBUTTON Then begin
Shift:=[ssMiddle];
WParam:=WParam - MK_RBUTTON;
end;
If WParam>=MK_LBUTTON Then begin
Shift:=[ssMiddle];
WParam:=WParam - MK_LBUTTON;
end;
If Assigned(FOnMouseDown) Then
FOnMouseDown(Self, mbRight, Shift, LoWord(LParam), HiWord(LParam));
end;
end;
procedure TDomino.ChangeDefBorderColor(Val : TColor);
begin
FDefBorderColor:=Val;
Invalidate;
end;
procedure TDomino.ChangeDefColor(Val : TColor);
begin
FDefColor:=Val;
Invalidate;
end;
procedure TDomino.ChangeImage(Val : TBitmap);
begin
FImage:=Val;
Invalidate;
end;
procedure TDomino.ChangeRoundX(Val : Byte);
begin
If Val<=(Width - Width3D) div 2 Then FRoundX:=Val;
Invalidate;
end;
procedure TDomino.ChangeRoundY(Val : Byte);
begin
If Val<=(Height - Width3D) div 2 Then FRoundY:=Val;
Invalidate;
end;
procedure TDomino.ChangeSelBorderColor(Val : TColor);
begin
FSelBorderColor:=Val;
Invalidate;
end;
procedure TDomino.ChangeSelColor(Val : TColor);
begin
FSelColor:=Val;
Invalidate;
end;
procedure TDomino.ChangeSelected(Val : Boolean);
begin
FSelected:=Val;
Invalidate;
end;
procedure TDomino.ChangeWidth3D(Val : Byte);
begin
If ((Val<Height) and (Val<Width)) Then FWidth3D:=Val Else FWidth3D:=0;
Invalidate;
end;
procedure Register;
begin
RegisterComponents('Mahjong', [TDomino]);
end;
end. |
Partager