-
Notifications
You must be signed in to change notification settings - Fork 0
/
hexfml.h
151 lines (103 loc) · 3.66 KB
/
hexfml.h
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#ifndef H_HEXFML
#define H_HEXFML
#include <SFML/Graphics.hpp>
#include <iostream>
#include <stdint.h>
#include "HexTools.h"
using namespace HexTools; // temporary, to smoothly split hexfml.c
class HexSprite;
sf::FloatRect fitRectangleAt(double, double, const sf::FloatRect&, double, double);
class ScreenGrid {
private:
sf::Image hexPrototype;
int width, height;
// Exact pixel counts; not subject to rounding.
// Counted from the top left.
int hOffsetIncrement; // 2/3 hex width
int vOffsetIncrement; // 1/2 hex width
const uint32_t *pixels;
uint32_t mainColour,
northwestColour,
northeastColour,
southwestColour,
southeastColour;
void screenToGeometric( int&, int&, int, int ) const;
void geometricToScreen( int&, int&, int, int ) const;
int getColumn( int ) const;
int getRow( int, int ) const;
void cellClassify( int&, int&, int, int ) const;
void analysePrototype(void);
public:
explicit ScreenGrid( const std::string& );
~ScreenGrid(void);
void screenToHex( int&, int&, int, int ) const;
void hexToScreen( int&, int& ) const;
int getHexWidth(void) const { return width; }
int getHexHeight(void) const { return height; }
void centerRectangle(sf::FloatRect&) const;
sf::Image* createSingleColouredImage( const sf::Color& ) const;
};
// the viewport stuff could probably easily be generalized to use other
// sorts of grids
class HexBlitter {
public:
virtual void drawHex(int, int, sf::RenderWindow&) = 0;
};
class HexViewport {
// Note: this viewport is 1:1 and does not support
// zoom -- this is intentional to maintain a
// one to one pixel mapping.
// This is also why integers are used for coordinates
// throughout.
private:
const ScreenGrid& grid;
int screenXOffset, screenYOffset;
int screenWidth, screenHeight;
int centerX, centerY;
bool drawBackground;
sf::Color bgColor;
public:
HexViewport(const ScreenGrid&,int,int,int,int);
void setRectangle(int,int,int,int);
void center(int,int);
void center(double,double);
int getCenterX(void) { return centerX; }
int getCenterY(void) { return centerY; }
void draw(HexBlitter&, sf::RenderWindow&, sf::View&) const;
void drawGL(HexBlitter&, sf::RenderWindow&, double, double) const;
bool translateCoordinates(int&, int&) const;
void setBackgroundColour( const sf::Color& );
void setNoBackgroundColour(void);
void translateToHex(int,int,int,int,sf::View&) const;
void beginClip(int,int);
void endClip(void);
void hexToScreen(int&,int&);
};
class HexSprite {
private:
const ScreenGrid& grid;
sf::Image *image;
sf::Sprite sprite;
int offsetX, offsetY;
int hx, hy;
void loadSpriteFrom(const sf::Image&);
public:
HexSprite(const std::string&, const ScreenGrid&);
HexSprite(const sf::Image&, const ScreenGrid&); // does not adopt!
HexSprite(const sf::Sprite&, const ScreenGrid&);
~HexSprite(void);
void setPosition(int,int);
void getPosition(int&,int&) const;
void draw(sf::RenderWindow&) const;
};
class ViewportMouseScroller {
private:
HexViewport& vp;
const sf::Input& input;
int mouseX0, mouseY0;
int vpX0, vpY0;
public:
ViewportMouseScroller( HexViewport&, const sf::Input& );
void scroll(void);
};
#endif