-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpnggraph.h
88 lines (71 loc) · 2.83 KB
/
pnggraph.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
/*
SpeedSim - a OGame (www.ogame.org) combat simulator
Copyright (C) 2004-2008 Maximialian Matthé & Nicolas Höft
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef PNGGRAPH_H
#define PNGGRAPH_H
#include "pngwriter.h"
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
#define PLOT_DOT 0x002
#define PLOT_CIRCLE 0x004
#define PLOT_CROSS 0x008
#define PLOT_CONNECT_POINTS 0x020
#define PLOT_FILL 0x040
struct sColor
{
int r, g, b;
sColor() { r = g = b = 0; }
sColor(int red, int green, int blue) { r = red; g = green; b = blue; }
};
struct sPoint
{
float x, y;
sPoint() { x = y = 0; }
sPoint(float xPos, float yPos) { x = xPos; y = yPos; }
sPoint operator+(const sPoint& p) { return sPoint(x + p.x, y + p.y); };
sPoint operator+=(const sPoint& p) { x += p.x; y += p.y; return *this; };
sPoint operator-(const sPoint& p) { return sPoint(x - p.x, y - p.y); };
sPoint operator-=(const sPoint& p) { x -= p.x; y -= p.y; return *this; };
sPoint operator*(const float f) { return sPoint(x * f, y * f); };
sPoint operator*=(const float f) { x *= f; y *= f; return *this; };
sPoint operator/(const float f) { return sPoint(x / f, y / f); };
sPoint operator/=(const float f) { x /= f; y /= f; return *this; };
bool operator==(const sPoint& p) { return (x == p.x) && (y == p.y); };
bool operator<(const sPoint& p) { return (x < p.x) && !(*this == p); }
bool operator>(const sPoint& p) { return !(*this < p) && !(*this == p);}
};
class CPngGraph
{
public:
CPngGraph(int height, int width);
~CPngGraph();
bool WriteToFile(char* filename);
void SetColours(sColor BackgrndColor, sColor GraphColor, sColor AxisColor, sColor TextColor);
// paints the axes including , image data will be deleted
bool CreateAxes(float xMin, float xMax, float yMin, float yMax, float xStep, float yStep);
int PlotData(vector<sPoint> data, unsigned long flags);
private:
void PrepareData(vector<sPoint> &points);
pngwriter m_PngData;
bool m_bAxesDone;
sColor m_BackgrndColor, m_AxisColor, m_TextColor, m_GraphColor;
int m_Height, m_Width;
float m_pixPerX, m_pixPerY;
float m_minX, m_maxX;
sPoint m_Orgin;
};
#endif