48#include <srTextureMap.hpp>
50float Text2DObjClass::_LastWidth = 0.0f;
51float Text2DObjClass::_LastHeight = 0.0f;
65Text2DObjClass::Text2DObjClass(
FontClass &font,
const char *str,
float screen_x,
float screen_y,
int fore,
int back,
ConvertClass &conv,
bool center,
bool clamp, ...):
71 va_start(args,
clamp);
72 vsprintf(text, str, args);
75 Set_Text(font, text, screen_x, screen_y, fore, back, conv, center,
clamp);
92void Text2DObjClass::Set_Text(
FontClass &font,
const char *str,
float screen_x,
float screen_y,
int fore,
int back,
ConvertClass &conv,
bool center,
bool clamp, ...)
94 int resw, resh, resbits;
104 va_start(args,
clamp);
105 vsprintf(text, str, args);
111 if (!TextTexture.Build_Texture(font, text, fore, back, conv))
116 srTextureIFace *texture_map = TextTexture.Get_Texture();
117 int tsize = TextTexture.Get_Texture_Size();
129 int mw = (fw & (tsize - 1)) ? (fw / tsize)+1 : (fw /tsize);
133 float x_delta = 0.0f;
134 float y_delta = 0.0f;
136 x_delta = -((float)fw / (float)resw) / 2.0f;
137 y_delta = -((float)fh / (float)resh) / 2.0f;
141 _LastWidth = ((float) fw / (float)resw);
142 _LastHeight = ((float) fh / (float)resh);
148 if (screen_x < 0) screen_x = 0;
149 if (screen_x + _LastWidth > 1.0f) {
150 screen_x = 1.0f - _LastWidth;
151 assert(screen_x >= 0.0f);
153 if (screen_y < 0) screen_y = 0;
154 if (screen_y + _LastHeight > 1.0f) {
155 screen_y = 1.0f - _LastHeight;
156 assert(screen_y >= 0.0f);
161 Resize(mw * 2, mw * 4);
164 Set_Texture(texture_map);
175 for (
int lp = 0; lp < mw; lp ++) {
176 int pw =
MIN(fw - (tsize *lp), tsize);
182 float tw = (float)pw / (
float)tsize;
183 float th = (float)ph / (
float)tsize;
184 float ty = ((float)fh * (float)lp) / (
float)tsize;
187 float x = ((float)lp * (float)tsize) / (
float)resw;
198 float vw = (float)pw / (
float)resw;
199 float vh = (float)ph / (
float)resh;
202 Vertex( x, y, 0, 0, ty);
203 Vertex( x + vw, y, 0, tw, ty);
204 Vertex( x, y + vh, 0, 0, ty + th);
205 Vertex( x + vw, y + vh, 0, tw, ty + th);
210 float pixel_x, pixel_y;
213 screen_x *= (float)resw;
214 screen_x = floor(screen_x) + pixel_x;
215 screen_x /= (float)resw;
218 screen_y *= (float)resh;
219 screen_y = floor(screen_y) + pixel_y;
220 screen_y /= (float)resh;
222 Set_Position(
Vector3(screen_x, screen_y, 0));
NUM clamp(NUM lo, NUM val, NUM hi)
virtual int String_Pixel_Width(char const *string) const =0
virtual int Get_Height(void) const =0
static ShaderClass _PresetOpaque2DShader
static void Get_Device_Resolution(int &set_w, int &set_h, int &get_bits, bool &get_windowed)
static void Get_Pixel_Center(float &x, float &y)