{"id":4158,"date":"2022-01-24T14:34:22","date_gmt":"2022-01-24T14:34:22","guid":{"rendered":"http:\/\/truelogic.org\/wordpress\/?p=4158"},"modified":"2022-01-24T14:34:23","modified_gmt":"2022-01-24T14:34:23","slug":"wxwidgets-11a-drawing-lines","status":"publish","type":"post","link":"https:\/\/truelogic.org\/wordpress\/2022\/01\/24\/wxwidgets-11a-drawing-lines\/","title":{"rendered":"wxWidgets &#8211; 11a.Drawing Lines"},"content":{"rendered":"\n<p><strong>OVERVIEW<\/strong><\/p>\n\n\n\n<p>We use the <em>DrawLine()<\/em> method to draw straight lines on the screen. All GDI methods work by overriding the <em>wxEVT_PAINT<\/em> method. The <em>DrawLine<\/em> method takes in the starting x.y coordinates and ending x,y coordinates. <\/p>\n\n\n\n<p><strong>SAMPLE CODE<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">line.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 Line: public wxFrame {\n\tpublic:\n\t\tLine(const wxString &amp;title);\n\t\tvoid onPaint(wxPaintEvent &amp;event);\n\n};\n\n\n<\/pre><\/div>\n\n\n<pre class=\"wp-block-preformatted\">line.cpp<\/pre>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\n#include &quot;line.h&quot;\n\nLine::Line(const wxString &amp;title):\n\twxFrame(NULL, -1, title, wxDefaultPosition, wxSize(500,300)) {\n\n\tBind(wxEVT_PAINT, &amp;Line::onPaint, this);\n}\n\nvoid Line::onPaint(wxPaintEvent &amp;event) {\n\twxPaintDC dc(this);\n\tint x1=5, x2=270,y1=80,y2=0;\n\tfor(int i =10; i &lt;= 500; i+=20) {\n\n\t\ty2= y1+i;\n\t\tdc.DrawLine(x1, y1, x2, y2);\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\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;line.h&quot;\n\nIMPLEMENT_APP(Main)\n\nbool Main::OnInit() {\n\tLine *app = new Line(wxT(&quot;Lines&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=\"572\" height=\"636\" src=\"https:\/\/truelogic.org\/wordpress\/wp-content\/uploads\/2022\/01\/Screenshot-from-2022-01-24-20-03-29.png\" alt=\"\" class=\"wp-image-4161\" srcset=\"https:\/\/truelogic.org\/wordpress\/wp-content\/uploads\/2022\/01\/Screenshot-from-2022-01-24-20-03-29.png 572w, https:\/\/truelogic.org\/wordpress\/wp-content\/uploads\/2022\/01\/Screenshot-from-2022-01-24-20-03-29-300x334.png 300w\" sizes=\"auto, (max-width: 572px) 100vw, 572px\" \/><\/figure>\n","protected":false},"excerpt":{"rendered":"<div class=\"mh-excerpt\"><p>OVERVIEW We use the DrawLine() method to draw straight lines on the screen. All GDI methods work by overriding the wxEVT_PAINT method. The DrawLine method <a class=\"mh-excerpt-more\" href=\"https:\/\/truelogic.org\/wordpress\/2022\/01\/24\/wxwidgets-11a-drawing-lines\/\" title=\"wxWidgets &#8211; 11a.Drawing Lines\">[&#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-4158","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\/4158","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=4158"}],"version-history":[{"count":4,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/posts\/4158\/revisions"}],"predecessor-version":[{"id":4163,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/posts\/4158\/revisions\/4163"}],"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=4158"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/categories?post=4158"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/tags?post=4158"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}