The SharedImage API is a mess. It should be made VERY clear that to
load a pngImage or a jpgImage, they can't be loaded directly as shared
images and this should be documented for every Image class we support
inherently with a note that by adding handlers we can use the same
interface for all.
For example...
* SharedImage* im = pngImage::get("gc_16x16_png", gc_16x16_png);
*
works.
* SharedImage* im = SharedImage::get("gc_16x16_png", gc_16x16_png);
*
does not work although using the name alone like this
* SharedImage* im = SharedImage::get("gc_16x16_png");
*
does work.
For those not adequately confused, when you add the datas after the name
these images load from memory. The memory is the format of the file and
can be generated by fluid if you play with it a bit or by any bin2text
kind of utility.
But all images loaded this way need a unique text name so they can be
hashed and found by a unique identifier (like an Atom but generated by
fltk).
Adding to the confusion, fluid2 inlines the data (good) but uses the
filename alone to load the image, giving one the false impression that
you a) can't load data from memory and b) SharedImage doesn't work right.
The filename is fine! It's a uinique identifier. But fluid also can
determine what file type it is (if it can show the picture, right?), so
fluid should use the proper loader and load the data from memory, thus
solving about three problems at once.
The third problem it solves is serving as a fltk programming tutorial. :-)
If you don't "get this" yet, pay close attention to the loader's name
and the number of parameters used. (Aha! See what I mean?)
* pngImage::get(); can take one or two parameters. Same with
xpmImage, jpgImage.
*
SharedImage::get(); only works with one parameter, the name.
This is as it should be, believe it or not, because sometimes we load
files by name not knowing the extension. And it works great for loading
KDE theme icons and probably will for other themes as well...
Got a sec and an itchy programming finger?
-------------> try this. Create an empty window in fluid (don't
generate a main, we have one)
*#include "Ui.h" // <- the name of your fluid header file.
// #include Ui.cxx too if you don't know how to "make" it
#include <fltk/run.h> // roughly equiv. to "FL/Fl.H"
#include <fltk/SharedImage.h> // roughly equiv. to "Murder/Mayhem.madness"
const unsigned char binary_data[306] = {
0x89,0x50,0x4E,0x47,0x0D,0x0A,0x1A,0x0A,0x00,0x00,0x00,0x0D,0x49,0x48,0x44,0x52,
0x00,0x00,0x00,0x27,0x00,0x00,0x00,0x0E,0x08,0x06,0x00,0x00,0x00,0xAC,0x00,0x05,
0xCB,0x00,0x00,0x00,0x04,0x73,0x42,0x49,0x54,0x08,0x08,0x08,0x08,0x7C,0x08,0x64,
0x88,0x00,0x00,0x00,0x19,0x74,0x45,0x58,0x74,0x53,0x6F,0x66,0x74,0x77,0x61,0x72,
0x65,0x00,0x77,0x77,0x77,0x2E,0x69,0x6E,0x6B,0x73,0x63,0x61,0x70,0x65,0x2E,0x6F,
0x72,0x67,0x9B,0xEE,0x3C,0x1A,0x00,0x00,0x00,0xC4,0x49,0x44,0x41,0x54,0x48,0x89,
0xED,0xD0,0xBD,0x6A,0x84,0x40,0x18,0x46,0xE1,0xF3,0x39,0x43,0x7E,0x30,0xC8,0x82,
0x29,0xAC,0x96,0xB9,0x6B,0x3B,0x3B,0x6F,0x44,0xB0,0xB3,0xB7,0x13,0x9B,0x54,0x2A,
0x81,0xB0,0x66,0x75,0x20,0xF3,0x6D,0xB3,0x75,0x0A,0x9B,0x69,0x3C,0xF0,0xF6,0x0F,
0xAF,0xA8,0x2A,0xC0,0x27,0x90,0x03,0x96,0xF8,0xED,0xC0,0x02,0x7C,0x5B,0x80,0x75,
0x5D,0xDF,0xD2,0x34,0xBD,0x00,0x2F,0x51,0x59,0xC0,0x3C,0xCF,0xF7,0xB6,0x6D,0x7D,
0x59,0x96,0x3F,0x76,0x1C,0x47,0x93,0x65,0xD9,0x75,0xDB,0xB6,0x39,0xCF,0xF3,0xAF,
0xD8,0xB8,0xA6,0x69,0xDE,0xBB,0xAE,0x4B,0x01,0xB1,0x00,0x21,0x84,0xDD,0x7B,0xFF,
0x0B,0xAC,0x71,0x69,0x50,0x55,0x55,0xB0,0xD6,0x1A,0x80,0x24,0x36,0xE6,0xBF,0x4E,
0xDC,0xD1,0x4E,0xDC,0xD1,0x4E,0xDC,0xD1,0x12,0x40,0x45,0xE4,0x6F,0x9A,0x26,0x44,
0xC4,0xC4,0xDE,0xB2,0x2C,0xC6,0x7B,0x9F,0x00,0x58,0xE7,0x5C,0x18,0x86,0xE1,0x56,
0xD7,0xF5,0x2B,0x70,0x89,0xFB,0x15,0xF4,0x7D,0x6F,0x9D,0x73,0xF7,0xA2,0x28,0x54,
0x54,0x15,0x11,0x31,0xC0,0x47,0x6C,0xD8,0x33,0x05,0x76,0x55,0xDD,0x1F,0x6B,0x0E,
0x4B,0x9E,0xD3,0x19,0x3F,0x17,0x00,0x00,0x00,0x00,0x49,0x45,0x4E,0x44,0xAE,0x42,
0x60,0x82
};
int main(int argc, char** argv)
{
fltk::Window* w = make_window();
w->label("ok ");
w->color(0xCCBBAA00); // set 8-digit hex bg color here, last two
digits = 0
fltk::SharedImage* im = fltk::pngImage::get("any unique name",
binary_data);
w->align(fltk::ALIGN_CENTER);
w->image(im);
w->show();
return fltk::run();
}
// Two levels of alpha, 16 and 8. I probably went a bit light on
// the alpha, eh? Still, it mixes with any background color.
*
_______________________________________________
fltk-bugs mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-bugs