void ModelViewController::ConvertToGCode() { string GcodeTxt; Fl_Text_Buffer* buffer = gui->GCodeResult->buffer(); buffer->remove(0, buffer->length()); buffer = gui->GCodeStart->buffer(); char* pText = buffer->text(); string GCodeStart(pText); buffer = gui->GCodeLayer->buffer(); free(pText); pText = buffer->text(); string GCodeLayer(pText); buffer = gui->GCodeEnd->buffer(); free(pText); pText = buffer->text(); string GCodeEnd(pText); free(pText); ProcessControl.ConvertToGCode(GcodeTxt, GCodeStart, GCodeLayer, GCodeEnd); buffer = gui->GCodeResult->buffer(); GcodeTxt += "\0"; buffer->append( GcodeTxt.c_str() ); redraw(); }
void help_button_cb( Fl_Widget* o, void*) { const char* title = "help_dockbar.txt"; // get file content string content = ""; string line; ifstream ifs (title); if (ifs.is_open()) { while ( getline (ifs,line) ) { content += line + "\n"; } ifs.close(); } else cerr<<"Unable to open file"<<endl; // create window Fl_Window *help_win = new Fl_Window(border_space + button_size + border_space, 100, //border_space + button_size + border_space, screen_width / 2 + 10, screen_height / 4 + 10 , title); Fl_Text_Display *help_display = new Fl_Text_Display( 5,5, screen_width / 2 , screen_height / 4 ); Fl_Text_Buffer *buff = new Fl_Text_Buffer(); buff->append(content.c_str() ); // add content to buffer help_display->buffer(buff); // register buffer help_win->add(help_display); help_win->show(); }
void Runner::RunProtected() { SPADES_MARK_FUNCTION(); std::string err; try{ Run(); }catch(const spades::Exception& ex){ err = ex.GetShortMessage(); SPLog("Unhandled exception in SDLRunner:\n%s", ex.what()); }catch(const std::exception& ex){ err = ex.what(); SPLog("Unhandled exception in SDLRunner:\n%s", ex.what()); } if(!err.empty()){ ErrorDialog dlg; dlg.set_modal(); dlg.result = 0; // TODO: free this buffer (just leaking) Fl_Text_Buffer *buf = new Fl_Text_Buffer; buf->append(err.c_str()); dlg.infoView->wrap_mode(Fl_Text_Display::WRAP_AT_BOUNDS, 0); dlg.infoView->buffer(buf); dlg.helpView->value("See SystemMessages.log for more details."); dlg.show(); while(dlg.visible()){ Fl::wait(); } } }
static void describe_in_editor_cb(Fl_Widget*, void *s) { ObjectTree *self = (ObjectTree*)s; Fl_Tree_Item *titem = self->first_selected_item(); if(!titem || !titem->user_data()) return; Entity *en = (Entity*)titem->user_data(); Fl_Text_Buffer *ebuf = self->get_editor_buffer(); E_RETURN_IF_FAIL(ebuf != NULL); char buf[EDELIB_DBUS_EXPLORER_DEFAULT_SCRIPT_EVAL_BUFSIZE]; ebuf->append("\n;; "); if(en->get_prototype(buf, sizeof(buf))) ebuf->append(buf); ebuf->append("\n"); }
/* ========================================================================= Checks for errors and updates icon. ========================================================================= */ void VTLpt::ShowErrors(void) { int c, count; if (m_pActivePrinter == NULL) return; count = m_pActivePrinter->GetErrorCount(); if (count == 1) { fl_message("%s", (const char *) m_pActivePrinter->GetError(0)); } else { Fl_Text_Buffer* tb = new Fl_Text_Buffer(); for (c = 0; c < count; c++) { tb->append(m_pActivePrinter->GetError(c)); tb->append("\n"); } Fl_Window* o = new Fl_Window(500, 300, "Printer Errors"); Fl_Text_Display* td = new Fl_Text_Display(0, 0, 500, 300, ""); td->buffer(tb); o->show(); } // Clear the errors m_pActivePrinter->ClearErrors(); // Set the icon back to normal gpPrint->set_image(&gPrinterIcon); gpPrint->label("Idle"); m_PortStatus = LPT_STATUS_IDLE; gPrintMenu[3].flags = FL_MENU_INVISIBLE; gAnimationNeeded = FALSE; m_animIconIndex = 1; // Report port status change if (m_pMonCallback != NULL) m_pMonCallback(LPT_MON_PORT_STATUS_CHANGE, 0); }
//lm: this doesnt really belong here, should be somewhere in core or client probably? // we might need to introduce some base object that will handle global state and whatnot.. // now all windows just spawn eachother, instead of being managed from a central place. void MainWindow::StartGame(const spades::ServerAddress &host) { SPADES_MARK_FUNCTION(); //hide(); #if 0 SDLRunner r(host); r.Run(); #else std::string err; try{ if(cg_smp){ SDLAsyncRunner r(host, cg_playerName); r.Run(); }else{ SDLRunner r(host, cg_playerName); r.Run(); } }catch(const spades::Exception& ex){ err = ex.GetShortMessage(); SPLog("Unhandled exception in SDLRunner:\n%s", ex.what()); }catch(const std::exception& ex){ err = ex.what(); SPLog("Unhandled exception in SDLRunner:\n%s", ex.what()); } if(!err.empty()){ ErrorDialog dlg; dlg.set_modal(); dlg.result = 0; // TODO: free this buffer (just leaking) Fl_Text_Buffer *buf = new Fl_Text_Buffer; buf->append(err.c_str()); dlg.infoView->wrap_mode(Fl_Text_Display::WRAP_AT_BOUNDS, 0); dlg.infoView->buffer(buf); dlg.helpView->value("See SystemMessages.log for more details."); dlg.show(); while(dlg.visible()){ Fl::wait(); } if( dlg.result == 1 ){ //show(); } } #endif }
void notify_cb(const char* dir, const char* wh, int flag, void* l) { Fl_Text_Buffer* tl = (Fl_Text_Buffer*)l; if(wh) { snprintf(write_buff, 256, "In %s, %s was ", dir, wh); tl->append(write_buff); if(flag == DW_REPORT_CREATE) tl->append("created\n"); else if(flag == DW_REPORT_DELETE) tl->append("deleted\n"); else if(flag == DW_REPORT_MODIFY) tl->append("modified\n"); else tl->append("unknown\n"); } else { snprintf(write_buff, 256, "In %s changed (null!!)\n", dir); tl->append(write_buff); } }
void Line::draw() { //DrawingAlgorithms::BresenhamLine(xs, ys, xe, ye, lineThickness, lineStyle, rgba, textDisplay, print); /* Prepare OpenGL */ /* Set Line Thickness */ glPointSize(lineThickness); /* Set Draw Color */ glColor4f(rgba.red, rgba.green, rgba.blue, rgba.alpha); glBegin(GL_POINTS); /* OpenGL Ready. Draw Bresenham */ /* Bresenham's Algorithm */ // Get all static values int deltaX = abs(xe - xs); int deltaY = abs(ye - ys); bool steep = deltaY > deltaX; bool negativeY = (ye - ys) < 0; bool negativeX = (xe - xs) < 0; // Get all conditional values int update0, update1, d; // If the line is steep the decision // is between N and NE pixel as opposed // to the E and NE pixel. // The initial decision variable should // reflect this as well. if( steep ) { update0 = deltaX<<1; update1 = (deltaX<<1) - (deltaY<<1); d = (deltaX<<1) - deltaY; } else { update0 = deltaY<<1; update1 = (deltaY<<1) - (deltaX<<1); d = (deltaY<<1) - deltaX; } // Get looping variables // If the line is steep, swap x and y // so the decision is between N and NE // pixels as opposed to E and NE int x = (steep ? ys : xs); int y = (steep ? xs : ys); /* Print Variables */ Fl_Text_Buffer * textBuffer = NULL; if( print ) { textBuffer = textDisplay->buffer(); textBuffer->append("Line: "); } /* Create Draw Mask */ LineStyle::DrawMask* p_DrawMask = LineStyle::getDrawMask(lineStyle); int *drawMask = p_DrawMask->drawMask; int drawMaskSize = p_DrawMask->drawMaskSize; int drawMaskIndex = 0; // Loop int steps = (steep ? deltaY : deltaX ); for( int i = 0 ; i < steps ; i++ ) { // If the line is steep, then x and y // have been swapped. This must be accounted // for before drawing anything. if( steep ) { // If print is set to True... if( print && textBuffer != NULL) { std::stringstream ostream; ostream << "(" << y << "," << x << ") "; textBuffer->append(ostream.str().c_str()); } // Draw the pixel if( drawMask[drawMaskIndex] ) glVertex2i(y,x); drawMaskIndex = (++drawMaskIndex)%drawMaskSize; // x and y were swapped, so check the // correct negative flag x = (negativeY ? x-1 : x+1); } else { // If print is set to True... if( print && textBuffer != NULL) { std::stringstream ostream; ostream << "(" << x << "," << y << ") "; textBuffer->append(ostream.str().c_str()); } // Draw the pixel if( drawMask[drawMaskIndex] ) glVertex2i(x,y); drawMaskIndex = (++drawMaskIndex)%drawMaskSize; // Inc or Dec x depending on direction of drawing x = (negativeX ? x-1 : x+1); } // If d is negative, then next pixel to // fill in is East (generically speaking) // otherwise, North East. if( d < 0 ) { d+=update0; } else { // x and y were swapped so check the // correct negative flag if( steep ) { y = (negativeX ? y-1 : y+1); } else { y = (negativeY ? y-1 : y+1); } d+=update1; } } // Print the final value if( steep ) glVertex2i(y,x); else glVertex2i(x,y); if( print && textBuffer != NULL) { std::stringstream ostream; if( steep) { ostream << "(" << y << "," << x << ")\n"; } else { ostream << "(" << x << "," << y << ")\n"; } textBuffer->append(ostream.str().c_str()); } /* Free LineMask */ free(drawMask); free(p_DrawMask); /* End Bresenham */ glEnd(); /* Reset Color */ glColor4f(1,1,1,1); /* Reset Pixel Size */ glPointSize(1); glPointSize(1.0); }
void populate_psg(int pid_no) { rapidxml::xml_node<> *passage_data=node->first_node(); char cur_img_file_name[16]; int cur_pid=atoi(get_attr_value(passage_data,"pid")); if(cur_pid<pid_no) { while(cur_pid!=pid_no) { passage_data=passage_data->next_sibling(); cur_pid=atoi(get_attr_value(passage_data,"pid")); } } else if(cur_pid>pid_no) { while(cur_pid!=pid_no) { passage_data=passage_data->previous_sibling(); cur_pid=atoi(get_attr_value(passage_data,"pid")); } } pid=pid_no; //so at this point i should have the right pid char temp[4]; sprintf(temp,"%d",(pid+1)); // as the pids go from 0 to n while we count from 1 to n+1 p_no->value(temp); rapidxml::xml_node<> *p_data=passage_data->first_node(); Fl_Text_Buffer* buf; buf=new Fl_Text_Buffer(); buf->text(get_attr_value(p_data,"txt")); unsigned char *pixels; int w,h; gen_random(cur_img_file_name,10); char *file_path=NULL; file_path = (char*)malloc((strlen(current_path)+16)*sizeof(char)); strcpy(file_path,current_path); strcat(file_path,"line_no.gif"); #ifdef __APPLE__ pixels = stbi_load(file_path, &w, &h, 0, 3); #else pixels = stbi_load("line_no.gif", &w, &h, 0, 3); #endif if (pixels == 0) { fprintf(stderr, "Couldn't open input file '%s'\n", "line_no.gif"); exit(1); } strcpy(file_path,current_path); strcat(file_path,cur_img_file_name); #ifdef __APPLE__ stbi_write_png(file_path, w, (int)(buf->length()/1.6), 3, pixels, w*3); #else stbi_write_png(cur_img_file_name, w, (int)(buf->length()/1.6), 3, pixels, w*3); #endif buf->text("<body><table width='378' cellspacing=0 cellpadding=0 border=0><tr><td width='100' valign='top'><img src='"); #ifdef __APPLE__ buf->append(file_path); #else buf->append(cur_img_file_name); #endif buf->append("'></td><td><font face='courier' size=5>"); buf->append(get_attr_value(p_data,"txt")); buf->append("</font></p></td></tr></table><table>"); p->value(buf->text()); //free(questions); questions=p_data->next_sibling(); rapidxml::xml_node<> *temp_node=questions->last_node(); totalq=atoi(get_attr_value(temp_node,"qid")); cur_progress *o1 = (cur_progress*)obj_progress; free(o1->circle_data); o1->circle_data = (int*)malloc((totalq+1)*sizeof(int)); for(int i=0;i<=totalq;i++) //1 = wrong, 2=right, 3=not asked o1->circle_data[i]=3; o1->num_circles=totalq+1; o1->redraw(); populate_question(0); count_sec=0; count_min=0; enable_timer=1; #ifdef __APPLE__ unlink(file_path); #else unlink(cur_img_file_name); #endif }
void populate_question(int qid_no) { rapidxml::xml_node<> *question_data=questions->first_node(); int c=atoi(get_attr_value(question_data,"qid")); if(c<qid_no) { while(c!=qid_no) { question_data=question_data->next_sibling(); c=atoi(get_attr_value(question_data,"qid")); } } else if(c>qid_no) { while(c!=qid_no) { question_data=question_data->previous_sibling(); c=atoi(get_attr_value(question_data,"qid")); } } cur_qid=qid_no; //at this point we are at the right question //printf("%s",get_attr_value(question_data,"qid")); rapidxml::xml_node<> *q_data=question_data->first_node(); //printf("%s",get_attr_value(q_data,"txt")); Fl_Text_Buffer* buf; buf=new Fl_Text_Buffer(); char options[6]= {'A','B','C','D','E'}; char temp[16]; buf->text("<p><font face='courier' size=5>"); buf->append(get_attr_value(q_data,"txt")); buf->append("</font></p><table border='0' cellspacing='0' cellpadding='0'>"); rapidxml::xml_node<> *answer=q_data->next_sibling(); q_data=q_data->next_sibling(); srand (time(NULL)); cur_ans=rand() % 5; //printf("%d ",cur_ans); for(int i=0; i<5; i++) { if(i!=cur_ans) { q_data=q_data->next_sibling(); buf->append("<tr><td width='20' valign='top'><font face='courier' size=5><b>"); sprintf(temp,"%c",options[i]); buf->append(temp); buf->append(".</b></font></td><td width='365' valign='top'><font face='courier' size=5>"); buf->append(get_attr_value(q_data,"txt")); buf->append("</font></td></tr>"); } else { buf->append("<tr><td width='20' valign='top'><font face='courier' size=5><b>"); sprintf(temp,"%c",options[i]); buf->append(temp); buf->append(".</b></font></td><td width='365' valign='top'><font face='courier' size=5>"); buf->append(get_attr_value(answer,"txt")); buf->append("</font></td></tr>"); } } buf->append("</table>"); q->value(buf->text()); disable_buttons(0); nxt_question->deactivate(); enable_timer=1; }
void check_answer(int usr_ans) { rapidxml::xml_node<> *question_data=questions->first_node(); int c=atoi(get_attr_value(question_data,"qid")); if(c<cur_qid) { while(c!=cur_qid) { question_data=question_data->next_sibling(); c=atoi(get_attr_value(question_data,"qid")); } } else if(c>cur_qid) { while(c!=cur_qid) { question_data=question_data->previous_sibling(); c=atoi(get_attr_value(question_data,"qid")); } } //at this point we are at the right question //printf("%s",get_attr_value(question_data,"qid")); rapidxml::xml_node<> *q_data=question_data->first_node(); //printf("%s",get_attr_value(q_data,"txt")); Fl_Text_Buffer* buf; buf=new Fl_Text_Buffer(); char options[6]= {'A','B','C','D','E'}; char temp[16]; buf->text("<p><font face='courier' size=5>"); buf->append(get_attr_value(q_data,"txt")); buf->append("</font></p><table border='0' cellspacing='0' cellpadding='0'>"); rapidxml::xml_node<> *answer=q_data->next_sibling(); q_data=q_data->next_sibling(); //printf("%d=",cur_qid); for(int i=0; i<5; i++) { if(i!=cur_ans) { q_data=q_data->next_sibling(); if(i!=usr_ans) { buf->append("<tr><td width='20' valign='top'><font face='courier' size=5><b>"); sprintf(temp,"%c",options[i]); buf->append(temp); buf->append(".</b></font></td><td width='365' valign='top'><font face='courier' size='5'>"); buf->append(get_attr_value(q_data,"txt")); buf->append("</font></td></tr>"); } else { buf->append("<tr><td width='20' valign='top' bgcolor='#ff6666'><font face='courier' size=5><b>"); sprintf(temp,"%c",options[i]); buf->append(temp); buf->append(".</b></font></td><td width='365' valign='top' bgcolor='#ff6666'><font face='courier' size='5'>"); buf->append(get_attr_value(q_data,"txt")); buf->append("</font></td></tr>"); } } else { buf->append("<tr><td width='20' valign='top' bgcolor='#66ff66'><font face='courier' size=5><b>"); sprintf(temp,"%c",options[i]); buf->append(temp); buf->append(".</b></font></td><td width='365' valign='top' bgcolor='#66ff66'><font face='courier' size='5'>"); buf->append(get_attr_value(answer,"txt")); buf->append("</font></td></tr>"); } } buf->append("</table>"); cur_progress *o1 = (cur_progress*)obj_progress; Fl_Text_Buffer* buf1; buf1=new Fl_Text_Buffer(); if(usr_ans==cur_ans) { buf1->text("<body><center><font face='courier' size='5' color='#009900'><b>✔ Correct answer</b></font></center></body>"); o1->circle_data[cur_qid]=2; } else { buf1->text("<body><center><font face='courier' size='5' color='#cc3300'><b>✖ Incorrect. Correct answer is "); sprintf(temp,"%c",options[cur_ans]); buf1->append(temp); buf1->append("</b></font></center></body>"); o1->circle_data[cur_qid]=1; } info_box->value(buf1->text()); //o1->circle_data=cur_answers; //1 = wrong, 2=right, 3=not asked o1->redraw(); q->value(buf->text()); disable_buttons(1); nxt_question->activate(); nxt_question->take_focus(); enable_timer=0; }