forked from exebook/glxwin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
glxwin.js
132 lines (116 loc) · 4.18 KB
/
glxwin.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
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
var glxwin = require('./build/Release/glxwin.node')
TGLXWin = kindof()
TGLXWin.can.init = function(parent, fontName, fontSize, extraX, tuneY) {
this.handle = glxwin.create_win(undefined, fontName, fontSize, extraX, tuneY)
if (glxwin.mainWindow == undefined) glxwin.mainWindow = this
if (glxwin.all == undefined) glxwin.all = [this]
else glxwin.all.push(this)
}
TGLXWin.can.setXYWH = function(x, y, w, h) { glxwin.set_xywh(this.handle, x, y, w, h) }
TGLXWin.can.getXYWH = function() { return glxwin.get_xywh(this.handle) }
TGLXWin.can.show = function() { glxwin.show(this.handle) }
TGLXWin.can.step = function() { return glxwin.step(this.handle) }
TGLXWin.can.crect = function(x, y, w, h, color) { glxwin.crect(this.handle, x, y, w, h, color) }
TGLXWin.can.print = function(text, x, y) { glxwin.print(this.handle, text, x, y) }
TGLXWin.can.fontColor = function(color) { glxwin.font_color(this.handle, color) }
TGLXWin.can.applyFont = function(name, size, color, bgcolor) { return glxwin.apply_font(this.handle, name, size, color, bgcolor) }
TGLXWin.can.textExtent = function(txt) { return glxwin.text_extent(this.handle, txt) }
TGLXWin.can.repaint = function() { glxwin.repaint(this.handle) }
TGLXWin.can.forceRepaint = function() { glxwin.force_repaint(this.handle) }
TGLXWin.can.hide = function() { glxwin.hide(this.handle) }
TGLXWin.can.colorText = function(x, y, w, h, TXT, CLR) { glxwin.color_text(this.handle, x, y, w, h, TXT, CLR) }
TGLXWin.can.getXWindowHandle = function() { return glxwin.get_xwindow_handle(this.handle) }//not tested
TGLXWin.can.paintBegin = function() { glxwin.paintBegin(this.handle) }
TGLXWin.can.paintEnd = function() { glxwin.paintEnd(this.handle) }
TGLXWin.can.setCursor = function(cursor) { glxwin.setCursor(this.handle, cursor) }
TGLXWin.can.setSizeSteps = function(w, h) { glxwin.setSizeSteps(this.handle, w, h) }
glxwin.dispatch = function(hand) {
var O = this.findObject(hand.handle)
if (hand.call == 'onPaint') {
if (O.onPaint != undefined) { O.paintBegin(); O.onPaint(); O.paintEnd() }
} else if (hand.call == 'onKey') {
if (O.onKey != undefined) O.onKey(hand.down, hand.char, hand.key, hand.physical)
} else log('dispatch error')
}
glxwin.findObject = function(handle) {
for (var i = 0; i < this.all.length; i++) if (this.all[i].handle == handle) return this.all[i]
}
glxwin.onCursor = function (handle, x, y) {
var O = this.findObject(handle)
if (O.onCursor != undefined) O.onCursor(x, y)
}
glxwin.onSize = function (handle, w, h) {
var O = this.findObject(handle)
if (O.onSize != undefined) O.onSize(w, h)
}
glxwin.onMouse = function (handle, button, down, x, y) {
var O = this.findObject(handle)
if (O.onMouse != undefined) O.onMouse(button, down, x, y)
}
//glxwin.onKey = function (handle, down, char, key, physical) {
// var O = this.findObject(handle)
// if (O.onKey != undefined) O.onKey(down, char, key, physical)
//}
glxwin.onFocus = function(handle, on) {
var O = this.findObject(handle)
if (O.onFocus != undefined) if (O.onFocus(on)) O.repaint()
}
//glxwin.onPaint = function (handle) {
// var O = this.findObject(handle)
// if (O.onPaint != undefined) O.onPaint()
//}
glxwin.onPipe = function() {
var O = this.findObject(handle)
if (O.onPipe != undefined) O.onPipe()
}
glxwin.register_callbacks(glxwin)
glxwin.mainLoop = function() {
var speed = 100, timer
function slowDown() {
speed = 100
timer = undefined
}
function go() {
if (glxwin.x11quit()) {
process.exit()
return
}
var event = glxwin.step()
if (event) {
speed = 1
if (timer) clearTimeout(timer)
timer = setTimeout(slowDown, 1000)
var A = glxwin['c++callbacks']
while (A.length > 0) {
glxwin.dispatch(A.shift())
}
}
setTimeout(function() { setImmediate(go) }, speed)
}
var AR = glxwin['c++callbacks']
function rend() {
if (glxwin.x11quit()) return
glxwin.step_renders()
while (AR.length > 0) {
glxwin.dispatch(AR.shift())
}
setTimeout(rend, 20)
}
setImmediate(go)
setImmediate(rend)
}
module.exports = glxwin
/*
// MINIMAL PROGRAM
glxwin = require('./glxwin/glxwin.js')
var w = TGLXWin.create()
w.setXYWH(0, 0, 100, 100)
w.onKey = function(K) {
console.log(K)
}
w.onPaint = function() {
w.crect(0, 0, 1000, 1000, 0xff000000)
}
w.show()
glxwin.mainLoop()
*/