2005-07-24 14:12:37 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2007-03-01 01:24:44 +00:00
|
|
|
/** @file gfx.cpp */
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
#include "stdafx.h"
|
2005-06-02 19:30:21 +00:00
|
|
|
#include "openttd.h"
|
2007-12-23 10:56:02 +00:00
|
|
|
#include "gfx_func.h"
|
2005-02-10 05:43:30 +00:00
|
|
|
#include "spritecache.h"
|
2005-07-21 18:44:27 +00:00
|
|
|
#include "variables.h"
|
2006-11-16 22:05:33 +00:00
|
|
|
#include "fontcache.h"
|
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 10:00:30 +00:00
|
|
|
#include "genworld.h"
|
2006-12-03 17:42:56 +00:00
|
|
|
#include "debug.h"
|
2007-12-23 10:56:02 +00:00
|
|
|
#include "zoom_func.h"
|
2007-06-21 16:17:47 +00:00
|
|
|
#include "texteff.hpp"
|
2007-06-17 20:30:28 +00:00
|
|
|
#include "blitter/factory.hpp"
|
2007-07-05 12:23:54 +00:00
|
|
|
#include "video/video_driver.hpp"
|
2007-12-21 19:49:27 +00:00
|
|
|
#include "strings_func.h"
|
2007-12-25 11:26:07 +00:00
|
|
|
#include "core/math_func.hpp"
|
2008-01-13 14:37:30 +00:00
|
|
|
#include "settings_type.h"
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-01-13 01:21:35 +00:00
|
|
|
#include "table/palettes.h"
|
|
|
|
#include "table/sprites.h"
|
|
|
|
#include "table/control_codes.h"
|
|
|
|
|
2007-03-01 01:24:44 +00:00
|
|
|
byte _dirkeys; ///< 1 = left, 2 = up, 4 = right, 8 = down
|
2007-01-13 14:43:46 +00:00
|
|
|
bool _fullscreen;
|
|
|
|
CursorVars _cursor;
|
2007-03-01 01:24:44 +00:00
|
|
|
bool _ctrl_pressed; ///< Is Ctrl pressed?
|
|
|
|
bool _shift_pressed; ///< Is Shift pressed?
|
2007-01-13 14:43:46 +00:00
|
|
|
byte _fast_forward;
|
|
|
|
bool _left_button_down;
|
|
|
|
bool _left_button_clicked;
|
|
|
|
bool _right_button_down;
|
|
|
|
bool _right_button_clicked;
|
|
|
|
DrawPixelInfo _screen;
|
2008-01-11 17:12:41 +00:00
|
|
|
bool _screen_disable_anim = false; ///< Disable palette animation (important for 32bpp-anim blitter during giant screenshot)
|
2007-01-13 14:43:46 +00:00
|
|
|
bool _exit_game;
|
|
|
|
bool _networking; ///< are we in networking mode?
|
|
|
|
byte _game_mode;
|
2008-03-04 12:14:34 +00:00
|
|
|
int8 _pause_game;
|
2007-01-13 14:43:46 +00:00
|
|
|
int _pal_first_dirty;
|
2007-06-19 15:04:08 +00:00
|
|
|
int _pal_count_dirty;
|
2007-01-13 14:43:46 +00:00
|
|
|
|
2005-06-30 05:27:32 +00:00
|
|
|
Colour _cur_palette[256];
|
2006-05-09 13:23:04 +00:00
|
|
|
byte _stringwidth_table[FS_END][224];
|
2007-12-23 10:56:02 +00:00
|
|
|
DrawPixelInfo *_cur_dpi;
|
|
|
|
byte _colour_gradient[16][8];
|
|
|
|
bool _use_dos_palette;
|
2005-06-30 05:27:32 +00:00
|
|
|
|
2007-10-05 21:49:15 +00:00
|
|
|
static void GfxMainBlitter(const Sprite *sprite, int x, int y, BlitterMode mode, const SubSprite *sub = NULL);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-05-09 13:23:04 +00:00
|
|
|
FontSize _cur_fontsize;
|
|
|
|
static FontSize _last_fontsize;
|
2007-06-12 20:24:12 +00:00
|
|
|
static uint8 _cursor_backup[64 * 64 * 4];
|
2007-09-09 10:13:17 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The rect for repaint.
|
|
|
|
*
|
|
|
|
* This rectangle defines the area which should be repaint by the video driver.
|
|
|
|
*
|
|
|
|
* @ingroup dirty
|
|
|
|
*/
|
2004-08-09 17:04:08 +00:00
|
|
|
static Rect _invalid_rect;
|
2005-02-11 17:12:11 +00:00
|
|
|
static const byte *_color_remap_ptr;
|
2004-08-09 17:04:08 +00:00
|
|
|
static byte _string_colorremap[3];
|
|
|
|
|
2005-07-05 11:09:18 +00:00
|
|
|
#define DIRTY_BYTES_PER_LINE (MAX_SCREEN_WIDTH / 64)
|
2004-08-09 17:04:08 +00:00
|
|
|
static byte _dirty_blocks[DIRTY_BYTES_PER_LINE * MAX_SCREEN_HEIGHT / 8];
|
|
|
|
|
2005-07-05 11:09:18 +00:00
|
|
|
void GfxScroll(int left, int top, int width, int height, int xo, int yo)
|
|
|
|
{
|
2007-06-17 20:30:28 +00:00
|
|
|
Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter();
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-07-05 11:09:18 +00:00
|
|
|
if (xo == 0 && yo == 0) return;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-07-05 11:09:18 +00:00
|
|
|
if (_cursor.visible) UndrawMouseCursor();
|
2007-08-19 09:38:30 +00:00
|
|
|
UndrawChatMessage();
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-06-18 20:08:21 +00:00
|
|
|
blitter->ScrollBuffer(_screen.dst_ptr, left, top, width, height, xo, yo);
|
2007-03-01 01:24:44 +00:00
|
|
|
/* This part of the screen is now dirty. */
|
2007-07-05 12:23:54 +00:00
|
|
|
_video_driver->MakeDirty(left, top, width, height);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-07-05 11:09:18 +00:00
|
|
|
void GfxFillRect(int left, int top, int right, int bottom, int color)
|
|
|
|
{
|
2007-06-17 20:30:28 +00:00
|
|
|
Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter();
|
2007-06-12 20:24:12 +00:00
|
|
|
const DrawPixelInfo *dpi = _cur_dpi;
|
|
|
|
void *dst;
|
2004-11-01 15:08:40 +00:00
|
|
|
const int otop = top;
|
|
|
|
const int oleft = left;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-05-15 14:08:39 +00:00
|
|
|
if (dpi->zoom != ZOOM_LVL_NORMAL) return;
|
2005-07-05 11:09:18 +00:00
|
|
|
if (left > right || top > bottom) return;
|
|
|
|
if (right < dpi->left || left >= dpi->left + dpi->width) return;
|
|
|
|
if (bottom < dpi->top || top >= dpi->top + dpi->height) return;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
if ( (left -= dpi->left) < 0) left = 0;
|
|
|
|
right = right - dpi->left + 1;
|
2005-07-05 11:09:18 +00:00
|
|
|
if (right > dpi->width) right = dpi->width;
|
2004-08-09 17:04:08 +00:00
|
|
|
right -= left;
|
|
|
|
assert(right > 0);
|
|
|
|
|
|
|
|
if ( (top -= dpi->top) < 0) top = 0;
|
|
|
|
bottom = bottom - dpi->top + 1;
|
2005-07-05 11:09:18 +00:00
|
|
|
if (bottom > dpi->height) bottom = dpi->height;
|
2004-08-09 17:04:08 +00:00
|
|
|
bottom -= top;
|
|
|
|
assert(bottom > 0);
|
|
|
|
|
2007-06-17 20:30:28 +00:00
|
|
|
dst = blitter->MoveTo(dpi->dst_ptr, left, top);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-11-19 21:02:30 +00:00
|
|
|
if (!HasBit(color, PALETTE_MODIFIER_GREYOUT)) {
|
|
|
|
if (!HasBit(color, USE_COLORTABLE)) {
|
2007-06-18 18:45:12 +00:00
|
|
|
blitter->DrawRect(dst, right, bottom, (uint8)color);
|
2004-08-09 17:04:08 +00:00
|
|
|
} else {
|
2007-06-17 20:30:28 +00:00
|
|
|
blitter->DrawColorMappingRect(dst, right, bottom, GB(color, 0, PALETTE_WIDTH));
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
} else {
|
2004-11-01 15:08:40 +00:00
|
|
|
byte bo = (oleft - left + dpi->left + otop - top + dpi->top) & 1;
|
2004-08-09 17:04:08 +00:00
|
|
|
do {
|
2007-06-17 20:30:28 +00:00
|
|
|
for (int i = (bo ^= 1); i < right; i += 2) blitter->SetPixel(dst, i, 0, (uint8)color);
|
|
|
|
dst = blitter->MoveTo(dst, 0, 1);
|
2004-11-01 15:08:40 +00:00
|
|
|
} while (--bottom > 0);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GfxDrawLine(int x, int y, int x2, int y2, int color)
|
|
|
|
{
|
2007-06-18 19:38:23 +00:00
|
|
|
Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter();
|
|
|
|
DrawPixelInfo *dpi = _cur_dpi;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-06-18 19:38:23 +00:00
|
|
|
x -= dpi->left;
|
|
|
|
x2 -= dpi->left;
|
|
|
|
y -= dpi->top;
|
|
|
|
y2 -= dpi->top;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-06-18 19:38:23 +00:00
|
|
|
/* Check clipping */
|
|
|
|
if (x < 0 && x2 < 0) return;
|
|
|
|
if (y < 0 && y2 < 0) return;
|
|
|
|
if (x > dpi->width && x2 > dpi->width) return;
|
|
|
|
if (y > dpi->height && y2 > dpi->height) return;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-06-18 19:38:23 +00:00
|
|
|
blitter->DrawLine(dpi->dst_ptr, x, y, x2, y2, dpi->width, dpi->height, color);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2007-09-28 19:17:33 +00:00
|
|
|
void GfxDrawLineUnscaled(int x, int y, int x2, int y2, int color)
|
|
|
|
{
|
|
|
|
Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter();
|
|
|
|
DrawPixelInfo *dpi = _cur_dpi;
|
|
|
|
|
|
|
|
x -= dpi->left;
|
|
|
|
x2 -= dpi->left;
|
|
|
|
y -= dpi->top;
|
|
|
|
y2 -= dpi->top;
|
|
|
|
|
|
|
|
/* Check clipping */
|
|
|
|
if (x < 0 && x2 < 0) return;
|
|
|
|
if (y < 0 && y2 < 0) return;
|
|
|
|
if (x > dpi->width && x2 > dpi->width) return;
|
|
|
|
if (y > dpi->height && y2 > dpi->height) return;
|
|
|
|
|
|
|
|
blitter->DrawLine(dpi->dst_ptr, UnScaleByZoom(x, dpi->zoom), UnScaleByZoom(y, dpi->zoom),
|
|
|
|
UnScaleByZoom(x2, dpi->zoom), UnScaleByZoom(y2, dpi->zoom),
|
|
|
|
UnScaleByZoom(dpi->width, dpi->zoom), UnScaleByZoom(dpi->height, dpi->zoom), color);
|
|
|
|
}
|
|
|
|
|
2007-09-26 19:27:29 +00:00
|
|
|
/**
|
|
|
|
* Draws the projection of a parallelepiped.
|
|
|
|
* This can be used to draw boxes in world coordinates.
|
|
|
|
*
|
|
|
|
* @param x Screen X-coordinate of top front corner.
|
|
|
|
* @param y Screen Y-coordinate of top front corner.
|
|
|
|
* @param dx1 Screen X-length of first edge.
|
|
|
|
* @param dy1 Screen Y-length of first edge.
|
|
|
|
* @param dx2 Screen X-length of second edge.
|
|
|
|
* @param dy2 Screen Y-length of second edge.
|
|
|
|
* @param dx3 Screen X-length of third edge.
|
|
|
|
* @param dy3 Screen Y-length of third edge.
|
|
|
|
*/
|
|
|
|
void DrawBox(int x, int y, int dx1, int dy1, int dx2, int dy2, int dx3, int dy3)
|
|
|
|
{
|
|
|
|
/* ....
|
|
|
|
* .. ....
|
|
|
|
* .. ....
|
|
|
|
* .. ^
|
|
|
|
* <--__(dx1,dy1) /(dx2,dy2)
|
|
|
|
* : --__ / :
|
|
|
|
* : --__ / :
|
|
|
|
* : *(x,y) :
|
|
|
|
* : | :
|
|
|
|
* : | ..
|
|
|
|
* .... |(dx3,dy3)
|
|
|
|
* .... | ..
|
|
|
|
* ....V.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static const byte color = 255;
|
|
|
|
|
2007-09-28 19:17:33 +00:00
|
|
|
GfxDrawLineUnscaled(x, y, x + dx1, y + dy1, color);
|
|
|
|
GfxDrawLineUnscaled(x, y, x + dx2, y + dy2, color);
|
|
|
|
GfxDrawLineUnscaled(x, y, x + dx3, y + dy3, color);
|
2007-09-26 19:27:29 +00:00
|
|
|
|
2007-09-28 19:17:33 +00:00
|
|
|
GfxDrawLineUnscaled(x + dx1, y + dy1, x + dx1 + dx2, y + dy1 + dy2, color);
|
|
|
|
GfxDrawLineUnscaled(x + dx1, y + dy1, x + dx1 + dx3, y + dy1 + dy3, color);
|
|
|
|
GfxDrawLineUnscaled(x + dx2, y + dy2, x + dx2 + dx1, y + dy2 + dy1, color);
|
|
|
|
GfxDrawLineUnscaled(x + dx2, y + dy2, x + dx2 + dx3, y + dy2 + dy3, color);
|
|
|
|
GfxDrawLineUnscaled(x + dx3, y + dy3, x + dx3 + dx1, y + dy3 + dy1, color);
|
|
|
|
GfxDrawLineUnscaled(x + dx3, y + dy3, x + dx3 + dx2, y + dy3 + dy2, color);
|
2007-09-26 19:27:29 +00:00
|
|
|
}
|
|
|
|
|
2006-05-09 13:23:04 +00:00
|
|
|
|
2005-07-17 15:54:57 +00:00
|
|
|
/** Truncate a given string to a maximum width if neccessary.
|
|
|
|
* If the string is truncated, add three dots ('...') to show this.
|
2007-04-17 20:23:13 +00:00
|
|
|
* @param *str string that is checked and possibly truncated
|
2005-07-17 15:54:57 +00:00
|
|
|
* @param maxw maximum width in pixels of the string
|
|
|
|
* @return new width of (truncated) string */
|
2005-07-17 19:23:18 +00:00
|
|
|
static int TruncateString(char *str, int maxw)
|
2005-07-17 15:54:57 +00:00
|
|
|
{
|
2005-07-17 19:23:18 +00:00
|
|
|
int w = 0;
|
2006-05-09 13:23:04 +00:00
|
|
|
FontSize size = _cur_fontsize;
|
2005-07-17 15:54:57 +00:00
|
|
|
int ddd, ddd_w;
|
|
|
|
|
2006-11-16 22:05:33 +00:00
|
|
|
WChar c;
|
2005-07-17 15:54:57 +00:00
|
|
|
char *ddd_pos;
|
|
|
|
|
2006-05-09 13:23:04 +00:00
|
|
|
ddd_w = ddd = GetCharacterWidth(size, '.') * 3;
|
2005-07-17 15:54:57 +00:00
|
|
|
|
2006-11-16 22:05:33 +00:00
|
|
|
for (ddd_pos = str; (c = Utf8Consume((const char **)&str)) != '\0'; ) {
|
|
|
|
if (IsPrintable(c)) {
|
2006-05-09 13:23:04 +00:00
|
|
|
w += GetCharacterWidth(size, c);
|
2005-07-17 15:54:57 +00:00
|
|
|
|
|
|
|
if (w >= maxw) {
|
2007-03-01 01:24:44 +00:00
|
|
|
/* string got too big... insert dotdotdot */
|
2005-07-17 15:54:57 +00:00
|
|
|
ddd_pos[0] = ddd_pos[1] = ddd_pos[2] = '.';
|
2007-03-05 00:45:56 +00:00
|
|
|
ddd_pos[3] = '\0';
|
2005-07-17 15:54:57 +00:00
|
|
|
return ddd_w;
|
|
|
|
}
|
|
|
|
} else {
|
2006-11-16 22:05:33 +00:00
|
|
|
if (c == SCC_SETX) str++;
|
|
|
|
else if (c == SCC_SETXY) str += 2;
|
|
|
|
else if (c == SCC_TINYFONT) {
|
2006-05-09 13:23:04 +00:00
|
|
|
size = FS_SMALL;
|
|
|
|
ddd = GetCharacterWidth(size, '.') * 3;
|
2006-11-16 22:05:33 +00:00
|
|
|
} else if (c == SCC_BIGFONT) {
|
2006-05-09 13:23:04 +00:00
|
|
|
size = FS_LARGE;
|
|
|
|
ddd = GetCharacterWidth(size, '.') * 3;
|
2005-07-17 15:54:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-01 01:24:44 +00:00
|
|
|
/* Remember the last position where three dots fit. */
|
2005-07-17 15:54:57 +00:00
|
|
|
if (w + ddd < maxw) {
|
|
|
|
ddd_w = w + ddd;
|
2005-07-17 19:23:18 +00:00
|
|
|
ddd_pos = str;
|
2005-07-17 15:54:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return w;
|
|
|
|
}
|
|
|
|
|
2006-10-21 23:31:34 +00:00
|
|
|
static inline int TruncateStringID(StringID src, char *dest, int maxw, const char* last)
|
2005-07-17 15:54:57 +00:00
|
|
|
{
|
2006-10-21 23:31:34 +00:00
|
|
|
GetString(dest, src, last);
|
2005-07-17 15:54:57 +00:00
|
|
|
return TruncateString(dest, maxw);
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
/* returns right coordinate */
|
2005-07-17 15:54:57 +00:00
|
|
|
int DrawString(int x, int y, StringID str, uint16 color)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2005-02-07 12:32:35 +00:00
|
|
|
char buffer[512];
|
|
|
|
|
2006-10-21 23:31:34 +00:00
|
|
|
GetString(buffer, str, lastof(buffer));
|
2005-02-07 12:32:35 +00:00
|
|
|
return DoDrawString(buffer, x, y, color);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2005-07-17 15:54:57 +00:00
|
|
|
int DrawStringTruncated(int x, int y, StringID str, uint16 color, uint maxw)
|
|
|
|
{
|
|
|
|
char buffer[512];
|
2006-10-21 23:31:34 +00:00
|
|
|
TruncateStringID(str, buffer, maxw, lastof(buffer));
|
2005-07-17 15:54:57 +00:00
|
|
|
return DoDrawString(buffer, x, y, color);
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-07-17 15:54:57 +00:00
|
|
|
|
2006-08-20 10:50:23 +00:00
|
|
|
int DrawStringRightAligned(int x, int y, StringID str, uint16 color)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2005-02-07 12:32:35 +00:00
|
|
|
char buffer[512];
|
2006-08-20 10:50:23 +00:00
|
|
|
int w;
|
2005-02-07 12:32:35 +00:00
|
|
|
|
2006-10-21 23:31:34 +00:00
|
|
|
GetString(buffer, str, lastof(buffer));
|
2006-09-16 13:20:14 +00:00
|
|
|
w = GetStringBoundingBox(buffer).width;
|
2006-08-20 10:50:23 +00:00
|
|
|
DoDrawString(buffer, x - w, y, color);
|
|
|
|
|
|
|
|
return w;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2005-07-17 15:54:57 +00:00
|
|
|
void DrawStringRightAlignedTruncated(int x, int y, StringID str, uint16 color, uint maxw)
|
|
|
|
{
|
|
|
|
char buffer[512];
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-10-21 23:31:34 +00:00
|
|
|
TruncateStringID(str, buffer, maxw, lastof(buffer));
|
2006-09-16 13:20:14 +00:00
|
|
|
DoDrawString(buffer, x - GetStringBoundingBox(buffer).width, y, color);
|
2005-07-17 15:54:57 +00:00
|
|
|
}
|
|
|
|
|
2006-08-20 10:50:23 +00:00
|
|
|
void DrawStringRightAlignedUnderline(int x, int y, StringID str, uint16 color)
|
|
|
|
{
|
|
|
|
int w = DrawStringRightAligned(x, y, str, color);
|
|
|
|
GfxFillRect(x - w, y + 10, x, y + 10, _string_colorremap[1]);
|
|
|
|
}
|
|
|
|
|
2005-07-17 15:54:57 +00:00
|
|
|
|
|
|
|
int DrawStringCentered(int x, int y, StringID str, uint16 color)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2005-02-07 12:32:35 +00:00
|
|
|
char buffer[512];
|
2004-08-09 17:04:08 +00:00
|
|
|
int w;
|
|
|
|
|
2006-10-21 23:31:34 +00:00
|
|
|
GetString(buffer, str, lastof(buffer));
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-09-16 13:20:14 +00:00
|
|
|
w = GetStringBoundingBox(buffer).width;
|
2005-02-07 12:32:35 +00:00
|
|
|
DoDrawString(buffer, x - w / 2, y, color);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
return w;
|
|
|
|
}
|
|
|
|
|
2005-07-17 19:23:18 +00:00
|
|
|
int DrawStringCenteredTruncated(int xl, int xr, int y, StringID str, uint16 color)
|
2005-07-17 15:54:57 +00:00
|
|
|
{
|
|
|
|
char buffer[512];
|
2006-10-21 23:31:34 +00:00
|
|
|
int w = TruncateStringID(str, buffer, xr - xl, lastof(buffer));
|
2005-07-17 19:23:18 +00:00
|
|
|
return DoDrawString(buffer, (xl + xr - w) / 2, y, color);
|
2005-07-17 15:54:57 +00:00
|
|
|
}
|
|
|
|
|
2005-07-19 22:12:04 +00:00
|
|
|
int DoDrawStringCentered(int x, int y, const char *str, uint16 color)
|
|
|
|
{
|
2006-09-16 13:20:14 +00:00
|
|
|
int w = GetStringBoundingBox(str).width;
|
2005-07-19 22:12:04 +00:00
|
|
|
DoDrawString(str, x - w / 2, y, color);
|
|
|
|
return w;
|
|
|
|
}
|
|
|
|
|
2005-07-17 15:54:57 +00:00
|
|
|
void DrawStringCenterUnderline(int x, int y, StringID str, uint16 color)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
int w = DrawStringCentered(x, y, str, color);
|
2005-07-05 11:09:18 +00:00
|
|
|
GfxFillRect(x - (w >> 1), y + 10, x - (w >> 1) + w, y + 10, _string_colorremap[1]);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2005-07-17 19:23:18 +00:00
|
|
|
void DrawStringCenterUnderlineTruncated(int xl, int xr, int y, StringID str, uint16 color)
|
2005-07-17 15:54:57 +00:00
|
|
|
{
|
2005-07-17 19:23:18 +00:00
|
|
|
int w = DrawStringCenteredTruncated(xl, xr, y, str, color);
|
|
|
|
GfxFillRect((xl + xr - w) / 2, y + 10, (xl + xr + w) / 2, y + 10, _string_colorremap[1]);
|
2005-07-17 15:54:57 +00:00
|
|
|
}
|
|
|
|
|
2007-09-09 10:13:17 +00:00
|
|
|
/**
|
|
|
|
* 'Correct' a string to a maximum length. Longer strings will be cut into
|
2006-10-27 09:55:38 +00:00
|
|
|
* additional lines at whitespace characters if possible. The string parameter
|
|
|
|
* is modified with terminating characters mid-string which are the
|
2007-04-17 20:23:13 +00:00
|
|
|
* placeholders for the newlines.
|
2006-10-27 09:55:38 +00:00
|
|
|
* The string WILL be truncated if there was no whitespace for the current
|
|
|
|
* line's maximum width.
|
|
|
|
*
|
2007-04-17 20:23:13 +00:00
|
|
|
* @note To know if the terminating '\0' is the string end or just a
|
2006-10-27 09:55:38 +00:00
|
|
|
* newline, the returned 'num' value should be consulted. The num'th '\0',
|
|
|
|
* starting with index 0 is the real string end.
|
|
|
|
*
|
|
|
|
* @param str string to check and correct for length restrictions
|
|
|
|
* @param maxw the maximum width the string can have on one line
|
|
|
|
* @return return a 32bit wide number consisting of 2 packed values:
|
|
|
|
* 0 - 15 the number of lines ADDED to the string
|
2007-09-09 10:13:17 +00:00
|
|
|
* 16 - 31 the fontsize in which the length calculation was done at
|
|
|
|
*/
|
2006-10-27 09:55:38 +00:00
|
|
|
uint32 FormatStringLinebreaks(char *str, int maxw)
|
2005-01-22 22:47:58 +00:00
|
|
|
{
|
2006-05-09 13:23:04 +00:00
|
|
|
FontSize size = _cur_fontsize;
|
2006-10-27 09:55:38 +00:00
|
|
|
int num = 0;
|
|
|
|
|
|
|
|
assert(maxw > 0);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-02-01 07:36:15 +00:00
|
|
|
for (;;) {
|
2006-10-27 09:55:38 +00:00
|
|
|
char *last_space = NULL;
|
|
|
|
int w = 0;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-02-01 07:36:15 +00:00
|
|
|
for (;;) {
|
2006-11-16 22:05:33 +00:00
|
|
|
WChar c = Utf8Consume((const char **)&str);
|
2006-10-27 09:55:38 +00:00
|
|
|
/* whitespace is where we will insert the line-break */
|
2007-03-05 00:45:56 +00:00
|
|
|
if (IsWhitespace(c)) last_space = str;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-11-16 22:05:33 +00:00
|
|
|
if (IsPrintable(c)) {
|
2006-05-09 13:23:04 +00:00
|
|
|
w += GetCharacterWidth(size, c);
|
2006-10-27 09:55:38 +00:00
|
|
|
/* string is longer than maximum width so we need to decide what to
|
|
|
|
* do. We can do two things:
|
|
|
|
* 1. If no whitespace was found at all up until now (on this line) then
|
|
|
|
* we will truncate the string and bail out.
|
|
|
|
* 2. In all other cases force a linebreak at the last seen whitespace */
|
2004-08-09 17:04:08 +00:00
|
|
|
if (w > maxw) {
|
2006-10-27 09:55:38 +00:00
|
|
|
if (last_space == NULL) {
|
2007-03-05 00:45:56 +00:00
|
|
|
*Utf8PrevChar(str) = '\0';
|
2006-05-09 13:23:04 +00:00
|
|
|
return num + (size << 16);
|
2006-10-27 09:55:38 +00:00
|
|
|
}
|
|
|
|
str = last_space;
|
2004-08-09 17:04:08 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
2006-10-27 09:55:38 +00:00
|
|
|
switch (c) {
|
|
|
|
case '\0': return num + (size << 16); break;
|
2006-11-16 22:05:33 +00:00
|
|
|
case SCC_SETX: str++; break;
|
2007-04-18 22:10:36 +00:00
|
|
|
case SCC_SETXY: str += 2; break;
|
2006-11-16 22:05:33 +00:00
|
|
|
case SCC_TINYFONT: size = FS_SMALL; break;
|
|
|
|
case SCC_BIGFONT: size = FS_LARGE; break;
|
|
|
|
case '\n': goto end_of_inner_loop;
|
2006-10-27 09:55:38 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
2006-10-27 09:55:38 +00:00
|
|
|
end_of_inner_loop:
|
2007-03-05 00:45:56 +00:00
|
|
|
/* String didn't fit on line (or a '\n' was encountered), so 'dummy' terminate
|
|
|
|
* and increase linecount. We use Utf8PrevChar() as also non 1 char long
|
|
|
|
* whitespace seperators are supported */
|
2004-08-09 17:04:08 +00:00
|
|
|
num++;
|
2007-03-05 00:45:56 +00:00
|
|
|
char *s = Utf8PrevChar(str);
|
|
|
|
*s++ = '\0';
|
|
|
|
|
|
|
|
/* In which case (see above) we will shift remainder to left and close the gap */
|
|
|
|
if (str - s >= 1) {
|
|
|
|
for (; str[-1] != '\0';) *s++ = *str++;
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-12-27 16:14:21 +00:00
|
|
|
/** Draw a given string with the centre around the given x coordinates
|
|
|
|
* @param x Centre the string around this pixel width
|
|
|
|
* @param y Draw the string at this pixel height (first line's bottom)
|
|
|
|
* @param str String to draw
|
2007-04-17 20:23:13 +00:00
|
|
|
* @param maxw Maximum width the string can have before it is wrapped */
|
2005-11-13 21:16:34 +00:00
|
|
|
void DrawStringMultiCenter(int x, int y, StringID str, int maxw)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2005-02-07 12:32:35 +00:00
|
|
|
char buffer[512];
|
2004-08-09 17:04:08 +00:00
|
|
|
uint32 tmp;
|
2005-11-13 14:54:09 +00:00
|
|
|
int num, w, mt;
|
2005-02-06 18:30:45 +00:00
|
|
|
const char *src;
|
2006-11-16 22:05:33 +00:00
|
|
|
WChar c;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-10-21 23:31:34 +00:00
|
|
|
GetString(buffer, str, lastof(buffer));
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-02-07 12:32:35 +00:00
|
|
|
tmp = FormatStringLinebreaks(buffer, maxw);
|
2005-11-14 08:09:57 +00:00
|
|
|
num = GB(tmp, 0, 16);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-01-10 18:56:51 +00:00
|
|
|
mt = GetCharacterHeight((FontSize)GB(tmp, 16, 16));
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
y -= (mt >> 1) * num;
|
|
|
|
|
2005-02-07 12:32:35 +00:00
|
|
|
src = buffer;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-02-01 07:36:15 +00:00
|
|
|
for (;;) {
|
2006-09-16 13:20:14 +00:00
|
|
|
w = GetStringBoundingBox(src).width;
|
2007-04-18 22:10:36 +00:00
|
|
|
DoDrawString(src, x - (w >> 1), y, 0xFE);
|
2006-05-09 13:23:04 +00:00
|
|
|
_cur_fontsize = _last_fontsize;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-02-01 07:36:15 +00:00
|
|
|
for (;;) {
|
2006-11-16 22:05:33 +00:00
|
|
|
c = Utf8Consume(&src);
|
2004-08-09 17:04:08 +00:00
|
|
|
if (c == 0) {
|
|
|
|
y += mt;
|
|
|
|
if (--num < 0) {
|
2006-05-09 13:23:04 +00:00
|
|
|
_cur_fontsize = FS_NORMAL;
|
2004-08-09 17:04:08 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
break;
|
2006-11-16 22:05:33 +00:00
|
|
|
} else if (c == SCC_SETX) {
|
2004-08-09 17:04:08 +00:00
|
|
|
src++;
|
2006-11-16 22:05:33 +00:00
|
|
|
} else if (c == SCC_SETXY) {
|
2007-04-18 22:10:36 +00:00
|
|
|
src += 2;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-10-23 18:13:24 +00:00
|
|
|
|
2007-03-25 16:09:36 +00:00
|
|
|
uint DrawStringMultiLine(int x, int y, StringID str, int maxw, int maxh)
|
2005-07-05 11:09:18 +00:00
|
|
|
{
|
2005-02-07 12:32:35 +00:00
|
|
|
char buffer[512];
|
2004-08-09 17:04:08 +00:00
|
|
|
uint32 tmp;
|
2005-12-14 06:28:48 +00:00
|
|
|
int num, mt;
|
2006-10-23 18:13:24 +00:00
|
|
|
uint total_height;
|
2005-02-06 18:30:45 +00:00
|
|
|
const char *src;
|
2006-11-16 22:05:33 +00:00
|
|
|
WChar c;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-10-21 23:31:34 +00:00
|
|
|
GetString(buffer, str, lastof(buffer));
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-02-07 12:32:35 +00:00
|
|
|
tmp = FormatStringLinebreaks(buffer, maxw);
|
2005-11-14 08:09:57 +00:00
|
|
|
num = GB(tmp, 0, 16);
|
2005-11-13 14:54:09 +00:00
|
|
|
|
2007-01-10 18:56:51 +00:00
|
|
|
mt = GetCharacterHeight((FontSize)GB(tmp, 16, 16));
|
2006-10-23 18:13:24 +00:00
|
|
|
total_height = (num + 1) * mt;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-03-26 08:04:29 +00:00
|
|
|
if (maxh != -1 && (int)total_height > maxh) {
|
|
|
|
/* Check there's room enough for at least one line. */
|
|
|
|
if (maxh < mt) return 0;
|
2007-03-25 16:09:36 +00:00
|
|
|
|
2007-03-26 08:04:29 +00:00
|
|
|
num = maxh / mt - 1;
|
2007-03-25 16:09:36 +00:00
|
|
|
total_height = (num + 1) * mt;
|
|
|
|
}
|
|
|
|
|
2005-02-07 12:32:35 +00:00
|
|
|
src = buffer;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-02-01 07:36:15 +00:00
|
|
|
for (;;) {
|
2004-08-09 17:04:08 +00:00
|
|
|
DoDrawString(src, x, y, 0xFE);
|
2006-05-09 13:23:04 +00:00
|
|
|
_cur_fontsize = _last_fontsize;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-02-01 07:36:15 +00:00
|
|
|
for (;;) {
|
2006-11-16 22:05:33 +00:00
|
|
|
c = Utf8Consume(&src);
|
2004-08-09 17:04:08 +00:00
|
|
|
if (c == 0) {
|
|
|
|
y += mt;
|
|
|
|
if (--num < 0) {
|
2006-05-09 13:23:04 +00:00
|
|
|
_cur_fontsize = FS_NORMAL;
|
2006-10-23 18:13:24 +00:00
|
|
|
return total_height;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
break;
|
2006-11-16 22:05:33 +00:00
|
|
|
} else if (c == SCC_SETX) {
|
2004-08-09 17:04:08 +00:00
|
|
|
src++;
|
2006-11-16 22:05:33 +00:00
|
|
|
} else if (c == SCC_SETXY) {
|
2007-04-18 22:10:36 +00:00
|
|
|
src += 2;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-09-16 13:20:14 +00:00
|
|
|
/** Return the string dimension in pixels. The height and width are returned
|
2007-12-22 23:30:28 +00:00
|
|
|
* in a single Dimension value. TINYFONT, BIGFONT modifiers are only
|
2006-09-16 13:20:14 +00:00
|
|
|
* supported as the first character of the string. The returned dimensions
|
|
|
|
* are therefore a rough estimation correct for all the current strings
|
|
|
|
* but not every possible combination
|
|
|
|
* @param str string to calculate pixel-width
|
|
|
|
* @return string width and height in pixels */
|
2007-12-22 23:30:28 +00:00
|
|
|
Dimension GetStringBoundingBox(const char *str)
|
2005-02-06 18:30:45 +00:00
|
|
|
{
|
2006-05-09 13:23:04 +00:00
|
|
|
FontSize size = _cur_fontsize;
|
2007-12-22 23:30:28 +00:00
|
|
|
Dimension br;
|
2006-09-16 13:20:14 +00:00
|
|
|
int max_width;
|
2006-11-16 22:05:33 +00:00
|
|
|
WChar c;
|
2006-09-05 23:02:31 +00:00
|
|
|
|
2006-09-16 13:20:14 +00:00
|
|
|
br.width = br.height = max_width = 0;
|
2006-11-16 22:05:33 +00:00
|
|
|
for (;;) {
|
|
|
|
c = Utf8Consume(&str);
|
|
|
|
if (c == 0) break;
|
|
|
|
if (IsPrintable(c)) {
|
2006-09-16 13:20:14 +00:00
|
|
|
br.width += GetCharacterWidth(size, c);
|
2004-08-09 17:04:08 +00:00
|
|
|
} else {
|
2006-09-16 13:20:14 +00:00
|
|
|
switch (c) {
|
2006-12-27 16:14:21 +00:00
|
|
|
case SCC_SETX: br.width += (byte)*str++; break;
|
2006-11-16 22:05:33 +00:00
|
|
|
case SCC_SETXY:
|
2006-12-27 16:14:21 +00:00
|
|
|
br.width += (byte)*str++;
|
|
|
|
br.height += (byte)*str++;
|
2006-09-16 13:20:14 +00:00
|
|
|
break;
|
2006-11-16 22:05:33 +00:00
|
|
|
case SCC_TINYFONT: size = FS_SMALL; break;
|
|
|
|
case SCC_BIGFONT: size = FS_LARGE; break;
|
|
|
|
case '\n':
|
2006-09-16 13:20:14 +00:00
|
|
|
br.height += GetCharacterHeight(size);
|
2006-09-16 13:44:12 +00:00
|
|
|
if (br.width > max_width) max_width = br.width;
|
|
|
|
br.width = 0;
|
2006-09-16 13:20:14 +00:00
|
|
|
break;
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
2006-09-16 13:20:14 +00:00
|
|
|
br.height += GetCharacterHeight(size);
|
2006-09-05 23:02:31 +00:00
|
|
|
|
2006-09-16 13:20:14 +00:00
|
|
|
br.width = max(br.width, max_width);
|
|
|
|
return br;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2008-03-26 10:08:17 +00:00
|
|
|
void DrawCharCentered(WChar c, int x, int y, uint16 real_color)
|
|
|
|
{
|
|
|
|
FontSize size = FS_NORMAL;
|
|
|
|
byte color = real_color & 0xFF;
|
|
|
|
uint palette = _use_dos_palette ? 1 : 0;
|
|
|
|
int w = GetCharacterWidth(size, c);
|
|
|
|
|
|
|
|
_string_colorremap[1] = _string_colormap[palette][color].text;
|
|
|
|
_string_colorremap[2] = _string_colormap[palette][color].shadow;
|
|
|
|
_color_remap_ptr = _string_colorremap;
|
|
|
|
|
|
|
|
GfxMainBlitter(GetGlyph(size, c), x - w / 2, y, BM_COLOUR_REMAP);
|
|
|
|
}
|
|
|
|
|
2006-10-24 23:11:40 +00:00
|
|
|
/** Draw a string at the given coordinates with the given colour
|
|
|
|
* @param string the string to draw
|
|
|
|
* @param x offset from left side of the screen, if negative offset from the right side
|
2007-04-17 20:23:13 +00:00
|
|
|
* @param y offset from top side of the screen, if negative offset from the bottom
|
2006-10-24 23:11:40 +00:00
|
|
|
* @param real_color colour of the string, see _string_colormap in
|
2007-12-23 10:56:02 +00:00
|
|
|
* table/palettes.h or docs/ottd-colourtext-palette.png or the enum TextColour in gfx_type.h
|
2006-10-24 23:11:40 +00:00
|
|
|
* @return the x-coordinates where the drawing has finished. If nothing is drawn
|
|
|
|
* the originally passed x-coordinate is returned */
|
2005-02-06 18:30:45 +00:00
|
|
|
int DoDrawString(const char *string, int x, int y, uint16 real_color)
|
|
|
|
{
|
2006-09-02 20:34:33 +00:00
|
|
|
DrawPixelInfo *dpi = _cur_dpi;
|
2006-05-09 13:23:04 +00:00
|
|
|
FontSize size = _cur_fontsize;
|
2006-11-16 22:05:33 +00:00
|
|
|
WChar c;
|
2004-08-09 17:04:08 +00:00
|
|
|
int xo = x, yo = y;
|
|
|
|
|
2007-08-07 15:20:31 +00:00
|
|
|
byte color = real_color & 0xFF;
|
|
|
|
byte previous_color = color;
|
2004-12-04 17:54:56 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
if (color != 0xFE) {
|
|
|
|
if (x >= dpi->left + dpi->width ||
|
2007-04-18 22:10:36 +00:00
|
|
|
x + _screen.width * 2 <= dpi->left ||
|
2004-08-09 17:04:08 +00:00
|
|
|
y >= dpi->top + dpi->height ||
|
|
|
|
y + _screen.height <= dpi->top)
|
|
|
|
return x;
|
|
|
|
|
|
|
|
if (color != 0xFF) {
|
|
|
|
switch_color:;
|
2004-12-14 20:54:01 +00:00
|
|
|
if (real_color & IS_PALETTE_COLOR) {
|
2004-12-04 17:54:56 +00:00
|
|
|
_string_colorremap[1] = color;
|
2007-04-17 10:08:17 +00:00
|
|
|
_string_colorremap[2] = _use_dos_palette ? 1 : 215;
|
2004-12-04 17:54:56 +00:00
|
|
|
} else {
|
2007-04-17 10:08:17 +00:00
|
|
|
uint palette = _use_dos_palette ? 1 : 0;
|
|
|
|
_string_colorremap[1] = _string_colormap[palette][color].text;
|
|
|
|
_string_colorremap[2] = _string_colormap[palette][color].shadow;
|
2004-12-04 17:54:56 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
_color_remap_ptr = _string_colorremap;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
check_bounds:
|
|
|
|
if (y + 19 <= dpi->top || dpi->top + dpi->height <= y) {
|
|
|
|
skip_char:;
|
2006-02-01 07:36:15 +00:00
|
|
|
for (;;) {
|
2006-11-16 22:05:33 +00:00
|
|
|
c = Utf8Consume(&string);
|
|
|
|
if (!IsPrintable(c)) goto skip_cont;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-02-01 07:36:15 +00:00
|
|
|
for (;;) {
|
2006-11-16 22:05:33 +00:00
|
|
|
c = Utf8Consume(&string);
|
2004-08-09 17:04:08 +00:00
|
|
|
skip_cont:;
|
|
|
|
if (c == 0) {
|
2006-05-09 13:23:04 +00:00
|
|
|
_last_fontsize = size;
|
2004-08-09 17:04:08 +00:00
|
|
|
return x;
|
|
|
|
}
|
2006-11-16 22:05:33 +00:00
|
|
|
if (IsPrintable(c)) {
|
2004-08-09 17:04:08 +00:00
|
|
|
if (x >= dpi->left + dpi->width) goto skip_char;
|
|
|
|
if (x + 26 >= dpi->left) {
|
2007-06-11 11:50:49 +00:00
|
|
|
GfxMainBlitter(GetGlyph(size, c), x, y, BM_COLOUR_REMAP);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2006-05-09 13:23:04 +00:00
|
|
|
x += GetCharacterWidth(size, c);
|
2006-11-16 22:05:33 +00:00
|
|
|
} else if (c == '\n') { // newline = {}
|
2004-08-09 17:04:08 +00:00
|
|
|
x = xo;
|
2006-05-09 13:23:04 +00:00
|
|
|
y += GetCharacterHeight(size);
|
2004-08-09 17:04:08 +00:00
|
|
|
goto check_bounds;
|
2006-11-16 22:05:33 +00:00
|
|
|
} else if (c >= SCC_BLUE && c <= SCC_BLACK) { // change color?
|
2007-08-07 15:20:31 +00:00
|
|
|
previous_color = color;
|
2006-11-16 22:05:33 +00:00
|
|
|
color = (byte)(c - SCC_BLUE);
|
2004-08-09 17:04:08 +00:00
|
|
|
goto switch_color;
|
2007-08-07 15:20:31 +00:00
|
|
|
} else if (c == SCC_PREVIOUS_COLOUR) { // revert to the previous color
|
|
|
|
Swap(color, previous_color);
|
|
|
|
goto switch_color;
|
2006-11-16 22:05:33 +00:00
|
|
|
} else if (c == SCC_SETX) { // {SETX}
|
2005-02-06 18:30:45 +00:00
|
|
|
x = xo + (byte)*string++;
|
2006-11-16 22:05:33 +00:00
|
|
|
} else if (c == SCC_SETXY) {// {SETXY}
|
2005-02-06 18:30:45 +00:00
|
|
|
x = xo + (byte)*string++;
|
|
|
|
y = yo + (byte)*string++;
|
2006-11-16 22:05:33 +00:00
|
|
|
} else if (c == SCC_TINYFONT) { // {TINYFONT}
|
2006-05-09 13:23:04 +00:00
|
|
|
size = FS_SMALL;
|
2006-11-16 22:05:33 +00:00
|
|
|
} else if (c == SCC_BIGFONT) { // {BIGFONT}
|
2006-05-09 13:23:04 +00:00
|
|
|
size = FS_LARGE;
|
2004-08-09 17:04:08 +00:00
|
|
|
} else {
|
2006-12-27 16:14:21 +00:00
|
|
|
DEBUG(misc, 0, "[utf8] unknown string command character %d", c);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-07-17 15:54:57 +00:00
|
|
|
int DoDrawStringTruncated(const char *str, int x, int y, uint16 color, uint maxw)
|
|
|
|
{
|
|
|
|
char buffer[512];
|
|
|
|
ttd_strlcpy(buffer, str, sizeof(buffer));
|
|
|
|
TruncateString(buffer, maxw);
|
|
|
|
return DoDrawString(buffer, x, y, color);
|
|
|
|
}
|
|
|
|
|
2007-10-05 21:49:15 +00:00
|
|
|
void DrawSprite(SpriteID img, SpriteID pal, int x, int y, const SubSprite *sub)
|
2005-07-05 11:09:18 +00:00
|
|
|
{
|
2007-11-19 21:02:30 +00:00
|
|
|
if (HasBit(img, PALETTE_MODIFIER_TRANSPARENT)) {
|
2007-01-14 19:57:49 +00:00
|
|
|
_color_remap_ptr = GetNonSprite(GB(pal, 0, PALETTE_WIDTH)) + 1;
|
2007-10-05 21:49:15 +00:00
|
|
|
GfxMainBlitter(GetSprite(GB(img, 0, SPRITE_WIDTH)), x, y, BM_TRANSPARENT, sub);
|
2007-01-14 19:57:49 +00:00
|
|
|
} else if (pal != PAL_NONE) {
|
|
|
|
_color_remap_ptr = GetNonSprite(GB(pal, 0, PALETTE_WIDTH)) + 1;
|
2007-10-05 21:49:15 +00:00
|
|
|
GfxMainBlitter(GetSprite(GB(img, 0, SPRITE_WIDTH)), x, y, BM_COLOUR_REMAP, sub);
|
2004-08-09 17:04:08 +00:00
|
|
|
} else {
|
2007-10-05 21:49:15 +00:00
|
|
|
GfxMainBlitter(GetSprite(GB(img, 0, SPRITE_WIDTH)), x, y, BM_NORMAL, sub);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-10-05 21:49:15 +00:00
|
|
|
static inline void GfxMainBlitter(const Sprite *sprite, int x, int y, BlitterMode mode, const SubSprite *sub)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2006-07-26 03:33:12 +00:00
|
|
|
const DrawPixelInfo *dpi = _cur_dpi;
|
2007-06-11 11:50:49 +00:00
|
|
|
Blitter::BlitterParams bp;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-10-05 21:49:15 +00:00
|
|
|
/* Amount of pixels to clip from the source sprite */
|
|
|
|
int clip_left = (sub != NULL ? max(0, -sprite->x_offs + sub->left ) : 0);
|
|
|
|
int clip_top = (sub != NULL ? max(0, -sprite->y_offs + sub->top ) : 0);
|
|
|
|
int clip_right = (sub != NULL ? max(0, sprite->width - (-sprite->x_offs + sub->right + 1)) : 0);
|
|
|
|
int clip_bottom = (sub != NULL ? max(0, sprite->height - (-sprite->y_offs + sub->bottom + 1)) : 0);
|
|
|
|
|
|
|
|
if (clip_left + clip_right >= sprite->width) return;
|
|
|
|
if (clip_top + clip_bottom >= sprite->height) return;
|
|
|
|
|
2007-06-11 11:50:49 +00:00
|
|
|
/* Move to the correct offset */
|
2005-02-10 12:26:41 +00:00
|
|
|
x += sprite->x_offs;
|
|
|
|
y += sprite->y_offs;
|
2007-06-11 11:50:49 +00:00
|
|
|
|
|
|
|
/* Copy the main data directly from the sprite */
|
2006-09-02 08:14:16 +00:00
|
|
|
bp.sprite = sprite->data;
|
2007-06-11 11:50:49 +00:00
|
|
|
bp.sprite_width = sprite->width;
|
|
|
|
bp.sprite_height = sprite->height;
|
2007-10-05 21:49:15 +00:00
|
|
|
bp.width = UnScaleByZoom(sprite->width - clip_left - clip_right, dpi->zoom);
|
|
|
|
bp.height = UnScaleByZoom(sprite->height - clip_top - clip_bottom, dpi->zoom);
|
2007-06-11 11:50:49 +00:00
|
|
|
bp.top = 0;
|
|
|
|
bp.left = 0;
|
2007-10-05 21:49:15 +00:00
|
|
|
bp.skip_left = UnScaleByZoom(clip_left, dpi->zoom);
|
|
|
|
bp.skip_top = UnScaleByZoom(clip_top, dpi->zoom);
|
|
|
|
|
|
|
|
x += ScaleByZoom(bp.skip_left, dpi->zoom);
|
|
|
|
y += ScaleByZoom(bp.skip_top, dpi->zoom);
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
bp.dst = dpi->dst_ptr;
|
|
|
|
bp.pitch = dpi->pitch;
|
2007-06-11 11:50:49 +00:00
|
|
|
bp.remap = _color_remap_ptr;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-06-11 11:50:49 +00:00
|
|
|
assert(sprite->width > 0);
|
|
|
|
assert(sprite->height > 0);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-06-11 11:50:49 +00:00
|
|
|
if (bp.width <= 0) return;
|
|
|
|
if (bp.height <= 0) return;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-06-11 11:50:49 +00:00
|
|
|
y -= dpi->top;
|
|
|
|
/* Check for top overflow */
|
|
|
|
if (y < 0) {
|
|
|
|
bp.height -= -UnScaleByZoom(y, dpi->zoom);
|
2007-06-05 12:01:50 +00:00
|
|
|
if (bp.height <= 0) return;
|
2007-06-11 11:50:49 +00:00
|
|
|
bp.skip_top += -UnScaleByZoom(y, dpi->zoom);
|
2007-06-05 12:01:50 +00:00
|
|
|
y = 0;
|
|
|
|
} else {
|
2007-06-11 11:50:49 +00:00
|
|
|
bp.top = UnScaleByZoom(y, dpi->zoom);
|
2007-06-05 12:01:50 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-06-11 11:50:49 +00:00
|
|
|
/* Check for bottom overflow */
|
|
|
|
y += ScaleByZoom(bp.height, dpi->zoom) - dpi->height;
|
|
|
|
if (y > 0) {
|
|
|
|
bp.height -= UnScaleByZoom(y, dpi->zoom);
|
2007-06-05 12:01:50 +00:00
|
|
|
if (bp.height <= 0) return;
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-06-11 11:50:49 +00:00
|
|
|
x -= dpi->left;
|
|
|
|
/* Check for left overflow */
|
|
|
|
if (x < 0) {
|
|
|
|
bp.width -= -UnScaleByZoom(x, dpi->zoom);
|
2007-06-05 12:01:50 +00:00
|
|
|
if (bp.width <= 0) return;
|
2007-06-11 11:50:49 +00:00
|
|
|
bp.skip_left += -UnScaleByZoom(x, dpi->zoom);
|
2007-06-05 12:01:50 +00:00
|
|
|
x = 0;
|
2007-06-11 11:50:49 +00:00
|
|
|
} else {
|
|
|
|
bp.left = UnScaleByZoom(x, dpi->zoom);
|
2007-06-05 12:01:50 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-06-11 11:50:49 +00:00
|
|
|
/* Check for right overflow */
|
|
|
|
x += ScaleByZoom(bp.width, dpi->zoom) - dpi->width;
|
|
|
|
if (x > 0) {
|
|
|
|
bp.width -= UnScaleByZoom(x, dpi->zoom);
|
2007-06-05 12:01:50 +00:00
|
|
|
if (bp.width <= 0) return;
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-06-11 11:50:49 +00:00
|
|
|
BlitterFactoryBase::GetCurrentBlitter()->Draw(&bp, mode, dpi->zoom);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
void DoPaletteAnimations();
|
2004-12-12 20:36:24 +00:00
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
void GfxInitPalettes()
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2005-06-30 05:27:32 +00:00
|
|
|
memcpy(_cur_palette, _palettes[_use_dos_palette ? 1 : 0], sizeof(_cur_palette));
|
2004-12-12 20:36:24 +00:00
|
|
|
|
2007-06-19 15:40:27 +00:00
|
|
|
DoPaletteAnimations();
|
2004-08-09 17:04:08 +00:00
|
|
|
_pal_first_dirty = 0;
|
2007-08-03 02:21:10 +00:00
|
|
|
_pal_count_dirty = 256;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2007-06-22 20:04:21 +00:00
|
|
|
#define EXTR(p, q) (((uint16)(_palette_animation_counter * (p)) * (q)) >> 16)
|
|
|
|
#define EXTR2(p, q) (((uint16)(~_palette_animation_counter * (p)) * (q)) >> 16)
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
void DoPaletteAnimations()
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2007-06-19 15:04:08 +00:00
|
|
|
Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter();
|
2006-07-26 03:33:12 +00:00
|
|
|
const Colour *s;
|
|
|
|
Colour *d;
|
2004-12-12 20:36:24 +00:00
|
|
|
/* Amount of colors to be rotated.
|
|
|
|
* A few more for the DOS palette, because the water colors are
|
|
|
|
* 245-254 for DOS and 217-226 for Windows. */
|
2004-08-09 17:04:08 +00:00
|
|
|
const ExtraPaletteValues *ev = &_extra_palette_values;
|
2005-07-03 11:31:03 +00:00
|
|
|
int c = _use_dos_palette ? 38 : 28;
|
2007-06-19 15:04:08 +00:00
|
|
|
Colour old_val[38];
|
2005-07-03 11:31:03 +00:00
|
|
|
uint i;
|
|
|
|
uint j;
|
2007-06-22 20:04:21 +00:00
|
|
|
uint old_tc = _palette_animation_counter;
|
2007-06-12 20:24:12 +00:00
|
|
|
|
2007-06-19 15:04:08 +00:00
|
|
|
if (blitter != NULL && blitter->UsePaletteAnimation() == Blitter::PALETTE_ANIMATION_NONE) {
|
2007-06-22 20:04:21 +00:00
|
|
|
_palette_animation_counter = 0;
|
2007-06-12 20:24:12 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-06-30 05:27:32 +00:00
|
|
|
d = &_cur_palette[217];
|
|
|
|
memcpy(old_val, d, c * sizeof(*old_val));
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-03-01 01:24:44 +00:00
|
|
|
/* Dark blue water */
|
2007-03-22 03:42:43 +00:00
|
|
|
s = (_opt.landscape == LT_TOYLAND) ? ev->ac : ev->a;
|
2005-07-03 11:31:03 +00:00
|
|
|
j = EXTR(320, 5);
|
|
|
|
for (i = 0; i != 5; i++) {
|
2005-06-30 05:27:32 +00:00
|
|
|
*d++ = s[j];
|
|
|
|
j++;
|
|
|
|
if (j == 5) j = 0;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2007-03-01 01:24:44 +00:00
|
|
|
/* Glittery water */
|
2007-03-22 03:42:43 +00:00
|
|
|
s = (_opt.landscape == LT_TOYLAND) ? ev->bc : ev->b;
|
2005-06-30 05:27:32 +00:00
|
|
|
j = EXTR(128, 15);
|
2005-07-03 11:31:03 +00:00
|
|
|
for (i = 0; i != 5; i++) {
|
2005-06-30 05:27:32 +00:00
|
|
|
*d++ = s[j];
|
|
|
|
j += 3;
|
|
|
|
if (j >= 15) j -= 15;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
s = ev->e;
|
2005-06-30 05:27:32 +00:00
|
|
|
j = EXTR2(512, 5);
|
2005-07-03 11:31:03 +00:00
|
|
|
for (i = 0; i != 5; i++) {
|
2005-06-30 05:27:32 +00:00
|
|
|
*d++ = s[j];
|
|
|
|
j++;
|
|
|
|
if (j == 5) j = 0;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2007-03-01 01:24:44 +00:00
|
|
|
/* Oil refinery fire animation */
|
2004-08-09 17:04:08 +00:00
|
|
|
s = ev->oil_ref;
|
2005-06-30 05:27:32 +00:00
|
|
|
j = EXTR2(512, 7);
|
2005-07-03 11:31:03 +00:00
|
|
|
for (i = 0; i != 7; i++) {
|
2005-06-30 05:27:32 +00:00
|
|
|
*d++ = s[j];
|
|
|
|
j++;
|
|
|
|
if (j == 7) j = 0;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2007-03-01 01:24:44 +00:00
|
|
|
/* Radio tower blinking */
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2007-06-22 20:04:21 +00:00
|
|
|
byte i = (_palette_animation_counter >> 1) & 0x7F;
|
2005-07-03 11:31:03 +00:00
|
|
|
byte v;
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
(v = 255, i < 0x3f) ||
|
|
|
|
(v = 128, i < 0x4A || i >= 0x75) ||
|
|
|
|
(v = 20);
|
2005-06-30 05:27:32 +00:00
|
|
|
d->r = v;
|
|
|
|
d->g = 0;
|
|
|
|
d->b = 0;
|
|
|
|
d++;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
i ^= 0x40;
|
|
|
|
(v = 255, i < 0x3f) ||
|
|
|
|
(v = 128, i < 0x4A || i >= 0x75) ||
|
|
|
|
(v = 20);
|
2005-06-30 05:27:32 +00:00
|
|
|
d->r = v;
|
|
|
|
d->g = 0;
|
|
|
|
d->b = 0;
|
|
|
|
d++;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2007-03-01 01:24:44 +00:00
|
|
|
/* Handle lighthouse and stadium animation */
|
2004-08-09 17:04:08 +00:00
|
|
|
s = ev->lighthouse;
|
2005-06-30 05:27:32 +00:00
|
|
|
j = EXTR(256, 4);
|
2005-07-03 11:31:03 +00:00
|
|
|
for (i = 0; i != 4; i++) {
|
2005-06-30 05:27:32 +00:00
|
|
|
*d++ = s[j];
|
|
|
|
j++;
|
|
|
|
if (j == 4) j = 0;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2007-03-01 01:24:44 +00:00
|
|
|
/* Animate water for old DOS graphics */
|
2005-07-03 11:31:03 +00:00
|
|
|
if (_use_dos_palette) {
|
2007-03-01 01:24:44 +00:00
|
|
|
/* Dark blue water DOS */
|
2007-03-22 03:42:43 +00:00
|
|
|
s = (_opt.landscape == LT_TOYLAND) ? ev->ac : ev->a;
|
2005-07-03 11:31:03 +00:00
|
|
|
j = EXTR(320, 5);
|
|
|
|
for (i = 0; i != 5; i++) {
|
2005-06-30 05:27:32 +00:00
|
|
|
*d++ = s[j];
|
|
|
|
j++;
|
|
|
|
if (j == 5) j = 0;
|
2004-12-12 20:36:24 +00:00
|
|
|
}
|
2005-01-06 18:45:28 +00:00
|
|
|
|
2007-03-01 01:24:44 +00:00
|
|
|
/* Glittery water DOS */
|
2007-03-22 03:42:43 +00:00
|
|
|
s = (_opt.landscape == LT_TOYLAND) ? ev->bc : ev->b;
|
2005-06-30 05:27:32 +00:00
|
|
|
j = EXTR(128, 15);
|
2005-07-03 11:31:03 +00:00
|
|
|
for (i = 0; i != 5; i++) {
|
2005-06-30 05:27:32 +00:00
|
|
|
*d++ = s[j];
|
|
|
|
j += 3;
|
|
|
|
if (j >= 15) j -= 15;
|
2004-12-12 20:36:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-06-19 15:04:08 +00:00
|
|
|
if (blitter != NULL && blitter->UsePaletteAnimation() == Blitter::PALETTE_ANIMATION_NONE) {
|
2007-06-22 20:04:21 +00:00
|
|
|
_palette_animation_counter = old_tc;
|
2007-06-19 15:04:08 +00:00
|
|
|
} else {
|
|
|
|
if (memcmp(old_val, &_cur_palette[217], c * sizeof(*old_val)) != 0) {
|
|
|
|
_pal_first_dirty = 217;
|
|
|
|
_pal_count_dirty = c;
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
void LoadStringWidthTable()
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2005-07-03 11:31:03 +00:00
|
|
|
uint i;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-05-09 11:42:51 +00:00
|
|
|
/* Normal font */
|
2006-05-09 13:23:04 +00:00
|
|
|
for (i = 0; i != 224; i++) {
|
2006-11-16 22:05:33 +00:00
|
|
|
_stringwidth_table[FS_NORMAL][i] = GetGlyphWidth(FS_NORMAL, i + 32);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2006-05-09 11:42:51 +00:00
|
|
|
/* Small font */
|
2006-05-09 13:23:04 +00:00
|
|
|
for (i = 0; i != 224; i++) {
|
2006-11-16 22:05:33 +00:00
|
|
|
_stringwidth_table[FS_SMALL][i] = GetGlyphWidth(FS_SMALL, i + 32);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2006-05-09 11:42:51 +00:00
|
|
|
/* Large font */
|
2006-05-09 13:23:04 +00:00
|
|
|
for (i = 0; i != 224; i++) {
|
2006-11-16 22:05:33 +00:00
|
|
|
_stringwidth_table[FS_LARGE][i] = GetGlyphWidth(FS_LARGE, i + 32);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-11-16 22:05:33 +00:00
|
|
|
|
|
|
|
byte GetCharacterWidth(FontSize size, WChar key)
|
|
|
|
{
|
|
|
|
if (key >= 32 && key < 256) return _stringwidth_table[size][key - 32];
|
|
|
|
|
|
|
|
return GetGlyphWidth(size, key);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
void ScreenSizeChanged()
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2007-03-01 01:24:44 +00:00
|
|
|
/* check the dirty rect */
|
2004-08-09 17:04:08 +00:00
|
|
|
if (_invalid_rect.right >= _screen.width) _invalid_rect.right = _screen.width;
|
|
|
|
if (_invalid_rect.bottom >= _screen.height) _invalid_rect.bottom = _screen.height;
|
|
|
|
|
2007-03-01 01:24:44 +00:00
|
|
|
/* screen size changed and the old bitmap is invalid now, so we don't want to undraw it */
|
2004-08-09 17:04:08 +00:00
|
|
|
_cursor.visible = false;
|
|
|
|
}
|
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
void UndrawMouseCursor()
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
if (_cursor.visible) {
|
2007-06-17 20:30:28 +00:00
|
|
|
Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter();
|
2004-08-09 17:04:08 +00:00
|
|
|
_cursor.visible = false;
|
2007-06-21 12:36:46 +00:00
|
|
|
blitter->CopyFromBuffer(blitter->MoveTo(_screen.dst_ptr, _cursor.draw_pos.x, _cursor.draw_pos.y), _cursor_backup, _cursor.draw_size.x, _cursor.draw_size.y);
|
2007-07-05 12:23:54 +00:00
|
|
|
_video_driver->MakeDirty(_cursor.draw_pos.x, _cursor.draw_pos.y, _cursor.draw_size.x, _cursor.draw_size.y);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
void DrawMouseCursor()
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2007-08-04 12:53:41 +00:00
|
|
|
#if defined(WINCE)
|
|
|
|
/* Don't ever draw the mouse for WinCE, as we work with a stylus */
|
|
|
|
return;
|
|
|
|
#endif
|
|
|
|
|
2007-06-17 20:30:28 +00:00
|
|
|
Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter();
|
2005-07-05 11:09:18 +00:00
|
|
|
int x;
|
|
|
|
int y;
|
|
|
|
int w;
|
|
|
|
int h;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-03-24 00:42:35 +00:00
|
|
|
/* Redraw mouse cursor but only when it's inside the window */
|
|
|
|
if (!_cursor.in_window) return;
|
|
|
|
|
2007-03-01 01:24:44 +00:00
|
|
|
/* Don't draw the mouse cursor if it's already drawn */
|
2004-08-09 17:04:08 +00:00
|
|
|
if (_cursor.visible) {
|
2005-07-05 11:09:18 +00:00
|
|
|
if (!_cursor.dirty) return;
|
2004-08-09 17:04:08 +00:00
|
|
|
UndrawMouseCursor();
|
|
|
|
}
|
|
|
|
|
|
|
|
w = _cursor.size.x;
|
|
|
|
x = _cursor.pos.x + _cursor.offs.x;
|
2005-07-05 11:09:18 +00:00
|
|
|
if (x < 0) {
|
|
|
|
w += x;
|
|
|
|
x = 0;
|
|
|
|
}
|
|
|
|
if (w > _screen.width - x) w = _screen.width - x;
|
2004-08-09 17:04:08 +00:00
|
|
|
if (w <= 0) return;
|
|
|
|
_cursor.draw_pos.x = x;
|
|
|
|
_cursor.draw_size.x = w;
|
|
|
|
|
|
|
|
h = _cursor.size.y;
|
|
|
|
y = _cursor.pos.y + _cursor.offs.y;
|
2005-07-05 11:09:18 +00:00
|
|
|
if (y < 0) {
|
|
|
|
h += y;
|
|
|
|
y = 0;
|
|
|
|
}
|
|
|
|
if (h > _screen.height - y) h = _screen.height - y;
|
2004-08-09 17:04:08 +00:00
|
|
|
if (h <= 0) return;
|
|
|
|
_cursor.draw_pos.y = y;
|
|
|
|
_cursor.draw_size.y = h;
|
|
|
|
|
2007-06-17 20:30:28 +00:00
|
|
|
assert(blitter->BufferSize(w, h) < (int)sizeof(_cursor_backup));
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-03-01 01:24:44 +00:00
|
|
|
/* Make backup of stuff below cursor */
|
2007-06-21 12:36:46 +00:00
|
|
|
blitter->CopyToBuffer(blitter->MoveTo(_screen.dst_ptr, _cursor.draw_pos.x, _cursor.draw_pos.y), _cursor_backup, _cursor.draw_size.x, _cursor.draw_size.y);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-03-01 01:24:44 +00:00
|
|
|
/* Draw cursor on screen */
|
2004-08-09 17:04:08 +00:00
|
|
|
_cur_dpi = &_screen;
|
2007-01-14 19:57:49 +00:00
|
|
|
DrawSprite(_cursor.sprite, _cursor.pal, _cursor.pos.x, _cursor.pos.y);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-07-05 12:23:54 +00:00
|
|
|
_video_driver->MakeDirty(_cursor.draw_pos.x, _cursor.draw_pos.y, _cursor.draw_size.x, _cursor.draw_size.y);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
_cursor.visible = true;
|
|
|
|
_cursor.dirty = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void RedrawScreenRect(int left, int top, int right, int bottom)
|
|
|
|
{
|
|
|
|
assert(right <= _screen.width && bottom <= _screen.height);
|
|
|
|
if (_cursor.visible) {
|
|
|
|
if (right > _cursor.draw_pos.x &&
|
|
|
|
left < _cursor.draw_pos.x + _cursor.draw_size.x &&
|
|
|
|
bottom > _cursor.draw_pos.y &&
|
|
|
|
top < _cursor.draw_pos.y + _cursor.draw_size.y) {
|
|
|
|
UndrawMouseCursor();
|
|
|
|
}
|
|
|
|
}
|
2007-08-19 09:38:30 +00:00
|
|
|
UndrawChatMessage();
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-06-21 16:53:57 +00:00
|
|
|
DrawOverlappedWindowForAll(left, top, right, bottom);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-07-05 12:23:54 +00:00
|
|
|
_video_driver->MakeDirty(left, top, right - left, bottom - top);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2007-09-09 10:13:17 +00:00
|
|
|
/*!
|
|
|
|
* Repaints the rectangle blocks which are marked as 'dirty'.
|
|
|
|
*
|
|
|
|
* @see SetDirtyBlocks
|
|
|
|
*/
|
2007-03-07 11:47:46 +00:00
|
|
|
void DrawDirtyBlocks()
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
byte *b = _dirty_blocks;
|
2007-11-19 20:40:14 +00:00
|
|
|
const int w = Align(_screen.width, 64);
|
|
|
|
const int h = Align(_screen.height, 8);
|
2005-07-08 21:24:27 +00:00
|
|
|
int x;
|
|
|
|
int y;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 10:00:30 +00:00
|
|
|
if (IsGeneratingWorld() && !IsGeneratingWorldReadyForPaint()) return;
|
|
|
|
|
2005-07-08 21:24:27 +00:00
|
|
|
y = 0;
|
2004-08-09 17:04:08 +00:00
|
|
|
do {
|
2005-07-08 21:24:27 +00:00
|
|
|
x = 0;
|
|
|
|
do {
|
|
|
|
if (*b != 0) {
|
|
|
|
int left;
|
|
|
|
int top;
|
|
|
|
int right = x + 64;
|
|
|
|
int bottom = y;
|
|
|
|
byte *p = b;
|
|
|
|
int h2;
|
|
|
|
|
2007-03-01 01:24:44 +00:00
|
|
|
/* First try coalescing downwards */
|
2004-08-09 17:04:08 +00:00
|
|
|
do {
|
2005-07-08 21:24:27 +00:00
|
|
|
*p = 0;
|
|
|
|
p += DIRTY_BYTES_PER_LINE;
|
|
|
|
bottom += 8;
|
|
|
|
} while (bottom != h && *p != 0);
|
|
|
|
|
2007-03-01 01:24:44 +00:00
|
|
|
/* Try coalescing to the right too. */
|
2005-07-08 21:24:27 +00:00
|
|
|
h2 = (bottom - y) >> 3;
|
|
|
|
assert(h2 > 0);
|
|
|
|
p = b;
|
|
|
|
|
|
|
|
while (right != w) {
|
|
|
|
byte *p2 = ++p;
|
|
|
|
int h = h2;
|
2007-03-01 01:24:44 +00:00
|
|
|
/* Check if a full line of dirty flags is set. */
|
2005-07-08 21:24:27 +00:00
|
|
|
do {
|
|
|
|
if (!*p2) goto no_more_coalesc;
|
|
|
|
p2 += DIRTY_BYTES_PER_LINE;
|
|
|
|
} while (--h != 0);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-03-01 01:24:44 +00:00
|
|
|
/* Wohoo, can combine it one step to the right!
|
|
|
|
* Do that, and clear the bits. */
|
2005-07-08 21:24:27 +00:00
|
|
|
right += 64;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-07-08 21:24:27 +00:00
|
|
|
h = h2;
|
|
|
|
p2 = p;
|
|
|
|
do {
|
|
|
|
*p2 = 0;
|
|
|
|
p2 += DIRTY_BYTES_PER_LINE;
|
|
|
|
} while (--h != 0);
|
|
|
|
}
|
|
|
|
no_more_coalesc:
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-07-08 21:24:27 +00:00
|
|
|
left = x;
|
|
|
|
top = y;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-07-08 21:24:27 +00:00
|
|
|
if (left < _invalid_rect.left ) left = _invalid_rect.left;
|
|
|
|
if (top < _invalid_rect.top ) top = _invalid_rect.top;
|
|
|
|
if (right > _invalid_rect.right ) right = _invalid_rect.right;
|
|
|
|
if (bottom > _invalid_rect.bottom) bottom = _invalid_rect.bottom;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-07-08 21:24:27 +00:00
|
|
|
if (left < right && top < bottom) {
|
|
|
|
RedrawScreenRect(left, top, right, bottom);
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-07-08 21:24:27 +00:00
|
|
|
}
|
|
|
|
} while (b++, (x += 64) != w);
|
|
|
|
} while (b += -(w >> 6) + DIRTY_BYTES_PER_LINE, (y += 8) != h);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
_invalid_rect.left = w;
|
|
|
|
_invalid_rect.top = h;
|
|
|
|
_invalid_rect.right = 0;
|
|
|
|
_invalid_rect.bottom = 0;
|
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 10:00:30 +00:00
|
|
|
|
|
|
|
/* If we are generating a world, and waiting for a paint run, mark it here
|
|
|
|
* as done painting, so we can continue generating. */
|
|
|
|
if (IsGeneratingWorld() && IsGeneratingWorldReadyForPaint()) {
|
|
|
|
SetGeneratingWorldPaintStatus(false);
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2007-09-09 10:13:17 +00:00
|
|
|
/*!
|
|
|
|
* This function extends the internal _invalid_rect rectangle as it
|
|
|
|
* now contains the rectangle defined by the given parameters. Note
|
|
|
|
* the point (0,0) is top left.
|
|
|
|
*
|
|
|
|
* @param left The left edge of the rectangle
|
|
|
|
* @param top The top edge of the rectangle
|
|
|
|
* @param right The right edge of the rectangle
|
|
|
|
* @param bottom The bottm edge of the rectangle
|
|
|
|
* @see DrawDirtyBlocks
|
|
|
|
*
|
|
|
|
* @todo The name of the function should be called like @c AddDirtyBlock as
|
|
|
|
* it neither set a dirty rect nor add several dirty rects although
|
|
|
|
* the function name is in plural. (Progman)
|
|
|
|
*/
|
2004-08-09 17:04:08 +00:00
|
|
|
void SetDirtyBlocks(int left, int top, int right, int bottom)
|
|
|
|
{
|
|
|
|
byte *b;
|
2005-07-05 11:09:18 +00:00
|
|
|
int width;
|
|
|
|
int height;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
if (left < 0) left = 0;
|
|
|
|
if (top < 0) top = 0;
|
|
|
|
if (right > _screen.width) right = _screen.width;
|
|
|
|
if (bottom > _screen.height) bottom = _screen.height;
|
|
|
|
|
2005-07-05 11:09:18 +00:00
|
|
|
if (left >= right || top >= bottom) return;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-07-05 11:09:18 +00:00
|
|
|
if (left < _invalid_rect.left ) _invalid_rect.left = left;
|
|
|
|
if (top < _invalid_rect.top ) _invalid_rect.top = top;
|
|
|
|
if (right > _invalid_rect.right ) _invalid_rect.right = right;
|
|
|
|
if (bottom > _invalid_rect.bottom) _invalid_rect.bottom = bottom;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
left >>= 6;
|
2005-07-05 11:09:18 +00:00
|
|
|
top >>= 3;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
b = _dirty_blocks + top * DIRTY_BYTES_PER_LINE + left;
|
|
|
|
|
2005-07-05 11:09:18 +00:00
|
|
|
width = ((right - 1) >> 6) - left + 1;
|
|
|
|
height = ((bottom - 1) >> 3) - top + 1;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
assert(width > 0 && height > 0);
|
|
|
|
|
|
|
|
do {
|
2005-07-05 11:09:18 +00:00
|
|
|
int i = width;
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
do b[--i] = 0xFF; while (i);
|
|
|
|
|
|
|
|
b += DIRTY_BYTES_PER_LINE;
|
2005-07-05 11:09:18 +00:00
|
|
|
} while (--height != 0);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2007-09-09 10:13:17 +00:00
|
|
|
/*!
|
|
|
|
* This function mark the whole screen as dirty. This results in repainting
|
|
|
|
* the whole screen. Use this with care as this function will break the
|
|
|
|
* idea about marking only parts of the screen as 'dirty'.
|
|
|
|
*/
|
2007-03-07 11:47:46 +00:00
|
|
|
void MarkWholeScreenDirty()
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
SetDirtyBlocks(0, 0, _screen.width, _screen.height);
|
|
|
|
}
|
|
|
|
|
2006-10-27 11:09:24 +00:00
|
|
|
/** Set up a clipping area for only drawing into a certain area. To do this,
|
|
|
|
* Fill a DrawPixelInfo object with the supplied relative rectangle, backup
|
|
|
|
* the original (calling) _cur_dpi and assign the just returned DrawPixelInfo
|
|
|
|
* _cur_dpi. When you are done, give restore _cur_dpi's original value
|
|
|
|
* @param *n the DrawPixelInfo that will be the clipping rectangle box allowed
|
|
|
|
* for drawing
|
|
|
|
* @param left,top,width,height the relative coordinates of the clipping
|
|
|
|
* rectangle relative to the current _cur_dpi. This will most likely be the
|
|
|
|
* offset from the calling window coordinates
|
|
|
|
* @return return false if the requested rectangle is not possible with the
|
|
|
|
* current dpi pointer. Only continue of the return value is true, or you'll
|
|
|
|
* get some nasty results */
|
2006-08-28 07:33:51 +00:00
|
|
|
bool FillDrawPixelInfo(DrawPixelInfo *n, int left, int top, int width, int height)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2007-06-17 20:30:28 +00:00
|
|
|
Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter();
|
2006-08-28 07:33:51 +00:00
|
|
|
const DrawPixelInfo *o = _cur_dpi;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-05-15 14:08:39 +00:00
|
|
|
n->zoom = ZOOM_LVL_NORMAL;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
assert(width > 0);
|
|
|
|
assert(height > 0);
|
|
|
|
|
|
|
|
if ((left -= o->left) < 0) {
|
2005-07-05 11:09:18 +00:00
|
|
|
width += left;
|
2006-09-02 21:52:06 +00:00
|
|
|
if (width <= 0) return false;
|
2004-08-09 17:04:08 +00:00
|
|
|
n->left = -left;
|
|
|
|
left = 0;
|
2006-08-28 07:33:51 +00:00
|
|
|
} else {
|
|
|
|
n->left = 0;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2006-08-28 07:33:51 +00:00
|
|
|
if (width > o->width - left) {
|
|
|
|
width = o->width - left;
|
2006-09-02 21:52:06 +00:00
|
|
|
if (width <= 0) return false;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
n->width = width;
|
|
|
|
|
|
|
|
if ((top -= o->top) < 0) {
|
2005-07-05 11:09:18 +00:00
|
|
|
height += top;
|
2006-09-02 21:52:06 +00:00
|
|
|
if (height <= 0) return false;
|
2004-08-09 17:04:08 +00:00
|
|
|
n->top = -top;
|
|
|
|
top = 0;
|
2006-08-28 07:33:51 +00:00
|
|
|
} else {
|
|
|
|
n->top = 0;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2007-06-17 20:30:28 +00:00
|
|
|
n->dst_ptr = blitter->MoveTo(o->dst_ptr, left, top);
|
2007-06-12 20:24:12 +00:00
|
|
|
n->pitch = o->pitch;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-08-28 07:33:51 +00:00
|
|
|
if (height > o->height - top) {
|
|
|
|
height = o->height - top;
|
2006-09-02 21:52:06 +00:00
|
|
|
if (height <= 0) return false;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
n->height = height;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2007-01-14 19:57:49 +00:00
|
|
|
static void SetCursorSprite(SpriteID cursor, SpriteID pal)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
CursorVars *cv = &_cursor;
|
2005-02-08 22:22:42 +00:00
|
|
|
const Sprite *p;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-07-05 11:09:18 +00:00
|
|
|
if (cv->sprite == cursor) return;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-01-14 19:57:49 +00:00
|
|
|
p = GetSprite(GB(cursor, 0, SPRITE_WIDTH));
|
2004-08-09 17:04:08 +00:00
|
|
|
cv->sprite = cursor;
|
2007-01-14 19:57:49 +00:00
|
|
|
cv->pal = pal;
|
2005-02-08 22:22:42 +00:00
|
|
|
cv->size.y = p->height;
|
2005-02-10 12:26:41 +00:00
|
|
|
cv->size.x = p->width;
|
|
|
|
cv->offs.x = p->x_offs;
|
|
|
|
cv->offs.y = p->y_offs;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
cv->dirty = true;
|
|
|
|
}
|
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
static void SwitchAnimatedCursor()
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2007-02-24 15:05:14 +00:00
|
|
|
const AnimCursor *cur = _cursor.animate_cur;
|
2005-06-06 13:47:06 +00:00
|
|
|
|
2007-02-24 15:05:14 +00:00
|
|
|
if (cur == NULL || cur->sprite == AnimCursor::LAST) cur = _cursor.animate_list;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-02-24 15:05:14 +00:00
|
|
|
SetCursorSprite(cur->sprite, _cursor.pal);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-02-24 15:05:14 +00:00
|
|
|
_cursor.animate_timeout = cur->display_time;
|
|
|
|
_cursor.animate_cur = cur + 1;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
void CursorTick()
|
2005-01-22 20:23:18 +00:00
|
|
|
{
|
2005-07-05 11:09:18 +00:00
|
|
|
if (_cursor.animate_timeout != 0 && --_cursor.animate_timeout == 0)
|
2004-08-09 17:04:08 +00:00
|
|
|
SwitchAnimatedCursor();
|
|
|
|
}
|
|
|
|
|
2007-01-14 19:57:49 +00:00
|
|
|
void SetMouseCursor(SpriteID sprite, SpriteID pal)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2007-03-01 01:24:44 +00:00
|
|
|
/* Turn off animation */
|
2004-08-09 17:04:08 +00:00
|
|
|
_cursor.animate_timeout = 0;
|
2007-03-01 01:24:44 +00:00
|
|
|
/* Set cursor */
|
2007-01-14 19:57:49 +00:00
|
|
|
SetCursorSprite(sprite, pal);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2007-02-24 15:05:14 +00:00
|
|
|
void SetAnimatedMouseCursor(const AnimCursor *table)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
_cursor.animate_list = table;
|
|
|
|
_cursor.animate_cur = NULL;
|
2007-01-14 19:57:49 +00:00
|
|
|
_cursor.pal = PAL_NONE;
|
2004-08-09 17:04:08 +00:00
|
|
|
SwitchAnimatedCursor();
|
|
|
|
}
|
|
|
|
|
2007-07-29 15:48:43 +00:00
|
|
|
bool ChangeResInGame(int width, int height)
|
2004-09-10 19:02:27 +00:00
|
|
|
{
|
2007-07-29 19:18:22 +00:00
|
|
|
return (_screen.width == width && _screen.height == height) || _video_driver->ChangeResolution(width, height);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2004-09-21 20:56:49 +00:00
|
|
|
|
2008-01-01 14:20:48 +00:00
|
|
|
bool ToggleFullScreen(bool fs)
|
2006-12-03 17:42:56 +00:00
|
|
|
{
|
2008-01-01 14:20:48 +00:00
|
|
|
bool result = _video_driver->ToggleFullscreen(fs);
|
2006-12-03 17:42:56 +00:00
|
|
|
if (_fullscreen != fs && _num_resolutions == 0) {
|
2006-12-26 17:36:18 +00:00
|
|
|
DEBUG(driver, 0, "Could not find a suitable fullscreen resolution");
|
2006-12-03 17:42:56 +00:00
|
|
|
}
|
2008-01-01 14:20:48 +00:00
|
|
|
return result;
|
2006-12-03 17:42:56 +00:00
|
|
|
}
|
2005-05-16 16:19:32 +00:00
|
|
|
|
2005-05-14 21:01:57 +00:00
|
|
|
static int CDECL compare_res(const void *pa, const void *pb)
|
2004-09-21 20:56:49 +00:00
|
|
|
{
|
2005-05-14 21:01:57 +00:00
|
|
|
int x = ((const uint16*)pa)[0] - ((const uint16*)pb)[0];
|
|
|
|
if (x != 0) return x;
|
|
|
|
return ((const uint16*)pa)[1] - ((const uint16*)pb)[1];
|
|
|
|
}
|
|
|
|
|
|
|
|
void SortResolutions(int count)
|
|
|
|
{
|
|
|
|
qsort(_resolutions, count, sizeof(_resolutions[0]), compare_res);
|
2004-09-21 20:56:49 +00:00
|
|
|
}
|