-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.hx
187 lines (156 loc) · 4.99 KB
/
Main.hx
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
/*
this is needed atm to let qtminimal know that this file needs to be analysed and the following modules need to be generated
import (
"github.com/therecipe/qt/core"
"github.com/therecipe/qt/quick"
"github.com/therecipe/qt/gui"
"github.com/therecipe/qt/widgets"
"github.com/therecipe/qt/quickcontrols2"
)
*/
import qt.Internal;
import qt.Core;
import qt.Gui;
import qt.Widgets;
import qt.Quick;
import qt.QuickControls2;
import qt.Interop;
/*
import qt.Charts;
import qt.Bluetooth;
import qt.DataVisualization;
import qt.DBus;
import qt.Designer;
import qt.Gamepad;
import qt.Help;
import qt.Location;
import qt.MacExtras;
import qt.Multimedia;
import qt.Network;
import qt.Nfc;
import qt.Positioning;
import qt.PrintSupport;
import qt.Purchasing;
import qt.Qml;
import qt.Remoteobjects;
import qt.Sailfish;
import qt.Script;
import qt.ScriptTools;
import qt.Scxml;
import qt.Sensors;
import qt.SerialBus;
import qt.SerialPort;
import qt.Speech;
import qt.Sql;
import qt.Svg;
import qt.TestLib;
import qt.UiTools;
import qt.Virtualkeyboard;
import qt.WebChannel;
import qt.WebEngine;
import qt.WebSockets;
import qt.WebView;
import qt.Xml;
import qt.XmlPatterns;
*/
class Main {
public static function main():Void {
final process = initProcess(); // TODO: NewQApplication
//
// Haxe-Go-Qml Interop
//
final interopEngine = PseudoQJSEngine_qjsEngine(null);
final quickWidget = NewQQuickWidget(null);
final haxeFunction = function(s:String) {
trace('haxe: $s');
};
// setup the qml widget
QQuickStyle_SetStyle("Material");
quickWidget.Engine().GlobalObject().SetProperty("haxeFunction", quickWidget.Engine().NewGoType(haxeFunction));
quickWidget.Engine()
.GlobalObject()
.SetProperty("qml",
quickWidget.Engine()
.NewObject()); // create an empty object here, so we can write to it later from within Qml (since we can't directly add properties to the globalObject from within Qml)
quickWidget.SetMinimumSize(NewQSize2(400, 300));
quickWidget.SetResizeMode(1); // TODO: quick.QQuickWidget__SizeRootObjectToView
quickWidget.SetSource(NewQUrl3("qrc:/qml/main.qml", 0));
interopEngine.GlobalObject().SetProperty("quickWidget", interopEngine.NewGoType(quickWidget));
// setup the haxe widget
final hw = NewQGroupBox2("Haxe Widget", null);
hw.SetWindowTitle("Haxe-Go-Qml Interop");
final l = NewQVBoxLayout2(hw);
final callGo = NewQPushButton2("Haxe calls Go", null);
callGo.ConnectClicked(function(b:Bool) {
interopEngine.GlobalObject().Property("goFunction").Call([interopEngine.NewGoType("Hello from Haxe")]);
});
l.AddWidget_QBoxLayout(callGo, 0, 0); // TODO:
final callQml = NewQPushButton2("Haxe calls Qml", null);
callQml.ConnectClicked(function(b:Bool) {
quickWidget.Engine()
.GlobalObject()
.Property("qml")
.Property("qmlFunction")
.Call([quickWidget.Engine().NewGoType("Hello from Haxe")]);
});
l.AddWidget_QBoxLayout(callQml, 0, 0); // TODO:
interopEngine.GlobalObject().SetProperty("haxeFunction", interopEngine.NewGoType(haxeFunction));
interopEngine.GlobalObject().SetProperty("haxeWidget", interopEngine.NewGoType(hw));
// call into go and let it finish the layout setup
interopEngine.GlobalObject().Property("goSetupFunction").Call(null);
//
// simplified port of the pixel editor example: https://github.com/therecipe/qt/blob/master/internal/examples/widgets/pixel_editor/pixel_editor.go
//
if (true) {
final view = NewQGraphicsView(null);
final scene = NewQGraphicsScene(null);
view.SetScene(scene);
view.ConnectResizeEvent(function(event:QEvent) {
view.FitInView(scene.ItemsBoundingRect(), 1);
});
final img = NewQImage3(16, 32, 5);
for (x in 0...img.Width()) {
for (y in 0...img.Height()) {
img.SetPixelColor2(x, y, NewQColor3(x * 3, y * 6, x * 9, 255));
}
}
final item = NewQGraphicsPixmapItem2(QPixmap_FromImage(img, 0), null);
scene.AddItem(item);
final color = NewQColor3(255, 255, 255, 255);
final drawPixel = function(xF:Float, yF:Float) {
final x = Std.int(xF);
final y = Std.int(yF);
final pixmap = item.Pixmap();
if (x >= 1 && x < pixmap.Width() - 1 && y >= 1 && y < pixmap.Height() - 1) {
final img = item.Pixmap().ToImage();
img.SetPixelColor2(x, y, color);
item.SetPixmap(QPixmap_FromImage(img, 0));
}
}
item.ConnectMouseMoveEvent(function(event:QGraphicsSceneMouseEvent) {
final mousePosition = event.Pos();
drawPixel(mousePosition.X(), mousePosition.Y());
});
item.ConnectMousePressEvent(function(event:QGraphicsSceneMouseEvent) {
final mousePosition = event.Pos();
drawPixel(mousePosition.X(), mousePosition.Y());
});
view.Resize2(400, 800);
view.Show();
}
//
// test stack depth
//
if (true) {
final o = NewQObject(null);
o.ConnectObjectNameChanged(function(n:String) {
if (o.ObjectName().length < 200) {
o.SetObjectName(o.ObjectName() + "x");
}
});
o.SetObjectName("x");
}
//
exec(process); // TODO: QApplication_Exec
}
}