Commit 5c6e6dfb authored by sumpfralle's avatar sumpfralle

added OpenGL settings for "light", "shadow" and "polygon fill"

added shortkeys for these settings (done by lode)
seperated settings window into multiple tabs


git-svn-id: https://pycam.svn.sourceforge.net/svnroot/pycam/trunk@208 bbaffbd6-741e-11dd-a85d-61de82d9cad9
parent 66ed9af2
......@@ -103,6 +103,7 @@ class GLView:
self.area.connect("button-press-event", self.mouse_handler)
self.area.connect('motion-notify-event', self.mouse_handler)
self.area.show()
self.container.add(self.area)
self.camera = ogl_tools.Camera(self.settings, lambda: (self.area.allocation.width, self.area.allocation.height))
# color the dimension value according to the axes
# for "y" axis: 100% green is too bright on light background - we reduce it a bit
......@@ -114,7 +115,7 @@ class GLView:
attributes.insert(color)
for name in names:
self.gui.get_object(name).set_attributes(attributes)
self.container.add(self.area)
# show the window
self.container.show()
self.show()
......@@ -139,6 +140,21 @@ class GLView:
if not (0 <= keyval <= 255):
# e.g. "shift" key
return
if chr(keyval) in ('l', 'm', 's'):
if (chr(keyval) == 'l'):
key = "view_light"
elif (chr(keyval) == 'm'):
key = "view_polygon"
elif (chr(keyval) == 's'):
key = "view_shadow"
else:
key = None
# toggle setting
self.settings.set(key, not self.settings.get(key))
# re-init gl settings
self.glsetup()
self.paint()
else:
print "Key pressed: %s (%s)" % (chr(keyval), get_state())
def check_busy(func):
......@@ -168,10 +184,11 @@ class GLView:
return refresh_wrapper
def glsetup(self):
if self.initialized:
return
GLUT.glutInit()
if self.settings.get("view_shadow"):
GL.glShadeModel(GL.GL_FLAT)
else:
GL.glShadeModel(GL.GL_SMOOTH)
bg_col = self.settings.get("color_background")
GL.glClearColor(bg_col[0], bg_col[1], bg_col[2], 0.0)
GL.glClearDepth(1.)
......@@ -183,7 +200,10 @@ class GLView:
#GL.glMaterial(GL.GL_FRONT_AND_BACK, GL.GL_AMBIENT, (0.1, 0.1, 0.1, 1.0))
GL.glMaterial(GL.GL_FRONT_AND_BACK, GL.GL_SPECULAR, (0.1, 0.1, 0.1, 1.0))
#GL.glMaterial(GL.GL_FRONT_AND_BACK, GL.GL_SHININESS, (0.5))
if self.settings.get("view_polygon"):
GL.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_FILL)
else:
GL.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_LINE)
GL.glMatrixMode(GL.GL_MODELVIEW)
GL.glLoadIdentity()
GL.glMatrixMode(GL.GL_PROJECTION)
......@@ -195,7 +215,10 @@ class GLView:
GL.glLightfv(GL.GL_LIGHT0, GL.GL_SPECULAR, (.3, .3, .3, 1.0)) # Setup The SpecularLight
GL.glEnable(GL.GL_LIGHT0)
# Enable Light One
if self.settings.get("view_light"):
GL.glEnable(GL.GL_LIGHTING)
else:
GL.glDisable(GL.GL_LIGHTING)
GL.glEnable(GL.GL_NORMALIZE)
GL.glColorMaterial(GL.GL_FRONT_AND_BACK,GL.GL_AMBIENT_AND_DIFFUSE)
#GL.glColorMaterial(GL.GL_FRONT_AND_BACK,GL.GL_SPECULAR)
......@@ -224,6 +247,9 @@ class GLView:
return result
return decorated # TODO: make this a well behaved decorator (keeping name, docstring etc)
def keyboard_handler(self, widget, event):
print "KEY:", event
@check_busy
@gtkgl_functionwrapper
def mouse_handler(self, widget, event):
......@@ -419,6 +445,14 @@ class ProjectGui:
# all of the objects above should trigger redraw
if name != "enable_ode":
obj.connect("toggled", self.update_view)
for name, objname in (
("view_light", "OpenGLLight"),
("view_shadow", "OpenGLShadow"),
("view_polygon", "OpenGLPolygon")):
obj = self.gui.get_object(objname)
self.settings.add_item(name, obj.get_active, obj.set_active)
# send "True" to trigger a re-setup of GL settings
obj.connect("toggled", self.update_view, True)
# color selectors
def get_color_wrapper(obj):
def gtk_color_to_float():
......@@ -458,6 +492,9 @@ class ProjectGui:
self.settings.set("show_bounding_box", True)
self.settings.set("show_axes", True)
self.settings.set("show_dimensions", True)
self.settings.set("view_light", True)
self.settings.set("view_shadow", True)
self.settings.set("view_polygon", True)
skip_obj = self.gui.get_object("DrillProgressFrameSkipControl")
self.settings.add_item("drill_progress_max_fps", skip_obj.get_value, skip_obj.set_value)
self.settings.set("drill_progress_max_fps", 2)
......@@ -581,6 +618,8 @@ class ProjectGui:
def update_view(self, widget=None, data=None):
if self.view3d and self.view3d.is_visible and not self.no_dialog:
if data:
self.view3d.glsetup()
self.view3d.paint()
def update_physics(self, cutter):
......
......@@ -2545,6 +2545,10 @@
<property name="visible">True</property>
<property name="orientation">vertical</property>
<property name="spacing">2</property>
<child>
<object class="GtkNotebook" id="notebook1">
<property name="visible">True</property>
<property name="can_focus">True</property>
<child>
<object class="GtkVBox" id="vbox7">
<property name="visible">True</property>
......@@ -2633,13 +2637,15 @@
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkHSeparator" id="hseparator5">
</object>
</child>
<child type="tab">
<object class="GtkLabel" id="GeneralSettingsTabLabel">
<property name="visible">True</property>
<property name="label" translatable="yes">General</property>
</object>
<packing>
<property name="expand">False</property>
<property name="position">1</property>
<property name="tab_fill">False</property>
</packing>
</child>
<child>
......@@ -2734,38 +2740,6 @@
<property name="position">5</property>
</packing>
</child>
<child>
<object class="GtkHBox" id="hbox7">
<property name="visible">True</property>
<property name="spacing">2</property>
<child>
<object class="GtkLabel" id="DrillUpdateFPSLabel">
<property name="visible">True</property>
<property name="label" translatable="yes">Maximum Frames per Second:</property>
</object>
<packing>
<property name="expand">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkSpinButton" id="DrillProgressFrameSkipControl">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="invisible_char">&#x2022;</property>
<property name="adjustment">DrillProgressMaxFPS</property>
</object>
<packing>
<property name="expand">False</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="position">6</property>
</packing>
</child>
</object>
</child>
</object>
......@@ -2779,17 +2753,17 @@
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="position">2</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkHSeparator" id="hseparator1">
<child type="tab">
<object class="GtkLabel" id="DisplayItemSettingsTabLabel">
<property name="visible">True</property>
<property name="label" translatable="yes">Display Items</property>
</object>
<packing>
<property name="expand">False</property>
<property name="position">3</property>
<property name="position">1</property>
<property name="tab_fill">False</property>
</packing>
</child>
<child>
......@@ -2960,14 +2934,137 @@
</object>
</child>
</object>
<packing>
<property name="position">2</property>
</packing>
</child>
<child type="tab">
<object class="GtkLabel" id="ColorSettingsTabLabel">
<property name="visible">True</property>
<property name="label" translatable="yes">Colors</property>
</object>
<packing>
<property name="position">2</property>
<property name="tab_fill">False</property>
</packing>
</child>
<child>
<object class="GtkFrame" id="OpenGLSettingsFrame">
<property name="visible">True</property>
<property name="label_xalign">0</property>
<property name="shadow_type">none</property>
<child>
<object class="GtkAlignment" id="alignment11">
<property name="visible">True</property>
<property name="left_padding">12</property>
<child>
<object class="GtkVBox" id="vbox1">
<property name="visible">True</property>
<property name="orientation">vertical</property>
<property name="spacing">2</property>
<child>
<object class="GtkCheckButton" id="OpenGLPolygon">
<property name="label" translatable="yes">Polygon fill</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="tooltip_text" translatable="yes">Hotkey: &lt;p&gt;</property>
<property name="draw_indicator">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="position">4</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkCheckButton" id="OpenGLLight">
<property name="label" translatable="yes">Lightning</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="tooltip_text" translatable="yes">Hotkey: &lt;l&gt;</property>
<property name="draw_indicator">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkCheckButton" id="OpenGLShadow">
<property name="label" translatable="yes">Shadows</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="tooltip_text" translatable="yes">Hotkey: &lt;s&gt;</property>
<property name="draw_indicator">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="position">2</property>
</packing>
</child>
<child>
<object class="GtkHBox" id="hbox7">
<property name="visible">True</property>
<property name="spacing">2</property>
<child>
<object class="GtkLabel" id="DrillUpdateFPSLabel">
<property name="visible">True</property>
<property name="tooltip_text" translatable="yes">Maximum number of frame updates per second for drill progress visualization.</property>
<property name="label" translatable="yes">Maximum Frames per Second:</property>
</object>
<packing>
<property name="expand">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkSpinButton" id="DrillProgressFrameSkipControl">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="invisible_char">&#x2022;</property>
<property name="adjustment">DrillProgressMaxFPS</property>
</object>
<packing>
<property name="expand">False</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="position">3</property>
</packing>
</child>
</object>
</child>
</object>
</child>
<child type="label">
<object class="GtkLabel" id="OpenGLSettingsFrameLabel">
<property name="visible">True</property>
<property name="label" translatable="yes">&lt;b&gt;OpenGL Settings&lt;/b&gt;</property>
<property name="use_markup">True</property>
</object>
</child>
</object>
<packing>
<property name="position">3</property>
</packing>
</child>
<child type="tab">
<object class="GtkLabel" id="GLSettingsTabLabel">
<property name="visible">True</property>
<property name="label" translatable="yes">OpenGL</property>
</object>
<packing>
<property name="position">3</property>
<property name="tab_fill">False</property>
</packing>
</child>
</object>
<packing>
<property name="position">1</property>
</packing>
</child>
......
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