Re: GTKD resources

2017-08-11 Thread Mr. Pib via Digitalmars-d-learn

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, ))

assert(__PixbufLoader, "Error: Cannot load pixbuf 
loader!");
if (!gdk_pixbuf_loader_close(__PixbufLoader, ))
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.


Re: GTKD resources

2017-08-10 Thread Mr. Pib via Digitalmars-d-learn

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





Re: GTKD resources

2017-08-10 Thread captaindet via Digitalmars-d-learn

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 );
...


GTKD resources

2017-08-10 Thread Mr. Pib via Digitalmars-d-learn
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?