1
0
mirror of https://github.com/Ylianst/MeshAgent synced 2025-12-17 00:33:33 +00:00

Updated support for settting alternate background/foreground color using an options object

This commit is contained in:
Bryan Roe
2022-02-14 19:29:34 -08:00
parent 7a2356f777
commit a4d76c0ffb
4 changed files with 80 additions and 30 deletions

View File

@@ -184,6 +184,19 @@ function SCALE(val, dpi)
var factor = val / 96;
return (dpi * factor);
}
function string_RGB(s)
{
var ret = RGB(0, 0, 0);
try
{
var t = s.split(',');
ret = RGB(parseInt(t[0]), parseInt(t[1]), parseInt(t[2]));
}
catch (z)
{
}
return (ret);
}
function RGB(r, g, b)
{
return (r | (g << 8) | (b << 16));
@@ -341,7 +354,7 @@ function pump_onMessage(msg)
function pump_onHwnd(h)
{
this._HANDLE = h;
this._icon = getScaledImage(x_icon, SCALE(this.dpi / 3, this.dpi) * 0.75, SCALE(this.dpi / 3, this.dpi) * 0.75);
this._icon = getScaledImage(x_icon, SCALE(this.dpi / 3, this.dpi) * 0.75, SCALE(this.dpi / 3, this.dpi) * 0.75, this.options.background);
this._addAsyncMethodCall(this._user32.LoadCursorA.async, [0, IDC_ARROW]).then(function (cs)
{
@@ -597,6 +610,9 @@ function create(title, caption, username, options)
if (options == null) { options = {}; }
if (!options.b64Image) { options.b64Image = defaultImage; }
if (options.uid == null) { options.uid = require('user-sessions').consoleUid(); }
if (options.background != null && typeof (options.background == 'string')) { options.background = string_RGB(options.background); }
if (options.foreground != null && typeof (options.foreground == 'string')) { options.foreground = string_RGB(options.foreground); }
var self = require('user-sessions').getProcessOwnerName(process.pid).tsid;
if (self != 0)
{
@@ -678,7 +694,7 @@ function create(title, caption, username, options)
return (ret);
}
function getScaledImage(b64, width, height)
function getScaledImage(b64, width, height, background)
{
var startupinput = require('_GenericMarshal').CreateVariable(24);
var gdipToken = require('_GenericMarshal').CreatePointer();
@@ -718,8 +734,7 @@ function getScaledImage(b64, width, height)
console.info1('DrawImage: ' + gdip.GdipDrawImageRectI(graphics.Deref(), pimage.Deref(), 0, 0, width, height).Val);
var scaledhbitmap = GM.CreatePointer();
//console.info1('GetScaledHBITMAP: ' + gdip.GdipCreateHBITMAPFromBitmap(nb.Deref(), scaledhbitmap, options.background).Val);
console.info1('GetScaledHBITMAP: ' + gdip.GdipCreateHBITMAPFromBitmap(nb.Deref(), scaledhbitmap, gdip_RGB(0, 54, 105)).Val);
console.info1('GetScaledHBITMAP: ' + gdip.GdipCreateHBITMAPFromBitmap(nb.Deref(), scaledhbitmap, gdip_RGB(background)).Val);
console.info1('ImageDispose: ' + gdip.GdipDisposeImage(pimage.Deref()).Val);
scaledhbitmap._token = gdipToken;
return (scaledhbitmap);