Correct way to undo a painting event

Hi,

I’m looking for the correct way to undo the painting event, the painting done, prior to GIMP_PAINT_STATE_FINISH:
So that clicking and drawing is automatically undone. This allows me to rework the stroke with knowledge of the intended stroke. Attempted to do this, so do that, but first clear the attempt.

in gimppaintbrush.c

static void
gimp_paintbrush_paint (GimpPaintCore    *paint_core,
                       GList            *drawables,
                       GimpPaintOptions *paint_options,
                       GimpSymmetry     *sym,
                       GimpPaintState    paint_state,
                       guint32           time)
{
  GimpPaintbrush *paintbrush = GIMP_PAINTBRUSH (paint_core);

  g_return_if_fail (g_list_length (drawables) == 1);

  switch (paint_state)
    {
    case GIMP_PAINT_STATE_INIT:
      {
        GimpRGB color;

        for (GList *iter = drawables; iter; iter = iter->next)
          if (GIMP_PAINTBRUSH_GET_CLASS (paintbrush)->get_color_history_color &&
              GIMP_PAINTBRUSH_GET_CLASS (paintbrush)->get_color_history_color (paintbrush,
                                                                               iter->data,
                                                                               paint_options,
                                                                               &color))
            {
              GimpContext *context = GIMP_CONTEXT (paint_options);

              gimp_palettes_add_color_history (context->gimp, &color);
            }
      }
      break;

    case GIMP_PAINT_STATE_MOTION:
      for (GList *iter = drawables; iter; iter = iter->next)
        _gimp_paintbrush_motion (paint_core, iter->data, paint_options,
                                 sym, GIMP_OPACITY_OPAQUE);
      break;

    case GIMP_PAINT_STATE_FINISH:
      g_clear_weak_pointer (&paintbrush->paint_buffer);
      g_clear_pointer (&paintbrush->paint_pixmap, gimp_temp_buf_unref);
      break;
    }
}

Hi! I’m not sure what you’re trying to do exactly yet (perhaps look into DrawableUndo Code to see how changes to the drawable are undone and redone?)

However, post-2.99.18 the get_color_history_color() functions now use GeglColor *color rather than GimpRGB color. So if you’re having compiling issues, that might be part of the problem.

Hello,

Thanks, trying to undo the painted stroke, immediately after its been painted, within the same switch statement. So the history of the stroke is created but not pixels, the undo seems poised to be used, and instinctively i think the solution is simple. using gimp_paint_core_cancel, almost worked, but hit error message, g_critical (“%s: missing undo buffer for ‘%s’.”,
G_STRFUNC, gimp_object_get_name (iter->data)); and the undo was malfunctioning.

case GIMP_PAINT_STATE_FINISH:
  gimp_paint_core_cancel /* Undo attemp,  almost worked, failed on the layer having no undo bufffer ??? */
  /* do pixel painting stuff here based on the previously recorded stroke */
  /* then finish */

This topic was automatically closed 45 days after the last reply. New replies are no longer allowed.