2 * QLIB 1.0 Sprite Object
\r
3 * Copyright (C) 2002 2003, Quazzle.com Serge Dolgov
\r
4 * This program is free software; you can redistribute it and/or
\r
5 * modify it under the terms of the GNU General Public License
\r
6 * as published by the Free Software Foundation; either version 2
\r
7 * of the License, or (at your option) any later version.
\r
8 * http://qlib.quazzle.com
\r
11 function QSprite_load(src) {
\r
13 this.face = new Image(this.cwidth, this.cheight);
\r
14 this.face.src = src;
\r
19 function QSprite_show(show) {
\r
20 if (show && !this.valid && this.face.complete) {
\r
21 this._img.src = this.face.src;
\r
27 function QSprite_moveTo(x, y) {
\r
32 function QSprite_slideTo(x, y) {
\r
35 this.doSlide(++this._spro, x, y);
\r
41 function QSprite_shake() {
\r
44 this.doShake(++this._spro, 0, this.x, this.y);
\r
48 function QSprite_stop() {
\r
51 clearTimeout(this._sprt);
\r
56 function QSprite_doSlide(id, x, y) {
\r
57 if (this._spro == id) {
\r
59 var dx = Math.round(x - this.x);
\r
60 var dy = Math.round(y - this.y);
\r
62 if (dx) dx = dx > 0 ? Math.ceil(dx/4) : Math.floor(dx/4);
\r
63 if (dy) dy = dy > 0 ? Math.ceil(dy/4) : Math.floor(dy/4);
\r
64 this._move(this.x + dx, this.y + dy);
\r
65 this._sprt = setTimeout(this.name + ".doSlide(" + id + "," + x + "," + y + ")", 30);
\r
72 function QSprite_doShake(id, phase, x, y) {
\r
73 if (this._spro == id) {
\r
76 var m = 3 * Math.sin(.16 * phase);
\r
77 this._move(x + m * Math.sin(phase), y + m * Math.cos(phase));
\r
78 this._sprt = setTimeout(this.name + ".doShake(" + id + "," + (++phase) + "," + x + "," + y + ")", 20);
\r
85 function QSprite_doClick() {
\r
87 this.onClick(this.tag);
\r
92 function QSprite(parent, name, x, y, width, height, src, visible, effects, opacity, zindex) {
\r
93 this.init(parent, name);
\r
96 this.width = (this.cwidth = width - 0) + 8;
\r
97 this.height = (this.cheight = height - 0) + 8;
\r
98 var j = QSprite.arguments.length;
\r
99 this.visible = (j > 7) ? visible : true;
\r
100 this.effects = (j > 8) ? effects : 0;
\r
101 this.opacity = (j > 9) ? opacity : 100;
\r
102 this.zindex = (j > 10) ? zindex : null;
\r
103 this.valid = !!src;
\r
104 this.content = '<a href="#" title="" onclick="return false" onmousedown="return ' + this.name +
\r
105 '.doClick()" onmouseover="window.top.status=\'\';return true" hidefocus="true" unselectable="on"><img name="' +
\r
106 this.id + '" src="' + (src || '') + '" border="0" width="' + this.cwidth + '" height="' + this.cheight +
\r
107 '" alt="" unselectable="on"></a>';
\r
108 this.doClick = QSprite_doClick;
\r
109 this.doSlide = QSprite_doSlide;
\r
110 this.doShake = QSprite_doShake;
\r
111 this.onClick = QControl.event;
\r
113 this.face = this._img = this.document.images[this.id] || new Image(1, 1);
\r
115 this._sprt = false;
\r
116 this._show = this.show;
\r
117 this._move = this.moveTo;
\r
118 this.load = QSprite_load;
\r
119 this.show = QSprite_show;
\r
120 this.moveTo = QSprite_moveTo;
\r
121 this.slideTo = QSprite_slideTo;
\r
122 this.shake = QSprite_shake;
\r
123 this.stop = QSprite_stop;
\r
125 QSprite.prototype = new QWndCtrl();
\r