From 9e336c5677c321ea80adfe28fb7fd77981b18d69 Mon Sep 17 00:00:00 2001 From: David Hackbarth Date: Wed, 26 Feb 2025 12:59:43 +0100 Subject: [PATCH] add detailed sfml example add simple wxWidgets example --- CPlusPlus/CPlusPlus.sln | 10 ++ CPlusPlus/sfml/assets/card_clubs_02.png | Bin 0 -> 190 bytes CPlusPlus/sfml/main.cpp | 38 ++++- CPlusPlus/wxWidgets/MyApp.cpp | 13 ++ CPlusPlus/wxWidgets/MyApp.h | 10 ++ CPlusPlus/wxWidgets/wxWidgets.vcxproj | 142 ++++++++++++++++++ CPlusPlus/wxWidgets/wxWidgets.vcxproj.filters | 27 ++++ 7 files changed, 238 insertions(+), 2 deletions(-) create mode 100644 CPlusPlus/sfml/assets/card_clubs_02.png create mode 100644 CPlusPlus/wxWidgets/MyApp.cpp create mode 100644 CPlusPlus/wxWidgets/MyApp.h create mode 100644 CPlusPlus/wxWidgets/wxWidgets.vcxproj create mode 100644 CPlusPlus/wxWidgets/wxWidgets.vcxproj.filters diff --git a/CPlusPlus/CPlusPlus.sln b/CPlusPlus/CPlusPlus.sln index 5d66c93..5696c4c 100644 --- a/CPlusPlus/CPlusPlus.sln +++ b/CPlusPlus/CPlusPlus.sln @@ -7,6 +7,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "intro", "intro\intro.vcxpro EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "sfml", "sfml\sfml.vcxproj", "{A4867C7F-0C8C-471F-92D6-D7017E813975}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "wxWidgets", "wxWidgets\wxWidgets.vcxproj", "{62CADE1F-B8ED-44C4-B16E-A024B680EA45}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|x64 = Debug|x64 @@ -31,6 +33,14 @@ Global {A4867C7F-0C8C-471F-92D6-D7017E813975}.Release|x64.Build.0 = Release|x64 {A4867C7F-0C8C-471F-92D6-D7017E813975}.Release|x86.ActiveCfg = Release|Win32 {A4867C7F-0C8C-471F-92D6-D7017E813975}.Release|x86.Build.0 = Release|Win32 + {62CADE1F-B8ED-44C4-B16E-A024B680EA45}.Debug|x64.ActiveCfg = Debug|x64 + {62CADE1F-B8ED-44C4-B16E-A024B680EA45}.Debug|x64.Build.0 = Debug|x64 + {62CADE1F-B8ED-44C4-B16E-A024B680EA45}.Debug|x86.ActiveCfg = Debug|Win32 + {62CADE1F-B8ED-44C4-B16E-A024B680EA45}.Debug|x86.Build.0 = Debug|Win32 + {62CADE1F-B8ED-44C4-B16E-A024B680EA45}.Release|x64.ActiveCfg = Release|x64 + {62CADE1F-B8ED-44C4-B16E-A024B680EA45}.Release|x64.Build.0 = Release|x64 + {62CADE1F-B8ED-44C4-B16E-A024B680EA45}.Release|x86.ActiveCfg = Release|Win32 + {62CADE1F-B8ED-44C4-B16E-A024B680EA45}.Release|x86.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/CPlusPlus/sfml/assets/card_clubs_02.png b/CPlusPlus/sfml/assets/card_clubs_02.png new file mode 100644 index 0000000000000000000000000000000000000000..7d1644d142f7d249a7d698e79632aee3214f175f GIT binary patch literal 190 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!73?$#)eFPFbvv-Z=-BB#YS&k_nCihi^!nDroGq=w6^%CdSCsD5>V4sG_+*w5dr! f`@ytBa~K&yXUPVBEOlQ7G?>BD)z4*}Q$iB}Yq>U- literal 0 HcmV?d00001 diff --git a/CPlusPlus/sfml/main.cpp b/CPlusPlus/sfml/main.cpp index b14e46f..c412908 100644 --- a/CPlusPlus/sfml/main.cpp +++ b/CPlusPlus/sfml/main.cpp @@ -1,13 +1,47 @@ #include "SFML/Graphics.hpp" -//using namespace sf; +using namespace sf; int main() { - sf::RenderWindow window(sf::VideoMode({ 640, 480 }), "Hello World Example"); + RenderWindow window(VideoMode({ 640, 480 }), "Hello World Example"); + + CircleShape circle(100.0f); + circle.setFillColor(Color(200, 0, 0)); + + Texture texture("assets/card_clubs_02.png"); + Sprite sprite(texture); while (window.isOpen()) { + while (const std::optional event = window.pollEvent()) + { + if (event->is()) + { + window.close(); + } + //else if (event->is()) { + else if (const Event::KeyPressed* keyPressed = event->getIf()) + { + if (keyPressed->scancode == Keyboard::Scancode::Escape) + { + window.close(); + } + } + } + + // move circle + //circle.setPosition(circle.getPosition() + Vector2f(1, 0)); + + if (Keyboard::isKeyPressed(Keyboard::Scancode::Right)) + { + circle.setPosition(circle.getPosition() + Vector2f(1, 0)); + } + + // clear window to start each frame from scratch + window.clear(); + window.draw(circle); + window.draw(sprite); window.display(); } diff --git a/CPlusPlus/wxWidgets/MyApp.cpp b/CPlusPlus/wxWidgets/MyApp.cpp new file mode 100644 index 0000000..a8d5b13 --- /dev/null +++ b/CPlusPlus/wxWidgets/MyApp.cpp @@ -0,0 +1,13 @@ +#include "MyApp.h" + +bool MyApp::OnInit() +{ + wxFrame* pFrame = new wxFrame(nullptr, wxID_ANY, "Hello World"); + + wxPanel* pPanel = new wxPanel(pFrame); + wxButton* pButton = new wxButton(pPanel, wxID_ANY, "Click me", wxPoint(10, 10), wxSize(100, 30)); + + pFrame->Show(); + + return true; +} diff --git a/CPlusPlus/wxWidgets/MyApp.h b/CPlusPlus/wxWidgets/MyApp.h new file mode 100644 index 0000000..531c487 --- /dev/null +++ b/CPlusPlus/wxWidgets/MyApp.h @@ -0,0 +1,10 @@ +#pragma once +#include + +class MyApp : public wxApp +{ +public: + bool OnInit() override; +}; + +wxIMPLEMENT_APP(MyApp); diff --git a/CPlusPlus/wxWidgets/wxWidgets.vcxproj b/CPlusPlus/wxWidgets/wxWidgets.vcxproj new file mode 100644 index 0000000..3fab426 --- /dev/null +++ b/CPlusPlus/wxWidgets/wxWidgets.vcxproj @@ -0,0 +1,142 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 17.0 + Win32Proj + {62cade1f-b8ed-44c4-b16e-a024b680ea45} + wxWidgets + 10.0 + + + + Application + true + v143 + Unicode + + + Application + false + v143 + true + Unicode + + + Application + true + v143 + Unicode + + + Application + false + v143 + true + Unicode + + + + + + + + + + + + + + + + + + + + + + + + + + Level3 + true + WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions) + true + + + Windows + true + + + + + Level3 + true + true + true + WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions) + true + + + Windows + true + true + true + + + + + Level3 + true + _DEBUG;_WINDOWS;%(PreprocessorDefinitions) + true + + + Windows + true + + + + + Level3 + true + true + true + NDEBUG;_WINDOWS;%(PreprocessorDefinitions) + true + + + Windows + true + true + true + + + + + + + + + + + + \ No newline at end of file diff --git a/CPlusPlus/wxWidgets/wxWidgets.vcxproj.filters b/CPlusPlus/wxWidgets/wxWidgets.vcxproj.filters new file mode 100644 index 0000000..2b1c726 --- /dev/null +++ b/CPlusPlus/wxWidgets/wxWidgets.vcxproj.filters @@ -0,0 +1,27 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Header Files + + + + + Source Files + + + \ No newline at end of file