{"id":4177,"date":"2022-01-24T15:15:01","date_gmt":"2022-01-24T15:15:01","guid":{"rendered":"http:\/\/truelogic.org\/wordpress\/?p=4177"},"modified":"2022-01-24T15:15:02","modified_gmt":"2022-01-24T15:15:02","slug":"11d-wxwidgets-the-pen-object","status":"publish","type":"post","link":"https:\/\/truelogic.org\/wordpress\/2022\/01\/24\/11d-wxwidgets-the-pen-object\/","title":{"rendered":"11d.wxWidgets &#8211; The Pen Object"},"content":{"rendered":"\n<p><strong>OVERVIEW<\/strong><\/p>\n\n\n\n<p>All drawing is done by the<em> wxPen<\/em> object. A pen object can configure color, width and style . Styles can be as shown below<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>wxSOLID<\/li><li>wxDOT<\/li><li>wxLONG_DASH<\/li><li>wxSHORT_DASH<\/li><li>wxDOT_DASH<\/li><li>wxTRANSPARENT<\/li><\/ul>\n\n\n\n<p>In the sample code below, we draw rectangles using various parameters with the <em>wxPen<\/em> object<\/p>\n\n\n\n<p><strong>SAMPLE CODE<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">pens.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 Pens: public wxFrame {\n\tpublic:\n\t\tPens(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\">pens.cpp<\/pre>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\n#include &quot;pens.h&quot;\n\nPens::Pens(const wxString &amp;title):\n\twxFrame(NULL, -1, title, wxDefaultPosition, wxSize(500,300)) {\n\tsrand(time(NULL));\n\tBind(wxEVT_PAINT, &amp;Pens::onPaint, this);\n\tSetBackgroundColour(wxColour(255,255,255));\n}\n\nvoid Pens::onPaint(wxPaintEvent &amp;event) {\n\twxPaintDC dc(this);\n\n\tint x1=50, x2=100,y1=80,y2=150;\n\twxColour *color = new wxColour(40,50,100);\n\twxPenStyle style = wxPENSTYLE_SOLID;\n\t\n\tfor(int i =10; i &lt;= 500; i+=20) {\n\t   if (i &lt; 100) {\n\t      \/\/ do nothing\n\t   }\n\t   else if (i &lt; 200) {\n\t       color = new wxColour(200,145,80);\n\t       style = wxPENSTYLE_DOT;\n\t   } else if (i &lt; 300) {\n\t       color = new wxColour(220,45,80);\n\t       style = wxPENSTYLE_LONG_DASH;\n\t   } else if (i &lt; 400) {\n\t       style = wxPENSTYLE_DOT_DASH;\n\t       color = new wxColour(220,115,180);\n\t   } else {\n\t       color = new wxColour(120,35,18);\n\t       style = wxPENSTYLE_SHORT_DASH;\n\t   }\n\t  dc.SetPen(wxPen(*color,1, style));\n\t  y1 += 10; x1 += 10;\n\t  y2 = y1 + 70;  x2 = x1 + 50;\n\t  dc.DrawRectangle(x1, y1, x2, y2);\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;pens.h&quot;\n\nIMPLEMENT_APP(Main)\n\nbool Main::OnInit() {\n\tPens *app = new Pens(wxT(&quot;Pen&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=\"663\" src=\"https:\/\/truelogic.org\/wordpress\/wp-content\/uploads\/2022\/01\/Screenshot-from-2022-01-24-20-44-12-940x663.png\" alt=\"\" class=\"wp-image-4179\" srcset=\"https:\/\/truelogic.org\/wordpress\/wp-content\/uploads\/2022\/01\/Screenshot-from-2022-01-24-20-44-12-940x663.png 940w, https:\/\/truelogic.org\/wordpress\/wp-content\/uploads\/2022\/01\/Screenshot-from-2022-01-24-20-44-12-620x437.png 620w, https:\/\/truelogic.org\/wordpress\/wp-content\/uploads\/2022\/01\/Screenshot-from-2022-01-24-20-44-12-300x212.png 300w, https:\/\/truelogic.org\/wordpress\/wp-content\/uploads\/2022\/01\/Screenshot-from-2022-01-24-20-44-12-768x542.png 768w, https:\/\/truelogic.org\/wordpress\/wp-content\/uploads\/2022\/01\/Screenshot-from-2022-01-24-20-44-12.png 995w\" sizes=\"auto, (max-width: 940px) 100vw, 940px\" \/><\/figure>\n","protected":false},"excerpt":{"rendered":"<div class=\"mh-excerpt\"><p>OVERVIEW All drawing is done by the wxPen object. A pen object can configure color, width and style . Styles can be as shown below <a class=\"mh-excerpt-more\" href=\"https:\/\/truelogic.org\/wordpress\/2022\/01\/24\/11d-wxwidgets-the-pen-object\/\" title=\"11d.wxWidgets &#8211; The Pen Object\">[&#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-4177","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\/4177","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=4177"}],"version-history":[{"count":2,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/posts\/4177\/revisions"}],"predecessor-version":[{"id":4180,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/posts\/4177\/revisions\/4180"}],"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=4177"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/categories?post=4177"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/tags?post=4177"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}