diff --git a/eek/eek-layout.c b/eek/eek-layout.c index ce84e23c..93f5aa9f 100644 --- a/eek/eek-layout.c +++ b/eek/eek-layout.c @@ -60,17 +60,21 @@ section_placer(EekElement *element, gpointer user_data) { struct place_data *data = (struct place_data*)user_data; - EekBounds section_bounds = {0}; - eek_element_get_bounds(element, §ion_bounds); - section_bounds.width = data->desired_width; - eek_element_set_bounds(element, §ion_bounds); + EekSection *section = EEK_SECTION(element); + EekBounds section_bounds = { + .x = 0, + .y = 0, + .width = data->desired_width, + .height = 0, + }; + eek_section_set_bounds(section, section_bounds); // Sections are rows now. Gather up all the keys and adjust their bounds. eek_section_place_keys(EEK_SECTION(element), data->keyboard); - eek_element_get_bounds(element, §ion_bounds); + section_bounds = eek_section_get_bounds(section); section_bounds.y = data->current_offset; - eek_element_set_bounds(element, §ion_bounds); + eek_section_set_bounds(section, section_bounds); data->current_offset += section_bounds.height + section_spacing; } @@ -78,8 +82,7 @@ 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); + EekBounds section_bounds = eek_section_get_bounds(EEK_SECTION(element)); *total_height += section_bounds.height + section_spacing; } diff --git a/eek/eek-renderer.c b/eek/eek-renderer.c index 7e39c8ff..dbf79fce 100644 --- a/eek/eek-renderer.c +++ b/eek/eek-renderer.c @@ -122,19 +122,18 @@ create_keyboard_surface_section_callback (EekElement *element, gpointer user_data) { CreateKeyboardSurfaceCallbackData *data = user_data; - EekBounds bounds; + EekSection *section = EEK_SECTION(element); + EekBounds bounds = eek_section_get_bounds(section); gint angle; cairo_save (data->cr); - - eek_element_get_bounds (element, &bounds); cairo_translate (data->cr, bounds.x, bounds.y); - angle = eek_section_get_angle (EEK_SECTION(element)); + angle = eek_section_get_angle (section); cairo_rotate (data->cr, angle * G_PI / 180); - data->section = EEK_SECTION(element); - eek_section_foreach(EEK_SECTION(element), + data->section = section; + eek_section_foreach(section, create_keyboard_surface_button_callback, data); @@ -761,7 +760,7 @@ eek_renderer_get_button_bounds (EekRenderer *renderer, EekBounds *bounds, gboolean rotate) { - EekBounds section_bounds, keyboard_bounds; + EekBounds keyboard_bounds; gint angle = 0; EekPoint points[4], min, max; @@ -772,7 +771,7 @@ eek_renderer_get_button_bounds (EekRenderer *renderer, EekRendererPrivate *priv = eek_renderer_get_instance_private (renderer); EekBounds button_bounds = squeek_button_get_bounds(place->button); - eek_element_get_bounds (EEK_ELEMENT(place->section), §ion_bounds); + EekBounds section_bounds = eek_section_get_bounds (place->section); eek_element_get_bounds (EEK_ELEMENT(level_keyboard_current(priv->keyboard)), &keyboard_bounds); @@ -792,7 +791,7 @@ eek_renderer_get_button_bounds (EekRenderer *renderer, points[3].y = points[2].y; if (rotate) - angle = eek_section_get_angle (EEK_SECTION(place->section)); + angle = eek_section_get_angle (place->section); min = points[2]; max = points[0]; @@ -1028,14 +1027,13 @@ find_button_by_position_section_callback (EekElement *element, { EekSection *section = EEK_SECTION(element); FindKeyByPositionCallbackData *data = user_data; - EekBounds bounds; + EekBounds bounds = eek_section_get_bounds(section); EekPoint origin; origin = data->origin; - eek_element_get_bounds (element, &bounds); data->origin.x += bounds.x; data->origin.y += bounds.y; - data->angle = eek_section_get_angle (EEK_SECTION(element)); + data->angle = eek_section_get_angle(section); eek_section_foreach(section, find_button_by_position_key_callback, data); data->origin = origin; diff --git a/eek/eek-section.c b/eek/eek-section.c index a958e7ae..e3f80620 100644 --- a/eek/eek-section.c +++ b/eek/eek-section.c @@ -164,14 +164,6 @@ eek_section_get_row (EekSection *section) return priv->row; } -const double keyspacing = 4.0; - -struct keys_info { - uint count; - double total_width; - double biggest_height; -}; - EekBounds eek_get_outline_size(LevelKeyboard *keyboard, uint32_t oref) { EekOutline *outline = level_keyboard_get_outline (keyboard, oref); if (outline && outline->num_points > 0) { @@ -206,7 +198,13 @@ EekBounds eek_get_outline_size(LevelKeyboard *keyboard, uint32_t oref) { } void eek_section_set_bounds(EekSection *section, EekBounds bounds) { - eek_element_set_bounds(EEK_ELEMENT(section), &bounds); + EekSectionPrivate *priv = eek_section_get_instance_private (section); + squeek_row_set_bounds(priv->row, bounds); +} + +EekBounds eek_section_get_bounds(EekSection *section) { + EekSectionPrivate *priv = eek_section_get_instance_private (section); + return squeek_row_get_bounds(priv->row); } void @@ -214,15 +212,14 @@ eek_section_place_keys(EekSection *section, LevelKeyboard *keyboard) { EekSectionPrivate *priv = eek_section_get_instance_private (section); EekBounds section_size = squeek_row_place_keys(priv->row, keyboard); - EekBounds section_bounds = {0}; - eek_element_get_bounds(EEK_ELEMENT(section), §ion_bounds); + EekBounds section_bounds = eek_section_get_bounds(section); // FIXME: do centering of each section based on keyboard dimensions, // one level up the iterators // now centering by comparing previous width to the new, calculated one section_bounds.x = (section_bounds.width - section_size.width) / 2; section_bounds.width = section_size.width; section_bounds.height = section_size.height; - eek_element_set_bounds(EEK_ELEMENT(section), §ion_bounds); + eek_section_set_bounds(section, section_bounds); } void eek_section_foreach (EekSection *section, diff --git a/eek/eek-section.h b/eek/eek-section.h index 12397f00..16c0aa6b 100644 --- a/eek/eek-section.h +++ b/eek/eek-section.h @@ -83,5 +83,7 @@ gboolean eek_section_find(EekSection *section, struct squeek_button *eek_section_find_key(EekSection *section, struct squeek_key *key); +void eek_section_set_bounds(EekSection *section, EekBounds bounds); +EekBounds eek_section_get_bounds(EekSection *section); G_END_DECLS #endif /* EEK_SECTION_H */ diff --git a/src/layout.h b/src/layout.h index 2cc3fd7a..327ab2de 100644 --- a/src/layout.h +++ b/src/layout.h @@ -17,6 +17,9 @@ struct squeek_button *squeek_row_create_button_with_state(struct squeek_row *row void squeek_row_set_angle(struct squeek_row *row, int32_t angle); int32_t squeek_row_get_angle(struct squeek_row*); +EekBounds squeek_row_get_bounds(const struct squeek_row*); +void squeek_row_set_bounds(struct squeek_row* row, EekBounds bounds); + uint32_t squeek_row_contains(struct squeek_row*, struct squeek_button *button); struct squeek_button* squeek_row_find_key(struct squeek_row*, struct squeek_key *state); diff --git a/src/layout.rs b/src/layout.rs index e44a0e3b..8d912792 100644 --- a/src/layout.rs +++ b/src/layout.rs @@ -43,6 +43,7 @@ pub mod c { Box::into_raw(Box::new(::layout::Row { buttons: Vec::new(), angle: angle, + bounds: None, })) } @@ -108,6 +109,25 @@ pub mod c { row.angle } + #[no_mangle] + pub extern "C" + fn squeek_row_get_bounds(row: *const ::layout::Row) -> Bounds { + let row = unsafe { &*row }; + match &row.bounds { + Some(bounds) => bounds.clone(), + None => panic!("Row doesn't have any bounds yet"), + } + } + + /// Set bounds by consuming the value + #[no_mangle] + pub extern "C" + fn squeek_row_set_bounds(row: *mut ::layout::Row, bounds: Bounds) { + let row = unsafe { &mut *row }; + row.bounds = Some(bounds); + } + + #[no_mangle] pub extern "C" fn squeek_row_contains( @@ -242,8 +262,6 @@ pub mod c { mod procedures { use super::*; - use std::convert::TryFrom; - #[repr(transparent)] pub struct LevelKeyboard(*const c_void); @@ -376,4 +394,5 @@ pub struct Button { pub struct Row { buttons: Vec>, angle: i32, + bounds: Option, }