Skip to content

fix: fixing color wheel history pollution due to mouse drag - #2750

Open
mohamedAdhamc wants to merge 27 commits into
synfig:masterfrom
mohamedAdhamc:color-wheel-history-pollution
Open

mohamedAdhamc wants to merge 27 commits into
synfig:masterfrom
mohamedAdhamc:color-wheel-history-pollution

Conversation

@mohamedAdhamc

@mohamedAdhamc mohamedAdhamc commented Jul 14, 2022 •

Copy link
Copy Markdown
Member

Fixes #451

Using a flag to know when there are rapid repeated actions (as in here and in #2717 ) then if it's a rapid repeated action only showing in the history panel the very last value.

-For setting the color wheel using the mouse it works perfectly. also when setting with one key.

-However, if setting with multiple keys at the same time there appears a number of actions depending on the number of keys released. I tried implementing a counter variable which increments on signal key press and decrements on key release but it was behaving weirdly and also I dont thinks its much of an issue here if otherwise though please let me know.

as suggested I solved color history issue using the same method. I will be then cherry picking this commit into anew branch with a new proposal then after its merged i can rebase this branch.
@mohamedAdhamc
mohamedAdhamc requested a review from ice0 July 15, 2022 01:42
@ice0

ice0 commented Jul 18, 2022

Copy link
Copy Markdown
Collaborator
history-broken.mp4

Now history is completely broken.
The first change is not recorded in history.
After adding a change, pressing Ctrl+Z does not undo the change.

Gdk::RGBA newColor = hvsColorWidget->get_current_rgba();
Color synfigColor(
Color synfigColor;
if(was_released){// if there was a release means drag is over and record this final color in history panel

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mohamedAdhamc mohamedAdhamc Jul 18, 2022 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there was a reason there were some cases is_adjusting() wasn't handling them correctly (with regards to this feature) but I can't really remember. If this part is kept after addressing the other issues of this PR I will then look into it.

@mohamedAdhamc

Copy link
Copy Markdown
Member Author

history-broken.mp4
Now history is completely broken. The first change is not recorded in history. After adding a change, pressing Ctrl+Z does not undo the change.

Oh, maybe I forgot something in the commit. It was working fine on my machine. I will look into it.

@mohamedAdhamc

mohamedAdhamc commented Jul 18, 2022 •

Copy link
Copy Markdown
Member Author

@ice0
it seems weird that it's not working on your machine(the first change not being recorded), I checked, and it's working alright here. I will look into it also.
never mind I replicated it. seems like this happens when picking one of the vertices of the triangle and releasing outside the color wheel. I'll look into it.

My.Project.mp4

p.s. its a little glitichy because of the screen recorder. the windows screen recorder didnt record the new color dialog window.

but yes there is something wrong with the undo I just checked.
update: its because im just blocking the rendering of new rows in history panel, not getting to the heart of the issue which would probably be in the action class itself. Maybe then try to combine all the actions into one action kind of like how some actions when expanded are actually a couple minin action. maybe for this it could be like that, and I think then undo would work fine, but i really dont know how difficult that would be I would have to look into the action system.
Will first thought get it moving a bit with feature 2 then will return to this hopefully later on tonight.

@mohamedAdhamc

mohamedAdhamc commented Jul 19, 2022 •

Copy link
Copy Markdown
Member Author

hey, @rodolforg do you think grouping these actions into one group is a good way of fixing this history pollution issue?

I think this way makes the undo easier as it would just work normally im assuming. However, not really sure though how easy it would be to group them this is what I'm figuring out now :).

update: I made the group and stored the actions in it but still undo isn't working as should be. Im thinking I probably initialized the handle for the action group in a wrong way but I honestly have no clue at this point xD. I will keep at it and will be commiting by the end of the day to get advice from you guys.

I also noticed jump seems to be working correctly for the gorup. I mean jumping to previous action or action group does what undo should be doing which it is not. however jump in general also seems to be messed up.

update: ok so while I still am not sure why the undo isn't working properly, I realized that the undo works as if there was the total number of actions done (with the group not being counted as one action). so for example if we have
1- layer new circle action group
2- regular certain parameter set from edit mode action
3- color action group
Now the expected behaviour is that after doing these three undos will return us to point zero. but in fact what happens is the color action group is as if it is expanded and basically how it would have been without grouping.

which leads me to the conclusion that the grouping just like the thing I did before (instead of grouping hiding the in between actions from rendering into rows) is not getting to the heart of the issue here. Although I had thought grouping would fix this by "grouping" these multiple actions into one single action.

update: or maybe just I have to use synfigapp::Action::PassiveGrouper instead of synfigapp::Action::Group (* _ *) I will look into this

@ice0

ice0 commented Jul 19, 2022

Copy link
Copy Markdown
Collaborator

hey, @rodolforg do you think grouping these actions into one group is a good way of fixing this history pollution issue?

I don't like the grouping solution because it doesn't solve the problem, it just hides it.
Every group in history can be opened, so this brings us back to the original issue.

Screenshot_19

@mohamedAdhamc

mohamedAdhamc commented Jul 19, 2022 •

Copy link
Copy Markdown
Member Author

I don't like the grouping solution because it doesn't solve the problem, it just hides it. Every group in history can be opened, so this brings us back to the original issue.

yes, this is actually very understandable. I will be looking for a better solution tomorrow... I'm about to go to sleep in a bit.

In the meanwhile, it would be great if you guys could give me suggestions on what I should be trying to do/ where i should be looking?
I will read the original issues comments though I think I might find something interesting there.

update: ironically in the comments the same idea of a passive group was mentioned xD. However @rodolforg seems to have solved something similar in #982 however its a huge commit (^_^) so I willl probably start tommorow by seeing what he did there for inspiration.

update again: I went through it quickly seems like it was also done using passive grouping. I think maybe if I am to group the actions into a pasive group then just not render all the child actions --(the rendering part shouldn't be difficult, it would just most likely be messing around with the history tree views insert_action() / on_new_action methods)--. This way
1- undo should work
2- history polllution in the sense that too many rows are rendered is also fixed
@ice0 does this sound good ?

update: currently im looking into synfig::App:PassiveGroup it does seem to be quite diffrent from the regular Group which can be
update 2: but maybe no need to even group anything if i find a way to block actions from being created/processed.
update 3: I think I'm getting to something here. I found where the action is "processed". I'm now testing it out.
update 4: wohoo ! I got it to work just how we wanted it to by only showing the last color action in the history and undo works fine. what I did is just basically stopped the "processing" of the action while the color is being dragged, as during the drag we dont want to be making actions we only want one action at the end which is the final.
I will be trying to optimise and clean it a bit then commiting,
p.s. this could also be applied in my feature 1 , and any other place in the future where something like this is needed by setting the value of a boolean during the drag to indicate that we dont want actions during the drag.
update: shoot :( i found out that I blocked the color from being shown as the drag is happening. I believe im getting really close though I just have to figure this out.

update: seems I finally got to the root of the issue now, will be testing, then reviewing/optimizing and committing.
update: ok so I did find out what was happening with redo but trying not to add the unneeded action to the undo stack gives out segmentation errors, its probaby messing something else somewhere so I will be trying to go over the whole undo mechanism in place
update: ok so as of right now there is no pollution but the first undo is after the action is made is not working for some reason. Im looking into it.
update: actually seems like the action with the update are both working well the problem though seems to be that the new layers color/(drag parameter) is changed to be same as that of the first action which follows its creation. So this means its an issue with the function i have for setting the color. I'll be looking into it.
update: ok so im like almost sure now this is the problem. current action gets set with the same value as the action after it. hence always first undo doesnt do anything. I will try to fix it up now but I'm about to sleep so if i dont get to finish it I will try to get it done wit as quick as possible when I wake up.

quick summary: If anyone is reading this and wants a quick summary just read the last couple updates old ones are regularly being invalidated by newer ones.

@mohamedAdhamc

Copy link
Copy Markdown
Member Author

update:
ok so finally its working, on drag ending a new action is made, and undoing successfully undoes the color. I will clean up the code and make sure there arent any corner cases im not handling then commit hopefully.

@mohamedAdhamc

mohamedAdhamc commented Jul 21, 2022 •

Copy link
Copy Markdown
Member Author

ok so a description of what happened.

color history polution should now be fixed for the color wheel. As in dragging the wheel makes no pollution.

However there are two cases I havent handled the pollution for
1- dragging the color wheel using the keyboard
2- color pollution when using the spin buttons in the dialog (i mean clicking on the +/- buttons of the spin button)

I don't think one is necessary to me it felt really unnatural using the keys to adjust the color wheel. If it has to be handled though please let me know.

Two I think wouldn't be related to this PR as these spin buttons arent part of the color wheel. So maybe I can fix them in another PR later if they should be fixed. But I'd rather continue with the issues I have for my project so as to not get carried away too much now during the project.

p.s. i removed some unecessary thing and waiting or it to rebuild to make sure I didnt accidently mess up anything so I wil be comiiting in a couple minutes after it builds. update: there are 100 files to rebuild so thiis might take a bit :(

@mohamedAdhamc
mohamedAdhamc requested a review from ice0 July 21, 2022 03:40
@mohamedAdhamc mohamedAdhamc changed the title Color Wheel History Pollution Fix fix: fixing Color Wheel History Pollution due to mouse drag Aug 2, 2022
@mohamedAdhamc mohamedAdhamc changed the title fix: fixing Color Wheel History Pollution due to mouse drag fix: fixing color wheel history pollution due to mouse drag Aug 2, 2022
@ice0

ice0 commented Aug 2, 2022 •

Copy link
Copy Markdown
Collaborator

Pressing Esc key doesn't cancel the change:

color-wheel-esc.mp4

Pressing Esc overwrites the history:

color-wheel-esc2.mp4

@mohamedAdhamc

Copy link
Copy Markdown
Member Author

Pressing Esc key doesn't cancel the change:

Yes actually I didn't handle ESC for cancelling change will do it in a bit (just woke up) shouldn't take long.

@ice0

ice0 commented Aug 26, 2022

Copy link
Copy Markdown
Collaborator

this is due to the current way of resetting the original color before setting the final one, in which case here the original is "the original" for only one of the selected. seems like the current fix isnt general enough yet, I will try to go along with what rodolf suggested.

Is any progress here?

@mohamedAdhamc

Copy link
Copy Markdown
Member Author

Is any progress here?

Not really I was mainly caught up with the other features and reviews. I think to actually get to a fix that would be general enough for everything i'd have to really understand in detail the action system in place. I should get to it soon though (starting tomorrow if things go well with the things I'm supposed to address from reviews).

@ice0

ice0 commented Aug 26, 2022

Copy link
Copy Markdown
Collaborator

Not really I was mainly caught up with the other features and reviews.

I suggest to concentrate here, because without completing this PR we cannot continue with #2717

@mohamedAdhamc

Copy link
Copy Markdown
Member Author

I suggest to concentrate here, because without completing this PR we cannot continue with #2717

ok I will be focusing on this as yes this is critical for #2717.

@mohamedAdhamc

mohamedAdhamc commented Aug 28, 2022 •

Copy link
Copy Markdown
Member Author

I meant instead of pushing action in undo-history stack, those overwriting actions (like the main one here, "ValueDescSet") replace the immediately previous one, if the latter is related to the same ValueDesc (i.e., changing the exact same parameter).

@ice0 , @rodolforg
ok so I have been trying to do this but there is something I dont really understand and is causing lots of problems.

I tried doing what rodolf suggested which is for these actions to have the new one replace the old one in the undo_action_stack so theoretically we should end up with the very last action in the undo stack and then whichever is before it so for example:

making a new circle layer (let say default color is black)
setting the color to blue using color wheel (now the last action in undo stack should be this one)

here when I undo it only takes me back to the previous action but with the wrong color (slightly lighter blue) not black, it seems like the new circle actions "color parameter" is somehow changed so I actually wonder why that happens shouldn't each change only affect the action it is in ?

the only time that seems to not happen is when the very first action in the color wheel is pushed onto the undo stack and not removed (to which I thought maybe then using the same logic not creating any more actions will alter this actions color parameter but unfortuantely it doesnt xd when I undo and redo the color changes). So right now I think maybe I could make a passive group with the very first and last action/actions (num_layers * 2)
but even for that I'm not really sure how i would even put them in a passive group with the way they are sent and processed.

any ideas?

update: seems like using a modified passive grouper so that it includes the very first and last action is the best way to go at it, it would be the safest and would solve the history pollution without having to change any key thing in the current action system. whether use the current PassiveGrouper as is with some modifications or creating a new similar grouper though I would still have to see how the rest of the implemetnation goes.
p.s. I think I have quite a descent model right now I will be working on continuing with it then i will commit.

@mohamedAdhamc

mohamedAdhamc commented Aug 28, 2022 •

Copy link
Copy Markdown
Member Author

ok so I went with rodolf's second suggestion which is using a passive group but modified ( because a passive group directly would just be hiding all the many actions not more). Now the passive group only includes the very first and last actions which are necessary for the undo process to work, and importantly it works for any selected number of layers.

@mohamedAdhamc

Copy link
Copy Markdown
Member Author

ok its not yet fully complete I will finish it first thing in the morning tommorow.
whats left to do
1- ok so now we reduced the number of actions into only two actions, very first and very last (for one layer, for n layers its n*2).
now in the passive group containing the action, it shows these two actions although its not really important for the user to
see both we only need them in the group stack for the undo/redo, so maybe only show the user one action and not have the
other one printed out in the group, so for example if its only one layer being edited he sees only one action.
2- I have to adjust the "escape to cancel" to fit in with the new implementation.
3- quite a bit of clean-ups, lots of commented-out code from when I was experimenting diffrent ideas :).

@mohamedAdhamc

mohamedAdhamc commented Aug 29, 2022 •

Copy link
Copy Markdown
Member Author

Now the three points I mentioned should be done (there may be more cleaning needed though I will have to review the changes).

Quick brief of what is reached so far:

  • the large number of actions (history pollution) is reduced to only two actions per layer (initial+final) which are grouped in a passive group so as to become one action in the undo/redo stacks. And also the end-level user only sees the color change as one action (no need to show him an initial and a final action).
  • escape to cancel works.
  • also most importantly all that's mentioned works for any number of layers :)

p.s. note to self use sigc::track_obj in the lambdas

*/

public:
static bool repeated_action;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's better to move this to private non-static variables.
Each file has its own ActionSystem. If we try to work with them in parallel (from different threads for example), in the case of static members, this will lead to undefined behavior.

@mohamedAdhamc mohamedAdhamc Sep 16, 2022 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, I was initially thinking that because it probably isn't possible to have more than one of these "repeated actions" at the same time then a static variable would be enough to be used by each "repeated action". But yes I can see how this could get messy and possibly lead to some undefined behavior.

switched over to public non-static variables. As they need to be set and gotten from outside, however if its better to just keep them private and write setters and getters please let me know :)

@mohamedAdhamc

Copy link
Copy Markdown
Member Author

@ice0 done

@ice0

ice0 commented Oct 1, 2022

Copy link
Copy Markdown
Collaborator

Just tested.
When a color is exported to the project library, two undo steps are required to undo the change.
Demonstration and test file below.

The first circle is a normal circle, the second circle has an exported color value.
Notice the chain icon on the Parameters panel.

Screenshot_120

history-exported-issue.mp4

test-history.zip

@mohamedAdhamc

Copy link
Copy Markdown
Member Author

@ice0, I tried replicating but its not doing that.

trying-to-replicate.mp4

(here i set the color from the color wheel twice and it works fine, for some reason the windows screen recorder doesnt capture windows on top of windows xD but the point is shown i hope)

However, I noticed something similar earlier but I don't think it's related to exported values. Sometimes an extra action is shown in addition to the change color action group, as shown in the video you sent there was the regular group but one set layer parameter action wasn't grouped in it for some reason.

it happens only fairly rarely though soI will keep on testing, and debugging to see why this happens sometimes.

i was having the ation group deeted before the action being performed for the very last time which was  a reason that once every couple times an axtra action was shn when the last action differs significantly which usually isnt the case
@mohamedAdhamc

mohamedAdhamc commented Oct 1, 2022 •

Copy link
Copy Markdown
Member Author

ok @ice0 I believe it should be fixed now :).

p.s. connection is a bit low it might take a bit to upload

@mohamedAdhamc
mohamedAdhamc requested a review from ice0 October 7, 2022 00:06
@ice0

ice0 commented Oct 7, 2022

Copy link
Copy Markdown
Collaborator

I think there's room for improvement here, but it looks like the current implementation is leading to a dead end.

What would like to be improved:

  1. Make it easier to work with preview from the point of view of the author of the new code
  2. Remove PassiveGrouper

In order to make sure that this is possible, I have already made my own implementation.

This is how the changes in widget_coloredit.cpp looks like for user (f255b22)

This is how the history looks like:

history-example.mp4

I think maybe to leave this PR as it is, and try to implement the same thing from the scratch?

@mohamedAdhamc

Copy link
Copy Markdown
Member Author

What would like to be improved:

  1. Make it easier to work with preview from the point of view of the author of the new code
  2. Remove PassiveGrouper

I think maybe to leave this PR as it is, and try to implement the same thing from the scratch?

Fair enough, this implementation relies on passive-groupers abilities to do certain things like handling undo history, etc.. so this is in fact very close to its dead end. Will start thinking of a new way that could be better.

I.e. have the repeated actions replace each other smoothly without segmentation errors :). which would be a bit more complex especially with multiple layers being processed at the same time, as some type of sorting might be needed. But if theres already a simpler core idea please let me know :)

@mohamedAdhamc

Copy link
Copy Markdown
Member Author

ok I think i reached something here, and now i'll begin implementing and make a new PR. So the thing here is that we cant just push the first action into the undo stack as that will only make and undo possible and not redo, same for pushing last action only. so we need to push into the undo stack a group of the first and last action, and then that should make undo/redo work fine and regarding the history tree store we just show the action (first or last) normally without being in an expandable passive group as in the previous implementation.

@mohamedAdhamc

mohamedAdhamc commented Oct 12, 2022 •

Copy link
Copy Markdown
Member Author

@ice0, here is what I reached

So in order to fix history pollution and at the same time not compromise undo/redo there has to be some sort of group to be stored in the undo action list which contains the very first and very last action. Now we could make a whole new grouper, and call it something like "repeated grouper", or just expand the existing functionality of the passive grouper. Since there are not much core differences between this "repeated grouper" and the "passive grouper" I chose to
extend the passive grouper here.

Now up until now this is very similar to the last implementation, but with this new commit I have hopefully addressed the issues you mentioned

1- "Making it easier to work with preview from the point of view of the author of the new code ":

Now to be able to use this all one has to do is 2 steps:

  • make a passive group (with the repeated_group parameter set to true in the constructor) before the repeated actions start.
  • have it destruct when they end. The destruction could either be implicit, or explicit using new and delete if that is what suits the nature of the action more.

And also this implementation makes it very easy to add "escape/key to cancel" feature. Just make the escape/key pressed signal call App::get_selected_instance()->cancel_repeated_action() and destruct the group.

( This could all also be further enhanced by using only a variable and then when this variable is set to true while it was false we create the passive group under the hood and when its false we destruct it also and escape to cancel is kept the same way by just doing what is mentioned above. But I think this could make things messier, and also the concept of using something like a passive grouper shouldn't be too foreign for someone working on Synfig code so he just uses it as if he is making a regular passive group but just supplies its constructor one extra argument so that under the hood history pollution is taken care of )

2- to not use a passive grouper:
I assumed what is meant here is to not have an extra grouper shown for the users as was the case with the "change color" grouper. So I removed it and now what is shown is only the action done. So basically the appearance for the
users is the same as before this PR just without the "pollution"

Here is a video of how it is working now:

(at the end I was showing escape to cancel functionality. Also the software I use for recordidng make everything very laggy xd)
https://user-images.githubusercontent.com/100296264/195347809-c2f04092-940c-4bdf-a267-53c6daf39850.mp4

I hope to have fully addresed the things mentioned :) if there is something that I have missed though please let me know.

p.s. I originally was going to make a new pr as suggested but then due to things stated I found it makes sense to continue here. Anyways we can always revert this last commit and head over to a new PR if its needed :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Color wheel fills history too much

3 participants