diff --git a/eek/Makefile.am b/eek/Makefile.am index 1966dc7b..2f554893 100644 --- a/eek/Makefile.am +++ b/eek/Makefile.am @@ -35,6 +35,7 @@ libeek_public_headers = \ $(srcdir)/eek-key.h \ $(srcdir)/eek-symbol.h \ $(srcdir)/eek-keysym.h \ + $(srcdir)/eek-symbol-matrix.h \ $(srcdir)/eek-types.h \ $(srcdir)/eek-xml.h \ $(srcdir)/eek-xml-layout.h \ @@ -59,6 +60,7 @@ libeek_sources = \ $(srcdir)/eek-keyboard.c \ $(srcdir)/eek-section.c \ $(srcdir)/eek-key.c \ + $(srcdir)/eek-symbol-matrix.c \ $(srcdir)/eek-symbol.c \ $(srcdir)/eek-keysym.c \ $(srcdir)/eek-types.c \ diff --git a/eek/eek-key.h b/eek/eek-key.h index 45952a40..3724cbaf 100644 --- a/eek/eek-key.h +++ b/eek/eek-key.h @@ -20,9 +20,8 @@ #ifndef EEK_KEY_H #define EEK_KEY_H 1 -#include #include "eek-element.h" -#include "eek-types.h" +#include "eek-symbol-matrix.h" G_BEGIN_DECLS diff --git a/eek/eek-symbol-matrix.c b/eek/eek-symbol-matrix.c new file mode 100644 index 00000000..63e0e524 --- /dev/null +++ b/eek/eek-symbol-matrix.c @@ -0,0 +1,105 @@ +/* + * Copyright (C) 2011 Daiki Ueno + * Copyright (C) 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 + * 02110-1301 USA + */ +#include "eek-symbol-matrix.h" + +EekSymbolMatrix * +eek_symbol_matrix_new (gint num_groups, + gint num_levels) +{ + EekSymbolMatrix *matrix = g_slice_new (EekSymbolMatrix); + + matrix->num_groups = num_groups; + matrix->num_levels = num_levels; + matrix->data = g_slice_alloc0 (sizeof (EekSymbol *) * + num_groups * num_levels); + return matrix; +} + +EekSymbolMatrix * +eek_symbol_matrix_copy (const EekSymbolMatrix *matrix) +{ + EekSymbolMatrix *retval; + gint i, num_symbols = matrix->num_groups * matrix->num_levels; + + retval = g_slice_dup (EekSymbolMatrix, matrix); + retval->data = g_slice_copy (sizeof (EekSymbol *) * num_symbols, + matrix->data); + for (i = 0; i < num_symbols; i++) + if (retval->data[i]) + g_object_ref (retval->data[i]); + return retval; +} + +void +eek_symbol_matrix_free (EekSymbolMatrix *matrix) +{ + gint i, num_symbols = matrix->num_groups * matrix->num_levels; + for (i = 0; i < num_symbols; i++) + if (matrix->data[i]) + g_object_unref (matrix->data[i]); + g_slice_free1 (sizeof (EekSymbol *) * num_symbols, matrix->data); + g_slice_free (EekSymbolMatrix, matrix); +} + +GType +eek_symbol_matrix_get_type (void) +{ + static GType our_type = 0; + + if (our_type == 0) + our_type = + g_boxed_type_register_static ("EekSymbolMatrix", + (GBoxedCopyFunc)eek_symbol_matrix_copy, + (GBoxedFreeFunc)eek_symbol_matrix_free); + return our_type; +} + +void +eek_symbol_matrix_set_symbol (EekSymbolMatrix *matrix, + gint group, + gint level, + EekSymbol *symbol) +{ + g_return_if_fail (group >= 0 && group < matrix->num_groups); + g_return_if_fail (level >= 0 && level < matrix->num_levels); + g_return_if_fail (EEK_IS_SYMBOL(symbol)); + matrix->data[group * matrix->num_levels + level] = g_object_ref (symbol); +} + +/** + * eek_symbol_matrix_get_symbol: + * @matrix: an #EekSymbolMatrix + * @group: group index of @matrix + * @level: level index of @matrix + * + * Get an #EekSymbol stored in the cell selected by (@group, @level) + * in @matrix. + * + * Return value: (transfer none): an #EekSymbol. + */ +EekSymbol * +eek_symbol_matrix_get_symbol (EekSymbolMatrix *matrix, + gint group, + gint level) +{ + g_return_val_if_fail (group >= 0 && group < matrix->num_groups, NULL); + g_return_val_if_fail (level >= 0 && level < matrix->num_levels, NULL); + return matrix->data[group * matrix->num_levels + level]; +} diff --git a/eek/eek-symbol-matrix.h b/eek/eek-symbol-matrix.h new file mode 100644 index 00000000..badef2be --- /dev/null +++ b/eek/eek-symbol-matrix.h @@ -0,0 +1,60 @@ +/* + * Copyright (C) 2011 Daiki Ueno + * Copyright (C) 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 + * 02110-1301 USA + */ +#ifndef EEK_SYMBOL_MATRIX_H +#define EEK_SYMBOL_MATRIX_H 1 + +#include "eek-symbol.h" + +G_BEGIN_DECLS + +/** + * EekSymbolMatrix: + * @data: array of symbols + * @num_groups: the number of groups (rows) + * @num_levels: the number of levels (columns) + * + * Symbol matrix of a key. + */ +struct _EekSymbolMatrix +{ + gint num_groups; + gint num_levels; + EekSymbol **data; +}; + +GType eek_symbol_matrix_get_type (void) G_GNUC_CONST; +EekSymbolMatrix *eek_symbol_matrix_new (gint num_groups, + gint num_levels); +EekSymbolMatrix *eek_symbol_matrix_copy (const EekSymbolMatrix *matrix); +void eek_symbol_matrix_free (EekSymbolMatrix *matrix); + +void eek_symbol_matrix_set_symbol + (EekSymbolMatrix *matrix, + gint group, + gint level, + EekSymbol *symbol); +EekSymbol *eek_symbol_matrix_get_symbol + (EekSymbolMatrix *matrix, + gint group, + gint level); + +G_END_DECLS + +#endif /* EEK_SYMBOL_MATRIX_H */ diff --git a/eek/eek-symbol.h b/eek/eek-symbol.h index 5ff4d852..7af49d7e 100644 --- a/eek/eek-symbol.h +++ b/eek/eek-symbol.h @@ -20,7 +20,6 @@ #ifndef EEK_SYMBOL_H #define EEK_SYMBOL_H 1 -#include #include "eek-types.h" G_BEGIN_DECLS diff --git a/eek/eek-types.c b/eek/eek-types.c index 9a1e9987..16355b63 100644 --- a/eek/eek-types.c +++ b/eek/eek-types.c @@ -32,58 +32,6 @@ #include "eek-types.h" -/* EekSymbolMatrix */ -EekSymbolMatrix * -eek_symbol_matrix_new (gint num_groups, gint num_levels) -{ - EekSymbolMatrix *matrix = g_slice_new (EekSymbolMatrix); - - matrix->num_groups = num_groups; - matrix->num_levels = num_levels; - matrix->data = g_slice_alloc0 (sizeof (EekSymbol *) * - num_groups * num_levels); - return matrix; -} - -EekSymbolMatrix * -eek_symbol_matrix_copy (const EekSymbolMatrix *matrix) -{ - EekSymbolMatrix *retval; - gint i, num_symbols = matrix->num_groups * matrix->num_levels; - - retval = g_slice_dup (EekSymbolMatrix, matrix); - retval->data = g_slice_copy (sizeof (EekSymbol *) * num_symbols, - matrix->data); - for (i = 0; i < num_symbols; i++) - if (retval->data[i]) - g_object_ref (retval->data[i]); - return retval; -} - -void -eek_symbol_matrix_free (EekSymbolMatrix *matrix) -{ - gint i, num_symbols = matrix->num_groups * matrix->num_levels; - for (i = 0; i < num_symbols; i++) - if (matrix->data[i]) - g_object_unref (matrix->data[i]); - g_slice_free1 (sizeof (EekSymbol *) * num_symbols, matrix->data); - g_slice_free (EekSymbolMatrix, matrix); -} - -GType -eek_symbol_matrix_get_type (void) -{ - static GType our_type = 0; - - if (our_type == 0) - our_type = - g_boxed_type_register_static ("EekSymbolMatrix", - (GBoxedCopyFunc)eek_symbol_matrix_copy, - (GBoxedFreeFunc)eek_symbol_matrix_free); - return our_type; -} - /* EekPoint */ static EekPoint * eek_point_copy (const EekPoint *point) diff --git a/eek/eek-types.h b/eek/eek-types.h index c60b9ad3..61cb7694 100644 --- a/eek/eek-types.h +++ b/eek/eek-types.h @@ -146,28 +146,6 @@ typedef struct _EekBounds EekBounds; typedef struct _EekOutline EekOutline; typedef struct _EekColor EekColor; -/** - * EekSymbolMatrix: - * @data: array of symbols - * @num_groups: the number of groups (rows) - * @num_levels: the number of levels (columns) - * - * Symbol matrix of a key. - */ -struct _EekSymbolMatrix -{ - gint num_groups; - gint num_levels; - EekSymbol **data; -}; - -GType eek_symbol_matrix_get_type - (void) G_GNUC_CONST; -EekSymbolMatrix * eek_symbol_matrix_new (gint num_groups, - gint num_levels); -EekSymbolMatrix *eek_symbol_matrix_copy (const EekSymbolMatrix *matrix); -void eek_symbol_matrix_free (EekSymbolMatrix *matrix); - /** * EekPoint: * @x: X coordinate of the point