Change how libresrc is built:

* Instead of putting code into the .(c|h) files place it into two new files libresrc.(c|h)
 * Bitmaps now go into bitmaps.(c|h)
 * Default configs into default_config.(c|h)

With this approach we can easily embed any resources by simply calling it with common-respack and not having to do anything else.

Originally committed to SVN as r4169.
This commit is contained in:
Amar Takhar 2010-03-03 00:44:17 +00:00
parent e4364ae6f9
commit c3c14b0815
5 changed files with 55 additions and 20 deletions

View file

@ -1,9 +1,21 @@
noinst_LIBRARIES = libresrc.a noinst_LIBRARIES = libresrc.a
nodist_libresrc_a_SOURCES = libresrc.cpp libresrc_a_SOURCES = libresrc.cpp libresrc.h
nodist_libresrc_a_SOURCES = bitmap.cpp bitmap.h default_config.cpp default_config.h
libresrc_a_CPPFLAGS = @WX_CPPFLAGS@ libresrc_a_CPPFLAGS = @WX_CPPFLAGS@
libresrc.cpp: ../../tools/common-respack BUILT_SOURCES = bitmap.cpp default_config.cpp
../../tools/common-respack libresrc.cpp ../bitmaps/16 ../bitmaps/24 ../bitmaps/misc/splash.png ../bitmaps/misc/wxicon.png
CLEANFILES= libresrc.cpp libresrc.h bitmap.cpp: ../../tools/common-respack
../../tools/common-respack bitmap.cpp ../bitmaps/16 ../bitmaps/24 ../bitmaps/misc/splash.png ../bitmaps/misc/wxicon.png
default_config.cpp: ../../tools/common-respack
../../tools/common-respack default_config.cpp ./default_mru.json
EXTRA_DIST = mru.json
CLEANFILES= \
bitmap.cpp \
bitmap.h \
default_config.cpp \
default_config.h

View file

@ -0,0 +1,5 @@
{
"Audio" : [],
"Video" : [],
"Scripts" : [],
}

View file

@ -0,0 +1,12 @@
#include "libresrc.h"
wxBitmap libresrc_getimage(const unsigned char *buff, size_t size) {
wxMemoryInputStream mem(buff, size);
wxImage image(mem);
return wxBitmap(image);
}
const std::string libresrc_getconfig(const char *config, size_t size) {
std::string str(config, size);
return str;
}

View file

@ -0,0 +1,14 @@
#include <wx/mstream.h>
#include <wx/bitmap.h>
#include <wx/image.h>
#include <sstream>
#include "bitmap.h"
#include "default_config.h"
wxBitmap libresrc_getimage(const unsigned char *image, size_t size);
#define GETIMAGE(a) libresrc_getimage(a, sizeof(a))
const std::string libresrc_getconfig(const char *config, size_t size);
#define CET_DEFAULT_CONFIG(a) libresrc_getconfig(a, sizeof(a))

View file

@ -113,21 +113,6 @@ int main(int argc, const char *argv[]) {
ofstream outH(headerFileName.GetFullPath().char_str()); ofstream outH(headerFileName.GetFullPath().char_str());
ofstream outC(argv[1]); ofstream outC(argv[1]);
outC << "/* This is an automatically generated file and should not be modified directly */" << endl
<< "#include \"" << headerFileName.GetFullName() << "\"" << endl
<< "wxBitmap " << headerFileName.GetName() << "_getimage(const unsigned char *buff, size_t size) {" << endl
<< " wxMemoryInputStream mem(buff, size);" << endl
<< " wxImage image(mem);" << endl
<< " return wxBitmap(image);" << endl
<< "}" << endl;
outH << "/* This is an automatically generated file and should not be modified directly */" << endl
<< "#include <wx/mstream.h>" << endl
<< "#include <wx/bitmap.h>" << endl
<< "#include <wx/image.h>" << endl
<< "wxBitmap " << headerFileName.GetName() << "_getimage(const unsigned char *image, size_t size);" << endl
<< "#define GETIMAGE(a) " << headerFileName.GetName() << "_getimage(a, sizeof(a))" << endl;
wxRegEx nameCleaner("[^A-Za-z_0-9]"); wxRegEx nameCleaner("[^A-Za-z_0-9]");
wxString filename; wxString filename;
FileIterator iter(argc, argv); FileIterator iter(argc, argv);
@ -139,9 +124,16 @@ int main(int argc, const char *argv[]) {
infile.seekg(0, ios::beg); infile.seekg(0, ios::beg);
wxFileName file(filename); wxFileName file(filename);
wxString identifier = file.GetName() + "_" + file.GetDirs().Last();
wxString identifier = file.GetName();
// Hack to work around inserting files in the current directory
if (file.GetDirs().Last() != ".")
identifier.Append("_" + file.GetDirs().Last());
nameCleaner.ReplaceAll(&identifier, "_"); nameCleaner.ReplaceAll(&identifier, "_");
outC << "#include \"libresrc.h\"" << endl;
outC << "const unsigned char " << identifier << "[] = {"; outC << "const unsigned char " << identifier << "[] = {";
bool first = true; bool first = true;
char c[1]; char c[1];