author | translators |
Tue, 02 Dec 2008 18:47:03 +0000 | |
changeset 10397 | 3794189a5524 |
parent 10310 | ca2eb5811a07 |
child 10415 | fabf65e49e38 |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
9111
48ce04029fe4
(svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium
parents:
8985
diff
changeset
|
3 |
/** @file gfx.cpp Handling of drawing text and other gfx related stuff. */ |
6179
d19b0137d8e4
(svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6138
diff
changeset
|
4 |
|
0 | 5 |
#include "stdafx.h" |
1891
862800791170
(svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents:
1829
diff
changeset
|
6 |
#include "openttd.h" |
8123
ce31d2843a95
(svn r11684) -Codechange: split gfx.h in a type and functional header.
rubidium
parents:
8121
diff
changeset
|
7 |
#include "gfx_func.h" |
1349
15979a2e9001
(svn r1853) Move spritecache function declarations into a header of their own and use SpriteID as parameter type where appropriate
tron
parents:
1348
diff
changeset
|
8 |
#include "spritecache.h" |
2153
ecfc674410b4
(svn r2663) Include variables.h only in these files which need it, not globally via openttd.h
tron
parents:
2134
diff
changeset
|
9 |
#include "variables.h" |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
10 |
#include "fontcache.h" |
4300
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4171
diff
changeset
|
11 |
#include "genworld.h" |
5217
7a9e91919a93
(svn r7332) -Fix: segmentation fault, discovered by ln-, in the SDL video driver when one goes to fullscreen and there are no suitable resolutions.
rubidium
parents:
5156
diff
changeset
|
12 |
#include "debug.h" |
8123
ce31d2843a95
(svn r11684) -Codechange: split gfx.h in a type and functional header.
rubidium
parents:
8121
diff
changeset
|
13 |
#include "zoom_func.h" |
6998
39e783d3816c
(svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents:
6985
diff
changeset
|
14 |
#include "texteff.hpp" |
6937
40c760fcf1f6
(svn r10190) -Codechange: merged renderer and blitter to one single class API: blitter
truelight
parents:
6889
diff
changeset
|
15 |
#include "blitter/factory.hpp" |
7170
923946ec324f
(svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents:
7018
diff
changeset
|
16 |
#include "video/video_driver.hpp" |
8114
dd6d21dc99c1
(svn r11675) -Codechange: split the string types from the string functions.
rubidium
parents:
8113
diff
changeset
|
17 |
#include "strings_func.h" |
8131
160939e24ed3
(svn r11692) -Codechange: move some functions from 'functions.h' to a more logical place and remove about 50% of the includes of 'functions.h'
rubidium
parents:
8123
diff
changeset
|
18 |
#include "core/math_func.hpp" |
8270
e7c342f6b14c
(svn r11834) -Codechange: only include settings_type.h if needed.
rubidium
parents:
8264
diff
changeset
|
19 |
#include "settings_type.h" |
8985
6461e5c6d6e4
(svn r12779) -Codechange: remove a few constants from openttd.h.
rubidium
parents:
8981
diff
changeset
|
20 |
#include "core/alloc_func.hpp" |
9527
c1bf97006786
(svn r13523) -Codechange: replace qsort by the internal typesafe QSortT for resolution sorting
skidd13
parents:
9511
diff
changeset
|
21 |
#include "core/sort_func.hpp" |
9126
5648d696456b
(svn r12986) -Codechange: move the landscape and transport related types from openttd.h to their own headers.
rubidium
parents:
9111
diff
changeset
|
22 |
#include "landscape_type.h" |
9898
75347c78b276
(svn r14047) -Codechange: move chatmessage handling to the network directory as that's the only case chat messages are used. Furthermore remove any trace of chatmessages when compiling without network support.
rubidium
parents:
9895
diff
changeset
|
23 |
#include "network/network_func.h" |
0 | 24 |
|
8264
b1e85998c7d3
(svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents:
8249
diff
changeset
|
25 |
#include "table/palettes.h" |
b1e85998c7d3
(svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents:
8249
diff
changeset
|
26 |
#include "table/sprites.h" |
b1e85998c7d3
(svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents:
8249
diff
changeset
|
27 |
#include "table/control_codes.h" |
b1e85998c7d3
(svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents:
8249
diff
changeset
|
28 |
|
6179
d19b0137d8e4
(svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6138
diff
changeset
|
29 |
byte _dirkeys; ///< 1 = left, 2 = up, 4 = right, 8 = down |
5636
3c19b56dc982
(svn r8095) -Codechange: stuff that is not related to HAL moved from hal.h to gfx.h
KUDr
parents:
5587
diff
changeset
|
30 |
bool _fullscreen; |
3c19b56dc982
(svn r8095) -Codechange: stuff that is not related to HAL moved from hal.h to gfx.h
KUDr
parents:
5587
diff
changeset
|
31 |
CursorVars _cursor; |
6179
d19b0137d8e4
(svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6138
diff
changeset
|
32 |
bool _ctrl_pressed; ///< Is Ctrl pressed? |
d19b0137d8e4
(svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6138
diff
changeset
|
33 |
bool _shift_pressed; ///< Is Shift pressed? |
5636
3c19b56dc982
(svn r8095) -Codechange: stuff that is not related to HAL moved from hal.h to gfx.h
KUDr
parents:
5587
diff
changeset
|
34 |
byte _fast_forward; |
8857
7593af4962e6
(svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents:
8737
diff
changeset
|
35 |
bool _left_button_down; ///< Is left mouse button pressed? |
7593af4962e6
(svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents:
8737
diff
changeset
|
36 |
bool _left_button_clicked; ///< Is left mouse button clicked? |
7593af4962e6
(svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents:
8737
diff
changeset
|
37 |
bool _right_button_down; ///< Is right mouse button pressed? |
7593af4962e6
(svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents:
8737
diff
changeset
|
38 |
bool _right_button_clicked; ///< Is right mouse button clicked? |
5636
3c19b56dc982
(svn r8095) -Codechange: stuff that is not related to HAL moved from hal.h to gfx.h
KUDr
parents:
5587
diff
changeset
|
39 |
DrawPixelInfo _screen; |
8249
90bd3316062f
(svn r11813) -Fix [FS#1602]: Switch _screen to the output buffer and disable usage of 32bpp-anim animation buffer during giant screenshots.
frosch
parents:
8214
diff
changeset
|
40 |
bool _screen_disable_anim = false; ///< Disable palette animation (important for 32bpp-anim blitter during giant screenshot) |
5636
3c19b56dc982
(svn r8095) -Codechange: stuff that is not related to HAL moved from hal.h to gfx.h
KUDr
parents:
5587
diff
changeset
|
41 |
bool _exit_game; |
3c19b56dc982
(svn r8095) -Codechange: stuff that is not related to HAL moved from hal.h to gfx.h
KUDr
parents:
5587
diff
changeset
|
42 |
bool _networking; ///< are we in networking mode? |
3c19b56dc982
(svn r8095) -Codechange: stuff that is not related to HAL moved from hal.h to gfx.h
KUDr
parents:
5587
diff
changeset
|
43 |
byte _game_mode; |
8670
4f8e4590be7f
(svn r12335) -Codechange: Don't stuff signed values into a unsigned variable when the variable can just be unsigned...
peter1138
parents:
8270
diff
changeset
|
44 |
int8 _pause_game; |
5636
3c19b56dc982
(svn r8095) -Codechange: stuff that is not related to HAL moved from hal.h to gfx.h
KUDr
parents:
5587
diff
changeset
|
45 |
int _pal_first_dirty; |
6960
356d856462b6
(svn r10216) -Fix: palette animation always redid all palette entries, where in fact only a few indexes were needed
truelight
parents:
6951
diff
changeset
|
46 |
int _pal_count_dirty; |
5636
3c19b56dc982
(svn r8095) -Codechange: stuff that is not related to HAL moved from hal.h to gfx.h
KUDr
parents:
5587
diff
changeset
|
47 |
|
1991
4ce69ba880b4
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
48 |
Colour _cur_palette[256]; |
9773
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
49 |
byte _stringwidth_table[FS_END][224]; ///< Cache containing width of often used characters. @see GetCharacterWidth() |
8123
ce31d2843a95
(svn r11684) -Codechange: split gfx.h in a type and functional header.
rubidium
parents:
8121
diff
changeset
|
50 |
DrawPixelInfo *_cur_dpi; |
9850
61bd42a09ddd
(svn r13994) -Codechange: replace a few rogue magic numbers with Colours enum values
belugas
parents:
9773
diff
changeset
|
51 |
byte _colour_gradient[COLOUR_END][8]; |
1991
4ce69ba880b4
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
52 |
|
7681
582e8912e8d1
(svn r11212) -Codechange: add support for drawing parts of sprites. Patch by frosch.
rubidium
parents:
7651
diff
changeset
|
53 |
static void GfxMainBlitter(const Sprite *sprite, int x, int y, BlitterMode mode, const SubSprite *sub = NULL); |
10248
f0297aac2ff2
(svn r14479) -Add: initial (optional) support for handling bidirectional scripts and connecting Arabic characters.
rubidium
parents:
10056
diff
changeset
|
54 |
static int ReallyDoDrawString(const char *string, int x, int y, uint16 real_colour, bool parse_string_also_when_clipped = false); |
0 | 55 |
|
3798
b1f5290b36b1
(svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents:
3797
diff
changeset
|
56 |
FontSize _cur_fontsize; |
b1f5290b36b1
(svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents:
3797
diff
changeset
|
57 |
static FontSize _last_fontsize; |
6878
5cefd3ac59c7
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
6852
diff
changeset
|
58 |
static uint8 _cursor_backup[64 * 64 * 4]; |
7545
d44e19c5671e
(svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents:
7454
diff
changeset
|
59 |
|
d44e19c5671e
(svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents:
7454
diff
changeset
|
60 |
/** |
d44e19c5671e
(svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents:
7454
diff
changeset
|
61 |
* The rect for repaint. |
d44e19c5671e
(svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents:
7454
diff
changeset
|
62 |
* |
d44e19c5671e
(svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents:
7454
diff
changeset
|
63 |
* This rectangle defines the area which should be repaint by the video driver. |
d44e19c5671e
(svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents:
7454
diff
changeset
|
64 |
* |
d44e19c5671e
(svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents:
7454
diff
changeset
|
65 |
* @ingroup dirty |
d44e19c5671e
(svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents:
7454
diff
changeset
|
66 |
*/ |
0 | 67 |
static Rect _invalid_rect; |
1357 | 68 |
static const byte *_color_remap_ptr; |
0 | 69 |
static byte _string_colorremap[3]; |
70 |
||
8981
dd0cd0e54ac3
(svn r12773) -Codechange: replace some magic numbers with enums.
rubidium
parents:
8857
diff
changeset
|
71 |
enum { |
dd0cd0e54ac3
(svn r12773) -Codechange: replace some magic numbers with enums.
rubidium
parents:
8857
diff
changeset
|
72 |
DIRTY_BLOCK_HEIGHT = 8, |
dd0cd0e54ac3
(svn r12773) -Codechange: replace some magic numbers with enums.
rubidium
parents:
8857
diff
changeset
|
73 |
DIRTY_BLOCK_WIDTH = 64, |
dd0cd0e54ac3
(svn r12773) -Codechange: replace some magic numbers with enums.
rubidium
parents:
8857
diff
changeset
|
74 |
}; |
8985
6461e5c6d6e4
(svn r12779) -Codechange: remove a few constants from openttd.h.
rubidium
parents:
8981
diff
changeset
|
75 |
static uint _dirty_bytes_per_line = 0; |
6461e5c6d6e4
(svn r12779) -Codechange: remove a few constants from openttd.h.
rubidium
parents:
8981
diff
changeset
|
76 |
static byte *_dirty_blocks = NULL; |
0 | 77 |
|
2010 | 78 |
void GfxScroll(int left, int top, int width, int height, int xo, int yo) |
79 |
{ |
|
6937
40c760fcf1f6
(svn r10190) -Codechange: merged renderer and blitter to one single class API: blitter
truelight
parents:
6889
diff
changeset
|
80 |
Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter(); |
0 | 81 |
|
2010 | 82 |
if (xo == 0 && yo == 0) return; |
0 | 83 |
|
2010 | 84 |
if (_cursor.visible) UndrawMouseCursor(); |
9898
75347c78b276
(svn r14047) -Codechange: move chatmessage handling to the network directory as that's the only case chat messages are used. Furthermore remove any trace of chatmessages when compiling without network support.
rubidium
parents:
9895
diff
changeset
|
85 |
|
75347c78b276
(svn r14047) -Codechange: move chatmessage handling to the network directory as that's the only case chat messages are used. Furthermore remove any trace of chatmessages when compiling without network support.
rubidium
parents:
9895
diff
changeset
|
86 |
#ifdef ENABLE_NETWORK |
75347c78b276
(svn r14047) -Codechange: move chatmessage handling to the network directory as that's the only case chat messages are used. Furthermore remove any trace of chatmessages when compiling without network support.
rubidium
parents:
9895
diff
changeset
|
87 |
NetworkUndrawChatMessage(); |
75347c78b276
(svn r14047) -Codechange: move chatmessage handling to the network directory as that's the only case chat messages are used. Furthermore remove any trace of chatmessages when compiling without network support.
rubidium
parents:
9895
diff
changeset
|
88 |
#endif /* ENABLE_NETWORK */ |
0 | 89 |
|
6951
b24e0f108ede
(svn r10206) -Codechange: more moving things to blitter-layer: ScrollBuffer
truelight
parents:
6948
diff
changeset
|
90 |
blitter->ScrollBuffer(_screen.dst_ptr, left, top, width, height, xo, yo); |
6179
d19b0137d8e4
(svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6138
diff
changeset
|
91 |
/* This part of the screen is now dirty. */ |
7170
923946ec324f
(svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents:
7018
diff
changeset
|
92 |
_video_driver->MakeDirty(left, top, width, height); |
0 | 93 |
} |
94 |
||
95 |
||
9607
5a5728fb702a
(svn r13649) -Codechange: Split the GfxFillRect() special flags from 'color' into their own parameter.
frosch
parents:
9533
diff
changeset
|
96 |
/** |
5a5728fb702a
(svn r13649) -Codechange: Split the GfxFillRect() special flags from 'color' into their own parameter.
frosch
parents:
9533
diff
changeset
|
97 |
* Applies a certain FillRectMode-operation to a rectangle [left, right] x [top, bottom] on the screen. |
5a5728fb702a
(svn r13649) -Codechange: Split the GfxFillRect() special flags from 'color' into their own parameter.
frosch
parents:
9533
diff
changeset
|
98 |
* |
5a5728fb702a
(svn r13649) -Codechange: Split the GfxFillRect() special flags from 'color' into their own parameter.
frosch
parents:
9533
diff
changeset
|
99 |
* @pre dpi->zoom == ZOOM_LVL_NORMAL, right >= left, bottom >= top |
5a5728fb702a
(svn r13649) -Codechange: Split the GfxFillRect() special flags from 'color' into their own parameter.
frosch
parents:
9533
diff
changeset
|
100 |
* @param left Minimum X (inclusive) |
5a5728fb702a
(svn r13649) -Codechange: Split the GfxFillRect() special flags from 'color' into their own parameter.
frosch
parents:
9533
diff
changeset
|
101 |
* @param top Minimum Y (inclusive) |
5a5728fb702a
(svn r13649) -Codechange: Split the GfxFillRect() special flags from 'color' into their own parameter.
frosch
parents:
9533
diff
changeset
|
102 |
* @param right Maximum X (inclusive) |
5a5728fb702a
(svn r13649) -Codechange: Split the GfxFillRect() special flags from 'color' into their own parameter.
frosch
parents:
9533
diff
changeset
|
103 |
* @param bottom Maximum Y (inclusive) |
5a5728fb702a
(svn r13649) -Codechange: Split the GfxFillRect() special flags from 'color' into their own parameter.
frosch
parents:
9533
diff
changeset
|
104 |
* @param color A 8 bit palette index (FILLRECT_OPAQUE and FILLRECT_CHECKER) or a recolor spritenumber (FILLRECT_RECOLOR) |
5a5728fb702a
(svn r13649) -Codechange: Split the GfxFillRect() special flags from 'color' into their own parameter.
frosch
parents:
9533
diff
changeset
|
105 |
* @param mode |
5a5728fb702a
(svn r13649) -Codechange: Split the GfxFillRect() special flags from 'color' into their own parameter.
frosch
parents:
9533
diff
changeset
|
106 |
* FILLRECT_OPAQUE: Fill the rectangle with the specified color |
5a5728fb702a
(svn r13649) -Codechange: Split the GfxFillRect() special flags from 'color' into their own parameter.
frosch
parents:
9533
diff
changeset
|
107 |
* FILLRECT_CHECKER: Like FILLRECT_OPAQUE, but only draw every second pixel (used to grey out things) |
5a5728fb702a
(svn r13649) -Codechange: Split the GfxFillRect() special flags from 'color' into their own parameter.
frosch
parents:
9533
diff
changeset
|
108 |
* FILLRECT_RECOLOR: Apply a recolor sprite to every pixel in the rectangle currently on screen |
5a5728fb702a
(svn r13649) -Codechange: Split the GfxFillRect() special flags from 'color' into their own parameter.
frosch
parents:
9533
diff
changeset
|
109 |
*/ |
5a5728fb702a
(svn r13649) -Codechange: Split the GfxFillRect() special flags from 'color' into their own parameter.
frosch
parents:
9533
diff
changeset
|
110 |
void GfxFillRect(int left, int top, int right, int bottom, int color, FillRectMode mode) |
2010 | 111 |
{ |
6937
40c760fcf1f6
(svn r10190) -Codechange: merged renderer and blitter to one single class API: blitter
truelight
parents:
6889
diff
changeset
|
112 |
Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter(); |
6878
5cefd3ac59c7
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
6852
diff
changeset
|
113 |
const DrawPixelInfo *dpi = _cur_dpi; |
5cefd3ac59c7
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
6852
diff
changeset
|
114 |
void *dst; |
332 | 115 |
const int otop = top; |
116 |
const int oleft = left; |
|
0 | 117 |
|
6624
880e29b1f25e
(svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents:
6615
diff
changeset
|
118 |
if (dpi->zoom != ZOOM_LVL_NORMAL) return; |
2010 | 119 |
if (left > right || top > bottom) return; |
120 |
if (right < dpi->left || left >= dpi->left + dpi->width) return; |
|
121 |
if (bottom < dpi->top || top >= dpi->top + dpi->height) return; |
|
0 | 122 |
|
123 |
if ( (left -= dpi->left) < 0) left = 0; |
|
124 |
right = right - dpi->left + 1; |
|
2010 | 125 |
if (right > dpi->width) right = dpi->width; |
0 | 126 |
right -= left; |
127 |
assert(right > 0); |
|
128 |
||
129 |
if ( (top -= dpi->top) < 0) top = 0; |
|
130 |
bottom = bottom - dpi->top + 1; |
|
2010 | 131 |
if (bottom > dpi->height) bottom = dpi->height; |
0 | 132 |
bottom -= top; |
133 |
assert(bottom > 0); |
|
134 |
||
6937
40c760fcf1f6
(svn r10190) -Codechange: merged renderer and blitter to one single class API: blitter
truelight
parents:
6889
diff
changeset
|
135 |
dst = blitter->MoveTo(dpi->dst_ptr, left, top); |
0 | 136 |
|
9607
5a5728fb702a
(svn r13649) -Codechange: Split the GfxFillRect() special flags from 'color' into their own parameter.
frosch
parents:
9533
diff
changeset
|
137 |
switch (mode) { |
5a5728fb702a
(svn r13649) -Codechange: Split the GfxFillRect() special flags from 'color' into their own parameter.
frosch
parents:
9533
diff
changeset
|
138 |
default: // FILLRECT_OPAQUE |
6947
2e14760f63f9
(svn r10201) -Codechange: Replace Blitter::SetHorizontalLine with Blitter::DrawRect, as the former was only used by the rectangle drawing code anyway. This lets us draw rectangles in one go.
peter1138
parents:
6937
diff
changeset
|
139 |
blitter->DrawRect(dst, right, bottom, (uint8)color); |
9607
5a5728fb702a
(svn r13649) -Codechange: Split the GfxFillRect() special flags from 'color' into their own parameter.
frosch
parents:
9533
diff
changeset
|
140 |
break; |
5a5728fb702a
(svn r13649) -Codechange: Split the GfxFillRect() special flags from 'color' into their own parameter.
frosch
parents:
9533
diff
changeset
|
141 |
|
5a5728fb702a
(svn r13649) -Codechange: Split the GfxFillRect() special flags from 'color' into their own parameter.
frosch
parents:
9533
diff
changeset
|
142 |
case FILLRECT_RECOLOR: |
6937
40c760fcf1f6
(svn r10190) -Codechange: merged renderer and blitter to one single class API: blitter
truelight
parents:
6889
diff
changeset
|
143 |
blitter->DrawColorMappingRect(dst, right, bottom, GB(color, 0, PALETTE_WIDTH)); |
9607
5a5728fb702a
(svn r13649) -Codechange: Split the GfxFillRect() special flags from 'color' into their own parameter.
frosch
parents:
9533
diff
changeset
|
144 |
break; |
5a5728fb702a
(svn r13649) -Codechange: Split the GfxFillRect() special flags from 'color' into their own parameter.
frosch
parents:
9533
diff
changeset
|
145 |
|
5a5728fb702a
(svn r13649) -Codechange: Split the GfxFillRect() special flags from 'color' into their own parameter.
frosch
parents:
9533
diff
changeset
|
146 |
case FILLRECT_CHECKER: { |
5a5728fb702a
(svn r13649) -Codechange: Split the GfxFillRect() special flags from 'color' into their own parameter.
frosch
parents:
9533
diff
changeset
|
147 |
byte bo = (oleft - left + dpi->left + otop - top + dpi->top) & 1; |
5a5728fb702a
(svn r13649) -Codechange: Split the GfxFillRect() special flags from 'color' into their own parameter.
frosch
parents:
9533
diff
changeset
|
148 |
do { |
5a5728fb702a
(svn r13649) -Codechange: Split the GfxFillRect() special flags from 'color' into their own parameter.
frosch
parents:
9533
diff
changeset
|
149 |
for (int i = (bo ^= 1); i < right; i += 2) blitter->SetPixel(dst, i, 0, (uint8)color); |
5a5728fb702a
(svn r13649) -Codechange: Split the GfxFillRect() special flags from 'color' into their own parameter.
frosch
parents:
9533
diff
changeset
|
150 |
dst = blitter->MoveTo(dst, 0, 1); |
5a5728fb702a
(svn r13649) -Codechange: Split the GfxFillRect() special flags from 'color' into their own parameter.
frosch
parents:
9533
diff
changeset
|
151 |
} while (--bottom > 0); |
5a5728fb702a
(svn r13649) -Codechange: Split the GfxFillRect() special flags from 'color' into their own parameter.
frosch
parents:
9533
diff
changeset
|
152 |
break; |
0 | 153 |
} |
154 |
} |
|
155 |
} |
|
156 |
||
157 |
void GfxDrawLine(int x, int y, int x2, int y2, int color) |
|
158 |
{ |
|
6948
d7d326482813
(svn r10203) -Codechange: more moving things to blitter-layer: DrawLine
truelight
parents:
6947
diff
changeset
|
159 |
Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter(); |
d7d326482813
(svn r10203) -Codechange: more moving things to blitter-layer: DrawLine
truelight
parents:
6947
diff
changeset
|
160 |
DrawPixelInfo *dpi = _cur_dpi; |
0 | 161 |
|
6948
d7d326482813
(svn r10203) -Codechange: more moving things to blitter-layer: DrawLine
truelight
parents:
6947
diff
changeset
|
162 |
x -= dpi->left; |
d7d326482813
(svn r10203) -Codechange: more moving things to blitter-layer: DrawLine
truelight
parents:
6947
diff
changeset
|
163 |
x2 -= dpi->left; |
d7d326482813
(svn r10203) -Codechange: more moving things to blitter-layer: DrawLine
truelight
parents:
6947
diff
changeset
|
164 |
y -= dpi->top; |
d7d326482813
(svn r10203) -Codechange: more moving things to blitter-layer: DrawLine
truelight
parents:
6947
diff
changeset
|
165 |
y2 -= dpi->top; |
0 | 166 |
|
6948
d7d326482813
(svn r10203) -Codechange: more moving things to blitter-layer: DrawLine
truelight
parents:
6947
diff
changeset
|
167 |
/* Check clipping */ |
d7d326482813
(svn r10203) -Codechange: more moving things to blitter-layer: DrawLine
truelight
parents:
6947
diff
changeset
|
168 |
if (x < 0 && x2 < 0) return; |
d7d326482813
(svn r10203) -Codechange: more moving things to blitter-layer: DrawLine
truelight
parents:
6947
diff
changeset
|
169 |
if (y < 0 && y2 < 0) return; |
d7d326482813
(svn r10203) -Codechange: more moving things to blitter-layer: DrawLine
truelight
parents:
6947
diff
changeset
|
170 |
if (x > dpi->width && x2 > dpi->width) return; |
d7d326482813
(svn r10203) -Codechange: more moving things to blitter-layer: DrawLine
truelight
parents:
6947
diff
changeset
|
171 |
if (y > dpi->height && y2 > dpi->height) return; |
d7d326482813
(svn r10203) -Codechange: more moving things to blitter-layer: DrawLine
truelight
parents:
6947
diff
changeset
|
172 |
|
d7d326482813
(svn r10203) -Codechange: more moving things to blitter-layer: DrawLine
truelight
parents:
6947
diff
changeset
|
173 |
blitter->DrawLine(dpi->dst_ptr, x, y, x2, y2, dpi->width, dpi->height, color); |
0 | 174 |
} |
175 |
||
7651
99bd9cd9e684
(svn r11182) -Fix [FS#1261] (r11174): bounding boxes caused crashes when zoomed out. Patch by SmatZ.
rubidium
parents:
7643
diff
changeset
|
176 |
void GfxDrawLineUnscaled(int x, int y, int x2, int y2, int color) |
99bd9cd9e684
(svn r11182) -Fix [FS#1261] (r11174): bounding boxes caused crashes when zoomed out. Patch by SmatZ.
rubidium
parents:
7643
diff
changeset
|
177 |
{ |
99bd9cd9e684
(svn r11182) -Fix [FS#1261] (r11174): bounding boxes caused crashes when zoomed out. Patch by SmatZ.
rubidium
parents:
7643
diff
changeset
|
178 |
Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter(); |
99bd9cd9e684
(svn r11182) -Fix [FS#1261] (r11174): bounding boxes caused crashes when zoomed out. Patch by SmatZ.
rubidium
parents:
7643
diff
changeset
|
179 |
DrawPixelInfo *dpi = _cur_dpi; |
99bd9cd9e684
(svn r11182) -Fix [FS#1261] (r11174): bounding boxes caused crashes when zoomed out. Patch by SmatZ.
rubidium
parents:
7643
diff
changeset
|
180 |
|
99bd9cd9e684
(svn r11182) -Fix [FS#1261] (r11174): bounding boxes caused crashes when zoomed out. Patch by SmatZ.
rubidium
parents:
7643
diff
changeset
|
181 |
x -= dpi->left; |
99bd9cd9e684
(svn r11182) -Fix [FS#1261] (r11174): bounding boxes caused crashes when zoomed out. Patch by SmatZ.
rubidium
parents:
7643
diff
changeset
|
182 |
x2 -= dpi->left; |
99bd9cd9e684
(svn r11182) -Fix [FS#1261] (r11174): bounding boxes caused crashes when zoomed out. Patch by SmatZ.
rubidium
parents:
7643
diff
changeset
|
183 |
y -= dpi->top; |
99bd9cd9e684
(svn r11182) -Fix [FS#1261] (r11174): bounding boxes caused crashes when zoomed out. Patch by SmatZ.
rubidium
parents:
7643
diff
changeset
|
184 |
y2 -= dpi->top; |
99bd9cd9e684
(svn r11182) -Fix [FS#1261] (r11174): bounding boxes caused crashes when zoomed out. Patch by SmatZ.
rubidium
parents:
7643
diff
changeset
|
185 |
|
99bd9cd9e684
(svn r11182) -Fix [FS#1261] (r11174): bounding boxes caused crashes when zoomed out. Patch by SmatZ.
rubidium
parents:
7643
diff
changeset
|
186 |
/* Check clipping */ |
99bd9cd9e684
(svn r11182) -Fix [FS#1261] (r11174): bounding boxes caused crashes when zoomed out. Patch by SmatZ.
rubidium
parents:
7643
diff
changeset
|
187 |
if (x < 0 && x2 < 0) return; |
99bd9cd9e684
(svn r11182) -Fix [FS#1261] (r11174): bounding boxes caused crashes when zoomed out. Patch by SmatZ.
rubidium
parents:
7643
diff
changeset
|
188 |
if (y < 0 && y2 < 0) return; |
99bd9cd9e684
(svn r11182) -Fix [FS#1261] (r11174): bounding boxes caused crashes when zoomed out. Patch by SmatZ.
rubidium
parents:
7643
diff
changeset
|
189 |
if (x > dpi->width && x2 > dpi->width) return; |
99bd9cd9e684
(svn r11182) -Fix [FS#1261] (r11174): bounding boxes caused crashes when zoomed out. Patch by SmatZ.
rubidium
parents:
7643
diff
changeset
|
190 |
if (y > dpi->height && y2 > dpi->height) return; |
99bd9cd9e684
(svn r11182) -Fix [FS#1261] (r11174): bounding boxes caused crashes when zoomed out. Patch by SmatZ.
rubidium
parents:
7643
diff
changeset
|
191 |
|
99bd9cd9e684
(svn r11182) -Fix [FS#1261] (r11174): bounding boxes caused crashes when zoomed out. Patch by SmatZ.
rubidium
parents:
7643
diff
changeset
|
192 |
blitter->DrawLine(dpi->dst_ptr, UnScaleByZoom(x, dpi->zoom), UnScaleByZoom(y, dpi->zoom), |
99bd9cd9e684
(svn r11182) -Fix [FS#1261] (r11174): bounding boxes caused crashes when zoomed out. Patch by SmatZ.
rubidium
parents:
7643
diff
changeset
|
193 |
UnScaleByZoom(x2, dpi->zoom), UnScaleByZoom(y2, dpi->zoom), |
99bd9cd9e684
(svn r11182) -Fix [FS#1261] (r11174): bounding boxes caused crashes when zoomed out. Patch by SmatZ.
rubidium
parents:
7643
diff
changeset
|
194 |
UnScaleByZoom(dpi->width, dpi->zoom), UnScaleByZoom(dpi->height, dpi->zoom), color); |
99bd9cd9e684
(svn r11182) -Fix [FS#1261] (r11174): bounding boxes caused crashes when zoomed out. Patch by SmatZ.
rubidium
parents:
7643
diff
changeset
|
195 |
} |
99bd9cd9e684
(svn r11182) -Fix [FS#1261] (r11174): bounding boxes caused crashes when zoomed out. Patch by SmatZ.
rubidium
parents:
7643
diff
changeset
|
196 |
|
7643
af32b07bc027
(svn r11174) -Codechange: add possibility to show the bounding boxes of sprites using CTRL-B so one can get a better understanding of the used bounding boxes to fix the glitches that still exist. Patch by frosch.
rubidium
parents:
7545
diff
changeset
|
197 |
/** |
af32b07bc027
(svn r11174) -Codechange: add possibility to show the bounding boxes of sprites using CTRL-B so one can get a better understanding of the used bounding boxes to fix the glitches that still exist. Patch by frosch.
rubidium
parents:
7545
diff
changeset
|
198 |
* Draws the projection of a parallelepiped. |
af32b07bc027
(svn r11174) -Codechange: add possibility to show the bounding boxes of sprites using CTRL-B so one can get a better understanding of the used bounding boxes to fix the glitches that still exist. Patch by frosch.
rubidium
parents:
7545
diff
changeset
|
199 |
* This can be used to draw boxes in world coordinates. |
af32b07bc027
(svn r11174) -Codechange: add possibility to show the bounding boxes of sprites using CTRL-B so one can get a better understanding of the used bounding boxes to fix the glitches that still exist. Patch by frosch.
rubidium
parents:
7545
diff
changeset
|
200 |
* |
af32b07bc027
(svn r11174) -Codechange: add possibility to show the bounding boxes of sprites using CTRL-B so one can get a better understanding of the used bounding boxes to fix the glitches that still exist. Patch by frosch.
rubidium
parents:
7545
diff
changeset
|
201 |
* @param x Screen X-coordinate of top front corner. |
af32b07bc027
(svn r11174) -Codechange: add possibility to show the bounding boxes of sprites using CTRL-B so one can get a better understanding of the used bounding boxes to fix the glitches that still exist. Patch by frosch.
rubidium
parents:
7545
diff
changeset
|
202 |
* @param y Screen Y-coordinate of top front corner. |
af32b07bc027
(svn r11174) -Codechange: add possibility to show the bounding boxes of sprites using CTRL-B so one can get a better understanding of the used bounding boxes to fix the glitches that still exist. Patch by frosch.
rubidium
parents:
7545
diff
changeset
|
203 |
* @param dx1 Screen X-length of first edge. |
af32b07bc027
(svn r11174) -Codechange: add possibility to show the bounding boxes of sprites using CTRL-B so one can get a better understanding of the used bounding boxes to fix the glitches that still exist. Patch by frosch.
rubidium
parents:
7545
diff
changeset
|
204 |
* @param dy1 Screen Y-length of first edge. |
af32b07bc027
(svn r11174) -Codechange: add possibility to show the bounding boxes of sprites using CTRL-B so one can get a better understanding of the used bounding boxes to fix the glitches that still exist. Patch by frosch.
rubidium
parents:
7545
diff
changeset
|
205 |
* @param dx2 Screen X-length of second edge. |
af32b07bc027
(svn r11174) -Codechange: add possibility to show the bounding boxes of sprites using CTRL-B so one can get a better understanding of the used bounding boxes to fix the glitches that still exist. Patch by frosch.
rubidium
parents:
7545
diff
changeset
|
206 |
* @param dy2 Screen Y-length of second edge. |
af32b07bc027
(svn r11174) -Codechange: add possibility to show the bounding boxes of sprites using CTRL-B so one can get a better understanding of the used bounding boxes to fix the glitches that still exist. Patch by frosch.
rubidium
parents:
7545
diff
changeset
|
207 |
* @param dx3 Screen X-length of third edge. |
af32b07bc027
(svn r11174) -Codechange: add possibility to show the bounding boxes of sprites using CTRL-B so one can get a better understanding of the used bounding boxes to fix the glitches that still exist. Patch by frosch.
rubidium
parents:
7545
diff
changeset
|
208 |
* @param dy3 Screen Y-length of third edge. |
af32b07bc027
(svn r11174) -Codechange: add possibility to show the bounding boxes of sprites using CTRL-B so one can get a better understanding of the used bounding boxes to fix the glitches that still exist. Patch by frosch.
rubidium
parents:
7545
diff
changeset
|
209 |
*/ |
af32b07bc027
(svn r11174) -Codechange: add possibility to show the bounding boxes of sprites using CTRL-B so one can get a better understanding of the used bounding boxes to fix the glitches that still exist. Patch by frosch.
rubidium
parents:
7545
diff
changeset
|
210 |
void DrawBox(int x, int y, int dx1, int dy1, int dx2, int dy2, int dx3, int dy3) |
af32b07bc027
(svn r11174) -Codechange: add possibility to show the bounding boxes of sprites using CTRL-B so one can get a better understanding of the used bounding boxes to fix the glitches that still exist. Patch by frosch.
rubidium
parents:
7545
diff
changeset
|
211 |
{ |
af32b07bc027
(svn r11174) -Codechange: add possibility to show the bounding boxes of sprites using CTRL-B so one can get a better understanding of the used bounding boxes to fix the glitches that still exist. Patch by frosch.
rubidium
parents:
7545
diff
changeset
|
212 |
/* .... |
af32b07bc027
(svn r11174) -Codechange: add possibility to show the bounding boxes of sprites using CTRL-B so one can get a better understanding of the used bounding boxes to fix the glitches that still exist. Patch by frosch.
rubidium
parents:
7545
diff
changeset
|
213 |
* .. .... |
af32b07bc027
(svn r11174) -Codechange: add possibility to show the bounding boxes of sprites using CTRL-B so one can get a better understanding of the used bounding boxes to fix the glitches that still exist. Patch by frosch.
rubidium
parents:
7545
diff
changeset
|
214 |
* .. .... |
af32b07bc027
(svn r11174) -Codechange: add possibility to show the bounding boxes of sprites using CTRL-B so one can get a better understanding of the used bounding boxes to fix the glitches that still exist. Patch by frosch.
rubidium
parents:
7545
diff
changeset
|
215 |
* .. ^ |
af32b07bc027
(svn r11174) -Codechange: add possibility to show the bounding boxes of sprites using CTRL-B so one can get a better understanding of the used bounding boxes to fix the glitches that still exist. Patch by frosch.
rubidium
parents:
7545
diff
changeset
|
216 |
* <--__(dx1,dy1) /(dx2,dy2) |
af32b07bc027
(svn r11174) -Codechange: add possibility to show the bounding boxes of sprites using CTRL-B so one can get a better understanding of the used bounding boxes to fix the glitches that still exist. Patch by frosch.
rubidium
parents:
7545
diff
changeset
|
217 |
* : --__ / : |
af32b07bc027
(svn r11174) -Codechange: add possibility to show the bounding boxes of sprites using CTRL-B so one can get a better understanding of the used bounding boxes to fix the glitches that still exist. Patch by frosch.
rubidium
parents:
7545
diff
changeset
|
218 |
* : --__ / : |
af32b07bc027
(svn r11174) -Codechange: add possibility to show the bounding boxes of sprites using CTRL-B so one can get a better understanding of the used bounding boxes to fix the glitches that still exist. Patch by frosch.
rubidium
parents:
7545
diff
changeset
|
219 |
* : *(x,y) : |
af32b07bc027
(svn r11174) -Codechange: add possibility to show the bounding boxes of sprites using CTRL-B so one can get a better understanding of the used bounding boxes to fix the glitches that still exist. Patch by frosch.
rubidium
parents:
7545
diff
changeset
|
220 |
* : | : |
af32b07bc027
(svn r11174) -Codechange: add possibility to show the bounding boxes of sprites using CTRL-B so one can get a better understanding of the used bounding boxes to fix the glitches that still exist. Patch by frosch.
rubidium
parents:
7545
diff
changeset
|
221 |
* : | .. |
af32b07bc027
(svn r11174) -Codechange: add possibility to show the bounding boxes of sprites using CTRL-B so one can get a better understanding of the used bounding boxes to fix the glitches that still exist. Patch by frosch.
rubidium
parents:
7545
diff
changeset
|
222 |
* .... |(dx3,dy3) |
af32b07bc027
(svn r11174) -Codechange: add possibility to show the bounding boxes of sprites using CTRL-B so one can get a better understanding of the used bounding boxes to fix the glitches that still exist. Patch by frosch.
rubidium
parents:
7545
diff
changeset
|
223 |
* .... | .. |
af32b07bc027
(svn r11174) -Codechange: add possibility to show the bounding boxes of sprites using CTRL-B so one can get a better understanding of the used bounding boxes to fix the glitches that still exist. Patch by frosch.
rubidium
parents:
7545
diff
changeset
|
224 |
* ....V. |
af32b07bc027
(svn r11174) -Codechange: add possibility to show the bounding boxes of sprites using CTRL-B so one can get a better understanding of the used bounding boxes to fix the glitches that still exist. Patch by frosch.
rubidium
parents:
7545
diff
changeset
|
225 |
*/ |
af32b07bc027
(svn r11174) -Codechange: add possibility to show the bounding boxes of sprites using CTRL-B so one can get a better understanding of the used bounding boxes to fix the glitches that still exist. Patch by frosch.
rubidium
parents:
7545
diff
changeset
|
226 |
|
af32b07bc027
(svn r11174) -Codechange: add possibility to show the bounding boxes of sprites using CTRL-B so one can get a better understanding of the used bounding boxes to fix the glitches that still exist. Patch by frosch.
rubidium
parents:
7545
diff
changeset
|
227 |
static const byte color = 255; |
af32b07bc027
(svn r11174) -Codechange: add possibility to show the bounding boxes of sprites using CTRL-B so one can get a better understanding of the used bounding boxes to fix the glitches that still exist. Patch by frosch.
rubidium
parents:
7545
diff
changeset
|
228 |
|
7651
99bd9cd9e684
(svn r11182) -Fix [FS#1261] (r11174): bounding boxes caused crashes when zoomed out. Patch by SmatZ.
rubidium
parents:
7643
diff
changeset
|
229 |
GfxDrawLineUnscaled(x, y, x + dx1, y + dy1, color); |
99bd9cd9e684
(svn r11182) -Fix [FS#1261] (r11174): bounding boxes caused crashes when zoomed out. Patch by SmatZ.
rubidium
parents:
7643
diff
changeset
|
230 |
GfxDrawLineUnscaled(x, y, x + dx2, y + dy2, color); |
99bd9cd9e684
(svn r11182) -Fix [FS#1261] (r11174): bounding boxes caused crashes when zoomed out. Patch by SmatZ.
rubidium
parents:
7643
diff
changeset
|
231 |
GfxDrawLineUnscaled(x, y, x + dx3, y + dy3, color); |
7643
af32b07bc027
(svn r11174) -Codechange: add possibility to show the bounding boxes of sprites using CTRL-B so one can get a better understanding of the used bounding boxes to fix the glitches that still exist. Patch by frosch.
rubidium
parents:
7545
diff
changeset
|
232 |
|
7651
99bd9cd9e684
(svn r11182) -Fix [FS#1261] (r11174): bounding boxes caused crashes when zoomed out. Patch by SmatZ.
rubidium
parents:
7643
diff
changeset
|
233 |
GfxDrawLineUnscaled(x + dx1, y + dy1, x + dx1 + dx2, y + dy1 + dy2, color); |
99bd9cd9e684
(svn r11182) -Fix [FS#1261] (r11174): bounding boxes caused crashes when zoomed out. Patch by SmatZ.
rubidium
parents:
7643
diff
changeset
|
234 |
GfxDrawLineUnscaled(x + dx1, y + dy1, x + dx1 + dx3, y + dy1 + dy3, color); |
99bd9cd9e684
(svn r11182) -Fix [FS#1261] (r11174): bounding boxes caused crashes when zoomed out. Patch by SmatZ.
rubidium
parents:
7643
diff
changeset
|
235 |
GfxDrawLineUnscaled(x + dx2, y + dy2, x + dx2 + dx1, y + dy2 + dy1, color); |
99bd9cd9e684
(svn r11182) -Fix [FS#1261] (r11174): bounding boxes caused crashes when zoomed out. Patch by SmatZ.
rubidium
parents:
7643
diff
changeset
|
236 |
GfxDrawLineUnscaled(x + dx2, y + dy2, x + dx2 + dx3, y + dy2 + dy3, color); |
99bd9cd9e684
(svn r11182) -Fix [FS#1261] (r11174): bounding boxes caused crashes when zoomed out. Patch by SmatZ.
rubidium
parents:
7643
diff
changeset
|
237 |
GfxDrawLineUnscaled(x + dx3, y + dy3, x + dx3 + dx1, y + dy3 + dy1, color); |
99bd9cd9e684
(svn r11182) -Fix [FS#1261] (r11174): bounding boxes caused crashes when zoomed out. Patch by SmatZ.
rubidium
parents:
7643
diff
changeset
|
238 |
GfxDrawLineUnscaled(x + dx3, y + dy3, x + dx3 + dx2, y + dy3 + dy2, color); |
7643
af32b07bc027
(svn r11174) -Codechange: add possibility to show the bounding boxes of sprites using CTRL-B so one can get a better understanding of the used bounding boxes to fix the glitches that still exist. Patch by frosch.
rubidium
parents:
7545
diff
changeset
|
239 |
} |
af32b07bc027
(svn r11174) -Codechange: add possibility to show the bounding boxes of sprites using CTRL-B so one can get a better understanding of the used bounding boxes to fix the glitches that still exist. Patch by frosch.
rubidium
parents:
7545
diff
changeset
|
240 |
|
3798
b1f5290b36b1
(svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents:
3797
diff
changeset
|
241 |
|
10248
f0297aac2ff2
(svn r14479) -Add: initial (optional) support for handling bidirectional scripts and connecting Arabic characters.
rubidium
parents:
10056
diff
changeset
|
242 |
#if !defined(WITH_ICU) |
f0297aac2ff2
(svn r14479) -Add: initial (optional) support for handling bidirectional scripts and connecting Arabic characters.
rubidium
parents:
10056
diff
changeset
|
243 |
static void HandleBiDiAndArabicShapes(char *text, const char *lastof) {} |
f0297aac2ff2
(svn r14479) -Add: initial (optional) support for handling bidirectional scripts and connecting Arabic characters.
rubidium
parents:
10056
diff
changeset
|
244 |
#else |
f0297aac2ff2
(svn r14479) -Add: initial (optional) support for handling bidirectional scripts and connecting Arabic characters.
rubidium
parents:
10056
diff
changeset
|
245 |
#include "unicode/ubidi.h" |
f0297aac2ff2
(svn r14479) -Add: initial (optional) support for handling bidirectional scripts and connecting Arabic characters.
rubidium
parents:
10056
diff
changeset
|
246 |
#include "unicode/ushape.h" |
f0297aac2ff2
(svn r14479) -Add: initial (optional) support for handling bidirectional scripts and connecting Arabic characters.
rubidium
parents:
10056
diff
changeset
|
247 |
|
f0297aac2ff2
(svn r14479) -Add: initial (optional) support for handling bidirectional scripts and connecting Arabic characters.
rubidium
parents:
10056
diff
changeset
|
248 |
/** |
f0297aac2ff2
(svn r14479) -Add: initial (optional) support for handling bidirectional scripts and connecting Arabic characters.
rubidium
parents:
10056
diff
changeset
|
249 |
* Function to be able to handle right-to-left text and Arabic chars properly. |
f0297aac2ff2
(svn r14479) -Add: initial (optional) support for handling bidirectional scripts and connecting Arabic characters.
rubidium
parents:
10056
diff
changeset
|
250 |
* |
f0297aac2ff2
(svn r14479) -Add: initial (optional) support for handling bidirectional scripts and connecting Arabic characters.
rubidium
parents:
10056
diff
changeset
|
251 |
* First: right-to-left (RTL) is stored 'logically' in almost all applications |
f0297aac2ff2
(svn r14479) -Add: initial (optional) support for handling bidirectional scripts and connecting Arabic characters.
rubidium
parents:
10056
diff
changeset
|
252 |
* and so do we. This means that their text is stored from right to the |
f0297aac2ff2
(svn r14479) -Add: initial (optional) support for handling bidirectional scripts and connecting Arabic characters.
rubidium
parents:
10056
diff
changeset
|
253 |
* left in memory and any non-RTL text (like numbers or English) are |
f0297aac2ff2
(svn r14479) -Add: initial (optional) support for handling bidirectional scripts and connecting Arabic characters.
rubidium
parents:
10056
diff
changeset
|
254 |
* then stored from left-to-right. When we want to actually draw the |
f0297aac2ff2
(svn r14479) -Add: initial (optional) support for handling bidirectional scripts and connecting Arabic characters.
rubidium
parents:
10056
diff
changeset
|
255 |
* text we need to reverse the RTL text in memory, which is what |
f0297aac2ff2
(svn r14479) -Add: initial (optional) support for handling bidirectional scripts and connecting Arabic characters.
rubidium
parents:
10056
diff
changeset
|
256 |
* happens in ubidi_writeReordered. |
f0297aac2ff2
(svn r14479) -Add: initial (optional) support for handling bidirectional scripts and connecting Arabic characters.
rubidium
parents:
10056
diff
changeset
|
257 |
* Second: Arabic characters "differ" based on their context. To draw the |
f0297aac2ff2
(svn r14479) -Add: initial (optional) support for handling bidirectional scripts and connecting Arabic characters.
rubidium
parents:
10056
diff
changeset
|
258 |
* correct variant we pass it through u_shapeArabic. This function can |
f0297aac2ff2
(svn r14479) -Add: initial (optional) support for handling bidirectional scripts and connecting Arabic characters.
rubidium
parents:
10056
diff
changeset
|
259 |
* add or remove some characters. This is the reason for the lastof |
f0297aac2ff2
(svn r14479) -Add: initial (optional) support for handling bidirectional scripts and connecting Arabic characters.
rubidium
parents:
10056
diff
changeset
|
260 |
* so we know till where we can fill the output. |
f0297aac2ff2
(svn r14479) -Add: initial (optional) support for handling bidirectional scripts and connecting Arabic characters.
rubidium
parents:
10056
diff
changeset
|
261 |
* |
f0297aac2ff2
(svn r14479) -Add: initial (optional) support for handling bidirectional scripts and connecting Arabic characters.
rubidium
parents:
10056
diff
changeset
|
262 |
* Sadly enough these functions work with a custom character format, UChar, |
f0297aac2ff2
(svn r14479) -Add: initial (optional) support for handling bidirectional scripts and connecting Arabic characters.
rubidium
parents:
10056
diff
changeset
|
263 |
* which isn't the same size as WChar. Because of that we need to transform |
f0297aac2ff2
(svn r14479) -Add: initial (optional) support for handling bidirectional scripts and connecting Arabic characters.
rubidium
parents:
10056
diff
changeset
|
264 |
* our text first to UChars and then back to something we can use. |
f0297aac2ff2
(svn r14479) -Add: initial (optional) support for handling bidirectional scripts and connecting Arabic characters.
rubidium
parents:
10056
diff
changeset
|
265 |
* |
f0297aac2ff2
(svn r14479) -Add: initial (optional) support for handling bidirectional scripts and connecting Arabic characters.
rubidium
parents:
10056
diff
changeset
|
266 |
* To be able to truncate strings properly you must truncate before passing to |
f0297aac2ff2
(svn r14479) -Add: initial (optional) support for handling bidirectional scripts and connecting Arabic characters.
rubidium
parents:
10056
diff
changeset
|
267 |
* this function. This way the logical begin of the string remains and the end |
f0297aac2ff2
(svn r14479) -Add: initial (optional) support for handling bidirectional scripts and connecting Arabic characters.
rubidium
parents:
10056
diff
changeset
|
268 |
* gets chopped of instead of the other way around. |
f0297aac2ff2
(svn r14479) -Add: initial (optional) support for handling bidirectional scripts and connecting Arabic characters.
rubidium
parents:
10056
diff
changeset
|
269 |
* |
f0297aac2ff2
(svn r14479) -Add: initial (optional) support for handling bidirectional scripts and connecting Arabic characters.
rubidium
parents:
10056
diff
changeset
|
270 |
* The reshaping of Arabic characters might increase or decrease the width of |
f0297aac2ff2
(svn r14479) -Add: initial (optional) support for handling bidirectional scripts and connecting Arabic characters.
rubidium
parents:
10056
diff
changeset
|
271 |
* the characters/string. So it might still overflow after truncation, though |
f0297aac2ff2
(svn r14479) -Add: initial (optional) support for handling bidirectional scripts and connecting Arabic characters.
rubidium
parents:
10056
diff
changeset
|
272 |
* the chance is fairly slim as most characters get shorter instead of longer. |
f0297aac2ff2
(svn r14479) -Add: initial (optional) support for handling bidirectional scripts and connecting Arabic characters.
rubidium
parents:
10056
diff
changeset
|
273 |
* @param buffer the buffer to read from/to |
f0297aac2ff2
(svn r14479) -Add: initial (optional) support for handling bidirectional scripts and connecting Arabic characters.
rubidium
parents:
10056
diff
changeset
|
274 |
* @param lastof the end of the buffer |
f0297aac2ff2
(svn r14479) -Add: initial (optional) support for handling bidirectional scripts and connecting Arabic characters.
rubidium
parents:
10056
diff
changeset
|
275 |
*/ |
f0297aac2ff2
(svn r14479) -Add: initial (optional) support for handling bidirectional scripts and connecting Arabic characters.
rubidium
parents:
10056
diff
changeset
|
276 |
static void HandleBiDiAndArabicShapes(char *buffer, const char *lastof) |
f0297aac2ff2
(svn r14479) -Add: initial (optional) support for handling bidirectional scripts and connecting Arabic characters.
rubidium
parents:
10056
diff
changeset
|
277 |
{ |
f0297aac2ff2
(svn r14479) -Add: initial (optional) support for handling bidirectional scripts and connecting Arabic characters.
rubidium
parents:
10056
diff
changeset
|
278 |
UChar input_output[DRAW_STRING_BUFFER]; |
f0297aac2ff2
(svn r14479) -Add: initial (optional) support for handling bidirectional scripts and connecting Arabic characters.
rubidium
parents:
10056
diff
changeset
|
279 |
UChar intermediate[DRAW_STRING_BUFFER]; |
f0297aac2ff2
(svn r14479) -Add: initial (optional) support for handling bidirectional scripts and connecting Arabic characters.
rubidium
parents:
10056
diff
changeset
|
280 |
|
f0297aac2ff2
(svn r14479) -Add: initial (optional) support for handling bidirectional scripts and connecting Arabic characters.
rubidium
parents:
10056
diff
changeset
|
281 |
char *t = buffer; |
f0297aac2ff2
(svn r14479) -Add: initial (optional) support for handling bidirectional scripts and connecting Arabic characters.
rubidium
parents:
10056
diff
changeset
|
282 |
size_t length = 0; |
f0297aac2ff2
(svn r14479) -Add: initial (optional) support for handling bidirectional scripts and connecting Arabic characters.
rubidium
parents:
10056
diff
changeset
|
283 |
while (*t != '\0' && length < lengthof(input_output)) { |
f0297aac2ff2
(svn r14479) -Add: initial (optional) support for handling bidirectional scripts and connecting Arabic characters.
rubidium
parents:
10056
diff
changeset
|
284 |
WChar tmp; |
f0297aac2ff2
(svn r14479) -Add: initial (optional) support for handling bidirectional scripts and connecting Arabic characters.
rubidium
parents:
10056
diff
changeset
|
285 |
t += Utf8Decode(&tmp, t); |
f0297aac2ff2
(svn r14479) -Add: initial (optional) support for handling bidirectional scripts and connecting Arabic characters.
rubidium
parents:
10056
diff
changeset
|
286 |
input_output[length++] = tmp; |
f0297aac2ff2
(svn r14479) -Add: initial (optional) support for handling bidirectional scripts and connecting Arabic characters.
rubidium
parents:
10056
diff
changeset
|
287 |
} |
f0297aac2ff2
(svn r14479) -Add: initial (optional) support for handling bidirectional scripts and connecting Arabic characters.
rubidium
parents:
10056
diff
changeset
|
288 |
input_output[length] = 0; |
f0297aac2ff2
(svn r14479) -Add: initial (optional) support for handling bidirectional scripts and connecting Arabic characters.
rubidium
parents:
10056
diff
changeset
|
289 |
|
f0297aac2ff2
(svn r14479) -Add: initial (optional) support for handling bidirectional scripts and connecting Arabic characters.
rubidium
parents:
10056
diff
changeset
|
290 |
UErrorCode err = U_ZERO_ERROR; |
10263 | 291 |
UBiDi *para = ubidi_openSized((int32_t)length, 0, &err); |
10248
f0297aac2ff2
(svn r14479) -Add: initial (optional) support for handling bidirectional scripts and connecting Arabic characters.
rubidium
parents:
10056
diff
changeset
|
292 |
if (para == NULL) return; |
f0297aac2ff2
(svn r14479) -Add: initial (optional) support for handling bidirectional scripts and connecting Arabic characters.
rubidium
parents:
10056
diff
changeset
|
293 |
|
10278
ca32d210119d
(svn r14516) -Fix: determine the default text direction based on the language file instead of hardcoding one.
rubidium
parents:
10263
diff
changeset
|
294 |
ubidi_setPara(para, input_output, (int32_t)length, _dynlang.text_dir == TD_RTL ? UBIDI_DEFAULT_RTL : UBIDI_DEFAULT_LTR, NULL, &err); |
10263 | 295 |
ubidi_writeReordered(para, intermediate, (int32_t)length, 0, &err); |
296 |
length = u_shapeArabic(intermediate, (int32_t)length, input_output, lengthof(input_output), U_SHAPE_TEXT_DIRECTION_VISUAL_LTR | U_SHAPE_LETTERS_SHAPE, &err); |
|
10248
f0297aac2ff2
(svn r14479) -Add: initial (optional) support for handling bidirectional scripts and connecting Arabic characters.
rubidium
parents:
10056
diff
changeset
|
297 |
ubidi_close(para); |
f0297aac2ff2
(svn r14479) -Add: initial (optional) support for handling bidirectional scripts and connecting Arabic characters.
rubidium
parents:
10056
diff
changeset
|
298 |
|
f0297aac2ff2
(svn r14479) -Add: initial (optional) support for handling bidirectional scripts and connecting Arabic characters.
rubidium
parents:
10056
diff
changeset
|
299 |
if (U_FAILURE(err)) return; |
f0297aac2ff2
(svn r14479) -Add: initial (optional) support for handling bidirectional scripts and connecting Arabic characters.
rubidium
parents:
10056
diff
changeset
|
300 |
|
f0297aac2ff2
(svn r14479) -Add: initial (optional) support for handling bidirectional scripts and connecting Arabic characters.
rubidium
parents:
10056
diff
changeset
|
301 |
t = buffer; |
f0297aac2ff2
(svn r14479) -Add: initial (optional) support for handling bidirectional scripts and connecting Arabic characters.
rubidium
parents:
10056
diff
changeset
|
302 |
for (size_t i = 0; i < length && t < (lastof - 4); i++) { |
f0297aac2ff2
(svn r14479) -Add: initial (optional) support for handling bidirectional scripts and connecting Arabic characters.
rubidium
parents:
10056
diff
changeset
|
303 |
t += Utf8Encode(t, input_output[i]); |
f0297aac2ff2
(svn r14479) -Add: initial (optional) support for handling bidirectional scripts and connecting Arabic characters.
rubidium
parents:
10056
diff
changeset
|
304 |
} |
f0297aac2ff2
(svn r14479) -Add: initial (optional) support for handling bidirectional scripts and connecting Arabic characters.
rubidium
parents:
10056
diff
changeset
|
305 |
*t = '\0'; |
f0297aac2ff2
(svn r14479) -Add: initial (optional) support for handling bidirectional scripts and connecting Arabic characters.
rubidium
parents:
10056
diff
changeset
|
306 |
} |
f0297aac2ff2
(svn r14479) -Add: initial (optional) support for handling bidirectional scripts and connecting Arabic characters.
rubidium
parents:
10056
diff
changeset
|
307 |
#endif /* WITH_ICU */ |
f0297aac2ff2
(svn r14479) -Add: initial (optional) support for handling bidirectional scripts and connecting Arabic characters.
rubidium
parents:
10056
diff
changeset
|
308 |
|
f0297aac2ff2
(svn r14479) -Add: initial (optional) support for handling bidirectional scripts and connecting Arabic characters.
rubidium
parents:
10056
diff
changeset
|
309 |
|
2097
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
310 |
/** Truncate a given string to a maximum width if neccessary. |
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
311 |
* If the string is truncated, add three dots ('...') to show this. |
6481
85ad87daf4b0
(svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas
parents:
6478
diff
changeset
|
312 |
* @param *str string that is checked and possibly truncated |
2097
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
313 |
* @param maxw maximum width in pixels of the string |
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
314 |
* @return new width of (truncated) string */ |
2113
be2f07df0dfa
(svn r2623) - CodeChange: rework DrawStringCenteredTruncated() a bit. Instead of giving center + width you give the coordinates of the bounding box (left, right) it has to fit in (ludde)
Darkvater
parents:
2107
diff
changeset
|
315 |
static int TruncateString(char *str, int maxw) |
2097
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
316 |
{ |
2113
be2f07df0dfa
(svn r2623) - CodeChange: rework DrawStringCenteredTruncated() a bit. Instead of giving center + width you give the coordinates of the bounding box (left, right) it has to fit in (ludde)
Darkvater
parents:
2107
diff
changeset
|
317 |
int w = 0; |
3798
b1f5290b36b1
(svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents:
3797
diff
changeset
|
318 |
FontSize size = _cur_fontsize; |
2097
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
319 |
int ddd, ddd_w; |
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
320 |
|
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
321 |
WChar c; |
2097
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
322 |
char *ddd_pos; |
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
323 |
|
3798
b1f5290b36b1
(svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents:
3797
diff
changeset
|
324 |
ddd_w = ddd = GetCharacterWidth(size, '.') * 3; |
2097
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
325 |
|
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
326 |
for (ddd_pos = str; (c = Utf8Consume((const char **)&str)) != '\0'; ) { |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
327 |
if (IsPrintable(c)) { |
3798
b1f5290b36b1
(svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents:
3797
diff
changeset
|
328 |
w += GetCharacterWidth(size, c); |
2097
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
329 |
|
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
330 |
if (w >= maxw) { |
9637
4af6001e7fee
(svn r13700) -Fix: possible buffer overflow in string truncation code.
rubidium
parents:
9636
diff
changeset
|
331 |
/* string got too big... insert dotdotdot, but make sure we do not |
4af6001e7fee
(svn r13700) -Fix: possible buffer overflow in string truncation code.
rubidium
parents:
9636
diff
changeset
|
332 |
* print anything beyond the string termination character. */ |
4af6001e7fee
(svn r13700) -Fix: possible buffer overflow in string truncation code.
rubidium
parents:
9636
diff
changeset
|
333 |
for (int i = 0; *ddd_pos != '\0' && i < 3; i++, ddd_pos++) *ddd_pos = '.'; |
4af6001e7fee
(svn r13700) -Fix: possible buffer overflow in string truncation code.
rubidium
parents:
9636
diff
changeset
|
334 |
*ddd_pos = '\0'; |
2097
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
335 |
return ddd_w; |
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
336 |
} |
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
337 |
} else { |
9636
a70cb623e3e7
(svn r13699) -Fix: handle SETX(Y) properly when truncating a string instead of ignoring it and returning a too long string.
rubidium
parents:
9607
diff
changeset
|
338 |
if (c == SCC_SETX) { |
a70cb623e3e7
(svn r13699) -Fix: handle SETX(Y) properly when truncating a string instead of ignoring it and returning a too long string.
rubidium
parents:
9607
diff
changeset
|
339 |
w = *str; |
a70cb623e3e7
(svn r13699) -Fix: handle SETX(Y) properly when truncating a string instead of ignoring it and returning a too long string.
rubidium
parents:
9607
diff
changeset
|
340 |
str++; |
a70cb623e3e7
(svn r13699) -Fix: handle SETX(Y) properly when truncating a string instead of ignoring it and returning a too long string.
rubidium
parents:
9607
diff
changeset
|
341 |
} else if (c == SCC_SETXY) { |
a70cb623e3e7
(svn r13699) -Fix: handle SETX(Y) properly when truncating a string instead of ignoring it and returning a too long string.
rubidium
parents:
9607
diff
changeset
|
342 |
w = *str; |
a70cb623e3e7
(svn r13699) -Fix: handle SETX(Y) properly when truncating a string instead of ignoring it and returning a too long string.
rubidium
parents:
9607
diff
changeset
|
343 |
str += 2; |
a70cb623e3e7
(svn r13699) -Fix: handle SETX(Y) properly when truncating a string instead of ignoring it and returning a too long string.
rubidium
parents:
9607
diff
changeset
|
344 |
} else if (c == SCC_TINYFONT) { |
3798
b1f5290b36b1
(svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents:
3797
diff
changeset
|
345 |
size = FS_SMALL; |
b1f5290b36b1
(svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents:
3797
diff
changeset
|
346 |
ddd = GetCharacterWidth(size, '.') * 3; |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
347 |
} else if (c == SCC_BIGFONT) { |
3798
b1f5290b36b1
(svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents:
3797
diff
changeset
|
348 |
size = FS_LARGE; |
b1f5290b36b1
(svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents:
3797
diff
changeset
|
349 |
ddd = GetCharacterWidth(size, '.') * 3; |
2097
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
350 |
} |
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
351 |
} |
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
352 |
|
6179
d19b0137d8e4
(svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6138
diff
changeset
|
353 |
/* Remember the last position where three dots fit. */ |
2097
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
354 |
if (w + ddd < maxw) { |
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
355 |
ddd_w = w + ddd; |
2113
be2f07df0dfa
(svn r2623) - CodeChange: rework DrawStringCenteredTruncated() a bit. Instead of giving center + width you give the coordinates of the bounding box (left, right) it has to fit in (ludde)
Darkvater
parents:
2107
diff
changeset
|
356 |
ddd_pos = str; |
2097
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
357 |
} |
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
358 |
} |
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
359 |
|
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
360 |
return w; |
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
361 |
} |
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
362 |
|
9773
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
363 |
/** |
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
364 |
* Write string to output buffer, truncating it to specified maximal width in pixels if it is too long. |
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
365 |
* |
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
366 |
* @param src String to truncate |
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
367 |
* @param dest Start of character output buffer where truncated string is stored |
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
368 |
* @param maxw Maximal allowed length of the string in pixels |
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
369 |
* @param last Address of last character in output buffer |
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
370 |
* |
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
371 |
* @return Actual width of the (possibly) truncated string in pixels |
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
372 |
*/ |
4912
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4819
diff
changeset
|
373 |
static inline int TruncateStringID(StringID src, char *dest, int maxw, const char* last) |
2097
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
374 |
{ |
4912
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4819
diff
changeset
|
375 |
GetString(dest, src, last); |
2097
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
376 |
return TruncateString(dest, maxw); |
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
377 |
} |
0 | 378 |
|
9773
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
379 |
/** |
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
380 |
* Draw string starting at position (x,y). |
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
381 |
* |
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
382 |
* @param x X position to start drawing |
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
383 |
* @param y Y position to start drawing |
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
384 |
* @param str String to draw |
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
385 |
* @param color Color used for drawing the string, see DoDrawString() for details |
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
386 |
* |
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
387 |
* @return Horizontal coordinate after drawing the string |
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
388 |
*/ |
2097
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
389 |
int DrawString(int x, int y, StringID str, uint16 color) |
0 | 390 |
{ |
9901
602720bd2d53
(svn r14051) -Codechange: enumify the DrawString buffer length.
rubidium
parents:
9900
diff
changeset
|
391 |
char buffer[DRAW_STRING_BUFFER]; |
1336
69391734ce23
(svn r1840) Repel str_buffr and use local buffers where possible
tron
parents:
1323
diff
changeset
|
392 |
|
4912
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4819
diff
changeset
|
393 |
GetString(buffer, str, lastof(buffer)); |
10248
f0297aac2ff2
(svn r14479) -Add: initial (optional) support for handling bidirectional scripts and connecting Arabic characters.
rubidium
parents:
10056
diff
changeset
|
394 |
HandleBiDiAndArabicShapes(buffer, lastof(buffer)); |
f0297aac2ff2
(svn r14479) -Add: initial (optional) support for handling bidirectional scripts and connecting Arabic characters.
rubidium
parents:
10056
diff
changeset
|
395 |
return ReallyDoDrawString(buffer, x, y, color); |
0 | 396 |
} |
397 |
||
9773
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
398 |
/** |
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
399 |
* Draw string, possibly truncated to make it fit in its allocated space |
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
400 |
* |
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
401 |
* @param x X position to start drawing |
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
402 |
* @param y Y position to start drawing |
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
403 |
* @param str String to draw |
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
404 |
* @param color Color used for drawing the string, see DoDrawString() for details |
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
405 |
* @param maxw Maximal width of the string |
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
406 |
* |
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
407 |
* @return Horizontal coordinate after drawing the (possibly truncated) string |
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
408 |
*/ |
2097
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
409 |
int DrawStringTruncated(int x, int y, StringID str, uint16 color, uint maxw) |
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
410 |
{ |
9901
602720bd2d53
(svn r14051) -Codechange: enumify the DrawString buffer length.
rubidium
parents:
9900
diff
changeset
|
411 |
char buffer[DRAW_STRING_BUFFER]; |
4912
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4819
diff
changeset
|
412 |
TruncateStringID(str, buffer, maxw, lastof(buffer)); |
10248
f0297aac2ff2
(svn r14479) -Add: initial (optional) support for handling bidirectional scripts and connecting Arabic characters.
rubidium
parents:
10056
diff
changeset
|
413 |
HandleBiDiAndArabicShapes(buffer, lastof(buffer)); |
f0297aac2ff2
(svn r14479) -Add: initial (optional) support for handling bidirectional scripts and connecting Arabic characters.
rubidium
parents:
10056
diff
changeset
|
414 |
return ReallyDoDrawString(buffer, x, y, color); |
2097
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
415 |
} |
0 | 416 |
|
9773
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
417 |
/** |
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
418 |
* Draw string right-aligned. |
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
419 |
* |
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
420 |
* @param x Right-most x position of the string |
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
421 |
* @param y Y position of the string |
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
422 |
* @param str String to draw |
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
423 |
* @param color Color used for drawing the string, see DoDrawString() for details |
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
424 |
* |
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
425 |
* @return Width of drawn string in pixels |
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
426 |
*/ |
4314
5c816195d9d4
(svn r5967) -Change: use right alignment for the year in the player's balance window instead of centering (about) 'string width' / 2 from the right edge
rubidium
parents:
4300
diff
changeset
|
427 |
int DrawStringRightAligned(int x, int y, StringID str, uint16 color) |
0 | 428 |
{ |
9901
602720bd2d53
(svn r14051) -Codechange: enumify the DrawString buffer length.
rubidium
parents:
9900
diff
changeset
|
429 |
char buffer[DRAW_STRING_BUFFER]; |
4314
5c816195d9d4
(svn r5967) -Change: use right alignment for the year in the player's balance window instead of centering (about) 'string width' / 2 from the right edge
rubidium
parents:
4300
diff
changeset
|
430 |
int w; |
1336
69391734ce23
(svn r1840) Repel str_buffr and use local buffers where possible
tron
parents:
1323
diff
changeset
|
431 |
|
4912
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4819
diff
changeset
|
432 |
GetString(buffer, str, lastof(buffer)); |
10248
f0297aac2ff2
(svn r14479) -Add: initial (optional) support for handling bidirectional scripts and connecting Arabic characters.
rubidium
parents:
10056
diff
changeset
|
433 |
HandleBiDiAndArabicShapes(buffer, lastof(buffer)); |
f0297aac2ff2
(svn r14479) -Add: initial (optional) support for handling bidirectional scripts and connecting Arabic characters.
rubidium
parents:
10056
diff
changeset
|
434 |
|
4609
954fe701062f
(svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents:
4557
diff
changeset
|
435 |
w = GetStringBoundingBox(buffer).width; |
10248
f0297aac2ff2
(svn r14479) -Add: initial (optional) support for handling bidirectional scripts and connecting Arabic characters.
rubidium
parents:
10056
diff
changeset
|
436 |
ReallyDoDrawString(buffer, x - w, y, color); |
4314
5c816195d9d4
(svn r5967) -Change: use right alignment for the year in the player's balance window instead of centering (about) 'string width' / 2 from the right edge
rubidium
parents:
4300
diff
changeset
|
437 |
|
5c816195d9d4
(svn r5967) -Change: use right alignment for the year in the player's balance window instead of centering (about) 'string width' / 2 from the right edge
rubidium
parents:
4300
diff
changeset
|
438 |
return w; |
0 | 439 |
} |
440 |
||
9773
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
441 |
/** |
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
442 |
* Draw string right-aligned, possibly truncated to make it fit in its allocated space |
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
443 |
* |
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
444 |
* @param x Right-most x position to start drawing |
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
445 |
* @param y Y position to start drawing |
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
446 |
* @param str String to draw |
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
447 |
* @param color Color used for drawing the string, see DoDrawString() for details |
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
448 |
* @param maxw Maximal width of the string |
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
449 |
*/ |
2097
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
450 |
void DrawStringRightAlignedTruncated(int x, int y, StringID str, uint16 color, uint maxw) |
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
451 |
{ |
9901
602720bd2d53
(svn r14051) -Codechange: enumify the DrawString buffer length.
rubidium
parents:
9900
diff
changeset
|
452 |
char buffer[DRAW_STRING_BUFFER]; |
0 | 453 |
|
4912
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4819
diff
changeset
|
454 |
TruncateStringID(str, buffer, maxw, lastof(buffer)); |
10248
f0297aac2ff2
(svn r14479) -Add: initial (optional) support for handling bidirectional scripts and connecting Arabic characters.
rubidium
parents:
10056
diff
changeset
|
455 |
HandleBiDiAndArabicShapes(buffer, lastof(buffer)); |
f0297aac2ff2
(svn r14479) -Add: initial (optional) support for handling bidirectional scripts and connecting Arabic characters.
rubidium
parents:
10056
diff
changeset
|
456 |
ReallyDoDrawString(buffer, x - GetStringBoundingBox(buffer).width, y, color); |
2097
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
457 |
} |
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
458 |
|
9773
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
459 |
/** |
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
460 |
* Draw string right-aligned with a line underneath it. |
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
461 |
* |
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
462 |
* @param x Right-most x position of the string |
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
463 |
* @param y Y position of the string |
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
464 |
* @param str String to draw |
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
465 |
* @param color Color used for drawing the string, see DoDrawString() for details |
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
466 |
*/ |
4314
5c816195d9d4
(svn r5967) -Change: use right alignment for the year in the player's balance window instead of centering (about) 'string width' / 2 from the right edge
rubidium
parents:
4300
diff
changeset
|
467 |
void DrawStringRightAlignedUnderline(int x, int y, StringID str, uint16 color) |
5c816195d9d4
(svn r5967) -Change: use right alignment for the year in the player's balance window instead of centering (about) 'string width' / 2 from the right edge
rubidium
parents:
4300
diff
changeset
|
468 |
{ |
5c816195d9d4
(svn r5967) -Change: use right alignment for the year in the player's balance window instead of centering (about) 'string width' / 2 from the right edge
rubidium
parents:
4300
diff
changeset
|
469 |
int w = DrawStringRightAligned(x, y, str, color); |
5c816195d9d4
(svn r5967) -Change: use right alignment for the year in the player's balance window instead of centering (about) 'string width' / 2 from the right edge
rubidium
parents:
4300
diff
changeset
|
470 |
GfxFillRect(x - w, y + 10, x, y + 10, _string_colorremap[1]); |
5c816195d9d4
(svn r5967) -Change: use right alignment for the year in the player's balance window instead of centering (about) 'string width' / 2 from the right edge
rubidium
parents:
4300
diff
changeset
|
471 |
} |
5c816195d9d4
(svn r5967) -Change: use right alignment for the year in the player's balance window instead of centering (about) 'string width' / 2 from the right edge
rubidium
parents:
4300
diff
changeset
|
472 |
|
9773
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
473 |
/** |
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
474 |
* Draw string centered. |
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
475 |
* |
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
476 |
* @param x X position of center of the string |
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
477 |
* @param y Y position of center of the string |
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
478 |
* @param str String to draw |
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
479 |
* @param color Color used for drawing the string, see DoDrawString() for details |
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
480 |
* |
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
481 |
* @return Width of the drawn string in pixels |
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
482 |
*/ |
2097
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
483 |
int DrawStringCentered(int x, int y, StringID str, uint16 color) |
0 | 484 |
{ |
9901
602720bd2d53
(svn r14051) -Codechange: enumify the DrawString buffer length.
rubidium
parents:
9900
diff
changeset
|
485 |
char buffer[DRAW_STRING_BUFFER]; |
0 | 486 |
int w; |
487 |
||
4912
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4819
diff
changeset
|
488 |
GetString(buffer, str, lastof(buffer)); |
10248
f0297aac2ff2
(svn r14479) -Add: initial (optional) support for handling bidirectional scripts and connecting Arabic characters.
rubidium
parents:
10056
diff
changeset
|
489 |
HandleBiDiAndArabicShapes(buffer, lastof(buffer)); |
0 | 490 |
|
4609
954fe701062f
(svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents:
4557
diff
changeset
|
491 |
w = GetStringBoundingBox(buffer).width; |
10248
f0297aac2ff2
(svn r14479) -Add: initial (optional) support for handling bidirectional scripts and connecting Arabic characters.
rubidium
parents:
10056
diff
changeset
|
492 |
ReallyDoDrawString(buffer, x - w / 2, y, color); |
0 | 493 |
|
494 |
return w; |
|
495 |
} |
|
496 |
||
9773
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
497 |
/** |
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
498 |
* Draw string centered, possibly truncated to fit in the assigned space. |
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
499 |
* |
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
500 |
* @param xl Left-most x position |
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
501 |
* @param xr Right-most x position |
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
502 |
* @param y Y position of the string |
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
503 |
* @param str String to draw |
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
504 |
* @param color Color used for drawing the string, see DoDrawString() for details |
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
505 |
* |
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
506 |
* @return Right-most coordinate of the (possibly truncated) drawn string |
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
507 |
*/ |
2113
be2f07df0dfa
(svn r2623) - CodeChange: rework DrawStringCenteredTruncated() a bit. Instead of giving center + width you give the coordinates of the bounding box (left, right) it has to fit in (ludde)
Darkvater
parents:
2107
diff
changeset
|
508 |
int DrawStringCenteredTruncated(int xl, int xr, int y, StringID str, uint16 color) |
2097
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
509 |
{ |
9901
602720bd2d53
(svn r14051) -Codechange: enumify the DrawString buffer length.
rubidium
parents:
9900
diff
changeset
|
510 |
char buffer[DRAW_STRING_BUFFER]; |
10248
f0297aac2ff2
(svn r14479) -Add: initial (optional) support for handling bidirectional scripts and connecting Arabic characters.
rubidium
parents:
10056
diff
changeset
|
511 |
TruncateStringID(str, buffer, xr - xl, lastof(buffer)); |
f0297aac2ff2
(svn r14479) -Add: initial (optional) support for handling bidirectional scripts and connecting Arabic characters.
rubidium
parents:
10056
diff
changeset
|
512 |
HandleBiDiAndArabicShapes(buffer, lastof(buffer)); |
f0297aac2ff2
(svn r14479) -Add: initial (optional) support for handling bidirectional scripts and connecting Arabic characters.
rubidium
parents:
10056
diff
changeset
|
513 |
|
f0297aac2ff2
(svn r14479) -Add: initial (optional) support for handling bidirectional scripts and connecting Arabic characters.
rubidium
parents:
10056
diff
changeset
|
514 |
int w = GetStringBoundingBox(buffer).width; |
f0297aac2ff2
(svn r14479) -Add: initial (optional) support for handling bidirectional scripts and connecting Arabic characters.
rubidium
parents:
10056
diff
changeset
|
515 |
return ReallyDoDrawString(buffer, (xl + xr - w) / 2, y, color); |
2097
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
516 |
} |
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
517 |
|
9773
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
518 |
/** |
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
519 |
* Draw string centered. |
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
520 |
* |
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
521 |
* @param x X position of center of the string |
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
522 |
* @param y Y position of center of the string |
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
523 |
* @param str String to draw |
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
524 |
* @param color Color used for drawing the string, see DoDrawString() for details |
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
525 |
* |
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
526 |
* @return Width of the drawn string in pixels |
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
527 |
*/ |
2134 | 528 |
int DoDrawStringCentered(int x, int y, const char *str, uint16 color) |
529 |
{ |
|
10248
f0297aac2ff2
(svn r14479) -Add: initial (optional) support for handling bidirectional scripts and connecting Arabic characters.
rubidium
parents:
10056
diff
changeset
|
530 |
char buffer[DRAW_STRING_BUFFER]; |
f0297aac2ff2
(svn r14479) -Add: initial (optional) support for handling bidirectional scripts and connecting Arabic characters.
rubidium
parents:
10056
diff
changeset
|
531 |
strecpy(buffer, str, lastof(buffer)); |
f0297aac2ff2
(svn r14479) -Add: initial (optional) support for handling bidirectional scripts and connecting Arabic characters.
rubidium
parents:
10056
diff
changeset
|
532 |
HandleBiDiAndArabicShapes(buffer, lastof(buffer)); |
f0297aac2ff2
(svn r14479) -Add: initial (optional) support for handling bidirectional scripts and connecting Arabic characters.
rubidium
parents:
10056
diff
changeset
|
533 |
|
f0297aac2ff2
(svn r14479) -Add: initial (optional) support for handling bidirectional scripts and connecting Arabic characters.
rubidium
parents:
10056
diff
changeset
|
534 |
int w = GetStringBoundingBox(buffer).width; |
f0297aac2ff2
(svn r14479) -Add: initial (optional) support for handling bidirectional scripts and connecting Arabic characters.
rubidium
parents:
10056
diff
changeset
|
535 |
ReallyDoDrawString(buffer, x - w / 2, y, color); |
2134 | 536 |
return w; |
537 |
} |
|
538 |
||
9773
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
539 |
/** |
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
540 |
* Draw string centered, with additional line underneath it |
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
541 |
* |
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
542 |
* @param x X position of center of the string |
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
543 |
* @param y Y position of center of the string |
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
544 |
* @param str String to draw |
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
545 |
* @param color Color used for drawing the string, see DoDrawString() for details |
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
546 |
*/ |
2097
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
547 |
void DrawStringCenterUnderline(int x, int y, StringID str, uint16 color) |
0 | 548 |
{ |
549 |
int w = DrawStringCentered(x, y, str, color); |
|
2010 | 550 |
GfxFillRect(x - (w >> 1), y + 10, x - (w >> 1) + w, y + 10, _string_colorremap[1]); |
0 | 551 |
} |
552 |
||
9773
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
553 |
/** |
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
554 |
* Draw string centered possibly truncated, with additional line underneath it |
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
555 |
* |
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
556 |
* @param xl Left x position of the string |
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
557 |
* @param xr Right x position of the string |
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
558 |
* @param y Y position of center of the string |
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
559 |
* @param str String to draw |
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
560 |
* @param color Color used for drawing the string, see DoDrawString() for details |
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
561 |
*/ |
2113
be2f07df0dfa
(svn r2623) - CodeChange: rework DrawStringCenteredTruncated() a bit. Instead of giving center + width you give the coordinates of the bounding box (left, right) it has to fit in (ludde)
Darkvater
parents:
2107
diff
changeset
|
562 |
void DrawStringCenterUnderlineTruncated(int xl, int xr, int y, StringID str, uint16 color) |
2097
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
563 |
{ |
2113
be2f07df0dfa
(svn r2623) - CodeChange: rework DrawStringCenteredTruncated() a bit. Instead of giving center + width you give the coordinates of the bounding box (left, right) it has to fit in (ludde)
Darkvater
parents:
2107
diff
changeset
|
564 |
int w = DrawStringCenteredTruncated(xl, xr, y, str, color); |
be2f07df0dfa
(svn r2623) - CodeChange: rework DrawStringCenteredTruncated() a bit. Instead of giving center + width you give the coordinates of the bounding box (left, right) it has to fit in (ludde)
Darkvater
parents:
2107
diff
changeset
|
565 |
GfxFillRect((xl + xr - w) / 2, y + 10, (xl + xr + w) / 2, y + 10, _string_colorremap[1]); |
2097
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
566 |
} |
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
567 |
|
7545
d44e19c5671e
(svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents:
7454
diff
changeset
|
568 |
/** |
d44e19c5671e
(svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents:
7454
diff
changeset
|
569 |
* 'Correct' a string to a maximum length. Longer strings will be cut into |
4954
c1f059faa899
(svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents:
4949
diff
changeset
|
570 |
* additional lines at whitespace characters if possible. The string parameter |
c1f059faa899
(svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents:
4949
diff
changeset
|
571 |
* is modified with terminating characters mid-string which are the |
6481
85ad87daf4b0
(svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas
parents:
6478
diff
changeset
|
572 |
* placeholders for the newlines. |
4954
c1f059faa899
(svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents:
4949
diff
changeset
|
573 |
* The string WILL be truncated if there was no whitespace for the current |
c1f059faa899
(svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents:
4949
diff
changeset
|
574 |
* line's maximum width. |
c1f059faa899
(svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents:
4949
diff
changeset
|
575 |
* |
6481
85ad87daf4b0
(svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas
parents:
6478
diff
changeset
|
576 |
* @note To know if the terminating '\0' is the string end or just a |
4954
c1f059faa899
(svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents:
4949
diff
changeset
|
577 |
* newline, the returned 'num' value should be consulted. The num'th '\0', |
c1f059faa899
(svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents:
4949
diff
changeset
|
578 |
* starting with index 0 is the real string end. |
c1f059faa899
(svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents:
4949
diff
changeset
|
579 |
* |
c1f059faa899
(svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents:
4949
diff
changeset
|
580 |
* @param str string to check and correct for length restrictions |
c1f059faa899
(svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents:
4949
diff
changeset
|
581 |
* @param maxw the maximum width the string can have on one line |
c1f059faa899
(svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents:
4949
diff
changeset
|
582 |
* @return return a 32bit wide number consisting of 2 packed values: |
c1f059faa899
(svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents:
4949
diff
changeset
|
583 |
* 0 - 15 the number of lines ADDED to the string |
7545
d44e19c5671e
(svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents:
7454
diff
changeset
|
584 |
* 16 - 31 the fontsize in which the length calculation was done at |
d44e19c5671e
(svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents:
7454
diff
changeset
|
585 |
*/ |
4954
c1f059faa899
(svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents:
4949
diff
changeset
|
586 |
uint32 FormatStringLinebreaks(char *str, int maxw) |
1095 | 587 |
{ |
4954
c1f059faa899
(svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents:
4949
diff
changeset
|
588 |
FontSize size = _cur_fontsize; |
0 | 589 |
int num = 0; |
4954
c1f059faa899
(svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents:
4949
diff
changeset
|
590 |
|
c1f059faa899
(svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents:
4949
diff
changeset
|
591 |
assert(maxw > 0); |
0 | 592 |
|
2952 | 593 |
for (;;) { |
4954
c1f059faa899
(svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents:
4949
diff
changeset
|
594 |
char *last_space = NULL; |
c1f059faa899
(svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents:
4949
diff
changeset
|
595 |
int w = 0; |
0 | 596 |
|
2952 | 597 |
for (;;) { |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
598 |
WChar c = Utf8Consume((const char **)&str); |
4954
c1f059faa899
(svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents:
4949
diff
changeset
|
599 |
/* whitespace is where we will insert the line-break */ |
6215
bbd141b026b5
(svn r9012) -Fix/Feature (UTF8): When cutting strings into multiple lines also take into consideration whitespace characters of more than 1 byte length (eg IDEOGRAPHIC SPACE, IsWhitespace() function). When trimming such strings, account for multiple-byte long sequences so use *Utf8PrevChar(v) = '\0'.
Darkvater
parents:
6179
diff
changeset
|
600 |
if (IsWhitespace(c)) last_space = str; |
0 | 601 |
|
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
602 |
if (IsPrintable(c)) { |
3798
b1f5290b36b1
(svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents:
3797
diff
changeset
|
603 |
w += GetCharacterWidth(size, c); |
4954
c1f059faa899
(svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents:
4949
diff
changeset
|
604 |
/* string is longer than maximum width so we need to decide what to |
c1f059faa899
(svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents:
4949
diff
changeset
|
605 |
* do. We can do two things: |
c1f059faa899
(svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents:
4949
diff
changeset
|
606 |
* 1. If no whitespace was found at all up until now (on this line) then |
c1f059faa899
(svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents:
4949
diff
changeset
|
607 |
* we will truncate the string and bail out. |
c1f059faa899
(svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents:
4949
diff
changeset
|
608 |
* 2. In all other cases force a linebreak at the last seen whitespace */ |
0 | 609 |
if (w > maxw) { |
4954
c1f059faa899
(svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents:
4949
diff
changeset
|
610 |
if (last_space == NULL) { |
6215
bbd141b026b5
(svn r9012) -Fix/Feature (UTF8): When cutting strings into multiple lines also take into consideration whitespace characters of more than 1 byte length (eg IDEOGRAPHIC SPACE, IsWhitespace() function). When trimming such strings, account for multiple-byte long sequences so use *Utf8PrevChar(v) = '\0'.
Darkvater
parents:
6179
diff
changeset
|
611 |
*Utf8PrevChar(str) = '\0'; |
4954
c1f059faa899
(svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents:
4949
diff
changeset
|
612 |
return num + (size << 16); |
c1f059faa899
(svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents:
4949
diff
changeset
|
613 |
} |
0 | 614 |
str = last_space; |
615 |
break; |
|
616 |
} |
|
617 |
} else { |
|
4954
c1f059faa899
(svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents:
4949
diff
changeset
|
618 |
switch (c) { |
c1f059faa899
(svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents:
4949
diff
changeset
|
619 |
case '\0': return num + (size << 16); break; |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
620 |
case SCC_SETX: str++; break; |
6491
00dc414c909d
(svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents:
6481
diff
changeset
|
621 |
case SCC_SETXY: str += 2; break; |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
622 |
case SCC_TINYFONT: size = FS_SMALL; break; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
623 |
case SCC_BIGFONT: size = FS_LARGE; break; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
624 |
case '\n': goto end_of_inner_loop; |
4954
c1f059faa899
(svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents:
4949
diff
changeset
|
625 |
} |
0 | 626 |
} |
627 |
} |
|
4954
c1f059faa899
(svn r6953) -Codechange: Change FormatStringLinebreaks in such a way that if no whitespace was seen
Darkvater
parents:
4949
diff
changeset
|
628 |
end_of_inner_loop: |
6215
bbd141b026b5
(svn r9012) -Fix/Feature (UTF8): When cutting strings into multiple lines also take into consideration whitespace characters of more than 1 byte length (eg IDEOGRAPHIC SPACE, IsWhitespace() function). When trimming such strings, account for multiple-byte long sequences so use *Utf8PrevChar(v) = '\0'.
Darkvater
parents:
6179
diff
changeset
|
629 |
/* String didn't fit on line (or a '\n' was encountered), so 'dummy' terminate |
bbd141b026b5
(svn r9012) -Fix/Feature (UTF8): When cutting strings into multiple lines also take into consideration whitespace characters of more than 1 byte length (eg IDEOGRAPHIC SPACE, IsWhitespace() function). When trimming such strings, account for multiple-byte long sequences so use *Utf8PrevChar(v) = '\0'.
Darkvater
parents:
6179
diff
changeset
|
630 |
* and increase linecount. We use Utf8PrevChar() as also non 1 char long |
bbd141b026b5
(svn r9012) -Fix/Feature (UTF8): When cutting strings into multiple lines also take into consideration whitespace characters of more than 1 byte length (eg IDEOGRAPHIC SPACE, IsWhitespace() function). When trimming such strings, account for multiple-byte long sequences so use *Utf8PrevChar(v) = '\0'.
Darkvater
parents:
6179
diff
changeset
|
631 |
* whitespace seperators are supported */ |
0 | 632 |
num++; |
6215
bbd141b026b5
(svn r9012) -Fix/Feature (UTF8): When cutting strings into multiple lines also take into consideration whitespace characters of more than 1 byte length (eg IDEOGRAPHIC SPACE, IsWhitespace() function). When trimming such strings, account for multiple-byte long sequences so use *Utf8PrevChar(v) = '\0'.
Darkvater
parents:
6179
diff
changeset
|
633 |
char *s = Utf8PrevChar(str); |
bbd141b026b5
(svn r9012) -Fix/Feature (UTF8): When cutting strings into multiple lines also take into consideration whitespace characters of more than 1 byte length (eg IDEOGRAPHIC SPACE, IsWhitespace() function). When trimming such strings, account for multiple-byte long sequences so use *Utf8PrevChar(v) = '\0'.
Darkvater
parents:
6179
diff
changeset
|
634 |
*s++ = '\0'; |
bbd141b026b5
(svn r9012) -Fix/Feature (UTF8): When cutting strings into multiple lines also take into consideration whitespace characters of more than 1 byte length (eg IDEOGRAPHIC SPACE, IsWhitespace() function). When trimming such strings, account for multiple-byte long sequences so use *Utf8PrevChar(v) = '\0'.
Darkvater
parents:
6179
diff
changeset
|
635 |
|
bbd141b026b5
(svn r9012) -Fix/Feature (UTF8): When cutting strings into multiple lines also take into consideration whitespace characters of more than 1 byte length (eg IDEOGRAPHIC SPACE, IsWhitespace() function). When trimming such strings, account for multiple-byte long sequences so use *Utf8PrevChar(v) = '\0'.
Darkvater
parents:
6179
diff
changeset
|
636 |
/* In which case (see above) we will shift remainder to left and close the gap */ |
bbd141b026b5
(svn r9012) -Fix/Feature (UTF8): When cutting strings into multiple lines also take into consideration whitespace characters of more than 1 byte length (eg IDEOGRAPHIC SPACE, IsWhitespace() function). When trimming such strings, account for multiple-byte long sequences so use *Utf8PrevChar(v) = '\0'.
Darkvater
parents:
6179
diff
changeset
|
637 |
if (str - s >= 1) { |
bbd141b026b5
(svn r9012) -Fix/Feature (UTF8): When cutting strings into multiple lines also take into consideration whitespace characters of more than 1 byte length (eg IDEOGRAPHIC SPACE, IsWhitespace() function). When trimming such strings, account for multiple-byte long sequences so use *Utf8PrevChar(v) = '\0'.
Darkvater
parents:
6179
diff
changeset
|
638 |
for (; str[-1] != '\0';) *s++ = *str++; |
bbd141b026b5
(svn r9012) -Fix/Feature (UTF8): When cutting strings into multiple lines also take into consideration whitespace characters of more than 1 byte length (eg IDEOGRAPHIC SPACE, IsWhitespace() function). When trimming such strings, account for multiple-byte long sequences so use *Utf8PrevChar(v) = '\0'.
Darkvater
parents:
6179
diff
changeset
|
639 |
} |
0 | 640 |
} |
641 |
} |
|
642 |
||
9682
142c31e35bfa
(svn r13787) -Codechange: resize the red error message box if needed
smatz
parents:
9670
diff
changeset
|
643 |
|
142c31e35bfa
(svn r13787) -Codechange: resize the red error message box if needed
smatz
parents:
9670
diff
changeset
|
644 |
/** Calculates height of string (in pixels). Accepts multiline string with '\0' as separators. |
142c31e35bfa
(svn r13787) -Codechange: resize the red error message box if needed
smatz
parents:
9670
diff
changeset
|
645 |
* @param src string to check |
142c31e35bfa
(svn r13787) -Codechange: resize the red error message box if needed
smatz
parents:
9670
diff
changeset
|
646 |
* @param num number of extra lines (output of FormatStringLinebreaks()) |
142c31e35bfa
(svn r13787) -Codechange: resize the red error message box if needed
smatz
parents:
9670
diff
changeset
|
647 |
* @note assumes text won't be truncated. FormatStringLinebreaks() is a good way to ensure that. |
142c31e35bfa
(svn r13787) -Codechange: resize the red error message box if needed
smatz
parents:
9670
diff
changeset
|
648 |
* @return height of pixels of string when it is drawn |
142c31e35bfa
(svn r13787) -Codechange: resize the red error message box if needed
smatz
parents:
9670
diff
changeset
|
649 |
*/ |
142c31e35bfa
(svn r13787) -Codechange: resize the red error message box if needed
smatz
parents:
9670
diff
changeset
|
650 |
static int GetMultilineStringHeight(const char *src, int num) |
142c31e35bfa
(svn r13787) -Codechange: resize the red error message box if needed
smatz
parents:
9670
diff
changeset
|
651 |
{ |
142c31e35bfa
(svn r13787) -Codechange: resize the red error message box if needed
smatz
parents:
9670
diff
changeset
|
652 |
int maxy = 0; |
142c31e35bfa
(svn r13787) -Codechange: resize the red error message box if needed
smatz
parents:
9670
diff
changeset
|
653 |
int y = 0; |
142c31e35bfa
(svn r13787) -Codechange: resize the red error message box if needed
smatz
parents:
9670
diff
changeset
|
654 |
int fh = GetCharacterHeight(_cur_fontsize); |
142c31e35bfa
(svn r13787) -Codechange: resize the red error message box if needed
smatz
parents:
9670
diff
changeset
|
655 |
|
142c31e35bfa
(svn r13787) -Codechange: resize the red error message box if needed
smatz
parents:
9670
diff
changeset
|
656 |
for (;;) { |
142c31e35bfa
(svn r13787) -Codechange: resize the red error message box if needed
smatz
parents:
9670
diff
changeset
|
657 |
WChar c = Utf8Consume(&src); |
142c31e35bfa
(svn r13787) -Codechange: resize the red error message box if needed
smatz
parents:
9670
diff
changeset
|
658 |
|
142c31e35bfa
(svn r13787) -Codechange: resize the red error message box if needed
smatz
parents:
9670
diff
changeset
|
659 |
switch (c) { |
142c31e35bfa
(svn r13787) -Codechange: resize the red error message box if needed
smatz
parents:
9670
diff
changeset
|
660 |
case 0: y += fh; if (--num < 0) return maxy; break; |
142c31e35bfa
(svn r13787) -Codechange: resize the red error message box if needed
smatz
parents:
9670
diff
changeset
|
661 |
case '\n': y += fh; break; |
142c31e35bfa
(svn r13787) -Codechange: resize the red error message box if needed
smatz
parents:
9670
diff
changeset
|
662 |
case SCC_SETX: src++; break; |
142c31e35bfa
(svn r13787) -Codechange: resize the red error message box if needed
smatz
parents:
9670
diff
changeset
|
663 |
case SCC_SETXY: src++; y = (int)*src++; break; |
142c31e35bfa
(svn r13787) -Codechange: resize the red error message box if needed
smatz
parents:
9670
diff
changeset
|
664 |
case SCC_TINYFONT: fh = GetCharacterHeight(FS_SMALL); break; |
142c31e35bfa
(svn r13787) -Codechange: resize the red error message box if needed
smatz
parents:
9670
diff
changeset
|
665 |
case SCC_BIGFONT: fh = GetCharacterHeight(FS_LARGE); break; |
142c31e35bfa
(svn r13787) -Codechange: resize the red error message box if needed
smatz
parents:
9670
diff
changeset
|
666 |
default: maxy = max<int>(maxy, y + fh); break; |
142c31e35bfa
(svn r13787) -Codechange: resize the red error message box if needed
smatz
parents:
9670
diff
changeset
|
667 |
} |
142c31e35bfa
(svn r13787) -Codechange: resize the red error message box if needed
smatz
parents:
9670
diff
changeset
|
668 |
} |
142c31e35bfa
(svn r13787) -Codechange: resize the red error message box if needed
smatz
parents:
9670
diff
changeset
|
669 |
} |
142c31e35bfa
(svn r13787) -Codechange: resize the red error message box if needed
smatz
parents:
9670
diff
changeset
|
670 |
|
142c31e35bfa
(svn r13787) -Codechange: resize the red error message box if needed
smatz
parents:
9670
diff
changeset
|
671 |
|
142c31e35bfa
(svn r13787) -Codechange: resize the red error message box if needed
smatz
parents:
9670
diff
changeset
|
672 |
/** Calculates height of string (in pixels). The string is changed to a multiline string if needed. |
142c31e35bfa
(svn r13787) -Codechange: resize the red error message box if needed
smatz
parents:
9670
diff
changeset
|
673 |
* @param str string to check |
142c31e35bfa
(svn r13787) -Codechange: resize the red error message box if needed
smatz
parents:
9670
diff
changeset
|
674 |
* @param maxw maximum string width |
142c31e35bfa
(svn r13787) -Codechange: resize the red error message box if needed
smatz
parents:
9670
diff
changeset
|
675 |
* @return height of pixels of string when it is drawn |
142c31e35bfa
(svn r13787) -Codechange: resize the red error message box if needed
smatz
parents:
9670
diff
changeset
|
676 |
*/ |
142c31e35bfa
(svn r13787) -Codechange: resize the red error message box if needed
smatz
parents:
9670
diff
changeset
|
677 |
int GetStringHeight(StringID str, int maxw) |
142c31e35bfa
(svn r13787) -Codechange: resize the red error message box if needed
smatz
parents:
9670
diff
changeset
|
678 |
{ |
9901
602720bd2d53
(svn r14051) -Codechange: enumify the DrawString buffer length.
rubidium
parents:
9900
diff
changeset
|
679 |
char buffer[DRAW_STRING_BUFFER]; |
9682
142c31e35bfa
(svn r13787) -Codechange: resize the red error message box if needed
smatz
parents:
9670
diff
changeset
|
680 |
|
142c31e35bfa
(svn r13787) -Codechange: resize the red error message box if needed
smatz
parents:
9670
diff
changeset
|
681 |
GetString(buffer, str, lastof(buffer)); |
142c31e35bfa
(svn r13787) -Codechange: resize the red error message box if needed
smatz
parents:
9670
diff
changeset
|
682 |
|
142c31e35bfa
(svn r13787) -Codechange: resize the red error message box if needed
smatz
parents:
9670
diff
changeset
|
683 |
uint32 tmp = FormatStringLinebreaks(buffer, maxw); |
142c31e35bfa
(svn r13787) -Codechange: resize the red error message box if needed
smatz
parents:
9670
diff
changeset
|
684 |
|
142c31e35bfa
(svn r13787) -Codechange: resize the red error message box if needed
smatz
parents:
9670
diff
changeset
|
685 |
return GetMultilineStringHeight(buffer, GB(tmp, 0, 16)); |
142c31e35bfa
(svn r13787) -Codechange: resize the red error message box if needed
smatz
parents:
9670
diff
changeset
|
686 |
} |
142c31e35bfa
(svn r13787) -Codechange: resize the red error message box if needed
smatz
parents:
9670
diff
changeset
|
687 |
|
142c31e35bfa
(svn r13787) -Codechange: resize the red error message box if needed
smatz
parents:
9670
diff
changeset
|
688 |
|
9322
cf7dc39f9576
(svn r13206) -Feature(ette): Display all owners of a tile in the tile-info-window.
frosch
parents:
9126
diff
changeset
|
689 |
/** Draw a given string with the centre around the given (x,y) coordinates |
5391
18028f19893d
(svn r7580) -Fix (r7182): UTF8-merge changed the string handling a bit, now the str pointer for
Darkvater
parents:
5380
diff
changeset
|
690 |
* @param x Centre the string around this pixel width |
9322
cf7dc39f9576
(svn r13206) -Feature(ette): Display all owners of a tile in the tile-info-window.
frosch
parents:
9126
diff
changeset
|
691 |
* @param y Centre the string around this pixel height |
5391
18028f19893d
(svn r7580) -Fix (r7182): UTF8-merge changed the string handling a bit, now the str pointer for
Darkvater
parents:
5380
diff
changeset
|
692 |
* @param str String to draw |
6481
85ad87daf4b0
(svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas
parents:
6478
diff
changeset
|
693 |
* @param maxw Maximum width the string can have before it is wrapped */ |
2634
0df9396b0067
(svn r3176) Use proper types, not some variants of int
tron
parents:
2631
diff
changeset
|
694 |
void DrawStringMultiCenter(int x, int y, StringID str, int maxw) |
0 | 695 |
{ |
9901
602720bd2d53
(svn r14051) -Codechange: enumify the DrawString buffer length.
rubidium
parents:
9900
diff
changeset
|
696 |
char buffer[DRAW_STRING_BUFFER]; |
0 | 697 |
uint32 tmp; |
10248
f0297aac2ff2
(svn r14479) -Add: initial (optional) support for handling bidirectional scripts and connecting Arabic characters.
rubidium
parents:
10056
diff
changeset
|
698 |
int num, mt; |
1323
bac2e38e8b60
(svn r1827) Next iteration of the byte -> char transition: some string drawing functions and buffers
tron
parents:
1309
diff
changeset
|
699 |
const char *src; |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
700 |
WChar c; |
0 | 701 |
|
4912
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4819
diff
changeset
|
702 |
GetString(buffer, str, lastof(buffer)); |
0 | 703 |
|
1336
69391734ce23
(svn r1840) Repel str_buffr and use local buffers where possible
tron
parents:
1323
diff
changeset
|
704 |
tmp = FormatStringLinebreaks(buffer, maxw); |
2635 | 705 |
num = GB(tmp, 0, 16); |
0 | 706 |
|
5587
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
707 |
mt = GetCharacterHeight((FontSize)GB(tmp, 16, 16)); |
0 | 708 |
|
709 |
y -= (mt >> 1) * num; |
|
710 |
||
1336
69391734ce23
(svn r1840) Repel str_buffr and use local buffers where possible
tron
parents:
1323
diff
changeset
|
711 |
src = buffer; |
0 | 712 |
|
2952 | 713 |
for (;;) { |
10248
f0297aac2ff2
(svn r14479) -Add: initial (optional) support for handling bidirectional scripts and connecting Arabic characters.
rubidium
parents:
10056
diff
changeset
|
714 |
char buf2[DRAW_STRING_BUFFER]; |
f0297aac2ff2
(svn r14479) -Add: initial (optional) support for handling bidirectional scripts and connecting Arabic characters.
rubidium
parents:
10056
diff
changeset
|
715 |
strecpy(buf2, src, lastof(buf2)); |
f0297aac2ff2
(svn r14479) -Add: initial (optional) support for handling bidirectional scripts and connecting Arabic characters.
rubidium
parents:
10056
diff
changeset
|
716 |
HandleBiDiAndArabicShapes(buf2, lastof(buf2)); |
f0297aac2ff2
(svn r14479) -Add: initial (optional) support for handling bidirectional scripts and connecting Arabic characters.
rubidium
parents:
10056
diff
changeset
|
717 |
int w = GetStringBoundingBox(buf2).width; |
f0297aac2ff2
(svn r14479) -Add: initial (optional) support for handling bidirectional scripts and connecting Arabic characters.
rubidium
parents:
10056
diff
changeset
|
718 |
ReallyDoDrawString(buf2, x - (w >> 1), y, 0xFE, true); |
3798
b1f5290b36b1
(svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents:
3797
diff
changeset
|
719 |
_cur_fontsize = _last_fontsize; |
0 | 720 |
|
2952 | 721 |
for (;;) { |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
722 |
c = Utf8Consume(&src); |
0 | 723 |
if (c == 0) { |
724 |
y += mt; |
|
725 |
if (--num < 0) { |
|
3798
b1f5290b36b1
(svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents:
3797
diff
changeset
|
726 |
_cur_fontsize = FS_NORMAL; |
0 | 727 |
return; |
728 |
} |
|
729 |
break; |
|
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
730 |
} else if (c == SCC_SETX) { |
0 | 731 |
src++; |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
732 |
} else if (c == SCC_SETXY) { |
6491
00dc414c909d
(svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents:
6481
diff
changeset
|
733 |
src += 2; |
0 | 734 |
} |
735 |
} |
|
736 |
} |
|
737 |
} |
|
738 |
||
4928
ff53f78c5a87
(svn r6908) - Codechange: Modify DrawStringMultiLine() to return the number of pixel lines used, and use it for drawing NewGRF additional text (mart3p)
peter1138
parents:
4912
diff
changeset
|
739 |
|
6377
c1bc323eaf0c
(svn r9449) -Fix: Truncate the newgrf information text in the newgrf gui if it's too long.
maedhros
parents:
6357
diff
changeset
|
740 |
uint DrawStringMultiLine(int x, int y, StringID str, int maxw, int maxh) |
2010 | 741 |
{ |
9901
602720bd2d53
(svn r14051) -Codechange: enumify the DrawString buffer length.
rubidium
parents:
9900
diff
changeset
|
742 |
char buffer[DRAW_STRING_BUFFER]; |
0 | 743 |
uint32 tmp; |
2753 | 744 |
int num, mt; |
4928
ff53f78c5a87
(svn r6908) - Codechange: Modify DrawStringMultiLine() to return the number of pixel lines used, and use it for drawing NewGRF additional text (mart3p)
peter1138
parents:
4912
diff
changeset
|
745 |
uint total_height; |
1323
bac2e38e8b60
(svn r1827) Next iteration of the byte -> char transition: some string drawing functions and buffers
tron
parents:
1309
diff
changeset
|
746 |
const char *src; |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
747 |
WChar c; |
0 | 748 |
|
4912
0f51b47cb983
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents:
4819
diff
changeset
|
749 |
GetString(buffer, str, lastof(buffer)); |
0 | 750 |
|
1336
69391734ce23
(svn r1840) Repel str_buffr and use local buffers where possible
tron
parents:
1323
diff
changeset
|
751 |
tmp = FormatStringLinebreaks(buffer, maxw); |
2635 | 752 |
num = GB(tmp, 0, 16); |
2631
2ed0eb408229
(svn r3173) Use the trinary operator and switch to improve readability
tron
parents:
2548
diff
changeset
|
753 |
|
5587
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
754 |
mt = GetCharacterHeight((FontSize)GB(tmp, 16, 16)); |
4928
ff53f78c5a87
(svn r6908) - Codechange: Modify DrawStringMultiLine() to return the number of pixel lines used, and use it for drawing NewGRF additional text (mart3p)
peter1138
parents:
4912
diff
changeset
|
755 |
total_height = (num + 1) * mt; |
0 | 756 |
|
6382
08cb3e868ca8
(svn r9472) -Fix (r9449): num is the number of newlines in the string, not the number of lines. Also allow for maxh being negative.
maedhros
parents:
6377
diff
changeset
|
757 |
if (maxh != -1 && (int)total_height > maxh) { |
08cb3e868ca8
(svn r9472) -Fix (r9449): num is the number of newlines in the string, not the number of lines. Also allow for maxh being negative.
maedhros
parents:
6377
diff
changeset
|
758 |
/* Check there's room enough for at least one line. */ |
08cb3e868ca8
(svn r9472) -Fix (r9449): num is the number of newlines in the string, not the number of lines. Also allow for maxh being negative.
maedhros
parents:
6377
diff
changeset
|
759 |
if (maxh < mt) return 0; |
08cb3e868ca8
(svn r9472) -Fix (r9449): num is the number of newlines in the string, not the number of lines. Also allow for maxh being negative.
maedhros
parents:
6377
diff
changeset
|
760 |
|
6377
c1bc323eaf0c
(svn r9449) -Fix: Truncate the newgrf information text in the newgrf gui if it's too long.
maedhros
parents:
6357
diff
changeset
|
761 |
num = maxh / mt - 1; |
c1bc323eaf0c
(svn r9449) -Fix: Truncate the newgrf information text in the newgrf gui if it's too long.
maedhros
parents:
6357
diff
changeset
|
762 |
total_height = (num + 1) * mt; |
c1bc323eaf0c
(svn r9449) -Fix: Truncate the newgrf information text in the newgrf gui if it's too long.
maedhros
parents:
6357
diff
changeset
|
763 |
} |
c1bc323eaf0c
(svn r9449) -Fix: Truncate the newgrf information text in the newgrf gui if it's too long.
maedhros
parents:
6357
diff
changeset
|
764 |
|
1336
69391734ce23
(svn r1840) Repel str_buffr and use local buffers where possible
tron
parents:
1323
diff
changeset
|
765 |
src = buffer; |
0 | 766 |
|
2952 | 767 |
for (;;) { |
10248
f0297aac2ff2
(svn r14479) -Add: initial (optional) support for handling bidirectional scripts and connecting Arabic characters.
rubidium
parents:
10056
diff
changeset
|
768 |
char buf2[DRAW_STRING_BUFFER]; |
f0297aac2ff2
(svn r14479) -Add: initial (optional) support for handling bidirectional scripts and connecting Arabic characters.
rubidium
parents:
10056
diff
changeset
|
769 |
strecpy(buf2, src, lastof(buf2)); |
f0297aac2ff2
(svn r14479) -Add: initial (optional) support for handling bidirectional scripts and connecting Arabic characters.
rubidium
parents:
10056
diff
changeset
|
770 |
HandleBiDiAndArabicShapes(buf2, lastof(buf2)); |
f0297aac2ff2
(svn r14479) -Add: initial (optional) support for handling bidirectional scripts and connecting Arabic characters.
rubidium
parents:
10056
diff
changeset
|
771 |
ReallyDoDrawString(buf2, x, y, 0xFE, true); |
3798
b1f5290b36b1
(svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents:
3797
diff
changeset
|
772 |
_cur_fontsize = _last_fontsize; |
0 | 773 |
|
2952 | 774 |
for (;;) { |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
775 |
c = Utf8Consume(&src); |
0 | 776 |
if (c == 0) { |
777 |
y += mt; |
|
778 |
if (--num < 0) { |
|
3798
b1f5290b36b1
(svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents:
3797
diff
changeset
|
779 |
_cur_fontsize = FS_NORMAL; |
4928
ff53f78c5a87
(svn r6908) - Codechange: Modify DrawStringMultiLine() to return the number of pixel lines used, and use it for drawing NewGRF additional text (mart3p)
peter1138
parents:
4912
diff
changeset
|
780 |
return total_height; |
0 | 781 |
} |
782 |
break; |
|
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
783 |
} else if (c == SCC_SETX) { |
0 | 784 |
src++; |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
785 |
} else if (c == SCC_SETXY) { |
6491
00dc414c909d
(svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents:
6481
diff
changeset
|
786 |
src += 2; |
0 | 787 |
} |
788 |
} |
|
789 |
} |
|
790 |
} |
|
791 |
||
4609
954fe701062f
(svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents:
4557
diff
changeset
|
792 |
/** Return the string dimension in pixels. The height and width are returned |
8121
3bc6351e7369
(svn r11682) -Codechange: move some 'generic' geometry related types into a single file and do not include gfx.h everywhere to get a Point type.
rubidium
parents:
8114
diff
changeset
|
793 |
* in a single Dimension value. TINYFONT, BIGFONT modifiers are only |
4609
954fe701062f
(svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents:
4557
diff
changeset
|
794 |
* supported as the first character of the string. The returned dimensions |
954fe701062f
(svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents:
4557
diff
changeset
|
795 |
* are therefore a rough estimation correct for all the current strings |
954fe701062f
(svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents:
4557
diff
changeset
|
796 |
* but not every possible combination |
954fe701062f
(svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents:
4557
diff
changeset
|
797 |
* @param str string to calculate pixel-width |
954fe701062f
(svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents:
4557
diff
changeset
|
798 |
* @return string width and height in pixels */ |
8121
3bc6351e7369
(svn r11682) -Codechange: move some 'generic' geometry related types into a single file and do not include gfx.h everywhere to get a Point type.
rubidium
parents:
8114
diff
changeset
|
799 |
Dimension GetStringBoundingBox(const char *str) |
1323
bac2e38e8b60
(svn r1827) Next iteration of the byte -> char transition: some string drawing functions and buffers
tron
parents:
1309
diff
changeset
|
800 |
{ |
3798
b1f5290b36b1
(svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents:
3797
diff
changeset
|
801 |
FontSize size = _cur_fontsize; |
8121
3bc6351e7369
(svn r11682) -Codechange: move some 'generic' geometry related types into a single file and do not include gfx.h everywhere to get a Point type.
rubidium
parents:
8114
diff
changeset
|
802 |
Dimension br; |
4609
954fe701062f
(svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents:
4557
diff
changeset
|
803 |
int max_width; |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
804 |
WChar c; |
4557
fe3fbd6204aa
(svn r6404) -Fix: GetStringWidth failed to calculate correct string width if the string
Darkvater
parents:
4525
diff
changeset
|
805 |
|
4609
954fe701062f
(svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents:
4557
diff
changeset
|
806 |
br.width = br.height = max_width = 0; |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
807 |
for (;;) { |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
808 |
c = Utf8Consume(&str); |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
809 |
if (c == 0) break; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
810 |
if (IsPrintable(c)) { |
4609
954fe701062f
(svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents:
4557
diff
changeset
|
811 |
br.width += GetCharacterWidth(size, c); |
0 | 812 |
} else { |
4609
954fe701062f
(svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents:
4557
diff
changeset
|
813 |
switch (c) { |
5391
18028f19893d
(svn r7580) -Fix (r7182): UTF8-merge changed the string handling a bit, now the str pointer for
Darkvater
parents:
5380
diff
changeset
|
814 |
case SCC_SETX: br.width += (byte)*str++; break; |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
815 |
case SCC_SETXY: |
5391
18028f19893d
(svn r7580) -Fix (r7182): UTF8-merge changed the string handling a bit, now the str pointer for
Darkvater
parents:
5380
diff
changeset
|
816 |
br.width += (byte)*str++; |
18028f19893d
(svn r7580) -Fix (r7182): UTF8-merge changed the string handling a bit, now the str pointer for
Darkvater
parents:
5380
diff
changeset
|
817 |
br.height += (byte)*str++; |
4609
954fe701062f
(svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents:
4557
diff
changeset
|
818 |
break; |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
819 |
case SCC_TINYFONT: size = FS_SMALL; break; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
820 |
case SCC_BIGFONT: size = FS_LARGE; break; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
821 |
case '\n': |
4609
954fe701062f
(svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents:
4557
diff
changeset
|
822 |
br.height += GetCharacterHeight(size); |
4610
f264efbf7f4f
(svn r6463) -Fix (r6462): Reset the string width to zero on every new line of course...
Darkvater
parents:
4609
diff
changeset
|
823 |
if (br.width > max_width) max_width = br.width; |
f264efbf7f4f
(svn r6463) -Fix (r6462): Reset the string width to zero on every new line of course...
Darkvater
parents:
4609
diff
changeset
|
824 |
br.width = 0; |
4609
954fe701062f
(svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents:
4557
diff
changeset
|
825 |
break; |
954fe701062f
(svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents:
4557
diff
changeset
|
826 |
} |
0 | 827 |
} |
828 |
} |
|
4609
954fe701062f
(svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents:
4557
diff
changeset
|
829 |
br.height += GetCharacterHeight(size); |
4557
fe3fbd6204aa
(svn r6404) -Fix: GetStringWidth failed to calculate correct string width if the string
Darkvater
parents:
4525
diff
changeset
|
830 |
|
4609
954fe701062f
(svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents:
4557
diff
changeset
|
831 |
br.width = max(br.width, max_width); |
954fe701062f
(svn r6462) -Codechange: Have GetStringWidth() return width as well as the height bounding
Darkvater
parents:
4557
diff
changeset
|
832 |
return br; |
0 | 833 |
} |
834 |
||
9773
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
835 |
/** |
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
836 |
* Draw single character horizontally centered around (x,y) |
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
837 |
* @param c Character (glyph) to draw |
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
838 |
* @param x X position to draw character |
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
839 |
* @param y Y position to draw character |
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
840 |
* @param real_color Colour to use, see DoDrawString() for details |
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
841 |
*/ |
8737
4405e2e80db6
(svn r12425) -Feature [FS#1846]: On Screen Keyboard for input fields so someone without a keyboard can enter text too. Patch by Dominik.
rubidium
parents:
8670
diff
changeset
|
842 |
void DrawCharCentered(WChar c, int x, int y, uint16 real_color) |
4405e2e80db6
(svn r12425) -Feature [FS#1846]: On Screen Keyboard for input fields so someone without a keyboard can enter text too. Patch by Dominik.
rubidium
parents:
8670
diff
changeset
|
843 |
{ |
4405e2e80db6
(svn r12425) -Feature [FS#1846]: On Screen Keyboard for input fields so someone without a keyboard can enter text too. Patch by Dominik.
rubidium
parents:
8670
diff
changeset
|
844 |
FontSize size = FS_NORMAL; |
4405e2e80db6
(svn r12425) -Feature [FS#1846]: On Screen Keyboard for input fields so someone without a keyboard can enter text too. Patch by Dominik.
rubidium
parents:
8670
diff
changeset
|
845 |
byte color = real_color & 0xFF; |
4405e2e80db6
(svn r12425) -Feature [FS#1846]: On Screen Keyboard for input fields so someone without a keyboard can enter text too. Patch by Dominik.
rubidium
parents:
8670
diff
changeset
|
846 |
int w = GetCharacterWidth(size, c); |
4405e2e80db6
(svn r12425) -Feature [FS#1846]: On Screen Keyboard for input fields so someone without a keyboard can enter text too. Patch by Dominik.
rubidium
parents:
8670
diff
changeset
|
847 |
|
9989
62e68bd41c90
(svn r14146) -Codechange: allow palette override in both ways and remove some unneeded '(x == 0) ? 0 : 1' constructs.
rubidium
parents:
9911
diff
changeset
|
848 |
_string_colorremap[1] = _string_colormap[_use_palette][color].text; |
62e68bd41c90
(svn r14146) -Codechange: allow palette override in both ways and remove some unneeded '(x == 0) ? 0 : 1' constructs.
rubidium
parents:
9911
diff
changeset
|
849 |
_string_colorremap[2] = _string_colormap[_use_palette][color].shadow; |
8737
4405e2e80db6
(svn r12425) -Feature [FS#1846]: On Screen Keyboard for input fields so someone without a keyboard can enter text too. Patch by Dominik.
rubidium
parents:
8670
diff
changeset
|
850 |
_color_remap_ptr = _string_colorremap; |
4405e2e80db6
(svn r12425) -Feature [FS#1846]: On Screen Keyboard for input fields so someone without a keyboard can enter text too. Patch by Dominik.
rubidium
parents:
8670
diff
changeset
|
851 |
|
4405e2e80db6
(svn r12425) -Feature [FS#1846]: On Screen Keyboard for input fields so someone without a keyboard can enter text too. Patch by Dominik.
rubidium
parents:
8670
diff
changeset
|
852 |
GfxMainBlitter(GetGlyph(size, c), x - w / 2, y, BM_COLOUR_REMAP); |
4405e2e80db6
(svn r12425) -Feature [FS#1846]: On Screen Keyboard for input fields so someone without a keyboard can enter text too. Patch by Dominik.
rubidium
parents:
8670
diff
changeset
|
853 |
} |
4405e2e80db6
(svn r12425) -Feature [FS#1846]: On Screen Keyboard for input fields so someone without a keyboard can enter text too. Patch by Dominik.
rubidium
parents:
8670
diff
changeset
|
854 |
|
9879
9329707cba0a
(svn r14027) -Codechange: Document a bit the DoDrawString function while removing yet som more magic numbers and one "false" colour
belugas
parents:
9870
diff
changeset
|
855 |
/** Draw a string at the given coordinates with the given colour. |
9329707cba0a
(svn r14027) -Codechange: Document a bit the DoDrawString function while removing yet som more magic numbers and one "false" colour
belugas
parents:
9870
diff
changeset
|
856 |
* While drawing the string, parse it in case some formatting is specified, |
9329707cba0a
(svn r14027) -Codechange: Document a bit the DoDrawString function while removing yet som more magic numbers and one "false" colour
belugas
parents:
9870
diff
changeset
|
857 |
* like new colour, new size or even positionning. |
10248
f0297aac2ff2
(svn r14479) -Add: initial (optional) support for handling bidirectional scripts and connecting Arabic characters.
rubidium
parents:
10056
diff
changeset
|
858 |
* @param string The string to draw. This is not yet bidi reordered. |
9904
774f078c0e5c
(svn r14054) -Fix (rthebeginning): long strings in the edit box would cause OpenTTD to stop drawing the string. This is especially noticable with low resolutions and the chat input box.
rubidium
parents:
9901
diff
changeset
|
859 |
* @param x Offset from left side of the screen |
774f078c0e5c
(svn r14054) -Fix (rthebeginning): long strings in the edit box would cause OpenTTD to stop drawing the string. This is especially noticable with low resolutions and the chat input box.
rubidium
parents:
9901
diff
changeset
|
860 |
* @param y Offset from top side of the screen |
9879
9329707cba0a
(svn r14027) -Codechange: Document a bit the DoDrawString function while removing yet som more magic numbers and one "false" colour
belugas
parents:
9870
diff
changeset
|
861 |
* @param real_colour Colour of the string, see _string_colormap in |
9329707cba0a
(svn r14027) -Codechange: Document a bit the DoDrawString function while removing yet som more magic numbers and one "false" colour
belugas
parents:
9870
diff
changeset
|
862 |
* table/palettes.h or docs/ottd-colourtext-palette.png or the enum TextColour in gfx_type.h |
9882
aa5f19fddb3c
(svn r14030) -Fix (r14027): true != false, also rename the parameter to make 'true' and 'false' more intuitively useable.
frosch
parents:
9881
diff
changeset
|
863 |
* @param parse_string_also_when_clipped |
aa5f19fddb3c
(svn r14030) -Fix (r14027): true != false, also rename the parameter to make 'true' and 'false' more intuitively useable.
frosch
parents:
9881
diff
changeset
|
864 |
* By default, always test the available space where to draw the string. |
aa5f19fddb3c
(svn r14030) -Fix (r14027): true != false, also rename the parameter to make 'true' and 'false' more intuitively useable.
frosch
parents:
9881
diff
changeset
|
865 |
* When in multipline drawing, it would already be done, |
aa5f19fddb3c
(svn r14030) -Fix (r14027): true != false, also rename the parameter to make 'true' and 'false' more intuitively useable.
frosch
parents:
9881
diff
changeset
|
866 |
* so no need to re-perform the same kind (more or less) of verifications. |
aa5f19fddb3c
(svn r14030) -Fix (r14027): true != false, also rename the parameter to make 'true' and 'false' more intuitively useable.
frosch
parents:
9881
diff
changeset
|
867 |
* It's not only an optimisation, it's also a way to ensures the string will be parsed |
aa5f19fddb3c
(svn r14030) -Fix (r14027): true != false, also rename the parameter to make 'true' and 'false' more intuitively useable.
frosch
parents:
9881
diff
changeset
|
868 |
* (as there are certain side effects on global variables, which are important for the next line) |
9879
9329707cba0a
(svn r14027) -Codechange: Document a bit the DoDrawString function while removing yet som more magic numbers and one "false" colour
belugas
parents:
9870
diff
changeset
|
869 |
* @return the x-coordinates where the drawing has finished. |
9329707cba0a
(svn r14027) -Codechange: Document a bit the DoDrawString function while removing yet som more magic numbers and one "false" colour
belugas
parents:
9870
diff
changeset
|
870 |
* If nothing is drawn, the originally passed x-coordinate is returned |
9329707cba0a
(svn r14027) -Codechange: Document a bit the DoDrawString function while removing yet som more magic numbers and one "false" colour
belugas
parents:
9870
diff
changeset
|
871 |
*/ |
9882
aa5f19fddb3c
(svn r14030) -Fix (r14027): true != false, also rename the parameter to make 'true' and 'false' more intuitively useable.
frosch
parents:
9881
diff
changeset
|
872 |
int DoDrawString(const char *string, int x, int y, uint16 real_colour, bool parse_string_also_when_clipped) |
1323
bac2e38e8b60
(svn r1827) Next iteration of the byte -> char transition: some string drawing functions and buffers
tron
parents:
1309
diff
changeset
|
873 |
{ |
10248
f0297aac2ff2
(svn r14479) -Add: initial (optional) support for handling bidirectional scripts and connecting Arabic characters.
rubidium
parents:
10056
diff
changeset
|
874 |
char buffer[DRAW_STRING_BUFFER]; |
f0297aac2ff2
(svn r14479) -Add: initial (optional) support for handling bidirectional scripts and connecting Arabic characters.
rubidium
parents:
10056
diff
changeset
|
875 |
strecpy(buffer, string, lastof(buffer)); |
f0297aac2ff2
(svn r14479) -Add: initial (optional) support for handling bidirectional scripts and connecting Arabic characters.
rubidium
parents:
10056
diff
changeset
|
876 |
HandleBiDiAndArabicShapes(buffer, lastof(buffer)); |
f0297aac2ff2
(svn r14479) -Add: initial (optional) support for handling bidirectional scripts and connecting Arabic characters.
rubidium
parents:
10056
diff
changeset
|
877 |
|
f0297aac2ff2
(svn r14479) -Add: initial (optional) support for handling bidirectional scripts and connecting Arabic characters.
rubidium
parents:
10056
diff
changeset
|
878 |
return ReallyDoDrawString(buffer, x, y, real_colour, parse_string_also_when_clipped); |
f0297aac2ff2
(svn r14479) -Add: initial (optional) support for handling bidirectional scripts and connecting Arabic characters.
rubidium
parents:
10056
diff
changeset
|
879 |
} |
f0297aac2ff2
(svn r14479) -Add: initial (optional) support for handling bidirectional scripts and connecting Arabic characters.
rubidium
parents:
10056
diff
changeset
|
880 |
|
f0297aac2ff2
(svn r14479) -Add: initial (optional) support for handling bidirectional scripts and connecting Arabic characters.
rubidium
parents:
10056
diff
changeset
|
881 |
/** Draw a string at the given coordinates with the given colour. |
f0297aac2ff2
(svn r14479) -Add: initial (optional) support for handling bidirectional scripts and connecting Arabic characters.
rubidium
parents:
10056
diff
changeset
|
882 |
* While drawing the string, parse it in case some formatting is specified, |
f0297aac2ff2
(svn r14479) -Add: initial (optional) support for handling bidirectional scripts and connecting Arabic characters.
rubidium
parents:
10056
diff
changeset
|
883 |
* like new colour, new size or even positionning. |
f0297aac2ff2
(svn r14479) -Add: initial (optional) support for handling bidirectional scripts and connecting Arabic characters.
rubidium
parents:
10056
diff
changeset
|
884 |
* @param string The string to draw. This is already bidi reordered. |
f0297aac2ff2
(svn r14479) -Add: initial (optional) support for handling bidirectional scripts and connecting Arabic characters.
rubidium
parents:
10056
diff
changeset
|
885 |
* @param x Offset from left side of the screen |
f0297aac2ff2
(svn r14479) -Add: initial (optional) support for handling bidirectional scripts and connecting Arabic characters.
rubidium
parents:
10056
diff
changeset
|
886 |
* @param y Offset from top side of the screen |
f0297aac2ff2
(svn r14479) -Add: initial (optional) support for handling bidirectional scripts and connecting Arabic characters.
rubidium
parents:
10056
diff
changeset
|
887 |
* @param real_colour Colour of the string, see _string_colormap in |
f0297aac2ff2
(svn r14479) -Add: initial (optional) support for handling bidirectional scripts and connecting Arabic characters.
rubidium
parents:
10056
diff
changeset
|
888 |
* table/palettes.h or docs/ottd-colourtext-palette.png or the enum TextColour in gfx_type.h |
f0297aac2ff2
(svn r14479) -Add: initial (optional) support for handling bidirectional scripts and connecting Arabic characters.
rubidium
parents:
10056
diff
changeset
|
889 |
* @param parse_string_also_when_clipped |
f0297aac2ff2
(svn r14479) -Add: initial (optional) support for handling bidirectional scripts and connecting Arabic characters.
rubidium
parents:
10056
diff
changeset
|
890 |
* By default, always test the available space where to draw the string. |
f0297aac2ff2
(svn r14479) -Add: initial (optional) support for handling bidirectional scripts and connecting Arabic characters.
rubidium
parents:
10056
diff
changeset
|
891 |
* When in multipline drawing, it would already be done, |
f0297aac2ff2
(svn r14479) -Add: initial (optional) support for handling bidirectional scripts and connecting Arabic characters.
rubidium
parents:
10056
diff
changeset
|
892 |
* so no need to re-perform the same kind (more or less) of verifications. |
f0297aac2ff2
(svn r14479) -Add: initial (optional) support for handling bidirectional scripts and connecting Arabic characters.
rubidium
parents:
10056
diff
changeset
|
893 |
* It's not only an optimisation, it's also a way to ensures the string will be parsed |
f0297aac2ff2
(svn r14479) -Add: initial (optional) support for handling bidirectional scripts and connecting Arabic characters.
rubidium
parents:
10056
diff
changeset
|
894 |
* (as there are certain side effects on global variables, which are important for the next line) |
f0297aac2ff2
(svn r14479) -Add: initial (optional) support for handling bidirectional scripts and connecting Arabic characters.
rubidium
parents:
10056
diff
changeset
|
895 |
* @return the x-coordinates where the drawing has finished. |
f0297aac2ff2
(svn r14479) -Add: initial (optional) support for handling bidirectional scripts and connecting Arabic characters.
rubidium
parents:
10056
diff
changeset
|
896 |
* If nothing is drawn, the originally passed x-coordinate is returned |
f0297aac2ff2
(svn r14479) -Add: initial (optional) support for handling bidirectional scripts and connecting Arabic characters.
rubidium
parents:
10056
diff
changeset
|
897 |
*/ |
f0297aac2ff2
(svn r14479) -Add: initial (optional) support for handling bidirectional scripts and connecting Arabic characters.
rubidium
parents:
10056
diff
changeset
|
898 |
static int ReallyDoDrawString(const char *string, int x, int y, uint16 real_colour, bool parse_string_also_when_clipped) |
f0297aac2ff2
(svn r14479) -Add: initial (optional) support for handling bidirectional scripts and connecting Arabic characters.
rubidium
parents:
10056
diff
changeset
|
899 |
{ |
4522 | 900 |
DrawPixelInfo *dpi = _cur_dpi; |
3798
b1f5290b36b1
(svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents:
3797
diff
changeset
|
901 |
FontSize size = _cur_fontsize; |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
902 |
WChar c; |
0 | 903 |
int xo = x, yo = y; |
904 |
||
9879
9329707cba0a
(svn r14027) -Codechange: Document a bit the DoDrawString function while removing yet som more magic numbers and one "false" colour
belugas
parents:
9870
diff
changeset
|
905 |
byte colour = real_colour & 0xFF; // extract the 8 bits colour index that is required for the mapping |
9329707cba0a
(svn r14027) -Codechange: Document a bit the DoDrawString function while removing yet som more magic numbers and one "false" colour
belugas
parents:
9870
diff
changeset
|
906 |
byte previous_colour = colour; |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
510
diff
changeset
|
907 |
|
9882
aa5f19fddb3c
(svn r14030) -Fix (r14027): true != false, also rename the parameter to make 'true' and 'false' more intuitively useable.
frosch
parents:
9881
diff
changeset
|
908 |
if (!parse_string_also_when_clipped) { |
9879
9329707cba0a
(svn r14027) -Codechange: Document a bit the DoDrawString function while removing yet som more magic numbers and one "false" colour
belugas
parents:
9870
diff
changeset
|
909 |
/* in "mode multiline", the available space have been verified. Not in regular one. |
9329707cba0a
(svn r14027) -Codechange: Document a bit the DoDrawString function while removing yet som more magic numbers and one "false" colour
belugas
parents:
9870
diff
changeset
|
910 |
* So if the string cannot be drawn, return the original start to say so.*/ |
9904
774f078c0e5c
(svn r14054) -Fix (rthebeginning): long strings in the edit box would cause OpenTTD to stop drawing the string. This is especially noticable with low resolutions and the chat input box.
rubidium
parents:
9901
diff
changeset
|
911 |
if (x >= dpi->left + dpi->width || y >= dpi->top + dpi->height) return x; |
0 | 912 |
|
9879
9329707cba0a
(svn r14027) -Codechange: Document a bit the DoDrawString function while removing yet som more magic numbers and one "false" colour
belugas
parents:
9870
diff
changeset
|
913 |
if (colour != TC_INVALID) { // the invalid colour flag test should not really occur. But better be safe |
9329707cba0a
(svn r14027) -Codechange: Document a bit the DoDrawString function while removing yet som more magic numbers and one "false" colour
belugas
parents:
9870
diff
changeset
|
914 |
switch_colour:; |
9329707cba0a
(svn r14027) -Codechange: Document a bit the DoDrawString function while removing yet som more magic numbers and one "false" colour
belugas
parents:
9870
diff
changeset
|
915 |
if (real_colour & IS_PALETTE_COLOR) { |
9329707cba0a
(svn r14027) -Codechange: Document a bit the DoDrawString function while removing yet som more magic numbers and one "false" colour
belugas
parents:
9870
diff
changeset
|
916 |
_string_colorremap[1] = colour; |
9989
62e68bd41c90
(svn r14146) -Codechange: allow palette override in both ways and remove some unneeded '(x == 0) ? 0 : 1' constructs.
rubidium
parents:
9911
diff
changeset
|
917 |
_string_colorremap[2] = (_use_palette == PAL_DOS) ? 1 : 215; |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
510
diff
changeset
|
918 |
} else { |
9989
62e68bd41c90
(svn r14146) -Codechange: allow palette override in both ways and remove some unneeded '(x == 0) ? 0 : 1' constructs.
rubidium
parents:
9911
diff
changeset
|
919 |
_string_colorremap[1] = _string_colormap[_use_palette][colour].text; |
62e68bd41c90
(svn r14146) -Codechange: allow palette override in both ways and remove some unneeded '(x == 0) ? 0 : 1' constructs.
rubidium
parents:
9911
diff
changeset
|
920 |
_string_colorremap[2] = _string_colormap[_use_palette][colour].shadow; |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
510
diff
changeset
|
921 |
} |
0 | 922 |
_color_remap_ptr = _string_colorremap; |
923 |
} |
|
924 |
} |
|
925 |
||
926 |
check_bounds: |
|
927 |
if (y + 19 <= dpi->top || dpi->top + dpi->height <= y) { |
|
928 |
skip_char:; |
|
2952 | 929 |
for (;;) { |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
930 |
c = Utf8Consume(&string); |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
931 |
if (!IsPrintable(c)) goto skip_cont; |
0 | 932 |
} |
933 |
} |
|
934 |
||
2952 | 935 |
for (;;) { |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
936 |
c = Utf8Consume(&string); |
0 | 937 |
skip_cont:; |
938 |
if (c == 0) { |
|
3798
b1f5290b36b1
(svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents:
3797
diff
changeset
|
939 |
_last_fontsize = size; |
9879
9329707cba0a
(svn r14027) -Codechange: Document a bit the DoDrawString function while removing yet som more magic numbers and one "false" colour
belugas
parents:
9870
diff
changeset
|
940 |
return x; // Nothing more to draw, get out. And here is the new x position |
0 | 941 |
} |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
942 |
if (IsPrintable(c)) { |
0 | 943 |
if (x >= dpi->left + dpi->width) goto skip_char; |
944 |
if (x + 26 >= dpi->left) { |
|
6852
439563b70fd3
(svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
6831
diff
changeset
|
945 |
GfxMainBlitter(GetGlyph(size, c), x, y, BM_COLOUR_REMAP); |
0 | 946 |
} |
3798
b1f5290b36b1
(svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents:
3797
diff
changeset
|
947 |
x += GetCharacterWidth(size, c); |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
948 |
} else if (c == '\n') { // newline = {} |
9879
9329707cba0a
(svn r14027) -Codechange: Document a bit the DoDrawString function while removing yet som more magic numbers and one "false" colour
belugas
parents:
9870
diff
changeset
|
949 |
x = xo; // We require a new line, so the x coordinate is reset |
3798
b1f5290b36b1
(svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents:
3797
diff
changeset
|
950 |
y += GetCharacterHeight(size); |
0 | 951 |
goto check_bounds; |
9879
9329707cba0a
(svn r14027) -Codechange: Document a bit the DoDrawString function while removing yet som more magic numbers and one "false" colour
belugas
parents:
9870
diff
changeset
|
952 |
} else if (c >= SCC_BLUE && c <= SCC_BLACK) { // change colour? |
9329707cba0a
(svn r14027) -Codechange: Document a bit the DoDrawString function while removing yet som more magic numbers and one "false" colour
belugas
parents:
9870
diff
changeset
|
953 |
previous_colour = colour; |
9329707cba0a
(svn r14027) -Codechange: Document a bit the DoDrawString function while removing yet som more magic numbers and one "false" colour
belugas
parents:
9870
diff
changeset
|
954 |
colour = (byte)(c - SCC_BLUE); |
9329707cba0a
(svn r14027) -Codechange: Document a bit the DoDrawString function while removing yet som more magic numbers and one "false" colour
belugas
parents:
9870
diff
changeset
|
955 |
goto switch_colour; |
9329707cba0a
(svn r14027) -Codechange: Document a bit the DoDrawString function while removing yet som more magic numbers and one "false" colour
belugas
parents:
9870
diff
changeset
|
956 |
} else if (c == SCC_PREVIOUS_COLOUR) { // revert to the previous colour |
9329707cba0a
(svn r14027) -Codechange: Document a bit the DoDrawString function while removing yet som more magic numbers and one "false" colour
belugas
parents:
9870
diff
changeset
|
957 |
Swap(colour, previous_colour); |
9329707cba0a
(svn r14027) -Codechange: Document a bit the DoDrawString function while removing yet som more magic numbers and one "false" colour
belugas
parents:
9870
diff
changeset
|
958 |
goto switch_colour; |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
959 |
} else if (c == SCC_SETX) { // {SETX} |
1323
bac2e38e8b60
(svn r1827) Next iteration of the byte -> char transition: some string drawing functions and buffers
tron
parents:
1309
diff
changeset
|
960 |
x = xo + (byte)*string++; |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
961 |
} else if (c == SCC_SETXY) {// {SETXY} |
1323
bac2e38e8b60
(svn r1827) Next iteration of the byte -> char transition: some string drawing functions and buffers
tron
parents:
1309
diff
changeset
|
962 |
x = xo + (byte)*string++; |
bac2e38e8b60
(svn r1827) Next iteration of the byte -> char transition: some string drawing functions and buffers
tron
parents:
1309
diff
changeset
|
963 |
y = yo + (byte)*string++; |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
964 |
} else if (c == SCC_TINYFONT) { // {TINYFONT} |
3798
b1f5290b36b1
(svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents:
3797
diff
changeset
|
965 |
size = FS_SMALL; |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
966 |
} else if (c == SCC_BIGFONT) { // {BIGFONT} |
3798
b1f5290b36b1
(svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents:
3797
diff
changeset
|
967 |
size = FS_LARGE; |
0 | 968 |
} else { |
5391
18028f19893d
(svn r7580) -Fix (r7182): UTF8-merge changed the string handling a bit, now the str pointer for
Darkvater
parents:
5380
diff
changeset
|
969 |
DEBUG(misc, 0, "[utf8] unknown string command character %d", c); |
0 | 970 |
} |
971 |
} |
|
972 |
} |
|
973 |
||
9773
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
974 |
/** |
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
975 |
* Draw the string of the character buffer, starting at position (x,y) with a given maximal width. |
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
976 |
* String is truncated if it is too long. |
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
977 |
* |
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
978 |
* @param str Character buffer containing the string |
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
979 |
* @param x Left-most x coordinate to start drawing |
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
980 |
* @param y Y coordinate to draw the string |
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
981 |
* @param color Colour to use, see DoDrawString() for details. |
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
982 |
* @param maxw Maximal width in pixels that may be used for drawing |
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
983 |
* |
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
984 |
* @return Right-most x position after drawing the (possibly truncated) string |
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
985 |
*/ |
2097
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
986 |
int DoDrawStringTruncated(const char *str, int x, int y, uint16 color, uint maxw) |
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
987 |
{ |
9901
602720bd2d53
(svn r14051) -Codechange: enumify the DrawString buffer length.
rubidium
parents:
9900
diff
changeset
|
988 |
char buffer[DRAW_STRING_BUFFER]; |
10310
ca2eb5811a07
(svn r14555) -Codechange: replace ttd_strlcat and ttd_strlcpy with strecat and strecpy where direct conversion is possible
skidd13
parents:
10278
diff
changeset
|
989 |
strecpy(buffer, str, lastof(buffer)); |
2097
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
990 |
TruncateString(buffer, maxw); |
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
991 |
return DoDrawString(buffer, x, y, color); |
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
992 |
} |
e95d19e1941f
(svn r2607) - Feature: add support for truncating strings to a given (pixel) length. Function courtesy of Ludde.
Darkvater
parents:
2062
diff
changeset
|
993 |
|
9773
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
994 |
/** |
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
995 |
* Draw a sprite. |
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
996 |
* @param img Image number to draw |
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
997 |
* @param pal Palette to use. |
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
998 |
* @param x Left coordinate of image |
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
999 |
* @param y Top coordinate of image |
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
1000 |
* @param sub If available, draw only specified part of the sprite |
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
1001 |
*/ |
7681
582e8912e8d1
(svn r11212) -Codechange: add support for drawing parts of sprites. Patch by frosch.
rubidium
parents:
7651
diff
changeset
|
1002 |
void DrawSprite(SpriteID img, SpriteID pal, int x, int y, const SubSprite *sub) |
2010 | 1003 |
{ |
7928
63e18de69e50
(svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents:
7927
diff
changeset
|
1004 |
if (HasBit(img, PALETTE_MODIFIER_TRANSPARENT)) { |
10056
48659f7d4fa5
(svn r14223) -Codechange: make GetSprite aware of the 4 different types of sprites: fonts, recolour, mapgen and normal sprites.
rubidium
parents:
9989
diff
changeset
|
1005 |
_color_remap_ptr = GetNonSprite(GB(pal, 0, PALETTE_WIDTH), ST_RECOLOUR) + 1; |
48659f7d4fa5
(svn r14223) -Codechange: make GetSprite aware of the 4 different types of sprites: fonts, recolour, mapgen and normal sprites.
rubidium
parents:
9989
diff
changeset
|
1006 |
GfxMainBlitter(GetSprite(GB(img, 0, SPRITE_WIDTH), ST_NORMAL), x, y, BM_TRANSPARENT, sub); |
5668
36b39f4a9032
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5636
diff
changeset
|
1007 |
} else if (pal != PAL_NONE) { |
10056
48659f7d4fa5
(svn r14223) -Codechange: make GetSprite aware of the 4 different types of sprites: fonts, recolour, mapgen and normal sprites.
rubidium
parents:
9989
diff
changeset
|
1008 |
_color_remap_ptr = GetNonSprite(GB(pal, 0, PALETTE_WIDTH), ST_RECOLOUR) + 1; |
48659f7d4fa5
(svn r14223) -Codechange: make GetSprite aware of the 4 different types of sprites: fonts, recolour, mapgen and normal sprites.
rubidium
parents:
9989
diff
changeset
|
1009 |
GfxMainBlitter(GetSprite(GB(img, 0, SPRITE_WIDTH), ST_NORMAL), x, y, BM_COLOUR_REMAP, sub); |
0 | 1010 |
} else { |
10056
48659f7d4fa5
(svn r14223) -Codechange: make GetSprite aware of the 4 different types of sprites: fonts, recolour, mapgen and normal sprites.
rubidium
parents:
9989
diff
changeset
|
1011 |
GfxMainBlitter(GetSprite(GB(img, 0, SPRITE_WIDTH), ST_NORMAL), x, y, BM_NORMAL, sub); |
0 | 1012 |
} |
1013 |
} |
|
1014 |
||
9511
b6465bcb7e9b
(svn r13502) -Fix (r11212): drawing of zoomed out partial sprites could cause deadlocks or crashes
smatz
parents:
9413
diff
changeset
|
1015 |
static void GfxMainBlitter(const Sprite *sprite, int x, int y, BlitterMode mode, const SubSprite *sub) |
0 | 1016 |
{ |
4171 | 1017 |
const DrawPixelInfo *dpi = _cur_dpi; |
6852
439563b70fd3
(svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
6831
diff
changeset
|
1018 |
Blitter::BlitterParams bp; |
0 | 1019 |
|
7681
582e8912e8d1
(svn r11212) -Codechange: add support for drawing parts of sprites. Patch by frosch.
rubidium
parents:
7651
diff
changeset
|
1020 |
/* Amount of pixels to clip from the source sprite */ |
582e8912e8d1
(svn r11212) -Codechange: add support for drawing parts of sprites. Patch by frosch.
rubidium
parents:
7651
diff
changeset
|
1021 |
int clip_left = (sub != NULL ? max(0, -sprite->x_offs + sub->left ) : 0); |
582e8912e8d1
(svn r11212) -Codechange: add support for drawing parts of sprites. Patch by frosch.
rubidium
parents:
7651
diff
changeset
|
1022 |
int clip_top = (sub != NULL ? max(0, -sprite->y_offs + sub->top ) : 0); |
582e8912e8d1
(svn r11212) -Codechange: add support for drawing parts of sprites. Patch by frosch.
rubidium
parents:
7651
diff
changeset
|
1023 |
int clip_right = (sub != NULL ? max(0, sprite->width - (-sprite->x_offs + sub->right + 1)) : 0); |
582e8912e8d1
(svn r11212) -Codechange: add support for drawing parts of sprites. Patch by frosch.
rubidium
parents:
7651
diff
changeset
|
1024 |
int clip_bottom = (sub != NULL ? max(0, sprite->height - (-sprite->y_offs + sub->bottom + 1)) : 0); |
582e8912e8d1
(svn r11212) -Codechange: add support for drawing parts of sprites. Patch by frosch.
rubidium
parents:
7651
diff
changeset
|
1025 |
|
582e8912e8d1
(svn r11212) -Codechange: add support for drawing parts of sprites. Patch by frosch.
rubidium
parents:
7651
diff
changeset
|
1026 |
if (clip_left + clip_right >= sprite->width) return; |
582e8912e8d1
(svn r11212) -Codechange: add support for drawing parts of sprites. Patch by frosch.
rubidium
parents:
7651
diff
changeset
|
1027 |
if (clip_top + clip_bottom >= sprite->height) return; |
582e8912e8d1
(svn r11212) -Codechange: add support for drawing parts of sprites. Patch by frosch.
rubidium
parents:
7651
diff
changeset
|
1028 |
|
6852
439563b70fd3
(svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
6831
diff
changeset
|
1029 |
/* Move to the correct offset */ |
1351
a08ab043dd08
(svn r1855) Handle endianness of sprite headers when loading a sprite, not everytime when accessing it
tron
parents:
1350
diff
changeset
|
1030 |
x += sprite->x_offs; |
a08ab043dd08
(svn r1855) Handle endianness of sprite headers when loading a sprite, not everytime when accessing it
tron
parents:
1350
diff
changeset
|
1031 |
y += sprite->y_offs; |
6852
439563b70fd3
(svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
6831
diff
changeset
|
1032 |
|
439563b70fd3
(svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
6831
diff
changeset
|
1033 |
/* Copy the main data directly from the sprite */ |
4518 | 1034 |
bp.sprite = sprite->data; |
6852
439563b70fd3
(svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
6831
diff
changeset
|
1035 |
bp.sprite_width = sprite->width; |
439563b70fd3
(svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
6831
diff
changeset
|
1036 |
bp.sprite_height = sprite->height; |
7681
582e8912e8d1
(svn r11212) -Codechange: add support for drawing parts of sprites. Patch by frosch.
rubidium
parents:
7651
diff
changeset
|
1037 |
bp.width = UnScaleByZoom(sprite->width - clip_left - clip_right, dpi->zoom); |
582e8912e8d1
(svn r11212) -Codechange: add support for drawing parts of sprites. Patch by frosch.
rubidium
parents:
7651
diff
changeset
|
1038 |
bp.height = UnScaleByZoom(sprite->height - clip_top - clip_bottom, dpi->zoom); |
6852
439563b70fd3
(svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
6831
diff
changeset
|
1039 |
bp.top = 0; |
439563b70fd3
(svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
6831
diff
changeset
|
1040 |
bp.left = 0; |
9511
b6465bcb7e9b
(svn r13502) -Fix (r11212): drawing of zoomed out partial sprites could cause deadlocks or crashes
smatz
parents:
9413
diff
changeset
|
1041 |
bp.skip_left = UnScaleByZoomLower(clip_left, dpi->zoom); |
b6465bcb7e9b
(svn r13502) -Fix (r11212): drawing of zoomed out partial sprites could cause deadlocks or crashes
smatz
parents:
9413
diff
changeset
|
1042 |
bp.skip_top = UnScaleByZoomLower(clip_top, dpi->zoom); |
7681
582e8912e8d1
(svn r11212) -Codechange: add support for drawing parts of sprites. Patch by frosch.
rubidium
parents:
7651
diff
changeset
|
1043 |
|
582e8912e8d1
(svn r11212) -Codechange: add support for drawing parts of sprites. Patch by frosch.
rubidium
parents:
7651
diff
changeset
|
1044 |
x += ScaleByZoom(bp.skip_left, dpi->zoom); |
582e8912e8d1
(svn r11212) -Codechange: add support for drawing parts of sprites. Patch by frosch.
rubidium
parents:
7651
diff
changeset
|
1045 |
y += ScaleByZoom(bp.skip_top, dpi->zoom); |
582e8912e8d1
(svn r11212) -Codechange: add support for drawing parts of sprites. Patch by frosch.
rubidium
parents:
7651
diff
changeset
|
1046 |
|
0 | 1047 |
bp.dst = dpi->dst_ptr; |
1048 |
bp.pitch = dpi->pitch; |
|
6852
439563b70fd3
(svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
6831
diff
changeset
|
1049 |
bp.remap = _color_remap_ptr; |
0 | 1050 |
|
6852
439563b70fd3
(svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
6831
diff
changeset
|
1051 |
assert(sprite->width > 0); |
439563b70fd3
(svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
6831
diff
changeset
|
1052 |
assert(sprite->height > 0); |
439563b70fd3
(svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
6831
diff
changeset
|
1053 |
|
439563b70fd3
(svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
6831
diff
changeset
|
1054 |
if (bp.width <= 0) return; |
439563b70fd3
(svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
6831
diff
changeset
|
1055 |
if (bp.height <= 0) return; |
439563b70fd3
(svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
6831
diff
changeset
|
1056 |
|
439563b70fd3
(svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
6831
diff
changeset
|
1057 |
y -= dpi->top; |
439563b70fd3
(svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
6831
diff
changeset
|
1058 |
/* Check for top overflow */ |
439563b70fd3
(svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
6831
diff
changeset
|
1059 |
if (y < 0) { |
439563b70fd3
(svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
6831
diff
changeset
|
1060 |
bp.height -= -UnScaleByZoom(y, dpi->zoom); |
439563b70fd3
(svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
6831
diff
changeset
|
1061 |
if (bp.height <= 0) return; |
439563b70fd3
(svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
6831
diff
changeset
|
1062 |
bp.skip_top += -UnScaleByZoom(y, dpi->zoom); |
439563b70fd3
(svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
6831
diff
changeset
|
1063 |
y = 0; |
439563b70fd3
(svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
6831
diff
changeset
|
1064 |
} else { |
439563b70fd3
(svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
6831
diff
changeset
|
1065 |
bp.top = UnScaleByZoom(y, dpi->zoom); |
6804
0d8d33842119
(svn r10043) -Change: make templates of the blitters, based on zoom and mode, which makes the optimizing better, and therefor a higher blitter speed (tnx boekabart)
truelight
parents:
6653
diff
changeset
|
1066 |
} |
0 | 1067 |
|
6852
439563b70fd3
(svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
6831
diff
changeset
|
1068 |
/* Check for bottom overflow */ |
439563b70fd3
(svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
6831
diff
changeset
|
1069 |
y += ScaleByZoom(bp.height, dpi->zoom) - dpi->height; |
439563b70fd3
(svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
6831
diff
changeset
|
1070 |
if (y > 0) { |
439563b70fd3
(svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
6831
diff
changeset
|
1071 |
bp.height -= UnScaleByZoom(y, dpi->zoom); |
6804
0d8d33842119
(svn r10043) -Change: make templates of the blitters, based on zoom and mode, which makes the optimizing better, and therefor a higher blitter speed (tnx boekabart)
truelight
parents:
6653
diff
changeset
|
1072 |
if (bp.height <= 0) return; |
0d8d33842119
(svn r10043) -Change: make templates of the blitters, based on zoom and mode, which makes the optimizing better, and therefor a higher blitter speed (tnx boekabart)
truelight
parents:
6653
diff
changeset
|
1073 |
} |
0d8d33842119
(svn r10043) -Change: make templates of the blitters, based on zoom and mode, which makes the optimizing better, and therefor a higher blitter speed (tnx boekabart)
truelight
parents:
6653
diff
changeset
|
1074 |
|
6852
439563b70fd3
(svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
6831
diff
changeset
|
1075 |
x -= dpi->left; |
439563b70fd3
(svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
6831
diff
changeset
|
1076 |
/* Check for left overflow */ |
439563b70fd3
(svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
6831
diff
changeset
|
1077 |
if (x < 0) { |
439563b70fd3
(svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
6831
diff
changeset
|
1078 |
bp.width -= -UnScaleByZoom(x, dpi->zoom); |
6804
0d8d33842119
(svn r10043) -Change: make templates of the blitters, based on zoom and mode, which makes the optimizing better, and therefor a higher blitter speed (tnx boekabart)
truelight
parents:
6653
diff
changeset
|
1079 |
if (bp.width <= 0) return; |
6852
439563b70fd3
(svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
6831
diff
changeset
|
1080 |
bp.skip_left += -UnScaleByZoom(x, dpi->zoom); |
6804
0d8d33842119
(svn r10043) -Change: make templates of the blitters, based on zoom and mode, which makes the optimizing better, and therefor a higher blitter speed (tnx boekabart)
truelight
parents:
6653
diff
changeset
|
1081 |
x = 0; |
6852
439563b70fd3
(svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
6831
diff
changeset
|
1082 |
} else { |
439563b70fd3
(svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
6831
diff
changeset
|
1083 |
bp.left = UnScaleByZoom(x, dpi->zoom); |
6804
0d8d33842119
(svn r10043) -Change: make templates of the blitters, based on zoom and mode, which makes the optimizing better, and therefor a higher blitter speed (tnx boekabart)
truelight
parents:
6653
diff
changeset
|
1084 |
} |
0d8d33842119
(svn r10043) -Change: make templates of the blitters, based on zoom and mode, which makes the optimizing better, and therefor a higher blitter speed (tnx boekabart)
truelight
parents:
6653
diff
changeset
|
1085 |
|
6852
439563b70fd3
(svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
6831
diff
changeset
|
1086 |
/* Check for right overflow */ |
439563b70fd3
(svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
6831
diff
changeset
|
1087 |
x += ScaleByZoom(bp.width, dpi->zoom) - dpi->width; |
439563b70fd3
(svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
6831
diff
changeset
|
1088 |
if (x > 0) { |
439563b70fd3
(svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
6831
diff
changeset
|
1089 |
bp.width -= UnScaleByZoom(x, dpi->zoom); |
6804
0d8d33842119
(svn r10043) -Change: make templates of the blitters, based on zoom and mode, which makes the optimizing better, and therefor a higher blitter speed (tnx boekabart)
truelight
parents:
6653
diff
changeset
|
1090 |
if (bp.width <= 0) return; |
0d8d33842119
(svn r10043) -Change: make templates of the blitters, based on zoom and mode, which makes the optimizing better, and therefor a higher blitter speed (tnx boekabart)
truelight
parents:
6653
diff
changeset
|
1091 |
} |
0d8d33842119
(svn r10043) -Change: make templates of the blitters, based on zoom and mode, which makes the optimizing better, and therefor a higher blitter speed (tnx boekabart)
truelight
parents:
6653
diff
changeset
|
1092 |
|
9511
b6465bcb7e9b
(svn r13502) -Fix (r11212): drawing of zoomed out partial sprites could cause deadlocks or crashes
smatz
parents:
9413
diff
changeset
|
1093 |
assert(bp.skip_left + bp.width <= UnScaleByZoom(sprite->width, dpi->zoom)); |
b6465bcb7e9b
(svn r13502) -Fix (r11212): drawing of zoomed out partial sprites could cause deadlocks or crashes
smatz
parents:
9413
diff
changeset
|
1094 |
assert(bp.skip_top + bp.height <= UnScaleByZoom(sprite->height, dpi->zoom)); |
b6465bcb7e9b
(svn r13502) -Fix (r11212): drawing of zoomed out partial sprites could cause deadlocks or crashes
smatz
parents:
9413
diff
changeset
|
1095 |
|
6852
439563b70fd3
(svn r10092) -Codechange: code-seperated the spriteloader and blitter from the rest of the code
truelight
parents:
6831
diff
changeset
|
1096 |
BlitterFactoryBase::GetCurrentBlitter()->Draw(&bp, mode, dpi->zoom); |
0 | 1097 |
} |
1098 |
||
6247 | 1099 |
void DoPaletteAnimations(); |
614
b96f987dbf80
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
543
diff
changeset
|
1100 |
|
6247 | 1101 |
void GfxInitPalettes() |
0 | 1102 |
{ |
9989
62e68bd41c90
(svn r14146) -Codechange: allow palette override in both ways and remove some unneeded '(x == 0) ? 0 : 1' constructs.
rubidium
parents:
9911
diff
changeset
|
1103 |
memcpy(_cur_palette, _palettes[_use_palette], sizeof(_cur_palette)); |
614
b96f987dbf80
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
543
diff
changeset
|
1104 |
|
6964
500951fcc645
(svn r10220) -Fix r10216: even more fuck-ups for non-SDL video backends
truelight
parents:
6960
diff
changeset
|
1105 |
DoPaletteAnimations(); |
0 | 1106 |
_pal_first_dirty = 0; |
7392
0964cfefbe64
(svn r10761) -Fix (FS#1101, r10216): _pal_last_dirty changed to _pal_count_dirty without updating, so it was of by one
glx
parents:
7362
diff
changeset
|
1107 |
_pal_count_dirty = 256; |
0 | 1108 |
} |
1109 |
||
7018
71e174292e42
(svn r10276) -Codechange: made a counter based on milliseconds and independent of the game-state to base double-click and TGP Generation Process on
truelight
parents:
6999
diff
changeset
|
1110 |
#define EXTR(p, q) (((uint16)(_palette_animation_counter * (p)) * (q)) >> 16) |
71e174292e42
(svn r10276) -Codechange: made a counter based on milliseconds and independent of the game-state to base double-click and TGP Generation Process on
truelight
parents:
6999
diff
changeset
|
1111 |
#define EXTR2(p, q) (((uint16)(~_palette_animation_counter * (p)) * (q)) >> 16) |
0 | 1112 |
|
6247 | 1113 |
void DoPaletteAnimations() |
0 | 1114 |
{ |
6960
356d856462b6
(svn r10216) -Fix: palette animation always redid all palette entries, where in fact only a few indexes were needed
truelight
parents:
6951
diff
changeset
|
1115 |
Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter(); |
4171 | 1116 |
const Colour *s; |
9911
7cfcf47b372d
(svn r14061) -Codechange: constification and move a declaration more logically
belugas
parents:
9904
diff
changeset
|
1117 |
const ExtraPaletteValues *ev = &_extra_palette_values; |
614
b96f987dbf80
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
543
diff
changeset
|
1118 |
/* Amount of colors to be rotated. |
b96f987dbf80
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
543
diff
changeset
|
1119 |
* A few more for the DOS palette, because the water colors are |
b96f987dbf80
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
543
diff
changeset
|
1120 |
* 245-254 for DOS and 217-226 for Windows. */ |
9989
62e68bd41c90
(svn r14146) -Codechange: allow palette override in both ways and remove some unneeded '(x == 0) ? 0 : 1' constructs.
rubidium
parents:
9911
diff
changeset
|
1121 |
const int colour_rotation_amount = (_use_palette == PAL_DOS) ? PALETTE_ANIM_SIZE_DOS : PALETTE_ANIM_SIZE_WIN; |
9870
0aade3ddf995
(svn r14016) -Codechange: Remove some magical numbers
belugas
parents:
9850
diff
changeset
|
1122 |
Colour old_val[PALETTE_ANIM_SIZE_DOS]; |
9900
2d46371cbad7
(svn r14049) -Codechange: rename a variable to a somewhat more descriptive one. And constify it too.
belugas
parents:
9898
diff
changeset
|
1123 |
const int oldval_size = colour_rotation_amount * sizeof(*old_val); |
9911
7cfcf47b372d
(svn r14061) -Codechange: constification and move a declaration more logically
belugas
parents:
9904
diff
changeset
|
1124 |
const uint old_tc = _palette_animation_counter; |
2005 | 1125 |
uint i; |
1126 |
uint j; |
|
6878
5cefd3ac59c7
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
6852
diff
changeset
|
1127 |
|
6960
356d856462b6
(svn r10216) -Fix: palette animation always redid all palette entries, where in fact only a few indexes were needed
truelight
parents:
6951
diff
changeset
|
1128 |
if (blitter != NULL && blitter->UsePaletteAnimation() == Blitter::PALETTE_ANIMATION_NONE) { |
7018
71e174292e42
(svn r10276) -Codechange: made a counter based on milliseconds and independent of the game-state to base double-click and TGP Generation Process on
truelight
parents:
6999
diff
changeset
|
1129 |
_palette_animation_counter = 0; |
6878
5cefd3ac59c7
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
6852
diff
changeset
|
1130 |
} |
0 | 1131 |
|
9895
f1aa2d783739
(svn r14043) -Codechange: Rename a variable to a more obvious name. And a few comments added too.
belugas
parents:
9894
diff
changeset
|
1132 |
Colour *palette_pos = &_cur_palette[PALETTE_ANIM_SIZE_START]; // Points to where animations are taking place on the palette |
f1aa2d783739
(svn r14043) -Codechange: Rename a variable to a more obvious name. And a few comments added too.
belugas
parents:
9894
diff
changeset
|
1133 |
/* Makes a copy of the current anmation palette in old_val, |
f1aa2d783739
(svn r14043) -Codechange: Rename a variable to a more obvious name. And a few comments added too.
belugas
parents:
9894
diff
changeset
|
1134 |
* so the work on the current palette could be compared, see if there has been any changes */ |
9900
2d46371cbad7
(svn r14049) -Codechange: rename a variable to a somewhat more descriptive one. And constify it too.
belugas
parents:
9898
diff
changeset
|
1135 |
memcpy(old_val, palette_pos, oldval_size); |
0 | 1136 |
|
6179
d19b0137d8e4
(svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6138
diff
changeset
|
1137 |
/* Dark blue water */ |
9894
530e5e689612
(svn r14042) -Codechange: Rename some structure members to more obvious names. And add a few comments on the _extra_palette_values array.
belugas
parents:
9882
diff
changeset
|
1138 |
s = (_settings_game.game_creation.landscape == LT_TOYLAND) ? ev->dark_water_TOY : ev->dark_water; |
2005 | 1139 |
j = EXTR(320, 5); |
1140 |
for (i = 0; i != 5; i++) { |
|
9895
f1aa2d783739
(svn r14043) -Codechange: Rename a variable to a more obvious name. And a few comments added too.
belugas
parents:
9894
diff
changeset
|
1141 |
*palette_pos++ = s[j]; |
1991
4ce69ba880b4
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1142 |
j++; |
4ce69ba880b4
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1143 |
if (j == 5) j = 0; |
0 | 1144 |
} |
1145 |
||
6179
d19b0137d8e4
(svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6138
diff
changeset
|
1146 |
/* Glittery water */ |
9894
530e5e689612
(svn r14042) -Codechange: Rename some structure members to more obvious names. And add a few comments on the _extra_palette_values array.
belugas
parents:
9882
diff
changeset
|
1147 |
s = (_settings_game.game_creation.landscape == LT_TOYLAND) ? ev->glitter_water_TOY : ev->glitter_water; |
1991
4ce69ba880b4
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1148 |
j = EXTR(128, 15); |
2005 | 1149 |
for (i = 0; i != 5; i++) { |
9895
f1aa2d783739
(svn r14043) -Codechange: Rename a variable to a more obvious name. And a few comments added too.
belugas
parents:
9894
diff
changeset
|
1150 |
*palette_pos++ = s[j]; |
1991
4ce69ba880b4
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1151 |
j += 3; |
4ce69ba880b4
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1152 |
if (j >= 15) j -= 15; |
0 | 1153 |
} |
1154 |
||
9894
530e5e689612
(svn r14042) -Codechange: Rename some structure members to more obvious names. And add a few comments on the _extra_palette_values array.
belugas
parents:
9882
diff
changeset
|
1155 |
/* Fizzy Drink bubbles animation */ |
530e5e689612
(svn r14042) -Codechange: Rename some structure members to more obvious names. And add a few comments on the _extra_palette_values array.
belugas
parents:
9882
diff
changeset
|
1156 |
s = ev->fizzy_drink; |
1991
4ce69ba880b4
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1157 |
j = EXTR2(512, 5); |
2005 | 1158 |
for (i = 0; i != 5; i++) { |
9895
f1aa2d783739
(svn r14043) -Codechange: Rename a variable to a more obvious name. And a few comments added too.
belugas
parents:
9894
diff
changeset
|
1159 |
*palette_pos++ = s[j]; |
1991
4ce69ba880b4
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1160 |
j++; |
4ce69ba880b4
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1161 |
if (j == 5) j = 0; |
0 | 1162 |
} |
1163 |
||
6179
d19b0137d8e4
(svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6138
diff
changeset
|
1164 |
/* Oil refinery fire animation */ |
0 | 1165 |
s = ev->oil_ref; |
1991
4ce69ba880b4
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1166 |
j = EXTR2(512, 7); |
2005 | 1167 |
for (i = 0; i != 7; i++) { |
9895
f1aa2d783739
(svn r14043) -Codechange: Rename a variable to a more obvious name. And a few comments added too.
belugas
parents:
9894
diff
changeset
|
1168 |
*palette_pos++ = s[j]; |
1991
4ce69ba880b4
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1169 |
j++; |
4ce69ba880b4
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1170 |
if (j == 7) j = 0; |
0 | 1171 |
} |
1172 |
||
6179
d19b0137d8e4
(svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6138
diff
changeset
|
1173 |
/* Radio tower blinking */ |
0 | 1174 |
{ |
7018
71e174292e42
(svn r10276) -Codechange: made a counter based on milliseconds and independent of the game-state to base double-click and TGP Generation Process on
truelight
parents:
6999
diff
changeset
|
1175 |
byte i = (_palette_animation_counter >> 1) & 0x7F; |
2005 | 1176 |
byte v; |
1177 |
||
0 | 1178 |
(v = 255, i < 0x3f) || |
1179 |
(v = 128, i < 0x4A || i >= 0x75) || |
|
1180 |
(v = 20); |
|
9895
f1aa2d783739
(svn r14043) -Codechange: Rename a variable to a more obvious name. And a few comments added too.
belugas
parents:
9894
diff
changeset
|
1181 |
palette_pos->r = v; |
f1aa2d783739
(svn r14043) -Codechange: Rename a variable to a more obvious name. And a few comments added too.
belugas
parents:
9894
diff
changeset
|
1182 |
palette_pos->g = 0; |
f1aa2d783739
(svn r14043) -Codechange: Rename a variable to a more obvious name. And a few comments added too.
belugas
parents:
9894
diff
changeset
|
1183 |
palette_pos->b = 0; |
f1aa2d783739
(svn r14043) -Codechange: Rename a variable to a more obvious name. And a few comments added too.
belugas
parents:
9894
diff
changeset
|
1184 |
palette_pos++; |
0 | 1185 |
|
1186 |
i ^= 0x40; |
|
1187 |
(v = 255, i < 0x3f) || |
|
1188 |
(v = 128, i < 0x4A || i >= 0x75) || |
|
1189 |
(v = 20); |
|
9895
f1aa2d783739
(svn r14043) -Codechange: Rename a variable to a more obvious name. And a few comments added too.
belugas
parents:
9894
diff
changeset
|
1190 |
palette_pos->r = v; |
f1aa2d783739
(svn r14043) -Codechange: Rename a variable to a more obvious name. And a few comments added too.
belugas
parents:
9894
diff
changeset
|
1191 |
palette_pos->g = 0; |
f1aa2d783739
(svn r14043) -Codechange: Rename a variable to a more obvious name. And a few comments added too.
belugas
parents:
9894
diff
changeset
|
1192 |
palette_pos->b = 0; |
f1aa2d783739
(svn r14043) -Codechange: Rename a variable to a more obvious name. And a few comments added too.
belugas
parents:
9894
diff
changeset
|
1193 |
palette_pos++; |
0 | 1194 |
} |
1195 |
||
6179
d19b0137d8e4
(svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6138
diff
changeset
|
1196 |
/* Handle lighthouse and stadium animation */ |
0 | 1197 |
s = ev->lighthouse; |
1991
4ce69ba880b4
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1198 |
j = EXTR(256, 4); |
2005 | 1199 |
for (i = 0; i != 4; i++) { |
9895
f1aa2d783739
(svn r14043) -Codechange: Rename a variable to a more obvious name. And a few comments added too.
belugas
parents:
9894
diff
changeset
|
1200 |
*palette_pos++ = s[j]; |
1991
4ce69ba880b4
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1201 |
j++; |
4ce69ba880b4
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1202 |
if (j == 4) j = 0; |
0 | 1203 |
} |
1204 |
||
6179
d19b0137d8e4
(svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6138
diff
changeset
|
1205 |
/* Animate water for old DOS graphics */ |
9989
62e68bd41c90
(svn r14146) -Codechange: allow palette override in both ways and remove some unneeded '(x == 0) ? 0 : 1' constructs.
rubidium
parents:
9911
diff
changeset
|
1206 |
if (_use_palette == PAL_DOS) { |
6179
d19b0137d8e4
(svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6138
diff
changeset
|
1207 |
/* Dark blue water DOS */ |
9894
530e5e689612
(svn r14042) -Codechange: Rename some structure members to more obvious names. And add a few comments on the _extra_palette_values array.
belugas
parents:
9882
diff
changeset
|
1208 |
s = (_settings_game.game_creation.landscape == LT_TOYLAND) ? ev->dark_water_TOY : ev->dark_water; |
2005 | 1209 |
j = EXTR(320, 5); |
1210 |
for (i = 0; i != 5; i++) { |
|
9895
f1aa2d783739
(svn r14043) -Codechange: Rename a variable to a more obvious name. And a few comments added too.
belugas
parents:
9894
diff
changeset
|
1211 |
*palette_pos++ = s[j]; |
1991
4ce69ba880b4
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1212 |
j++; |
4ce69ba880b4
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1213 |
if (j == 5) j = 0; |
614
b96f987dbf80
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
543
diff
changeset
|
1214 |
} |
915 | 1215 |
|
6179
d19b0137d8e4
(svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6138
diff
changeset
|
1216 |
/* Glittery water DOS */ |
9894
530e5e689612
(svn r14042) -Codechange: Rename some structure members to more obvious names. And add a few comments on the _extra_palette_values array.
belugas
parents:
9882
diff
changeset
|
1217 |
s = (_settings_game.game_creation.landscape == LT_TOYLAND) ? ev->glitter_water_TOY : ev->glitter_water; |
1991
4ce69ba880b4
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1218 |
j = EXTR(128, 15); |
2005 | 1219 |
for (i = 0; i != 5; i++) { |
9895
f1aa2d783739
(svn r14043) -Codechange: Rename a variable to a more obvious name. And a few comments added too.
belugas
parents:
9894
diff
changeset
|
1220 |
*palette_pos++ = s[j]; |
1991
4ce69ba880b4
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1221 |
j += 3; |
4ce69ba880b4
(svn r2497) Use a struct array for palette entries instead of a flat byte array
tron
parents:
1914
diff
changeset
|
1222 |
if (j >= 15) j -= 15; |
614
b96f987dbf80
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
543
diff
changeset
|
1223 |
} |
b96f987dbf80
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
543
diff
changeset
|
1224 |
} |
b96f987dbf80
(svn r1038) Feature: OpenTTD runs with the grf files of the DOS version
dominik
parents:
543
diff
changeset
|
1225 |
|
6960
356d856462b6
(svn r10216) -Fix: palette animation always redid all palette entries, where in fact only a few indexes were needed
truelight
parents:
6951
diff
changeset
|
1226 |
if (blitter != NULL && blitter->UsePaletteAnimation() == Blitter::PALETTE_ANIMATION_NONE) { |
7018
71e174292e42
(svn r10276) -Codechange: made a counter based on milliseconds and independent of the game-state to base double-click and TGP Generation Process on
truelight
parents:
6999
diff
changeset
|
1227 |
_palette_animation_counter = old_tc; |
6960
356d856462b6
(svn r10216) -Fix: palette animation always redid all palette entries, where in fact only a few indexes were needed
truelight
parents:
6951
diff
changeset
|
1228 |
} else { |
9900
2d46371cbad7
(svn r14049) -Codechange: rename a variable to a somewhat more descriptive one. And constify it too.
belugas
parents:
9898
diff
changeset
|
1229 |
if (memcmp(old_val, &_cur_palette[PALETTE_ANIM_SIZE_START], oldval_size) != 0) { |
9895
f1aa2d783739
(svn r14043) -Codechange: Rename a variable to a more obvious name. And a few comments added too.
belugas
parents:
9894
diff
changeset
|
1230 |
/* Did we changed anything on the palette? Seems so. Mark it as dirty */ |
9870
0aade3ddf995
(svn r14016) -Codechange: Remove some magical numbers
belugas
parents:
9850
diff
changeset
|
1231 |
_pal_first_dirty = PALETTE_ANIM_SIZE_START; |
9900
2d46371cbad7
(svn r14049) -Codechange: rename a variable to a somewhat more descriptive one. And constify it too.
belugas
parents:
9898
diff
changeset
|
1232 |
_pal_count_dirty = colour_rotation_amount; |
6960
356d856462b6
(svn r10216) -Fix: palette animation always redid all palette entries, where in fact only a few indexes were needed
truelight
parents:
6951
diff
changeset
|
1233 |
} |
0 | 1234 |
} |
1235 |
} |
|
1236 |
||
1237 |
||
9773
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
1238 |
/** Initialize _stringwidth_table cache */ |
6247 | 1239 |
void LoadStringWidthTable() |
0 | 1240 |
{ |
2005 | 1241 |
uint i; |
0 | 1242 |
|
3797
db2306464bbe
(svn r4793) - Replace list of magic numbers (characters that don't exist) with a call to SpriteExists(), when building the character width cache.
peter1138
parents:
3312
diff
changeset
|
1243 |
/* Normal font */ |
3798
b1f5290b36b1
(svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents:
3797
diff
changeset
|
1244 |
for (i = 0; i != 224; i++) { |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
1245 |
_stringwidth_table[FS_NORMAL][i] = GetGlyphWidth(FS_NORMAL, i + 32); |
0 | 1246 |
} |
1247 |
||
3797
db2306464bbe
(svn r4793) - Replace list of magic numbers (characters that don't exist) with a call to SpriteExists(), when building the character width cache.
peter1138
parents:
3312
diff
changeset
|
1248 |
/* Small font */ |
3798
b1f5290b36b1
(svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents:
3797
diff
changeset
|
1249 |
for (i = 0; i != 224; i++) { |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
1250 |
_stringwidth_table[FS_SMALL][i] = GetGlyphWidth(FS_SMALL, i + 32); |
0 | 1251 |
} |
1252 |
||
3797
db2306464bbe
(svn r4793) - Replace list of magic numbers (characters that don't exist) with a call to SpriteExists(), when building the character width cache.
peter1138
parents:
3312
diff
changeset
|
1253 |
/* Large font */ |
3798
b1f5290b36b1
(svn r4802) - Codechange: replace _stringwidth_base and associated magic numbers with a FontSize enum, using the numbers (which are SpriteIDs) in only the places needed.
peter1138
parents:
3797
diff
changeset
|
1254 |
for (i = 0; i != 224; i++) { |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
1255 |
_stringwidth_table[FS_LARGE][i] = GetGlyphWidth(FS_LARGE, i + 32); |
0 | 1256 |
} |
1257 |
} |
|
1258 |
||
9773
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
1259 |
/** |
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
1260 |
* Return width of character glyph. |
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
1261 |
* @param size Font of the character |
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
1262 |
* @param key Character code glyph |
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
1263 |
* @return Width of the character glyph |
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
1264 |
*/ |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
1265 |
byte GetCharacterWidth(FontSize size, WChar key) |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
1266 |
{ |
9773
fd7309d22bc6
(svn r13910) -Document: string drawing related functions and types (Alberth)
rubidium
parents:
9682
diff
changeset
|
1267 |
/* Use _stringwidth_table cache if possible */ |
5108
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
1268 |
if (key >= 32 && key < 256) return _stringwidth_table[size][key - 32]; |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
1269 |
|
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
1270 |
return GetGlyphWidth(size, key); |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
1271 |
} |
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
1272 |
|
aeaef6fe53b7
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
4958
diff
changeset
|
1273 |
|
6247 | 1274 |
void ScreenSizeChanged() |
0 | 1275 |
{ |
8985
6461e5c6d6e4
(svn r12779) -Codechange: remove a few constants from openttd.h.
rubidium
parents:
8981
diff
changeset
|
1276 |
_dirty_bytes_per_line = (_screen.width + DIRTY_BLOCK_WIDTH - 1) / DIRTY_BLOCK_WIDTH; |
6461e5c6d6e4
(svn r12779) -Codechange: remove a few constants from openttd.h.
rubidium
parents:
8981
diff
changeset
|
1277 |
_dirty_blocks = ReallocT<byte>(_dirty_blocks, _dirty_bytes_per_line * ((_screen.height + DIRTY_BLOCK_HEIGHT - 1) / DIRTY_BLOCK_HEIGHT)); |
6461e5c6d6e4
(svn r12779) -Codechange: remove a few constants from openttd.h.
rubidium
parents:
8981
diff
changeset
|
1278 |
|
6179
d19b0137d8e4
(svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6138
diff
changeset
|
1279 |
/* check the dirty rect */ |
0 | 1280 |
if (_invalid_rect.right >= _screen.width) _invalid_rect.right = _screen.width; |
1281 |
if (_invalid_rect.bottom >= _screen.height) _invalid_rect.bottom = _screen.height; |
|
1282 |
||
6179
d19b0137d8e4
(svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6138
diff
changeset
|
1283 |
/* screen size changed and the old bitmap is invalid now, so we don't want to undraw it */ |
0 | 1284 |
_cursor.visible = false; |
1285 |
} |
|
1286 |
||
6247 | 1287 |
void UndrawMouseCursor() |
0 | 1288 |
{ |
1289 |
if (_cursor.visible) { |
|
6937
40c760fcf1f6
(svn r10190) -Codechange: merged renderer and blitter to one single class API: blitter
truelight
parents:
6889
diff
changeset
|
1290 |
Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter(); |
0 | 1291 |
_cursor.visible = false; |
6985
d50d59dca7c1
(svn r10241) -Codechange: CopyToBuffer now produces a buffer that is unreadable from outside the blitter, so the blitter can store anything he likes
truelight
parents:
6964
diff
changeset
|
1292 |
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); |
7170
923946ec324f
(svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents:
7018
diff
changeset
|
1293 |
_video_driver->MakeDirty(_cursor.draw_pos.x, _cursor.draw_pos.y, _cursor.draw_size.x, _cursor.draw_size.y); |
0 | 1294 |
} |
1295 |
} |
|
1296 |
||
6247 | 1297 |
void DrawMouseCursor() |
0 | 1298 |
{ |
7408
605b333582d5
(svn r10781) -Fix: ported more pieces to WinCE, so it compiles a bit more
truelight
parents:
7392
diff
changeset
|
1299 |
#if defined(WINCE) |
605b333582d5
(svn r10781) -Fix: ported more pieces to WinCE, so it compiles a bit more
truelight
parents:
7392
diff
changeset
|
1300 |
/* Don't ever draw the mouse for WinCE, as we work with a stylus */ |
605b333582d5
(svn r10781) -Fix: ported more pieces to WinCE, so it compiles a bit more
truelight
parents:
7392
diff
changeset
|
1301 |
return; |
605b333582d5
(svn r10781) -Fix: ported more pieces to WinCE, so it compiles a bit more
truelight
parents:
7392
diff
changeset
|
1302 |
#endif |
605b333582d5
(svn r10781) -Fix: ported more pieces to WinCE, so it compiles a bit more
truelight
parents:
7392
diff
changeset
|
1303 |
|
6937
40c760fcf1f6
(svn r10190) -Codechange: merged renderer and blitter to one single class API: blitter
truelight
parents:
6889
diff
changeset
|
1304 |
Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter(); |
2010 | 1305 |
int x; |
1306 |
int y; |
|
1307 |
int w; |
|
1308 |
int h; |
|
0 | 1309 |
|
3312
d28f88dc5587
(svn r4075) - Feature: Undraw the mouse when it leaves the window and Draw it again when it enters. Added both for WIN32 and SDL. Since Win95 has troubles with TrackMouseEvent(), this function was just simply rewritten which was the easiest. Based on a patch by DmitryKo.
Darkvater
parents:
3252
diff
changeset
|
1310 |
/* Redraw mouse cursor but only when it's inside the window */ |
d28f88dc5587
(svn r4075) - Feature: Undraw the mouse when it leaves the window and Draw it again when it enters. Added both for WIN32 and SDL. Since Win95 has troubles with TrackMouseEvent(), this function was just simply rewritten which was the easiest. Based on a patch by DmitryKo.
Darkvater
parents:
3252
diff
changeset
|
1311 |
if (!_cursor.in_window) return; |
d28f88dc5587
(svn r4075) - Feature: Undraw the mouse when it leaves the window and Draw it again when it enters. Added both for WIN32 and SDL. Since Win95 has troubles with TrackMouseEvent(), this function was just simply rewritten which was the easiest. Based on a patch by DmitryKo.
Darkvater
parents:
3252
diff
changeset
|
1312 |
|
6179
d19b0137d8e4
(svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6138
diff
changeset
|
1313 |
/* Don't draw the mouse cursor if it's already drawn */ |
0 | 1314 |
if (_cursor.visible) { |
2010 | 1315 |
if (!_cursor.dirty) return; |
0 | 1316 |
UndrawMouseCursor(); |
1317 |
} |
|
1318 |
||
1319 |
w = _cursor.size.x; |
|
9670
ce7645fdaed5
(svn r13759) -Fix [FS#2147]: selecting non-full length vehicles in the depot gui would place the "mouse pointer" out of the center of the vehicle making it hard to "aim".
rubidium
parents:
9637
diff
changeset
|
1320 |
x = _cursor.pos.x + _cursor.offs.x + _cursor.short_vehicle_offset; |
2010 | 1321 |
if (x < 0) { |
1322 |
w += x; |
|
1323 |
x = 0; |
|
1324 |
} |
|
1325 |
if (w > _screen.width - x) w = _screen.width - x; |
|
0 | 1326 |
if (w <= 0) return; |
1327 |
_cursor.draw_pos.x = x; |
|
1328 |
_cursor.draw_size.x = w; |
|
1329 |
||
1330 |
h = _cursor.size.y; |
|
1331 |
y = _cursor.pos.y + _cursor.offs.y; |
|
2010 | 1332 |
if (y < 0) { |
1333 |
h += y; |
|
1334 |
y = 0; |
|
1335 |
} |
|
1336 |
if (h > _screen.height - y) h = _screen.height - y; |
|
0 | 1337 |
if (h <= 0) return; |
1338 |
_cursor.draw_pos.y = y; |
|
1339 |
_cursor.draw_size.y = h; |
|
1340 |
||
6937
40c760fcf1f6
(svn r10190) -Codechange: merged renderer and blitter to one single class API: blitter
truelight
parents:
6889
diff
changeset
|
1341 |
assert(blitter->BufferSize(w, h) < (int)sizeof(_cursor_backup)); |
0 | 1342 |
|
6179
d19b0137d8e4
(svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6138
diff
changeset
|
1343 |
/* Make backup of stuff below cursor */ |
6985
d50d59dca7c1
(svn r10241) -Codechange: CopyToBuffer now produces a buffer that is unreadable from outside the blitter, so the blitter can store anything he likes
truelight
parents:
6964
diff
changeset
|
1344 |
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); |
0 | 1345 |
|
6179
d19b0137d8e4
(svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6138
diff
changeset
|
1346 |
/* Draw cursor on screen */ |
0 | 1347 |
_cur_dpi = &_screen; |
9670
ce7645fdaed5
(svn r13759) -Fix [FS#2147]: selecting non-full length vehicles in the depot gui would place the "mouse pointer" out of the center of the vehicle making it hard to "aim".
rubidium
parents:
9637
diff
changeset
|
1348 |
DrawSprite(_cursor.sprite, _cursor.pal, _cursor.pos.x + _cursor.short_vehicle_offset, _cursor.pos.y); |
0 | 1349 |
|
7170
923946ec324f
(svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents:
7018
diff
changeset
|
1350 |
_video_driver->MakeDirty(_cursor.draw_pos.x, _cursor.draw_pos.y, _cursor.draw_size.x, _cursor.draw_size.y); |
0 | 1351 |
|
1352 |
_cursor.visible = true; |
|
1353 |
_cursor.dirty = false; |
|
1354 |
} |
|
1355 |
||
1356 |
void RedrawScreenRect(int left, int top, int right, int bottom) |
|
1357 |
{ |
|
1358 |
assert(right <= _screen.width && bottom <= _screen.height); |
|
1359 |
if (_cursor.visible) { |
|
1360 |
if (right > _cursor.draw_pos.x && |
|
1361 |
left < _cursor.draw_pos.x + _cursor.draw_size.x && |
|
1362 |
bottom > _cursor.draw_pos.y && |
|
1363 |
top < _cursor.draw_pos.y + _cursor.draw_size.y) { |
|
1364 |
UndrawMouseCursor(); |
|
1365 |
} |
|
1366 |
} |
|
9898
75347c78b276
(svn r14047) -Codechange: move chatmessage handling to the network directory as that's the only case chat messages are used. Furthermore remove any trace of chatmessages when compiling without network support.
rubidium
parents:
9895
diff
changeset
|
1367 |
|
75347c78b276
(svn r14047) -Codechange: move chatmessage handling to the network directory as that's the only case chat messages are used. Furthermore remove any trace of chatmessages when compiling without network support.
rubidium
parents:
9895
diff
changeset
|
1368 |
#ifdef ENABLE_NETWORK |
75347c78b276
(svn r14047) -Codechange: move chatmessage handling to the network directory as that's the only case chat messages are used. Furthermore remove any trace of chatmessages when compiling without network support.
rubidium
parents:
9895
diff
changeset
|
1369 |
NetworkUndrawChatMessage(); |
75347c78b276
(svn r14047) -Codechange: move chatmessage handling to the network directory as that's the only case chat messages are used. Furthermore remove any trace of chatmessages when compiling without network support.
rubidium
parents:
9895
diff
changeset
|
1370 |
#endif /* ENABLE_NETWORK */ |
0 | 1371 |
|
6999
069962f178e0
(svn r10255) -Codechange: remove some old debug code nobody was using anymore
truelight
parents:
6998
diff
changeset
|
1372 |
DrawOverlappedWindowForAll(left, top, right, bottom); |
0 | 1373 |
|
7170
923946ec324f
(svn r10444) -Codechange: switch to c++ classes and inheritance for sound/music/video drivers, using self-registration based on the blitter-model.
peter1138
parents:
7018
diff
changeset
|
1374 |
_video_driver->MakeDirty(left, top, right - left, bottom - top); |
0 | 1375 |
} |
1376 |
||
7545
d44e19c5671e
(svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents:
7454
diff
changeset
|
1377 |
/*! |
d44e19c5671e
(svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents:
7454
diff
changeset
|
1378 |
* Repaints the rectangle blocks which are marked as 'dirty'. |
d44e19c5671e
(svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents:
7454
diff
changeset
|
1379 |
* |
d44e19c5671e
(svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents:
7454
diff
changeset
|
1380 |
* @see SetDirtyBlocks |
d44e19c5671e
(svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents:
7454
diff
changeset
|
1381 |
*/ |
6247 | 1382 |
void DrawDirtyBlocks() |
0 | 1383 |
{ |
1384 |
byte *b = _dirty_blocks; |
|
8981
dd0cd0e54ac3
(svn r12773) -Codechange: replace some magic numbers with enums.
rubidium
parents:
8857
diff
changeset
|
1385 |
const int w = Align(_screen.width, DIRTY_BLOCK_WIDTH); |
dd0cd0e54ac3
(svn r12773) -Codechange: replace some magic numbers with enums.
rubidium
parents:
8857
diff
changeset
|
1386 |
const int h = Align(_screen.height, DIRTY_BLOCK_HEIGHT); |
2025 | 1387 |
int x; |
1388 |
int y; |
|
0 | 1389 |
|
4300
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4171
diff
changeset
|
1390 |
if (IsGeneratingWorld() && !IsGeneratingWorldReadyForPaint()) return; |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4171
diff
changeset
|
1391 |
|
2025 | 1392 |
y = 0; |
0 | 1393 |
do { |
2025 | 1394 |
x = 0; |
1395 |
do { |
|
1396 |
if (*b != 0) { |
|
1397 |
int left; |
|
1398 |
int top; |
|
8981
dd0cd0e54ac3
(svn r12773) -Codechange: replace some magic numbers with enums.
rubidium
parents:
8857
diff
changeset
|
1399 |
int right = x + DIRTY_BLOCK_WIDTH; |
2025 | 1400 |
int bottom = y; |
1401 |
byte *p = b; |
|
1402 |
int h2; |
|
0 | 1403 |
|
6179
d19b0137d8e4
(svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6138
diff
changeset
|
1404 |
/* First try coalescing downwards */ |
0 | 1405 |
do { |
2025 | 1406 |
*p = 0; |
8985
6461e5c6d6e4
(svn r12779) -Codechange: remove a few constants from openttd.h.
rubidium
parents:
8981
diff
changeset
|
1407 |
p += _dirty_bytes_per_line; |
8981
dd0cd0e54ac3
(svn r12773) -Codechange: replace some magic numbers with enums.
rubidium
parents:
8857
diff
changeset
|
1408 |
bottom += DIRTY_BLOCK_HEIGHT; |
2025 | 1409 |
} while (bottom != h && *p != 0); |
0 | 1410 |
|
6179
d19b0137d8e4
(svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6138
diff
changeset
|
1411 |
/* Try coalescing to the right too. */ |
8981
dd0cd0e54ac3
(svn r12773) -Codechange: replace some magic numbers with enums.
rubidium
parents:
8857
diff
changeset
|
1412 |
h2 = (bottom - y) / DIRTY_BLOCK_HEIGHT; |
2025 | 1413 |
assert(h2 > 0); |
1414 |
p = b; |
|
0 | 1415 |
|
2025 | 1416 |
while (right != w) { |
1417 |
byte *p2 = ++p; |
|
1418 |
int h = h2; |
|
6179
d19b0137d8e4
(svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6138
diff
changeset
|
1419 |
/* Check if a full line of dirty flags is set. */ |
2025 | 1420 |
do { |
1421 |
if (!*p2) goto no_more_coalesc; |
|
8985
6461e5c6d6e4
(svn r12779) -Codechange: remove a few constants from openttd.h.
rubidium
parents:
8981
diff
changeset
|
1422 |
p2 += _dirty_bytes_per_line; |
2025 | 1423 |
} while (--h != 0); |
1424 |
||
6179
d19b0137d8e4
(svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6138
diff
changeset
|
1425 |
/* Wohoo, can combine it one step to the right! |
d19b0137d8e4
(svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6138
diff
changeset
|
1426 |
* Do that, and clear the bits. */ |
8981
dd0cd0e54ac3
(svn r12773) -Codechange: replace some magic numbers with enums.
rubidium
parents:
8857
diff
changeset
|
1427 |
right += DIRTY_BLOCK_WIDTH; |
2025 | 1428 |
|
1429 |
h = h2; |
|
1430 |
p2 = p; |
|
1431 |
do { |
|
1432 |
*p2 = 0; |
|
8985
6461e5c6d6e4
(svn r12779) -Codechange: remove a few constants from openttd.h.
rubidium
parents:
8981
diff
changeset
|
1433 |
p2 += _dirty_bytes_per_line; |
2025 | 1434 |
} while (--h != 0); |
1435 |
} |
|
1436 |
no_more_coalesc: |
|
1437 |
||
1438 |
left = x; |
|
1439 |
top = y; |
|
1440 |
||
1441 |
if (left < _invalid_rect.left ) left = _invalid_rect.left; |
|
1442 |
if (top < _invalid_rect.top ) top = _invalid_rect.top; |
|
1443 |
if (right > _invalid_rect.right ) right = _invalid_rect.right; |
|
1444 |
if (bottom > _invalid_rect.bottom) bottom = _invalid_rect.bottom; |
|
1445 |
||
1446 |
if (left < right && top < bottom) { |
|
1447 |
RedrawScreenRect(left, top, right, bottom); |
|
1448 |
} |
|
1449 |
||
0 | 1450 |
} |
8981
dd0cd0e54ac3
(svn r12773) -Codechange: replace some magic numbers with enums.
rubidium
parents:
8857
diff
changeset
|
1451 |
} while (b++, (x += DIRTY_BLOCK_WIDTH) != w); |
8985
6461e5c6d6e4
(svn r12779) -Codechange: remove a few constants from openttd.h.
rubidium
parents:
8981
diff
changeset
|
1452 |
} while (b += -(w / DIRTY_BLOCK_WIDTH) + _dirty_bytes_per_line, (y += DIRTY_BLOCK_HEIGHT) != h); |
0 | 1453 |
|
1454 |
_invalid_rect.left = w; |
|
1455 |
_invalid_rect.top = h; |
|
1456 |
_invalid_rect.right = 0; |
|
1457 |
_invalid_rect.bottom = 0; |
|
4300
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4171
diff
changeset
|
1458 |
|
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4171
diff
changeset
|
1459 |
/* If we are generating a world, and waiting for a paint run, mark it here |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4171
diff
changeset
|
1460 |
* as done painting, so we can continue generating. */ |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4171
diff
changeset
|
1461 |
if (IsGeneratingWorld() && IsGeneratingWorldReadyForPaint()) { |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4171
diff
changeset
|
1462 |
SetGeneratingWorldPaintStatus(false); |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4171
diff
changeset
|
1463 |
} |
0 | 1464 |
} |
1465 |
||
7545
d44e19c5671e
(svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents:
7454
diff
changeset
|
1466 |
/*! |
d44e19c5671e
(svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents:
7454
diff
changeset
|
1467 |
* This function extends the internal _invalid_rect rectangle as it |
d44e19c5671e
(svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents:
7454
diff
changeset
|
1468 |
* now contains the rectangle defined by the given parameters. Note |
d44e19c5671e
(svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents:
7454
diff
changeset
|
1469 |
* the point (0,0) is top left. |
d44e19c5671e
(svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents:
7454
diff
changeset
|
1470 |
* |
d44e19c5671e
(svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents:
7454
diff
changeset
|
1471 |
* @param left The left edge of the rectangle |
d44e19c5671e
(svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents:
7454
diff
changeset
|
1472 |
* @param top The top edge of the rectangle |
d44e19c5671e
(svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents:
7454
diff
changeset
|
1473 |
* @param right The right edge of the rectangle |
d44e19c5671e
(svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents:
7454
diff
changeset
|
1474 |
* @param bottom The bottm edge of the rectangle |
d44e19c5671e
(svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents:
7454
diff
changeset
|
1475 |
* @see DrawDirtyBlocks |
d44e19c5671e
(svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents:
7454
diff
changeset
|
1476 |
* |
d44e19c5671e
(svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents:
7454
diff
changeset
|
1477 |
* @todo The name of the function should be called like @c AddDirtyBlock as |
d44e19c5671e
(svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents:
7454
diff
changeset
|
1478 |
* it neither set a dirty rect nor add several dirty rects although |
d44e19c5671e
(svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents:
7454
diff
changeset
|
1479 |
* the function name is in plural. (Progman) |
d44e19c5671e
(svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents:
7454
diff
changeset
|
1480 |
*/ |
0 | 1481 |
void SetDirtyBlocks(int left, int top, int right, int bottom) |
1482 |
{ |
|
1483 |
byte *b; |
|
2010 | 1484 |
int width; |
1485 |
int height; |
|
0 | 1486 |
|
1487 |
if (left < 0) left = 0; |
|
1488 |
if (top < 0) top = 0; |
|
1489 |
if (right > _screen.width) right = _screen.width; |
|
1490 |
if (bottom > _screen.height) bottom = _screen.height; |
|
1491 |
||
2010 | 1492 |
if (left >= right || top >= bottom) return; |
0 | 1493 |
|
2010 | 1494 |
if (left < _invalid_rect.left ) _invalid_rect.left = left; |
1495 |
if (top < _invalid_rect.top ) _invalid_rect.top = top; |
|
1496 |
if (right > _invalid_rect.right ) _invalid_rect.right = right; |
|
1497 |
if (bottom > _invalid_rect.bottom) _invalid_rect.bottom = bottom; |
|
0 | 1498 |
|
8981
dd0cd0e54ac3
(svn r12773) -Codechange: replace some magic numbers with enums.
rubidium
parents:
8857
diff
changeset
|
1499 |
left /= DIRTY_BLOCK_WIDTH; |
dd0cd0e54ac3
(svn r12773) -Codechange: replace some magic numbers with enums.
rubidium
parents:
8857
diff
changeset
|
1500 |
top /= DIRTY_BLOCK_HEIGHT; |
0 | 1501 |
|
8985
6461e5c6d6e4
(svn r12779) -Codechange: remove a few constants from openttd.h.
rubidium
parents:
8981
diff
changeset
|
1502 |
b = _dirty_blocks + top * _dirty_bytes_per_line + left; |
0 | 1503 |
|
8981
dd0cd0e54ac3
(svn r12773) -Codechange: replace some magic numbers with enums.
rubidium
parents:
8857
diff
changeset
|
1504 |
width = ((right - 1) / DIRTY_BLOCK_WIDTH) - left + 1; |
dd0cd0e54ac3
(svn r12773) -Codechange: replace some magic numbers with enums.
rubidium
parents:
8857
diff
changeset
|
1505 |
height = ((bottom - 1) / DIRTY_BLOCK_HEIGHT) - top + 1; |
0 | 1506 |
|
1507 |
assert(width > 0 && height > 0); |
|
1508 |
||
1509 |
do { |
|
2010 | 1510 |
int i = width; |
1511 |
||
0 | 1512 |
do b[--i] = 0xFF; while (i); |
1513 |
||
8985
6461e5c6d6e4
(svn r12779) -Codechange: remove a few constants from openttd.h.
rubidium
parents:
8981
diff
changeset
|
1514 |
b += _dirty_bytes_per_line; |
2010 | 1515 |
} while (--height != 0); |
0 | 1516 |
} |
1517 |
||
7545
d44e19c5671e
(svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents:
7454
diff
changeset
|
1518 |
/*! |
d44e19c5671e
(svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents:
7454
diff
changeset
|
1519 |
* This function mark the whole screen as dirty. This results in repainting |
d44e19c5671e
(svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents:
7454
diff
changeset
|
1520 |
* the whole screen. Use this with care as this function will break the |
d44e19c5671e
(svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents:
7454
diff
changeset
|
1521 |
* idea about marking only parts of the screen as 'dirty'. |
d44e19c5671e
(svn r11065) -Documentation [FS#1186]: of the dirty marking/repainting subsystem. Patch by Progman.
rubidium
parents:
7454
diff
changeset
|
1522 |
*/ |
6247 | 1523 |
void MarkWholeScreenDirty() |
0 | 1524 |
{ |
1525 |
SetDirtyBlocks(0, 0, _screen.width, _screen.height); |
|
1526 |
} |
|
1527 |
||
4958 | 1528 |
/** Set up a clipping area for only drawing into a certain area. To do this, |
1529 |
* Fill a DrawPixelInfo object with the supplied relative rectangle, backup |
|
1530 |
* the original (calling) _cur_dpi and assign the just returned DrawPixelInfo |
|
1531 |
* _cur_dpi. When you are done, give restore _cur_dpi's original value |
|
1532 |
* @param *n the DrawPixelInfo that will be the clipping rectangle box allowed |
|
1533 |
* for drawing |
|
1534 |
* @param left,top,width,height the relative coordinates of the clipping |
|
1535 |
* rectangle relative to the current _cur_dpi. This will most likely be the |
|
1536 |
* offset from the calling window coordinates |
|
1537 |
* @return return false if the requested rectangle is not possible with the |
|
1538 |
* current dpi pointer. Only continue of the return value is true, or you'll |
|
1539 |
* get some nasty results */ |
|
4429
b4eb6d97996f
(svn r6184) Remove the unused (because it was NULL in all callers) second parameter of FillDrawPixelInfo() and simplify some expressions
tron
parents:
4428
diff
changeset
|
1540 |
bool FillDrawPixelInfo(DrawPixelInfo *n, int left, int top, int width, int height) |
0 | 1541 |
{ |
6937
40c760fcf1f6
(svn r10190) -Codechange: merged renderer and blitter to one single class API: blitter
truelight
parents:
6889
diff
changeset
|
1542 |
Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter(); |
4429
b4eb6d97996f
(svn r6184) Remove the unused (because it was NULL in all callers) second parameter of FillDrawPixelInfo() and simplify some expressions
tron
parents:
4428
diff
changeset
|
1543 |
const DrawPixelInfo *o = _cur_dpi; |
0 | 1544 |
|
6624
880e29b1f25e
(svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents:
6615
diff
changeset
|
1545 |
n->zoom = ZOOM_LVL_NORMAL; |
0 | 1546 |
|
1547 |
assert(width > 0); |
|
1548 |
assert(height > 0); |
|
1549 |
||
1550 |
if ((left -= o->left) < 0) { |
|
2010 | 1551 |
width += left; |
4525
d12168a85134
(svn r6351) -Fix: Due to some off-by-one errors the width or height of a clipping rectangle could become 0, which isn't sensible. This should fix a very rare and hard to trigger assertion in GfxFillRect()
tron
parents:
4522
diff
changeset
|
1552 |
if (width <= 0) return false; |
0 | 1553 |
n->left = -left; |
1554 |
left = 0; |
|
4429
b4eb6d97996f
(svn r6184) Remove the unused (because it was NULL in all callers) second parameter of FillDrawPixelInfo() and simplify some expressions
tron
parents:
4428
diff
changeset
|
1555 |
} else { |
b4eb6d97996f
(svn r6184) Remove the unused (because it was NULL in all callers) second parameter of FillDrawPixelInfo() and simplify some expressions
tron
parents:
4428
diff
changeset
|
1556 |
n->left = 0; |
0 | 1557 |
} |
1558 |
||
4429
b4eb6d97996f
(svn r6184) Remove the unused (because it was NULL in all callers) second parameter of FillDrawPixelInfo() and simplify some expressions
tron
parents:
4428
diff
changeset
|
1559 |
if (width > o->width - left) { |
b4eb6d97996f
(svn r6184) Remove the unused (because it was NULL in all callers) second parameter of FillDrawPixelInfo() and simplify some expressions
tron
parents:
4428
diff
changeset
|
1560 |
width = o->width - left; |
4525
d12168a85134
(svn r6351) -Fix: Due to some off-by-one errors the width or height of a clipping rectangle could become 0, which isn't sensible. This should fix a very rare and hard to trigger assertion in GfxFillRect()
tron
parents:
4522
diff
changeset
|
1561 |
if (width <= 0) return false; |
0 | 1562 |
} |
1563 |
n->width = width; |
|
1564 |
||
1565 |
if ((top -= o->top) < 0) { |
|
2010 | 1566 |
height += top; |
4525
d12168a85134
(svn r6351) -Fix: Due to some off-by-one errors the width or height of a clipping rectangle could become 0, which isn't sensible. This should fix a very rare and hard to trigger assertion in GfxFillRect()
tron
parents:
4522
diff
changeset
|
1567 |
if (height <= 0) return false; |
0 | 1568 |
n->top = -top; |
1569 |
top = 0; |
|
4429
b4eb6d97996f
(svn r6184) Remove the unused (because it was NULL in all callers) second parameter of FillDrawPixelInfo() and simplify some expressions
tron
parents:
4428
diff
changeset
|
1570 |
} else { |
b4eb6d97996f
(svn r6184) Remove the unused (because it was NULL in all callers) second parameter of FillDrawPixelInfo() and simplify some expressions
tron
parents:
4428
diff
changeset
|
1571 |
n->top = 0; |
0 | 1572 |
} |
1573 |
||
6937
40c760fcf1f6
(svn r10190) -Codechange: merged renderer and blitter to one single class API: blitter
truelight
parents:
6889
diff
changeset
|
1574 |
n->dst_ptr = blitter->MoveTo(o->dst_ptr, left, top); |
6878
5cefd3ac59c7
(svn r10121) -Codechange: split renderer from rest of code; no longer any code directly accesses the video-buffer
truelight
parents:
6852
diff
changeset
|
1575 |
n->pitch = o->pitch; |
0 | 1576 |
|
4429
b4eb6d97996f
(svn r6184) Remove the unused (because it was NULL in all callers) second parameter of FillDrawPixelInfo() and simplify some expressions
tron
parents:
4428
diff
changeset
|
1577 |
if (height > o->height - top) { |
b4eb6d97996f
(svn r6184) Remove the unused (because it was NULL in all callers) second parameter of FillDrawPixelInfo() and simplify some expressions
tron
parents:
4428
diff
changeset
|
1578 |
height = o->height - top; |
4525
d12168a85134
(svn r6351) -Fix: Due to some off-by-one errors the width or height of a clipping rectangle could become 0, which isn't sensible. This should fix a very rare and hard to trigger assertion in GfxFillRect()
tron
parents:
4522
diff
changeset
|
1579 |
if (height <= 0) return false; |
0 | 1580 |
} |
1581 |
n->height = height; |
|
1582 |
||
1583 |
return true; |
|
1584 |
} |
|
1585 |
||
5668
36b39f4a9032
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5636
diff
changeset
|
1586 |
static void SetCursorSprite(SpriteID cursor, SpriteID pal) |
0 | 1587 |
{ |
1588 |
CursorVars *cv = &_cursor; |
|
1348 | 1589 |
const Sprite *p; |
0 | 1590 |
|
2010 | 1591 |
if (cv->sprite == cursor) return; |
0 | 1592 |
|
10056
48659f7d4fa5
(svn r14223) -Codechange: make GetSprite aware of the 4 different types of sprites: fonts, recolour, mapgen and normal sprites.
rubidium
parents:
9989
diff
changeset
|
1593 |
p = GetSprite(GB(cursor, 0, SPRITE_WIDTH), ST_NORMAL); |
0 | 1594 |
cv->sprite = cursor; |
5668
36b39f4a9032
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5636
diff
changeset
|
1595 |
cv->pal = pal; |
1348 | 1596 |
cv->size.y = p->height; |
1351
a08ab043dd08
(svn r1855) Handle endianness of sprite headers when loading a sprite, not everytime when accessing it
tron
parents:
1350
diff
changeset
|
1597 |
cv->size.x = p->width; |
a08ab043dd08
(svn r1855) Handle endianness of sprite headers when loading a sprite, not everytime when accessing it
tron
parents:
1350
diff
changeset
|
1598 |
cv->offs.x = p->x_offs; |
a08ab043dd08
(svn r1855) Handle endianness of sprite headers when loading a sprite, not everytime when accessing it
tron
parents:
1350
diff
changeset
|
1599 |
cv->offs.y = p->y_offs; |
0 | 1600 |
|
1601 |
cv->dirty = true; |
|
9670
ce7645fdaed5
(svn r13759) -Fix [FS#2147]: selecting non-full length vehicles in the depot gui would place the "mouse pointer" out of the center of the vehicle making it hard to "aim".
rubidium
parents:
9637
diff
changeset
|
1602 |
cv->short_vehicle_offset = 0; |
0 | 1603 |
} |
1604 |
||
6247 | 1605 |
static void SwitchAnimatedCursor() |
0 | 1606 |
{ |
6138
f1196498ef66
(svn r8880) -Codechange: make anim cursors an array of structs.
rubidium
parents:
5668
diff
changeset
|
1607 |
const AnimCursor *cur = _cursor.animate_cur; |
0 | 1608 |
|
6138
f1196498ef66
(svn r8880) -Codechange: make anim cursors an array of structs.
rubidium
parents:
5668
diff
changeset
|
1609 |
if (cur == NULL || cur->sprite == AnimCursor::LAST) cur = _cursor.animate_list; |
1914
2b4b3c3a95b4
(svn r2420) - Codechange: magic number elminitation of cursorsprites.
Darkvater
parents:
1891
diff
changeset
|
1610 |
|
6138
f1196498ef66
(svn r8880) -Codechange: make anim cursors an array of structs.
rubidium
parents:
5668
diff
changeset
|
1611 |
SetCursorSprite(cur->sprite, _cursor.pal); |
0 | 1612 |
|
6138
f1196498ef66
(svn r8880) -Codechange: make anim cursors an array of structs.
rubidium
parents:
5668
diff
changeset
|
1613 |
_cursor.animate_timeout = cur->display_time; |
f1196498ef66
(svn r8880) -Codechange: make anim cursors an array of structs.
rubidium
parents:
5668
diff
changeset
|
1614 |
_cursor.animate_cur = cur + 1; |
0 | 1615 |
} |
1616 |
||
6247 | 1617 |
void CursorTick() |
1093
4fdc46eaf423
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1056
diff
changeset
|
1618 |
{ |
2010 | 1619 |
if (_cursor.animate_timeout != 0 && --_cursor.animate_timeout == 0) |
0 | 1620 |
SwitchAnimatedCursor(); |
1621 |
} |
|
1622 |
||
5668
36b39f4a9032
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5636
diff
changeset
|
1623 |
void SetMouseCursor(SpriteID sprite, SpriteID pal) |
0 | 1624 |
{ |
6179
d19b0137d8e4
(svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6138
diff
changeset
|
1625 |
/* Turn off animation */ |
0 | 1626 |
_cursor.animate_timeout = 0; |
6179
d19b0137d8e4
(svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
6138
diff
changeset
|
1627 |
/* Set cursor */ |
5668
36b39f4a9032
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5636
diff
changeset
|
1628 |
SetCursorSprite(sprite, pal); |
0 | 1629 |
} |
1630 |
||
6138
f1196498ef66
(svn r8880) -Codechange: make anim cursors an array of structs.
rubidium
parents:
5668
diff
changeset
|
1631 |
void SetAnimatedMouseCursor(const AnimCursor *table) |
0 | 1632 |
{ |
1633 |
_cursor.animate_list = table; |
|
1634 |
_cursor.animate_cur = NULL; |
|
5668
36b39f4a9032
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5636
diff
changeset
|
1635 |
_cursor.pal = PAL_NONE; |
0 | 1636 |
SwitchAnimatedCursor(); |
1637 |
} |
|
1638 |
||
7360
113ae4cb8aad
(svn r10723) -Codechange: dynamically sized (width) main toolbars and status bar for when the window becomes less than 640 pixels in width.
rubidium
parents:
7170
diff
changeset
|
1639 |
bool ChangeResInGame(int width, int height) |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
126
diff
changeset
|
1640 |
{ |
7362
959896e9b55b
(svn r10725) -Codechange: move some window related code out of gfx.cpp to windows.cpp
rubidium
parents:
7361
diff
changeset
|
1641 |
return (_screen.width == width && _screen.height == height) || _video_driver->ChangeResolution(width, height); |
0 | 1642 |
} |
298
0123c0489940
(svn r304) -Fix: [967096] fullscreen. New button 'Fullscreen' in 'Game Options' menu which lets you set fullscreen ingame.
darkvater
parents:
193
diff
changeset
|
1643 |
|
8171
3fb9d1f8ac3b
(svn r11734) -Change: Allow ToggleFullScreen to return the result of the operation' attempt. Previously, only visual clues were available.
belugas
parents:
8131
diff
changeset
|
1644 |
bool ToggleFullScreen(bool fs) |
5217
7a9e91919a93
(svn r7332) -Fix: segmentation fault, discovered by ln-, in the SDL video driver when one goes to fullscreen and there are no suitable resolutions.
rubidium
parents:
5156
diff
changeset
|
1645 |
{ |
8171
3fb9d1f8ac3b
(svn r11734) -Change: Allow ToggleFullScreen to return the result of the operation' attempt. Previously, only visual clues were available.
belugas
parents:
8131
diff
changeset
|
1646 |
bool result = _video_driver->ToggleFullscreen(fs); |
5217
7a9e91919a93
(svn r7332) -Fix: segmentation fault, discovered by ln-, in the SDL video driver when one goes to fullscreen and there are no suitable resolutions.
rubidium
parents:
5156
diff
changeset
|
1647 |
if (_fullscreen != fs && _num_resolutions == 0) { |
5380
8ea58542b6e0
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5217
diff
changeset
|
1648 |
DEBUG(driver, 0, "Could not find a suitable fullscreen resolution"); |
5217
7a9e91919a93
(svn r7332) -Fix: segmentation fault, discovered by ln-, in the SDL video driver when one goes to fullscreen and there are no suitable resolutions.
rubidium
parents:
5156
diff
changeset
|
1649 |
} |
8171
3fb9d1f8ac3b
(svn r11734) -Change: Allow ToggleFullScreen to return the result of the operation' attempt. Previously, only visual clues were available.
belugas
parents:
8131
diff
changeset
|
1650 |
return result; |
5217
7a9e91919a93
(svn r7332) -Fix: segmentation fault, discovered by ln-, in the SDL video driver when one goes to fullscreen and there are no suitable resolutions.
rubidium
parents:
5156
diff
changeset
|
1651 |
} |
1829
e90fe433fa7d
(svn r2334) - Fix (regression): moved togglefullscreen into the video-driver, now windows works, dedicated works and sdl works. Also reverted the change to the makefile.
Darkvater
parents:
1806
diff
changeset
|
1652 |
|
9533
e8b86b70c5f6
(svn r13537) -Fix [FS#2090](r13523): QSortT won't work this way, use Dimension instead of uint16[2] for resolutions
smatz
parents:
9527
diff
changeset
|
1653 |
static int CDECL compare_res(const Dimension *pa, const Dimension *pb) |
298
0123c0489940
(svn r304) -Fix: [967096] fullscreen. New button 'Fullscreen' in 'Game Options' menu which lets you set fullscreen ingame.
darkvater
parents:
193
diff
changeset
|
1654 |
{ |
9533
e8b86b70c5f6
(svn r13537) -Fix [FS#2090](r13523): QSortT won't work this way, use Dimension instead of uint16[2] for resolutions
smatz
parents:
9527
diff
changeset
|
1655 |
int x = pa->width - pb->width; |
1806
5a55d508c23e
(svn r2310) - Fix: Game would crash if you full-screened with the 'fullscreen' button than chose a resolution from the dropdown box that was no longer valid. Big thanks to DaleStan for track down the crashing bug.
Darkvater
parents:
1390
diff
changeset
|
1656 |
if (x != 0) return x; |
9533
e8b86b70c5f6
(svn r13537) -Fix [FS#2090](r13523): QSortT won't work this way, use Dimension instead of uint16[2] for resolutions
smatz
parents:
9527
diff
changeset
|
1657 |
return pa->height - pb->height; |
1806
5a55d508c23e
(svn r2310) - Fix: Game would crash if you full-screened with the 'fullscreen' button than chose a resolution from the dropdown box that was no longer valid. Big thanks to DaleStan for track down the crashing bug.
Darkvater
parents:
1390
diff
changeset
|
1658 |
} |
5a55d508c23e
(svn r2310) - Fix: Game would crash if you full-screened with the 'fullscreen' button than chose a resolution from the dropdown box that was no longer valid. Big thanks to DaleStan for track down the crashing bug.
Darkvater
parents:
1390
diff
changeset
|
1659 |
|
5a55d508c23e
(svn r2310) - Fix: Game would crash if you full-screened with the 'fullscreen' button than chose a resolution from the dropdown box that was no longer valid. Big thanks to DaleStan for track down the crashing bug.
Darkvater
parents:
1390
diff
changeset
|
1660 |
void SortResolutions(int count) |
5a55d508c23e
(svn r2310) - Fix: Game would crash if you full-screened with the 'fullscreen' button than chose a resolution from the dropdown box that was no longer valid. Big thanks to DaleStan for track down the crashing bug.
Darkvater
parents:
1390
diff
changeset
|
1661 |
{ |
9533
e8b86b70c5f6
(svn r13537) -Fix [FS#2090](r13523): QSortT won't work this way, use Dimension instead of uint16[2] for resolutions
smatz
parents:
9527
diff
changeset
|
1662 |
QSortT(_resolutions, count, &compare_res); |
298
0123c0489940
(svn r304) -Fix: [967096] fullscreen. New button 'Fullscreen' in 'Game Options' menu which lets you set fullscreen ingame.
darkvater
parents:
193
diff
changeset
|
1663 |
} |