Created
April 5, 2025 18:02
-
-
Save proffix4/69ca0f989886f4e7a81936b37ec647e2 to your computer and use it in GitHub Desktop.
drawing in wxwidgets
This file contains hidden or 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
| #include <wx/wx.h> | |
| class MyPanel : public wxPanel // Панель для рисования | |
| { | |
| public: | |
| MyPanel(wxWindow* parent) : wxPanel(parent, wxID_ANY) { | |
| // Регистрируем обработчик события рисования | |
| Bind(wxEVT_PAINT, &MyPanel::OnPaint, this); | |
| } | |
| private: | |
| void OnPaint(wxPaintEvent& event) | |
| { | |
| wxPaintDC dc(this); // Создаём контекст рисования | |
| // 1. Настраиваем перо и кисть | |
| dc.SetPen(*wxBLUE_PEN); // Устанавливаем синее перо | |
| dc.SetBrush(*wxGREEN_BRUSH); // Устанавливаем зелёную кисть | |
| // 2. Рисуем прямоугольник | |
| dc.DrawRectangle(10, 10, 100, 50); | |
| // 3. Рисуем окружность | |
| dc.SetBrush(*wxCYAN_BRUSH); // Устанавливаем голубую кисть | |
| dc.DrawCircle(150, 60, 30); // Рисуем окружность | |
| // 4. Выводим текст | |
| dc.SetFont(wxFontInfo(12).Bold().FaceName("Arial")); // Устанавливаем шрифт | |
| dc.SetTextForeground(*wxRED); // Устанавливаем красный цвет текста | |
| dc.DrawText(L"Привет, wxDC!", 10, 80); // Выводим текст | |
| // 5. Рисуем линию | |
| dc.SetPen(*wxBLACK_PEN); // Устанавливаем черное перо | |
| dc.DrawLine(0, 0, 200, 100); // Рисуем линию | |
| } | |
| }; | |
| class MyFrame : public wxFrame { | |
| public: | |
| MyFrame() | |
| : wxFrame(nullptr, wxID_ANY, L"Пример EVT_PAINT", wxDefaultPosition, wxSize(400, 300)) | |
| { | |
| CreateStatusBar(); | |
| SetStatusText(L"Сверните/разверните окно, чтобы вызвать перерисовку"); | |
| SetBackgroundColour(*wxWHITE); | |
| Centre(); | |
| new MyPanel(this); // Добавляем панель, где рисуем | |
| } | |
| }; | |
| class MyApp : public wxApp { | |
| public: | |
| virtual bool OnInit() { | |
| MyFrame* frame = new MyFrame(); | |
| frame->Show(true); | |
| return true; | |
| } | |
| }; | |
| wxIMPLEMENT_APP_NO_MAIN(MyApp); | |
| int main(int argc, char** argv) | |
| { | |
| wxEntry(argc, argv); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment