Commit b9acfc99 authored by Guillaume Seguin's avatar Guillaume Seguin

Rework OnReshape to zoom when resizing

parent 12fb2780
...@@ -44,6 +44,9 @@ class wxGLPanel(wx.Panel): ...@@ -44,6 +44,9 @@ class wxGLPanel(wx.Panel):
glcanvas.WX_GL_DOUBLEBUFFER, # Double Buffered glcanvas.WX_GL_DOUBLEBUFFER, # Double Buffered
glcanvas.WX_GL_DEPTH_SIZE, 24) # 24 bit glcanvas.WX_GL_DEPTH_SIZE, 24) # 24 bit
self.width = None
self.height = None
self.sizer = wx.BoxSizer(wx.HORIZONTAL) self.sizer = wx.BoxSizer(wx.HORIZONTAL)
self.canvas = glcanvas.GLCanvas(self, attribList = attribList) self.canvas = glcanvas.GLCanvas(self, attribList = attribList)
self.context = glcanvas.GLContext(self.canvas) self.context = glcanvas.GLContext(self.canvas)
...@@ -61,12 +64,10 @@ class wxGLPanel(wx.Panel): ...@@ -61,12 +64,10 @@ class wxGLPanel(wx.Panel):
def processSizeEvent(self, event): def processSizeEvent(self, event):
'''Process the resize event.''' '''Process the resize event.'''
size = self.GetClientSize()
self.width, self.height = size.width, size.height
if (wx.VERSION > (2,9) and self.canvas.IsShownOnScreen()) or self.canvas.GetContext(): if (wx.VERSION > (2,9) and self.canvas.IsShownOnScreen()) or self.canvas.GetContext():
# Make sure the frame is shown before calling SetCurrent. # Make sure the frame is shown before calling SetCurrent.
self.canvas.SetCurrent(self.context) self.canvas.SetCurrent(self.context)
self.OnReshape(size.width, size.height) self.OnReshape()
self.canvas.Refresh(False) self.canvas.Refresh(False)
event.Skip() event.Skip()
...@@ -106,10 +107,15 @@ class wxGLPanel(wx.Panel): ...@@ -106,10 +107,15 @@ class wxGLPanel(wx.Panel):
glEnable(GL_BLEND) glEnable(GL_BLEND)
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
if call_reshape: if call_reshape:
self.OnReshape(*self.GetClientSize()) self.OnReshape()
def OnReshape(self, width, height): def OnReshape(self):
'''Reshape the OpenGL viewport based on the dimensions of the window.''' '''Reshape the OpenGL viewport based on the dimensions of the window.'''
size = self.GetClientSize()
oldwidth, oldheight = self.width, self.height
width, height = size.width, size.height
self.width = max(float(width), 1.0)
self.height = max(float(height), 1.0)
self.OnInitGL(call_reshape = False) self.OnInitGL(call_reshape = False)
glViewport(0, 0, width, height) glViewport(0, 0, width, height)
glMatrixMode(GL_PROJECTION) glMatrixMode(GL_PROJECTION)
...@@ -123,6 +129,9 @@ class wxGLPanel(wx.Panel): ...@@ -123,6 +129,9 @@ class wxGLPanel(wx.Panel):
if not self.mview_initialized: if not self.mview_initialized:
self.reset_mview(0.9) self.reset_mview(0.9)
self.mview_initialized = True self.mview_initialized = True
elif oldwidth is not None and oldheight is not None:
factor = min(self.width / oldwidth, self.height / oldheight)
self.zoom(factor)
# Wrap text to the width of the window # Wrap text to the width of the window
if self.GLinitialized: if self.GLinitialized:
......
...@@ -81,14 +81,14 @@ class StlViewPanel(wxGLPanel): ...@@ -81,14 +81,14 @@ class StlViewPanel(wxGLPanel):
wx.CallAfter(self.forceresize) wx.CallAfter(self.forceresize)
self.mousepos = (0, 0) self.mousepos = (0, 0)
def OnReshape(self, width, height): def OnReshape(self):
self.mview_initialized = False self.mview_initialized = False
super(StlViewPanel, self).OnReshape(width, height) super(StlViewPanel, self).OnReshape()
#========================================================================== #==========================================================================
# GLFrame OpenGL Event Handlers # GLFrame OpenGL Event Handlers
#========================================================================== #==========================================================================
def OnInitGL(self): def OnInitGL(self, call_reshape = True):
'''Initialize OpenGL for use in the window.''' '''Initialize OpenGL for use in the window.'''
if self.GLinitialized: if self.GLinitialized:
return return
...@@ -127,6 +127,8 @@ class StlViewPanel(wxGLPanel): ...@@ -127,6 +127,8 @@ class StlViewPanel(wxGLPanel):
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, vec(1, 1, 1, 1)) glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, vec(1, 1, 1, 1))
glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 50) glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 50)
glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, vec(0, 0.1, 0, 0.9)) glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, vec(0, 0.1, 0, 0.9))
if call_reshape:
self.OnReshape()
if self.parent.filenames: if self.parent.filenames:
for filename in self.parent.filenames: for filename in self.parent.filenames:
self.parent.load_file(None, filename) self.parent.load_file(None, filename)
......
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