remove some dead code

and some braind* concepts
This commit is contained in:
ac-stef
2015-02-12 12:54:03 +01:00
parent d4110288da
commit 4b75405829
5 changed files with 9 additions and 534 deletions
+5 -46
View File
@@ -141,44 +141,6 @@ int rendercommand(int x, int y, int w)
return height;
}
const char *getCONprefix(int n)
{
const char* CONpreSTR[] = {
">", // ">>>", // "TALK" // "T" // ">"
"/", // "CFG", // "EXEC" // "!" // "!"
"%", // "TEAM" // ">" // "T"
};
return (n>=0 && size_t(n) < sizeof(CONpreSTR)/sizeof(CONpreSTR[0])) ? CONpreSTR[n] : "#";
}
int getCONlength(int n)
{
const char* CURpreSTR = getCONprefix(n);
return strlen(CURpreSTR);
}
/** WIP ALERT */
int rendercommand_wip(int x, int y, int w)
{
int width, height = 0;
if( strlen(cmdline.buf) > 0 )
{
int ctx = -1;
switch( cmdline.buf[0] )
{
case '>': ctx = 0; break;
case '/': ctx = 1; break;
case '%': ctx = 2; break;
default: break;
}
defformatstring(s)("%s %s", getCONprefix(ctx), cmdline.buf+1);
text_bounds(s, width, height, w);
y -= height - FONTH;
draw_text(s, x, y, 0xFF, 0xFF, 0xFF, 0xFF, cmdline.pos>=0 ? cmdline.pos/*+1*/+getCONlength(ctx) : (int)strlen(s), w);
}
return height;
}
// keymap is defined externally in keymap.cfg
vector<keym> keyms;
@@ -338,11 +300,12 @@ void saycommand(char *init) // turns input to the comman
setscope(false);
setburst(false);
if(!editmode) keyrepeat(saycommandon);
copystring(cmdline.buf, init ? init : ">"); // ALL cmdline.buf[0] ARE flag-chars ! ">" is for talk - the previous "no flag-char" item
copystring(cmdline.buf, init ? init : "");
DELETEA(cmdaction);
DELETEA(cmdprompt);
cmdline.pos = -1;
}
COMMAND(saycommand, "c");
void inputcommand(char *init, char *action, char *prompt)
{
@@ -350,6 +313,7 @@ void inputcommand(char *init, char *action, char *prompt)
if(action[0]) cmdaction = newstring(action);
if(prompt[0]) cmdprompt = newstring(prompt);
}
COMMAND(inputcommand, "sss");
void mapmsg(char *s)
{
@@ -359,6 +323,7 @@ void mapmsg(char *s)
copystring(hdr.maptitle, text, 128);
if(editmode) unsavededits++;
}
COMMAND(mapmsg, "s");
void getmapmsg(void)
{
@@ -366,10 +331,6 @@ void getmapmsg(void)
copystring(text, hdr.maptitle, 128);
result(text);
}
COMMAND(saycommand, "c");
COMMAND(inputcommand, "sss");
COMMAND(mapmsg, "s");
COMMAND(getmapmsg, "");
#if !defined(WIN32) && !defined(__APPLE__)
@@ -459,9 +420,7 @@ struct hline
execute(action);
}
else if(buf[0]=='/') execute(buf+1);
else if(buf[0]=='>') toserver(buf+1);
else if(buf[0]=='%') toserver(buf);
else toserver(buf); // execute(buf); // still default to simple "say".
else toserver(buf);
popscontext();
}
};
-137
View File
@@ -30,10 +30,6 @@ template<class LINE> struct consolebuffer
virtual void render() = 0;
};
/** This is the 1.0.4 structure
It will substituted by textinputbuffer_wip
I am putting this temporarily here to fix the weird cursor behavior
Please, read the comments in rendercommand::console.cpp : Brahma */
struct textinputbuffer
{
string buf;
@@ -127,136 +123,3 @@ struct textinputbuffer
}
};
/** WIP ALERT */
struct textinputbuffer_wip
{
string buf;
int pos, max;
textinputbuffer_wip() : pos(-1), max(0)
{
buf[0] = '\0';
}
bool key(int code, bool isdown, int unicode)
{
switch(code)
{
case SDLK_RETURN:
case SDLK_KP_ENTER:
break;
case SDLK_HOME:
if(strlen(buf)) pos = 0;
break;
case SDLK_END:
pos = -1;
break;
case SDLK_DELETE:
{
if(pos < 0) break;
std::string s(buf);
int len = utf8::distance(s.begin(), s.end());
std::string::iterator first = s.begin();
std::string::iterator second = s.begin();
utf8::advance(first, pos, s.end());
utf8::advance(second, pos + 1, s.end());
s.erase(first, second);
strcpy(buf, s.c_str());
if(pos>=len-1) pos = -1;
return true;
}
case SDLK_BACKSPACE:
{
std::string s(buf);
int len = utf8::distance(s.begin(), s.end());
int i = pos>=0 ? pos : len;
if(i<1) break;
std::string::iterator first = s.begin();
std::string::iterator second = s.begin();
utf8::advance(first, i - 1, s.end());
utf8::advance(second, i, s.end());
s.erase(first, second);
strcpy(buf, s.c_str());
if(pos > 0) pos--;
else if(!pos && len <=1 ) pos = -1;
return true;
}
case SDLK_LEFT:
{
std::string s(buf);
int len = utf8::distance(s.begin(), s.end());
if(pos > 0) pos--;
else if(pos < 0) pos = len-1;
break;
}
case SDLK_RIGHT:
{
std::string s(buf);
int len = utf8::distance(s.begin(), s.end());
if(pos>=0 && ++pos >= len) pos = -1;
break;
}
case SDLK_v:
extern void pasteconsole(char *dst);
#ifdef __APPLE__
#define MOD_KEYS (KMOD_LMETA|KMOD_RMETA)
#else
#define MOD_KEYS (KMOD_LCTRL|KMOD_RCTRL)
#endif
if(SDL_GetModState()&MOD_KEYS)
{
pasteconsole(buf);
return true;
}
// fall through
default:
{
if(unicode)
{
std::string s(buf);
char tmp[5] = { 0, 0, 0, 0, 0 };
utf8::append(unicode, tmp);
std::string newchar(tmp);
int len = utf8::distance(s.begin(), s.end());
if(max && (int)len>=max) break;
if(s.length() + newchar.length() < sizeof(buf))
{
if(pos < 0)
{
s.append(newchar);
}
else
{
std::string::iterator first = s.begin();
utf8::advance(first, pos + 1, s.end());
s.insert(first, newchar.begin(), newchar.end());
pos++;
}
strcpy(buf, s.c_str());
return true;
}
}
break;
}
}
return false;
}
};
void savehistory();
void loadhistory();
-3
View File
@@ -45,9 +45,6 @@
#ifndef STANDALONE
#include <SDL.h>
#include <SDL_image.h>
//#include <SDL_ttf.h>
#include <utf8.h>
#define GL_GLEXT_LEGACY
#define __glext_h__
+2 -5
View File
@@ -60,6 +60,8 @@ extern int rendercommand(int x, int y, int w);
extern void renderconsole();
extern char *getcurcommand();
extern char *addreleaseaction(const char *s);
extern void savehistory();
extern void loadhistory();
extern void writebinds(stream *f);
extern void pasteconsole(char *dst);
extern void clientlogf(const char *s, ...);
@@ -549,11 +551,6 @@ struct font
short x, y, w, h;
};
struct utf8charinfo : charinfo
{
int code;
};
char *name;
Texture *tex;
vector<charinfo> chars;
+2 -343
View File
@@ -113,157 +113,8 @@ void draw_textf(const char *fstr, int left, int top, ...)
draw_text(str, left, top);
}
extern int shdsize, outline, win32msg;
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
#define RMASK 0xff000000
#define GMASK 0x00ff0000
#define BMASK 0x0000ff00
#define AMASK 0x000000ff
#else
#define RMASK 0x000000ff
#define GMASK 0x0000ff00
#define BMASK 0x00ff0000
#define AMASK 0xff000000
#endif
/*
// ringbuf for utf8 character storage
struct charringbuf : ringbuf<font::utf8charinfo, 32>
int draw_char_contd(font &f, font::charinfo &info, int charcode, int x, int y)
{
// find by character code
int findbycharcode(int code)
{
loopi(len)
{
if(data[i].code == code)
return i;
}
return -1;
}
};
TTF_Font *ttffont = NULL;
font utf8font;
charringbuf utf8chars;
void initfont()
{
static bool initialized = false;
if(!initialized)
{
TTF_Init();
int fsize = 64;
const char *fontname = "packages/misc/font.ttf";
ttffont = TTF_OpenFont(findfile(path(fontname, true), "r"), fsize);
utf8font.defaulth = 0;
utf8font.defaultw = 0;
utf8font.offsetw = 0;
utf8font.offseth = 10;
utf8font.offsetx = 0;
utf8font.offsety = 0;
initialized = true;
}
}
void createutf8charset()
{
int isize = 512;
SDL_Surface *charsetsurface = SDL_CreateRGBSurface(SDL_SWSURFACE, isize, isize, 32, RMASK, GMASK, BMASK, AMASK);
if(charsetsurface)
{
SDL_Color color;
color.r = 255;
color.g = 255;
color.b = 255;
int posx = 0;
int posy = 0;
loopv(utf8chars)
{
font::utf8charinfo &charinfo = utf8chars[i];
int code = charinfo.code;
char u[5] = {0,0,0,0,0};
utf8::append(code, u);
SDL_Surface *fontsurface = TTF_RenderUTF8_Blended(ttffont, u, color);
// update row/column info
if(posx + fontsurface->w > charsetsurface->w)
{
posx = 0;
posy += fontsurface->h; // fixme
}
if(posy + fontsurface->h > charsetsurface->h)
break;
// blit onto charset
SDL_SetAlpha(fontsurface, 0, 0);
blitsurface(charsetsurface, fontsurface, posx, posy);
// update charinfo properties
charinfo.x = posx;
charinfo.y = posy;
charinfo.w = fontsurface->w;
charinfo.h = fontsurface->h;
posx += fontsurface->w;
SDL_FreeSurface(fontsurface);
}
utf8font.tex = createtexturefromsurface("utf8charset", charsetsurface);
//extern void savepng(SDL_Surface *s, const char *name);
//savepng(t, "font.png");
SDL_FreeSurface(charsetsurface);
}
}
void addutf8char(int code)
{
// add to buf
font::utf8charinfo charinfo;
charinfo.code = code;
charinfo.x = charinfo.y = charinfo.w = charinfo.h = 0;
utf8chars.add(charinfo);
// update charset
createutf8charset();
}
font::charinfo *loadchar(int code)
{
int idx = utf8chars.findbycharcode(code);
if(idx >= 0)
return &utf8chars[idx];
// add
addutf8char(code);
idx = utf8chars.findbycharcode(code);
return &utf8chars[idx];
}
*/
int draw_char(font &f, font::charinfo &info, int charcode, int x, int y)
{
/*
// fixme
glEnd();
glBindTexture(GL_TEXTURE_2D, f.tex->id);
glBegin(GL_QUADS);
*/
float tc_left = (info.x + f.offsetx) / float(f.tex->xs);
float tc_top = (info.y + f.offsety) / float(f.tex->ys);
float tc_right = (info.x + info.w + f.offsetw) / float(f.tex->xs);
@@ -278,41 +129,14 @@ int draw_char(font &f, font::charinfo &info, int charcode, int x, int y)
return info.w;
}
/*
// fixme
font::charinfo &getcharinfo(int c)
{
if(curfont->chars.inrange(c-curfont->skip))
{
font::charinfo &info = curfont->chars[c-curfont->skip];
return info;
}
//else { font::charinfo &info = *loadchar(c); return info; }
//return NULL;
font::charinfo &info = curfont->chars[0]; // 0 || (FONTCHARS-1)
return info;
}
*/
static int draw_char(int c, int x, int y)
{
if(curfont->chars.inrange(c-curfont->skip))
{
font::charinfo &info = curfont->chars[c-curfont->skip];
return draw_char(*curfont, info, c, x, y);
return draw_char_contd(*curfont, info, c, x, y);
}
/*
else
{
// fixme
glEnd();
font::charinfo &info = *loadchar(c);
glBegin(GL_QUADS);
return draw_char(utf8font, info, c, x, y);
}
*/
return 0;
}
@@ -532,9 +356,6 @@ void text_bounds(const char *str, int &width, int &height, int maxwidth)
#undef TEXTWORD
}
/** This is the 1.0.4 function
It will substituted by draw_text_wip
I am putting this temporarily here because it is impossible to test without colours : Brahma */
void draw_text(const char *str, int left, int top, int r, int g, int b, int a, int cursor, int maxwidth)
{
#define TEXTINDEX(idx) if(idx == cursor) { cx = x; cy = y; cc = str[idx]; }
@@ -570,170 +391,8 @@ void draw_text(const char *str, int left, int top, int r, int g, int b, int a, i
#undef TEXTWORD
}
/* WIP ALERT */
/*
void draw_text_wip(const char *str, int left, int top, int r, int g, int b, int a, int cursor, int maxwidth)
{
char colorstack[10];
bvec color(r, g, b);
int colorpos = 0, cx = INT_MIN, cy = 0, cc = ' ';
colorstack[0] = 'c'; //indicate user color
glBlendFunc(GL_SRC_ALPHA, curfont->tex->bpp==32 ? GL_ONE_MINUS_SRC_ALPHA : GL_ONE);
glBindTexture(GL_TEXTURE_2D, curfont->tex->id);
glBegin(GL_QUADS);
glColor4ub(color.x, color.y, color.z, a);
std::string text(str);
std::string::iterator begin = text.begin();
std::string::iterator end = text.end();
std::string::iterator cursoriter = end;
if(cursor >= 0 && cursor < utf8::distance(begin, end))
{
cursoriter = begin;
utf8::advance(cursoriter, cursor, end);
}
int y = 0, x = 0, col = 0, colx = 0;
for(std::string::iterator iter = text.begin(); iter != text.end(); utf8::next(iter, text.end()))
{
int c = utf8::peek_next(iter, text.end());
if(iter == cursoriter)
{
cx = x;
cy = y;
cc = c;
}
if(c=='\t')
{
if(columns && col<columns->length())
{
colx += (*columns)[col++];
x = colx;
}
else x = TABALIGN(x);
}
else if(c==' ')
{
x += curfont->defaultw;
}
else if(c=='\n')
{
x = 0;
y += FONTH;
}
else if(c=='\f')
{
std::string::iterator test = iter;
test++;
if(test != end)
{
c = utf8::next(iter, end);
text_color(c, colorstack, sizeof(colorstack), colorpos, color, a);
}
}
else if(c=='\a')
{
std::string::iterator next = iter;
next++;
if(next != end)
{
iter++;
}
}
else if(curfont->chars.inrange(c-curfont->skip))
{
font::charinfo &cinfo = getcharinfo(c);
if(maxwidth != -1)
{
std::string::iterator next = iter;
int w = cinfo.w;
do
{
std::string::iterator test = iter;
int c = utf8::next(test, end);
if(test == end) break;
if(c=='\f')
{
std::string::iterator test = iter;
utf8::advance(test, 2, end);
if(test == end) break;
utf8::next(iter, end);
continue;
}
if(utf8::distance(iter, next) > 16) break;
//if(!curfont->chars.inrange(c-curfont->skip)) fixme
if(c < curfont->skip) // fixme
{
break;
}
int cw = getcharinfo(c).w + 1;
if(w + cw >= maxwidth) break;
w += cw;
utf8::next(iter, end);
} while(true);
if(x + w >= maxwidth && next != begin) //fixme
{
x = 0;
y += FONTH;
}
for(; next <= iter && next != end; )
{
int c = utf8::peek_next(next, end);
if(next == cursoriter) { cx = x; cy = y; cc = c; }
if(c=='\f')
{
std::string::iterator test = next;
utf8::next(test, end);
if(test != end)
{
c = utf8::next(next, end);
text_color(c, colorstack, sizeof(colorstack), colorpos, color, a);
}
}
else
{
x += draw_char(c, left+x, top+y)+1;
}
utf8::next(next, end);
}
}
else
{
x += draw_char(c, left+x, top+y)+1;
}
}
}
glEnd();
if(cursor >= 0)
{
if(cx == INT_MIN) { cx = x; cy = y; }
if(maxwidth != -1 && cx >= maxwidth) { cx = 0; cy += FONTH; }
int cw = curfont->chars.inrange(cc-curfont->skip) ? curfont->chars[cc-curfont->skip].w + 1 : curfont->defaultw;
rendercursor(left+cx, top+cy, cw);
}
}
*/
void reloadfonts()
{
//createutf8charset();
enumerate(fonts, font, f,
if(!reloadtexture(*f.tex)) fatal("failed to reload font texture");
);