annotate nodejs/phone.js @ 856:88f4916a0691 abs_n_rel_center

Compute y position according center of lightbar and text
author Thinker K.F. Li <thinker@codemud.net>
date Mon, 20 Sep 2010 22:43:43 +0800
parents 586e50f82c1f
children 23dffb564ace
rev   line source
794
a27606be2cab Change modeline
Thinker K.F. Li <thinker@codemud.net>
parents: 793
diff changeset
1 // -*- indent-tabs-mode: t; tab-width: 8; c-basic-offset: 4; -*-
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 800
diff changeset
2 // vim: sw=4:ts=8:sts=4
789
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;
796
0b1764cd53b0 Fix missed naming for variables
Thinker K.F. Li <thinker@codemud.net>
parents: 795
diff changeset
13 for(c = 0; c < 4; c++) { // 4 columns
0b1764cd53b0 Fix missed naming for variables
Thinker K.F. Li <thinker@codemud.net>
parents: 795
diff changeset
14 for(r = 0; r < 5; r++) { // 5 rows
0b1764cd53b0 Fix missed naming for variables
Thinker K.F. Li <thinker@codemud.net>
parents: 795
diff changeset
15 mbname = "icon" + c + "" + r;
789
9b2d803701e0 Phone UI example
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
16 icons.push(app.get(mbname));
9b2d803701e0 Phone UI example
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
17 }
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 var overhint, presshint;
9b2d803701e0 Phone UI example
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
21 var overholder, pressholder;
9b2d803701e0 Phone UI example
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
22 overhint = app.get("overhint");
9b2d803701e0 Phone UI example
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
23 presshint = app.get("presshint");
9b2d803701e0 Phone UI example
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
24 overholder = new animate.holder(app, overhint);
9b2d803701e0 Phone UI example
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
25 pressholder = new animate.holder(app, presshint);
9b2d803701e0 Phone UI example
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
26
9b2d803701e0 Phone UI example
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
27 var dock;
9b2d803701e0 Phone UI example
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
28 var dockholder;
9b2d803701e0 Phone UI example
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
29 dock = app.get("dock");
9b2d803701e0 Phone UI example
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
30 dockholder = new animate.holder(app, dock);
9b2d803701e0 Phone UI example
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
31
9b2d803701e0 Phone UI example
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
32 var i;
9b2d803701e0 Phone UI example
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
33 var icon;
9b2d803701e0 Phone UI example
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
34 for(i = 0; i < icons.length; i++) {
9b2d803701e0 Phone UI example
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
35 icon = icons[i];
9b2d803701e0 Phone UI example
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
36 icon.mouse_event.add_event_observer(1, function(evt) {
792
bf2794eed702 Remove redundant code
Thinker K.F. Li <thinker@codemud.net>
parents: 791
diff changeset
37 overholder.go_center(evt.cur_tgt);
789
9b2d803701e0 Phone UI example
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
38 });
9b2d803701e0 Phone UI example
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
39 icon.mouse_event.add_event_observer(2, function(evt) {
9b2d803701e0 Phone UI example
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
40 overholder.home();
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(4, function(evt) {
792
bf2794eed702 Remove redundant code
Thinker K.F. Li <thinker@codemud.net>
parents: 791
diff changeset
43 pressholder.go_center(evt.cur_tgt);
800
76470d692bb9 Rotate an icon when it is pressed
Thinker K.F. Li <thinker@codemud.net>
parents: 797
diff changeset
44 var rotate = new animate.rotate(app, evt.cur_tgt, 2 * 3.1415, 0.7);
76470d692bb9 Rotate an icon when it is pressed
Thinker K.F. Li <thinker@codemud.net>
parents: 797
diff changeset
45 rotate.start();
789
9b2d803701e0 Phone UI example
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
46 });
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
9b2d803701e0 Phone UI example
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
49 var sw = 0;
793
cad706a8f5b1 Simplify phone.js
Thinker K.F. Li <thinker@codemud.net>
parents: 792
diff changeset
50 var dock_up = new animate.linear(app, dock, 0, -300, 0.5);
795
46a4cd4d382b Remove dependent on system time to gain frame rate
Thinker K.F. Li <thinker@codemud.net>
parents: 794
diff changeset
51 var dock_down = new animate.linear(app, dock, 0, 0, 0.2);
789
9b2d803701e0 Phone UI example
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
52 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
53 if(sw == 0) {
793
cad706a8f5b1 Simplify phone.js
Thinker K.F. Li <thinker@codemud.net>
parents: 792
diff changeset
54 dock_up.start();
791
85c5949352bb Slide the dock of phone UI
Thinker K.F. Li <thinker@codemud.net>
parents: 789
diff changeset
55 } else {
793
cad706a8f5b1 Simplify phone.js
Thinker K.F. Li <thinker@codemud.net>
parents: 792
diff changeset
56 dock_down.start();
791
85c5949352bb Slide the dock of phone UI
Thinker K.F. Li <thinker@codemud.net>
parents: 789
diff changeset
57 }
793
cad706a8f5b1 Simplify phone.js
Thinker K.F. Li <thinker@codemud.net>
parents: 792
diff changeset
58 sw = sw ^ 1;
789
9b2d803701e0 Phone UI example
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
59 });
9b2d803701e0 Phone UI example
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
60
9b2d803701e0 Phone UI example
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
61 app.loop();