コード例 #1
0
ファイル: treescanner.cpp プロジェクト: kai66673/qt-creator
void TreeScanner::scanForFiles(FutureInterface *fi, const Utils::FileName& directory,
                               const FileFilter &filter, const FileTypeFactory &factory)
{
    std::unique_ptr<FutureInterface> fip(fi);
    fip->reportStarted();

    Result nodes = FileNode::scanForFiles(
                directory,
                [&filter, &factory](const Utils::FileName &fn) -> FileNode * {
        const Utils::MimeType mimeType = Utils::mimeTypeForFile(fn.toString());

        // Skip some files during scan.
        if (filter && filter(mimeType, fn))
            return nullptr;

        // Type detection
        FileType type = FileType::Unknown;
        if (factory)
            type = factory(mimeType, fn);

        return new FileNode(fn, type, false);
    }, fip.get());

    Utils::sort(nodes, ProjectExplorer::Node::sortByPath);

    fip->setProgressValue(fip->progressMaximum());
    fip->reportResult(nodes);
    fip->reportFinished();
}
コード例 #2
0
void SongSettingWidget::on_toolButtonBrowseBackround2_clicked()
{
    QString filename;
    if (mySettings2.backgroundType == 0)
    {
        QColor c(QColorDialog::getColor(mySettings2.backgroundColor,this));
        if(c.isValid())
        {
            mySettings2.backgroundColor = c;
            mySettings2.isChangedBackColor = true;
        }
        QPalette p;
        p.setColor(QPalette::Base,mySettings2.backgroundColor);
        ui->graphicsViewBackgroundColor2->setPalette(p);
    }
    else if (mySettings2.backgroundType == 1)
    {
        filename = QFileDialog::getOpenFileName(this, tr("Select a image for Bible wallpaper"),
                                                ".", tr("Images(%1)").arg(getSupportedImageFormats()));
        if(!filename.isNull())
        {
            QPixmap pix(filename);
            if(pix.width()>1280 || pix.height()>1280)
                mySettings2.backgroundPix = pix.scaled(1280,1280,Qt::KeepAspectRatio);
            else
                mySettings2.backgroundPix = pix;
            QFileInfo fip(filename);
            filename = fip.fileName();
            mySettings2.backgroundName = filename;
            ui->lineEditBackPath2->setText(filename);
            mySettings2.isChangedBackPix = true;
        }
    }
    else if (mySettings2.backgroundType == 2)
    {
        filename = QFileDialog::getOpenFileName(this, tr("Select a video for Bible wallpaper"),
                                                ".", "*");
        if(!filename.isNull())
        {
            mySettings2.backgroundVideoPath = filename;
            QFileInfo fiv(filename);
            filename = fiv.fileName();

            ui->lineEditBackPath2->setText(filename);
            mySettings2.isChangedBackVid = true;
        }
    }
}
コード例 #3
0
ファイル: exercise (no LUT).c プロジェクト: samskiter/compass
//subpixel line drawing is pretty: http://www.antigrain.com/doc/introduction/introduction.agdoc.html (Bresenham's)
void line_algorithm(fixedPointCoord start, fixedPointCoord end, int8_t transpose) {
//transpose make x and y be flipped when written (for incrementing in the y direction
	//initialise and draw the first pointcurrent
	fixedPoint dx = end.x - start.x;
	fixedPoint dy = end.y - start.y;
	fixedPoint d = fip(dy)/dx; //be careful of divides and multiplies
	uintCoord current; //records the current pixel we are writing to
	if (end.x < start.x) {
		fixedPointCoord tmp = start;
		start = end;
		end = tmp;
		d=(-1)*d;
	}
	
	current.x = roundfip(start.x);
	fixedPoint yf = start.y + roundfip(d * (fip(current.x) - start.x)); //because of multiplying, we have to take a layer of fipping off - roundfip does this
	current.y = roundfip(yf);
	yf = yf - fip(current.y);
	LCD_set_pixel_tr(current, transpose);
	
	//make sure the iteration goes the right way
	int y_dir = 1;
	if (end.y < start.y) {
		y_dir = -1;
		yf = -1 * yf; //we will be only be incrementing Yf as it it simply a reference to proportion through the pixel we are. If we are moving negatively through y, we should move yf to the other end of its range
	}
	while (fip(current.x) < (end.x - fip(0.5))) {
		current.x += 1;
		yf += absint(d);
		if (yf > fip(0.5)) {
			current.y += y_dir;
			yf -= fip(1);
		}
		LCD_set_pixel_tr(current, transpose);
	}
}
コード例 #4
0
int main(void) {
	int(*func)(void);
	func = fip();
	return func() == 42 ? 0 : 1;
}
コード例 #5
0
ファイル: exercise (no LUT).c プロジェクト: samskiter/compass
int main(void) {
_delay_ms(100);
	// IO port initialisation
	port_direction_init();
	
	centre.x = ((float)LCD_WIDTH-1.0)/(float)2.0;	//the X origin offset
	centre.y = ((float)LCD_HEIGHT-1.0)/(float)2.0;	//the Y origin offset
	
	//set up the compass serial port
	compass_init();
	LCD_init();
	SREG |= 0x80;	//Set the global interrupt enable bit in the Status Register SREG, see section 6.3.1 of the datasheet.
	LCD_clear();
	
	//north
	fixedPointLine northline1;
	northline1.start.x = fip(centre.x);
	northline1.start.y = fip(0);
	northline1.end.x = fip(37);
	northline1.end.y = fip(centre.y);
	fixedPointLine northline2;
	northline2.start.x = fip(centre.x);
	northline2.start.y = fip(0);
	northline2.end.x = fip(46);
	northline2.end.y = fip(centre.y);
	//north small
	fixedPointLine northsmallline1;
	northsmallline1.start.x = fip(41.5);
	northsmallline1.start.y = fip(15);
	northsmallline1.end.x = fip(46);
	northsmallline1.end.y = fip(23.5);
	fixedPointLine northsmallline2;
	northsmallline2.start.x = fip(41.5);
	northsmallline2.start.y = fip(15);
	northsmallline2.end.x = fip(37);
	northsmallline2.end.y = fip(23.5);
	//horizontal line
	fixedPointLine horizontalline;
	horizontalline.start.x = fip(30);//37;
	horizontalline.start.y = fip(centre.y);
	horizontalline.end.x = fip(53);//46;
	horizontalline.end.y = fip(centre.y);
	//south
	fixedPointLine southline1;
	southline1.start.x = fip(centre.x);
	southline1.start.y = fip(47);
	southline1.end.x = fip(46);
	southline1.end.y = fip(centre.y);
	fixedPointLine southline2;
	southline2.start.x = fip(centre.x);
	southline2.start.y = fip(47);
	southline2.end.x = fip(37);
	southline2.end.y = fip(centre.y);
	
	fixedPointPolygon northTriangle;
	northTriangle.num_vertices = 4;
	fixedPointCoord vertices[northTriangle.num_vertices];
	vertices[0].x = fip(centre.x); //point
	vertices[0].y = fip(0);
	vertices[1].x = fip(46); //bottom right
	vertices[1].y = fip(centre.y);
	vertices[2].x = fip(centre.x); //middle arrow
	vertices[2].y = fip(19);
	vertices[3].x = fip(37); //bottom left
	vertices[3].y = fip(centre.y);
	northTriangle.vertices = vertices; //vertices points to the start of the array
	
	fixedPointPolygon rotatedPoly;
	fixedPointEdgeTable globalEdgeTable;
	while (1) {
	//TODO: use a timed interrupt to send the LCD update
	//TODO: stop the LCD update during the compass update (MAYBE??)
	//TODO: name public and private headers
	//TODO: separate out LCD functions
		updated = 0;
		compass_transmit((char) 0x12);
		while (!updated) {
		}
		LCD_clear_buff();
		
		//north
		//draw_line_l(rotateLine(northline1, angle));
		//draw_line_l(rotateLine(northline2, angle));
		//north small
		/*draw_line_l(rotateLine(northsmallline1, angle));
		draw_line_l(rotateLine(northsmallline2, angle));*/
		//horizontal line
		//draw_line_l(rotateLine(horizontalline, angle));
		//south
		draw_line_l(rotateLine(southline1, angle));
		
		if (rotatePolygon(&northTriangle, angle, &rotatedPoly)) {
			if (initialise_global_edge_table(&rotatedPoly, &globalEdgeTable)) {
			//remember a logical check that after initialisation, there are at least 2 edges!
				draw_polygon(&globalEdgeTable);
				free(globalEdgeTable.edges);
				globalEdgeTable.edges = NULL;
				draw_line_l(rotateLine(southline2, angle));
			}
			free(rotatedPoly.vertices);
			rotatedPoly.vertices = NULL;
		}
		
		//steps:
		//rotate polygon - check
		//http://www.cs.rit.edu/~icss571/filling/how_to.html
		//initializing should return a bool for successful or not (cos of mallocing)
		//initialize edges
		//initializing global edge table (sorted) (size should be total number of edges)
		//initializing parity
		//initializing the scan-line
		//initializing active edge table (size should be number of edges)
		//fill polygon
		//aim for a draw_scene function (pass an array of polygons and an angle)
		//  if N is 2 for a polygon, cast its array to a line

		LCD_update();

 	}
}
コード例 #6
0
ファイル: exercise (no LUT).c プロジェクト: samskiter/compass
void draw_polygon(fixedPointEdgeTable* global_edge_table) {
	//initialise parity
	uint8_t parity = 0; //0 represents 'not inside polygon'
	uint8_t last_type = 2;
	//initialise the scan-line - set to lowest y value
	int8_t scan_line = roundfip(global_edge_table->edges[0].ymin);
	
	//initialise active edge table (size should be number of edges in the global edge table)
	/*fixedPointEdgeTable active_edge_table;
	fixedPointEdge* fpedges = calloc(global_edge_table->num_edges, sizeof(fixedPointEdge));
	if (NULL == fpedges) {
		return false; //error, not enough space to make this
	}
	active_edge_table.edges = fpedges; //we have now successfully assigned enough memory to do this
	*/
	uint8_t active_edges = 0;
	//loop the global edge table and update the edges for this scan line
	uint8_t current_edge;
	fixedPointEdge start_edge;
	uintCoord current;
	
	while(1) {
		for (current_edge = 0; current_edge < global_edge_table->num_edges; current_edge++) {
			if (global_edge_table->edges[current_edge].status == ACTIVE) {
				//evaluate if this edge should be deactivated
				if (global_edge_table->edges[current_edge].ymax < (fip(scan_line) - fip(0.5))) { //we subtract 0.5 because we want the scan line to be beyond the end of the edge before disabling it
					//deactivate it
					global_edge_table->edges[current_edge].status = COMPLETE;
					active_edges--;
				} else {
					//increment the pixel's x value
					global_edge_table->edges[current_edge].x += global_edge_table->edges[current_edge].slope;
					//put a cap on x values - this fixes issues with very high gradients creating lines off the polygon
					if (((global_edge_table->edges[current_edge].slope > 0) && (roundfip(global_edge_table->edges[current_edge].x) > global_edge_table->edges[current_edge].xlim))
						|| ((global_edge_table->edges[current_edge].slope < 0) && (roundfip(global_edge_table->edges[current_edge].x) < global_edge_table->edges[current_edge].xlim))) {
						global_edge_table->edges[current_edge].x = fip(global_edge_table->edges[current_edge].xlim);
					}
				}
			} else if (global_edge_table->edges[current_edge].status == INACTIVE) {
				//evaluate if this edge should be activated
				if (global_edge_table->edges[current_edge].ymin < (fip(scan_line) + fip(0.5))) { //we add 0.5 because if the scan line were at 0, we would want to pick up ymins from -0.5 to 0.5
					global_edge_table->edges[current_edge].status = ACTIVE;
					active_edges++;
					//we need to make sure this edge is in the right place
					int8_t past_edge;
					for (past_edge = (current_edge-1); past_edge >= 0; past_edge--) { //iterate back down through the older (active/complete) edges and find any active ones with greater x
						if (global_edge_table->edges[current_edge].status == ACTIVE) {
							if ((global_edge_table->edges[current_edge].x < global_edge_table->edges[past_edge].x) 
								&& (global_edge_table->edges[past_edge].ymax != global_edge_table->edges[current_edge].ymin)) {
								//the above if statement stops a new edge that is continuing upward from an older edge from swapping with it while they are both active
								//this is relevant as they are allowed to both be active simultaneously (as the +-0.5 has to account for inflection points)
								current.y = scan_line;
								current.x = past_edge;
								LCD_set_pixel(current);
								fixedPointEdge tmp_edge = global_edge_table->edges[current_edge]; //this assignment copies the data across (there are no pointers in a fixepoint edge)
								global_edge_table->edges[current_edge] = global_edge_table->edges[past_edge];
								global_edge_table->edges[past_edge] = tmp_edge;
							}
						}
					}
				}
			}
		}
		
		if (active_edges == 0) break;
		parity = 1;
		last_type = 2; //2 is a special value meaning uninitialised
		current.y = 0;
		current.x = 0;
		LCD_set_pixel(current);
		current.y = scan_line;
		for (current_edge = 0; current_edge < global_edge_table->num_edges; current_edge++) {
			if (global_edge_table->edges[current_edge].status == ACTIVE) {
				if(last_type == 2) last_type = 1 - global_edge_table->edges[current_edge].type; //initialise last_type
				if (global_edge_table->edges[current_edge].type != last_type) {
					parity = 1 - parity;
					if (parity == 0) {
						start_edge = global_edge_table->edges[current_edge];
					}/* else if (start_edge.ymax != global_edge_table->edges[current_edge].ymin) { //this accounts for the case when 2 connected edges which continue upward are active at the same time
						for (current.x = roundfip(start_edge.x); fip(current.x) <= (global_edge_table->edges[current_edge].x + fip(0.5)); current.x++) {
							LCD_set_pixel(current);
						}
					}*/ else {
						for (current.x = roundfip(start_edge.x); fip(current.x) <= (global_edge_table->edges[current_edge].x + fip(0.5)); current.x++) {
							LCD_set_pixel(current);
						}
					}
				}
				last_type = global_edge_table->edges[current_edge].type;
			}
		}
		scan_line++;
	}
}
コード例 #7
0
ファイル: exercise (no LUT).c プロジェクト: samskiter/compass
//this function initialises all the edges and orders them into the edge table sorted by increasing ymin and xmin
bool initialise_global_edge_table(fixedPointPolygon* poly, fixedPointEdgeTable* edge_table) {
	//malloc
	fixedPointEdge* fpedges = calloc(poly->num_vertices, sizeof(fixedPointEdge)); //we must assign enough memory for every edge to be in the edge table, even though some may be discarded
	if (NULL == fpedges) {
		return false; //error, not enough space to make this
	}
	edge_table->edges = fpedges; //we have now successfully assigned enough memory to do this
	edge_table->num_edges = 0; //we will increment this as we add each edge to the edge table
	fixedPointCoord start_vertex;
	fixedPointCoord end_vertex;
	fixedPointLine last_line;
	uint8_t vertex;
	uint8_t curr_edge_type = 0;
	for (vertex = 0; vertex < poly->num_vertices; vertex++) { //for every vertex, make an edge using it and the previous vertex
		start_vertex = poly->vertices[vertex];
		if (vertex == 0) {
			end_vertex = poly->vertices[poly->num_vertices - 1]; //pull out the last vertex
		} else {
			end_vertex = poly->vertices[vertex - 1];
		}
		
		//make sure 'start' has the lowest y
		if (start_vertex.y > end_vertex.y) {
			fixedPointCoord tmp = start_vertex;
			start_vertex = end_vertex;
			end_vertex = tmp;
		}
		fixedPoint dy = end_vertex.y - start_vertex.y;
		if (roundfip(dy) == 0) {
			if (last_line.end.x != NULL) {
				//this section moves the end of the previous line onto the end of this horizontal line
				if (start_vertex.x == last_line.end.x) {
					//if the start vertex matches the top of the previous line
					last_line.end.x = end_vertex.x;
					last_line.end.y = end_vertex.y;
				} else if (start_vertex.x == last_line.start.x) {
					//if the start vertex happens to match the bottom of the previous line
					last_line.start.x = end_vertex.x;
					last_line.start.y = end_vertex.y;
				} else if (end_vertex.x == last_line.end.x) {
					//if the start vertex happens to match the top of the previous line
					last_line.end.x = start_vertex.x;
					last_line.end.y = start_vertex.y;
				}  else if (end_vertex.x == last_line.start.x) {
					//if the start vertex happens to match the bottom of the previous line
					last_line.start.x = start_vertex.x;
					last_line.start.y = start_vertex.y;
				}
			}
			continue; //we dont need to draw horizontal lines (or close-to horizontal lines!), other edges will take care of this
		}
		
		fixedPoint dx = end_vertex.x - start_vertex.x;
		fixedPointEdge new_edge;
		new_edge.slope = fip(dx)/dy; //be careful of divides and multiplies
		new_edge.ymin = start_vertex.y;
		new_edge.x = start_vertex.x; //start vertex
		new_edge.ymax = end_vertex.y;
		new_edge.xlim = roundfip(end_vertex.x);
		new_edge.status = INACTIVE;
		if (((start_vertex.x == last_line.start.x) && (start_vertex.y == last_line.start.y))
			|| ((end_vertex.x == last_line.end.x) && (end_vertex.y == last_line.end.y))) {
			//changing direction
			curr_edge_type = 1 - curr_edge_type; //invert
		}
		last_line.start.x = start_vertex.x;
		last_line.start.y = start_vertex.y;
		last_line.end.x = end_vertex.x;
		last_line.end.y = end_vertex.y;
		new_edge.type = curr_edge_type;
		//now find out where the new edge goes in the edge table (order by ymin then xmin, then slope)
		uint8_t current_edge;
		uint8_t new_position = edge_table->num_edges; //default position is to put it on the end
		uintCoord current;
		current.y = roundfip(start_vertex.y);
		current.x = roundfip(start_vertex.x) + (vertex*10) + 3;
		LCD_set_pixel(current);
		current.y = roundfip(end_vertex.y);
		current.x = roundfip(end_vertex.x) + (vertex*10) + 3;
		LCD_set_pixel(current);
		for (current_edge = 0; current_edge < edge_table->num_edges; current_edge++) {
			if (edge_table->edges[current_edge].ymin > new_edge.ymin) { //if the current edge starts above the new edge
				new_position = current_edge;
				break;
			} else if (edge_table->edges[current_edge].ymin == new_edge.ymin) {
				if (edge_table->edges[current_edge].x > new_edge.x) { // if the current edge starts to the right of the new edge
					//add the edge where current_edge is
					new_position = current_edge;
					break;
				} else if (edge_table->edges[current_edge].x == new_edge.x) { //if these two edges start at the same point (and diverge)
					//sort by slope
					
					if (edge_table->edges[current_edge].slope > new_edge.slope) { //if the current edge slopes rightward of the new edge
						new_position = current_edge;
						break;
					}
				}
			}
		}
		//insert the new edge in the new_position in the edge matrix (involves bumping the others up)
		for (current_edge = edge_table->num_edges; current_edge > new_position; current_edge--) {
			edge_table->edges[current_edge] = edge_table->edges[current_edge-1];
		}
		edge_table->edges[new_position] = new_edge;
		edge_table->num_edges++;
	}
	return true;
}
コード例 #8
0
ファイル: exercise (no LUT).c プロジェクト: samskiter/compass
fixedPointCoord fipCoord(doubleCoord c) {
	fixedPointCoord tmpCoord;
	tmpCoord.x = fip(c.x);
	tmpCoord.y = fip(c.y);
	return tmpCoord;
}