Commit 892ccd7c authored by Václav 'Ax' Hůla's avatar Václav 'Ax' Hůla

refactor - shape moving and rotating into funcions. Keyboard mainipulation is...

refactor - shape moving and rotating into funcions. Keyboard mainipulation is there, except it doesnt work as I have no idea where keypress events go (definitely not canvas)
parent 7f880dc3
...@@ -445,7 +445,7 @@ class TestGlPanel(GLPanel): ...@@ -445,7 +445,7 @@ class TestGlPanel(GLPanel):
self.initialized=1 self.initialized=1
self.canvas.Bind(wx.EVT_MOUSEWHEEL,self.wheel) self.canvas.Bind(wx.EVT_MOUSEWHEEL,self.wheel)
self.parent=parent self.parent=parent
self.initp=None self.initpos=None
self.dist=200 self.dist=200
self.bedsize=[200,200] self.bedsize=[200,200]
self.transv=[0, 0, -self.dist] self.transv=[0, 0, -self.dist]
...@@ -469,26 +469,49 @@ class TestGlPanel(GLPanel): ...@@ -469,26 +469,49 @@ class TestGlPanel(GLPanel):
threading.Thread(target=self.update).start() threading.Thread(target=self.update).start()
self.initialized=0 self.initialized=0
def move_shape(self, delta):
"""moves shape (selected in l, which is list ListBox of shapes)
by an offset specified in tuple delta.
Positive numbers move to (rigt, down)"""
name = self.parent.l.GetSelection()
if name == wx.NOT_FOUND:
return False
name = self.parent.l.GetString(name)
model = self.parent.models[name]
model.offsets = [
model.offsets[0] + delta[0],
model.offsets[1] + delta[1],
model.offsets[2]
]
self.Refresh()
return True
def move(self, event): def move(self, event):
"""react to mouse actions:
no mouse: show red mousedrop
LMB: move active object,
with shift rotate viewport
RMB: nothing
with shift move viewport
"""
if event.Dragging() and event.LeftIsDown(): if event.Dragging() and event.LeftIsDown():
if self.initp==None: if self.initpos==None:
self.initp=event.GetPositionTuple() self.initpos=event.GetPositionTuple()
else: else:
if not event.ShiftDown(): if not event.ShiftDown():
i=self.parent.l.GetSelection() currentpos = event.GetPositionTuple()
if i<0: delta = (
(currentpos[0] - self.initpos[0]),
-(currentpos[1] - self.initpos[1])
)
self.move_shape(delta)
self.initpos=None
return return
p1=list(self.initp) #print self.initpos
p1[1]*=-1 p1=self.initpos
self.initp=None self.initpos=None
p2=list(event.GetPositionTuple())
p2[1]*=-1
m=self.parent.models[self.parent.l.GetString(i)]
m.offsets=map(lambda old,new,original:original+(new-old), list(p1)+[0],list(p2)+[0],m.offsets)
return
#print self.initp
p1=self.initp
self.initp=None
p2=event.GetPositionTuple() p2=event.GetPositionTuple()
sz=self.GetClientSize() sz=self.GetClientSize()
p1x=(float(p1[0])-sz[0]/2)/(sz[0]/2) p1x=(float(p1[0])-sz[0]/2)/(sz[0]/2)
...@@ -511,18 +534,18 @@ class TestGlPanel(GLPanel): ...@@ -511,18 +534,18 @@ class TestGlPanel(GLPanel):
self.rot=1 self.rot=1
elif event.ButtonUp(wx.MOUSE_BTN_LEFT): elif event.ButtonUp(wx.MOUSE_BTN_LEFT):
if self.initp is not None: if self.initpos is not None:
self.initp=None self.initpos=None
elif event.ButtonUp(wx.MOUSE_BTN_RIGHT): elif event.ButtonUp(wx.MOUSE_BTN_RIGHT):
if self.initp is not None: if self.initpos is not None:
self.initp=None self.initpos=None
elif event.Dragging() and event.RightIsDown() and event.ShiftDown(): elif event.Dragging() and event.RightIsDown() and event.ShiftDown():
if self.initp is None: if self.initpos is None:
self.initp=event.GetPositionTuple() self.initpos=event.GetPositionTuple()
else: else:
p1=self.initp p1=self.initpos
p2=event.GetPositionTuple() p2=event.GetPositionTuple()
sz=self.GetClientSize() sz=self.GetClientSize()
p1=list(p1) p1=list(p1)
...@@ -539,7 +562,7 @@ class TestGlPanel(GLPanel): ...@@ -539,7 +562,7 @@ class TestGlPanel(GLPanel):
glMultMatrixd(build_rotmatrix(self.basequat)) glMultMatrixd(build_rotmatrix(self.basequat))
glGetDoublev(GL_MODELVIEW_MATRIX,self.mvmat) glGetDoublev(GL_MODELVIEW_MATRIX,self.mvmat)
self.rot=1 self.rot=1
self.initp=None self.initpos=None
else: else:
#mouse is moving without a button press #mouse is moving without a button press
p=event.GetPositionTuple() p=event.GetPositionTuple()
...@@ -548,9 +571,24 @@ class TestGlPanel(GLPanel): ...@@ -548,9 +571,24 @@ class TestGlPanel(GLPanel):
v[1]=self.bedsize[1]-v[1] v[1]=self.bedsize[1]-v[1]
self.mousepos=v self.mousepos=v
def rotate_shape(self, angle):
"""rotates acive shape
positive angle is clockwise
"""
name = self.parent.l.GetSelection()
if name == wx.NOT_FOUND:
return False
name = self.parent.l.GetString(name)
model = self.parent.models[name]
model.rot += angle
def wheel(self,event): def wheel(self,event):
"""react to mouse wheel actions:
rotate object
with shift zoom viewport
"""
z=event.GetWheelRotation() z=event.GetWheelRotation()
delta=10 angle=10
if not event.ShiftDown(): if not event.ShiftDown():
i=self.parent.l.GetSelection() i=self.parent.l.GetSelection()
...@@ -560,17 +598,16 @@ class TestGlPanel(GLPanel): ...@@ -560,17 +598,16 @@ class TestGlPanel(GLPanel):
except: except:
pass pass
return return
m=self.parent.models[self.parent.l.GetString(i)]
if z > 0: if z > 0:
m.rot+=delta/2 self.rotate_shape(angle/2)
else: else:
m.rot-=delta/2 self.rotate_shape(-angle/2)
return return
if z > 0: if z > 0:
self.transv[2]+=delta self.transv[2]+=angle
else: else:
self.transv[2]-=delta self.transv[2]-=angle
glLoadIdentity() glLoadIdentity()
glTranslatef(*self.transv) glTranslatef(*self.transv)
...@@ -579,6 +616,34 @@ class TestGlPanel(GLPanel): ...@@ -579,6 +616,34 @@ class TestGlPanel(GLPanel):
glGetDoublev(GL_MODELVIEW_MATRIX,self.mvmat) glGetDoublev(GL_MODELVIEW_MATRIX,self.mvmat)
self.rot=1 self.rot=1
def keypress(self, event):
"""gets keypress events and moves/rotates acive shape"""
keycode = event.GetKeyCode()
print keycode
step = 5
angle = 18
if event.ControlDown():
step = 1
angle = 1
#h
if keycode == 72:
self.move_shape((-step, 0))
#l
if keycode == 76:
self.move_shape((step, 0))
#j
if keycode == 75:
self.move_shape((0, step))
#k
if keycode == 74:
self.move_shape((0, -step))
#[
if keycode == 91:
self.rotate_shape(-angle)
#]
if keycode == 93:
self.rotate_shape(angle)
event.Skip()
def update(self): def update(self):
while(1): while(1):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment