fixed bugs in the ui code

This commit is contained in:
Magnus Auvinen 2007-07-20 22:19:40 +00:00
parent 9c56ddd5fa
commit 52c8d980a2
2 changed files with 42 additions and 55 deletions

View file

@ -44,6 +44,8 @@ int ui_update(float mx, float my, float mwx, float mwy, int buttons)
mouse_wy = mwy; mouse_wy = mwy;
mouse_buttons = buttons; mouse_buttons = buttons;
hot_item = becomming_hot_item; hot_item = becomming_hot_item;
if(active_item)
hot_item = active_item;
becomming_hot_item = 0; becomming_hot_item = 0;
return 0; return 0;
} }
@ -89,29 +91,25 @@ int ui_do_button(void *id, const char *text, int checked, float x, float y, floa
int r = 0; int r = 0;
int inside = ui_mouse_inside(x,y,w,h); int inside = ui_mouse_inside(x,y,w,h);
if(inside) if(ui_active_item() == id)
{
if(!ui_mouse_button(0))
{
if(inside)
r = 1;
ui_set_active_item(0);
}
}
else if(ui_hot_item() == id)
{ {
ui_set_hot_item(id);
if(ui_mouse_button(0)) if(ui_mouse_button(0))
ui_set_active_item(id); ui_set_active_item(id);
} }
// this gets rid of an annoying bug :< (but it creates another annoying bug :O) if(inside)
if (!inside && ui_active_item() == id && !ui_mouse_button(0)) ui_set_hot_item(id);
ui_set_active_item(0);
if(ui_active_item() == id && ui_hot_item() == id && !ui_mouse_button(0))
{
ui_set_active_item(0);
r = 1;
}
if (!inside && ui_hot_item() == id)
ui_set_hot_item(0);
draw_func(id, text, checked, x, y, w, h, extra); draw_func(id, text, checked, x, y, w, h, extra);
return r; return r;
} }

View file

@ -206,7 +206,7 @@ void draw_teewars_button(void *id, const char *text, int checked, float x, float
float text_width = gfx_pretty_text_width(46.f, text); float text_width = gfx_pretty_text_width(46.f, text);
gui_tileset_enum tileset; gui_tileset_enum tileset;
if (ui_active_item() == id && ui_hot_item() == id) if (ui_active_item() == id)
tileset = tileset_active; tileset = tileset_active;
else if (ui_hot_item() == id) else if (ui_hot_item() == id)
tileset = tileset_hot; tileset = tileset_hot;
@ -247,37 +247,26 @@ int ui_do_key_reader(void *id, float x, float y, float w, float h, int key)
int inside = ui_mouse_inside(x, y, w, h); int inside = ui_mouse_inside(x, y, w, h);
int new_key = key; int new_key = key;
if (!ui_mouse_button(0) && !can_be_selected) if(ui_active_item() == id)
can_be_selected = true;
if (can_be_selected)
{ {
if (inside) int k = input::last_key();
if (k)
{ {
ui_set_hot_item(id); new_key = k;
ui_set_active_item(0);
if (ui_mouse_button(0) && ui_active_item() != id) can_be_selected = false;
{
ui_set_active_item(id);
can_be_selected = false;
}
} }
} }
else if(ui_hot_item() == id)
if (can_be_selected)
{ {
if (ui_active_item() == id) if(ui_mouse_button(0))
{ ui_set_active_item(id);
int k = input::last_key();
if (k)
{
new_key = k;
ui_set_active_item(0);
can_be_selected = false;
}
}
} }
if(inside)
ui_set_hot_item(id);
// draw // draw
draw_box(GUI_BOX_SCREEN_INFO, tileset_regular, x, y, w, h); draw_box(GUI_BOX_SCREEN_INFO, tileset_regular, x, y, w, h);
@ -340,14 +329,6 @@ int ui_do_edit_box(void *id, float x, float y, float w, float h, char *str, int
int inside = ui_mouse_inside(x, y, w, h); int inside = ui_mouse_inside(x, y, w, h);
int r = 0; int r = 0;
if(inside)
{
ui_set_hot_item(id);
if(ui_mouse_button(0))
ui_set_active_item(id);
}
if (ui_active_item() == id) if (ui_active_item() == id)
{ {
int c = input::last_char(); int c = input::last_char();
@ -370,6 +351,14 @@ int ui_do_edit_box(void *id, float x, float y, float w, float h, char *str, int
} }
r = 1; r = 1;
} }
else if(ui_hot_item() == id)
{
if(ui_mouse_button(0))
ui_set_active_item(id);
}
if(inside)
ui_set_hot_item(id);
draw_box(GUI_BOX_SCREEN_TEXTBOX, tileset_regular, x, y, w, h); draw_box(GUI_BOX_SCREEN_TEXTBOX, tileset_regular, x, y, w, h);