digitalmars.D.learn - GTKD resources
- Mr. Pib (6/6) Aug 10 2017 How can one include external files such as glade, icons, images
- captaindet (9/15) Aug 10 2017 including the glade UI/XML defs to the executable is simple, compile
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?
Aug 10 2017
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 ); ...
Aug 10 2017
On Friday, 11 August 2017 at 02:27:21 UTC, captaindet wrote:On 2017-08-11 13:00, Mr. Pib wrote:Thanks. It one can use pixbuf to do something similar, albeit more complicated. https://stackoverflow.com/questions/14121166/gdk-pixbuf-load-image-from-memoryHow 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 ); ...
Aug 10 2017
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.
Aug 11 2017