layout: Use outlines for key bounds
This commit is contained in:
		@ -71,7 +71,7 @@
 | 
				
			|||||||
  <section angle="0">
 | 
					  <section angle="0">
 | 
				
			||||||
    <bounds x="15.60975" y="78.04878" width="608.7804" height="201.3658"/>
 | 
					    <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="altline">
 | 
				
			||||||
	<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"/>
 | 
				
			||||||
      </key>
 | 
					      </key>
 | 
				
			||||||
      <key keycode="52" name="AB01" oref="outline2">
 | 
					      <key keycode="52" name="AB01" oref="outline2">
 | 
				
			||||||
@ -95,7 +95,7 @@
 | 
				
			|||||||
      <key keycode="58" name="AB07" oref="outline2">
 | 
					      <key keycode="58" name="AB07" oref="outline2">
 | 
				
			||||||
	<bounds x="337.1707" y="121.7560" width="37.46341" height="37.46341"/>
 | 
						<bounds x="337.1707" y="121.7560" width="37.46341" height="37.46341"/>
 | 
				
			||||||
      </key>
 | 
					      </key>
 | 
				
			||||||
      <key keycode="22" name="BKSP" oref="outline13">
 | 
					      <key keycode="22" name="BKSP" oref="altline">
 | 
				
			||||||
	<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>
 | 
				
			||||||
@ -103,13 +103,13 @@
 | 
				
			|||||||
  <section angle="0">
 | 
					  <section angle="0">
 | 
				
			||||||
    <bounds x="15.60975" y="78.04878" width="608.7804" height="201.3658"/>
 | 
					    <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="altline">
 | 
				
			||||||
	<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"/>
 | 
				
			||||||
      </key>
 | 
					      </key>
 | 
				
			||||||
      <key keycode="64" name="LALT" oref="outline1">
 | 
					      <key keycode="64" name="LALT" oref="altline">
 | 
				
			||||||
	<bounds x="113.9512" y="162.3414" width="48.39024" height="37.46341"/>
 | 
						<bounds x="113.9512" y="162.3414" width="48.39024" height="37.46341"/>
 | 
				
			||||||
      </key>
 | 
					      </key>
 | 
				
			||||||
      <key keycode="65" name="SPCE" oref="outline3">
 | 
					      <key keycode="65" name="SPCE" oref="spaceline">
 | 
				
			||||||
	<bounds x="165.4634" y="162.3414" width="217.5853" height="37.46341"/>
 | 
						<bounds x="165.4634" y="162.3414" width="217.5853" height="37.46341"/>
 | 
				
			||||||
      </key>
 | 
					      </key>
 | 
				
			||||||
      <key keycode="60" name="AB09" oref="outline2">
 | 
					      <key keycode="60" name="AB09" oref="outline2">
 | 
				
			||||||
@ -126,7 +126,7 @@
 | 
				
			|||||||
    <point x="37.46341" y="37.46341"/>
 | 
					    <point x="37.46341" y="37.46341"/>
 | 
				
			||||||
    <point x="0.000000" y="37.46341"/>
 | 
					    <point x="0.000000" y="37.46341"/>
 | 
				
			||||||
  </outline>
 | 
					  </outline>
 | 
				
			||||||
  <outline id="outline1" corner-radius="1.000000">
 | 
					  <outline id="altline" corner-radius="1.000000">
 | 
				
			||||||
    <point x="0.000000" y="0.000000"/>
 | 
					    <point x="0.000000" y="0.000000"/>
 | 
				
			||||||
    <point x="48.39024" y="0.000000"/>
 | 
					    <point x="48.39024" y="0.000000"/>
 | 
				
			||||||
    <point x="48.39024" y="37.46341"/>
 | 
					    <point x="48.39024" y="37.46341"/>
 | 
				
			||||||
@ -180,10 +180,10 @@
 | 
				
			|||||||
    <point x="79.60975" y="37.46341"/>
 | 
					    <point x="79.60975" y="37.46341"/>
 | 
				
			||||||
    <point x="0.000000" y="37.46341"/>
 | 
					    <point x="0.000000" y="37.46341"/>
 | 
				
			||||||
  </outline>
 | 
					  </outline>
 | 
				
			||||||
  <outline id="outline3" corner-radius="1.000000">
 | 
					  <outline id="spaceline" corner-radius="1.000000">
 | 
				
			||||||
    <point x="0.000000" y="0.000000"/>
 | 
					    <point x="0.000000" y="0.000000"/>
 | 
				
			||||||
    <point x="217.5853" y="0.000000"/>
 | 
					    <point x="150.5853" y="0.000000"/>
 | 
				
			||||||
    <point x="217.5853" y="37.46341"/>
 | 
					    <point x="150.5853" y="37.46341"/>
 | 
				
			||||||
    <point x="0.000000" y="37.46341"/>
 | 
					    <point x="0.000000" y="37.46341"/>
 | 
				
			||||||
  </outline>
 | 
					  </outline>
 | 
				
			||||||
</geometry>
 | 
					</geometry>
 | 
				
			||||||
 | 
				
			|||||||
@ -480,6 +480,38 @@ eek_section_create_key (EekSection *section,
 | 
				
			|||||||
                                                       row);
 | 
					                                                       row);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static void keysizer(EekElement *element, gpointer user_data) {
 | 
				
			||||||
 | 
					    EekKey *key = EEK_KEY(element);
 | 
				
			||||||
 | 
					    EekKeyboard *keyboard = EEK_KEYBOARD(user_data);
 | 
				
			||||||
 | 
					    uint oref = eek_key_get_oref (key);
 | 
				
			||||||
 | 
					    EekOutline *outline = eek_keyboard_get_outline (keyboard, oref);
 | 
				
			||||||
 | 
					    if (outline && outline->num_points > 0) {
 | 
				
			||||||
 | 
					        double minx = outline->points[0].x;
 | 
				
			||||||
 | 
					        double maxx = minx;
 | 
				
			||||||
 | 
					        double miny = outline->points[0].y;
 | 
				
			||||||
 | 
					        double maxy = miny;
 | 
				
			||||||
 | 
					        for (uint i = 1; i < outline->num_points; i++) {
 | 
				
			||||||
 | 
					            EekPoint p = outline->points[i];
 | 
				
			||||||
 | 
					            if (p.x < minx) {
 | 
				
			||||||
 | 
					                minx = p.x;
 | 
				
			||||||
 | 
					            } else if (p.x > maxx) {
 | 
				
			||||||
 | 
					                maxx = p.x;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            if (p.y < miny) {
 | 
				
			||||||
 | 
					                miny = p.y;
 | 
				
			||||||
 | 
					            } else if (p.y > maxy) {
 | 
				
			||||||
 | 
					                maxy = p.y;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        EekBounds key_bounds = {0};
 | 
				
			||||||
 | 
					        eek_element_get_bounds(element, &key_bounds);
 | 
				
			||||||
 | 
					        key_bounds.height = maxy - miny;
 | 
				
			||||||
 | 
					        key_bounds.width = maxx - minx;
 | 
				
			||||||
 | 
					        eek_element_set_bounds(element, &key_bounds);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct keys_info {
 | 
					struct keys_info {
 | 
				
			||||||
    uint count;
 | 
					    uint count;
 | 
				
			||||||
    double total_width;
 | 
					    double total_width;
 | 
				
			||||||
@ -509,14 +541,15 @@ static void keyplacer(EekElement *element, gpointer user_data) {
 | 
				
			|||||||
    *current_offset += key_bounds.width + keyspacing;
 | 
					    *current_offset += key_bounds.width + keyspacing;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void eek_section_place_keys(EekSection *section)
 | 
					void eek_section_place_keys(EekSection *section, EekKeyboard *keyboard)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
					    eek_container_foreach_child(EEK_CONTAINER(section), keysizer, keyboard);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    struct keys_info keyinfo = {0};
 | 
					    struct keys_info keyinfo = {0};
 | 
				
			||||||
    eek_container_foreach_child(EEK_CONTAINER(section), keycounter, &keyinfo);
 | 
					    eek_container_foreach_child(EEK_CONTAINER(section), keycounter, &keyinfo);
 | 
				
			||||||
    EekBounds section_bounds = {0};
 | 
					    EekBounds section_bounds = {0};
 | 
				
			||||||
    eek_element_get_bounds(EEK_ELEMENT(section), §ion_bounds);
 | 
					    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;
 | 
					    double key_offset = (section_bounds.width - (keyinfo.total_width + (keyinfo.count - 1) * keyspacing)) / 2;
 | 
				
			||||||
    eek_container_foreach_child(EEK_CONTAINER(section), keyplacer, &key_offset);
 | 
					    eek_container_foreach_child(EEK_CONTAINER(section), keyplacer, &key_offset);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -127,7 +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);
 | 
					void eek_section_place_keys              (EekSection     *section, EekKeyboard *keyboard);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
G_END_DECLS
 | 
					G_END_DECLS
 | 
				
			||||||
#endif  /* EEK_SECTION_H */
 | 
					#endif  /* EEK_SECTION_H */
 | 
				
			||||||
 | 
				
			|||||||
@ -510,8 +510,6 @@ geometry_end_element_callback (GMarkupParseContext *pcontext,
 | 
				
			|||||||
    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;
 | 
				
			||||||
@ -1138,13 +1136,22 @@ eek_xml_keyboard_desc_free (EekXmlKeyboardDesc *desc)
 | 
				
			|||||||
    g_slice_free (EekXmlKeyboardDesc, desc);
 | 
					    g_slice_free (EekXmlKeyboardDesc, desc);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					struct place_data {
 | 
				
			||||||
 | 
					    double current_offset;
 | 
				
			||||||
 | 
					    EekKeyboard *keyboard;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void section_placer(EekElement *element, gpointer user_data) {
 | 
					static void section_placer(EekElement *element, gpointer user_data) {
 | 
				
			||||||
    double *current_offset = user_data;
 | 
					    struct place_data *data = user_data;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // Sections are rows now. Gather up all the keys and adjust their bounds.
 | 
				
			||||||
 | 
					    eek_section_place_keys(EEK_SECTION(element), EEK_KEYBOARD(data->keyboard));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    EekBounds section_bounds = {0};
 | 
					    EekBounds section_bounds = {0};
 | 
				
			||||||
    eek_element_get_bounds(element, §ion_bounds);
 | 
					    eek_element_get_bounds(element, §ion_bounds);
 | 
				
			||||||
    section_bounds.y = *current_offset;
 | 
					    section_bounds.y = data->current_offset;
 | 
				
			||||||
    eek_element_set_bounds(element, §ion_bounds);
 | 
					    eek_element_set_bounds(element, §ion_bounds);
 | 
				
			||||||
    *current_offset += section_bounds.height;
 | 
					    data->current_offset += section_bounds.height;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void section_counter(EekElement *element, gpointer user_data) {
 | 
					static void section_counter(EekElement *element, gpointer user_data) {
 | 
				
			||||||
@ -1187,18 +1194,6 @@ 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);
 | 
				
			||||||
@ -1218,6 +1213,22 @@ parse_geometry (const gchar *path, EekKeyboard *keyboard, GError **error)
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
    g_hash_table_destroy (oref_hash);
 | 
					    g_hash_table_destroy (oref_hash);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /* Order rows */
 | 
				
			||||||
 | 
					    // This needs to be done after outlines, because outlines define key sizes
 | 
				
			||||||
 | 
					    // TODO: do this only for rows without bounds
 | 
				
			||||||
 | 
					    struct place_data placer_data = {
 | 
				
			||||||
 | 
					        .current_offset = 0,
 | 
				
			||||||
 | 
					        .keyboard = keyboard,
 | 
				
			||||||
 | 
					    };
 | 
				
			||||||
 | 
					    eek_container_foreach_child(EEK_CONTAINER(keyboard), section_placer, &placer_data);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    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);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    geometry_parse_data_free (data);
 | 
					    geometry_parse_data_free (data);
 | 
				
			||||||
    return TRUE;
 | 
					    return TRUE;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user