section: Moved bounds to row

This commit is contained in:
Dorota Czaplejewicz
2019-08-15 17:57:33 +00:00
parent 4f8de42598
commit 0d33179727
6 changed files with 56 additions and 34 deletions

View File

@ -60,17 +60,21 @@ section_placer(EekElement *element, gpointer user_data)
{ {
struct place_data *data = (struct place_data*)user_data; struct place_data *data = (struct place_data*)user_data;
EekBounds section_bounds = {0}; EekSection *section = EEK_SECTION(element);
eek_element_get_bounds(element, &section_bounds); EekBounds section_bounds = {
section_bounds.width = data->desired_width; .x = 0,
eek_element_set_bounds(element, &section_bounds); .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. // Sections are rows now. Gather up all the keys and adjust their bounds.
eek_section_place_keys(EEK_SECTION(element), data->keyboard); eek_section_place_keys(EEK_SECTION(element), data->keyboard);
eek_element_get_bounds(element, &section_bounds); section_bounds = eek_section_get_bounds(section);
section_bounds.y = data->current_offset; section_bounds.y = data->current_offset;
eek_element_set_bounds(element, &section_bounds); eek_section_set_bounds(section, section_bounds);
data->current_offset += section_bounds.height + section_spacing; data->current_offset += section_bounds.height + section_spacing;
} }
@ -78,8 +82,7 @@ static void
section_counter(EekElement *element, gpointer user_data) { section_counter(EekElement *element, gpointer user_data) {
double *total_height = user_data; double *total_height = user_data;
EekBounds section_bounds = {0}; EekBounds section_bounds = eek_section_get_bounds(EEK_SECTION(element));
eek_element_get_bounds(element, &section_bounds);
*total_height += section_bounds.height + section_spacing; *total_height += section_bounds.height + section_spacing;
} }

View File

@ -122,19 +122,18 @@ create_keyboard_surface_section_callback (EekElement *element,
gpointer user_data) gpointer user_data)
{ {
CreateKeyboardSurfaceCallbackData *data = user_data; CreateKeyboardSurfaceCallbackData *data = user_data;
EekBounds bounds; EekSection *section = EEK_SECTION(element);
EekBounds bounds = eek_section_get_bounds(section);
gint angle; gint angle;
cairo_save (data->cr); cairo_save (data->cr);
eek_element_get_bounds (element, &bounds);
cairo_translate (data->cr, bounds.x, bounds.y); 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); cairo_rotate (data->cr, angle * G_PI / 180);
data->section = EEK_SECTION(element); data->section = section;
eek_section_foreach(EEK_SECTION(element), eek_section_foreach(section,
create_keyboard_surface_button_callback, create_keyboard_surface_button_callback,
data); data);
@ -761,7 +760,7 @@ eek_renderer_get_button_bounds (EekRenderer *renderer,
EekBounds *bounds, EekBounds *bounds,
gboolean rotate) gboolean rotate)
{ {
EekBounds section_bounds, keyboard_bounds; EekBounds keyboard_bounds;
gint angle = 0; gint angle = 0;
EekPoint points[4], min, max; EekPoint points[4], min, max;
@ -772,7 +771,7 @@ eek_renderer_get_button_bounds (EekRenderer *renderer,
EekRendererPrivate *priv = eek_renderer_get_instance_private (renderer); EekRendererPrivate *priv = eek_renderer_get_instance_private (renderer);
EekBounds button_bounds = squeek_button_get_bounds(place->button); EekBounds button_bounds = squeek_button_get_bounds(place->button);
eek_element_get_bounds (EEK_ELEMENT(place->section), &section_bounds); EekBounds section_bounds = eek_section_get_bounds (place->section);
eek_element_get_bounds (EEK_ELEMENT(level_keyboard_current(priv->keyboard)), eek_element_get_bounds (EEK_ELEMENT(level_keyboard_current(priv->keyboard)),
&keyboard_bounds); &keyboard_bounds);
@ -792,7 +791,7 @@ eek_renderer_get_button_bounds (EekRenderer *renderer,
points[3].y = points[2].y; points[3].y = points[2].y;
if (rotate) if (rotate)
angle = eek_section_get_angle (EEK_SECTION(place->section)); angle = eek_section_get_angle (place->section);
min = points[2]; min = points[2];
max = points[0]; max = points[0];
@ -1028,14 +1027,13 @@ find_button_by_position_section_callback (EekElement *element,
{ {
EekSection *section = EEK_SECTION(element); EekSection *section = EEK_SECTION(element);
FindKeyByPositionCallbackData *data = user_data; FindKeyByPositionCallbackData *data = user_data;
EekBounds bounds; EekBounds bounds = eek_section_get_bounds(section);
EekPoint origin; EekPoint origin;
origin = data->origin; origin = data->origin;
eek_element_get_bounds (element, &bounds);
data->origin.x += bounds.x; data->origin.x += bounds.x;
data->origin.y += bounds.y; 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); eek_section_foreach(section, find_button_by_position_key_callback, data);
data->origin = origin; data->origin = origin;

View File

@ -164,14 +164,6 @@ eek_section_get_row (EekSection *section)
return priv->row; 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) { EekBounds eek_get_outline_size(LevelKeyboard *keyboard, uint32_t oref) {
EekOutline *outline = level_keyboard_get_outline (keyboard, oref); EekOutline *outline = level_keyboard_get_outline (keyboard, oref);
if (outline && outline->num_points > 0) { 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) { 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 void
@ -214,15 +212,14 @@ eek_section_place_keys(EekSection *section, LevelKeyboard *keyboard)
{ {
EekSectionPrivate *priv = eek_section_get_instance_private (section); EekSectionPrivate *priv = eek_section_get_instance_private (section);
EekBounds section_size = squeek_row_place_keys(priv->row, keyboard); EekBounds section_size = squeek_row_place_keys(priv->row, keyboard);
EekBounds section_bounds = {0}; EekBounds section_bounds = eek_section_get_bounds(section);
eek_element_get_bounds(EEK_ELEMENT(section), &section_bounds);
// FIXME: do centering of each section based on keyboard dimensions, // FIXME: do centering of each section based on keyboard dimensions,
// one level up the iterators // one level up the iterators
// now centering by comparing previous width to the new, calculated one // now centering by comparing previous width to the new, calculated one
section_bounds.x = (section_bounds.width - section_size.width) / 2; section_bounds.x = (section_bounds.width - section_size.width) / 2;
section_bounds.width = section_size.width; section_bounds.width = section_size.width;
section_bounds.height = section_size.height; section_bounds.height = section_size.height;
eek_element_set_bounds(EEK_ELEMENT(section), &section_bounds); eek_section_set_bounds(section, section_bounds);
} }
void eek_section_foreach (EekSection *section, void eek_section_foreach (EekSection *section,

View File

@ -83,5 +83,7 @@ gboolean eek_section_find(EekSection *section,
struct squeek_button *eek_section_find_key(EekSection *section, struct squeek_button *eek_section_find_key(EekSection *section,
struct squeek_key *key); struct squeek_key *key);
void eek_section_set_bounds(EekSection *section, EekBounds bounds);
EekBounds eek_section_get_bounds(EekSection *section);
G_END_DECLS G_END_DECLS
#endif /* EEK_SECTION_H */ #endif /* EEK_SECTION_H */

View File

@ -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); void squeek_row_set_angle(struct squeek_row *row, int32_t angle);
int32_t squeek_row_get_angle(struct squeek_row*); 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); 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); struct squeek_button* squeek_row_find_key(struct squeek_row*, struct squeek_key *state);

View File

@ -43,6 +43,7 @@ pub mod c {
Box::into_raw(Box::new(::layout::Row { Box::into_raw(Box::new(::layout::Row {
buttons: Vec::new(), buttons: Vec::new(),
angle: angle, angle: angle,
bounds: None,
})) }))
} }
@ -108,6 +109,25 @@ pub mod c {
row.angle 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] #[no_mangle]
pub extern "C" pub extern "C"
fn squeek_row_contains( fn squeek_row_contains(
@ -242,8 +262,6 @@ pub mod c {
mod procedures { mod procedures {
use super::*; use super::*;
use std::convert::TryFrom;
#[repr(transparent)] #[repr(transparent)]
pub struct LevelKeyboard(*const c_void); pub struct LevelKeyboard(*const c_void);
@ -376,4 +394,5 @@ pub struct Button {
pub struct Row { pub struct Row {
buttons: Vec<Box<Button>>, buttons: Vec<Box<Button>>,
angle: i32, angle: i32,
bounds: Option<c::Bounds>,
} }