Add wxwidgets module with initial implementation and integrate into CMake build system. Improve asset management in sfml module.
This commit is contained in:
@@ -6,3 +6,5 @@ add_subdirectory(pointer)
|
||||
add_subdirectory(classes)
|
||||
add_subdirectory(containers)
|
||||
add_subdirectory(misc)
|
||||
add_subdirectory(sfml)
|
||||
add_subdirectory(wxwidgets)
|
||||
|
||||
@@ -16,8 +16,11 @@ add_executable(main src/main.cpp
|
||||
src/elements/Paddle.cpp
|
||||
src/elements/Paddle.h
|
||||
src/elements/Ball.cpp
|
||||
src/elements/Ball.h)
|
||||
src/elements/Ball.h
|
||||
src/assets_ids.h)
|
||||
target_compile_features(main PRIVATE cxx_std_17)
|
||||
target_link_libraries(main PRIVATE SFML::Graphics)
|
||||
|
||||
set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT main)
|
||||
set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT main)
|
||||
|
||||
file(COPY assets DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
|
||||
@@ -0,0 +1,12 @@
|
||||
//
|
||||
// Created by David Hackbarth on 06.03.26.
|
||||
//
|
||||
|
||||
#ifndef CMAKESFMLPROJECT_ASSETS_IDS_H
|
||||
#define CMAKESFMLPROJECT_ASSETS_IDS_H
|
||||
|
||||
#define IDLE "assets/Characters/Default/character_green_idle.png"
|
||||
#define WALK(frame, color) std::string("assets/Characters/Default/character_") + \
|
||||
std::string(color) + std::string("_walk_") + std::string(frame) + std::string(".png")
|
||||
|
||||
#endif //CMAKESFMLPROJECT_ASSETS_IDS_H
|
||||
@@ -1,6 +1,7 @@
|
||||
#include <SFML/Graphics.hpp>
|
||||
#include <vector>
|
||||
#include "elements/Paddle.h"
|
||||
#include "assets_ids.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
@@ -23,9 +24,9 @@ int main()
|
||||
drawables.push_back( &player2.getShape() );
|
||||
|
||||
// sprite
|
||||
sf::Texture idleTexture("/Users/hacky/Projects/HWR/hwr2024_b/cpp/sfml/assets/Characters/Default/character_green_idle.png");
|
||||
sf::Texture walk1Texture("/Users/hacky/Projects/HWR/hwr2024_b/cpp/sfml/assets/Characters/Default/character_green_walk_a.png");
|
||||
sf::Texture walk2Texture("/Users/hacky/Projects/HWR/hwr2024_b/cpp/sfml/assets/Characters/Default/character_green_walk_b.png");
|
||||
sf::Texture idleTexture(IDLE);
|
||||
sf::Texture walk1Texture(WALK("a", "green"));
|
||||
sf::Texture walk2Texture(WALK("b", "green"));
|
||||
sf::Sprite character(idleTexture);
|
||||
character.setPosition( { 300.f, 220.f } );
|
||||
drawables.push_back( &character );
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
cmake_minimum_required(VERSION 4.1)
|
||||
project(wxwidgets LANGUAGES CXX)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 20)
|
||||
|
||||
find_package(wxWidgets REQUIRED COMPONENTS net core base)
|
||||
if(wxWidgets_USE_FILE)
|
||||
include(${wxWidgets_USE_FILE})
|
||||
endif()
|
||||
|
||||
add_executable(wxwidgets src/main.cpp)
|
||||
target_link_libraries(wxwidgets ${wxWidgets_LIBRARIES})
|
||||
@@ -0,0 +1,60 @@
|
||||
#include <wx/wx.h>
|
||||
|
||||
class App : public wxApp {
|
||||
public:
|
||||
bool OnInit() override;
|
||||
};
|
||||
|
||||
wxIMPLEMENT_APP(App);
|
||||
|
||||
class MainWindow : public wxFrame {
|
||||
public:
|
||||
MainWindow();
|
||||
|
||||
private:
|
||||
void OnShowMenuButtonClick(wxCommandEvent& event);
|
||||
};
|
||||
|
||||
bool App::OnInit() {
|
||||
MainWindow* mainWindow = new MainWindow();
|
||||
mainWindow->Show();
|
||||
return true;
|
||||
}
|
||||
|
||||
enum AppIds {
|
||||
ID_LOWEST = 0,
|
||||
|
||||
ID_SHOW
|
||||
};
|
||||
|
||||
MainWindow::MainWindow() : wxFrame(nullptr, wxID_ANY, "Unsere kleine App") {
|
||||
wxMenu* menu = new wxMenu();
|
||||
menu->Append(ID_SHOW, "Zeige Nachricht");
|
||||
menu->Append(wxID_EXIT);
|
||||
|
||||
wxMenuBar* menuBar = new wxMenuBar();
|
||||
menuBar->Append(menu, "&Datei");
|
||||
|
||||
SetMenuBar(menuBar);
|
||||
|
||||
Bind(wxEVT_MENU, &MainWindow::OnShowMenuButtonClick, this, ID_SHOW);
|
||||
|
||||
wxBoxSizer* mainVertical = new wxBoxSizer(wxVERTICAL);
|
||||
wxStaticText* label = new wxStaticText(this, wxID_ANY, "Hallo Welt!");
|
||||
mainVertical->Add(label);
|
||||
mainVertical->Add(new wxStaticText(this, wxID_ANY, "Hallo Welt!"));
|
||||
mainVertical->Add(new wxStaticText(this, wxID_ANY, "Hallo Welt!"));
|
||||
|
||||
wxBoxSizer* buttonBar = new wxBoxSizer(wxHORIZONTAL);
|
||||
buttonBar->Add(new wxButton(this, ID_SHOW, "Zeige Nachricht"));
|
||||
buttonBar->Add(new wxButton(this, ID_SHOW, "Zeige Nachricht"));
|
||||
buttonBar->Add(new wxButton(this, ID_SHOW, "Zeige Nachricht"));
|
||||
|
||||
mainVertical->Add(buttonBar);
|
||||
|
||||
SetSizer(mainVertical);
|
||||
}
|
||||
|
||||
void MainWindow::OnShowMenuButtonClick(wxCommandEvent& event) {
|
||||
wxMessageBox("Hallo Welt!");
|
||||
}
|
||||
Reference in New Issue
Block a user