Skip to content

feat: added support for setting playback interval through movable buttons - #2765

Merged
rodolforg merged 24 commits into
synfig:masterfrom
mohamedAdhamc:playback-bounds
May 4, 2025
Merged

rodolforg merged 24 commits into
synfig:masterfrom
mohamedAdhamc:playback-bounds

Conversation

@mohamedAdhamc

@mohamedAdhamc mohamedAdhamc commented Jul 26, 2022 •

Copy link
Copy Markdown
Member

Quick description of what I did in terms of implementation.

  • added the boundary button rectangle
  • adjusted the old rectangle to make its width smaller by the value which is the width of the button
  • event handling for the button

Things that need opinions:

  • Is the button width good or should it be wider also the color and look of it (I chose blue as I think it fits and was the same in the original request) ?

Feature:

bounds.feature.mp4

Fix #1493

@ice0

ice0 commented Jul 26, 2022

Copy link
Copy Markdown
Collaborator

Looks good.

  1. I propose to add on hover cursor (GDK_LEFT_SIDE/GDK_RIGHT_SIDE). This will show the user that these elements are interactive.
    https://docs.gtk.org/gdk3/enum.CursorType.html
  2. Proposed handles/current handles.
    proposed

I think maybe better to make them as icons? In this case, the artist will be able to draw them himself.

@mohamedAdhamc

Copy link
Copy Markdown
Member Author
  1. I propose to add on hover cursor (GDK_LEFT_SIDE/GDK_RIGHT_SIDE). This will show the user that these elements are interactive.
    https://docs.gtk.org/gdk3/enum.CursorType.html

yes, i think the on hover cursor is a good idea to notify the users that it is movable. But since they are able to be moved in both directions along the x axis why not just this one for both ?
cursor for buttons (3)

@mohamedAdhamc

mohamedAdhamc commented Jul 27, 2022 •

Copy link
Copy Markdown
Member Author

I added the "ew-resize" cursor, however, if other two cursors are more suitable, I could just switch them up it wouldn't be a big deal.

~~ regarding making them as icons. I saw that the icon would have to be rendered into a pixbuf then the pixbuff would be used in the cairo rectangle/context but I dont quite know yet how I would put the icon into the pixbuf, im looking into how to do it, in the documentation it mentions using Gdk::Pixbuf::create_from_file(""); with the strirng being the path to the image but I dont really know how that would work, any ideas?~~

update: so I kinda got to hafway do it but using a random icon from the icon theme using gtk_icon_theme_load_icon () I have to figure out how to do so with a custom icon. in synfig Gtk::Button().render_icon_pixbuf() is used but this is deprecated and it says in docs to use gtk_icon_theme_load_icon () instead, I wonder if the icons added the regular way can be also "added to the theme". or actually an easier bettter way is that it seem i could use a gtk imge and get the pixbf from it.
update: so for some reason Gdk::Cairo::set_source_pixbuf() s causing a seg error

update: ok actually no, seems that as documentation ssays best is gtk_icon_theme_load_icon () which works with regular icons :-)

update: ok I think now its working I just need to make the icon.

update: I made a test icon and set it and everything looks to be working fine, so I'll just spend some time making the icon and then I will hopefully be committing in a bit.

@mohamedAdhamc

Copy link
Copy Markdown
Member Author

These are the new icons:
the new icons (2)

Maybe, they would need some more adjustment but that should be just as easy as adjusting and changing the icon file.

@mohamedAdhamc

Copy link
Copy Markdown
Member Author

@ice0 done.

cr->paint();
cr->restore();

Glib::RefPtr<Gdk::Pixbuf> icon;

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.

I changed the icon just to show the problem:
Icon:
Screenshot_59

Problem:
Screenshot_58

Screenshot_60

As you can see, it overlaps with borders.
My suggestion is to first draw the borders and then draw a handle over them.

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.

ok sounds good will do.

@mohamedAdhamc

Copy link
Copy Markdown
Member Author

ok, now when the added icon is 100 x 200 pixels it should be showing fine, I also added a bit of extra buffer width for the rectangle to be safe.

Comment thread synfig-studio/images/CMakeLists.txt Resolved
Comment on lines +179 to +180
lower_boundary_pixbuf = icon_theme->load_icon("bound_button_icon_lower", 1);
upper_boundary_pixbuf = icon_theme->load_icon("bound_button_icon_upper", 1);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

There is no need to this "1". Or is there?

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.

This is the desired icon size.

@mohamedAdhamc

Copy link
Copy Markdown
Member Author

Hmm, looks like I messed something up while renaming the icon , will look into it when I get back home/ in the morning.

@mohamedAdhamc

mohamedAdhamc commented Aug 7, 2022 •

Copy link
Copy Markdown
Member Author

unfortunately, we are having a power outage now for the past 3/4 hours or so but they say it will end soon I was just about to push a commit in the very latest feature but power went out and laptop is about to die soon :( . will push the commit when power comes back then resolve the comments here.

update: power is back finally i'll push the commit in the latest feature then update here ( looks like this is gonna be delayed till morning it got really late :( )

virtual void draw_background(const Cairo::RefPtr<Cairo::Context> &cr);

void get_bounds_rectangle_dimensions(double& x0, double& x1, double& w , bool lower);
const double boundary_dimension =8;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ugh. It is used in more than one method, so we cannot reduce its scope.
However, if we decide to change the default value, it will force recompilation of any file that #includes Widget_TimeSlider.h

@ice0 opinion?

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.

Agree.
@mohamedAdhamc Can you explain how it is used?

@mohamedAdhamc mohamedAdhamc Aug 9, 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.

boundary_dimension is the width of the draggable handle.
It's used in
1- Widget_Timeslider::on_draw in the process of rendering using cairo to set the dimensions for the bound rectangles and the bound handle.
2- it is also used in the button press and motion notify event to know if the press/ position of the mouse is within the boundaries of the "bound handle"

I guess then we can move it to the cpp file as a global along with the other constants already there.

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.

I think it might be much easier to use Gtk::Image for handles?
It supports event handling, knows the position and size, and we can control the boundaries with margins.
Am I missing something here?

@mohamedAdhamc mohamedAdhamc Aug 9, 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 it might be much easier to use Gtk::Image for handles? It supports event handling, knows the position and size, and we can control the boundaries with margins. Am I missing something here?

well the thing is the whole "timetrack/timeslide/playback area" is drawn with cairo surfaces, I mean the play bounds, the patterns, etc... and it isnt resizable. so I think it kind of makes sense to have this bound handle be the same as well to be moved in the same manner and for overall consistency. An image may make it easier to be resized and all ----- even though really that isn't necessarily needed the only thing needed if a user would want to replace the icon he just needs to make sure to replace it with an icon of the same size and everything should be fine, which I think shouldnt be too foreign as although im not exactly sure but I think replacing any other icon with another of incorrect size may cause problems -----, but I'm not sure how reliable moving a gtk::image would be in terms of being moved around the time track/slider .

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't know if it be better, but you could use a Gtk::Overlay that contains a Gtk::Fixed to then include the Gtk::Images

@mohamedAdhamc

Copy link
Copy Markdown
Member Author

alright, I spent most of the day today working on the latest feature, I'm now heading out and hopefully, when I come back in a couple of hours I will address the comments before I sleep.

@mohamedAdhamc

Copy link
Copy Markdown
Member Author

done

@ice0

ice0 commented Aug 9, 2022

Copy link
Copy Markdown
Collaborator

Increased boundary_dimension to 80.

It looks like the changes should be mirrored?

Screenshot_69

@mohamedAdhamc

mohamedAdhamc commented Aug 9, 2022 •

Copy link
Copy Markdown
Member Author

Increased boundary_dimension to 80.

It looks like the changes should be mirrored?

I think the problem here is that the boundary dimension was increased but the icon size wasnt, and because the icon is rendered from left to right for the lower handle it is fully drawn then there is a big space left unused to the right of it, and for the upper bound it is drawn fully at the start of the rectangle specified for the icon and then also a large portion is left unused.

I mean increasing the boundary dimension without increasing the width of the icon would always cause issue, the way it is now if I remember correctly is that the icon of size 100x200 pixels is drawn perfectly, so Im guessing in this case increasing the width of the cairo rectangle of the icon from 8 to 80 width would have to be increased from 100 to 1000.

p.s. this is how it looks like
correct size icon bound

also the way it was now is that I had extra width in the icons cairo rectangle to accomndate for any extra parts but I realized instead its better to just have the icon be the correct size which isnt exactly 100 x 200, more like 85x200. im experimenting to see the perfect size.

p.s. this is a 85x200 icon
the new icon size update
I will make the icon here 85x200 and then anyone replacing it with a 85x200 icon the new icon should be showing fully without a problem.

update: this is the new 85x200 icon
new 85x200 icon

@mohamedAdhamc

Copy link
Copy Markdown
Member Author

@rodolforg, done :)

p.s. I believe the deadline for the mentor mid- evaluation is sometime tomorrow the 12th. they probably should've sent out an email, but I'm notifying here just in case as my timeline is non-standard.

@rodolforg rodolforg left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

One thing that bothers me is that the current time changes when dragging the playback boundaries.
But I don't know if it is really a problem or just me XD

The rest seems to work nice :)

@rodolforg
rodolforg dismissed their stale review August 14, 2022 16:16

I'm "letting" @ice0 and @morevnaproject decide here XD

@mohamedAdhamc

Copy link
Copy Markdown
Member Author

One thing that bothers me is that the current time changes when dragging the playback boundaries. But I don't know if it is really a problem or just me XD

Hmm, I'm not sure either if it could be a problem - that is better left for you guys to decide- but if it is of any help. The reason I thought it may be helpful is while moving the bound knowing the exact place where it is, and if there is already an animation in place it lets you visualise which part of it you are bounding as was shown in the video above.

@ice0

ice0 commented Aug 17, 2022

Copy link
Copy Markdown
Collaborator

I think the problem here is that the boundary dimension was increased but the icon size wasnt

  1. I thought the boundary dimension is the space between the handle and the borders.
    If not, how is it used?

Screenshot_84

One thing that bothers me is that the current time changes when dragging the playback boundaries.

  1. Same for me, but I prefer to hear @morevnaproject opinion here.

  2. I suggest to use synfig::Rect class to check bounds.
    Example pseudcode:

Point cursor_pos(event->x, 0);

Rect low_bound = get_play_bounds_rect(true);
Rect up_bound  = get_play_bounds_rect(false);

Before:

if (moving_lower_bound_handle || (current_x <= x1 && current_x >= x1 - boundary_dimension))
	   get_window()->set_cursor(bounds_cursor);
else if (moving_upper_bound_handle || ((current_x <= (z0 + boundary_dimension))  && (current_x >= (z0))))
	   get_window()->set_cursor(bounds_cursor);
else
	   get_window()->set_cursor(default_cursor);

After:

bool moving_handle = moving_lower_bound_handle || moving_upper_bound_handle;
if (moving_handle || low_bound.contains(cursor_pos) || up_bound.contains(cursor_pos))
	get_window()->set_cursor(bounds_cursor);
else
	get_window()->set_cursor(default_cursor);

As for me now it's more clear what is going on here.

  1. Cursor problem:
cursor-issue.mp4

@mohamedAdhamc

Copy link
Copy Markdown
Member Author

Time has finally come!

Exactly my reaction when I received the "approved" email notification a few hours back XD.

@rodolforg

Copy link
Copy Markdown
Contributor

Should I merge, @mohamedAdhamc ? XD I think I'll squash all commits then merge. What do you think?

@mohamedAdhamc

mohamedAdhamc commented May 3, 2025 •

Copy link
Copy Markdown
Member Author

Should I merge, @mohamedAdhamc ? XD

Konstantin approved so I'm assuming things are good 😄 . I'll also give it one final test from my side as extra precaution.

update: tested, seems to be functioning as expected.

I think I'll squash all commits then merge. What do you think?

Yes sure, I think most of the commits were just multiple fixes and adjustments anyways.

@rodolforg rodolforg left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Final touches then ;)

@github-actions

github-actions Bot commented May 4, 2025

Copy link
Copy Markdown

Thank you for attempting to improve your contribution description!
Below is how your updated contribution will appear in Synfig's release notes. Review it and make further improvements until you're satisfied!

✨ New Features

  • Added support for setting playback area through movable buttons

    Quick description of what I did in terms of implementation.
    -added the boundary button rectangle
    -adjusted the old rectangle to make its width smaller by the value which is the width of the button
    -event handling for the button

    things that need opinions: -is the button width good or should it be wider also the color and look of it (I chose blue as I think it fits and was the same in the original request) ?

    feature:

    bounds.feature.mp4

    Fixes #1493

@mohamedAdhamc

Copy link
Copy Markdown
Member Author

Nice catches, qt creator has the tendency to be really weird with indentations, it wasn't even showing me some of the tabs correctly now xD.

Btw -sidenote- has there even been a clang file made for synfig ? I don't recall one being mentioned before. Maybe if we make one that only targets indentation for pr specific changes it could be helpful in reviews just to ask people to run it. What do you think ?

@rodolforg

Copy link
Copy Markdown
Contributor

Btw -sidenote- has there even been a clang file made for synfig ? I don't recall one being mentioned before. Maybe if we make one that only targets indentation for pr specific changes it could be helpful in reviews just to ask people to run it. What do you think ?

I'm trying to create one, but it still has some issues.
synfig-clang-format.zip

@rodolforg rodolforg changed the title feat: added support for setting playback area through movable buttons feat: added support for setting playback interval through movable buttons May 4, 2025
@github-actions

github-actions Bot commented May 4, 2025

Copy link
Copy Markdown

Thank you for attempting to improve your contribution description!
Below is how your updated contribution will appear in Synfig's release notes. Review it and make further improvements until you're satisfied!

✨ New Features

  • Added support for setting playback interval through movable buttons

    Quick description of what I did in terms of implementation.
    -added the boundary button rectangle
    -adjusted the old rectangle to make its width smaller by the value which is the width of the button
    -event handling for the button

    things that need opinions: -is the button width good or should it be wider also the color and look of it (I chose blue as I think it fits and was the same in the original request) ?

    feature:

    bounds.feature.mp4

    Fixes #1493

@github-actions

github-actions Bot commented May 4, 2025

Copy link
Copy Markdown

Thank you for attempting to improve your contribution description!
Below is how your updated contribution will appear in Synfig's release notes. Review it and make further improvements until you're satisfied!

✨ New Features

  • Added support for setting playback interval through movable buttons

    Quick description of what I did in terms of implementation.

    • added the boundary button rectangle
    • adjusted the old rectangle to make its width smaller by the value which is the width of the button
    • event handling for the button

    Things that need opinions:

    • Is the button width good or should it be wider also the color and look of it (I chose blue as I think it fits and was the same in the original request) ?

    Feature:

    bounds.feature.mp4

    Fix #1493

@rodolforg
rodolforg merged commit 758de39 into synfig:master May 4, 2025
@rodolforg

Copy link
Copy Markdown
Contributor

Merged! Thank you for your contribution.

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.

Better way to set playback area

4 participants