{"id":4187,"date":"2022-01-24T16:07:46","date_gmt":"2022-01-24T16:07:46","guid":{"rendered":"http:\/\/truelogic.org\/wordpress\/?p=4187"},"modified":"2025-09-28T15:41:28","modified_gmt":"2025-09-28T15:41:28","slug":"11f-wxwidgets-gradient","status":"publish","type":"post","link":"https:\/\/truelogic.org\/wordpress\/2022\/01\/24\/11f-wxwidgets-gradient\/","title":{"rendered":"11f.wxWidgets &#8211; Gradient"},"content":{"rendered":"\n<p><strong>OVERVIEW<\/strong><\/p>\n\n\n\n<p>A Gradient is a  gradual transition in a color from one shade to another. This is useful for complex coloring and effects. wxWidgets provides two kinds of gradients:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>GradientFillLinear<\/li>\n\n\n\n<li>GradientFillConcentric<\/li>\n<\/ul>\n\n\n\n<p><em>GradientFillLinear<\/em><strong> <\/strong>implements the gradient in a straight linear line from one side of the container to another. <em>GradientFillConcentric <\/em>implements the gradient in a circular concentric path starting from the innermost circle to the outermost circle <\/p>\n\n\n\n<p>The sample code below shows both the gradient types <\/p>\n\n\n\n<p><strong>SAMPLE CODE<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">gradient.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 Gradients: public wxFrame {\n\tpublic:\n\t\tGradients(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\">gradients.cpp<\/pre>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\n#include &quot;gradients.h&quot;\n\nGradients::Gradients(const wxString &amp;title):\n\twxFrame(NULL, -1, title, wxDefaultPosition, wxSize(900,600)) {\n\tBind(wxEVT_PAINT, &amp;Gradients::onPaint, this);\n\tSetBackgroundColour(wxColour(255,255,255));\n}\n\nvoid Gradients::onPaint(wxPaintEvent &amp;event) {\n\twxPaintDC dc(this);\n\n\t wxColour *color1 = new wxColour(40,50,100);\n\twxColour *color2 = new wxColour(90,150,200);\n\n\twxColour *color3 = new wxColour(190,150,200);\n\twxColour *color4 = new wxColour(0,0,160);\n\n    wxColour *color5 = new wxColour(114,50,100);\n    wxColour *color6 = new wxColour(50,30,200);\n\n\tdc.GradientFillLinear(wxRect(10, 10, 180, 100), *color1, *color2, wxNORTH);\n\tdc.GradientFillLinear(wxRect(110, 10, 180, 100), *color1, *color2, wxSOUTH);\n\tdc.GradientFillLinear(wxRect(210, 120, 280, 100), *color1, *color2, wxEAST);\n\tdc.GradientFillLinear(wxRect(110, 220, 180, 400), *color1, *color2, wxWEST);\n\n\tdc.GradientFillConcentric(wxRect(290, 210, 280, 300), *color3, *color4);\n\tdc.GradientFillConcentric(wxRect(430, 210, 480, 400), *color5, *color6);\n\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;gradients.h&quot;\n\nIMPLEMENT_APP(Main)\n\nbool Main::OnInit() {\n\tGradients *app = new Gradients(wxT(&quot;Gradients&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-full\"><img loading=\"lazy\" decoding=\"async\" width=\"851\" height=\"545\" src=\"https:\/\/truelogic.org\/wordpress\/wp-content\/uploads\/2022\/01\/Screenshot-from-2025-09-28-21-10-58.png\" alt=\"\" class=\"wp-image-4693\" srcset=\"https:\/\/truelogic.org\/wordpress\/wp-content\/uploads\/2022\/01\/Screenshot-from-2025-09-28-21-10-58.png 851w, https:\/\/truelogic.org\/wordpress\/wp-content\/uploads\/2022\/01\/Screenshot-from-2025-09-28-21-10-58-620x397.png 620w, https:\/\/truelogic.org\/wordpress\/wp-content\/uploads\/2022\/01\/Screenshot-from-2025-09-28-21-10-58-300x192.png 300w, https:\/\/truelogic.org\/wordpress\/wp-content\/uploads\/2022\/01\/Screenshot-from-2025-09-28-21-10-58-768x492.png 768w\" sizes=\"auto, (max-width: 851px) 100vw, 851px\" \/><\/figure>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"mh-excerpt\"><p>OVERVIEW A Gradient is a gradual transition in a color from one shade to another. This is useful for complex coloring and effects. wxWidgets provides <a class=\"mh-excerpt-more\" href=\"https:\/\/truelogic.org\/wordpress\/2022\/01\/24\/11f-wxwidgets-gradient\/\" title=\"11f.wxWidgets &#8211; Gradient\">[&#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-4187","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\/4187","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=4187"}],"version-history":[{"count":6,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/posts\/4187\/revisions"}],"predecessor-version":[{"id":4694,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/posts\/4187\/revisions\/4694"}],"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=4187"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/categories?post=4187"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/tags?post=4187"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}