Drawing a Polygon in a TBCPanel lazarus / 21-General ---------------------------------------------------------------------- seany · 2023-07-14 22:47 I have a class : Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i     T2DRenderEngine = class //------------------------------------------------------// the 2D render Engine renders on a 2D infinite plane.                                                                                // So we need to set a coordinate system                                                                                // assume, that the topmost, leftmost of the plane is                                                                                // bound to a known point                                                                              // set that point coordinate to be 0, 0                                                                                // matches with everything that is computer graphics standards                                                                                // now, the "infinite plane"has became a                                                                                // SEMI INFINITE plane   public     left          : Integer; //---------------------------------------------------// the left coordinate of the bound point of the semi infinte plane    top         : Integer; //---------------------------------------------------// the top coordinate of the bound point of the semi infinte plane     root          : renderNodePtr; //---------------------------------------------// the root node of the render tree.     canvas        : TBCPanel;     canvasWidth   : Integer;    canvasHeight  : Integer;     defaultColor  : TColor;    defaultStyle  : TBCBackgroundStyle;     defaultPageShape : TGeomShape;     defaultFont   : TFont;       constructor Create();    procedure associateCanvas(renderPanel : TBCPanel);     procedure addPageNode();    procedure addPage(page : TGeomShape);    procedure renderAllPages();    procedure renderPage(pageNum : Integer);       function existsPageNode() : Boolean;   end;                 I want to draw a polygon on a TBCPanel with this function. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   procedure T2DRenderEngine.renderAllPages();var  currPage        : TGeomShape;  ii_dummy        : Integer;  center          : TPoint;  sideLength      : Double;  Vertices        : Array of TPoint;  vCount_dummy    : Integer;  moveAngle       : Double;  v10             : Double;  v11           : Double;  currVert        : TPoint;begin   //-------------------- First check if the root element is for page -------------//   if root^.renderSequence <> 1 then Exit; //--------------------------------------// No page group node, so leave   //----------------------- loop through all the children ------------------------//   for ii_dummy    := 0 to length(root^.Children)-1 do  begin    currPage      := root^.Children[ii_dummy]^.shape;     center.X      := Trunc(currPage.shapeShortCutParams[1]);    center.Y      := Trunc(currPage.shapeShortCutParams[2]);     if currPage.isShapeShortcut then    begin      case currPage.shapeShortcut of           shapeShortcuts.polygon:           begin               moveAngle := 2 * PI / Trunc(currPage.shapeShortCutParams[0]);               SetLength(Vertices,Trunc(currPage.shapeShortCutParams[0])+1);             v10:= 0 + center.X;               v11:= Trunc(currPage.shapeShortCutParams[3]) + center.Y;                for vCount_dummy := 1 to Trunc(currPage.shapeShortCutParams[0])+1 do             begin                 v10 := v10 * cos(moveAngle * vCount_dummy-1) - v11 * sin(moveAngle * vCount_dummy-1);               v11 := v10 * sin(moveAngle * vCount_dummy-1) - v10 * cos(moveAngle * vCount_dummy-1);                  currVert.X:=Trunc(v10 * currpage.rotate[0] + v11 * currPage.rotate[1]);                 currVert.Y:=Trunc(v10 * currpage.rotate[2] + v11 * currPage.rotate[3]);                  Vertices[vCount_dummy]:=currVert;               end;                canvas.Canvas.Brush.Color:=currPage.floodFillColor;               canvas.Canvas.Brush.Style:=bsSolid;                canvas.Canvas.Pen.Color:=currPage.strokes[0].color;               canvas.Canvas.Pen.Width:=currPage.strokes[0].width;               canvas.Canvas.Pen.Style:=psSolid;                 canvas.Canvas.Polygon(Vertices);                canvas.Refresh;              end;      end;    end;       end; end;   Full code may be found here I am calling this like: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i MainRenderer  : TRenderEngine.T2DRenderEngine;   MainRenderer  := TRenderEngine.T2DRenderEngine.Create();      MainRenderer.associateCanvas(renderPanel); //-----------------------------------// supply the canvas a TBCPanel created by form designer, is visible, etc...   MainRenderer.addPageNod e();//---------------------------------------------------// Create the Page node   strkx         := New(TRenderEngine.TStrokePtr);   strkx^.color:= clBlack;  strkx^.width:= 2;  strkx^.isSingleColor:=True;  strkx^.isUniformWidth:=True;    pagex       := New(TRenderEngine.TGeomShapePtr);   pageX^.isShapeShortcut:=True;  pageX^.shapeShortcut:= TRenderEngine.shapeShortCuts.polygon;   SetLength(pageX^.shapeShortCutParams,4);   pageX^.shapeShortCutParams[0] := 6;  pageX^.shapeShortCutParams[1] := 100;  pageX^.shapeShortCutParams[2] := 100;  pageX^.shapeShortCutParams[3] := 50;    pageX^.dimension:= 2;   pageX^.isFloodFill:=True;  pageX^.floodFillColor:=clMoneyGreen;   SetLength(pageX^.rotate,4);   pageX^.rotate[0] :=  cos(PI/3);  pageX^.rotate[1] := -sin(PI/3);  pageX^.rotate[2] :=  sin(PI/3);  pageX^.rotate[3] :=  cos(PI/3);   SetLength(pageX^.strokes,1);  pageX^.strokes[0]:= strkx^;   MainRenderer.addPage(pageX^);  MainRenderer.renderAllPages();     Notice, that I passed a TBCPanel as a Canvas I notice (by adding messageboxes) that the canvas.refresh is being called. I would imagine this triggers the onpaint method, and should draw the polygon. However, nothing is drawn. How can I pass a TBCPanel to an external class, as a canvas and make a method of that class draw a polygon on my TBCPanel. Thank you. ---------------------------------------------------------------------- jamie · 2023-07-15 16:11 the Panel does not have a ONPaint event? that would be the place to paint the polygone.