layout: Using bigger keys
This commit is contained in:
@ -35,6 +35,9 @@
|
|||||||
<bounds x="429.2682" y="42.14634" width="37.46341" height="37.46341"/>
|
<bounds x="429.2682" y="42.14634" width="37.46341" height="37.46341"/>
|
||||||
</key>
|
</key>
|
||||||
</row>
|
</row>
|
||||||
|
</section>
|
||||||
|
<section angle="0">
|
||||||
|
<bounds x="15.60975" y="78.04878" width="608.7804" height="201.3658"/>
|
||||||
<row orientation="1">
|
<row orientation="1">
|
||||||
<key keycode="38" name="AC01" oref="outline2">
|
<key keycode="38" name="AC01" oref="outline2">
|
||||||
<bounds x="76.48780" y="82.73170" width="37.46341" height="37.46341"/>
|
<bounds x="76.48780" y="82.73170" width="37.46341" height="37.46341"/>
|
||||||
@ -64,6 +67,9 @@
|
|||||||
<bounds x="399.6097" y="82.73170" width="37.46341" height="37.46341"/>
|
<bounds x="399.6097" y="82.73170" width="37.46341" height="37.46341"/>
|
||||||
</key>
|
</key>
|
||||||
</row>
|
</row>
|
||||||
|
</section>
|
||||||
|
<section angle="0">
|
||||||
|
<bounds x="15.60975" y="78.04878" width="608.7804" height="201.3658"/>
|
||||||
<row orientation="1">
|
<row orientation="1">
|
||||||
<key keycode="50" name="LFSH" oref="outline8">
|
<key keycode="50" name="LFSH" oref="outline8">
|
||||||
<bounds x="3.121951" y="121.7560" width="88.97561" height="37.46341"/>
|
<bounds x="3.121951" y="121.7560" width="88.97561" height="37.46341"/>
|
||||||
@ -93,6 +99,9 @@
|
|||||||
<bounds x="529.1707" y="1.560976" width="79.60975" height="37.46341"/>
|
<bounds x="529.1707" y="1.560976" width="79.60975" height="37.46341"/>
|
||||||
</key>
|
</key>
|
||||||
</row>
|
</row>
|
||||||
|
</section>
|
||||||
|
<section angle="0">
|
||||||
|
<bounds x="15.60975" y="78.04878" width="608.7804" height="201.3658"/>
|
||||||
<row orientation="1">
|
<row orientation="1">
|
||||||
<key keycode="37" name="LCTL" oref="outline1">
|
<key keycode="37" name="LCTL" oref="outline1">
|
||||||
<bounds x="62.43902" y="162.3414" width="48.39024" height="37.46341"/>
|
<bounds x="62.43902" y="162.3414" width="48.39024" height="37.46341"/>
|
||||||
|
|||||||
@ -66,7 +66,7 @@ struct _EekKeyPrivate
|
|||||||
EekSymbolMatrix *symbol_matrix;
|
EekSymbolMatrix *symbol_matrix;
|
||||||
gint column;
|
gint column;
|
||||||
gint row;
|
gint row;
|
||||||
gulong oref;
|
gulong oref; // UI outline reference
|
||||||
gboolean is_pressed;
|
gboolean is_pressed;
|
||||||
gboolean is_locked;
|
gboolean is_locked;
|
||||||
};
|
};
|
||||||
|
|||||||
@ -48,6 +48,8 @@ typedef struct _EekKeyboardPrivate EekKeyboardPrivate;
|
|||||||
*
|
*
|
||||||
* Contains the state of the physical keyboard.
|
* Contains the state of the physical keyboard.
|
||||||
*
|
*
|
||||||
|
* Is also a graphical element...
|
||||||
|
*
|
||||||
* The #EekKeyboard structure contains only private data and should
|
* The #EekKeyboard structure contains only private data and should
|
||||||
* only be accessed using the provided API.
|
* only be accessed using the provided API.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -129,7 +129,7 @@ static EekKey *
|
|||||||
eek_section_real_create_key (EekSection *self,
|
eek_section_real_create_key (EekSection *self,
|
||||||
guint keycode,
|
guint keycode,
|
||||||
gint column_index,
|
gint column_index,
|
||||||
gint row_index)
|
guint row_index)
|
||||||
{
|
{
|
||||||
EekKey *key;
|
EekKey *key;
|
||||||
gint num_rows;
|
gint num_rows;
|
||||||
@ -479,3 +479,47 @@ eek_section_create_key (EekSection *section,
|
|||||||
column,
|
column,
|
||||||
row);
|
row);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct keys_info {
|
||||||
|
uint count;
|
||||||
|
double total_width;
|
||||||
|
double biggest_height;
|
||||||
|
};
|
||||||
|
|
||||||
|
static void keycounter (EekElement *element, gpointer user_data) {
|
||||||
|
struct keys_info *data = user_data;
|
||||||
|
data->count++;
|
||||||
|
EekBounds key_bounds = {0};
|
||||||
|
eek_element_get_bounds(element, &key_bounds);
|
||||||
|
data->total_width += key_bounds.width;
|
||||||
|
if (key_bounds.height > data->biggest_height) {
|
||||||
|
data->biggest_height = key_bounds.height;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const double keyspacing = 2.0;
|
||||||
|
|
||||||
|
static void keyplacer(EekElement *element, gpointer user_data) {
|
||||||
|
double *current_offset = user_data;
|
||||||
|
EekBounds key_bounds = {0};
|
||||||
|
eek_element_get_bounds(element, &key_bounds);
|
||||||
|
key_bounds.x = *current_offset;
|
||||||
|
key_bounds.y = 0;
|
||||||
|
eek_element_set_bounds(element, &key_bounds);
|
||||||
|
*current_offset += key_bounds.width + keyspacing;
|
||||||
|
}
|
||||||
|
|
||||||
|
void eek_section_place_keys(EekSection *section)
|
||||||
|
{
|
||||||
|
struct keys_info keyinfo = {0};
|
||||||
|
eek_container_foreach_child(EEK_CONTAINER(section), keycounter, &keyinfo);
|
||||||
|
EekBounds section_bounds = {0};
|
||||||
|
eek_element_get_bounds(EEK_ELEMENT(section), §ion_bounds);
|
||||||
|
|
||||||
|
// FIXME: find a way to center buttons
|
||||||
|
double key_offset = (section_bounds.width - (keyinfo.total_width + (keyinfo.count - 1) * keyspacing)) / 2;
|
||||||
|
eek_container_foreach_child(EEK_CONTAINER(section), keyplacer, &key_offset);
|
||||||
|
|
||||||
|
section_bounds.height = keyinfo.biggest_height;
|
||||||
|
eek_element_set_bounds(EEK_ELEMENT(section), §ion_bounds);
|
||||||
|
}
|
||||||
|
|||||||
@ -127,5 +127,7 @@ EekKey *eek_section_create_key (EekSection *section,
|
|||||||
EekKey *eek_section_find_key_by_keycode (EekSection *section,
|
EekKey *eek_section_find_key_by_keycode (EekSection *section,
|
||||||
guint keycode);
|
guint keycode);
|
||||||
|
|
||||||
|
void eek_section_place_keys (EekSection *section);
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
#endif /* EEK_SECTION_H */
|
#endif /* EEK_SECTION_H */
|
||||||
|
|||||||
@ -214,7 +214,7 @@ struct _EekOutline
|
|||||||
/*< public >*/
|
/*< public >*/
|
||||||
gdouble corner_radius;
|
gdouble corner_radius;
|
||||||
EekPoint *points;
|
EekPoint *points;
|
||||||
gint num_points;
|
guint num_points;
|
||||||
};
|
};
|
||||||
|
|
||||||
GType eek_outline_get_type (void) G_GNUC_CONST;
|
GType eek_outline_get_type (void) G_GNUC_CONST;
|
||||||
|
|||||||
@ -504,13 +504,14 @@ geometry_end_element_callback (GMarkupParseContext *pcontext,
|
|||||||
{
|
{
|
||||||
GeometryParseData *data = user_data;
|
GeometryParseData *data = user_data;
|
||||||
GSList *head = data->element_stack;
|
GSList *head = data->element_stack;
|
||||||
gint i;
|
|
||||||
|
|
||||||
g_free (head->data);
|
g_free (head->data);
|
||||||
data->element_stack = g_slist_next (data->element_stack);
|
data->element_stack = g_slist_next (data->element_stack);
|
||||||
g_slist_free1 (head);
|
g_slist_free1 (head);
|
||||||
|
|
||||||
if (g_strcmp0 (element_name, "section") == 0) {
|
if (g_strcmp0 (element_name, "section") == 0) {
|
||||||
|
// Sections are rows now. Gather up all the keys and adjust their bounds.
|
||||||
|
eek_section_place_keys(data->section);
|
||||||
data->section = NULL;
|
data->section = NULL;
|
||||||
data->num_rows = 0;
|
data->num_rows = 0;
|
||||||
return;
|
return;
|
||||||
@ -536,7 +537,8 @@ geometry_end_element_callback (GMarkupParseContext *pcontext,
|
|||||||
outline->num_points = g_slist_length (data->points);
|
outline->num_points = g_slist_length (data->points);
|
||||||
outline->points = g_slice_alloc0 (sizeof (EekPoint) *
|
outline->points = g_slice_alloc0 (sizeof (EekPoint) *
|
||||||
outline->num_points);
|
outline->num_points);
|
||||||
for (head = data->points = g_slist_reverse (data->points), i = 0;
|
guint i;
|
||||||
|
for (i = 0, head = data->points = g_slist_reverse (data->points);
|
||||||
head && i < outline->num_points;
|
head && i < outline->num_points;
|
||||||
head = g_slist_next (head), i++) {
|
head = g_slist_next (head), i++) {
|
||||||
memcpy (&outline->points[i], head->data, sizeof (EekPoint));
|
memcpy (&outline->points[i], head->data, sizeof (EekPoint));
|
||||||
@ -1136,6 +1138,22 @@ eek_xml_keyboard_desc_free (EekXmlKeyboardDesc *desc)
|
|||||||
g_slice_free (EekXmlKeyboardDesc, desc);
|
g_slice_free (EekXmlKeyboardDesc, desc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void section_placer(EekElement *element, gpointer user_data) {
|
||||||
|
double *current_offset = user_data;
|
||||||
|
EekBounds section_bounds = {0};
|
||||||
|
eek_element_get_bounds(element, §ion_bounds);
|
||||||
|
section_bounds.y = *current_offset;
|
||||||
|
eek_element_set_bounds(element, §ion_bounds);
|
||||||
|
*current_offset += section_bounds.height;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void section_counter(EekElement *element, gpointer user_data) {
|
||||||
|
double *total_height = user_data;
|
||||||
|
EekBounds section_bounds = {0};
|
||||||
|
eek_element_get_bounds(element, §ion_bounds);
|
||||||
|
*total_height += section_bounds.height + 2.0;
|
||||||
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
parse_geometry (const gchar *path, EekKeyboard *keyboard, GError **error)
|
parse_geometry (const gchar *path, EekKeyboard *keyboard, GError **error)
|
||||||
{
|
{
|
||||||
@ -1169,6 +1187,18 @@ parse_geometry (const gchar *path, EekKeyboard *keyboard, GError **error)
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Order rows */
|
||||||
|
// TODO: do this only for rows without bounds
|
||||||
|
double current_offset = 0;
|
||||||
|
eek_container_foreach_child(EEK_CONTAINER(keyboard), section_placer, ¤t_offset);
|
||||||
|
|
||||||
|
double total_height = 0;
|
||||||
|
eek_container_foreach_child(EEK_CONTAINER(keyboard), section_counter, &total_height);
|
||||||
|
EekBounds keyboard_bounds = {0};
|
||||||
|
eek_element_get_bounds(EEK_ELEMENT(keyboard), &keyboard_bounds);
|
||||||
|
keyboard_bounds.height = total_height;
|
||||||
|
eek_element_set_bounds(EEK_ELEMENT(keyboard), &keyboard_bounds);
|
||||||
|
|
||||||
/* Resolve outline references. */
|
/* Resolve outline references. */
|
||||||
oref_hash = g_hash_table_new (g_str_hash, g_str_equal);
|
oref_hash = g_hash_table_new (g_str_hash, g_str_equal);
|
||||||
g_hash_table_iter_init (&iter, data->oref_outline_hash);
|
g_hash_table_iter_init (&iter, data->oref_outline_hash);
|
||||||
|
|||||||
Reference in New Issue
Block a user