summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSimon <simon@hardwired.org.uk>2010-11-03 15:51:02 (GMT)
committer Simon <simon@hardwired.org.uk>2010-11-03 15:51:02 (GMT)
commit9a40e4924e99af80a50b2c5f409d8463f993c4da (patch)
tree1aa4f3982d1af6c2cbe523d2631e7d47df2e9fb6 /src
parentd1ce8e55dfd07faa3eb8029ea47a1db6a30f6988 (diff)
downloadpowder-9a40e4924e99af80a50b2c5f409d8463f993c4da.zip
powder-9a40e4924e99af80a50b2c5f409d8463f993c4da.tar.gz
Major improvements to text wrapping, acceptible but still character based
Diffstat (limited to 'src')
-rw-r--r--src/graphics.c30
-rw-r--r--src/interface.c14
2 files changed, 37 insertions, 7 deletions
diff --git a/src/graphics.c b/src/graphics.c
index d6604a3..83b1141 100644
--- a/src/graphics.c
+++ b/src/graphics.c
@@ -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)
diff --git a/src/interface.c b/src/interface.c
index f108efc..3a58ba4 100644
--- a/src/interface.c
+++ b/src/interface.c
@@ -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)
{
- cx = textnwidth(str, ed->cursor);
+ 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;