1 
2 #ifndef ENGINE_GUI_H
3 #define ENGINE_GUI_H
4 
5 #include <stdint.h>
6 
7 // Anchoring is needed to link specific GUI element to specific screen position,
8 // independent of screen resolution and aspect ratio. Vertical and horizontal
9 // anchorings are seperated, so you can link element at any place - top, bottom,
10 // center, left or right.
11 
12 #define GUI_ANCHOR_VERT_TOP         0
13 #define GUI_ANCHOR_VERT_BOTTOM      1
14 #define GUI_ANCHOR_VERT_CENTER      2
15 
16 #define GUI_ANCHOR_HOR_LEFT         0
17 #define GUI_ANCHOR_HOR_RIGHT        1
18 #define GUI_ANCHOR_HOR_CENTER       2
19 
20 // Immutable bars enumeration.
21 // These are the bars that are always exist in GUI.
22 // Scripted bars could be created and drawn separately later.
23 
24 enum Bars
25 {
26     BAR_HEALTH,     // TR 1-5
27     BAR_AIR,        // TR 1-5, alternate state - gas (TR5)
28     BAR_STAMINA,    // TR 3-5
29     BAR_WARMTH,     // TR 3 only
30     BAR_LOADING,
31     BAR_LASTINDEX
32 };
33 
34 // Bar color types.
35 // Each bar part basically has two colours - main and fade.
36 
37 enum BarColorType
38 {
39     BASE_MAIN,
40     BASE_FADE,
41     ALT_MAIN,
42     ALT_FADE,
43     BACK_MAIN,
44     BACK_FADE,
45     BORDER_MAIN,
46     BORDER_FADE
47 };
48 
49 // Main bar class.
50 class gui_ProgressBar
51 {
52 public:
53     gui_ProgressBar();  // Bar constructor.
54 
55     void Show(float value);    // Main show bar procedure.
56     void Resize();
57 
58     void SetColor(BarColorType colType, uint8_t R, uint8_t G, uint8_t B, uint8_t alpha);
59     void SetSize(float width, float height, float borderSize);
60     void SetPosition(int8_t anchor_X, float offset_X, int8_t anchor_Y, float offset_Y);
61     void SetValues(float maxValue, float warnValue);
62     void SetBlink(int interval);
63     void SetExtrude(bool enabled, uint8_t depth);
64     void SetAutoshow(bool enabled, int delay, bool fade, int fadeDelay);
65 
66     bool          Forced;               // Forced flag is set when bar is strictly drawn.
67     bool          Visible;              // Is it visible or not.
68     bool          Alternate;            // Alternate state, in which bar changes color to AltColor.
69 
70     bool          Invert;               // Invert decrease direction flag.
71     bool          Vertical;             // Change bar style to vertical.
72 
73 private:
74     void          RecalculateSize();    // Recalculate size and position.
75     void          RecalculatePosition();
76 
77     float         mX;                   // Horizontal position.
78     float         mY;                   // Vertical position.
79     float         mWidth;               // Real width.
80     float         mHeight;              // Real height.
81     float         mBorderWidth;         // Real border size (horizontal).
82     float         mBorderHeight;        // Real border size (vertical).
83 
84     int8_t        mXanchor;             // Horizontal anchoring: left, right or center.
85     int8_t        mYanchor;             // Vertical anchoring: top, bottom or center.
86     float         mAbsXoffset;          // Absolute (resolution-independent) X offset.
87     float         mAbsYoffset;          // Absolute Y offset.
88     float         mAbsWidth;            // Absolute width.
89     float         mAbsHeight;           // Absolute height.
90     float         mAbsBorderSize;       // Absolute border size (horizontal).
91 
92     float         mBaseMainColor[5];    // Color at the min. of bar.
93     float         mBaseFadeColor[5];    // Color at the max. of bar.
94     float         mAltMainColor[5];     // Alternate main color.
95     float         mAltFadeColor[5];     // Alternate fade color.
96     float         mBackMainColor[5];    // Background main color.
97     float         mBackFadeColor[5];    // Background fade color.
98     float         mBorderMainColor[5];  // Border main color.
99     float         mBorderFadeColor[5];  // Border fade color.
100 
101     int8_t        mBaseBlendingMode;    // Blending modes for all bar parts.
102     int8_t        mBackBlendingMode;    // Note there is no alt. blending mode, cause
103     int8_t        mBorderBlendingMode;  // base and alt are actually the same part.
104 
105     bool          mExtrude;             // Extrude effect.
106     float         mExtrudeDepth[5];     // Extrude effect depth.
107 
108     float         mMaxValue;            // Maximum possible value.
109     float         mWarnValue;           // Warning value, at which bar begins to blink.
110     float         mLastValue;           // Last value back-up for autoshow on change event.
111 
112     bool          mBlink;               // Warning state (blink) flag.
113     float         mBlinkInterval;       // Blink interval (speed).
114     float         mBlinkCnt;            // Blink counter.
115 
116     bool          mAutoShow;            // Autoshow on change flag.
117     float         mAutoShowDelay;       // How long bar will stay on-screen in AutoShow mode.
118     float         mAutoShowCnt;         // Auto-show counter.
119     bool          mAutoShowFade;        // Fade flag.
120     float         mAutoShowFadeDelay;   // Fade length.
121     float         mAutoShowFadeCnt;     // Fade progress counter.
122 
123     float         mRangeUnit;           // Range unit used to set base bar size.
124     float         mBaseSize;            // Base bar size.
125     float         mBaseRatio;           // Max. / actual value ratio.
126 };
127 
128 void Gui_Init();
129 void Gui_InitBars();
130 void Gui_Destroy();
131 
132 /**
133  * Helper method to setup OpenGL state for console drawing.
134  *
135  * Either changes to 2D matrix state (is_gui = 1) or away from it (is_gui = 0). Does not do any drawing.
136  */
137 void Gui_SwitchGLMode(char is_gui);
138 
139 /**
140  * Draws wireframe of this frustum.
141  *
142  * Expected state:
143  *  - Vertex array is enabled, color, tex coord, normal disabled
144  *  - No vertex buffer object is bound
145  *  - Texturing is disabled
146  *  - Alpha test is disabled
147  *  - Blending is enabled
148  *  - Lighting is disabled
149  * Ignored state:
150  *  - Currently bound texture.
151  *  - Currently bound element buffer.
152  *  - Depth test enabled (disables it, then restores)
153  *  - Vertex pointer (changes it)
154  *  - Matrices (changes them, restores)
155  *  - Line width (changes it, then restores)
156  *  - Current color (changes it)
157  * Changed state:
158  *  - Current position will be arbitrary.
159  *  - Vertex pointer will be arbitray.
160  *  - Current color will be arbitray (set by console)
161  *  - Blend mode will be SRC_ALPHA, ONE_MINUS_SRC_ALPHA (set by console)
162  */
163 void Gui_Render();
164 
165 /**
166  *  Draw simple rectangle.
167  *  Only state it changes is the blend mode, according to blendMode value.
168  */
169 void Gui_DrawRect(const GLfloat &x, const GLfloat &y,
170                   const GLfloat &width, const GLfloat &height,
171                   const GLfloat colorUpperLeft[], const GLfloat colorUpperRight[],
172                   const GLfloat colorLowerLeft[], const GLfloat colorLowerRight[],
173                   const int &blendMode,
174                   const GLuint texture = 0);
175 
176 /**
177  * General GUI drawing routines.
178  */
179 void Gui_DrawCrosshair();
180 void Gui_DrawBars();
181 void Gui_DrawLoadScreen(int value);
182 bool Gui_SetScreenTexture(void *data, int w, int h, int bpp);
183 bool Gui_LoadScreenAssignPic(const char* pic_name);
184 
185 /**
186  * General GUI update routines.
187  */
188 void Gui_UpdateResize();  // Called every resize event.
189 
190 #endif
191