-
Notifications
You must be signed in to change notification settings - Fork 1
/
canvas.js
56 lines (53 loc) · 2.04 KB
/
canvas.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// Image scaling page
//
exports.View =
{
title: "Canvas",
elements:
[
{ control: "canvas", width: "*", height: "300", contents: [
{ control: "rectangle", width: "100", height: "100", left: "{redLeft}", top: "{redTop}", color: "Red", margin: 0, binding: "redTapped" },
{ control: "rectangle", width: "100", height: "100", left: "100", top: "100", color: "Green", margin: 0, binding: "greenTapped" },
] },
{ control: "stackpanel", orientation: "Horizontal", contents: [
{ control: "text", value: "Red Left", fontsize: 10, width: 140, verticalAlignment: "Center" },
{ control: "slider", minimum: 0, maximum: 200, binding: "redLeft", width: 300, verticalAlignment: "Center" },
] },
{ control: "stackpanel", orientation: "Horizontal", contents: [
{ control: "text", value: "Red Top", fontsize: 10, width: 140, verticalAlignment: "Center" },
{ control: "slider", minimum: 0, maximum: 200, binding: "redTop", width: 300, verticalAlignment: "Center" },
] },
{ control: "text", value: "{message}", fontsize: 12, visibility: "{message}" },
]
}
exports.InitializeViewModel = function (context, session)
{
var viewModel =
{
redLeft: 50,
redTop: 50,
message: null
}
return viewModel;
}
function waitInterval(intervalMillis, callback)
{
setTimeout(function(){callback()}, intervalMillis);
}
exports.Commands =
{
redTapped: function * (context, session, viewModel)
{
viewModel.message = "Red tapped";
yield Synchro.interimUpdateAwaitable(context);
yield Synchro.yieldAwaitable(context, function(callback){ waitInterval(1000, callback) });;
viewModel.message = "";
},
greenTapped: function * (context, session, viewModel)
{
viewModel.message = "Green tapped";
yield Synchro.interimUpdateAwaitable(context);
yield Synchro.yieldAwaitable(context, function(callback){ waitInterval(1000, callback) });;
viewModel.message = "";
},
}