Added new type 'Binary Data' to Fluid. Use this to include an arbitrary file as a byte array into your source code. Changes to load jpegs etc. from program memory will follow.

git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@7084 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
Matthias Melcher
2010-02-15 16:43:51 +00:00
parent ea31edb241
commit fb1b0fab0a
11 changed files with 600 additions and 102 deletions
+2
View File
@@ -1,5 +1,7 @@
CHANGES IN FLTK 1.3.0
- Added binary data type to Fluid
- File chosser preview would hang if a device was choosen
- Replaced _WIN32 symbols that had come with UTF-8 and the
new Fl_Table widget with WIN32
- Fixed a buffer overflow in fl_utf8from_mb() (STR #2279)
File diff suppressed because it is too large Load Diff
+4 -2
View File
@@ -66,6 +66,7 @@ static Fl_Pixmap protected_pixmap(protected_xpm);
#include "pixmaps/flCode.xpm"
#include "pixmaps/flCodeBlock.xpm"
#include "pixmaps/flComment.xpm"
#include "pixmaps/flData.xpm"
#include "pixmaps/flDeclaration.xpm"
#include "pixmaps/flDeclarationBlock.xpm"
#include "pixmaps/flClass.xpm"
@@ -153,6 +154,7 @@ static Fl_Pixmap valueinput_pixmap(flValueInput_xpm);
static Fl_Pixmap valueoutput_pixmap(flValueOutput_xpm);
static Fl_Pixmap spinner_pixmap(flSpinner_xpm);
static Fl_Pixmap widgetclass_pixmap(flWidgetClass_xpm);
static Fl_Pixmap data_pixmap(flData_xpm);
Fl_Pixmap *pixmap[] = { 0, &window_pixmap, &button_pixmap, &checkbutton_pixmap, &roundbutton_pixmap, /* 0..4 */
&box_pixmap, &group_pixmap, &function_pixmap, &code_pixmap, &codeblock_pixmap, &declaration_pixmap, /* 5..10 */
@@ -160,10 +162,10 @@ Fl_Pixmap *pixmap[] = { 0, &window_pixmap, &button_pixmap, &checkbutton_pixmap,
&menuitem_pixmap, &menubar_pixmap, &submenu_pixmap, &scroll_pixmap, &tile_pixmap, &wizard_pixmap, /* 16..21 */
&pack_pixmap, &returnbutton_pixmap, &lightbutton_pixmap, &repeatbutton_pixmap, &menubutton_pixmap, /* 22..26 */
&output_pixmap, &textdisplay_pixmap, &textedit_pixmap, &fileinput_pixmap, &browser_pixmap, /* 27..32 */
&checkbrowser_pixmap, &filebrowser_pixmap, &clock_pixmap, &help_pixmap, &progress_pixmap, /* 33..36 */
&checkbrowser_pixmap, &filebrowser_pixmap, &clock_pixmap, &help_pixmap, &progress_pixmap, /* 33..36 */
&slider_pixmap, &scrollbar_pixmap, &valueslider_pixmap, &adjuster_pixmap, &counter_pixmap, /* 37..41 */
&dial_pixmap, &roller_pixmap, &valueinput_pixmap, &valueoutput_pixmap, &comment_pixmap, /* 42..46 */
&spinner_pixmap, &widgetclass_pixmap /* 47..48 */ };
&spinner_pixmap, &widgetclass_pixmap, &data_pixmap }; /* 47..49 */
extern int show_comments;
+14
View File
@@ -213,6 +213,7 @@ public:
};
class Fl_Decl_Type : public Fl_Type {
protected:
char public_;
char static_;
public:
@@ -227,6 +228,19 @@ public:
int pixmapID() { return 10; }
};
class Fl_Data_Type : public Fl_Decl_Type {
const char *filename_;
public:
Fl_Type *make();
void write_code1();
void write_code2();
void open();
virtual const char *type_name() {return "data";}
void write_properties();
void read_property(const char *);
int pixmapID() { return 49; }
};
class Fl_DeclBlock_Type : public Fl_Type {
const char* after;
char public_;
+11
View File
@@ -235,6 +235,17 @@ void write_cdata(const char *s, int length) {
varused = 1;
return;
}
if (write_sourceview) {
if (length>=0)
fprintf(code_file, "{ /* ... %d bytes of binary data... */ }", length);
else
fprintf(code_file, "{ /* ... binary data... */ }");
return;
}
if (length==-1) {
fprintf(code_file, "{ /* ... undefined size binary data... */ }");
return;
}
const unsigned char *w = (const unsigned char *)s;
const unsigned char *e = w+length;
int linelength = 1;
+2
View File
@@ -915,6 +915,7 @@ int Fl_Value_Slider_Type::textstuff(int w, Fl_Font& f, int& s, Fl_Color& c) {
extern class Fl_Function_Type Fl_Function_type;
extern class Fl_Code_Type Fl_Code_type;
extern class Fl_CodeBlock_Type Fl_CodeBlock_type;
extern class Fl_Data_Type Fl_Data_type;
extern class Fl_Decl_Type Fl_Decl_type;
extern class Fl_DeclBlock_Type Fl_DeclBlock_type;
extern class Fl_Comment_Type Fl_Comment_type;
@@ -988,6 +989,7 @@ Fl_Menu_Item New_Menu[] = {
{"Class",0,cb,(void*)&Fl_Class_type},
{"Widget Class",0,cb,(void*)&Fl_Widget_Class_type},
{"Comment",0,cb,(void*)&Fl_Comment_type},
{"Binary Data",0,cb,(void*)&Fl_Data_type},
{0},
{"Group",0,0,0,FL_SUBMENU},
{0,0,cb,(void*)&Fl_Window_type},
+112
View File
@@ -420,6 +420,112 @@ n int foo();\", a #directive like \"#include <foo.h>\", a comment like \"//foo\
return decl_panel;
}
Fl_Double_Window *data_panel=(Fl_Double_Window *)0;
Fl_Choice *data_choice=(Fl_Choice *)0;
Fl_Menu_Item menu_data_choice[] = {
{"in source file only", 0, 0, 0, 0, FL_NORMAL_LABEL, 0, 11, 0},
{"in header file only", 0, 0, 0, 16, FL_NORMAL_LABEL, 0, 11, 0},
{"\"static\" in source file", 0, 0, 0, 0, FL_NORMAL_LABEL, 0, 11, 0},
{"in source and \"extern\" in header", 0, 0, 0, 0, FL_NORMAL_LABEL, 0, 11, 0},
{0,0,0,0,0,0,0,0,0}
};
Fl_Choice *data_class_choice=(Fl_Choice *)0;
Fl_Menu_Item menu_data_class_choice[] = {
{"private", 0, 0, 0, 0, FL_NORMAL_LABEL, 0, 11, 0},
{"public", 0, 0, 0, 0, FL_NORMAL_LABEL, 0, 11, 0},
{"protected", 0, 0, 0, 0, FL_NORMAL_LABEL, 0, 11, 0},
{0,0,0,0,0,0,0,0,0}
};
Fl_Input *data_input=(Fl_Input *)0;
Fl_Input *data_filename=(Fl_Input *)0;
Fl_Button *data_filebrowser=(Fl_Button *)0;
Fl_Return_Button *data_panel_ok=(Fl_Return_Button *)0;
Fl_Button *data_panel_cancel=(Fl_Button *)0;
Fl_Text_Editor *data_comment_input=(Fl_Text_Editor *)0;
Fl_Double_Window* make_data_panel() {
{ data_panel = new Fl_Double_Window(343, 237, "Binary Data Properties");
data_panel->align(Fl_Align(FL_ALIGN_CLIP|FL_ALIGN_INSIDE));
{ Fl_Group* o = new Fl_Group(10, 10, 270, 20);
{ Fl_Box* o = new Fl_Box(200, 10, 80, 20);
Fl_Group::current()->resizable(o);
} // Fl_Box* o
{ data_choice = new Fl_Choice(10, 10, 185, 20);
data_choice->down_box(FL_BORDER_BOX);
data_choice->labelsize(11);
data_choice->textsize(11);
data_choice->menu(menu_data_choice);
} // Fl_Choice* data_choice
{ data_class_choice = new Fl_Choice(10, 10, 75, 20);
data_class_choice->down_box(FL_BORDER_BOX);
data_class_choice->labelsize(11);
data_class_choice->textsize(11);
data_class_choice->menu(menu_data_class_choice);
} // Fl_Choice* data_class_choice
o->end();
} // Fl_Group* o
{ data_input = new Fl_Input(10, 52, 320, 20, "Variable Name:");
data_input->tooltip("Binary Data variables are declared \"const unsigned char []\".");
data_input->labelfont(1);
data_input->labelsize(11);
data_input->textfont(4);
data_input->textsize(11);
data_input->align(Fl_Align(133));
data_input->when(FL_WHEN_NEVER);
} // Fl_Input* data_input
{ data_filename = new Fl_Input(10, 90, 280, 20, "Filename:");
data_filename->tooltip("Name and path of binary file that will be included.");
data_filename->labelfont(1);
data_filename->labelsize(11);
data_filename->textfont(4);
data_filename->textsize(11);
data_filename->align(Fl_Align(133));
data_filename->when(FL_WHEN_NEVER);
} // Fl_Input* data_filename
{ data_filebrowser = new Fl_Button(290, 90, 40, 20, "@fileopen");
data_filebrowser->labelcolor((Fl_Color)134);
} // Fl_Button* data_filebrowser
{ Fl_Group* o = new Fl_Group(10, 205, 320, 20);
{ data_panel_ok = new Fl_Return_Button(200, 205, 60, 20, "OK");
data_panel_ok->labelsize(11);
data_panel_ok->window()->hotspot(data_panel_ok);
} // Fl_Return_Button* data_panel_ok
{ data_panel_cancel = new Fl_Button(270, 205, 60, 20, "Cancel");
data_panel_cancel->shortcut(0xff1b);
data_panel_cancel->labelsize(11);
} // Fl_Button* data_panel_cancel
{ Fl_Box* o = new Fl_Box(10, 205, 185, 20);
Fl_Group::current()->resizable(o);
} // Fl_Box* o
o->end();
} // Fl_Group* o
{ data_comment_input = new Fl_Text_Editor(10, 130, 320, 65, "Comment:");
data_comment_input->tooltip("Declaration comment in Doxygen format");
data_comment_input->box(FL_DOWN_BOX);
data_comment_input->labelfont(1);
data_comment_input->labelsize(11);
data_comment_input->textfont(4);
data_comment_input->textsize(11);
data_comment_input->align(Fl_Align(FL_ALIGN_TOP_LEFT));
Fl_Group::current()->resizable(data_comment_input);
data_comment_input->buffer(new Fl_Text_Buffer());
} // Fl_Text_Editor* data_comment_input
data_panel->size_range(343, 237);
data_panel->end();
} // Fl_Double_Window* data_panel
return data_panel;
}
Fl_Double_Window *class_panel=(Fl_Double_Window *)0;
Fl_Light_Button *c_public_button=(Fl_Light_Button *)0;
@@ -657,6 +763,12 @@ Fl_Window* make_widgetbin() {
o->callback((Fl_Callback*)type_make_cb, (void*)("declblock"));
o->image(pixmap[11]);
} // Fl_Button* o
{ Fl_Button* o = new Fl_Button(55, 55, 24, 24);
o->tooltip("Binary Data");
o->box(FL_THIN_UP_BOX);
o->callback((Fl_Callback*)type_make_cb, (void*)("data"));
o->image(pixmap[49]);
} // Fl_Button* o
o->end();
} // Fl_Group* o
{ Fl_Group* o = new Fl_Group(87, 3, 79, 79);
+111 -15
View File
@@ -31,22 +31,28 @@ comment {//
} {in_source in_header
}
decl {\#include <FL/Fl_Pixmap.H>} {}
decl {\#include "Fl_Type.h"} {}
decl {\#include "undo.h"} {}
decl {extern class Fl_Pixmap *pixmap[];} {}
decl {extern class Fl_Type *Fl_Type_make(const char*);} {}
decl {extern void select_only(Fl_Type*);} {}
decl {extern void exit_cb(Fl_Widget*, void*);} {global
decl {\#include <FL/Fl_Pixmap.H>} {private local
}
decl {extern void toggle_widgetbin_cb(Fl_Widget*, void*);} {global
decl {\#include "Fl_Type.h"} {private local
}
decl {\#include "undo.h"} {private local
}
decl {extern class Fl_Pixmap *pixmap[];} {private local
}
decl {extern class Fl_Type *Fl_Type_make(const char*);} {private local
}
decl {extern void select_only(Fl_Type*);} {private local
}
decl {extern void exit_cb(Fl_Widget*, void*);} {private global
}
decl {extern void toggle_widgetbin_cb(Fl_Widget*, void*);} {private global
}
Function {make_function_panel()} {} {
@@ -322,6 +328,90 @@ Function {make_decl_panel()} {} {
}
}
Function {make_data_panel()} {open
} {
Fl_Window data_panel {
label {Binary Data Properties} open
xywh {414 355 343 237} type Double align 80 resizable size_range {343 237 0 0} visible
} {
Fl_Group {} {open
xywh {10 10 270 20}
} {
Fl_Box {} {
xywh {200 10 80 20} resizable
}
Fl_Choice data_choice {open
xywh {10 10 185 20} down_box BORDER_BOX labelsize 11 textsize 11
} {
MenuItem {} {
label {in source file only}
xywh {0 0 100 20} labelsize 11
}
MenuItem {} {
label {in header file only}
xywh {0 0 100 20} labelsize 11 hide
}
MenuItem {} {
label {"static" in source file}
xywh {0 0 100 20} labelsize 11
}
MenuItem {} {
label {in source and "extern" in header}
xywh {0 0 100 20} labelsize 11
}
}
Fl_Choice data_class_choice {open
xywh {10 10 75 20} down_box BORDER_BOX labelsize 11 textsize 11
} {
MenuItem {} {
label private
xywh {10 10 100 20} labelsize 11
}
MenuItem {} {
label public
xywh {10 10 100 20} labelsize 11
}
MenuItem {} {
label protected
xywh {10 10 100 20} labelsize 11
}
}
}
Fl_Input data_input {
label {Variable Name:}
tooltip {Binary Data variables are declared "const unsigned char []".} xywh {10 52 320 20} labelfont 1 labelsize 11 align 133 when 0 textfont 4 textsize 11
}
Fl_Input data_filename {
label {Filename:}
tooltip {Name and path of binary file that will be included.} xywh {10 90 280 20} labelfont 1 labelsize 11 align 133 when 0 textfont 4 textsize 11
}
Fl_Button data_filebrowser {
label {@fileopen}
xywh {290 90 40 20} labelcolor 134
}
Fl_Group {} {open
xywh {10 205 320 20}
} {
Fl_Return_Button data_panel_ok {
label OK selected
xywh {200 205 60 20} labelsize 11 hotspot
}
Fl_Button data_panel_cancel {
label Cancel
xywh {270 205 60 20} shortcut 0xff1b labelsize 11
}
Fl_Box {} {
xywh {10 205 185 20} resizable
}
}
Fl_Text_Editor data_comment_input {
label {Comment:}
tooltip {Declaration comment in Doxygen format} xywh {10 130 320 65} box DOWN_BOX labelfont 1 labelsize 11 align 5 textfont 4 textsize 11 resizable
code0 {data_comment_input->buffer(new Fl_Text_Buffer());}
}
}
}
Function {make_class_panel()} {} {
Fl_Window class_panel {
label {Class Properties} open
@@ -441,7 +531,7 @@ Function {make_widgetbin()} {} {
callback {if (Fl::event()==FL_SHORTCUT && Fl::event_key()==FL_Escape)
exit_cb((Fl_Widget*)o, v);
else
toggle_widgetbin_cb((Fl_Widget*)o, v);} open selected
toggle_widgetbin_cb((Fl_Widget*)o, v);}
xywh {410 171 550 85} type Single align 80 non_modal visible
} {
Fl_Group {} {
@@ -495,6 +585,12 @@ else
tooltip {Declaration Block} xywh {30 55 24 24} box THIN_UP_BOX
code0 {o->image(pixmap[11]);}
}
Fl_Button {} {
user_data {"data"}
callback type_make_cb
tooltip {Binary Data} xywh {55 55 24 24} box THIN_UP_BOX
code0 {o->image(pixmap[49]);}
}
}
Fl_Group {} {
xywh {87 3 79 79}
+12
View File
@@ -82,6 +82,18 @@ extern Fl_Text_Editor *decl_comment_input;
Fl_Double_Window* make_decl_panel();
extern Fl_Menu_Item menu_decl_choice[];
extern Fl_Menu_Item menu_decl_class_choice[];
extern Fl_Double_Window *data_panel;
extern Fl_Choice *data_choice;
extern Fl_Choice *data_class_choice;
extern Fl_Input *data_input;
extern Fl_Input *data_filename;
extern Fl_Button *data_filebrowser;
extern Fl_Return_Button *data_panel_ok;
extern Fl_Button *data_panel_cancel;
extern Fl_Text_Editor *data_comment_input;
Fl_Double_Window* make_data_panel();
extern Fl_Menu_Item menu_data_choice[];
extern Fl_Menu_Item menu_data_class_choice[];
extern Fl_Double_Window *class_panel;
extern Fl_Light_Button *c_public_button;
extern Fl_Input *c_name_input;
+29
View File
@@ -0,0 +1,29 @@
/* XPM */
static const char *flData_xpm[] = {
/* width height ncolors chars_per_pixel */
"16 16 6 1",
/* colors */
". c none",
"a c #000000",
"b c #c0e0c0",
"c c #000000",
" c #000000",
"- c #607006",
/* pixels */
"................",
"................",
"...aaaaaaaaaaaaa",
"...abbbbbbbbbbbc",
"...ab b- -b bbbc",
"..abb b b b bbc.",
"..abb b- -b bbc.",
"..abbbbbbbbbbbc.",
".abbbbbbbbbbbc..",
".ab b b- -bbbc..",
".ab b b b bbbc..",
"abb b b- -bbc...",
"abbbbbbbbbbbc...",
"acccccccccccc...",
"................",
"................",
};
+1 -1
View File
@@ -1288,7 +1288,7 @@ Fl_File_Chooser::update_preview()
{
const char *filename; // Current filename
const char *newlabel = 0; // New label text
Fl_Shared_Image *image = 0, // New image
Fl_Shared_Image *image = 0, // New image
*oldimage; // Old image
int pbw, pbh; // Width and height of preview box
int w, h; // Width and height of preview image