Scheme_Object* spark_fltk_progress::fl_progress(int argc, Scheme_Object** argv) { DEFAULT_RET_INIT; int x = 0; int y = 0; int w = 0; int h = 0; spark::Utils::int_from_scheme_long(argv[0], x); spark::Utils::int_from_scheme_long(argv[1], y); spark::Utils::int_from_scheme_long(argv[2], w); spark::Utils::int_from_scheme_long(argv[3], h); std::string title; if (argv[4] != scheme_null) { Scheme_Object* str = scheme_char_string_to_byte_string(argv[4]); title = SCHEME_BYTE_STR_VAL(str); } Fl_Progress* p = new Fl_Progress(x, y, w, h); if (title.length() > 0) p->copy_label(title.c_str()); Fltk_tag t = FL_WIDGET_TAG; Widget* widget = new Widget; p->argument(reinterpret_cast<long>(widget)); { Scheme_Object* tag = 0; MZ_GC_DECL_REG(1); MZ_GC_VAR_IN_REG(0, tag); MZ_GC_REG(); tag = scheme_make_integer(t); MZ_GC_UNREG(); _ret_ = scheme_make_cptr(p, tag); } DEFAULT_RET_FINISH; }
int main(int argc, char **argv) { ThemeLoader::init(); IconLoader::init(); win = new EdeWindow(455, 485, "Theme demo"); win->begin(); { Fl_Button* o = new Fl_Button(355, 450, 90, 25, "Load"); o->tooltip("Load predefined theme"); o->callback(load_theme_cb); } // Fl_Button* o { Fl_Menu_Bar* o = new Fl_Menu_Bar(0, 0, 455, 25); o->menu(menu_); } // Fl_Menu_Bar* o { Fl_Round_Button* o = new Fl_Round_Button(5, 285, 90, 25, "round"); o->down_box(FL_ROUND_DOWN_BOX); } // Fl_Round_Button* o { new Fl_Return_Button(5, 195, 90, 25, "button"); } // Fl_Return_Button* o { new Fl_Input(160, 196, 285, 25, "input:"); } // Fl_Input* o { Fl_Output* o = new Fl_Output(160, 225, 285, 25, "output:"); o->value("Some output value"); } // Fl_Output* o { Fl_File_Browser* o = new Fl_File_Browser(5, 30, 210, 125); o->load("/"); } // Fl_File_Browser* o { Fl_Check_Browser* o = new Fl_Check_Browser(220, 30, 225, 125); o->add("foo"); o->add("foo"); o->add("foo"); } // Fl_Check_Browser* o { Fl_Progress* o = new Fl_Progress(5, 160, 210, 25, "progress bar"); o->value(50); } // Fl_Progress* o { Fl_Slider* o = new Fl_Slider(220, 160, 225, 25); o->type(1); o->align(Fl_Align(FL_ALIGN_TOP_LEFT)); } // Fl_Slider* o { new Fl_Light_Button(5, 225, 90, 25, "button"); } // Fl_Light_Button* o { Fl_Check_Button* o = new Fl_Check_Button(5, 255, 90, 25, "check"); o->down_box(FL_DOWN_BOX); } // Fl_Check_Button* o { Fl_File_Input* o = new Fl_File_Input(160, 256, 285, 35, "file:"); o->value("/home/foo/baz/taz.txt"); } // Fl_File_Input* o { Fl_Text_Editor* o = new Fl_Text_Editor(160, 325, 285, 115, "Text editor"); o->buffer(new Fl_Text_Buffer()); } // Fl_Text_Editor* o { Fl_Box* o = new Fl_Box(25, 328, 80, 80, "image"); IconLoader::set(o, "utilities-terminal", ICON_SIZE_MEDIUM); } // Fl_Box* o win->end(); win->show(argc, argv); Fl::run(); ThemeLoader::shutdown(); IconLoader::shutdown(); return 0; }
ct_image_window::ct_image_window( ) { Fl_Double_Window* w; { Fl_Double_Window* o = image_window = new Fl_Double_Window(421, 528); w = o; o->user_data((void*)(this)); { Fl_Group* o = new Fl_Group(5, 30, 410, 410); o->box(FL_PLASTIC_DOWN_FRAME); { ct_draw_area* o = ct_image = new ct_draw_area(10, 35, 400, 400, "label"); o->box(FL_FLAT_BOX); o->color(FL_DARK3); o->selection_color(FL_BACKGROUND_COLOR); o->labeltype(FL_NORMAL_LABEL); o->labelfont(0); o->labelsize(14); o->labelcolor(FL_BLACK); o->align(FL_ALIGN_CENTER); o->when(FL_WHEN_RELEASE); } o->end(); } { Fl_Menu_Bar* o = new Fl_Menu_Bar(0, 0, 100, 25); o->box(FL_FLAT_BOX); o->menu(menu_); } { Fl_Value_Slider* o = WL = new Fl_Value_Slider(40, 470, 375, 20, "WL"); o->type(1); o->box(FL_PLASTIC_THIN_DOWN_BOX); o->minimum(-2000); o->maximum(7000); o->step(1); o->value(40); o->callback((Fl_Callback*)cb_WL); o->align(FL_ALIGN_LEFT); } { Fl_Value_Slider* o = WW = new Fl_Value_Slider(40, 495, 375, 20, "WW"); o->type(1); o->box(FL_PLASTIC_THIN_DOWN_BOX); o->minimum(1); o->maximum(4000); o->step(1); o->value(300); o->callback((Fl_Callback*)cb_WW); o->align(FL_ALIGN_LEFT); } { Fl_Value_Slider* o = Indx = new Fl_Value_Slider(40, 445, 375, 20, "Indx"); o->type(1); o->box(FL_PLASTIC_THIN_DOWN_BOX); o->step(1); o->callback((Fl_Callback*)cb_Indx); o->align(FL_ALIGN_LEFT); } { Fl_Progress* o = progress_bar = new Fl_Progress(115, 5, 300, 20); o->box(FL_PLASTIC_THIN_UP_BOX); o->selection_color((Fl_Color)1); o->hide(); } o->end(); } }
void butt_cb(Fl_Widget *butt, void *data) { // Deactivate the button butt->deactivate(); // prevent button from being pressed again Fl::check(); // give fltk some cpu to gray out button // Make the progress bar Fl_Window *w = (Fl_Window*)data; // access parent window w->begin(); // add progress bar to it.. Fl_Progress *progress = new Fl_Progress(10,50,200,30); progress->minimum(0); // set progress range to be 0.0 ~ 1.0 progress->maximum(1); progress->color(0x88888800); // background color progress->selection_color(0x4444ff00); // progress bar color progress->labelcolor(FL_WHITE); // percent text color w->end(); // end adding to window // Computation loop.. for ( int t=1; t<=500; t++ ) { progress->value(t/500.0); // update progress bar with 0.0 ~ 1.0 value char percent[10]; sprintf(percent, "%d%%", int((t/500.0)*100.0)); progress->label(percent); // update progress bar's label Fl::check(); // give fltk some cpu to update the screen Sleep(1000); // 'your stuff' that's compute intensive } // Cleanup w->remove(progress); // remove progress bar from window delete(progress); // deallocate it butt->activate(); // reactivate button w->redraw(); // tell window to redraw now that progress removed }
//constructeur Fl_Progress_Window() : Fl_Window(238,105,"Progression...") { // Progress 1 Label Fl_Box *label = new Fl_Box(10,10,215,15,"Pourcentage Général:"); label->labelsize(12); label->labelfont(1); label->labelcolor((Fl_Color)136); label->align(FL_ALIGN_LEFT|FL_ALIGN_INSIDE); //Progress1 progress1 = new Fl_Progress(10,28,215,20,"0%"); progress1->selection_color((Fl_Color)175); progress1->maximum(100); progress1->minimum(0); progress1->labelsize(12); // Progress filename (label progress 2) progress_filename = new Fl_Box(10,52,215,15, "Fichier:"); progress_filename->labelsize(12); progress_filename->labelfont(1); progress_filename->labelcolor((Fl_Color)136); progress_filename->align(FL_ALIGN_LEFT|FL_ALIGN_INSIDE); // Progress 2 progress2 = new Fl_Progress(10,70,215,20,"0%"); progress2->maximum(100); progress2->minimum(0); progress2->labelsize(12); progress2->selection_color((Fl_Color)175); //fin du window... this->set_modal(); this->end(); }
Scheme_Object* spark_fltk_progress::value(int argc, Scheme_Object** argv) { DEFAULT_RET_INIT; Fl_Progress* p = _get_fl_progress(argc, argv, 0); if (p) { if (argc == 1) { float v = p->value(); _ret_ = scheme_make_float(v); } else { double x = 0.0f; spark::Utils::double_from_scheme_double(argv[1], x); p->value(static_cast<float>(x)); _ret_ = scheme_true; } } DEFAULT_RET_FINISH; }
void sprites::importSpriteSheet(const char*fname){ if(!fname){ if(!load_file_generic("Load image")) return; fname=the_file.c_str(); } if(fname){ Fl_Shared_Image * loaded_image=Fl_Shared_Image::get(fname); if(!loaded_image){ fl_alert("Error loading image"); return; } unsigned depth=loaded_image->d(); if (unlikely(depth != 3 && depth != 4 && depth!=1)){ fl_alert("Please use color depth of 1,3 or 4\nYou Used %d",depth); loaded_image->release(); return; }else printf("Image depth %d\n",depth); uint32_t w,h; w=loaded_image->w(); h=loaded_image->h(); bool grayscale; uint8_t*palMap; uint8_t*imgptr; unsigned remap[256]; if(depth==1){ grayscale=handle1byteImg(loaded_image,remap); if(!grayscale){ palMap=(uint8_t*)loaded_image->data()[1]; imgptr=(uint8_t*)loaded_image->data()[2]; } } uint8_t mask[3]; bool useAlpha; if(getMaskColorImg(loaded_image,grayscale,remap,palMap,mask,useAlpha)){ std::vector<int> rects;//x0,x1,y0,y1 Fl_Window *winP; Fl_Progress *progress; mkProgress(&winP,&progress); time_t lasttime=time(NULL); progress->maximum(h); Fl::check(); for(int y=0;y<h;++y){ for(int x=0;x<w;++x){ if(!isMask(x,y,loaded_image,grayscale,useAlpha,mask)){ rects.push_back(x); while(!isMask(x+1,y,loaded_image,grayscale,useAlpha,mask)) ++x; rects.push_back(x); rects.push_back(y); rects.push_back(y); } } if((time(NULL)-lasttime)>=1){ lasttime=time(NULL); progress->value(h); Fl::check(); } } progress->maximum(rects.size()); progress->value(0); //Now combine the rectangles //Start by combining rectangles by that touch with y values bool canEnd; int pass=0; char txtbufstage[1024]; char txtbuf[1024]; do{ canEnd=true; snprintf(txtbufstage,1024,"Stage 1 pass %d",pass++); winP->label(txtbufstage); Fl::check(); for(int i=0;i<rects.size();i+=4){ for(int j=0;j<rects.size();j+=4){ if(i==j) continue; //See if rectangles are touching or overlap //if((inRange(rects[j+2],rects[i+2]-1,rects[i+3]+1)||inRange(rects[i+2],rects[j+2]-1,rects[j+3]+1))&&(!((rects[i+2]==rects[j+2])||(rects[i+3]==rects[j+3])))){//Is rectange j directly above or below i if((rects[j+3]-rects[i+2])==1){ if((inRange(rects[j],rects[i]-1,rects[i+1]+1)||inRange(rects[i],rects[j]-1,rects[j+1]+1))){ canEnd=false; //Merge the two squares obtaining maximum size //Now try and find the combination that results in the largest rectangle rects[i]=std::min(rects[i],rects[j]); rects[i+1]=std::max(rects[i+1],rects[j+1]); rects[i+2]=std::min(rects[i+2],rects[j+2]); rects[i+3]=std::max(rects[i+3],rects[j+3]); rects.erase(rects.begin()+j,rects.begin()+j+4); //Now try to find next in sequence bool foundit; do{ foundit=false; for(int a=0;a<rects.size();a+=4){ int look=rects[i+3]+1; if(rects[a+2]==look){ if((inRange(rects[a],rects[i]-1,rects[i+1]+1)||inRange(rects[i],rects[a]-1,rects[a+1]+1))){ foundit=true; rects[i]=std::min(rects[i],rects[a]); rects[i+1]=std::max(rects[i+1],rects[a+1]); rects[i+2]=std::min(rects[i+2],rects[a+2]); rects[i+3]=std::max(rects[i+3],rects[a+3]); rects.erase(rects.begin()+a,rects.begin()+a+4); } } } }while(foundit); } } } if((time(NULL)-lasttime)>=1){ lasttime=time(NULL); progress->maximum(rects.size()); progress->value(i); snprintf(txtbuf,1024,"Rectangles: %d",rects.size()); progress->label(txtbuf); Fl::check(); } } }while(!canEnd); pass=0; do{ canEnd=true; snprintf(txtbufstage,1024,"Stage 2 pass %d",pass++); winP->label(txtbufstage); progress->maximum(rects.size()); progress->value(0); Fl::check(); for(int i=0;i<rects.size();i+=4){ for(int j=0;j<rects.size();j+=4){ if(i==j) continue; //Merge overlapping rectangles if((rects[i]<=rects[j+1])&&(rects[i+1]>=rects[j])&&(rects[i+2]<=rects[j+3])&&(rects[i+3]>=rects[j+2])){ canEnd=false; rects[i]=std::min(rects[i],rects[j]); rects[i+1]=std::max(rects[i+1],rects[j+1]); rects[i+2]=std::min(rects[i+2],rects[j+2]); rects[i+3]=std::max(rects[i+3],rects[j+3]); rects.erase(rects.begin()+j,rects.begin()+j+4); } //Merge touching rectangles if(abs(rects[i+1]-rects[j])==1){ if((inRange(rects[j+2],rects[i+2]-1,rects[i+3]+1)||inRange(rects[i+2],rects[j+2]-1,rects[j+3]+1))){ canEnd=false; rects[i]=std::min(rects[i],rects[j]); rects[i+1]=std::max(rects[i+1],rects[j+1]); rects[i+2]=std::min(rects[i+2],rects[j+2]); rects[i+3]=std::max(rects[i+3],rects[j+3]); rects.erase(rects.begin()+j,rects.begin()+j+4); } } } if((time(NULL)-lasttime)>=1){ lasttime=time(NULL); progress->maximum(rects.size()); progress->value(i); snprintf(txtbuf,1024,"Rectangles: %d",rects.size()); progress->label(txtbuf); Fl::check(); } } }while(!canEnd); winP->remove(progress);// remove progress bar from window delete(progress);// deallocate it delete winP; std::vector<bool> deleted; deleted.resize(rects.size()/4); //Now show the window allowing user to adjust sprite settings if(window){ win=new Fl_Double_Window(640,480,"Sprite selection"); win->begin(); win->resizable(win); Fl_Button * Ok=new Fl_Button(256,448,64,24,"Okay"); Ok->callback(RetCB,(void*)1); Fl_Button * Cancel=new Fl_Button(320,448,64,24,"Cancel"); Cancel->callback(RetCB,0); Fl_Scroll*scroll=new Fl_Scroll(8,8,624,440); box=new RectBox(8,8,w,h); box->scroll=scroll; box->rects=&rects; box->deleted=&deleted; box->image(loaded_image); scroll->end(); win->end(); win->set_modal(); win->show(); Fl::check(); while(win->shown()) Fl::wait(); delete win; }else retOkay=true; if(retOkay){ for(unsigned i=0;i<rects.size();i+=4){ recttoSprite(rects[i],rects[i+1],rects[i+2],rects[i+3],-1,loaded_image,grayscale,remap,palMap,mask,true,useAlpha); } updateTileSelectAmt(); } deleted.clear(); rects.clear(); } loaded_image->release(); } }
void IconChooser::load_from_list(list<String>& lst) { if(lst.empty()) return; Fl_Shared_Image* img = NULL; int imax_w = 0; int imax_h = 0; int iw, ih; bool show_progress = false; list<String>::iterator it = lst.begin(), it_end = lst.end(); /* * lst_info contains coresponding indexes with list<String> so we can deduce what * files to skip (not readable image or dimensions greater than allowed); skippable are marked as 0 */ int* lst_info = new int[lst.size()]; for(int n = 0; it != it_end; ++it, n++){ img = Fl_Shared_Image::get((*it).c_str()); if(!img) { lst_info[n] = 0; continue; } iw = img->w(); ih = img->h(); if(iw > MAX_ICON_W || ih > MAX_ICON_H) { lst_info[n] = 0; continue; } imax_w = MAX(imax_w, iw); imax_h = MAX(imax_h, ih); lst_info[n] = 1; } /* clear potential content of ExpandableGroup */ if(icongrp->children()) icongrp->clear(); if(lst.size() > 10) { show_progress = true; progress->minimum(0); progress->maximum(lst.size()); progress->show(); } if(imax_w < 64) imax_w = 64; else imax_w += 10; if(imax_h < 64) imax_h = 64; else imax_h += 10; imax_w += 5; imax_h += 5; /* * focus_index() is only valid on childs before we show them and that is what we need * so other childs don't mess it when they are added */ //icongrp->focus(child(0)); icongrp->set_visible_focus(); IconBox* preview; it = lst.begin(); for(int n = 0; it != it_end; ++it, n++) { img = Fl_Shared_Image::get((*it).c_str()); if(img && lst_info[n] == 1) { preview = new IconBox(0, 0, imax_w, imax_h); preview->set_icon_path((*it)); /* use background/selection from ExpandableGroup */ preview->color(icongrp->color()); preview->selection_color(icongrp->color()); if(show_progress) progress->value(int((n * 100) / int(progress->maximum()))); preview->image(img); preview->callback(iconbox_cb, this); icongrp->add(preview); Fl::check(); } } progress->hide(); delete [] lst_info; }