1
|
1 |
|
|
2 |
// Initialization.
|
|
3 |
D.init();
|
|
4 |
|
0
|
5 |
|
|
6 |
$( window ).ready( function() {
|
1
|
7 |
|
|
8 |
// FIXME: screwin around
|
|
9 |
var updateIdle = function() {
|
|
10 |
var idlesecs = Math.round( Ti.UI.getIdleTime() / 1000 );
|
|
11 |
Ti.UI.setBadge( idlesecs.toString() );
|
|
12 |
D.delay( updateIdle, 1000, true );
|
|
13 |
};
|
|
14 |
updateIdle();
|
|
15 |
|
|
16 |
// FIXME: more screwin around
|
|
17 |
$( '.thing' ).contextmenu( function( event ) {
|
|
18 |
var menu = Ti.UI.createMenu();
|
|
19 |
var val = $(this).data( 'value' );
|
|
20 |
|
|
21 |
menu.addItem( 'Whoa!', function() {
|
|
22 |
console.log( "This seems to have worked: " + val );
|
|
23 |
});
|
|
24 |
|
|
25 |
D.window.main.setContextMenu( menu );
|
|
26 |
event.stopPropagation();
|
|
27 |
});
|
|
28 |
|
|
29 |
$( '.save' ).click( function() {
|
|
30 |
var canvas = $( '#draw' )[0];
|
|
31 |
var img = canvas.toDataURL( "image/png" ).replace( 'data:image/png;base64,', '' );
|
|
32 |
img = window.atob( img );
|
|
33 |
|
|
34 |
D.window.main.openSaveAsDialog( function( path ) {
|
|
35 |
if ( path.length != 1 ) return;
|
|
36 |
|
|
37 |
var file = Ti.Filesystem.getFileStream( path[0] );
|
|
38 |
file.open( Ti.Filesystem.MODE_WRITE, true, false );
|
|
39 |
file.write( img );
|
|
40 |
file.close();
|
0
|
41 |
|
1
|
42 |
Processing.getInstanceById( 'draw' ).setup();
|
|
43 |
},
|
|
44 |
{
|
|
45 |
title: "Save image..",
|
|
46 |
path: Ti.Filesystem.getDesktopDirectory().toString(),
|
|
47 |
types: [ 'png' ],
|
|
48 |
defaultFile: 'image.png'
|
|
49 |
});
|
|
50 |
});
|
|
51 |
|
|
52 |
|
|
53 |
// If we're in development mode, automatically display the inspector.
|
|
54 |
if ( D.devmode() ) D.window.main.showInspector( true );
|
|
55 |
|
|
56 |
// Make sure we're able to talk to the remote server.
|
0
|
57 |
//
|
1
|
58 |
var remoteCheck = function() {
|
|
59 |
if ( D.tf.version ) return; // all is well
|
|
60 |
|
|
61 |
// URI configured, but unable to get the version.
|
|
62 |
//
|
|
63 |
if ( D.tf.uri ) {
|
|
64 |
D.notify( 'Offline', 'Unable to talk to the Thingfish server!' );
|
|
65 |
}
|
|
66 |
|
|
67 |
// No URI configured.
|
|
68 |
//
|
|
69 |
else {
|
|
70 |
D.window.prefs = D.window.main.createWindow( 'app://window/prefs.html#server' );
|
|
71 |
D.window.prefs.open();
|
|
72 |
D.notify( 'Configuration needed.', 'Please point me to a Thingfish server URI!' );
|
|
73 |
}
|
|
74 |
};
|
|
75 |
|
|
76 |
// Skip the splash screen.
|
|
77 |
//
|
|
78 |
if ( D.getBoolPref('hidesplash') ) {
|
|
79 |
if ( D.getBoolPref('remember_window') ) D.setWindowState();
|
|
80 |
remoteCheck();
|
0
|
81 |
}
|
|
82 |
|
1
|
83 |
// "Regular" behavior. Hide the main window, show splash
|
|
84 |
// before continuing.
|
0
|
85 |
//
|
1
|
86 |
else {
|
0
|
87 |
D.window.main.hide();
|
|
88 |
D.window.splash = D.window.main.createWindow( 'app://window/splash.html' );
|
|
89 |
D.window.splash.setTopMost( true );
|
|
90 |
D.window.splash.open();
|
|
91 |
|
1
|
92 |
// Show the main window after a few moments.
|
|
93 |
//
|
|
94 |
D.delay(function() {
|
|
95 |
D.window.splash.close();
|
0
|
96 |
D.window.main.show();
|
1
|
97 |
if ( D.getBoolPref('remember_window') ) D.setWindowState();
|
|
98 |
remoteCheck();
|
|
99 |
}, 3000, true );
|
|
100 |
}
|
0
|
101 |
});
|
|
102 |
|