Comparing version 0.2.0 to 0.2.1
@@ -15,2 +15,3 @@ const GDIGraphics = require('./GDIGraphics'); | ||
__cbCreate: () => {}, | ||
__cbCustomMsg: () => {}, | ||
__cbPaint: () => {}, | ||
@@ -161,2 +162,8 @@ __cbResize: () => {}, | ||
}, | ||
onCustomMsg (cb) { | ||
if (!util.isFunction(cb)) { | ||
throw new Error('A callback function should be passed!'); | ||
} | ||
ret.__cbCustomMsg = cb; | ||
}, | ||
setCursor (type) { | ||
@@ -221,4 +228,5 @@ const cursorTypes = { | ||
if (!Win32Constants.wndProcMsgConstants[event.msg]) { | ||
return true; | ||
return; | ||
} | ||
const msg = { | ||
@@ -228,6 +236,15 @@ type: Win32Constants.wndProcMsgConstants[event.msg], | ||
}; | ||
if (!msg) { | ||
return true; | ||
return; | ||
} | ||
// console.log('msg', msg); | ||
const customResponse = currentWindow.__cbCustomMsg(msg); | ||
if (customResponse !== undefined) { | ||
if (!util.isInteger(customResponse)) { | ||
throw new Error('Custom msg response result should be an integer.'); | ||
} | ||
return customResponse; | ||
} | ||
if (msg.type === 'WM_CLOSE') { | ||
@@ -263,2 +280,12 @@ try { | ||
} | ||
} else if (msg.type === 'WM_NCMOUSEMOVE') { | ||
try { | ||
currentWindow.__cbMouseMove({ | ||
x: msg.event.llParam, | ||
y: msg.event.hlParam | ||
}); | ||
} catch (err) { | ||
console.error(err); | ||
process.exit(1); | ||
} | ||
} else if (msg.type === 'WM_MOUSEWHEEL') { | ||
@@ -275,19 +302,27 @@ try { | ||
} | ||
} else if (['WM_LBUTTONDOWN', 'WM_RBUTTONDOWN', 'WM_MBUTTONDOWN', 'WM_XBUTTONDOWN'].includes(msg.type)) { | ||
} else if (['WM_LBUTTONDOWN', 'WM_RBUTTONDOWN', 'WM_MBUTTONDOWN', 'WM_XBUTTONDOWN', 'WM_NCLBUTTONDOWN', 'WM_NCRBUTTONDOWN', 'WM_NCMBUTTONDOWN', 'WM_NCXBUTTONDOWN'].includes(msg.type)) { | ||
let button; | ||
if (msg.type === 'WM_LBUTTONDOWN') { | ||
if (msg.type.includes('LBUTTONDOWN')) { | ||
button = 0; | ||
} else if (msg.type === 'WM_MBUTTONDOWN') { | ||
} else if (msg.type.includes('MBUTTONDOWN')) { | ||
button = 1; | ||
} else if (msg.type === 'WM_RBUTTONDOWN') { | ||
} else if (msg.type.includes('RBUTTONDOWN')) { | ||
button = 2; | ||
} | ||
try { | ||
currentWindow.__cbMouseDown({ | ||
control: !!(event.lwParam & 8), | ||
shift: !!(event.lwParam & 4), | ||
button, | ||
x: event.llParam, | ||
y: event.hlParam | ||
}); | ||
if (msg.type.startsWith('WM_NC')) { | ||
currentWindow.__cbMouseDown({ | ||
button, | ||
x: event.llParam, | ||
y: event.hlParam | ||
}); | ||
} else { | ||
currentWindow.__cbMouseDown({ | ||
control: !!(event.lwParam & 8), | ||
shift: !!(event.lwParam & 4), | ||
button, | ||
x: event.llParam, | ||
y: event.hlParam | ||
}); | ||
} | ||
} catch (err) { | ||
@@ -297,19 +332,28 @@ console.error(err); | ||
} | ||
} else if (['WM_LBUTTONUP', 'WM_RBUTTONUP', 'WM_MBUTTONUP', 'WM_XBUTTONUP'].includes(msg.type)) { | ||
} else if (['WM_LBUTTONUP', 'WM_RBUTTONUP', 'WM_MBUTTONUP', 'WM_XBUTTONUP', 'WM_NCLBUTTONUP', 'WM_NCRBUTTONUP', 'WM_NCMBUTTONUP', 'WM_NCXBUTTONUP'].includes(msg.type)) { | ||
let button; | ||
if (msg.type === 'WM_LBUTTONUP') { | ||
if (msg.type.includes('LBUTTONUP')) { | ||
button = 0; | ||
} else if (msg.type === 'WM_MBUTTONUP') { | ||
} else if (msg.type.includes('MBUTTONUP')) { | ||
button = 1; | ||
} else if (msg.type === 'WM_RBUTTONUP') { | ||
} else if (msg.type.includes('RBUTTONUP')) { | ||
button = 2; | ||
} | ||
console.log(msg.type); | ||
try { | ||
currentWindow.__cbMouseUp({ | ||
control: !!(event.lwParam & 8), | ||
shift: !!(event.lwParam & 4), | ||
button, | ||
x: event.llParam, | ||
y: event.hlParam | ||
}); | ||
if (msg.type.startsWith('WM_NC')) { | ||
currentWindow.__cbMouseUp({ | ||
button, | ||
x: event.llParam, | ||
y: event.hlParam | ||
}); | ||
} else { | ||
currentWindow.__cbMouseUp({ | ||
control: !!(event.lwParam & 8), | ||
shift: !!(event.lwParam & 4), | ||
button, | ||
x: event.llParam, | ||
y: event.hlParam | ||
}); | ||
} | ||
} catch (err) { | ||
@@ -374,3 +418,2 @@ console.error(err); | ||
} | ||
return true; | ||
} | ||
@@ -412,3 +455,4 @@ | ||
backgroundColor: [39, 40, 34], | ||
showTitleBar: true | ||
frameless: false, | ||
titleBarHeight: 0 | ||
}; | ||
@@ -431,3 +475,4 @@ const windowConfig = { ...defaultConfig, ...options }; | ||
b: windowConfig.backgroundColor[2], | ||
showTitleBar: windowConfig.showTitleBar | ||
showTitleBar: !windowConfig.frameless, | ||
titleBarHeight: windowConfig.titleBarHeight | ||
}); | ||
@@ -434,0 +479,0 @@ windowStarted = true; |
{ | ||
"name": "gdi", | ||
"version": "0.2.0", | ||
"version": "0.2.1", | ||
"description": "Node.js bindings to Windows GDI/GDI+ (graphics device interface)", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -88,3 +88,4 @@ # node-gdi | ||
backgroundColor: [39, 40, 34], | ||
showTitleBar: true | ||
frameless: false, | ||
titleBarHeight: 0 | ||
}; | ||
@@ -144,2 +145,7 @@ ``` | ||
window.onCustomMsg(cb) | ||
----- | ||
window.onKeyDown(cb) | ||
@@ -146,0 +152,0 @@ ----- |
Sorry, the diff of this file is not supported yet
112495
2109
326