From 480d412d50334dc244846aa1bc585cdeb17b07d5 Mon Sep 17 00:00:00 2001 From: zokrezyl Date: Sun, 7 Jun 2020 09:02:52 +0200 Subject: [PATCH] fixed scaling with mouse-wheel (ctrl) --- src/asciterm_generic.py | 26 ++++++++++++++++++++------ src/asciterm_glumpy.py | 7 ++++--- src/asciterm_vispy.py | 18 ++++-------------- 3 files changed, 28 insertions(+), 23 deletions(-) diff --git a/src/asciterm_generic.py b/src/asciterm_generic.py index e7d730d..52d583a 100644 --- a/src/asciterm_generic.py +++ b/src/asciterm_generic.py @@ -189,7 +189,7 @@ def adapt_to_dim(self, width, height): def __init__(self, args): self.src_path = os.path.dirname(os.path.abspath(__file__)) - + self.ctrl_pressed = False self.altscreen = False self.width = 1000 self.height = 1000 @@ -247,6 +247,7 @@ def __init__(self, args): def _on_resize(self, width, height): self.adapt_to_dim(width, height) + self.vt.recalc() def on_cursor_move(self): x1 = 2 * self.cursor_pos.col / self.cols - 1 @@ -344,14 +345,27 @@ def pty_function(self): break def on_scroll(self, dx, dy): - # atm we ignore the amount, we care about the sign - # as glumpy and vispy (likely due to the backends) are reporting different values - self.vt.on_scroll(int(abs(dx)/(dx if dx != 0 else 1)), - int(abs(dy)/(dy if dy !=0 else 1))) - self.vt.recalc() + if self.ctrl_pressed: + print("key pressed!!!") + self.scale += dy/20 + if self.scale < 0.5: + self.scale = 0.5 + self.adapt_to_dim(self.width, self.height) + self.program["scale"] = self.scale + self.vt.recalc() + else: + # atm we ignore the amount, we care about the sign + # as glumpy and vispy (likely due to the backends) are reporting different values + self.vt.on_scroll(int(abs(dx)/(dx if dx != 0 else 1)), + int(abs(dy)/(dy if dy != 0 else 1))) + self.vt.recalc() self.update() def on_text(self, text): self.vt.scroll = 0 os.write(self.master_fd, text) + def on_ctrl_pressed(self, on): + # this is a temp naive implementation for the polymorfism + # between glumpy and vispy for key pressed + self.ctrl_pressed = on diff --git a/src/asciterm_glumpy.py b/src/asciterm_glumpy.py index 8a29816..c69c70c 100644 --- a/src/asciterm_glumpy.py +++ b/src/asciterm_glumpy.py @@ -77,7 +77,6 @@ def as_texture_2d(self, data): def update(self): pass - #self.on_draw() def on_draw(self, event): self.window.clear() @@ -86,6 +85,9 @@ def on_draw(self, event): def on_resize(self, width, height): self._on_resize(width, height) + def on_key_press(self, key, modifiers): + self.on_ctrl_pressed(modifiers & app.window.key.MOD_CTRL) + def on_character(self, text): self.on_text(str.encode(text)) @@ -98,5 +100,4 @@ def quit(self): self.finish = True def on_mouse_scroll(self, x, y, dx, dy): - print("mouse scroll ", x, y, dx, dy) - self.on_scroll(self, dx, dy) + self.on_scroll(dx, dy) diff --git a/src/asciterm_vispy.py b/src/asciterm_vispy.py index ae8a484..955f49f 100644 --- a/src/asciterm_vispy.py +++ b/src/asciterm_vispy.py @@ -1,10 +1,11 @@ from asciterm_generic import ArtSciTerm from vispy import gloo, app, util -import os + class Null: pass + class ArtSciTermVispyProgram(gloo.Program): def get_uniforms(self): uniforms = [] @@ -17,14 +18,13 @@ def get_attributes(self): attributes = [] for variable in self.variables: if variable.kind == 'attribute': - attributesuniforms.append((variable[2], variable[1])) + attributes.append((variable[2], variable[1])) return attributes def to_gl_constant(self, txt): return txt - GL_CLAMP = "clamp_to_edge" GL_POINTS = "points" GL_TRIANGLES = "triangles" @@ -36,8 +36,6 @@ def __init__(self, args): setattr(self.factory, "create_program", ArtSciTermVispyProgram) setattr(self.factory, "ortho", util.transforms.ortho) - #self.gloo = gloo - #self._app = app app.Canvas.__init__(self) ArtSciTerm.__init__(self, args) @@ -76,15 +74,7 @@ def on_timer(self, event): def on_mouse_wheel(self, event): self.on_scroll(*event.delta) - return # TODO ... implement the scale when shift is pressed - self.scale += event.delta[1]/10 - if self.scale < 0.5: - self.scale = 0.5 - self.adapt_to_dim(self.width, self.height) - self.program["scale"]= self.scale - #self.program1["scale"]= self.scale - #self.on_cursor_move() - self.dirty = True + return def on_draw(self, event): gloo.clear('black')