selection: Create it's dedicated class
This commit is contained in:
@@ -19,6 +19,8 @@ class Render;
|
||||
namespace gol {
|
||||
class SettingsMenu;
|
||||
class SelectionMenu;
|
||||
class ControlMenu;
|
||||
class Selection;
|
||||
|
||||
typedef struct ctx {
|
||||
std::shared_ptr<World> world = nullptr;
|
||||
@@ -26,6 +28,8 @@ typedef struct ctx {
|
||||
std::shared_ptr<Render> render = nullptr;
|
||||
std::shared_ptr<SettingsMenu> settings_menu = nullptr;
|
||||
std::shared_ptr<SelectionMenu> selection_menu = nullptr;
|
||||
std::shared_ptr<ControlMenu> control_menu = nullptr;
|
||||
std::shared_ptr<Selection> selection = nullptr;
|
||||
nlohmann::json config_json;
|
||||
} ctx;
|
||||
|
||||
|
||||
32
includes/selection.hpp
Normal file
32
includes/selection.hpp
Normal file
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* File name: selection.hpp
|
||||
* Author: lejulien
|
||||
* Date created: 01-01-1970 00:59:59
|
||||
// Date modified: 12-01-2026 21:30:10
|
||||
* ------
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <context.hpp>
|
||||
|
||||
#include <imgui.h>
|
||||
#include <raylib.h>
|
||||
#include <rlImGui.h>
|
||||
|
||||
namespace gol {
|
||||
|
||||
class Selection {
|
||||
public:
|
||||
Selection(std::shared_ptr<ctx>);
|
||||
~Selection() = default;
|
||||
void update();
|
||||
void display();
|
||||
private:
|
||||
std::shared_ptr<ctx> context_ = nullptr;
|
||||
Vector2 sel_pos_ = {0., 0.};
|
||||
Vector2 mouse_pos_ = {0., 0.};
|
||||
bool selecting_ = false;
|
||||
};
|
||||
|
||||
} // namespace gol
|
||||
24
includes/snapping.hpp
Normal file
24
includes/snapping.hpp
Normal file
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* File name: selection.cpp
|
||||
* Author: lejulien
|
||||
* Date created: 01-01-1970 00:59:59
|
||||
// Date modified: 12-01-2026 21:30:10
|
||||
* ------
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <types.hpp>
|
||||
|
||||
#include <raylib.h>
|
||||
#include <cmath>
|
||||
|
||||
Vector2 snapToGrid(Vector2 screen, int cell_size) {
|
||||
return {static_cast<float>(round(screen.x / cell_size) * cell_size),
|
||||
static_cast<float>(round(screen.y / cell_size) * cell_size)};
|
||||
}
|
||||
|
||||
Vector2i screenToGrid(Vector2 screen, int cell_size) {
|
||||
return {static_cast<int>(round(screen.x / cell_size)),
|
||||
static_cast<int>(round(screen.y / cell_size))};
|
||||
}
|
||||
Reference in New Issue
Block a user