Major improvements to text wrapping, acceptible but still character based
This commit is contained in:
parent
d1ce8e55df
commit
9a40e4924e
@ -93,10 +93,12 @@ int drawtextmax(pixel *vid, int x, int y, int w, char *s, int r, int g, int b, i
|
||||
|
||||
int textnwidth(char *s, int n);
|
||||
|
||||
int textnheight(char *s, int n, int w);
|
||||
void textnpos(char *s, int n, int w, int *cx, int *cy);
|
||||
|
||||
int textwidthx(char *s, int w);
|
||||
|
||||
int textposxy(char *s, int width, int w, int h);
|
||||
|
||||
#ifdef WIN32
|
||||
_inline void blendpixel(pixel *vid, int x, int y, int r, int g, int b, int a);
|
||||
#else
|
||||
|
@ -1002,18 +1002,25 @@ int textnwidth(char *s, int n)
|
||||
}
|
||||
return x-1;
|
||||
}
|
||||
int textnheight(char *s, int n, int w)
|
||||
void textnpos(char *s, int n, int w, int *cx, int *cy)
|
||||
{
|
||||
int x = 0;
|
||||
int y = 0;
|
||||
//TODO: Implement Textnheight for wrapped text
|
||||
for(; *s; s++)
|
||||
{
|
||||
if(!n)
|
||||
if(!n){
|
||||
break;
|
||||
}
|
||||
x += font_data[font_ptrs[(int)(*(unsigned char *)s)]];
|
||||
if(x>=w) {
|
||||
x = 0;
|
||||
y += FONT_H+2;
|
||||
}
|
||||
n--;
|
||||
}
|
||||
return x-1;
|
||||
*cx = x-1;
|
||||
*cy = y;
|
||||
}
|
||||
|
||||
int textwidthx(char *s, int w)
|
||||
@ -1029,6 +1036,23 @@ int textwidthx(char *s, int w)
|
||||
}
|
||||
return n;
|
||||
}
|
||||
int textposxy(char *s, int width, int w, int h)
|
||||
{
|
||||
int x=0,y=0,n=0,cw;
|
||||
for(; *s; s++)
|
||||
{
|
||||
cw = font_data[font_ptrs[(int)(*(unsigned char *)s)]];
|
||||
if(x+(cw/2) >= w && y+6 >= h)
|
||||
break;
|
||||
x += cw;
|
||||
if(x>=width) {
|
||||
x = 0;
|
||||
y += FONT_H+2;
|
||||
}
|
||||
n++;
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
#ifdef WIN32
|
||||
_inline void blendpixel(pixel *vid, int x, int y, int r, int g, int b, int a)
|
||||
|
@ -215,7 +215,7 @@ void add_sign_ui(pixel *vid_buf, int mx, int my)
|
||||
//TODO: Finish text wrapping in text edits
|
||||
void ui_edit_draw(pixel *vid_buf, ui_edit *ed)
|
||||
{
|
||||
int cx, i;
|
||||
int cx, i, cy;
|
||||
char echo[256], *str;
|
||||
|
||||
if(ed->hide)
|
||||
@ -242,9 +242,15 @@ void ui_edit_draw(pixel *vid_buf, ui_edit *ed)
|
||||
drawtext(vid_buf, ed->x, ed->y, ed->def, 128, 128, 128, 255);
|
||||
if(ed->focus)
|
||||
{
|
||||
if(ed->multiline){
|
||||
textnpos(str, ed->cursor, ed->w-14, &cx, &cy);
|
||||
} else {
|
||||
cx = textnwidth(str, ed->cursor);
|
||||
cy = 0;
|
||||
}
|
||||
|
||||
for(i=-3; i<9; i++)
|
||||
drawpixel(vid_buf, ed->x+cx, ed->y+i, 255, 255, 255, 255);
|
||||
drawpixel(vid_buf, ed->x+cx, ed->y+i+cy, 255, 255, 255, 255);
|
||||
}
|
||||
}
|
||||
|
||||
@ -278,7 +284,7 @@ void ui_edit_process(int mx, int my, int mb, ui_edit *ed)
|
||||
else if(mx>=ed->x-ed->nx && mx<ed->x+ed->w && my>=ed->y-5 && my<ed->y+ed->h)
|
||||
{
|
||||
ed->focus = 1;
|
||||
ed->cursor = textwidthx(str, mx-ed->x);
|
||||
ed->cursor = textposxy(str, ed->w-14, mx-ed->x, my-ed->y);
|
||||
}
|
||||
else
|
||||
ed->focus = 0;
|
||||
|
Loading…
Reference in New Issue
Block a user