diff options
| author | Matthias Melcher <github@matthiasm.com> | 2023-11-16 13:21:17 +0100 |
|---|---|---|
| committer | Matthias Melcher <github@matthiasm.com> | 2023-11-16 13:21:17 +0100 |
| commit | 01d30ed9cc4c080dea45ee85ec7af76cbd7e61bb (patch) | |
| tree | 383c090f41b22e706775f98d704ed1a39d498175 /fluid | |
| parent | d28d03e1aca7d2e4d3b625a95912f0cebf9bac10 (diff) | |
FLUID: inlined data can be stored compressed.
Diffstat (limited to 'fluid')
| -rw-r--r-- | fluid/Fl_Function_Type.cxx | 57 | ||||
| -rw-r--r-- | fluid/README_fl.txt | 1 | ||||
| -rw-r--r-- | fluid/code.cxx | 6 | ||||
| -rw-r--r-- | fluid/function_panel.cxx | 41 | ||||
| -rw-r--r-- | fluid/function_panel.fl | 45 | ||||
| -rw-r--r-- | fluid/function_panel.h | 4 | ||||
| -rw-r--r-- | fluid/template_panel.cxx | 93 | ||||
| -rw-r--r-- | fluid/template_panel.fl | 56 | ||||
| -rw-r--r-- | fluid/template_panel.h | 1 | ||||
| -rw-r--r-- | fluid/templates/1of7GUIs.fl | 36 | ||||
| -rw-r--r-- | fluid/templates/FLTK_License.fl | 21 |
11 files changed, 282 insertions, 79 deletions
diff --git a/fluid/Fl_Function_Type.cxx b/fluid/Fl_Function_Type.cxx index 557947e93..cce44b5d6 100644 --- a/fluid/Fl_Function_Type.cxx +++ b/fluid/Fl_Function_Type.cxx @@ -25,12 +25,16 @@ #include "function_panel.h" #include "comments.h" #include "mergeback.h" +#include "undo.h" #include <FL/fl_string_functions.h> #include <FL/Fl_File_Chooser.H> #include <FL/fl_ask.H> #include "../src/flstring.h" +#include <zlib.h> + + /// Set a current class, so that the code of the children is generated correctly. Fl_Class_Type *current_class = NULL; @@ -1128,9 +1132,12 @@ void Fl_Data_Type::write_properties(Fd_Project_Writer &f) { f.write_string("filename"); f.write_word(filename_); } - if (text_mode_) { + if (text_mode_ == 1) { f.write_string("textmode"); } + if (text_mode_ == 2) { + f.write_string("compressed"); + } } /** @@ -1141,6 +1148,8 @@ void Fl_Data_Type::read_property(Fd_Project_Reader &f, const char *c) { storestring(f.read_word(), filename_, 1); } else if (!strcmp(c,"textmode")) { text_mode_ = 1; + } else if (!strcmp(c,"compressed")) { + text_mode_ = 2; } else { Fl_Decl_Type::read_property(f, c); } @@ -1209,6 +1218,7 @@ void Fl_Data_Type::open() { if (v==0) { free(s); continue; } // Continue Editing //if (v==1) { } // Ignore Error and close dialog } + undo_checkpoint(); name(n); free(s); // store flags @@ -1228,6 +1238,8 @@ void Fl_Data_Type::open() { } } text_mode_ = data_mode->value(); + if (text_mode_ < 0) text_mode_ = 0; + if (text_mode_ > 2) text_mode_ = 2; // store the filename c = data_filename->value(); if (filename_ && strcmp(filename_, data_filename->value())) @@ -1246,6 +1258,7 @@ void Fl_Data_Type::open() { comment(0); } if (c) free((void*)c); + set_modflag(1); break; } BREAK2: @@ -1262,6 +1275,7 @@ void Fl_Data_Type::write_code1(Fd_Code_Writer& f) { const char *fn = filename_; char *data = 0; int nData = -1; + int uncompressedDataSize = 0; // path should be set correctly already if (filename_ && !f.write_sourceview) { enter_project_dir(); @@ -1276,6 +1290,15 @@ void Fl_Data_Type::write_code1(Fd_Code_Writer& f) { if (nData) { data = (char*)calloc(nData, 1); if (fread(data, nData, 1, f)==0) { /* use default */ } + if (text_mode_ == 2) { + uncompressedDataSize = nData; + uLong nzData = compressBound(nData); + Bytef *zdata = (Bytef*)::malloc(nzData); + if (compress(zdata, &nzData, (Bytef*)data, nData) != Z_OK) { /* error */ } + ::free(data); + data = (char*)zdata; + nData = (int)nzData; + } } fclose(f); } @@ -1284,13 +1307,22 @@ void Fl_Data_Type::write_code1(Fd_Code_Writer& f) { } if (is_in_class()) { f.write_public(public_); - if (text_mode_) { + if (text_mode_ == 1) { f.write_h("%sstatic const char *%s;\n", f.indent(1), c); f.write_c("\n"); write_comment_c(f); f.write_c("const char *%s::%s = /* text inlined from %s */\n", class_name(1), c, fn); if (message) f.write_c("#error %s %s\n", message, fn); f.write_cstring(data, nData); + } else if (text_mode_ == 2) { + f.write_h("%sstatic int %s_size;\n", f.indent(1), c); + f.write_h("%sstatic unsigned char %s[%d];\n", f.indent(1), c, nData); + f.write_c("\n"); + write_comment_c(f); + f.write_c("int %s::%s_size = %d;\n", class_name(1), c, uncompressedDataSize); + f.write_c("unsigned char %s::%s[%d] = /* data compressed and inlined from %s */\n", class_name(1), c, nData, fn); + if (message) f.write_c("#error %s %s\n", message, fn); + f.write_cdata(data, nData); } else { f.write_h("%sstatic unsigned char %s[%d];\n", f.indent(1), c, nData); f.write_c("\n"); @@ -1304,13 +1336,22 @@ void Fl_Data_Type::write_code1(Fd_Code_Writer& f) { // the "header only" option does not apply here! if (public_) { if (static_) { - if (text_mode_) { + if (text_mode_ == 1) { f.write_h("extern const char *%s;\n", c); f.write_c("\n"); write_comment_c(f); f.write_c("const char *%s = /* text inlined from %s */\n", c, fn); if (message) f.write_c("#error %s %s\n", message, fn); f.write_cstring(data, nData); + } else if (text_mode_ == 2) { + f.write_h("extern int %s_size;\n", c); + f.write_h("extern unsigned char %s[%d];\n", c, nData); + f.write_c("\n"); + write_comment_c(f); + f.write_c("int %s_size = %d;\n", c, uncompressedDataSize); + f.write_c("unsigned char %s[%d] = /* data compressed and inlined from %s */\n", c, nData, fn); + if (message) f.write_c("#error %s %s\n", message, fn); + f.write_cdata(data, nData); } else { f.write_h("extern unsigned char %s[%d];\n", c, nData); f.write_c("\n"); @@ -1323,7 +1364,7 @@ void Fl_Data_Type::write_code1(Fd_Code_Writer& f) { } else { write_comment_h(f); f.write_h("#error Unsupported declaration loading inline data %s\n", fn); - if (text_mode_) + if (text_mode_ == 1) f.write_h("const char *%s = \"abc...\";\n", c); else f.write_h("unsigned char %s[3] = { 1, 2, 3 };\n", c); @@ -1333,10 +1374,16 @@ void Fl_Data_Type::write_code1(Fd_Code_Writer& f) { write_comment_c(f); if (static_) f.write_c("static "); - if (text_mode_) { + if (text_mode_ == 1) { f.write_c("const char *%s = /* text inlined from %s */\n", c, fn); if (message) f.write_c("#error %s %s\n", message, fn); f.write_cstring(data, nData); + } else if (text_mode_ == 2) { + f.write_c("int %s_size = %d;\n", c, uncompressedDataSize); + if (static_) f.write_c("static "); + f.write_c("unsigned char %s[%d] = /* data compressed and inlined from %s */\n", c, nData, fn); + if (message) f.write_c("#error %s %s\n", message, fn); + f.write_cdata(data, nData); } else { f.write_c("unsigned char %s[%d] = /* data inlined from %s */\n", c, nData, fn); if (message) f.write_c("#error %s %s\n", message, fn); diff --git a/fluid/README_fl.txt b/fluid/README_fl.txt index 83062beb3..1a824b1e2 100644 --- a/fluid/README_fl.txt +++ b/fluid/README_fl.txt @@ -413,6 +413,7 @@ Type "data" <word> : C++ variable name "filename" <word> : name or path as entered by user, forward slashes "textmode" : defaults to binary mode + "compressed" : defaults to not compressed ... : inherits more from decl Type "declblock" <word> : C++ code diff --git a/fluid/code.cxx b/fluid/code.cxx index 09d1eb257..caff62607 100644 --- a/fluid/code.cxx +++ b/fluid/code.cxx @@ -886,15 +886,15 @@ int Fd_Code_Writer::write_code(const char *s, const char *t, bool to_sourceview) fprintf(header_file, "#endif\n"); Fl_Type* last_type = Fl_Type::last; - if (last_type && last_type->is_a(ID_Comment)) { + if (last_type && (last_type != Fl_Type::first) && last_type->is_a(ID_Comment)) { if (write_sourceview) { last_type->code1_start = last_type->code2_start = (int)ftell(code_file); - first_type->header1_start = first_type->header2_start = (int)ftell(header_file); + last_type->header1_start = last_type->header2_start = (int)ftell(header_file); } last_type->write_code1(*this); if (write_sourceview) { last_type->code1_end = last_type->code2_end = (int)ftell(code_file); - first_type->header1_end = first_type->header2_end = (int)ftell(header_file); + last_type->header1_end = last_type->header2_end = (int)ftell(header_file); } } int x = 0, y = 0; diff --git a/fluid/function_panel.cxx b/fluid/function_panel.cxx index d79acec30..b287f0b65 100644 --- a/fluid/function_panel.cxx +++ b/fluid/function_panel.cxx @@ -447,7 +447,14 @@ Fl_Menu_Item menu_data_class_choice[] = { {0,0,0,0,0,0,0,0,0} }; -Fl_Check_Button *data_mode=(Fl_Check_Button *)0; +Fl_Choice *data_mode=(Fl_Choice *)0; + +Fl_Menu_Item menu_data_mode[] = { + {"binary mode", 0, 0, (void*)(0), 0, (uchar)FL_NORMAL_LABEL, 0, 11, 0}, + {"text mode", 0, 0, (void*)(1), 0, (uchar)FL_NORMAL_LABEL, 0, 11, 0}, + {"compressed binary", 0, 0, (void*)(2), 0, (uchar)FL_NORMAL_LABEL, 0, 11, 0}, + {0,0,0,0,0,0,0,0,0} +}; Fl_Input *data_input=(Fl_Input *)0; @@ -462,9 +469,9 @@ Fl_Return_Button *data_panel_ok=(Fl_Return_Button *)0; Fl_Button *data_panel_cancel=(Fl_Button *)0; Fl_Double_Window* make_data_panel() { - { data_panel = new Fl_Double_Window(343, 237, "Inline Data Properties"); + { data_panel = new Fl_Double_Window(343, 264, "Inline Data Properties"); data_panel->align(Fl_Align(FL_ALIGN_CLIP|FL_ALIGN_INSIDE)); - { Fl_Group* o = new Fl_Group(10, 10, 320, 20); + { Fl_Group* o = new Fl_Group(10, 10, 320, 48); { Fl_Box* o = new Fl_Box(288, 10, 42, 20); Fl_Group::current()->resizable(o); } // Fl_Box* o @@ -480,15 +487,17 @@ Fl_Double_Window* make_data_panel() { data_class_choice->textsize(11); data_class_choice->menu(menu_data_class_choice); } // Fl_Choice* data_class_choice - { data_mode = new Fl_Check_Button(200, 10, 78, 20, "text mode"); - data_mode->tooltip("When text mode is selected, the returned type is \"const char*\" and a traili\ -ng NUL will be appended to the data."); - data_mode->down_box(FL_DOWN_BOX); + { data_mode = new Fl_Choice(10, 38, 185, 20); + data_mode->tooltip("text mode generates a \"const char*\" and a trailing NUL, compressed mode use\ +s zlib to generate a binary block"); + data_mode->down_box(FL_BORDER_BOX); data_mode->labelsize(11); - } // Fl_Check_Button* data_mode + data_mode->textsize(11); + data_mode->menu(menu_data_mode); + } // Fl_Choice* data_mode o->end(); } // Fl_Group* o - { data_input = new Fl_Input(10, 52, 320, 20, "Variable Name:"); + { data_input = new Fl_Input(10, 78, 320, 20, "Variable Name:"); data_input->tooltip("Inline Data variables are declared \"const unsigned char []\" in binary mode \ and \"const char*\" in text mode."); data_input->labelfont(1); @@ -498,7 +507,7 @@ and \"const char*\" in text mode."); 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 = new Fl_Input(10, 116, 280, 20, "Filename:"); data_filename->tooltip("Name and path of file that will be inlined."); data_filename->labelfont(1); data_filename->labelsize(11); @@ -507,10 +516,10 @@ and \"const char*\" in text mode."); 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 = new Fl_Button(290, 116, 40, 20, "@fileopen"); data_filebrowser->labelcolor((Fl_Color)134); } // Fl_Button* data_filebrowser - { data_comment_input = new Fl_Text_Editor(10, 130, 320, 65, "Comment:"); + { data_comment_input = new Fl_Text_Editor(10, 156, 320, 65, "Comment:"); data_comment_input->tooltip("Declaration comment in Doxygen format"); data_comment_input->box(FL_DOWN_BOX); data_comment_input->labelfont(1); @@ -522,16 +531,16 @@ and \"const char*\" in text mode."); data_comment_input->buffer(new Fl_Text_Buffer()); data_comment_input->add_key_binding(FL_Tab, 0, use_tab_navigation); } // Fl_Text_Editor* data_comment_input - { Fl_Group* o = new Fl_Group(10, 205, 320, 20); - { data_panel_ok = new Fl_Return_Button(200, 205, 60, 20, "OK"); + { Fl_Group* o = new Fl_Group(10, 231, 320, 20); + { data_panel_ok = new Fl_Return_Button(200, 231, 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 = new Fl_Button(270, 231, 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_Box* o = new Fl_Box(10, 231, 185, 20); Fl_Group::current()->resizable(o); } // Fl_Box* o o->end(); diff --git a/fluid/function_panel.fl b/fluid/function_panel.fl index 051ada0bc..3e4c8e85f 100644 --- a/fluid/function_panel.fl +++ b/fluid/function_panel.fl @@ -341,11 +341,11 @@ Function {make_decl_panel()} {open Function {make_data_panel()} {open } { Fl_Window data_panel { - label {Inline Data Properties} - xywh {589 362 343 237} type Double align 80 hide resizable size_range {343 237 0 0} + label {Inline Data Properties} open + xywh {567 382 343 264} type Double align 80 resizable size_range {343 237 0 0} visible } { Fl_Group {} {open - xywh {10 10 320 20} + xywh {10 10 320 48} } { Fl_Box {} { xywh {288 10 42 20} resizable @@ -386,42 +386,57 @@ Function {make_data_panel()} {open xywh {10 10 100 20} labelsize 11 } } - Fl_Check_Button data_mode { - label {text mode} - tooltip {When text mode is selected, the returned type is "const char*" and a trailing NUL will be appended to the data.} xywh {200 10 78 20} down_box DOWN_BOX labelsize 11 + Fl_Choice data_mode {open + tooltip {text mode generates a "const char*" and a trailing NUL, compressed mode uses zlib to generate a binary block} xywh {10 38 185 20} down_box BORDER_BOX labelsize 11 textsize 11 + } { + MenuItem {} { + label {binary mode} + user_data 0 user_data_type long + xywh {0 0 100 20} labelsize 11 + } + MenuItem {} { + label {text mode} + user_data 1 user_data_type long + xywh {0 0 100 20} labelsize 11 + } + MenuItem {} { + label {compressed binary} + user_data 2 user_data_type long + xywh {0 0 100 20} labelsize 11 + } } } Fl_Input data_input { label {Variable Name:} - tooltip {Inline Data variables are declared "const unsigned char []" in binary mode and "const char*" in text mode.} xywh {10 52 320 20} labelfont 1 labelsize 11 align 133 when 0 textfont 4 textsize 11 + tooltip {Inline Data variables are declared "const unsigned char []" in binary mode and "const char*" in text mode.} xywh {10 78 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 file that will be inlined.} xywh {10 90 280 20} labelfont 1 labelsize 11 align 133 when 0 textfont 4 textsize 11 + tooltip {Name and path of file that will be inlined.} xywh {10 116 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 + xywh {290 116 40 20} labelcolor 134 } 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 + tooltip {Declaration comment in Doxygen format} xywh {10 156 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());} code1 {data_comment_input->add_key_binding(FL_Tab, 0, use_tab_navigation);} } Fl_Group {} {open - xywh {10 205 320 20} + xywh {10 231 320 20} } { Fl_Return_Button data_panel_ok { label OK - xywh {200 205 60 20} labelsize 11 hotspot + xywh {200 231 60 20} labelsize 11 hotspot } Fl_Button data_panel_cancel { label Cancel - xywh {270 205 60 20} shortcut 0xff1b labelsize 11 + xywh {270 231 60 20} shortcut 0xff1b labelsize 11 } Fl_Box {} { - xywh {10 205 185 20} resizable + xywh {10 231 185 20} resizable } } } @@ -839,7 +854,7 @@ else } Fl_Button {} { user_data {"Fl_Terminal"} - callback type_make_cb selected + callback type_make_cb tooltip Terminal xywh {366 71 24 24} box THIN_UP_BOX code0 {o->image(pixmap[ID_Terminal]);} class Widget_Bin_Button diff --git a/fluid/function_panel.h b/fluid/function_panel.h index ba07009d5..ce9e1a03b 100644 --- a/fluid/function_panel.h +++ b/fluid/function_panel.h @@ -74,8 +74,7 @@ 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; -#include <FL/Fl_Check_Button.H> -extern Fl_Check_Button *data_mode; +extern Fl_Choice *data_mode; extern Fl_Input *data_input; extern Fl_Input *data_filename; extern Fl_Button *data_filebrowser; @@ -85,6 +84,7 @@ extern Fl_Button *data_panel_cancel; Fl_Double_Window* make_data_panel(); extern Fl_Menu_Item menu_data_choice[]; extern Fl_Menu_Item menu_data_class_choice[]; +extern Fl_Menu_Item menu_data_mode[]; extern Fl_Double_Window *class_panel; extern Fl_Light_Button *c_public_button; extern Fl_Input *c_name_input; diff --git a/fluid/template_panel.cxx b/fluid/template_panel.cxx index 14d974b54..0911deb7e 100644 --- a/fluid/template_panel.cxx +++ b/fluid/template_panel.cxx @@ -26,6 +26,7 @@ #include <stdio.h> #include <stdlib.h> #include <errno.h> +#include <zlib.h> #if defined(_WIN32) && !defined(__CYGWIN__) #include <io.h> #else @@ -140,7 +141,7 @@ Fl_Double_Window* make_template_panel() { template_browser->align(Fl_Align(FL_ALIGN_TOP_LEFT)); template_browser->when(FL_WHEN_CHANGED | FL_WHEN_NOT_CHANGED); } // Fl_Browser* template_browser - { template_preview = new Fl_Box(200, 28, 250, 250, "no preview..."); + { template_preview = new Fl_Box(200, 28, 250, 250); template_preview->box(FL_THIN_DOWN_BOX); template_preview->align(Fl_Align(FL_ALIGN_CLIP|FL_ALIGN_INSIDE)); Fl_Group::current()->resizable(template_preview); @@ -205,10 +206,78 @@ void template_delete_cb(Fl_Button *, void *) { return; } + char pngfile[1024], *ext; + strlcpy(pngfile, flfile, sizeof(pngfile)); + if ((ext = strrchr(pngfile, '.')) != NULL) { + strcpy(ext, ".png"); + fl_unlink(pngfile); + } + template_browser->remove(item); template_browser->do_callback(); } +static int tmpl_FLTK_License_fl_size = 623; +static unsigned char tmpl_FLTK_License_fl[401] = /* data compressed and inlined from templates/FLTK_License.fl */ +{120,156,133,82,77,79,220,48,16,189,231,87,60,209,11,72,109,178,208,30,10, +39,218,165,84,43,208,22,137,237,161,39,228,196,147,120,132,99,71,246,132,176, +93,237,127,199,14,187,234,177,62,217,227,247,53,99,127,128,86,162,208,178,37, +180,62,64,12,225,214,202,51,126,71,10,88,57,161,208,170,134,112,67,145,59,151, +74,167,173,29,89,159,21,47,20,34,123,135,243,114,241,101,177,40,12,41,77,225, +201,169,158,176,43,205,190,104,188,166,227,177,121,125,205,133,190,39,39,216,85, +85,81,85,184,94,173,31,55,223,214,203,31,215,255,124,85,20,220,115,103,4,27, +239,45,238,88,112,122,123,191,185,59,43,139,119,210,210,15,219,48,3,206,47,47, +191,126,186,88,92,124,70,189,197,119,182,22,143,3,203,95,245,12,229,52,124,146, +11,241,200,218,24,142,176,92,7,21,182,72,219,54,16,33,250,86,38,21,168,196,13, +71,9,92,143,146,219,201,236,49,18,102,151,136,4,128,31,197,178,35,13,118,89,45, +39,157,199,117,178,252,245,240,103,181,254,121,130,201,112,99,16,141,31,173, +134,81,47,132,154,200,37,124,99,71,157,136,19,139,73,188,108,157,136,37,176,106, +231,99,150,155,165,210,77,207,49,178,235,144,102,161,85,175,58,210,31,17,83,206, +108,103,185,33,151,66,41,185,58,180,148,151,17,25,226,85,85,77,211,84,182,233, +201,74,31,186,234,144,169,28,204,112,128,62,88,82,137,123,212,106,189,181,126, +202,78,67,50,65,106,217,248,9,226,17,104,240,65,80,143,93,156,167,144,242,140, +20,255,107,152,241,71,183,61,118,145,44,53,50,15,235,41,250,49,164,175,147,118, +239,191,163,216,23,111,13,176,205,39}; + +static int tmpl_1of7GUIs_fl_size = 763; +static unsigned char tmpl_1of7GUIs_fl[486] = /* data compressed and inlined from templates/1of7GUIs.fl */ +{120,156,109,82,203,138,219,64,16,188,207,87,52,228,178,102,177,45,25,59, +187,142,73,14,121,56,187,36,224,92,76,142,102,36,181,164,206,142,102,196,60,252, +88,33,216,223,200,61,127,146,63,201,151,164,37,69,176,9,97,4,163,26,122,170, +170,171,231,5,100,210,75,200,73,33,228,198,130,47,17,182,202,63,192,222,161,133, +123,237,209,230,50,69,120,143,142,10,205,71,87,185,10,148,77,4,28,209,58,50,26, +226,89,180,140,34,1,37,202,12,237,65,203,10,161,153,149,173,72,77,134,35,76,207, +231,86,64,106,170,10,181,135,70,196,96,114,184,249,184,191,119,66,244,27,156, +164,131,4,81,67,106,81,122,204,128,177,4,87,147,158,154,60,239,202,59,107,149, +116,236,232,215,211,119,39,24,58,114,240,206,84,181,180,228,216,9,215,236,146, +111,152,250,233,206,18,235,116,36,58,131,109,208,169,103,167,82,137,47,214,20, +86,86,21,233,162,239,150,149,185,179,35,42,83,247,198,146,11,124,8,5,155,248, +68,142,229,125,167,41,238,66,37,245,180,211,9,126,204,68,246,140,80,88,19,234, +209,219,103,164,68,211,163,216,107,234,179,241,63,127,120,184,147,90,27,134,64, +26,22,81,188,156,9,81,122,95,187,87,243,249,77,17,200,205,10,242,101,72,102, +100,6,60,23,45,52,14,21,119,193,246,73,31,156,9,150,243,215,198,31,24,13,33,139, +86,136,177,43,104,248,130,169,81,119,23,197,86,29,190,146,206,204,169,63,22,74, +38,168,56,162,208,121,134,190,234,124,57,149,208,44,111,95,194,98,189,128,120, +189,132,213,170,5,127,169,121,198,38,36,252,12,44,231,250,40,187,191,35,57,226, +125,100,222,5,207,17,240,20,123,186,195,137,178,2,187,97,14,148,241,10,248,187, +141,96,177,24,102,31,65,243,119,233,244,205,81,170,128,87,209,100,211,114,11, +204,248,54,120,255,167,133,231,94,69,42,149,74,100,250,0,13,241,84,8,94,195,191, +76,52,80,77,54,130,174,175,55,226,255,66,212,9,13,238,214,235,103,238,134,245, +27,226,34,7,2}; + +void template_install(const char *path, const char *name, const uchar *inSrc, int inSrcLen, int inDstLen) { + char filename[FL_PATH_MAX]; + strcpy(filename, path); + strcat(filename, name); + FILE *f = fopen(filename, "wb"); + if (!f) return; + uLong dstLen = inDstLen; + Bytef *dst = (Bytef*)::malloc(inDstLen); + if (uncompress(dst, &dstLen, (Bytef*)inSrc, (uLong)inSrcLen) != Z_OK) { /* error */ } + if (fwrite(dst, dstLen, 1, f) <= 0) { /* error */ } + fclose(f); +} + void template_load() { int i; char name[1024], filename[1400], path[1024], *ptr; @@ -216,14 +285,13 @@ void template_load() { int num_files; fluid_prefs.getUserdataPath(path, sizeof(path)); - if (path[0] == 0) return; strlcat(path, "templates", sizeof(path)); fl_make_path(path); int sample_templates_generated = 0; fluid_prefs.get("sample_templates_generated", sample_templates_generated, 0); - if (sample_templates_generated < 2) { + if (sample_templates_generated < 2) { strcpy(filename, path); strcat(filename, "/FLTK_License.fl"); FILE *f = fopen(filename, "wb"); @@ -239,22 +307,9 @@ void template_load() { "er\n}\n", f); fclose(f); } - strcpy(filename, path); - strcat(filename, "/1of7GUIs.fl"); - f = fopen(filename, "wb"); - if (f) { - fputs( - "# data file for the Fltk User Interface Designer (fluid)\n version 1.0400\n header_name {.h}\n" - "code_name {.cxx}\n comment {\n1 of 7GUIs\n\n7GUIs was been created as a spin-off of the master’s\n" - "thesis Comparison of Object-Oriented and Functional\nProgramming for GUI Development by Eugen Kiss at the\n" - "Human-Computer Interaction group of the Leibniz\nUniversität Hannover in 2014.\n\n" - "https://7guis.github.io/7guis/\n} {selected in_source not_in_header\n}\n\nFunction {} {open\n" - "} {\nFl_Window {} {\nlabel Counter open\nxywh {486 292 194 55} type Double resizable visible\n" - "} {\nFl_Output counter_widget {\nxywh {15 15 80 22}\ncode0 {counter_widget->value(0);}\n" - "}\nFl_Button {} {\nlabel Count\ncallback {int i = counter_widget->ivalue();\ni++;\n" - "counter_widget->value(i);}\nxywh {99 15 80 22}\n}\n}\n}\n", f); - fclose(f); - } + + template_install(path, "/FLTK_License.fl", tmpl_FLTK_License_fl, sizeof(tmpl_FLTK_License_fl), tmpl_FLTK_License_fl_size); + template_install(path, "/1of7GUIs.fl", tmpl_1of7GUIs_fl, sizeof(tmpl_1of7GUIs_fl), tmpl_1of7GUIs_fl_size); sample_templates_generated = 2; fluid_prefs.set("sample_templates_generated", sample_templates_generated); fluid_prefs.flush(); diff --git a/fluid/template_panel.fl b/fluid/template_panel.fl index e64f95739..2a98219b0 100644 --- a/fluid/template_panel.fl +++ b/fluid/template_panel.fl @@ -47,6 +47,9 @@ decl {\#include <stdlib.h>} {private local decl {\#include <errno.h>} {private local } +decl {\#include <zlib.h>} {private local +} + declblock {\#if defined(_WIN32) && !defined(__CYGWIN__)} {after {\#endif // _WIN32 && !__CYGWIN__} } { decl {\#include <io.h>} {private local @@ -120,7 +123,6 @@ if (img) { xywh {10 28 180 250} type Hold labelfont 1 align 5 when 3 } Fl_Box template_preview { - label {no preview...} selected xywh {200 28 250 250} box THIN_DOWN_BOX align 80 resizable } Fl_Input template_name { @@ -184,7 +186,7 @@ template_browser->deselect(); template_browser->clear();} {} } -Function {template_delete_cb(Fl_Button *, void *)} {return_type void +Function {template_delete_cb(Fl_Button *, void *)} {open return_type void } { code {int item = template_browser->value(); if (item < 1) return; @@ -201,8 +203,36 @@ if (fl_unlink(flfile)) { return; } +char pngfile[1024], *ext; +strlcpy(pngfile, flfile, sizeof(pngfile)); +if ((ext = strrchr(pngfile, '.')) != NULL) { + strcpy(ext, ".png"); + fl_unlink(pngfile); +} + template_browser->remove(item); -template_browser->do_callback();} {} +template_browser->do_callback();} {selected + } +} + +data tmpl_FLTK_License_fl {private local filename {templates/FLTK_License.fl} compressed +} + +data tmpl_1of7GUIs_fl {private local filename {templates/1of7GUIs.fl} compressed +} + +Function {template_install(const char *path, const char *name, const uchar *inSrc, int inSrcLen, int inDstLen)} {open return_type void +} { + code {char filename[FL_PATH_MAX]; + strcpy(filename, path); + strcat(filename, name); + FILE *f = fopen(filename, "wb"); + if (!f) return; + uLong dstLen = inDstLen; + Bytef *dst = (Bytef*)::malloc(inDstLen); + if (uncompress(dst, &dstLen, (Bytef*)inSrc, (uLong)inSrcLen) != Z_OK) { /* error */ } + if (fwrite(dst, dstLen, 1, f) <= 0) { /* error */ } + fclose(f);} {} } Function {template_load()} {open return_type void @@ -214,6 +244,7 @@ int num_files; fluid_prefs.getUserdataPath(path, sizeof(path)); strlcat(path, "templates", sizeof(path)); +fl_make_path(path); int sample_templates_generated = 0; fluid_prefs.get("sample_templates_generated", sample_templates_generated, 0); @@ -234,22 +265,9 @@ if (sample_templates_generated < 2) { "er\\n}\\n", f); fclose(f); } - strcpy(filename, path); - strcat(filename, "/1of7GUIs.fl"); - f = fopen(filename, "wb"); - if (f) { - fputs( -"\# data file for the Fltk User Interface Designer (fluid)\\n version 1.0400\\n header_name {.h}\\n" -"code_name {.cxx}\\n comment {\\n1 of 7GUIs\\n\\n7GUIs was been created as a spin-off of the master’s\\n" -"thesis Comparison of Object-Oriented and Functional\\nProgramming for GUI Development by Eugen Kiss at the\\n" -"Human-Computer Interaction group of the Leibniz\\nUniversität Hannover in 2014.\\n\\n" -"https://7guis.github.io/7guis/\\n} {selected in_source not_in_header\\n}\\n\\nFunction {} {open\\n" -"} {\\nFl_Window {} {\\nlabel Counter open\\nxywh {486 292 194 55} type Double resizable visible\\n" -"} {\\nFl_Output counter_widget {\\nxywh {15 15 80 22}\\ncode0 {counter_widget->value(0);}\\n" -"}\\nFl_Button {} {\\nlabel Count\\ncallback {int i = counter_widget->ivalue();\\ni++;\\n" -"counter_widget->value(i);}\\nxywh {99 15 80 22}\\n}\\n}\\n}\\n", f); - fclose(f); - } + + template_install(path, "/FLTK_License.fl", tmpl_FLTK_License_fl, sizeof(tmpl_FLTK_License_fl), tmpl_FLTK_License_fl_size); + template_install(path, "/1of7GUIs.fl", tmpl_1of7GUIs_fl, sizeof(tmpl_1of7GUIs_fl), tmpl_1of7GUIs_fl_size); sample_templates_generated = 2; fluid_prefs.set("sample_templates_generated", sample_templates_generated); fluid_prefs.flush(); diff --git a/fluid/template_panel.h b/fluid/template_panel.h index 5c754d77c..cfbcc72c2 100644 --- a/fluid/template_panel.h +++ b/fluid/template_panel.h @@ -36,5 +36,6 @@ extern Fl_Return_Button *template_submit; Fl_Double_Window* make_template_panel(); void template_clear(); void template_delete_cb(Fl_Button *, void *); +void template_install(const char *path, const char *name, const uchar *inSrc, int inSrcLen, int inDstLen); void template_load(); #endif diff --git a/fluid/templates/1of7GUIs.fl b/fluid/templates/1of7GUIs.fl new file mode 100644 index 000000000..8f5fd0652 --- /dev/null +++ b/fluid/templates/1of7GUIs.fl @@ -0,0 +1,36 @@ +# data file for the Fltk User Interface Designer (fluid) + version 1.0400 + header_name {.h} +code_name {.cxx} + comment { +1 of 7GUIs + +7GUIs was been created as a spin-off of the master’s +thesis Comparison of Object-Oriented and Functional +Programming for GUI Development by Eugen Kiss at the +Human-Computer Interaction group of the Leibniz +Universität Hannover in 2014. + +https://7guis.github.io/7guis/ +} {selected in_source not_in_header +} + +Function {} {open +} { +Fl_Window {} { +label Counter open +xywh {486 292 194 55} type Double resizable visible +} { +Fl_Output counter_widget { +xywh {15 15 80 22} +code0 {counter_widget->value(0);} +} +Fl_Button {} { +label Count +callback {int i = counter_widget->ivalue(); +i++; +counter_widget->value(i);} +xywh {99 15 80 22} +} +} +} diff --git a/fluid/templates/FLTK_License.fl b/fluid/templates/FLTK_License.fl new file mode 100644 index 000000000..e708bfc2c --- /dev/null +++ b/fluid/templates/FLTK_License.fl @@ -0,0 +1,21 @@ +# data file for the Fltk User Interface Designer (fluid) +version 1.0400 +header_name {.h} +code_name {.cxx} +comment {// +// @INSTANCE@ for the Fast Light Tool Kit (FLTK). +// +// Copyright 1998-2023 by Bill Spitzak and others. +// +// This library is free software. Distribution and use rights are outlined in +// the file "COPYING" which should have been included with this file. If this +// file is missing or damaged, see the license at: +// +// https://www.fltk.org/COPYING.php +// +// Please see the following page on how to report bugs and issues: +// +// https://www.fltk.org/bugs.php +// +} {selected in_source in_header +} |
