diff options
-rw-r--r-- | src/canvas.c | 98 | ||||
-rw-r--r-- | src/canvas.h | 59 | ||||
-rw-r--r-- | src/document.h | 91 | ||||
-rw-r--r-- | src/symbol-category.h | 4 | ||||
-rw-r--r-- | src/symbol-library.c | 68 | ||||
-rw-r--r-- | src/symbol.h | 12 | ||||
-rw-r--r-- | src/window-main.c | 18 |
7 files changed, 339 insertions, 11 deletions
diff --git a/src/canvas.c b/src/canvas.c index 7febdb3..0168639 100644 --- a/src/canvas.c +++ b/src/canvas.c @@ -1 +1,99 @@ +/* + * canvas.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 "canvas.h" +#include "document.h" + /* http://www.gnomejournal.org/article/34/writing-a-widget-using-cairo-and-gtk28 */ + +/** + * SECTION:canvas + * @short_description: A canvas. + * @see_also: #LogdiagDocument + * + * #LogdiagCanvas is used for displaying #LogdiagDocument objects. + */ + +/* + * LogdiagCanvasPrivate: + * @document: A document object assigned to this canvas as a model. + */ +struct _LogdiagCanvasPrivate +{ + LogdiagDocument *document; +}; + +G_DEFINE_TYPE (LogdiagCanvas, logdiag_canvas, GTK_TYPE_DRAWING_AREA); + +static void +logdiag_canvas_finalize (GObject *gobject); + + +static void +logdiag_canvas_class_init (LogdiagCanvasClass *klass) +{ + GObjectClass *object_class; + GtkWidgetClass *widget_class; + + object_class = G_OBJECT_CLASS (klass); + object_class->finalize = logdiag_canvas_finalize; + + widget_class = GTK_WIDGET_CLASS (klass); + +/** + * LogdiagCanvas::set-scroll-adjustments: + * @canvas: The canvas object. + * + * Contents of the library have changed. + */ +/* + widget_class->set_scroll_adjustments_signal = g_signal_new + ("set-scroll-adjustments", G_TYPE_FROM_CLASS (widget_class), + G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, + 0, // G_STRUCT_OFFSET (LogdiagCanvasClass, ...) + NULL, NULL, + gtk_marshal_NONE__POINTER_POINTER, + G_TYPE_NONE, 2, GTK_TYPE_ADJUSTMENT, GTK_TYPE_ADJUSTMENT); +*/ + g_type_class_add_private (klass, sizeof (LogdiagCanvasPrivate)); +} + +static void +logdiag_canvas_init (LogdiagCanvas *self) +{ + self->priv = G_TYPE_INSTANCE_GET_PRIVATE + (self, LOGDIAG_TYPE_CANVAS, LogdiagCanvasPrivate); +} + +static void +logdiag_canvas_finalize (GObject *gobject) +{ + LogdiagCanvas *self; + + self = LOGDIAG_CANVAS (gobject); + + /* Chain up to the parent class. */ + G_OBJECT_CLASS (logdiag_canvas_parent_class)->finalize (gobject); +} + +/** + * logdiag_canvas_new: + * + * Create an instance. + */ +LogdiagCanvas * +logdiag_canvas_new (void) +{ + return g_object_new (LOGDIAG_TYPE_CANVAS, NULL); +} diff --git a/src/canvas.h b/src/canvas.h index e69de29..be3539a 100644 --- a/src/canvas.h +++ b/src/canvas.h @@ -0,0 +1,59 @@ +/* + * canvas.h + * + * This file is a part of logdiag. + * Copyright Přemysl Janouch 2010. All rights reserved. + * + * See the file LICENSE for licensing information. + * + */ + +#ifndef __CANVAS_H__ +#define __CANVAS_H__ + +G_BEGIN_DECLS + + +#define LOGDIAG_TYPE_CANVAS (logdiag_canvas_get_type ()) +#define LOGDIAG_CANVAS(obj) (G_TYPE_CHECK_INSTANCE_CAST \ + ((obj), LOGDIAG_TYPE_CANVAS, LogdiagCanvas)) +#define LOGDIAG_CANVAS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST \ + ((klass), LOGDIAG_TYPE_CANVAS, LogdiagCanvasClass)) +#define LOGDIAG_IS_CANVAS(obj) (G_TYPE_CHECK_INSTANCE_TYPE \ + ((obj), LOGDIAG_TYPE_CANVAS)) +#define LOGDIAG_IS_CANVAS_CLASS(klass) (G_TYPE_CHECK_INSTANCE_TYPE \ + ((klass), LOGDIAG_TYPE_CANVAS)) +#define LOGDIAG_CANVAS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS \ + ((obj), LOGDIAG_CANVAS, LogdiagCanvasClass)) + +typedef struct _LogdiagCanvas LogdiagCanvas; +typedef struct _LogdiagCanvasPrivate LogdiagCanvasPrivate; +typedef struct _LogdiagCanvasClass LogdiagCanvasClass; + + +/** + * LogdiagCanvas: + */ +struct _LogdiagCanvas +{ +/*< private >*/ + GtkDrawingArea parent_instance; + LogdiagCanvasPrivate *priv; + +/*< public >*/ +}; + +struct _LogdiagCanvasClass +{ + GtkDrawingAreaClass parent_class; +}; + + +GType logdiag_canvas_get_type (void) G_GNUC_CONST; + +LogdiagCanvas *logdiag_canvas_new (void); + + +G_END_DECLS + +#endif /* ! __CANVAS_H__ */ diff --git a/src/document.h b/src/document.h index e69de29..198d8f8 100644 --- a/src/document.h +++ b/src/document.h @@ -0,0 +1,91 @@ +/* + * document.h + * + * This file is a part of logdiag. + * Copyright Přemysl Janouch 2010. All rights reserved. + * + * See the file LICENSE for licensing information. + * + */ + +#ifndef __DOCUMENT_H__ +#define __DOCUMENT_H__ + +G_BEGIN_DECLS + + +#define LOGDIAG_TYPE_DOCUMENT (logdiag_symbol_library_get_type ()) +#define LOGDIAG_DOCUMENT(obj) (G_TYPE_CHECK_INSTANCE_CAST \ + ((obj), LOGDIAG_TYPE_DOCUMENT, LogdiagDocument)) +#define LOGDIAG_DOCUMENT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST \ + ((klass), LOGDIAG_TYPE_DOCUMENT, LogdiagDocumentClass)) +#define LOGDIAG_IS_DOCUMENT(obj) (G_TYPE_CHECK_INSTANCE_TYPE \ + ((obj), LOGDIAG_TYPE_DOCUMENT)) +#define LOGDIAG_IS_DOCUMENT_CLASS(klass) (G_TYPE_CHECK_INSTANCE_TYPE \ + ((klass), LOGDIAG_TYPE_DOCUMENT)) +#define LOGDIAG_DOCUMENT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS \ + ((obj), LOGDIAG_DOCUMENT, LogdiagDocumentClass)) + +typedef struct _LogdiagDocument LogdiagDocument; +/*typedef struct _LogdiagDocumentPrivate LogdiagDocumentPrivate;*/ +typedef struct _LogdiagDocumentClass LogdiagDocumentClass; + + +/** + * LogdiagDocument: + */ +struct _LogdiagDocument +{ +/*< private >*/ + GObject parent_instance; + +/*< public >*/ +}; + +struct _LogdiagDocumentClass +{ + GObjectClass parent_class; +}; + + +GType logdiag_document_get_type (void) G_GNUC_CONST; + +LogdiagDocument *logdiag_document_new (void); +gboolean logdiag_document_new_from_file (const char *file_name, GError *error); +gboolean logdiag_document_save_to_file (const char *file_name, GError *error); + +#if 0 +/* + * LogdiagDocumentPrivate: + * @objects: All the objects in the document. + */ +struct _LogdiagDocumentPrivate +{ + GSList *objects; +}; + +/** The contents of the document have changed. */ +signal documentChanged (...); + +/* TODO: A list of objects: */ +LogdiagDocumentSymbol +LogdiagDocumentLabel + +logdiag_document_add_symbol (LogdiagSymbol *symbol, x, y); + +/* XXX: Separated lists of objects + * or a single list for all objects? + */ +/* TODO: Wires. */ +logdiag_document_selection_... +logdiag_document_selection_get_json (LogdiagDocument *self); +logdiag_document_insert_json (LogdiagDocument *self); +/** Go back or forward in the history of changes. */ +/* TODO: An interface that informs about the history. */ +logdiag_document_history_go (LogdiagDocument *self); +#endif /* 0 */ + + +G_END_DECLS + +#endif /* ! __DOCUMENT_H__ */ diff --git a/src/symbol-category.h b/src/symbol-category.h index e6b1b75..51ccb78 100644 --- a/src/symbol-category.h +++ b/src/symbol-category.h @@ -35,7 +35,7 @@ typedef struct _LogdiagSymbolCategoryClass LogdiagSymbolCategoryClass; * @parent: The parent object, may be LogdiagSymbolLibrary * or another LogdiagSymbolCategory. * @name: The name of the category. - * @image_path: Path to the image of the category. + * @image_path: Path to the image for this category. * @children: Children of this category. */ struct _LogdiagSymbolCategory @@ -52,7 +52,7 @@ struct _LogdiagSymbolCategory struct _LogdiagSymbolCategoryClass { - GtkObjectClass parent_class; + GObjectClass parent_class; }; diff --git a/src/symbol-library.c b/src/symbol-library.c index 869e3f2..679a068 100644 --- a/src/symbol-library.c +++ b/src/symbol-library.c @@ -177,6 +177,7 @@ logdiag_symbol_library_load (LogdiagSymbolLibrary *self, const char *path) /** * logdiag_symbol_library_clear: + * @self: A symbol library object. * * Clears all the contents. */ @@ -246,6 +247,7 @@ logdiag_symbol_category_finalize (GObject *gobject) /** * logdiag_symbol_category_new: + * @parent: The parent library for this category. * * Create an instance. */ @@ -276,16 +278,72 @@ logdiag_symbol_category_new (LogdiagSymbolLibrary *parent) /* * LogdiagSymbolPrivate: - * @parent_library: The parent LogdiagSymbolLibrary. + * @library: The parent LogdiagSymbolLibrary. * The library contains the real function for rendering. */ struct _LogdiagSymbolPrivate { - LogdiagSymbolLibrary *parent_library; + LogdiagSymbolLibrary *library; }; +G_DEFINE_TYPE (LogdiagSymbol, logdiag_symbol, G_TYPE_OBJECT); + +static void +logdiag_symbol_finalize (GObject *gobject); + + +static void +logdiag_symbol_class_init (LogdiagSymbolClass *klass) +{ + GObjectClass *object_class; + + object_class = G_OBJECT_CLASS (klass); + object_class->finalize = logdiag_symbol_finalize; + + g_type_class_add_private (klass, sizeof (LogdiagSymbolPrivate)); +} + +static void +logdiag_symbol_init (LogdiagSymbol *self) +{ + self->priv = G_TYPE_INSTANCE_GET_PRIVATE + (self, LOGDIAG_TYPE_SYMBOL_LIBRARY, LogdiagSymbolPrivate); +} + +static void +logdiag_symbol_finalize (GObject *gobject) +{ + LogdiagSymbol *self; + + self = LOGDIAG_SYMBOL (gobject); + g_object_unref (self->priv->library); + + /* Chain up to the parent class. */ + G_OBJECT_CLASS (logdiag_symbol_parent_class)->finalize (gobject); +} + +/** + * logdiag_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. + */ +LogdiagSymbol *logdiag_symbol_new (LogdiagSymbolLibrary *library, + const gchar *filename) +{ + LogdiagSymbol *symbol; + + symbol = g_object_new (LOGDIAG_TYPE_SYMBOL, NULL); + /* TODO: Use the filename, Luke. */ + + symbol->priv->library = library; + g_object_ref (library); +} + /** * logdiag_symbol_build_identifier: + * @self: A symbol object. * * Build an identifier for the symbol. * The identifier is in the format "Category/Category/Symbol". @@ -298,6 +356,12 @@ logdiag_symbol_build_identifier (LogdiagSymbol *self) /** * logdiag_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. */ diff --git a/src/symbol.h b/src/symbol.h index c8f851f..046786a 100644 --- a/src/symbol.h +++ b/src/symbol.h @@ -27,34 +27,34 @@ G_BEGIN_DECLS ((obj), LOGDIAG_SYMBOL, LogdiagSymbolClass)) typedef struct _LogdiagSymbol LogdiagSymbol; -/*typedef struct _LogdiagSymbolPrivate LogdiagSymbolPrivate;*/ +typedef struct _LogdiagSymbolPrivate LogdiagSymbolPrivate; typedef struct _LogdiagSymbolClass LogdiagSymbolClass; /** * LogdiagSymbol: - * @parent: The parent category. * @name: The name of this symbol. */ struct _LogdiagSymbol { /*< private >*/ GObject parent_instance; -/* LogdiagSymbolPrivate *priv;*/ + LogdiagSymbolPrivate *priv; /*< public >*/ - LogdiagSymbolCategory *parent; - char *name; + gchar *name; }; struct _LogdiagSymbolClass { - GtkObjectClass parent_class; + GObjectClass parent_class; }; GType logdiag_symbol_get_type (void) G_GNUC_CONST; +LogdiagSymbol *logdiag_symbol_new (LogdiagSymbolLibrary *library, + const gchar *filename); char *logdiag_symbol_build_identifier (LogdiagSymbol *self); void logdiag_symbol_draw (LogdiagSymbol *self, cairo_t *surface, GHashTable *param, gint x, gint y, gdouble zoom); diff --git a/src/window-main.c b/src/window-main.c index 43ce429..89714a5 100644 --- a/src/window-main.c +++ b/src/window-main.c @@ -13,8 +13,11 @@ #include "config.h" #include "window-main.h" +#include "canvas.h" +#include "document.h" #include "symbol-library.h" #include "symbol-category.h" +#include "symbol.h" /** @@ -37,11 +40,19 @@ struct _LogdiagWindowMainPrivate GtkWidget *toolbar; LogdiagSymbolLibrary *library; + LogdiagCanvas *canvas; GtkWidget *statusbar; guint statusbar_menu_context_id; }; +struct DocumentData +{ + LogdiagDocument *document; + const gchar *file_name; + /* Canvas viewport settings (for multitabbed) */ +}; + /* Define the type. */ G_DEFINE_TYPE (LogdiagWindowMain, logdiag_window_main, GTK_TYPE_WINDOW); @@ -219,6 +230,11 @@ logdiag_window_main_init (LogdiagWindowMain *self) load_toolbar (self); + /* Canvas. */ + priv->canvas = logdiag_canvas_new (); + gtk_box_pack_start (GTK_BOX (priv->hbox), GTK_WIDGET (priv->canvas), + FALSE, FALSE, 0); + /* TODO: GtkHPaned */ priv->statusbar = gtk_statusbar_new (); @@ -227,7 +243,7 @@ logdiag_window_main_init (LogdiagWindowMain *self) gtk_box_pack_end (GTK_BOX (priv->vbox), priv->statusbar, FALSE, FALSE, 0); - /* Do this on disposal. */ + /* TODO: Do this on disposal. */ /* g_object_unref(ui_manager); */ /* Proceed to showing the window. */ |