Split ld-symbol-library.c.
Originally, there were three object classes defined in this file. It would later become rather chaotic if left that way.
This commit is contained in:
parent
f675a7c07c
commit
f250621519
|
@ -88,6 +88,8 @@ set (logdiag_SOURCES
|
||||||
src/ld-window-main.c
|
src/ld-window-main.c
|
||||||
src/ld-document.c
|
src/ld-document.c
|
||||||
src/ld-canvas.c
|
src/ld-canvas.c
|
||||||
|
src/ld-symbol.c
|
||||||
|
src/ld-symbol-category.c
|
||||||
src/ld-symbol-library.c)
|
src/ld-symbol-library.c)
|
||||||
set (logdiag_HEADERS
|
set (logdiag_HEADERS
|
||||||
${CMAKE_CURRENT_BINARY_DIR}/config.h
|
${CMAKE_CURRENT_BINARY_DIR}/config.h
|
||||||
|
|
|
@ -0,0 +1,90 @@
|
||||||
|
/*
|
||||||
|
* ld-symbol-category.c
|
||||||
|
*
|
||||||
|
* This file is a part of logdiag.
|
||||||
|
* Copyright Přemysl Janouch 2010. All rights reserved.
|
||||||
|
*
|
||||||
|
* See the file LICENSE for licensing information.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <gtk/gtk.h>
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
|
#include "ld-symbol-library.h"
|
||||||
|
#include "ld-symbol-category.h"
|
||||||
|
#include "ld-symbol.h"
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SECTION:ld-symbol-category
|
||||||
|
* @short_description: A category of symbols.
|
||||||
|
* @see_also: #LdSymbol, #LdSymbolLibrary
|
||||||
|
*
|
||||||
|
* #LdSymbolCategory represents a category of #LdSymbol objects.
|
||||||
|
*/
|
||||||
|
|
||||||
|
G_DEFINE_TYPE (LdSymbolCategory, ld_symbol_category, G_TYPE_OBJECT);
|
||||||
|
|
||||||
|
static void
|
||||||
|
ld_symbol_category_finalize (GObject *gobject);
|
||||||
|
|
||||||
|
|
||||||
|
static void
|
||||||
|
ld_symbol_category_class_init (LdSymbolCategoryClass *klass)
|
||||||
|
{
|
||||||
|
GObjectClass *object_class;
|
||||||
|
|
||||||
|
object_class = G_OBJECT_CLASS (klass);
|
||||||
|
object_class->finalize = ld_symbol_category_finalize;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
ld_symbol_category_init (LdSymbolCategory *self)
|
||||||
|
{
|
||||||
|
/* TODO: use _new_full, correct equal and specify destroy functions. */
|
||||||
|
/* XXX: How's the situation with subcategory names and symbol names
|
||||||
|
* within the same hashtable?
|
||||||
|
*/
|
||||||
|
self->children = g_hash_table_new (g_str_hash, g_str_equal);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
ld_symbol_category_finalize (GObject *gobject)
|
||||||
|
{
|
||||||
|
LdSymbolCategory *self;
|
||||||
|
|
||||||
|
self = LD_SYMBOL_CATEGORY (gobject);
|
||||||
|
|
||||||
|
if (self->name)
|
||||||
|
g_free (self->name);
|
||||||
|
if (self->image_path)
|
||||||
|
g_free (self->image_path);
|
||||||
|
|
||||||
|
g_object_unref (self->parent);
|
||||||
|
g_hash_table_destroy (self->children);
|
||||||
|
|
||||||
|
/* Chain up to the parent class. */
|
||||||
|
G_OBJECT_CLASS (ld_symbol_category_parent_class)->finalize (gobject);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ld_symbol_category_new:
|
||||||
|
* @parent: The parent library for this category.
|
||||||
|
*
|
||||||
|
* Create an instance.
|
||||||
|
*/
|
||||||
|
LdSymbolCategory *
|
||||||
|
ld_symbol_category_new (LdSymbolLibrary *parent)
|
||||||
|
{
|
||||||
|
LdSymbolCategory *cat;
|
||||||
|
|
||||||
|
cat = g_object_new (LD_TYPE_SYMBOL_CATEGORY, NULL);
|
||||||
|
|
||||||
|
cat->parent = parent;
|
||||||
|
g_object_ref (parent);
|
||||||
|
|
||||||
|
return cat;
|
||||||
|
}
|
||||||
|
|
|
@ -32,8 +32,8 @@ typedef struct _LdSymbolCategoryClass LdSymbolCategoryClass;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* LdSymbolCategory:
|
* LdSymbolCategory:
|
||||||
* @parent: The parent object, may be LdSymbolLibrary
|
* @parent: The parent object, may be #LdSymbolLibrary
|
||||||
* or another LdSymbolCategory.
|
* or another #LdSymbolCategory.
|
||||||
* @name: The name of the category.
|
* @name: The name of the category.
|
||||||
* @image_path: Path to the image for this category.
|
* @image_path: Path to the image for this category.
|
||||||
* @children: Children of this category.
|
* @children: Children of this category.
|
||||||
|
|
|
@ -18,7 +18,6 @@
|
||||||
#include "ld-symbol-category.h"
|
#include "ld-symbol-category.h"
|
||||||
#include "ld-symbol.h"
|
#include "ld-symbol.h"
|
||||||
|
|
||||||
/* ===== Symbol library ==================================================== */
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SECTION:ld-symbol-library
|
* SECTION:ld-symbol-library
|
||||||
|
@ -190,184 +189,3 @@ ld_symbol_library_clear (LdSymbolLibrary *self)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* ===== Symbol category =================================================== */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* SECTION:ld-symbol-category
|
|
||||||
* @short_description: A category of symbols.
|
|
||||||
* @see_also: #LdSymbol, #LdSymbolLibrary
|
|
||||||
*
|
|
||||||
* #LdSymbolCategory represents a category of #LdSymbol objects.
|
|
||||||
*/
|
|
||||||
|
|
||||||
G_DEFINE_TYPE (LdSymbolCategory, ld_symbol_category, G_TYPE_OBJECT);
|
|
||||||
|
|
||||||
static void
|
|
||||||
ld_symbol_category_finalize (GObject *gobject);
|
|
||||||
|
|
||||||
|
|
||||||
static void
|
|
||||||
ld_symbol_category_class_init (LdSymbolCategoryClass *klass)
|
|
||||||
{
|
|
||||||
GObjectClass *object_class;
|
|
||||||
|
|
||||||
object_class = G_OBJECT_CLASS (klass);
|
|
||||||
object_class->finalize = ld_symbol_category_finalize;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
ld_symbol_category_init (LdSymbolCategory *self)
|
|
||||||
{
|
|
||||||
/* TODO: use _new_full, correct equal and specify destroy functions. */
|
|
||||||
/* XXX: How's the situation with subcategory names and symbol names
|
|
||||||
* within the same hashtable?
|
|
||||||
*/
|
|
||||||
self->children = g_hash_table_new (g_str_hash, g_str_equal);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
ld_symbol_category_finalize (GObject *gobject)
|
|
||||||
{
|
|
||||||
LdSymbolCategory *self;
|
|
||||||
|
|
||||||
self = LD_SYMBOL_CATEGORY (gobject);
|
|
||||||
|
|
||||||
if (self->name)
|
|
||||||
g_free (self->name);
|
|
||||||
if (self->image_path)
|
|
||||||
g_free (self->image_path);
|
|
||||||
|
|
||||||
g_object_unref (self->parent);
|
|
||||||
g_hash_table_destroy (self->children);
|
|
||||||
|
|
||||||
/* Chain up to the parent class. */
|
|
||||||
G_OBJECT_CLASS (ld_symbol_category_parent_class)->finalize (gobject);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* ld_symbol_category_new:
|
|
||||||
* @parent: The parent library for this category.
|
|
||||||
*
|
|
||||||
* Create an instance.
|
|
||||||
*/
|
|
||||||
LdSymbolCategory *
|
|
||||||
ld_symbol_category_new (LdSymbolLibrary *parent)
|
|
||||||
{
|
|
||||||
LdSymbolCategory *cat;
|
|
||||||
|
|
||||||
cat = g_object_new (LD_TYPE_SYMBOL_CATEGORY, NULL);
|
|
||||||
|
|
||||||
cat->parent = parent;
|
|
||||||
g_object_ref (parent);
|
|
||||||
|
|
||||||
return cat;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* ===== Symbol ============================================================ */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* SECTION:ld-symbol
|
|
||||||
* @short_description: A symbol.
|
|
||||||
* @see_also: #LdDocument, #LdCanvas
|
|
||||||
*
|
|
||||||
* #LdSymbol represents a symbol in the #LdDocument that is in turn
|
|
||||||
* drawn onto the #LdCanvas.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
* LdSymbolPrivate:
|
|
||||||
* @library: The parent LdSymbolLibrary.
|
|
||||||
* The library contains the real function for rendering.
|
|
||||||
*/
|
|
||||||
struct _LdSymbolPrivate
|
|
||||||
{
|
|
||||||
LdSymbolLibrary *library;
|
|
||||||
};
|
|
||||||
|
|
||||||
G_DEFINE_TYPE (LdSymbol, ld_symbol, G_TYPE_OBJECT);
|
|
||||||
|
|
||||||
static void
|
|
||||||
ld_symbol_finalize (GObject *gobject);
|
|
||||||
|
|
||||||
|
|
||||||
static void
|
|
||||||
ld_symbol_class_init (LdSymbolClass *klass)
|
|
||||||
{
|
|
||||||
GObjectClass *object_class;
|
|
||||||
|
|
||||||
object_class = G_OBJECT_CLASS (klass);
|
|
||||||
object_class->finalize = ld_symbol_finalize;
|
|
||||||
|
|
||||||
g_type_class_add_private (klass, sizeof (LdSymbolPrivate));
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
ld_symbol_init (LdSymbol *self)
|
|
||||||
{
|
|
||||||
self->priv = G_TYPE_INSTANCE_GET_PRIVATE
|
|
||||||
(self, LD_TYPE_SYMBOL_LIBRARY, LdSymbolPrivate);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
ld_symbol_finalize (GObject *gobject)
|
|
||||||
{
|
|
||||||
LdSymbol *self;
|
|
||||||
|
|
||||||
self = LD_SYMBOL (gobject);
|
|
||||||
g_object_unref (self->priv->library);
|
|
||||||
|
|
||||||
/* Chain up to the parent class. */
|
|
||||||
G_OBJECT_CLASS (ld_symbol_parent_class)->finalize (gobject);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* ld_symbol_new:
|
|
||||||
* @library: A library object.
|
|
||||||
* @filename: The file from which the symbol will be loaded.
|
|
||||||
*
|
|
||||||
* Load a symbol from a file into the library.
|
|
||||||
*/
|
|
||||||
LdSymbol *ld_symbol_new (LdSymbolLibrary *library,
|
|
||||||
const gchar *filename)
|
|
||||||
{
|
|
||||||
LdSymbol *symbol;
|
|
||||||
|
|
||||||
symbol = g_object_new (LD_TYPE_SYMBOL, NULL);
|
|
||||||
/* TODO: Use the filename, Luke. */
|
|
||||||
|
|
||||||
symbol->priv->library = library;
|
|
||||||
g_object_ref (library);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* ld_symbol_build_identifier:
|
|
||||||
* @self: A symbol object.
|
|
||||||
*
|
|
||||||
* Build an identifier for the symbol.
|
|
||||||
* The identifier is in the format "Category/Category/Symbol".
|
|
||||||
*/
|
|
||||||
char *
|
|
||||||
ld_symbol_build_identifier (LdSymbol *self)
|
|
||||||
{
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* ld_symbol_draw:
|
|
||||||
* @self: A symbol object.
|
|
||||||
* @surface: A cairo surface to be drawn on.
|
|
||||||
* @param: Parameters for the symbol in a table.
|
|
||||||
* @x: The X coordinate on the surface.
|
|
||||||
* @y: The Y coordinate on the surface.
|
|
||||||
* @zoom: Zoom ratio.
|
|
||||||
*
|
|
||||||
* Draw the symbol onto a Cairo surface.
|
|
||||||
*/
|
|
||||||
void
|
|
||||||
ld_symbol_draw (LdSymbol *self, cairo_t *surface,
|
|
||||||
GHashTable *param, gint x, gint y, gdouble zoom)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
|
@ -0,0 +1,123 @@
|
||||||
|
/*
|
||||||
|
* ld-symbol.c
|
||||||
|
*
|
||||||
|
* This file is a part of logdiag.
|
||||||
|
* Copyright Přemysl Janouch 2010. All rights reserved.
|
||||||
|
*
|
||||||
|
* See the file LICENSE for licensing information.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <gtk/gtk.h>
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
|
#include "ld-symbol-library.h"
|
||||||
|
#include "ld-symbol-category.h"
|
||||||
|
#include "ld-symbol.h"
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SECTION:ld-symbol
|
||||||
|
* @short_description: A symbol.
|
||||||
|
* @see_also: #LdDocument, #LdCanvas
|
||||||
|
*
|
||||||
|
* #LdSymbol represents a symbol in the #LdDocument that is in turn
|
||||||
|
* drawn onto the #LdCanvas.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* LdSymbolPrivate:
|
||||||
|
* @library: The parent LdSymbolLibrary.
|
||||||
|
* The library contains the real function for rendering.
|
||||||
|
*/
|
||||||
|
struct _LdSymbolPrivate
|
||||||
|
{
|
||||||
|
LdSymbolLibrary *library;
|
||||||
|
};
|
||||||
|
|
||||||
|
G_DEFINE_TYPE (LdSymbol, ld_symbol, G_TYPE_OBJECT);
|
||||||
|
|
||||||
|
static void
|
||||||
|
ld_symbol_finalize (GObject *gobject);
|
||||||
|
|
||||||
|
|
||||||
|
static void
|
||||||
|
ld_symbol_class_init (LdSymbolClass *klass)
|
||||||
|
{
|
||||||
|
GObjectClass *object_class;
|
||||||
|
|
||||||
|
object_class = G_OBJECT_CLASS (klass);
|
||||||
|
object_class->finalize = ld_symbol_finalize;
|
||||||
|
|
||||||
|
g_type_class_add_private (klass, sizeof (LdSymbolPrivate));
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
ld_symbol_init (LdSymbol *self)
|
||||||
|
{
|
||||||
|
self->priv = G_TYPE_INSTANCE_GET_PRIVATE
|
||||||
|
(self, LD_TYPE_SYMBOL_LIBRARY, LdSymbolPrivate);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
ld_symbol_finalize (GObject *gobject)
|
||||||
|
{
|
||||||
|
LdSymbol *self;
|
||||||
|
|
||||||
|
self = LD_SYMBOL (gobject);
|
||||||
|
g_object_unref (self->priv->library);
|
||||||
|
|
||||||
|
/* Chain up to the parent class. */
|
||||||
|
G_OBJECT_CLASS (ld_symbol_parent_class)->finalize (gobject);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ld_symbol_new:
|
||||||
|
* @library: A library object.
|
||||||
|
* @filename: The file from which the symbol will be loaded.
|
||||||
|
*
|
||||||
|
* Load a symbol from a file into the library.
|
||||||
|
*/
|
||||||
|
LdSymbol *ld_symbol_new (LdSymbolLibrary *library,
|
||||||
|
const gchar *filename)
|
||||||
|
{
|
||||||
|
LdSymbol *symbol;
|
||||||
|
|
||||||
|
symbol = g_object_new (LD_TYPE_SYMBOL, NULL);
|
||||||
|
/* TODO: Use the filename, Luke. */
|
||||||
|
|
||||||
|
symbol->priv->library = library;
|
||||||
|
g_object_ref (library);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ld_symbol_build_identifier:
|
||||||
|
* @self: A symbol object.
|
||||||
|
*
|
||||||
|
* Build an identifier for the symbol.
|
||||||
|
* The identifier is in the format "Category/Category/Symbol".
|
||||||
|
*/
|
||||||
|
char *
|
||||||
|
ld_symbol_build_identifier (LdSymbol *self)
|
||||||
|
{
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ld_symbol_draw:
|
||||||
|
* @self: A symbol object.
|
||||||
|
* @surface: A cairo surface to be drawn on.
|
||||||
|
* @param: Parameters for the symbol in a table.
|
||||||
|
* @x: The X coordinate on the surface.
|
||||||
|
* @y: The Y coordinate on the surface.
|
||||||
|
* @zoom: Zoom ratio.
|
||||||
|
*
|
||||||
|
* Draw the symbol onto a Cairo surface.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
ld_symbol_draw (LdSymbol *self, cairo_t *surface,
|
||||||
|
GHashTable *param, gint x, gint y, gdouble zoom)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
Loading…
Reference in New Issue