Move EekSymbolMatrix code from eek-types.[ch] to eek-symbol-matrix.[ch].
This commit is contained in:
@ -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 \
|
||||
|
||||
@ -20,9 +20,8 @@
|
||||
#ifndef EEK_KEY_H
|
||||
#define EEK_KEY_H 1
|
||||
|
||||
#include <glib-object.h>
|
||||
#include "eek-element.h"
|
||||
#include "eek-types.h"
|
||||
#include "eek-symbol-matrix.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
|
||||
105
eek/eek-symbol-matrix.c
Normal file
105
eek/eek-symbol-matrix.c
Normal file
@ -0,0 +1,105 @@
|
||||
/*
|
||||
* Copyright (C) 2011 Daiki Ueno <ueno@unixuser.org>
|
||||
* 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];
|
||||
}
|
||||
60
eek/eek-symbol-matrix.h
Normal file
60
eek/eek-symbol-matrix.h
Normal file
@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright (C) 2011 Daiki Ueno <ueno@unixuser.org>
|
||||
* 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 */
|
||||
@ -20,7 +20,6 @@
|
||||
#ifndef EEK_SYMBOL_H
|
||||
#define EEK_SYMBOL_H 1
|
||||
|
||||
#include <glib-object.h>
|
||||
#include "eek-types.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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
|
||||
|
||||
Reference in New Issue
Block a user