Introduce LdRectangle, LdPoint and LdPointArray.
Remove LdCanvasRect and LdSymbolArea.
This commit is contained in:
parent
0b3f6503bb
commit
96f7710c25
@ -82,6 +82,7 @@ set (project_DOC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/docs/reference")
|
||||
set (logdiag_SOURCES
|
||||
src/logdiag.c
|
||||
src/ld-marshal.c
|
||||
src/ld-types.c
|
||||
src/ld-window-main.c
|
||||
src/ld-diagram.c
|
||||
src/ld-diagram-object.c
|
||||
@ -95,6 +96,7 @@ set (logdiag_SOURCES
|
||||
set (logdiag_HEADERS
|
||||
${CMAKE_CURRENT_BINARY_DIR}/config.h
|
||||
src/ld-marshal.h
|
||||
src/ld-types.h
|
||||
src/ld-window-main.h
|
||||
src/ld-diagram.h
|
||||
src/ld-diagram-object.h
|
||||
|
@ -15,6 +15,7 @@
|
||||
#include "config.h"
|
||||
|
||||
#include "ld-marshal.h"
|
||||
#include "ld-types.h"
|
||||
#include "ld-diagram-object.h"
|
||||
#include "ld-diagram-symbol.h"
|
||||
#include "ld-diagram.h"
|
||||
@ -83,8 +84,6 @@ struct _LdCanvasColor
|
||||
gdouble a;
|
||||
};
|
||||
|
||||
typedef cairo_rectangle_t LdCanvasRect;
|
||||
|
||||
/*
|
||||
* LdCanvasPrivate:
|
||||
* @diagram: A diagram object assigned to this canvas as a model.
|
||||
@ -138,7 +137,7 @@ struct _DrawData
|
||||
{
|
||||
LdCanvas *self;
|
||||
cairo_t *cr;
|
||||
LdCanvasRect exposed_rect;
|
||||
LdRectangle exposed_rect;
|
||||
gdouble scale;
|
||||
};
|
||||
|
||||
@ -181,12 +180,6 @@ static void ld_canvas_color_set (LdCanvasColor *color,
|
||||
gdouble r, gdouble g, gdouble b, gdouble a);
|
||||
static void ld_canvas_color_apply (LdCanvasColor *color, cairo_t *cr);
|
||||
|
||||
static gboolean ld_canvas_rect_contains (LdCanvasRect *rect,
|
||||
gdouble x, gdouble y);
|
||||
static gboolean ld_canvas_rect_intersects (LdCanvasRect *first,
|
||||
LdCanvasRect *second);
|
||||
static void ld_canvas_rect_extend (LdCanvasRect *rect, gdouble border);
|
||||
|
||||
static void move_object_to_coords (LdCanvas *self, LdDiagramObject *object,
|
||||
gdouble x, gdouble y);
|
||||
static LdDiagramObject *get_object_at_coords (LdCanvas *self,
|
||||
@ -195,11 +188,11 @@ static gboolean is_object_selected (LdCanvas *self, LdDiagramObject *object);
|
||||
static LdSymbol *resolve_diagram_symbol (LdCanvas *self,
|
||||
LdDiagramSymbol *diagram_symbol);
|
||||
static gboolean get_symbol_area (LdCanvas *self, LdDiagramSymbol *symbol,
|
||||
LdCanvasRect *rect);
|
||||
LdRectangle *rect);
|
||||
static gboolean get_symbol_clip_area (LdCanvas *self, LdDiagramSymbol *symbol,
|
||||
LdCanvasRect *rect);
|
||||
LdRectangle *rect);
|
||||
static gboolean get_object_area (LdCanvas *self, LdDiagramObject *object,
|
||||
LdCanvasRect *rect);
|
||||
LdRectangle *rect);
|
||||
static gboolean object_hit_test (LdCanvas *self, LdDiagramObject *object,
|
||||
gdouble x, gdouble y);
|
||||
static void queue_object_redraw (LdCanvas *self, LdDiagramObject *object);
|
||||
@ -792,37 +785,6 @@ ld_canvas_color_apply (LdCanvasColor *color, cairo_t *cr)
|
||||
cairo_set_source_rgba (cr, color->r, color->g, color->b, color->a);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
ld_canvas_rect_contains (LdCanvasRect *rect, gdouble x, gdouble y)
|
||||
{
|
||||
g_return_val_if_fail (rect != NULL, FALSE);
|
||||
return (x >= rect->x && x <= rect->x + rect->width
|
||||
&& y >= rect->y && y <= rect->y + rect->height);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
ld_canvas_rect_intersects (LdCanvasRect *first, LdCanvasRect *second)
|
||||
{
|
||||
g_return_val_if_fail (first != NULL, FALSE);
|
||||
g_return_val_if_fail (second != NULL, FALSE);
|
||||
|
||||
return !(first->x > second->x + second->width
|
||||
|| first->y > second->y + second->height
|
||||
|| first->x + first->width < second->x
|
||||
|| first->y + first->height < second->y);
|
||||
}
|
||||
|
||||
static void
|
||||
ld_canvas_rect_extend (LdCanvasRect *rect, gdouble border)
|
||||
{
|
||||
g_return_if_fail (rect != NULL);
|
||||
|
||||
rect->x -= border;
|
||||
rect->y -= border;
|
||||
rect->width += 2 * border;
|
||||
rect->height += 2 * border;
|
||||
}
|
||||
|
||||
static void
|
||||
move_object_to_coords (LdCanvas *self, LdDiagramObject *object,
|
||||
gdouble x, gdouble y)
|
||||
@ -870,12 +832,12 @@ resolve_diagram_symbol (LdCanvas *self, LdDiagramSymbol *diagram_symbol)
|
||||
}
|
||||
|
||||
static gboolean
|
||||
get_symbol_area (LdCanvas *self, LdDiagramSymbol *symbol, LdCanvasRect *rect)
|
||||
get_symbol_area (LdCanvas *self, LdDiagramSymbol *symbol, LdRectangle *rect)
|
||||
{
|
||||
LdDiagramObject *object;
|
||||
gdouble object_x, object_y;
|
||||
LdSymbol *library_symbol;
|
||||
LdSymbolArea area;
|
||||
LdRectangle area;
|
||||
gdouble x1, x2;
|
||||
gdouble y1, y2;
|
||||
|
||||
@ -908,20 +870,20 @@ get_symbol_area (LdCanvas *self, LdDiagramSymbol *symbol, LdCanvasRect *rect)
|
||||
|
||||
static gboolean
|
||||
get_symbol_clip_area (LdCanvas *self, LdDiagramSymbol *symbol,
|
||||
LdCanvasRect *rect)
|
||||
LdRectangle *rect)
|
||||
{
|
||||
LdCanvasRect object_rect;
|
||||
LdRectangle object_rect;
|
||||
|
||||
if (!get_object_area (self, LD_DIAGRAM_OBJECT (symbol), &object_rect))
|
||||
return FALSE;
|
||||
|
||||
*rect = object_rect;
|
||||
ld_canvas_rect_extend (rect, SYMBOL_CLIP_TOLERANCE);
|
||||
ld_rectangle_extend (rect, SYMBOL_CLIP_TOLERANCE);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
get_object_area (LdCanvas *self, LdDiagramObject *object, LdCanvasRect *rect)
|
||||
get_object_area (LdCanvas *self, LdDiagramObject *object, LdRectangle *rect)
|
||||
{
|
||||
if (LD_IS_DIAGRAM_SYMBOL (object))
|
||||
return get_symbol_area (self, LD_DIAGRAM_SYMBOL (object), rect);
|
||||
@ -931,12 +893,12 @@ get_object_area (LdCanvas *self, LdDiagramObject *object, LdCanvasRect *rect)
|
||||
static gboolean
|
||||
object_hit_test (LdCanvas *self, LdDiagramObject *object, gdouble x, gdouble y)
|
||||
{
|
||||
LdCanvasRect rect;
|
||||
LdRectangle rect;
|
||||
|
||||
if (!get_object_area (self, object, &rect))
|
||||
return FALSE;
|
||||
ld_canvas_rect_extend (&rect, OBJECT_BORDER_TOLERANCE);
|
||||
return ld_canvas_rect_contains (&rect, x, y);
|
||||
ld_rectangle_extend (&rect, OBJECT_BORDER_TOLERANCE);
|
||||
return ld_rectangle_contains (&rect, x, y);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -944,7 +906,7 @@ queue_object_redraw (LdCanvas *self, LdDiagramObject *object)
|
||||
{
|
||||
if (LD_IS_DIAGRAM_SYMBOL (object))
|
||||
{
|
||||
LdCanvasRect rect;
|
||||
LdRectangle rect;
|
||||
|
||||
if (!get_symbol_clip_area (self, LD_DIAGRAM_SYMBOL (object), &rect))
|
||||
return;
|
||||
@ -1151,7 +1113,7 @@ static void
|
||||
draw_symbol (LdDiagramSymbol *diagram_symbol, DrawData *data)
|
||||
{
|
||||
LdSymbol *symbol;
|
||||
LdCanvasRect clip_rect;
|
||||
LdRectangle clip_rect;
|
||||
gdouble x, y;
|
||||
|
||||
symbol = resolve_diagram_symbol (data->self, diagram_symbol);
|
||||
@ -1165,7 +1127,7 @@ draw_symbol (LdDiagramSymbol *diagram_symbol, DrawData *data)
|
||||
}
|
||||
|
||||
if (!get_symbol_clip_area (data->self, diagram_symbol, &clip_rect)
|
||||
|| !ld_canvas_rect_intersects (&clip_rect, &data->exposed_rect))
|
||||
|| !ld_rectangle_intersects (&clip_rect, &data->exposed_rect))
|
||||
return;
|
||||
|
||||
cairo_save (data->cr);
|
||||
|
@ -2,7 +2,7 @@
|
||||
* ld-library.c
|
||||
*
|
||||
* This file is a part of logdiag.
|
||||
* Copyright Přemysl Janouch 2010. All rights reserved.
|
||||
* Copyright Přemysl Janouch 2010 - 2011. All rights reserved.
|
||||
*
|
||||
* See the file LICENSE for licensing information.
|
||||
*
|
||||
@ -15,6 +15,7 @@
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "ld-types.h"
|
||||
#include "ld-symbol.h"
|
||||
#include "ld-symbol-category.h"
|
||||
#include "ld-library.h"
|
||||
|
@ -2,7 +2,7 @@
|
||||
* ld-lua-symbol-private.h
|
||||
*
|
||||
* This file is a part of logdiag.
|
||||
* Copyright Přemysl Janouch 2010. All rights reserved.
|
||||
* Copyright Přemysl Janouch 2010 - 2011. All rights reserved.
|
||||
*
|
||||
* See the file LICENSE for licensing information.
|
||||
*
|
||||
@ -28,7 +28,7 @@ struct _LdLuaSymbolPrivate
|
||||
LdLua *lua;
|
||||
gchar *name;
|
||||
gchar *human_name;
|
||||
LdSymbolArea area;
|
||||
LdRectangle area;
|
||||
};
|
||||
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
* ld-lua-symbol.c
|
||||
*
|
||||
* This file is a part of logdiag.
|
||||
* Copyright Přemysl Janouch 2010. All rights reserved.
|
||||
* Copyright Přemysl Janouch 2010 - 2011. All rights reserved.
|
||||
*
|
||||
* See the file LICENSE for licensing information.
|
||||
*
|
||||
@ -12,6 +12,7 @@
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "ld-types.h"
|
||||
#include "ld-symbol.h"
|
||||
#include "ld-symbol-category.h"
|
||||
#include "ld-library.h"
|
||||
@ -35,7 +36,7 @@ static void ld_lua_symbol_finalize (GObject *gobject);
|
||||
|
||||
static const gchar *ld_lua_symbol_real_get_name (LdSymbol *symbol);
|
||||
static const gchar *ld_lua_symbol_real_get_human_name (LdSymbol *symbol);
|
||||
static void ld_lua_symbol_real_get_area (LdSymbol *symbol, LdSymbolArea *area);
|
||||
static void ld_lua_symbol_real_get_area (LdSymbol *symbol, LdRectangle *area);
|
||||
static void ld_lua_symbol_real_draw (LdSymbol *symbol, cairo_t *cr);
|
||||
|
||||
|
||||
@ -102,7 +103,7 @@ ld_lua_symbol_real_get_human_name (LdSymbol *symbol)
|
||||
}
|
||||
|
||||
static void
|
||||
ld_lua_symbol_real_get_area (LdSymbol *symbol, LdSymbolArea *area)
|
||||
ld_lua_symbol_real_get_area (LdSymbol *symbol, LdRectangle *area)
|
||||
{
|
||||
LdLuaSymbol *self;
|
||||
|
||||
|
@ -15,6 +15,7 @@
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "ld-types.h"
|
||||
#include "ld-symbol.h"
|
||||
#include "ld-library.h"
|
||||
|
||||
@ -90,7 +91,7 @@ static int ld_lua_private_unregister_cb (lua_State *L);
|
||||
static int ld_lua_logdiag_register (lua_State *L);
|
||||
static int process_registration (lua_State *L);
|
||||
static gchar *get_translation (lua_State *L, int index);
|
||||
static gboolean read_symbol_area (lua_State *L, int index, LdSymbolArea *area);
|
||||
static gboolean read_symbol_area (lua_State *L, int index, LdRectangle *area);
|
||||
|
||||
static void push_cairo_object (lua_State *L, LdLuaDrawData *draw_data);
|
||||
static gdouble get_cairo_scale (cairo_t *cr);
|
||||
@ -528,7 +529,7 @@ get_translation (lua_State *L, int index)
|
||||
* Return value: TRUE on success, FALSE on failure.
|
||||
*/
|
||||
static gboolean
|
||||
read_symbol_area (lua_State *L, int index, LdSymbolArea *area)
|
||||
read_symbol_area (lua_State *L, int index, LdRectangle *area)
|
||||
{
|
||||
lua_Number x1, x2, y1, y2;
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
* ld-symbol-category.c
|
||||
*
|
||||
* This file is a part of logdiag.
|
||||
* Copyright Přemysl Janouch 2010. All rights reserved.
|
||||
* Copyright Přemysl Janouch 2010 - 2011. All rights reserved.
|
||||
*
|
||||
* See the file LICENSE for licensing information.
|
||||
*
|
||||
@ -12,6 +12,7 @@
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "ld-types.h"
|
||||
#include "ld-symbol.h"
|
||||
#include "ld-symbol-category.h"
|
||||
#include "ld-library.h"
|
||||
|
@ -2,7 +2,7 @@
|
||||
* ld-symbol.c
|
||||
*
|
||||
* This file is a part of logdiag.
|
||||
* Copyright Přemysl Janouch 2010. All rights reserved.
|
||||
* Copyright Přemysl Janouch 2010 - 2011. All rights reserved.
|
||||
*
|
||||
* See the file LICENSE for licensing information.
|
||||
*
|
||||
@ -12,6 +12,7 @@
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "ld-types.h"
|
||||
#include "ld-symbol.h"
|
||||
#include "ld-symbol-category.h"
|
||||
#include "ld-library.h"
|
||||
@ -82,7 +83,7 @@ ld_symbol_class_init (LdSymbolClass *klass)
|
||||
*/
|
||||
pspec = g_param_spec_boxed ("area", "Area",
|
||||
"The area of this symbol.",
|
||||
LD_TYPE_SYMBOL_AREA, G_PARAM_READABLE);
|
||||
LD_TYPE_RECTANGLE, G_PARAM_READABLE);
|
||||
g_object_class_install_property (object_class, PROP_AREA, pspec);
|
||||
}
|
||||
|
||||
@ -108,7 +109,7 @@ ld_symbol_get_property (GObject *object, guint property_id,
|
||||
break;
|
||||
case PROP_AREA:
|
||||
{
|
||||
LdSymbolArea area;
|
||||
LdRectangle area;
|
||||
|
||||
ld_symbol_get_area (self, &area);
|
||||
g_value_set_boxed (value, &area);
|
||||
@ -171,7 +172,7 @@ ld_symbol_get_human_name (LdSymbol *self)
|
||||
* Get the area of the symbol.
|
||||
*/
|
||||
void
|
||||
ld_symbol_get_area (LdSymbol *self, LdSymbolArea *area)
|
||||
ld_symbol_get_area (LdSymbol *self, LdRectangle *area)
|
||||
{
|
||||
LdSymbolClass *klass;
|
||||
|
||||
@ -202,51 +203,3 @@ ld_symbol_draw (LdSymbol *self, cairo_t *cr)
|
||||
g_return_if_fail (klass->draw != NULL);
|
||||
klass->draw (self, cr);
|
||||
}
|
||||
|
||||
/**
|
||||
* ld_symbol_area_copy:
|
||||
* @self: An #LdSymbolArea structure.
|
||||
*
|
||||
* Makes a copy of the structure.
|
||||
* The result must be freed by ld_symbol_area_free().
|
||||
*
|
||||
* Return value: A copy of @self.
|
||||
**/
|
||||
LdSymbolArea *
|
||||
ld_symbol_area_copy (const LdSymbolArea *self)
|
||||
{
|
||||
LdSymbolArea *new_area;
|
||||
|
||||
g_return_val_if_fail (self != NULL, NULL);
|
||||
|
||||
new_area = g_slice_new (LdSymbolArea);
|
||||
*new_area = *self;
|
||||
return new_area;
|
||||
}
|
||||
|
||||
/**
|
||||
* ld_symbol_area_free:
|
||||
* @self: An #LdSymbolArea structure.
|
||||
*
|
||||
* Frees the structure created with ld_symbol_area_copy().
|
||||
**/
|
||||
void
|
||||
ld_symbol_area_free (LdSymbolArea *self)
|
||||
{
|
||||
g_return_if_fail (self != NULL);
|
||||
|
||||
g_slice_free (LdSymbolArea, self);
|
||||
}
|
||||
|
||||
GType
|
||||
ld_symbol_area_get_type (void)
|
||||
{
|
||||
static GType our_type = 0;
|
||||
|
||||
if (our_type == 0)
|
||||
our_type = g_boxed_type_register_static
|
||||
(g_intern_static_string ("LdSymbolArea"),
|
||||
(GBoxedCopyFunc) ld_symbol_area_copy,
|
||||
(GBoxedFreeFunc) ld_symbol_area_free);
|
||||
return our_type;
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
* ld-symbol.h
|
||||
*
|
||||
* This file is a part of logdiag.
|
||||
* Copyright Přemysl Janouch 2010. All rights reserved.
|
||||
* Copyright Přemysl Janouch 2010 - 2011. All rights reserved.
|
||||
*
|
||||
* See the file LICENSE for licensing information.
|
||||
*
|
||||
@ -14,33 +14,6 @@
|
||||
G_BEGIN_DECLS
|
||||
|
||||
|
||||
#define LD_TYPE_SYMBOL_AREA (ld_symbol_area_get_type ())
|
||||
|
||||
typedef struct _LdSymbolArea LdSymbolArea;
|
||||
|
||||
/**
|
||||
* LdSymbolArea:
|
||||
* @x: Left-top X coordinate.
|
||||
* @y: Left-top Y coordinate.
|
||||
* @width: Width of the area, must be positive.
|
||||
* @height: Height of the area, must be positive.
|
||||
*
|
||||
* Defines the area of the symbol relative to the center of the symbol,
|
||||
* which is at the (0, 0) coordinates.
|
||||
*/
|
||||
struct _LdSymbolArea
|
||||
{
|
||||
gdouble x, y;
|
||||
gdouble width, height;
|
||||
};
|
||||
|
||||
|
||||
GType ld_symbol_area_get_type (void) G_GNUC_CONST;
|
||||
|
||||
LdSymbolArea *ld_symbol_area_copy (const LdSymbolArea *self);
|
||||
void ld_symbol_area_free (LdSymbolArea *self);
|
||||
|
||||
|
||||
#define LD_TYPE_SYMBOL (ld_symbol_get_type ())
|
||||
#define LD_SYMBOL(obj) (G_TYPE_CHECK_INSTANCE_CAST \
|
||||
((obj), LD_TYPE_SYMBOL, LdSymbol))
|
||||
@ -79,7 +52,7 @@ struct _LdSymbolClass
|
||||
|
||||
const gchar *(*get_name) (LdSymbol *self);
|
||||
const gchar *(*get_human_name) (LdSymbol *self);
|
||||
void (*get_area) (LdSymbol *self, LdSymbolArea *area);
|
||||
void (*get_area) (LdSymbol *self, LdRectangle *area);
|
||||
void (*draw) (LdSymbol *self, cairo_t *cr);
|
||||
};
|
||||
|
||||
@ -88,7 +61,7 @@ GType ld_symbol_get_type (void) G_GNUC_CONST;
|
||||
|
||||
const gchar *ld_symbol_get_name (LdSymbol *self);
|
||||
const gchar *ld_symbol_get_human_name (LdSymbol *self);
|
||||
void ld_symbol_get_area (LdSymbol *self, LdSymbolArea *area);
|
||||
void ld_symbol_get_area (LdSymbol *self, LdRectangle *area);
|
||||
void ld_symbol_draw (LdSymbol *self, cairo_t *cr);
|
||||
|
||||
/* TODO: Interface for terminals.
|
||||
|
202
src/ld-types.c
Normal file
202
src/ld-types.c
Normal file
@ -0,0 +1,202 @@
|
||||
/*
|
||||
* ld-types.c
|
||||
*
|
||||
* This file is a part of logdiag.
|
||||
* Copyright Přemysl Janouch 2010 - 2011. All rights reserved.
|
||||
*
|
||||
* See the file LICENSE for licensing information.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "ld-types.h"
|
||||
|
||||
|
||||
#define DEFINE_BOXED_TYPE(TypeName, type_name) \
|
||||
GType \
|
||||
type_name ## _get_type (void) \
|
||||
{ \
|
||||
static GType our_type = 0; \
|
||||
if (our_type == 0) \
|
||||
our_type = g_boxed_type_register_static \
|
||||
(g_intern_static_string (#TypeName), \
|
||||
(GBoxedCopyFunc) type_name ## _copy, \
|
||||
(GBoxedFreeFunc) type_name ## _free); \
|
||||
return our_type; \
|
||||
}
|
||||
|
||||
DEFINE_BOXED_TYPE (LdPoint, ld_point)
|
||||
DEFINE_BOXED_TYPE (LdPointArray, ld_point_array)
|
||||
DEFINE_BOXED_TYPE (LdRectangle, ld_rectangle)
|
||||
|
||||
#define DEFINE_BOXED_TRIVIAL_COPY(TypeName, type_name) \
|
||||
TypeName * \
|
||||
type_name ## _copy (const TypeName *self) \
|
||||
{ \
|
||||
TypeName *new_copy; \
|
||||
g_return_val_if_fail (self != NULL, NULL); \
|
||||
new_copy = g_slice_new (TypeName); \
|
||||
*new_copy = *self; \
|
||||
return new_copy; \
|
||||
}
|
||||
|
||||
#define DEFINE_BOXED_TRIVIAL_FREE(TypeName, type_name) \
|
||||
void \
|
||||
type_name ## _free (TypeName *self) \
|
||||
{ \
|
||||
g_return_if_fail (self != NULL); \
|
||||
g_slice_free (TypeName, self); \
|
||||
}
|
||||
|
||||
/**
|
||||
* ld_point_copy:
|
||||
* @self: An #LdPoint structure.
|
||||
*
|
||||
* Makes a copy of the structure.
|
||||
* The result must be freed by ld_point_free().
|
||||
*
|
||||
* Return value: A copy of @self.
|
||||
*/
|
||||
DEFINE_BOXED_TRIVIAL_COPY (LdPoint, ld_point)
|
||||
|
||||
/**
|
||||
* ld_point_free:
|
||||
* @self: An #LdPoint structure.
|
||||
*
|
||||
* Frees the structure created with ld_point_copy().
|
||||
*/
|
||||
DEFINE_BOXED_TRIVIAL_FREE (LdPoint, ld_point)
|
||||
|
||||
/**
|
||||
* ld_point_array_new:
|
||||
* @num_points: The number of points the array can store.
|
||||
*
|
||||
* Create a new array of points and initialize.
|
||||
*
|
||||
* Return value: An #LdPointArray structure.
|
||||
*/
|
||||
LdPointArray *
|
||||
ld_point_array_new (gint num_points)
|
||||
{
|
||||
LdPointArray *new_array;
|
||||
|
||||
g_return_val_if_fail (num_points >= 1, NULL);
|
||||
|
||||
new_array = g_slice_new (LdPointArray);
|
||||
new_array->num_points = num_points;
|
||||
new_array->points = g_malloc0 (num_points * sizeof (LdPoint));
|
||||
return new_array;
|
||||
}
|
||||
|
||||
/**
|
||||
* ld_point_array_copy:
|
||||
* @self: An #LdPointArray structure.
|
||||
*
|
||||
* Makes a copy of the structure.
|
||||
* The result must be freed by ld_point_array_free().
|
||||
*
|
||||
* Return value: A copy of @self.
|
||||
*/
|
||||
LdPointArray *
|
||||
ld_point_array_copy (const LdPointArray *self)
|
||||
{
|
||||
LdPointArray *new_array;
|
||||
|
||||
g_return_val_if_fail (self != NULL, NULL);
|
||||
|
||||
new_array = g_slice_new (LdPointArray);
|
||||
new_array->num_points = self->num_points;
|
||||
new_array->points = g_memdup (self->points,
|
||||
self->num_points * sizeof (LdPoint));
|
||||
return new_array;
|
||||
}
|
||||
|
||||
/**
|
||||
* ld_point_array_free:
|
||||
* @self: An #LdPointArray structure.
|
||||
*
|
||||
* Frees the structure created with ld_point_array_copy().
|
||||
*/
|
||||
void
|
||||
ld_point_array_free (LdPointArray *self)
|
||||
{
|
||||
g_return_if_fail (self != NULL);
|
||||
|
||||
g_free (self->points);
|
||||
g_slice_free (LdPointArray, self);
|
||||
}
|
||||
|
||||
/**
|
||||
* ld_rectangle_copy:
|
||||
* @self: An #LdRectangle structure.
|
||||
*
|
||||
* Makes a copy of the structure.
|
||||
* The result must be freed by ld_rectangle_free().
|
||||
*
|
||||
* Return value: A copy of @self.
|
||||
*/
|
||||
DEFINE_BOXED_TRIVIAL_COPY (LdRectangle, ld_rectangle)
|
||||
|
||||
/**
|
||||
* ld_rectangle_free:
|
||||
* @self: An #LdRectangle structure.
|
||||
*
|
||||
* Frees the structure created with ld_rectangle_copy().
|
||||
*/
|
||||
DEFINE_BOXED_TRIVIAL_FREE (LdRectangle, ld_rectangle)
|
||||
|
||||
/**
|
||||
* ld_rectangle_contains:
|
||||
* @self: An #LdRectangle structure.
|
||||
* @x: The X coordinate of the point to be checked.
|
||||
* @y: The Y coordinate of the point to be checked.
|
||||
*
|
||||
* Return value: TRUE if the rectangle contains the specified point.
|
||||
*/
|
||||
gboolean
|
||||
ld_rectangle_contains (LdRectangle *self, gdouble x, gdouble y)
|
||||
{
|
||||
g_return_val_if_fail (self != NULL, FALSE);
|
||||
return (x >= self->x && x <= self->x + self->width
|
||||
&& y >= self->y && y <= self->y + self->height);
|
||||
}
|
||||
|
||||
/**
|
||||
* ld_rectangle_intersects:
|
||||
* @self: An #LdRectangle structure.
|
||||
* @rect: An #LdRectangle to be checked for intersection.
|
||||
*
|
||||
* Return value: TRUE if the two rectangles intersect.
|
||||
*/
|
||||
gboolean
|
||||
ld_rectangle_intersects (LdRectangle *self, LdRectangle *rect)
|
||||
{
|
||||
g_return_val_if_fail (self != NULL, FALSE);
|
||||
g_return_val_if_fail (rect != NULL, FALSE);
|
||||
|
||||
return !(self->x > rect->x + rect->width
|
||||
|| self->y > rect->y + rect->height
|
||||
|| self->x + self->width < rect->x
|
||||
|| self->y + self->height < rect->y);
|
||||
}
|
||||
|
||||
/**
|
||||
* ld_rectangle_extend:
|
||||
* @self: An #LdRectangle structure.
|
||||
* @border: The border by which the rectangle should be extended.
|
||||
*
|
||||
* Extend a rectangle on all sides.
|
||||
*/
|
||||
void
|
||||
ld_rectangle_extend (LdRectangle *self, gdouble border)
|
||||
{
|
||||
g_return_if_fail (self != NULL);
|
||||
|
||||
self->x -= border;
|
||||
self->y -= border;
|
||||
self->width += 2 * border;
|
||||
self->height += 2 * border;
|
||||
}
|
100
src/ld-types.h
Normal file
100
src/ld-types.h
Normal file
@ -0,0 +1,100 @@
|
||||
/*
|
||||
* ld-types.h
|
||||
*
|
||||
* This file is a part of logdiag.
|
||||
* Copyright Přemysl Janouch 2010 - 2011. All rights reserved.
|
||||
*
|
||||
* See the file LICENSE for licensing information.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef __LD_TYPES_H__
|
||||
#define __LD_TYPES_H__
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
|
||||
/**
|
||||
* SECTION:ld-types
|
||||
* @short_description: Simple data types.
|
||||
*
|
||||
* #LdPoint defines coordinates of a point.
|
||||
*
|
||||
* #LdRectangle defines the position and size of a rectangle.
|
||||
*/
|
||||
|
||||
#define LD_TYPE_POINT (ld_point_get_type ())
|
||||
#define LD_TYPE_POINT_ARRAY (ld_point_array_get_type ())
|
||||
#define LD_TYPE_RECTANGLE (ld_rectangle_get_type ())
|
||||
|
||||
typedef struct _LdPoint LdPoint;
|
||||
typedef struct _LdPointArray LdPointArray;
|
||||
typedef struct _LdRectangle LdRectangle;
|
||||
|
||||
|
||||
/**
|
||||
* LdPoint:
|
||||
* @x: The X coordinate.
|
||||
* @y: The Y coordinate.
|
||||
*
|
||||
* Defines a point.
|
||||
*/
|
||||
struct _LdPoint
|
||||
{
|
||||
gdouble x, y;
|
||||
};
|
||||
|
||||
GType ld_point_get_type (void) G_GNUC_CONST;
|
||||
|
||||
LdPoint *ld_point_copy (const LdPoint *self);
|
||||
void ld_point_free (LdPoint *self);
|
||||
|
||||
|
||||
/**
|
||||
* LdPointArray:
|
||||
* @points: An array of #LdPoint structures.
|
||||
* @num_points: Count of points in @points.
|
||||
*
|
||||
* Moves quickly.
|
||||
*/
|
||||
struct _LdPointArray
|
||||
{
|
||||
LdPoint *points;
|
||||
gint num_points;
|
||||
};
|
||||
|
||||
GType ld_point_array_get_type (void) G_GNUC_CONST;
|
||||
|
||||
LdPointArray *ld_point_array_new (gint num_points);
|
||||
LdPointArray *ld_point_array_copy (const LdPointArray *self);
|
||||
void ld_point_array_free (LdPointArray *self);
|
||||
|
||||
|
||||
/**
|
||||
* LdRectangle:
|
||||
* @x: Left-top X coordinate.
|
||||
* @y: Left-top Y coordinate.
|
||||
* @width: Width of the area, must be positive.
|
||||
* @height: Height of the area, must be positive.
|
||||
*
|
||||
* Defines a rectangle.
|
||||
*/
|
||||
struct _LdRectangle
|
||||
{
|
||||
gdouble x, y;
|
||||
gdouble width, height;
|
||||
};
|
||||
|
||||
GType ld_rectangle_get_type (void) G_GNUC_CONST;
|
||||
|
||||
LdRectangle *ld_rectangle_copy (const LdRectangle *self);
|
||||
void ld_rectangle_free (LdRectangle *self);
|
||||
gboolean ld_rectangle_contains (LdRectangle *self, gdouble x, gdouble y);
|
||||
gboolean ld_rectangle_intersects (LdRectangle *self, LdRectangle *rect);
|
||||
void ld_rectangle_extend (LdRectangle *self, gdouble border);
|
||||
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* ! __LD_TYPES_H__ */
|
||||
|
@ -14,6 +14,7 @@
|
||||
|
||||
#include "ld-window-main.h"
|
||||
|
||||
#include "ld-types.h"
|
||||
#include "ld-symbol.h"
|
||||
#include "ld-symbol-category.h"
|
||||
#include "ld-library.h"
|
||||
@ -610,7 +611,7 @@ on_category_toggle (GtkToggleButton *toggle_button, gpointer user_data)
|
||||
for (symbol_iter = children; symbol_iter;
|
||||
symbol_iter = symbol_iter->next)
|
||||
{
|
||||
LdSymbolArea area;
|
||||
LdRectangle area;
|
||||
|
||||
item->symbol = LD_SYMBOL (symbol_iter->data);
|
||||
g_object_ref (item->symbol);
|
||||
|
Loading…
Reference in New Issue
Block a user