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

Should AeCairoContext provide a single source setter method that double-dispatchs on Color and AeCairoSurface? #88

Open
tinchodias opened this issue Dec 18, 2024 · 1 comment

Comments

@tinchodias
Copy link
Contributor

In cairo, the "source" can be a color, a gradient or a surface. The C API and our bindings are:

void	cairo_set_source () -> #source:
void	cairo_set_source_rgb () -> #sourceColorR:g:b:  
void	cairo_set_source_rgba () -> #sourceColorR:g:b:a:
void	cairo_set_source_surface () -> #sourceSurface:x:y:

The first function receives a AeCairoPattern, an instance of this hierarchy:
Screenshot 2024-12-18 at 14 14 53
in the other hand, the cairo_set_source_rgb, cairo_set_source_rgba and cairo_set_source_surface are only shortcuts that internally create a pattern but avoid creation of the patterns explicitly on lib users.

In our bindings, I added this method to simplify setting as source an instance of Color:

AeCairoContext>>
sourceColor: aColor

	aColor isTranslucent
		ifTrue: [
			self
				sourceColorR: aColor red
				g: aColor green
				b: aColor blue
				a: aColor alpha ]
		ifFalse: [
			self
				sourceColorR: aColor red
				g: aColor green
				b: aColor blue ]

My point: When writing examples and tests, several times I had the intuition to type aCairoContext source: Color black instead of aCairoContext sourceColor: Color black.

We could provide something like:

AeCairoContext>>
source: anObject
	anObject aeSetAsSourceIn: self

and then:

AeCairoSurface>>
aeSetAsSourceIn: aCairoContext
	aCairoContext sourceSurface: self x: 0 y: 0

and convert AeCairoContext>>sourceColor: into Color>>aeSetAsSourceIn:.

Not sure if I like it, anyway.

👉 Please share your opinions 👈

@tinchodias
Copy link
Contributor Author

This would include as well renaming current AeCairoContext>>source: as sourcePattern:, and add AeCairoPattern>>asSetAsSourceIn: that sets it when using the generic source:.

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

No branches or pull requests

1 participant