| 53203200 |
sago007 |
2015-12-25 13:30 |
1 |
/* |
| 53203200 |
sago007 |
2015-12-25 13:30 |
2 |
NFont v4.0.0: A font class for SDL |
| 53203200 |
sago007 |
2015-12-25 13:30 |
3 |
by Jonathan Dearborn |
| 53203200 |
sago007 |
2015-12-25 13:30 |
4 |
Dedicated to the memory of Florian Hufsky |
| 53203200 |
sago007 |
2015-12-25 13:30 |
5 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
6 |
License: |
| 53203200 |
sago007 |
2015-12-25 13:30 |
7 |
The short: |
| 53203200 |
sago007 |
2015-12-25 13:30 |
8 |
Use it however you'd like, but keep the copyright and license notice |
| 53203200 |
sago007 |
2015-12-25 13:30 |
9 |
whenever these files or parts of them are distributed in uncompiled form. |
| 53203200 |
sago007 |
2015-12-25 13:30 |
10 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
11 |
The long: |
| 53203200 |
sago007 |
2015-12-25 13:30 |
12 |
Copyright (c) 2014 Jonathan Dearborn |
| 53203200 |
sago007 |
2015-12-25 13:30 |
13 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
14 |
Permission is hereby granted, free of charge, to any person obtaining a copy |
| 53203200 |
sago007 |
2015-12-25 13:30 |
15 |
of this software and associated documentation files (the "Software"), to deal |
| 53203200 |
sago007 |
2015-12-25 13:30 |
16 |
in the Software without restriction, including without limitation the rights |
| 53203200 |
sago007 |
2015-12-25 13:30 |
17 |
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 53203200 |
sago007 |
2015-12-25 13:30 |
18 |
copies of the Software, and to permit persons to whom the Software is |
| 53203200 |
sago007 |
2015-12-25 13:30 |
19 |
furnished to do so, subject to the following conditions: |
| 53203200 |
sago007 |
2015-12-25 13:30 |
20 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
21 |
The above copyright notice and this permission notice shall be included in |
| 53203200 |
sago007 |
2015-12-25 13:30 |
22 |
all copies or substantial portions of the Software. |
| 53203200 |
sago007 |
2015-12-25 13:30 |
23 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
24 |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 53203200 |
sago007 |
2015-12-25 13:30 |
25 |
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 53203200 |
sago007 |
2015-12-25 13:30 |
26 |
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 53203200 |
sago007 |
2015-12-25 13:30 |
27 |
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 53203200 |
sago007 |
2015-12-25 13:30 |
28 |
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 53203200 |
sago007 |
2015-12-25 13:30 |
29 |
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 53203200 |
sago007 |
2015-12-25 13:30 |
30 |
THE SOFTWARE. |
| 53203200 |
sago007 |
2015-12-25 13:30 |
31 |
*/ |
| 53203200 |
sago007 |
2015-12-25 13:30 |
32 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
33 |
#include "NFont.h" |
| 53203200 |
sago007 |
2015-12-25 13:30 |
34 |
#include "SDL_FontCache.h" |
| 53203200 |
sago007 |
2015-12-25 13:30 |
35 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
36 |
#include <cmath> |
| 53203200 |
sago007 |
2015-12-25 13:30 |
37 |
#include <cstdio> |
| 53203200 |
sago007 |
2015-12-25 13:30 |
38 |
#ifndef M_PI |
| 53203200 |
sago007 |
2015-12-25 13:30 |
39 |
#define M_PI 3.14159265358979323846 |
| 53203200 |
sago007 |
2015-12-25 13:30 |
40 |
#endif |
| 53203200 |
sago007 |
2015-12-25 13:30 |
41 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
42 |
#include <string> |
| 53203200 |
sago007 |
2015-12-25 13:30 |
43 |
#include <cstring> |
| 53203200 |
sago007 |
2015-12-25 13:30 |
44 |
#include <list> |
| 53203200 |
sago007 |
2015-12-25 13:30 |
45 |
using std::string; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
46 |
using std::list; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
47 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
48 |
#ifdef NFONT_USE_SDL_GPU |
| 53203200 |
sago007 |
2015-12-25 13:30 |
49 |
#define NFont_Target GPU_Target |
| 53203200 |
sago007 |
2015-12-25 13:30 |
50 |
#define NFont_Image GPU_Image |
| 53203200 |
sago007 |
2015-12-25 13:30 |
51 |
#define NFont_Log GPU_LogError |
| 53203200 |
sago007 |
2015-12-25 13:30 |
52 |
#else |
| 53203200 |
sago007 |
2015-12-25 13:30 |
53 |
#define NFont_Target SDL_Renderer |
| 53203200 |
sago007 |
2015-12-25 13:30 |
54 |
#define NFont_Image SDL_Texture |
| 53203200 |
sago007 |
2015-12-25 13:30 |
55 |
#define NFont_Log SDL_Log |
| 53203200 |
sago007 |
2015-12-25 13:30 |
56 |
#endif |
| 53203200 |
sago007 |
2015-12-25 13:30 |
57 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
58 |
#define MIN(a,b) ((a) < (b)? (a) : (b)) |
| 53203200 |
sago007 |
2015-12-25 13:30 |
59 |
#define MAX(a,b) ((a) > (b)? (a) : (b)) |
| 53203200 |
sago007 |
2015-12-25 13:30 |
60 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
61 |
static inline SDL_Surface* createSurface24(Uint32 width, Uint32 height) { |
| 53203200 |
sago007 |
2015-12-25 13:30 |
62 |
#if SDL_BYTEORDER == SDL_BIG_ENDIAN |
| 53203200 |
sago007 |
2015-12-25 13:30 |
63 |
return SDL_CreateRGBSurface(SDL_SWSURFACE, width, height, 24, 0xFF0000, 0x00FF00, 0x0000FF, 0); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
64 |
#else |
| 53203200 |
sago007 |
2015-12-25 13:30 |
65 |
return SDL_CreateRGBSurface(SDL_SWSURFACE, width, height, 24, 0x0000FF, 0x00FF00, 0xFF0000, 0); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
66 |
#endif |
| 53203200 |
sago007 |
2015-12-25 13:30 |
67 |
} |
| 53203200 |
sago007 |
2015-12-25 13:30 |
68 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
69 |
static inline SDL_Surface* createSurface32(Uint32 width, Uint32 height) { |
| 53203200 |
sago007 |
2015-12-25 13:30 |
70 |
#if SDL_BYTEORDER == SDL_BIG_ENDIAN |
| 53203200 |
sago007 |
2015-12-25 13:30 |
71 |
return SDL_CreateRGBSurface(SDL_SWSURFACE, width, height, 32, 0xFF000000, 0x00FF0000, 0x0000FF00, 0x000000FF); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
72 |
#else |
| 53203200 |
sago007 |
2015-12-25 13:30 |
73 |
return SDL_CreateRGBSurface(SDL_SWSURFACE, width, height, 32, 0x000000FF, 0x0000FF00, 0x00FF0000, 0xFF000000); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
74 |
#endif |
| 53203200 |
sago007 |
2015-12-25 13:30 |
75 |
} |
| 53203200 |
sago007 |
2015-12-25 13:30 |
76 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
77 |
static inline char* copyString(const char* c) { |
| 53203200 |
sago007 |
2015-12-25 13:30 |
78 |
if (c == NULL) { |
| 53203200 |
sago007 |
2015-12-25 13:30 |
79 |
return NULL; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
80 |
} |
| 53203200 |
sago007 |
2015-12-25 13:30 |
81 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
82 |
char* result = new char[strlen(c)+1]; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
83 |
strcpy(result, c); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
84 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
85 |
return result; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
86 |
} |
| 53203200 |
sago007 |
2015-12-25 13:30 |
87 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
88 |
static inline Uint32 getPixel(SDL_Surface* Surface, int x, int y) { |
| 53203200 |
sago007 |
2015-12-25 13:30 |
89 |
Uint8* bits; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
90 |
Uint32 bpp; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
91 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
92 |
if (x < 0 || x >= Surface->w) { |
| 53203200 |
sago007 |
2015-12-25 13:30 |
93 |
return 0; // Best I could do for errors |
| 53203200 |
sago007 |
2015-12-25 13:30 |
94 |
} |
| 53203200 |
sago007 |
2015-12-25 13:30 |
95 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
96 |
bpp = Surface->format->BytesPerPixel; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
97 |
bits = ((Uint8*)Surface->pixels) + y*Surface->pitch + x*bpp; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
98 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
99 |
switch (bpp) { |
| 53203200 |
sago007 |
2015-12-25 13:30 |
100 |
case 1: |
| 53203200 |
sago007 |
2015-12-25 13:30 |
101 |
return *((Uint8*)Surface->pixels + y * Surface->pitch + x); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
102 |
break; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
103 |
case 2: |
| 53203200 |
sago007 |
2015-12-25 13:30 |
104 |
return *((Uint16*)Surface->pixels + y * Surface->pitch/2 + x); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
105 |
break; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
106 |
case 3: |
| 53203200 |
sago007 |
2015-12-25 13:30 |
107 |
// Endian-correct, but slower |
| 53203200 |
sago007 |
2015-12-25 13:30 |
108 |
Uint8 r, g, b; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
109 |
r = *((bits)+Surface->format->Rshift/8); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
110 |
g = *((bits)+Surface->format->Gshift/8); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
111 |
b = *((bits)+Surface->format->Bshift/8); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
112 |
return SDL_MapRGB(Surface->format, r, g, b); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
113 |
break; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
114 |
case 4: |
| 53203200 |
sago007 |
2015-12-25 13:30 |
115 |
return *((Uint32*)Surface->pixels + y * Surface->pitch/4 + x); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
116 |
break; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
117 |
} |
| 53203200 |
sago007 |
2015-12-25 13:30 |
118 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
119 |
return 0; // FIXME: Handle errors better |
| 53203200 |
sago007 |
2015-12-25 13:30 |
120 |
} |
| 53203200 |
sago007 |
2015-12-25 13:30 |
121 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
122 |
static inline void setPixel(SDL_Surface* surface, int x, int y, Uint32 color) { |
| 53203200 |
sago007 |
2015-12-25 13:30 |
123 |
int bpp = surface->format->BytesPerPixel; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
124 |
Uint8* bits = ((Uint8*)surface->pixels) + y*surface->pitch + x*bpp; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
125 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
126 |
/* Set the pixel */ |
| 53203200 |
sago007 |
2015-12-25 13:30 |
127 |
switch (bpp) { |
| 53203200 |
sago007 |
2015-12-25 13:30 |
128 |
case 1: |
| 53203200 |
sago007 |
2015-12-25 13:30 |
129 |
*((Uint8*)(bits)) = (Uint8)color; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
130 |
break; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
131 |
case 2: |
| 53203200 |
sago007 |
2015-12-25 13:30 |
132 |
*((Uint16*)(bits)) = (Uint16)color; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
133 |
break; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
134 |
case 3: { /* Format/endian independent */ |
| 53203200 |
sago007 |
2015-12-25 13:30 |
135 |
Uint8 r,g,b; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
136 |
r = (color >> surface->format->Rshift) & 0xFF; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
137 |
g = (color >> surface->format->Gshift) & 0xFF; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
138 |
b = (color >> surface->format->Bshift) & 0xFF; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
139 |
*((bits)+surface->format->Rshift/8) = r; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
140 |
*((bits)+surface->format->Gshift/8) = g; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
141 |
*((bits)+surface->format->Bshift/8) = b; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
142 |
} |
| 53203200 |
sago007 |
2015-12-25 13:30 |
143 |
break; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
144 |
case 4: |
| 53203200 |
sago007 |
2015-12-25 13:30 |
145 |
*((Uint32*)(bits)) = (Uint32)color; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
146 |
break; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
147 |
} |
| 53203200 |
sago007 |
2015-12-25 13:30 |
148 |
} |
| 53203200 |
sago007 |
2015-12-25 13:30 |
149 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
150 |
static inline void drawPixel(SDL_Surface* surface, Sint16 x, Sint16 y, Uint32 color, Uint8 alpha) { |
| 53203200 |
sago007 |
2015-12-25 13:30 |
151 |
if (x > surface->clip_rect.x + surface->clip_rect.w || x < surface->clip_rect.x || y > surface->clip_rect.y + surface->clip_rect.h || y < surface->clip_rect.y) { |
| 53203200 |
sago007 |
2015-12-25 13:30 |
152 |
return; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
153 |
} |
| 53203200 |
sago007 |
2015-12-25 13:30 |
154 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
155 |
switch (surface->format->BytesPerPixel) { |
| 53203200 |
sago007 |
2015-12-25 13:30 |
156 |
case 1: { /* Assuming 8-bpp */ |
| 53203200 |
sago007 |
2015-12-25 13:30 |
157 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
158 |
Uint8* pixel = (Uint8*)surface->pixels + y*surface->pitch + x; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
159 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
160 |
Uint8 dR = surface->format->palette->colors[*pixel].r; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
161 |
Uint8 dG = surface->format->palette->colors[*pixel].g; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
162 |
Uint8 dB = surface->format->palette->colors[*pixel].b; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
163 |
Uint8 sR = surface->format->palette->colors[color].r; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
164 |
Uint8 sG = surface->format->palette->colors[color].g; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
165 |
Uint8 sB = surface->format->palette->colors[color].b; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
166 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
167 |
dR = dR + ((sR-dR)*alpha >> 8); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
168 |
dG = dG + ((sG-dG)*alpha >> 8); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
169 |
dB = dB + ((sB-dB)*alpha >> 8); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
170 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
171 |
*pixel = SDL_MapRGB(surface->format, dR, dG, dB); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
172 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
173 |
} |
| 53203200 |
sago007 |
2015-12-25 13:30 |
174 |
break; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
175 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
176 |
case 2: { /* Probably 15-bpp or 16-bpp */ |
| 53203200 |
sago007 |
2015-12-25 13:30 |
177 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
178 |
Uint32 Rmask = surface->format->Rmask, Gmask = surface->format->Gmask, Bmask = surface->format->Bmask, Amask = surface->format->Amask; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
179 |
Uint16* pixel = (Uint16*)surface->pixels + y*surface->pitch/2 + x; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
180 |
Uint32 dc = *pixel; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
181 |
Uint32 R,G,B,A=0; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
182 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
183 |
R = ((dc & Rmask) + (( (color & Rmask) - (dc & Rmask) ) * alpha >> 8)) & Rmask; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
184 |
G = ((dc & Gmask) + (( (color & Gmask) - (dc & Gmask) ) * alpha >> 8)) & Gmask; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
185 |
B = ((dc & Bmask) + (( (color & Bmask) - (dc & Bmask) ) * alpha >> 8)) & Bmask; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
186 |
if ( Amask ) { |
| 53203200 |
sago007 |
2015-12-25 13:30 |
187 |
A = ((dc & Amask) + (( (color & Amask) - (dc & Amask) ) * alpha >> 8)) & Amask; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
188 |
} |
| 53203200 |
sago007 |
2015-12-25 13:30 |
189 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
190 |
*pixel= R | G | B | A; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
191 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
192 |
} |
| 53203200 |
sago007 |
2015-12-25 13:30 |
193 |
break; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
194 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
195 |
case 3: { /* Slow 24-bpp mode, usually not used */ |
| 53203200 |
sago007 |
2015-12-25 13:30 |
196 |
Uint8* pix = (Uint8*)surface->pixels + y * surface->pitch + x*3; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
197 |
Uint8 rshift8=surface->format->Rshift/8; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
198 |
Uint8 gshift8=surface->format->Gshift/8; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
199 |
Uint8 bshift8=surface->format->Bshift/8; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
200 |
Uint8 ashift8=surface->format->Ashift/8; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
201 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
202 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
203 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
204 |
Uint8 dR, dG, dB, dA; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
205 |
Uint8 sR, sG, sB, sA; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
206 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
207 |
pix = (Uint8*)surface->pixels + y * surface->pitch + x*3; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
208 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
209 |
dR = *((pix)+rshift8); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
210 |
dG = *((pix)+gshift8); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
211 |
dB = *((pix)+bshift8); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
212 |
dA = *((pix)+ashift8); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
213 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
214 |
sR = (color>>surface->format->Rshift)&0xff; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
215 |
sG = (color>>surface->format->Gshift)&0xff; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
216 |
sB = (color>>surface->format->Bshift)&0xff; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
217 |
sA = (color>>surface->format->Ashift)&0xff; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
218 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
219 |
dR = dR + ((sR-dR)*alpha >> 8); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
220 |
dG = dG + ((sG-dG)*alpha >> 8); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
221 |
dB = dB + ((sB-dB)*alpha >> 8); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
222 |
dA = dA + ((sA-dA)*alpha >> 8); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
223 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
224 |
*((pix)+rshift8) = dR; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
225 |
*((pix)+gshift8) = dG; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
226 |
*((pix)+bshift8) = dB; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
227 |
*((pix)+ashift8) = dA; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
228 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
229 |
} |
| 53203200 |
sago007 |
2015-12-25 13:30 |
230 |
break; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
231 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
232 |
case 4: { /* Probably 32-bpp */ |
| 53203200 |
sago007 |
2015-12-25 13:30 |
233 |
Uint32 Rmask = surface->format->Rmask, Gmask = surface->format->Gmask, Bmask = surface->format->Bmask, Amask = surface->format->Amask; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
234 |
Uint32* pixel = (Uint32*)surface->pixels + y*surface->pitch/4 + x; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
235 |
Uint32 source = *pixel; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
236 |
Uint32 R,G,B,A; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
237 |
R = color & Rmask; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
238 |
G = color & Gmask; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
239 |
B = color & Bmask; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
240 |
A = 0; // keep this as 0 to avoid corruption of non-alpha surfaces |
| 53203200 |
sago007 |
2015-12-25 13:30 |
241 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
242 |
// Blend and keep dest alpha |
| 53203200 |
sago007 |
2015-12-25 13:30 |
243 |
if ( alpha != SDL_ALPHA_OPAQUE ) { |
| 53203200 |
sago007 |
2015-12-25 13:30 |
244 |
R = ((source & Rmask) + (( R - (source & Rmask) ) * alpha >> 8)) & Rmask; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
245 |
G = ((source & Gmask) + (( G - (source & Gmask) ) * alpha >> 8)) & Gmask; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
246 |
B = ((source & Bmask) + (( B - (source & Bmask) ) * alpha >> 8)) & Bmask; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
247 |
} |
| 53203200 |
sago007 |
2015-12-25 13:30 |
248 |
if (Amask) { |
| 53203200 |
sago007 |
2015-12-25 13:30 |
249 |
A = (source & Amask); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
250 |
} |
| 53203200 |
sago007 |
2015-12-25 13:30 |
251 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
252 |
*pixel = R | G | B | A; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
253 |
} |
| 53203200 |
sago007 |
2015-12-25 13:30 |
254 |
break; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
255 |
} |
| 53203200 |
sago007 |
2015-12-25 13:30 |
256 |
} |
| 53203200 |
sago007 |
2015-12-25 13:30 |
257 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
258 |
static inline NFont::Rectf rectUnion(const NFont::Rectf& A, const NFont::Rectf& B) { |
| 53203200 |
sago007 |
2015-12-25 13:30 |
259 |
float x,x2,y,y2; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
260 |
x = MIN(A.x, B.x); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
261 |
y = MIN(A.y, B.y); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
262 |
x2 = MAX(A.x+A.w, B.x+B.w); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
263 |
y2 = MAX(A.y+A.h, B.y+B.h); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
264 |
NFont::Rectf result(x, y, MAX(0, x2 - x), MAX(0, y2 - y)); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
265 |
return result; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
266 |
} |
| 53203200 |
sago007 |
2015-12-25 13:30 |
267 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
268 |
// Adapted from SDL_IntersectRect |
| 53203200 |
sago007 |
2015-12-25 13:30 |
269 |
static inline NFont::Rectf rectIntersect(const NFont::Rectf& A, const NFont::Rectf& B) { |
| 53203200 |
sago007 |
2015-12-25 13:30 |
270 |
NFont::Rectf result; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
271 |
float Amin, Amax, Bmin, Bmax; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
272 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
273 |
// Horizontal intersection |
| 53203200 |
sago007 |
2015-12-25 13:30 |
274 |
Amin = A.x; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
275 |
Amax = Amin + A.w; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
276 |
Bmin = B.x; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
277 |
Bmax = Bmin + B.w; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
278 |
if (Bmin > Amin) { |
| 53203200 |
sago007 |
2015-12-25 13:30 |
279 |
Amin = Bmin; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
280 |
} |
| 53203200 |
sago007 |
2015-12-25 13:30 |
281 |
result.x = Amin; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
282 |
if (Bmax < Amax) { |
| 53203200 |
sago007 |
2015-12-25 13:30 |
283 |
Amax = Bmax; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
284 |
} |
| 53203200 |
sago007 |
2015-12-25 13:30 |
285 |
result.w = Amax - Amin > 0 ? Amax - Amin : 0; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
286 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
287 |
// Vertical intersection |
| 53203200 |
sago007 |
2015-12-25 13:30 |
288 |
Amin = A.y; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
289 |
Amax = Amin + A.h; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
290 |
Bmin = B.y; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
291 |
Bmax = Bmin + B.h; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
292 |
if (Bmin > Amin) { |
| 53203200 |
sago007 |
2015-12-25 13:30 |
293 |
Amin = Bmin; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
294 |
} |
| 53203200 |
sago007 |
2015-12-25 13:30 |
295 |
result.y = Amin; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
296 |
if (Bmax < Amax) { |
| 53203200 |
sago007 |
2015-12-25 13:30 |
297 |
Amax = Bmax; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
298 |
} |
| 53203200 |
sago007 |
2015-12-25 13:30 |
299 |
result.h = Amax - Amin > 0 ? Amax - Amin : 0; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
300 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
301 |
return result; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
302 |
} |
| 53203200 |
sago007 |
2015-12-25 13:30 |
303 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
304 |
static inline SDL_Surface* copySurface(SDL_Surface* Surface) { |
| 53203200 |
sago007 |
2015-12-25 13:30 |
305 |
return SDL_ConvertSurface(Surface, Surface->format, Surface->flags); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
306 |
} |
| 53203200 |
sago007 |
2015-12-25 13:30 |
307 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
308 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
309 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
310 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
311 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
312 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
313 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
314 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
315 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
316 |
NFont::Color::Color() |
| 53203200 |
sago007 |
2015-12-25 13:30 |
317 |
: r(0), g(0), b(0), a(255) { |
| 53203200 |
sago007 |
2015-12-25 13:30 |
318 |
} |
| 53203200 |
sago007 |
2015-12-25 13:30 |
319 |
NFont::Color::Color(Uint8 r, Uint8 g, Uint8 b) |
| 53203200 |
sago007 |
2015-12-25 13:30 |
320 |
: r(r), g(g), b(b), a(255) { |
| 53203200 |
sago007 |
2015-12-25 13:30 |
321 |
} |
| 53203200 |
sago007 |
2015-12-25 13:30 |
322 |
NFont::Color::Color(Uint8 r, Uint8 g, Uint8 b, Uint8 a) |
| 53203200 |
sago007 |
2015-12-25 13:30 |
323 |
: r(r), g(g), b(b), a(a) { |
| 53203200 |
sago007 |
2015-12-25 13:30 |
324 |
} |
| 53203200 |
sago007 |
2015-12-25 13:30 |
325 |
NFont::Color::Color(const SDL_Color& color) |
| 53203200 |
sago007 |
2015-12-25 13:30 |
326 |
: r(color.r), g(color.g), b(color.b), a(color.a) { |
| 53203200 |
sago007 |
2015-12-25 13:30 |
327 |
} |
| 53203200 |
sago007 |
2015-12-25 13:30 |
328 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
329 |
NFont::Color& NFont::Color::rgb(Uint8 R, Uint8 G, Uint8 B) { |
| 53203200 |
sago007 |
2015-12-25 13:30 |
330 |
r = R; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
331 |
g = G; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
332 |
b = B; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
333 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
334 |
return *this; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
335 |
} |
| 53203200 |
sago007 |
2015-12-25 13:30 |
336 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
337 |
NFont::Color& NFont::Color::rgba(Uint8 R, Uint8 G, Uint8 B, Uint8 A) { |
| 53203200 |
sago007 |
2015-12-25 13:30 |
338 |
r = R; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
339 |
g = G; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
340 |
b = B; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
341 |
a = A; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
342 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
343 |
return *this; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
344 |
} |
| 53203200 |
sago007 |
2015-12-25 13:30 |
345 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
346 |
NFont::Color& NFont::Color::color(const SDL_Color& color) { |
| 53203200 |
sago007 |
2015-12-25 13:30 |
347 |
r = color.r; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
348 |
g = color.g; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
349 |
b = color.b; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
350 |
a = color.a; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
351 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
352 |
return *this; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
353 |
} |
| 53203200 |
sago007 |
2015-12-25 13:30 |
354 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
355 |
SDL_Color NFont::Color::to_SDL_Color() const { |
| 53203200 |
sago007 |
2015-12-25 13:30 |
356 |
SDL_Color c = {r, g, b, a}; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
357 |
return c; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
358 |
} |
| 53203200 |
sago007 |
2015-12-25 13:30 |
359 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
360 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
361 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
362 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
363 |
NFont::Rectf::Rectf() |
| 53203200 |
sago007 |
2015-12-25 13:30 |
364 |
: x(0), y(0), w(0), h(0) { |
| 53203200 |
sago007 |
2015-12-25 13:30 |
365 |
} |
| 53203200 |
sago007 |
2015-12-25 13:30 |
366 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
367 |
NFont::Rectf::Rectf(float x, float y) |
| 53203200 |
sago007 |
2015-12-25 13:30 |
368 |
: x(x), y(y), w(0), h(0) { |
| 53203200 |
sago007 |
2015-12-25 13:30 |
369 |
} |
| 53203200 |
sago007 |
2015-12-25 13:30 |
370 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
371 |
NFont::Rectf::Rectf(float x, float y, float w, float h) |
| 53203200 |
sago007 |
2015-12-25 13:30 |
372 |
: x(x), y(y), w(w), h(h) { |
| 53203200 |
sago007 |
2015-12-25 13:30 |
373 |
} |
| 53203200 |
sago007 |
2015-12-25 13:30 |
374 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
375 |
NFont::Rectf::Rectf(const SDL_Rect& rect) |
| 53203200 |
sago007 |
2015-12-25 13:30 |
376 |
: x(rect.x), y(rect.y), w(rect.w), h(rect.h) { |
| 53203200 |
sago007 |
2015-12-25 13:30 |
377 |
} |
| 53203200 |
sago007 |
2015-12-25 13:30 |
378 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
379 |
#ifdef NFONT_USE_SDL_GPU |
| 53203200 |
sago007 |
2015-12-25 13:30 |
380 |
NFont::Rectf::Rectf(const GPU_Rect& rect) |
| 53203200 |
sago007 |
2015-12-25 13:30 |
381 |
: x(rect.x), y(rect.y), w(rect.w), h(rect.h) { |
| 53203200 |
sago007 |
2015-12-25 13:30 |
382 |
} |
| 53203200 |
sago007 |
2015-12-25 13:30 |
383 |
#endif |
| 53203200 |
sago007 |
2015-12-25 13:30 |
384 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
385 |
SDL_Rect NFont::Rectf::to_SDL_Rect() const { |
| 53203200 |
sago007 |
2015-12-25 13:30 |
386 |
SDL_Rect r = {int(x), int(y), int(w), int(h)}; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
387 |
return r; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
388 |
} |
| 53203200 |
sago007 |
2015-12-25 13:30 |
389 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
390 |
#ifdef NFONT_USE_SDL_GPU |
| 53203200 |
sago007 |
2015-12-25 13:30 |
391 |
GPU_Rect NFont::Rectf::to_GPU_Rect() const { |
| 53203200 |
sago007 |
2015-12-25 13:30 |
392 |
return GPU_MakeRect(x, y, w, h); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
393 |
} |
| 53203200 |
sago007 |
2015-12-25 13:30 |
394 |
#endif |
| 53203200 |
sago007 |
2015-12-25 13:30 |
395 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
396 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
397 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
398 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
399 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
400 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
401 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
402 |
char* NFont::buffer = NULL; // Shared buffer for efficient drawing |
| 53203200 |
sago007 |
2015-12-25 13:30 |
403 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
404 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
405 |
// Constructors |
| 53203200 |
sago007 |
2015-12-25 13:30 |
406 |
NFont::NFont() { |
| 53203200 |
sago007 |
2015-12-25 13:30 |
407 |
init(); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
408 |
} |
| 53203200 |
sago007 |
2015-12-25 13:30 |
409 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
410 |
NFont::NFont(const NFont& font) { |
| 53203200 |
sago007 |
2015-12-25 13:30 |
411 |
init(); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
412 |
// FIXME: Duplicate font data |
| 53203200 |
sago007 |
2015-12-25 13:30 |
413 |
} |
| 53203200 |
sago007 |
2015-12-25 13:30 |
414 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
415 |
#ifdef NFONT_USE_SDL_GPU |
| 53203200 |
sago007 |
2015-12-25 13:30 |
416 |
NFont::NFont(TTF_Font* ttf) { |
| 53203200 |
sago007 |
2015-12-25 13:30 |
417 |
init(); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
418 |
load(ttf, FC_GetDefaultColor(font)); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
419 |
} |
| 53203200 |
sago007 |
2015-12-25 13:30 |
420 |
NFont::NFont(TTF_Font* ttf, const NFont::Color& color) { |
| 53203200 |
sago007 |
2015-12-25 13:30 |
421 |
init(); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
422 |
load(ttf, color); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
423 |
} |
| 53203200 |
sago007 |
2015-12-25 13:30 |
424 |
NFont::NFont(const char* filename_ttf, Uint32 pointSize) { |
| 53203200 |
sago007 |
2015-12-25 13:30 |
425 |
init(); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
426 |
load(filename_ttf, pointSize); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
427 |
} |
| 53203200 |
sago007 |
2015-12-25 13:30 |
428 |
NFont::NFont(const char* filename_ttf, Uint32 pointSize, const NFont::Color& color, int style) { |
| 53203200 |
sago007 |
2015-12-25 13:30 |
429 |
init(); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
430 |
load(filename_ttf, pointSize, color, style); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
431 |
} |
| 53203200 |
sago007 |
2015-12-25 13:30 |
432 |
NFont::NFont(SDL_RWops* file_rwops_ttf, Uint8 own_rwops, Uint32 pointSize, const NFont::Color& color, int style) { |
| 53203200 |
sago007 |
2015-12-25 13:30 |
433 |
init(); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
434 |
load(file_rwops_ttf, own_rwops, pointSize, color, style); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
435 |
} |
| 53203200 |
sago007 |
2015-12-25 13:30 |
436 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
437 |
#else |
| 53203200 |
sago007 |
2015-12-25 13:30 |
438 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
439 |
NFont::NFont(NFont_Target* renderer, TTF_Font* ttf) { |
| 53203200 |
sago007 |
2015-12-25 13:30 |
440 |
init(); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
441 |
load(renderer, ttf, FC_GetDefaultColor(font)); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
442 |
} |
| 53203200 |
sago007 |
2015-12-25 13:30 |
443 |
NFont::NFont(NFont_Target* renderer, TTF_Font* ttf, const NFont::Color& color) { |
| 53203200 |
sago007 |
2015-12-25 13:30 |
444 |
init(); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
445 |
load(renderer, ttf, color); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
446 |
} |
| 53203200 |
sago007 |
2015-12-25 13:30 |
447 |
NFont::NFont(NFont_Target* renderer, const char* filename_ttf, Uint32 pointSize) { |
| 53203200 |
sago007 |
2015-12-25 13:30 |
448 |
init(); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
449 |
load(renderer, filename_ttf, pointSize); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
450 |
} |
| 53203200 |
sago007 |
2015-12-25 13:30 |
451 |
NFont::NFont(NFont_Target* renderer, const char* filename_ttf, Uint32 pointSize, const NFont::Color& color, int style) { |
| 53203200 |
sago007 |
2015-12-25 13:30 |
452 |
init(); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
453 |
load(renderer, filename_ttf, pointSize, color, style); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
454 |
} |
| 53203200 |
sago007 |
2015-12-25 13:30 |
455 |
NFont::NFont(NFont_Target* renderer, SDL_RWops* file_rwops_ttf, Uint8 own_rwops, Uint32 pointSize, const NFont::Color& color, int style) { |
| 53203200 |
sago007 |
2015-12-25 13:30 |
456 |
init(); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
457 |
load(renderer, file_rwops_ttf, own_rwops, pointSize, color, style); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
458 |
} |
| 53203200 |
sago007 |
2015-12-25 13:30 |
459 |
#endif |
| 53203200 |
sago007 |
2015-12-25 13:30 |
460 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
461 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
462 |
NFont::~NFont() { |
| 53203200 |
sago007 |
2015-12-25 13:30 |
463 |
FC_FreeFont(font); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
464 |
} |
| 53203200 |
sago007 |
2015-12-25 13:30 |
465 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
466 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
467 |
NFont& NFont::operator=(const NFont& font) { |
| 53203200 |
sago007 |
2015-12-25 13:30 |
468 |
// FIXME: Duplicate font data |
| 53203200 |
sago007 |
2015-12-25 13:30 |
469 |
return *this; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
470 |
} |
| 53203200 |
sago007 |
2015-12-25 13:30 |
471 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
472 |
void NFont::init() { |
| 53203200 |
sago007 |
2015-12-25 13:30 |
473 |
font = FC_CreateFont(); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
474 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
475 |
if (buffer == NULL) { |
| 53203200 |
sago007 |
2015-12-25 13:30 |
476 |
buffer = new char[1024]; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
477 |
} |
| 53203200 |
sago007 |
2015-12-25 13:30 |
478 |
} |
| 53203200 |
sago007 |
2015-12-25 13:30 |
479 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
480 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
481 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
482 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
483 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
484 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
485 |
void NFont::setLoadingString(const char* str) { |
| 53203200 |
sago007 |
2015-12-25 13:30 |
486 |
FC_SetLoadingString(font, str); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
487 |
} |
| 53203200 |
sago007 |
2015-12-25 13:30 |
488 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
489 |
#ifdef NFONT_USE_SDL_GPU |
| 53203200 |
sago007 |
2015-12-25 13:30 |
490 |
bool NFont::load(TTF_Font* ttf) |
| 53203200 |
sago007 |
2015-12-25 13:30 |
491 |
#else |
| 53203200 |
sago007 |
2015-12-25 13:30 |
492 |
bool NFont::load(NFont_Target* renderer, TTF_Font* ttf) |
| 53203200 |
sago007 |
2015-12-25 13:30 |
493 |
#endif |
| 53203200 |
sago007 |
2015-12-25 13:30 |
494 |
{ |
| 53203200 |
sago007 |
2015-12-25 13:30 |
495 |
#ifdef NFONT_USE_SDL_GPU |
| 53203200 |
sago007 |
2015-12-25 13:30 |
496 |
return load(ttf, FC_GetDefaultColor(font)); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
497 |
#else |
| 53203200 |
sago007 |
2015-12-25 13:30 |
498 |
return load(renderer, ttf, Color(0,0,0,255)); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
499 |
#endif |
| 53203200 |
sago007 |
2015-12-25 13:30 |
500 |
} |
| 53203200 |
sago007 |
2015-12-25 13:30 |
501 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
502 |
#ifdef NFONT_USE_SDL_GPU |
| 53203200 |
sago007 |
2015-12-25 13:30 |
503 |
bool NFont::load(TTF_Font* ttf, const NFont::Color& color) |
| 53203200 |
sago007 |
2015-12-25 13:30 |
504 |
#else |
| 53203200 |
sago007 |
2015-12-25 13:30 |
505 |
bool NFont::load(NFont_Target* renderer, TTF_Font* ttf, const NFont::Color& color) |
| 53203200 |
sago007 |
2015-12-25 13:30 |
506 |
#endif |
| 53203200 |
sago007 |
2015-12-25 13:30 |
507 |
{ |
| 53203200 |
sago007 |
2015-12-25 13:30 |
508 |
if (ttf == NULL) { |
| 53203200 |
sago007 |
2015-12-25 13:30 |
509 |
return false; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
510 |
} |
| 53203200 |
sago007 |
2015-12-25 13:30 |
511 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
512 |
#ifndef NFONT_USE_SDL_GPU |
| 53203200 |
sago007 |
2015-12-25 13:30 |
513 |
if (renderer == NULL) { |
| 53203200 |
sago007 |
2015-12-25 13:30 |
514 |
return false; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
515 |
} |
| 53203200 |
sago007 |
2015-12-25 13:30 |
516 |
#endif |
| 53203200 |
sago007 |
2015-12-25 13:30 |
517 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
518 |
FC_ClearFont(font); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
519 |
#ifdef NFONT_USE_SDL_GPU |
| 53203200 |
sago007 |
2015-12-25 13:30 |
520 |
return FC_LoadFontFromTTF(font, ttf, color.to_SDL_Color()); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
521 |
#else |
| 53203200 |
sago007 |
2015-12-25 13:30 |
522 |
return FC_LoadFontFromTTF(font, renderer, ttf, color.to_SDL_Color()); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
523 |
#endif |
| 53203200 |
sago007 |
2015-12-25 13:30 |
524 |
} |
| 53203200 |
sago007 |
2015-12-25 13:30 |
525 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
526 |
#ifdef NFONT_USE_SDL_GPU |
| 53203200 |
sago007 |
2015-12-25 13:30 |
527 |
bool NFont::load(const char* filename_ttf, Uint32 pointSize) |
| 53203200 |
sago007 |
2015-12-25 13:30 |
528 |
#else |
| 53203200 |
sago007 |
2015-12-25 13:30 |
529 |
bool NFont::load(NFont_Target* renderer, const char* filename_ttf, Uint32 pointSize) |
| 53203200 |
sago007 |
2015-12-25 13:30 |
530 |
#endif |
| 53203200 |
sago007 |
2015-12-25 13:30 |
531 |
{ |
| 53203200 |
sago007 |
2015-12-25 13:30 |
532 |
#ifdef NFONT_USE_SDL_GPU |
| 53203200 |
sago007 |
2015-12-25 13:30 |
533 |
return load(filename_ttf, pointSize, Color(0,0,0,255)); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
534 |
#else |
| 53203200 |
sago007 |
2015-12-25 13:30 |
535 |
return load(renderer, filename_ttf, pointSize, Color(0,0,0,255)); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
536 |
#endif |
| 53203200 |
sago007 |
2015-12-25 13:30 |
537 |
} |
| 53203200 |
sago007 |
2015-12-25 13:30 |
538 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
539 |
#ifdef NFONT_USE_SDL_GPU |
| 53203200 |
sago007 |
2015-12-25 13:30 |
540 |
bool NFont::load(const char* filename_ttf, Uint32 pointSize, const NFont::Color& color, int style) |
| 53203200 |
sago007 |
2015-12-25 13:30 |
541 |
#else |
| 53203200 |
sago007 |
2015-12-25 13:30 |
542 |
bool NFont::load(NFont_Target* renderer, const char* filename_ttf, Uint32 pointSize, const NFont::Color& color, int style) |
| 53203200 |
sago007 |
2015-12-25 13:30 |
543 |
#endif |
| 53203200 |
sago007 |
2015-12-25 13:30 |
544 |
{ |
| 53203200 |
sago007 |
2015-12-25 13:30 |
545 |
FC_ClearFont(font); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
546 |
#ifdef NFONT_USE_SDL_GPU |
| 53203200 |
sago007 |
2015-12-25 13:30 |
547 |
return FC_LoadFont(font, filename_ttf, pointSize, color.to_SDL_Color(), style); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
548 |
#else |
| 53203200 |
sago007 |
2015-12-25 13:30 |
549 |
return FC_LoadFont(font, renderer, filename_ttf, pointSize, color.to_SDL_Color(), style); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
550 |
#endif |
| 53203200 |
sago007 |
2015-12-25 13:30 |
551 |
} |
| 53203200 |
sago007 |
2015-12-25 13:30 |
552 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
553 |
#ifdef NFONT_USE_SDL_GPU |
| 53203200 |
sago007 |
2015-12-25 13:30 |
554 |
bool NFont::load(SDL_RWops* file_rwops_ttf, Uint8 own_rwops, Uint32 pointSize, const NFont::Color& color, int style) |
| 53203200 |
sago007 |
2015-12-25 13:30 |
555 |
#else |
| 53203200 |
sago007 |
2015-12-25 13:30 |
556 |
bool NFont::load(NFont_Target* renderer, SDL_RWops* file_rwops_ttf, Uint8 own_rwops, Uint32 pointSize, const NFont::Color& color, int style) |
| 53203200 |
sago007 |
2015-12-25 13:30 |
557 |
#endif |
| 53203200 |
sago007 |
2015-12-25 13:30 |
558 |
{ |
| 53203200 |
sago007 |
2015-12-25 13:30 |
559 |
FC_ClearFont(font); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
560 |
#ifdef NFONT_USE_SDL_GPU |
| 53203200 |
sago007 |
2015-12-25 13:30 |
561 |
return FC_LoadFont_RW(font, file_rwops_ttf, own_rwops, pointSize, color.to_SDL_Color(), style); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
562 |
#else |
| 53203200 |
sago007 |
2015-12-25 13:30 |
563 |
return FC_LoadFont_RW(font, renderer, file_rwops_ttf, own_rwops, pointSize, color.to_SDL_Color(), style); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
564 |
#endif |
| 53203200 |
sago007 |
2015-12-25 13:30 |
565 |
} |
| 53203200 |
sago007 |
2015-12-25 13:30 |
566 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
567 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
568 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
569 |
void NFont::free() { |
| 53203200 |
sago007 |
2015-12-25 13:30 |
570 |
FC_ClearFont(font); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
571 |
} |
| 53203200 |
sago007 |
2015-12-25 13:30 |
572 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
573 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
574 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
575 |
NFont::Rectf NFont::draw(NFont_Target* dest, float x, float y, const char* formatted_text, ...) { |
| 53203200 |
sago007 |
2015-12-25 13:30 |
576 |
if (formatted_text == NULL) { |
| 53203200 |
sago007 |
2015-12-25 13:30 |
577 |
return Rectf(x, y, 0, 0); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
578 |
} |
| 53203200 |
sago007 |
2015-12-25 13:30 |
579 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
580 |
va_list lst; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
581 |
va_start(lst, formatted_text); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
582 |
vsprintf(buffer, formatted_text, lst); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
583 |
va_end(lst); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
584 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
585 |
return FC_Draw(font, dest, x, y, "%s", buffer); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
586 |
} |
| 53203200 |
sago007 |
2015-12-25 13:30 |
587 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
588 |
/*static int getIndexPastWidth(const char* text, int width, const int* charWidth) |
| 53203200 |
sago007 |
2015-12-25 13:30 |
589 |
{ |
| 53203200 |
sago007 |
2015-12-25 13:30 |
590 |
int charnum; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
591 |
int len = strlen(text); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
592 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
593 |
for (int index = 0; index < len; index++) |
| 53203200 |
sago007 |
2015-12-25 13:30 |
594 |
{ |
| 53203200 |
sago007 |
2015-12-25 13:30 |
595 |
char c = text[index]; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
596 |
charnum = (unsigned char)(c) - 33; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
597 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
598 |
// spaces and nonprintable characters |
| 53203200 |
sago007 |
2015-12-25 13:30 |
599 |
if (c == ' ' || charnum > 222) |
| 53203200 |
sago007 |
2015-12-25 13:30 |
600 |
{ |
| 53203200 |
sago007 |
2015-12-25 13:30 |
601 |
width -= charWidth[0]; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
602 |
} |
| 53203200 |
sago007 |
2015-12-25 13:30 |
603 |
else |
| 53203200 |
sago007 |
2015-12-25 13:30 |
604 |
width -= charWidth[charnum]; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
605 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
606 |
if(width <= 0) |
| 53203200 |
sago007 |
2015-12-25 13:30 |
607 |
return index; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
608 |
} |
| 53203200 |
sago007 |
2015-12-25 13:30 |
609 |
return 0; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
610 |
}*/ |
| 53203200 |
sago007 |
2015-12-25 13:30 |
611 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
612 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
613 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
614 |
/*static list<string> explode(const string& str, char delimiter) |
| 53203200 |
sago007 |
2015-12-25 13:30 |
615 |
{ |
| 53203200 |
sago007 |
2015-12-25 13:30 |
616 |
list<string> result; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
617 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
618 |
size_t oldPos = 0; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
619 |
size_t pos = str.find_first_of(delimiter); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
620 |
while(pos != string::npos) |
| 53203200 |
sago007 |
2015-12-25 13:30 |
621 |
{ |
| 53203200 |
sago007 |
2015-12-25 13:30 |
622 |
result.push_back(str.substr(oldPos, pos - oldPos)); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
623 |
oldPos = pos+1; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
624 |
pos = str.find_first_of(delimiter, oldPos); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
625 |
} |
| 53203200 |
sago007 |
2015-12-25 13:30 |
626 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
627 |
result.push_back(str.substr(oldPos, string::npos)); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
628 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
629 |
return result; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
630 |
}*/ |
| 53203200 |
sago007 |
2015-12-25 13:30 |
631 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
632 |
NFont::Rectf NFont::drawBox(NFont_Target* dest, const Rectf& box, const char* formatted_text, ...) { |
| 53203200 |
sago007 |
2015-12-25 13:30 |
633 |
if (formatted_text == NULL) { |
| 53203200 |
sago007 |
2015-12-25 13:30 |
634 |
return Rectf(box.x, box.y, 0, 0); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
635 |
} |
| 53203200 |
sago007 |
2015-12-25 13:30 |
636 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
637 |
va_list lst; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
638 |
va_start(lst, formatted_text); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
639 |
vsprintf(buffer, formatted_text, lst); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
640 |
va_end(lst); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
641 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
642 |
#ifdef NFONT_USE_SDL_GPU |
| 53203200 |
sago007 |
2015-12-25 13:30 |
643 |
return FC_DrawBox(font, dest, box.to_GPU_Rect(), "%s", buffer); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
644 |
#else |
| 53203200 |
sago007 |
2015-12-25 13:30 |
645 |
return FC_DrawBox(font, dest, box.to_SDL_Rect(), "%s", buffer); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
646 |
#endif |
| 53203200 |
sago007 |
2015-12-25 13:30 |
647 |
} |
| 53203200 |
sago007 |
2015-12-25 13:30 |
648 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
649 |
static FC_AlignEnum translate_enum_NFont_to_FC(NFont::AlignEnum align) { |
| 53203200 |
sago007 |
2015-12-25 13:30 |
650 |
switch (align) { |
| 53203200 |
sago007 |
2015-12-25 13:30 |
651 |
case NFont::LEFT: |
| 53203200 |
sago007 |
2015-12-25 13:30 |
652 |
return FC_ALIGN_LEFT; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
653 |
case NFont::CENTER: |
| 53203200 |
sago007 |
2015-12-25 13:30 |
654 |
return FC_ALIGN_CENTER; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
655 |
case NFont::RIGHT: |
| 53203200 |
sago007 |
2015-12-25 13:30 |
656 |
return FC_ALIGN_RIGHT; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
657 |
default: |
| 53203200 |
sago007 |
2015-12-25 13:30 |
658 |
return FC_ALIGN_LEFT; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
659 |
} |
| 53203200 |
sago007 |
2015-12-25 13:30 |
660 |
} |
| 53203200 |
sago007 |
2015-12-25 13:30 |
661 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
662 |
NFont::Rectf NFont::drawBox(NFont_Target* dest, const Rectf& box, AlignEnum align, const char* formatted_text, ...) { |
| 53203200 |
sago007 |
2015-12-25 13:30 |
663 |
if (formatted_text == NULL) { |
| 53203200 |
sago007 |
2015-12-25 13:30 |
664 |
return Rectf(box.x, box.y, 0, 0); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
665 |
} |
| 53203200 |
sago007 |
2015-12-25 13:30 |
666 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
667 |
va_list lst; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
668 |
va_start(lst, formatted_text); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
669 |
vsprintf(buffer, formatted_text, lst); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
670 |
va_end(lst); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
671 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
672 |
#ifdef NFONT_USE_SDL_GPU |
| 53203200 |
sago007 |
2015-12-25 13:30 |
673 |
return FC_DrawBoxAlign(font, dest, box.to_GPU_Rect(), translate_enum_NFont_to_FC(align), "%s", buffer); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
674 |
#else |
| 53203200 |
sago007 |
2015-12-25 13:30 |
675 |
return FC_DrawBoxAlign(font, dest, box.to_SDL_Rect(), translate_enum_NFont_to_FC(align), "%s", buffer); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
676 |
#endif |
| 53203200 |
sago007 |
2015-12-25 13:30 |
677 |
} |
| 53203200 |
sago007 |
2015-12-25 13:30 |
678 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
679 |
NFont::Rectf NFont::drawBox(NFont_Target* dest, const Rectf& box, const Scale& scale, const char* formatted_text, ...) { |
| 53203200 |
sago007 |
2015-12-25 13:30 |
680 |
if (formatted_text == NULL) { |
| 53203200 |
sago007 |
2015-12-25 13:30 |
681 |
return Rectf(box.x, box.y, 0, 0); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
682 |
} |
| 53203200 |
sago007 |
2015-12-25 13:30 |
683 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
684 |
va_list lst; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
685 |
va_start(lst, formatted_text); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
686 |
vsprintf(buffer, formatted_text, lst); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
687 |
va_end(lst); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
688 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
689 |
#ifdef NFONT_USE_SDL_GPU |
| 53203200 |
sago007 |
2015-12-25 13:30 |
690 |
return FC_DrawBoxScale(font, dest, box.to_GPU_Rect(), FC_MakeScale(scale.x, scale.y), "%s", buffer); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
691 |
#else |
| 53203200 |
sago007 |
2015-12-25 13:30 |
692 |
return FC_DrawBoxScale(font, dest, box.to_SDL_Rect(), FC_MakeScale(scale.x, scale.y), "%s", buffer); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
693 |
#endif |
| 53203200 |
sago007 |
2015-12-25 13:30 |
694 |
} |
| 53203200 |
sago007 |
2015-12-25 13:30 |
695 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
696 |
NFont::Rectf NFont::drawBox(NFont_Target* dest, const Rectf& box, const Color& color, const char* formatted_text, ...) { |
| 53203200 |
sago007 |
2015-12-25 13:30 |
697 |
if (formatted_text == NULL) { |
| 53203200 |
sago007 |
2015-12-25 13:30 |
698 |
return Rectf(box.x, box.y, 0, 0); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
699 |
} |
| 53203200 |
sago007 |
2015-12-25 13:30 |
700 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
701 |
va_list lst; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
702 |
va_start(lst, formatted_text); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
703 |
vsprintf(buffer, formatted_text, lst); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
704 |
va_end(lst); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
705 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
706 |
#ifdef NFONT_USE_SDL_GPU |
| 53203200 |
sago007 |
2015-12-25 13:30 |
707 |
return FC_DrawBoxColor(font, dest, box.to_GPU_Rect(), color.to_SDL_Color(), "%s", buffer); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
708 |
#else |
| 53203200 |
sago007 |
2015-12-25 13:30 |
709 |
return FC_DrawBoxColor(font, dest, box.to_SDL_Rect(), color.to_SDL_Color(), "%s", buffer); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
710 |
#endif |
| 53203200 |
sago007 |
2015-12-25 13:30 |
711 |
} |
| 53203200 |
sago007 |
2015-12-25 13:30 |
712 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
713 |
NFont::Rectf NFont::drawBox(NFont_Target* dest, const Rectf& box, const Effect& effect, const char* formatted_text, ...) { |
| 53203200 |
sago007 |
2015-12-25 13:30 |
714 |
if (formatted_text == NULL) { |
| 53203200 |
sago007 |
2015-12-25 13:30 |
715 |
return Rectf(box.x, box.y, 0, 0); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
716 |
} |
| 53203200 |
sago007 |
2015-12-25 13:30 |
717 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
718 |
va_list lst; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
719 |
va_start(lst, formatted_text); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
720 |
vsprintf(buffer, formatted_text, lst); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
721 |
va_end(lst); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
722 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
723 |
#ifdef NFONT_USE_SDL_GPU |
| 53203200 |
sago007 |
2015-12-25 13:30 |
724 |
return FC_DrawBoxEffect(font, dest, box.to_GPU_Rect(), FC_MakeEffect(translate_enum_NFont_to_FC(effect.alignment), FC_MakeScale(effect.scale.x, effect.scale.y), effect.color.to_SDL_Color()), "%s", buffer); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
725 |
#else |
| 53203200 |
sago007 |
2015-12-25 13:30 |
726 |
return FC_DrawBoxEffect(font, dest, box.to_SDL_Rect(), FC_MakeEffect(translate_enum_NFont_to_FC(effect.alignment), FC_MakeScale(effect.scale.x, effect.scale.y), effect.color.to_SDL_Color()), "%s", buffer); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
727 |
#endif |
| 53203200 |
sago007 |
2015-12-25 13:30 |
728 |
} |
| 53203200 |
sago007 |
2015-12-25 13:30 |
729 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
730 |
NFont::Rectf NFont::drawColumn(NFont_Target* dest, float x, float y, Uint16 width, const char* formatted_text, ...) { |
| 53203200 |
sago007 |
2015-12-25 13:30 |
731 |
if (formatted_text == NULL) { |
| 53203200 |
sago007 |
2015-12-25 13:30 |
732 |
return Rectf(x, y, 0, 0); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
733 |
} |
| 53203200 |
sago007 |
2015-12-25 13:30 |
734 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
735 |
va_list lst; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
736 |
va_start(lst, formatted_text); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
737 |
vsprintf(buffer, formatted_text, lst); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
738 |
va_end(lst); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
739 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
740 |
return FC_DrawColumn(font, dest, x, y, width, "%s", buffer); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
741 |
} |
| 53203200 |
sago007 |
2015-12-25 13:30 |
742 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
743 |
NFont::Rectf NFont::drawColumn(NFont_Target* dest, float x, float y, Uint16 width, AlignEnum align, const char* formatted_text, ...) { |
| 53203200 |
sago007 |
2015-12-25 13:30 |
744 |
if (formatted_text == NULL) { |
| 53203200 |
sago007 |
2015-12-25 13:30 |
745 |
return Rectf(x, y, 0, 0); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
746 |
} |
| 53203200 |
sago007 |
2015-12-25 13:30 |
747 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
748 |
va_list lst; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
749 |
va_start(lst, formatted_text); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
750 |
vsprintf(buffer, formatted_text, lst); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
751 |
va_end(lst); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
752 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
753 |
return FC_DrawColumnAlign(font, dest, x, y, width, translate_enum_NFont_to_FC(align), "%s", buffer); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
754 |
} |
| 53203200 |
sago007 |
2015-12-25 13:30 |
755 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
756 |
NFont::Rectf NFont::drawColumn(NFont_Target* dest, float x, float y, Uint16 width, const Scale& scale, const char* formatted_text, ...) { |
| 53203200 |
sago007 |
2015-12-25 13:30 |
757 |
if (formatted_text == NULL) { |
| 53203200 |
sago007 |
2015-12-25 13:30 |
758 |
return Rectf(x, y, 0, 0); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
759 |
} |
| 53203200 |
sago007 |
2015-12-25 13:30 |
760 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
761 |
va_list lst; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
762 |
va_start(lst, formatted_text); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
763 |
vsprintf(buffer, formatted_text, lst); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
764 |
va_end(lst); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
765 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
766 |
return FC_DrawColumnScale(font, dest, x, y, width, FC_MakeScale(scale.x, scale.y), "%s", buffer); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
767 |
} |
| 53203200 |
sago007 |
2015-12-25 13:30 |
768 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
769 |
NFont::Rectf NFont::drawColumn(NFont_Target* dest, float x, float y, Uint16 width, const Color& color, const char* formatted_text, ...) { |
| 53203200 |
sago007 |
2015-12-25 13:30 |
770 |
if (formatted_text == NULL) { |
| 53203200 |
sago007 |
2015-12-25 13:30 |
771 |
return Rectf(x, y, 0, 0); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
772 |
} |
| 53203200 |
sago007 |
2015-12-25 13:30 |
773 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
774 |
va_list lst; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
775 |
va_start(lst, formatted_text); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
776 |
vsprintf(buffer, formatted_text, lst); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
777 |
va_end(lst); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
778 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
779 |
return FC_DrawColumnColor(font, dest, x, y, width, color.to_SDL_Color(), "%s", buffer); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
780 |
} |
| 53203200 |
sago007 |
2015-12-25 13:30 |
781 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
782 |
NFont::Rectf NFont::drawColumn(NFont_Target* dest, float x, float y, Uint16 width, const Effect& effect, const char* formatted_text, ...) { |
| 53203200 |
sago007 |
2015-12-25 13:30 |
783 |
if (formatted_text == NULL) { |
| 53203200 |
sago007 |
2015-12-25 13:30 |
784 |
return Rectf(x, y, 0, 0); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
785 |
} |
| 53203200 |
sago007 |
2015-12-25 13:30 |
786 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
787 |
va_list lst; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
788 |
va_start(lst, formatted_text); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
789 |
vsprintf(buffer, formatted_text, lst); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
790 |
va_end(lst); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
791 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
792 |
#ifdef NFONT_USE_SDL_GPU |
| 53203200 |
sago007 |
2015-12-25 13:30 |
793 |
return FC_DrawColumnEffect(font, dest, x, y, width, FC_MakeEffect(translate_enum_NFont_to_FC(effect.alignment), FC_MakeScale(effect.scale.x, effect.scale.y), effect.color.to_SDL_Color()), "%s", buffer); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
794 |
#else |
| 53203200 |
sago007 |
2015-12-25 13:30 |
795 |
return FC_DrawColumnEffect(font, dest, x, y, width, FC_MakeEffect(translate_enum_NFont_to_FC(effect.alignment), FC_MakeScale(effect.scale.x, effect.scale.y), effect.color.to_SDL_Color()), "%s", buffer); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
796 |
#endif |
| 53203200 |
sago007 |
2015-12-25 13:30 |
797 |
} |
| 53203200 |
sago007 |
2015-12-25 13:30 |
798 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
799 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
800 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
801 |
NFont::Rectf NFont::draw(NFont_Target* dest, float x, float y, const Scale& scale, const char* formatted_text, ...) { |
| 53203200 |
sago007 |
2015-12-25 13:30 |
802 |
if (formatted_text == NULL) { |
| 53203200 |
sago007 |
2015-12-25 13:30 |
803 |
return Rectf(x, y, 0, 0); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
804 |
} |
| 53203200 |
sago007 |
2015-12-25 13:30 |
805 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
806 |
va_list lst; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
807 |
va_start(lst, formatted_text); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
808 |
vsprintf(buffer, formatted_text, lst); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
809 |
va_end(lst); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
810 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
811 |
return FC_DrawScale(font, dest, x, y, FC_MakeScale(scale.x, scale.y), "%s", buffer); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
812 |
} |
| 53203200 |
sago007 |
2015-12-25 13:30 |
813 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
814 |
NFont::Rectf NFont::draw(NFont_Target* dest, float x, float y, AlignEnum align, const char* formatted_text, ...) { |
| 53203200 |
sago007 |
2015-12-25 13:30 |
815 |
if (formatted_text == NULL) { |
| 53203200 |
sago007 |
2015-12-25 13:30 |
816 |
return Rectf(x, y, 0, 0); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
817 |
} |
| 53203200 |
sago007 |
2015-12-25 13:30 |
818 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
819 |
va_list lst; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
820 |
va_start(lst, formatted_text); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
821 |
vsprintf(buffer, formatted_text, lst); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
822 |
va_end(lst); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
823 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
824 |
return FC_DrawAlign(font, dest, x, y, translate_enum_NFont_to_FC(align), "%s", buffer); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
825 |
} |
| 53203200 |
sago007 |
2015-12-25 13:30 |
826 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
827 |
NFont::Rectf NFont::draw(NFont_Target* dest, float x, float y, const Color& color, const char* formatted_text, ...) { |
| 53203200 |
sago007 |
2015-12-25 13:30 |
828 |
if (formatted_text == NULL) { |
| 53203200 |
sago007 |
2015-12-25 13:30 |
829 |
return Rectf(x, y, 0, 0); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
830 |
} |
| 53203200 |
sago007 |
2015-12-25 13:30 |
831 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
832 |
va_list lst; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
833 |
va_start(lst, formatted_text); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
834 |
vsprintf(buffer, formatted_text, lst); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
835 |
va_end(lst); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
836 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
837 |
return FC_DrawColor(font, dest, x, y, color.to_SDL_Color(), "%s", buffer); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
838 |
} |
| 53203200 |
sago007 |
2015-12-25 13:30 |
839 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
840 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
841 |
NFont::Rectf NFont::draw(NFont_Target* dest, float x, float y, const Effect& effect, const char* formatted_text, ...) { |
| 53203200 |
sago007 |
2015-12-25 13:30 |
842 |
if (formatted_text == NULL) { |
| 53203200 |
sago007 |
2015-12-25 13:30 |
843 |
return Rectf(x, y, 0, 0); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
844 |
} |
| 53203200 |
sago007 |
2015-12-25 13:30 |
845 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
846 |
va_list lst; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
847 |
va_start(lst, formatted_text); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
848 |
vsprintf(buffer, formatted_text, lst); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
849 |
va_end(lst); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
850 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
851 |
return FC_DrawEffect(font, dest, x, y, FC_MakeEffect(translate_enum_NFont_to_FC(effect.alignment), FC_MakeScale(effect.scale.x, effect.scale.y), effect.color.to_SDL_Color()), "%s", buffer); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
852 |
} |
| 53203200 |
sago007 |
2015-12-25 13:30 |
853 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
854 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
855 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
856 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
857 |
// Getters |
| 53203200 |
sago007 |
2015-12-25 13:30 |
858 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
859 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
860 |
NFont::FilterEnum NFont::getFilterMode() const { |
| 53203200 |
sago007 |
2015-12-25 13:30 |
861 |
FC_FilterEnum f = FC_GetFilterMode(font); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
862 |
if (f == FC_FILTER_LINEAR) { |
| 53203200 |
sago007 |
2015-12-25 13:30 |
863 |
return NFont::LINEAR; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
864 |
} |
| 53203200 |
sago007 |
2015-12-25 13:30 |
865 |
return NFont::NEAREST; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
866 |
} |
| 53203200 |
sago007 |
2015-12-25 13:30 |
867 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
868 |
Uint16 NFont::getHeight() const { |
| 53203200 |
sago007 |
2015-12-25 13:30 |
869 |
return FC_GetLineHeight(font); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
870 |
} |
| 53203200 |
sago007 |
2015-12-25 13:30 |
871 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
872 |
Uint16 NFont::getHeight(const char* formatted_text, ...) const { |
| 53203200 |
sago007 |
2015-12-25 13:30 |
873 |
if (formatted_text == NULL) { |
| 53203200 |
sago007 |
2015-12-25 13:30 |
874 |
return 0; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
875 |
} |
| 53203200 |
sago007 |
2015-12-25 13:30 |
876 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
877 |
va_list lst; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
878 |
va_start(lst, formatted_text); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
879 |
vsprintf(buffer, formatted_text, lst); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
880 |
va_end(lst); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
881 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
882 |
return FC_GetHeight(font, "%s", buffer); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
883 |
} |
| 53203200 |
sago007 |
2015-12-25 13:30 |
884 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
885 |
Uint16 NFont::getWidth(const char* formatted_text, ...) { |
| 53203200 |
sago007 |
2015-12-25 13:30 |
886 |
if (formatted_text == NULL) { |
| 53203200 |
sago007 |
2015-12-25 13:30 |
887 |
return 0; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
888 |
} |
| 53203200 |
sago007 |
2015-12-25 13:30 |
889 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
890 |
va_list lst; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
891 |
va_start(lst, formatted_text); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
892 |
vsprintf(buffer, formatted_text, lst); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
893 |
va_end(lst); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
894 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
895 |
return FC_GetWidth(font, "%s", buffer); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
896 |
} |
| 53203200 |
sago007 |
2015-12-25 13:30 |
897 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
898 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
899 |
NFont::Rectf NFont::getCharacterOffset(Uint16 position_index, int column_width, const char* formatted_text, ...) { |
| 53203200 |
sago007 |
2015-12-25 13:30 |
900 |
if (formatted_text == NULL) { |
| 53203200 |
sago007 |
2015-12-25 13:30 |
901 |
return Rectf(0,0,0,0); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
902 |
} |
| 53203200 |
sago007 |
2015-12-25 13:30 |
903 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
904 |
va_list lst; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
905 |
va_start(lst, formatted_text); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
906 |
vsprintf(buffer, formatted_text, lst); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
907 |
va_end(lst); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
908 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
909 |
return FC_GetCharacterOffset(font, position_index, column_width, "%s", buffer); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
910 |
} |
| 53203200 |
sago007 |
2015-12-25 13:30 |
911 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
912 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
913 |
Uint16 NFont::getColumnHeight(Uint16 width, const char* formatted_text, ...) { |
| 53203200 |
sago007 |
2015-12-25 13:30 |
914 |
if (formatted_text == NULL || width == 0) { |
| 53203200 |
sago007 |
2015-12-25 13:30 |
915 |
return 0; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
916 |
} |
| 53203200 |
sago007 |
2015-12-25 13:30 |
917 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
918 |
va_list lst; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
919 |
va_start(lst, formatted_text); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
920 |
vsprintf(buffer, formatted_text, lst); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
921 |
va_end(lst); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
922 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
923 |
return FC_GetColumnHeight(font, width, "%s", buffer); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
924 |
} |
| 53203200 |
sago007 |
2015-12-25 13:30 |
925 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
926 |
int NFont::getAscent(const char character) { |
| 53203200 |
sago007 |
2015-12-25 13:30 |
927 |
return FC_GetAscent(font, "%c", character); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
928 |
} |
| 53203200 |
sago007 |
2015-12-25 13:30 |
929 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
930 |
int NFont::getAscent() const { |
| 53203200 |
sago007 |
2015-12-25 13:30 |
931 |
return FC_GetAscent(font, NULL); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
932 |
} |
| 53203200 |
sago007 |
2015-12-25 13:30 |
933 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
934 |
int NFont::getAscent(const char* formatted_text, ...) { |
| 53203200 |
sago007 |
2015-12-25 13:30 |
935 |
if (formatted_text == NULL) { |
| 53203200 |
sago007 |
2015-12-25 13:30 |
936 |
return FC_GetAscent(font, NULL); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
937 |
} |
| 53203200 |
sago007 |
2015-12-25 13:30 |
938 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
939 |
va_list lst; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
940 |
va_start(lst, formatted_text); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
941 |
vsprintf(buffer, formatted_text, lst); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
942 |
va_end(lst); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
943 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
944 |
return FC_GetAscent(font, "%s", buffer); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
945 |
} |
| 53203200 |
sago007 |
2015-12-25 13:30 |
946 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
947 |
int NFont::getDescent(const char character) { |
| 53203200 |
sago007 |
2015-12-25 13:30 |
948 |
return FC_GetDescent(font, "%c", character); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
949 |
} |
| 53203200 |
sago007 |
2015-12-25 13:30 |
950 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
951 |
int NFont::getDescent() const { |
| 53203200 |
sago007 |
2015-12-25 13:30 |
952 |
return FC_GetDescent(font, NULL); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
953 |
} |
| 53203200 |
sago007 |
2015-12-25 13:30 |
954 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
955 |
int NFont::getDescent(const char* formatted_text, ...) { |
| 53203200 |
sago007 |
2015-12-25 13:30 |
956 |
if (formatted_text == NULL) { |
| 53203200 |
sago007 |
2015-12-25 13:30 |
957 |
return FC_GetDescent(font, NULL); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
958 |
} |
| 53203200 |
sago007 |
2015-12-25 13:30 |
959 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
960 |
va_list lst; |
| 53203200 |
sago007 |
2015-12-25 13:30 |
961 |
va_start(lst, formatted_text); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
962 |
vsprintf(buffer, formatted_text, lst); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
963 |
va_end(lst); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
964 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
965 |
return FC_GetDescent(font, "%s", buffer); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
966 |
} |
| 53203200 |
sago007 |
2015-12-25 13:30 |
967 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
968 |
int NFont::getSpacing() const { |
| 53203200 |
sago007 |
2015-12-25 13:30 |
969 |
return FC_GetSpacing(font); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
970 |
} |
| 53203200 |
sago007 |
2015-12-25 13:30 |
971 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
972 |
int NFont::getLineSpacing() const { |
| 53203200 |
sago007 |
2015-12-25 13:30 |
973 |
return FC_GetLineSpacing(font); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
974 |
} |
| 53203200 |
sago007 |
2015-12-25 13:30 |
975 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
976 |
Uint16 NFont::getBaseline() const { |
| 53203200 |
sago007 |
2015-12-25 13:30 |
977 |
return FC_GetBaseline(font); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
978 |
} |
| 53203200 |
sago007 |
2015-12-25 13:30 |
979 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
980 |
Uint16 NFont::getMaxWidth() const { |
| 53203200 |
sago007 |
2015-12-25 13:30 |
981 |
return FC_GetMaxWidth(font); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
982 |
} |
| 53203200 |
sago007 |
2015-12-25 13:30 |
983 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
984 |
NFont::Color NFont::getDefaultColor() const { |
| 53203200 |
sago007 |
2015-12-25 13:30 |
985 |
return FC_GetDefaultColor(font); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
986 |
} |
| 53203200 |
sago007 |
2015-12-25 13:30 |
987 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
988 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
989 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
990 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
991 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
992 |
// Setters |
| 53203200 |
sago007 |
2015-12-25 13:30 |
993 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
994 |
void NFont::setFilterMode(NFont::FilterEnum filter) { |
| 53203200 |
sago007 |
2015-12-25 13:30 |
995 |
if (filter == NFont::LINEAR) { |
| 53203200 |
sago007 |
2015-12-25 13:30 |
996 |
FC_SetFilterMode(font, FC_FILTER_LINEAR); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
997 |
} |
| 53203200 |
sago007 |
2015-12-25 13:30 |
998 |
else { |
| 53203200 |
sago007 |
2015-12-25 13:30 |
999 |
FC_SetFilterMode(font, FC_FILTER_NEAREST); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
1000 |
} |
| 53203200 |
sago007 |
2015-12-25 13:30 |
1001 |
} |
| 53203200 |
sago007 |
2015-12-25 13:30 |
1002 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
1003 |
void NFont::setSpacing(int LetterSpacing) { |
| 53203200 |
sago007 |
2015-12-25 13:30 |
1004 |
FC_SetSpacing(font, LetterSpacing); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
1005 |
} |
| 53203200 |
sago007 |
2015-12-25 13:30 |
1006 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
1007 |
void NFont::setLineSpacing(int LineSpacing) { |
| 53203200 |
sago007 |
2015-12-25 13:30 |
1008 |
FC_SetLineSpacing(font, LineSpacing); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
1009 |
} |
| 53203200 |
sago007 |
2015-12-25 13:30 |
1010 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
1011 |
void NFont::setBaseline() { |
| 53203200 |
sago007 |
2015-12-25 13:30 |
1012 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
1013 |
} |
| 53203200 |
sago007 |
2015-12-25 13:30 |
1014 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
1015 |
void NFont::setBaseline(Uint16 Baseline) { |
| 53203200 |
sago007 |
2015-12-25 13:30 |
1016 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
1017 |
} |
| 53203200 |
sago007 |
2015-12-25 13:30 |
1018 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
1019 |
void NFont::setDefaultColor(const Color& color) { |
| 53203200 |
sago007 |
2015-12-25 13:30 |
1020 |
FC_SetDefaultColor(font, color.to_SDL_Color()); |
| 53203200 |
sago007 |
2015-12-25 13:30 |
1021 |
} |
| 53203200 |
sago007 |
2015-12-25 13:30 |
1022 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
1023 |
void NFont::enableTTFOwnership() { |
| 53203200 |
sago007 |
2015-12-25 13:30 |
1024 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
1025 |
} |
| 53203200 |
sago007 |
2015-12-25 13:30 |
1026 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
1027 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
1028 |
|
| 53203200 |
sago007 |
2015-12-25 13:30 |
1029 |
|
|
|
1970-01-01 00:00 |
1030 |
|