1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205
|
/* The GIMP -- an image manipulation program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (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, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include <stdlib.h>
#include "appenv.h"
#include "gdisplay.h"
#include "tools.h"
#include "perspective_tool.h"
#include "rotate_tool.h"
#include "scale_tool.h"
#include "shear_tool.h"
#include "transform_tool.h"
typedef struct _TransformOptions TransformOptions;
struct _TransformOptions
{
int smoothing;
ToolType type;
};
/* local functions */
static void transform_change_type (int);
/* Static variables */
static TransformOptions *transform_options = NULL;
static void
transform_toggle_update (GtkWidget *w,
gpointer data)
{
int *toggle_val;
toggle_val = (int *) data;
if (GTK_TOGGLE_BUTTON (w)->active)
*toggle_val = TRUE;
else
*toggle_val = FALSE;
}
static void
transform_type_callback (GtkWidget *w,
gpointer client_data)
{
transform_change_type ((long) client_data);
}
static TransformOptions *
create_transform_options (void)
{
TransformOptions *options;
GtkWidget *vbox;
GtkWidget *label;
GtkWidget *radio_frame;
GtkWidget *radio_box;
GtkWidget *radio_button;
GtkWidget *smoothing_toggle;
GSList *group = NULL;
int i;
char *button_names[4] =
{
"Rotation",
"Scaling",
"Shearing",
"Perspective"
};
/* the new options structure */
options = (TransformOptions *) g_malloc (sizeof (TransformOptions));
options->smoothing = 1;
options->type = ROTATE;
/* the main vbox */
vbox = gtk_vbox_new (FALSE, 1);
/* the main label */
label = gtk_label_new ("Transform Tool Options");
gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
gtk_widget_show (label);
/* the radio frame and box */
radio_frame = gtk_frame_new ("Transform");
gtk_box_pack_start (GTK_BOX (vbox), radio_frame, FALSE, FALSE, 0);
radio_box = gtk_vbox_new (FALSE, 1);
gtk_container_add (GTK_CONTAINER (radio_frame), radio_box);
/* the radio buttons */
for (i = 0; i < 4; i++)
{
radio_button = gtk_radio_button_new_with_label (group, button_names[i]);
group = gtk_radio_button_group (GTK_RADIO_BUTTON (radio_button));
gtk_box_pack_start (GTK_BOX (radio_box), radio_button, FALSE, FALSE, 0);
gtk_signal_connect (GTK_OBJECT (radio_button), "toggled",
(GtkSignalFunc) transform_type_callback,
(gpointer) ((long) ROTATE + i));
gtk_widget_show (radio_button);
}
gtk_widget_show (radio_box);
gtk_widget_show (radio_frame);
/* the smoothing toggle button */
smoothing_toggle = gtk_check_button_new_with_label ("Smoothing");
gtk_box_pack_start (GTK_BOX (vbox), smoothing_toggle, FALSE, FALSE, 0);
gtk_signal_connect (GTK_OBJECT (smoothing_toggle), "toggled",
(GtkSignalFunc) transform_toggle_update,
&options->smoothing);
gtk_toggle_button_set_state (GTK_TOGGLE_BUTTON (smoothing_toggle),
options->smoothing);
gtk_widget_show (smoothing_toggle);
/* Register this selection options widget with the main tools options dialog */
tools_register_options (ROTATE, vbox);
tools_register_options (SCALE, vbox);
tools_register_options (SHEAR, vbox);
tools_register_options (PERSPECTIVE, vbox);
return options;
}
Tool *
tools_new_transform_tool ()
{
if (! transform_options)
transform_options = create_transform_options ();
switch (transform_options->type)
{
case ROTATE:
return tools_new_rotate_tool ();
break;
case SCALE:
return tools_new_scale_tool ();
break;
case SHEAR:
return tools_new_shear_tool ();
break;
case PERSPECTIVE:
return tools_new_perspective_tool ();
break;
default :
return NULL;
break;
}
}
void
tools_free_transform_tool (Tool *tool)
{
switch (transform_options->type)
{
case ROTATE:
tools_free_rotate_tool (tool);
break;
case SCALE:
tools_free_scale_tool (tool);
break;
case SHEAR:
tools_free_shear_tool (tool);
break;
case PERSPECTIVE:
tools_free_perspective_tool (tool);
break;
default:
break;
}
}
static void
transform_change_type (int new_type)
{
if (transform_options->type != new_type)
{
/* change the type, free the old tool, create the new tool */
transform_options->type = new_type;
tools_select (transform_options->type);
}
}
int
transform_tool_smoothing ()
{
if (!transform_options)
return 1;
else
return transform_options->smoothing;
}
|