forked from treeman/Rejection
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Grid.hpp
37 lines (26 loc) · 809 Bytes
/
Grid.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#pragma once
#include <vector>
#include "Tree/Vec2D.hpp"
#include "Sprite.hpp"
struct GridPos {
GridPos( int _x = 0, int _y = 0 ) :
x( _x), y( _y) { }
bool operator == ( const GridPos &g ) const { return x == g.x && y == g.y; }
bool operator != ( const GridPos &g ) const { return !(*this == g); }
int x, y;
};
class Grid {
public:
Grid( int x, int box_w, int columns, int y, int box_h, int rows );
float ConvertXToScreen( int x_pos ) const;
float ConvertYToScreen( int y_pos ) const;
Vec2D ConvertToScreen( GridPos p ) const;
GridPos ConvertToGrid( Vec2D p ) const;
int GetColumns() const { return columns; }
int GetRows() const { return rows; }
void GetBounds( float &x1, float &y1, float &x2, float &y2 ) const;
private:
int x, y;
int box_w, box_h;
int columns, rows;
};