Support colour

This commit is contained in:
Lea Anthony
2020-09-22 20:46:36 +10:00
parent 5572fccaf6
commit 52bb397105
10 changed files with 45 additions and 30 deletions

View File

@@ -6,4 +6,5 @@ var Default = &Options{
Width: 1024,
Height: 768,
DevTools: true,
Colour: 0xFFFFFFFF,
}

View File

@@ -14,6 +14,7 @@ type Options struct {
MaxHeight int
StartHidden bool
DevTools bool
Colour int
Mac MacOptions
}

View File

@@ -126,6 +126,14 @@ type DispatchClient interface {
SendMessage(string)
}
func intToColour(colour int) (C.int, C.int, C.int, C.int) {
var alpha = C.int(colour & 0xFF)
var blue = C.int((colour >> 8) & 0xFF)
var green = C.int((colour >> 16) & 0xFF)
var red = C.int((colour >> 24) & 0xFF)
return red, green, blue, alpha
}
// Run the application
func (a *Application) Run(incomingDispatcher Dispatcher, bindings string) error {
title := a.string2CString(a.config.Title)
@@ -158,6 +166,11 @@ func (a *Application) Run(incomingDispatcher Dispatcher, bindings string) error
C.DisableFrame(a.app)
}
if a.config.Colour != 0 {
r, b, g, alpha := intToColour(a.config.Colour)
C.SetColour(a.app, r, g, b, alpha)
}
// Escape bindings so C doesn't freak out
bindings = strings.ReplaceAll(bindings, `"`, `\"`)

View File

@@ -20,6 +20,7 @@ extern void ToggleMaximise(void *app);
extern void Minimise(void *app);
extern void Unminimise(void *app);
extern void ToggleMinimise(void *app);
extern void SetColour(void *app, int red, int green, int blue, int alpha);
extern void SetSize(void *app, int width, int height);
extern void SetPosition(void *app, int x, int y);
extern void Quit(void *app);
@@ -27,7 +28,6 @@ extern void SetTitle(void *app, const char *title);
extern void Fullscreen(void *app);
extern void UnFullscreen(void *app);
extern void ToggleFullscreen(void *app);
extern int SetColour(void *app, const char *colourString);
extern void DisableFrame(void *app);
extern char *SaveFileDialog(void *appPointer, char *title, char *filter);
extern char *OpenFileDialog(void *appPointer, char *title, char *filter);

View File

@@ -114,9 +114,9 @@ func (c *Client) WindowSize(width int, height int) {
}
// WindowSetColour sets the window colour
func (c *Client) WindowSetColour(colour string) bool {
result := C.SetColour(c.app.app, c.app.string2CString(colour))
return result == 1
func (c *Client) WindowSetColour(colour int) {
r, b, g, a := intToColour(colour)
C.SetColour(c.app.app, r, g, b, a)
}
// OpenFileDialog will open a file dialog with the given title

View File

@@ -7,7 +7,6 @@
// Macros to make it slightly more sane
#define msg objc_msgSend
#define msg_stret objc_msgSend_stret
#define c(str) (id)objc_getClass(str)
#define s(str) sel_registerName(str)
@@ -108,6 +107,10 @@ struct Application {
int resizable;
int devtools;
int fullscreen;
int red;
int green;
int blue;
int alpha;
// Features
int frame;
@@ -155,6 +158,13 @@ void UseToolbar(struct Application *app) {
app->useToolBar = 1;
}
void SetColour(struct Application *app, int red, int green, int blue, int alpha) {
app->red = red;
app->green = green;
app->blue = blue;
app->alpha = alpha;
}
void FullSizeContent(struct Application *app) {
app->fullSizeContent = 1;
}
@@ -482,23 +492,6 @@ char* OpenDirectoryDialog(void *appPointer, char *title) {
return foldername;
}
// SetColour sets the colour of the webview to the given colour string
int SetColour(void *appPointer, const char *colourString) {
Debug("SetColour Called with: %s", colourString);
// struct Application *app = (struct Application*) appPointer;
// GdkRGBA rgba;
// gboolean result = gdk_rgba_parse(&rgba, colourString);
// if (result == FALSE) {
// return 0;
// }
// Debug("Setting webview colour to: %s", colourString);
// webkit_web_view_get_background_color((WebKitWebView*)(app->webView), &rgba);
// int c = NS_RGBA(1, 0, 0, 0.5);
return 1;
}
const char *invoke = "window.external={invoke:function(x){window.webkit.messageHandlers.external.postMessage(x);}};";
// DisableFrame disables the window frame
@@ -693,7 +686,6 @@ void Run(void *applicationPointer, int argc, char **argv) {
}
if( app->fullSizeContent || app->frame == 0) {
Debug("FULLSIZECONTENTT!!!!!!");
decorations |= NSWindowStyleMaskFullSizeContentView;
}
@@ -733,6 +725,14 @@ void Run(void *applicationPointer, int argc, char **argv) {
// Set Style Mask
msg(mainWindow, s("setStyleMask:"), decorations);
// Set Colour
id colour = msg(c("NSColor"), s("colorWithCalibratedRed:green:blue:alpha:"),
(float)app->red / 255.0,
(float)app->green / 255.0,
(float)app->blue / 255.0,
(float)app->alpha / 255.0);
msg(mainWindow, s("setBackgroundColor:"), colour);
// Setup webview

View File

@@ -28,7 +28,7 @@ type Client interface {
WindowSize(width int, height int)
WindowFullscreen()
WindowUnFullscreen()
WindowSetColour(colour string) bool
WindowSetColour(colour int)
}
// DispatchClient is what the frontends use to interface with the

View File

@@ -231,7 +231,7 @@ func (d *Dispatcher) processWindowMessage(result *servicebus.Message) {
client.frontend.WindowUnFullscreen()
}
case "setcolour":
colour, ok := result.Data().(string)
colour, ok := result.Data().(int)
if !ok {
d.logger.Error("Invalid colour for 'window:setcolour' : %#v", result.Data())
return

View File

@@ -59,8 +59,7 @@ func (wc *WebClient) WindowFullscreen() {}
func (wc *WebClient) WindowUnFullscreen() {}
// WindowSetColour is a noop in the webclient
func (wc *WebClient) WindowSetColour(colour string) bool {
return false
func (wc *WebClient) WindowSetColour(colour int) {
}
// Run processes messages from the remote webclient

View File

@@ -20,11 +20,12 @@ func main() {
Height: 620,
DisableResize: false,
Fullscreen: false,
Colour: 0xFF000088,
Mac: wails.MacOptions{
HideTitle: true,
HideTitle: false,
HideTitleBar: false,
TitlebarAppearsTransparent: false,
FullSizeContent: true,
TitlebarAppearsTransparent: true,
FullSizeContent: false,
UseToolbar: true,
HideToolbarSeparator: true,
},