Graphics in C# on macOS

The Einhugur framework has similarities to Xojo in many ways

It has a Canvas, just like Xojo

And when you use its paint event you can do many of the same things like drawing text and shapes and pictures.

We can add a canvas just like other controls. And we can implement the paint event in the same way.

canvas = new Canvas(left,top,width,height);
canvas.Paint += canvas_Paint;

And the paint event would look like

private void canvas_Paint(object sender, PaintEventArgs args)
{
    GraphicsContext g = args.Graphics;

    // GraphicsContext is in many respect like Xojo's
    // Graphics

}

Now you can change the fill colors, stroke colors (borders), and draw shapes & text. You also have built in rotation, clipping, and scaling. There are no bezier paths and some more complex drawing operations – yet.

One thing you will notice is that getting an RGB or RGBA color is a little different.
Since colors in the Einhugur framework are based on CGColors internally they permit a really wide range of colors. Much more than the 0 – 255 based Xojo colors.
So, each component of a RGB color is a floating point value in the range 0 – 1 like the following

g.FillColor = Einhugur.Drawing.Color.RGB((nfloat).6, (nfloat).3, (nfloat).4);

RGBA is similar with the Alpha also being a value ni the range 0 – 1.

Once you have the basics in place you can draw most anything you want.

private void canvas_Paint(object sender, PaintEventArgs args)
{
   GraphicsContext g = args.Graphics;

   g.FillColor = 
     Einhugur.Drawing.Color.RGB((nfloat).6, (nfloat).3, (nfloat).4);

   g.StrokeColor = 
     Einhugur.Drawing.Color.RGB((nfloat)0, (nfloat)1.0, (nfloat)0);

   g.DrawRoundRectangle(1, 1, 
         (float)(canvas.Width - 2), (float)(canvas.Height - 2),
         4, 4);
}

Oh and yes, with creativity you can combine drawing pictures with threads !

As usual a link to the project as it is now