-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathslice9.html
152 lines (124 loc) · 5.89 KB
/
slice9.html
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
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<title>Studio3</title>
<meta name="viewport" content="width=device-width, user-scalable=0, maximum-scale=1"/>
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<link rel="apple-touch-icon" href="icon.png" />
<link rel="stylesheet" href="assets/debug.css" />
</head>
<body style="margin:0;background: #333">
<canvas id="canvas" height="320" width="320" style="cursor:pointer;display: block;outline:1px solid #BBFF00;"></canvas>
<div class="debug_controls">
<label>Target FPS (fixed step)
<input id="targetFrameRate" type="range" value="16.66" max="100" min="1">
</label>
<label>Resolution
<input id="resolution" type="range" value="1" max="2" min=".25" step=".25">
</label>
<label>Snap Pixels: <input id="snap" type="checkbox"></label>
<label>Full Screen: <input id="fullscreen" type="checkbox"></label>
<!-- <input type = 'text'> -->
</div>
</body>
<script src="studio-compiled.js"></script>
<script>
var stage = new Studio.Stage('canvas',{webgl:0, dur:1000/6, fullscreen:1, color: Studio.BLUE})
var fps_range = document.getElementById("targetFrameRate");
var resolution = document.getElementById("resolution");
var snap = document.getElementById("snap");
var fullscreen = document.getElementById("fullscreen");
stage.onEnterFrame = function(){1
}
Studio.Slice9 = function(attr) {
this.borders = null;
this.color = new Studio.Color(1, 1, 1, 1);
this.rect = {x: 0, y: 0, height: 32, width: 32};
this.innerRect = {x:8, y:8, width:18, height: 18};
this._boundingBox = new Studio.Box();
this.resolution = 1;
if (attr) {
this.apply(attr);
}
this.image = new Studio.Cache(this.width*this.resolution, this.height*this.resolution,1)
};
Studio.inherit(Studio.Slice9, Studio.Sprite);
Studio.Slice9.prototype._drawStreched = function(ctx){
var a_w = this.innerRect.x - this.rect.x;
var a_h = this.innerRect.y - this.rect.y;
var c_w = this.rect.width - this.innerRect.width - a_w;
var b_w = this.width*this.resolution - ( c_w + a_w );
var g_h = this.rect.height - this.innerRect.height -a_h;
var d_h = this.height*this.resolution - ( g_h + a_h );
ctx.drawImage(this.borders.bitmap, this.rect.x, this.rect.y, this.innerRect.x, this.innerRect.y, 0, 0, a_w, a_h);
ctx.drawImage(this.borders.bitmap, this.innerRect.x, this.rect.y, this.innerRect.width, a_h, a_w, 0, b_w, a_h);
ctx.drawImage(this.borders.bitmap, this.innerRect.x + this.innerRect.width, this.rect.y, c_w, a_h, a_w + b_w, 0, c_w, a_h);
ctx.drawImage(this.borders.bitmap, this.rect.x, this.innerRect.y, a_w, this.innerRect.height, 0, a_h, a_w, d_h);
ctx.drawImage(this.borders.bitmap, this.innerRect.x, this.innerRect.y, this.innerRect.width, this.innerRect.height, a_w, a_h, b_w, d_h);
ctx.drawImage(this.borders.bitmap, this.innerRect.x + this.innerRect.width, this.innerRect.y, c_w, this.innerRect.height, a_w + b_w, a_h, c_w, d_h);
ctx.drawImage(this.borders.bitmap, this.rect.x, this.innerRect.y + this.innerRect.height, a_w, g_h, 0, a_h + d_h, a_w, g_h);
ctx.drawImage(this.borders.bitmap, this.innerRect.x, this.innerRect.y + this.innerRect.height, this.innerRect.width, g_h, a_w, a_h + d_h, b_w, g_h);
ctx.drawImage(this.borders.bitmap, this.innerRect.x + this.innerRect.width, this.innerRect.y + this.innerRect.height, c_w, g_h, a_w + b_w , a_h + d_h, c_w, g_h);
}
Studio.Slice9.prototype.updateCache = function(){
this._drawStreched(this.image.ctx);
this.image.ready = true;
}
// Studio.Slice9.prototype.draw = function(ctx) {
// if (!this.borders) {
// return;
// }
// if (!this.borders.ready) {
// return;
// }
// this.setAlpha(ctx);
// ctx.drawImage(this.image.bitmap, this.innerRect.x + this.innerRect.width, this.innerRect.y + this.innerRect.height, c_w, g_h, a_w + b_w , a_h + d_h, c_w, g_h);
// // this._drawStreched(this.image.buffer, 0,0);
// };
Studio.Slice9.prototype.drawAngled = function(ctx) {
ctx.save();
this.prepAngled(ctx);
ctx.drawImage(this.image.bitmap, 0, 0, this.image.bitmap.width, this.image.bitmap.height, -(this.width * this.anchorX), -(this.height * this.anchorY), this.width, this.height);
ctx.restore();
};
Studio.Slice9.prototype.draw = function(ctx) {
if (!this.borders) {
return;
}
if (!this.image.ready) {
this.updateCache();
return;
}
this.setAlpha(ctx);
if (this.angle) {
this.drawAngled(ctx);
} else {
ctx.drawImage(this.image.bitmap, 0, 0, this.image.bitmap.width, this.image.bitmap.height, this._dx - (this._world.width * this.anchorX), this._dy - (this._world.height * this.anchorY), this._world.width, this._world.height);
}
};
var temp = new Studio.Image('assets/paused.png')
var slice9_2 = new Studio.Slice9({borders:temp, rect: {x:0,y:0,height:520, width: 480}, innerRect: {x:36, y:36, width: 408, height: 446}, height: 300, width: 137, x: 80, y: 160})
var cc = new Studio.Cache(51,51,2);
cc.ctx.fillStyle="rgba(200,0,20,.5)";
cc.ctx.fillRect(10,10,40,40);
cc.ctx.lineWidth = 1
cc.ctx.strokeRect(1,1,40,40);
cc.ctx.fillStyle="rgba(0,0,200,.5)";
cc.ctx.fillRect(1,1,40,40);
cc.ctx.strokeRect(10,10,40,40);
var cc_border = new Studio.Slice9({borders:cc, rect: {x:0,y:0,height:51*2, width: 51*2}, innerRect: {x:11*2, y:11*2, width: 20*2, height: 20*2}, height: 100, width: 100, x: 100, y: 100, resolution:2})
var slice9 = new Studio.Slice9({borders:temp, rect: {x:0,y:0,height:520, width: 480}, innerRect: {x:36, y:36, width: 408, height: 446}, height: 200, width: 200, x: 200, y: 200, resolution:2})
stage.addChild(slice9)
stage.addChild(slice9_2)
stage.addChild(cc_border)
slice9._snapback();
slice9_2._snapback();
cc_border._snapback();
var tt = stage.createTween(slice9,'linear',{y:360},4000,null, function(){this._snapback();}).loop().reflect(false);
slice9.onEnterFrame = function(){
// this.rotation++;
}
stage.playTween(tt);
Studio.start();
</script>
</html>