forked from Moddable-OpenSource/moddable
-
Notifications
You must be signed in to change notification settings - Fork 0
/
piuBehavior.c
130 lines (120 loc) · 4.09 KB
/
piuBehavior.c
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/*
* Copyright (c) 2016-2017 Moddable Tech, Inc.
*
* This file is part of the Moddable SDK Runtime.
*
* The Moddable SDK Runtime is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* The Moddable SDK Runtime is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the Moddable SDK Runtime. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "piuAll.h"
void PiuBehaviorOnCreate(void* it)
{
PiuContent* content = it;
if ((*content)->behavior) {
xsMachine* the = (*content)->the;
xsVar(0) = xsReference((*content)->behavior);
if (xsFindResult(xsVar(0), xsID_onCreate)) {
xsVar(1) = xsReference((*content)->reference);
(void)xsCallFunction3(xsResult, xsVar(0), xsVar(1), xsArg(0), xsArg(1));
}
}
}
void PiuBehaviorOnDefaultID(void* it, xsIdentifier id)
{
PiuContent* content = it;
if ((*content)->behavior) {
xsBeginHost((*content)->the);
xsVars(2);
xsVar(0) = xsReference((*content)->behavior);
if (xsFindResult(xsVar(0), id)) {
xsVar(1) = xsReference((*content)->reference);
(void)xsCallFunction1(xsResult, xsVar(0), xsVar(1));
}
xsEndHost((*content)->the);
}
}
void PiuBehaviorOnDraw(void* it, PiuRectangle area)
{
PiuContent* content = it;
if ((*content)->behavior) {
xsBeginHost((*content)->the);
xsVars(2);
xsVar(0) = xsReference((*content)->behavior);
if (xsFindResult(xsVar(0), xsID_onDraw)) {
xsVar(1) = xsReference((*content)->reference);
(void)xsCallFunction5(xsResult, xsVar(0), xsVar(1), xsPiuCoordinate(area->x), xsPiuCoordinate(area->y), xsPiuDimension(area->width), xsPiuDimension(area->height));
}
xsEndHost((*content)->the);
}
}
void PiuBehaviorOnFitID(void* it, xsIdentifier id, PiuDimension dimension)
{
PiuContent* content = it;
if ((*content)->behavior) {
xsBeginHost((*content)->the);
xsVars(2);
xsVar(0) = xsReference((*content)->behavior);
if (xsFindResult(xsVar(0), id)) {
xsVar(1) = xsReference((*content)->reference);
(void)xsCallFunction2(xsResult, xsVar(0), xsVar(1), xsPiuDimension(dimension));
}
xsEndHost((*content)->the);
}
}
PiuDimension PiuBehaviorOnMeasureID(void* it, xsIdentifier id, PiuDimension dimension)
{
PiuContent* content = it;
if ((*content)->behavior) {
xsBeginHost((*content)->the);
xsVars(2);
xsVar(0) = xsReference((*content)->behavior);
if (xsFindResult(xsVar(0), id)) {
xsVar(1) = xsReference((*content)->reference);
dimension = xsToPiuDimension(xsCallFunction2(xsResult, xsVar(0), xsVar(1), xsPiuDimension(dimension)));
}
xsEndHost((*content)->the);
}
return dimension;
}
PiuBoolean PiuBehaviorOnMouseID(void* it, xsIdentifier id, PiuCoordinate x, PiuCoordinate y)
{
PiuBoolean result = 0;
PiuContent* content = it;
if ((*content)->behavior) {
xsBeginHost((*content)->the);
xsVars(2);
xsVar(0) = xsReference((*content)->behavior);
if (xsFindResult(xsVar(0), id)) {
xsVar(1) = xsReference((*content)->reference);
result = (PiuBoolean)xsToBoolean(xsCallFunction3(xsResult, xsVar(0), xsVar(1), xsPiuCoordinate(x), xsPiuCoordinate(y)));
}
xsEndHost((*content)->the);
}
return result;
}
void PiuBehaviorOnTouchID(void* it, xsIdentifier id, xsIntegerValue index, PiuCoordinate x, PiuCoordinate y, double ticks, PiuTouchLink* link)
{
PiuContent* content = it;
if ((*content)->behavior) {
xsBeginHost((*content)->the);
xsVars(3);
xsVar(0) = xsReference((*content)->behavior);
if (xsFindResult(xsVar(0), id)) {
xsVar(1) = xsReference((*content)->reference);
xsVar(2) = xsReference((*link)->reference);
(void)xsCallFunction6(xsResult, xsVar(0), xsVar(1), xsInteger(index), xsPiuCoordinate(x), xsPiuCoordinate(y), xsNumber(ticks), xsVar(2));
}
xsEndHost((*content)->the);
}
}