1 /*
2 Solar Conquest
3 Copyright (C) 2006 Greg Beaman
4 
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9 
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU General Public License for more details.
14 
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19 
20 class CBarChart : public CMenuItem
21 {
22 protected:
23 	int numBars;
24 	float xfactor;
25 
26 public:
27 	CBarChart(int iid, int px, int py, int w, int h);
28 	virtual ~CBarChart();
29 
30 	void DrawItem(bool selected);
31 	void DrawBar(int num, float barHeight);
32 	void DrawItemText(bool selected);
33 
34 	void BeginBars(int bars);
35 	void EndBars();
36 };
37 
CBarChart(int iid,int px,int py,int w,int h)38 CBarChart::CBarChart(int iid, int px, int py, int w, int h)
39 {
40 	id = iid;
41 
42 	x = px;
43 	y = py;
44 	width = w;
45 	height = h;
46 	itemType = MENU_ITEM_BARCHART;
47 	strcpy(caption,"");
48 
49 	nextItem = NULL;
50 };
51 
~CBarChart()52 CBarChart::~CBarChart()
53 {
54 }
55 
DrawItem(bool selected)56 void CBarChart::DrawItem(bool selected)
57 {
58 	//Draw the box
59 	glBegin(GL_LINES);
60 		glColor4f(0,0,1,1);
61 		glVertex2f(x,y);
62 		glVertex2f(x+width,y);
63 		glVertex2f(x+width,y);
64 		glVertex2f(x+width,y+height);
65 		glVertex2f(x+width,y+height);
66 		glVertex2f(x,y+height);
67 		glVertex2f(x,y+height);
68 		glVertex2f(x,y);
69 	glEnd();
70 
71 	glBegin(GL_QUADS);
72 		glColor4f(0,0,1,0.5);
73 		glVertex2f(x,y);
74 		glVertex2f(x+width,y);
75 		glVertex2f(x+width,y+height);
76 		glVertex2f(x,y+height);
77 	glEnd();
78 }
79 
DrawItemText(bool selected)80 void CBarChart::DrawItemText(bool selected)
81 {
82 	g_MainFont->RenderText(x+6,y+6,1,1,caption);
83 }
84 
BeginBars(int bars)85 void CBarChart::BeginBars(int bars)
86 {
87 	glBegin(GL_QUADS);
88 	numBars = bars;
89 	xfactor = width/2 - bars * 5;
90 }
91 
DrawBar(int num,float barHeight)92 void CBarChart::DrawBar(int num, float barHeight)
93 {
94 	float bheight = (height-2) * barHeight;
95 	int color = num % 5;
96 
97 	if (color == 0)
98 		glColor4f(1,0,0,1);
99 	else if (color == 1)
100 		glColor4f(0,1,0,1);
101 	else if (color == 2)
102 		glColor4f(1,1,0,1);
103 	else if (color == 3)
104 		glColor4f(0,1,1,1);
105 	else if (color == 4)
106 		glColor4f(1,0,1,1);
107 
108 	float xpos = x+1+xfactor+10*num;
109 	glVertex2f(xpos-1, y+height-1);
110 	glVertex2f(xpos-1, y+height-bheight-1);
111 	glVertex2f(xpos+1, y+height-bheight-1);
112 	glVertex2f(xpos+1, y+height-1);
113 }
114 
EndBars()115 void CBarChart::EndBars()
116 {
117 	glEnd();
118 }
119