Skip to content

Commit bed8d6d

Browse files
Propose graphics object store
1 parent 76b278c commit bed8d6d

File tree

6 files changed

+167
-125
lines changed

6 files changed

+167
-125
lines changed

CMakeLists.txt

-2
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,6 @@ set(sources
5959
src/drawing.h
6060
src/coordlist_ops.c
6161
src/coordlist_ops.h
62-
src/objects.c
63-
src/objects.h
6462
src/main.c
6563
src/main.h
6664
src/input.c

src/callbacks.c

+55-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ gboolean on_expose (GtkWidget *widget,
3939
{
4040
GromitData *data = (GromitData *) user_data;
4141

42-
if(data->debug || 1)
42+
if(data->debug)
4343
g_printerr("DEBUG: got draw event\n");
4444

4545
cairo_save (cr);
@@ -930,6 +930,60 @@ void on_intro(GtkMenuItem *menuitem,
930930
gtk_widget_show_all (assistant);
931931
}
932932

933+
void on_edit_config(GtkMenuItem *menuitem,
934+
gpointer user_data)
935+
{
936+
/*
937+
Check if user config does not exist or is empty.
938+
If so, copy system config to user config.
939+
*/
940+
gchar *user_config_path = g_strjoin (G_DIR_SEPARATOR_S, g_get_user_config_dir(), "gromit-mpx.cfg", NULL);
941+
GFile *user_config_file = g_file_new_for_path(user_config_path);
942+
943+
guint64 user_config_size = 0;
944+
GFileInfo *user_config_info = g_file_query_info(user_config_file, G_FILE_ATTRIBUTE_STANDARD_SIZE, 0, NULL, NULL);
945+
if (user_config_info != NULL) {
946+
user_config_size = g_file_info_get_size(user_config_info);
947+
g_object_unref(user_config_info);
948+
}
949+
950+
if (!g_file_query_exists(user_config_file, NULL) || user_config_size == 0) {
951+
g_print("User config does not exist or is empty, copying system config\n");
952+
953+
gchar *system_config_path = g_strjoin (G_DIR_SEPARATOR_S, SYSCONFDIR, "gromit-mpx", "gromit-mpx.cfg", NULL);
954+
GFile *system_config_file = g_file_new_for_path(system_config_path);
955+
956+
GError *error = NULL;
957+
gboolean result = g_file_copy(system_config_file, user_config_file, G_FILE_COPY_OVERWRITE, NULL, NULL, NULL, &error);
958+
if (!result) {
959+
g_printerr("Error copying system config to user config: %s\n", error->message);
960+
g_error_free(error);
961+
}
962+
963+
g_object_unref(system_config_file);
964+
g_free(system_config_path);
965+
}
966+
967+
968+
/*
969+
Open user config for editing.
970+
*/
971+
gchar *user_config_uri = g_strjoin (G_DIR_SEPARATOR_S, "file://", user_config_path, NULL);
972+
973+
gtk_show_uri_on_window (NULL,
974+
user_config_uri,
975+
GDK_CURRENT_TIME,
976+
NULL);
977+
978+
/*
979+
Clean up
980+
*/
981+
g_object_unref(user_config_file);
982+
g_free(user_config_path);
983+
g_free(user_config_uri);
984+
}
985+
986+
933987
void on_issues(GtkMenuItem *menuitem,
934988
gpointer user_data)
935989
{

src/coordlist_ops.c

+104
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,110 @@ static GList *build_section_list(GList *const coords,
459459
return section_list;
460460
}
461461

462+
void coord_list_prepend (GromitData *data,
463+
GdkDevice* dev,
464+
gint x,
465+
gint y,
466+
gint width)
467+
{
468+
/* get the data for this device */
469+
GromitDeviceData *devdata = g_hash_table_lookup(data->devdatatable, dev);
470+
471+
GromitStrokeCoordinate *point;
472+
473+
point = g_malloc (sizeof (GromitStrokeCoordinate));
474+
point->x = x;
475+
point->y = y;
476+
point->width = width;
477+
478+
devdata->coordlist = g_list_prepend (devdata->coordlist, point);
479+
}
480+
481+
482+
void coord_list_free (GromitData *data,
483+
GdkDevice* dev)
484+
{
485+
/* get the data for this device */
486+
GromitDeviceData *devdata = g_hash_table_lookup(data->devdatatable, dev);
487+
488+
GList *ptr;
489+
ptr = devdata->coordlist;
490+
491+
while (ptr)
492+
{
493+
g_free (ptr->data);
494+
ptr = ptr->next;
495+
}
496+
497+
g_list_free (devdata->coordlist);
498+
499+
devdata->coordlist = NULL;
500+
}
501+
502+
/*
503+
* for double-ended arrows, two separate calls are required
504+
*/
505+
506+
gboolean coord_list_get_arrow_param (GromitData *data,
507+
GdkDevice *dev,
508+
gint search_radius,
509+
GromitArrowType arrow_end,
510+
gint *x0,
511+
gint *y0,
512+
gint *ret_width,
513+
gfloat *ret_direction)
514+
{
515+
gint r2, dist;
516+
gboolean success = FALSE;
517+
GromitStrokeCoordinate *cur_point, *valid_point;
518+
/* get the data for this device */
519+
GromitDeviceData *devdata = g_hash_table_lookup(data->devdatatable, dev);
520+
GList *ptr = devdata->coordlist;
521+
gfloat width;
522+
523+
valid_point = NULL;
524+
525+
if (ptr)
526+
{
527+
if (arrow_end == GROMIT_ARROW_START)
528+
ptr = g_list_last(ptr);
529+
cur_point = ptr->data;
530+
*x0 = cur_point->x;
531+
*y0 = cur_point->y;
532+
r2 = search_radius * search_radius;
533+
dist = 0;
534+
535+
while (ptr && dist < r2)
536+
{
537+
if (arrow_end == GROMIT_ARROW_END)
538+
ptr = ptr->next;
539+
else
540+
ptr = ptr->prev;
541+
if (ptr)
542+
{
543+
cur_point = ptr->data;
544+
dist = (cur_point->x - *x0) * (cur_point->x - *x0) +
545+
(cur_point->y - *y0) * (cur_point->y - *y0);
546+
width = cur_point->width * devdata->cur_context->arrowsize;
547+
if (width * 2 <= dist &&
548+
(!valid_point || valid_point->width < cur_point->width))
549+
valid_point = cur_point;
550+
}
551+
}
552+
553+
if (valid_point)
554+
{
555+
*ret_width = MAX (valid_point->width * devdata->cur_context->arrowsize,
556+
2);
557+
*ret_direction = atan2 (*y0 - valid_point->y, *x0 - valid_point->x);
558+
success = TRUE;
559+
}
560+
}
561+
562+
return success;
563+
}
564+
565+
462566
// ----------------------- orthogonalize path ------------------------
463567

464568
void orthogonalize(GList *const coords,

src/drawing.c

-104
Original file line numberDiff line numberDiff line change
@@ -105,107 +105,3 @@ void draw_arrow (GromitData *data,
105105
data->painted = 1;
106106
}
107107

108-
109-
void coord_list_prepend (GromitData *data,
110-
GdkDevice* dev,
111-
gint x,
112-
gint y,
113-
gint width)
114-
{
115-
/* get the data for this device */
116-
GromitDeviceData *devdata = g_hash_table_lookup(data->devdatatable, dev);
117-
118-
GromitStrokeCoordinate *point;
119-
120-
point = g_malloc (sizeof (GromitStrokeCoordinate));
121-
point->x = x;
122-
point->y = y;
123-
point->width = width;
124-
125-
devdata->coordlist = g_list_prepend (devdata->coordlist, point);
126-
}
127-
128-
129-
void coord_list_free (GromitData *data,
130-
GdkDevice* dev)
131-
{
132-
/* get the data for this device */
133-
GromitDeviceData *devdata = g_hash_table_lookup(data->devdatatable, dev);
134-
135-
GList *ptr;
136-
ptr = devdata->coordlist;
137-
138-
while (ptr)
139-
{
140-
g_free (ptr->data);
141-
ptr = ptr->next;
142-
}
143-
144-
g_list_free (devdata->coordlist);
145-
146-
devdata->coordlist = NULL;
147-
}
148-
149-
/*
150-
* for double-ended arrows, two separate calls are required
151-
*/
152-
153-
gboolean coord_list_get_arrow_param (GromitData *data,
154-
GdkDevice *dev,
155-
gint search_radius,
156-
GromitArrowType arrow_end,
157-
gint *x0,
158-
gint *y0,
159-
gint *ret_width,
160-
gfloat *ret_direction)
161-
{
162-
gint r2, dist;
163-
gboolean success = FALSE;
164-
GromitStrokeCoordinate *cur_point, *valid_point;
165-
/* get the data for this device */
166-
GromitDeviceData *devdata = g_hash_table_lookup(data->devdatatable, dev);
167-
GList *ptr = devdata->coordlist;
168-
gfloat width;
169-
170-
valid_point = NULL;
171-
172-
if (ptr)
173-
{
174-
if (arrow_end == GROMIT_ARROW_START)
175-
ptr = g_list_last(ptr);
176-
cur_point = ptr->data;
177-
*x0 = cur_point->x;
178-
*y0 = cur_point->y;
179-
r2 = search_radius * search_radius;
180-
dist = 0;
181-
182-
while (ptr && dist < r2)
183-
{
184-
if (arrow_end == GROMIT_ARROW_END)
185-
ptr = ptr->next;
186-
else
187-
ptr = ptr->prev;
188-
if (ptr)
189-
{
190-
cur_point = ptr->data;
191-
dist = (cur_point->x - *x0) * (cur_point->x - *x0) +
192-
(cur_point->y - *y0) * (cur_point->y - *y0);
193-
width = cur_point->width * devdata->cur_context->arrowsize;
194-
if (width * 2 <= dist &&
195-
(!valid_point || valid_point->width < cur_point->width))
196-
valid_point = cur_point;
197-
}
198-
}
199-
200-
if (valid_point)
201-
{
202-
*ret_width = MAX (valid_point->width * devdata->cur_context->arrowsize,
203-
2);
204-
*ret_direction = atan2 (*y0 - valid_point->y, *x0 - valid_point->x);
205-
success = TRUE;
206-
}
207-
}
208-
209-
return success;
210-
}
211-

src/main.c

+7-8
Original file line numberDiff line numberDiff line change
@@ -446,14 +446,7 @@ void snap_undo_state (GromitData *data)
446446
data->redo_depth = 0;
447447
}
448448

449-
void clear_surface (cairo_surface_t *dst)
450-
{
451-
cairo_t *cr = cairo_create(dst);
452-
cairo_set_source_rgb(cr, 0, 0, 0);
453-
cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
454-
cairo_paint (cr);
455-
cairo_destroy(cr);
456-
}
449+
457450

458451
void copy_surface (cairo_surface_t *dst, cairo_surface_t *src)
459452
{
@@ -904,6 +897,7 @@ void setup_main_app (GromitData *data, int argc, char ** argv)
904897

905898
GtkWidget* sep1_item = gtk_separator_menu_item_new();
906899
GtkWidget* intro_item = gtk_menu_item_new_with_mnemonic(_("_Introduction"));
900+
GtkWidget* edit_config_item = gtk_menu_item_new_with_mnemonic(_("_Edit Config"));
907901
GtkWidget* issues_item = gtk_menu_item_new_with_mnemonic(_("_Report Bug / Request Feature"));
908902
GtkWidget* support_item = gtk_menu_item_new_with_mnemonic(_("_Support Gromit-MPX"));
909903
GtkWidget* about_item = gtk_menu_item_new_with_mnemonic(_("_About"));
@@ -926,6 +920,7 @@ void setup_main_app (GromitData *data, int argc, char ** argv)
926920

927921
gtk_menu_shell_append (GTK_MENU_SHELL (menu), sep1_item);
928922
gtk_menu_shell_append (GTK_MENU_SHELL (menu), intro_item);
923+
gtk_menu_shell_append (GTK_MENU_SHELL (menu), edit_config_item);
929924
gtk_menu_shell_append (GTK_MENU_SHELL (menu), issues_item);
930925
gtk_menu_shell_append (GTK_MENU_SHELL (menu), support_item);
931926
gtk_menu_shell_append (GTK_MENU_SHELL (menu), about_item);
@@ -988,6 +983,9 @@ void setup_main_app (GromitData *data, int argc, char ** argv)
988983
g_signal_connect(G_OBJECT (intro_item), "activate",
989984
G_CALLBACK (on_intro),
990985
data);
986+
g_signal_connect(G_OBJECT (edit_config_item), "activate",
987+
G_CALLBACK (on_edit_config),
988+
data);
991989
g_signal_connect(G_OBJECT (issues_item), "activate",
992990
G_CALLBACK (on_issues),
993991
data);
@@ -1012,6 +1010,7 @@ void setup_main_app (GromitData *data, int argc, char ** argv)
10121010

10131011
gtk_widget_show (sep1_item);
10141012
gtk_widget_show (intro_item);
1013+
gtk_widget_show (edit_config_item);
10151014
gtk_widget_show (issues_item);
10161015
gtk_widget_show (support_item);
10171016
gtk_widget_show (about_item);

src/main.h

+1-10
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
#define GROMIT_MPX_MAIN_H
2525

2626
#include "build-config.h"
27-
#include "cairo.h"
2827

2928
#include <glib.h>
3029
#include <glib/gi18n.h>
@@ -143,8 +142,6 @@ typedef struct
143142
GHashTable *tool_config;
144143

145144
cairo_surface_t *backbuffer;
146-
cairo_surface_t *cache_buffer;
147-
guint32 cache_id;
148145
/* Auxiliary backbuffer for tools like LINE or RECT */
149146
cairo_surface_t *aux_backbuffer;
150147

@@ -174,10 +171,6 @@ typedef struct
174171

175172
gboolean show_intro_on_startup;
176173

177-
178-
GList *gfx_store;
179-
180-
181174
} GromitData;
182175

183176

@@ -189,9 +182,7 @@ void parse_print_help (gpointer key, gpointer value, gpointer user_data);
189182

190183
void select_tool (GromitData *data, GdkDevice *device, GdkDevice *slave_device, guint state);
191184

192-
void copy_surface(cairo_surface_t *dst, cairo_surface_t *src);
193-
void clear_surface (cairo_surface_t *dst);
194-
185+
void copy_surface (cairo_surface_t *dst, cairo_surface_t *src);
195186
void snap_undo_state(GromitData *data);
196187
void undo_drawing (GromitData *data);
197188
void redo_drawing (GromitData *data);

0 commit comments

Comments
 (0)