1 TTweet = enchant.Class.create(enchant.Sprite, {
2 initialize : function(w, h) {
4 enchant.Sprite.call(this, w, h + TTweet.TAIL);
5 this.image = new Surface(w, h + TTweet.TAIL);
16 lt : {x: 0+s, y: t+s},
17 rt : {x: w-s, y: t+s},
18 rd : {x: w-s, y:h+t-s},
19 ld : {x: 0+s, y:h+t-s}
21 this.image.context.font = "12px 'Times New Roman'";
22 this.addEventListener('enterframe', function(){
23 if((this.age % 15) == 0){
26 if(this.lifetime <= 0){
34 var o = this.outCurve;
35 with(this.image.context) {
37 strokeStyle = 'black';
39 moveTo(o.lt.x, o.lt.y+c);
40 quadraticCurveTo(o.lt.x, o.lt.y, o.lt.x+c, o.lt.y);
41 lineTo(o.rt.x-c, o.rt.y);
42 quadraticCurveTo(o.rt.x, o.rt.y, o.rt.x, o.rt.y+c);
43 lineTo(o.rd.x, o.rd.y-c);
44 quadraticCurveTo(o.rd.x, o.rd.y, o.rd.x-c, o.rd.y);
45 lineTo(o.ld.x+c, o.ld.y);
46 quadraticCurveTo(o.ld.x, o.ld.y, o.ld.x, o.ld.y-c);
49 // lineTo(this.width/2-4,_height + TTweet.TAIL);
50 // lineTo(this.width/2,_height + 0);
51 // lineTo(this.width/2+4,_height + TTweet.TAIL);
60 var o = this.outCurve;
62 with(this.image.context) {
66 moveTo(i.lt.x, o.lt.y+c);
67 quadraticCurveTo(i.lt.x, i.lt.y, o.lt.x+c, i.lt.y);
68 lineTo(o.rt.x-c, i.rt.y);
69 quadraticCurveTo(i.rt.x, i.rt.y, i.rt.x, o.rt.y+c);
70 lineTo(i.rd.x, o.rd.y-c);
71 quadraticCurveTo(i.rd.x, i.rd.y, o.rd.x-c, i.rd.y);
72 lineTo(o.ld.x+c, i.ld.y);
73 quadraticCurveTo(i.ld.x, i.ld.y, i.ld.x, o.ld.y-c);
78 text : function(text, x, y) {
83 with(this.image.context) {
84 // var size = measureText(text);
87 textBaseline = 'middle';
90 // fillText(text,this.width/2,this.height/2);
93 // console.log(this.width);
95 var textList = text.split("\n");
96 var len = textList.length / 2;
97 var height = (this.height/(1 + len));
98 this.fillTextLine(text,this.width/2, height);
103 fillTextLine : function(text, x, y) {
104 var textList = text.split("\n");
105 var lineHeight = this.image.context.measureText("あ").width + 2;
107 textList.forEach(function(text, i) {
108 self.image.context.fillText(text, x, y + lineHeight * i);
119 var Box = enchant.Class.create(enchant.Sprite, {
120 initialize : function(ctl, node, x, y, w, h) {
121 enchant.Sprite.call(this, w, h + TTweet.TAIL);
131 ctl.game.rootScene.addEventListener('touchstart', this.touchstart(this));
132 ctl.backgroundMap.addChild(this);
136 this.image = new Surface(w, h + TTweet.TAIL);
139 var c = TTweet.CURVE;
147 lt : {x: 0+s, y: t+s},
148 rt : {x: w-s, y: t+s},
149 rd : {x: w-s, y:h+t-s},
150 ld : {x: 0+s, y:h+t-s}
152 this.image.context.font = "12px 'Times New Roman'";
154 this.addEventListener('enterframe', function(){
155 if((this.age % BASE_FPS) == 0){
159 if(this.lifetime <= 0){
162 this.removeEventListener('enterframe', arguments.callee);
167 reDraw : function() {
168 var c = TTweet.CURVE;
169 var o = this.outCurve;
170 with(this.image.context) {
173 strokeStyle = 'black';
175 moveTo(o.lt.x, o.lt.y+c);
176 quadraticCurveTo(o.lt.x, o.lt.y, o.lt.x+c, o.lt.y);
177 lineTo(o.rt.x-c, o.rt.y);
178 quadraticCurveTo(o.rt.x, o.rt.y, o.rt.x, o.rt.y+c);
179 lineTo(o.rd.x, o.rd.y-c);
180 quadraticCurveTo(o.rd.x, o.rd.y, o.rd.x-c, o.rd.y);
181 lineTo(o.ld.x+c, o.ld.y);
182 quadraticCurveTo(o.ld.x, o.ld.y, o.ld.x, o.ld.y-c);
190 var c = TTweet.CURVE;
191 var o = this.outCurve;
192 var i = this.inCurve;
193 with(this.image.context) {
197 moveTo(i.lt.x, o.lt.y+c);
198 quadraticCurveTo(i.lt.x, i.lt.y, o.lt.x+c, i.lt.y);
199 lineTo(o.rt.x-c, i.rt.y);
200 quadraticCurveTo(i.rt.x, i.rt.y, i.rt.x, o.rt.y+c);
201 lineTo(i.rd.x, o.rd.y-c);
202 quadraticCurveTo(i.rd.x, i.rd.y, o.rd.x-c, i.rd.y);
203 lineTo(o.ld.x+c, i.ld.y);
204 quadraticCurveTo(i.ld.x, i.ld.y, i.ld.x, o.ld.y-c);
209 drawBox : function() {
212 text = this.node.getStatusForDisplay();
214 with(this.image.context) {
216 textAlign = 'center';
217 textBaseline = 'middle';
218 var textList = text.split("\n");
219 var len = textList.length / 2;
220 var height = (this.height/(1 + len));
221 this.fillTextLine(text,this.width/2, height);
224 fillTextLine : function(text, x, y) {
225 var textList = text.split("\n");
226 var lineHeight = this.image.context.measureText("あ").width + 2;
228 textList.forEach(function(text, i) {
229 self.image.context.fillText(text, x, y + lineHeight * i);
238 getWidth: function(){
241 getHeight: function(){
244 touchstart:function(self){
246 if(typeof e === "undefined")return;
247 // this.removeEventListener('touchstart', arguments.callee);
249 // if(self.x <= e.x && self.x + self.width >= e.x
250 // && self.y <= e.y && self.y + self.height >= e.y
252 if(ctl.isCollision(e, self)){
253 this.removeEventListener('touchstart', arguments.callee);
260 this.parentNode.removeChild(this);
261 ctl.backgroundMap.removeChild(this);
263 this.lifetime = null;
270 GPopup = enchant.Class.create(enchant.Sprite, {
271 initialize : function(scene, x, y, w, h) {
272 enchant.Sprite.call(this, w, h);
273 this.image = new Surface(w, h);
276 scene.addChild(this);
281 this.image.context.fillStyle = '#000099';
282 this.image.context.fillRect(0, 0, this.getWidth(), this.getHeight());
284 setText : function(text) {
285 this.image.context.fillStyle = 'black';
286 this.image.context.textAlign = 'left';
287 this.image.context.textBaseline = 'top';
288 this.image.context.font = "13px 'Times New Roman'";
290 var textWidth = Math.floor(this.image.context.measureText(text).width);
291 var lineHeight = this.image.context.measureText("あ").width;
292 var _textList = text.split("\n");
293 this.renew(this.scene, this.x, this.y, textWidth, (lineHeight) * _textList.length + 6);
296 drawText : function (){
300 // var lineHeight = this.image.context.measureText("あ").width;
301 this.image.context.fillStyle = '#ffffff';
302 this.image.context.textAlign = 'left';
303 this.image.context.textBaseline = 'alphabetic';
304 this.image.context.font = "12px 'Times New Roman'";
305 this.fillTextLine(this.text ,x, y);
307 getWidth : function(){
308 return this.image.width;
310 getHeight : function(){
311 return this.image.height;
313 fillTextLine : function(text, x, y) {
314 var textList = text.split("\n");
315 var lineHeight = this.image.context.measureText("あ").width + 2;
317 textList.forEach(function(text, i) {
318 self.image.context.fillText(text, x, y + lineHeight * (i+1));
321 renew : function(scene, x, y, w, h){
322 scene.removeChild(this);
323 enchant.Sprite.call(this, w, h);
324 this.image = new Surface(w, h);
327 scene.addChild(this);
332 GWindow = enchant.Class.create(enchant.Sprite, {
333 initialize : function(scene, x, y, w, h) {
334 enchant.Sprite.call(this, w, h);
335 this.image = new Surface(w, h);
338 scene.addChild(this);
341 this.image.context.fillStyle = '#ffff00';
342 this.image.context.fillRect(0, 0, this.getWidth(), this.getHeight());
344 text : function(text, x, y) {
346 this.image.context.fillStyle = 'black';
347 this.image.context.textAlign = 'left';
348 this.image.context.textBaseline = 'middle';
349 this.image.context.font = "12px 'Times New Roman'";
350 var textWidth = Math.floor(this.image.context.measureText(text).width);
352 var lineHeight = this.image.context.measureText("あ").width;
353 this.image.context.fillText(text + ":" + textWidth,x, y + lineHeight);
355 getWidth : function(){
356 return this.image.width;
358 getHeight : function(){
359 return this.image.height;
362 renew : function(scene, x, y, w, h){
363 scene.removeChild(this);
364 enchant.Sprite.call(this, w, h);
365 this.image = new Surface(w, h);
368 scene.addChild(this);
374 //var tweet = new TTweet(128, 64);
375 //tweet.text("ABCDEFG");