Take page as input and take advantage of s_visit_page.
[geda-gaf/berndj.git] / gschem / src / x_stroke.c
blob661e1989d6db609e559b070e626375371fc45bfb
1 /* gEDA - GPL Electronic Design Automation
2 * gschem - gEDA Schematic Capture
3 * Copyright (C) 1998-2007 Ales Hvezda
4 * Copyright (C) 1998-2007 gEDA Contributors (see ChangeLog for details)
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA
20 #include <config.h>
22 #include "gschem.h"
24 #ifdef HAS_LIBSTROKE
25 #include <stroke.h>
27 #ifdef HAVE_LIBDMALLOC
28 #include <dmalloc.h>
29 #endif
32 * <B>stroke_points</B> is an array of points for the stroke
33 * footprints. The points of the stroke are displayed over the display
34 * area of the main window. They have to be erased when the stroke is
35 * translated and the sequence evaluated.
37 * Its size will never exceed <B>STROKE_MAX_POINTS</B> (the limit in
38 * number of points of a stroke provided by libstroke).
40 typedef struct {
41 gint x, y;
42 } StrokePoint;
44 static GArray *stroke_points = NULL;
47 /*! \brief Initializes the stroke interface.
48 * \par Function Description
49 * This is the initialization function for the stroke interface. It
50 * initializes the libstroke library and prepare an array of points
51 * for the mouse footprints.
53 * This function has to be called only once at application
54 * initialization before any use of the stroke interface.
56 void
57 x_stroke_init (void)
59 g_return_if_fail (stroke_points == NULL);
61 stroke_init ();
63 stroke_points = g_array_new (FALSE,
64 FALSE,
65 sizeof (StrokePoint));
68 /*! \brief Frees memory of the stroke interface.
69 * \par Function Description
70 * This function frees the memory used for the mouse footprint
71 * points. It terminates the use of the stroke interface.
73 void
74 x_stroke_free (void)
76 g_return_if_fail (stroke_points != NULL);
78 g_array_free (stroke_points, TRUE);
79 stroke_points = NULL;
82 /*! \brief Records a new point for the stroke.
83 * \par Function Description
84 * This function adds the point (<B>x</B>,<B>y</B>) as a new point in
85 * the stroke.
87 * The footprint is updated and the new point is drawn on the drawing area.
89 * \param [in] w_current The GSCHEM_TOPLEVEL object.
90 * \param [in] x The X coord of the new point.
91 * \param [in] Y The X coord of the new point.
93 void
94 x_stroke_record (GSCHEM_TOPLEVEL *w_current, gint x, gint y)
96 g_assert (stroke_points != NULL);
98 stroke_record (x, y);
100 if (stroke_points->len < STROKE_MAX_POINTS) {
101 StrokePoint point = { x, y };
103 g_array_append_val (stroke_points, point);
105 gdk_gc_set_foreground (w_current->gc,
106 x_get_color (w_current->stroke_color));
107 gdk_draw_point (w_current->window, w_current->gc, x, y);
112 /*! \brief Evaluates the stroke.
113 * \par Function Description
114 * This function transforms the stroke input so far in an action.
116 * It makes use of the guile procedure <B>eval-stroke</B> to evaluate
117 * the stroke sequence into a possible action. The mouse footprint is
118 * erased in this function.
120 * It returns 1 if the stroke has been successfully evaluated as an
121 * action. It returns 0 if libstroke failed to transform the stroke
122 * or there is no action attached to the stroke.
124 * \param [in] w_current The GSCHEM_TOPLEVEL object.
125 * \returns 1 on success, 0 otherwise.
127 gint
128 x_stroke_translate_and_execute (GSCHEM_TOPLEVEL *w_current)
130 gchar sequence[STROKE_MAX_SEQUENCE];
131 gint i;
133 g_assert (stroke_points != NULL);
135 /* erase footprint */
136 for (i = 0; i < stroke_points->len; i++) {
137 StrokePoint *point = &g_array_index (stroke_points, StrokePoint, i);
139 gdk_gc_set_foreground (w_current->gc,
140 x_get_color (
141 w_current->toplevel->background_color));
142 gdk_draw_point (w_current->window, w_current->gc,
143 point->x, point->y);
145 /* resets length of array */
146 stroke_points->len = 0;
148 /* try evaluating stroke */
149 if (stroke_trans ((char*)&sequence)) {
150 SCM ret;
152 ret = g_scm_apply_protected(g_scm_safe_ref_lookup("eval-stroke"),
153 scm_list_1(scm_from_locale_string(sequence)),
154 NULL, NULL);
156 return (SCM_NFALSEP (ret));
159 return 0;
162 #endif /* HAS_LIBSTROKE */