add header for rendertext
This commit is contained in:
parent
c053bcbe03
commit
e304e82ab0
11 changed files with 101 additions and 86 deletions
|
@ -1,5 +1,7 @@
|
|||
// console.cpp: the console buffer, its display, and command line control
|
||||
|
||||
#include "rendertext.hh"
|
||||
|
||||
#include "engine.hh"
|
||||
|
||||
#define MAXCONLINES 1000
|
||||
|
|
|
@ -28,42 +28,6 @@ extern bool inbetweenframes, renderedframe;
|
|||
extern SDL_Window *screen;
|
||||
extern int screenw, screenh, renderw, renderh, hudw, hudh;
|
||||
|
||||
// rendertext
|
||||
struct font
|
||||
{
|
||||
struct charinfo
|
||||
{
|
||||
float x, y, w, h, offsetx, offsety, advance;
|
||||
int tex;
|
||||
};
|
||||
|
||||
char *name;
|
||||
vector<Texture *> texs;
|
||||
vector<charinfo> chars;
|
||||
int charoffset, defaultw, defaulth, scale;
|
||||
float bordermin, bordermax, outlinemin, outlinemax;
|
||||
|
||||
font() : name(NULL) {}
|
||||
~font() { DELETEA(name); }
|
||||
};
|
||||
|
||||
#define FONTH (curfont->scale)
|
||||
#define FONTW (FONTH/2)
|
||||
#define MINRESW 640
|
||||
#define MINRESH 480
|
||||
|
||||
struct Shader;
|
||||
|
||||
extern font *curfont;
|
||||
extern Shader *textshader;
|
||||
extern const matrix4x3 *textmatrix;
|
||||
extern float textscale;
|
||||
|
||||
extern font *findfont(const char *name);
|
||||
extern void reloadfonts();
|
||||
|
||||
static inline void setfont(font *f) { if(f) curfont = f; }
|
||||
|
||||
// texture
|
||||
struct cubemapside;
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
// main.cpp: initialisation & main loop
|
||||
|
||||
#include "blend.hh"
|
||||
#include "rendertext.hh"
|
||||
#include "renderva.hh"
|
||||
#include "shader.hh"
|
||||
#include "texture.hh"
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
// avidemux - ok - 3Apr09-RockKeyman:had to swap UV channels as it showed up blue
|
||||
// kino - ok
|
||||
|
||||
#include "rendertext.hh"
|
||||
#include "texture.hh"
|
||||
|
||||
#include "engine.hh"
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
#include "aa.hh"
|
||||
#include "blend.hh"
|
||||
#include "material.hh"
|
||||
#include "rendertext.hh"
|
||||
#include "renderva.hh"
|
||||
#include "texture.hh"
|
||||
#include "water.hh"
|
||||
|
|
|
@ -4,4 +4,6 @@
|
|||
#define LIGHTTILE_MAXW 16
|
||||
#define LIGHTTILE_MAXH 16
|
||||
|
||||
enum { L_NOSHADOW = 1<<0, L_NODYNSHADOW = 1<<1, L_VOLUMETRIC = 1<<2, L_NOSPEC = 1<<3 };
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
// renderparticles.cpp
|
||||
|
||||
#include "rendertext.hh"
|
||||
#include "renderva.hh"
|
||||
#include "shader.hh"
|
||||
#include "texture.hh"
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
#include "rendertext.hh"
|
||||
#include "texture.hh"
|
||||
|
||||
#include "engine.hh"
|
||||
|
@ -7,9 +8,8 @@ static font *fontdef = NULL;
|
|||
static int fontdeftex = 0;
|
||||
|
||||
font *curfont = NULL;
|
||||
int curfonttex = 0;
|
||||
|
||||
void newfont(char *name, char *tex, int *defaultw, int *defaulth, int *scale)
|
||||
static void newfont(char *name, char *tex, int *defaultw, int *defaulth, int *scale)
|
||||
{
|
||||
font *f = &fonts[name];
|
||||
if(!f->name) f->name = newstring(name);
|
||||
|
@ -29,7 +29,7 @@ void newfont(char *name, char *tex, int *defaultw, int *defaulth, int *scale)
|
|||
fontdeftex = 0;
|
||||
}
|
||||
|
||||
void fontborder(float *bordermin, float *bordermax)
|
||||
static void fontborder(float *bordermin, float *bordermax)
|
||||
{
|
||||
if(!fontdef) return;
|
||||
|
||||
|
@ -37,7 +37,7 @@ void fontborder(float *bordermin, float *bordermax)
|
|||
fontdef->bordermax = max(*bordermax, *bordermin+0.01f);
|
||||
}
|
||||
|
||||
void fontoutline(float *outlinemin, float *outlinemax)
|
||||
static void fontoutline(float *outlinemin, float *outlinemax)
|
||||
{
|
||||
if(!fontdef) return;
|
||||
|
||||
|
@ -45,21 +45,21 @@ void fontoutline(float *outlinemin, float *outlinemax)
|
|||
fontdef->outlinemax = *outlinemax;
|
||||
}
|
||||
|
||||
void fontoffset(char *c)
|
||||
static void fontoffset(char *c)
|
||||
{
|
||||
if(!fontdef) return;
|
||||
|
||||
fontdef->charoffset = c[0];
|
||||
}
|
||||
|
||||
void fontscale(int *scale)
|
||||
static void fontscale(int *scale)
|
||||
{
|
||||
if(!fontdef) return;
|
||||
|
||||
fontdef->scale = *scale > 0 ? *scale : fontdef->defaulth;
|
||||
}
|
||||
|
||||
void fonttex(char *s)
|
||||
static void fonttex(char *s)
|
||||
{
|
||||
if(!fontdef) return;
|
||||
|
||||
|
@ -69,7 +69,7 @@ void fonttex(char *s)
|
|||
fontdef->texs.add(t);
|
||||
}
|
||||
|
||||
void fontchar(float *x, float *y, float *w, float *h, float *offsetx, float *offsety, float *advance)
|
||||
static void fontchar(float *x, float *y, float *w, float *h, float *offsetx, float *offsety, float *advance)
|
||||
{
|
||||
if(!fontdef) return;
|
||||
|
||||
|
@ -84,7 +84,7 @@ void fontchar(float *x, float *y, float *w, float *h, float *offsetx, float *off
|
|||
c.tex = fontdeftex;
|
||||
}
|
||||
|
||||
void fontskip(int *n)
|
||||
static void fontskip(int *n)
|
||||
{
|
||||
if(!fontdef) return;
|
||||
loopi(max(*n, 1))
|
||||
|
@ -104,7 +104,7 @@ COMMAND(fonttex, "s");
|
|||
COMMAND(fontchar, "fffffff");
|
||||
COMMAND(fontskip, "i");
|
||||
|
||||
void fontalias(const char *dst, const char *src)
|
||||
static void fontalias(const char *dst, const char *src)
|
||||
{
|
||||
font *s = fonts.access(src);
|
||||
if(!s) return;
|
||||
|
@ -127,10 +127,12 @@ void fontalias(const char *dst, const char *src)
|
|||
|
||||
COMMAND(fontalias, "ss");
|
||||
|
||||
font *findfont(const char *name)
|
||||
# if 0
|
||||
static font *findfont(const char *name)
|
||||
{
|
||||
return fonts.access(name);
|
||||
}
|
||||
#endif
|
||||
|
||||
bool setfont(const char *name)
|
||||
{
|
||||
|
@ -181,7 +183,7 @@ float text_widthf(const char *str)
|
|||
#define FONTTAB (4*FONTW)
|
||||
#define TEXTTAB(x) ((int((x)/FONTTAB)+1.0f)*FONTTAB)
|
||||
|
||||
void tabify(const char *str, int *numtabs)
|
||||
static void tabify(const char *str, int *numtabs)
|
||||
{
|
||||
int tw = max(*numtabs, 0)*FONTTAB-1, tabs = 0;
|
||||
for(float w = text_widthf(str); w <= tw; w = TEXTTAB(w)) ++tabs;
|
||||
|
@ -326,7 +328,8 @@ static void text_color(char c, char *stack, int size, int &sp, bvec color, int a
|
|||
|
||||
#define TEXTEND(cursor) if(cursor >= i) { do { TEXTINDEX(cursor); } while(0); }
|
||||
|
||||
int text_visible(const char *str, float hitx, float hity, int maxwidth)
|
||||
#if 0
|
||||
static int text_visible(const char *str, float hitx, float hity, int maxwidth)
|
||||
{
|
||||
#define TEXTINDEX(idx)
|
||||
#define TEXTWHITE(idx) if(y+FONTH > hity && x >= hitx) return idx;
|
||||
|
@ -343,6 +346,7 @@ int text_visible(const char *str, float hitx, float hity, int maxwidth)
|
|||
#undef TEXTWORD
|
||||
return i;
|
||||
}
|
||||
#endif
|
||||
|
||||
//inverse of text_visible
|
||||
void text_posf(const char *str, int cursor, float &cx, float &cy, int maxwidth)
|
||||
|
|
75
src/engine/rendertext.hh
Normal file
75
src/engine/rendertext.hh
Normal file
|
@ -0,0 +1,75 @@
|
|||
#ifndef ENGINE_RENDERTEXT_HH
|
||||
#define ENGINE_RENDERTEXT_HH
|
||||
|
||||
#include <shared/tools.hh>
|
||||
#include <shared/geom.hh>
|
||||
|
||||
struct Texture;
|
||||
struct Shader;
|
||||
|
||||
// rendertext
|
||||
struct font
|
||||
{
|
||||
struct charinfo
|
||||
{
|
||||
float x, y, w, h, offsetx, offsety, advance;
|
||||
int tex;
|
||||
};
|
||||
|
||||
char *name;
|
||||
vector<Texture *> texs;
|
||||
vector<charinfo> chars;
|
||||
int charoffset, defaultw, defaulth, scale;
|
||||
float bordermin, bordermax, outlinemin, outlinemax;
|
||||
|
||||
font() : name(NULL) {}
|
||||
~font() { DELETEA(name); }
|
||||
};
|
||||
|
||||
#define FONTH (curfont->scale)
|
||||
#define FONTW (FONTH/2)
|
||||
#define MINRESW 640
|
||||
#define MINRESH 480
|
||||
|
||||
extern font *curfont;
|
||||
extern Shader *textshader;
|
||||
extern const matrix4x3 *textmatrix;
|
||||
extern float textscale;
|
||||
|
||||
static inline void setfont(font *f) { if(f) curfont = f; }
|
||||
|
||||
bool setfont(const char *name);
|
||||
void pushfont();
|
||||
bool popfont();
|
||||
void reloadfonts();
|
||||
|
||||
void gettextres(int &w, int &h);
|
||||
|
||||
void draw_text(const char *str, float left, float top, int r = 255, int g = 255, int b = 255, int a = 255, int cursor = -1, int maxwidth = -1);
|
||||
void draw_textf(const char *fstr, float left, float top, ...) PRINTFARGS(1, 4);
|
||||
float text_widthf(const char *str);
|
||||
void text_boundsf(const char *str, float &width, float &height, int maxwidth = -1);
|
||||
void text_posf(const char *str, int cursor, float &cx, float &cy, int maxwidth);
|
||||
|
||||
static inline int text_width(const char *str)
|
||||
{
|
||||
return int(ceil(text_widthf(str)));
|
||||
}
|
||||
|
||||
static inline void text_bounds(const char *str, int &width, int &height, int maxwidth = -1)
|
||||
{
|
||||
float widthf, heightf;
|
||||
text_boundsf(str, widthf, heightf, maxwidth);
|
||||
width = int(ceil(widthf));
|
||||
height = int(ceil(heightf));
|
||||
}
|
||||
|
||||
static inline void text_pos(const char *str, int cursor, int &cx, int &cy, int maxwidth)
|
||||
{
|
||||
float cxf, cyf;
|
||||
text_posf(str, cursor, cxf, cyf, maxwidth);
|
||||
cx = int(cxf);
|
||||
cy = int(cyf);
|
||||
}
|
||||
|
||||
#endif
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include "blend.hh"
|
||||
#include "octa.hh"
|
||||
#include "renderlights.hh"
|
||||
#include "texture.hh"
|
||||
#include "worldio.hh"
|
||||
#include "world.hh"
|
||||
|
|
|
@ -139,47 +139,10 @@ extern void conoutfv(int type, const char *fmt, va_list args);
|
|||
// main
|
||||
extern void fatal(const char *s, ...) PRINTFARGS(1, 2);
|
||||
|
||||
// rendertext
|
||||
extern bool setfont(const char *name);
|
||||
extern void pushfont();
|
||||
extern bool popfont();
|
||||
extern void gettextres(int &w, int &h);
|
||||
extern void draw_text(const char *str, float left, float top, int r = 255, int g = 255, int b = 255, int a = 255, int cursor = -1, int maxwidth = -1);
|
||||
extern void draw_textf(const char *fstr, float left, float top, ...) PRINTFARGS(1, 4);
|
||||
extern float text_widthf(const char *str);
|
||||
extern void text_boundsf(const char *str, float &width, float &height, int maxwidth = -1);
|
||||
extern int text_visible(const char *str, float hitx, float hity, int maxwidth);
|
||||
extern void text_posf(const char *str, int cursor, float &cx, float &cy, int maxwidth);
|
||||
|
||||
static inline int text_width(const char *str)
|
||||
{
|
||||
return int(ceil(text_widthf(str)));
|
||||
}
|
||||
|
||||
static inline void text_bounds(const char *str, int &width, int &height, int maxwidth = -1)
|
||||
{
|
||||
float widthf, heightf;
|
||||
text_boundsf(str, widthf, heightf, maxwidth);
|
||||
width = int(ceil(widthf));
|
||||
height = int(ceil(heightf));
|
||||
}
|
||||
|
||||
static inline void text_pos(const char *str, int cursor, int &cx, int &cy, int maxwidth)
|
||||
{
|
||||
float cxf, cyf;
|
||||
text_posf(str, cursor, cxf, cyf, maxwidth);
|
||||
cx = int(cxf);
|
||||
cy = int(cyf);
|
||||
}
|
||||
|
||||
// texture
|
||||
|
||||
struct VSlot;
|
||||
|
||||
// renderlights
|
||||
|
||||
enum { L_NOSHADOW = 1<<0, L_NODYNSHADOW = 1<<1, L_VOLUMETRIC = 1<<2, L_NOSPEC = 1<<3 };
|
||||
|
||||
// dynlight
|
||||
enum
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue