From 75fe38b72b6890893ed003ade70a8f1606a5cf65 Mon Sep 17 00:00:00 2001 From: mmcwilliams Date: Tue, 1 Aug 2023 23:01:34 -0400 Subject: [PATCH] Create wxwidgets example. Working on macos. --- .gitignore | 1 + CMakeLists.txt | 8 ++++++ compile.sh | 6 +++++ main.cpp | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 82 insertions(+) create mode 100644 .gitignore create mode 100644 CMakeLists.txt create mode 100644 compile.sh create mode 100644 main.cpp diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c795b05 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +build \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..3f60e4f --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,8 @@ +cmake_minimum_required(VERSION 3.20) +project(wxTest) + +find_package(wxWidgets REQUIRED gl core base OPTIONAL_COMPONENTS net) +include(${wxWidgets_USE_FILE}) + +add_executable(wxTest main.cpp) +target_link_libraries(wxTest PRIVATE ${wxWidgets_LIBRARIES}) diff --git a/compile.sh b/compile.sh new file mode 100644 index 0000000..7917863 --- /dev/null +++ b/compile.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +mkdir -p build +cd build +cmake .. +make -j # builds with all cores \ No newline at end of file diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..562f106 --- /dev/null +++ b/main.cpp @@ -0,0 +1,67 @@ +// wxWidgets "Hello world" Program +// For compilers that support precompilation, includes "wx/wx.h". +#include +#ifndef WX_PRECOMP + #include +#endif +class MyApp: public wxApp +{ +public: + virtual bool OnInit(); +}; +class MyFrame: public wxFrame +{ +public: + MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size); +private: + void OnHello(wxCommandEvent& event); + void OnExit(wxCommandEvent& event); + void OnAbout(wxCommandEvent& event); + wxDECLARE_EVENT_TABLE(); +}; +enum +{ + ID_Hello = 1 +}; +wxBEGIN_EVENT_TABLE(MyFrame, wxFrame) + EVT_MENU(ID_Hello, MyFrame::OnHello) + EVT_MENU(wxID_EXIT, MyFrame::OnExit) + EVT_MENU(wxID_ABOUT, MyFrame::OnAbout) +wxEND_EVENT_TABLE() +wxIMPLEMENT_APP(MyApp); +bool MyApp::OnInit() +{ + MyFrame *frame = new MyFrame( "Hello World", wxPoint(50, 50), wxSize(450, 340) ); + frame->Show( true ); + return true; +} +MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size) + : wxFrame(NULL, wxID_ANY, title, pos, size) +{ + wxMenu *menuFile = new wxMenu; + menuFile->Append(ID_Hello, "&Hello...\tCtrl-H", + "Help string shown in status bar for this menu item"); + menuFile->AppendSeparator(); + menuFile->Append(wxID_EXIT); + wxMenu *menuHelp = new wxMenu; + menuHelp->Append(wxID_ABOUT); + wxMenuBar *menuBar = new wxMenuBar; + menuBar->Append( menuFile, "&File" ); + menuBar->Append( menuHelp, "&Help" ); + SetMenuBar( menuBar ); + CreateStatusBar(); + SetStatusText( "Welcome to wxWidgets!" ); +} +void MyFrame::OnExit(wxCommandEvent& event) +{ + Close( true ); +} +void MyFrame::OnAbout(wxCommandEvent& event) +{ + wxMessageBox( "This is a wxWidgets' Hello world sample", + "About Hello World", wxOK | wxICON_INFORMATION ); +} +void MyFrame::OnHello(wxCommandEvent& event) +{ + wxLogMessage("Hello world from wxWidgets!"); +} \ No newline at end of file