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 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308
|
program Project1;
{$FRAME_WIDTH 640}
{$FRAME_HEIGHT 480}
uses
Flash8;
var
Arial12 : TextFormat;
ActiveItem: TextFormat;
type
TListBox = class(MovieClip)
FWidth : Integer;
FHeight: Integer;
FItems : array of TextField;
FCount : Integer;
FIndex : Integer;
FFocus : Integer;
constructor Create(Parent: MovieClip; x, y, w, h: Integer);
procedure AddItem(Value: string);
procedure SetItemIndex(Value: Integer);
procedure Show;
function MouseItem: Integer;
procedure onMouseMove;
procedure onMouseDown;
procedure redraw();
end;
TComboBox = class(MovieClip)
FText : TextField;
FList : TListBox;
FOver: Boolean;
constructor Create(Parent: MovieClip; x, y, w, h: Integer);
procedure redraw();
procedure onRollOver;
procedure onRollOut;
procedure onMouseDown;
procedure onRelease;
procedure onReleaseOutside;
procedure onPress;
procedure AddItem(Value: string);
procedure SetItemIndex(Value: Integer);
end;
constructor TListBox.Create(Parent: MovieClip; x, y, w, h: Integer);
begin
inherited Create(Parent, '', Parent.getNextHighestDepth);
_x := x;
_y := y;
FWidth := w;
FHeight := h;
FIndex := -1;
redraw();
end;
procedure TListBox.redraw();
begin
clear;
lineStyle(1, 0);
beginFill(clWhite);
moveTo(0, 0);
lineTo(FWidth, 0);
lineTo(FWidth, FCount * FHeight);
lineTo(0, FCount * FHeight);
lineTo(0, 0);
end;
procedure TListBox.AddItem(Value: string);
var
Item: TextField;
begin
Item := TextField.Create(Self, '', FCount, 1, FHeight * FCount, FWidth - 1, FHeight);
Item.setNewTextFormat(Arial12);
Item.backgroundColor := $3399ff;
Item.Text := Value;
FItems[FCount] := Item;
Inc(FCount);
redraw();
end;
procedure TListBox.SetItemIndex(Value: Integer);
begin
if FIndex <> Value then
begin
if FIndex >= 0 then
with FItems[FIndex] do
begin
setTextFormat(0, $7FFFFFF, Arial12);
background := False;
end;
FIndex := Value;
FFocus := Value;
if FIndex >= 0 then
with FItems[FIndex] do
begin
setTextFormat(0, $7FFFFFF, ActiveItem);
background := True;
end;
end;
end;
procedure TListBox.Show;
begin
if FFocus <> FIndex then
begin
if FFocus >= 0 then
with FItems[FFocus] do
begin
setTextFormat(0, $7FFFFFF, Arial12);
background := False;
end;
FFocus := FIndex;
if FIndex > 0 then
with FItems[FIndex] do
begin
setTextFormat(0, $7FFFFFF, ActiveItem);
background := True;
end;
end;
_visible := True;
end;
function TListBox.MouseItem: Integer;
begin
if (_xmouse < 0) or (_ymouse < 0) or (_xmouse > FWidth) or (_ymouse > FCount * FHeight) then
Result := -1
else
Result := Trunc(_ymouse / FHeight);
end;
procedure TListBox.onMouseMove;
var
i: Integer;
begin
i := MouseItem;
if i < 0 then
Exit;
if i <> FFocus then
begin
if FFocus >= 0 then
with FItems[FFocus] do
begin
setTextFormat(0, $7FFFFFF, Arial12);
background := False;
end;
FFocus := i;
if FFocus >= 0 then
with FItems[FFocus] do
begin
setTextFormat(0, $7FFFFFF, ActiveItem);
background := True;
end;
end;
end;
procedure TListBox.onMouseDown;
var
i: Integer;
begin
i := MouseItem;
if i >= 0 then
TComboBox(_parent).SetItemIndex(i); // quick hack en attendant mieux
end;
constructor TComboBox.Create(Parent: MovieClip; x, y, w, h: Integer);
begin
inherited Create(Parent, '', Parent.getNextHighestDepth);
FText := TextField.Create(Self, 'Text', 1, 1, 1, w - 14, h - 2);
FText.selectable := False;
FText.setNewTextFormat(Arial12);
FText.Text := 'ComboBox1';
FList := TListBox.Create(Self, 0, h, w, h - 2);
FList._visible := False;
FOver := False;
_x := x;
_y := y;
redraw();
end;
procedure TComboBox.redraw();
var
w, h, t: Number;
matrix: Flash8.Matrix;
begin
w := FText._width + 15;
h := FText._height + 2;
clear();
lineStyle(1, $707070);
matrix := Flash8.Matrix.Create();
matrix.createGradientBox(w, h, Math.PI/2, 0, 0);
if FList._visible then
beginGradientFill('linear',
[$deedf6,$c4e5f6,$98d1ef,$66afd7],
[100,100,100,100],
[0,127,128,255],
matrix
)
else
if FOver then
beginGradientFill('linear',
[$eaf6f2,$d9f0fc,$bef6fd,$a7d9f5],
[100,100,100,100],
[0,127,128,255],
matrix
)
else
beginGradientFill('linear',
[$f2f2f2,$ebebeb,$dddddd,$cfcfcf],
[100,100,100,100],
[0,127,128,255],
matrix
);
moveTo(0, 2);
lineTo(2, 0);
lineTo(w - 2, 0);
lineTo(w, 2);
lineTo(w, h - 2);
lineTo(w - 2, h);
lineTo(2, h);
lineTo(0, h - 2);
lineTo(0, 2);
endFill;
lineStyle(1, 0);
beginFill(0);
t := (h - 4) / 2;
moveTo(w - 12, t);
lineTo(w - 6, t);
lineTo(w - 9, t + 4);
end;
procedure TComboBox.AddItem(Value: string);
begin
FList.AddItem(Value);
end;
procedure TComboBox.SetItemIndex(Value: Integer);
begin
FList.SetItemIndex(Value);
FText.Text := FList.FItems[Value].Text;
FOver := False; // ??
redraw();
end;
procedure TComboBox.onRollOver;
begin
FOver := True;
redraw();
end;
procedure TComboBox.onRollOut;
begin
FOver := False;
redraw();
end;
procedure TComboBox.onMouseDown;
begin
if FList._visible and (FOver = False) then
begin
FList._visible := False;
redraw();
end;
end;
procedure TComboBox.onRelease;
begin
if _ymouse > FText._height then
begin
SetItemIndex(FList.FFocus);
FList._visible := False;
redraw();
end;
end;
procedure TComboBox.onReleaseOutside;
begin
FList._visible := False;
FOver := False; // ??
redraw();
end;
procedure TComboBox.onPress;
begin
if FList._visible then
FList._visible := False
else
FList.Show;
redraw();
end;
begin
Arial12 := TextFormat.Create('Arial', 12, 0);
ActiveItem := TextFormat.Create();
ActiveItem.Color := clWhite;
with TComboBox.Create(_root, 10, 10, 250, 21) do
begin
AddItem("Arrière-plans du Bureau Windows");
AddItem("Bibliothèque d'images");
AddItem('Photos ayant le meilleur classement');
AddItem('Couleurs unies');
AddItem('Fond Ecran');
AddItem("Téléchargements");
SetItemIndex(4);
end;
end. |
Partager