Skip to content

Commit 3e5d5fb

Browse files
committed
2nd part of Copilot suggested fix
1 parent 2d96001 commit 3e5d5fb

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

SkiaGLFWExample-v1.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ def __init__(self, width, height):
1212
self.window_width = width
1313
self.window_height = height
1414
self.fRects = []
15+
self.surface = None
16+
self.canvas = None
1517

1618
def create_star():
1719
kNumPoints = 5
@@ -76,6 +78,8 @@ def main():
7678
canvas = surface.getCanvas()
7779

7880
state = ApplicationState(scr_width, scr_height)
81+
state.surface = surface
82+
state.canvas = surface.getCanvas()
7983
helpMessage = "Click and drag to create rects. Press esc to quit."
8084
paint = skia.Paint()
8185
font = skia.Font()
@@ -152,22 +156,22 @@ def framebuffer_size_callback(window, width, height):
152156

153157
# Draw help message
154158
paint.setColor(skia.ColorBLACK)
155-
canvas.drawString(helpMessage, 0, font.getSize(), font, paint)
159+
state.canvas.drawString(helpMessage, 0, font.getSize(), font, paint)
156160

157161
# Draw rectangles
158162
for rect in state.fRects:
159163
paint.setColor(random.randint(0, 0xFFFFFFFF) | 0x44808080)
160-
canvas.drawRect(rect, paint)
164+
state.canvas.drawRect(rect, paint)
161165

162166
# Draw spinning star image in center
163-
canvas.save()
164-
canvas.translate(state.window_width / 2.0, state.window_height / 2.0)
165-
canvas.rotate(rotation)
167+
state.canvas.save()
168+
state.canvas.translate(state.window_width / 2.0, state.window_height / 2.0)
169+
state.canvas.rotate(rotation)
166170
rotation += 1
167-
canvas.drawImage(image, -50.0, -50.0)
168-
canvas.restore()
171+
state.canvas.drawImage(image, -50.0, -50.0)
172+
state.canvas.restore()
169173

170-
canvas.flush()
174+
state.canvas.flush()
171175
glfw.swap_buffers(window)
172176

173177
glfw.destroy_window(window)

0 commit comments

Comments
 (0)