From afb2ff85cfb5bca48995d6ddd354949d5207e848 Mon Sep 17 00:00:00 2001 From: Travis Hunter Date: Sat, 11 Feb 2023 17:41:55 -0700 Subject: [PATCH] MainWindow now uses splitters --- CMakeLists.txt | 12 ++--- src/gui/CMakeLists.txt | 4 +- src/gui/MainWindow.cpp | 107 +++++++++++++++++++++++++++++++++++++++++ src/gui/MainWindow.h | 26 ++++++++++ src/gui/main.cpp | 61 ++--------------------- 5 files changed, 145 insertions(+), 65 deletions(-) create mode 100644 src/gui/MainWindow.cpp create mode 100644 src/gui/MainWindow.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 030c9b3..9b4a285 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,12 +13,12 @@ if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) include(CTest) - find_package(Doxygen) - if(Doxygen_FOUND) - add_subdirectory(docs) - else() - message(STATUS "Doxygen not found, not building docs") - endif() + #find_package(Doxygen) + #if(Doxygen_FOUND) + # add_subdirectory(docs) + #else() + # message(STATUS "Doxygen not found, not building docs") + #endif() endif() enable_testing() diff --git a/src/gui/CMakeLists.txt b/src/gui/CMakeLists.txt index d640cae..67336b7 100644 --- a/src/gui/CMakeLists.txt +++ b/src/gui/CMakeLists.txt @@ -1,5 +1,7 @@ find_package(wxWidgets REQUIRED gl core base) include(${wxWidgets_USE_FILE}) -add_executable(wxRocket main.cpp) +add_executable(wxRocket + main.cpp + MainWindow.cpp) target_link_libraries(wxRocket PRIVATE ${wxWidgets_LIBRARIES}) diff --git a/src/gui/MainWindow.cpp b/src/gui/MainWindow.cpp new file mode 100644 index 0000000..5c659e3 --- /dev/null +++ b/src/gui/MainWindow.cpp @@ -0,0 +1,107 @@ +#include "MainWindow.h" + +#include +#include + +namespace gui +{ + +MainWindowFrame::MainWindowFrame() + : wxFrame(nullptr, wxID_ANY, "wxRocket", wxDefaultPosition, wxDefaultSize) +{ + // Add a File menu + wxMenu* fileMenu = new wxMenu; + fileMenu->Append(wxID_NEW); + fileMenu->AppendSeparator(); + fileMenu->Append(wxID_EXIT); + + // Add an Edit menu + wxMenu* editMenu = new wxMenu; + // Add a Tools menu + wxMenu* toolsMenu = new wxMenu; + + // Add a Help menu + wxMenu* helpMenu = new wxMenu; + helpMenu->Append(wxID_ABOUT); + + wxMenuBar* menuBar = new wxMenuBar; + menuBar->Append(fileMenu, _("&File")); + menuBar->Append(editMenu, _("&Edit")); + menuBar->Append(toolsMenu, _("&Tools")); + menuBar->Append(helpMenu, _("&Help")); + + SetMenuBar(menuBar); + CreateStatusBar(); + SetStatusText(_("Welcome to wxRocket!")); + + wxToolBar* toolbar = CreateToolBar(); + toolbar->AddTool(wxID_NEW, _("New"), wxArtProvider::GetBitmap("wxART_NEW")); + toolbar->Realize(); + + // Create the layout + + // Create the splitter window, then we can add panels to it + wxSplitterWindow* windowSplitter = new wxSplitterWindow(this, + wxID_ANY, + wxDefaultPosition, + wxDefaultSize, + wxSP_BORDER | wxSP_LIVE_UPDATE); + windowSplitter->SetMinimumPaneSize(200); + //wxSplitterWindow* topSplitter = new wxSplitterWindow(this); + + + // NOTE, we never call delete manually on the panel since setting the parent pointer (this) + // will put the onus on the parent to manage the resource. It'll get deleted + // when the parent gets deleted. In this case the MainWindowFrame + wxPanel* rocketTreePanel = new wxPanel(windowSplitter, + wxID_ANY, + wxDefaultPosition, + wxSize(200, 100)); + rocketTreePanel->SetBackgroundColour(wxColor(100, 100, 200)); + + wxPanel* rocketComponentPanel = new wxPanel(windowSplitter, + wxID_ANY, + wxDefaultPosition, + wxSize(200, 100)); + rocketComponentPanel->SetBackgroundColour(wxColor(200, 100, 100)); + + windowSplitter->SplitVertically(rocketTreePanel, rocketComponentPanel); +/* + wxSizer* rocketDesignSizer = new wxBoxSizer(wxHORIZONTAL); + rocketDesignSizer->Add(rocketTreePanel, 1, wxEXPAND | wxRIGHT, 2); + rocketDesignSizer->Add(rocketComponentPanel, 1, wxEXPAND); +*/ + +/* + wxPanel* rocketVisPanel = new wxPanel(this, wxID_ANY); + rocketVisPanel->SetBackgroundColour(wxColor(100, 200, 100)); +*/ + +// wxBoxSizer* mainSizer = new wxBoxSizer(wxVERTICAL); +// mainSizer->Add(rocketDesignSizer, 2, wxEXPAND | wxALL, 2); +// mainSizer->Add(rocketVisPanel, 1, wxEXPAND | wxLEFT | wxBOTTOM | wxRIGHT, 2); +// this->SetSizerAndFit(mainSizer); + /* + SetSizer(mainSizer); + wxTextCtrl* firstNameBox = new wxTextCtrl(this, wxID_ANY); + mainSizer->Add(firstNameBox, 1, wxEXPAND); + */ + + + Bind(wxEVT_MENU, &MainWindowFrame::onAbout, this, wxID_ABOUT); + Bind(wxEVT_MENU, &MainWindowFrame::onExit, this, wxID_EXIT); + +} + +void MainWindowFrame::onExit(wxCommandEvent& evt) +{ + Close(true); +} + +void MainWindowFrame::onAbout(wxCommandEvent& evt) +{ + wxMessageBox(_("This is wxRocket. (c) 2023 by Travis Hunter"), + _("About wxRocket"), wxOK | wxICON_INFORMATION); +} + +} \ No newline at end of file diff --git a/src/gui/MainWindow.h b/src/gui/MainWindow.h new file mode 100644 index 0000000..0963a5d --- /dev/null +++ b/src/gui/MainWindow.h @@ -0,0 +1,26 @@ +#ifndef GUI_MAINWINDOW_H +#define GUI_MAINWINDOW_H + +#include +#ifndef WX_PRECOMP + #include +#endif + +namespace gui +{ + +class MainWindowFrame : public wxFrame +{ +public: + MainWindowFrame(); + +private: + void onExit(wxCommandEvent& evt); + void onAbout(wxCommandEvent& evt); + +}; + + +} + +#endif // GUI_MAINWINDOW_H \ No newline at end of file diff --git a/src/gui/main.cpp b/src/gui/main.cpp index 850de2f..152c977 100644 --- a/src/gui/main.cpp +++ b/src/gui/main.cpp @@ -6,6 +6,8 @@ #include #endif +#include "MainWindow.h" + class wxRocket : public wxApp { public: @@ -16,69 +18,12 @@ public: }; -class MainWindowFrame : public wxFrame -{ -public: - MainWindowFrame(); - -private: - void onExit(wxCommandEvent& evt); - void onAbout(wxCommandEvent& evt); - -}; - - bool wxRocket::OnInit() { - MainWindowFrame* frame = new MainWindowFrame; + gui::MainWindowFrame* frame = new gui::MainWindowFrame; frame->Show(true); return true; } -MainWindowFrame::MainWindowFrame() - : wxFrame(nullptr, wxID_ANY, "wxRocket") -{ - // Add a File menu - wxMenu* fileMenu = new wxMenu; - fileMenu->Append(wxID_NEW); - fileMenu->AppendSeparator(); - fileMenu->Append(wxID_EXIT); - - // Add an Edit menu - wxMenu* editMenu = new wxMenu; - // Add a Tools menu - wxMenu* toolsMenu = new wxMenu; - - // Add a Help menu - wxMenu* helpMenu = new wxMenu; - helpMenu->Append(wxID_ABOUT); - - wxMenuBar* menuBar = new wxMenuBar; - menuBar->Append(fileMenu, _("&File")); - menuBar->Append(editMenu, _("&Edit")); - menuBar->Append(toolsMenu, _("&Tools")); - menuBar->Append(helpMenu, _("&Help")); - - SetMenuBar(menuBar); - - CreateStatusBar(); - SetStatusText(_("Welcome to wxRocket!")); - - Bind(wxEVT_MENU, &MainWindowFrame::onAbout, this, wxID_ABOUT); - Bind(wxEVT_MENU, &MainWindowFrame::onExit, this, wxID_EXIT); - -} - -void MainWindowFrame::onExit(wxCommandEvent& evt) -{ - Close(true); -} - -void MainWindowFrame::onAbout(wxCommandEvent& evt) -{ - wxMessageBox(_("This is wxRocket. (c) 2023 by Travis Hunter"), - _("About wxRocket"), wxOK | wxICON_INFORMATION); -} - // This will build the main function wxIMPLEMENT_APP(wxRocket); \ No newline at end of file