Search found 122 matches

by Deluge
Mon Jul 01, 2019 9:11 am
Forum: C++ Development
Topic: Embedding Fonts
Replies: 10
Views: 2239

Re: Embedding Fonts

Sorry for reviving an old thread, but wanted to make mention to anyone trying to do this that since version 3.1.1 the static method wxFont::AddPrivateFont has been added. Hopefully support for loading from memory will also be supported in the future. --- Edit --- Also, I had trouble getting the AddF...
by Deluge
Mon Jul 01, 2019 9:11 am
Forum: C++ Development
Topic: how to load a font from a file
Replies: 6
Views: 2151

Re: how to load a font from a file

Sorry for reviving an old thread, but wanted to make mention to anyone trying to do this that since version 3.1.1 the static method wxFont::AddPrivateFont has been added. Hopefully support for loading from memory will also be supported in the future.
by Deluge
Sun Jun 30, 2019 12:15 am
Forum: C++ Development
Topic: Check if wxString Contains Alphabetic Characters Only
Replies: 6
Views: 199

Re: Check if wxString Contains Alphabetic Characters Only

Found an answer . I can use the expression "^[A-Za-z]+$" with the wxRegEx class (doesn't seem to work with wxString::Matches(_T("^[A-Za-z]+$")) ): ... const static wxRegEx alpha(_T("^[A-Za-z]+$")); ... bool isAlphaOnly(wxString s) { cout << "Checking string \"" << s.c_str() << "\":\t"; return alpha...
by Deluge
Sat Jun 29, 2019 11:38 pm
Forum: C++ Development
Topic: Check if wxString Contains Alphabetic Characters Only
Replies: 6
Views: 199

Check if wxString Contains Alphabetic Characters Only

My understanding is that wxString::IsWord() is deprecated, & that I should use the wxRegEx class or the wxString::Matches method. I am not good with regular expressions, but all I want to do is check if a wxString (or wxChar ) contains alphabetic characters only. According to the docs, I should be a...
by Deluge
Mon Jun 24, 2019 6:35 pm
Forum: C++ Development
Topic: Char Array Is Getting Corrupted
Replies: 16
Views: 455

Re: Char Array Is Getting Corrupted

Though, I'm told over at cplusplus.com forums that the code as I have it will leak memory: as it stands, if you call this routine more than once, you will leak memory, and if these are sizeable image files, you will actually be leaking LARGE amounts of memory. ... vectors are microscopically slower ...
by Deluge
Mon Jun 24, 2019 6:26 pm
Forum: C++ Development
Topic: Char Array Is Getting Corrupted
Replies: 16
Views: 455

Re: Char Array Is Getting Corrupted

Yes, thank you.
by Deluge
Mon Jun 24, 2019 11:34 am
Forum: C++ Development
Topic: Char Array Is Getting Corrupted
Replies: 16
Views: 455

Re: Char Array Is Getting Corrupted

unsigned int getSize() { return sizeof(objectData); } This won't work. You need to store the size of the data. Thanks doublemax! I understand now: class ResourceObject { public: ResourceObject(unsigned char* data, unsigned int data_size); ~ResourceObject() { delete[] objectData; } unsigned char* ge...
by Deluge
Mon Jun 24, 2019 11:14 am
Forum: C++ Development
Topic: Loading WAV from Char Array or Resource
Replies: 7
Views: 1634

Re: Loading WAV from Char Array or Resource

I recently learned how to do this, so thought I would post my answer. wxSound has a constructor for loading wav data from memory . So wav data loaded into a char array can be played: // load sound data into memory fstream wavinput; wavinput.open(filename, fstream::in|fstream::binary); int data_lengt...
by Deluge
Mon Jun 24, 2019 9:42 am
Forum: C++ Development
Topic: Char Array Is Getting Corrupted
Replies: 16
Views: 455

Re: Char Array Is Getting Corrupted

Here is some simplified sample code of what I was doing: res/failsafe.png.h: #ifndef RES_FAILSAFE_PNG_H #define RES_FAILSAFE_PNG_H static const unsigned char failsafe_png[] = { 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00, 0x0d, 0x49, 0x48, 0x44, 0x52, 0x00, 0x00, 0x01, 0x22, 0x0...
by Deluge
Sun Jun 23, 2019 11:38 pm
Forum: C++ Development
Topic: Char Array Is Getting Corrupted
Replies: 16
Views: 455

Re: Char Array Is Getting Corrupted

alys666 wrote:
Sun Jun 23, 2019 6:03 pm
better to take an array by new[size], copy there, and do not forget to delete it by delete[].
If I am understanding you correctly, that is what I did here:

Code: Select all

objectData = new unsigned char[data_size];
But it still didn't work. Let me know if I misunderstood you.
by Deluge
Sun Jun 23, 2019 9:50 am
Forum: C++ Development
Topic: Char Array Is Getting Corrupted
Replies: 16
Views: 455

Re: Char Array Is Getting Corrupted

I've decided to store the data in std::vector instead (easier). I was trying to pass the size of the array & use memcpy [/i], but it wasn't working & I'm not sure why: ResourceObject::ResourceObject(unsigned char* data, unsigned int data_size, const int id) : objectId(id) { objectData = new unsigned...
by Deluge
Sun Jun 23, 2019 4:25 am
Forum: C++ Development
Topic: Char Array Is Getting Corrupted
Replies: 16
Views: 455

Char Array Is Getting Corrupted

I have PNG image data stored in char arrays. Example: const static unsigned char png1[] = { 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00, 0x0d, ... ... I can load the data into a wxImage using the following method: // load image data into input stream wxMemoryInputStream is(png1,...
by Deluge
Sat Jun 22, 2019 12:04 am
Forum: C++ Development
Topic: How to convert wxInputStream to wxBitmap?
Replies: 2
Views: 449

Re: How to convert wxInputStream to wxBitmap?

You can try something like the following : wxMemoryInputStream memIS(bmp_file, bmp_file_size); wxBitmap myBitmap(wxImage(memIS, wxBITMAP_TYPE_ANY, -1),-1); Sorry for posting in an old thread, but I wanted to say thank you for this answer. Was able to display my PNG image data: static const unsigned...
by Deluge
Fri Jun 21, 2019 4:20 am
Forum: General Development
Topic: png2c script failed
Replies: 8
Views: 538

Re: png2c script failed

Not sure if it is a better alternative, but there is Binary to Header that converts any file's binary data into a C character array. So it's not limited to PNG images only.
by Deluge
Fri Jun 21, 2019 4:07 am
Forum: General Development
Topic: [wxSVG] Centering an Image
Replies: 1
Views: 1492

Re: [wxSVG] Centering an Image

This is very old. But I recently started working on an old project & found an answer. The method that I used for centering an SVG image with wxSVG is to create a wxSVGDocument then render it to a wxImage & load it into a wxStaticBitmap: wxString filename = "example.svg"; wxSVGDocument* svgdoc = new ...