Skip to content
This repository has been archived by the owner on Sep 6, 2023. It is now read-only.

Commit

Permalink
Fix rotation
Browse files Browse the repository at this point in the history
  • Loading branch information
tenko committed Oct 26, 2012
1 parent b3d0ad2 commit 52f1bcf
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 15 deletions.
12 changes: 8 additions & 4 deletions occmodel/occmodeldemo.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,13 +447,17 @@ def onUI(self):
w, h = self.width, self.height
x, y = self.lastPos

scroll = self.uiScroll
if scroll != 0:
self.uiScroll = 0

if not self.showUI:
# empty gui
ui.beginFrame(x,h - y,self.currentButton,0)
ui.beginFrame(x,h - y,self.currentButton,scroll)
ui.endFrame()
return update

ui.beginFrame(x,h - y,self.currentButton,0)
ui.beginFrame(x,h - y,self.currentButton,scroll)

ui.beginScrollArea("Menu", 10, .4*h, 200, .6*h - 10)
ui.separatorLine()
Expand Down Expand Up @@ -572,9 +576,9 @@ def onUI(self):

if self.source:
ui.beginScrollArea("Source", .5*w, 10, .5*w - 10, 150.)
ui.separatorLine()
for line in self.source.splitlines():
if not line.strip():
ui.separator()
continue
ui.label(line)
ui.endScrollArea()
Expand All @@ -583,7 +587,7 @@ def onUI(self):
return update

def onSetDemo(self, demo):
self.source = demo.TEXT
self.source = demo.TEXT.strip()

self.bbox.invalidate()
self.objects.clear()
Expand Down
33 changes: 22 additions & 11 deletions occmodel/occmodelviewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ def __init__(self, width = -1, height = -1, title = None, fullscreen = False):
self.bbox.invalidate()

self.lastPos = 0,0
self.mouseCenter = geo.Point()
self.uiScroll = 0
self.currentButton = -1

self.uiGradient = True
Expand Down Expand Up @@ -488,7 +490,11 @@ def onUI(self):
w, h = self.width, self.height
x, y = self.lastPos

ui.beginFrame(x,h - y,self.currentButton,0)
scroll = self.uiScroll
if scroll != 0:
self.uiScroll = 0

ui.beginFrame(x,h - y,self.currentButton,scroll)
ui.beginScrollArea("Menu", 10, .4*h, 200, .6*h - 10)

ui.separatorLine()
Expand Down Expand Up @@ -588,18 +594,20 @@ def onCursorPos(self, x, y):
# rotate view
dx = x - lastx
dy = y - lasty
cam.rotateDeltas(dx, dy)
cam.rotateDeltas(dx, dy, target = self.mouseCenter)

elif not ui and self.currentButton == gl.MOUSE.RIGHT:
# pan view
cam.pan(lastx,lasty,x,y)
cam.pan(lastx, lasty, x, y, target = self.mouseCenter)

self.lastPos = x, y
self.onRefresh()

def onMouseButton(self, button, action):
if action == gl.ACTION.PRESS:
if button in {gl.MOUSE.LEFT, gl.MOUSE.RIGHT}:
# temporary rotation center to avoid exponential increase
self.mouseCenter.set(self.cam.target)
self.currentButton = button
else:
self.currentButton = -1
Expand All @@ -613,26 +621,29 @@ def onKey(self, key, action):
def onChar(self, ch):
if ch == 'f':
self.onZoomExtents()
self.mouseCenter.set(self.cam.target)
self.onRefresh()

def onScroll(self, scx, scy):
x, y = self.lastPos
self.uiScroll = -int(scy)

if self.activeUI(x, y):
return

delta = 1e-4*scy
dx = delta*self.width
dy = delta*self.height

self.cam.zoomFactor(1. + max(dx,dy), (x, y))
if not self.activeUI(x, y):
delta = 1e-4*scy
dx = delta*self.width
dy = delta*self.height
self.cam.zoomFactor(1. + max(dx,dy), (x, y))
self.mouseCenter.set(self.cam.target)
self.onRefresh()

def onClose(self):
return True

def onZoomExtents(self):
self.cam.zoomExtents(self.bbox.min, self.bbox.max)
self.mouseCenter.set(self.cam.target)

def onTopView(self):
self.cam.setTopView()
Expand Down

0 comments on commit 52f1bcf

Please sign in to comment.