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 309 310 311 312 313
|
unit UScrollbar;
interface
uses Flash8;
const bgColorup = $F0F0F0;
const bgColorsurvol = $D6EEFB;
const bgColordown= $42A1D4;
type
TState =(normal,survol,click);
{ *********************
*** ScrollButton **
********************* }
TScrollButton=Class(movieclip)
private
etat:TState;
tail:number;
Ffonction:String;
procedure skin(size:number);
procedure onPress;override;
procedure onRelease;override;
procedure onReleaseOutside;override;
procedure onRollOver;override;
procedure onRollOut;override;
procedure onEnterFrame;override;
public
constructor Create(parent:movieclip;size:number);
Property Fonction:String read Ffonction write Ffonction;
end;
{ *********************
*** Curseur **
********************* }
TCurseur=Class(movieclip)
private
procedure draw(val:integer);
public
Click:boolean;
constructor Create(parent:movieclip);
procedure onRollOver;override;
procedure onRollOut;override;
procedure onPress;override;
procedure onReleaseOutside;override;
procedure onRelease;override;
end;
{ *********************
*** ScrollBar **
********************* }
TScrollbar=Class(movieclip)
private
taille,w,ymouse:number;
Fmin,Fmax,Fposition:integer;
Forientation:string;
but1,but2:TScrollButton;
cur:TCurseur;
procedure setPosition(value:integer);
procedure setOrientation(value:string);
procedure docurmove;
procedure onMouseWheel(Delta: Number; target: Variant);
public
constructor Create(parent:movieclip;size:number);
procedure onChange;virtual;
property position:integer read Fposition write Setposition;
property min:integer read FMin write FMin;
property max:integer read FMax write FMax;
property orientation:string read FOrientation write SetOrientation;
end;
implementation
procedure DrawRect(x,y,w,h:number;mc:movieclip);
begin
with mc do
begin
moveto(x,y);
lineto(x+w,y);
lineto(x+w,y+h);
lineto(x,y+h);
lineto(x,y);
end;
end;
//************************************
//****** -| Scrollbutton |*****
//************************************
constructor TScrollButton.Create(parent:movieclip;size:number);
begin
inherited Create(parent,'ScrollButton',movieclip(parent).getNextHighestDepth());
etat:=normal;
tail:=size;
skin(size);
end;
procedure TScrollButton.Skin(size:number);
begin
if etat=normal then beginFill(bgColorup)
else if etat=survol then beginFill(bgColorsurvol)
else if etat=click then beginFill(bgColordown);
linestyle(1,0);
drawRect(-size/2, -size/2,size, size,self);
endFill();
beginFill(0);
moveTo(0, -size/2+size/3);
lineTo(size/2-size/3,size/2-size/3);
lineTo(-size/2+size/3,size/2-size/3);
lineTo(0, -size/2+size/3);
endFill();
end;
procedure TScrollButton.onEnterFrame;
begin
if etat=click then
begin
if (Fonction = 'Add') and (TscrollBar(_parent).Position <TscrollBar(_parent).Max) then tscrollBar(_parent).Position :=TscrollBar(_parent).Position+ 1
else if (Fonction = 'Substract') and (TscrollBar(_parent).Position >TscrollBar(_parent).Min) then TscrollBar(_parent).Position:=TscrollBar(_parent).Position- 1;
TScrollBar(_parent).onChange();
end else exit;
end;
procedure TScrollButton.onPress;
begin
etat:=click;
clear;
skin(tail);
end;
procedure TScrollButton.onRollOver;
begin
etat:=survol;
clear();
skin(tail);
end;
procedure TScrollButton.onRollOut;
begin
etat:=normal;
clear();
skin(tail);
end;
procedure TScrollButton.onRelease;
begin
etat:=survol;
clear();
skin(tail);
end;
procedure TScrollButton.onReleaseOutside;
begin
etat:=normal;
clear();
skin(tail);
end;
//************************************
//****** -| Curseur |*********
//************************************
constructor TCurseur.Create(parent:movieclip);
begin
inherited Create(parent,'Curseur',movieclip(parent).getNextHighestDepth());
draw(1);
end;
procedure TCurseur.onRollOver;
begin
clear();
draw(2);
end;
procedure TCurseur.onRollOut;
begin
clear;
draw(1);
end;
procedure TCurseur.draw(val:integer);
var M:Matrix;
begin
M:=Matrix.create();
M.createGradientBox(5,40,0,0,0);
case val of
1: begin
lineStyle(1,$949494);
beginGradientFill('linear',[$FCFCFC, $dcdcdc],[100, 100],[0,255],M);
drawRect( -7, -20, 13.5, 40,self);
endFill();
beginFill($B1B1B1);
lineStyle(1, $727171);
end;
2: begin
lineStyle(1,$949494);
beginGradientFill('linear',[$E3F4FC,$9CCAE3],[100, 100],[0,255],M);
drawRect( -7, -20, 13.5, 40,self);
endFill();
beginFill($58A2C2);
lineStyle(1, $62A8CA)
end;
end;
drawRect( -4, -5, 8, 2,self);
drawRect( -4, -1, 8, 2,self);
drawRect( -4, 3, 8, 2,self);
endFill();
end;
procedure TCurseur.onPress;
begin
click:=true;
TScrollbar(_parent).ymouse:=_Ymouse;
end;
procedure TCurseur.onReleaseOutside;
begin
draw(1);
click:=false;
end;
procedure TCurseur.onRelease;
begin
click:=false;
end;
//************************************
//****** | Scrollbar |*********
//************************************
constructor TScrollbar.Create(parent:movieclip;size:number);
begin
inherited Create(parent,'ScrollBar'+floattostr(parent.getNextHighestDepth()),parent.getNextHighestDepth());
taille := size;
w := taille-70;//30 ->15+15 + 40->2x20 taille 2x bouton+curseur
lineStyle(1, $E7E7E7);
beginFill($F0F0F0);
drawRect( -7.5, 0, 15, taille,self);
endFill();
but1:=TScrollButton.Create(self,15);
but2:=TScrollButton.Create(self,15);
cur:=TCurseur.Create(self);
but1._y := 7.5;
but1.Fonction := 'Substract';
but2._y := taille-7.5;
but2._rotation := 180;
but2.Fonction := 'Add';
cur.onMouseMove:=docurmove;
mouse.addlistener(self);
end;
procedure TScrollBar.docurmove;
begin
if cur.Click then
begin
cur._y:= cur._y + cur._Ymouse -ymouse;
if cur._y<35 then cur._y:=35;
if cur._y>taille-35 then cur._y:=taille-35;
Position:=round((cur._y-35)*(max-min)/w+min);
onChange();
end;
end;
procedure TScrollBar.onMouseWheel(Delta: Number; target: Variant);
var temppos:integer;
begin
if Orientation = 'vertical' then
begin
temppos := Position;
if Delta > 0 then Delta := 1 else Delta := -1;
Position:=Position-Delta;
if (Position >= min) and (Position <= max) then cur._y := 35 + (Position - min) * w / (max - min) else Position := temppos;
onChange();
end;
end;
procedure TScrollBar.onChange;
begin
end;
procedure TScrollBar.SetPosition(value:integer);
begin
cur._y :=35+ abs(value -min) * w / (max - min);
Fposition := value;
end;
procedure TScrollBar.setOrientation(value:string);
begin
if value='horizontal' then
begin
_rotation := -90;
_y := _y +but1._height/2;
end
else if value= 'vertical' then _x := _x +but1._width / 2;
FOrientation := value;
end;
end. |
Partager