@@ -41,8 +41,9 @@ def __init__(self, parent, size):
41
41
self .zoom = 1.0
42
42
43
43
self .svg_picture = None
44
- self .svg_size = None
45
- self .scale = 0
44
+ self .img_size = None
45
+ self .img_scale_enum = 0
46
+ self .img_zoom = 1.0
46
47
47
48
self .Bind (wx .EVT_LEFT_DOWN , self .on_mouse_left_down )
48
49
self .Bind (wx .EVT_LEFT_UP , self .on_mouse_left_up )
@@ -83,11 +84,10 @@ def on_paint(self, event):
83
84
84
85
def on_key_down (self , event ):
85
86
keycode = event .GetKeyCode ()
86
- if (keycode == 43 ): # '+'
87
- self .scale += 2
88
- self .Refresh ()
89
- if (keycode == 45 ): # '-'
90
- self .scale -= 2
87
+ if ((keycode == 43 ) or # '+'
88
+ (keycode == 45 )): # '-'
89
+ self .img_scale_enum += (44 - keycode )
90
+ self .img_zoom = 1.2 ** self .img_scale_enum
91
91
self .Refresh ()
92
92
event .Skip ()
93
93
@@ -160,11 +160,11 @@ def on_draw(self):
160
160
self .canvas .translate (self .offset_x , self .offset_y )
161
161
162
162
if self .svg_picture :
163
- self .canvas .scale (1 + self .scale * 0.1 , 1 + self .scale * 0.1 )
164
- self .canvas .translate (- self .svg_size .width ()/ 2 , - self .svg_size .height ()/ 2 )
163
+ self .canvas .scale (self .img_zoom , self .img_zoom )
164
+ self .canvas .translate (- self .img_size .width ()/ 2 , - self .img_size .height ()/ 2 )
165
165
self .svg_picture .render (self .canvas )
166
- self .canvas .translate (self .svg_size .width ()/ 2 , self .svg_size .height ()/ 2 )
167
- self .canvas .scale (1 / ( 1 + self .scale * 0.1 ) , 1 / ( 1 + self .scale * 0.1 ) )
166
+ self .canvas .translate (self .img_size .width ()/ 2 , self .img_size .height ()/ 2 )
167
+ self .canvas .scale (1 / self .img_zoom , 1 / self .img_zoom )
168
168
169
169
self .canvas .restore ()
170
170
self .surface .flushAndSubmit ()
@@ -212,7 +212,7 @@ def on_open_file(self, event):
212
212
try :
213
213
svgstream = skia .Stream .MakeFromFile (path )
214
214
self .canvas .svg_picture = skia .SVGDOM .MakeFromStream (svgstream )
215
- self .canvas .svg_size = self .canvas .svg_picture .containerSize ()
215
+ self .canvas .img_size = self .canvas .svg_picture .containerSize ()
216
216
self .canvas .Refresh ()
217
217
self .canvas .SetFocus ()
218
218
except Exception as e :
0 commit comments