dontpanic92 / wxGo

Golang wxWidgets Wrapper
Other
403 stars 51 forks source link

Embedding images #50

Closed blimmo closed 6 years ago

blimmo commented 6 years ago

In wxWidgets in C, I've used the wxBITMAP_PNG_FROM_DATA macro along with xpm files. Obviously this doesn't work in go so can anyone recommend an approach that does?

I'd like to keep the images embedded in the executable and not separate. Also I'd prefer something cross platform (why I liked xpm so much).

dontpanic92 commented 6 years ago

Indeed xpm is not working now, as the char* doesn't correctly mapped when it is used for binary data rather than a string 2D char array doesn't correctly mapped. I will take a look at that

dontpanic92 commented 6 years ago

The mapping is updated. Now we can use a string slice to construct a wxImage or wxBitmap. Please have a check onexamples/webview for usage reference

blimmo commented 6 years ago

Thanks that's great!

On another note I'd like to use something like the wx.Bitmap.NewFromPNGData method to display images from raw data (I have it in a []byte).

The equivalent function in wxGo is wx.BitmapNewFromPNGData but this takes a uintptr so I'm not sure if this is wrapped properly?

Thanks again for the quick response on xpm :)

dontpanic92 commented 6 years ago

Updated, please check the webview example about the NewFromPNGData

blimmo commented 6 years ago

Damn you're quick!

I notice you haven't freed the bitmap you've created in the example. Is this intentional and Bitmap is memory managed or should I be calling wx.DeleteBitmap?

dontpanic92 commented 6 years ago

Oh that is a mistake :(, and wx.DeleteBitmap should be called. It seems that image should also be deleted. I'll fix them

blimmo commented 6 years ago

Actually could you add a T version which is managed by go like wx.NewBitmapT? I often use it in a wx.NewStaticBitmap and it would be nice to be able to use it inline.

dontpanic92 commented 6 years ago

My apologize - I was wrong in the previous reply - they are already tracked by Go. What these functions return are wxBitmap and wxImage(instead of a wxBitmap* and wxImage*). We can safely track them because nobody on C++ side would reference them.

blimmo commented 6 years ago

Oh great!

Thanks for all your help on this :)