Skip to content

Commit

Permalink
merge(gui): add right pannel objects and config file load in menu
Browse files Browse the repository at this point in the history
core(gui): add right pannel objects and config file load in menu
  • Loading branch information
sdragos1 authored May 12, 2024
2 parents a95d0b6 + e8941b1 commit 6d59058
Show file tree
Hide file tree
Showing 20 changed files with 524 additions and 102 deletions.
1 change: 1 addition & 0 deletions common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ endif()
add_subdirectory(types)
add_subdirectory(interfaces)
add_subdirectory(config)
add_subdirectory(abstracts)
42 changes: 42 additions & 0 deletions common/abstracts/AObject.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
** EPITECH PROJECT, 2024
** DFMY-Raytracer [WSL: Ubuntu-22.04]
** File description:
** AObject
*/

#include "AObject.hpp"

using namespace Raytracer::Common;

AObject::AObject(
const std::string &name,
Common::Graphics::Material::Ptr material,
const Common::Math::Vector3D &rotation,
const Common::Math::Point3D &position) :
_name(name),
_material(material),
_rotation(rotation),
_position(position)
{
}

Graphics::Material::Ptr AObject::getMaterial()
{
return _material;
}

std::string &AObject::getName() noexcept
{
return _name;
}

Math::Point3D &AObject::getPosition() noexcept
{
return _position;
}

Math::Vector3D &AObject::getRotation() noexcept
{
return _rotation;
}
61 changes: 61 additions & 0 deletions common/abstracts/AObject.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
** EPITECH PROJECT, 2024
** DFMY-Raytracer [WSL: Ubuntu-22.04]
** File description:
** AObject
*/

#pragma once

#include "types/math/Ray.hpp"
#include "types/math/HitInfo.hpp"
#include "types/graphics/Material.hpp"
#include "interfaces/IObject.hpp"

namespace Raytracer::Common {
class AObject : public IObject {
public:
/**
* @brief Construct a new Cube object
* @param name Name of the cube
* @param material Material of the cube
* @param rotation Rotation of the cube
* @param position Position of the cube
*/
AObject(
const std::string &name,
Graphics::Material::Ptr material,
const Math::Vector3D &rotation,
const Math::Point3D &position);

/**
* @brief Destroy the Cube object
*/
~AObject() override = default;


/// @brief Get the material associated to an object
Graphics::Material::Ptr getMaterial() override;

/// @brief Get the name of the object
std::string &getName() noexcept override;

/// @brief Get the position of the object
Math::Point3D &getPosition() noexcept override;

/// @brief Get the rotation of the object
Math::Vector3D &getRotation() noexcept override;
protected:
/// @brief Name of the cube
std::string _name;

/// @brief Material of the cube
Graphics::Material::Ptr _material;

/// @brief Position of the cube
Math::Point3D _position;

/// @brief Rotation of the cube
Math::Vector3D _rotation;
};
}
4 changes: 4 additions & 0 deletions common/abstracts/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
target_sources(raytracer_common PRIVATE
AObject.hpp
AObject.cpp
)
12 changes: 12 additions & 0 deletions common/interfaces/IObject.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,17 @@ namespace Raytracer::Common {
* @return Material of the object
*/
virtual Graphics::Material::Ptr getMaterial() = 0;

/// @brief Get the name of the object
virtual std::string &getName() noexcept = 0;

/// @brief Get the type of the object
virtual const std::string getType() noexcept = 0;

/// @brief Get the position of the object
virtual Math::Point3D &getPosition() noexcept = 0;

/// @brief Get the rotation of the object
virtual Math::Vector3D &getRotation() noexcept = 0;
};
}
2 changes: 2 additions & 0 deletions core/app/gui/components/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,6 @@ target_sources(raytracer_core PRIVATE
CameraProperties.hpp
RenderingSettings.cpp
RenderingSettings.hpp
ObjectProperties.hpp
ObjectProperties.cpp
)
40 changes: 29 additions & 11 deletions core/app/gui/components/MenuBar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

#include "MenuBar.hpp"
#include "config/Config.hpp"

using namespace Raytracer::Core::Gui;

Expand All @@ -19,19 +20,9 @@ void MenuBar::init() {
_menuBar->setTextSize(13);

_menuBar->addMenu("File");
/* _menuBar->addMenuItem({ "File", "Open" });
_menuBar->addMenuItem({ "File", "Save image as", "PPM" });
_menuBar->addMenuItem({ "File", "Save image as", "PNG" });
_menuBar->addMenuItem({ "File", "Save image as", "JPG" });
_menuBar->addMenuItem({ "File", "Save image as", "BMP" });*/
_menuBar->addMenuItem({ "File", "Open" });
_menuBar->addMenuItem({ "File", "Quit" });

/* _menuBar->addMenu("Scene");
_menuBar->addMenuItem({ "Scene", "Cameras", "Add" });
_menuBar->addMenuItem({ "Scene", "Objects", "Add" });
_menuBar->addMenuItem({ "Scene", "Materials", "Add" });
_menuBar->addMenuItem({ "Scene", "Lights", "Add" });*/

_menuBar->addMenu("Help");
_menuBar->addMenuItem({ "Help", "About" });

Expand All @@ -41,6 +32,7 @@ void MenuBar::init() {

void MenuBar::_initEvents() {
_menuBar->connectMenuItem({ "File", "Quit" }, [this]() { _context.gui.getWindow()->close(); });
_menuBar->connectMenuItem({ "File", "Open" }, [this]() { _openFileExplorer(); });
_menuBar->connectMenuItem({ "Help", "About" }, [this]() { _openAboutBox(); });
}

Expand All @@ -64,4 +56,30 @@ void MenuBar::_openAboutBox() {
_context.gui.add(_aboutBox);
}

void MenuBar::_openFileExplorer()
{
auto fileDialog = tgui::FileDialog::create();
fileDialog->setTitle("Open file");
fileDialog->setFileMustExist(true);
fileDialog->setFileTypeFilters({{"Raytracer Config", {"*.cfg"}}});
fileDialog->setPosition("(&.width - width) / 2", "(&.height - height) / 2");
fileDialog->onFileSelect([this](const tgui::String &selectedFile) {
try {
auto config = Config::loadFromFile(selectedFile.toStdString(), _context.app.pluginsManager);
auto scene = config.toScene();

_context.app.scene = std::move(scene);
} catch (const std::exception &e) {
auto messageBox = tgui::MessageBox::create("Error", e.what(), {"OK"});

messageBox->setPosition("(&.width - width) / 2", "(&.height - height) / 2");
messageBox->onButtonPress([this, messageBox]() {
_context.gui.remove(messageBox);
});
_context.gui.add(messageBox);
}
});
_context.gui.add(fileDialog);
}

MenuBar::~MenuBar() = default;
5 changes: 5 additions & 0 deletions core/app/gui/components/MenuBar.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,10 @@ namespace Raytracer::Core::Gui {
* @brief Initialize the about box
*/
void _openAboutBox();

/**
* @brief Open the file explorer
*/
void _openFileExplorer();
};
}
Loading

0 comments on commit 6d59058

Please sign in to comment.