Subversion Repositories Games.Chess Giants

Rev

Rev 164 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 164 Rev 185
Line 10... Line 10...
10
#include "DirectX9/Include/d3dx9.h"
10
#include "DirectX9/Include/d3dx9.h"
11
 
11
 
12
// include the Direct3D library files
12
// include the Direct3D library files
13
#pragma comment (lib, "DirectX9/Lib/x86/d3d9.lib")
13
#pragma comment (lib, "DirectX9/Lib/x86/d3d9.lib")
14
#pragma comment (lib, "DirectX9/Lib/x86/d3dx9.lib")
14
#pragma comment (lib, "DirectX9/Lib/x86/d3dx9.lib")
-
 
15
 
-
 
16
 
-
 
17
// local definitions
-
 
18
#define TEXTBG_NONE    0
-
 
19
#define TEXTBG_CENTER (1 << 0)
-
 
20
#define TEXTBG_LEFT   (1 << 1)
-
 
21
#define TEXTBG_RIGHT  (1 << 2)
-
 
22
#define TEXTBG_TOP    (1 << 3)
-
 
23
#define TEXTBG_BOTTOM (1 << 4)
-
 
24
#define TEXTBG_ALL    (TEXTBG_CENTER | TEXTBG_LEFT | TEXTBG_RIGHT | TEXTBG_TOP | TEXTBG_BOTTOM)
15
 
25
 
16
 
26
 
17
// handy macro to print a chatter channel reply
27
// handy macro to print a chatter channel reply
18
#define PRINT_CCREPLY(ccreply) \
28
#define PRINT_CCREPLY(ccreply) \
19
{ \
29
{ \
20
   Render_wprintf (rect.right * 100.0f / initial_width, 100 - combinedheight_percent, (initial_width - rect.right) * 100.0f / initial_width, ALIGN_LEFT, ALIGN_TOP, ALIGN_LEFT, \
-
 
21
                   chat_fontindex, (ccreply)->color, &rect, \
-
 
22
                   L"["); \
-
 
23
   Render_wprintf (rect.right * 100.0f / initial_width, 100 - combinedheight_percent, (initial_width - rect.right) * 100.0f / initial_width, ALIGN_LEFT, ALIGN_TOP, ALIGN_LEFT, \
-
 
24
                   chat_fontindex, RGBA_TO_RGBACOLOR (159, 159, 159, RGBACOLOR_ALPHA ((ccreply)->color)), &rect, \
-
 
25
                   (ccreply)->channelname); \
30
   if (ccreply->channelname[0] != 0) \
26
   Render_wprintf (rect.right * 100.0f / initial_width, 100 - combinedheight_percent, (initial_width - rect.right) * 100.0f / initial_width, ALIGN_LEFT, ALIGN_TOP, ALIGN_LEFT, \
-
 
27
                   chat_fontindex, (ccreply)->color, &rect, \
-
 
28
                   L"] "); /* closing bracket + non-breakable space */ \
-
 
29
   Render_wprintf (rect.right * 100.0f / initial_width, 100 - combinedheight_percent, (initial_width - rect.right) * 100.0f / initial_width, ALIGN_LEFT, ALIGN_TOP, ALIGN_LEFT, \
-
 
30
                   chat_fontindex, RGBA_TO_RGBACOLOR (159, 159, 159, RGBACOLOR_ALPHA ((ccreply)->color)), &rect, \
-
 
31
                   (ccreply)->nickname); \
-
 
32
   Render_wprintf (rect.right * 100.0f / initial_width, 100 - combinedheight_percent, (initial_width - rect.right) * 100.0f / initial_width, ALIGN_LEFT, ALIGN_TOP, ALIGN_LEFT, \
-
 
33
                   chat_fontindex, (ccreply)->color, &rect, \
-
 
34
                   L": "); /* colon + non-breakable space */ \
-
 
35
   if ((ccreply)->text != NULL) \
31
   { \
36
      Render_wprintf (rect.right * 100.0f / initial_width, 100 - combinedheight_percent, (initial_width - rect.right) * 100.0f / initial_width, ALIGN_LEFT, ALIGN_TOP, ALIGN_LEFT, \
32
      Render_wprintf (rect.right * 100.0f / initial_width, 100 - combinedheight_percent, (initial_width - rect.right) * 100.0f / initial_width, ALIGN_LEFT, ALIGN_TOP, ALIGN_LEFT, \
-
 
33
                      L"Papyrus", 8.0f, false, false, (ccreply)->color, TEXTBG_CENTER | TEXTBG_LEFT, &rect, \
-
 
34
                      L"["); \
-
 
35
      Render_wprintf (rect.right * 100.0f / initial_width, 100 - combinedheight_percent, (initial_width - rect.right) * 100.0f / initial_width, ALIGN_LEFT, ALIGN_TOP, ALIGN_LEFT, \
-
 
36
                      L"Papyrus", 8.0f, false, false, RGBA_TO_RGBACOLOR (159, 159, 159, RGBACOLOR_ALPHA ((ccreply)->color)), TEXTBG_CENTER, &rect, \
37
                      chat_fontindex, (ccreply)->color, &rect, \
37
                      (ccreply)->channelname); \
-
 
38
      Render_wprintf (rect.right * 100.0f / initial_width, 100 - combinedheight_percent, (initial_width - rect.right) * 100.0f / initial_width, ALIGN_LEFT, ALIGN_TOP, ALIGN_LEFT, \
-
 
39
                      L"Papyrus", 8.0f, false, false, (ccreply)->color, TEXTBG_CENTER, &rect, \
-
 
40
                      L"] "); /* closing bracket + non-breakable space */ \
-
 
41
   } \
-
 
42
   else \
-
 
43
      Render_wprintf (rect.right * 100.0f / initial_width, 100 - combinedheight_percent, (initial_width - rect.right) * 100.0f / initial_width, ALIGN_LEFT, ALIGN_TOP, ALIGN_LEFT, \
-
 
44
                      L"Papyrus", 8.0f, false, false, (ccreply)->color, TEXTBG_CENTER | TEXTBG_LEFT, &rect, \
-
 
45
                      L" "); \
-
 
46
   if (ccreply->nickname[0] != 0) \
-
 
47
   { \
-
 
48
      Render_wprintf (rect.right * 100.0f / initial_width, 100 - combinedheight_percent, (initial_width - rect.right) * 100.0f / initial_width, ALIGN_LEFT, ALIGN_TOP, ALIGN_LEFT, \
-
 
49
                      L"Papyrus", 8.0f, false, false, RGBA_TO_RGBACOLOR (159, 159, 159, RGBACOLOR_ALPHA ((ccreply)->color)), TEXTBG_CENTER, &rect, \
38
                      (ccreply)->text); \
50
                      (ccreply)->nickname); \
-
 
51
      Render_wprintf (rect.right * 100.0f / initial_width, 100 - combinedheight_percent, (initial_width - rect.right) * 100.0f / initial_width, ALIGN_LEFT, ALIGN_TOP, ALIGN_LEFT, \
-
 
52
                      L"Papyrus", 8.0f, false, false, (ccreply)->color, TEXTBG_CENTER, &rect, \
-
 
53
                      L": "); /* colon + non-breakable space */ \
-
 
54
   } \
-
 
55
   Render_wprintf (rect.right * 100.0f / initial_width, 100 - combinedheight_percent, (initial_width - rect.right) * 100.0f / initial_width, ALIGN_LEFT, ALIGN_TOP, ALIGN_LEFT, \
-
 
56
                   L"Papyrus", 8.0f, false, false, (ccreply)->color, TEXTBG_CENTER | TEXTBG_RIGHT, &rect, \
-
 
57
                   ((ccreply)->text != NULL ? (ccreply)->text : L"")); /* CC text (or empty string) */ \
39
}
58
}
40
 
59
 
41
 
60
 
42
// handy macro to draw a GUI button
61
// handy macro to draw a GUI button
43
#define DRAW_BUTTON_IF_NEEDED(button) \
62
#define DRAW_BUTTON_IF_NEEDED(button) \
44
{ \
63
{ \
45
   if ((button).state != 0) \
64
   if ((button).state != 0) \
46
   { \
65
   { \
47
      Render_DrawSprite (&sprites[(button).sprite_index], (button).left, (button).top, (button).width, (button).height, ((button).state == 2 ? 0xFF : 0x7F)); \
66
      Render_DrawSprite (&sprites[(button).sprite_index], (button).left, (button).top, (button).width, (button).height, ((button).state == 2 ? 0xFF : 0x7F)); \
48
      if ((button).text[0] != 0) \
67
      if ((button).text[0] != 0) \
49
         Render_wprintf ((button).left + (button).width / 2.0f, (button).top + (button).height / 2.0f, (button).width, ALIGN_CENTER, ALIGN_CENTER, ALIGN_CENTER, chat_fontindex, D3DCOLOR_ARGB (255, 255, 255, /*alpha*/ ((button).state == 2 ? 0xFF : 0x7F)), NULL, (button).text); \
68
         Render_wprintf ((button).left + (button).width / 2.0f, (button).top + (button).height / 2.0f, (button).width, ALIGN_CENTER, ALIGN_CENTER, ALIGN_CENTER, \
-
 
69
         (button).font_face, (button).font_sizepct, (button).is_bold, (button).is_italic, D3DCOLOR_ARGB (255, 255, 255, /*alpha*/ ((button).state == 2 ? 0xFF : 0x7F)), TEXTBG_NONE, NULL, (button).text); \
50
   } \
70
   } \
51
}
71
}
52
 
72
 
53
 
73
 
54
// handy macro to draw a GUI text
74
// handy macro to draw a GUI text
55
#define DRAW_TEXT_IF_NEEDED(text) \
75
#define DRAW_TEXT_IF_NEEDED(text) \
56
{ \
76
{ \
57
   if ((text).is_displayed) \
77
   if ((text).is_displayed) \
58
   { \
78
   { \
59
      Render_wprintf ((text).xpos_percent, (text).ypos_percent, \
79
      Render_wprintf ((text).xpos_percent, (text).ypos_percent, \
60
                      (text).maxwidth_percent, (text).horizontal_align, (text).vertical_align, (text).text_align, (text).font_index, \
80
                      (text).maxwidth_percent, (text).horizontal_align, (text).vertical_align, (text).text_align, (text).font_face, (text).font_sizepct, (text).is_bold, (text).is_italic, \
61
                      ((text).want_fade ? \
81
                      ((text).want_fade ? \
62
                       RGBACOLOR_SETALPHA ((text).color, \
82
                       RGBACOLOR_SETALPHA ((text).color, \
63
                                           (((text).appear_time + (text).disappear_time) * 0.5f > current_time ? \
83
                                           (((text).appear_time + (text).disappear_time) * 0.5f > current_time ? \
64
                                           /* fading in  */ (int) FadeFloat (0, RGBACOLOR_ALPHA ((text).color), (text).appear_time, (text).appear_time + 0.5f) : \
84
                                           /* fading in  */ (int) FadeFloat (0, RGBACOLOR_ALPHA ((text).color), (text).appear_time, (text).appear_time + 0.5f) : \
65
                                           /* fading out */ (int) FadeFloat (RGBACOLOR_ALPHA ((text).color), 0, (text).disappear_time - 3.0f, (text).disappear_time))) : \
85
                                           /* fading out */ (int) FadeFloat (RGBACOLOR_ALPHA ((text).color), 0, (text).disappear_time - 3.0f, (text).disappear_time))) : \
66
                       (text).color), \
86
                       (text).color), TEXTBG_NONE, \
67
                      NULL, (text).buffer); \
87
                      NULL, (text).buffer); \
68
      if ((text).disappear_time < current_time) \
88
      if ((text).disappear_time < current_time) \
69
         (text).is_displayed = false; \
89
         (text).is_displayed = false; \
70
   } \
90
   } \
71
}
91
}
Line 141... Line 161...
141
typedef struct texture_s
161
typedef struct texture_s
142
{
162
{
143
   unsigned long hash; // basic content hash, to avoid duplicates
163
   unsigned long hash; // basic content hash, to avoid duplicates
144
   int width;
164
   int width;
145
   int height;
165
   int height;
146
   IDirect3DTexture9 *texture;
166
   IDirect3DTexture9 *d3dtexture;
147
} texture_t;
167
} texture_t;
148
 
168
 
149
 
169
 
150
// definition for a font
170
// definition for a font
151
typedef struct font_s
171
typedef struct font_s
152
{
172
{
153
   unsigned long pathname_hash;
173
   unsigned long pathname_hash;
154
   ID3DXFont *font;
174
   ID3DXFont *d3dfont;
155
} font_t;
175
} font_t;
156
 
176
 
157
 
177
 
158
// definition for a sprite
178
// definition for a sprite
159
typedef struct sprite_s
179
typedef struct sprite_s
160
{
180
{
161
   unsigned long hash; // basic content hash, to avoid duplicates
181
   unsigned long hash; // basic content hash, to avoid duplicates
162
   ID3DXSprite *sprite;
182
   ID3DXSprite *d3dsprite;
163
   int texture_index;
183
   int texture_index;
164
} sprite_t;
184
} sprite_t;
165
 
185
 
166
 
186
 
167
// global variables used in this module only
187
// global variables used in this module only
Line 194... Line 214...
194
 
214
 
195
static wchar_t printf_buffer[0xffff];
215
static wchar_t printf_buffer[0xffff];
196
 
216
 
197
 
217
 
198
// prototypes of functions used in this module only
218
// prototypes of functions used in this module only
199
static bool Render_LoadMesh_X (mesh_t *mesh, const wchar_t *xfile_pathname);
219
static int Render_LoadFont (const wchar_t *font_name, float font_sizepct, bool is_bold, bool is_italic);
200
static bool Render_LoadMesh_Obj (mesh_t *mesh, const wchar_t *objfile_pathname);
220
static bool Render_LoadMesh_Obj (mesh_t *mesh, const wchar_t *objfile_pathname);
201
static void Render_DrawSceneObjectReflection (sceneobject_t *sceneobject);
221
static void Render_DrawSceneObjectReflection (sceneobject_t *sceneobject);
202
static void Render_DrawSceneObject (sceneobject_t *sceneobject);
222
static void Render_DrawSceneObject (sceneobject_t *sceneobject);
203
static void Render_DrawSceneTile (sceneobject_t *sceneobject);
223
static void Render_DrawSceneTile (sceneobject_t *sceneobject);
204
static void Render_DrawSprite (sprite_t *sprite, float x_percent, float y_percent, float width_percent, float height_percent, int alpha);
224
static void Render_DrawSprite (sprite_t *sprite, float x_percent, float y_percent, float width_percent, float height_percent, int alpha);
205
static void Render_GetTextBoundaries (float maxwidth_percent, int font_id, wchar_t *text, RECT *rect);
225
static int Render_GetTextBoundaries (float maxwidth_percent, wchar_t *font_face, float font_sizepct, bool is_bold, bool is_italic, wchar_t *text, RECT *rect);
206
static void Render_wprintf (float x_percent, float y_percent, float maxwidth_percent, int horiz_align, int vert_align, int text_align, int font_id, unsigned long color_rgba, RECT *out_rect, const wchar_t *fmt, ...);
226
static void Render_wprintf (float x_percent, float y_percent, float maxwidth_percent, int horiz_align, int vert_align, int text_align, wchar_t *font_face, float font_sizepct, bool want_bold, bool want_italic, unsigned long color_rgba, int background_flags, RECT *out_rect, const wchar_t *fmt, ...);
207
static float DistanceToCamera (float x, float y, float z);
227
static float DistanceToCamera (float x, float y, float z);
208
static float FadeFloat (float from, float to, float start_time, float end_time);
228
static float FadeFloat (float from, float to, float start_time, float end_time);
209
static unsigned long HashString (const wchar_t *string_buffer);
229
static unsigned long HashString (const wchar_t *string_buffer);
210
static unsigned long HashFile (const wchar_t *file_pathname);
230
static unsigned long HashFile (const wchar_t *file_pathname);
211
static void ResolveWildcard (wchar_t *file_pathname, wchar_t *extensions_separated_by_bars);
231
static void ResolveWildcard (wchar_t *file_pathname, wchar_t *extensions_separated_by_bars);
Line 251... Line 271...
251
   // grab info from that and adjust our D3D settings
271
   // grab info from that and adjust our D3D settings
252
   best_supported_filter = (device_capabilities.RasterCaps & D3DPRASTERCAPS_ANISOTROPY ? D3DTEXF_ANISOTROPIC : D3DTEXF_LINEAR);
272
   best_supported_filter = (device_capabilities.RasterCaps & D3DPRASTERCAPS_ANISOTROPY ? D3DTEXF_ANISOTROPIC : D3DTEXF_LINEAR);
253
   behaviour_flags = (device_capabilities.VertexProcessingCaps != 0 ? D3DCREATE_HARDWARE_VERTEXPROCESSING : D3DCREATE_SOFTWARE_VERTEXPROCESSING);
273
   behaviour_flags = (device_capabilities.VertexProcessingCaps != 0 ? D3DCREATE_HARDWARE_VERTEXPROCESSING : D3DCREATE_SOFTWARE_VERTEXPROCESSING);
254
 
274
 
255
   // see if simple (non-maskable) full-scene antialiasing is supported and in how many quality flavors
275
   // see if simple (non-maskable) full-scene antialiasing is supported and in how many quality flavors
256
   if (SUCCEEDED (d3d->CheckDeviceMultiSampleType (D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8, false, D3DMULTISAMPLE_NONMASKABLE, &multisample_quality_count)))
276
   if (SUCCEEDED (d3d->CheckDeviceMultiSampleType (D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8, true, D3DMULTISAMPLE_NONMASKABLE, &multisample_quality_count)) && (multisample_quality_count > 0))
257
      is_fsaa_supported = true; // remember FSAA is supported
277
      is_fsaa_supported = true; // remember FSAA is supported
258
 
278
 
259
   memset (&d3dpp, 0, sizeof (d3dpp)); // clear out the struct for use
279
   memset (&d3dpp, 0, sizeof (d3dpp)); // clear out the struct for use
260
   d3dpp.Windowed = true; // always windowed (because we can't display dialog boxes in fullscreen mode)
280
   d3dpp.Windowed = true; // always windowed (because we can't display dialog boxes in fullscreen mode)
261
   d3dpp.BackBufferCount = 1;
281
   d3dpp.BackBufferCount = 1;
Line 264... Line 284...
264
   d3dpp.EnableAutoDepthStencil = true; // enable Z-buffer and stencil buffer
284
   d3dpp.EnableAutoDepthStencil = true; // enable Z-buffer and stencil buffer
265
   d3dpp.AutoDepthStencilFormat = D3DFMT_D24S8; // D3DFMT_D15S1 15 bits should be enough to store each pixel's Z depth
285
   d3dpp.AutoDepthStencilFormat = D3DFMT_D24S8; // D3DFMT_D15S1 15 bits should be enough to store each pixel's Z depth
266
   if (is_fsaa_supported)
286
   if (is_fsaa_supported)
267
   {
287
   {
268
      d3dpp.MultiSampleType = D3DMULTISAMPLE_NONMASKABLE; // use multisampling (full scene antialiasing) if supported
288
      d3dpp.MultiSampleType = D3DMULTISAMPLE_NONMASKABLE; // use multisampling (full scene antialiasing) if supported
269
      d3dpp.MultiSampleQuality = multisample_quality_count - 1; // use the best available multisample quality
289
      d3dpp.MultiSampleQuality = multisample_quality_count - 1; // use the best available multisample quality (FIXME: not working)
270
   }
290
   }
271
   else
291
   else
272
   {
292
   {
273
      d3dpp.MultiSampleType = D3DMULTISAMPLE_NONE; // do not use multisampling (full scene antialiasing)
293
      d3dpp.MultiSampleType = D3DMULTISAMPLE_NONE; // do not use multisampling (full scene antialiasing)
274
      d3dpp.MultiSampleQuality = 0;
294
      d3dpp.MultiSampleQuality = 0;
275
   }
295
   }
-
 
296
   /*{ // this FSAA code isn't working any better
-
 
297
      int start = D3DMULTISAMPLE_2_SAMPLES;
-
 
298
      int end = D3DMULTISAMPLE_16_SAMPLES;
-
 
299
      for (int n = start; n < end; n++)
-
 
300
      {
-
 
301
         D3DMULTISAMPLE_TYPE mst = (D3DMULTISAMPLE_TYPE) n;
-
 
302
         DWORD quality = 0;
-
 
303
         if (SUCCEEDED (d3d->CheckDeviceMultiSampleType (D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8, true, mst, &quality)))
-
 
304
         {
-
 
305
            d3dpp.MultiSampleType = mst; // use multisampling (full scene antialiasing) if supported
-
 
306
            d3dpp.MultiSampleQuality = D3DMULTISAMPLE_2_SAMPLES;// quality - 1; // use the best available multisample quality
-
 
307
         }
-
 
308
      }
-
 
309
   }*/
276
 
310
 
277
   // get main window's current rectangle and full screen size
311
   // get main window's current rectangle and full screen size
278
   GetWindowRect (hMainWnd, &rect);
312
   GetWindowRect (hMainWnd, &rect);
279
 
313
 
280
   // create a device class using this information and the info from the d3dpp stuct. Resize the window to the max displayable
314
   // create a device class using this information and the info from the d3dpp stuct. Resize the window to the max displayable
281
   // size before creating the DirectX device, so as to guarantee the viewport will never be upscaled in case of window resize.
315
   // size before creating the DirectX device, so as to guarantee the viewport will never be upscaled in case of window resize.
282
   MoveWindow (hMainWnd, rect.left, rect.top, GetSystemMetrics (SM_CXSCREEN), GetSystemMetrics (SM_CYSCREEN), false);
316
   SetWindowPos (hMainWnd, NULL, rect.left, rect.top, GetSystemMetrics (SM_CXSCREEN), GetSystemMetrics (SM_CYSCREEN), SWP_NOZORDER | SWP_NOSENDCHANGING | SWP_NOREPOSITION | SWP_NOREDRAW | SWP_NOMOVE | SWP_NOCOPYBITS | SWP_NOACTIVATE);
283
   if (FAILED (ret = d3d->CreateDevice (D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hMainWnd, behaviour_flags, &d3dpp, &d3ddev)))
317
   if (FAILED (ret = d3d->CreateDevice (D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, NULL, behaviour_flags, &d3dpp, &d3ddev)))
284
   {
318
   {
285
      MessageBox (NULL, LOCALIZE (L"Error_CouldNotCreateD3DDevCreateDeviceFailed"), LOCALIZE (L"FatalError"), MB_ICONERROR | MB_OK);
319
      MessageBox (NULL, LOCALIZE (L"Error_CouldNotCreateD3DDevCreateDeviceFailed"), LOCALIZE (L"FatalError"), MB_ICONERROR | MB_OK);
286
 
320
 
287
      // on error, write a log file on the user's desktop
321
      // on error, write a log file on the user's desktop
288
      errorfile_path[0] = 0;
322
      errorfile_path[0] = 0;
Line 389... Line 423...
389
   GetClientRect (hMainWnd, &viewport_rect);
423
   GetClientRect (hMainWnd, &viewport_rect);
390
   initial_width = viewport_rect.right;
424
   initial_width = viewport_rect.right;
391
   initial_height = viewport_rect.bottom;
425
   initial_height = viewport_rect.bottom;
392
 
426
 
393
   // now resize the window to its original size
427
   // now resize the window to its original size
394
   MoveWindow (hMainWnd, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, false);
428
   SetWindowPos (hMainWnd, NULL, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, SWP_SHOWWINDOW);
395
 
429
 
396
   // set the texture parameters
430
   // set the texture parameters
397
   d3ddev->SetSamplerState (0, D3DSAMP_ADDRESSU, D3DTADDRESS_WRAP); // wrap textures around their edges
431
   d3ddev->SetSamplerState (0, D3DSAMP_ADDRESSU, D3DTADDRESS_WRAP); // wrap textures around their edges
398
   d3ddev->SetSamplerState (0, D3DSAMP_ADDRESSV, D3DTADDRESS_WRAP);
432
   d3ddev->SetSamplerState (0, D3DSAMP_ADDRESSV, D3DTADDRESS_WRAP);
399
   d3ddev->SetTextureStageState (0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE); // and modulate their alpha with the material's alpha
433
   d3ddev->SetTextureStageState (0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE); // and modulate their alpha with the material's alpha
Line 499... Line 533...
499
 
533
 
500
   // close and release texture data
534
   // close and release texture data
501
   if (textures != NULL)
535
   if (textures != NULL)
502
   {
536
   {
503
      for (array_index = 0; array_index < texture_count; array_index++)
537
      for (array_index = 0; array_index < texture_count; array_index++)
504
         if (textures[array_index].texture != NULL)
538
         if (textures[array_index].d3dtexture != NULL)
505
            textures[array_index].texture->Release ();
539
            textures[array_index].d3dtexture->Release ();
506
      SAFE_free ((void **) &textures);
540
      SAFE_free ((void **) &textures);
507
   }
541
   }
508
   texture_count = 0;
542
   texture_count = 0;
509
 
543
 
510
   // close and release materials data
544
   // close and release materials data
Line 782... Line 816...
782
   DRAW_BUTTON_IF_NEEDED (scene->gui.llarrow); // "jump to beginning" arrow
816
   DRAW_BUTTON_IF_NEEDED (scene->gui.llarrow); // "jump to beginning" arrow
783
   DRAW_BUTTON_IF_NEEDED (scene->gui.larrow); // "previous move" arrow
817
   DRAW_BUTTON_IF_NEEDED (scene->gui.larrow); // "previous move" arrow
784
   DRAW_BUTTON_IF_NEEDED (scene->gui.rarrow); // "next move" arrow
818
   DRAW_BUTTON_IF_NEEDED (scene->gui.rarrow); // "next move" arrow
785
   DRAW_BUTTON_IF_NEEDED (scene->gui.rrarrow); // "jump to end" arrow
819
   DRAW_BUTTON_IF_NEEDED (scene->gui.rrarrow); // "jump to end" arrow
786
   DRAW_TEXT_IF_NEEDED (scene->gui.arrow_text); // arrow text
820
   DRAW_TEXT_IF_NEEDED (scene->gui.arrow_text); // arrow text
787
 
-
 
788
   if (want_framerate)
-
 
789
      Render_wprintf (99.0f, 1.0f, 0.0f, ALIGN_RIGHT, ALIGN_TOP, ALIGN_CENTER, arrow_fontindex, D3DCOLOR_RGBA (255, 255, 255, 255), NULL,
-
 
790
                      L"%d textures\n"
-
 
791
                      L"%d meshes\n"
-
 
792
                      L"%d fonts\n"
-
 
793
                      L"%d sprites\n"
-
 
794
                      L"%d fps", texture_count, mesh_count, font_count, sprite_count, framerate_value);
-
 
795
 
821
 
796
   // draw the other GUI buttons
822
   // draw the other GUI buttons
797
   DRAW_BUTTON_IF_NEEDED (scene->gui.chatbutton); // chat button
823
   DRAW_BUTTON_IF_NEEDED (scene->gui.chatbutton); // chat button
798
   DRAW_BUTTON_IF_NEEDED (scene->gui.gamesbutton); // games button
824
   DRAW_BUTTON_IF_NEEDED (scene->gui.gamesbutton); // games button
799
   DRAW_BUTTON_IF_NEEDED (scene->gui.peoplebutton); // people button
825
   DRAW_BUTTON_IF_NEEDED (scene->gui.peoplebutton); // people button
Line 801... Line 827...
801
   // does the parts pick line need to be displayed ?
827
   // does the parts pick line need to be displayed ?
802
   if (scene->gui.is_partspick_displayed)
828
   if (scene->gui.is_partspick_displayed)
803
   {
829
   {
804
#define PARTSIZE_PCT (100.0f / 13.0f)
830
#define PARTSIZE_PCT (100.0f / 13.0f)
805
 
831
 
806
      if (scene->gui.partspick_selectedpart == 'P')      Render_DrawSprite (&sprites[theme->lastmovetarget_spriteindex],  0.0f * PARTSIZE_PCT, 0.0f, PARTSIZE_PCT, 11.0f, 0xFF);
832
      if      (scene->gui.partspick_selectedpart == 'P') Render_DrawSprite (&sprites[theme->lastmovetarget_spriteindex],  0.0f * PARTSIZE_PCT, 0.0f, PARTSIZE_PCT, 11.0f, 0xFF);
807
      else if (scene->gui.partspick_selectedpart == 'R') Render_DrawSprite (&sprites[theme->lastmovetarget_spriteindex],  1.0f * PARTSIZE_PCT, 0.0f, PARTSIZE_PCT, 11.0f, 0xFF);
833
      else if (scene->gui.partspick_selectedpart == 'R') Render_DrawSprite (&sprites[theme->lastmovetarget_spriteindex],  1.0f * PARTSIZE_PCT, 0.0f, PARTSIZE_PCT, 11.0f, 0xFF);
808
      else if (scene->gui.partspick_selectedpart == 'N') Render_DrawSprite (&sprites[theme->lastmovetarget_spriteindex],  2.0f * PARTSIZE_PCT, 0.0f, PARTSIZE_PCT, 11.0f, 0xFF);
834
      else if (scene->gui.partspick_selectedpart == 'N') Render_DrawSprite (&sprites[theme->lastmovetarget_spriteindex],  2.0f * PARTSIZE_PCT, 0.0f, PARTSIZE_PCT, 11.0f, 0xFF);
809
      else if (scene->gui.partspick_selectedpart == 'B') Render_DrawSprite (&sprites[theme->lastmovetarget_spriteindex],  3.0f * PARTSIZE_PCT, 0.0f, PARTSIZE_PCT, 11.0f, 0xFF);
835
      else if (scene->gui.partspick_selectedpart == 'B') Render_DrawSprite (&sprites[theme->lastmovetarget_spriteindex],  3.0f * PARTSIZE_PCT, 0.0f, PARTSIZE_PCT, 11.0f, 0xFF);
810
      else if (scene->gui.partspick_selectedpart == 'Q') Render_DrawSprite (&sprites[theme->lastmovetarget_spriteindex],  4.0f * PARTSIZE_PCT, 0.0f, PARTSIZE_PCT, 11.0f, 0xFF);
836
      else if (scene->gui.partspick_selectedpart == 'Q') Render_DrawSprite (&sprites[theme->lastmovetarget_spriteindex],  4.0f * PARTSIZE_PCT, 0.0f, PARTSIZE_PCT, 11.0f, 0xFF);
811
      else if (scene->gui.partspick_selectedpart == 'K') Render_DrawSprite (&sprites[theme->lastmovetarget_spriteindex],  5.0f * PARTSIZE_PCT, 0.0f, PARTSIZE_PCT, 11.0f, 0xFF);
837
      else if (scene->gui.partspick_selectedpart == 'K') Render_DrawSprite (&sprites[theme->lastmovetarget_spriteindex],  5.0f * PARTSIZE_PCT, 0.0f, PARTSIZE_PCT, 11.0f, 0xFF);
Line 821... Line 847...
821
      Render_DrawSprite (&sprites[theme->flatsprites[COLOR_WHITE][PART_ROOK]],       1.0f * PARTSIZE_PCT, 0, PARTSIZE_PCT, 11.0f, (((scene->gui.partspick_hoveredpart == 'R') || (scene->gui.partspick_selectedpart == 'R')) ? 0xFF : 0x7F)); // white rook
847
      Render_DrawSprite (&sprites[theme->flatsprites[COLOR_WHITE][PART_ROOK]],       1.0f * PARTSIZE_PCT, 0, PARTSIZE_PCT, 11.0f, (((scene->gui.partspick_hoveredpart == 'R') || (scene->gui.partspick_selectedpart == 'R')) ? 0xFF : 0x7F)); // white rook
822
      Render_DrawSprite (&sprites[theme->flatsprites[COLOR_WHITE][PART_KNIGHT]],     2.0f * PARTSIZE_PCT, 0, PARTSIZE_PCT, 11.0f, (((scene->gui.partspick_hoveredpart == 'N') || (scene->gui.partspick_selectedpart == 'N')) ? 0xFF : 0x7F)); // white knight
848
      Render_DrawSprite (&sprites[theme->flatsprites[COLOR_WHITE][PART_KNIGHT]],     2.0f * PARTSIZE_PCT, 0, PARTSIZE_PCT, 11.0f, (((scene->gui.partspick_hoveredpart == 'N') || (scene->gui.partspick_selectedpart == 'N')) ? 0xFF : 0x7F)); // white knight
823
      Render_DrawSprite (&sprites[theme->flatsprites[COLOR_WHITE][PART_BISHOP]],     3.0f * PARTSIZE_PCT, 0, PARTSIZE_PCT, 11.0f, (((scene->gui.partspick_hoveredpart == 'B') || (scene->gui.partspick_selectedpart == 'B')) ? 0xFF : 0x7F)); // white bishop
849
      Render_DrawSprite (&sprites[theme->flatsprites[COLOR_WHITE][PART_BISHOP]],     3.0f * PARTSIZE_PCT, 0, PARTSIZE_PCT, 11.0f, (((scene->gui.partspick_hoveredpart == 'B') || (scene->gui.partspick_selectedpart == 'B')) ? 0xFF : 0x7F)); // white bishop
824
      Render_DrawSprite (&sprites[theme->flatsprites[COLOR_WHITE][PART_QUEEN]],      4.0f * PARTSIZE_PCT, 0, PARTSIZE_PCT, 11.0f, (((scene->gui.partspick_hoveredpart == 'Q') || (scene->gui.partspick_selectedpart == 'Q')) ? 0xFF : 0x7F)); // white queen
850
      Render_DrawSprite (&sprites[theme->flatsprites[COLOR_WHITE][PART_QUEEN]],      4.0f * PARTSIZE_PCT, 0, PARTSIZE_PCT, 11.0f, (((scene->gui.partspick_hoveredpart == 'Q') || (scene->gui.partspick_selectedpart == 'Q')) ? 0xFF : 0x7F)); // white queen
825
      Render_DrawSprite (&sprites[theme->flatsprites[COLOR_WHITE][PART_KING]],       5.0f * PARTSIZE_PCT, 0, PARTSIZE_PCT, 11.0f, (((scene->gui.partspick_hoveredpart == 'K') || (scene->gui.partspick_selectedpart == 'K')) ? 0xFF : 0x7F)); // white king
851
      Render_DrawSprite (&sprites[theme->flatsprites[COLOR_WHITE][PART_KING]],       5.0f * PARTSIZE_PCT, 0, PARTSIZE_PCT, 11.0f, (((scene->gui.partspick_hoveredpart == 'K') || (scene->gui.partspick_selectedpart == 'K')) ? 0xFF : 0x7F)); // white king
826
      Render_DrawSprite (&sprites[theme->lastmovesource_spriteindex],         6.0f * PARTSIZE_PCT, 0, PARTSIZE_PCT, 11.0f, (((scene->gui.partspick_hoveredpart == ' ') || (scene->gui.partspick_selectedpart == ' ')) ? 0xFF : 0x7F)); // erase mark
852
      Render_DrawSprite (&sprites[theme->lastmovesource_spriteindex],                6.0f * PARTSIZE_PCT, 0, PARTSIZE_PCT, 11.0f, (((scene->gui.partspick_hoveredpart == ' ') || (scene->gui.partspick_selectedpart == ' ')) ? 0xFF : 0x7F)); // erase mark
827
      Render_DrawSprite (&sprites[theme->flatsprites[COLOR_BLACK][PART_KING]],       7.0f * PARTSIZE_PCT, 0, PARTSIZE_PCT, 11.0f, (((scene->gui.partspick_hoveredpart == 'k') || (scene->gui.partspick_selectedpart == 'k')) ? 0xFF : 0x7F)); // black king
853
      Render_DrawSprite (&sprites[theme->flatsprites[COLOR_BLACK][PART_KING]],       7.0f * PARTSIZE_PCT, 0, PARTSIZE_PCT, 11.0f, (((scene->gui.partspick_hoveredpart == 'k') || (scene->gui.partspick_selectedpart == 'k')) ? 0xFF : 0x7F)); // black king
828
      Render_DrawSprite (&sprites[theme->flatsprites[COLOR_BLACK][PART_QUEEN]],      8.0f * PARTSIZE_PCT, 0, PARTSIZE_PCT, 11.0f, (((scene->gui.partspick_hoveredpart == 'q') || (scene->gui.partspick_selectedpart == 'q')) ? 0xFF : 0x7F)); // black queen
854
      Render_DrawSprite (&sprites[theme->flatsprites[COLOR_BLACK][PART_QUEEN]],      8.0f * PARTSIZE_PCT, 0, PARTSIZE_PCT, 11.0f, (((scene->gui.partspick_hoveredpart == 'q') || (scene->gui.partspick_selectedpart == 'q')) ? 0xFF : 0x7F)); // black queen
829
      Render_DrawSprite (&sprites[theme->flatsprites[COLOR_BLACK][PART_BISHOP]],     9.0f * PARTSIZE_PCT, 0, PARTSIZE_PCT, 11.0f, (((scene->gui.partspick_hoveredpart == 'b') || (scene->gui.partspick_selectedpart == 'b')) ? 0xFF : 0x7F)); // black bishop
855
      Render_DrawSprite (&sprites[theme->flatsprites[COLOR_BLACK][PART_BISHOP]],     9.0f * PARTSIZE_PCT, 0, PARTSIZE_PCT, 11.0f, (((scene->gui.partspick_hoveredpart == 'b') || (scene->gui.partspick_selectedpart == 'b')) ? 0xFF : 0x7F)); // black bishop
830
      Render_DrawSprite (&sprites[theme->flatsprites[COLOR_BLACK][PART_KNIGHT]],    10.0f * PARTSIZE_PCT, 0, PARTSIZE_PCT, 11.0f, (((scene->gui.partspick_hoveredpart == 'n') || (scene->gui.partspick_selectedpart == 'n')) ? 0xFF : 0x7F)); // black knight
856
      Render_DrawSprite (&sprites[theme->flatsprites[COLOR_BLACK][PART_KNIGHT]],    10.0f * PARTSIZE_PCT, 0, PARTSIZE_PCT, 11.0f, (((scene->gui.partspick_hoveredpart == 'n') || (scene->gui.partspick_selectedpart == 'n')) ? 0xFF : 0x7F)); // black knight
831
      Render_DrawSprite (&sprites[theme->flatsprites[COLOR_BLACK][PART_ROOK]],      11.0f * PARTSIZE_PCT, 0, PARTSIZE_PCT, 11.0f, (((scene->gui.partspick_hoveredpart == 'r') || (scene->gui.partspick_selectedpart == 'r')) ? 0xFF : 0x7F)); // black rook
857
      Render_DrawSprite (&sprites[theme->flatsprites[COLOR_BLACK][PART_ROOK]],      11.0f * PARTSIZE_PCT, 0, PARTSIZE_PCT, 11.0f, (((scene->gui.partspick_hoveredpart == 'r') || (scene->gui.partspick_selectedpart == 'r')) ? 0xFF : 0x7F)); // black rook
Line 838... Line 864...
838
   DRAW_TEXT_IF_NEEDED (scene->gui.comment_text); // move comments
864
   DRAW_TEXT_IF_NEEDED (scene->gui.comment_text); // move comments
839
   DRAW_TEXT_IF_NEEDED (scene->gui.history_text); // game history
865
   DRAW_TEXT_IF_NEEDED (scene->gui.history_text); // game history
840
   DRAW_TEXT_IF_NEEDED (scene->gui.clock_text); // game clock
866
   DRAW_TEXT_IF_NEEDED (scene->gui.clock_text); // game clock
841
 
867
 
842
   // draw the chatter channels text
868
   // draw the chatter channels text
843
   Render_GetTextBoundaries (-1, chat_fontindex, L"a", &rect);
869
   Render_GetTextBoundaries (-1, L"Papyrus", 8.0f, false, false, L"a", &rect);
844
   combinedheight_percent = (float) (rect.bottom * 100 / initial_height); // get a string's height
870
   combinedheight_percent = (float) (rect.bottom * 100 / initial_height) * 1.14f; // get a string's height
845
 
871
 
846
   // cycle through all the chat strings...
872
   // cycle through all the chat strings...
847
   ccreply = NULL;
873
   ccreply = NULL;
848
   for (cchistory_index = 0; cchistory_index < scene->gui.cchistory_count; cchistory_index++)
874
   for (cchistory_index = 0; cchistory_index < scene->gui.cchistory_count; cchistory_index++)
849
   {
875
   {
Line 859... Line 885...
859
      for (cchistory_index2 = cchistory_index; cchistory_index2 < scene->gui.cchistory_count; cchistory_index2++)
885
      for (cchistory_index2 = cchistory_index; cchistory_index2 < scene->gui.cchistory_count; cchistory_index2++)
860
      {
886
      {
861
         ccreply = &scene->gui.cchistory[cchistory_index2]; // quick access to CC reply
887
         ccreply = &scene->gui.cchistory[cchistory_index2]; // quick access to CC reply
862
 
888
 
863
         combinedwidth_percent = 1.0f;
889
         combinedwidth_percent = 1.0f;
-
 
890
         if (ccreply->channelname[0] != 0)
-
 
891
         {
864
         Render_GetTextBoundaries (100 - combinedwidth_percent, chat_fontindex, L"[] : ", &rect);
892
            Render_GetTextBoundaries (100 - combinedwidth_percent, L"Papyrus", 8.0f, false, false, L"[] : ", &rect);
865
         combinedwidth_percent += (float) (rect.right * 100 / initial_width);
893
            combinedwidth_percent += (float) (rect.right * 100 / initial_width);
866
         Render_GetTextBoundaries (100 - combinedwidth_percent, chat_fontindex, ccreply->channelname, &rect);
894
            Render_GetTextBoundaries (100 - combinedwidth_percent, L"Papyrus", 8.0f, false, false, ccreply->channelname, &rect);
867
         combinedwidth_percent += (float) (rect.right * 100 / initial_width);
895
            combinedwidth_percent += (float) (rect.right * 100 / initial_width);
-
 
896
         }
-
 
897
         if (ccreply->nickname[0] != 0)
-
 
898
         {
868
         Render_GetTextBoundaries (100 - combinedwidth_percent, chat_fontindex, ccreply->nickname, &rect);
899
            Render_GetTextBoundaries (100 - combinedwidth_percent, L"Papyrus", 8.0f, false, false, ccreply->nickname, &rect);
869
         combinedwidth_percent += (float) (rect.right * 100 / initial_width);
900
            combinedwidth_percent += (float) (rect.right * 100 / initial_width);
-
 
901
         }
870
         Render_GetTextBoundaries (100 - combinedwidth_percent, chat_fontindex, ccreply->text, &rect);
902
         Render_GetTextBoundaries (100 - combinedwidth_percent, L"Papyrus", 8.0f, false, false, ccreply->text, &rect);
871
         combinedheight_percent += (float) (rect.bottom * 100 / initial_height); // add this string's height 
903
         combinedheight_percent += (float) (rect.bottom * 100 / initial_height) * 1.14f; // add this string's height 
872
      }
904
      }
873
 
905
 
874
      // now for each string remaining...
906
      // now for each string remaining...
875
      for (; cchistory_index < scene->gui.cchistory_count; cchistory_index++)
907
      for (; cchistory_index < scene->gui.cchistory_count; cchistory_index++)
876
      {
908
      {
877
         ccreply = &scene->gui.cchistory[cchistory_index]; // quick access to CC reply
909
         ccreply = &scene->gui.cchistory[cchistory_index]; // quick access to CC reply
878
         rect.right = 10;
910
         rect.right = 10;
879
         PRINT_CCREPLY (ccreply); // print CC reply on screen
911
         PRINT_CCREPLY (ccreply); // print CC reply on screen
880
         combinedheight_percent -= (float) ((rect.bottom - rect.top) * 100 / initial_height); // draw it from top of zone to bottom
912
         combinedheight_percent -= (float) ((rect.bottom - rect.top) * 100 / initial_height) * 1.14f; // draw it from top of zone to bottom
881
      }
913
      }
882
   }
914
   }
883
 
915
 
884
   // are we online ?
916
   // are we online ?
885
   if (Player_FindByType (PLAYER_INTERNET) != NULL)
917
   if (Player_FindByType (PLAYER_INTERNET) != NULL)
Line 901... Line 933...
901
      Render_DrawSprite (&sprites[spinner_spriteindex[(int) (10.0f * current_time) % 12]], 47.0f, 46.0f, 6.0f, 8.0f, 255);
933
      Render_DrawSprite (&sprites[spinner_spriteindex[(int) (10.0f * current_time) % 12]], 47.0f, 46.0f, 6.0f, 8.0f, 255);
902
 
934
 
903
   // are we in demo mode ? if so, display the program name as a watermark
935
   // are we in demo mode ? if so, display the program name as a watermark
904
#ifndef NO_REGISTRATION
936
#ifndef NO_REGISTRATION
905
   if (!is_registered)
937
   if (!is_registered)
906
      Render_wprintf (50.0f, 60.0f, 0.0f, ALIGN_CENTER, ALIGN_CENTER, ALIGN_CENTER, chat_fontindex,
938
      Render_wprintf (50.0f, 60.0f, 0.0f, ALIGN_CENTER, ALIGN_CENTER, ALIGN_CENTER, L"Papyrus", 4.0f, false, false, D3DCOLOR_RGBA (255, 255, 255, 255), TEXTBG_NONE,
907
                      D3DCOLOR_RGBA (255, 255, 255, 255),
-
 
908
                      NULL, PROGRAM_NAME L"%s - " PROGRAM_URL L"\n- %d:%02d -", LOCALIZE (L"EvaluationMode"), (int) (DEMO_TIMEOUT - current_time) / 60, (int) (DEMO_TIMEOUT - current_time) % 60);
939
                      NULL, PROGRAM_NAME L"%s - " PROGRAM_URL L"\n- %d:%02d -", LOCALIZE (L"EvaluationMode"), (int) (DEMO_TIMEOUT - current_time) / 60, (int) (DEMO_TIMEOUT - current_time) % 60);
909
#endif // !NO_REGISTRATION
940
#endif // !NO_REGISTRATION
-
 
941
 
-
 
942
   // this must be printed last, so as to overlay all the rest
-
 
943
   if (want_framerate)
-
 
944
      Render_wprintf (99.0f, 1.0f, 0.0f, ALIGN_RIGHT, ALIGN_TOP, ALIGN_CENTER, L"Papyrus", 6.0f, false, false, D3DCOLOR_RGBA (255, 255, 255, 255), TEXTBG_NONE, NULL,
-
 
945
                      L"%d textures\n"
-
 
946
                      L"%d meshes\n"
-
 
947
                      L"%d fonts\n"
-
 
948
                      L"%d sprites\n"
-
 
949
                      L"%d fps", texture_count, mesh_count, font_count, sprite_count, framerate_value);
910
 
950
 
911
   // end 3D rendering on the back buffer
951
   // end 3D rendering on the back buffer
912
   //////////////////////////////////////
952
   //////////////////////////////////////
913
 
953
 
914
   d3ddev->EndScene (); // ends the 3D scene
954
   d3ddev->EndScene (); // ends the 3D scene
915
   d3ddev->Present (NULL, NULL, NULL, NULL); // displays the created frame on the screen
955
   d3ddev->Present (NULL, NULL, hMainWnd, NULL); // displays the created frame on the screen
916
 
956
 
917
   // update the frame rate
957
   // update the frame rate
918
   if (framerate_time < current_time)
958
   if (framerate_time < current_time)
919
   {
959
   {
920
      framerate_value = framerate_count;
960
      framerate_value = framerate_count;
Line 992... Line 1032...
992
 
1032
 
993
   // reallocate space to hold one texture more
1033
   // reallocate space to hold one texture more
994
   textures = (texture_t *) SAFE_realloc (textures, texture_count, texture_count + 1, sizeof (texture_t), false);
1034
   textures = (texture_t *) SAFE_realloc (textures, texture_count, texture_count + 1, sizeof (texture_t), false);
995
 
1035
 
996
   // ask Direct3D to prepare texture data
1036
   // ask Direct3D to prepare texture data
997
   if (FAILED (D3DXCreateTextureFromFile (d3ddev, texturefile_pathname, &textures[texture_count].texture)))
1037
   if (FAILED (D3DXCreateTextureFromFile (d3ddev, texturefile_pathname, &textures[texture_count].d3dtexture)))
998
   {
1038
   {
999
      MessageBox (NULL, LOCALIZE (L"Error_UnableToAddTextureD3DXCreateTextureFromFileFailed"), LOCALIZE (L"FatalError"), MB_ICONERROR | MB_OK);
1039
      MessageBox (NULL, LOCALIZE (L"Error_UnableToAddTextureD3DXCreateTextureFromFileFailed"), LOCALIZE (L"FatalError"), MB_ICONERROR | MB_OK);
1000
      terminate_everything = true; // this is a fatal error
1040
      terminate_everything = true; // this is a fatal error
1001
      return (-1); // bomb out on error
1041
      return (-1); // bomb out on error
1002
   }
1042
   }
1003
 
1043
 
1004
   // get info on the newly loaded texture such as size etc.
1044
   // get info on the newly loaded texture such as size etc.
1005
   textures[texture_count].texture->GetLevelDesc (0, &texture_description);
1045
   textures[texture_count].d3dtexture->GetLevelDesc (0, &texture_description);
1006
   textures[texture_count].width = texture_description.Width; // save texture width (as loaded)
1046
   textures[texture_count].width = texture_description.Width; // save texture width (as loaded)
1007
   textures[texture_count].height = texture_description.Height; // save texture height (as loaded)
1047
   textures[texture_count].height = texture_description.Height; // save texture height (as loaded)
1008
   textures[texture_count].hash = hash; // save its hash
1048
   textures[texture_count].hash = hash; // save its hash
1009
   texture_count++; // we know now one texture more
1049
   texture_count++; // we know now one texture more
1010
   return (texture_count - 1); // return its index
1050
   return (texture_count - 1); // return its index
1011
}
1051
}
1012
 
1052
 
1013
 
1053
 
1014
int Render_LoadFont (const wchar_t *font_name, int font_size, bool is_bold, bool is_italic)
1054
static int Render_LoadFont (const wchar_t *font_name, float font_sizepct, bool is_bold, bool is_italic)
1015
{
1055
{
1016
   // this function appends a new font in the global fonts buffer and returns its index
1056
   // this function appends a new font in the global fonts buffer and returns its index
1017
 
1057
 
1018
   unsigned long pathname_hash;
1058
   unsigned long pathname_hash;
1019
   int font_index;
1059
   int font_index;
-
 
1060
   int font_size;
-
 
1061
 
-
 
1062
   // convert font size to pixels
-
 
1063
   font_size = (int) ((font_sizepct * (float) initial_height) / 100.0f);
1020
 
1064
 
1021
   // first, get the hash of the requested pathname (include font size and weight parameters)
1065
   // first, get the hash of the requested pathname (include font size and weight parameters)
1022
   pathname_hash = HashString (font_name);
1066
   pathname_hash = HashString (font_name);
1023
   pathname_hash += 3 * (unsigned long) font_size + 2 * (unsigned long) is_bold + (unsigned long) is_italic;
1067
   pathname_hash += 3 * (unsigned long) font_size + 2 * (unsigned long) is_bold + (unsigned long) is_italic;
1024
 
1068
 
Line 1030... Line 1074...
1030
   // reallocate space to hold one font more
1074
   // reallocate space to hold one font more
1031
   fonts = (font_t *) SAFE_realloc (fonts, font_count, font_count + 1, sizeof (font_t), false);
1075
   fonts = (font_t *) SAFE_realloc (fonts, font_count, font_count + 1, sizeof (font_t), false);
1032
 
1076
 
1033
   // create a Direct3D font object and record font data
1077
   // create a Direct3D font object and record font data
1034
   if (FAILED (D3DXCreateFont (d3ddev, font_size, // font height
1078
   if (FAILED (D3DXCreateFont (d3ddev, font_size, // font height
1035
                               2 * font_size / 5, // font width
1079
                               0, // font width (0 means "use default width")
1036
                               (is_bold ? FW_BOLD : FW_NORMAL), // font weight (bold, etc)
1080
                               (is_bold ? FW_BOLD : FW_NORMAL), // font weight (bold, etc)
1037
                               0, // miplevels
1081
                               0, // miplevels
1038
                               is_italic, // is italic
1082
                               is_italic, // is italic
1039
                               DEFAULT_CHARSET, // charset
1083
                               DEFAULT_CHARSET, // charset
1040
                               OUT_DEFAULT_PRECIS, // precision
1084
                               OUT_DEFAULT_PRECIS, // precision
1041
                               CLEARTYPE_QUALITY, // font quality (antialiased or not)
1085
                               CLEARTYPE_QUALITY, // font quality (antialiased or not)
1042
                               DEFAULT_PITCH | FF_DONTCARE, // font family
1086
                               DEFAULT_PITCH | FF_DONTCARE, // font family
1043
                               font_name, // font name
1087
                               font_name, // font name
1044
                               &fonts[font_count].font))) // and a pointer that will receive the font
1088
                               &fonts[font_count].d3dfont))) // and a pointer that will receive the font
1045
   {
1089
   {
1046
      MessageBox (NULL, LOCALIZE (L"Error_UnableToAddFontD3DXCreateFontFailed"), LOCALIZE (L"FatalError"), MB_ICONERROR | MB_OK);
1090
      MessageBox (NULL, LOCALIZE (L"Error_UnableToAddFontD3DXCreateFontFailed"), LOCALIZE (L"FatalError"), MB_ICONERROR | MB_OK);
1047
      terminate_everything = true; // this is a fatal error
1091
      terminate_everything = true; // this is a fatal error
1048
      return (-1); // bomb out on error
1092
      return (-1); // bomb out on error
1049
   }
1093
   }
Line 1079... Line 1123...
1079
 
1123
 
1080
   // reallocate space to hold one sprite more
1124
   // reallocate space to hold one sprite more
1081
   sprites = (sprite_t *) SAFE_realloc (sprites, sprite_count, sprite_count + 1, sizeof (sprite_t), false);
1125
   sprites = (sprite_t *) SAFE_realloc (sprites, sprite_count, sprite_count + 1, sizeof (sprite_t), false);
1082
 
1126
 
1083
   // ask Direct3D to prepare texture data
1127
   // ask Direct3D to prepare texture data
1084
   if (FAILED (D3DXCreateSprite (d3ddev, &sprites[sprite_count].sprite)))
1128
   if (FAILED (D3DXCreateSprite (d3ddev, &sprites[sprite_count].d3dsprite)))
1085
   {
1129
   {
1086
      MessageBox (NULL, LOCALIZE (L"Error_UnableToAddSpriteD3DXCreateSpriteFailed"), LOCALIZE (L"FatalError"), MB_ICONERROR | MB_OK);
1130
      MessageBox (NULL, LOCALIZE (L"Error_UnableToAddSpriteD3DXCreateSpriteFailed"), LOCALIZE (L"FatalError"), MB_ICONERROR | MB_OK);
1087
      terminate_everything = true; // this is a fatal error
1131
      terminate_everything = true; // this is a fatal error
1088
      return (-1); // bomb out on error
1132
      return (-1); // bomb out on error
1089
   }
1133
   }
Line 1407... Line 1451...
1407
   d3ddev->SetRenderState (D3DRS_STENCILFUNC, D3DCMP_LESS); // instruct how to fill the stencil buffer
1451
   d3ddev->SetRenderState (D3DRS_STENCILFUNC, D3DCMP_LESS); // instruct how to fill the stencil buffer
1408
   d3ddev->SetRenderState (D3DRS_STENCILPASS, D3DSTENCILOP_KEEP); // instruct how to fill the stencil buffer
1452
   d3ddev->SetRenderState (D3DRS_STENCILPASS, D3DSTENCILOP_KEEP); // instruct how to fill the stencil buffer
1409
 
1453
 
1410
   // set the texture for this mesh
1454
   // set the texture for this mesh
1411
   if (sceneobject->texture_index != -1)
1455
   if (sceneobject->texture_index != -1)
1412
      d3ddev->SetTexture (0, textures[sceneobject->texture_index].texture);
1456
      d3ddev->SetTexture (0, textures[sceneobject->texture_index].d3dtexture);
1413
   else
1457
   else
1414
      d3ddev->SetTexture (0, NULL);
1458
      d3ddev->SetTexture (0, NULL);
1415
 
1459
 
1416
   // adjust the light reflection properties by setting the material
1460
   // adjust the light reflection properties by setting the material
1417
   if (sceneobject->material_index != -1)
1461
   if (sceneobject->material_index != -1)
Line 1458... Line 1502...
1458
   d3dmaterial.Emissive = D3DXCOLOR (material->emissive, material->emissive, material->emissive, material->transparency);
1502
   d3dmaterial.Emissive = D3DXCOLOR (material->emissive, material->emissive, material->emissive, material->transparency);
1459
   d3dmaterial.Specular = D3DXCOLOR (material->specular, material->specular, material->specular, material->transparency);
1503
   d3dmaterial.Specular = D3DXCOLOR (material->specular, material->specular, material->specular, material->transparency);
1460
   d3dmaterial.Power = material->shininess;
1504
   d3dmaterial.Power = material->shininess;
1461
   d3ddev->SetMaterial (&d3dmaterial);
1505
   d3ddev->SetMaterial (&d3dmaterial);
1462
 
1506
 
1463
   d3ddev->SetTexture (0, textures[theme->shadow_textureindex].texture); // select the texture we want
1507
   d3ddev->SetTexture (0, textures[theme->shadow_textureindex].d3dtexture); // select the texture we want
1464
 
1508
 
1465
   // and then draw it
1509
   // and then draw it
1466
   d3ddev->SetStreamSource (0, tile_mesh->d3dvertices, 0, sizeof (vertex_t)); // set stream source
1510
   d3ddev->SetStreamSource (0, tile_mesh->d3dvertices, 0, sizeof (vertex_t)); // set stream source
1467
   d3ddev->SetFVF (tile_mesh->vertex_format); // select which vertex format we are using
1511
   d3ddev->SetFVF (tile_mesh->vertex_format); // select which vertex format we are using
1468
   d3ddev->SetRenderState (D3DRS_CULLMODE, D3DCULL_CW); // draw the faces backwards
1512
   d3ddev->SetRenderState (D3DRS_CULLMODE, D3DCULL_CW); // draw the faces backwards
Line 1511... Line 1555...
1511
   // tell Direct3D about our matrix
1555
   // tell Direct3D about our matrix
1512
   d3ddev->SetTransform (D3DTS_WORLD, &(scaling_matrix * rotation_matrix * translation_matrix));
1556
   d3ddev->SetTransform (D3DTS_WORLD, &(scaling_matrix * rotation_matrix * translation_matrix));
1513
 
1557
 
1514
   // set the texture for this mesh
1558
   // set the texture for this mesh
1515
   if (sceneobject->texture_index != -1)
1559
   if (sceneobject->texture_index != -1)
1516
      d3ddev->SetTexture (0, textures[sceneobject->texture_index].texture);
1560
      d3ddev->SetTexture (0, textures[sceneobject->texture_index].d3dtexture);
1517
   else
1561
   else
1518
      d3ddev->SetTexture (0, NULL);
1562
      d3ddev->SetTexture (0, NULL);
1519
 
1563
 
1520
   // adjust the light reflection properties by setting the material
1564
   // adjust the light reflection properties by setting the material
1521
   if (sceneobject->material_index != -1)
1565
   if (sceneobject->material_index != -1)
Line 1592... Line 1636...
1592
   d3dmaterial.Specular = D3DXCOLOR (material->specular, material->specular, material->specular, material->specular);
1636
   d3dmaterial.Specular = D3DXCOLOR (material->specular, material->specular, material->specular, material->specular);
1593
   d3dmaterial.Power = material->shininess;
1637
   d3dmaterial.Power = material->shininess;
1594
   d3ddev->SetMaterial (&d3dmaterial);
1638
   d3ddev->SetMaterial (&d3dmaterial);
1595
 
1639
 
1596
   // select the texture we want
1640
   // select the texture we want
1597
   d3ddev->SetTexture (0, textures[sceneobject->texture_index].texture);
1641
   d3ddev->SetTexture (0, textures[sceneobject->texture_index].d3dtexture);
1598
 
1642
 
1599
   // and then draw it
1643
   // and then draw it
1600
   d3ddev->SetStreamSource (0, tile_mesh->d3dvertices, 0, sizeof (vertex_t)); // set stream source
1644
   d3ddev->SetStreamSource (0, tile_mesh->d3dvertices, 0, sizeof (vertex_t)); // set stream source
1601
   d3ddev->SetFVF (tile_mesh->vertex_format); // select which vertex format we are using
1645
   d3ddev->SetFVF (tile_mesh->vertex_format); // select which vertex format we are using
1602
   d3ddev->SetRenderState (D3DRS_CULLMODE, D3DCULL_CW); // draw the back faces
1646
   d3ddev->SetRenderState (D3DRS_CULLMODE, D3DCULL_CW); // draw the back faces
Line 1628... Line 1672...
1628
 
1672
 
1629
   scale_x = (width_percent * (float) initial_width) / (float) (100 * texture->width);
1673
   scale_x = (width_percent * (float) initial_width) / (float) (100 * texture->width);
1630
   scale_y = (height_percent * (float) initial_height) / (float) (100 * texture->height);
1674
   scale_y = (height_percent * (float) initial_height) / (float) (100 * texture->height);
1631
 
1675
 
1632
   // start rendering the sprite (an optimized version would draw all sprites in a row...)
1676
   // start rendering the sprite (an optimized version would draw all sprites in a row...)
1633
   sprite->sprite->Begin (D3DXSPRITE_ALPHABLEND);
1677
   sprite->d3dsprite->Begin (D3DXSPRITE_ALPHABLEND);
1634
 
1678
 
1635
   // scale and position the sprite
1679
   // scale and position the sprite
1636
   D3DXMatrixTransformation2D (&scaling_matrix, // output matrix
1680
   D3DXMatrixTransformation2D (&scaling_matrix, // output matrix
1637
                               NULL, // scaling center
1681
                               NULL, // scaling center
1638
                               0.0f, // scaling rotation
1682
                               0.0f, // scaling rotation
1639
                               &D3DXVECTOR2 (scale_x, scale_y), // scaling ratio
1683
                               &D3DXVECTOR2 (scale_x, scale_y), // scaling ratio
1640
                               &D3DXVECTOR2 (0, 0), // rotation center
1684
                               &D3DXVECTOR2 (0, 0), // rotation center
1641
                               0.0f, // rotation
1685
                               0.0f, // rotation
1642
                               &D3DXVECTOR2 (x_percent * (float) initial_width / 100.0f, y_percent * (float) initial_height / 100.0f)); // translation
1686
                               &D3DXVECTOR2 (x_percent * (float) initial_width / 100.0f, y_percent * (float) initial_height / 100.0f)); // translation
1643
   sprite->sprite->SetTransform (&scaling_matrix); // tell the sprite about the scaling and position transform
1687
   sprite->d3dsprite->SetTransform (&scaling_matrix); // tell the sprite about the scaling and position transform
1644
 
1688
 
1645
   // now draw the sprite with the specified alpha and finish rendering
1689
   // now draw the sprite with the specified alpha and finish rendering
1646
   sprite->sprite->Draw (texture->texture, NULL, NULL, NULL, D3DCOLOR_ARGB (alpha, 255, 255, 255));
1690
   sprite->d3dsprite->Draw (texture->d3dtexture, NULL, NULL, NULL, D3DCOLOR_ARGB (alpha, 255, 255, 255));
1647
   sprite->sprite->End ();
1691
   sprite->d3dsprite->End ();
1648
 
1692
 
1649
   return; // finished
1693
   return; // finished
1650
}
1694
}
1651
 
1695
 
1652
 
1696
 
1653
static void Render_GetTextBoundaries (float maxwidth_percent, int font_id, wchar_t *text, RECT *rect)
1697
static int Render_GetTextBoundaries (float maxwidth_percent, wchar_t *font_face, float font_sizepct, bool is_bold, bool is_italic, wchar_t *text, RECT *rect)
1654
{
1698
{
1655
   // this function computes and returns the size of the rectangle the specified text will fit into. Note that text may be modified
1699
   // this function computes and returns the size of the rectangle the specified text will fit into. Note that text may be modified
1656
   // to insert new lines if it doesn't fit in a single line.
1700
   // to insert new lines if it doesn't fit in a single line.
1657
 
1701
 
1658
   int char_index;
1702
   int char_index;
1659
   int length;
1703
   int length;
1660
   int optimal_length;
1704
   int optimal_length;
1661
   bool have_split;
1705
   bool have_split;
1662
   int max_width;
1706
   int max_width;
-
 
1707
   int font_id;
-
 
1708
 
-
 
1709
   // figure out the font to use and load it if necessary
-
 
1710
   font_id = Render_LoadFont (font_face, font_sizepct, is_bold, is_italic);
1663
 
1711
 
1664
   // blank out the output rectangle
1712
   // blank out the output rectangle
1665
   memset (rect, 0, sizeof (RECT));
1713
   memset (rect, 0, sizeof (RECT));
1666
 
1714
 
1667
   // ask direct3D to compute the text size a first time
1715
   // ask direct3D to compute the text size a first time
1668
   fonts[font_id].font->DrawText (NULL, text, -1, rect, DT_CALCRECT, D3DCOLOR (0));
1716
   fonts[font_id].d3dfont->DrawText (NULL, text, -1, rect, DT_CALCRECT | DT_WORDBREAK, D3DCOLOR (0));
1669
 
1717
 
1670
   // if max width is not set, set it to viewport width
1718
   // if max width is not set, set it to viewport width
1671
   if (maxwidth_percent <= 0)
1719
   if (maxwidth_percent <= 0)
1672
      max_width = initial_width; // then use it to compute the real max width
1720
      max_width = initial_width; // then use it to compute the real max width
1673
   else
1721
   else
Line 1687... Line 1735...
1687
            have_split = true; // remember string has been split
1735
            have_split = true; // remember string has been split
1688
            char_index += optimal_length;
1736
            char_index += optimal_length;
1689
         }
1737
         }
1690
 
1738
 
1691
      // and ask direct3D to compute the text size again
1739
      // and ask direct3D to compute the text size again
1692
      fonts[font_id].font->DrawText (NULL, text, -1, rect, DT_CALCRECT, D3DCOLOR (0));
1740
      fonts[font_id].d3dfont->DrawText (NULL, text, -1, rect, DT_CALCRECT, D3DCOLOR (0));
1693
   }
1741
   }
1694
 
1742
 
1695
   return; // finished
1743
   return (font_id); // finished, return the index of the font in the fonts array
1696
}
1744
}
1697
 
1745
 
1698
 
1746
 
1699
static void Render_wprintf (float x_percent, float y_percent, float maxwidth_percent, int horiz_align, int vert_align, int text_align, int font_id, unsigned long color_rgba, RECT *out_rect, const wchar_t *fmt, ...)
1747
static void Render_wprintf (float x_percent, float y_percent, float maxwidth_percent, int horiz_align, int vert_align, int text_align, wchar_t *font_face, float font_sizepct, bool want_bold, bool want_italic, unsigned long color_rgba, int background_flags, RECT *out_rect, const wchar_t *fmt, ...)
1700
{
1748
{
1701
   // this function displays text on the Direct3D interface according to the given parameters. X and Y are the base coordinates of
1749
   // this function displays text on the Direct3D interface according to the given parameters. X and Y are the base coordinates of
1702
   // the text's bounding rectangle. Max_width is the maximum allowed width of this rectangle before wrapping words on a new line.
1750
   // the text's bounding rectangle. Max_width is the maximum allowed width of this rectangle before wrapping words on a new line.
1703
   // Horiz_align and vert_align are the alignment parameters of the RECTANGLE relatively to X and Y. Text_align is the alignment of
1751
   // Horiz_align and vert_align are the alignment parameters of the RECTANGLE relatively to X and Y. Text_align is the alignment of
1704
   // the TEXT inside this rectangle (meaning, you can have right-aligned text in a rectangle that is centered on a point). Font_id
1752
   // the TEXT inside this rectangle (meaning, you can have right-aligned text in a rectangle that is centered on a point). Font_id
1705
   // and color.alphargb define the font and color of the text. Out_rect, if filled, will point to a RECT structure describing the text's
1753
   // and color.alphargb define the font and color of the text. Out_rect, if filled, will point to a RECT structure describing the text's
1706
   // bounding rectangle, after any word wrapping corrections have been made. Fmt is a format string containing the text itself,
1754
   // bounding rectangle, after any word wrapping corrections have been made. Fmt is a format string containing the text itself,
1707
   // printf-style.
1755
   // printf-style.
1708
 
1756
 
-
 
1757
   DWORD text_format;
1709
   va_list argptr;
1758
   va_list argptr;
1710
   RECT rect;
1759
   RECT rect;
-
 
1760
   int font_id;
1711
   int left;
1761
   int left;
1712
   int top;
1762
   int top;
1713
   int x;
1763
   int x;
1714
   int y;
1764
   int y;
1715
 
1765
 
1716
   // concatenate all the arguments in one string
1766
   // concatenate all the arguments in one string
1717
   va_start (argptr, fmt);
1767
   va_start (argptr, fmt);
1718
   wvsprintf (printf_buffer, fmt, argptr);
1768
   wvsprintf (printf_buffer, fmt, argptr);
1719
   va_end (argptr);
1769
   va_end (argptr);
-
 
1770
 
-
 
1771
   /*
-
 
1772
   current_height = 1024   2048
-
 
1773
   min               48     24
-
 
1774
   */
-
 
1775
 
-
 
1776
   // bound font_size according to viewport height
1720
 
1777
 
1721
   // translate percent coordinates into absolute coordinates
1778
   // translate percent coordinates into absolute coordinates
1722
   x = (int) ((x_percent * (float) initial_width) / 100.0f);
1779
   x = (int) ((x_percent * (float) initial_width) / 100.0f);
1723
   y = (int) ((y_percent * (float) initial_height) / 100.0f);
1780
   y = (int) ((y_percent * (float) initial_height) / 100.0f);
1724
 
1781
 
1725
   // get the text boundaries
1782
   // get the text boundaries
1726
   Render_GetTextBoundaries (maxwidth_percent, font_id, printf_buffer, &rect);
1783
   font_id = Render_GetTextBoundaries (maxwidth_percent, font_face, font_sizepct, want_bold, want_italic, printf_buffer, &rect);
1727
 
1784
 
1728
   // horizontal alignment
1785
   // horizontal alignment
1729
   if (horiz_align == ALIGN_LEFT)
1786
   if (horiz_align == ALIGN_LEFT)
1730
      left = x;
1787
      left = x;
1731
   else if (horiz_align == ALIGN_RIGHT)
1788
   else if (horiz_align == ALIGN_RIGHT)
Line 1741... Line 1798...
1741
   else
1798
   else
1742
      top = y - rect.bottom / 2;
1799
      top = y - rect.bottom / 2;
1743
 
1800
 
1744
   // now reposition our rectangle correctly acording to alignment
1801
   // now reposition our rectangle correctly acording to alignment
1745
   OffsetRect (&rect, left, top);
1802
   OffsetRect (&rect, left, top);
-
 
1803
 
-
 
1804
   // compute the DirectX text format parameter value
-
 
1805
   text_format = (text_align == ALIGN_LEFT ? DT_LEFT : (text_align == ALIGN_RIGHT ? DT_RIGHT : DT_CENTER));
-
 
1806
 
-
 
1807
   // draw a fading rectangle behind the text
-
 
1808
   if (background_flags != TEXTBG_NONE)
-
 
1809
   {
-
 
1810
      static int textbgsprite_index = -1;
-
 
1811
 
-
 
1812
      D3DXMATRIX scaling_matrix;
-
 
1813
      sprite_t *textbgsprite;
-
 
1814
      texture_t *texture;
-
 
1815
 
-
 
1816
      if (textbgsprite_index == -1)
-
 
1817
         textbgsprite_index = Render_LoadSprite (L"%s/data/sprites/textbg.png", app_path);
-
 
1818
      textbgsprite = &sprites[textbgsprite_index];
-
 
1819
      texture = &textures[textbgsprite->texture_index]; // quick access to sprite's texture
-
 
1820
 
-
 
1821
      // start rendering the sprite (an optimized version would draw all sprites in a row...)
-
 
1822
      textbgsprite->d3dsprite->Begin (D3DXSPRITE_ALPHABLEND);
-
 
1823
 
-
 
1824
      // scale and position the sprite
-
 
1825
      D3DXMatrixTransformation2D (&scaling_matrix, // output matrix
-
 
1826
                                  NULL, // scaling center
-
 
1827
                                  0.0f, // scaling rotation
-
 
1828
                                  &D3DXVECTOR2 ((rect.right - rect.left + (((background_flags & TEXTBG_LEFT ? 0.5f : 0.0f) + (background_flags & TEXTBG_RIGHT  ? 0.5f : 0.0f)) * initial_width / 100.0f)) / (float) texture->width,
-
 
1829
                                                (rect.bottom - rect.top + (((background_flags & TEXTBG_TOP  ? 0.5f : 0.0f) + (background_flags & TEXTBG_BOTTOM ? 0.5f : 0.0f)) * initial_width / 100.0f)) / (float) texture->height), // scaling ratio
-
 
1830
                                  &D3DXVECTOR2 (0, 0), // rotation center
-
 
1831
                                  0.0f, // rotation
-
 
1832
                                  &D3DXVECTOR2 ((float) rect.left - ((background_flags & TEXTBG_LEFT ? 0.5f : 0.0f) * initial_width / 100.0f),
-
 
1833
                                                (float) rect.top  - ((background_flags & TEXTBG_TOP  ? 0.5f : 0.0f) * initial_width / 100.0f))); // translation
-
 
1834
      textbgsprite->d3dsprite->SetTransform (&scaling_matrix); // tell the sprite about the scaling and position transform
-
 
1835
 
-
 
1836
      // now draw the sprite with the specified alpha and finish rendering
-
 
1837
      textbgsprite->d3dsprite->Draw (texture->d3dtexture, NULL, NULL, NULL, D3DCOLOR_ARGB (176, 255, 255, 255));
-
 
1838
      textbgsprite->d3dsprite->End ();
-
 
1839
   }
-
 
1840
 
-
 
1841
   // else if no fading rectangle, draw a letter border in inverted colors
-
 
1842
   else if (current_height > 1000)
-
 
1843
   {
-
 
1844
      unsigned long inverted_argbcolor = 0x7F000000 | ((0xFFFFFFFF - color_rgba) >> 8);
-
 
1845
 
-
 
1846
      rect.left--; fonts[font_id].d3dfont->DrawText (NULL, printf_buffer, -1, &rect, text_format, inverted_argbcolor);
-
 
1847
      rect.top--;  fonts[font_id].d3dfont->DrawText (NULL, printf_buffer, -1, &rect, text_format, inverted_argbcolor);
-
 
1848
      rect.left++; fonts[font_id].d3dfont->DrawText (NULL, printf_buffer, -1, &rect, text_format, inverted_argbcolor);
-
 
1849
      rect.left++; fonts[font_id].d3dfont->DrawText (NULL, printf_buffer, -1, &rect, text_format, inverted_argbcolor);
-
 
1850
      rect.top++;  fonts[font_id].d3dfont->DrawText (NULL, printf_buffer, -1, &rect, text_format, inverted_argbcolor);
-
 
1851
      rect.top++;  fonts[font_id].d3dfont->DrawText (NULL, printf_buffer, -1, &rect, text_format, inverted_argbcolor);
-
 
1852
      rect.left--; fonts[font_id].d3dfont->DrawText (NULL, printf_buffer, -1, &rect, text_format, inverted_argbcolor);
-
 
1853
      rect.left--; fonts[font_id].d3dfont->DrawText (NULL, printf_buffer, -1, &rect, text_format, inverted_argbcolor);
-
 
1854
 
-
 
1855
      rect.left++; rect.top--; // restore original rectangle position
-
 
1856
   }
1746
 
1857
 
1747
   // and draw the text
1858
   // and draw the text
1748
   if (text_align == ALIGN_LEFT)
-
 
1749
      fonts[font_id].font->DrawText (NULL, printf_buffer, -1, &rect, DT_LEFT, RGBACOLOR_TO_ARGBCOLOR (color_rgba));
-
 
1750
   else if (horiz_align == ALIGN_RIGHT)
-
 
1751
      fonts[font_id].font->DrawText (NULL, printf_buffer, -1, &rect, DT_RIGHT, RGBACOLOR_TO_ARGBCOLOR (color_rgba));
-
 
1752
   else
-
 
1753
      fonts[font_id].font->DrawText (NULL, printf_buffer, -1, &rect, DT_CENTER, RGBACOLOR_TO_ARGBCOLOR (color_rgba));
1859
   fonts[font_id].d3dfont->DrawText (NULL, printf_buffer, -1, &rect, text_format, 0xFF000000 | (RGBACOLOR_TO_ARGBCOLOR (color_rgba) & 0x00FFFFFF));
1754
 
1860
 
1755
   // do we want the output rectangle ?
1861
   // do we want the output rectangle ?
1756
   if (out_rect != NULL)
1862
   if (out_rect != NULL)
1757
      memcpy (out_rect, &rect, sizeof (rect)); // if so, copy it in the given variable
1863
      memcpy (out_rect, &rect, sizeof (rect)); // if so, copy it in the given variable
1758
 
1864