section: Move properties into Row
This commit is contained in:
@ -1,17 +1,17 @@
|
||||
/*
|
||||
/*
|
||||
* Copyright (C) 2010-2011 Daiki Ueno <ueno@unixuser.org>
|
||||
* Copyright (C) 2010-2011 Red Hat, Inc.
|
||||
*
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public License
|
||||
* as published by the Free Software Foundation; either version 2 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
@ -432,9 +432,9 @@ EekKeyboard *level_keyboard_current(LevelKeyboard *keyboard)
|
||||
}
|
||||
|
||||
struct GetSectionData {
|
||||
const struct squeek_button *button;
|
||||
struct squeek_button *button;
|
||||
EekSection *section;
|
||||
const struct squeek_key *needle;
|
||||
struct squeek_key *needle;
|
||||
};
|
||||
|
||||
void find_button_in_section(EekElement *element, gpointer user_data) {
|
||||
@ -449,7 +449,7 @@ void find_button_in_section(EekElement *element, gpointer user_data) {
|
||||
}
|
||||
|
||||
EekSection *eek_keyboard_get_section(EekKeyboard *keyboard,
|
||||
const struct squeek_button *button) {
|
||||
struct squeek_button *button) {
|
||||
struct GetSectionData data = {
|
||||
.button = button,
|
||||
.section = NULL,
|
||||
@ -473,7 +473,7 @@ void find_key_in_section(EekElement *element, gpointer user_data) {
|
||||
|
||||
// TODO: return multiple
|
||||
struct button_place eek_keyboard_get_button_by_state(EekKeyboard *keyboard,
|
||||
const struct squeek_key *key) {
|
||||
struct squeek_key *key) {
|
||||
struct GetSectionData data = {
|
||||
.section = NULL,
|
||||
.button = NULL,
|
||||
@ -482,7 +482,7 @@ struct button_place eek_keyboard_get_button_by_state(EekKeyboard *keyboard,
|
||||
eek_container_foreach_child(EEK_CONTAINER(keyboard), find_key_in_section, &data);
|
||||
struct button_place ret = {
|
||||
.section = data.section,
|
||||
.button = (struct squeek_button*)data.button,
|
||||
.button = data.button,
|
||||
};
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -158,7 +158,7 @@ EekSection *eek_keyboard_create_section
|
||||
(EekKeyboard *keyboard);
|
||||
EekSection *eek_keyboard_get_section
|
||||
(EekKeyboard *keyboard,
|
||||
const struct squeek_button *button);
|
||||
struct squeek_button *button);
|
||||
struct squeek_button *eek_keyboard_find_button_by_name(LevelKeyboard *keyboard,
|
||||
const gchar *name);
|
||||
|
||||
@ -169,7 +169,7 @@ struct button_place {
|
||||
};
|
||||
|
||||
struct button_place eek_keyboard_get_button_by_state(EekKeyboard *keyboard,
|
||||
const struct squeek_key *key);
|
||||
struct squeek_key *key);
|
||||
|
||||
EekOutline *level_keyboard_get_outline
|
||||
(LevelKeyboard *keyboard,
|
||||
@ -196,5 +196,9 @@ void level_keyboard_free(LevelKeyboard *self);
|
||||
EekSection *
|
||||
eek_keyboard_real_create_section (EekKeyboard *self);
|
||||
|
||||
struct squeek_row *
|
||||
eek_keyboard_real_create_row (EekKeyboard *self);
|
||||
|
||||
|
||||
G_END_DECLS
|
||||
#endif /* EEK_KEYBOARD_H */
|
||||
|
||||
@ -93,10 +93,9 @@ struct _CreateKeyboardSurfaceCallbackData {
|
||||
typedef struct _CreateKeyboardSurfaceCallbackData CreateKeyboardSurfaceCallbackData;
|
||||
|
||||
static void
|
||||
create_keyboard_surface_button_callback (gpointer item,
|
||||
create_keyboard_surface_button_callback (struct squeek_button *button,
|
||||
gpointer user_data)
|
||||
{
|
||||
struct squeek_button *button = item;
|
||||
CreateKeyboardSurfaceCallbackData *data = user_data;
|
||||
EekBounds bounds = squeek_button_get_bounds(button);
|
||||
|
||||
@ -978,10 +977,9 @@ sign (EekPoint *p1, EekPoint *p2, EekPoint *p3)
|
||||
}
|
||||
|
||||
static void
|
||||
find_button_by_position_key_callback (gpointer item,
|
||||
find_button_by_position_key_callback (struct squeek_button *button,
|
||||
gpointer user_data)
|
||||
{
|
||||
struct squeek_button *button = item;
|
||||
FindKeyByPositionCallbackData *data = user_data;
|
||||
if (data->button) {
|
||||
return;
|
||||
|
||||
@ -44,36 +44,11 @@ enum {
|
||||
|
||||
typedef struct _EekSectionPrivate
|
||||
{
|
||||
gint angle;
|
||||
EekModifierType modifiers;
|
||||
GPtrArray *buttons; // struct squeek_button*
|
||||
struct squeek_row *row;
|
||||
} EekSectionPrivate;
|
||||
|
||||
G_DEFINE_TYPE_WITH_PRIVATE (EekSection, eek_section, EEK_TYPE_ELEMENT)
|
||||
|
||||
struct squeek_button*
|
||||
eek_section_create_button (EekSection *self,
|
||||
const gchar *name,
|
||||
guint keycode,
|
||||
guint oref)
|
||||
{
|
||||
struct squeek_button *button = squeek_button_new(keycode, oref);
|
||||
g_return_val_if_fail (button, NULL);
|
||||
EekSectionPrivate *priv = eek_section_get_instance_private (self);
|
||||
g_ptr_array_add(priv->buttons, button);
|
||||
return button;
|
||||
}
|
||||
|
||||
struct squeek_button *eek_section_create_button_with_state(EekSection *self,
|
||||
const gchar *name,
|
||||
struct squeek_button *source) {
|
||||
struct squeek_button *button = squeek_button_new_with_state(source);
|
||||
g_return_val_if_fail (button, NULL);
|
||||
EekSectionPrivate *priv = eek_section_get_instance_private (self);
|
||||
g_ptr_array_add(priv->buttons, button);
|
||||
return button;
|
||||
}
|
||||
|
||||
static void
|
||||
eek_section_finalize (GObject *object)
|
||||
{
|
||||
@ -143,7 +118,7 @@ static void
|
||||
eek_section_init (EekSection *self)
|
||||
{
|
||||
EekSectionPrivate *priv = eek_section_get_instance_private (self);
|
||||
priv->buttons = g_ptr_array_new();
|
||||
priv->row = squeek_row_new(0);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -161,10 +136,7 @@ eek_section_set_angle (EekSection *section,
|
||||
|
||||
EekSectionPrivate *priv = eek_section_get_instance_private (section);
|
||||
|
||||
if (priv->angle != angle) {
|
||||
priv->angle = angle;
|
||||
g_object_notify (G_OBJECT(section), "angle");
|
||||
}
|
||||
squeek_row_set_angle(priv->row, angle);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -180,7 +152,16 @@ eek_section_get_angle (EekSection *section)
|
||||
|
||||
EekSectionPrivate *priv = eek_section_get_instance_private (section);
|
||||
|
||||
return priv->angle;
|
||||
return squeek_row_get_angle(priv->row);
|
||||
}
|
||||
|
||||
struct squeek_row *
|
||||
eek_section_get_row (EekSection *section)
|
||||
{
|
||||
g_return_val_if_fail (EEK_IS_SECTION(section), NULL);
|
||||
|
||||
EekSectionPrivate *priv = eek_section_get_instance_private (section);
|
||||
return priv->row;
|
||||
}
|
||||
|
||||
const double keyspacing = 4.0;
|
||||
@ -191,14 +172,7 @@ struct keys_info {
|
||||
double biggest_height;
|
||||
};
|
||||
|
||||
/// Set button size to match the outline. Reset position
|
||||
static void
|
||||
buttonsizer(gpointer item, gpointer user_data)
|
||||
{
|
||||
struct squeek_button *button = item;
|
||||
|
||||
LevelKeyboard *keyboard = user_data;
|
||||
uint oref = squeek_button_get_oref(button);
|
||||
EekBounds eek_get_outline_size(LevelKeyboard *keyboard, uint32_t oref) {
|
||||
EekOutline *outline = level_keyboard_get_outline (keyboard, oref);
|
||||
if (outline && outline->num_points > 0) {
|
||||
double minx = outline->points[0].x;
|
||||
@ -225,81 +199,47 @@ buttonsizer(gpointer item, gpointer user_data)
|
||||
.x = 0,
|
||||
.y = 0,
|
||||
};
|
||||
squeek_button_set_bounds(button, key_bounds);
|
||||
return key_bounds;
|
||||
}
|
||||
EekBounds bounds = {0, 0, 0, 0};
|
||||
return bounds;
|
||||
}
|
||||
|
||||
static void
|
||||
buttoncounter (gpointer item, gpointer user_data)
|
||||
{
|
||||
struct squeek_button *button = item;
|
||||
struct keys_info *data = user_data;
|
||||
data->count++;
|
||||
EekBounds key_bounds = squeek_button_get_bounds(button);
|
||||
data->total_width += key_bounds.width;
|
||||
if (key_bounds.height > data->biggest_height) {
|
||||
data->biggest_height = key_bounds.height;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
buttonplacer(gpointer item, gpointer user_data)
|
||||
{
|
||||
struct squeek_button *button = item;
|
||||
double *current_offset = user_data;
|
||||
EekBounds key_bounds = squeek_button_get_bounds(button);
|
||||
key_bounds.x = *current_offset;
|
||||
key_bounds.y = 0;
|
||||
squeek_button_set_bounds(button, key_bounds);
|
||||
*current_offset += key_bounds.width + keyspacing;
|
||||
void eek_section_set_bounds(EekSection *section, EekBounds bounds) {
|
||||
eek_element_set_bounds(EEK_ELEMENT(section), &bounds);
|
||||
}
|
||||
|
||||
void
|
||||
eek_section_place_keys(EekSection *section, LevelKeyboard *keyboard)
|
||||
{
|
||||
EekSectionPrivate *priv = eek_section_get_instance_private (section);
|
||||
|
||||
g_ptr_array_foreach(priv->buttons, buttonsizer, keyboard);
|
||||
|
||||
struct keys_info keyinfo = {0};
|
||||
g_ptr_array_foreach(priv->buttons, buttoncounter, &keyinfo);
|
||||
|
||||
EekBounds section_size = squeek_row_place_keys(priv->row, keyboard);
|
||||
EekBounds section_bounds = {0};
|
||||
eek_element_get_bounds(EEK_ELEMENT(section), §ion_bounds);
|
||||
|
||||
double key_offset = (section_bounds.width - (keyinfo.total_width + (keyinfo.count - 1) * keyspacing)) / 2;
|
||||
g_ptr_array_foreach(priv->buttons, buttonplacer, &key_offset);
|
||||
|
||||
section_bounds.height = keyinfo.biggest_height;
|
||||
// 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);
|
||||
}
|
||||
|
||||
void eek_section_foreach (EekSection *section,
|
||||
GFunc func,
|
||||
ButtonCallback func,
|
||||
gpointer user_data) {
|
||||
EekSectionPrivate *priv = eek_section_get_instance_private (section);
|
||||
g_ptr_array_foreach(priv->buttons, func, user_data);
|
||||
squeek_row_foreach(priv->row, func, user_data);
|
||||
}
|
||||
|
||||
gboolean eek_section_find(EekSection *section,
|
||||
const struct squeek_button *button) {
|
||||
struct squeek_button *button) {
|
||||
EekSectionPrivate *priv = eek_section_get_instance_private (section);
|
||||
return g_ptr_array_find(priv->buttons, button, NULL);
|
||||
}
|
||||
|
||||
static gboolean button_has_key(gconstpointer buttonptr, gconstpointer keyptr) {
|
||||
const struct squeek_button *button = buttonptr;
|
||||
const struct squeek_key *key = keyptr;
|
||||
return squeek_button_has_key((struct squeek_button*)button, key) != 0;
|
||||
return squeek_row_contains(priv->row, button) != 0;
|
||||
}
|
||||
|
||||
struct squeek_button *eek_section_find_key(EekSection *section,
|
||||
const struct squeek_key *key) {
|
||||
struct squeek_key *key) {
|
||||
EekSectionPrivate *priv = eek_section_get_instance_private (section);
|
||||
guint index;
|
||||
gboolean ret = g_ptr_array_find_with_equal_func(priv->buttons, key, button_has_key, &index);
|
||||
if (ret) {
|
||||
return g_ptr_array_index(priv->buttons, index);
|
||||
}
|
||||
return NULL;// TODO: store keys in locked_keys, pressed_keys
|
||||
return squeek_row_find_key(priv->row, key);
|
||||
}
|
||||
|
||||
@ -64,6 +64,8 @@ GType eek_section_get_type (void) G_GNUC_CONST;
|
||||
void eek_section_set_angle (EekSection *section,
|
||||
gint angle);
|
||||
gint eek_section_get_angle (EekSection *section);
|
||||
struct squeek_row *
|
||||
eek_section_get_row (EekSection *section);
|
||||
|
||||
struct squeek_button *eek_section_create_button (EekSection *section,
|
||||
const gchar *name,
|
||||
@ -73,13 +75,13 @@ struct squeek_button *eek_section_create_button_with_state(EekSection *self,
|
||||
struct squeek_button *source);
|
||||
void eek_section_place_keys (EekSection *section, LevelKeyboard *keyboard);
|
||||
void eek_section_foreach (EekSection *section,
|
||||
GFunc func,
|
||||
ButtonCallback func,
|
||||
gpointer user_data);
|
||||
|
||||
gboolean eek_section_find(EekSection *section,
|
||||
const struct squeek_button *button);
|
||||
struct squeek_button *button);
|
||||
|
||||
struct squeek_button *eek_section_find_key(EekSection *section,
|
||||
const struct squeek_key *key);
|
||||
struct squeek_key *key);
|
||||
G_END_DECLS
|
||||
#endif /* EEK_SECTION_H */
|
||||
|
||||
@ -235,6 +235,7 @@ struct _GeometryParseData {
|
||||
EekKeyboard **views;
|
||||
guint view_idx;
|
||||
EekSection *section;
|
||||
struct squeek_row *row;
|
||||
gint num_rows;
|
||||
EekOrientation orientation;
|
||||
gdouble corner_radius;
|
||||
@ -375,6 +376,7 @@ geometry_start_element_callback (GMarkupParseContext *pcontext,
|
||||
|
||||
if (g_strcmp0 (element_name, "section") == 0) {
|
||||
data->section = eek_keyboard_real_create_section (data->views[data->view_idx]);
|
||||
data->row = eek_section_get_row(data->section);
|
||||
attribute = get_attribute (attribute_names, attribute_values,
|
||||
"id");
|
||||
if (attribute != NULL)
|
||||
@ -384,7 +386,7 @@ geometry_start_element_callback (GMarkupParseContext *pcontext,
|
||||
if (attribute != NULL) {
|
||||
gint angle;
|
||||
angle = strtol (attribute, NULL, 10);
|
||||
eek_section_set_angle (data->section, angle);
|
||||
squeek_row_set_angle (data->row, angle);
|
||||
}
|
||||
|
||||
goto out;
|
||||
@ -566,15 +568,12 @@ geometry_end_element_callback (GMarkupParseContext *pcontext,
|
||||
|
||||
guint oref = GPOINTER_TO_UINT(g_hash_table_lookup(data->keyname_oref_hash, name));
|
||||
// default value gives idx 0, which is guaranteed to be occupied
|
||||
button = eek_section_create_button (data->section,
|
||||
name,
|
||||
keycode,
|
||||
oref);
|
||||
button = squeek_row_create_button (data->row, keycode, oref);
|
||||
g_hash_table_insert (data->name_button_hash,
|
||||
g_strdup(name),
|
||||
button);
|
||||
} else {
|
||||
struct squeek_button *new_button = eek_section_create_button_with_state(data->section, name, button);
|
||||
struct squeek_button *new_button = squeek_row_create_button_with_state(data->row, button);
|
||||
if (!new_button) {
|
||||
g_set_error (error,
|
||||
G_MARKUP_ERROR,
|
||||
@ -586,6 +585,7 @@ geometry_end_element_callback (GMarkupParseContext *pcontext,
|
||||
}
|
||||
|
||||
data->section = NULL;
|
||||
data->row = NULL;
|
||||
data->num_rows = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user