Commit e9dd3012 authored by Michael Natterer's avatar Michael Natterer 😴

app: add an on-canvas progress facility to GimpTool

and use it in GimpCageTool.
parent 927ce61c
......@@ -40,18 +40,14 @@
#include "core/gimpimage.h"
#include "core/gimpimagemap.h"
#include "core/gimplayer.h"
#include "core/gimpprogress.h"
#include "core/gimpprojection.h"
#include "gegl/gimpcageconfig.h"
#include "widgets/gimphelp-ids.h"
#include "widgets/gimpwidgets-utils.h"
#include "display/gimpcanvasprogress.h"
#include "display/gimpdisplay.h"
#include "display/gimpdisplayshell.h"
#include "display/gimpdisplayshell-items.h"
#include "display/gimpdisplayshell-transform.h"
#include "gimpcagetool.h"
......@@ -944,33 +940,17 @@ static void
gimp_cage_tool_compute_coef (GimpCageTool *ct,
GimpDisplay *display)
{
GimpDisplayShell *shell = gimp_display_get_shell (display);
GimpCageConfig *config = ct->config;
Babl *format;
GeglNode *gegl;
GeglNode *input;
GeglNode *output;
GeglProcessor *processor;
GimpCanvasItem *p;
GimpProgress *progress;
GeglBuffer *buffer;
gdouble value;
{
gint x, y, w, h;
gimp_display_shell_untransform_viewport (shell, &x, &y, &w, &h);
p = gimp_canvas_progress_new (shell, GIMP_HANDLE_ANCHOR_CENTER,
x + w / 2, y + h / 2);
gimp_display_shell_add_item (shell, p);
g_object_unref (p);
}
progress = gimp_progress_start (GIMP_PROGRESS (p),
_("Coefficient computation"),
FALSE);
gimp_widget_flush_expose (shell->canvas);
GimpCageConfig *config = ct->config;
Babl *format;
GeglNode *gegl;
GeglNode *input;
GeglNode *output;
GeglProcessor *processor;
GeglBuffer *buffer;
gdouble value;
gimp_tool_progress_start (GIMP_TOOL (ct), display,
_("Coefficient computation..."));
if (ct->coef)
{
......@@ -1002,11 +982,10 @@ gimp_cage_tool_compute_coef (GimpCageTool *ct,
while (gegl_processor_work (processor, &value))
{
gimp_progress_set_value (progress, value);
gimp_widget_flush_expose (shell->canvas);
gimp_tool_progress_set_value (GIMP_TOOL (ct), value);
}
gimp_progress_end (progress);
gimp_tool_progress_end (GIMP_TOOL (ct));
gegl_processor_destroy (processor);
......@@ -1014,8 +993,6 @@ gimp_cage_tool_compute_coef (GimpCageTool *ct,
g_object_unref (gegl);
ct->dirty_coef = FALSE;
gimp_display_shell_remove_item (shell, p);
}
static void
......
......@@ -27,11 +27,17 @@
#include "core/gimp.h"
#include "core/gimpcontainer.h"
#include "core/gimpimage.h"
#include "core/gimpprogress.h"
#include "core/gimptoolinfo.h"
#include "widgets/gimpwidgets-utils.h"
#include "display/gimpcanvasprogress.h"
#include "display/gimpdisplay.h"
#include "display/gimpdisplayshell.h"
#include "display/gimpdisplayshell-cursor.h"
#include "display/gimpdisplayshell-items.h"
#include "display/gimpdisplayshell-transform.h"
#include "display/gimpstatusbar.h"
#include "gimptool.h"
......@@ -1127,6 +1133,66 @@ gimp_tool_set_cursor (GimpTool *tool,
cursor, tool_cursor, modifier);
}
void
gimp_tool_progress_start (GimpTool *tool,
GimpDisplay *display,
const gchar *text)
{
GimpDisplayShell *shell;
gint x, y, w, h;
g_return_if_fail (GIMP_IS_TOOL (tool));
g_return_if_fail (GIMP_IS_DISPLAY (display));
g_return_if_fail (tool->progress == NULL);
shell = gimp_display_get_shell (display);
gimp_display_shell_untransform_viewport (shell, &x, &y, &w, &h);
tool->progress = gimp_canvas_progress_new (shell, GIMP_HANDLE_ANCHOR_CENTER,
x + w / 2, y + h / 2);
gimp_display_shell_add_item (shell, tool->progress);
g_object_unref (tool->progress);
gimp_progress_start (GIMP_PROGRESS (tool->progress),
text, FALSE);
gimp_widget_flush_expose (shell->canvas);
tool->progress_display = display;
}
void
gimp_tool_progress_set_value (GimpTool *tool,
gdouble value)
{
GimpDisplayShell *shell;
g_return_if_fail (GIMP_IS_TOOL (tool));
g_return_if_fail (GIMP_IS_PROGRESS (tool->progress));
shell = gimp_display_get_shell (tool->progress_display);
gimp_progress_set_value (GIMP_PROGRESS (tool->progress), value);
gimp_widget_flush_expose (shell->canvas);
}
void
gimp_tool_progress_end (GimpTool *tool)
{
GimpDisplayShell *shell;
g_return_if_fail (GIMP_IS_TOOL (tool));
g_return_if_fail (GIMP_IS_PROGRESS (tool->progress));
shell = gimp_display_get_shell (tool->progress_display);
gimp_progress_end (GIMP_PROGRESS (tool->progress));
gimp_display_shell_remove_item (shell, tool->progress);
tool->progress = NULL;
tool->progress_display = NULL;
}
/* private functions */
......
......@@ -67,6 +67,10 @@ struct _GimpTool
/* private list of displays which have a status message from this tool
*/
GList *status_displays;
/* on-canvas progress */
GimpCanvasItem *progress;
GimpDisplay *progress_display;
};
struct _GimpToolClass
......@@ -247,5 +251,12 @@ void gimp_tool_set_cursor (GimpTool *tool,
GimpToolCursorType tool_cursor,
GimpCursorModifier modifier);
void gimp_tool_progress_start (GimpTool *tool,
GimpDisplay *display,
const gchar *text);
void gimp_tool_progress_set_value (GimpTool *tool,
gdouble value);
void gimp_tool_progress_end (GimpTool *tool);
#endif /* __GIMP_TOOL_H__ */
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