annotate nodejs/phone.js @ 791:85c5949352bb

Slide the dock of phone UI
author Thinker K.F. Li <thinker@codemud.net>
date Tue, 31 Aug 2010 02:54:54 +0800
parents 9b2d803701e0
children bf2794eed702
rev   line source
789
9b2d803701e0 Phone UI example
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
1 // -*- indent-tabs-mode: t; tab-width: 4; c-basic-offset: 4; -*-
9b2d803701e0 Phone UI example
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
2 // vim: sw=4:ts=8:sts=4:ai
9b2d803701e0 Phone UI example
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
3 var mbapp = require("./mbapp");
9b2d803701e0 Phone UI example
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
4 var sys=require("sys");
9b2d803701e0 Phone UI example
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
5 var animate=require("./animate");
9b2d803701e0 Phone UI example
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
6
9b2d803701e0 Phone UI example
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
7 app = new mbapp.app(":0.0", 320, 480);
9b2d803701e0 Phone UI example
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
8 app.loadSVG("phone_ui.svg");
9b2d803701e0 Phone UI example
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
9
9b2d803701e0 Phone UI example
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
10 var icons = [];
9b2d803701e0 Phone UI example
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
11 var r, c;
9b2d803701e0 Phone UI example
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
12 var mbname;
9b2d803701e0 Phone UI example
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
13
9b2d803701e0 Phone UI example
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
14 for(r = 0; r < 4; r++) {
9b2d803701e0 Phone UI example
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
15 for(c = 0; c < 5; c++) {
9b2d803701e0 Phone UI example
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
16 mbname = "icon" + r + "" + c;
9b2d803701e0 Phone UI example
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
17 icons.push(app.get(mbname));
9b2d803701e0 Phone UI example
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
18 }
9b2d803701e0 Phone UI example
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
19 }
9b2d803701e0 Phone UI example
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
20
9b2d803701e0 Phone UI example
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
21 var overhint, presshint;
9b2d803701e0 Phone UI example
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
22 var overholder, pressholder;
9b2d803701e0 Phone UI example
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
23 overhint = app.get("overhint");
9b2d803701e0 Phone UI example
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
24 presshint = app.get("presshint");
9b2d803701e0 Phone UI example
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
25 overholder = new animate.holder(app, overhint);
9b2d803701e0 Phone UI example
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
26 pressholder = new animate.holder(app, presshint);
9b2d803701e0 Phone UI example
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
27
9b2d803701e0 Phone UI example
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
28 var dock;
9b2d803701e0 Phone UI example
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
29 var dockholder;
9b2d803701e0 Phone UI example
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
30 dock = app.get("dock");
9b2d803701e0 Phone UI example
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
31 dockholder = new animate.holder(app, dock);
9b2d803701e0 Phone UI example
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
32
9b2d803701e0 Phone UI example
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
33 var i;
9b2d803701e0 Phone UI example
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
34 var icon;
9b2d803701e0 Phone UI example
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
35 for(i = 0; i < icons.length; i++) {
9b2d803701e0 Phone UI example
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
36 icon = icons[i];
9b2d803701e0 Phone UI example
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
37 icon.mouse_event.add_event_observer(1, function(evt) {
9b2d803701e0 Phone UI example
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
38 var tgt = evt.cur_tgt;
9b2d803701e0 Phone UI example
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
39
9b2d803701e0 Phone UI example
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
40 overholder.go_center(tgt);
9b2d803701e0 Phone UI example
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
41 });
9b2d803701e0 Phone UI example
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
42 icon.mouse_event.add_event_observer(2, function(evt) {
9b2d803701e0 Phone UI example
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
43 overholder.home();
9b2d803701e0 Phone UI example
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
44 });
9b2d803701e0 Phone UI example
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
45 icon.mouse_event.add_event_observer(4, function(evt) {
9b2d803701e0 Phone UI example
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
46 var tgt = evt.cur_tgt;
9b2d803701e0 Phone UI example
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
47
9b2d803701e0 Phone UI example
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
48 pressholder.go_center(tgt);
9b2d803701e0 Phone UI example
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
49 });
9b2d803701e0 Phone UI example
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
50 }
9b2d803701e0 Phone UI example
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
51
9b2d803701e0 Phone UI example
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
52 var sw = 0;
9b2d803701e0 Phone UI example
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
53 dock.mouse_event.add_event_observer(4, function(evt) {
791
85c5949352bb Slide the dock of phone UI
Thinker K.F. Li <thinker@codemud.net>
parents: 789
diff changeset
54 if(sw == 0) {
85c5949352bb Slide the dock of phone UI
Thinker K.F. Li <thinker@codemud.net>
parents: 789
diff changeset
55 var an = new animate.linear(app, dock, 0, -300, 0.5);
85c5949352bb Slide the dock of phone UI
Thinker K.F. Li <thinker@codemud.net>
parents: 789
diff changeset
56 an.start();
85c5949352bb Slide the dock of phone UI
Thinker K.F. Li <thinker@codemud.net>
parents: 789
diff changeset
57 } else {
85c5949352bb Slide the dock of phone UI
Thinker K.F. Li <thinker@codemud.net>
parents: 789
diff changeset
58 var an = new animate.linear(app, dock, 0, 0, 0.5);
85c5949352bb Slide the dock of phone UI
Thinker K.F. Li <thinker@codemud.net>
parents: 789
diff changeset
59 an.start();
85c5949352bb Slide the dock of phone UI
Thinker K.F. Li <thinker@codemud.net>
parents: 789
diff changeset
60 }
789
9b2d803701e0 Phone UI example
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
61 sw = (sw + 1) % 2;
9b2d803701e0 Phone UI example
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
62 });
9b2d803701e0 Phone UI example
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
63
9b2d803701e0 Phone UI example
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
64 app.loop();