gimp/plug-ins/imagemap/imap_rectangle.c

541 lines
16 KiB
C
Raw Normal View History

1999-09-07 08:03:20 +08:00
/*
* This is a plug-in for GIMP.
1999-09-07 08:03:20 +08:00
*
* Generates clickable image maps.
*
* Copyright (C) 1998-2004 Maurits Rijk m.rijk@chello.nl
1999-09-07 08:03:20 +08:00
*
* This program is free software: you can redistribute it and/or modify
1999-09-07 08:03:20 +08:00
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
1999-09-07 08:03:20 +08:00
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1999-09-07 08:03:20 +08:00
*
*/
2000-02-17 16:36:46 +08:00
#include "config.h"
#include <stdlib.h> /* abs */
app/gimpprogress.c app/nav_window.c app/ops_buttons.c app/undo_history.c 2001-12-29 Michael Natterer <mitch@gimp.org> * app/gimpprogress.c * app/nav_window.c * app/ops_buttons.c * app/undo_history.c * app/display/gimpdisplayshell.c * app/gui/about-dialog.c * app/gui/brush-editor.c * app/gui/channels-commands.c * app/gui/color-area.c * app/gui/color-notebook.c * app/gui/color-select.c * app/gui/colormap-dialog.c * app/gui/convert-dialog.c * app/gui/device-status-dialog.c * app/gui/file-new-dialog.c * app/gui/file-open-dialog.c * app/gui/file-save-dialog.c * app/gui/gradient-editor.c * app/gui/info-dialog.c * app/gui/layers-commands.c * app/gui/module-browser.c * app/gui/offset-dialog.c * app/gui/palette-editor.c * app/gui/palettes-commands.c * app/gui/paths-dialog.c * app/gui/qmask-commands.c * app/gui/resize-dialog.c * app/gui/resolution-calibrate-dialog.c * app/gui/splash.c * app/gui/tips-dialog.c * app/gui/toolbox.c * app/gui/user-install-dialog.c * app/tools/gimpbrightnesscontrasttool.c * app/tools/gimpbycolorselecttool.c * app/tools/gimpcolorbalancetool.c * app/tools/gimpcolorpickertool.c * app/tools/gimpcroptool.c * app/tools/gimpcurvestool.c * app/tools/gimphuesaturationtool.c * app/tools/gimpinktool.c * app/tools/gimplevelstool.c * app/tools/gimpposterizetool.c * app/tools/gimprotatetool.c * app/tools/gimpthresholdtool.c * app/tools/paint_options.c * app/tools/selection_options.c * app/widgets/gimpchannellistview.c * app/widgets/gimpcolorpanel.c * app/widgets/gimpcomponentlistitem.c * app/widgets/gimpconstrainedhwrapbox.c * app/widgets/gimpcontainergridview.c * app/widgets/gimpcontainerlistview.c * app/widgets/gimpcontainermenuimpl.c * app/widgets/gimpdialogfactory.c * app/widgets/gimpdnd.c * app/widgets/gimpdock.c * app/widgets/gimpdockbook.c * app/widgets/gimpdrawablelistitem.c * app/widgets/gimpdrawablelistview.c * app/widgets/gimpfontselection-dialog.c * app/widgets/gimphistogramview.c * app/widgets/gimpitemfactory.c * app/widgets/gimplayerlistitem.c * app/widgets/gimplistitem.[ch] * app/widgets/gimpmenuitem.c * app/widgets/gimppreview.[ch] * app/widgets/gtkhwrapbox.c * app/widgets/gtkvwrapbox.c * app/widgets/gtkwrapbox.c * libgimp/gimpbrushmenu.c * libgimp/gimpexport.c * libgimp/gimpgradientmenu.c * libgimp/gimpmenu.c * libgimp/gimppatternmenu.c * libgimpwidgets/gimpbutton.c * libgimpwidgets/gimpchainbutton.[ch] * libgimpwidgets/gimpcolorarea.h * libgimpwidgets/gimpcolorbutton.c * libgimpwidgets/gimpfileselection.c * libgimpwidgets/gimphelpui.c * libgimpwidgets/gimpoffsetarea.c * libgimpwidgets/gimppatheditor.c * libgimpwidgets/gimppixmap.h * libgimpwidgets/gimpquerybox.c * libgimpwidgets/gimpstock.[ch] * libgimpwidgets/gimpwidgets.h * plug-ins/FractalExplorer/Dialogs.c * plug-ins/FractalExplorer/Events.c * plug-ins/FractalExplorer/FractalExplorer.c * plug-ins/Lighting/lighting_ui.c * plug-ins/MapObject/mapobject_ui.c * plug-ins/bmp/bmpwrite.c * plug-ins/dbbrowser/dbbrowser_utils.c * plug-ins/fits/fits.c * plug-ins/flame/flame.c * plug-ins/fp/fp_gtk.c * plug-ins/fp/fp_misc.c * plug-ins/gfig/gfig.c * plug-ins/gflare/gflare.c * plug-ins/gfli/gfli.c * plug-ins/gimpressionist/*.c * plug-ins/imagemap/*.[ch] * plug-ins/maze/maze_face.c * plug-ins/mosaic/mosaic.c * plug-ins/pagecurl/pagecurl.c * plug-ins/print/print_gimp.h * plug-ins/rcm/rcm_callback.c * plug-ins/rcm/rcm_dialog.c * plug-ins/rcm/rcm_misc.c * plug-ins/script-fu/script-fu-console.c * plug-ins/script-fu/script-fu-scripts.c * plug-ins/script-fu/script-fu-server.c * plug-ins/sel2path/sel2path.c * plug-ins/sel2path/sel2path_adv_dialog.c * plug-ins/sgi/sgi.c * plug-ins/webbrowser/webbrowser.c * plug-ins/xjt/xjt.c * plug-ins/common/[A-n]*.c: compile with GTK_DISABLE_DEPRECATED defined. Not everything is fully ported yet, had to #undef GTK_DISABLE_DEPRECATED in many places and added #warnings when doing so. * pixmaps/Makefile.am * pixmaps/chain.xpm: removed. * themes/Default/Makefile.am * themes/Default/images/Makefile.am * themes/Default/images/stock-button-hchain-broken.png * themes/Default/images/stock-button-hchain.png * themes/Default/images/stock-button-vchain-broken.png * themes/Default/images/stock-button-vchain.png: new stock icons.
2001-12-29 21:26:29 +08:00
#include <gtk/gtk.h>
#include <libgimp/gimp.h>
#include <libgimp/gimpui.h>
1999-09-07 08:03:20 +08:00
#include "imap_main.h"
#include "imap_misc.h"
#include "imap_object_popup.h"
#include "imap_rectangle.h"
#include "imap_stock.h"
1999-09-07 08:03:20 +08:00
#include "imap_table.h"
#include "libgimp/stdplugins-intl.h"
1999-09-07 08:03:20 +08:00
static gboolean rectangle_is_valid(Object_t *obj);
static Object_t *rectangle_clone(Object_t *obj);
1999-10-25 04:57:17 +08:00
static void rectangle_assign(Object_t *obj, Object_t *des);
1999-09-07 08:03:20 +08:00
static void rectangle_normalize(Object_t *obj);
2011-02-21 22:45:26 +08:00
static void rectangle_draw(Object_t *obj, cairo_t *cr);
static void rectangle_draw_sashes(Object_t *obj, cairo_t *cr);
1999-09-07 08:03:20 +08:00
static MoveSashFunc_t rectangle_near_sash(Object_t *obj, gint x, gint y);
static gboolean rectangle_point_is_on(Object_t *obj, gint x, gint y);
static void rectangle_get_dimensions(Object_t *obj, gint *x, gint *y,
2011-02-21 18:51:47 +08:00
gint *width, gint *height);
static void rectangle_resize(Object_t *obj, gint percentage_x,
2011-02-21 18:51:47 +08:00
gint percentage_y);
1999-09-07 08:03:20 +08:00
static void rectangle_move(Object_t *obj, gint dx, gint dy);
1999-10-25 04:57:17 +08:00
static gpointer rectangle_create_info_widget(GtkWidget *frame);
1999-09-07 08:03:20 +08:00
static void rectangle_fill_info_tab(Object_t *obj, gpointer data);
static void rectangle_set_initial_focus(Object_t *obj, gpointer data);
static void rectangle_update(Object_t *obj, gpointer data);
static void rectangle_write_csim(Object_t *obj, gpointer param,
2011-02-21 18:51:47 +08:00
OutputFunc_t output);
static void rectangle_write_cern(Object_t *obj, gpointer param,
2011-02-21 18:51:47 +08:00
OutputFunc_t output);
static void rectangle_write_ncsa(Object_t *obj, gpointer param,
2011-02-21 18:51:47 +08:00
OutputFunc_t output);
static const gchar* rectangle_get_stock_icon_name(void);
1999-09-07 08:03:20 +08:00
static ObjectClass_t rectangle_class = {
N_("_Rectangle"),
2011-02-21 18:51:47 +08:00
NULL, /* info_dialog */
NULL, /* icon */
NULL, /* mask */
1999-09-07 08:03:20 +08:00
rectangle_is_valid,
2011-02-21 18:51:47 +08:00
NULL, /* rectangle_destruct */
1999-09-07 08:03:20 +08:00
rectangle_clone,
rectangle_assign,
rectangle_normalize,
rectangle_draw,
rectangle_draw_sashes,
rectangle_near_sash,
rectangle_point_is_on,
rectangle_get_dimensions,
rectangle_resize,
rectangle_move,
1999-10-25 04:57:17 +08:00
rectangle_create_info_widget,
2011-02-21 18:51:47 +08:00
rectangle_fill_info_tab, /* rectangle_update_info_widget */
1999-09-07 08:03:20 +08:00
rectangle_fill_info_tab,
rectangle_set_initial_focus,
rectangle_update,
rectangle_write_csim,
rectangle_write_cern,
rectangle_write_ncsa,
object_do_popup,
rectangle_get_stock_icon_name
1999-09-07 08:03:20 +08:00
};
Object_t*
create_rectangle(gint x, gint y, gint width, gint height)
{
Rectangle_t *rectangle = g_new(Rectangle_t, 1);
rectangle->x = x;
rectangle->y = y;
rectangle->width = width;
rectangle->height = height;
return object_init(&rectangle->obj, &rectangle_class);
}
static void
2011-02-21 22:45:26 +08:00
draw_any_rectangle(cairo_t *cr, gint x, gint y, gint w, gint h)
1999-09-07 08:03:20 +08:00
{
if (w < 0) {
x += w;
w = -w;
}
if (h < 0) {
y += h;
h = -h;
}
2011-02-21 22:45:26 +08:00
draw_rectangle(cr, FALSE, x, y, w, h);
1999-09-07 08:03:20 +08:00
}
static gboolean
rectangle_is_valid(Object_t *obj)
{
Rectangle_t *rectangle = ObjectToRectangle(obj);
return rectangle->width && rectangle->height;
}
static Object_t*
rectangle_clone(Object_t *obj)
{
Rectangle_t *rectangle = ObjectToRectangle(obj);
Rectangle_t *clone = g_new(Rectangle_t, 1);
clone->x = rectangle->x;
clone->y = rectangle->y;
clone->width = rectangle->width;
clone->height = rectangle->height;
return &clone->obj;
}
1999-10-25 04:57:17 +08:00
static void
1999-09-07 08:03:20 +08:00
rectangle_assign(Object_t *obj, Object_t *des)
{
Rectangle_t *src_rectangle = ObjectToRectangle(obj);
Rectangle_t *des_rectangle = ObjectToRectangle(des);
des_rectangle->x = src_rectangle->x;
des_rectangle->y = src_rectangle->y;
des_rectangle->width = src_rectangle->width;
des_rectangle->height = src_rectangle->height;
}
static void
rectangle_normalize(Object_t *obj)
{
Rectangle_t *rectangle = ObjectToRectangle(obj);
if (rectangle->width < 0) {
rectangle->x += rectangle->width;
rectangle->width = -rectangle->width;
}
if (rectangle->height < 0) {
rectangle->y += rectangle->height;
rectangle->height = -rectangle->height;
}
}
static void
2011-02-21 22:45:26 +08:00
rectangle_draw(Object_t *obj, cairo_t *cr)
1999-09-07 08:03:20 +08:00
{
Rectangle_t *rectangle = ObjectToRectangle(obj);
2011-02-21 22:45:26 +08:00
draw_any_rectangle(cr, rectangle->x, rectangle->y,
2011-02-21 18:51:47 +08:00
rectangle->width, rectangle->height);
1999-09-07 08:03:20 +08:00
}
static void
2011-02-21 22:45:26 +08:00
rectangle_draw_sashes(Object_t *obj, cairo_t *cr)
1999-09-07 08:03:20 +08:00
{
Rectangle_t *rectangle = ObjectToRectangle(obj);
2011-02-21 22:45:26 +08:00
draw_sash(cr, rectangle->x, rectangle->y);
draw_sash(cr, rectangle->x + rectangle->width / 2, rectangle->y);
draw_sash(cr, rectangle->x + rectangle->width, rectangle->y);
draw_sash(cr, rectangle->x, rectangle->y + rectangle->height / 2);
draw_sash(cr, rectangle->x + rectangle->width,
2011-02-21 18:51:47 +08:00
rectangle->y + rectangle->height / 2);
2011-02-21 22:45:26 +08:00
draw_sash(cr, rectangle->x, rectangle->y + rectangle->height);
draw_sash(cr, rectangle->x + rectangle->width / 2,
2011-02-21 18:51:47 +08:00
rectangle->y + rectangle->height);
2011-02-21 22:45:26 +08:00
draw_sash(cr, rectangle->x + rectangle->width,
2011-02-21 18:51:47 +08:00
rectangle->y + rectangle->height);
1999-09-07 08:03:20 +08:00
}
static void
MoveUpperSash(Object_t *obj, gint dx, gint dy)
{
Rectangle_t *rectangle = ObjectToRectangle(obj);
rectangle->y += dy;
rectangle->height -= dy;
}
static void
MoveLeftSash(Object_t *obj, gint dx, gint dy)
{
Rectangle_t *rectangle = ObjectToRectangle(obj);
rectangle->x += dx;
rectangle->width -= dx;
}
static void
MoveRightSash(Object_t *obj, gint dx, gint dy)
{
Rectangle_t *rectangle = ObjectToRectangle(obj);
rectangle->width += dx;
}
static void
MoveLowerSash(Object_t *obj, gint dx, gint dy)
{
Rectangle_t *rectangle = ObjectToRectangle(obj);
rectangle->height += dy;
}
static void
MoveUpperLeftSash(Object_t *obj, gint dx, gint dy)
{
Rectangle_t *rectangle = ObjectToRectangle(obj);
rectangle->x += dx;
rectangle->y += dy;
rectangle->width -= dx;
rectangle->height -= dy;
}
static void
MoveUpperRightSash(Object_t *obj, gint dx, gint dy)
{
Rectangle_t *rectangle = ObjectToRectangle(obj);
rectangle->y += dy;
rectangle->width += dx;
rectangle->height -= dy;
}
static void
MoveLowerLeftSash(Object_t *obj, gint dx, gint dy)
{
Rectangle_t *rectangle = ObjectToRectangle(obj);
rectangle->x += dx;
rectangle->width -= dx;
rectangle->height += dy;
}
static void
MoveLowerRightSash(Object_t *obj, gint dx, gint dy)
{
Rectangle_t *rectangle = ObjectToRectangle(obj);
rectangle->width += dx;
rectangle->height += dy;
}
static MoveSashFunc_t
rectangle_near_sash(Object_t *obj, gint x, gint y)
{
Rectangle_t *rectangle = ObjectToRectangle(obj);
if (near_sash(rectangle->x, rectangle->y, x, y))
return MoveUpperLeftSash;
1999-09-07 08:03:20 +08:00
else if (near_sash(rectangle->x + rectangle->width / 2, rectangle->y, x, y))
return MoveUpperSash;
1999-09-07 08:03:20 +08:00
else if (near_sash(rectangle->x + rectangle->width, rectangle->y, x, y))
return MoveUpperRightSash;
else if (near_sash(rectangle->x, rectangle->y + rectangle->height / 2,
2011-02-21 18:51:47 +08:00
x, y))
return MoveLeftSash;
else if (near_sash(rectangle->x + rectangle->width,
2011-02-21 18:51:47 +08:00
rectangle->y + rectangle->height / 2, x, y))
return MoveRightSash;
1999-09-07 08:03:20 +08:00
else if (near_sash(rectangle->x, rectangle->y + rectangle->height, x, y))
return MoveLowerLeftSash;
else if (near_sash(rectangle->x + rectangle->width / 2,
2011-02-21 18:51:47 +08:00
rectangle->y + rectangle->height, x, y))
return MoveLowerSash;
else if (near_sash(rectangle->x + rectangle->width,
2011-02-21 18:51:47 +08:00
rectangle->y + rectangle->height, x, y))
return MoveLowerRightSash;
1999-09-07 08:03:20 +08:00
return NULL;
}
static gboolean
rectangle_point_is_on(Object_t *obj, gint x, gint y)
{
Rectangle_t *rectangle = ObjectToRectangle(obj);
return x >= rectangle->x && x <= rectangle->x + rectangle->width &&
y >= rectangle->y && y <= rectangle->y + rectangle->height;
}
static void
1999-09-07 08:03:20 +08:00
rectangle_get_dimensions(Object_t *obj, gint *x, gint *y,
2011-02-21 18:51:47 +08:00
gint *width, gint *height)
1999-09-07 08:03:20 +08:00
{
Rectangle_t *rectangle = ObjectToRectangle(obj);
*x = rectangle->x;
*y = rectangle->y;
*width = rectangle->width;
*height = rectangle->height;
}
static void
1999-09-07 08:03:20 +08:00
rectangle_resize(Object_t *obj, gint percentage_x, gint percentage_y)
{
Rectangle_t *rectangle = ObjectToRectangle(obj);
rectangle->x = rectangle->x * percentage_x / 100;
rectangle->y = rectangle->y * percentage_y / 100;
rectangle->width = rectangle->width * percentage_x / 100;
rectangle->height = rectangle->height * percentage_y / 100;
}
static void
rectangle_move(Object_t *obj, gint dx, gint dy)
{
Rectangle_t *rectangle = ObjectToRectangle(obj);
rectangle->x += dx;
rectangle->y += dy;
}
typedef struct {
Object_t *obj;
GtkWidget *x;
GtkWidget *y;
GtkWidget *width;
GtkWidget *height;
GtkWidget *chain_button;
1999-09-07 08:03:20 +08:00
} RectangleProperties_t;
static void
x_changed_cb(GtkWidget *widget, gpointer data)
{
RectangleProperties_t *props = (RectangleProperties_t*) data;
Object_t *obj = props->obj;
1999-09-07 08:03:20 +08:00
gint x = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(widget));
if (gimp_chain_button_get_active(GIMP_CHAIN_BUTTON(props->chain_button)))
gtk_spin_button_set_value(GTK_SPIN_BUTTON(props->y), x);
1999-09-07 08:03:20 +08:00
ObjectToRectangle(obj)->x = x;
1999-10-25 04:57:17 +08:00
edit_area_info_dialog_emit_geometry_signal(obj->class->info_dialog);
}
static void
y_changed_cb(GtkWidget *widget, gpointer data)
{
Object_t *obj = ((RectangleProperties_t*) data)->obj;
gint y = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(widget));
ObjectToRectangle(obj)->y = y;
edit_area_info_dialog_emit_geometry_signal(obj->class->info_dialog);
}
static void
width_changed_cb(GtkWidget *widget, gpointer data)
{
Object_t *obj = ((RectangleProperties_t*) data)->obj;
gint width = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(widget));
ObjectToRectangle(obj)->width = width;
edit_area_info_dialog_emit_geometry_signal(obj->class->info_dialog);
}
static void
height_changed_cb(GtkWidget *widget, gpointer data)
{
Object_t *obj = ((RectangleProperties_t*) data)->obj;
gint height = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(widget));
ObjectToRectangle(obj)->height = height;
edit_area_info_dialog_emit_geometry_signal(obj->class->info_dialog);
1999-09-07 08:03:20 +08:00
}
static gpointer
1999-10-25 04:57:17 +08:00
rectangle_create_info_widget(GtkWidget *frame)
1999-09-07 08:03:20 +08:00
{
RectangleProperties_t *props = g_new(RectangleProperties_t, 1);
GtkWidget *table, *label, *chain_button;
1999-09-07 08:03:20 +08:00
gint max_width = get_image_width();
gint max_height = get_image_height();
table = gtk_table_new(4, 4, FALSE);
1999-10-25 04:57:17 +08:00
gtk_container_add(GTK_CONTAINER(frame), table);
1999-09-07 08:03:20 +08:00
gtk_table_set_row_spacings(GTK_TABLE(table), 6);
gtk_table_set_col_spacings(GTK_TABLE(table), 6);
1999-09-07 08:03:20 +08:00
gtk_widget_show(table);
label = create_label_in_table(table, 0, 0, _("Upper left _x:"));
props->x = create_spin_button_in_table(table, label, 0, 1, 1, 0,
2011-02-21 18:51:47 +08:00
max_width - 1);
g_signal_connect(props->x, "value-changed",
2011-02-21 18:51:47 +08:00
G_CALLBACK(x_changed_cb), (gpointer) props);
create_label_in_table(table, 0, 3, _("pixels"));
label = create_label_in_table(table, 1, 0, _("Upper left _y:"));
props->y = create_spin_button_in_table(table, label, 1, 1, 1, 0,
2011-02-21 18:51:47 +08:00
max_height - 1);
g_signal_connect(props->y, "value-changed",
2011-02-21 18:51:47 +08:00
G_CALLBACK(y_changed_cb), (gpointer) props);
create_label_in_table(table, 1, 3, _("pixels"));
label = create_label_in_table(table, 2, 0, _("_Width:"));
props->width = create_spin_button_in_table(table, label, 2, 1, 1, 1,
2011-02-21 18:51:47 +08:00
max_width);
g_signal_connect(props->width, "value-changed",
2011-02-21 18:51:47 +08:00
G_CALLBACK(width_changed_cb), (gpointer) props);
create_label_in_table(table, 2, 3, _("pixels"));
label = create_label_in_table(table, 3, 0, _("_Height:"));
props->height = create_spin_button_in_table(table, label, 3, 1, 1, 1,
2011-02-21 18:51:47 +08:00
max_height);
g_signal_connect(props->height, "value-changed",
2011-02-21 18:51:47 +08:00
G_CALLBACK(height_changed_cb), (gpointer) props);
create_label_in_table(table, 3, 3, _("pixels"));
chain_button = gimp_chain_button_new(GIMP_CHAIN_RIGHT);
props->chain_button = chain_button;
gtk_table_attach_defaults(GTK_TABLE(table), chain_button, 2, 3, 2, 4);
gtk_widget_show(chain_button);
1999-09-07 08:03:20 +08:00
return props;
}
static void
1999-09-07 08:03:20 +08:00
rectangle_fill_info_tab(Object_t *obj, gpointer data)
{
Rectangle_t *rectangle = ObjectToRectangle(obj);
RectangleProperties_t *props = (RectangleProperties_t*) data;
props->obj = obj;
gtk_spin_button_set_value(GTK_SPIN_BUTTON(props->x), rectangle->x);
gtk_spin_button_set_value(GTK_SPIN_BUTTON(props->y), rectangle->y);
gtk_spin_button_set_value(GTK_SPIN_BUTTON(props->width), rectangle->width);
gtk_spin_button_set_value(GTK_SPIN_BUTTON(props->height),
2011-02-21 18:51:47 +08:00
rectangle->height);
1999-09-07 08:03:20 +08:00
}
static void
1999-09-07 08:03:20 +08:00
rectangle_set_initial_focus(Object_t *obj, gpointer data)
{
RectangleProperties_t *props = (RectangleProperties_t*) data;
gtk_widget_grab_focus(props->x);
}
static void
1999-09-07 08:03:20 +08:00
rectangle_update(Object_t* obj, gpointer data)
{
Rectangle_t *rectangle = ObjectToRectangle(obj);
RectangleProperties_t *props = (RectangleProperties_t*) data;
rectangle->x = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(props->x));
rectangle->y = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(props->y));
rectangle->width = gtk_spin_button_get_value_as_int(
GTK_SPIN_BUTTON(props->width));
rectangle->height = gtk_spin_button_get_value_as_int(
GTK_SPIN_BUTTON(props->height));
}
static void
rectangle_write_csim(Object_t *obj, gpointer param, OutputFunc_t output)
{
Rectangle_t *rectangle = ObjectToRectangle(obj);
output(param, "\"rect\" coords=\"%d,%d,%d,%d\"", rectangle->x, rectangle->y,
2011-02-21 18:51:47 +08:00
rectangle->x + rectangle->width, rectangle->y + rectangle->height);
1999-09-07 08:03:20 +08:00
}
static void
rectangle_write_cern(Object_t *obj, gpointer param, OutputFunc_t output)
{
Rectangle_t *rectangle = ObjectToRectangle(obj);
output(param, "rect (%d,%d) (%d,%d)", rectangle->x, rectangle->y,
2011-02-21 18:51:47 +08:00
rectangle->x + rectangle->width, rectangle->y + rectangle->height);
1999-09-07 08:03:20 +08:00
}
static void
rectangle_write_ncsa(Object_t *obj, gpointer param, OutputFunc_t output)
{
Rectangle_t *rectangle = ObjectToRectangle(obj);
output(param, "rect %s %d,%d %d,%d", obj->url,
2011-02-21 18:51:47 +08:00
rectangle->x, rectangle->y,
rectangle->x + rectangle->width, rectangle->y + rectangle->height);
1999-09-07 08:03:20 +08:00
}
static const gchar*
rectangle_get_stock_icon_name(void)
1999-09-07 08:03:20 +08:00
{
return IMAP_STOCK_RECTANGLE;
1999-09-07 08:03:20 +08:00
}
static gboolean
rectangle_factory_finish(Object_t *obj, gint x, gint y)
{
Rectangle_t *rectangle = ObjectToRectangle(obj);
rectangle->width = x - rectangle->x;
rectangle->height = y - rectangle->y;
rectangle_normalize(obj);
return TRUE;
}
1999-09-07 08:03:20 +08:00
static Object_t*
rectangle_factory_create_object(gint x, gint y)
{
return create_rectangle(x, y, 0, 0);
}
static void
rectangle_factory_set_xy(Object_t *obj, guint state, gint x, gint y)
{
Rectangle_t *rectangle = ObjectToRectangle(obj);
rectangle->width = x - rectangle->x;
rectangle->height = y - rectangle->y;
if (state & GDK_SHIFT_MASK){
gint width = abs(rectangle->width);
gint height = abs(rectangle->height);
if (width < height)
2011-02-21 18:51:47 +08:00
rectangle->height = (rectangle->height < 0) ? -width : width;
1999-09-07 08:03:20 +08:00
else
2011-02-21 18:51:47 +08:00
rectangle->width = (rectangle->width < 0) ? -height : height;
1999-09-07 08:03:20 +08:00
}
main_set_dimension(rectangle->width, rectangle->height);
}
static ObjectFactory_t rectangle_factory = {
2011-02-21 18:51:47 +08:00
NULL, /* Object pointer */
rectangle_factory_finish,
2011-02-21 18:51:47 +08:00
NULL, /* Cancel func */
1999-09-07 08:03:20 +08:00
rectangle_factory_create_object,
rectangle_factory_set_xy
};
ObjectFactory_t*
get_rectangle_factory(guint state)
{
return &rectangle_factory;
}