[gimp/soc-2010-cage-2: 314/315] app: Make cage tool behave nice with offset layers
- From: Alexia Death <alexiade src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp/soc-2010-cage-2: 314/315] app: Make cage tool behave nice with offset layers
- Date: Wed, 3 Nov 2010 23:12:51 +0000 (UTC)
commit 9b96120c31e89209fd7fb25f98099e26d53d2ea8
Author: Alexia Death <alexiadeath gmail com>
Date: Thu Nov 4 00:10:22 2010 +0200
app: Make cage tool behave nice with offset layers
app/gegl/gimpcageconfig.c | 17 +++++-----
app/gegl/gimpcageconfig.h | 4 ++
app/tools/gimpcagetool.c | 74 +++++++++++++++++++++++++++++----------------
3 files changed, 61 insertions(+), 34 deletions(-)
---
diff --git a/app/gegl/gimpcageconfig.c b/app/gegl/gimpcageconfig.c
index 65ea2e8..2acbeb2 100644
--- a/app/gegl/gimpcageconfig.c
+++ b/app/gegl/gimpcageconfig.c
@@ -78,6 +78,7 @@ print_cage (GimpCageConfig *gcc)
printf("cgx: %.0f cgy: %.0f cvdx: %.0f cvdy: %.0f sf: %.2f normx: %.2f normy: %.2f\n", gcc->cage_vertices[i].x, gcc->cage_vertices[i].y, gcc->cage_vertices_d[i].x, gcc->cage_vertices_d[i].y, gcc->scaling_factor[i], gcc->normal_d[i].x, gcc->normal_d[i].y);
}
printf("bounding box: x: %d y: %d width: %d height: %d\n", bounding_box.x, bounding_box.y, bounding_box.width, bounding_box.height);
+ printf("offsets: (%d, %d)", gcc->offset_x, gcc->offset_y);
printf("done\n");
}
#endif
@@ -178,11 +179,11 @@ gimp_cage_config_add_cage_point (GimpCageConfig *gcc,
gcc->cage_vertices_max);
}
- gcc->cage_vertices[gcc->cage_vertice_number].x = x + DELTA;
- gcc->cage_vertices[gcc->cage_vertice_number].y = y + DELTA;
+ gcc->cage_vertices[gcc->cage_vertice_number].x = x + DELTA - gcc->offset_x;
+ gcc->cage_vertices[gcc->cage_vertice_number].y = y + DELTA - gcc->offset_y;
- gcc->cage_vertices_d[gcc->cage_vertice_number].x = x + DELTA;
- gcc->cage_vertices_d[gcc->cage_vertice_number].y = y + DELTA;
+ gcc->cage_vertices_d[gcc->cage_vertice_number].x = x + DELTA - gcc->offset_x;
+ gcc->cage_vertices_d[gcc->cage_vertice_number].y = y + DELTA - gcc->offset_y;
gcc->cage_vertice_number++;
@@ -217,13 +218,13 @@ gimp_cage_config_move_cage_point (GimpCageConfig *gcc,
if (mode == GIMP_CAGE_MODE_CAGE_CHANGE)
{
- gcc->cage_vertices[point_number].x = x + DELTA;
- gcc->cage_vertices[point_number].y = y + DELTA;
+ gcc->cage_vertices[point_number].x = x + DELTA - gcc->offset_x;
+ gcc->cage_vertices[point_number].y = y + DELTA - gcc->offset_y;
}
else
{
- gcc->cage_vertices_d[point_number].x = x + DELTA;
- gcc->cage_vertices_d[point_number].y = y + DELTA;
+ gcc->cage_vertices_d[point_number].x = x + DELTA - gcc->offset_x;
+ gcc->cage_vertices_d[point_number].y = y + DELTA - gcc->offset_y;
}
gimp_cage_config_compute_scaling_factor (gcc);
diff --git a/app/gegl/gimpcageconfig.h b/app/gegl/gimpcageconfig.h
index 2127796..b93f31b 100644
--- a/app/gegl/gimpcageconfig.h
+++ b/app/gegl/gimpcageconfig.h
@@ -41,6 +41,9 @@ struct _GimpCageConfig
gint cage_vertice_number; /* number of vertices used by the cage */
gint cage_vertices_max; /* number of vertices allocated in memory */
+ gint offset_x;
+ gint offset_y;
+
GimpVector2 *cage_vertices; /* cage before deformation */
GimpVector2 *cage_vertices_d; /* cage after deformation */
gdouble *scaling_factor;
@@ -136,4 +139,5 @@ void gimp_cage_config_reverse_cage (GimpCageConfig *gcc);
gboolean gimp_cage_config_point_inside (GimpCageConfig *gcc,
gfloat x,
gfloat y);
+
#endif /* __GIMP_CAGE_CONFIG_H__ */
diff --git a/app/tools/gimpcagetool.c b/app/tools/gimpcagetool.c
index 9b99874..17cfe53 100644
--- a/app/tools/gimpcagetool.c
+++ b/app/tools/gimpcagetool.c
@@ -36,15 +36,16 @@
#include "core/core-types.h"
#include "core/gimp.h"
-#include "core/gimpprogress.h"
-#include "core/gimpimage.h"
-#include "core/gimplayer.h"
#include "core/gimp-transform-utils.h"
+#include "core/gimpchannel.h"
#include "core/gimpdrawable.h"
#include "core/gimpdrawable-operation.h"
#include "core/gimpdrawable-shadow.h"
+#include "core/gimpimage.h"
#include "core/gimpimagemap.h"
+#include "core/gimplayer.h"
#include "core/gimpprojection.h"
+#include "core/gimpprogress.h"
#include "display/gimpdisplay.h"
#include "display/gimpdisplayshell.h"
@@ -234,6 +235,10 @@ gimp_cage_tool_start (GimpCageTool *ct,
{
GimpTool *tool = GIMP_TOOL (ct);
GimpDrawTool *draw_tool = GIMP_DRAW_TOOL (tool);
+ GimpImage *image = gimp_display_get_image (display);
+ GimpDrawable *drawable = gimp_image_get_active_drawable (image);
+ gint off_x;
+ gint off_y;
gimp_tool_control_activate (tool->control);
@@ -256,6 +261,15 @@ gimp_cage_tool_start (GimpCageTool *ct,
ct->handle_moved = -1;
ct->cage_complete = FALSE;
+ /*Setting up cage offset to convert the cage point coords to drawable coords*/
+ gimp_item_get_offset (GIMP_ITEM (drawable),
+ &off_x,
+ &off_y);
+
+
+ ct->config->offset_x = off_x;
+ ct->config->offset_y = off_y;
+
gimp_draw_tool_start (draw_tool, display);
}
@@ -547,26 +561,26 @@ gimp_cage_tool_draw (GimpDrawTool *draw_tool)
}
- gimp_draw_tool_add_lines (draw_tool,
+ /*gimp_draw_tool_add_lines (draw_tool,
vertices,
config->cage_vertice_number,
- FALSE);
+ FALSE);*/
if (!ct->cage_complete && ct->cursor_position.x != -1000)
{
gimp_draw_tool_add_line (draw_tool,
- vertices[config->cage_vertice_number - 1].x,
- vertices[config->cage_vertice_number - 1].y,
+ vertices[config->cage_vertice_number - 1].x + ct->config->offset_x,
+ vertices[config->cage_vertice_number - 1].y + ct->config->offset_y,
ct->cursor_position.x,
ct->cursor_position.y);
}
else
{
gimp_draw_tool_add_line (draw_tool,
- vertices[config->cage_vertice_number - 1].x,
- vertices[config->cage_vertice_number - 1].y,
- vertices[0].x,
- vertices[0].y);
+ vertices[config->cage_vertice_number - 1].x + ct->config->offset_x,
+ vertices[config->cage_vertice_number - 1].y + ct->config->offset_y,
+ vertices[0].x + ct->config->offset_x,
+ vertices[0].y + ct->config->offset_y);
}
on_handle = gimp_cage_tool_is_on_handle (config,
@@ -579,7 +593,6 @@ gimp_cage_tool_draw (GimpDrawTool *draw_tool)
for(i = 0; i < config->cage_vertice_number; i++)
{
- GimpVector2 point = vertices[i];
GimpHandleType handle = GIMP_HANDLE_CIRCLE;
@@ -588,12 +601,19 @@ gimp_cage_tool_draw (GimpDrawTool *draw_tool)
handle = GIMP_HANDLE_FILLED_CIRCLE;
}
+ if (i > 0)
+ gimp_draw_tool_add_line (draw_tool,
+ vertices[i - 1].x + ct->config->offset_x,
+ vertices[i - 1].y + ct->config->offset_y,
+ vertices[i].x + ct->config->offset_x,
+ vertices[i].y + ct->config->offset_y);
+
gimp_draw_tool_add_handle (draw_tool,
- handle,
- point.x,
- point.y,
- HANDLE_SIZE, HANDLE_SIZE,
- GTK_ANCHOR_CENTER);
+ handle,
+ vertices[i].x + ct->config->offset_x,
+ vertices[i].y + ct->config->offset_y,
+ HANDLE_SIZE, HANDLE_SIZE,
+ GTK_ANCHOR_CENTER);
}
}
@@ -620,13 +640,13 @@ gimp_cage_tool_is_on_handle (GimpCageConfig *gcc,
{
if (mode == GIMP_CAGE_MODE_CAGE_CHANGE)
{
- vert_x = gcc->cage_vertices[i].x;
- vert_y = gcc->cage_vertices[i].y;
+ vert_x = gcc->cage_vertices[i].x + gcc->offset_x;
+ vert_y = gcc->cage_vertices[i].y + gcc->offset_y;
}
else
{
- vert_x = gcc->cage_vertices_d[i].x;
- vert_y = gcc->cage_vertices_d[i].y;
+ vert_x = gcc->cage_vertices_d[i].x + gcc->offset_x;
+ vert_y = gcc->cage_vertices_d[i].y + gcc->offset_y;
}
dist = gimp_draw_tool_calc_distance_square (GIMP_DRAW_TOOL (draw_tool),
@@ -669,12 +689,12 @@ gimp_cage_tool_compute_coef (GimpCageTool *ct,
{
GimpCageConfig *config = ct->config;
- Babl *format;
- GeglNode *gegl, *input, *output;
+ Babl *format;
+ GeglNode *gegl, *input, *output;
GeglProcessor *processor;
- GimpProgress *progress;
- GeglBuffer *buffer;
- gdouble value;
+ GimpProgress *progress;
+ GeglBuffer *buffer;
+ gdouble value;
if (ct->coef)
{
@@ -839,7 +859,9 @@ gimp_cage_tool_process (GimpCageTool *ct,
if (GIMP_IS_DRAWABLE (drawable))
{
+
GimpProgress *progress;
+
progress = gimp_progress_start (GIMP_PROGRESS (display),
_("Rendering cage transform"),
FALSE);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]