libeek: eek_keyboard_find_key_by_position(): consider overlapped sections.

This commit is contained in:
Daiki Ueno
2010-08-13 11:42:32 +09:00
parent d7cb78ecf5
commit ae9df021c2

View File

@ -485,6 +485,13 @@ eek_keyboard_find_key_by_keycode (EekKeyboard *keyboard,
keycode); keycode);
} }
struct _FkbpData {
gdouble x;
gdouble y;
EekKey *key;
};
typedef struct _FkbpData FkbpData;
static gint static gint
compare_section_by_position (EekElement *element, gpointer user_data) compare_section_by_position (EekElement *element, gpointer user_data)
{ {
@ -507,22 +514,22 @@ compare_section_by_position (EekElement *element, gpointer user_data)
return -1; return -1;
} }
static EekSection * static void
eek_keyboard_find_section_by_position (EekKeyboard *keyboard, fkbp_foreach_child_callback (EekElement *element,
gdouble x, gpointer user_data)
gdouble y)
{ {
EekBounds bounds; FkbpData *data = user_data;
EekPoint point; EekPoint point;
EekElement *element;
eek_element_get_bounds (EEK_ELEMENT(keyboard), &bounds); if (!data->key) {
point.x = x - bounds.x; point.x = data->x;
point.y = y - bounds.y; point.y = data->y;
element = eek_container_find (EEK_CONTAINER(keyboard), if (compare_section_by_position (element, &point) == 0) {
compare_section_by_position, data->key = eek_section_find_key_by_position (EEK_SECTION(element),
&point); point.x,
return EEK_SECTION(element); point.y);
}
}
} }
EekKey * EekKey *
@ -530,15 +537,17 @@ eek_keyboard_find_key_by_position (EekKeyboard *keyboard,
gdouble x, gdouble x,
gdouble y) gdouble y)
{ {
FkbpData data;
EekSection *section; EekSection *section;
EekBounds bounds; EekBounds bounds;
section = eek_keyboard_find_section_by_position (keyboard, x, y);
if (!section)
return NULL;
eek_element_get_bounds (EEK_ELEMENT(keyboard), &bounds); eek_element_get_bounds (EEK_ELEMENT(keyboard), &bounds);
x -= bounds.x; data.x = x - bounds.x;
y -= bounds.y; data.y = y - bounds.y;
return eek_section_find_key_by_position (section, x, y); data.key = NULL;
/* eek_container_find() cannot be used here since sections may overlap. */
eek_container_foreach_child (EEK_CONTAINER(keyboard),
fkbp_foreach_child_callback,
&data);
return data.key;
} }