Comment 1 for bug 857123

Revision history for this message
ciplogic (ciprian-mustiata) wrote :

I attached a patch that may address the problem (certainly fixes on my machine, I don't know side effects on other actions).

In short the fixes are:
 Added an internal class (could be added to Utility class, as was added RangeEnumerator) that can store just one computation, and made one internal instance to compute that:
       ToCompute _toCompute = new ToCompute();
         class ToCompute
        {
            public delegate void ExecutedEvent();
            public ExecutedEvent Executed;

            public void AddEvent(ExecutedEvent ev)
            {
                Executed = null;
                 Executed += ev;
            }

            public void ComputeAll()
            {
                if(Executed!=null)
                    Executed();
                Executed = null;
             }
        }

Add the MotionEvents with AddEvent that will clear the previous motion event and will take all closures arguments using lambdas:
So previous code was:
MotionNotifyEvent += delegate (object sender, MotionNotifyEventArgs e) {
                 if (!PintaCore.Workspace.HasOpenDocuments)
And it was replaced with:
MotionNotifyEvent += delegate (object sender, MotionNotifyEventArgs e) {
                _toCompute.AddEvent( () => { //here is the lambda
                 if (!PintaCore.Workspace.HasOpenDocuments)
and after that is forcing a view paint:
               }; //end of lambda
                GdkWindow.Invalidate();

And at last, but not at least, added the motion event in invalidate method at start of it:
 So the previous code:

            base.OnExposeEvent (e);

            if (!PintaCore.Workspace.HasOpenDocuments)
                return true;

was replaced with:

            base.OnExposeEvent (e);

            _toCompute.ComputeAll();

            if (!PintaCore.Workspace.HasOpenDocuments)
                return true;