Skip to content

[UI Feature 1] Change Parameters with the Mouse - #2717

Open
mohamedAdhamc wants to merge 36 commits into
synfig:masterfrom
mohamedAdhamc:changing-params-mouse
Open

mohamedAdhamc wants to merge 36 commits into
synfig:masterfrom
mohamedAdhamc:changing-params-mouse

Conversation

@mohamedAdhamc

Copy link
Copy Markdown
Member

This is main feature number 1 in my project. it was asked for in #2528 .

The first commit is very preliminary (as in includes comments that I write for my self,etc...) it includes
1- switching the mouse cursor to "move" when pressing on the parameters row (will probably have to be a diffrent icon when its actually done). then switching it back to default when released.
2- storing the selected row and tree view selection object and then updating them when changed.

Main things left to do
1- Change the actual values. moving right increases, left decreases. I'm assuming this would most likely be done through the TreeView model.
2- Of course also optimization, clean ups, and changing the mouse cursor to a more suitable icon. Also probably oher things that come up in the way, this is probably one of the "longer" features.

@mohamedAdhamc

mohamedAdhamc commented Jun 29, 2022 •

Copy link
Copy Markdown
Member Author

Hey @ice0 , @rodolforg

so I'm going through with the suggested implementation, and now I'm working on incrementing/decrementing the values. I believe there might be two ways to do this:

1- through getting the value base stored in the tree model and then going all the way back to its original type and then incrementing it. I think this would require more work but the advantage would be that its independent of the "view" columns implementation ( i mean the spin button). However I think it also might cause problems with the spin button maybe not updating etc...

2-through just incrementing the spin button. I think this might be easier however this would be spin button dependent so if in the future the spin button is to be changed to another thing this would have to be updated as well probably.

now the questions are
1- How to get the c++ value from the ValueBase object. so then I can increment and update the valueBase
2- How to reach the spin button from the CellRenderer_ValueBase class. which actually turned out to be a bit complicated as I found the original spibutton for example is a member of Widget_ValueBase class which is then used in a valuebase entry class which is then finally used in the CellRenderer_ValueBase class. so it's a bit complex xD.

I will be spending tomorrow mostly trying to answer these two or either as I think after they are answered rest is a lot easier. However, if you guys could maybe give some insight onto them it would help a lot.

Thanks!

update: so far I think maybe 1 is better ? i'm curently working on finding a way to increment the valuebase.

update 2: ok so I found that there is already a function in the ValueBase class called get() which is a "template to get the value of the class ta by casting the ValueBase". I think if I test it out and it works then the rest would be to increment/decrement and then finally set the new data (which I'm not sure how it will be done yet).

update 3: using the get() method and passing the data as a parameter just gives out a segmentation error. so something is off

update 4: get_string works fine for getting the value which can be converted to the appropriate type now Im looking into how to set the new data in the valuebase.

update 5: get() would be the best as it would return the value right away with the correct type and there is also a get_type which could be used to get the type of the value to put as the argument for get(), however doing so the compiler complains that the "type" is private in the class Type. Also seems there is also a set() which would be implented the same way. but for now I have to see what the type class is about.

update 6: ok so get returns a value of type synfig::type which is still not the c++ type (which im assuming would be some variation of a double/float). Again I have to see what the type class is about.

@mohamedAdhamc

mohamedAdhamc commented Jul 1, 2022 •

Copy link
Copy Markdown
Member Author

ok guys so this is driving me nuts xD
there are already implemented get and set functions for the Value Base but I cant seem to use them
this is the function i'm talking about
function def

and these are the errors:

error 1
error 2

Basically the main obstacle right now is getting the value of the ValueBase as a float and then setting it back again. if this is done correctly the feature would be almost done.

update: maybe this is done through the Value class ?

ok I think I manged to get it as a float using the value class now im trying to set it.

update got it to set too and now clicking on the rows succesfully increments the parameter woohoo xD.

@ice0

ice0 commented Jul 2, 2022

Copy link
Copy Markdown
Collaborator

update got it to set too and now clicking on the rows succesfully increments the parameter woohoo xD.

Awesome!

@mohamedAdhamc

mohamedAdhamc commented Jul 2, 2022 •

Copy link
Copy Markdown
Member Author

Ok so quick update here

what I have now is
1- cursor changes on button press and resets on release
2- data in the treeview row needed is succesfully obtained, incremented/decremented, and set again.
3- inital cursor position which is sent along with the mouse press event is stored
4- new mouse position/positions are also obtained this time through the window .

What's left here is somehow to loop in the button press callback until the button is released. I dont quite know how that could be done yet as the event sent to the button press method isn't updated meaning i cant do something like check for when its type becomes GDK_BUTTON_RELEASE. I'm thinking maybe signals somehow, if anyone has an idea it would be appreciated :-)

overall:
if this last part is done this feature would be 90 percent done maybe just optimizations, and cleanups will be left to do.

@rodolforg

rodolforg commented Jul 2, 2022 •

Copy link
Copy Markdown
Contributor

Basically the main obstacle right now is getting the value of the ValueBase as a float and then setting it back again. if this is done correctly the feature would be almost done.

Our (irritating) way to do it is:

float data = value.get(float());

I don't know if this is useful here (I'm sleepy now), but Ducks have set_edit_immediatelly() method - but this will pollute undo history.

@mohamedAdhamc

mohamedAdhamc commented Jul 2, 2022 •

Copy link
Copy Markdown
Member Author

Our (irritating) way to do it is:

float data = value.get(float());

Yes, actually I have managed to get and set using a class called Value, but this could -possibly- be a neater way to do it. will have to look into it at the end.

@ice0

ice0 commented Jul 3, 2022

Copy link
Copy Markdown
Collaborator

1- cursor changes on button press and resets on release

  1. It is better to save and restore the previous cursor, in case it somehow changed here.
  2. Please check the history while you change the value - it should not pollute history while you moving mouse - only set the value then you release mouse button. Also pressing the Esc key should cancel the change and return the original value.

@mohamedAdhamc

mohamedAdhamc commented Jul 3, 2022 •

Copy link
Copy Markdown
Member Author

Also pressing the Esc key should cancel the change and return the original value.

Well, currently ctr+z undoes the change. The way its implemented is that the ValueBase itself of the parameter is changed. There might be something I'm missing here. Maybe you mean this should be done through the spin button?

update:
regarding

What's left here is somehow to loop in the button press callback until the button is released. I dont quite know how that could be done yet as the event sent to the button press method isn't updated meaning i cant do something like check for when its type becomes GDK_BUTTON_RELEASE. I'm thinking maybe signals somehow, if anyone has an idea it would be appreciated :-)

I have found that gtk has two functions which help in doing this, namely gtk_events_pending(), and gtk_main_iteration(); . Tested the new implementation now the incrementation/decrementation continues until button release . I for a little thought that I would have had to do some multi-threading which would have been overkill xD.

@mohamedAdhamc

mohamedAdhamc commented Jul 3, 2022 •

Copy link
Copy Markdown
Member Author

ok guys, so this is how its working so far
moving right increments, moving left decrements. incrementing/decrementing keeps going until button release
(sorry for the horrible recording quality though xD)
https://media.giphy.com/media/tGGfbeFgLtN7dlD2yE/giphy.gif

Issues/things left/ways of improving
1- Currently this method does pollute the history as each iteration which increments/decrements shows up in the history.
possible solution: Im thinking maybe disable the history somehow for the iterations. I.E makes history only capture
final change. However, I dont really have an idea how the history is implemented so I'm not sure how difficult it would be.

2- moving further right increases incrementation speed. this shouldnt be time consuming though.

3- increment by smalled amounts but faster (in the video it incremented by 1 every time). Also not time consuming but I
wonder what its effect would be on the performance aspect.

4- Oh and also I think the cursor should be diffrent xD. not the one I have now. Any suggestions ?

p.s. I will be working on 2, and 3 then cleaning up the code a bit and then make a commit by today.

update: now increases by smaller amount and does so faster

there is still a slight bug with selection + history is polluted
@rodolforg

Copy link
Copy Markdown
Contributor

@mohamedAdhamc

  1. I think you should receive and parse these events in the cell editor widget itself, not in the TreeView itself. @ice0 ?
  2. In order to reduce undo history pollution, I propose you to deal/handle/"create" with 3 signals: editing-started, editing-canceled, editing-done. This way you can apply temporary changes and "easily" discard them, keeping only the final value (if edition was not canceled by pressing Esc for example).

@ice0

ice0 commented Jul 4, 2022

Copy link
Copy Markdown
Collaborator

Well, currently ctr+z undoes the change. The way its implemented is that the ValueBase itself of the parameter is changed. There might be something I'm missing here. Maybe you mean this should be done through the spin button?

I mean pressing the Esc key while you are pressing the mouse button and moving it.

I think you should receive and parse these events in the cell editor widget itself, not in the TreeView itself. @ice0 ?

Yes, this is the next step.

@ice0

ice0 commented Jul 4, 2022

Copy link
Copy Markdown
Collaborator

@mohamedAdhamc

Just tested. It should change the value only when you move the mouse.

@ice0

ice0 commented Jul 4, 2022

Copy link
Copy Markdown
Collaborator

I have found that gtk has two functions which help in doing this, namely gtk_events_pending(), and gtk_main_iteration(); . Tested the new implementation now the incrementation/decrementation continues until button release . I for a little thought that I would have had to do some multi-threading which would have been overkill xD.

This all happens because you doing this wrong way.

You should subscribe to signal_motion_notify_event() and get mouse position from here. Doing endless cycle inside event listener or anywhere in event thread is just a bad practice.

I recommend you to write a simple Gtk application just to better understand how it works.

@mohamedAdhamc

mohamedAdhamc commented Jul 4, 2022 •

Copy link
Copy Markdown
Member Author

Alright guys will be looking into these and updating you soon.

@mohamedAdhamc

mohamedAdhamc commented Jul 4, 2022 •

Copy link
Copy Markdown
Member Author

Just tested. It should change the value only when you move the mouse.

@ice0 Just so I'm sure I understand you correctly here. You mean that even if the mouse is to the right of the initial clicking position, the parameter shouldn't increase. It should only increase while the mouse is moving right correct?

update:
{ used the motion notify event along with the button event and it is indeed way better. will be making a commit in a bit.
as of now moving right increases parameter only while moving, and opposite for moving left.

now major things left are:
1- fixing the history pollution
2- Esc to cancel change, this will propably be kind of related to point one though I believe.
3- using the celll editor widget instead of the treeview. although i'm not sure what is meant by that yet and why it is better
than the way it is done now. }

Also are the signal_edited/cancelled etc.. proposed by @rodolforg related to switching over to using the cell editor widget or not because I dont quite get what is meant here.

main changes
1- using motion notify instead of limitless loop
2- parameter changes only happen when the mouse is moving
@mohamedAdhamc

Copy link
Copy Markdown
Member Author

@ice0 should I start with working on fixing history pollution first or moving to the cell editor widget instead of treeview ?

p.s. until I get a response from you guys i will be workking onfixing history pollution more specifacaly first I will be trying to understand how the history works for the parameter layer values then seeing how it could be stopped while increasin with mouse.

@ice0

ice0 commented Jul 12, 2022

Copy link
Copy Markdown
Collaborator

@ice0 should I start with working on fixing history pollution first or moving to the cell editor widget instead of treeview ?

p.s. until I get a response from you guys i will be workking onfixing history pollution more specifacaly first I will be trying to understand how the history works for the parameter layer values then seeing how it could be stopped while increasin with mouse.

Yes, better to start from history.

@mohamedAdhamc

mohamedAdhamc commented Jul 12, 2022 •

Copy link
Copy Markdown
Member Author

update: I got the history to stop making new actions using a flag, I will be trying to enhance it up a bit to be a bit more sophisticated and will be committing before the end of the day hopefully :-)

now history dock only shows the final change when changing parameter value by mouse.
@mohamedAdhamc

Copy link
Copy Markdown
Member Author

ok so as stated in the commit description. this commit makes only the final changed value appear in the history dock. There probably might be a more sophisticated way of doing this but I think this was the simplest approach I could think of.

so a rough updated version of whats left:
1- using the cell editor widget instead of the treeview.
2- Esc to cancel change, this will propably be kind of related to point one though I believe.

2 shouldnt take much time it would just be capturing the escape press and canceling change. the main thing here is 1.
Could you guys explain more what you meant by one as I'm not really sure what is meant, and im kind of worried it will mean reimplementing a huge chunk of things done xD.

@ice0

ice0 commented Jul 13, 2022

Copy link
Copy Markdown
Collaborator

ok so as stated in the commit description. this commit makes only the final changed value appear in the history dock. There probably might be a more sophisticated way of doing this but I think this was the simplest approach I could think of.

There is an easy way to check if this is done right. As you already know, Synfig has a history pollution issue when choosing a color using the color wheel. A good and universal solution should solve both of these problems.
So, I propose the following plan:

  1. Solve the color history pollution issue in this PR (this will help you see the common code/solution);
  2. Extract the code that fixes the color history issue into the new PR;
  3. These changes will be merged into the master branch;
  4. Rebase this PR to master branch (this will remove already merged changes).

@ice0

ice0 commented Jul 13, 2022

Copy link
Copy Markdown
Collaborator

Could you guys explain more what you meant by one as I'm not really sure what is meant, and im kind of worried it will mean reimplementing a huge chunk of things done xD.

First please read about Gtk Inspector (this will help you a lot).
https://wiki.gnome.org/Projects/GTK/Inspector

In short, you need to set an environment variable before running the ./synfigstudio binary. For example:

GTK_DEBUG=interactive ./synfigstudio

Now about cell editor.

Here's how a standard Gtk::Grid should look like (I've hidden our custom widget here):

Screenshot_3

This is how it looks with custom widget:

Screenshot_4

Reduced opacity for better understanding:

Screenshot_6

This is how this widget looks in widgets tree (you can see this Gtk Inspector):

Screenshot_5

This widget was implemented using custom Gtk::CellRenderer (https://docs.gtk.org/gtk3/class.CellRenderer.html)
Code is located in synfig-studio/src/gui/cellrenderer/cellrenderer_value.h

@mohamedAdhamc

mohamedAdhamc commented Jul 13, 2022 •

Copy link
Copy Markdown
Member Author

. So, I propose the following plan:

  1. Solve the color history pollution issue in this PR (this will help you see the common code/solution);
  2. Extract the code that fixes the color history issue into the new PR;
  3. These changes will be merged into the master branch;
  4. Rebase this PR to master branch (this will remove already merged changes).

ok, sounds good. I will be looking to do that but also I'm not sure how complex that could get and possibly divert us from the project at focus. However, it's a bit early to know that, I will first spend some time looking into that as yes a global solution for both would be perfect.

First please read about Gtk Inspector (this will help you a lot). https://wiki.gnome.org/Projects/GTK/Inspector

In short, you need to set an environment variable before running the ./synfigstudio binary. For example:

GTK_DEBUG=interactive ./synfigstudio

surprisingly in windows it was as simple as just typing out that command (^_^). great I think this will save time.

@mohamedAdhamc

mohamedAdhamc commented Jul 13, 2022 •

Copy link
Copy Markdown
Member Author

update:
so I have been looking at the color wheel history pollution problem. It could have been solved basically the same way as here using a flag but the problem for the color wheel, in particular, is that the color wheel in itself is a part of the Gtk::ColorSelection and there doesn't seem to be a way where I could access it from the parent widget if it were possible then maybe I would just use the same approach and connect to its button/key release events to know when the drag stopped (as I dont think it has signal_drag_started(), etc...)

but from reading in issue #451 it seems like @rodolforg solved a similar issue (with I think waypoints ?) but I cant seem to determine where exactly it is? if its possible here I could just have it done the same way o try and keep things more unified. Right now I have it done using a flag that is checked for in the function which makes the new row in the history tree view.

@mohamedAdhamc

mohamedAdhamc commented Jul 22, 2022 •

Copy link
Copy Markdown
Member Author

I have added the same method of fixing history pollution used in the color wheel pollution fix and added the ability to press escape for cancelling. I will be testing it out a bit then cleaning up the code and pushing a comit when I'm done.

@mohamedAdhamc

Copy link
Copy Markdown
Member Author

ok, that took a while xD. But I tried my best to test every single case I could think of to make sure that everything in the parameters panel is working as it should be along with the feature. I tested when there were waypoints around and when not and made sure to my best that I checked everything also handling things when they showed up.

I haven't cleaned up the code completely though, will do that tommorow first thing hopefully, and it shouldnt take long all the testing was done today.

Looking forward to having you guys test and review it.

{

auto t_now = std::chrono::high_resolution_clock::now();
double elapsed_time_ms = std::chrono::duration<double, std::milli>(t_now-t_start).count();

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.

Why are you trying to implement the click behavior yourself? Why not just use standard event listeners?

@mohamedAdhamc mohamedAdhamc Jul 22, 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 couldn't find anything in the standard listeners regarding the normal clicked event, closest I found was a long click gesture which I believe was also more geared toward touch devices. If there is one though? yes it would be much better.

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.

signal_button_press_event?

@mohamedAdhamc mohamedAdhamc Jul 22, 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.

But then that gets executed right away on press. My understanding of a click is that there has to be a press followed by a release right away. Then after that it is a click and we enter edit mode. And if there is a press and the mouse is moving while the press is going on without the release then it's a drag.

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.

Ok, I need a time to make a test app to test this.

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.

Alright, sounds good.

- to make the cancellation show without needing button release or movement
- to not block the dialog exits escape
making color change from wheel drag and color change from else where mutually exclusive.
@rodolforg

Copy link
Copy Markdown
Contributor

I tested and you are just hiding history pollution on the History panel. But ctrl+Z still suffers the problem: every little change at a time.

@mohamedAdhamc

Copy link
Copy Markdown
Member Author

I tested and you are just hiding history pollution on the History panel. But ctrl+Z still suffers the problem: every little change at a time.

Oh yes I haven't updated the history pollution as I was waiting on the history pollution pr. However at the current state if updated the history pollution should work and the undo.

@ice0

ice0 commented Oct 1, 2022

Copy link
Copy Markdown
Collaborator

@mohamedAdhamc

Try to merge changes from color-wheel-history-pollution branch and check if it works.

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

Copy link
Copy Markdown
Member Author

ok, looks like ill have to clean up this branch a bit before seeing how it looks like here, as a previous way was implemented here which conflicts with the new "to be used" way

@mohamedAdhamc

Copy link
Copy Markdown
Member Author

ok @ice0 , i merged the changes and it seems like its working fine (exactly same way as in color wheel).

while testing some things came into mind though.
1- should the increase/decrease increase in magnitude as the mouse goes further to the right/left without stopping ?
i.e. the more I keep moving the cursor to the right the faster the increase is.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants