]> code.bitgloo.com Git - clyne/stmdsp.git/commitdiff
added window region painting
authorClyne Sullivan <clyne@bitgloo.com>
Sat, 13 Jun 2020 15:59:07 +0000 (11:59 -0400)
committerClyne Sullivan <clyne@bitgloo.com>
Sat, 13 Jun 2020 15:59:07 +0000 (11:59 -0400)
gui/wxmain.hpp

index 793fbc1a103cff46c8d6f38a872a7ecbb1b3c3a7..974affb76d6a53b2b2b902934b0e1bd7f213e3fd 100644 (file)
@@ -2,6 +2,7 @@
 #define WXMAIN_HPP_
 
 #include <wx/button.h>
+#include <wx/dcclient.h>
 #include <wx/frame.h>
 #include <wx/stattext.h>
 
@@ -12,6 +13,10 @@ class MainFrame : public wxFrame
         Single
     };
 
+    int m_radius = 10;
+
+    const wxRect m_clipping_region = {20, 100, 600, 360};
+
 public:
     MainFrame() : wxFrame(nullptr, -1, "Hello world", wxPoint(50, 50), wxSize(640, 480))
     {
@@ -19,11 +24,30 @@ public:
         new wxButton(this, Id::Single, "Single", wxPoint(20, 60));
 
         Bind(wxEVT_BUTTON, &MainFrame::onSinglePressed, this, Id::Single);
+        Bind(wxEVT_PAINT, &MainFrame::onPaint, this, wxID_ANY);
+    }
+
+    void onPaint([[maybe_unused]] wxPaintEvent& pe) {
+        auto *dc = new wxClientDC(this);
+        dc->SetClippingRegion(m_clipping_region);
+
+        dc->SetBrush(*wxBLACK_BRUSH);
+        dc->SetPen(*wxBLACK_PEN);
+        dc->DrawRectangle(m_clipping_region);
+
+        dc->SetPen(*wxRED_PEN);
+        dc->DrawCircle(320, 240, m_radius);
     }
 
     void onSinglePressed(wxCommandEvent& ce) {
         auto button = dynamic_cast<wxButton *>(ce.GetEventObject());
         button->SetLabel("Nice");
+        updateDrawing();
+    }
+
+    void updateDrawing() {
+        m_radius += 10;
+        this->RefreshRect(m_clipping_region);
     }
 };