Thread overview | ||||||
---|---|---|---|---|---|---|
|
August 11, 2017 GTKD resources | ||||
---|---|---|---|---|
| ||||
How can one include external files such as glade, icons, images that are static in nature in to the binary but not require extraction on program run to be used? gtk's builder doesn't seem to take an in memory representation of glade files and building a pixbuf seems quite over the top to do such simple things? |
August 11, 2017 Re: GTKD resources | ||||
---|---|---|---|---|
| ||||
Posted in reply to Mr. Pib | On 2017-08-11 13:00, Mr. Pib wrote:
> How can one include external files such as glade, icons, images that are
> static in nature in to the binary but not require extraction on program
> run to be used?
>
> gtk's builder doesn't seem to take an in memory representation of glade
> files and building a pixbuf seems quite over the top to do such simple
> things?
including the glade UI/XML defs to the executable is simple, compile with -J. switch and:
immutable string UIdefs = import("myuidefs.glade");
...
main(){
...
builder.addFromString( UIdefs );
...
|
August 11, 2017 Re: GTKD resources | ||||
---|---|---|---|---|
| ||||
Posted in reply to captaindet | On Friday, 11 August 2017 at 02:27:21 UTC, captaindet wrote: > On 2017-08-11 13:00, Mr. Pib wrote: >> How can one include external files such as glade, icons, images that are >> static in nature in to the binary but not require extraction on program >> run to be used? >> >> gtk's builder doesn't seem to take an in memory representation of glade >> files and building a pixbuf seems quite over the top to do such simple >> things? > > > including the glade UI/XML defs to the executable is simple, compile with -J. switch and: > > > immutable string UIdefs = import("myuidefs.glade"); > ... > main(){ > ... > builder.addFromString( UIdefs ); > ... Thanks. It one can use pixbuf to do something similar, albeit more complicated. https://stackoverflow.com/questions/14121166/gdk-pixbuf-load-image-from-memory |
August 12, 2017 Re: GTKD resources | ||||
---|---|---|---|---|
| ||||
Posted in reply to Mr. Pib | Here is what I came up with import gdkpixbuf.Pixbuf; GdkPixbuf*[string] __ImageCache; void SetImage(string imgName)(gtk.Image T) { import std.path, std.conv, gdkpixbuf.Pixbuf; GError* err = null; if (imgName !in __ImageCache) { GdkPixbufLoader* __PixbufLoader; writeln("Image not cached, caching: "~imgName); enum imgData = cast(ubyte[])(import(baseName(imgName)).ptr); if (__PixbufLoader == null) __PixbufLoader = gdk_pixbuf_loader_new(); assert(__PixbufLoader, "Error: Cannot create pixbuf loader!"); if (!gdk_pixbuf_loader_write(__PixbufLoader, cast(char*)imgData.ptr, imgData.length, &err)) assert(__PixbufLoader, "Error: Cannot load pixbuf loader!"); if (!gdk_pixbuf_loader_close(__PixbufLoader, &err)) assert(__PixbufLoader, "Error: Cannot create pixbuf!"); auto pixbuf = gdk_pixbuf_loader_get_pixbuf(__PixbufLoader); if (pixbuf == null) assert("Error: Cannot load pixbuf!"); __ImageCache[imgName] = pixbuf; } import gtk.c.functions; gtk_image_set_from_pixbuf(T.getImageStruct(), __ImageCache[imgName]); } Maybe that will help someone. Not sure if it is the best way but seems to work. |
Copyright © 1999-2021 by the D Language Foundation