section: Elininate references
This commit is contained in:
		@ -528,9 +528,9 @@ on_button_pressed (struct squeek_button *button,
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    struct button_place place = {
 | 
					    struct button_place place = {
 | 
				
			||||||
        .button = button,
 | 
					        .button = button,
 | 
				
			||||||
        .section = eek_keyboard_get_section(view, button),
 | 
					        .row = eek_keyboard_get_row(view, button),
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
    if (!place.section) {
 | 
					    if (!place.row) {
 | 
				
			||||||
        return;
 | 
					        return;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    render_pressed_button (GTK_WIDGET(self), &place);
 | 
					    render_pressed_button (GTK_WIDGET(self), &place);
 | 
				
			||||||
 | 
				
			|||||||
@ -66,7 +66,7 @@ struct _EekKeyboardPrivate
 | 
				
			|||||||
    char dummy;    // won't run otherwise
 | 
					    char dummy;    // won't run otherwise
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
G_DEFINE_TYPE_WITH_PRIVATE (EekKeyboard, eek_keyboard, EEK_TYPE_CONTAINER);
 | 
					G_DEFINE_TYPE_WITH_PRIVATE (EekKeyboard, eek_keyboard, EEK_TYPE_ELEMENT);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
G_DEFINE_BOXED_TYPE(EekModifierKey, eek_modifier_key,
 | 
					G_DEFINE_BOXED_TYPE(EekModifierKey, eek_modifier_key,
 | 
				
			||||||
                    eek_modifier_key_copy, eek_modifier_key_free);
 | 
					                    eek_modifier_key_copy, eek_modifier_key_free);
 | 
				
			||||||
@ -83,17 +83,12 @@ eek_modifier_key_free (EekModifierKey *modkey)
 | 
				
			|||||||
    g_slice_free (EekModifierKey, modkey);
 | 
					    g_slice_free (EekModifierKey, modkey);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
EekSection *
 | 
					struct squeek_row *
 | 
				
			||||||
eek_keyboard_real_create_section (EekKeyboard *self)
 | 
					eek_keyboard_real_create_row (EekKeyboard *self)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    EekSection *section;
 | 
					    struct squeek_row *row = squeek_row_new(0);
 | 
				
			||||||
 | 
					    g_ptr_array_add(self->rows, row);
 | 
				
			||||||
    section = g_object_new (EEK_TYPE_SECTION, NULL);
 | 
					    return row;
 | 
				
			||||||
    g_return_val_if_fail (section, NULL);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    EEK_CONTAINER_GET_CLASS(self)->add_child (EEK_CONTAINER(self),
 | 
					 | 
				
			||||||
                                              EEK_ELEMENT(section));
 | 
					 | 
				
			||||||
    return section;
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void
 | 
					static void
 | 
				
			||||||
@ -278,13 +273,9 @@ eek_keyboard_real_child_removed (EekContainer *self,
 | 
				
			|||||||
static void
 | 
					static void
 | 
				
			||||||
eek_keyboard_class_init (EekKeyboardClass *klass)
 | 
					eek_keyboard_class_init (EekKeyboardClass *klass)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    EekContainerClass *container_class = EEK_CONTAINER_CLASS (klass);
 | 
					 | 
				
			||||||
    GObjectClass      *gobject_class = G_OBJECT_CLASS (klass);
 | 
					    GObjectClass      *gobject_class = G_OBJECT_CLASS (klass);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* signals */
 | 
					    /* signals */
 | 
				
			||||||
    container_class->child_added = eek_keyboard_real_child_added;
 | 
					 | 
				
			||||||
    container_class->child_removed = eek_keyboard_real_child_removed;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    gobject_class->get_property = eek_keyboard_get_property;
 | 
					    gobject_class->get_property = eek_keyboard_get_property;
 | 
				
			||||||
    gobject_class->set_property = eek_keyboard_set_property;
 | 
					    gobject_class->set_property = eek_keyboard_set_property;
 | 
				
			||||||
    gobject_class->dispose = eek_keyboard_dispose;
 | 
					    gobject_class->dispose = eek_keyboard_dispose;
 | 
				
			||||||
@ -294,8 +285,14 @@ eek_keyboard_class_init (EekKeyboardClass *klass)
 | 
				
			|||||||
static void
 | 
					static void
 | 
				
			||||||
eek_keyboard_init (EekKeyboard *self)
 | 
					eek_keyboard_init (EekKeyboard *self)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    self->priv = EEK_KEYBOARD_GET_PRIVATE(self);
 | 
					 | 
				
			||||||
    self->scale = 1.0;
 | 
					    self->scale = 1.0;
 | 
				
			||||||
 | 
					    self->rows = g_ptr_array_new();
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void eek_keyboard_foreach (EekKeyboard *keyboard,
 | 
				
			||||||
 | 
					                     GFunc      func,
 | 
				
			||||||
 | 
					                          gpointer   user_data) {
 | 
				
			||||||
 | 
					    g_ptr_array_foreach(keyboard->rows, func, user_data);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void level_keyboard_init(LevelKeyboard *self) {
 | 
					void level_keyboard_init(LevelKeyboard *self) {
 | 
				
			||||||
@ -431,42 +428,42 @@ EekKeyboard *level_keyboard_current(LevelKeyboard *keyboard)
 | 
				
			|||||||
    return keyboard->views[keyboard->level];
 | 
					    return keyboard->views[keyboard->level];
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct GetSectionData {
 | 
					struct GetRowData {
 | 
				
			||||||
    struct squeek_button *button;
 | 
					    struct squeek_button *button;
 | 
				
			||||||
    EekSection *section;
 | 
					    struct squeek_row *row;
 | 
				
			||||||
    struct squeek_key *needle;
 | 
					    struct squeek_key *needle;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void find_button_in_section(EekElement *element, gpointer user_data) {
 | 
					void find_button_in_row(gpointer item, gpointer user_data) {
 | 
				
			||||||
    EekSection *section = EEK_SECTION(element);
 | 
					    struct squeek_row *row = item;
 | 
				
			||||||
    struct GetSectionData *data = user_data;
 | 
					    struct GetRowData *data = user_data;
 | 
				
			||||||
    if (data->section) {
 | 
					    if (data->row) {
 | 
				
			||||||
        return;
 | 
					        return;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    if (eek_section_find(section, data->button)) {
 | 
					    if (squeek_row_contains(row, data->button)) {
 | 
				
			||||||
        data->section = section;
 | 
					        data->row = row;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
EekSection *eek_keyboard_get_section(EekKeyboard *keyboard,
 | 
					struct squeek_row *eek_keyboard_get_row(EekKeyboard *keyboard,
 | 
				
			||||||
                                     struct squeek_button *button) {
 | 
					                                     struct squeek_button *button) {
 | 
				
			||||||
    struct GetSectionData data = {
 | 
					    struct GetRowData data = {
 | 
				
			||||||
        .button = button,
 | 
					        .button = button,
 | 
				
			||||||
        .section = NULL,
 | 
					        .row = NULL,
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
    eek_container_foreach_child(EEK_CONTAINER(keyboard), find_button_in_section, &data);
 | 
					    eek_keyboard_foreach(keyboard, find_button_in_row, &data);
 | 
				
			||||||
    return data.section;
 | 
					    return data.row;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void find_key_in_section(EekElement *element, gpointer user_data) {
 | 
					void find_key_in_row(gpointer item, gpointer user_data) {
 | 
				
			||||||
    EekSection *section = EEK_SECTION(element);
 | 
					    struct squeek_row *row = item;
 | 
				
			||||||
    struct GetSectionData *data = user_data;
 | 
					    struct GetRowData *data = user_data;
 | 
				
			||||||
    if (data->button) {
 | 
					    if (data->button) {
 | 
				
			||||||
        return;
 | 
					        return;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    data->button = eek_section_find_key(section, data->needle);
 | 
					    data->button = squeek_row_find_key(row, data->needle);
 | 
				
			||||||
    if (data->button) {
 | 
					    if (data->button) {
 | 
				
			||||||
        data->section = section;
 | 
					        data->row = row;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -474,14 +471,14 @@ void find_key_in_section(EekElement *element, gpointer user_data) {
 | 
				
			|||||||
// TODO: return multiple
 | 
					// TODO: return multiple
 | 
				
			||||||
struct button_place eek_keyboard_get_button_by_state(EekKeyboard *keyboard,
 | 
					struct button_place eek_keyboard_get_button_by_state(EekKeyboard *keyboard,
 | 
				
			||||||
                                             struct squeek_key *key) {
 | 
					                                             struct squeek_key *key) {
 | 
				
			||||||
    struct GetSectionData data = {
 | 
					    struct GetRowData data = {
 | 
				
			||||||
        .section = NULL,
 | 
					        .row = NULL,
 | 
				
			||||||
        .button = NULL,
 | 
					        .button = NULL,
 | 
				
			||||||
        .needle = key,
 | 
					        .needle = key,
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
    eek_container_foreach_child(EEK_CONTAINER(keyboard), find_key_in_section, &data);
 | 
					    eek_keyboard_foreach(keyboard, find_key_in_row, &data);
 | 
				
			||||||
    struct button_place ret = {
 | 
					    struct button_place ret = {
 | 
				
			||||||
        .section = data.section,
 | 
					        .row = data.row,
 | 
				
			||||||
        .button = data.button,
 | 
					        .button = data.button,
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
    return ret;
 | 
					    return ret;
 | 
				
			||||||
 | 
				
			|||||||
@ -57,10 +57,11 @@ typedef struct _EekKeyboardPrivate EekKeyboardPrivate;
 | 
				
			|||||||
struct _EekKeyboard
 | 
					struct _EekKeyboard
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    /*< private >*/
 | 
					    /*< private >*/
 | 
				
			||||||
    EekContainer parent;
 | 
					    EekElement parent;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    EekKeyboardPrivate *priv;
 | 
					    EekKeyboardPrivate *priv;
 | 
				
			||||||
    double scale;
 | 
					    double scale;
 | 
				
			||||||
 | 
					    GPtrArray *rows; // struct squeek_row*
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
@ -77,7 +78,7 @@ struct _EekKeyboard
 | 
				
			|||||||
struct _EekKeyboardClass
 | 
					struct _EekKeyboardClass
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    /*< private >*/
 | 
					    /*< private >*/
 | 
				
			||||||
    EekContainerClass parent_class;
 | 
					    EekElementClass parent_class;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* obsolete members moved to EekElement */
 | 
					    /* obsolete members moved to EekElement */
 | 
				
			||||||
    gpointer set_symbol_index;
 | 
					    gpointer set_symbol_index;
 | 
				
			||||||
@ -156,15 +157,14 @@ void                eek_keyboard_set_size
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
EekSection         *eek_keyboard_create_section
 | 
					EekSection         *eek_keyboard_create_section
 | 
				
			||||||
                                     (EekKeyboard        *keyboard);
 | 
					                                     (EekKeyboard        *keyboard);
 | 
				
			||||||
EekSection         *eek_keyboard_get_section
 | 
					struct squeek_row *eek_keyboard_get_row(EekKeyboard *keyboard,
 | 
				
			||||||
                                     (EekKeyboard *keyboard,
 | 
					 | 
				
			||||||
                                      struct squeek_button *button);
 | 
					                                      struct squeek_button *button);
 | 
				
			||||||
struct squeek_button *eek_keyboard_find_button_by_name(LevelKeyboard *keyboard,
 | 
					struct squeek_button *eek_keyboard_find_button_by_name(LevelKeyboard *keyboard,
 | 
				
			||||||
                                      const gchar        *name);
 | 
					                                      const gchar        *name);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/// Represents the path to the button within a view
 | 
					/// Represents the path to the button within a view
 | 
				
			||||||
struct button_place {
 | 
					struct button_place {
 | 
				
			||||||
    EekSection *section;
 | 
					    struct squeek_row *row;
 | 
				
			||||||
    struct squeek_button *button;
 | 
					    struct squeek_button *button;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -185,16 +185,14 @@ void eek_keyboard_release_button(LevelKeyboard *keyboard, struct squeek_button *
 | 
				
			|||||||
gchar *             eek_keyboard_get_keymap
 | 
					gchar *             eek_keyboard_get_keymap
 | 
				
			||||||
                                     (LevelKeyboard *keyboard);
 | 
					                                     (LevelKeyboard *keyboard);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void eek_keyboard_foreach (EekKeyboard *keyboard,
 | 
				
			||||||
 | 
					                     GFunc      func,
 | 
				
			||||||
 | 
					                          gpointer   user_data);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
EekKeyboard *level_keyboard_current(LevelKeyboard *keyboard);
 | 
					EekKeyboard *level_keyboard_current(LevelKeyboard *keyboard);
 | 
				
			||||||
LevelKeyboard *level_keyboard_new(EekboardContextService *manager, EekKeyboard *views[4], GHashTable *name_button_hash);
 | 
					LevelKeyboard *level_keyboard_new(EekboardContextService *manager, EekKeyboard *views[4], GHashTable *name_button_hash);
 | 
				
			||||||
void level_keyboard_deinit(LevelKeyboard *self);
 | 
					void level_keyboard_deinit(LevelKeyboard *self);
 | 
				
			||||||
void level_keyboard_free(LevelKeyboard *self);
 | 
					void level_keyboard_free(LevelKeyboard *self);
 | 
				
			||||||
/* Create an #EekSection instance and append it to @keyboard.  This
 | 
					 | 
				
			||||||
* function is rarely called by application but called by #EekLayout
 | 
					 | 
				
			||||||
* implementation.
 | 
					 | 
				
			||||||
*/
 | 
					 | 
				
			||||||
EekSection *
 | 
					 | 
				
			||||||
eek_keyboard_real_create_section (EekKeyboard *self);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct squeek_row *
 | 
					struct squeek_row *
 | 
				
			||||||
eek_keyboard_real_create_row (EekKeyboard *self);
 | 
					eek_keyboard_real_create_row (EekKeyboard *self);
 | 
				
			||||||
 | 
				
			|||||||
@ -46,7 +46,7 @@ eek_layout_init (EekLayout *self)
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const double section_spacing = 7.0;
 | 
					const double row_spacing = 7.0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct place_data {
 | 
					struct place_data {
 | 
				
			||||||
    double desired_width;
 | 
					    double desired_width;
 | 
				
			||||||
@ -56,38 +56,39 @@ struct place_data {
 | 
				
			|||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void
 | 
					static void
 | 
				
			||||||
section_placer(EekElement *element, gpointer user_data)
 | 
					row_placer(gpointer item, gpointer user_data)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    struct place_data *data = (struct place_data*)user_data;
 | 
					    struct place_data *data = (struct place_data*)user_data;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    EekSection *section = EEK_SECTION(element);
 | 
					    struct squeek_row *row = item;
 | 
				
			||||||
    EekBounds section_bounds = {
 | 
					    EekBounds row_bounds = {
 | 
				
			||||||
        .x = 0,
 | 
					        .x = 0,
 | 
				
			||||||
        .y = 0,
 | 
					        .y = 0,
 | 
				
			||||||
        .width = data->desired_width,
 | 
					        .width = data->desired_width,
 | 
				
			||||||
        .height = 0,
 | 
					        .height = 0,
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
    eek_section_set_bounds(section, section_bounds);
 | 
					    squeek_row_set_bounds(row, row_bounds);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Sections are rows now. Gather up all the keys and adjust their bounds.
 | 
					    // Gather up all the keys in a row and adjust their bounds.
 | 
				
			||||||
    eek_section_place_keys(EEK_SECTION(element), data->keyboard);
 | 
					    eek_row_place_buttons(row, data->keyboard);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    section_bounds = eek_section_get_bounds(section);
 | 
					    row_bounds = squeek_row_get_bounds(row);
 | 
				
			||||||
    section_bounds.y = data->current_offset;
 | 
					    row_bounds.y = data->current_offset;
 | 
				
			||||||
    eek_section_set_bounds(section, section_bounds);
 | 
					    squeek_row_set_bounds(row, row_bounds);
 | 
				
			||||||
    data->current_offset += section_bounds.height + section_spacing;
 | 
					    data->current_offset += row_bounds.height + row_spacing;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void
 | 
					static void
 | 
				
			||||||
section_counter(EekElement *element, gpointer user_data) {
 | 
					row_counter(gpointer item, gpointer user_data) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    double *total_height = user_data;
 | 
					    double *total_height = user_data;
 | 
				
			||||||
    EekBounds section_bounds = eek_section_get_bounds(EEK_SECTION(element));
 | 
					    struct squeek_row *row = item;
 | 
				
			||||||
    *total_height += section_bounds.height + section_spacing;
 | 
					    EekBounds row_bounds = squeek_row_get_bounds(row);
 | 
				
			||||||
 | 
					    *total_height += row_bounds.height + row_spacing;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void
 | 
					void
 | 
				
			||||||
eek_layout_place_sections(LevelKeyboard *keyboard, EekKeyboard *level)
 | 
					eek_layout_place_rows(LevelKeyboard *keyboard, EekKeyboard *level)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    /* Order rows */
 | 
					    /* Order rows */
 | 
				
			||||||
    // This needs to be done after outlines, because outlines define key sizes
 | 
					    // This needs to be done after outlines, because outlines define key sizes
 | 
				
			||||||
@ -103,10 +104,10 @@ eek_layout_place_sections(LevelKeyboard *keyboard, EekKeyboard *level)
 | 
				
			|||||||
        .current_offset = 0,
 | 
					        .current_offset = 0,
 | 
				
			||||||
        .keyboard = keyboard,
 | 
					        .keyboard = keyboard,
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
    eek_container_foreach_child(EEK_CONTAINER(level), section_placer, &placer_data);
 | 
					    eek_keyboard_foreach(level, row_placer, &placer_data);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    double total_height = 0;
 | 
					    double total_height = 0;
 | 
				
			||||||
    eek_container_foreach_child(EEK_CONTAINER(level), section_counter, &total_height);
 | 
					    eek_keyboard_foreach(level, row_counter, &total_height);
 | 
				
			||||||
    keyboard_bounds.height = total_height;
 | 
					    keyboard_bounds.height = total_height;
 | 
				
			||||||
    eek_element_set_bounds(EEK_ELEMENT(level), &keyboard_bounds);
 | 
					    eek_element_set_bounds(EEK_ELEMENT(level), &keyboard_bounds);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@ -114,5 +115,5 @@ eek_layout_place_sections(LevelKeyboard *keyboard, EekKeyboard *level)
 | 
				
			|||||||
void
 | 
					void
 | 
				
			||||||
eek_layout_update_layout(LevelKeyboard *keyboard)
 | 
					eek_layout_update_layout(LevelKeyboard *keyboard)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    eek_layout_place_sections(keyboard, level_keyboard_current(keyboard));
 | 
					    eek_layout_place_rows(keyboard, level_keyboard_current(keyboard));
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -55,7 +55,7 @@ struct _EekLayoutClass
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
GType        eek_layout_get_type  (void) G_GNUC_CONST;
 | 
					GType        eek_layout_get_type  (void) G_GNUC_CONST;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void         eek_layout_place_sections(LevelKeyboard *keyboard, EekKeyboard *level);
 | 
					void         eek_layout_place_rows(LevelKeyboard *keyboard, EekKeyboard *level);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void         eek_layout_update_layout(LevelKeyboard *keyboard);
 | 
					void         eek_layout_update_layout(LevelKeyboard *keyboard);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -88,7 +88,7 @@ struct _CreateKeyboardSurfaceCallbackData {
 | 
				
			|||||||
    cairo_t *cr;
 | 
					    cairo_t *cr;
 | 
				
			||||||
    EekRenderer *renderer;
 | 
					    EekRenderer *renderer;
 | 
				
			||||||
    EekKeyboard *view;
 | 
					    EekKeyboard *view;
 | 
				
			||||||
    EekSection *section;
 | 
					    struct squeek_row *row;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
typedef struct _CreateKeyboardSurfaceCallbackData CreateKeyboardSurfaceCallbackData;
 | 
					typedef struct _CreateKeyboardSurfaceCallbackData CreateKeyboardSurfaceCallbackData;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -109,7 +109,7 @@ create_keyboard_surface_button_callback (struct squeek_button *button,
 | 
				
			|||||||
                     bounds.height + 100);
 | 
					                     bounds.height + 100);
 | 
				
			||||||
    cairo_clip (data->cr);
 | 
					    cairo_clip (data->cr);
 | 
				
			||||||
    struct button_place place = {
 | 
					    struct button_place place = {
 | 
				
			||||||
        .section = data->section,
 | 
					        .row = data->row,
 | 
				
			||||||
        .button = button,
 | 
					        .button = button,
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
    render_button (data->renderer, data->cr, &place, FALSE);
 | 
					    render_button (data->renderer, data->cr, &place, FALSE);
 | 
				
			||||||
@ -118,23 +118,21 @@ create_keyboard_surface_button_callback (struct squeek_button *button,
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void
 | 
					static void
 | 
				
			||||||
create_keyboard_surface_section_callback (EekElement *element,
 | 
					create_keyboard_surface_row_callback (gpointer item,
 | 
				
			||||||
                                          gpointer    user_data)
 | 
					                                          gpointer    user_data)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    CreateKeyboardSurfaceCallbackData *data = user_data;
 | 
					    CreateKeyboardSurfaceCallbackData *data = user_data;
 | 
				
			||||||
    EekSection *section = EEK_SECTION(element);
 | 
					    struct squeek_row *row = item;
 | 
				
			||||||
    EekBounds bounds = eek_section_get_bounds(section);
 | 
					    EekBounds bounds = squeek_row_get_bounds(row);
 | 
				
			||||||
    gint angle;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    cairo_save (data->cr);
 | 
					    cairo_save (data->cr);
 | 
				
			||||||
    cairo_translate (data->cr, bounds.x, bounds.y);
 | 
					    cairo_translate (data->cr, bounds.x, bounds.y);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    angle = eek_section_get_angle (section);
 | 
					    gint angle = squeek_row_get_angle (row);
 | 
				
			||||||
    cairo_rotate (data->cr, angle * G_PI / 180);
 | 
					    cairo_rotate (data->cr, angle * G_PI / 180);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    data->section = section;
 | 
					    data->row = row;
 | 
				
			||||||
    eek_section_foreach(section,
 | 
					    squeek_row_foreach(row, create_keyboard_surface_button_callback,
 | 
				
			||||||
                                 create_keyboard_surface_button_callback,
 | 
					 | 
				
			||||||
                                 data);
 | 
					                                 data);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    cairo_restore (data->cr);
 | 
					    cairo_restore (data->cr);
 | 
				
			||||||
@ -177,9 +175,9 @@ render_keyboard_surface (EekRenderer *renderer, EekKeyboard *view)
 | 
				
			|||||||
                           foreground.blue,
 | 
					                           foreground.blue,
 | 
				
			||||||
                           foreground.alpha);
 | 
					                           foreground.alpha);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /* draw sections */
 | 
					    /* draw rows */
 | 
				
			||||||
    eek_container_foreach_child (EEK_CONTAINER(level_keyboard_current(priv->keyboard)),
 | 
					    eek_keyboard_foreach(level_keyboard_current(priv->keyboard),
 | 
				
			||||||
                                 create_keyboard_surface_section_callback,
 | 
					                                 create_keyboard_surface_row_callback,
 | 
				
			||||||
                                 &data);
 | 
					                                 &data);
 | 
				
			||||||
    cairo_restore (data.cr);
 | 
					    cairo_restore (data.cr);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -351,13 +349,12 @@ eek_renderer_apply_transformation_for_button (EekRenderer *self,
 | 
				
			|||||||
                                           gboolean     rotate)
 | 
					                                           gboolean     rotate)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    EekBounds bounds, rotated_bounds;
 | 
					    EekBounds bounds, rotated_bounds;
 | 
				
			||||||
    gint angle;
 | 
					 | 
				
			||||||
    gdouble s;
 | 
					    gdouble s;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    eek_renderer_get_button_bounds (self, place, &bounds, FALSE);
 | 
					    eek_renderer_get_button_bounds (self, place, &bounds, FALSE);
 | 
				
			||||||
    eek_renderer_get_button_bounds (self, place, &rotated_bounds, TRUE);
 | 
					    eek_renderer_get_button_bounds (self, place, &rotated_bounds, TRUE);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    angle = eek_section_get_angle (place->section);
 | 
					    gint angle = squeek_row_get_angle (place->row);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    cairo_scale (cr, scale, scale);
 | 
					    cairo_scale (cr, scale, scale);
 | 
				
			||||||
    if (rotate) {
 | 
					    if (rotate) {
 | 
				
			||||||
@ -771,13 +768,13 @@ 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);
 | 
				
			||||||
    EekBounds section_bounds = eek_section_get_bounds (place->section);
 | 
					    EekBounds row_bounds = squeek_row_get_bounds (place->row);
 | 
				
			||||||
    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);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (!rotate) {
 | 
					    if (!rotate) {
 | 
				
			||||||
        button_bounds.x += keyboard_bounds.x + section_bounds.x;
 | 
					        button_bounds.x += keyboard_bounds.x + row_bounds.x;
 | 
				
			||||||
        button_bounds.y += keyboard_bounds.y + section_bounds.y;
 | 
					        button_bounds.y += keyboard_bounds.y + row_bounds.y;
 | 
				
			||||||
        *bounds = button_bounds;
 | 
					        *bounds = button_bounds;
 | 
				
			||||||
        return;
 | 
					        return;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@ -790,8 +787,9 @@ eek_renderer_get_button_bounds (EekRenderer *renderer,
 | 
				
			|||||||
    points[3].x = points[0].x;
 | 
					    points[3].x = points[0].x;
 | 
				
			||||||
    points[3].y = points[2].y;
 | 
					    points[3].y = points[2].y;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (rotate)
 | 
					    if (rotate) {
 | 
				
			||||||
        angle = eek_section_get_angle (place->section);
 | 
					        angle = squeek_row_get_angle (place->row);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    min = points[2];
 | 
					    min = points[2];
 | 
				
			||||||
    max = points[0];
 | 
					    max = points[0];
 | 
				
			||||||
@ -806,8 +804,8 @@ eek_renderer_get_button_bounds (EekRenderer *renderer,
 | 
				
			|||||||
        if (points[i].y > max.y)
 | 
					        if (points[i].y > max.y)
 | 
				
			||||||
            max.y = points[i].y;
 | 
					            max.y = points[i].y;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    bounds->x = keyboard_bounds.x + section_bounds.x + min.x;
 | 
					    bounds->x = keyboard_bounds.x + row_bounds.x + min.x;
 | 
				
			||||||
    bounds->y = keyboard_bounds.y + section_bounds.y + min.y;
 | 
					    bounds->y = keyboard_bounds.y + row_bounds.y + min.y;
 | 
				
			||||||
    bounds->width = (max.x - min.x);
 | 
					    bounds->width = (max.x - min.x);
 | 
				
			||||||
    bounds->height = (max.y - min.y);
 | 
					    bounds->height = (max.y - min.y);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@ -1021,23 +1019,25 @@ find_button_by_position_key_callback (struct squeek_button *button,
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static gint
 | 
					static void
 | 
				
			||||||
find_button_by_position_section_callback (EekElement *element,
 | 
					find_button_by_position_row_callback (gpointer item,
 | 
				
			||||||
                                       gpointer user_data)
 | 
					                                       gpointer user_data)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    EekSection *section = EEK_SECTION(element);
 | 
					    struct squeek_row *row = item;
 | 
				
			||||||
    FindKeyByPositionCallbackData *data = user_data;
 | 
					    FindKeyByPositionCallbackData *data = user_data;
 | 
				
			||||||
    EekBounds bounds = eek_section_get_bounds(section);
 | 
					    if (data->button) {
 | 
				
			||||||
 | 
					        return;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    EekBounds bounds = squeek_row_get_bounds(row);
 | 
				
			||||||
    EekPoint origin;
 | 
					    EekPoint origin;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    origin = data->origin;
 | 
					    origin = data->origin;
 | 
				
			||||||
    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(section);
 | 
					    data->angle = squeek_row_get_angle(row);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    eek_section_foreach(section, find_button_by_position_key_callback, data);
 | 
					    squeek_row_foreach(row, find_button_by_position_key_callback, data);
 | 
				
			||||||
    data->origin = origin;
 | 
					    data->origin = origin;
 | 
				
			||||||
    return data->button ? 0 : -1;
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
@ -1080,8 +1080,7 @@ eek_renderer_find_button_by_position (EekRenderer *renderer,
 | 
				
			|||||||
    data.button = NULL;
 | 
					    data.button = NULL;
 | 
				
			||||||
    data.renderer = renderer;
 | 
					    data.renderer = renderer;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    eek_container_find (EEK_CONTAINER(view),
 | 
					    eek_keyboard_foreach (view, find_button_by_position_row_callback,
 | 
				
			||||||
                        find_button_by_position_section_callback,
 | 
					 | 
				
			||||||
                        &data);
 | 
					                        &data);
 | 
				
			||||||
    return data.button;
 | 
					    return data.button;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -208,18 +208,17 @@ EekBounds eek_section_get_bounds(EekSection *section) {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void
 | 
					void
 | 
				
			||||||
eek_section_place_keys(EekSection *section, LevelKeyboard *keyboard)
 | 
					eek_row_place_buttons(struct squeek_row *row, LevelKeyboard *keyboard)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    EekSectionPrivate *priv = eek_section_get_instance_private (section);
 | 
					    EekBounds row_size = squeek_row_place_keys(row, keyboard);
 | 
				
			||||||
    EekBounds section_size = squeek_row_place_keys(priv->row, keyboard);
 | 
					    EekBounds row_bounds = squeek_row_get_bounds(row);
 | 
				
			||||||
    EekBounds section_bounds = eek_section_get_bounds(section);
 | 
					    // FIXME: do centering of each row 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;
 | 
					    row_bounds.x = (row_bounds.width - row_size.width) / 2;
 | 
				
			||||||
    section_bounds.width = section_size.width;
 | 
					    row_bounds.width = row_size.width;
 | 
				
			||||||
    section_bounds.height = section_size.height;
 | 
					    row_bounds.height = row_size.height;
 | 
				
			||||||
    eek_section_set_bounds(section, section_bounds);
 | 
					    squeek_row_set_bounds(row, row_bounds);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void eek_section_foreach (EekSection *section,
 | 
					void eek_section_foreach (EekSection *section,
 | 
				
			||||||
 | 
				
			|||||||
@ -73,7 +73,8 @@ struct squeek_button *eek_section_create_button (EekSection     *section,
 | 
				
			|||||||
struct squeek_button *eek_section_create_button_with_state(EekSection *self,
 | 
					struct squeek_button *eek_section_create_button_with_state(EekSection *self,
 | 
				
			||||||
                                  const gchar *name,
 | 
					                                  const gchar *name,
 | 
				
			||||||
                                    struct squeek_button *source);
 | 
					                                    struct squeek_button *source);
 | 
				
			||||||
void eek_section_place_keys              (EekSection     *section, LevelKeyboard *keyboard);
 | 
					void
 | 
				
			||||||
 | 
					eek_row_place_buttons(struct squeek_row *row, LevelKeyboard *keyboard);
 | 
				
			||||||
void eek_section_foreach (EekSection *section,
 | 
					void eek_section_foreach (EekSection *section,
 | 
				
			||||||
                     ButtonCallback func,
 | 
					                     ButtonCallback func,
 | 
				
			||||||
                     gpointer   user_data);
 | 
					                     gpointer   user_data);
 | 
				
			||||||
 | 
				
			|||||||
@ -234,7 +234,6 @@ struct _GeometryParseData {
 | 
				
			|||||||
    EekBounds bounds;
 | 
					    EekBounds bounds;
 | 
				
			||||||
    EekKeyboard **views;
 | 
					    EekKeyboard **views;
 | 
				
			||||||
    guint view_idx;
 | 
					    guint view_idx;
 | 
				
			||||||
    EekSection *section;
 | 
					 | 
				
			||||||
    struct squeek_row *row;
 | 
					    struct squeek_row *row;
 | 
				
			||||||
    gint num_rows;
 | 
					    gint num_rows;
 | 
				
			||||||
    EekOrientation orientation;
 | 
					    EekOrientation orientation;
 | 
				
			||||||
@ -375,12 +374,7 @@ geometry_start_element_callback (GMarkupParseContext *pcontext,
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (g_strcmp0 (element_name, "section") == 0) {
 | 
					    if (g_strcmp0 (element_name, "section") == 0) {
 | 
				
			||||||
        data->section = eek_keyboard_real_create_section (data->views[data->view_idx]);
 | 
					        data->row = eek_keyboard_real_create_row(data->views[data->view_idx]);
 | 
				
			||||||
        data->row = eek_section_get_row(data->section);
 | 
					 | 
				
			||||||
        attribute = get_attribute (attribute_names, attribute_values,
 | 
					 | 
				
			||||||
                                   "id");
 | 
					 | 
				
			||||||
        if (attribute != NULL)
 | 
					 | 
				
			||||||
            eek_element_set_name (EEK_ELEMENT(data->section), attribute);
 | 
					 | 
				
			||||||
        attribute = get_attribute (attribute_names, attribute_values,
 | 
					        attribute = get_attribute (attribute_names, attribute_values,
 | 
				
			||||||
                                   "angle");
 | 
					                                   "angle");
 | 
				
			||||||
        if (attribute != NULL) {
 | 
					        if (attribute != NULL) {
 | 
				
			||||||
@ -584,7 +578,6 @@ geometry_end_element_callback (GMarkupParseContext *pcontext,
 | 
				
			|||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        data->section = NULL;
 | 
					 | 
				
			||||||
        data->row = NULL;
 | 
					        data->row = NULL;
 | 
				
			||||||
        data->num_rows = 0;
 | 
					        data->num_rows = 0;
 | 
				
			||||||
        return;
 | 
					        return;
 | 
				
			||||||
@ -939,7 +932,7 @@ eek_xml_layout_real_create_keyboard (EekLayout *self,
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    for (uint i = 0; i < 4; i++) {
 | 
					    for (uint i = 0; i < 4; i++) {
 | 
				
			||||||
        if (views[i]) {
 | 
					        if (views[i]) {
 | 
				
			||||||
            eek_layout_place_sections(keyboard, views[i]);
 | 
					            eek_layout_place_rows(keyboard, views[i]);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -127,7 +127,6 @@ pub mod c {
 | 
				
			|||||||
        row.bounds = Some(bounds);
 | 
					        row.bounds = Some(bounds);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    
 | 
					 | 
				
			||||||
    #[no_mangle]
 | 
					    #[no_mangle]
 | 
				
			||||||
    pub extern "C"
 | 
					    pub extern "C"
 | 
				
			||||||
    fn squeek_row_contains(
 | 
					    fn squeek_row_contains(
 | 
				
			||||||
 | 
				
			|||||||
@ -25,13 +25,10 @@ static void
 | 
				
			|||||||
test_create (void)
 | 
					test_create (void)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    EekKeyboard *keyboard;
 | 
					    EekKeyboard *keyboard;
 | 
				
			||||||
    EekSection *section;
 | 
					 | 
				
			||||||
    struct squeek_button *button0, *button1;
 | 
					    struct squeek_button *button0, *button1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    keyboard = g_object_new (EEK_TYPE_KEYBOARD, NULL);
 | 
					    keyboard = g_object_new (EEK_TYPE_KEYBOARD, NULL);
 | 
				
			||||||
    section = eek_keyboard_real_create_section (keyboard);
 | 
					    struct squeek_row *row = eek_keyboard_real_create_row (keyboard);
 | 
				
			||||||
    g_assert (EEK_IS_SECTION(section));
 | 
					 | 
				
			||||||
    struct squeek_row *row = eek_section_get_row(section);
 | 
					 | 
				
			||||||
    g_assert (row);
 | 
					    g_assert (row);
 | 
				
			||||||
    button0 = squeek_row_create_button (row, 1, 0);
 | 
					    button0 = squeek_row_create_button (row, 1, 0);
 | 
				
			||||||
    g_assert (button0);
 | 
					    g_assert (button0);
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user