Skip to content

Commit 6aebe82

Browse files
committed
Adding scaling on pressing + and -
1 parent d110ad0 commit 6aebe82

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

SKIA-WX-GPU-SVG-Viewer.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,15 @@ def __init__(self, parent, size):
4242

4343
self.svg_picture = None
4444
self.svg_size = None
45+
self.scale = 0
4546

4647
self.Bind(wx.EVT_LEFT_DOWN, self.on_mouse_left_down)
4748
self.Bind(wx.EVT_LEFT_UP, self.on_mouse_left_up)
4849
self.Bind(wx.EVT_MOTION, self.on_mouse_move)
4950
self.Bind(wx.EVT_MOUSEWHEEL, self.on_mouse_wheel)
5051
self.Bind(wx.EVT_PAINT, self.on_paint)
5152
self.Bind(wx.EVT_SIZE, self.on_size)
53+
self.Bind(wx.EVT_KEY_DOWN, self.on_key_down)
5254
# Do nothing, to avoid flashing on MSW.
5355
self.Bind(wx.EVT_ERASE_BACKGROUND, lambda x: None)
5456

@@ -79,6 +81,16 @@ def on_paint(self, event):
7981

8082
self.SwapBuffers()
8183

84+
def on_key_down(self, event):
85+
keycode = event.GetKeyCode()
86+
if (keycode == 43): # '+'
87+
self.scale += 2
88+
self.Refresh()
89+
if (keycode == 45): # '-'
90+
self.scale -= 2
91+
self.Refresh()
92+
event.Skip()
93+
8294
def on_mouse_left_down(self, event):
8395
self.is_dragging = True
8496
self.last_mouse_pos = (event.GetX(), event.GetY())
@@ -148,9 +160,11 @@ def on_draw(self):
148160
self.canvas.translate(self.offset_x, self.offset_y)
149161

150162
if self.svg_picture:
163+
self.canvas.scale(1 + self.scale * 0.1, 1 + self.scale * 0.1)
151164
self.canvas.translate(-self.svg_size.width()/2, -self.svg_size.height()/2)
152165
self.svg_picture.render(self.canvas)
153166
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))
154168

155169
self.canvas.restore()
156170
self.surface.flushAndSubmit()

0 commit comments

Comments
 (0)