{"id":1507,"date":"2022-11-06T10:01:58","date_gmt":"2022-11-06T17:01:58","guid":{"rendered":"https:\/\/www.great-white-software.com\/blog\/?p=1507"},"modified":"2022-11-06T10:06:54","modified_gmt":"2022-11-06T17:06:54","slug":"graphics-in-c-on-macos","status":"publish","type":"post","link":"https:\/\/www.great-white-software.com\/blog\/2022\/11\/06\/graphics-in-c-on-macos\/","title":{"rendered":"Graphics in C# on macOS"},"content":{"rendered":"\n<p>The Einhugur framework has similarities to Xojo in many ways<\/p>\n\n\n\n<p>It has a Canvas, just like Xojo<\/p>\n\n\n\n<p>And when you use its paint event you can do many of the same things like drawing text and shapes and pictures.<\/p>\n\n\n\n<p>We can add a canvas just like other controls. And we can implement the paint event in the same way.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>canvas = new Canvas(left,top,width,height);\ncanvas.Paint += canvas_Paint;<\/code><\/pre>\n\n\n\n<p>And the paint event would look like<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>private void canvas_Paint(object sender, PaintEventArgs args)\n{\n    GraphicsContext g = args.Graphics;\n\n    \/\/ GraphicsContext is in many respect like Xojo's\n    \/\/ Graphics\n\n}<\/code><\/pre>\n\n\n\n<p>Now you can change the fill colors, stroke colors (borders), and draw shapes &amp; text. You also have built in rotation, clipping, and scaling. There are no bezier paths and some more complex drawing operations &#8211; yet.<\/p>\n\n\n\n<p>One thing you will notice is that getting an RGB or RGBA color is a little different.<br>Since colors in the Einhugur framework are based on CGColors internally they permit a really wide range of colors. Much more than the 0 &#8211; 255 based Xojo colors.<br>So, each component of a RGB color is a floating point value in the range 0 &#8211; 1 like the following <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>g.FillColor = Einhugur.Drawing.Color.RGB((nfloat).6, (nfloat).3, (nfloat).4);<\/code><\/pre>\n\n\n\n<p>RGBA is similar with the Alpha also being a value ni the range 0 &#8211; 1. <\/p>\n\n\n\n<p>Once you have the basics in place you can draw most anything you want.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>private void canvas_Paint(object sender, PaintEventArgs args)\n{\n   GraphicsContext g = args.Graphics;\n\n   g.FillColor = \n     Einhugur.Drawing.Color.RGB((nfloat).6, (nfloat).3, (nfloat).4);\n\n   g.StrokeColor = \n     Einhugur.Drawing.Color.RGB((nfloat)0, (nfloat)1.0, (nfloat)0);\n\n   g.DrawRoundRectangle(1, 1, \n         (float)(canvas.Width - 2), (float)(canvas.Height - 2),\n         4, 4);\n}\n<\/code><\/pre>\n\n\n\n<p>Oh and yes, with creativity you can combine drawing pictures with threads !<\/p>\n\n\n\n<p>As usual<a href=\"https:\/\/great-white-software.com\/miscellaneous\/CSharp\/getting_started-2022-11-06.zip\"> a link to the project<\/a> as it is now<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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 &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.great-white-software.com\/blog\/2022\/11\/06\/graphics-in-c-on-macos\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Graphics in C# on macOS&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[1],"tags":[34,4],"class_list":["post-1507","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-csharp","tag-macos"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/posts\/1507","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/comments?post=1507"}],"version-history":[{"count":2,"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/posts\/1507\/revisions"}],"predecessor-version":[{"id":1509,"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/posts\/1507\/revisions\/1509"}],"wp:attachment":[{"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/media?parent=1507"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/categories?post=1507"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.great-white-software.com\/blog\/wp-json\/wp\/v2\/tags?post=1507"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}