social_cheesecake 0.0.4 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. data/.gitignore +2 -0
  2. data/Rakefile +111 -0
  3. data/app/assets/javascripts/kinetic.js +448 -407
  4. data/app/assets/javascripts/social_cheesecake.js +1 -2
  5. data/app/assets/javascripts/socialcheesecake/_header.js +28 -0
  6. data/app/assets/javascripts/socialcheesecake/actor.js +104 -41
  7. data/app/assets/javascripts/socialcheesecake/cheesecake.js +26 -31
  8. data/app/assets/javascripts/socialcheesecake/grid.js +53 -12
  9. data/app/assets/javascripts/socialcheesecake/sector.js +108 -93
  10. data/app/assets/javascripts/socialcheesecake/text.js +39 -36
  11. data/lib/generators/social_cheesecake/install_generator.rb +10 -0
  12. data/lib/social_cheesecake/version.rb +1 -1
  13. data/social_cheesecake.gemspec +1 -0
  14. data/test/dummy/.gitignore +15 -0
  15. data/test/dummy/Gemfile +34 -0
  16. data/test/dummy/README +261 -0
  17. data/test/dummy/Rakefile +7 -0
  18. data/test/dummy/app/assets/images/beatriz.png +0 -0
  19. data/test/dummy/app/assets/images/rails.png +0 -0
  20. data/test/dummy/app/assets/images/youngAlberto.png +0 -0
  21. data/test/dummy/app/assets/javascripts/application.js +10 -0
  22. data/test/dummy/app/assets/stylesheets/application.css +7 -0
  23. data/test/dummy/app/controllers/application_controller.rb +3 -0
  24. data/test/dummy/app/helpers/application_helper.rb +2 -0
  25. data/test/dummy/app/mailers/.gitkeep +0 -0
  26. data/test/dummy/app/models/.gitkeep +0 -0
  27. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  28. data/test/dummy/config/application.rb +48 -0
  29. data/test/dummy/config/boot.rb +6 -0
  30. data/test/dummy/config/database.yml +25 -0
  31. data/test/dummy/config/environment.rb +5 -0
  32. data/test/dummy/config/environments/development.rb +30 -0
  33. data/test/dummy/config/environments/production.rb +60 -0
  34. data/test/dummy/config/environments/test.rb +39 -0
  35. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  36. data/test/dummy/config/initializers/inflections.rb +10 -0
  37. data/test/dummy/config/initializers/mime_types.rb +5 -0
  38. data/test/dummy/config/initializers/secret_token.rb +7 -0
  39. data/test/dummy/config/initializers/session_store.rb +8 -0
  40. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  41. data/test/dummy/config/locales/en.yml +5 -0
  42. data/test/dummy/config/routes.rb +58 -0
  43. data/test/dummy/config.ru +4 -0
  44. data/test/dummy/db/seeds.rb +7 -0
  45. data/test/dummy/doc/README_FOR_APP +2 -0
  46. data/test/dummy/lib/assets/.gitkeep +0 -0
  47. data/test/dummy/lib/tasks/.gitkeep +0 -0
  48. data/test/dummy/log/.gitkeep +0 -0
  49. data/test/dummy/public/404.html +26 -0
  50. data/test/dummy/public/422.html +26 -0
  51. data/test/dummy/public/500.html +26 -0
  52. data/test/dummy/public/favicon.ico +0 -0
  53. data/test/dummy/public/index.html +133 -0
  54. data/test/dummy/public/robots.txt +5 -0
  55. data/test/dummy/script/rails +6 -0
  56. data/test/dummy/test/fixtures/.gitkeep +0 -0
  57. data/test/dummy/test/functional/.gitkeep +0 -0
  58. data/test/dummy/test/integration/.gitkeep +0 -0
  59. data/test/dummy/test/performance/browsing_test.rb +12 -0
  60. data/test/dummy/test/test_helper.rb +13 -0
  61. data/test/dummy/test/unit/.gitkeep +0 -0
  62. data/test/dummy/vendor/assets/stylesheets/.gitkeep +0 -0
  63. data/test/dummy/vendor/plugins/.gitkeep +0 -0
  64. metadata +114 -29
  65. data/app/assets/javascripts/socialCheesecake.js +0 -161
@@ -1,9 +1,9 @@
1
1
  /**
2
- * KineticJS JavaScript Library v2.3.2
2
+ * KineticJS JavaScript Library v3.1.0
3
3
  * http://www.kineticjs.com/
4
4
  * Copyright 2011, Eric Rowell
5
5
  * Licensed under the MIT or GPL Version 2 licenses.
6
- * Date: Dec 01 2011
6
+ * Date: Dec 19 2011
7
7
  *
8
8
  * Copyright (C) 2011 by Eric Rowell
9
9
  *
@@ -27,515 +27,556 @@
27
27
  */
28
28
  var Kinetic = {};
29
29
 
30
+ /****************************************
31
+ * Layer
32
+ */
33
+ Kinetic.Layer = function(stage, stripStyling) {
34
+ this.canvas = document.createElement('canvas');
35
+ this.context = this.canvas.getContext('2d');
36
+ this.canvas.width = stage.width;
37
+ this.canvas.height = stage.height;
38
+ this.canvas.style.position = 'absolute';
39
+ this.shapes = [];
40
+
41
+ if(stripStyling) {
42
+ this.context.stroke = function() {
43
+ };
44
+ this.context.fill = function() {
45
+ };
46
+ }
47
+
48
+ stage.container.appendChild(this.canvas);
49
+ }
50
+ /*
51
+ * clear layer
52
+ */
53
+ Kinetic.Layer.prototype.clear = function() {
54
+ var context = this.getContext();
55
+ var canvas = this.getCanvas();
56
+ context.clearRect(0, 0, canvas.width, canvas.height);
57
+ }
58
+ /*
59
+ * get layer canvas
60
+ */
61
+ Kinetic.Layer.prototype.getCanvas = function() {
62
+ return this.canvas;
63
+ }
64
+ /*
65
+ * get layer context
66
+ */
67
+ Kinetic.Layer.prototype.getContext = function() {
68
+ return this.context;
69
+ }
70
+ /*
71
+ * get layer shapes
72
+ */
73
+ Kinetic.Layer.prototype.getShapes = function() {
74
+ return this.shapes;
75
+ }
76
+ /*
77
+ * draw all shapes in layer
78
+ */
79
+ Kinetic.Layer.prototype.draw = function() {
80
+ this.clear();
81
+ var context = this.getContext();
82
+
83
+ for(var n = 0; n < this.getShapes().length; n++) {
84
+ this.getShapes()[n].draw(this);
85
+ }
86
+ };
30
87
  /****************************************
31
88
  * Stage
32
89
  */
33
- Kinetic.Stage = function(containerId, width, height){
34
- this.container = document.getElementById(containerId);
35
- this.width = width;
36
- this.height = height;
37
- this.shapes = [];
38
- this.zIndexCounter = 9999;
39
- this.idCounter = 0;
40
- this.dblClickWindow = 400; // ms
41
- // desktop flags
42
- this.mousePos = null;
43
- this.mouseDown = false;
44
- this.mouseUp = false;
45
-
46
- // mobile flags
47
- this.touchPos = null;
48
- this.touchStart = false;
49
- this.touchEnd = false;
50
-
51
- // add stage canvas
52
- this.canvas = document.createElement('canvas');
53
- this.context = this.canvas.getContext('2d');
54
- this.id = 0;
55
-
56
- this.canvas.width = this.width;
57
- this.canvas.height = this.height;
58
- this.canvas.style.position = 'absolute';
59
- this.container.appendChild(this.canvas);
60
-
61
- this.listen();
90
+ Kinetic.Stage = function(containerId, width, height) {
91
+ this.container = document.getElementById(containerId);
92
+ this.width = width;
93
+ this.height = height;
94
+ this.zIndexCounter = 9999;
95
+ this.idCounter = 0;
96
+ this.dblClickWindow = 400;
97
+ // ms
98
+ // desktop flags
99
+ this.mousePos = null;
100
+ this.mouseDown = false;
101
+ this.mouseUp = false;
102
+
103
+ // mobile flags
104
+ this.touchPos = null;
105
+ this.touchStart = false;
106
+ this.touchEnd = false;
107
+
108
+ // create layers
109
+ this.backStageLayer = new Kinetic.Layer(this, true);
110
+ this.stageLayer = new Kinetic.Layer(this);
111
+ this.propsLayer = new Kinetic.Layer(this);
112
+ this.actorsLayer = new Kinetic.Layer(this);
113
+ this.backStageLayer.getCanvas().style.display = 'none';
114
+ this.listen();
62
115
  };
63
-
64
116
  /*
65
- * clear stage canvas
117
+ * get back stage layer
66
118
  */
67
- Kinetic.Stage.prototype.clear = function(){
68
- var context = this.getContext();
69
- var canvas = this.getCanvas();
70
- context.clearRect(0, 0, canvas.width, canvas.height);
119
+ Kinetic.Stage.prototype.getBackStageLayer = function() {
120
+ return this.backStageLayer;
71
121
  };
72
-
73
122
  /*
74
- * clear stage canvas and all shape canvases
123
+ * get stage layer
75
124
  */
76
- Kinetic.Stage.prototype.clearAll = function(){
77
- // clear stage
78
- this.clear();
79
-
80
- // clear shapes
81
- for (var n = 0; n < this.shapes.length; n++) {
82
- this.shapes[n].clear();
83
- }
125
+ Kinetic.Stage.prototype.getStageLayer = function() {
126
+ return this.stageLayer;
84
127
  };
85
-
86
128
  /*
87
- * draw all shapes
129
+ * get props layer
88
130
  */
89
- Kinetic.Stage.prototype.drawAll = function(){
90
- // draw shapes
91
- for (var n = 0; n < this.shapes.length; n++) {
92
- this.shapes[n].draw();
93
- }
131
+ Kinetic.Stage.prototype.getPropsLayer = function() {
132
+ return this.propsLayer;
133
+ };
134
+ /*
135
+ * get actors layer
136
+ */
137
+ Kinetic.Stage.prototype.getActorsLayer = function() {
138
+ return this.actorsLayer;
139
+ };
140
+ /*
141
+ * clear stage
142
+ */
143
+ Kinetic.Stage.prototype.clear = function() {
144
+ this.stageLayer.clear();
145
+ };
146
+ /*
147
+ * clear all canvases
148
+ */
149
+ Kinetic.Stage.prototype.clearAll = function() {
150
+ this.backStageLayer.clear();
151
+ this.stageLayer.clear();
152
+ this.propsLayer.clear();
153
+ this.actorsLayer.clear();
154
+ };
155
+ /*
156
+ * short-hand for draw actors layer
157
+ */
158
+ Kinetic.Stage.prototype.draw = function() {
159
+ this.getActorsLayer().draw();
94
160
  };
95
-
96
161
  /*
97
162
  * remove a shape from the stage
98
163
  */
99
- Kinetic.Stage.prototype.remove = function(shape){
100
- var shapes = this.shapes;
101
-
102
- // remove canvas
103
- this.container.removeChild(shape.getCanvas());
104
-
105
- // remove from shapes array
106
- for (var n = 0; n < shapes.length; n++) {
107
- var id = shapes[n].id;
108
- if (id == shape.id) {
109
- this.shapes.splice(n, 1);
110
- }
111
- }
164
+ Kinetic.Stage.prototype.remove = function(shape) {
165
+ // remove from shapes array
166
+ var shapes = this.getShapes();
167
+ for(var n = 0; n < shapes.length; n++) {
168
+ var id = shapes[n].id;
169
+ if(id == shape.id) {
170
+ shape.getLayer().getShapes().splice(n, 1);
171
+ }
172
+ }
112
173
  };
113
-
114
174
  /*
115
175
  * remove all shapes from the stage
116
176
  */
117
- Kinetic.Stage.prototype.removeAll = function(){
118
- // remove all shapes
119
- while (this.shapes.length > 0) {
120
- var that = this;
121
- this.remove(that.shapes[0]);
122
- }
177
+ Kinetic.Stage.prototype.removeAll = function() {
178
+ // remove all shapes
179
+ this.getPropsLayer().shapes = [];
180
+ this.getActorsLayer().shapes = [];
123
181
  };
124
-
125
182
  /*
126
183
  * get stage canvas
127
184
  */
128
- Kinetic.Stage.prototype.getCanvas = function(){
129
- return this.canvas;
185
+ Kinetic.Stage.prototype.getCanvas = function() {
186
+ return this.stageLayer.getCanvas();
130
187
  };
131
-
132
188
  /*
133
189
  * get stage context
134
190
  */
135
- Kinetic.Stage.prototype.getContext = function(){
136
- return this.context;
191
+ Kinetic.Stage.prototype.getContext = function() {
192
+ return this.stageLayer.getContext();
137
193
  };
138
-
139
194
  /*
140
195
  * add event listener to stage (which is essentially
141
196
  * the container DOM)
142
197
  */
143
- Kinetic.Stage.prototype.addEventListener = function(type, func){
144
- this.container.addEventListener(type, func);
198
+ Kinetic.Stage.prototype.addEventListener = function(type, func) {
199
+ this.container.addEventListener(type, func);
145
200
  };
146
-
147
201
  /*
148
202
  * add shape to stage
149
203
  */
150
- Kinetic.Stage.prototype.add = function(shape){
151
- shape.stage = this;
152
- shape.canvas = document.createElement('canvas');
153
- shape.context = shape.canvas.getContext('2d');
154
- shape.id = ++this.idCounter;
155
- shape.canvas.width = this.width;
156
- shape.canvas.height = this.height;
157
- shape.canvas.style.zIndex = ++this.zIndexCounter;
158
- shape.canvas.style.position = 'absolute';
159
- this.container.appendChild(shape.canvas);
160
- this.shapes.push(shape);
161
- shape.draw();
204
+ Kinetic.Stage.prototype.add = function(shape) {
205
+ shape.stage = this;
206
+ if(shape.isProp) {
207
+ shape.layer = this.propsLayer;
208
+ } else {
209
+ shape.layer = this.actorsLayer;
210
+ }
211
+
212
+ shape.getLayer().shapes.push(shape);
213
+
214
+ shape.id = this.idCounter++;
215
+ shape.draw(shape.layer);
162
216
  };
163
-
164
217
  /*
165
218
  * handle incoming event
166
219
  */
167
- Kinetic.Stage.prototype.handleEvent = function(evt){
168
- if (!evt) {
169
- evt = window.event;
170
- }
171
-
172
- this.setMousePosition(evt);
173
- this.setTouchPosition(evt);
174
- var that = this;
175
- for (var n = this.shapes.length - 1; n >= 0; n--) {
176
- var pubShape = this.shapes[n];
177
-
178
- (function(){
179
- var shape = pubShape;
180
- var pos = that.touchPos || that.mousePos;
181
- var el = shape.eventListeners;
182
-
183
- if (pos !== null && shape.context.isPointInPath(pos.x, pos.y)) {
184
- // handle onmousedown
185
- if (that.mouseDown) {
186
- that.mouseDown = false;
187
- shape.clickStart = true;
188
-
189
- if (el.onmousedown !== undefined) {
190
- el.onmousedown(evt);
191
- }
192
-
193
- n = -1; // break;
194
- }
195
- // handle onmouseup & onclick
196
- else if (that.mouseUp) {
197
- that.mouseUp = false;
198
- if (el.onmouseup !== undefined) {
199
- el.onmouseup(evt);
200
- }
201
-
202
- // detect if click or double click occurred
203
- if (shape.clickStart) {
204
-
205
- if (el.onclick !== undefined) {
206
- el.onclick(evt);
207
- }
208
-
209
- if (el.ondblclick !== undefined && shape.inDoubleClickWindow) {
210
- el.ondblclick(evt);
211
- }
212
-
213
- shape.inDoubleClickWindow = true;
214
-
215
- setTimeout(function(){
216
- shape.inDoubleClickWindow = false;
217
- }, that.dblClickWindow);
218
- }
219
-
220
- n = -1; // break;
221
- }
222
-
223
- // handle onmouseover
224
- else if (!shape.mouseOver) {
225
- shape.mouseOver = true;
226
- if (el.onmouseover !== undefined) {
227
- el.onmouseover(evt);
228
- }
229
-
230
- n = -1; // break;
231
- }
232
-
233
- // handle onmousemove
234
- else if (el.onmousemove !== undefined) {
235
- el.onmousemove(evt);
236
-
237
- n = -1; // break;
238
- }
239
-
240
- // handle touchstart
241
- else if (that.touchStart) {
242
- that.touchStart = false;
243
- if (el.touchstart !== undefined) {
244
- el.touchstart(evt);
245
- }
246
-
247
- n = -1; // break;
248
- }
249
-
250
- // handle touchend
251
- else if (that.touchEnd) {
252
- that.touchEnd = false;
253
- if (el.touchend !== undefined) {
254
- el.touchend(evt);
255
- }
256
-
257
- n = -1; // break;
258
- }
259
-
260
- // handle touchmove
261
- else if (!that.touchMove) {
262
- if (el.touchmove !== undefined) {
263
- el.touchmove(evt);
264
- }
265
-
266
- n = -1; // break;
267
- }
268
- }
269
- // handle mouseout condition
270
- else if (shape.mouseOver) {
271
- shape.mouseOver = false;
272
- if (el.onmouseout !== undefined) {
273
- el.onmouseout(evt);
274
- }
275
-
276
- n = -1; // break;
277
- }
278
- }());
279
- }
220
+ Kinetic.Stage.prototype.handleEvent = function(evt) {
221
+ if(!evt) {
222
+ evt = window.event;
223
+ }
224
+
225
+ this.setMousePosition(evt);
226
+ this.setTouchPosition(evt);
227
+
228
+ var backStageLayer = this.backStageLayer;
229
+ var backStageLayerContext = backStageLayer.getContext();
230
+ var that = this;
231
+
232
+ backStageLayer.clear();
233
+
234
+ for(var n = this.getShapes().length - 1; n >= 0; n--) {
235
+ var pubShape = this.getShapes()[n]; ( function() {
236
+ var shape = pubShape;
237
+ shape.draw(backStageLayer);
238
+ var pos = that.touchPos || that.mousePos;
239
+ var el = shape.eventListeners;
240
+
241
+ if(shape.visible && pos !== null && backStageLayerContext.isPointInPath(pos.x, pos.y)) {
242
+ // handle onmousedown
243
+ if(that.mouseDown) {
244
+ that.mouseDown = false;
245
+ shape.clickStart = true;
246
+
247
+ if(el.onmousedown !== undefined) {
248
+ el.onmousedown(evt);
249
+ }
250
+ n = -1;
251
+ }
252
+ // handle onmouseup & onclick
253
+ else if(that.mouseUp) {
254
+ that.mouseUp = false;
255
+ if(el.onmouseup !== undefined) {
256
+ el.onmouseup(evt);
257
+ }
258
+
259
+ // detect if click or double click occurred
260
+ if(shape.clickStart) {
261
+
262
+ if(el.onclick !== undefined) {
263
+ el.onclick(evt);
264
+ }
265
+
266
+ if(el.ondblclick !== undefined && shape.inDoubleClickWindow) {
267
+ el.ondblclick(evt);
268
+ }
269
+
270
+ shape.inDoubleClickWindow = true;
271
+
272
+ setTimeout(function() {
273
+ shape.inDoubleClickWindow = false;
274
+ }, that.dblClickWindow);
275
+ }
276
+ n = -1;
277
+ }
278
+
279
+ // handle touchstart
280
+ else if(that.touchStart) {
281
+ that.touchStart = false;
282
+ if(el.touchstart !== undefined) {
283
+ el.touchstart(evt);
284
+ }
285
+ n = -1;
286
+ }
287
+
288
+ // handle touchend
289
+ else if(that.touchEnd) {
290
+ that.touchEnd = false;
291
+ if(el.touchend !== undefined) {
292
+ el.touchend(evt);
293
+ }
294
+ n = -1;
295
+ }
296
+
297
+ // handle touchmove
298
+ else if(el.touchmove !== undefined) {
299
+ el.touchmove(evt);
300
+ n = -1;
301
+ }
302
+
303
+ // handle onmouseover
304
+ else if(!shape.mouseOver) {
305
+ shape.mouseOver = true;
306
+ if(el.onmouseover !== undefined) {
307
+ el.onmouseover(evt);
308
+ }
309
+ n = -1;
310
+ }
311
+
312
+ // handle onmousemove
313
+ else if(el.onmousemove !== undefined) {
314
+ el.onmousemove(evt);
315
+ n = -1;
316
+ }
317
+ }
318
+ // handle mouseout condition
319
+ else if(shape.mouseOver) {
320
+ shape.mouseOver = false;
321
+ if(el.onmouseout !== undefined) {
322
+ el.onmouseout(evt);
323
+ }
324
+ n = -1;
325
+ }
326
+ }());
327
+ }
280
328
  };
281
-
282
329
  /*
283
330
  * begin listening for events by adding event handlers
284
331
  * to the container
285
332
  */
286
- Kinetic.Stage.prototype.listen = function(){
287
- var that = this;
288
-
289
- // desktop events
290
- this.container.addEventListener("mousedown", function(evt){
291
- that.mouseDown = true;
292
- that.handleEvent(evt);
293
- }, false);
294
-
295
- this.container.addEventListener("mousemove", function(evt){
296
- that.mouseUp = false;
297
- that.mouseDown = false;
298
- that.handleEvent(evt);
299
- }, false);
300
-
301
- this.container.addEventListener("mouseup", function(evt){
302
- that.mouseUp = true;
303
- that.mouseDown = false;
304
- that.handleEvent(evt);
305
-
306
- // clear all click starts
307
- for (var i = 0; i < that.shapes.length; i++) {
308
- that.shapes[i].clickStart = false;
309
- }
310
- }, false);
311
-
312
- this.container.addEventListener("mouseover", function(evt){
313
- that.handleEvent(evt);
314
- }, false);
315
-
316
- this.container.addEventListener("mouseout", function(evt){
317
- that.mousePos = null;
318
- }, false);
319
-
320
- // mobile events
321
- this.container.addEventListener("touchstart", function(evt){
322
- evt.preventDefault();
323
- that.touchStart = true;
324
- that.handleEvent(evt);
325
- }, false);
326
-
327
- this.container.addEventListener("touchmove", function(evt){
328
- evt.preventDefault();
329
- that.handleEvent(evt);
330
- }, false);
331
-
332
- this.container.addEventListener("touchend", function(evt){
333
- evt.preventDefault();
334
- that.touchEnd = true;
335
- that.handleEvent(evt);
336
- }, false);
333
+ Kinetic.Stage.prototype.listen = function() {
334
+ var that = this;
335
+
336
+ // desktop events
337
+ this.container.addEventListener("mousedown", function(evt) {
338
+ that.mouseDown = true;
339
+ that.handleEvent(evt);
340
+ }, false);
341
+
342
+ this.container.addEventListener("mousemove", function(evt) {
343
+ that.mouseUp = false;
344
+ that.mouseDown = false;
345
+ that.handleEvent(evt);
346
+ }, false);
347
+
348
+ this.container.addEventListener("mouseup", function(evt) {
349
+ that.mouseUp = true;
350
+ that.mouseDown = false;
351
+ that.handleEvent(evt);
352
+
353
+ // clear all click starts
354
+ for(var i = 0; i < that.getShapes().length; i++) {
355
+ that.getShapes()[i].clickStart = false;
356
+ }
357
+ }, false);
358
+
359
+ this.container.addEventListener("mouseover", function(evt) {
360
+ that.handleEvent(evt);
361
+ }, false);
362
+
363
+ this.container.addEventListener("mouseout", function(evt) {
364
+ that.mousePos = null;
365
+ }, false);
366
+ // mobile events
367
+ this.container.addEventListener("touchstart", function(evt) {
368
+ evt.preventDefault();
369
+ that.touchStart = true;
370
+ that.handleEvent(evt);
371
+ }, false);
372
+
373
+ this.container.addEventListener("touchmove", function(evt) {
374
+ evt.preventDefault();
375
+ that.handleEvent(evt);
376
+ }, false);
377
+
378
+ this.container.addEventListener("touchend", function(evt) {
379
+ evt.preventDefault();
380
+ that.touchEnd = true;
381
+ that.handleEvent(evt);
382
+ }, false);
337
383
  };
338
-
339
384
  /*
340
385
  * get mouse position for desktop apps
341
386
  */
342
- Kinetic.Stage.prototype.getMousePos = function(evt){
343
- return this.mousePos;
387
+ Kinetic.Stage.prototype.getMousePos = function(evt) {
388
+ return this.mousePos;
344
389
  };
345
-
346
390
  /*
347
391
  * get touch position for mobile apps
348
392
  */
349
- Kinetic.Stage.prototype.getTouchPos = function(evt){
350
- return this.touchPos;
393
+ Kinetic.Stage.prototype.getTouchPos = function(evt) {
394
+ return this.touchPos;
351
395
  };
352
-
353
396
  /*
354
397
  * set mouse positon for desktop apps
355
398
  */
356
- Kinetic.Stage.prototype.setMousePosition = function(evt){
357
- var mouseX = evt.clientX - this.getContainerPos().left + window.pageXOffset;
358
- var mouseY = evt.clientY - this.getContainerPos().top + window.pageYOffset;
359
- this.mousePos = {
360
- x: mouseX,
361
- y: mouseY
362
- };
399
+ Kinetic.Stage.prototype.setMousePosition = function(evt) {
400
+ var mouseX = evt.clientX - this.getContainerPos().left + window.pageXOffset;
401
+ var mouseY = evt.clientY - this.getContainerPos().top + window.pageYOffset;
402
+ this.mousePos = {
403
+ x : mouseX,
404
+ y : mouseY
405
+ };
363
406
  };
364
-
365
407
  /*
366
408
  * set touch position for mobile apps
367
409
  */
368
- Kinetic.Stage.prototype.setTouchPosition = function(evt){
369
- if (evt.touches !== undefined && evt.touches.length == 1) { // Only deal with
370
- // one finger
371
- var touch = evt.touches[0];
372
- // Get the information for finger #1
373
- var touchX = touch.clientX - this.getContainerPos().left + window.pageXOffset;
374
- var touchY = touch.clientY - this.getContainerPos().top + window.pageYOffset;
375
-
376
- this.touchPos = {
377
- x: touchX,
378
- y: touchY
379
- };
380
- }
410
+ Kinetic.Stage.prototype.setTouchPosition = function(evt) {
411
+ if(evt.touches !== undefined && evt.touches.length == 1) {// Only deal with
412
+ // one finger
413
+ var touch = evt.touches[0];
414
+ // Get the information for finger #1
415
+ var touchX = touch.clientX - this.getContainerPos().left + window.pageXOffset;
416
+ var touchY = touch.clientY - this.getContainerPos().top + window.pageYOffset;
417
+
418
+ this.touchPos = {
419
+ x : touchX,
420
+ y : touchY
421
+ };
422
+ }
381
423
  };
382
-
383
424
  /*
384
425
  * get container position
385
426
  */
386
- Kinetic.Stage.prototype.getContainerPos = function(){
387
- var obj = this.container;
388
- var top = 0;
389
- var left = 0;
390
- while (obj.tagName != "BODY") {
391
- top += obj.offsetTop;
392
- left += obj.offsetLeft;
393
- obj = obj.offsetParent;
394
- }
395
- return {
396
- top: top,
397
- left: left
398
- };
427
+ Kinetic.Stage.prototype.getContainerPos = function() {
428
+ var obj = this.container;
429
+ var top = 0;
430
+ var left = 0;
431
+ while(obj.tagName != "BODY") {
432
+ top += obj.offsetTop;
433
+ left += obj.offsetLeft;
434
+ obj = obj.offsetParent;
435
+ }
436
+ return {
437
+ top : top,
438
+ left : left
439
+ };
399
440
  };
400
-
401
441
  /*
402
442
  * get container DOM element
403
443
  */
404
- Kinetic.Stage.prototype.getContainer = function(){
405
- return this.container;
444
+ Kinetic.Stage.prototype.getContainer = function() {
445
+ return this.container;
446
+ };
447
+ /*
448
+ * get all shapes
449
+ */
450
+ Kinetic.Stage.prototype.getShapes = function() {
451
+ return (this.getPropsLayer().getShapes()).concat(this.getActorsLayer().getShapes());
406
452
  };
407
-
408
453
  /****************************************
409
454
  * Shape
410
455
  */
411
- Kinetic.Shape = function(drawFunc){
412
- this.drawFunc = drawFunc;
413
- this.x = 0;
414
- this.y = 0;
415
- this.scale = {
416
- x: 1,
417
- y: 1
418
- };
419
- this.rotation = 0; // radians
420
- this.eventListeners = {};
421
- this.mouseOver = false;
422
- this.clickStart = false;
423
- this.inDblClickWindow = false;
456
+ Kinetic.Shape = function(drawFunc, isProp) {
457
+ this.drawFunc = drawFunc;
458
+ this.isProp = isProp === undefined ? false : isProp;
459
+ this.x = 0;
460
+ this.y = 0;
461
+ this.scale = {
462
+ x : 1,
463
+ y : 1
464
+ };
465
+ this.rotation = 0;
466
+ // radians
467
+ // store state for next clear
468
+ this.lastX = 0;
469
+ this.lastY = 0;
470
+ this.lastRotation = 0;
471
+ // radians
472
+ this.lastScale = {
473
+ x : 1,
474
+ y : 1
475
+ };
476
+
477
+ this.eventListeners = {};
478
+ this.mouseOver = false;
479
+ this.clickStart = false;
480
+ this.inDblClickWindow = false;
481
+
482
+ this.visible = true;
424
483
  };
425
-
426
484
  /*
427
485
  * get stage
428
486
  */
429
- Kinetic.Shape.prototype.getStage = function(){
430
- return this.stage();
487
+ Kinetic.Shape.prototype.getStage = function() {
488
+ return this.stage;
431
489
  };
432
-
433
490
  /*
434
491
  * draw shape
435
492
  */
436
- Kinetic.Shape.prototype.draw = function(args){
437
- var context = this.getContext();
438
- this.clear();
439
- context.save();
440
-
441
- if (this.x !== 0 || this.y !== 0) {
442
- context.translate(this.x, this.y);
443
- }
444
- if (this.rotation !== 0) {
445
- context.rotate(this.rotation);
446
- }
447
- if (this.scale.x != 1 || this.scale.y != 1) {
448
- context.scale(this.scale.x, this.scale.y);
449
- }
450
-
451
- this.drawFunc(args);
452
- context.restore();
493
+ Kinetic.Shape.prototype.draw = function(layer) {
494
+ if(this.visible) {
495
+ var stage = this.getStage();
496
+ var context = layer.getContext();
497
+
498
+ context.save();
499
+
500
+ if(this.x !== 0 || this.y !== 0) {
501
+ context.translate(this.x, this.y);
502
+ }
503
+ if(this.rotation !== 0) {
504
+ context.rotate(this.rotation);
505
+ }
506
+ if(this.scale.x != 1 || this.scale.y != 1) {
507
+ context.scale(this.scale.x, this.scale.y);
508
+ }
509
+
510
+ this.drawFunc.call(layer);
511
+ context.restore();
512
+ }
453
513
  };
454
-
455
514
  /*
456
- * get shape canvas
515
+ * set shape canvas scale
457
516
  */
458
- Kinetic.Shape.prototype.getCanvas = function(){
459
- return this.canvas;
517
+ Kinetic.Shape.prototype.setScale = function(scale) {
518
+ this.scale.x = scale;
519
+ this.scale.y = scale;
460
520
  };
461
-
462
521
  /*
463
- * get shape context
522
+ * add event listener to shape
464
523
  */
465
- Kinetic.Shape.prototype.getContext = function(){
466
- return this.context;
524
+ Kinetic.Shape.prototype.addEventListener = function(type, func) {
525
+ var event = (type.indexOf('touch') == -1) ? 'on' + type : type;
526
+ this.eventListeners[event] = func;
467
527
  };
468
-
469
528
  /*
470
- * set shape canvas scale
529
+ * show shape
471
530
  */
472
- Kinetic.Shape.prototype.setScale = function(scale){
473
- this.scale.x = scale;
474
- this.scale.y = scale;
531
+ Kinetic.Shape.prototype.show = function() {
532
+ this.visible = true;
475
533
  };
476
-
477
534
  /*
478
- * clear shape canvas
535
+ * hide shape
479
536
  */
480
- Kinetic.Shape.prototype.clear = function(){
481
- var context = this.getContext();
482
- var canvas = this.getCanvas();
483
- context.clearRect(0, 0, canvas.width, canvas.height);
537
+ Kinetic.Shape.prototype.hide = function() {
538
+ this.visible = false;
484
539
  };
485
-
486
540
  /*
487
- * add event listener to shape
541
+ * move shape to top
488
542
  */
489
- Kinetic.Shape.prototype.addEventListener = function(type, func){
490
- var event = (type.indexOf('touch') == -1) ? 'on' + type : type;
491
- this.eventListeners[event] = func;
543
+ Kinetic.Shape.prototype.moveToTop = function() {
544
+ var stage = this.stage;
545
+ var layer = this.getLayer();
546
+ var shapes = layer.getShapes();
547
+
548
+ for(var n = 0; n < shapes.length; n++) {
549
+ var shape = shapes[n];
550
+ if(shape.id == this.id) {
551
+ layer.shapes.splice(n, 1);
552
+ layer.shapes.push(this);
553
+ break;
554
+ }
555
+ }
492
556
  };
493
-
494
557
  /*
495
- * move shape canvas to the top via z-index
558
+ * get shape layer
496
559
  */
497
- Kinetic.Shape.prototype.moveToTop = function(){
498
- var stage = this.stage;
499
- // remove shape from shapes
500
- for (var n = 0; n < stage.shapes.length; n++) {
501
- var reg = stage.shapes[n];
502
- if (reg.id == this.id) {
503
- stage.shapes.splice(n, 1);
504
- stage.shapes.push(this);
505
- break;
506
- }
507
- }
508
-
509
- // reorder canvases
510
- for (var n = 0; n < stage.shapes.length; n++) {
511
- var reg = stage.shapes[n];
512
- reg.getCanvas().style.zIndex = ++stage.zIndexCounter;
513
- }
560
+ Kinetic.Shape.prototype.getLayer = function() {
561
+ return this.layer;
514
562
  };
515
-
516
563
  /****************************************
517
564
  * drawImage util
518
565
  * This util function draws a rectangular shape
519
566
  * over a canvas image to provide a detectable path
520
567
  */
521
- Kinetic.drawImage = function(imageObj, x, y, width, height){
522
- if (!width) {
523
- width = imageObj.width;
524
- }
525
- if (!height) {
526
- height = imageObj.height;
527
- }
528
- return function(){
529
- var context = this.getContext();
530
- context.drawImage(imageObj, x, y, width, height);
531
- context.beginPath();
532
- context.rect(x, y, width, height);
533
- context.closePath();
534
- };
568
+ Kinetic.drawImage = function(imageObj, x, y, width, height) {
569
+ if(!width) {
570
+ width = imageObj.width;
571
+ }
572
+ if(!height) {
573
+ height = imageObj.height;
574
+ }
575
+ return function() {
576
+ var context = this.getContext();
577
+ context.drawImage(imageObj, x, y, width, height);
578
+ context.beginPath();
579
+ context.rect(x, y, width, height);
580
+ context.closePath();
581
+ };
535
582
  };
536
-
537
-
538
-
539
-
540
-
541
-