-
-
Notifications
You must be signed in to change notification settings - Fork 673
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
vector: add utility functions to draw Path #3150
Comments
I'm fine to add a utility functions, but
It is not good to use func DrawFilledPath(dst *ebiten.Image, path vector.Path, color color.Color)
func StrokePath(dst *ebiten.Image, path vector.Path, color color.Color) Also, would it be OK to fill paths only with a solid color? Also, do we need geometry matrix as an option? |
Yeah, sure, looks good to me.
Do you mean dashes or transparent color? The current api of vector utility functions dont have that so it should be ok without it by default.
I guess |
Note to myself: #3124 might be related. In order to render a better edge, we would need a special shader IIUC. In this case, the utility functions we are adding might be a good wrapper to do this. |
Btw, could you remind me please, why it needs to be:
I found it somewhere near vector example and can't remember why its made this way. |
I mean using an image with the path. I think just one color is fine along with the other existing utility functions. I suggest type VectorOptions struct {
GeoM ebiten.GeoM
ColorScale ebiten.ColorScale
Blend ebiten.Blend
AntiAlias bool
}
func DrawFilledPath(dst *ebiten.Image, path vector.Path, op *VectorOptions)
func StrokePath(dst *ebiten.Image, path vector.Path, op *VectorOptions) I might change the idea later. Let me think more.
The sub image size is 1x1.
In order to prevent bleeding edges. See https://ebitengine.org/en/blog/subimage.html |
Probably better to call it vector.DrawOptions like it was made with text.DrawOptions. |
With deprecating the existing utility functions, what about these type FillOptions struct {
ColorScale ebiten.ColorScale
Blend ebiten.Blend
AntiAlias bool
}
func FillPath(dst *ebiten.Image, path vector.Path, op *FillOptions)
func FillCircle(dst *ebiten.Image, x, y, r float32, op *FillOptions)
func FillRect(dst *ebiten.Image, x0, y0, x1, y1 float32, op *FillOptions) // or width/height?
type StrokeOptions struct {
StrokeWidth float32
ColorScale ebiten.ColorScale
Blend ebiten.Blend
AntiAlias bool
}
func StrokePath(dst *ebiten.Image, path vector.Path, op *StrokeOptions)
func StrokeLine(dst *ebiten.Image, x0, y0, x1, y1 float32, op *StrokeOptions)
func StrokeCircle(dst *ebiten.Image, x, y, r float32, op *StrokeOptions)
func StrokeRect(dst *ebiten.Image, x0, y0, x1, y1 float32, op *StrokeOptions) // or width/height?
EDIT: Oops, there is already |
I'll take a look tomorrow again as it is already midnight. Thanks, |
Idk if we should make another options just for |
type FillPathOptions struct {
ColorScale ebiten.ColorScale
AntiAlias bool
}
func FillPath(dst *ebiten.Image, path vector.Path, op *FillPathOptions)
func FillCircle(dst *ebiten.Image, x, y, r float32, op *FillPathOptions)
func FillRect(dst *ebiten.Image, x0, y0, x1, y1 float32, op *FillPathOptions) // or width/height?
type StrokePathOptions struct {
StrokeOptions
ColorScale ebiten.ColorScale
AntiAlias bool
}
func StrokePath(dst *ebiten.Image, path vector.Path, op *StrokePathOptions)
func StrokeLine(dst *ebiten.Image, x0, y0, x1, y1 float32, op *StrokePathOptions)
func StrokeCircle(dst *ebiten.Image, x, y, r float32, op *StrokePathOptions)
func StrokeRect(dst *ebiten.Image, x0, y0, x1, y1 float32, op *StrokePathOptions) // or width/height? EDIT: Removed Blend. |
|
We can skip them for now. It will be good addition in the future versions later. |
Oh, the option has to take the method (EvenOdd vs NonZero)... |
type FillRule int
const (
FillRuleNonZero FillRule = FillRule(ebiten.FillRuleNonZero) // The value is derived from the ebiten package for compatibility.
FillRuleEvenOdd FillRule = FillRule(ebiten.FillRuleEvenOdd)
)
type FillPathOptions struct {
ColorScale ebiten.ColorScale
AntiAlias bool
FillRule FillRule
}
func FillPath(dst *ebiten.Image, path vector.Path, op *FillPathOptions)
func FillCircle(dst *ebiten.Image, x, y, r float32, op *FillPathOptions)
func FillRect(dst *ebiten.Image, x0, y0, x1, y1 float32, op *FillPathOptions) // or width/height?
type StrokePathOptions struct {
StrokeOptions
ColorScale ebiten.ColorScale
AntiAlias bool
FillRule FillRule
}
func StrokePath(dst *ebiten.Image, path vector.Path, op *StrokePathOptions)
func StrokeLine(dst *ebiten.Image, x0, y0, x1, y1 float32, op *StrokePathOptions)
func StrokeCircle(dst *ebiten.Image, x, y, r float32, op *StrokePathOptions)
func StrokeRect(dst *ebiten.Image, x0, y0, x1, y1 float32, op *StrokePathOptions) // or width/height? I'll add APIs like above later. The implementation might change later to allow better rendering like transparent colors (see #3153) EDIT: I realized that FillRule is not needed for utility functions. Maybe this should be simply ignored for e.g. StorkeLine. |
Another suggestion would be like this: type FillRule int
const (
FillRuleNonZero FillRule = FillRule(ebiten.FillRuleNonZero) // The value is derived from the ebiten package for compatibility.
FillRuleEvenOdd FillRule = FillRule(ebiten.FillRuleEvenOdd)
)
func DrawFilledPath(dst *ebiten.Image, path *vector.Path, clr color.Color, antialias bool, fillRule FillRule)
func StrokePath(dst *ebiten.Image, path *vector.Path, clr color.Color, antialias bool, op *StrokeOptions) and leave the current existing APIs. |
Yeah, the situation might change later, so let's go a conservative way. |
Operating System
What feature would you like to be added?
It's pretty had for the novice user to draw custom shape without knowing some internal details.
I find myself copy-pasting the same two functions for all my projects:
Why is this needed?
To be able to just (same as text.Draw):
Personally, I don’t need more, but someone suggested options like these (similar to text.DrawOptions):
The text was updated successfully, but these errors were encountered: