Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix!: for some layers hit_check() missed some blend method influence #2754

Merged
merged 1 commit into from Jul 21, 2022

Conversation

rodolforg
Copy link
Contributor

Example:
Layer_Bitmap and Layer_SolidColor ignored BLEND_BEHIND completely.

Gradient layers need some investigation
(Conical, Curve, Linear, Radial, Spiral, Noise).
They behave differently, also checking the alpha channel for some blend
methods.

BREAKING CHANGE: synfig API changed:

  • add Layer_Composite::basic_hit_check() as a helper

Example:
 Layer_Bitmap and Layer_SolidColor ignored BLEND_BEHIND completely.

Gradient layers need some investigation
(Conical, Curve, Linear, Radial, Spiral, Noise).
They behave differently, also checking the alpha channel for some blend
methods.

BREAKING CHANGE: synfig API changed:
- add `Layer_Composite::basic_hit_check()` as a helper
@rodolforg
Copy link
Contributor Author

I just found out Layer_PasteCanvas has issues too.

@ice0
Copy link
Collaborator

ice0 commented Jul 21, 2022

Does it affect rendering?

@rodolforg
Copy link
Contributor Author

No, hit_check is for checking mouse click.

@ice0 ice0 merged commit 2363d73 into synfig:master Jul 21, 2022
@ice0
Copy link
Collaborator

ice0 commented Jul 21, 2022

Ok.
Merged. Thank you!

@rodolforg rodolforg deleted the fix-some-hitcheck branch July 21, 2022 09:41
@rodolforg
Copy link
Contributor Author

Coming back to the gradient layers, here are current code of each one, preceded by the commit id and date.
All of them are the same way as the initial commit from darco. Exception is LinearGradient that a non-relevant part was changed way later by blackwarthog.

ConicalGradient, LinearGradient, RadialGradient and SpiralGradient use the same hit_check algorithm.
NoiseGradient and CurveGradient use a different one each.

Most of them use this part:

if((get_blend_method()==Color::BLEND_STRAIGHT || get_blend_method()==Color::BLEND_COMPOSITE) && color_func(point).get_a()>0.5)
	return const_cast<ConicalGradient*>(this);

CurveGradient changes it by appending another || get_blend_method()==Color::BLEND_ONTO before ) &&

NoiseGradient ignores the blend method:

if(color_func(point,0,context).get_a()>0.5)
	return const_cast<Noise*>(this);

Finally, for comparison, this is the equivalent part for other layers (after this PR):

Layer::Handle tmp;
// if we are behind the context, and the click hits something in the context
if (get_blend_method() == Color::BLEND_BEHIND && (tmp = context.hit_check(point)))
	// then return the thing it hit in the context
	return tmp;

// if we're using an 'onto' blend method and the click missed the context
if (Color::is_onto(get_blend_method()) && !(tmp = context.hit_check(point)))
	// then it misses everything
	return nullptr;

So, what should we do? @morevnaproject @ice0 @anyone

Complete hit_check() methods below

16b3beced2 (Robert B. Quattlebaum Jr)  2005-03-24 21:02:18 +0000


synfig::Layer::Handle
ConicalGradient::hit_check(synfig::Context context, const synfig::Point &point)const
{
	if(get_blend_method()==Color::BLEND_STRAIGHT && get_amount()>=0.5)
		return const_cast<ConicalGradient*>(this);
	if(get_amount()==0.0)
		return context.hit_check(point);
	if((get_blend_method()==Color::BLEND_STRAIGHT || get_blend_method()==Color::BLEND_COMPOSITE) && color_func(point).get_a()>0.5)
		return const_cast<ConicalGradient*>(this);
	return context.hit_check(point);
}


16b3beced2 (Robert B. Quattlebaum Jr)  2005-03-24 21:02:18 +0000
synfig::Layer::Handle


CurveGradient::hit_check(synfig::Context context, const synfig::Point &point)const
{
	if(get_blend_method()==Color::BLEND_STRAIGHT && get_amount()>=0.5)
		return const_cast<CurveGradient*>(this);
	if(get_amount()==0.0)
		return context.hit_check(point);
	if((get_blend_method()==Color::BLEND_STRAIGHT || get_blend_method()==Color::BLEND_COMPOSITE|| get_blend_method()==Color::BLEND_ONTO) && color_func(point).get_a()>0.5)
		return const_cast<CurveGradient*>(this);
	return context.hit_check(point);
}



16b3beced2 (Robert B. Quattlebaum Jr)  2005-03-24 21:02:18 +0000
(the two lines about "params" is: 530b4a058a (Ivan Mahoniarthog)       2014-03-23 21:33:58 +0700



synfig::Layer::Handle
LinearGradient::hit_check(synfig::Context context, const synfig::Point &point)const
{
	if(get_blend_method()==Color::BLEND_STRAIGHT && get_amount()>=0.5)
		return const_cast<LinearGradient*>(this);
	if(get_amount()==0.0)
		return context.hit_check(point);

	Params params;
	fill_params(params);

	if((get_blend_method()==Color::BLEND_STRAIGHT || get_blend_method()==Color::BLEND_COMPOSITE) && color_func(params, point).get_a()>0.5)
		return const_cast<LinearGradient*>(this);
	return context.hit_check(point);
}

16b3beced2 (Robert B. Quattlebaum Jr)  2005-03-24 21:02:18 +0000


synfig::Layer::Handle
RadialGradient::hit_check(synfig::Context context, const synfig::Point &point)const
{
	if(get_blend_method()==Color::BLEND_STRAIGHT && get_amount()>=0.5)
		return const_cast<RadialGradient*>(this);
	if(get_amount()==0.0)
		return context.hit_check(point);
	if((get_blend_method()==Color::BLEND_STRAIGHT || get_blend_method()==Color::BLEND_COMPOSITE) && color_func(point).get_a()>0.5)
		return const_cast<RadialGradient*>(this);
	return context.hit_check(point);
}


16b3beced2 (Robert B. Quattlebaum Jr)  2005-03-24 21:02:18 +0000


synfig::Layer::Handle
SpiralGradient::hit_check(synfig::Context context, const synfig::Point &point)const
{
	if(get_blend_method()==Color::BLEND_STRAIGHT && get_amount()>=0.5)
		return const_cast<SpiralGradient*>(this);
	if(get_amount()==0.0)
		return context.hit_check(point);
	if((get_blend_method()==Color::BLEND_STRAIGHT || get_blend_method()==Color::BLEND_COMPOSITE) && color_func(point).get_a()>0.5)
		return const_cast<SpiralGradient*>(this);
	return context.hit_check(point);
}


16b3beced2 (Robert B. Quattlebaum Jr)  2005-03-24 21:02:18 +0000


synfig::Layer::Handle
Noise::hit_check(synfig::Context context, const synfig::Point &point)const
{
	if(get_blend_method()==Color::BLEND_STRAIGHT && get_amount()>=0.5)
		return const_cast<Noise*>(this);
	if(get_amount()==0.0)
		return context.hit_check(point);
	if(color_func(point,0,context).get_a()>0.5)
		return const_cast<Noise*>(this);
	return synfig::Layer::Handle();
}

@ice0
Copy link
Collaborator

ice0 commented Aug 10, 2022

So, what should we do?

Do you mean to fix them so they don't ignore the blend method?

@rodolforg
Copy link
Contributor Author

Yes.

And they bring the alpha value influence that others (unified in this PR) don't take it into account, simply ignore it.

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.

None yet

2 participants