Skip to content

Commit

Permalink
fixed scaling with mouse-wheel (ctrl)
Browse files Browse the repository at this point in the history
  • Loading branch information
zokrezyl committed Jun 7, 2020
1 parent fe44ad0 commit 480d412
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 23 deletions.
26 changes: 20 additions & 6 deletions src/asciterm_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
7 changes: 4 additions & 3 deletions src/asciterm_glumpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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))

Expand All @@ -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)
18 changes: 4 additions & 14 deletions src/asciterm_vispy.py
Original file line number Diff line number Diff line change
@@ -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 = []
Expand All @@ -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"
Expand All @@ -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)

Expand Down Expand Up @@ -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')
Expand Down

0 comments on commit 480d412

Please sign in to comment.