Created
April 5, 2021 20:44
-
-
Save tomay3000/1622eff72aaa0fd77ae8ed57e204fcc9 to your computer and use it in GitHub Desktop.
minimal 2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/samples/minimal/minimal.cpp b/samples/minimal/minimal.cpp | |
index 65da9f35b6..9ea46da6fc 100644 | |
--- a/samples/minimal/minimal.cpp | |
+++ b/samples/minimal/minimal.cpp | |
@@ -29,6 +29,8 @@ | |
#include "wx/wx.h" | |
#endif | |
+#include <wx/artprov.h> | |
+ | |
// ---------------------------------------------------------------------------- | |
// resources | |
// ---------------------------------------------------------------------------- | |
@@ -67,6 +69,23 @@ public: | |
void OnQuit(wxCommandEvent& event); | |
void OnAbout(wxCommandEvent& event); | |
+private: | |
+ wxStaticBitmap *m_pBitmap1; | |
+ wxSlider *m_pSlider1; | |
+ wxSlider *m_pSlider2; | |
+ wxSlider *m_pSlider3; | |
+ wxSlider *m_pSlider4; | |
+ wxImage m_image; | |
+ | |
+protected: | |
+ void ChangeHSVL(); | |
+ | |
+ // Virtual event handlers, overide them in your derived class | |
+ virtual void OnSlider1(wxCommandEvent& event); | |
+ virtual void OnSlider2(wxCommandEvent& event); | |
+ virtual void OnSlider3(wxCommandEvent& event); | |
+ virtual void OnSlider4(wxCommandEvent& event); | |
+ | |
private: | |
// any class wishing to process wxWidgets events must use this macro | |
wxDECLARE_EVENT_TABLE(); | |
@@ -178,8 +197,78 @@ MyFrame::MyFrame(const wxString& title) | |
CreateStatusBar(2); | |
SetStatusText("Welcome to wxWidgets!"); | |
#endif // wxUSE_STATUSBAR | |
+ | |
+ wxBitmap bmp = wxArtProvider::GetBitmap(wxART_INFORMATION, wxART_BUTTON, wxSize(256, 256)); | |
+ m_image = bmp.ConvertToImage(); | |
+ | |
+ wxBoxSizer *pBoxSizer1; | |
+ pBoxSizer1 = new wxBoxSizer(wxVERTICAL); | |
+ m_pBitmap1 = new wxStaticBitmap(this, wxID_ANY, bmp); | |
+ pBoxSizer1->Add(m_pBitmap1, 1, wxALL | wxALIGN_CENTER_HORIZONTAL, 5); | |
+ wxStaticBoxSizer *pStcBoxSizer1; | |
+ pStcBoxSizer1 = new wxStaticBoxSizer(new wxStaticBox(this, wxID_ANY, wxT("Hue (°)")), wxHORIZONTAL); | |
+ m_pSlider1 = new wxSlider(pStcBoxSizer1->GetStaticBox(), wxID_ANY, 0, -360, 360, wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL | wxSL_LABELS); | |
+ pStcBoxSizer1->Add(m_pSlider1, 1, wxALL | wxALIGN_CENTER_VERTICAL, 5); | |
+ pBoxSizer1->Add(pStcBoxSizer1, 0, wxEXPAND, 5); | |
+ wxStaticBoxSizer *pStcBoxSizer2; | |
+ pStcBoxSizer2 = new wxStaticBoxSizer(new wxStaticBox(this, wxID_ANY, wxT("Saturation (%)")), wxHORIZONTAL); | |
+ m_pSlider2 = new wxSlider(pStcBoxSizer2->GetStaticBox(), wxID_ANY, 0, -100, 100, wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL | wxSL_LABELS); | |
+ pStcBoxSizer2->Add(m_pSlider2, 1, wxALL | wxALIGN_CENTER_VERTICAL, 5); | |
+ pBoxSizer1->Add(pStcBoxSizer2, 0, wxEXPAND, 5); | |
+ wxStaticBoxSizer *pStcBoxSizer3; | |
+ pStcBoxSizer3 = new wxStaticBoxSizer(new wxStaticBox(this, wxID_ANY, wxT("Brightness (value) (%)")), wxHORIZONTAL); | |
+ m_pSlider3 = new wxSlider(pStcBoxSizer3->GetStaticBox(), wxID_ANY, 0, -100, 100, wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL | wxSL_LABELS); | |
+ pStcBoxSizer3->Add(m_pSlider3, 1, wxALL | wxALIGN_CENTER_VERTICAL, 5); | |
+ pBoxSizer1->Add(pStcBoxSizer3, 0, wxEXPAND, 5); | |
+ wxStaticBoxSizer *pStcBoxSizer4; | |
+ pStcBoxSizer4 = new wxStaticBoxSizer(new wxStaticBox(this, wxID_ANY, wxT("Lightness (via wxColour::ChangeLightness())")), wxHORIZONTAL); | |
+ m_pSlider4 = new wxSlider(pStcBoxSizer4->GetStaticBox(), wxID_ANY, 100, 0, 200, wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL | wxSL_LABELS); | |
+ pStcBoxSizer4->Add(m_pSlider4, 1, wxALL | wxALIGN_CENTER_VERTICAL, 5); | |
+ pBoxSizer1->Add(pStcBoxSizer4, 0, wxEXPAND, 5); | |
+ SetSizer(pBoxSizer1); | |
+ | |
+ // Connect Events | |
+ m_pSlider1->Connect(wxEVT_SLIDER, wxCommandEventHandler(MyFrame::OnSlider1), NULL, this); | |
+ m_pSlider2->Connect(wxEVT_SLIDER, wxCommandEventHandler(MyFrame::OnSlider2), NULL, this); | |
+ m_pSlider3->Connect(wxEVT_SLIDER, wxCommandEventHandler(MyFrame::OnSlider3), NULL, this); | |
+ m_pSlider4->Connect(wxEVT_SLIDER, wxCommandEventHandler(MyFrame::OnSlider4), NULL, this); | |
+} | |
+ | |
+void MyFrame::ChangeHSVL() | |
+{ | |
+ double angleH = m_pSlider1->GetValue() / 360.; | |
+ double factorS = m_pSlider2->GetValue() / 100.; | |
+ double factorV = m_pSlider3->GetValue() / 100.; | |
+ int ialpha = m_pSlider4->GetValue(); | |
+ wxImage image = m_image; | |
+ image.ChangeHSV(angleH, factorS, factorV); | |
+ image = image.ChangeLightness(ialpha); | |
+ m_pBitmap1->SetBitmap(image); | |
+} | |
+ | |
+void MyFrame::OnSlider1(wxCommandEvent& event) | |
+{ | |
+ ChangeHSVL(); | |
+ event.Skip(); | |
} | |
+void MyFrame::OnSlider2(wxCommandEvent& event) | |
+{ | |
+ ChangeHSVL(); | |
+ event.Skip(); | |
+} | |
+ | |
+void MyFrame::OnSlider3(wxCommandEvent& event) | |
+{ | |
+ ChangeHSVL(); | |
+ event.Skip(); | |
+} | |
+ | |
+void MyFrame::OnSlider4(wxCommandEvent& event) | |
+{ | |
+ ChangeHSVL(); | |
+ event.Skip(); | |
+} | |
// event handlers | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment