@@ -12,6 +12,8 @@ def __init__(self, width, height):
12
12
self .window_width = width
13
13
self .window_height = height
14
14
self .fRects = []
15
+ self .surface = None
16
+ self .canvas = None
15
17
16
18
def create_star ():
17
19
kNumPoints = 5
@@ -76,6 +78,8 @@ def main():
76
78
canvas = surface .getCanvas ()
77
79
78
80
state = ApplicationState (scr_width , scr_height )
81
+ state .surface = surface
82
+ state .canvas = surface .getCanvas ()
79
83
helpMessage = "Click and drag to create rects. Press esc to quit."
80
84
paint = skia .Paint ()
81
85
font = skia .Font ()
@@ -152,22 +156,22 @@ def framebuffer_size_callback(window, width, height):
152
156
153
157
# Draw help message
154
158
paint .setColor (skia .ColorBLACK )
155
- canvas .drawString (helpMessage , 0 , font .getSize (), font , paint )
159
+ state . canvas .drawString (helpMessage , 0 , font .getSize (), font , paint )
156
160
157
161
# Draw rectangles
158
162
for rect in state .fRects :
159
163
paint .setColor (random .randint (0 , 0xFFFFFFFF ) | 0x44808080 )
160
- canvas .drawRect (rect , paint )
164
+ state . canvas .drawRect (rect , paint )
161
165
162
166
# 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 )
166
170
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 ()
169
173
170
- canvas .flush ()
174
+ state . canvas .flush ()
171
175
glfw .swap_buffers (window )
172
176
173
177
glfw .destroy_window (window )
0 commit comments