1 /*******************************************************************
2 *
3 * DESCRIPTION: gadget.cpp
4 *
5 * AUTHOR: David Malcolm
6 *
7 * HISTORY: Created 13/11/97
8 *
9 *******************************************************************/
10
11 /* Includes ********************************************************/
12 #include "3dc.h"
13 #include "gadget.h"
14 #include "rootgadg.hpp"
15 #include "r2base.h"
16 #include "hudgadg.hpp"
17 #include "ahudgadg.hpp"
18 #include "indexfnt.hpp"
19 #include "trepgadg.hpp"
20 #define UseLocalAssert Yes
21 #include "ourasert.h"
22
23 /* Version settings ************************************************/
24
25 /* Constants *******************************************************/
26
27 /* Macros **********************************************************/
28
29 /* Imported function prototypes ************************************/
30
31 /* Imported data ***************************************************/
32 #ifdef __cplusplus
33 extern "C"
34 {
35 #endif
36 #if 0
37 extern OurBool DaveDebugOn;
38 extern FDIEXTENSIONTAG FDIET_Dummy;
39 extern IFEXTENSIONTAG IFET_Dummy;
40 extern FDIQUAD FDIQuad_WholeScreen;
41 extern FDIPOS FDIPos_Origin;
42 extern FDIPOS FDIPos_ScreenCentre;
43 extern IFOBJECTLOCATION IFObjLoc_Origin;
44 extern UncompressedGlobalPlotAtomID UGPAID_StandardNull;
45 extern IFCOLOUR IFColour_Dummy;
46 extern IFVECTOR IFVec_Zero;
47 #endif
48 #ifdef __cplusplus
49 };
50 #endif
51
52
53
54 /* Exported globals ************************************************/
55
56 /* Internal type definitions ***************************************/
57
58 /* Internal function prototypes ************************************/
59
60 /* Internal globals ************************************************/
61
62 /* Exported function definitions ***********************************/
63 #if UseGadgets
64
65 // class Gadget
66 // public:
67
~Gadget()68 /*virtual*/ Gadget :: ~Gadget()
69 {
70 // ensure virtual destructor
71
72 // empty
73 }
74
75 #if debug
Render_Report(const struct r2pos & R2Pos,const struct r2rect & R2Rect_Clip,int FixP_Alpha)76 void Gadget :: Render_Report
77 (
78 const struct r2pos& R2Pos,
79 const struct r2rect& R2Rect_Clip,
80 int FixP_Alpha
81 )
82 {
83 // use to textprint useful information about a call to "Render"
84 textprint
85 (
86 "%s::Render at(%i,%i) clip(%i,%i,%i,%i) a=%i\n",
87 DebugName,
88 R2Pos . x,
89 R2Pos . y,
90 R2Rect_Clip . x0,
91 R2Rect_Clip . y0,
92 R2Rect_Clip . x1,
93 R2Rect_Clip . y1,
94 FixP_Alpha
95 );
96 }
97 #endif
98
99 // protected:
100
101 // end of class Gadget
102
GADGET_Init(void)103 extern void GADGET_Init(void)
104 {
105 /* expects to be called at program boot-up time */
106
107 /* PRECONDITION */
108 {
109 GLOBALASSERT( RootGadget :: GetRoot() == NULL );
110 }
111
112 /* CODE */
113 {
114 new RootGadget;
115 }
116 }
117
118
GADGET_UnInit(void)119 extern void GADGET_UnInit(void)
120 {
121 /* expects to be called at program shutdown time */
122
123 /* PRECONDITION */
124 {
125 GLOBALASSERT( RootGadget :: GetRoot() );
126 }
127
128 /* CODE */
129 {
130 delete RootGadget :: GetRoot();
131 }
132 }
133
134
GADGET_Render(void)135 extern void GADGET_Render(void)
136 {
137 /* expects to be called within the rendering part of the main loop */
138
139 /* PRECONDITION */
140 {
141 }
142
143 /* CODE */
144 {
145 #if 0
146 textprint("GADGET_Render()\n");
147 #endif
148
149 // under construction...
150 GLOBALASSERT( RootGadget :: GetRoot() );
151 RootGadget :: GetRoot() -> Render
152 (
153 r2pos :: Origin, // const struct r2pos& R2Pos,
154 r2rect :: PhysicalScreen(), // const struct r2rect& R2Rect_Clip,
155 ONE_FIXED // int FixP_Alpha
156 );
157
158 #if 0
159 // Test all the fonts:
160 {
161 SCString* pSCString_Test = new SCString("FONT TEST STRING");
162
163 for (int i=0;i<NUM_FONTS;i++)
164 {
165 IndexedFont* pFont = IndexedFont :: GetFont( (fonts)i );
166 GLOBALASSERT(pFont);
167
168 r2pos R2Pos_TempCursor(0,i*20);
169
170 pFont -> Render_Unclipped
171 (
172 R2Pos_TempCursor, // struct r2pos& R2Pos_Cursor,
173 ONE_FIXED, // int FixP_Alpha,
174 *pSCString_Test// const SCString& SCStr
175 );
176 }
177
178 pSCString_Test -> R_Release();
179 }
180 #endif
181 }
182 }
183
184
GADGET_ScreenModeChange_Setup(void)185 extern void GADGET_ScreenModeChange_Setup(void)
186 {
187 /* expects to be called immediately before anything happens to the screen
188 mode */
189
190 /* PRECONDITION */
191 {
192 }
193
194 /* CODE */
195 {
196 }
197 }
198
199
GADGET_ScreenModeChange_Cleanup(void)200 extern void GADGET_ScreenModeChange_Cleanup(void)
201 {
202 /* expects to be called immediately after anything happens to the screen
203 mode */
204
205
206 /* PRECONDITION */
207 {
208 GLOBALASSERT( RootGadget :: GetRoot() );
209 }
210
211 /* CODE */
212 {
213 RootGadget :: GetRoot() -> RefreshHUD();
214 }
215 }
216
GADGET_NewOnScreenMessage(ProjChar * messagePtr)217 extern void GADGET_NewOnScreenMessage( ProjChar* messagePtr )
218 {
219 /* PRECONDITION */
220 {
221 GLOBALASSERT( messagePtr );
222 GLOBALASSERT( RootGadget :: GetRoot() );
223 }
224
225 /* CODE */
226 {
227 if ( RootGadget :: GetRoot() -> GetHUD() )
228 {
229 SCString* pSCString_New = new SCString( messagePtr );
230
231 RootGadget :: GetRoot() -> GetHUD() -> AddTextReport
232 (
233 pSCString_New
234 );
235
236 pSCString_New -> R_Release();
237 }
238 }
239 }
240
RemoveTheConsolePlease(void)241 extern void RemoveTheConsolePlease(void)
242 {
243 AlienHUDGadget *HUD = (AlienHUDGadget*)RootGadget::GetRoot()->GetHUD();
244 HUD->pTextReportGadg->Disappear();
245 }
246
247
248 #endif // UseGadgets
249
SendToScreen(void)250 void SCString :: SendToScreen(void)
251 {
252 // adds this as a new on-screen message
253 #if UseGadgets
254 /* PRECONDITION */
255 {
256 GLOBALASSERT( RootGadget :: GetRoot() );
257 }
258
259 /* CODE */
260 {
261 if ( RootGadget :: GetRoot() -> GetHUD() )
262 {
263 RootGadget :: GetRoot() -> GetHUD() -> AddTextReport
264 (
265 this
266 );
267 }
268 }
269 #else
270 {
271 // do nothing
272 }
273 #endif // UseGadgets
274 }
275
276
277
278
279
280 /* Internal function definitions ***********************************/
281