add gimp_draw_tool_draw_text_cursor() which draws a properly transformed

2008-10-31  Michael Natterer  <mitch@gimp.org>

	* app/tools/gimpdrawtool.[ch]: add gimp_draw_tool_draw_text_cursor()
	which draws a properly transformed cursor that always has the same
	line width.

	* app/tools/gimptexttool.c (gimp_text_tool_draw): use it instead
	of drawing a cursor here that is broken at anything but 1:1 zoom.


svn path=/trunk/; revision=27497
This commit is contained in:
Michael Natterer 2008-10-31 16:48:29 +00:00 committed by Michael Natterer
parent 9e7edcbe41
commit f971d31ff1
4 changed files with 70 additions and 12 deletions

View file

@ -1,3 +1,12 @@
2008-10-31 Michael Natterer <mitch@gimp.org>
* app/tools/gimpdrawtool.[ch]: add gimp_draw_tool_draw_text_cursor()
which draws a properly transformed cursor that always has the same
line width.
* app/tools/gimptexttool.c (gimp_text_tool_draw): use it instead
of drawing a cursor here that is broken at anything but 1:1 zoom.
2008-10-31 Michael Natterer <mitch@gimp.org>
* app/actions/text-tool-actions.c

View file

@ -1878,6 +1878,56 @@ gimp_draw_tool_draw_boundary (GimpDrawTool *draw_tool,
g_free (gdk_points);
}
void
gimp_draw_tool_draw_text_cursor (GimpDrawTool *draw_tool,
gdouble x1,
gdouble y1,
gdouble x2,
gdouble y2,
gboolean use_offsets)
{
GimpDisplayShell *shell;
gdouble tx1, ty1;
gdouble tx2, ty2;
g_return_if_fail (GIMP_IS_DRAW_TOOL (draw_tool));
shell = GIMP_DISPLAY_SHELL (draw_tool->display->shell);
gimp_display_shell_transform_xy_f (shell,
x1, y1,
&tx1, &ty1,
use_offsets);
gimp_display_shell_transform_xy_f (shell,
x2, y2,
&tx2, &ty2,
use_offsets);
/* vertical line */
gimp_canvas_draw_line (GIMP_CANVAS (shell->canvas), GIMP_CANVAS_STYLE_XOR,
PROJ_ROUND (tx1), PROJ_ROUND (ty1) + 2,
PROJ_ROUND (tx2), PROJ_ROUND (ty2) - 2);
gimp_canvas_draw_line (GIMP_CANVAS (shell->canvas), GIMP_CANVAS_STYLE_XOR,
PROJ_ROUND (tx1) - 1, PROJ_ROUND (ty1) + 2,
PROJ_ROUND (tx2) - 1, PROJ_ROUND (ty2) - 2);
/* top serif */
gimp_canvas_draw_line (GIMP_CANVAS (shell->canvas), GIMP_CANVAS_STYLE_XOR,
PROJ_ROUND (tx1) - 3, PROJ_ROUND (ty1),
PROJ_ROUND (tx1) + 3, PROJ_ROUND (ty1));
gimp_canvas_draw_line (GIMP_CANVAS (shell->canvas), GIMP_CANVAS_STYLE_XOR,
PROJ_ROUND (tx1) - 3, PROJ_ROUND (ty1) + 1,
PROJ_ROUND (tx1) + 3, PROJ_ROUND (ty1) + 1);
/* bottom serif */
gimp_canvas_draw_line (GIMP_CANVAS (shell->canvas), GIMP_CANVAS_STYLE_XOR,
PROJ_ROUND (tx2) - 3, PROJ_ROUND (ty2) - 1,
PROJ_ROUND (tx2) + 3, PROJ_ROUND (ty2) - 1);
gimp_canvas_draw_line (GIMP_CANVAS (shell->canvas), GIMP_CANVAS_STYLE_XOR,
PROJ_ROUND (tx2) - 3, PROJ_ROUND (ty2) - 2,
PROJ_ROUND (tx2) + 3, PROJ_ROUND (ty2) - 2);
}
/* private functions */

View file

@ -251,5 +251,12 @@ void gimp_draw_tool_draw_boundary (GimpDrawTool *draw_tool,
gdouble offset_y,
gboolean use_offsets);
void gimp_draw_tool_draw_text_cursor (GimpDrawTool *draw_tool,
gdouble x1,
gdouble y1,
gdouble x2,
gdouble y2,
gboolean use_offsets);
#endif /* __GIMP_DRAW_TOOL_H__ */

View file

@ -1089,18 +1089,10 @@ gimp_text_tool_draw (GimpDrawTool *draw_tool)
crect.y = PANGO_PIXELS (crect.y) + logical_off_y;
crect.height = PANGO_PIXELS (crect.height);
gimp_draw_tool_draw_rectangle (draw_tool, TRUE,
crect.x - 1, crect.y + 2,
3, crect.height - 4,
TRUE);
gimp_draw_tool_draw_rectangle (draw_tool, TRUE,
crect.x - 3, crect.y,
7, 3,
TRUE);
gimp_draw_tool_draw_rectangle (draw_tool, TRUE,
crect.x - 3, crect.y + crect.height - 3,
7, 3,
TRUE);
gimp_draw_tool_draw_text_cursor (draw_tool,
crect.x, crect.y,
crect.x, crect.y + crect.height,
TRUE);
if (text_tool->preedit_string && text_tool->preedit_len > 0)
gimp_text_tool_draw_preedit (draw_tool, logical_off_x, logical_off_y);