Пример #1
0
static void Timer_CB(void *data)                // timer callback
{
    if(enable_timer==1)
    {
        Fl_Text_Buffer* buf;
        buf=new Fl_Text_Buffer();

        char text[1024];
        if(count_min<=0)
            sprintf(text,"Time elapsed : %d Secs",count_sec);
        else
        {
            if(count_min==1)
                sprintf(text,"Time elapsed : %d min , %d Secs",count_min,count_sec);
            else
                sprintf(text,"Time elapsed : %d mins , %d Secs",count_min,count_sec);
        }

        buf->text(text);
        count_sec=count_sec+1;
        if(count_sec>=60)
        {
            count_sec=0;
            count_min=count_min+1;
        }
        clock1->buffer(buf);
    }
    Fl::repeat_timeout(1, Timer_CB, data);
    //}
}
Пример #2
0
void create_about_tab(int x, int y, int w, int h)
{
  int              border;
  Fl_Text_Display *ptext;
  Fl_Text_Buffer  *pbuff;

  Fl_Group *group1 = new Fl_Group(x, y, w, h, "About");
  {
    border = 10;
    ptext = new Fl_Text_Display(x + border, y + border, w - 3 * border, h - 3 * border);
    pbuff = new Fl_Text_Buffer();
    ptext->buffer(pbuff);
    ptext->textcolor(fl_rgb_color(85, 170, 255));
    ptext->color(fl_rgb_color(8, 7, 5));
    pbuff->text("\n"
		" BMS manager Feb 2016.\n"
		" Part of SombreroBMS (battery management system)\n"
		" Copyright 2016 Patrick Xavier Areny\n"
		"\n"
		"\n"
		" Used libraries:\n"
		"\n"
		"  Tinyxml    \tLee Thomason\n"
		"  FLTK       \twww.fltk.org\n"
		"  OpenGl     \tKhronos group\n"
		"\n"
		"\n"
		" Used font: "
		"\n"
		"\n"
		" VeraMono ttf, Bitstream, Inc.\n"
		"\n");
  }
  group1->end();
}
Пример #3
0
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();
}
Пример #4
0
		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();
				}
			}
		}
Пример #5
0
void text_editor::cb_save(Fl_Widget *widget, void *v)
{
	extern std::list<std::string> whitelist;

	text_editor *editor = (text_editor*)v;
	Fl_Text_Buffer *buffer = editor->buffer;
	
	int buff_length = buffer->length();
	int buff_lines = buffer->count_lines(0, buff_length);
	
	if (buff_lines > 0)
	{
		int pos = 0;
		whitelist.clear();
		
		for (int i = 0; i <= buff_lines; i++)
		{
			char* line_text = buffer->line_text(pos);
			std::string line(line_text);
			free(line_text);

			if(line.length() > 3)
				whitelist.push_back(line);

			pos = min(buffer->line_end(pos) + 1, buff_length);
		}
	}

	editor->hide();
}
Пример #6
0
int main(int argc, char **argv)
{
    //Fl::get_system_colors();

	Fl::background(0xEE,0xEE,0xEE);
	Fl::background2(0xFF,0xFF,0xFF);

	Fl::scheme("gtk+");

    CrashHandlerDlg dlg;
    Fl_Double_Window* window = dlg.create_window();

    dlg.stack_output->buffer(&buffer);

#ifndef _WIN32
    std::string path = getenv("HOME");
    path += "/.neoeditor/logfile.txt";

    buffer.loadfile(path.c_str());
#else
    std::string path = getenv("APPDATA");
    path += "\\neoeditor\\logfile.txt";

    buffer.loadfile(path.c_str());
#endif
    window->show();
    return Fl::run();
}
Пример #7
0
void ModelViewController::GetCustomButtonText(int nr)
{
	string Text = ProcessControl.CustomButtonGcode[nr];

	Fl_Text_Buffer* buffer = gui->CustomButtonText->buffer();
	buffer->text(Text.c_str());
	gui->CustomButtonLabel->value(ProcessControl.CustomButtonLabel[nr].c_str());
	Fl::check();
}
Пример #8
0
InfoWindow::InfoWindow(int W, int H, const char *l) : rkWindow(W,H,l)
{
	begin();
	display = new Fl_Text_Display(INFO_MARGIN,INFO_MARGIN,W-(INFO_MARGIN*3),H-INFO_MARGIN*3,0);
	display->wrap_mode(3,0);
	Fl_Text_Buffer *b = new Fl_Text_Buffer();
	b->insert(0, InfoWindow::info);
	display->buffer(b);
	end();
}
Пример #9
0
/*************************************************************************************
** Function: putChordInTextBox
** Description: Create current scale and write it to fullscale c string, pass
**				fullscale to buffer and print to display text box.
*************************************************************************************/
void putChordInTextBox(Fl_Widget * o, void *v){
	//Get the chord based on the chord meu and chord root menu selections
	//using the ScaleWindow's scale object
	((ScaleWindow*)v)->getChord(((ScaleWindow*)v)->chordMenu->value(), ((ScaleWindow*)v)->chordRootMenu->value());
	//Prepare the text with fullscale c-string and the buffer
	Fl_Text_Buffer *buffer = new Fl_Text_Buffer();
	buffer->text(((ScaleWindow *)v)->fullscale);
	//Print the buffer
	((ScaleWindow*)v)->out->buffer(buffer);
}
static void
serial_handler(
	int			fd,
	void *			user_arg
)
{

	char			line[ 256 ];
	int			    len;

    if (serial_fd==0) 
        return;

	if( !read_char_line( serial_fd, line, sizeof(line) ) )
	{
		perror( "read_char" );
		return;
	}

	len = strlen( line );
	line[len++] = '\n';
	line[len] = '\0';

    if (gui->pause_raw_output->value()!=1) {
        gui->raw_serial_output->insert(line);
        Fl_Text_Buffer *textBuffer = gui->raw_serial_output->buffer();
        int numLines = textBuffer->count_lines(0, textBuffer->length());
        gui->raw_serial_output->scroll(numLines, 0);

        // ugly way to keep the buffer from growing unchecked
        if (numLines > 1000) {
            textBuffer->remove(0, (textBuffer->length()-100));
        }
    }

	if( strncmp( line, "$GPADC", 6 ) == 0 )
	{
	    imu_samples++;
        update_adc(line);
	} else

	if( strncmp( line, "$GPPPM", 6 ) == 0 )
	{
        update_ppm(line);
	} else

    {
		// Ignore the line for now
	}

}
Пример #11
0
/*************************************************************************************
** Function: putScaleInTextBox
** Description: Create current scale and write it to fullscale c string, pass
**				fullscale to buffer and print to display text box.
*************************************************************************************/
void putScaleInTextBox(Fl_Widget * o, void *v){
	//Get the scale using the ScaleWindow's scale object
	((ScaleWindow*)v)->getScale(((ScaleWindow*)v)->modeMenu->value(), ((ScaleWindow*)v)->rootMenu->value());
	//Get a buffer so we can print in the display box
	Fl_Text_Buffer *buffer = new Fl_Text_Buffer();
	//Set the buffer to use the fullscale char string
	buffer->text(((ScaleWindow *)v)->fullscale);
	//Print the buffer
	((ScaleWindow*)v)->out->buffer(buffer);
	//Reset the chrord root menu and chord menu selections to zero
	((ScaleWindow*)v)->chordRootMenu->value(0);	
	((ScaleWindow*)v)->chordMenu->value(0);
	((ScaleWindow*)v)->scale.clearCurrentChord();
}
Пример #12
0
static void send_to_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];
	if(en->get_prototype_as_scheme(buf, sizeof(buf)))
		ebuf->append(buf);
}
Пример #13
0
void ModelViewController::SaveCustomButton()
{
	int ButtonNr = gui->CustomButtonSelectorSlider->value()-1;

	Fl_Text_Buffer* buffer = gui->CustomButtonText->buffer();
	char* pText = buffer->text();
	string Text = string(pText);
	free(pText);
	ProcessControl.CustomButtonGcode[ButtonNr] = Text;

	const char* text = gui->CustomButtonLabel->value();
	string label(text);
	ProcessControl.CustomButtonLabel[ButtonNr] = label;

	RefreshCustomButtonLabels();
}
//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
}
Пример #15
0
void ModelViewController::init()
{

	Fl_Text_Buffer* buffer = gui->GCodeStart->buffer();
	buffer->text(ProcessControl.GCodeStartText.c_str());
	buffer = gui->GCodeLayer->buffer();
	buffer->text(ProcessControl.GCodeLayerText.c_str());
	buffer = gui->GCodeEnd->buffer();
	buffer->text(ProcessControl.GCodeEndText.c_str());
    //buffer->text(ProcessControl.Notes.c_str());

	buffer = gui->LuaScriptEditor->buffer();
	buffer->text("--Clear existing gcode\nbase:ClearGcode()\n-- Set start speed for acceleration firmware\nbase:AddText(\"G1 F2600\\n\")\n\n	 z=0.0\n	 e=0;\n	oldx = 0;\n	oldy=0;\n	while(z<47) do\n	angle=0\n		while (angle < math.pi*2) do\n	x=(50*math.cos(z/30)*math.sin(angle))+70\n		y=(50*math.cos(z/30)*math.cos(angle))+70\n\n		--how much to extrude\n\n		dx=oldx-x\n		dy=oldy-y\n		if not (angle==0) then\n			e = e+math.sqrt(dx*dx+dy*dy)\n			end\n\n			-- Make gcode string\n\n			s=string.format(\"G1 X%f Y%f Z%f F2600 E%f\\n\", x,y,z,e)\n			if(angle == 0) then\n				s=string.format(\"G1 X%f Y%f Z%f F2600 E%f\\n\", x,y,z,e)\n				end\n				-- Add gcode to gcode result\nbase:AddText(s)\n	 angle=angle+0.2\n	 oldx=x\n	 oldy=y\n	 end\n	 z=z+0.4\n	 end\n	 ");

	//	buffer = gui->CommunationsLogText->buffer();
//	buffer->text("Dump");
}
Пример #16
0
void ModelViewController::WriteGCode (string filename)
{
  Fl_Text_Buffer* buffer = gui->GCodeResult->buffer();
  int result = buffer->savefile (filename.c_str());

  switch (result)
    {
    case 0: // Succes
      break;
    case 1: // Open for write failed
      fl_alert ("Error saving GCode file, error creating file.");
      break;
    case 2: // Partially saved file
      fl_alert ("Error saving GCode file, while writing file, is the disk full?.");
      break;
    }
}
Пример #17
0
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();
}
Пример #18
0
void ProcessController::SaveBuffers()
{
	Fl_Text_Buffer* buffer = gui->GCodeStart->buffer();
	char* pText = buffer->text();
	GCodeStartText = string(pText);
	free(pText);

	buffer = gui->GCodeLayer->buffer();
	pText = buffer->text();
	GCodeLayerText = string(pText);
	free(pText);

	buffer = gui->GCodeEnd->buffer();
	pText = buffer->text();
	GCodeEndText = string(pText);
	free(pText);

	AltInfillLayersText = string(gui->AltInfillLayersInput->value());
}
Пример #19
0
/*
=========================================================================
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);
}
Пример #20
0
void CFLTKEditor::Paste()
{
	string sText, sNewText;
	int iInsStart = 0, iInsEnd = 0;
	Fl_Text_Editor *pEditor = GetEditor();
	Fl_Text_Buffer *pBuffer = pEditor->buffer();

	pBuffer->selection_position(&iInsStart, &iInsEnd);
	if (iInsStart == iInsEnd)
	{
		iInsStart = pEditor->insert_position();
		Fl_Text_Editor::kf_paste(0, pEditor);
		iInsEnd = pEditor->insert_position();
	}
	else
	{
		Fl_Text_Editor::kf_paste(0, pEditor);
		iInsEnd = pEditor->insert_position();
	}

	pBuffer->select(iInsStart, iInsEnd);
	sText = pBuffer->selection_text();

	if (AdaptText(sNewText, sText))
	{
		pBuffer->replace_selection(sNewText.c_str());
	}
	pBuffer->unselect();
}
Пример #21
0
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();
}
Пример #22
0
void CFLTKEditor::Indent()
{
	bool bChangedBuffer = false;
	int iSelStart = 0, iSelEnd = 0, iCurPos = 0;
	Fl_Text_Buffer *pcBuffer = GetTextBuffer();

	pcBuffer->selection_position(&iSelStart, &iSelEnd);
	if (iSelEnd <= iSelStart)
		return;

	iCurPos = pcBuffer->line_start(iSelStart);
	while (pcBuffer->line_end(iCurPos) < iSelEnd)
	{
		bChangedBuffer = true;
		pcBuffer->insert(iCurPos, "\t");
		iCurPos = pcBuffer->skip_lines(iCurPos, 1);
		++iSelEnd;
	}

	if (bChangedBuffer)
		pcBuffer->select(pcBuffer->line_start(iSelStart), iSelEnd);
}
Пример #23
0
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);
	}
}
Пример #24
0
void CFLTKEditor::UnIndent()
{
	bool bChangedBuffer = false;
	int iSelStart = 0, iSelEnd = 0, iCurPos = 0, iTabSize, i;
	char *pcLine;
	Fl_Text_Buffer *pBuffer = GetTextBuffer();

	pBuffer->selection_position(&iSelStart, &iSelEnd);
	if (iSelEnd > iSelStart)
	{
		iCurPos = pBuffer->line_start(iSelStart);
		iTabSize = pBuffer->tab_distance();

		while (pBuffer->line_end(iCurPos) < iSelEnd)
		{
			pcLine = pBuffer->line_text(iCurPos);
			if (pcLine[0] == '\t')
			{
				bChangedBuffer = true;
				pBuffer->remove(iCurPos, iCurPos+1);
				--iSelEnd;
			}
			else if (pcLine[0] == ' ')
			{
				for (i = 1; i < iTabSize; i++)
				{
					if (pcLine[i] != ' ')
						break;
				}

				if (i == iTabSize) // same number of spaces as a tab
				{
					bChangedBuffer = true;
					pBuffer->remove(iCurPos, iCurPos + iTabSize);
					iSelEnd -= iTabSize;
				}
			}
			iCurPos = pBuffer->skip_lines(iCurPos, 1);
			free(pcLine);
		}

		if (bChangedBuffer)
			pBuffer->select(pBuffer->line_start(iSelStart), iSelEnd);
	}
}
Пример #25
0
/*************************************************************************************
** Function: showProgression
** Description: This function gets the current chord progression and displays it
**				in the text display box
*************************************************************************************/
void ScaleWindow::showProgression(){

	//If the current chord is empty, we have a problem. Abort!
	if(scale.isCurrentChordEmpty() == true){
		printErrorInProgression();	
		return;
	}

	//Get a buffer for printing later and vector to hold the progression
	Fl_Text_Buffer *buffer = new Fl_Text_Buffer();
	std::vector<std::vector<std::string> > prog;

	//Get the progression!
	prog = scale.getProgression();

	//Create and initialize a c-string for printing
	char progChar[2000];
	for(int i = 0; i < 2000; i++)
		progChar[i] = '\0';

	//Find how many notes the chord with the most notes has
	int pos = 0;
	int max = 0; 
	for(int i = 0; i < prog.size(); i++){
		if(prog[i].size() > max) max = prog[i].size();
	}

	//Loop through the progression, getting the first, second, third, etc.
	//note in each chord and printing them row by row.
	//So the first note from each chord is printed in the first row,
	//then the second notes in the second row, etc.
	int x = 0;
	while(x < max){
		for(int i = 0; i < prog.size(); i++){
			int curLen = 0;
			if(x < prog[i].size()){
				curLen = prog[i][x].length();
				for(int j = 0; j < curLen; j++){
					progChar[pos] = prog[i][x][j];
					pos++;
				}
			}
			//If the corresponding chord has less than the max
			//number of notes, just print a space for it
			else{
				progChar[pos] = ' ';
				pos++;
				curLen = 1;
			}
			//Pad with white space!
			while(curLen < 4){
				progChar[pos] = ' ';
				pos++;
				curLen++;
			}
		}
		progChar[pos] = '\n';
		pos++;
		x++;
	}

	//Print the progression!
	buffer->text(progChar);
	outProg->buffer(buffer);

}
Пример #26
0
static void
style_update(int		pos,			// I - Position of update
			 int		nInserted,		// I - Number of inserted chars
			 int		nDeleted,		// I - Number of deleted chars
			 int		/*nRestyled*/,	// I - Number of restyled chars
			 const char * /*deletedText*/,// I - Text that was deleted
			 void		*cbArg) {		// I - Callback data
  int	start,							// Start of text
		end;							// End of text
  char	last,							// Last style on line
		*style,							// Style data
		*text;							// Text data

  SchemeEditor *editor = (SchemeEditor*)cbArg;
  Fl_Text_Buffer *textbuf = editor->buffer();
  Fl_Text_Buffer *stylebuf = editor->style_buffer();

  // If this is just a selection change, just unselect the style buffer...
  if (nInserted == 0 && nDeleted == 0) {
	stylebuf->unselect();
	return;
  }

  // Track changes in the text buffer...
  if (nInserted > 0) {
	// Insert characters into the style buffer...
	style = new char[nInserted + 1];
	memset(style, 'A', nInserted);
	style[nInserted] = '\0';

	stylebuf->replace(pos, pos + nDeleted, style);
	delete[] style;
  } else {
	// Just delete characters in the style buffer...
	stylebuf->remove(pos, pos + nDeleted);
  }

  // Select the area that was just updated to avoid unnecessary
  // callbacks...
  stylebuf->select(pos, pos + nInserted - nDeleted);

  // Re-parse the changed region; we do this by parsing from the
  // beginning of the previous line of the changed region to the end of
  // the line of the changed region...	Then we check the last
  // style character and keep updating if we have a multi-line
  // comment character...
  start = textbuf->line_start(pos);
//	if (start > 0) start = textbuf->line_start(start - 1);
  end	= textbuf->line_end(pos + nInserted);
  text	= textbuf->text_range(start, end);
  style = stylebuf->text_range(start, end);
  if (start==end)
	last = 0;
  else
	last  = style[end - start - 1];

//	printf("start = %d, end = %d, text = \"%s\", style = \"%s\", last='%c'...\n",
//		   start, end, text, style, last);

  style_parse(text, style, end - start);

//	printf("new style = \"%s\", new last='%c'...\n",
//		   style, style[end - start - 1]);

  stylebuf->replace(start, end, style);
  editor->redisplay_range(start, end);

  if (start==end || last != style[end - start - 1]) {
//	  printf("Recalculate the rest of the buffer style\n");
	// Either the user deleted some text, or the last character
	// on the line changed styles, so reparse the
	// remainder of the buffer...
	free(text);
	free(style);

	end	  = textbuf->length();
	text  = textbuf->text_range(start, end);
	style = stylebuf->text_range(start, end);

	style_parse(text, style, end - start);

	stylebuf->replace(start, end, style);
	editor->redisplay_range(start, end);
  }

  free(text);
  free(style);
}
Пример #27
0
/*************************************************************************************
** Function: printErrorInProgression
** Description: This function is called when there's an error in adding a chord
**				to the chord progression. It adds an error message to the output
**				c-string which is printed in the text display
*************************************************************************************/
void ScaleWindow::printErrorInProgression(){
	//Create a buffer to printing
	Fl_Text_Buffer *buffer = new Fl_Text_Buffer();

	//Get the current progression so we can add it to the c-string
	//before addiging the error message
	std::vector<std::vector<std::string> > prog;
	prog = scale.getProgression();

	//Clear c-string
	char progChar[2000];
	for(int i = 0; i < 2000; i++)
		progChar[i] = '\0';

	//Find out which chord in the progression has the most notes
	//in it (since we're printing them vertically)
	int pos = 0;
	int max = 0; 
	for(int i = 0; i < prog.size(); i++){
		if(prog[i].size() > max) max = prog[i].size();
	}

	//Loop through the progression, getting the first, second, third, etc.
	//note in each chord and printing them row by row.
	//So the first note from each chord is printed in the first row,
	//then the second notes in the second row, etc.
	int x = 0;
	while(x < max){
		for(int i = 0; i < prog.size(); i++){
			int curLen = 0;
			if(x < prog[i].size()){
				curLen = prog[i][x].length();
				for(int j = 0; j < curLen; j++){
					progChar[pos] = prog[i][x][j];
					pos++;
				}
			}
			//If the corresponding chord has less than the max
			//number of notes, just print a space for it
			else{
				progChar[pos] = ' ';
				pos++;
				curLen = 1;
			}
			//Pad it out with white space
			while(curLen < 4){
				progChar[pos] = ' ';
				pos++;
				curLen++;
			}
		}
		//Add a new line at the end of each row
		progChar[pos] = '\n';
		pos++;
		x++;
	}

	//Error message to add to the c-string
	std::string errorMessage = "You must select a chord before adding to progression.";

	//Add the message!
	for(int i = 0; i < errorMessage.length(); i++){
		progChar[pos] = errorMessage[i];
		pos++;
	}

	//Print everything
	buffer->text(progChar);
	outProg->buffer(buffer);
}
Пример #28
0
int main(int argc, char *argv[])
{
	// example: Repsnapper.exe --no-gui -i Input.stl -o Output.gcode -s Settings.xml
	RepSnapper::CommandLineOptions options;
	for (int i = 1; i < argc; i++)
	{
		if (strcmp(argv[i], "--no-gui") == 0)
		{
			options.use_gui = false;
		}
		else if (strcmp(argv[i], "-i") == 0 && i + 1 < argc)
		{
			options.stl_input_path = argv[i+1];
			i++;
		}
		else if (strcmp(argv[i], "-o") == 0 && i + 1 < argc)
		{
			options.gcode_output_path = argv[i+1];
			i++;
		}
		else if (strcmp(argv[i], "-s") == 0 && i + 1 < argc)
		{
			options.settings_path = argv[i+1];
			i++;
		}
	}
	
	gui = new GUI();
	MVC = gui->MVC;
	Fl::visual(FL_DOUBLE|FL_INDEX);

	char WindowTitle[100] = "GCodeView";
	char* W = &WindowTitle[0];
	MVC->gui = gui;
	MVC->serial.setGUI(gui);
	MVC->ProcessControl.gui = gui;
	gui->show(1,&W);

	if (!options.use_gui)
	{
		if (options.stl_input_path.size() > 0)
		{
			MVC->ReadStl(options.stl_input_path);

			if (options.settings_path.size() > 0)
			{
				MVC->ProcessControl.LoadXML(options.settings_path);
				MVC->CopySettingsToGUI();
			}

			MVC->ConvertToGCode();

			if (options.gcode_output_path.size() > 0)
			{
				Fl_Text_Buffer *buffer = gui->GCodeResult->buffer();

				return buffer->savefile(options.gcode_output_path.c_str());
			}
		}
		return 0;
	}
	
	return Fl::run();
}
Пример #29
0
void send_report(Fl_Button* button, void*)
{
	Neo::HTTPRequest connection(REPORT_DOMAIN, 80);
	const char* response = connection.sendPostRequest("/crash.php", buffer.text());
}
Пример #30
0
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);

}