Re: gtkD load images

2017-08-06 Thread Mike Wey via Digitalmars-d-learn

On 05-08-17 22:59, ag0aep6g wrote:

On 08/05/2017 10:30 PM, Mike Wey wrote:

On 05-08-17 15:23, Johnson Jones wrote:

On Saturday, 5 August 2017 at 12:51:13 UTC, Mike Wey wrote:

[...]
There are two issues here, you need to properly escape the slash: 
"C:a.jpg".

[...]

```
Pixbuf p = new Pixbuf(r"C:\\a.jpg");
```


Thanks. Why do I need 4 slashes? Is that standard with gtk because 
strings are interpreted twice or something? Seemed to work though.





Nothing specific to GTK but in D and other programing languages the \ 
is used as an escape character, so you can use special characters in 
your sting like `\n` for a newline. But this means you will need to 
use \\ to get an literal back slash.


I think you missed the point of the question.

In the end, the path should contain only one backslash. But with 
`"C:a.jpg"` and `r"C:\\a.jpg"` you get two. Why do you need two? 
Does the library do another round of escape sequence handling?


That's me not being a Windows user shining trough, i somehow got it in 
my head that you needed two backslashes after the C:.


But indeed just "C:\\a.jpg" or r"C:\a.jpg" will work as expected.

--
Mike Wey


Re: gtkD load images

2017-08-05 Thread ag0aep6g via Digitalmars-d-learn

On 08/05/2017 10:30 PM, Mike Wey wrote:

On 05-08-17 15:23, Johnson Jones wrote:

On Saturday, 5 August 2017 at 12:51:13 UTC, Mike Wey wrote:

[...]
There are two issues here, you need to properly escape the slash: 
"C:a.jpg".

[...]

```
Pixbuf p = new Pixbuf(r"C:\\a.jpg");
```


Thanks. Why do I need 4 slashes? Is that standard with gtk because 
strings are interpreted twice or something? Seemed to work though.





Nothing specific to GTK but in D and other programing languages the \ is 
used as an escape character, so you can use special characters in your 
sting like `\n` for a newline. But this means you will need to use \\ to 
get an literal back slash.


I think you missed the point of the question.

In the end, the path should contain only one backslash. But with 
`"C:a.jpg"` and `r"C:\\a.jpg"` you get two. Why do you need two? 
Does the library do another round of escape sequence handling?


Re: gtkD load images

2017-08-05 Thread Mike Wey via Digitalmars-d-learn

On 05-08-17 15:23, Johnson Jones wrote:

On Saturday, 5 August 2017 at 12:51:13 UTC, Mike Wey wrote:

On 03-08-17 21:56, Johnson Jones wrote:

If I do something like

import gdkpixbuf.Pixbuf;
Pixbuf.newFromResource("C:\\a.jpg");


There are two issues here, you need to properly escape the slash: 
"C:a.jpg".


And a.jpg is not a resource file, so you would use the Pixbuf 
constuctor to load an image file.


```
Pixbuf p = new Pixbuf(r"C:\\a.jpg");
```


Thanks. Why do I need 4 slashes? Is that standard with gtk because 
strings are interpreted twice or something? Seemed to work though.





Nothing specific to GTK but in D and other programing languages the \ is 
used as an escape character, so you can use special characters in your 
sting like `\n` for a newline. But this means you will need to use \\ to 
get an literal back slash.


https://dlang.org/spec/lex.html#double_quoted_strings

You can also use an wysiwyg string by using `r"` at the start so what 
you type is what you get.


https://dlang.org/spec/lex.html#wysiwyg

--
Mike Wey


Re: gtkD load images

2017-08-05 Thread Johnson Jones via Digitalmars-d-learn

On Saturday, 5 August 2017 at 12:51:13 UTC, Mike Wey wrote:

On 03-08-17 21:56, Johnson Jones wrote:

If I do something like

import gdkpixbuf.Pixbuf;
Pixbuf.newFromResource("C:\\a.jpg");


There are two issues here, you need to properly escape the 
slash: "C:a.jpg".


And a.jpg is not a resource file, so you would use the Pixbuf 
constuctor to load an image file.


```
Pixbuf p = new Pixbuf(r"C:\\a.jpg");
```


Thanks. Why do I need 4 slashes? Is that standard with gtk 
because strings are interpreted twice or something? Seemed to 
work though.





Re: gtkD load images

2017-08-05 Thread Mike Wey via Digitalmars-d-learn

On 03-08-17 21:56, Johnson Jones wrote:

If I do something like

import gdkpixbuf.Pixbuf;
Pixbuf.newFromResource("C:\\a.jpg");


There are two issues here, you need to properly escape the slash: 
"C:a.jpg".


And a.jpg is not a resource file, so you would use the Pixbuf constuctor 
to load an image file.


```
Pixbuf p = new Pixbuf(r"C:\\a.jpg");
```

--
Mike Wey


Re: gtkD load images

2017-08-04 Thread Johnson Jones via Digitalmars-d-learn

On Friday, 4 August 2017 at 06:58:00 UTC, Antonio Corbi wrote:

On Thursday, 3 August 2017 at 21:06:36 UTC, Johnson Jones wrote:

[...]


Hi!

I load images using Gtk like this (I use gtk under gnu/linux):

[...]


Thanks! I'm sure it will if it works ;)





Re: gtkD load images

2017-08-04 Thread Antonio Corbi via Digitalmars-d-learn

On Thursday, 3 August 2017 at 21:06:36 UTC, Johnson Jones wrote:

On Thursday, 3 August 2017 at 13:12:03 UTC, Mengu wrote:
On Thursday, 3 August 2017 at 03:59:40 UTC, Johnson Jones 
wrote:
How can be use gtkD to load images, I assume through 
gdkpixbuf? While I am getting errors loading images through 
glade's image:


(test.exe:8188): Gtk-WARNING **: Could not load 
image 'a.jpg': Couldn't recognize the image file format for 
file 'test\a.jpg'


(loads fine in glade)

which needs to be resolved, I'd also like to be able to use 
gdkpixbuf to load images programmatically. There seems to be 
no demos on the gtkD github page that deals with image 
loading.


I've tried to do something like

import gtkc.gdkpixbuf;
auto x = c_gdk_pixbuf_get_formats().data;

but I don't know how to interpret x.

Also something like

import gtkc.gdkpixbuf;
void* x;
auto p = c_gdk_pixbuf_get_formats();
for(int i = 0; i < 10; i++)
{   
x = p.data;
p = p.next;
}

which doesn't offer any help.


Aside: How can we call the gtk functions directly using gtkD? 
Seems it uses stuff like


Linker.link(gdk_pixbuf_get_formats, "gdk_pixbuf_get_formats", 
LIBRARY_GDKPIXBUF);


It does seem to alias to these function but something is off 
and I'm not sure what.


hi

- is the gtk.Image class not working for you? 
https://api.gtkd.org/gtkd/gtk/Image.html


- there's also a gdkpixbuf.Pixbuf that you can use. 
https://api.gtkd.org/gtkd/gdkpixbuf/Pixbuf.html


- you can import those functions from gdkpixbuf.c.functions.


So, like I said, I've tried

import gdkpixbuf.Pixbuf;
auto x = Pixbuf.newFromResource("C:\\a.jpg");

which gives me that error I stated before for x86. For x64 it 
simply crashes and no exception is given.


If I use a dummy image I get the same error:

"Unhandled exception: glib.GException.GException The resource 
at “C:\adf.jpg” does not exist at 
generated\gtkd\glib\GException.d(40)"


The error message makes look like like it should be


"Unhandled exception: glib.GException.GException The resource 
at “C:\adf.jpg” does not exist at “C:\” 
generated\gtkd\glib\GException.d(40)"



I'd rather use Pixbuf than image because I don't need to 
generate a full blow image widget.


If I do

GError* err = null;
auto p = 
gdk_pixbuf_new_from_resource(Str.toStringz("C:\\a.jpg"), &err);


p is null and err is

The resource at “D:\a.jpgâ€. does not exist.

which is clearly not true.

So not sure what is going on ;/ Seems to be a bug in pixbuf or 
am I specifying the path wrong? If gtk.Image uses these 
internally then it is working so...


Hi!

I load images using Gtk like this (I use gtk under gnu/linux):

 Pixbuf pixbuf = new Pixbuf (filename);

And draw them in a GtkDrawingArea like this:

// redrawPage is a method from my window class
//theCanvas = cast(DrawingArea) 
theBuilder.getObject("wCanvas");

//theCanvas.addOnDraw (&redrawPage);

private bool redrawPage (Scoped!Context ctx, Widget wda) {
if (pixbuf !is null) {
  Pixbuf img;
  int w, h;

  ctx.scale (drawingScale, drawingScale);

  w = cast(int) (pixbuf.getWidth  * drawingScale);
  h = cast(int) (pixbuf.getHeight * drawingScale);

  theCanvas.setSizeRequest (w, h);

  ctx.setSourcePixbuf (cast(Pixbuf) thePixmap, 0.0, 0.0);
  ctx.paint ();
}
return true;
  }

Hope it helps you.
A. Corbi



Re: gtkD load images

2017-08-03 Thread Johnson Jones via Digitalmars-d-learn

On Thursday, 3 August 2017 at 13:12:03 UTC, Mengu wrote:

On Thursday, 3 August 2017 at 03:59:40 UTC, Johnson Jones wrote:
How can be use gtkD to load images, I assume through 
gdkpixbuf? While I am getting errors loading images through 
glade's image:


(test.exe:8188): Gtk-WARNING **: Could not load 
image 'a.jpg': Couldn't recognize the image file format for 
file 'test\a.jpg'


(loads fine in glade)

which needs to be resolved, I'd also like to be able to use 
gdkpixbuf to load images programmatically. There seems to be 
no demos on the gtkD github page that deals with image loading.


I've tried to do something like

import gtkc.gdkpixbuf;
auto x = c_gdk_pixbuf_get_formats().data;

but I don't know how to interpret x.

Also something like

import gtkc.gdkpixbuf;
void* x;
auto p = c_gdk_pixbuf_get_formats();
for(int i = 0; i < 10; i++)
{   
x = p.data;
p = p.next;
}

which doesn't offer any help.


Aside: How can we call the gtk functions directly using gtkD? 
Seems it uses stuff like


Linker.link(gdk_pixbuf_get_formats, "gdk_pixbuf_get_formats", 
LIBRARY_GDKPIXBUF);


It does seem to alias to these function but something is off 
and I'm not sure what.


hi

- is the gtk.Image class not working for you? 
https://api.gtkd.org/gtkd/gtk/Image.html


- there's also a gdkpixbuf.Pixbuf that you can use. 
https://api.gtkd.org/gtkd/gdkpixbuf/Pixbuf.html


- you can import those functions from gdkpixbuf.c.functions.


So, like I said, I've tried

import gdkpixbuf.Pixbuf;
auto x = Pixbuf.newFromResource("C:\\a.jpg");

which gives me that error I stated before for x86. For x64 it 
simply crashes and no exception is given.


If I use a dummy image I get the same error:

"Unhandled exception: glib.GException.GException The resource at 
“C:\adf.jpg” does not exist at 
generated\gtkd\glib\GException.d(40)"


The error message makes look like like it should be


"Unhandled exception: glib.GException.GException The resource at 
“C:\adf.jpg” does not exist at “C:\” 
generated\gtkd\glib\GException.d(40)"



I'd rather use Pixbuf than image because I don't need to generate 
a full blow image widget.


If I do

GError* err = null;
auto p = gdk_pixbuf_new_from_resource(Str.toStringz("C:\\a.jpg"), 
&err);


p is null and err is

The resource at “D:\a.jpgâ€. does not exist.

which is clearly not true.

So not sure what is going on ;/ Seems to be a bug in pixbuf or am 
I specifying the path wrong? If gtk.Image uses these internally 
then it is working so...




Re: gtkD load images

2017-08-03 Thread Johnson Jones via Digitalmars-d-learn

On Thursday, 3 August 2017 at 13:12:03 UTC, Mengu wrote:

On Thursday, 3 August 2017 at 03:59:40 UTC, Johnson Jones wrote:
How can be use gtkD to load images, I assume through 
gdkpixbuf? While I am getting errors loading images through 
glade's image:


(test.exe:8188): Gtk-WARNING **: Could not load 
image 'a.jpg': Couldn't recognize the image file format for 
file 'test\a.jpg'


(loads fine in glade)

which needs to be resolved, I'd also like to be able to use 
gdkpixbuf to load images programmatically. There seems to be 
no demos on the gtkD github page that deals with image loading.


I've tried to do something like

import gtkc.gdkpixbuf;
auto x = c_gdk_pixbuf_get_formats().data;

but I don't know how to interpret x.

Also something like

import gtkc.gdkpixbuf;
void* x;
auto p = c_gdk_pixbuf_get_formats();
for(int i = 0; i < 10; i++)
{   
x = p.data;
p = p.next;
}

which doesn't offer any help.


Aside: How can we call the gtk functions directly using gtkD? 
Seems it uses stuff like


Linker.link(gdk_pixbuf_get_formats, "gdk_pixbuf_get_formats", 
LIBRARY_GDKPIXBUF);


It does seem to alias to these function but something is off 
and I'm not sure what.


hi

- is the gtk.Image class not working for you? 
https://api.gtkd.org/gtkd/gtk/Image.html


- there's also a gdkpixbuf.Pixbuf that you can use. 
https://api.gtkd.org/gtkd/gdkpixbuf/Pixbuf.html


- you can import those functions from gdkpixbuf.c.functions.


no, they are not... I haven't tried though, but there seems to be 
a problem with the pixbuf not having loaders for any images. 
using a gtk Image widget does not load the image and complains 
about the image format.


If I do something like

import gdkpixbuf.Pixbuf;
Pixbuf.newFromResource("C:\\a.jpg");

Unhandled exception: glib.GException.GException The resource at 
'C:\a.jpg' does not exist at generated\gtkd\glib\GException.d(40) 
occurred


which doesn't seem to make much sense.

The resource exists where I say it is and not sure if this is 
related to the missing pixbuf loaders.


Re: gtkD load images

2017-08-03 Thread Mengu via Digitalmars-d-learn

On Thursday, 3 August 2017 at 03:59:40 UTC, Johnson Jones wrote:
How can be use gtkD to load images, I assume through gdkpixbuf? 
While I am getting errors loading images through glade's image:


(test.exe:8188): Gtk-WARNING **: Could not load 
image 'a.jpg': Couldn't recognize the image file format for 
file 'test\a.jpg'


(loads fine in glade)

which needs to be resolved, I'd also like to be able to use 
gdkpixbuf to load images programmatically. There seems to be no 
demos on the gtkD github page that deals with image loading.


I've tried to do something like

import gtkc.gdkpixbuf;
auto x = c_gdk_pixbuf_get_formats().data;

but I don't know how to interpret x.

Also something like

import gtkc.gdkpixbuf;
void* x;
auto p = c_gdk_pixbuf_get_formats();
for(int i = 0; i < 10; i++)
{   
x = p.data;
p = p.next;
}

which doesn't offer any help.


Aside: How can we call the gtk functions directly using gtkD? 
Seems it uses stuff like


Linker.link(gdk_pixbuf_get_formats, "gdk_pixbuf_get_formats", 
LIBRARY_GDKPIXBUF);


It does seem to alias to these function but something is off 
and I'm not sure what.


hi

- is the gtk.Image class not working for you? 
https://api.gtkd.org/gtkd/gtk/Image.html


- there's also a gdkpixbuf.Pixbuf that you can use. 
https://api.gtkd.org/gtkd/gdkpixbuf/Pixbuf.html


- you can import those functions from gdkpixbuf.c.functions.





gtkD load images

2017-08-02 Thread Johnson Jones via Digitalmars-d-learn
How can be use gtkD to load images, I assume through gdkpixbuf? 
While I am getting errors loading images through glade's image:


(test.exe:8188): Gtk-WARNING **: Could not load image 
'a.jpg': Couldn't recognize the image file format for file 
'test\a.jpg'


(loads fine in glade)

which needs to be resolved, I'd also like to be able to use 
gdkpixbuf to load images programmatically. There seems to be no 
demos on the gtkD github page that deals with image loading.


I've tried to do something like

import gtkc.gdkpixbuf;
auto x = c_gdk_pixbuf_get_formats().data;

but I don't know how to interpret x.

Also something like

import gtkc.gdkpixbuf;
void* x;
auto p = c_gdk_pixbuf_get_formats();
for(int i = 0; i < 10; i++)
{   
x = p.data;
p = p.next;
}

which doesn't offer any help.


Aside: How can we call the gtk functions directly using gtkD? 
Seems it uses stuff like


Linker.link(gdk_pixbuf_get_formats, "gdk_pixbuf_get_formats", 
LIBRARY_GDKPIXBUF);


It does seem to alias to these function but something is off and 
I'm not sure what.