1 /*
2 Copyright (C) 2007, 2010 - Bit-Blot
3 
4 This file is part of Aquaria.
5 
6 Aquaria is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License
8 as published by the Free Software Foundation; either version 2
9 of the License, or (at your option) any later version.
10 
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14 
15 See the GNU General Public License for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
20 */
21 #ifndef __quad__
22 #define __quad__
23 
24 #include "RenderObject.h"
25 
26 class OutlineRect : public RenderObject
27 {
28 public:
29 	OutlineRect();
30 	void setWidthHeight(int w, int h);
31 	void setLineSize(int ls);
32 
33 	bool renderCenter;
34 protected:
35 
36 	int w, h, w2, h2;
37 	int lineSize;
38 
39 	void onRender();
40 };
41 
42 class Quad : public RenderObject
43 {
44 public:
45 	Quad(const std::string &tex, const Vector &pos);
46 	Quad();
47 	void createGrid(int x, int y);
48 	void destroy();
49 	bool isCoordinateInside(Vector coord, int minSize=0);
50 	bool isCoordinateInsideWorld(const Vector &coord, int minSize=0);
51 	bool isCoordinateInsideWorldRect(const Vector &coord, int w, int h);
52 
53 	void flipVertical();
54 	void flipHorizontal();
55 	void setTextureSmooth(const std::string &texture, float t);
56 	void spawnChildClone(float t);
57 	void burn();
58 	void unburn();
59 	void setWidthHeight(float w, float h=-1);
60 	void setWidth(float w);
61 	void setHeight(float h);
getWidth()62 	int getWidth() const {return int(width);}
getHeight()63 	int getHeight() const {return int(height);}
64 
65 	void setSegs(int x, int y, float dgox, float dgoy, float dgmx, float dgmy, float dgtm, bool dgo);
66 	void setDrawGridAlpha(int x, int y, float alpha);
67 	void calculateQuadLighting();
68 	void repeatTextureToFill(bool on);
69 	void refreshRepeatTextureToFill();
isRepeatingTextureToFill()70 	bool isRepeatingTextureToFill() const { return repeatingTextureToFill; }
71 	void setGridPoints(bool vert, const std::vector<Vector> &points);
72 	void setStrip(const std::vector<Vector> &strip);
73 	virtual void createStrip(bool stripVert, int num);
74 	float getStripSegmentSize();
75 	void resetStrip();
getDrawGrid()76 	Vector ** getDrawGrid() { return drawGrid; }
77 
78 	void reloadDevice();
79 
80 	void deleteGrid();
81 
82 
83 	InterpolatedVector upperLeftTextureCoordinates, lowerRightTextureCoordinates;
84 	//InterpolatedVector upperLeftColor, upperRightColor, lowerLeftColor, lowerRightColor;
85 	//InterpolatedVector llalpha, lralpha, ulalpha, uralpha;
86 	//bool oriented;
87 
88 	enum GridType
89 	{
90 		GRID_WAVY	= 0,
91 		GRID_SET	= 1
92 	};
93 	unsigned char gridType;  // unsigned char to save space
94 
95 	char autoWidth, autoHeight;  // char to save space
96 
97 	bool renderQuad, renderBorder, renderCenter;
98 	bool stripVert;
99 	std::vector<Vector>strip;
100 	Vector texOff;
101 
102 	float borderAlpha;
103 	Vector repeatToFillScale;
104 
105 protected:
106 	bool repeatingTextureToFill;
107 	float gridTimer;
108 	int xDivs, yDivs;
109 	Vector ** drawGrid;
110 
111 	void resetGrid();
112 	void updateGrid(float dt);
113 	void renderGrid();
114 
115 
116 	float drawGridOffsetX;
117 	float drawGridOffsetY;
118 	float drawGridModX;
119 	float drawGridModY;
120 	float drawGridTimeMultiplier;
121 	bool drawGridOut;
122 
123 	static Vector renderBorderColor;
124 
125 	void onSetTexture();
126 	void onRender();
127 	void onUpdate(float dt);
128 private:
129 	bool doUpdateGrid;
130 	void initQuad();
131 };
132 
133 class PauseQuad : public Quad
134 {
135 public:
136 	PauseQuad();
137 	int pauseLevel;
138 protected:
139 
140 	void onUpdate(float dt);
141 };
142 
143 #define QUAD(x) Quad *x = new Quad; addRenderObject(x);
144 
145 #endif
146 
147