Move copybox into its own control

This commit is contained in:
Simon 2011-04-04 20:02:11 +01:00
parent 078db03a52
commit 8872a1065b
2 changed files with 65 additions and 31 deletions

View File

@ -82,6 +82,14 @@ struct ui_edit
}; };
typedef struct ui_edit ui_edit; typedef struct ui_edit ui_edit;
struct ui_copytext
{
int x, y, width, height;
char text[256];
int state, hover;
};
typedef struct ui_copytext ui_copytext;
struct save_info struct save_info
{ {
char *title; char *title;
@ -171,6 +179,10 @@ void ui_checkbox_draw(pixel *vid_buf, ui_checkbox *ed);
void ui_checkbox_process(int mx, int my, int mb, int mbq, ui_checkbox *ed); void ui_checkbox_process(int mx, int my, int mb, int mbq, ui_checkbox *ed);
void ui_copytext_draw(pixel *vid_buf, ui_copytext *ed);
void ui_copytext_process(int mx, int my, int mb, int mbq, ui_copytext *ed);
void draw_svf_ui(pixel *vid_buf); void draw_svf_ui(pixel *vid_buf);
void error_ui(pixel *vid_buf, int err, char *txt); void error_ui(pixel *vid_buf, int err, char *txt);

View File

@ -446,7 +446,7 @@ void ui_checkbox_draw(pixel *vid_buf, ui_checkbox *ed)
void ui_checkbox_process(int mx, int my, int mb, int mbq, ui_checkbox *ed) void ui_checkbox_process(int mx, int my, int mb, int mbq, ui_checkbox *ed)
{ {
int w = 12; int w = 12;
if (mb && !mbq) if (mb && !mbq)
{ {
if (mx>=ed->x && mx<=ed->x+w && my>=ed->y && my<=ed->y+w) if (mx>=ed->x && mx<=ed->x+w && my>=ed->y && my<=ed->y+w)
@ -467,6 +467,41 @@ void ui_checkbox_process(int mx, int my, int mb, int mbq, ui_checkbox *ed)
} }
} }
void ui_copytext_draw(pixel *vid_buf, ui_copytext *ed)
{
int g = 180, i = 0;
if(!ed->state){
if(ed->hover){
i = 0;
} else {
i = 100;
}
g = 255;
drawtext(vid_buf, (ed->x+(ed->width/2))-(textwidth("Click the box to copy the text")/2), ed->y-12, "Click the box to copy the text", 255, 255, 255, 255-i);
} else {
i = 0;
drawtext(vid_buf, (ed->x+(ed->width/2))-(textwidth("Copied!")/2), ed->y-12, "Copied!", 255, 255, 255, 255-i);
g = 190;
}
drawrect(vid_buf, ed->x, ed->y, ed->width, ed->height, g, 255, g, 255-i);
drawrect(vid_buf, ed->x+1, ed->y+1, ed->width-2, ed->height-2, g, 255, g, 100-i);
drawtext(vid_buf, ed->x+6, ed->y+5, ed->text, g, 255, g, 230-i);
}
void ui_copytext_process(int mx, int my, int mb, int mbq, ui_copytext *ed)
{
if(my>=ed->y && my<=ed->y+ed->height && mx>=ed->x && mx<=ed->x+ed->width && !ed->state){
if(mb && !mbq){
clipboard_push_text(ed->text);
ed->state = 1;
}
ed->hover = 1;
} else {
ed->hover = 0;
}
}
void draw_svf_ui(pixel *vid_buf)// all the buttons at the bottom void draw_svf_ui(pixel *vid_buf)// all the buttons at the bottom
{ {
int c; int c;
@ -738,6 +773,20 @@ void copytext_ui(pixel *vid_buf, char *top, char *txt, char *copytxt)
int buttony = 0; int buttony = 0;
int buttonwidth = 0; int buttonwidth = 0;
int buttonheight = 0; int buttonheight = 0;
ui_copytext ed;
buttonwidth = textwidth(copytxt)+12;
buttonheight = 10+8;
buttony = y0+50;
buttonx = x0+(xsize/2)-(buttonwidth/2);
ed.x = buttonx;
ed.y = buttony;
ed.width = buttonwidth;
ed.height = buttonheight;
ed.hover = 0;
ed.state = 0;
strcpy(ed.text, copytxt);
while (!sdl_poll()) while (!sdl_poll())
{ {
@ -753,40 +802,13 @@ void copytext_ui(pixel *vid_buf, char *top, char *txt, char *copytxt)
mx /= sdl_scale; mx /= sdl_scale;
my /= sdl_scale; my /= sdl_scale;
buttonwidth = textwidth(copytxt)+12; clearrect(vid_buf, x0-2, y0-2, xsize+4, ysize+4);
buttonheight = 10+8;
buttony = y0+50;
buttonx = x0+(xsize/2)-(buttonwidth/2);
clearrect(vid_buf, x0-2, y0-2, xsize, ysize);
drawrect(vid_buf, x0, y0, xsize, ysize, 192, 192, 192, 255); drawrect(vid_buf, x0, y0, xsize, ysize, 192, 192, 192, 255);
drawtext(vid_buf, x0+8, y0+8, top, 160, 160, 255, 255); drawtext(vid_buf, x0+8, y0+8, top, 160, 160, 255, 255);
drawtext(vid_buf, x0+8, y0+26, txt, 255, 255, 255, 255); drawtext(vid_buf, x0+8, y0+26, txt, 255, 255, 255, 255);
if(my>=buttony && my<=buttony+buttonheight && mx>=buttonx && mx<=buttonx+buttonwidth && !state){ ui_copytext_draw(vid_buf, &ed);
if(b && !bq){ ui_copytext_process(mx, my, b, bq, &ed);
clipboard_push_text(copytxt);
state = 1;
g = 210;
}
i = 0;
} else {
if(state==1){
i = 0;
} else {
i = 100;
}
}
if(!state){
drawtext(vid_buf, (x0+(xsize/2))-(textwidth("Click the box to copy the text")/2), y0+38, "Click the box to copy the text", 255, 255, 255, 255-i);
} else {
drawtext(vid_buf, (x0+(xsize/2))-(textwidth("Copied!")/2), y0+38, "Copied!", 255, 255, 255, 255-i);
}
drawrect(vid_buf, buttonx, buttony, buttonwidth, buttonheight, g, 255, g, 255-i);
drawrect(vid_buf, buttonx+1, buttony+1, buttonwidth-2, buttonheight-2, g, 255, g, 100-i);
drawtext(vid_buf, buttonx+6, buttony+5, copytxt, g, 255, g, 230-i);
drawtext(vid_buf, x0+5, y0+ysize-11, "OK", 255, 255, 255, 255); drawtext(vid_buf, x0+5, y0+ysize-11, "OK", 255, 255, 255, 255);
drawrect(vid_buf, x0, y0+ysize-16, xsize, 16, 192, 192, 192, 255); drawrect(vid_buf, x0, y0+ysize-16, xsize, 16, 192, 192, 192, 255);