From 6dc66f8d131e7ff60f34ff0588c62b63c8d5ed31 Mon Sep 17 00:00:00 2001 From: yum Date: Fri, 16 Dec 2022 16:22:48 -0800 Subject: Refactor app Create headers & implementation files for App and Frame. --- GUI/GUI/GUI/App.cpp | 10 ++++++ GUI/GUI/GUI/App.h | 13 ++++++++ GUI/GUI/GUI/Frame.cpp | 27 +++++++++++++++ GUI/GUI/GUI/Frame.h | 20 +++++++++++ GUI/GUI/GUI/GUI.vcxproj | 4 +++ GUI/GUI/GUI/GUI.vcxproj.filters | 12 +++++++ GUI/GUI/GUI/main.cpp | 74 +---------------------------------------- 7 files changed, 87 insertions(+), 73 deletions(-) create mode 100644 GUI/GUI/GUI/App.cpp create mode 100644 GUI/GUI/GUI/App.h create mode 100644 GUI/GUI/GUI/Frame.cpp create mode 100644 GUI/GUI/GUI/Frame.h (limited to 'GUI') diff --git a/GUI/GUI/GUI/App.cpp b/GUI/GUI/GUI/App.cpp new file mode 100644 index 0000000..8456447 --- /dev/null +++ b/GUI/GUI/GUI/App.cpp @@ -0,0 +1,10 @@ +#include "App.h" +#include "Frame.h" + +bool MyApp::OnInit() +{ + Frame* frame = new Frame(); + frame->Show(true); + + return true; +} diff --git a/GUI/GUI/GUI/App.h b/GUI/GUI/GUI/App.h new file mode 100644 index 0000000..fe6eeec --- /dev/null +++ b/GUI/GUI/GUI/App.h @@ -0,0 +1,13 @@ +#pragma once + +#include + +#ifndef WX_PRECOMP +#include +#endif + +class MyApp : public wxApp +{ +public: + virtual bool OnInit(); +}; diff --git a/GUI/GUI/GUI/Frame.cpp b/GUI/GUI/GUI/Frame.cpp new file mode 100644 index 0000000..841bfb9 --- /dev/null +++ b/GUI/GUI/GUI/Frame.cpp @@ -0,0 +1,27 @@ +#include "Frame.h" + +#include + +Frame::Frame() + : wxFrame(nullptr, wxID_ANY, "TaSTT") +{ + Bind(wxEVT_MENU, &Frame::OnExit, this, wxID_EXIT); + + // wx needs this to be able to load PNGs. + wxImage::AddHandler(&png_handler_); + + const std::string logo_path = "Resources/logo.png"; + if (!std::filesystem::exists(logo_path)) { + wxLogFatalError("Logo is missing from %s", logo_path.c_str()); + } + wxBitmap icon_img("Resources/logo.png", wxBITMAP_TYPE_PNG); + wxIcon icon; + icon.CopyFromBitmap(icon_img); + SetIcon(icon); +} + +void Frame::OnExit(wxCommandEvent& event) +{ + Close(true); +} + diff --git a/GUI/GUI/GUI/Frame.h b/GUI/GUI/GUI/Frame.h new file mode 100644 index 0000000..4dcfd4a --- /dev/null +++ b/GUI/GUI/GUI/Frame.h @@ -0,0 +1,20 @@ +#pragma once + +#include + +#ifndef WX_PRECOMP +#include +#endif + +class Frame : public wxFrame +{ +public: + Frame(); + +private: + wxPNGHandler png_handler_; + + void OnHello(wxCommandEvent& event); + void OnExit(wxCommandEvent& event); + void OnAbout(wxCommandEvent& event); +}; diff --git a/GUI/GUI/GUI/GUI.vcxproj b/GUI/GUI/GUI/GUI.vcxproj index e97523c..79bb220 100644 --- a/GUI/GUI/GUI/GUI.vcxproj +++ b/GUI/GUI/GUI/GUI.vcxproj @@ -135,9 +135,13 @@ + + + + diff --git a/GUI/GUI/GUI/GUI.vcxproj.filters b/GUI/GUI/GUI/GUI.vcxproj.filters index beb1941..c332693 100644 --- a/GUI/GUI/GUI/GUI.vcxproj.filters +++ b/GUI/GUI/GUI/GUI.vcxproj.filters @@ -18,10 +18,22 @@ Source Files + + Source Files + + + Source Files + Source Files + + Source Files + + + Source Files + \ No newline at end of file diff --git a/GUI/GUI/GUI/main.cpp b/GUI/GUI/GUI/main.cpp index c2e0222..d9303f5 100644 --- a/GUI/GUI/GUI/main.cpp +++ b/GUI/GUI/GUI/main.cpp @@ -1,4 +1,4 @@ -// wxWidgets "Hello World" Program +#include "App.h" #include @@ -6,77 +6,5 @@ #include #endif -#include "ScopeGuard.h" - -#include - -class MyApp : public wxApp -{ -public: - virtual bool OnInit(); -}; - -class MyFrame : public wxFrame -{ -public: - MyFrame(); - -private: - wxPNGHandler png_handler_; - - void OnHello(wxCommandEvent& event); - void OnExit(wxCommandEvent& event); - void OnAbout(wxCommandEvent& event); -}; - -enum -{ - ID_Hello = 1 -}; - wxIMPLEMENT_APP(MyApp); -bool MyApp::OnInit() -{ - MyFrame* frame = new MyFrame(); - frame->Show(true); - - return true; -} - -MyFrame::MyFrame() - : wxFrame(nullptr, wxID_ANY, "TaSTT") -{ - Bind(wxEVT_MENU, &MyFrame::OnHello, this, ID_Hello); - Bind(wxEVT_MENU, &MyFrame::OnAbout, this, wxID_ABOUT); - Bind(wxEVT_MENU, &MyFrame::OnExit, this, wxID_EXIT); - - // wx needs this to be able to load PNGs. - wxImage::AddHandler(&png_handler_); - - const std::string logo_path = "Resources/logo.png"; - if (!std::filesystem::exists(logo_path)) { - wxLogFatalError("Logo is missing from %s", logo_path.c_str()); - } - wxBitmap icon_img("Resources/logo.png", wxBITMAP_TYPE_PNG); - wxIcon icon; - icon.CopyFromBitmap(icon_img); - SetIcon(icon); -} - -void MyFrame::OnExit(wxCommandEvent& event) -{ - Close(true); -} - -void MyFrame::OnAbout(wxCommandEvent& event) -{ - wxMessageBox("This is a wxWidgets Hello World example", - "About Hello World", wxOK | wxICON_INFORMATION); -} - -void MyFrame::OnHello(wxCommandEvent& event) -{ - //wxLogMessage("Hello world from wxWidgets!"); -} - -- cgit v1.2.3