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

Gradients other than linear do not seem to work #296

Closed
chaosparrot opened this issue Apr 27, 2021 · 3 comments
Closed

Gradients other than linear do not seem to work #296

chaosparrot opened this issue Apr 27, 2021 · 3 comments

Comments

@chaosparrot
Copy link

chaosparrot commented Apr 27, 2021

Talon v0.1.5 - Windows 10

In the Skia.Shader api, the only gradients I have managed to make work is the linear gradient. Sweep, radial and two point conical do not seem to work properly when I look at the interface files. Any type of configuration seems to result in the following error: IndexError: too many initializers for 'sk_point_t[1]' (got 2)

Steps to reproduce - Put this as a python file in your user folder, this should generate a circle in the topleft part of the screen. You can uncomment a line to check the other gradients

from talon import app, canvas, skia

class GradientExample:
    canvas = None

    def __init__(self):
        self.canvas = canvas.Canvas(10, 10, 110, 110)
        self.canvas.register('draw', self.draw_cycle)
        self.canvas.freeze()

    def draw_cycle(self, canvas):
        paint = canvas.paint
        #paint.shader = skia.Shader.linear_gradient(10, 10, 10, 110, ['FF0000', '00FF00', '0000FF'], None)
        paint.shader = skia.Shader.radial_gradient(60, 60, 50, ['FF0000', '00FF00', '0000FF'], None)
        #paint.shader = skia.Shader.sweep_gradient(60, 60, 50, ['FF0000', '00FF00', '0000FF'], None)
        #paint.shader = skia.Shader.two_point_conical_gradient(10, 10, 50, 70, 70, 50, ['FF0000', '00FF00', '0000FF'], None)
        
        canvas.draw_circle(60, 60, 50, paint)

def open_example():
    GradientExample()

app.register('ready', open_example)```
@lunixbochs
Copy link

Resolved in next beta.

Note in this sort of code you should really hold onto the GradientExample object, otherwise it's going to get garbage collected at some point.

You could do something like this if you don't want it to draw while Talon is starting up:

example = GradientExample()
app.register('ready', example.canvas.freeze)```

@lunixbochs
Copy link

lunixbochs commented Apr 29, 2021

I kind of want to break the skia API to make you group points using either Point2d or a tuple, e.g.

paint.shader = skia.Shader.two_point_conical_gradient(
    (360, 60), 5, (370, 70), 20, ['FF0000', '00FF00', '0000FF'])

Because the huge list of numbers is kind of hard to read as is.

@lunixbochs
Copy link

lunixbochs commented Apr 29, 2021

I've worked on grouping points in API here:

paint = canvas.paint
paint.shader = skia.Shader.linear_gradient((10, 10), (10, 110), ['FF0000', '00FF00', '0000FF'], None)
canvas.draw_circle(60, 60, 50, paint)
paint.shader = skia.Shader.radial_gradient((160, 60), 50, ['FF0000', '00FF00', '0000FF'])
canvas.draw_circle(160, 60, 50, paint)
paint.shader = skia.Shader.sweep_gradient((260, 60), 50, ['FF0000', '00FF00', '0000FF'], 0, 180)
canvas.draw_circle(260, 60, 50, paint)
paint.shader = skia.Shader.two_point_conical_gradient((360, 60), 5, (370, 70), 20, ['FF0000', '00FF00', '0000FF'])
canvas.draw_circle(360, 60, 50, paint)

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

No branches or pull requests

2 participants