plug-ins: Port GFig to GAction/GMenuModel

Because of how many actions can change the sensitivity of "undo" options
most of the plug-in files had to be edited to pass GimpGfig to them.
This commit is contained in:
Alx Sa 2023-02-05 00:08:21 +00:00
parent e6382e9262
commit 38c031e01d
26 changed files with 699 additions and 449 deletions

View file

@ -93,8 +93,9 @@ static void d_update_arc_line (GdkPoint *pnt);
static void d_update_arc (GdkPoint *pnt);
static void d_arc_line_start (GdkPoint *pnt,
gboolean shift_down);
static void d_arc_line_end (GdkPoint *pnt,
gboolean shift_down);
static void d_arc_line_end (GimpGfig *gfig,
GdkPoint *pnt,
gboolean shift_down);
/* Distance between two points. */
static gdouble
@ -649,7 +650,8 @@ d_arc_start (GdkPoint *pnt,
}
static void
d_arc_line_end (GdkPoint *pnt,
d_arc_line_end (GimpGfig *gfig,
GdkPoint *pnt,
gboolean shift_down)
{
if (shift_down)
@ -671,7 +673,7 @@ d_arc_line_end (GdkPoint *pnt,
else
{
tmp_line = obj_creating;
add_to_all_obj (gfig_context->current_obj, obj_creating);
add_to_all_obj (gfig, gfig_context->current_obj, obj_creating);
}
obj_creating = d_new_object (LINE, pnt->x, pnt->y);
@ -694,7 +696,7 @@ d_arc_line_end (GdkPoint *pnt,
}
else
{
add_to_all_obj (gfig_context->current_obj, obj_creating);
add_to_all_obj (gfig, gfig_context->current_obj, obj_creating);
}
obj_creating = NULL;
tmp_line = NULL;
@ -703,7 +705,8 @@ d_arc_line_end (GdkPoint *pnt,
}
void
d_arc_end (GdkPoint *pnt,
d_arc_end (GimpGfig *gfig,
GdkPoint *pnt,
gboolean shift_down)
{
/* Under control point */
@ -712,7 +715,7 @@ d_arc_end (GdkPoint *pnt,
!tmp_line->points->next)
{
/* No arc created - yet. Must have three points */
d_arc_line_end (pnt, TRUE);
d_arc_line_end (gfig, pnt, TRUE);
}
else
{
@ -720,7 +723,7 @@ d_arc_end (GdkPoint *pnt,
/* Convert to an arc ... */
tmp_line->type = ARC;
tmp_line->class = &dobj_class[ARC];
d_arc_line_end (pnt, FALSE);
d_arc_line_end (gfig, pnt, FALSE);
if (need_to_scale)
{
selvals.scaletoimage = 0;

View file

@ -29,7 +29,8 @@ void d_arc_object_class_init (void);
void d_arc_start (GdkPoint *pnt,
gboolean shift_down);
void d_arc_end (GdkPoint *pnt,
void d_arc_end (GimpGfig *gfig,
GdkPoint *pnt,
gboolean shift_down);

View file

@ -342,7 +342,8 @@ d_bezier_start (GdkPoint *pnt,
}
void
d_bezier_end (GdkPoint *pnt,
d_bezier_end (GimpGfig *gfig,
GdkPoint *pnt,
gboolean shift_down)
{
DobjPoints *l_pnt;
@ -374,7 +375,7 @@ d_bezier_end (GdkPoint *pnt,
tmp_bezier->points->pnt.y, -1);
}
add_to_all_obj (gfig_context->current_obj, obj_creating);
add_to_all_obj (gfig, gfig_context->current_obj, obj_creating);
}
/* small mem leak if !l_pnt ? */

View file

@ -34,7 +34,8 @@ void d_bezier_object_class_init (void);
void d_bezier_start (GdkPoint *pnt,
gboolean shift_down);
void d_bezier_end (GdkPoint *pnt,
void d_bezier_end (GimpGfig *gfig,
GdkPoint *pnt,
gboolean shift_down);
void tool_options_bezier (GtkWidget *notebook);

View file

@ -215,7 +215,8 @@ d_circle_start (GdkPoint *pnt,
}
void
d_circle_end (GdkPoint *pnt,
d_circle_end (GimpGfig *gfig,
GdkPoint *pnt,
gboolean shift_down)
{
/* Under control point */
@ -226,7 +227,7 @@ d_circle_end (GdkPoint *pnt,
}
else
{
add_to_all_obj (gfig_context->current_obj, obj_creating);
add_to_all_obj (gfig, gfig_context->current_obj, obj_creating);
}
obj_creating = NULL;

View file

@ -29,7 +29,8 @@ void d_circle_object_class_init (void);
void d_circle_start (GdkPoint *pnt,
gboolean shift_down);
void d_circle_end (GdkPoint *pnt,
void d_circle_end (GimpGfig *gfig,
GdkPoint *pnt,
gboolean shift_down);
#endif /* __GFIG_CIRCLE_H__ */

View file

@ -141,24 +141,38 @@ static GtkWidget *tool_options_notebook;
static GtkWidget *fill_type_notebook;
static guint paint_timeout = 0;
static GtkActionGroup *gfig_actions = NULL;
static void shape_change_state (GSimpleAction *action,
GVariant *new_state,
gpointer user_data);
static void gfig_response (GtkWidget *widget,
gint response_id,
gpointer data);
static void gfig_load_action_callback (GtkAction *action,
gpointer data);
static void gfig_save_action_callback (GtkAction *action,
gpointer data);
static void gfig_load_action (GSimpleAction *action,
GVariant *parameter,
gpointer user_data);
static void gfig_save_action (GSimpleAction *action,
GVariant *parameter,
gpointer user_data);
static void gfig_list_load_all (const gchar *path);
static void gfig_list_free_all (void);
static void create_notebook_pages (GtkWidget *notebook);
static void select_filltype_callback (GtkWidget *widget);
static void gfig_grid_action_callback (GtkAction *action,
gpointer data);
static void gfig_prefs_action_callback (GtkAction *action,
gpointer data);
static void gfig_close_action (GSimpleAction *action,
GVariant *parameter,
gpointer user_data);
static void gfig_undo_action (GSimpleAction *action,
GVariant *parameter,
gpointer user_data);
static void gfig_clear_action (GSimpleAction *action,
GVariant *parameter,
gpointer user_data);
static void gfig_grid_action (GSimpleAction *action,
GVariant *parameter,
gpointer user_data);
static void gfig_prefs_action (GSimpleAction *action,
GVariant *parameter,
gpointer user_data);
static void toggle_show_image (void);
static void gridtype_combo_callback (GtkWidget *widget,
gpointer data);
@ -173,39 +187,79 @@ static void paint_combo_callback (GtkWidget *widget,
gpointer data);
static void select_button_clicked (gint type);
static void select_button_clicked_lt (void);
static void select_button_clicked_gt (void);
static void select_button_clicked_eq (void);
static void raise_selected_obj_to_top (GtkWidget *widget,
gpointer data);
static void lower_selected_obj_to_bottom (GtkWidget *widget,
gpointer data);
static void raise_selected_obj (GtkWidget *widget,
gpointer data);
static void lower_selected_obj (GtkWidget *widget,
gpointer data);
static void select_button_clicked_lt (GSimpleAction *action,
GVariant *parameter,
gpointer user_data);
static void select_button_clicked_gt (GSimpleAction *action,
GVariant *parameter,
gpointer user_data);
static void select_button_clicked_eq (GSimpleAction *action,
GVariant *parameter,
gpointer user_data);
static void raise_selected_obj_to_top (GSimpleAction *action,
GVariant *parameter,
gpointer user_data);
static void lower_selected_obj_to_bottom (GSimpleAction *action,
GVariant *parameter,
gpointer user_data);
static void raise_selected_obj (GSimpleAction *action,
GVariant *parameter,
gpointer user_data);
static void lower_selected_obj (GSimpleAction *action,
GVariant *parameter,
gpointer user_data);
static void toggle_obj_type (GtkRadioAction *action,
GtkRadioAction *current,
gpointer data);
static GtkUIManager *create_ui_manager (GtkWidget *window);
static void toggle_obj_type (DobjType new_type);
static void gfig_scale_entry_update_double (GimpLabelSpin *entry,
gdouble *value);
static void gfig_scale_entry_update_int (GimpLabelSpin *entry,
gint *value);
/* GAction helper methods */
static GtkWidget * add_tool_button (GtkWidget *toolbar,
const char *action,
const char *icon,
const char *label,
const char *tooltip);
static void add_tool_separator (GtkWidget *toolbar,
gboolean expand);
static const GActionEntry ACTIONS[] =
{
/* Sub-menu options */
{ "open", gfig_load_action },
{ "save", gfig_save_action },
{ "close", gfig_close_action },
{ "undo", gfig_undo_action },
{ "clear", gfig_clear_action },
{ "grid", gfig_grid_action },
{ "preferences", gfig_prefs_action },
/* Toolbar buttons */
{ "raise", raise_selected_obj },
{ "lower", lower_selected_obj },
{ "top", raise_selected_obj_to_top },
{ "bottom", lower_selected_obj_to_bottom },
{ "show-prev", select_button_clicked_lt },
{ "show-next", select_button_clicked_gt },
{ "show-all", select_button_clicked_eq },
/* RadioButtons - only the default state is shown here. */
{ "shape", shape_change_state, "s", "'line'", NULL },
};
gboolean
gfig_dialog (void)
gfig_dialog (GimpGfig *gfig)
{
GAction *action;
GtkWidget *main_hbox;
GtkWidget *vbox;
GFigObj *gfig;
GFigObj *gfig_obj;
GimpParasite *parasite;
GimpLayer *newlayer;
GtkWidget *menubar;
GMenuModel *model;
GtkWidget *toolbar;
GtkWidget *combo;
GtkWidget *frame;
@ -215,7 +269,6 @@ gfig_dialog (void)
GtkWidget *toggle;
GtkWidget *right_vbox;
GtkWidget *hbox;
GtkUIManager *ui_manager;
GtkWidget *empty_label;
gchar *path;
@ -289,48 +342,102 @@ gfig_dialog (void)
}
/* Start building the dialog up */
top_level_dlg = gimp_dialog_new (_("Gfig"), PLUG_IN_ROLE,
NULL, 0,
gimp_standard_help_func, PLUG_IN_PROC,
gfig->top_level_dlg = gimp_dialog_new (_("Gfig"), PLUG_IN_ROLE,
NULL, 0,
gimp_standard_help_func, PLUG_IN_PROC,
_("_Cancel"), GTK_RESPONSE_CANCEL,
_("_Close"), GTK_RESPONSE_OK,
_("_Cancel"), GTK_RESPONSE_CANCEL,
_("_Close"), GTK_RESPONSE_OK,
NULL);
NULL);
gimp_window_set_transient (GTK_WINDOW (top_level_dlg));
gtk_window_set_application (GTK_WINDOW (gfig->top_level_dlg), gfig->app);
gimp_window_set_transient (GTK_WINDOW (gfig->top_level_dlg));
gimp_dialog_set_alternative_button_order (GTK_DIALOG (top_level_dlg),
gimp_dialog_set_alternative_button_order (GTK_DIALOG (gfig->top_level_dlg),
GTK_RESPONSE_OK,
GTK_RESPONSE_CANCEL,
-1);
g_signal_connect (top_level_dlg, "response",
g_signal_connect (gfig->top_level_dlg, "response",
G_CALLBACK (gfig_response),
top_level_dlg);
gfig);
/* build the menu */
ui_manager = create_ui_manager (top_level_dlg);
menubar = gtk_ui_manager_get_widget (ui_manager, "/ui/gfig-menubar");
gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (top_level_dlg))),
g_action_map_add_action_entries (G_ACTION_MAP (gfig->app),
ACTIONS, G_N_ELEMENTS (ACTIONS),
gfig);
model = G_MENU_MODEL (gtk_builder_get_object (gfig->builder, "gfig-menubar"));
menubar = gtk_menu_bar_new_from_model (model);
gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (gfig->top_level_dlg))),
menubar, FALSE, FALSE, 0);
gtk_widget_show (menubar);
toolbar = gtk_ui_manager_get_widget (ui_manager, "/ui/gfig-toolbar");
gtk_toolbar_set_style (GTK_TOOLBAR (toolbar), GTK_TOOLBAR_ICONS);
gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (top_level_dlg))),
toolbar = gtk_toolbar_new ();
add_tool_button (toolbar, "app.shape::line", GFIG_ICON_LINE,
_("Line"), _("Create line"));
add_tool_button (toolbar, "app.shape::rectangle", GFIG_ICON_RECTANGLE,
_("Rectangle"), _("Create rectangle"));
add_tool_button (toolbar, "app.shape::circle", GFIG_ICON_CIRCLE,
_("Circle"), _("Create circle"));
add_tool_button (toolbar, "app.shape::ellipse", GFIG_ICON_ELLIPSE,
_("Ellipse"), _("Create ellipse"));
add_tool_button (toolbar, "app.shape::arc", GFIG_ICON_CURVE,
_("Arc"), _("Create arc"));
add_tool_button (toolbar, "app.shape::polygon", GFIG_ICON_POLYGON,
_("Polygon"), _("Create reg polygon"));
add_tool_button (toolbar, "app.shape::star", GFIG_ICON_STAR,
_("Star"), _("Create star"));
add_tool_button (toolbar, "app.shape::spiral", GFIG_ICON_SPIRAL,
_("Spiral"), _("Create spiral"));
add_tool_button (toolbar, "app.shape::bezier", GFIG_ICON_BEZIER,
_("Bezier"), _("Create bezier curve. "
"Shift + Button ends object creation."));
add_tool_button (toolbar, "app.shape::move-obj", GFIG_ICON_MOVE_OBJECT,
_("Move Object"), _("Move an object"));
add_tool_button (toolbar, "app.shape::move-point", GFIG_ICON_MOVE_POINT,
_("Move Point"), _("Move a single point"));
add_tool_button (toolbar, "app.shape::copy", GFIG_ICON_COPY_OBJECT,
_("Copy"), _("Copy an object"));
add_tool_button (toolbar, "app.shape::delete", GFIG_ICON_DELETE_OBJECT,
_("Delete"), _("Delete an object"));
add_tool_button (toolbar, "app.shape::select", GFIG_ICON_SELECT_OBJECT,
_("Select"), _("Select an object"));
add_tool_separator (toolbar, FALSE);
add_tool_button (toolbar, "app.raise", GIMP_ICON_GO_UP,
_("Raise"), _("Raise selected object"));
add_tool_button (toolbar, "app.lower", GIMP_ICON_GO_DOWN,
_("Lower"), _("Lower selected object"));
add_tool_button (toolbar, "app.raise", GIMP_ICON_GO_TOP,
_("To Top"), _("Raise selected object to top"));
add_tool_button (toolbar, "app.lower", GIMP_ICON_GO_BOTTOM,
_("To Bottom"), _("Lower selected object to bottom"));
add_tool_separator (toolbar, FALSE);
add_tool_button (toolbar, "app.show-prev", GIMP_ICON_GO_PREVIOUS,
_("Show Previous"), _("Show previous object"));
add_tool_button (toolbar, "app.show-next", GIMP_ICON_GO_NEXT,
_("Show Next"), _("Show next object"));
add_tool_button (toolbar, "app.show-all", GFIG_ICON_SHOW_ALL,
_("Show All"), _("Show all object"));
gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (gfig->top_level_dlg))),
toolbar, FALSE, FALSE, 0);
gtk_widget_show (toolbar);
gfig_dialog_action_set_sensitive ("undo", undo_level >= 0);
action = g_action_map_lookup_action (G_ACTION_MAP (gfig->app), "undo");
g_simple_action_set_enabled (G_SIMPLE_ACTION (action),
undo_level >= 0);
/* Main box */
main_hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
gtk_container_set_border_width (GTK_CONTAINER (main_hbox), 12);
gtk_box_pack_end (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (top_level_dlg))),
gtk_box_pack_end (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (gfig->top_level_dlg))),
main_hbox, TRUE, TRUE, 0);
/* Preview itself */
gtk_box_pack_start (GTK_BOX (main_hbox), make_preview (), FALSE, FALSE, 0);
gtk_box_pack_start (GTK_BOX (main_hbox), make_preview (gfig), FALSE, FALSE, 0);
gtk_widget_show (gfig_context->preview);
@ -526,13 +633,13 @@ gfig_dialog (void)
gtk_widget_show (main_hbox);
gtk_widget_show (top_level_dlg);
gtk_widget_show (gfig->top_level_dlg);
gfig = gfig_load_from_parasite ();
if (gfig)
gfig_obj = gfig_load_from_parasite (gfig);
if (gfig_obj)
{
gfig_list_insert (gfig);
new_obj_2edit (gfig);
gfig_list_insert (gfig_obj);
new_obj_2edit (gfig, gfig_obj);
gfig_style_set_context_from_style (&gfig_context->default_style);
gfig_style_apply (&gfig_context->default_style);
}
@ -540,18 +647,60 @@ gfig_dialog (void)
gfig_context->enable_repaint = TRUE;
gfig_paint_callback ();
gtk_main ();
/* FIXME */
return TRUE;
}
static void shape_change_state (GSimpleAction *action,
GVariant *new_state,
gpointer user_data)
{
gchar *str;
DobjType new_type = LINE;
str = g_strdup_printf ("%s", g_variant_get_string (new_state, NULL));
if (! strcmp (str, "line"))
new_type = LINE;
else if (! strcmp (str, "rectangle"))
new_type = RECTANGLE;
else if (! strcmp (str, "circle"))
new_type = CIRCLE;
else if (! strcmp (str, "ellipse"))
new_type = ELLIPSE;
else if (! strcmp (str, "arc"))
new_type = ARC;
else if (! strcmp (str, "polygon"))
new_type = POLY;
else if (! strcmp (str, "star"))
new_type = STAR;
else if (! strcmp (str, "spiral"))
new_type = SPIRAL;
else if (! strcmp (str, "bezier"))
new_type = BEZIER;
else if (! strcmp (str, "move-obj"))
new_type = MOVE_OBJ;
else if (! strcmp (str, "move-point"))
new_type = MOVE_POINT;
else if (! strcmp (str, "copy"))
new_type = COPY_OBJ;
else if (! strcmp (str, "delete"))
new_type = DEL_OBJ;
else if (! strcmp (str, "select"))
new_type = SELECT_OBJ;
g_free (str);
g_simple_action_set_state (action, new_state);
toggle_obj_type (new_type);
}
static void
gfig_response (GtkWidget *widget,
gint response_id,
gpointer data)
{
GFigObj *gfig;
GFigObj *gfig_obj;
switch (response_id)
{
@ -567,11 +716,11 @@ gfig_response (GtkWidget *widget,
{
free_all_objs (gfig_context->current_obj->obj_list);
gfig_context->current_obj->obj_list = NULL;
gfig = gfig_load_from_parasite ();
if (gfig)
gfig_obj = gfig_load_from_parasite (GIMP_GFIG (data));
if (gfig_obj)
{
gfig_list_insert (gfig);
new_obj_2edit (gfig);
gfig_list_insert (gfig_obj);
new_obj_2edit (GIMP_GFIG (data), gfig_obj);
}
gfig_context->enable_repaint = TRUE;
gfig_paint_callback ();
@ -586,30 +735,8 @@ gfig_response (GtkWidget *widget,
break;
}
gtk_widget_destroy (widget);
gtk_main_quit ();
}
void
gfig_dialog_action_set_sensitive (const gchar *name,
gboolean sensitive)
{
g_return_if_fail (name != NULL);
if (gfig_actions)
{
GtkAction *action = gtk_action_group_get_action (gfig_actions, name);
if (! action)
{
g_warning ("%s: Unable to set sensitivity of action "
"which doesn't exist: %s",
G_STRFUNC, name);
return;
}
g_object_set (action, "sensitive", sensitive ? TRUE : FALSE, NULL);
}
gtk_application_remove_window ((GIMP_GFIG (data))->app,
GTK_WINDOW ((GIMP_GFIG (data))->top_level_dlg));
}
static gchar *
@ -631,8 +758,9 @@ gfig_get_user_writable_dir (void)
}
static void
gfig_load_action_callback (GtkAction *action,
gpointer data)
gfig_load_action (GSimpleAction *action,
GVariant *parameter,
gpointer user_data)
{
static GtkWidget *dialog = NULL;
@ -642,7 +770,7 @@ gfig_load_action_callback (GtkAction *action,
dialog =
gtk_file_chooser_dialog_new (_("Load Gfig Object Collection"),
GTK_WINDOW (data),
NULL,
GTK_FILE_CHOOSER_ACTION_OPEN,
_("_Cancel"), GTK_RESPONSE_CANCEL,
@ -661,7 +789,7 @@ gfig_load_action_callback (GtkAction *action,
g_signal_connect (dialog, "response",
G_CALLBACK (load_file_chooser_response),
NULL);
user_data);
dir = gfig_get_user_writable_dir ();
if (dir)
@ -680,8 +808,9 @@ gfig_load_action_callback (GtkAction *action,
}
static void
gfig_save_action_callback (GtkAction *action,
gpointer data)
gfig_save_action (GSimpleAction *action,
GVariant *parameter,
gpointer user_data)
{
static GtkWidget *dialog = NULL;
@ -691,7 +820,7 @@ gfig_save_action_callback (GtkAction *action,
dialog =
gtk_file_chooser_dialog_new (_("Save Gfig Drawing"),
GTK_WINDOW (data),
NULL,
GTK_FILE_CHOOSER_ACTION_SAVE,
_("_Cancel"), GTK_RESPONSE_CANCEL,
@ -733,16 +862,23 @@ gfig_save_action_callback (GtkAction *action,
}
static void
gfig_close_action_callback (GtkAction *action,
gpointer data)
gfig_close_action (GSimpleAction *action,
GVariant *parameter,
gpointer user_data)
{
gtk_dialog_response (GTK_DIALOG (data), GTK_RESPONSE_OK);
GimpGfig *gfig = GIMP_GFIG (user_data);
gtk_dialog_response (GTK_DIALOG (gfig->top_level_dlg), GTK_RESPONSE_OK);
}
static void
gfig_undo_action_callback (GtkAction *action,
gpointer data)
gfig_undo_action (GSimpleAction *action,
GVariant *parameter,
gpointer user_data)
{
GAction *action_undo;
GimpGfig *gfig = GIMP_GFIG (user_data);
if (undo_level >= 0)
{
/* Free current objects an reinstate previous */
@ -761,19 +897,23 @@ gfig_undo_action_callback (GtkAction *action,
gfig_context->selected_obj = NULL;
}
gfig_dialog_action_set_sensitive ("undo", undo_level >= 0);
action_undo = g_action_map_lookup_action (G_ACTION_MAP (gfig->app), "undo");
g_simple_action_set_enabled (G_SIMPLE_ACTION (action_undo),
undo_level >= 0);
gfig_paint_callback ();
}
static void
gfig_clear_action_callback (GtkWidget *widget,
gpointer data)
gfig_clear_action (GSimpleAction *action,
GVariant *parameter,
gpointer user_data)
{
/* Make sure we can get back - if we have some objects to get back to */
if (!gfig_context->current_obj->obj_list)
return;
setup_undo ();
setup_undo (GIMP_GFIG (user_data));
/* Free all objects */
free_all_objs (gfig_context->current_obj->obj_list);
gfig_context->current_obj->obj_list = NULL;
@ -868,193 +1008,6 @@ gfig_list_free_all (void)
gfig_list = NULL;
}
static GtkUIManager *
create_ui_manager (GtkWidget *window)
{
static GtkActionEntry actions[] =
{
{ "gfig-menubar", NULL, "GFig Menu" },
{ "gfig-file-menu", NULL, "_File" },
{ "open", GIMP_ICON_DOCUMENT_OPEN,
N_("_Open..."), "<control>O", NULL,
G_CALLBACK (gfig_load_action_callback) },
{ "save", GIMP_ICON_DOCUMENT_SAVE,
N_("_Save..."), "<control>S", NULL,
G_CALLBACK (gfig_save_action_callback) },
{ "close", GIMP_ICON_CLOSE,
N_("_Close"), "<control>C", NULL,
G_CALLBACK (gfig_close_action_callback) },
{ "gfig-edit-menu", NULL, "_Edit" },
{ "undo", GIMP_ICON_EDIT_UNDO,
N_("_Undo"), "<control>Z", NULL,
G_CALLBACK (gfig_undo_action_callback) },
{ "clear", GIMP_ICON_EDIT_CLEAR,
N_("_Clear"), NULL, NULL,
G_CALLBACK (gfig_clear_action_callback) },
{ "grid", GIMP_ICON_GRID,
N_("_Grid"), "<control>G", NULL,
G_CALLBACK (gfig_grid_action_callback) },
{ "prefs", GIMP_ICON_PREFERENCES_SYSTEM,
N_("_Preferences..."), "<control>P", NULL,
G_CALLBACK (gfig_prefs_action_callback) },
{ "raise", GIMP_ICON_GO_UP,
N_("_Raise"), "<control>U", N_("Raise selected object"),
G_CALLBACK (raise_selected_obj) },
{ "lower", GIMP_ICON_GO_DOWN,
N_("_Lower"), "<control>D", N_("Lower selected object"),
G_CALLBACK (lower_selected_obj) },
{ "top", GIMP_ICON_GO_TOP,
N_("Raise to _top"), "<control>T", N_("Raise selected object to top"),
G_CALLBACK (raise_selected_obj_to_top) },
{ "bottom", GIMP_ICON_GO_BOTTOM,
N_("Lower to _bottom"), "<control>B", N_("Lower selected object to bottom"),
G_CALLBACK (lower_selected_obj_to_bottom) },
{ "show_previous", GIMP_ICON_GO_PREVIOUS,
N_("_Previous"), "<control>H", N_("Show previous object"),
G_CALLBACK (select_button_clicked_lt) },
{ "show_next", GIMP_ICON_GO_NEXT,
N_("_Next"), "<control>L", N_("Show next object"),
G_CALLBACK (select_button_clicked_gt) },
{ "show_all", GFIG_ICON_SHOW_ALL,
N_("Show _all"), "<control>A", N_("Show all objects"),
G_CALLBACK (select_button_clicked_eq) }
};
static GtkRadioActionEntry radio_actions[] =
{
{ "line", GFIG_ICON_LINE,
NULL, "L", N_("Create line"), LINE },
{ "rectangle", GFIG_ICON_RECTANGLE,
NULL, "R", N_("Create rectangle"), RECTANGLE },
{ "circle", GFIG_ICON_CIRCLE,
NULL, "C", N_("Create circle"), CIRCLE },
{ "ellipse", GFIG_ICON_ELLIPSE,
NULL, "E", N_("Create ellipse"), ELLIPSE },
{ "arc", GFIG_ICON_CURVE,
NULL, "A", N_("Create arc"), ARC },
{ "polygon", GFIG_ICON_POLYGON,
NULL, "P", N_("Create reg polygon"), POLY },
{ "star", GFIG_ICON_STAR,
NULL, "S", N_("Create star"), STAR },
{ "spiral", GFIG_ICON_SPIRAL,
NULL, "I", N_("Create spiral"), SPIRAL },
{ "bezier", GFIG_ICON_BEZIER,
NULL, "B", N_("Create bezier curve. "
"Shift + Button ends object creation."), BEZIER },
{ "move_obj", GFIG_ICON_MOVE_OBJECT,
NULL, "M", N_("Move an object"), MOVE_OBJ },
{ "move_point", GFIG_ICON_MOVE_POINT,
NULL, "V", N_("Move a single point"), MOVE_POINT },
{ "copy", GFIG_ICON_COPY_OBJECT,
NULL, "Y", N_("Copy an object"), COPY_OBJ },
{ "delete", GFIG_ICON_DELETE_OBJECT,
NULL, "D", N_("Delete an object"), DEL_OBJ },
{ "select", GFIG_ICON_SELECT_OBJECT,
NULL, "A", N_("Select an object"), SELECT_OBJ }
};
GtkUIManager *ui_manager = gtk_ui_manager_new ();
gfig_actions = gtk_action_group_new ("Actions");
gtk_action_group_set_translation_domain (gfig_actions, NULL);
gtk_action_group_add_actions (gfig_actions,
actions,
G_N_ELEMENTS (actions),
window);
gtk_action_group_add_radio_actions (gfig_actions,
radio_actions,
G_N_ELEMENTS (radio_actions),
LINE,
G_CALLBACK (toggle_obj_type),
window);
gtk_window_add_accel_group (GTK_WINDOW (window),
gtk_ui_manager_get_accel_group (ui_manager));
gtk_accel_group_lock (gtk_ui_manager_get_accel_group (ui_manager));
gtk_ui_manager_insert_action_group (ui_manager, gfig_actions, -1);
g_object_unref (gfig_actions);
gtk_ui_manager_add_ui_from_string (ui_manager,
"<ui>"
" <menubar name=\"gfig-menubar\">"
" <menu name=\"File\" action=\"gfig-file-menu\">"
" <menuitem action=\"open\" />"
" <menuitem action=\"save\" />"
" <menuitem action=\"close\" />"
" </menu>"
" <menu name=\"Edit\" action=\"gfig-edit-menu\">"
" <menuitem action=\"undo\" />"
" <menuitem action=\"clear\" />"
" <menuitem action=\"grid\" />"
" <menuitem action=\"prefs\" />"
" </menu>"
" </menubar>"
"</ui>",
-1, NULL);
gtk_ui_manager_add_ui_from_string (ui_manager,
"<ui>"
" <toolbar name=\"gfig-toolbar\">"
" <toolitem action=\"line\" />"
" <toolitem action=\"rectangle\" />"
" <toolitem action=\"circle\" />"
" <toolitem action=\"ellipse\" />"
" <toolitem action=\"arc\" />"
" <toolitem action=\"polygon\" />"
" <toolitem action=\"star\" />"
" <toolitem action=\"spiral\" />"
" <toolitem action=\"bezier\" />"
" <toolitem action=\"move_obj\" />"
" <toolitem action=\"move_point\" />"
" <toolitem action=\"copy\" />"
" <toolitem action=\"delete\" />"
" <toolitem action=\"select\" />"
" <separator />"
" <toolitem action=\"raise\" />"
" <toolitem action=\"lower\" />"
" <toolitem action=\"top\" />"
" <toolitem action=\"bottom\" />"
" <separator />"
" <toolitem action=\"show_previous\" />"
" <toolitem action=\"show_next\" />"
" <toolitem action=\"show_all\" />"
" </toolbar>"
"</ui>",
-1, NULL);
return ui_manager;
}
static void
tool_option_no_option (GtkWidget *notebook)
{
@ -1085,8 +1038,9 @@ create_notebook_pages (GtkWidget *notebook)
}
static void
raise_selected_obj_to_top (GtkWidget *widget,
gpointer data)
raise_selected_obj_to_top (GSimpleAction *action,
GVariant *parameter,
gpointer user_data)
{
if (!gfig_context->selected_obj)
return;
@ -1111,8 +1065,9 @@ raise_selected_obj_to_top (GtkWidget *widget,
}
static void
lower_selected_obj_to_bottom (GtkWidget *widget,
gpointer data)
lower_selected_obj_to_bottom (GSimpleAction *action,
GVariant *parameter,
gpointer user_data)
{
if (!gfig_context->selected_obj)
return;
@ -1137,8 +1092,9 @@ lower_selected_obj_to_bottom (GtkWidget *widget,
}
static void
raise_selected_obj (GtkWidget *widget,
gpointer data)
raise_selected_obj (GSimpleAction *action,
GVariant *parameter,
gpointer user_data)
{
if (!gfig_context->selected_obj)
return;
@ -1169,8 +1125,9 @@ raise_selected_obj (GtkWidget *widget,
static void
lower_selected_obj (GtkWidget *widget,
gpointer data)
lower_selected_obj (GSimpleAction *action,
GVariant *parameter,
gpointer user_data)
{
if (!gfig_context->selected_obj)
return;
@ -1235,8 +1192,9 @@ gfig_paint_delayed (void)
}
static void
gfig_prefs_action_callback (GtkAction *widget,
gpointer data)
gfig_prefs_action (GSimpleAction *action,
GVariant *parameter,
gpointer user_data)
{
static GtkWidget *dialog = NULL;
@ -1250,7 +1208,7 @@ gfig_prefs_action_callback (GtkAction *widget,
GtkAdjustment *scale_data;
dialog = gimp_dialog_new (_("Options"), "gimp-gfig-options",
GTK_WIDGET (data), 0, NULL, NULL,
NULL, 0, NULL, NULL,
_("_Close"), GTK_RESPONSE_CLOSE,
@ -1378,8 +1336,9 @@ gfig_prefs_action_callback (GtkAction *widget,
}
static void
gfig_grid_action_callback (GtkAction *action,
gpointer data)
gfig_grid_action (GSimpleAction *action,
GVariant *parameter,
gpointer user_data)
{
static GtkWidget *dialog = NULL;
@ -1394,7 +1353,7 @@ gfig_grid_action_callback (GtkAction *action,
GtkWidget *radius_scale;
dialog = gimp_dialog_new (_("Grid"), "gimp-gfig-grid",
GTK_WIDGET (data), 0, NULL, NULL,
NULL, 0, NULL, NULL,
_("_Close"), GTK_RESPONSE_CLOSE,
@ -1690,19 +1649,25 @@ select_button_clicked (gint type)
}
static void
select_button_clicked_lt (void)
select_button_clicked_lt (GSimpleAction *action,
GVariant *parameter,
gpointer user_data)
{
select_button_clicked (OBJ_SELECT_LT);
}
static void
select_button_clicked_gt (void)
select_button_clicked_gt (GSimpleAction *action,
GVariant *parameter,
gpointer user_data)
{
select_button_clicked (OBJ_SELECT_GT);
}
static void
select_button_clicked_eq (void)
select_button_clicked_eq (GSimpleAction *action,
GVariant *parameter,
gpointer user_data)
{
select_button_clicked (OBJ_SELECT_EQ);
}
@ -1862,7 +1827,7 @@ load_file_chooser_response (GtkFileChooser *chooser,
if (response_id == GTK_RESPONSE_OK)
{
gchar *filename;
GFigObj *gfig;
GFigObj *gfig_obj;
GFigObj *current_saved;
filename = gtk_file_chooser_get_filename (chooser);
@ -1874,17 +1839,17 @@ load_file_chooser_response (GtkFileChooser *chooser,
*/
current_saved = gfig_context->current_obj;
gfig_context->current_obj = NULL;
gfig = gfig_load (filename, filename);
gfig_obj = gfig_load (GIMP_GFIG (data), filename, filename);
gfig_context->current_obj = current_saved;
if (gfig)
if (gfig_obj)
{
/* Read only ?*/
if (access (filename, W_OK))
gfig->obj_status |= GFIG_READONLY;
gfig_obj->obj_status |= GFIG_READONLY;
gfig_list_insert (gfig);
new_obj_2edit (gfig);
gfig_list_insert (gfig_obj);
new_obj_2edit (GIMP_GFIG (data), gfig_obj);
}
}
@ -2030,21 +1995,17 @@ toggle_show_image (void)
}
static void
toggle_obj_type (GtkRadioAction *action,
GtkRadioAction *current,
gpointer data)
toggle_obj_type (DobjType new_type)
{
/* cache of cursors.
* Must be larger than action values, i.e. NULL_OPER.
* Must be larger than DobjType values, i.e. NULL_OPER.
* Test by clicking the "select object" icon.
* C ensures is initialized to NULL.
*/
static GdkCursor *p_cursors[NULL_OPER];
GdkCursorType ctype = GDK_LAST_CURSOR;
DobjType new_type;
new_type = gtk_radio_action_get_current_value (action);
if (selvals.otype != new_type)
{
/* Mem leak */
@ -2222,3 +2183,38 @@ gfig_scale_entry_update_int (GimpLabelSpin *entry,
{
*value = (gint) gimp_label_spin_get_value (entry);
}
static GtkWidget *
add_tool_button (GtkWidget *toolbar,
const char *action,
const char *icon,
const char *label,
const char *tooltip)
{
GtkWidget *tool_icon;
GtkToolItem *tool_button;
tool_icon = gtk_image_new_from_icon_name (icon, GTK_ICON_SIZE_BUTTON);
gtk_widget_show (GTK_WIDGET (tool_icon));
tool_button = gtk_tool_button_new (tool_icon, label);
gtk_widget_show (GTK_WIDGET (tool_button));
gtk_tool_item_set_tooltip_text (tool_button, tooltip);
gtk_actionable_set_detailed_action_name (GTK_ACTIONABLE (tool_button), action);
gtk_toolbar_insert (GTK_TOOLBAR (toolbar), tool_button, -1);
return GTK_WIDGET (tool_button);
}
static void
add_tool_separator (GtkWidget *toolbar,
gboolean expand)
{
GtkToolItem *item;
item = gtk_separator_tool_item_new ();
gtk_toolbar_insert (GTK_TOOLBAR (toolbar), item, -1);
gtk_separator_tool_item_set_draw (GTK_SEPARATOR_TOOL_ITEM (item), FALSE);
gtk_tool_item_set_expand (item, expand);
gtk_widget_show (GTK_WIDGET (item));
}

View file

@ -28,7 +28,7 @@
extern gint undo_level; /* Last slot filled in -1 = no undo */
extern GList *undo_table[MAX_UNDO];
gboolean gfig_dialog (void);
gboolean gfig_dialog (GimpGfig *gfig);
void gfig_dialog_action_set_sensitive (const gchar *name,
gboolean sensitive);

View file

@ -341,7 +341,8 @@ get_nearest_objs (GFigObj *obj,
}
void
object_operation_start (GdkPoint *pnt,
object_operation_start (GimpGfig *gfig,
GdkPoint *pnt,
gboolean shift_down)
{
GfigObject *new_obj;
@ -355,7 +356,7 @@ object_operation_start (GdkPoint *pnt,
{
move_all_pnt = g_new (GdkPoint, 1);
*move_all_pnt = *pnt; /* Structure copy */
setup_undo ();
setup_undo (gfig);
return;
}
@ -364,7 +365,7 @@ object_operation_start (GdkPoint *pnt,
gfig_context->selected_obj = operation_obj;
setup_undo ();
setup_undo (gfig);
switch (selvals.otype)
{
@ -411,7 +412,7 @@ object_operation_start (GdkPoint *pnt,
{
gfig_style_copy (&new_obj->style, &operation_obj->style, "Object");
scan_obj_points (new_obj->points, pnt);
add_to_all_obj (gfig_context->current_obj, new_obj);
add_to_all_obj (gfig, gfig_context->current_obj, new_obj);
operation_obj = new_obj;
selvals.otype = MOVE_COPY_OBJ;
gtk_widget_queue_draw (gfig_context->preview);
@ -710,10 +711,11 @@ draw_objects (GList *objs,
}
void
prepend_to_all_obj (GFigObj *fobj,
GList *nobj)
prepend_to_all_obj (GimpGfig *gfig,
GFigObj *fobj,
GList *nobj)
{
setup_undo (); /* Remember ME */
setup_undo (gfig); /* Remember ME */
fobj->obj_list = g_list_concat (fobj->obj_list, nobj);
}
@ -732,7 +734,8 @@ scale_obj_points (DobjPoints *opnt,
}
void
add_to_all_obj (GFigObj *fobj,
add_to_all_obj (GimpGfig *gfig,
GFigObj *fobj,
GfigObject *obj)
{
GList *nobj = NULL;
@ -742,7 +745,7 @@ add_to_all_obj (GFigObj *fobj,
if (need_to_scale)
scale_obj_points (obj->points, scale_x_factor, scale_y_factor);
prepend_to_all_obj (fobj, nobj);
prepend_to_all_obj (gfig, fobj, nobj);
/* initialize style when we add the object */
gfig_context->selected_obj = obj;
@ -816,7 +819,8 @@ object_start (GdkPoint *pnt,
}
void
object_end (GdkPoint *pnt,
object_end (GimpGfig *gfig,
GdkPoint *pnt,
gboolean shift_down)
{
/* end for the current object */
@ -826,31 +830,31 @@ object_end (GdkPoint *pnt,
switch (selvals.otype)
{
case LINE:
d_line_end (pnt, shift_down);
d_line_end (gfig, pnt, shift_down);
break;
case RECTANGLE:
d_rectangle_end (pnt, shift_down);
d_rectangle_end (gfig, pnt, shift_down);
break;
case CIRCLE:
d_circle_end (pnt, shift_down);
d_circle_end (gfig, pnt, shift_down);
break;
case ELLIPSE:
d_ellipse_end (pnt, shift_down);
d_ellipse_end (gfig, pnt, shift_down);
break;
case POLY:
d_poly_end (pnt, shift_down);
d_poly_end (gfig, pnt, shift_down);
break;
case STAR:
d_star_end (pnt, shift_down);
d_star_end (gfig, pnt, shift_down);
break;
case ARC:
d_arc_end (pnt, shift_down);
d_arc_end (gfig, pnt, shift_down);
break;
case SPIRAL:
d_spiral_end (pnt, shift_down);
d_spiral_end (gfig, pnt, shift_down);
break;
case BEZIER:
d_bezier_end (pnt, shift_down);
d_bezier_end (gfig, pnt, shift_down);
break;
default:
/* Internal error */
@ -931,9 +935,10 @@ get_line (gchar *buf,
}
void
clear_undo (void)
clear_undo (GimpGfig *gfig)
{
int lv;
int lv;
GAction *action;
for (lv = undo_level; lv >= 0; lv--)
{
@ -943,12 +948,16 @@ clear_undo (void)
undo_level = -1;
gfig_dialog_action_set_sensitive ("undo", FALSE);
action = g_action_map_lookup_action (G_ACTION_MAP (gfig->app), "undo");
g_simple_action_set_enabled (G_SIMPLE_ACTION (action),
FALSE);
}
void
setup_undo (void)
setup_undo (GimpGfig *gfig)
{
GAction *action;
/* Copy object list to undo buffer */
#if DEBUG
printf ("setup undo level [%d]\n", undo_level);
@ -978,21 +987,24 @@ setup_undo (void)
undo_table[undo_level] =
copy_all_objs (gfig_context->current_obj->obj_list);
gfig_dialog_action_set_sensitive ("undo", TRUE);
action = g_action_map_lookup_action (G_ACTION_MAP (gfig->app), "undo");
g_simple_action_set_enabled (G_SIMPLE_ACTION (action), TRUE);
gfig_context->current_obj->obj_status |= GFIG_MODIFIED;
}
void
new_obj_2edit (GFigObj *obj)
new_obj_2edit (GimpGfig *gfig,
GFigObj *obj)
{
GAction *action;
GFigObj *old_current = gfig_context->current_obj;
/* Clear undo levels */
/* redraw the preview */
/* Set up options as define in the selected object */
clear_undo ();
clear_undo (gfig);
/* Point at this one */
gfig_context->current_obj = obj;
@ -1006,16 +1018,19 @@ new_obj_2edit (GFigObj *obj)
/* redraw with new */
gtk_widget_queue_draw (gfig_context->preview);
action = g_action_map_lookup_action (G_ACTION_MAP (gfig->app), "save");
if (obj->obj_status & GFIG_READONLY)
{
g_message (_("Editing read-only object - "
"you will not be able to save it"));
gfig_dialog_action_set_sensitive ("save", FALSE);
g_simple_action_set_enabled (G_SIMPLE_ACTION (action),
FALSE);
}
else
{
gfig_dialog_action_set_sensitive ("save", TRUE);
g_simple_action_set_enabled (G_SIMPLE_ACTION (action),
FALSE);
}
}

View file

@ -98,9 +98,10 @@ void d_save_object (GfigObject *obj,
void free_all_objs (GList *objs);
void clear_undo (void);
void clear_undo (GimpGfig *gfig);
void new_obj_2edit (GFigObj *obj);
void new_obj_2edit (GimpGfig *gfig,
GFigObj *obj);
void gfig_init_object_classes (void);

View file

@ -216,7 +216,8 @@ d_ellipse_start (GdkPoint *pnt,
}
void
d_ellipse_end (GdkPoint *pnt,
d_ellipse_end (GimpGfig *gfig,
GdkPoint *pnt,
gboolean shift_down)
{
/* Under control point */
@ -227,7 +228,7 @@ d_ellipse_end (GdkPoint *pnt,
}
else
{
add_to_all_obj (gfig_context->current_obj, obj_creating);
add_to_all_obj (gfig, gfig_context->current_obj, obj_creating);
}
obj_creating = NULL;

View file

@ -29,7 +29,8 @@ void d_ellipse_object_class_init (void);
void d_ellipse_start (GdkPoint *pnt,
gboolean shift_down);
void d_ellipse_end (GdkPoint *pnt,
void d_ellipse_end (GimpGfig *gfig,
GdkPoint *pnt,
gboolean shift_down);
#endif /* __GFIG_ELLIPSE_H__ */

View file

@ -172,7 +172,8 @@ d_line_start (GdkPoint *pnt,
}
void
d_line_end (GdkPoint *pnt,
d_line_end (GimpGfig *gfig,
GdkPoint *pnt,
gboolean shift_down)
{
if (shift_down)
@ -194,7 +195,7 @@ d_line_end (GdkPoint *pnt,
else
{
tmp_line = obj_creating;
add_to_all_obj (gfig_context->current_obj, obj_creating);
add_to_all_obj (gfig, gfig_context->current_obj, obj_creating);
}
obj_creating = d_new_object (LINE, pnt->x, pnt->y);
@ -217,7 +218,7 @@ d_line_end (GdkPoint *pnt,
}
else
{
add_to_all_obj (gfig_context->current_obj, obj_creating);
add_to_all_obj (gfig, gfig_context->current_obj, obj_creating);
}
obj_creating = NULL;
tmp_line = NULL;

View file

@ -29,7 +29,8 @@ void d_line_object_class_init (void);
void d_line_start (GdkPoint *pnt,
gboolean shift_down);
void d_line_end (GdkPoint *pnt,
void d_line_end (GimpGfig *gfig,
GdkPoint *pnt,
gboolean shift_down);
#endif /* __GFIG_LINE_H__ */

View file

@ -525,9 +525,10 @@ d_poly_start (GdkPoint *pnt,
}
void
d_poly_end (GdkPoint *pnt,
d_poly_end (GimpGfig *gfig,
GdkPoint *pnt,
gboolean shift_down)
{
add_to_all_obj (gfig_context->current_obj, obj_creating);
add_to_all_obj (gfig, gfig_context->current_obj, obj_creating);
obj_creating = NULL;
}

View file

@ -36,7 +36,8 @@ void d_poly_object_class_init (void);
void d_poly_start (GdkPoint *pnt,
gboolean shift_down);
void d_poly_end (GdkPoint *pnt,
void d_poly_end (GimpGfig *gfig,
GdkPoint *pnt,
gboolean shift_down);
#endif /* __GFIG_POLY_H__ */

View file

@ -51,7 +51,8 @@ static GtkWidget *pos_label; /* XY pos marker */
static void gfig_preview_realize (GtkWidget *widget);
static gboolean gfig_preview_events (GtkWidget *widget,
GdkEvent *event);
GdkEvent *event,
gpointer data);
static gboolean gfig_preview_draw (GtkWidget *widget,
cairo_t *cr);
@ -65,7 +66,7 @@ static void gfig_pos_update (gint x,
static void gfig_pos_update_labels (gpointer data);
GtkWidget *
make_preview (void)
make_preview (GimpGfig *gfig)
{
GtkWidget *frame;
GtkWidget *vbox;
@ -82,7 +83,7 @@ make_preview (void)
g_signal_connect (gfig_context->preview , "event",
G_CALLBACK (gfig_preview_events),
NULL);
gfig);
g_signal_connect_after (gfig_context->preview , "draw",
G_CALLBACK (gfig_preview_draw),
@ -179,7 +180,8 @@ gfig_preview_draw (GtkWidget *widget,
static gboolean
gfig_preview_events (GtkWidget *widget,
GdkEvent *event)
GdkEvent *event,
gpointer data)
{
GdkEventButton *bevent;
GdkEventMotion *mevent;
@ -203,7 +205,8 @@ gfig_preview_events (GtkWidget *widget,
point.x = gfig_invscale_x (point.x);
point.y = gfig_invscale_y (point.y);
}
object_operation_start (&point, bevent->state & GDK_SHIFT_MASK);
object_operation_start (GIMP_GFIG (data), &point,
bevent->state & GDK_SHIFT_MASK);
/* If constraining save start pnt */
if (selvals.opts.snap2grid)
@ -248,7 +251,7 @@ gfig_preview_events (GtkWidget *widget,
{
if (obj_creating)
{
object_end (&point, bevent->state & GDK_SHIFT_MASK);
object_end (GIMP_GFIG (data), &point, bevent->state & GDK_SHIFT_MASK);
}
else
break;

View file

@ -27,7 +27,7 @@
#define PREVIEW_SIZE 400
GtkWidget *make_preview (void);
GtkWidget *make_preview (GimpGfig *gfig);
void gfig_pos_enable (GtkWidget *widget,
gpointer data);

View file

@ -199,7 +199,8 @@ d_rectangle_start (GdkPoint *pnt,
}
void
d_rectangle_end (GdkPoint *pnt,
d_rectangle_end (GimpGfig *gfig,
GdkPoint *pnt,
gboolean shift_down)
{
/* Under control point */
@ -210,7 +211,7 @@ d_rectangle_end (GdkPoint *pnt,
}
else
{
add_to_all_obj (gfig_context->current_obj, obj_creating);
add_to_all_obj (gfig, gfig_context->current_obj, obj_creating);
}
obj_creating = NULL;

View file

@ -29,7 +29,8 @@ void d_rectangle_object_class_init (void);
void d_rectangle_start (GdkPoint *pnt,
gboolean shift_down);
void d_rectangle_end (GdkPoint *pnt,
void d_rectangle_end (GimpGfig *gfig,
GdkPoint *pnt,
gboolean shift_down);
#endif /* __GFIG_RECTANGLE_H__ */

View file

@ -308,9 +308,10 @@ d_spiral_start (GdkPoint *pnt,
}
void
d_spiral_end (GdkPoint *pnt,
d_spiral_end (GimpGfig *gfig,
GdkPoint *pnt,
gboolean shift_down)
{
add_to_all_obj (gfig_context->current_obj, obj_creating);
add_to_all_obj (gfig, gfig_context->current_obj, obj_creating);
obj_creating = NULL;
}

View file

@ -31,7 +31,8 @@ void d_spiral_object_class_init (void);
void d_spiral_start (GdkPoint *pnt,
gboolean shift_down);
void d_spiral_end (GdkPoint *pnt,
void d_spiral_end (GimpGfig *gfig,
GdkPoint *pnt,
gboolean shift_down);
#endif /* __GFIG_SPIRAL_H__ */

View file

@ -397,10 +397,11 @@ d_star_start (GdkPoint *pnt,
}
void
d_star_end (GdkPoint *pnt,
d_star_end (GimpGfig *gfig,
GdkPoint *pnt,
gboolean shift_down)
{
add_to_all_obj (gfig_context->current_obj, obj_creating);
add_to_all_obj (gfig, gfig_context->current_obj, obj_creating);
obj_creating = NULL;
}

View file

@ -31,7 +31,8 @@ void d_star_object_class_init (void);
void d_star_start (GdkPoint *pnt,
gboolean shift_down);
void d_star_end (GdkPoint *pnt,
void d_star_end (GimpGfig *gfig,
GdkPoint *pnt,
gboolean shift_down);

View file

@ -57,25 +57,10 @@
#define GFIG_HEADER "GFIG Version 0.2\n"
typedef struct _Gfig Gfig;
typedef struct _GfigClass GfigClass;
struct _Gfig
{
GimpPlugIn parent_instance;
};
struct _GfigClass
{
GimpPlugInClass parent_class;
};
#define GFIG_TYPE (gfig_get_type ())
#define GFIG (obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GFIG_TYPE, Gfig))
GType gfig_get_type (void) G_GNUC_CONST;
static void gimp_gfig_finalize (GObject *object);
static GList * gfig_query_procedures (GimpPlugIn *plug_in);
static GimpProcedure * gfig_create_procedure (GimpPlugIn *plug_in,
const gchar *name);
@ -88,14 +73,17 @@ static GimpValueArray * gfig_run (GimpProcedure *procedure,
const GimpValueArray *args,
gpointer run_data);
static void on_app_activate (GApplication *gapp,
gpointer user_data);
static gint load_options (GFigObj *gfig,
FILE *fp);
G_DEFINE_TYPE (Gfig, gfig, GIMP_TYPE_PLUG_IN)
G_DEFINE_TYPE (GimpGfig, gimp_gfig, GIMP_TYPE_PLUG_IN)
GIMP_MAIN (GFIG_TYPE)
GIMP_MAIN (GIMP_TYPE_GFIG)
DEFINE_STD_SET_I18N
@ -129,9 +117,12 @@ GdkPixbuf *back_pixbuf = NULL;
static void
gfig_class_init (GfigClass *klass)
gimp_gfig_class_init (GimpGfigClass *klass)
{
GimpPlugInClass *plug_in_class = GIMP_PLUG_IN_CLASS (klass);
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->finalize = gimp_gfig_finalize;
plug_in_class->query_procedures = gfig_query_procedures;
plug_in_class->create_procedure = gfig_create_procedure;
@ -139,10 +130,21 @@ gfig_class_init (GfigClass *klass)
}
static void
gfig_init (Gfig *gfig)
gimp_gfig_init (GimpGfig *gfig)
{
}
static void
gimp_gfig_finalize (GObject *object)
{
GimpGfig *gfig = GIMP_GFIG (object);
G_OBJECT_CLASS (gimp_gfig_parent_class)->finalize (object);
g_clear_object (&gfig->builder);
}
static GList *
gfig_query_procedures (GimpPlugIn *plug_in)
{
@ -203,6 +205,7 @@ gfig_run (GimpProcedure *procedure,
GimpDrawable *drawable;
GimpPDBStatusType status = GIMP_PDB_SUCCESS;
gint pwidth, pheight;
GimpGfig *gfig;
if (n_drawables != 1)
{
@ -221,6 +224,159 @@ gfig_run (GimpProcedure *procedure,
drawable = drawables[0];
}
gfig = GIMP_GFIG (gimp_procedure_get_plug_in (procedure));
gfig->app = gtk_application_new (NULL, G_APPLICATION_FLAGS_NONE);
gfig->success = FALSE;
gfig->builder = gtk_builder_new_from_string (
"<interface>"
"<menu id=\"gfig-menubar\">"
"<section>"
"<submenu>"
"<attribute name=\"label\">File</attribute>"
"<item>"
"<attribute name=\"label\" translatable=\"yes\">Open</attribute>"
"<attribute name=\"action\">app.open</attribute>"
"</item>"
"<item>"
"<attribute name=\"label\" translatable=\"yes\">Save</attribute>"
"<attribute name=\"action\">app.save</attribute>"
"</item>"
"<item>"
"<attribute name=\"label\" translatable=\"yes\">Close</attribute>"
"<attribute name=\"action\">app.close</attribute>"
"</item>"
"</submenu>"
"<submenu>"
"<attribute name=\"label\">Edit</attribute>"
"<item>"
"<attribute name=\"label\" translatable=\"yes\">Undo</attribute>"
"<attribute name=\"action\">app.undo</attribute>"
"</item>"
"<item>"
"<attribute name=\"label\" translatable=\"yes\">Clear</attribute>"
"<attribute name=\"action\">app.clear</attribute>"
"</item>"
"<item>"
"<attribute name=\"label\" translatable=\"yes\">Grid</attribute>"
"<attribute name=\"action\">app.grid</attribute>"
"</item>"
"<item>"
"<attribute name=\"label\" translatable=\"yes\">Preferences</attribute>"
"<attribute name=\"action\">app.preferences</attribute>"
"</item>"
"</submenu>"
"</section>"
"</menu>"
"<menu id=\"gfig-toolbar\">"
"<section>"
"<item>"
"<attribute name=\"label\" translatable=\"yes\">Line</attribute>"
"<attribute name=\"action\">app.shape</attribute>"
"<attribute name=\"target\">line</attribute>"
"</item>"
"<item>"
"<attribute name=\"label\" translatable=\"yes\">Rectangle</attribute>"
"<attribute name=\"action\">app.shape</attribute>"
"<attribute name=\"target\">rectangle</attribute>"
"</item>"
"<item>"
"<attribute name=\"label\" translatable=\"yes\">Circle</attribute>"
"<attribute name=\"action\">app.shape</attribute>"
"<attribute name=\"target\">circle</attribute>"
"</item>"
"<item>"
"<attribute name=\"label\" translatable=\"yes\">Ellipse</attribute>"
"<attribute name=\"action\">app.shape</attribute>"
"<attribute name=\"target\">ellipse</attribute>"
"</item>"
"<item>"
"<attribute name=\"label\" translatable=\"yes\">Arc</attribute>"
"<attribute name=\"action\">app.shape</attribute>"
"<attribute name=\"target\">arc</attribute>"
"</item>"
"<item>"
"<attribute name=\"label\" translatable=\"yes\">Polygon</attribute>"
"<attribute name=\"action\">app.shape</attribute>"
"<attribute name=\"target\">polygon</attribute>"
"</item>"
"<item>"
"<attribute name=\"label\" translatable=\"yes\">Star</attribute>"
"<attribute name=\"action\">app.shape</attribute>"
"<attribute name=\"target\">star</attribute>"
"</item>"
"<item>"
"<attribute name=\"label\" translatable=\"yes\">Spiral</attribute>"
"<attribute name=\"action\">app.shape</attribute>"
"<attribute name=\"target\">spiral</attribute>"
"</item>"
"<item>"
"<attribute name=\"label\" translatable=\"yes\">Bezier</attribute>"
"<attribute name=\"action\">app.shape</attribute>"
"<attribute name=\"target\">bezier</attribute>"
"</item>"
"<item>"
"<attribute name=\"label\" translatable=\"yes\">Move Object</attribute>"
"<attribute name=\"action\">app.shape</attribute>"
"<attribute name=\"target\">move-obj</attribute>"
"</item>"
"<item>"
"<attribute name=\"label\" translatable=\"yes\">Move Point</attribute>"
"<attribute name=\"action\">app.shape</attribute>"
"<attribute name=\"target\">move-point</attribute>"
"</item>"
"<item>"
"<attribute name=\"label\" translatable=\"yes\">Copy</attribute>"
"<attribute name=\"action\">app.shape</attribute>"
"<attribute name=\"target\">copy</attribute>"
"</item>"
"<item>"
"<attribute name=\"label\" translatable=\"yes\">Delete</attribute>"
"<attribute name=\"action\">app.shape</attribute>"
"<attribute name=\"target\">delete</attribute>"
"</item>"
"<item>"
"<attribute name=\"label\" translatable=\"yes\">Select</attribute>"
"<attribute name=\"action\">app.shape</attribute>"
"<attribute name=\"target\">select</attribute>"
"</item>"
"</section>"
"<section>"
"<item>"
"<attribute name=\"label\" translatable=\"yes\">Raise</attribute>"
"<attribute name=\"action\">app.raise</attribute>"
"</item>"
"<item>"
"<attribute name=\"label\" translatable=\"yes\">Lower</attribute>"
"<attribute name=\"action\">app.lower</attribute>"
"</item>"
"<item>"
"<attribute name=\"label\" translatable=\"yes\">Top</attribute>"
"<attribute name=\"action\">app.top</attribute>"
"</item>"
"<item>"
"<attribute name=\"label\" translatable=\"yes\">Bottom</attribute>"
"<attribute name=\"action\">app.bottom</attribute>"
"</item>"
"</section>"
"<section>"
"<item>"
"<attribute name=\"label\" translatable=\"yes\">Show Previous</attribute>"
"<attribute name=\"action\">app.show-prev</attribute>"
"</item>"
"<item>"
"<attribute name=\"label\" translatable=\"yes\">Show Next</attribute>"
"<attribute name=\"action\">app.show-next</attribute>"
"</item>"
"<item>"
"<attribute name=\"label\" translatable=\"yes\">Show All</attribute>"
"<attribute name=\"action\">app.show-all</attribute>"
"</item>"
"</section>"
"</menu>"
"</interface>",
-1);
gfig_context = g_new0 (GFigContext, 1);
gfig_context->show_background = TRUE;
@ -275,7 +431,11 @@ gfig_run (GimpProcedure *procedure,
{
case GIMP_RUN_INTERACTIVE:
case GIMP_RUN_WITH_LAST_VALS:
if (! gfig_dialog ())
g_signal_connect (gfig->app, "activate", G_CALLBACK (on_app_activate), gfig);
g_application_run (G_APPLICATION (gfig->app), 0, NULL);
g_clear_object (&gfig->app);
if (! gfig->success)
{
gimp_image_undo_group_end (gfig_context->image);
@ -302,6 +462,38 @@ gfig_run (GimpProcedure *procedure,
return gimp_procedure_new_return_values (procedure, status, NULL);
}
static void
on_app_activate (GApplication *gapp,
gpointer user_data)
{
GimpGfig *gfig = GIMP_GFIG (user_data);
gfig_dialog (gfig);
gtk_application_set_accels_for_action (gfig->app, "app.open", (const char*[]) { "<control>O", NULL });
gtk_application_set_accels_for_action (gfig->app, "app.save", (const char*[]) { "<control>S", NULL });
gtk_application_set_accels_for_action (gfig->app, "app.close", (const char*[]) { "<control>C", NULL });
gtk_application_set_accels_for_action (gfig->app, "app.undo", (const char*[]) { "<control>Z", NULL });
gtk_application_set_accels_for_action (gfig->app, "app.clear", (const char*[]) { NULL });
gtk_application_set_accels_for_action (gfig->app, "app.grid", (const char*[]) { "<control>G", NULL });
gtk_application_set_accels_for_action (gfig->app, "app.preferences", (const char*[]) { "<control>P", NULL });
gtk_application_set_accels_for_action (gfig->app, "app.shape::line", (const char*[]) { "L", NULL });
gtk_application_set_accels_for_action (gfig->app, "app.shape::rectangle", (const char*[]) { "R", NULL });
gtk_application_set_accels_for_action (gfig->app, "app.shape::circle", (const char*[]) { "C", NULL });
gtk_application_set_accels_for_action (gfig->app, "app.shape::ellipse", (const char*[]) { "E", NULL });
gtk_application_set_accels_for_action (gfig->app, "app.shape::arc", (const char*[]) { "A", NULL });
gtk_application_set_accels_for_action (gfig->app, "app.shape::polygon", (const char*[]) { "P", NULL });
gtk_application_set_accels_for_action (gfig->app, "app.shape::star", (const char*[]) { "S", NULL });
gtk_application_set_accels_for_action (gfig->app, "app.shape::spiral", (const char*[]) { "I", NULL });
gtk_application_set_accels_for_action (gfig->app, "app.shape::bezier", (const char*[]) { "B", NULL });
gtk_application_set_accels_for_action (gfig->app, "app.shape::move-obj", (const char*[]) { "M", NULL });
gtk_application_set_accels_for_action (gfig->app, "app.shape::move-point", (const char*[]) { "V", NULL });
gtk_application_set_accels_for_action (gfig->app, "app.shape::copy", (const char*[]) { "Y", NULL });
gtk_application_set_accels_for_action (gfig->app, "app.shape::delete", (const char*[]) { "D", NULL });
gtk_application_set_accels_for_action (gfig->app, "app.shape::select", (const char*[]) { "A", NULL });
}
/*
Translate SPACE to "\\040", etc.
Taken from gflare plugin
@ -414,9 +606,10 @@ gfig_new (void)
}
static void
gfig_load_objs (GFigObj *gfig,
gint load_count,
FILE *fp)
gfig_load_objs (GimpGfig *gfig,
GFigObj *gfig_obj,
gint load_count,
FILE *fp)
{
GfigObject *obj;
gchar load_buf[MAX_LOAD_LINE];
@ -437,7 +630,7 @@ gfig_load_objs (GFigObj *gfig,
if (obj)
{
add_to_all_obj (gfig, obj);
add_to_all_obj (gfig, gfig_obj, obj);
offset2 = ftell (fp);
fseek (fp, offset, SEEK_SET);
gfig_load_style (&obj->style, fp);
@ -451,10 +644,11 @@ gfig_load_objs (GFigObj *gfig,
}
GFigObj *
gfig_load (const gchar *filename,
gfig_load (GimpGfig *gfig,
const gchar *filename,
const gchar *name)
{
GFigObj *gfig;
GFigObj *gfig_obj;
FILE *fp;
gchar load_buf[MAX_LOAD_LINE];
gchar str_buf[MAX_LOAD_LINE];
@ -478,10 +672,10 @@ gfig_load (const gchar *filename,
return NULL;
}
gfig = gfig_new ();
gfig_obj = gfig_new ();
gfig->name = g_strdup (name);
gfig->filename = g_strdup (filename);
gfig_obj->name = g_strdup (name);
gfig_obj->filename = g_strdup (filename);
/* HEADER
@ -497,8 +691,8 @@ gfig_load (const gchar *filename,
if (strcmp (magic1, "GFIG") || strcmp (magic2, "Version"))
{
g_message ("File '%s' is not a gfig file",
gimp_filename_to_utf8 (gfig->filename));
gfig_free (gfig);
gimp_filename_to_utf8 (gfig_obj->filename));
gfig_free (gfig_obj);
fclose (fp);
return NULL;
}
@ -506,46 +700,46 @@ gfig_load (const gchar *filename,
get_line (load_buf, MAX_LOAD_LINE, fp, 0);
sscanf (load_buf, "Name: %100s", str_buf);
gfig_name_decode (load_buf, str_buf);
gfig->draw_name = g_strdup (load_buf);
gfig_obj->draw_name = g_strdup (load_buf);
get_line (load_buf, MAX_LOAD_LINE, fp, 0);
if (strncmp (load_buf, "Version: ", 9) == 0)
gfig->version = g_ascii_strtod (load_buf + 9, NULL);
gfig_obj->version = g_ascii_strtod (load_buf + 9, NULL);
get_line (load_buf, MAX_LOAD_LINE, fp, 0);
sscanf (load_buf, "ObjCount: %d", &load_count);
if (load_options (gfig, fp))
if (load_options (gfig_obj, fp))
{
g_message ("File '%s' corrupt file - Line %d Option section incorrect",
gimp_filename_to_utf8 (filename), line_no);
gfig_free (gfig);
gfig_free (gfig_obj);
fclose (fp);
return NULL;
}
if (gfig_load_styles (gfig, fp))
if (gfig_load_styles (gfig_obj, fp))
{
g_message ("File '%s' corrupt file - Line %d Option section incorrect",
gimp_filename_to_utf8 (filename), line_no);
gfig_free (gfig);
gfig_free (gfig_obj);
fclose (fp);
return NULL;
}
gfig_load_objs (gfig, load_count, fp);
gfig_load_objs (gfig, gfig_obj, load_count, fp);
/* Check count ? */
chk_count = g_list_length (gfig->obj_list);
chk_count = g_list_length (gfig_obj->obj_list);
if (chk_count != load_count)
{
g_message ("File '%s' corrupt file - Line %d Object count to small",
gimp_filename_to_utf8 (filename), line_no);
gfig_free (gfig);
gfig_free (gfig_obj);
fclose (fp);
return NULL;
}
@ -553,11 +747,11 @@ gfig_load (const gchar *filename,
fclose (fp);
if (!gfig_context->current_obj)
gfig_context->current_obj = gfig;
gfig_context->current_obj = gfig_obj;
gfig->obj_status = GFIG_OK;
gfig_obj->obj_status = GFIG_OK;
return gfig;
return gfig_obj;
}
void
@ -790,14 +984,14 @@ gfig_save_as_parasite (void)
}
GFigObj *
gfig_load_from_parasite (void)
gfig_load_from_parasite (GimpGfig *gfig)
{
GFile *file;
FILE *fp;
GimpParasite *parasite;
const gchar *parasite_data;
guint32 parasite_size;
GFigObj *gfig;
GFigObj *gfig_obj;
parasite = gimp_item_get_parasite (GIMP_ITEM (gfig_context->drawable),
"gfig");
@ -821,13 +1015,13 @@ gfig_load_from_parasite (void)
gimp_parasite_free (parasite);
gfig = gfig_load (g_file_peek_path (file), "(none)");
gfig_obj = gfig_load (gfig, g_file_peek_path (file), "(none)");
g_file_delete (file, NULL, NULL);
g_object_unref (file);
return gfig;
return gfig_obj;
}
void

View file

@ -31,6 +31,24 @@
#define MAX_UNDO 10
#define MIN_UNDO 1
struct _GimpGfig
{
GimpPlugIn parent_instance;
GtkApplication *app;
GtkWidget *top_level_dlg;
gboolean success;
GtkBuilder *builder;
};
#define PLUG_IN_PROC "plug-in-gfig"
#define PLUG_IN_BINARY "gfig"
#define PLUG_IN_ROLE "gimp-gfig"
#define GIMP_TYPE_GFIG (gimp_gfig_get_type ())
G_DECLARE_FINAL_TYPE (GimpGfig, gimp_gfig, GIMP, GFIG, GimpPlugIn)
typedef struct
{
gint gridspacing;
@ -59,17 +77,17 @@ typedef struct
void object_start (GdkPoint *pnt, gint);
void object_operation (GdkPoint *pnt, gint);
void object_operation_start (GdkPoint *pnt, gint shift_down);
void object_operation_start (GimpGfig *gfig,
GdkPoint *pnt,
gint shift_down);
void object_operation_end (GdkPoint *pnt, gint);
void object_end (GdkPoint *pnt, gint shift_down);
void object_end (GimpGfig *gfig,
GdkPoint *pnt,
gint shift_down);
#define MAX_LOAD_LINE 256
#define SQ_SIZE 8
#define PLUG_IN_PROC "plug-in-gfig"
#define PLUG_IN_BINARY "gfig"
#define PLUG_IN_ROLE "gimp-gfig"
extern gint line_no;
extern gint preview_width, preview_height;
extern gint need_to_scale;
@ -156,7 +174,8 @@ extern GFigContext *gfig_context;
extern selection_option selopt;
extern SelectItVals selvals;
void add_to_all_obj (GFigObj *fobj,
void add_to_all_obj (GimpGfig *gfig,
GFigObj *fobj,
GfigObject *obj);
gchar *get_line (gchar *buf,
@ -193,10 +212,11 @@ GtkWidget *num_sides_widget (const gchar *d_title,
gint adj_min,
gint adj_max);
void setup_undo (void);
void setup_undo (GimpGfig *gfig);
void draw_grid_clear (void);
void prepend_to_all_obj (GFigObj *fobj,
GList *nobj);
void prepend_to_all_obj (GimpGfig *gfig,
GFigObj *fobj,
GList *nobj);
void gfig_draw_arc (gint x,
gint y,
@ -213,7 +233,8 @@ void gfig_draw_line (gint x0,
cairo_t *cr);
void gfig_paint_callback (void);
GFigObj *gfig_load (const gchar *filename,
GFigObj *gfig_load (GimpGfig *gfig,
const gchar *filename,
const gchar *name);
void gfig_name_encode (gchar *dest,
gchar *src);
@ -228,7 +249,7 @@ void save_options (GString *string);
GString *gfig_save_as_string (void);
gboolean gfig_save_as_parasite (void);
GFigObj *gfig_load_from_parasite (void);
GFigObj *gfig_load_from_parasite (GimpGfig *gfig);
GFigObj *gfig_new (void);
void gfig_save_callbk (void);
void paint_layer_fill (gdouble x1,