Commit e9363dbc authored by Sven Neumann's avatar Sven Neumann

A few fixes to the new transform tool UI.


--Sven
parent abdd2e56
Fri Aug 14 16:40:30 MEST 1998 Sven Neumann <sven@gimp.org>
* app/transform_tool.c
* app/transform_core.[ch]: Added a "Show grid" toggle. Fixed a
problem that occured when changing the grid size before the tool
is created. Don't draw the grid if the perspective trafo is too
weird.
Thu Aug 13 23:00:39 EDT 1998 Adrian Likins <adrian@gimp.org>
* plug-ins/script-fu/scripts: tileblur.scm, title-header.scm,
......
......@@ -245,7 +245,8 @@ transform_core_button_press (tool, bevent, gdisp_ptr)
transform_core_bounds (tool, gdisp_ptr);
/* Calculate the grid line endpoints */
transform_core_setup_grid (tool);
if (transform_tool_show_grid ())
transform_core_setup_grid (tool);
/* Initialize the transform tool */
(* transform_core->trans_func) (tool, gdisp_ptr, INIT);
......@@ -601,22 +602,30 @@ transform_core_draw (tool)
gdk_draw_line (transform_core->core->win, transform_core->core->gc,
x3, y3, x1, y1);
/* Draw the grid */
/* Draw the grid */
gci = 0;
k = transform_core->ngx + transform_core->ngy;
for (i = 0; i < k; i++)
if ((transform_core->grid_coords != NULL) &&
(transform_core->tgrid_coords != NULL) &&
((tool->type != PERSPECTIVE) ||
(transform_core->transform[0][0] >=0.0) &&
(transform_core->transform[1][1] >=0.0)))
{
gdisplay_transform_coords (gdisp, transform_core->tgrid_coords[gci],
transform_core->tgrid_coords[gci+1],
&xa, &ya, 0);
gdisplay_transform_coords (gdisp, transform_core->tgrid_coords[gci+2],
transform_core->tgrid_coords[gci+3],
&xb, &yb, 0);
gci = 0;
k = transform_core->ngx + transform_core->ngy;
for (i = 0; i < k; i++)
{
gdisplay_transform_coords (gdisp, transform_core->tgrid_coords[gci],
transform_core->tgrid_coords[gci+1],
&xa, &ya, 0);
gdisplay_transform_coords (gdisp, transform_core->tgrid_coords[gci+2],
transform_core->tgrid_coords[gci+3],
&xb, &yb, 0);
gdk_draw_line (transform_core->core->win, transform_core->core->gc,
xa, ya, xb, yb);
gci += 4;
gdk_draw_line (transform_core->core->win, transform_core->core->gc,
xa, ya, xb, yb);
gci += 4;
}
}
/* draw the tool handles */
......@@ -713,9 +722,11 @@ transform_core_free (tool)
info_dialog_free (transform_info);
transform_info = NULL;
/* Free the grid line endpoint arrays */
g_free (transform_core->grid_coords);
g_free (transform_core->tgrid_coords);
/* Free the grid line endpoint arrays if they exist */
if (transform_core->grid_coords != NULL)
g_free (transform_core->grid_coords);
if (transform_core->tgrid_coords != NULL)
g_free (transform_core->tgrid_coords);
/* Finally, free the transform tool itself */
g_free (transform_core);
......@@ -749,16 +760,20 @@ transform_bounding_box (tool)
transform_core->cx, transform_core->cy,
&transform_core->tcx, &transform_core->tcy);
gci = 0;
k = (transform_core->ngx + transform_core->ngy) * 2;
for (i = 0; i < k; i++)
if (transform_core->grid_coords != NULL &&
transform_core->tgrid_coords != NULL)
{
transform_point (transform_core->transform,
transform_core->grid_coords[gci],
transform_core->grid_coords[gci+1],
&(transform_core->tgrid_coords[gci]),
&(transform_core->tgrid_coords[gci+1]));
gci += 2;
gci = 0;
k = (transform_core->ngx + transform_core->ngy) * 2;
for (i = 0; i < k; i++)
{
transform_point (transform_core->transform,
transform_core->grid_coords[gci],
transform_core->grid_coords[gci+1],
&(transform_core->tgrid_coords[gci]),
&(transform_core->tgrid_coords[gci+1]));
gci += 2;
}
}
}
......@@ -1019,10 +1034,23 @@ transform_core_grid_density_changed ()
TransformCore * transform_core;
transform_core = (TransformCore *) active_tool->private;
if (transform_core->function == CREATING)
return;
draw_core_pause (transform_core->core, active_tool);
g_free (transform_core->grid_coords);
g_free (transform_core->tgrid_coords);
transform_core_setup_grid (active_tool);
if (transform_core->grid_coords != NULL)
{
g_free (transform_core->grid_coords);
transform_core->grid_coords = NULL;
}
if (transform_core->tgrid_coords != NULL)
{
g_free (transform_core->tgrid_coords);
transform_core->tgrid_coords = NULL;
}
if (transform_tool_show_grid())
transform_core_setup_grid (active_tool);
transform_bounding_box (active_tool);
draw_core_resume (transform_core->core, active_tool);
}
......@@ -1037,8 +1065,8 @@ transform_core_setup_grid (tool)
transform_core = (TransformCore *) tool->private;
/* We use the transform_tool_grid_size function only here, even if the
* user changes the grid size in the middle of a
/* We use the transform_tool_grid_size function only here, even
* if the user changes the grid size in the middle of an
* operation, nothing happens.
*/
transform_core->ngx =
......@@ -1055,7 +1083,7 @@ transform_core_setup_grid (tool)
transform_core->tgrid_coords = (double *)
g_malloc ((transform_core->ngx + transform_core->ngy) * 4
* sizeof(double));
gci = 0;
for (i = 1; i <= transform_core->ngx; i++)
{
......
......@@ -35,6 +35,7 @@ struct _TransformOptions
int smoothing;
int clip;
int grid_size;
int show_grid;
ToolType type;
};
......@@ -58,6 +59,14 @@ transform_toggle_update (GtkWidget *w,
*toggle_val = FALSE;
}
static void
transform_show_grid_update (GtkWidget *w,
gpointer data)
{
transform_toggle_update (w, data);
transform_core_grid_density_changed ();
}
static void
transform_type_callback (GtkWidget *w,
gpointer client_data)
......@@ -95,8 +104,7 @@ create_transform_options (void)
GtkWidget *radio_frame;
GtkWidget *radio_box;
GtkWidget *radio_button;
GtkWidget *smoothing_toggle;
GtkWidget *clip_toggle;
GtkWidget *toggle;
GtkAdjustment *grid_adj;
GtkWidget *grid_density;
GSList *group;
......@@ -121,6 +129,7 @@ create_transform_options (void)
options->clip = 1;
options->direction = TRANSFORM_TRADITIONAL;
options->grid_size = 32;
options->show_grid = TRUE;
/* the main vbox */
main_box = gtk_vbox_new (FALSE, 1);
......@@ -162,14 +171,14 @@ create_transform_options (void)
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",
toggle = gtk_check_button_new_with_label ("Smoothing");
gtk_box_pack_start (GTK_BOX (vbox), toggle, FALSE, FALSE, 0);
gtk_signal_connect (GTK_OBJECT (toggle), "toggled",
(GtkSignalFunc) transform_toggle_update,
&options->smoothing);
gtk_toggle_button_set_state (GTK_TOGGLE_BUTTON (smoothing_toggle),
gtk_toggle_button_set_state (GTK_TOGGLE_BUTTON (toggle),
options->smoothing);
gtk_widget_show (smoothing_toggle);
gtk_widget_show (toggle);
gtk_widget_show (vbox);
......@@ -200,6 +209,18 @@ create_transform_options (void)
gtk_widget_show (radio_box);
gtk_widget_show (radio_frame);
/* the show grid toggle button */
toggle = gtk_check_button_new_with_label ("Show grid");
gtk_box_pack_start (GTK_BOX (vbox), toggle, FALSE, FALSE, 0);
gtk_toggle_button_set_state (GTK_TOGGLE_BUTTON (toggle),
options->show_grid);
/* important: connect the signal after setting the state, because calling
transform_show_grid_update before the tool is created will fail */
gtk_signal_connect (GTK_OBJECT (toggle), "toggled",
(GtkSignalFunc) transform_show_grid_update,
&options->show_grid);
gtk_widget_show (toggle);
/* the grid density entry */
hbox = gtk_hbox_new (FALSE, 1);
gtk_widget_show (hbox);
......@@ -217,14 +238,14 @@ create_transform_options (void)
gtk_widget_show (grid_density);
/* the clip resulting image toggle button */
clip_toggle = gtk_check_button_new_with_label ("Clip perspective");
gtk_box_pack_start (GTK_BOX (vbox), clip_toggle, FALSE, FALSE, 0);
gtk_signal_connect (GTK_OBJECT (clip_toggle), "toggled",
toggle = gtk_check_button_new_with_label ("Clip perspective");
gtk_box_pack_start (GTK_BOX (vbox), toggle, FALSE, FALSE, 0);
gtk_signal_connect (GTK_OBJECT (toggle), "toggled",
(GtkSignalFunc) transform_toggle_update,
&options->clip);
gtk_toggle_button_set_state (GTK_TOGGLE_BUTTON (clip_toggle),
gtk_toggle_button_set_state (GTK_TOGGLE_BUTTON (toggle),
options->clip);
gtk_widget_show (clip_toggle);
gtk_widget_show (toggle);
gtk_widget_show (vbox);
gtk_widget_show (box);
......@@ -334,3 +355,12 @@ transform_tool_grid_size ()
else
return transform_options->grid_size;
}
int
transform_tool_show_grid ()
{
if (!transform_options)
return TRUE;
else
return transform_options->show_grid;
}
......@@ -25,6 +25,7 @@ int transform_tool_smoothing (void);
int transform_tool_clip (void);
int transform_tool_direction (void);
int transform_tool_grid_size (void);
int transform_tool_show_grid (void);
/* transform directions */
#define TRANSFORM_TRADITIONAL 0
......
......@@ -245,7 +245,8 @@ transform_core_button_press (tool, bevent, gdisp_ptr)
transform_core_bounds (tool, gdisp_ptr);
/* Calculate the grid line endpoints */
transform_core_setup_grid (tool);
if (transform_tool_show_grid ())
transform_core_setup_grid (tool);
/* Initialize the transform tool */
(* transform_core->trans_func) (tool, gdisp_ptr, INIT);
......@@ -601,22 +602,30 @@ transform_core_draw (tool)
gdk_draw_line (transform_core->core->win, transform_core->core->gc,
x3, y3, x1, y1);
/* Draw the grid */
/* Draw the grid */
gci = 0;
k = transform_core->ngx + transform_core->ngy;
for (i = 0; i < k; i++)
if ((transform_core->grid_coords != NULL) &&
(transform_core->tgrid_coords != NULL) &&
((tool->type != PERSPECTIVE) ||
(transform_core->transform[0][0] >=0.0) &&
(transform_core->transform[1][1] >=0.0)))
{
gdisplay_transform_coords (gdisp, transform_core->tgrid_coords[gci],
transform_core->tgrid_coords[gci+1],
&xa, &ya, 0);
gdisplay_transform_coords (gdisp, transform_core->tgrid_coords[gci+2],
transform_core->tgrid_coords[gci+3],
&xb, &yb, 0);
gci = 0;
k = transform_core->ngx + transform_core->ngy;
for (i = 0; i < k; i++)
{
gdisplay_transform_coords (gdisp, transform_core->tgrid_coords[gci],
transform_core->tgrid_coords[gci+1],
&xa, &ya, 0);
gdisplay_transform_coords (gdisp, transform_core->tgrid_coords[gci+2],
transform_core->tgrid_coords[gci+3],
&xb, &yb, 0);
gdk_draw_line (transform_core->core->win, transform_core->core->gc,
xa, ya, xb, yb);
gci += 4;
gdk_draw_line (transform_core->core->win, transform_core->core->gc,
xa, ya, xb, yb);
gci += 4;
}
}
/* draw the tool handles */
......@@ -713,9 +722,11 @@ transform_core_free (tool)
info_dialog_free (transform_info);
transform_info = NULL;
/* Free the grid line endpoint arrays */
g_free (transform_core->grid_coords);
g_free (transform_core->tgrid_coords);
/* Free the grid line endpoint arrays if they exist */
if (transform_core->grid_coords != NULL)
g_free (transform_core->grid_coords);
if (transform_core->tgrid_coords != NULL)
g_free (transform_core->tgrid_coords);
/* Finally, free the transform tool itself */
g_free (transform_core);
......@@ -749,16 +760,20 @@ transform_bounding_box (tool)
transform_core->cx, transform_core->cy,
&transform_core->tcx, &transform_core->tcy);
gci = 0;
k = (transform_core->ngx + transform_core->ngy) * 2;
for (i = 0; i < k; i++)
if (transform_core->grid_coords != NULL &&
transform_core->tgrid_coords != NULL)
{
transform_point (transform_core->transform,
transform_core->grid_coords[gci],
transform_core->grid_coords[gci+1],
&(transform_core->tgrid_coords[gci]),
&(transform_core->tgrid_coords[gci+1]));
gci += 2;
gci = 0;
k = (transform_core->ngx + transform_core->ngy) * 2;
for (i = 0; i < k; i++)
{
transform_point (transform_core->transform,
transform_core->grid_coords[gci],
transform_core->grid_coords[gci+1],
&(transform_core->tgrid_coords[gci]),
&(transform_core->tgrid_coords[gci+1]));
gci += 2;
}
}
}
......@@ -1019,10 +1034,23 @@ transform_core_grid_density_changed ()
TransformCore * transform_core;
transform_core = (TransformCore *) active_tool->private;
if (transform_core->function == CREATING)
return;
draw_core_pause (transform_core->core, active_tool);
g_free (transform_core->grid_coords);
g_free (transform_core->tgrid_coords);
transform_core_setup_grid (active_tool);
if (transform_core->grid_coords != NULL)
{
g_free (transform_core->grid_coords);
transform_core->grid_coords = NULL;
}
if (transform_core->tgrid_coords != NULL)
{
g_free (transform_core->tgrid_coords);
transform_core->tgrid_coords = NULL;
}
if (transform_tool_show_grid())
transform_core_setup_grid (active_tool);
transform_bounding_box (active_tool);
draw_core_resume (transform_core->core, active_tool);
}
......@@ -1037,8 +1065,8 @@ transform_core_setup_grid (tool)
transform_core = (TransformCore *) tool->private;
/* We use the transform_tool_grid_size function only here, even if the
* user changes the grid size in the middle of a
/* We use the transform_tool_grid_size function only here, even
* if the user changes the grid size in the middle of an
* operation, nothing happens.
*/
transform_core->ngx =
......@@ -1055,7 +1083,7 @@ transform_core_setup_grid (tool)
transform_core->tgrid_coords = (double *)
g_malloc ((transform_core->ngx + transform_core->ngy) * 4
* sizeof(double));
gci = 0;
for (i = 1; i <= transform_core->ngx; i++)
{
......
......@@ -35,6 +35,7 @@ struct _TransformOptions
int smoothing;
int clip;
int grid_size;
int show_grid;
ToolType type;
};
......@@ -58,6 +59,14 @@ transform_toggle_update (GtkWidget *w,
*toggle_val = FALSE;
}
static void
transform_show_grid_update (GtkWidget *w,
gpointer data)
{
transform_toggle_update (w, data);
transform_core_grid_density_changed ();
}
static void
transform_type_callback (GtkWidget *w,
gpointer client_data)
......@@ -95,8 +104,7 @@ create_transform_options (void)
GtkWidget *radio_frame;
GtkWidget *radio_box;
GtkWidget *radio_button;
GtkWidget *smoothing_toggle;
GtkWidget *clip_toggle;
GtkWidget *toggle;
GtkAdjustment *grid_adj;
GtkWidget *grid_density;
GSList *group;
......@@ -121,6 +129,7 @@ create_transform_options (void)
options->clip = 1;
options->direction = TRANSFORM_TRADITIONAL;
options->grid_size = 32;
options->show_grid = TRUE;
/* the main vbox */
main_box = gtk_vbox_new (FALSE, 1);
......@@ -162,14 +171,14 @@ create_transform_options (void)
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",
toggle = gtk_check_button_new_with_label ("Smoothing");
gtk_box_pack_start (GTK_BOX (vbox), toggle, FALSE, FALSE, 0);
gtk_signal_connect (GTK_OBJECT (toggle), "toggled",
(GtkSignalFunc) transform_toggle_update,
&options->smoothing);
gtk_toggle_button_set_state (GTK_TOGGLE_BUTTON (smoothing_toggle),
gtk_toggle_button_set_state (GTK_TOGGLE_BUTTON (toggle),
options->smoothing);
gtk_widget_show (smoothing_toggle);
gtk_widget_show (toggle);
gtk_widget_show (vbox);
......@@ -200,6 +209,18 @@ create_transform_options (void)
gtk_widget_show (radio_box);
gtk_widget_show (radio_frame);
/* the show grid toggle button */
toggle = gtk_check_button_new_with_label ("Show grid");
gtk_box_pack_start (GTK_BOX (vbox), toggle, FALSE, FALSE, 0);
gtk_toggle_button_set_state (GTK_TOGGLE_BUTTON (toggle),
options->show_grid);
/* important: connect the signal after setting the state, because calling
transform_show_grid_update before the tool is created will fail */
gtk_signal_connect (GTK_OBJECT (toggle), "toggled",
(GtkSignalFunc) transform_show_grid_update,
&options->show_grid);
gtk_widget_show (toggle);
/* the grid density entry */
hbox = gtk_hbox_new (FALSE, 1);
gtk_widget_show (hbox);
......@@ -217,14 +238,14 @@ create_transform_options (void)
gtk_widget_show (grid_density);
/* the clip resulting image toggle button */
clip_toggle = gtk_check_button_new_with_label ("Clip perspective");
gtk_box_pack_start (GTK_BOX (vbox), clip_toggle, FALSE, FALSE, 0);
gtk_signal_connect (GTK_OBJECT (clip_toggle), "toggled",
toggle = gtk_check_button_new_with_label ("Clip perspective");
gtk_box_pack_start (GTK_BOX (vbox), toggle, FALSE, FALSE, 0);
gtk_signal_connect (GTK_OBJECT (toggle), "toggled",
(GtkSignalFunc) transform_toggle_update,
&options->clip);
gtk_toggle_button_set_state (GTK_TOGGLE_BUTTON (clip_toggle),
gtk_toggle_button_set_state (GTK_TOGGLE_BUTTON (toggle),
options->clip);
gtk_widget_show (clip_toggle);
gtk_widget_show (toggle);
gtk_widget_show (vbox);
gtk_widget_show (box);
......@@ -334,3 +355,12 @@ transform_tool_grid_size ()
else
return transform_options->grid_size;
}
int
transform_tool_show_grid ()
{
if (!transform_options)
return TRUE;
else
return transform_options->show_grid;
}
......@@ -25,6 +25,7 @@ int transform_tool_smoothing (void);
int transform_tool_clip (void);
int transform_tool_direction (void);
int transform_tool_grid_size (void);
int transform_tool_show_grid (void);
/* transform directions */
#define TRANSFORM_TRADITIONAL 0
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment