Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2017
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 8.34 KB | None | 0 0
  1. import os, sys
  2.  
  3. from OpenGL.GL import *
  4. from OpenGL.GLU import *
  5. from OpenGL.GLUT import *
  6.  
  7. os.environ['PATH'] = "C:\\Users\\Martin Preisler\\Devel\\Tenuity\\Build\\bin\\release;" + os.environ['PATH']
  8. print os.environ['PATH']
  9. import CEGUI
  10. import CEGUIOpenGLRenderer
  11.  
  12. class SampleApp(object):
  13.     def __init__(self):
  14.         glutInit(sys.argv)
  15.         glutInitDisplayMode(GLUT_DEPTH|GLUT_DOUBLE|GLUT_RGBA)
  16.         glutInitWindowSize(1280, 1024)
  17.         glutInitWindowPosition(100, 100)
  18.         glutCreateWindow("Crazy Eddie's GUI Mk-2 - Sample Application")
  19.         glutSetCursor(GLUT_CURSOR_NONE)
  20.        
  21.         glutDisplayFunc(self.displayFunc)
  22.         glutReshapeFunc(self.reshapeFunc)
  23.         glutMouseFunc(self.mouseFunc)
  24.         glutMotionFunc(self.mouseMotionFunc)
  25.         glutPassiveMotionFunc(self.mouseMotionFunc)
  26.    
  27.         CEGUIOpenGLRenderer.OpenGLRenderer.bootstrapSystem()
  28.        
  29.     def __del__(self):
  30.         CEGUIOpenGLRenderer.OpenGLRenderer.destroySystem()
  31.        
  32.     def initialiseResources(self):
  33.         rp = CEGUI.System.getSingleton().getResourceProvider()
  34.  
  35.         rp.setResourceGroupDirectory("schemes", "C:\\Users\\Martin Preisler\\Devel\\Tenuity\\Dependencies\\cegui\\datafiles/schemes")
  36.         rp.setResourceGroupDirectory("imagesets", "C:\\Users\\Martin Preisler\\Devel\\Tenuity\\Dependencies\\cegui\\datafiles/imagesets")
  37.         rp.setResourceGroupDirectory("fonts", "C:\\Users\\Martin Preisler\\Devel\\Tenuity\\Dependencies\\cegui\\datafiles/fonts")
  38.         rp.setResourceGroupDirectory("layouts", "C:\\Users\\Martin Preisler\\Devel\\Tenuity\\Dependencies\\cegui\\datafiles/layouts")
  39.         rp.setResourceGroupDirectory("looknfeels", "C:\\Users\\Martin Preisler\\Devel\\Tenuity\\Dependencies\\cegui\\datafiles/looknfeel")
  40.         rp.setResourceGroupDirectory("schemas", "C:\\Users\\Martin Preisler\\Devel\\Tenuity\\Dependencies\\cegui\\datafiles/xml_schemas")
  41.        
  42.         CEGUI.Imageset.setDefaultResourceGroup("imagesets")
  43.         CEGUI.Font.setDefaultResourceGroup("fonts")
  44.         CEGUI.Scheme.setDefaultResourceGroup("schemes")
  45.         CEGUI.WidgetLookManager.setDefaultResourceGroup("looknfeels")
  46.         CEGUI.WindowManager.setDefaultResourceGroup("layouts")
  47.        
  48.         parser = CEGUI.System.getSingleton().getXMLParser()
  49.         if parser.isPropertyPresent("SchemaDefaultResourceGroup"):
  50.             parser.setProperty("SchemaDefaultResourceGroup", "schemas")    
  51.        
  52.     def setupUI(self):
  53.         CEGUI.SchemeManager.getSingleton().create("VanillaSkinAnimated.scheme")
  54.         CEGUI.SchemeManager.getSingleton().create("TaharezLook.scheme")
  55.         CEGUI.System.getSingleton().setDefaultMouseCursor("Vanilla-Images", "MouseArrow")
  56.  
  57.         root = CEGUI.WindowManager.getSingleton().loadWindowLayout("VanillaAnimatedWindows.layout")
  58.         CEGUI.System.getSingleton().setGUISheet(root)
  59.        
  60.         self.wnd = CEGUI.WindowManager.getSingleton().createWindow("TaharezLook/FrameWindow", "Demo Window")
  61.  
  62.         root.addChildWindow(self.wnd)
  63.         self.wnd.setPosition(CEGUI.UVector2(CEGUI.UDim(0.1, 0), CEGUI.UDim(0.1, 0)))
  64.         self.wnd.setSize(CEGUI.UVector2(CEGUI.UDim(0.8, 0), CEGUI.UDim(0.8, 0)))
  65.  
  66.         self.wnd.setText("Hello World!")
  67.        
  68.         vLayout = CEGUI.WindowManager.getSingleton().createWindow("VerticalLayoutContainer")
  69.         self.wnd.addChildWindow(vLayout)
  70.        
  71.         btn = CEGUI.WindowManager.getSingleton().createWindow("TaharezLook/Button", "blah")
  72.         vLayout.addChildWindow(btn)
  73.         btn.setMinSize(CEGUI.UVector2(CEGUI.UDim(0, 100), CEGUI.UDim(0, 40)))
  74.         btn.setText("blah")
  75.        
  76.         btn = CEGUI.WindowManager.getSingleton().createWindow("TaharezLook/Button", "blah2")
  77.         vLayout.addChildWindow(btn)
  78.         btn.setMinSize(CEGUI.UVector2(CEGUI.UDim(0, 100), CEGUI.UDim(0, 40)))
  79.         btn.setText("blah2")
  80.        
  81.         hLayout = CEGUI.WindowManager.getSingleton().createWindow("HorizontalLayoutContainer")
  82.         vLayout.addChildWindow(hLayout)
  83.        
  84.         btn = CEGUI.WindowManager.getSingleton().createWindow("TaharezLook/Button", "blah3")
  85.         hLayout.addChildWindow(btn)
  86.         btn.setMinSize(CEGUI.UVector2(CEGUI.UDim(0, 100), CEGUI.UDim(0, 40)))
  87.         btn.setText("blah3")
  88.        
  89.         btn = CEGUI.WindowManager.getSingleton().createWindow("TaharezLook/Button", "blah4")
  90.         hLayout.addChildWindow(btn)
  91.         btn.setMinSize(CEGUI.UVector2(CEGUI.UDim(0, 100), CEGUI.UDim(0, 40)))
  92.         btn.setText("blah4")
  93.        
  94.         btn = CEGUI.WindowManager.getSingleton().createWindow("TaharezLook/Button", "blah5")
  95.         vLayout.addChildWindow(btn)
  96.         btn.setMinSize(CEGUI.UVector2(CEGUI.UDim(0, 100), CEGUI.UDim(0, 40)))
  97.         btn.setText("blah5")
  98.        
  99.         self.wnd2 = self.wnd.clone("ClonedWindow")
  100.        
  101.         self.tabwnd = CEGUI.WindowManager.getSingleton().createWindow("TaharezLook/FrameWindow", "Demo Window TAb")
  102.         self.tabwnd.setText("Tab demo")
  103.        
  104.         self.tabctrl = CEGUI.WindowManager.getSingleton().createWindow("TaharezLook/TabControl")
  105.         self.tabctrl.setPosition(CEGUI.UVector2(CEGUI.UDim(0, 0), CEGUI.UDim(0, 0)))
  106.         self.tabctrl.setSize(CEGUI.UVector2(CEGUI.UDim(1, 0), CEGUI.UDim(1, 0)))
  107.        
  108.         tab1 = CEGUI.WindowManager.getSingleton().createWindow("TaharezLook/StaticText")
  109.         tab1.setText("Tab 1")
  110.         tab1.setPosition(CEGUI.UVector2(CEGUI.UDim(0, 0), CEGUI.UDim(0, 0)))
  111.         tab1.setSize(CEGUI.UVector2(CEGUI.UDim(1, 0), CEGUI.UDim(1, 0)))
  112.         tab2 = CEGUI.WindowManager.getSingleton().createWindow("TaharezLook/StaticText")
  113.         tab2.setText("Tab 2")
  114.         tab2.setPosition(CEGUI.UVector2(CEGUI.UDim(0, 0), CEGUI.UDim(0, 0)))
  115.         tab2.setSize(CEGUI.UVector2(CEGUI.UDim(1, 0), CEGUI.UDim(1, 0)))
  116.        
  117.         self.tabctrl.addChildWindow(tab1)
  118.         self.tabctrl.addChildWindow(tab2)
  119.        
  120.         self.tabwnd.addChildWindow(self.tabctrl)
  121.        
  122.         root.addChildWindow(self.tabwnd)
  123.        
  124.         self.tabwnd2 = self.tabwnd.clone("TabCopy")
  125.         root.addChildWindow(self.tabwnd2)
  126.        
  127.         root.addChildWindow(self.wnd2)
  128.        
  129.     def subscriptionTest(self, e):
  130.         print dir(e)
  131.        
  132.         return True
  133.    
  134.     def run(self):
  135.         self.initialiseResources()
  136.         self.setupUI()
  137.    
  138.         self.lastFrameTime = glutGet(GLUT_ELAPSED_TIME)
  139.         self.updateFPS = 0
  140.         glutMainLoop()
  141.        
  142.     def displayFunc(self):
  143.         thisTime = glutGet(GLUT_ELAPSED_TIME)
  144.         elapsed = (thisTime - self.lastFrameTime) / 1000.0
  145.         self.lastFrameTime = thisTime
  146.         self.updateFPS = self.updateFPS - elapsed
  147.         if self.updateFPS <= 0:
  148.             elapsed__ = elapsed
  149.             if elapsed__ == 0:
  150.                 elapsed__ = 1
  151.                
  152.             wnd = CEGUI.WindowManager.getSingleton().getWindow("Demo/NewNode")
  153.             wnd.setVisible(False)
  154.             wnd.setVisible(True)
  155.            
  156.             #self.wnd.setText(str(1.0 / (elapsed__)))
  157.             self.updateFPS = 5
  158.        
  159.         CEGUI.System.getSingleton().injectTimePulse(elapsed)
  160.  
  161.         # do rendering for this frame.
  162.         glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
  163.         CEGUI.System.getSingleton().renderGUI()
  164.         glutPostRedisplay()
  165.         glutSwapBuffers()
  166.    
  167.     def reshapeFunc(self, width, height):
  168.         glViewport(0, 0, width, height)
  169.         glMatrixMode(GL_PROJECTION)
  170.         glLoadIdentity()
  171.         gluPerspective(60.0, width / height, 1.0, 50.0)
  172.         glMatrixMode(GL_MODELVIEW)
  173.         CEGUI.System.getSingleton().notifyDisplaySizeChanged(CEGUI.Size(width, height))
  174.        
  175.     def mouseFunc(self, button, state, x, y):
  176.         if button == GLUT_LEFT_BUTTON:
  177.             if state == GLUT_UP:
  178.                 CEGUI.System.getSingleton().injectMouseButtonUp(CEGUI.LeftButton)
  179.             else:
  180.                 CEGUI.System.getSingleton().injectMouseButtonDown(CEGUI.LeftButton)
  181.                
  182.         elif button == GLUT_RIGHT_BUTTON:
  183.             if state == GLUT_UP:
  184.                 CEGUI.System.getSingleton().injectMouseButtonUp(CEGUI.RightButton)
  185.             else:
  186.                 CEGUI.System.getSingleton().injectMouseButtonDown(CEGUI.RightButton)
  187.        
  188.     def mouseMotionFunc(self, x, y):
  189.         CEGUI.System.getSingleton().injectMousePosition(x, y)
  190.  
  191. app = SampleApp()
  192. app.run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement