void TreeView::Draw(BRect updateRect) { //colours for drawing the triangle SetHighColor(0,0,0); SetLowColor(150,150,150); if(status && !down)//if view is showing { //horiz triangle FillTriangle(BPoint(0,2),BPoint(8,2),BPoint(4,6),B_SOLID_LOW); StrokeTriangle(BPoint(0,2),BPoint(8,2),BPoint(4,6),B_SOLID_HIGH); } else if (!status && !down){ //vert triangle FillTriangle(BPoint(2,0),BPoint(2,8),BPoint(6,4),B_SOLID_LOW); StrokeTriangle(BPoint(2,0),BPoint(2,8),BPoint(6,4),B_SOLID_HIGH); } else {//midway SetHighColor(0,0,0); SetLowColor(100,100,0); FillTriangle(BPoint(0,6),BPoint(6,0),BPoint(6,6),B_SOLID_LOW); StrokeTriangle(BPoint(0,6),BPoint(6,0),BPoint(6,6),B_SOLID_HIGH); } down = false; SetHighColor(0,0,0); SetLowColor(150,150,150); }
void GradientsView::DrawLinear(BRect update) { BGradientLinear gradient; rgb_color c; c.red = 255; c.green = 0; c.blue = 0; gradient.AddColor(c, 0); c.red = 0; c.green = 255; c.blue = 0; gradient.AddColor(c, 127); c.red = 0; c.green = 0; c.blue = 255; gradient.AddColor(c, 255); // RoundRect SetHighColor(0, 0, 0); FillRoundRect(BRect(10, 10, 110, 110), 5, 5); gradient.SetStart(BPoint(120, 10)); gradient.SetEnd(BPoint(220, 110)); FillRoundRect(BRect(120, 10, 220, 110), 5, 5, gradient); // Rect SetHighColor(0, 0, 0); FillRect(BRect(10, 120, 110, 220)); gradient.SetStart(BPoint(120, 120)); gradient.SetEnd(BPoint(220, 220)); FillRect(BRect(120, 120, 220, 220), gradient); // Triangle SetHighColor(0, 0, 0); FillTriangle(BPoint(60, 230), BPoint(10, 330), BPoint(110, 330)); gradient.SetStart(BPoint(60, 230)); gradient.SetEnd(BPoint(60, 330)); FillTriangle(BPoint(170, 230), BPoint(120, 330), BPoint(220, 330), gradient); // Ellipse SetHighColor(0, 0, 0); FillEllipse(BPoint(60, 390), 50, 50); gradient.SetStart(BPoint(60, 340)); gradient.SetEnd(BPoint(60, 440)); FillEllipse(BPoint(170, 390), 50, 50, gradient); }
void GradientsView::DrawRadialFocus(BRect update) { BGradientRadialFocus gradient; rgb_color c; c.red = 255; c.green = 0; c.blue = 0; gradient.AddColor(c, 0); c.red = 0; c.green = 255; c.blue = 0; gradient.AddColor(c, 127); c.red = 0; c.green = 0; c.blue = 255; gradient.AddColor(c, 255); // RoundRect SetHighColor(0, 0, 0); FillRoundRect(BRect(10, 10, 110, 110), 5, 5); gradient.SetCenter(BPoint(170, 60)); FillRoundRect(BRect(120, 10, 220, 110), 5, 5, gradient); // Rect SetHighColor(0, 0, 0); FillRect(BRect(10, 120, 110, 220)); gradient.SetCenter(BPoint(170, 170)); FillRect(BRect(120, 120, 220, 220), gradient); // Triangle SetHighColor(0, 0, 0); FillTriangle(BPoint(60, 230), BPoint(10, 330), BPoint(110, 330)); gradient.SetCenter(BPoint(170, 280)); FillTriangle(BPoint(170, 230), BPoint(120, 330), BPoint(220, 330), gradient); // Ellipse SetHighColor(0, 0, 0); FillEllipse(BPoint(60, 390), 50, 50); gradient.SetCenter(BPoint(170, 390)); FillEllipse(BPoint(170, 390), 50, 50, gradient); }
/** * @brief Draws a full poly-line (between many points). * @param Points: Pointer to the points array * @param PointCount: Number of points * @retval None */ void BSP_LCD_FillPolygon(pPoint Points, uint16_t PointCount) { int16_t X = 0, Y = 0, X2 = 0, Y2 = 0, X_center = 0, Y_center = 0, X_first = 0, Y_first = 0, pixelX = 0, pixelY = 0, counter = 0; uint16_t IMAGE_LEFT = 0, IMAGE_RIGHT = 0, IMAGE_TOP = 0, IMAGE_BOTTOM = 0; IMAGE_LEFT = IMAGE_RIGHT = Points->X; IMAGE_TOP= IMAGE_BOTTOM = Points->Y; for(counter = 1; counter < PointCount; counter++) { pixelX = POLY_X(counter); if(pixelX < IMAGE_LEFT) { IMAGE_LEFT = pixelX; } if(pixelX > IMAGE_RIGHT) { IMAGE_RIGHT = pixelX; } pixelY = POLY_Y(counter); if(pixelY < IMAGE_TOP) { IMAGE_TOP = pixelY; } if(pixelY > IMAGE_BOTTOM) { IMAGE_BOTTOM = pixelY; } } if(PointCount < 2) { return; } X_center = (IMAGE_LEFT + IMAGE_RIGHT)/2; Y_center = (IMAGE_BOTTOM + IMAGE_TOP)/2; X_first = Points->X; Y_first = Points->Y; while(--PointCount) { X = Points->X; Y = Points->Y; Points++; X2 = Points->X; Y2 = Points->Y; FillTriangle(X, X2, X_center, Y, Y2, Y_center); FillTriangle(X, X_center, X2, Y, Y_center, Y2); FillTriangle(X_center, X2, X, Y_center, Y2, Y); } FillTriangle(X_first, X2, X_center, Y_first, Y2, Y_center); FillTriangle(X_first, X_center, X2, Y_first, Y_center, Y2); FillTriangle(X_center, X2, X_first, Y_center, Y2, Y_first); }
/** * @brief Draws a full poly-line (between many points). * @param Points: Pointer to the points array * @param PointCount: Number of points * @retval None */ void BSP_LCD_FillPolygon(pPoint Points, uint16_t PointCount) { int16_t X = 0, Y = 0, X2 = 0, Y2 = 0, X_center = 0, Y_center = 0, X_first = 0, Y_first = 0, pixelX = 0, pixelY = 0, counter = 0; uint16_t image_left = 0, image_right = 0, image_top = 0, image_bottom = 0; image_left = image_right = Points->X; image_top= image_bottom = Points->Y; for(counter = 1; counter < PointCount; counter++) { pixelX = POLY_X(counter); if(pixelX < image_left) { image_left = pixelX; } if(pixelX > image_right) { image_right = pixelX; } pixelY = POLY_Y(counter); if(pixelY < image_top) { image_top = pixelY; } if(pixelY > image_bottom) { image_bottom = pixelY; } } if(PointCount < 2) { return; } X_center = (image_left + image_right)/2; Y_center = (image_bottom + image_top)/2; X_first = Points->X; Y_first = Points->Y; while(--PointCount) { X = Points->X; Y = Points->Y; Points++; X2 = Points->X; Y2 = Points->Y; FillTriangle(X, X2, X_center, Y, Y2, Y_center); FillTriangle(X, X_center, X2, Y, Y_center, Y2); FillTriangle(X_center, X2, X, Y_center, Y2, Y); } FillTriangle(X_first, X2, X_center, Y_first, Y2, Y_center); FillTriangle(X_first, X_center, X2, Y_first, Y_center, Y2); FillTriangle(X_center, X2, X_first, Y_center, Y2, Y_first); }
void SpinnerArrowButton::Draw(BRect update) { rgb_color c = ui_color(B_PANEL_BACKGROUND_COLOR); BRect r(Bounds()); rgb_color light, dark, normal,arrow,arrow2; if (fMouseDown) { light = tint_color(c,B_DARKEN_3_TINT); arrow2 = dark = tint_color(c,B_LIGHTEN_MAX_TINT); normal = c; arrow = tint_color(c,B_DARKEN_MAX_TINT); } else if (fEnabled) { arrow2 = light = tint_color(c,B_LIGHTEN_MAX_TINT); dark = tint_color(c,B_DARKEN_3_TINT); normal = c; arrow = tint_color(c,B_DARKEN_MAX_TINT); } else { arrow2 = light = tint_color(c,B_LIGHTEN_1_TINT); dark = tint_color(c,B_DARKEN_1_TINT); normal = c; arrow = tint_color(c,B_DARKEN_1_TINT); } r.InsetBy(1,1); SetHighColor(normal); FillRect(r); SetHighColor(arrow); FillTriangle(fTrianglePoint1,fTrianglePoint2,fTrianglePoint3); r.InsetBy(-1,-1); SetHighColor(dark); StrokeLine(r.LeftBottom(),r.RightBottom()); StrokeLine(r.RightTop(),r.RightBottom()); StrokeLine(fTrianglePoint2,fTrianglePoint3); StrokeLine(fTrianglePoint1,fTrianglePoint3); SetHighColor(light); StrokeLine(r.LeftTop(),r.RightTop()); StrokeLine(r.LeftTop(),r.LeftBottom()); SetHighColor(arrow2); StrokeLine(fTrianglePoint1,fTrianglePoint2); }
// Draw triangle on screen void DrawTriangle(SDL_Surface *screen, triangle_t *triangle) { int isOK; // Scale. ScaleTriangle(triangle); // Translate. TranslateTriangle(triangle); // Determine bounding box CalculateTriangleBoundingBox(triangle); // Sanity check that triangle is within screen boundaries. isOK = SanityCheckTriangle(screen, triangle); if (isOK == 0) { PrintTriangle(triangle, "Triangle outside screen boundaries"); return; } // TODO: Insert calls to DrawLine to draw the triangle. // Remember to use the on-screen coordinates (triangle->sx1, etc.) DrawLine(screen, triangle->sx1, triangle->sy1, triangle->sx2, triangle->sy2, TRIANGLE_PENCOLOR); DrawLine(screen, triangle->sx2, triangle->sy2, triangle->sx3, triangle->sy3, TRIANGLE_PENCOLOR); DrawLine(screen, triangle->sx1, triangle->sy1, triangle->sx3, triangle->sy3, TRIANGLE_PENCOLOR); // Fill triangle FillTriangle(screen, triangle); /* DrawLine(screen, triangle->bx, triangle->by, triangle->bx + triangle->bw, triangle->by, 0xffffffff); DrawLine(screen, triangle->bx, triangle->by, triangle->bx, triangle->by + triangle->bh, 0xffffffff); DrawLine(screen, triangle->bx + triangle->bw, triangle->by + triangle->bh, triangle->bx + triangle->bw, triangle->by, 0xffffffff); DrawLine(screen, triangle->bx, triangle->bh + triangle->by, triangle->bw + triangle->bx, triangle->by + triangle->bh, 0xffffffff); */ // Force screen update. SDL_UpdateRect(screen, triangle->bx, triangle->by, triangle->bw, triangle->bh); // Force update of entire screen. Comment/remove this call and uncomment the above call // when your CalculateTriangleBoundingBox function has been implemented. // SDL_UpdateRect(screen, 0, 0, screen->w, screen->h); }
// Add a horizontal polygon to the TLM grid void AddHorizontalPolygon(Polygon *HPolygon, double Thickness, double Permittivity, bool PropagateFlag) { int nVertices = HPolygon->nVertices; int VerticesRemaining; int Direction; double *Angles; double TotalAngle = 0; xyCoordinate *Vertices; xyCoordinate **Triangles; xyLine *Sides; bool *VertexRemoved; // Allocate memory for the angles, vertices, triangles and sides of the polygon Angles = (double*)malloc(nVertices*sizeof(double)); Vertices = (xyCoordinate*)malloc(nVertices*sizeof(xyCoordinate)); Triangles = (xyCoordinate**)malloc((nVertices-2)*sizeof(xyCoordinate*)); for (int i=0; i < (nVertices - 2); i++) { Triangles[i] = (xyCoordinate*)malloc(3*sizeof(xyCoordinate)); } Sides = (xyLine*)malloc(nVertices*sizeof(xyLine)); VertexRemoved = (bool*)malloc(nVertices*sizeof(bool)); // Store the xy coordinates of the vertices of the polygon in xyCoordinate structures for (int i = 0; i < nVertices; i++) { Vertices[i].X = HPolygon->Vertices[i].X; Vertices[i].Y = HPolygon->Vertices[i].Y; } // Costruct the equations of the sides of the polygon from its vertices for (int i = 0; i < nVertices; i++) { Sides[i] = CoordinatesToLine(Vertices[i], Vertices[(i+1)%nVertices]); } // Find the angles between each of the side vectors for (int i = 0; i < nVertices; i++) { Angles[i] = AngleBetweenLines(Sides[(i+nVertices-1)%nVertices],Sides[i]); TotalAngle += Angles[i]; } // Convert the angles between the side vectors into the inner angles of the polygon if (TotalAngle > 0) { // Points specified in anti-clockwise direction Direction = 1; } else { // Points specified in clockwise direction Direction = -1; } // Reduce the polygon to triangles, removing one vertex at a time int CurrentVertex = 0; // Count variable int Previous; // The previous and next valid vertices in the polygon int Next; // Set the number of remaining vertices to the initial order of the polygon VerticesRemaining = nVertices; // Set all of the removed flags to false for (int i = 0; i < nVertices; i++) { VertexRemoved[i] = false; } // Remove triangles one by one while (VerticesRemaining > 2) { if (VertexRemoved[CurrentVertex] == false) { // Check if the angle is reflex (adjusting for clockwise or anticlockwise points with 'Direction' if (Angles[CurrentVertex]*Direction > 0) { Previous = CurrentVertex; Next = CurrentVertex; // Find the next vertices in both directions that have not been removed do { Previous = (Previous + nVertices - 1)%nVertices; } while (VertexRemoved[Previous] == true); do { Next = (Next+1)%nVertices; } while (VertexRemoved[Next] == true); // Find the equation of the potential new side of the polygon xyLine NewSide = CoordinatesToLine(Vertices[Previous], Vertices[Next]); // Add a new side joining the previous and next vertices // Ensure the triangle formed does not enclose any other points bool EnclosesOtherPoints = false; for (int i=0; i<nVertices; i++) { if (VertexRemoved[i] == false && i != CurrentVertex && i != Next && i!= Previous) { if (IsWithinTriangle(NewSide, Sides[CurrentVertex], Sides[Previous], Vertices[i], Direction) == true) { EnclosesOtherPoints = true; } } } if (EnclosesOtherPoints == false) { // Fill in the current triangle FillTriangle(Vertices[CurrentVertex], Vertices[Previous], Vertices[Next], HPolygon->Vertices[0].Z, Thickness, Permittivity); // Reconstruct the polygon sides and angles following the removal of a vertex Sides[(Next+nVertices-1)%nVertices] = NewSide; // Replace both of the old sides Sides[Previous] = NewSide; // Find the prvious valid vertex to 'previous' // int PrePrevious = Previous; // do { // PrePrevious = (PrePrevious + nVertices - 1)%nVertices; // } // while (VertexRemoved[PrePrevious] == true); // Find the new angles for each vertex Angles[Next] = AngleBetweenLines(NewSide,Sides[Next]); Angles[Previous] = AngleBetweenLines(Sides[(Previous+nVertices-1)%nVertices], NewSide); VertexRemoved[CurrentVertex] = true; VerticesRemaining--; } } } CurrentVertex = (CurrentVertex+1)%nVertices; // Cyclically increment the count } // Remove allocated memory for arrays free(Angles); free(Vertices); free(Triangles); free(Sides); free(VertexRemoved); }