^ No. (But I did now, and the result is the same as below).
I think I give up. :D Can't get it to work.
Calling toBitmap() on the imagedata of my image results in a crash.
(I simplified the code)
SWIGINTERN VALUE
_wrap_Window_icone___(int argc, VALUE *argv, VALUE self) {
Gosu::Window *arg1 = (Gosu::Window *) 0 ;
Gosu::Image *icon = (Gosu::Image *) 0;
arg1 = reinterpret_cast< Gosu::Window * >(argp1);
icon = reinterpret_cast< Gosu::Image *>(argv[0]);
// Gives me a return value
std::cout << sizeof(icon->getData().toBitmap()) << std::endl;
// FAILS, ruby interpreter crashes
(arg1)->setIcon(icon->getData().toBitmap());
// same
Gosu::Bitmap bmp = getData().toBitmap());
}
I could provide the stacktrace, but it's useless. My Ruby code looks like this:
gem "gosu", ">9.0.00"
require 'gosu'
class Test < Gosu::Window
def initialize
super(640, 480, false)
bitmap = Gosu::Image.new(self, "./icon.png", false)
self.icon = bitmap # <= apocalypse
end
# ...
end
Well, from what I know of Windows, it's probably not going to accept a raw RGBA (ARGB?) chunk when it's expecting an Icon resource. There's probably some Windows API function for generating an Icon from a blob of pixels – which is what I assumed you were using when I suggested #to_blob. How exactly are you using #to_blob with the above code?
By SPK
Date 2013-09-13 11:19
The function setIcon(image) works (in C++), but the wrapper doesn't. I get the bitmap of an image from image.getData().toBitmap() thus I don't need to_blob.
Huh, Windows API?
By jlnr (dev)
Date 2013-09-13 11:17
Image#to_blob
is exactly what you want. :) It returns a binary RGBA string that should be easy to work with in C & Ruby. You can probably write it in pure Ruby using the Win32API module (or what it's called these days). It is just a Ruby-ish/RMagick compatible wrapper around ImageData::toBitmap()
.
But I think that setting the icon in code is not generally the right way, because if the .exe
binary has the right icon, it will be used in Explorer, for shortcuts and for the window itself (I think). Setting the icon in code is probably useful mostly for instant messengers etc?
Edit: And you cannot just cast the arguments into Gosu::Window
. The C++ classes have to be wrapped up as a Data
struct/thingie for the Ruby C API. If you look at the SWIG generated methods, you will see how to extract the C++ pointers back out of the Data
.
Posted almost simultaneously. :P
Why is it wrong to set the icon in code? The title is also set in code. And because of the #ifdef magic it's only Linux anyway, so it's not even possible to set the icon in Windows.
My code lies within the Ruby_Gosuwrapper.cxx thingie and I mostly copied from your other methods, so I guess it should be legal to cast to Gosu::Window.
Okay, let's assume I use to_blob, how would the cast to Gosu::Bitmap look like?
Simple as reinterpret_cast<Gosu::Bitmap *>(VALUE)?
I don't want to spend the whole night on trial and error again... :)
By jlnr (dev)
Date 2013-09-13 21:04
Nope, VALUE
will be a Ruby string. If you need a Gosu::Bitmap
, you can either memcpy
the string's contents into the bitmap.data()
, or look up how the image's VALUE
is converted into a Gosu::Image
in the SWIG generated code.
It's not wrong, but if the icon is ALSO set in the EXE file via Ocra (so that the EXE 'looks' right in Explorer), it will be a no-op in most of the cases? :)
Heh!
Finally got it working with SWIG_ConvertPtr without #to_blob.
What now? Pull request and you look over the code or do you don't want to see the code in gosu? :'(
(Will do it tomorrow, time to sleep.)
Yes, then it would be a no-op. But that's a problem of Windows. :P
By jlnr (dev)
Date 2013-09-14 03:27
Oh, definitely send a PR! Then we can discuss more code stuff on github. :)