<s> import sys <EOL> import sylphis <EOL> import pyui <EOL> from pyui . renderer3d import Renderer3DBase <EOL> from pyui . desktop import getDesktop <EOL> def floatColor ( color ) : <EOL> return ( float ( color [ <NUM_LIT:0> ] ) / <NUM_LIT> , float ( color [ <NUM_LIT:1> ] ) / <NUM_LIT> , float ( color [ <NUM_LIT:2> ] ) / <NUM_LIT> , float ( color [ <NUM_LIT:3> ] ) / <NUM_LIT> ) <EOL> class SylphisRenderer ( Renderer3DBase , sylphis . CPyInputListener ) : <EOL> name = "<STR_LIT>" <EOL> def __init__ ( self , w , h , fullscreen , title ) : <EOL> sylphis . CPyInputListener . __init__ ( self ) <EOL> self . self = self <EOL> Renderer3DBase . __init__ ( self , w , h , fullscreen , title ) <EOL> self . frame = <NUM_LIT:0> <EOL> self . last = <NUM_LIT:0> <EOL> self . width = w <EOL> self . height = h <EOL> self . fontId = <NUM_LIT> <EOL> self . fonts = { } <EOL> self . textures = { } <EOL> self . mouseX = <NUM_LIT:0> <EOL> self . mouseY = <NUM_LIT:0> <EOL> self . active = <NUM_LIT:0> <EOL> global input <EOL> input = CEngine . getInput ( ) <EOL> global rend <EOL> rend = CEngine . renderer <EOL> global efonts <EOL> efonts = CEngine . fonts <EOL> global materials <EOL> materials = CEngine . mMaterials <EOL> self . pointer = materials . registerMaterial ( "<STR_LIT>" ) <EOL> input . addListener ( self ) <EOL> pyui . locals . K_RETURN = sylphis . kENTER <EOL> pyui . locals . K_SHIFT = sylphis . kLEFTSHIFT <EOL> pyui . locals . K_LEFT = sylphis . kLARROW <EOL> pyui . locals . K_UP = sylphis . kUARROW <EOL> pyui . locals . K_RIGHT = sylphis . kRARROW <EOL> pyui . locals . K_DOWN = sylphis . kDARROW <EOL> pyui . locals . K_PAD0 = <NUM_LIT> <EOL> pyui . locals . K_PAD1 = <NUM_LIT> <EOL> pyui . locals . K_PAD2 = <NUM_LIT> <EOL> pyui . locals . K_PAD3 = <NUM_LIT> <EOL> pyui . locals . K_PAD4 = <NUM_LIT> <EOL> pyui . locals . K_PAD5 = <NUM_LIT> <EOL> pyui . locals . K_PAD6 = <NUM_LIT> <EOL> pyui . locals . K_PAD7 = <NUM_LIT> <EOL> pyui . locals . K_PAD8 = <NUM_LIT> <EOL> pyui . locals . K_PAD9 = <NUM_LIT> <EOL> pyui . locals . K_PADDIVIDE = <NUM_LIT> <EOL> pyui . locals . K_PADTIMES = <NUM_LIT> <EOL> pyui . locals . K_PADMINUS = <NUM_LIT> <EOL> pyui . locals . K_PADPLUS = <NUM_LIT> <EOL> pyui . locals . K_PADENTER = <NUM_LIT> <EOL> pyui . locals . K_PADDECIMAL = <NUM_LIT> <EOL> pyui . locals . K_F1 = <NUM_LIT> <EOL> pyui . locals . K_F2 = <NUM_LIT> <EOL> pyui . locals . K_F3 = <NUM_LIT> <EOL> pyui . locals . K_F4 = <NUM_LIT> <EOL> pyui . locals . K_F5 = <NUM_LIT> <EOL> pyui . locals . K_F6 = <NUM_LIT> <EOL> pyui . locals . K_F7 = <NUM_LIT> <EOL> pyui . locals . K_F8 = <NUM_LIT> <EOL> pyui . locals . K_F9 = <NUM_LIT> <EOL> pyui . locals . K_F10 = <NUM_LIT> <EOL> pyui . locals . K_F11 = <NUM_LIT> <EOL> pyui . locals . K_F12 = <NUM_LIT> <EOL> self . drawBackMethod = self . clear <EOL> def activate ( self ) : <EOL> self . active = <NUM_LIT:1> <EOL> def deactivate ( self ) : <EOL> self . active = <NUM_LIT:0> <EOL> def onKeyPressed ( self , key ) : <EOL> if not self . active : <EOL> if key == sylphis . kF9 : <EOL> self . activate ( ) <EOL> return <EOL> if key == sylphis . kF9 : <EOL> self . deactivate ( ) <EOL> x = self . mouseX <EOL> y = self . mouseY <EOL> if key == sylphis . kMOUSELEFT : <EOL> getDesktop ( ) . postUserEvent ( pyui . locals . LMOUSEBUTTONDOWN , x , y ) <EOL> return <EOL> if key == sylphis . kMOUSERIGHT : <EOL> getDesktop ( ) . postUserEvent ( pyui . locals . RMOUSEBUTTONDOWN , x , y ) <EOL> return <EOL> if key < <NUM_LIT:0> : <EOL> getDesktop ( ) . postUserEvent ( pyui . locals . CHAR , <NUM_LIT:0> , <NUM_LIT:0> , chr ( - key ) , self . getModifiers ( ) ) <EOL> if key > <NUM_LIT:0> and key < <NUM_LIT> : <EOL> getDesktop ( ) . postUserEvent ( pyui . locals . KEYDOWN , <NUM_LIT:0> , <NUM_LIT:0> , key , self . getModifiers ( ) ) <EOL> def onKeyReleased ( self , key ) : <EOL> if not self . active : <EOL> return <EOL> x = self . mouseX <EOL> y = self . mouseY <EOL> if key == sylphis . kMOUSELEFT : <EOL> getDesktop ( ) . postUserEvent ( pyui . locals . LMOUSEBUTTONUP , x , y ) <EOL> return <EOL> if key == sylphis . kMOUSERIGHT : <EOL> getDesktop ( ) . postUserEvent ( pyui . locals . RMOUSEBUTTONUP , x , y ) <EOL> return <EOL> getDesktop ( ) . postUserEvent ( pyui . locals . KEYUP , <NUM_LIT:0> , <NUM_LIT:0> , key , self . getModifiers ( ) ) <EOL> def setScissor ( self , rect ) : <EOL> rend . setScissor ( rect [ <NUM_LIT:0> ] , rect [ <NUM_LIT:1> ] , rect [ <NUM_LIT:2> ] , rect [ <NUM_LIT:3> ] ) <EOL> def drawRect ( self , color , rect ) : <EOL> """<STR_LIT>""" <EOL> rend . GLDisableTexture2D ( ) <EOL> rend . GLBeginQuad ( ) <EOL> color = floatColor ( color ) <EOL> rend . GLColor4 ( color [ <NUM_LIT:0> ] , color [ <NUM_LIT:1> ] , color [ <NUM_LIT:2> ] , color [ <NUM_LIT:3> ] ) <EOL> rend . GLVertex2 ( rect [ <NUM_LIT:0> ] , rect [ <NUM_LIT:1> ] ) <EOL> rend . GLVertex2 ( rect [ <NUM_LIT:0> ] + rect [ <NUM_LIT:2> ] , rect [ <NUM_LIT:1> ] ) <EOL> rend . GLVertex2 ( rect [ <NUM_LIT:0> ] + rect [ <NUM_LIT:2> ] , rect [ <NUM_LIT:1> ] + rect [ <NUM_LIT:3> ] ) <EOL> rend . GLVertex2 ( rect [ <NUM_LIT:0> ] , rect [ <NUM_LIT:1> ] + rect [ <NUM_LIT:3> ] ) <EOL> rend . GLEnd ( ) <EOL> def drawText ( self , text , pos , color , font = None ) : <EOL> """<STR_LIT>""" <EOL> self . do_text ( text , ( pos [ <NUM_LIT:0> ] , pos [ <NUM_LIT:1> ] ) , color , font ) <EOL> def drawGradient ( self , rect , c1 , c2 , c3 , c4 ) : <EOL> """<STR_LIT>""" <EOL> c1 = floatColor ( c1 ) <EOL> c2 = floatColor ( c2 ) <EOL> c3 = floatColor ( c3 ) <EOL> c4 = floatColor ( c4 ) <EOL> rend . GLBeginQuad ( ) <EOL> rend . GLColor4 ( c1 [ <NUM_LIT:0> ] , c1 [ <NUM_LIT:1> ] , c1 [ <NUM_LIT:2> ] , c1 [ <NUM_LIT:3> ] ) <EOL> rend . GLVertex2 ( rect [ <NUM_LIT:0> ] , rect [ <NUM_LIT:1> ] ) <EOL> rend . GLColor4 ( c2 [ <NUM_LIT:0> ] , c2 [ <NUM_LIT:1> ] , c2 [ <NUM_LIT:2> ] , c2 [ <NUM_LIT:3> ] ) <EOL> rend . GLVertex2 ( rect [ <NUM_LIT:0> ] + rect [ <NUM_LIT:2> ] , rect [ <NUM_LIT:1> ] ) <EOL> rend . GLColor4 ( c4 [ <NUM_LIT:0> ] , c4 [ <NUM_LIT:1> ] , c4 [ <NUM_LIT:2> ] , c4 [ <NUM_LIT:3> ] ) <EOL> rend . GLVertex2 ( rect [ <NUM_LIT:0> ] + rect [ <NUM_LIT:2> ] , rect [ <NUM_LIT:1> ] + rect [ <NUM_LIT:3> ] ) <EOL> rend . GLColor4 ( c3 [ <NUM_LIT:0> ] , c3 [ <NUM_LIT:1> ] , c3 [ <NUM_LIT:2> ] , c3 [ <NUM_LIT:3> ] ) <EOL> rend . GLVertex2 ( rect [ <NUM_LIT:0> ] , rect [ <NUM_LIT:1> ] + rect [ <NUM_LIT:3> ] ) <EOL> rend . GLEnd ( ) <EOL> def drawLine ( self , x1 , y1 , x2 , y2 , color ) : <EOL> """<STR_LIT>""" <EOL> color = floatColor ( color ) <EOL> rend . GLBeginLine ( ) <EOL> rend . GLColor4 ( color [ <NUM_LIT:0> ] , color [ <NUM_LIT:1> ] , color [ <NUM_LIT:2> ] , color [ <NUM_LIT:3> ] ) <EOL> rend . GLVertex2 ( x1 , y1 ) <EOL> rend . GLVertex2 ( x2 , y2 ) <EOL> rend . GLEnd ( ) <EOL> def drawImage ( self , rect , filename , pieceRect = None ) : <EOL> """<STR_LIT>""" <EOL> shader = filename <EOL> rend . drawPic ( rect [ <NUM_LIT:0> ] , rect [ <NUM_LIT:1> ] , rect [ <NUM_LIT:2> ] , rect [ <NUM_LIT:3> ] , shader ) <EOL> rend . renderOverlay2D ( ) <EOL> pass <EOL> def drawImageRotated ( self , rect , filename , rotDegrees = <NUM_LIT:0> , textureEffect = <NUM_LIT:0> ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> def loadImage ( self , filename , label = None ) : <EOL> if not filename : <EOL> return <EOL> self . loadTexture ( filename , label ) <EOL> def setClipping ( self , rect = None ) : <EOL> """<STR_LIT>""" <EOL> return <EOL> def draw ( self , windows ) : <EOL> """<STR_LIT>""" <EOL> for i in xrange ( len ( windows ) - <NUM_LIT:1> , - <NUM_LIT:1> , - <NUM_LIT:1> ) : <EOL> w = windows [ i ] <EOL> w . dirty = <NUM_LIT:1> <EOL> self . setWindowOrigin ( w . posX , w . posY ) <EOL> w . drawWindow ( self ) <EOL> self . unsetWindowOrigin ( ) <EOL> def update ( self ) : <EOL> pass <EOL> def getModifiers ( self ) : <EOL> mods = <NUM_LIT:0> <EOL> if input . isPressed ( sylphis . kRIGHTSHIFT ) or input . isPressed ( sylphis . kLEFTSHIFT ) : <EOL> mods |= pyui . locals . MOD_SHIFT <EOL> return mods <EOL> def quit ( self ) : <EOL> return <EOL> def clear ( self ) : <EOL> return <EOL> def packColor ( self , r , g , b , a = <NUM_LIT:255> ) : <EOL> """<STR_LIT>""" <EOL> return ( r , g , b , a ) <EOL> def dirtyCollidingWindows ( self , inRect ) : <EOL> """<STR_LIT>""" <EOL> return <EOL> def setup2D ( self ) : <EOL> """<STR_LIT>""" <EOL> rend . enter2DMode ( ) ; <EOL> def teardown2D ( self ) : <EOL> """<STR_LIT>""" <EOL> rend . exit2DMode ( ) <EOL> def getScreenSize ( self ) : <EOL> """<STR_LIT>""" <EOL> return ( self . width , self . height ) <EOL> def loadTexture ( self , filename , label = None ) : <EOL> return shaders . addShader ( filename ) <EOL> def setWindowOrigin ( self , winX , winY ) : <EOL> rend . beginObjectTransformations ( ) <EOL> rend . translate ( sylphis . CVector3 ( winX , winY , <NUM_LIT:0> ) ) <EOL> def unsetWindowOrigin ( self ) : <EOL> rend . endObjectTransformations ( ) <EOL> def do_text ( self , text , position , color , font ) : <EOL> """<STR_LIT>""" <EOL> if len ( text ) < <NUM_LIT:1> : <EOL> return <EOL> if not font : <EOL> font = pyui . desktop . getTheme ( ) . defaultFont <EOL> color = floatColor ( color ) <EOL> rend . GLColor4 ( color [ <NUM_LIT:0> ] , color [ <NUM_LIT:1> ] , color [ <NUM_LIT:2> ] , color [ <NUM_LIT:3> ] ) ; <EOL> font . renderString ( text , position [ <NUM_LIT:0> ] , position [ <NUM_LIT:1> ] ) <EOL> def getTextSize ( self , text , font = None ) : <EOL> """<STR_LIT>""" <EOL> if not font : <EOL> font = pyui . desktop . getTheme ( ) . defaultFont <EOL> size = font . stringSize ( text ) <EOL> return size <EOL> def createFont ( self , fontName , fontSize , flags ) : <EOL> print "<STR_LIT>" , fontName <EOL> if fontName == '<STR_LIT>' : <EOL> fontName = '<STR_LIT>' <EOL> if fontName == '<STR_LIT>' : <EOL> fontName = '<STR_LIT>' <EOL> try : <EOL> f = efonts . registerBitmapFont ( "<STR_LIT>" + fontName + "<STR_LIT>" , fontSize ) <EOL> return f <EOL> except IOError , e : <EOL> print fontName , "<STR_LIT>" <EOL> def run ( self , callback = None ) : <EOL> if not self . active : <EOL> return <EOL> self . mouseX += input . getPointerDeltaX ( ) <EOL> self . mouseY += input . getPointerDeltaY ( ) <EOL> if self . mouseX < <NUM_LIT:0> : <EOL> self . mouseX = <NUM_LIT:0> <EOL> if self . mouseY < <NUM_LIT:0> : <EOL> self . mouseY = <NUM_LIT:0> <EOL> if self . mouseX > self . width : <EOL> self . mouseX = self . width <EOL> if self . mouseY > self . height : <EOL> self . mouseY = self . height <EOL> getDesktop ( ) . postUserEvent ( pyui . locals . MOUSEMOVE , self . mouseX , self . mouseY ) <EOL> getDesktop ( ) . draw ( ) <EOL> getDesktop ( ) . update ( ) <EOL> self . drawImage ( ( self . mouseX , self . mouseY , <NUM_LIT:32> , <NUM_LIT:32> ) , self . pointer ) </s>
