Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os, sys
- from OpenGL.GL import *
- from OpenGL.GLU import *
- from OpenGL.GLUT import *
- os.environ['PATH'] = "C:\\Users\\Martin Preisler\\Devel\\Tenuity\\Build\\bin\\release;" + os.environ['PATH']
- print os.environ['PATH']
- import CEGUI
- import CEGUIOpenGLRenderer
- class SampleApp(object):
- def __init__(self):
- glutInit(sys.argv)
- glutInitDisplayMode(GLUT_DEPTH|GLUT_DOUBLE|GLUT_RGBA)
- glutInitWindowSize(1280, 1024)
- glutInitWindowPosition(100, 100)
- glutCreateWindow("Crazy Eddie's GUI Mk-2 - Sample Application")
- glutSetCursor(GLUT_CURSOR_NONE)
- glutDisplayFunc(self.displayFunc)
- glutReshapeFunc(self.reshapeFunc)
- glutMouseFunc(self.mouseFunc)
- glutMotionFunc(self.mouseMotionFunc)
- glutPassiveMotionFunc(self.mouseMotionFunc)
- CEGUIOpenGLRenderer.OpenGLRenderer.bootstrapSystem()
- def __del__(self):
- CEGUIOpenGLRenderer.OpenGLRenderer.destroySystem()
- def initialiseResources(self):
- rp = CEGUI.System.getSingleton().getResourceProvider()
- rp.setResourceGroupDirectory("schemes", "C:\\Users\\Martin Preisler\\Devel\\Tenuity\\Dependencies\\cegui\\datafiles/schemes")
- rp.setResourceGroupDirectory("imagesets", "C:\\Users\\Martin Preisler\\Devel\\Tenuity\\Dependencies\\cegui\\datafiles/imagesets")
- rp.setResourceGroupDirectory("fonts", "C:\\Users\\Martin Preisler\\Devel\\Tenuity\\Dependencies\\cegui\\datafiles/fonts")
- rp.setResourceGroupDirectory("layouts", "C:\\Users\\Martin Preisler\\Devel\\Tenuity\\Dependencies\\cegui\\datafiles/layouts")
- rp.setResourceGroupDirectory("looknfeels", "C:\\Users\\Martin Preisler\\Devel\\Tenuity\\Dependencies\\cegui\\datafiles/looknfeel")
- rp.setResourceGroupDirectory("schemas", "C:\\Users\\Martin Preisler\\Devel\\Tenuity\\Dependencies\\cegui\\datafiles/xml_schemas")
- CEGUI.Imageset.setDefaultResourceGroup("imagesets")
- CEGUI.Font.setDefaultResourceGroup("fonts")
- CEGUI.Scheme.setDefaultResourceGroup("schemes")
- CEGUI.WidgetLookManager.setDefaultResourceGroup("looknfeels")
- CEGUI.WindowManager.setDefaultResourceGroup("layouts")
- parser = CEGUI.System.getSingleton().getXMLParser()
- if parser.isPropertyPresent("SchemaDefaultResourceGroup"):
- parser.setProperty("SchemaDefaultResourceGroup", "schemas")
- def setupUI(self):
- CEGUI.SchemeManager.getSingleton().create("VanillaSkinAnimated.scheme")
- CEGUI.SchemeManager.getSingleton().create("TaharezLook.scheme")
- CEGUI.System.getSingleton().setDefaultMouseCursor("Vanilla-Images", "MouseArrow")
- root = CEGUI.WindowManager.getSingleton().loadWindowLayout("VanillaAnimatedWindows.layout")
- CEGUI.System.getSingleton().setGUISheet(root)
- self.wnd = CEGUI.WindowManager.getSingleton().createWindow("TaharezLook/FrameWindow", "Demo Window")
- root.addChildWindow(self.wnd)
- self.wnd.setPosition(CEGUI.UVector2(CEGUI.UDim(0.1, 0), CEGUI.UDim(0.1, 0)))
- self.wnd.setSize(CEGUI.UVector2(CEGUI.UDim(0.8, 0), CEGUI.UDim(0.8, 0)))
- self.wnd.setText("Hello World!")
- vLayout = CEGUI.WindowManager.getSingleton().createWindow("VerticalLayoutContainer")
- self.wnd.addChildWindow(vLayout)
- btn = CEGUI.WindowManager.getSingleton().createWindow("TaharezLook/Button", "blah")
- vLayout.addChildWindow(btn)
- btn.setMinSize(CEGUI.UVector2(CEGUI.UDim(0, 100), CEGUI.UDim(0, 40)))
- btn.setText("blah")
- btn = CEGUI.WindowManager.getSingleton().createWindow("TaharezLook/Button", "blah2")
- vLayout.addChildWindow(btn)
- btn.setMinSize(CEGUI.UVector2(CEGUI.UDim(0, 100), CEGUI.UDim(0, 40)))
- btn.setText("blah2")
- hLayout = CEGUI.WindowManager.getSingleton().createWindow("HorizontalLayoutContainer")
- vLayout.addChildWindow(hLayout)
- btn = CEGUI.WindowManager.getSingleton().createWindow("TaharezLook/Button", "blah3")
- hLayout.addChildWindow(btn)
- btn.setMinSize(CEGUI.UVector2(CEGUI.UDim(0, 100), CEGUI.UDim(0, 40)))
- btn.setText("blah3")
- btn = CEGUI.WindowManager.getSingleton().createWindow("TaharezLook/Button", "blah4")
- hLayout.addChildWindow(btn)
- btn.setMinSize(CEGUI.UVector2(CEGUI.UDim(0, 100), CEGUI.UDim(0, 40)))
- btn.setText("blah4")
- btn = CEGUI.WindowManager.getSingleton().createWindow("TaharezLook/Button", "blah5")
- vLayout.addChildWindow(btn)
- btn.setMinSize(CEGUI.UVector2(CEGUI.UDim(0, 100), CEGUI.UDim(0, 40)))
- btn.setText("blah5")
- self.wnd2 = self.wnd.clone("ClonedWindow")
- self.tabwnd = CEGUI.WindowManager.getSingleton().createWindow("TaharezLook/FrameWindow", "Demo Window TAb")
- self.tabwnd.setText("Tab demo")
- self.tabctrl = CEGUI.WindowManager.getSingleton().createWindow("TaharezLook/TabControl")
- self.tabctrl.setPosition(CEGUI.UVector2(CEGUI.UDim(0, 0), CEGUI.UDim(0, 0)))
- self.tabctrl.setSize(CEGUI.UVector2(CEGUI.UDim(1, 0), CEGUI.UDim(1, 0)))
- tab1 = CEGUI.WindowManager.getSingleton().createWindow("TaharezLook/StaticText")
- tab1.setText("Tab 1")
- tab1.setPosition(CEGUI.UVector2(CEGUI.UDim(0, 0), CEGUI.UDim(0, 0)))
- tab1.setSize(CEGUI.UVector2(CEGUI.UDim(1, 0), CEGUI.UDim(1, 0)))
- tab2 = CEGUI.WindowManager.getSingleton().createWindow("TaharezLook/StaticText")
- tab2.setText("Tab 2")
- tab2.setPosition(CEGUI.UVector2(CEGUI.UDim(0, 0), CEGUI.UDim(0, 0)))
- tab2.setSize(CEGUI.UVector2(CEGUI.UDim(1, 0), CEGUI.UDim(1, 0)))
- self.tabctrl.addChildWindow(tab1)
- self.tabctrl.addChildWindow(tab2)
- self.tabwnd.addChildWindow(self.tabctrl)
- root.addChildWindow(self.tabwnd)
- self.tabwnd2 = self.tabwnd.clone("TabCopy")
- root.addChildWindow(self.tabwnd2)
- root.addChildWindow(self.wnd2)
- def subscriptionTest(self, e):
- print dir(e)
- return True
- def run(self):
- self.initialiseResources()
- self.setupUI()
- self.lastFrameTime = glutGet(GLUT_ELAPSED_TIME)
- self.updateFPS = 0
- glutMainLoop()
- def displayFunc(self):
- thisTime = glutGet(GLUT_ELAPSED_TIME)
- elapsed = (thisTime - self.lastFrameTime) / 1000.0
- self.lastFrameTime = thisTime
- self.updateFPS = self.updateFPS - elapsed
- if self.updateFPS <= 0:
- elapsed__ = elapsed
- if elapsed__ == 0:
- elapsed__ = 1
- wnd = CEGUI.WindowManager.getSingleton().getWindow("Demo/NewNode")
- wnd.setVisible(False)
- wnd.setVisible(True)
- #self.wnd.setText(str(1.0 / (elapsed__)))
- self.updateFPS = 5
- CEGUI.System.getSingleton().injectTimePulse(elapsed)
- # do rendering for this frame.
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
- CEGUI.System.getSingleton().renderGUI()
- glutPostRedisplay()
- glutSwapBuffers()
- def reshapeFunc(self, width, height):
- glViewport(0, 0, width, height)
- glMatrixMode(GL_PROJECTION)
- glLoadIdentity()
- gluPerspective(60.0, width / height, 1.0, 50.0)
- glMatrixMode(GL_MODELVIEW)
- CEGUI.System.getSingleton().notifyDisplaySizeChanged(CEGUI.Size(width, height))
- def mouseFunc(self, button, state, x, y):
- if button == GLUT_LEFT_BUTTON:
- if state == GLUT_UP:
- CEGUI.System.getSingleton().injectMouseButtonUp(CEGUI.LeftButton)
- else:
- CEGUI.System.getSingleton().injectMouseButtonDown(CEGUI.LeftButton)
- elif button == GLUT_RIGHT_BUTTON:
- if state == GLUT_UP:
- CEGUI.System.getSingleton().injectMouseButtonUp(CEGUI.RightButton)
- else:
- CEGUI.System.getSingleton().injectMouseButtonDown(CEGUI.RightButton)
- def mouseMotionFunc(self, x, y):
- CEGUI.System.getSingleton().injectMousePosition(x, y)
- app = SampleApp()
- app.run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement