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):
glcanvas.WX_GL_DOUBLEBUFFER, # Double Buffered
glcanvas.WX_GL_DEPTH_SIZE, 24) # 24 bit
self.width = None
self.height = None
self.sizer = wx.BoxSizer(wx.HORIZONTAL)
self.canvas = glcanvas.GLCanvas(self, attribList = attribList)
self.context = glcanvas.GLContext(self.canvas)
......@@ -61,12 +64,10 @@ class wxGLPanel(wx.Panel):
def processSizeEvent(self, 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():
# Make sure the frame is shown before calling SetCurrent.
self.canvas.SetCurrent(self.context)
self.OnReshape(size.width, size.height)
self.OnReshape()
self.canvas.Refresh(False)
event.Skip()
......@@ -106,10 +107,15 @@ class wxGLPanel(wx.Panel):
glEnable(GL_BLEND)
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
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.'''
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)
glViewport(0, 0, width, height)
glMatrixMode(GL_PROJECTION)
......@@ -123,6 +129,9 @@ class wxGLPanel(wx.Panel):
if not self.mview_initialized:
self.reset_mview(0.9)
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
if self.GLinitialized:
......
......@@ -81,14 +81,14 @@ class StlViewPanel(wxGLPanel):
wx.CallAfter(self.forceresize)
self.mousepos = (0, 0)
def OnReshape(self, width, height):
def OnReshape(self):
self.mview_initialized = False
super(StlViewPanel, self).OnReshape(width, height)
super(StlViewPanel, self).OnReshape()
#==========================================================================
# GLFrame OpenGL Event Handlers
#==========================================================================
def OnInitGL(self):
def OnInitGL(self, call_reshape = True):
'''Initialize OpenGL for use in the window.'''
if self.GLinitialized:
return
......@@ -127,6 +127,8 @@ class StlViewPanel(wxGLPanel):
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, vec(1, 1, 1, 1))
glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 50)
glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, vec(0, 0.1, 0, 0.9))
if call_reshape:
self.OnReshape()
if self.parent.filenames:
for filename in self.parent.filenames:
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