Skip to content

Commit bf80613

Browse files
authored
Revert "Revert "Grid" (#6)" (#7)
This reverts commit a645805.
1 parent a645805 commit bf80613

File tree

4 files changed

+584
-59
lines changed

4 files changed

+584
-59
lines changed

include/object.hpp

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#pragma once
2+
3+
#include "SDL.h"
4+
5+
#include <array>
6+
#include <vector>
7+
#include <forward_list>
8+
9+
namespace king {
10+
11+
struct Object
12+
{
13+
protected:
14+
void pan_point(SDL_FPoint& point, float dx, float dy);
15+
};
16+
17+
class Farmhouse : private Object
18+
{
19+
public:
20+
Farmhouse(SDL_Renderer* renderer, std::array<SDL_Vertex, 4> const& _grid_snap_vertices);
21+
~Farmhouse();
22+
23+
public:
24+
void pan(float dx, float dy);
25+
/*
26+
* @returns True if mouse is pressed over the object
27+
*/
28+
bool mouse_pressed(float mx, float my);
29+
void drag(float mx, float my, std::forward_list<Farmhouse> const& farmhouses);
30+
void mouse_released();
31+
void zoom(SDL_MouseWheelEvent const& wheel);
32+
void render(SDL_Renderer* renderer);
33+
34+
bool isPointInObject(int px, int py) const;
35+
bool isPolygonInObject(std::array<SDL_Vertex, 4> const& _vertices) const;
36+
37+
public:
38+
inline static Farmhouse* drag_ptr = nullptr;
39+
40+
public:
41+
// Display
42+
SDL_Texture* texture;
43+
int texture_width, texture_height;
44+
SDL_Colour clr;
45+
46+
// Position
47+
std::array<SDL_Vertex, 4> grid_snap_vertices;
48+
std::array<SDL_Vertex, 4> absolute_vertices;
49+
50+
// Movement
51+
float start_mouse_drag_x, start_mouse_drag_y;
52+
// If the movement ends at an invalid location, reset the position to original
53+
std::array<SDL_Vertex, 4> start_grid_snap_vertices;
54+
std::array<SDL_Vertex, 4> start_absolute_vertices;
55+
56+
// Scaling
57+
float old_scale;
58+
};
59+
60+
} // namespace king

src/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
add_executable(kingdoms main.cpp ${SDL_fontcache_DIR}/SDL_FontCache.c)
1+
add_executable(kingdoms main.cpp object.cpp ${SDL_fontcache_DIR}/SDL_FontCache.c)
22

33
# Specify the SDL2 and SDL2_ttf library directories
44
target_link_libraries(kingdoms

0 commit comments

Comments
 (0)