Scene *readHeights(char* fn) { int width, height; unsigned char *height_map; height_map = readBMP(fn, width, height); if (!height_map) { fl_alert("Error loading height map\n"); return false; } Scene * ret = new Scene(); //TODO: customize mat Material * mat = new Material(); mat->kd = vec3f(1.0, 1.0, 1.0); //extract the points Trimesh * trimesh = new Trimesh(ret, mat, &ret->transformRoot); for (int y = 0; y < height; ++y) { for (int x = 0; x < width; ++x) { int pos = y * width + x; unsigned char pixel[3]; memcpy(pixel, height_map + pos * 3, 3); double height = double(pixel[0] + pixel[1] + pixel[2]) / 3 / 128; vec3f point(x, y, height); trimesh->addVertex(point); if (x > 0 && y > 0) { //link the points trimesh->addFace(pos, pos - 1, pos - 1 - width); trimesh->addFace(pos, pos - 1 - width, pos - width); } } } char *error; if (error = trimesh->doubleCheck()) throw ParseError(error); //add a trimesh ret->add(trimesh); //add a pointlight PointLight* point_light = new PointLight(ret, vec3f(width, height, 10), vec3f(1.0, 1.0, 1.0)); ret->add(point_light); //set the camerea //TODO: calculate the correct viewing distance; vec3f map_center((double)width / 2 - 0.5, (double)height / 2 - 0.5, 0.5); double camera_distance = (double)width + 3.0; vec3f camera_pos(0, -camera_distance, 2 * camera_distance); camera_pos += map_center; ret->getCamera()->setEye(camera_pos); ret->getCamera()->setLook((map_center - camera_pos).normalize(), vec3f(0, 0, 1).normalize()); return ret; }
void usage() { #ifdef WIN32 fl_alert( "usage: %s [-r <#> -w <#> -t] [input.ray output.bmp]\n", progname ); #else fprintf( stderr, "usage: %s [options] [input.ray output.bmp]\n", progname ); fprintf( stderr, " -r <#> set recurssion level (default %d)\n", recursion_depth ); fprintf( stderr, " -w <#> set output image width (default %d)\n", g_width ); fprintf( stderr, " -t report time statistics\n" ); #endif }
void Module::command_remove ( void ) { if ( is_default() ) fl_alert( "Default modules may not be deleted." ); else { chain()->remove( this ); Fl::delete_widget( this ); } }
void ImpressionistUI::cb_load_dissolve(Fl_Menu_* o, void* v) { ImpressionistDoc *pDoc = whoami(o)->getDocument(); if (!pDoc->m_ucBitmap) { fl_alert("Please load a background image first."); return; } char* newfile = fl_file_chooser("Open File?", "*.bmp", pDoc->getImageName()); if (newfile != NULL) { pDoc->loadDissolveImage(newfile); } }
// @override bool MaskBrush::init(void) { char* newfile = fl_file_chooser("Load mask image?", "*.bmp", fileName); if (newfile == NULL) { return false; } if ((data = readBMP(newfile, width, height)) == NULL) { fl_alert("Can't load bitmap file"); return false; } return true; }
void removeTilemapsPlane(Fl_Widget*,void*){ if(currentProject->tms->maps.size()>1){ pushTilemapPlaneDelete(currentProject->curPlane); currentProject->tms->removePlane(currentProject->curPlane); if(currentProject->curPlane) --currentProject->curPlane; window->planeSelect->value(currentProject->curPlane); updatePlaneTilemapMenu(); setCurPlaneTilemaps(0,(void*)(uintptr_t)currentProject->curPlane); }else fl_alert("This is the improper way to disable planes"); }
Fl_Image *BaseArea::CreateImageCover(int nW, int nH, uint32_t nColor) { if(true && nW > 0 && nH > 0){ std::vector<uint32_t> stvBuf(nW * nH, nColor); return Fl_RGB_Image((uchar *)(&(stvBuf[0])), nW, nH, 4, 0).copy(nW, nH); }else{ fl_alert("Invalid size for CreateImageCover(%d, %d, 0X%08" PRIu32 ")", nW, nH, nColor); return nullptr; } }
void Module::menu_cb ( const Fl_Menu_ *m ) { char picked[256]; if ( ! m->mvalue() || m->mvalue()->flags & FL_SUBMENU_POINTER || m->mvalue()->flags & FL_SUBMENU ) return; strncpy( picked, m->mvalue()->label(), sizeof( picked ) ); // m->item_pathname( picked, sizeof( picked ) ); DMESSAGE( "%s", picked ); Logger log( this ); if ( ! strcmp( picked, "Edit Parameters" ) ) command_open_parameter_editor(); else if ( ! strcmp( picked, "Bypass" ) ) { if ( ! bypassable() ) { fl_alert( "Due to its channel configuration, this module cannot be bypassed." ); } else { bypass( !bypass() ); redraw(); } } else if ( ! strcmp( picked, "Cut" ) ) { if ( copy() ) { chain()->remove( this ); Fl::delete_widget( this ); } } else if ( ! strcmp( picked, "Copy" ) ) { copy(); } else if ( ! strcmp( picked, "Paste" ) ) { paste_before(); } else if ( ! strcmp( picked, "Show Analysis" ) ) { show_analysis_window(); } else if ( ! strcmp( picked, "Remove" ) ) command_remove(); }
void saveScheme(char *scheme) { char *keys[] = { "color", "label color", "selection color", "selection text color", "highlight color", "text color", "highlight label color", }; Fl_Button *colorBoxes[7] = { colorBox, labelColorBox, selectionColorBox, selectionTextColorBox, highlightColorBox, textColorBox, highlightLabelColorBox }; if (schemeListBox->size() > 1) { if (colorBox->color() == labelColorBox->color()) { fl_alert(_("Color and label color are the same. Edit colors first.")); } else { Fl_Config colorConfig(scheme); //save to "active".scheme colorConfig.set_section("widgets/default"); for (int boxIndex=0; boxIndex<7; boxIndex++) { colorConfig.write(keys[boxIndex], (int)colorBoxes[boxIndex]->color()); } colorConfig.write("text background", (int)textBackgroundBox->color()); // we don't want to lose leading space... char tr[128]; strncpy (tr, labelfont.font->system_name(), 128); if (tr[0] == ' ') tr[0] = '_'; colorConfig.write("label font", tr); strncpy (tr, textfont.font->system_name(), 128); if (tr[0] == ' ') tr[0] = '_'; colorConfig.write("text font", tr); colorConfig.write("label size", labelfont.size); colorConfig.write("text size", textfont.size); colorConfig.write("font encoding", textfont.encoding); colorConfig.set_section("widgets/tooltip"); colorConfig.write("color", (int)tooltipBox->color()); colorConfig.write("label color", (int)tooltipTextColorButton->color()); colorConfig.set_section("global colors"); colorConfig.write("background", (int)backgroundBox->color()); } } }
int create_new_dnd_icon(int x, int y, char *filename) //create icon from dnd data { if (filename) { char config[FL_PATH_MAX]; const char *name = fl_file_filename(filename); snprintf(config, sizeof(config)-1, "%s/.ede/desktop/%s.desktop", getenv("HOME"), name); if (!fl_file_exists((char*)config)) { char val[FL_PATH_MAX]; Fl_Config checkconf(filename, true, false); if(!checkconf.get("Desktop Entry", "Exec", val, 0, sizeof(val))) { Fl_Config cfg(config); cfg.set_section("Desktop Entry"); checkconf.get("Desktop Entry", "Icon", val, "no icon", sizeof(val)); cfg.write("Icon", val); cfg.write("X", x); cfg.write("Y", y); cfg.write(get_localized_string(), get_localized_name(checkconf)); checkconf.get("Desktop Entry", "Exec", val, filename, sizeof(val)); cfg.write("Exec", val); cfg.flush(); } else { Fl_Config cfg(config); cfg.set_section("Desktop Entry"); cfg.write("Icon", "no icon"); cfg.write("X", x); cfg.write("Y", y); cfg.write(get_localized_string(), name); cfg.write("Exec", filename); cfg.flush(); } desktop->begin(); Icon *icon = new Icon((char*)config); icon->show(); desktop->end(); desktop->redraw(); } else { fl_alert(_("The icon with the same name already exists.")); } } return 0; }
void skeleton_open_cb( Fl_Widget* w, void* ) { #ifdef HAVE_LIBPNG const char *p = fl_file_chooser( _("Open Skeleton"), "*.{ifs,png}", NULL ); if ( p != NULL ) { string skeleton; try { skeleton = ImageGray::getDescriptionFromPNG(p); } catch ( const int e ) { if ( e == 1 ) { // not a PNG file. Maybe an IFS file skeleton = IS::readStringInFile(p); } } #else const char *p = fl_file_chooser( _("Open Skeleton"), "*.ifs", NULL ); if ( p != NULL ) { string skeleton = IS::readStringInFile(p); #endif if ( !glito->skel.fromXML(skeleton) ) { fl_alert( _("Failed to open \"%s\"."), p ); } else { glito->setSystemType(); glito->state = PREVIEW; glito->needRedraw = true; } } } void skeleton_save_cb( Fl_Widget* w, void* ) { const char *p = fl_file_chooser( _("Save Skeleton"), "*.ifs", "*.ifs" ); if ( p != NULL ) { IS::saveStringToFile( p, glito->skel.toXML() ); } } void export_fractint_cb( Fl_Widget* w, void* ) { const char *p = fl_file_chooser( _("Export Skeleton to Fractint"), "*.ifs", "*.ifs" ); if ( p != NULL ) { const string file(p); IS::saveStringToFile( p, glito->skel.toFractint(file.substr(0,file.find('.'))) ); } glito->needRedraw = true; } #ifdef HAVE_LIBPNG void set_snapshotPath_cb( Fl_Widget* w, void* ) { glito->setSnapshotPath(); } void saveSnapshot_cb( Fl_Widget* w, void* ) { glito->saveSnapshot(); glito->needRedraw = true; }
void GLWindow::readImage( const char * fname ) { if (state != LAB_BRUSH) { fl_alert("Must be in brush mode to open image"); return; } std::string filename(fname); std::string ext(filename.substr(filename.length() - 4, 4)); Fl_Image* image; if (ext == ".bmp") image = new Fl_BMP_Image(filename.c_str()); else if (ext == ".jpg") image = new Fl_JPEG_Image(filename.c_str()); else if (ext == ".png") image = new Fl_PNG_Image(filename.c_str()); else { fl_alert("Not a valid image file!"); return; } brushUI.loadImage(image); delete image; }
void readColorMap_cb( Fl_Widget*, void* ) { const char* p = fl_file_chooser( _("Open Color Map (pov-ray format)"), "*.map", "*.map" ); if ( p != NULL ) { const string colorText = IS::readStringInFile(p); if ( !IS::extractFirst( colorText, "color_map {", "}" ).empty() ) { Image::readColorMap( colorText ); glito->state = PREVIEW; glito->needRedraw = true; } else { fl_alert( _("Failed to open \"%s\"."), p ); } } }
void open_parameters_cb( Fl_Widget*, void* ) { const char* p = fl_file_chooser( _("Open Parameters"), "*.xml", "*.xml" ); if ( p != NULL ) { const string param = IS::readStringInFile(p); if ( !IS::ToXML::extractFirst( param, "parameters" ).empty() ) { glito->readParameters( param ); glito->state = PREVIEW; glito->needRedraw = true; } else { fl_alert( _("Failed to open \"%s\"."), p ); } } }
void PATransitionCreator::setInfo(bool isCreateMode, const std::string& stateName) { if (isCreateMode) { inputStateName->value(getUniqueStateName("state").c_str()); inputStateName->activate(); buttonCreateState->label(strdup("Create State")); } else { inputStateName->value(stateName.c_str()); inputStateName->deactivate(); buttonCreateState->label(strdup("Save Changes")); } loadMotions(); if (!isCreateMode) { SmartBody::SBAnimationBlendManager* stateManager = SmartBody::SBScene::getScene()->getBlendManager(); SmartBody::SBAnimationBlend* state = stateManager->getBlend(stateName); if (!state) { fl_alert("State %s does not exist.", stateName.c_str()); cancelState(this, NULL); return; } std::vector<SmartBody::SBMotion*>& motions = state->motions; for (std::vector<SmartBody::SBMotion*>::iterator iter = motions.begin(); iter != motions.end(); iter++) { stateAnimationList->add((*iter)->getName().c_str()); } SmartBody::SBAnimationBlend0D* state0d = dynamic_cast<SmartBody::SBAnimationBlend0D*>(state); if (state0d) choiceStateType->value(0); SmartBody::SBAnimationBlend1D* state1d = dynamic_cast<SmartBody::SBAnimationBlend1D*>(state); if (state1d) choiceStateType->value(1); SmartBody::SBAnimationBlend2D* state2d = dynamic_cast<SmartBody::SBAnimationBlend2D*>(state); if (state2d) choiceStateType->value(2); SmartBody::SBAnimationBlend3D* state3d = dynamic_cast<SmartBody::SBAnimationBlend3D*>(state); if (state3d) choiceStateType->value(3); } }
void ModelViewController::Print() { if( !serial->isConnected() ) { fl_alert ("Not connected to printer.\nCannot start printing"); return; } gui->ContinueButton->value(0); gui->ContinueButton->activate(); gui->ContinueButton->label("Pause"); gui->PrintButton->value(1); gui->PrintButton->label("Print"); gui->PrintButton->deactivate(); // Snack one line at a time from the Gcode view, and buffer it. /* if(gui->PrintButton->value() == 0) // Turned off print, cancel buffer and flush { m_bPrinting = false; return; } */ serial->Clear(); // resets line nr and buffer serial->m_bPrinting = false; serial->SetDebugMask(); serial->SetLineNr(-1); // Reset LineNr Count gui->CommunationLog->clear(); Fl_Text_Buffer* buffer = gui->GCodeResult->buffer(); char* pText = buffer->text(); uint length = buffer->length(); uint pos = 2; while(pos < length) { char* line = buffer->line_text(pos); if(line[0] == ';') { pos = buffer->line_end(pos)+1; // skip newline continue; } serial->AddToBuffer(line); pos = buffer->line_end(pos)+1; // find end of line } gui->ProgressBar->maximum(serial->Length()); gui->ProgressBar->label("Printing"); gui->ProgressBar->value(0); free(pText); serial->StartPrint(); }
void rename_cb(Fl_Widget*, void* ic) { Icon* icon = (Icon*)ic; assert(icon != NULL); const char* val = fl_input(_("Rename icon:"), icon->label().c_str()); if(val) { if(strlen(val) == 0) fl_alert(_("Please do not use empty values as icon names")); else icon->update_label(val); } }
// write the control points to our simple format void World::writePoints(const char* filename) { FILE* fp = fopen(filename,"w"); if (!fp) { fl_alert("Can't open file for writing"); } else { fprintf(fp,"%d\n",points.size()); for(size_t i=0; i<points.size(); ++i) fprintf(fp,"%g %g %g %g %g %g\n", points[i].pos.x, points[i].pos.y, points[i].pos.z, points[i].orient.x, points[i].orient.y, points[i].orient.z); fclose(fp); } }
static void cb_test(Fl_Widget*, void*) { char buffer[128]; Fl_Dialog& dialog = *dlg; // define widgets contents dialog["first_name"] = input1->value(); dialog["last_name"] = input2->value(); // show modal dialog, and get results after it's closed Fl_String fname, lname; switch (dialog.show_modal()) { case FL_DLG_OK: fname = dialog["first_name"]; lname = dialog["last_name"]; sprintf(buffer,"Ok pressed, %s %s", fname.c_str(), lname.c_str() ); fl_alert(buffer); input1->value(fname); input2->value(lname); break; case FL_DLG_CANCEL: fl_alert("Cancel pressed"); break; } }
void apply_colors_apps(Fl_Color fg, Fl_Color bg, Fl_Color text, Fl_String font) { uchar r, g, b, r1, g1, b1, r2, g2, b2; fl_get_color(bg, r, g, b); fl_get_color(fg, r1, g1, b1); fl_get_color(text, r2, g2, b2); Fl_String filePath(fl_homedir()); filePath += "/.Xdefaults"; char *backgroundTypes[34] = { "*XmList.background" , "*XmLGrid.background", "Netscape*XmList.background" , "Netscape*XmLGrid.background", "*text*background", "*list*background", "*Text*background", "*List*background", "*textBackground", "*XmTextField.background", "*XmText.background", "Netscape*XmTextField.background", "Netscape*XmText.background", "*background", "*Background", "nscal*Background", "*Menu*background", "OpenWindows*WindowColor", "Window.Color.Background", "netscape*background", "Netscape*background", ".netscape*background", "Ddd*background", "Emacs*Background", "Emacs*backgroundToolBarColor",//25 "*XmList.selectBackground" , "*XmLGrid.selectBackground", "Netscape*XmList.selectBackground" , "Netscape*XmLGrid.selectBackground", "*XmTextField.selectBackground", "*XmText.selectBackground", "Netscape*XmTextField.selectBackground", "Netscape*XmText.selectBackground", "*selectBackground" //34 }; FILE *colorFile = fopen(filePath, "w"); for (int i = 0 ; i < 34; i++) { fprintf(colorFile, "%s: #%02X%02X%02X\n", backgroundTypes[i],(short int) r, (short int) g, (short int) b); } fprintf(colorFile, "foreground: #%02X%02X%02X\n", r1, g1, b1); fprintf(colorFile, "xterm*background: #FFFFFF\n"); //especialy for Xterm fclose(colorFile); Fl_String runString("xrdb -merge -all "); runString += fl_homedir(); runString += "/.Xdefaults"; if (fl_start_child_process(runString)==-1) fl_alert("Error executing xrdb program."); }
void COGLWin::MenuShowScriptList(Fl_Widget *pWidget) { if (!m_pBrowserWin || !m_pBrowser) { fl_alert("Script list windows not available."); return; } if (m_pEditor) { vector<CCLUCodeBase::SScriptFile> &vecScriptList = m_Parse.GetCodeBase().GetScriptList(); int iCurScript = m_Parse.GetCodeBase().GetCurScriptIdx(); int iScript, iScriptCount = vecScriptList.size(); if (iScriptCount == 0) { fl_alert("No scripts in list."); return; } m_pBrowser->clear(); for( iScript = 0; iScript < iScriptCount; iScript++ ) { m_pBrowser->add(vecScriptList[iScript].sTitle.c_str(), (void *) iScript); } m_pBrowser->select(iCurScript+1); // In presentations do not reset BGColor m_bKeepBGColor = true; m_bPresentationAction = true; m_pBrowserWin->set_modal(); m_pBrowserWin->show(); return; } }
void ModelViewController::SimplePrint() { if( serial->isPrinting() ) { fl_alert ("Already printing.\nCannot start printing"); } if( !serial->isConnected() ) { ConnectToPrinter(true); WaitForConnection(5.0); } Print(); }
// Load a set of features for the query image. void FeaturesDoc::load_query_features(const char *name, bool sift) { if (queryImage == NULL) { fl_alert("no query image loaded"); } else { ui->set_images(queryImage, NULL); ui->set_features(NULL, NULL); // Delete the current query image features. if (queryFeatures != NULL) { delete queryFeatures; queryFeatures = NULL; } // Delete the current result image. if (resultImage != NULL) { resultImage->release(); resultImage = NULL; } queryFeatures = new FeatureSet(); // Load the feature set. if (((!sift) && (queryFeatures->load(name))) || ((sift) && (queryFeatures->load_sift(name)))) { ui->set_features(queryFeatures, NULL); } else { delete queryFeatures; queryFeatures = NULL; fl_alert("couldn't load feature data file"); } } ui->refresh(); }
void save_tiles_truecolor(Fl_Widget*,void*){ if(!currentProject->containsData(pjHaveTiles)){ currentProject->haveMessage(pjHaveTiles); return; } if (load_file_generic("Save truecolor tiles",true)){ FILE * myfile; myfile = fopen(the_file.c_str(),"wb"); if (myfile){ fwrite(currentProject->tileC->truetDat.data(),1,(currentProject->tileC->amt)*currentProject->tileC->tcSize,myfile); fclose(myfile); }else fl_alert("Error: can not save file %s",the_file.c_str()); } }
void ImpressionistUI::cb_filter_kernel(Fl_Menu_* o, void* v) { ImpressionistDoc* pDoc=whoami(o)->getDocument(); // Need to back up the current paint view status // so we can easily preview filters //If no image has been loaded, do not open filter kernel if (pDoc->m_ucPainting != NULL) { memcpy( pDoc->m_ucPreviewBackup, pDoc->m_ucPainting, pDoc->m_nPaintWidth * pDoc->m_nPaintHeight * 3 ); whoami(o)->fltDesignUI->show(); } else fl_alert("Must load an image first!"); }
void CFLTKEditor::SaveFile(const char* pcFilename) { if (GetTextBuffer()->savefile(pcFilename)) { fl_alert("Error writing to file \'%s\':\n%s.", pcFilename, strerror(errno)); } else { GetFilename() = pcFilename; SetNameAndPath(); } IsFileChanged() = false; //SetTitle(); GetTextBuffer()->call_modify_callbacks(); }
void skeleton_new_cb( Fl_Widget* w, void* ) { static int nb_tot = 2; const char* p = fl_input( _("Number of functions (1->%d) ?"), IS::translate(nb_tot).c_str(), Skeleton::NBM - 1 ); if ( p != NULL ) { nb_tot = atoi(p); if ( 1 <= nb_tot && nb_tot <= Skeleton::NBM - 1) { glito->skel = Skeleton( nb_tot ); glito->state = PREVIEW; glito->needRedraw = true; } else { fl_alert( _("The number of functions must be between 1 and %d"), Skeleton::NBM - 1 ); } } }
void CFLTKEditor::ReplaceAll() { char *pcFind = (char *) m_pReplaceFind->value(); char *pcReplace = (char *) m_pReplaceWith->value(); if (pcFind[0] == 0) { // Search string is blank; get a new one... m_pReplaceDlg->show(); return; } m_pReplaceDlg->hide(); GetEditor()->insert_position(0); // Loop through the whole string int iFound; int iTimes = 0; do { int iPos = GetEditor()->insert_position(); iFound = GetTextBuffer()->search_forward(iPos, pcFind, &iPos); if (iFound) { // Found a match; update the position and pcReplace text... GetTextBuffer()->select(iPos, iPos + (int) strlen(pcFind)); GetTextBuffer()->remove_selection(); GetTextBuffer()->insert(iPos, pcReplace); GetEditor()->insert_position(iPos + (int) strlen(pcReplace)); GetEditor()->show_insert_position(); iTimes++; } } while (iFound); if (iTimes) { fl_message("Replaced %d occurrences.", iTimes); } else { fl_alert("No occurrences of \'%s\' found!", pcFind); } }
void GUI::importCB2(){ string filename; Fl_File_Chooser chooser(".","Valid Files (*.{surfrev,extrude,obj})",Fl_File_Chooser::SINGLE, "Open file?"); chooser.show(); while(chooser.shown()){ Fl::wait(); } if ( chooser.value() != NULL ){ filename = chooser.value(); bool load = control->addMesh(filename); if(!load){ char msg[] = "Sorry. Invalid file."; fl_alert(msg); } } view->redraw(); }
static int lua_tile_setTileRGBA(lua_State*L) { getProjectIDX const size_t tile = idxPtr[1]; if (inRangeTile(tile, projectIDX)) { uint8_t*tptr = ((uint8_t*)projects[projectIDX].tileC->truetDat.data() + (tile * projects[projectIDX].tileC->tcSize)); unsigned len = lua_rawlen(L, 2); if (!len) { fl_alert("setTileRGBA error: parameter 2 must be a table"); return 0; } fillucharFromTab(L, 2, len, projects[projectIDX].tileC->tcSize, tptr); } return 0; }