{"id":4182,"date":"2022-01-24T15:23:02","date_gmt":"2022-01-24T15:23:02","guid":{"rendered":"http:\/\/truelogic.org\/wordpress\/?p=4182"},"modified":"2022-01-24T15:23:02","modified_gmt":"2022-01-24T15:23:02","slug":"11e-wxwidgets-regions","status":"publish","type":"post","link":"https:\/\/truelogic.org\/wordpress\/2022\/01\/24\/11e-wxwidgets-regions\/","title":{"rendered":"11e. wxWidgets &#8211; Regions"},"content":{"rendered":"\n<p><strong>OVERVIEW<\/strong><\/p>\n\n\n\n<p>Regions are used to change colors in certain areas of the screen by defining different regions and using one of the 4 operations available:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Union<\/li><li>Intersect<\/li><li>Subtract<\/li><li>Xor<\/li><\/ul>\n\n\n\n<p>The sample code shows the four operations in action<\/p>\n\n\n\n<p><strong>SAMPLE CODE<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">regions.h<\/pre>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\n#include &lt;wx\/wxprec.h&gt;\n#ifndef WX_PRECOMP\n\t#include &lt;wx\/wx.h&gt;\n#endif\n\nclass Regions: public wxFrame {\n\tpublic:\n\t\tRegions(const wxString &amp;title);\n\t\tvoid onPaint(wxPaintEvent &amp;event);\n\t\n};\n\n<\/pre><\/div>\n\n\n<pre class=\"wp-block-preformatted\">regions.cpp<\/pre>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\n#include &quot;regions.h&quot;\n\nRegions::Regions(const wxString &amp;title):\n\twxFrame(NULL, -1, title, wxDefaultPosition, wxSize(500,300)) {\n\tBind(wxEVT_PAINT, &amp;Regions::onPaint, this);\n\tSetBackgroundColour(wxColour(255,255,255));\n}\n\nvoid Regions::onPaint(wxPaintEvent &amp;event) {\n\twxPaintDC dc(this);\n\n\tint x1=50, x2=100,y1=80,y2=150;\n\tint prevx1 = 0, prevx2 = 0, prevy1 = 0, prevy2 = 0;\n\t\n\twxColour *color = new wxColour(40,50,100);\n\twxColour *rcolor = new wxColour(40,50,200);\n\twxPenStyle style = wxPENSTYLE_SOLID;\n\twxRegion *region1, *region2;\n\tfor(int i =10; i &lt;= 500; i+=20) {\n\t   region1 = new wxRegion(prevx1, prevy1, prevx2, prevy2);\n\t   region2 = new wxRegion(x1, y1, x2, y2);\n\n\t   if (i &lt; 100) {\n\t\tregion1-&gt;Intersect(*region2);\n\t   }\n\t   else if (i &lt; 200) {\n\t       color = new wxColour(200,145,80);\n\t       rcolor = new wxColour(20,145,80);\n\n\t       style = wxPENSTYLE_DOT;\n\t       region1-&gt;Union(*region2);\n\n\t   } else if (i &lt; 300) {\n\t       color = new wxColour(220,45,80);\n\t       rcolor = new wxColour(200,105,80);\n\t       style = wxPENSTYLE_LONG_DASH;\n\t       region1-&gt;Xor(*region2);\n\n\t   } else if (i &lt; 400) {\n\t       style = wxPENSTYLE_DOT_DASH;\n\t       color = new wxColour(220,115,180);\n\t       rcolor = new wxColour(220,115,10);\n\t       \n\t       \n\t       region1-&gt;Subtract(*region2);\n\n\t   } else {\n\t       color = new wxColour(120,35,18);\n\t       rcolor = new wxColour(220,5,180);\n\t       \n\t       style = wxPENSTYLE_SHORT_DASH;\n\t       region1-&gt;Intersect(*region2);\n\n\t   }\n\t  prevy1 = y1; prevx1 = x1; prevy2 = y2; prevx2 = x2; \n\t  dc.SetPen(wxPen(*color,1, style));\n\t  y1 += 50; x1 += 110;\n\t  y2 = y1 + 70;  x2 = x1 + 50;\n\t  dc.DrawRectangle(x1, y1, x2, y2);\n\n\t  wxRect rrect = region1-&gt;GetBox();\n\t  dc.SetClippingRegion(rrect);\n\t  dc.SetBrush(wxBrush(*rcolor));\n\t  dc.DrawRectangle(rrect);\n\t  dc.DestroyClippingRegion();\n\t}\n\n\t\n\n\n}\n\n<\/pre><\/div>\n\n\n<pre class=\"wp-block-preformatted\">main.h<\/pre>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\n#include &lt;wx\/wxprec.h&gt;\n#ifndef WX_PRECOMP\n\t#include &lt;wx\/wx.h&gt;\n#endif\n\nclass Main: public wxApp {\n\n\tpublic:\n\t\tvirtual bool OnInit();\n};\n<\/pre><\/div>\n\n\n<pre class=\"wp-block-preformatted\">main.cpp<\/pre>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\n#include &quot;main.h&quot;\n#include &quot;regions.h&quot;\n\nIMPLEMENT_APP(Main)\n\nbool Main::OnInit() {\n\tRegions *app = new Regions(wxT(&quot;Region&quot;));\n\tapp-&gt;Show(true);\n\n}\n\n<\/pre><\/div>\n\n\n<p>The output is shown below<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"940\" height=\"529\" src=\"https:\/\/truelogic.org\/wordpress\/wp-content\/uploads\/2022\/01\/Screenshot-from-2022-01-24-20-51-28-940x529.png\" alt=\"\" class=\"wp-image-4183\" srcset=\"https:\/\/truelogic.org\/wordpress\/wp-content\/uploads\/2022\/01\/Screenshot-from-2022-01-24-20-51-28-940x529.png 940w, https:\/\/truelogic.org\/wordpress\/wp-content\/uploads\/2022\/01\/Screenshot-from-2022-01-24-20-51-28-620x349.png 620w, https:\/\/truelogic.org\/wordpress\/wp-content\/uploads\/2022\/01\/Screenshot-from-2022-01-24-20-51-28-300x169.png 300w, https:\/\/truelogic.org\/wordpress\/wp-content\/uploads\/2022\/01\/Screenshot-from-2022-01-24-20-51-28-768x433.png 768w, https:\/\/truelogic.org\/wordpress\/wp-content\/uploads\/2022\/01\/Screenshot-from-2022-01-24-20-51-28-678x381.png 678w, https:\/\/truelogic.org\/wordpress\/wp-content\/uploads\/2022\/01\/Screenshot-from-2022-01-24-20-51-28.png 1330w\" sizes=\"auto, (max-width: 940px) 100vw, 940px\" \/><\/figure>\n","protected":false},"excerpt":{"rendered":"<div class=\"mh-excerpt\"><p>OVERVIEW Regions are used to change colors in certain areas of the screen by defining different regions and using one of the 4 operations available: <a class=\"mh-excerpt-more\" href=\"https:\/\/truelogic.org\/wordpress\/2022\/01\/24\/11e-wxwidgets-regions\/\" title=\"11e. wxWidgets &#8211; Regions\">[&#8230;]<\/a><\/p>\n<\/div>","protected":false},"author":1,"featured_media":3595,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[302,365],"tags":[],"class_list":["post-4182","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-cc","category-wxwidgets"],"_links":{"self":[{"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/posts\/4182","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/comments?post=4182"}],"version-history":[{"count":2,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/posts\/4182\/revisions"}],"predecessor-version":[{"id":4185,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/posts\/4182\/revisions\/4185"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/media\/3595"}],"wp:attachment":[{"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/media?parent=4182"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/categories?post=4182"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/tags?post=4182"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}