From e304e82ab01bcb83aebf63fe608f738693caf225 Mon Sep 17 00:00:00 2001 From: q66 Date: Sun, 3 May 2020 03:37:25 +0200 Subject: [PATCH] add header for rendertext --- src/engine/console.cc | 2 + src/engine/engine.hh | 36 ----------------- src/engine/main.cc | 1 + src/engine/movie.cc | 1 + src/engine/rendergl.cc | 1 + src/engine/renderlights.hh | 2 + src/engine/renderparticles.cc | 1 + src/engine/rendertext.cc | 30 ++++++++------ src/engine/rendertext.hh | 75 +++++++++++++++++++++++++++++++++++ src/engine/world.cc | 1 + src/shared/iengine.hh | 37 ----------------- 11 files changed, 101 insertions(+), 86 deletions(-) create mode 100644 src/engine/rendertext.hh diff --git a/src/engine/console.cc b/src/engine/console.cc index 18b11af..167f462 100644 --- a/src/engine/console.cc +++ b/src/engine/console.cc @@ -1,5 +1,7 @@ // console.cpp: the console buffer, its display, and command line control +#include "rendertext.hh" + #include "engine.hh" #define MAXCONLINES 1000 diff --git a/src/engine/engine.hh b/src/engine/engine.hh index 694a75c..78478ff 100644 --- a/src/engine/engine.hh +++ b/src/engine/engine.hh @@ -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 texs; - vector 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; diff --git a/src/engine/main.cc b/src/engine/main.cc index 1834c34..2a37110 100644 --- a/src/engine/main.cc +++ b/src/engine/main.cc @@ -1,6 +1,7 @@ // main.cpp: initialisation & main loop #include "blend.hh" +#include "rendertext.hh" #include "renderva.hh" #include "shader.hh" #include "texture.hh" diff --git a/src/engine/movie.cc b/src/engine/movie.cc index e8fb0d0..aa1ebc7 100644 --- a/src/engine/movie.cc +++ b/src/engine/movie.cc @@ -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" diff --git a/src/engine/rendergl.cc b/src/engine/rendergl.cc index a4bee33..4db620f 100644 --- a/src/engine/rendergl.cc +++ b/src/engine/rendergl.cc @@ -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" diff --git a/src/engine/renderlights.hh b/src/engine/renderlights.hh index d82cc4e..6baaa38 100644 --- a/src/engine/renderlights.hh +++ b/src/engine/renderlights.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 diff --git a/src/engine/renderparticles.cc b/src/engine/renderparticles.cc index e122f04..a30f814 100644 --- a/src/engine/renderparticles.cc +++ b/src/engine/renderparticles.cc @@ -1,5 +1,6 @@ // renderparticles.cpp +#include "rendertext.hh" #include "renderva.hh" #include "shader.hh" #include "texture.hh" diff --git a/src/engine/rendertext.cc b/src/engine/rendertext.cc index 6e9150b..4d30d1f 100644 --- a/src/engine/rendertext.cc +++ b/src/engine/rendertext.cc @@ -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) diff --git a/src/engine/rendertext.hh b/src/engine/rendertext.hh new file mode 100644 index 0000000..caff0c8 --- /dev/null +++ b/src/engine/rendertext.hh @@ -0,0 +1,75 @@ +#ifndef ENGINE_RENDERTEXT_HH +#define ENGINE_RENDERTEXT_HH + +#include +#include + +struct Texture; +struct Shader; + +// rendertext +struct font +{ + struct charinfo + { + float x, y, w, h, offsetx, offsety, advance; + int tex; + }; + + char *name; + vector texs; + vector 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 diff --git a/src/engine/world.cc b/src/engine/world.cc index 450f94b..9647b76 100644 --- a/src/engine/world.cc +++ b/src/engine/world.cc @@ -2,6 +2,7 @@ #include "blend.hh" #include "octa.hh" +#include "renderlights.hh" #include "texture.hh" #include "worldio.hh" #include "world.hh" diff --git a/src/shared/iengine.hh b/src/shared/iengine.hh index 226c0da..e79a57f 100644 --- a/src/shared/iengine.hh +++ b/src/shared/iengine.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 {