idx
int64
0
41.2k
question
stringlengths
73
5.81k
target
stringlengths
5
918
37,900
public static void enterSafeBlock ( ) { if ( inSafe ) { return ; } Renderer . get ( ) . flush ( ) ; lastUsed = TextureImpl . getLastBind ( ) ; TextureImpl . bindNone ( ) ; GL11 . glPushAttrib ( GL11 . GL_ALL_ATTRIB_BITS ) ; GL11 . glPushClientAttrib ( GL11 . GL_ALL_CLIENT_ATTRIB_BITS ) ; GL11 . glMatrixMode ( GL11 . GL_MODELVIEW ) ; GL11 . glPushMatrix ( ) ; GL11 . glMatrixMode ( GL11 . GL_PROJECTION ) ; GL11 . glPushMatrix ( ) ; GL11 . glMatrixMode ( GL11 . GL_MODELVIEW ) ; inSafe = true ; }
Enter a safe block ensuring that all the OpenGL state that slick uses is safe before touching the GL state directly .
37,901
public static void leaveSafeBlock ( ) { if ( ! inSafe ) { return ; } GL11 . glMatrixMode ( GL11 . GL_PROJECTION ) ; GL11 . glPopMatrix ( ) ; GL11 . glMatrixMode ( GL11 . GL_MODELVIEW ) ; GL11 . glPopMatrix ( ) ; GL11 . glPopClientAttrib ( ) ; GL11 . glPopAttrib ( ) ; if ( lastUsed != null ) { lastUsed . bind ( ) ; } else { TextureImpl . bindNone ( ) ; } inSafe = false ; }
Leave a safe block ensuring that all of Slick s OpenGL state is restored since the last enter .
37,902
private List createPoints ( int numberOfSegments , float radius , float cx , float cy , float start , float end ) { ArrayList tempPoints = new ArrayList ( ) ; int step = 360 / numberOfSegments ; for ( float a = start ; a <= end + step ; a += step ) { float ang = a ; if ( ang > end ) { ang = end ; } float x = ( float ) ( cx + ( FastTrig . cos ( Math . toRadians ( ang ) ) * radius ) ) ; float y = ( float ) ( cy + ( FastTrig . sin ( Math . toRadians ( ang ) ) * radius ) ) ; tempPoints . add ( new Float ( x ) ) ; tempPoints . add ( new Float ( y ) ) ; } return tempPoints ; }
Generate the points to fill a corner arc .
37,903
private void fireUpdated ( Object source ) { for ( int i = 0 ; i < listeners . size ( ) ; i ++ ) { ( ( InputPanelListener ) listeners . get ( i ) ) . valueUpdated ( this ) ; } }
Fire notification of updates to all listeners
37,904
private void loadBackground ( ) { JFileChooser chooser = new JFileChooser ( "." ) ; chooser . setDialogTitle ( "Open" ) ; int resp = chooser . showOpenDialog ( this ) ; if ( resp == JFileChooser . APPROVE_OPTION ) { game . setBackgroundImage ( chooser . getSelectedFile ( ) ) ; } }
Load a background image to display behind the particle system
37,905
private void initGraphEditorWindow ( ) { GraphEditorWindow editor = new GraphEditorWindow ( ) ; whiskasPanel . setEditor ( editor ) ; graphEditorFrame = new JFrame ( "Whiskas Gradient Editor" ) ; graphEditorFrame . getContentPane ( ) . add ( editor ) ; graphEditorFrame . setDefaultCloseOperation ( WindowConstants . HIDE_ON_CLOSE ) ; graphEditorFrame . pack ( ) ; graphEditorFrame . setSize ( 600 , 300 ) ; graphEditorFrame . setLocation ( this . getX ( ) , this . getY ( ) + this . getHeight ( ) ) ; graphEditorFrame . setVisible ( true ) ; }
init the graph editor window
37,906
public void importEmitter ( ) { chooser . setDialogTitle ( "Open" ) ; int resp = chooser . showOpenDialog ( this ) ; if ( resp == JFileChooser . APPROVE_OPTION ) { File file = chooser . getSelectedFile ( ) ; File path = file . getParentFile ( ) ; try { final ConfigurableEmitter emitter = ParticleIO . loadEmitter ( file ) ; if ( emitter . getImageName ( ) != null ) { File possible = new File ( path , emitter . getImageName ( ) ) ; if ( possible . exists ( ) ) { emitter . setImageName ( possible . getAbsolutePath ( ) ) ; } else { chooser . setDialogTitle ( "Locate the image: " + emitter . getImageName ( ) ) ; resp = chooser . showOpenDialog ( this ) ; FileFilter filter = new FileFilter ( ) { public boolean accept ( File f ) { if ( f . isDirectory ( ) ) { return true ; } return ( f . getName ( ) . equals ( emitter . getImageName ( ) ) ) ; } public String getDescription ( ) { return emitter . getImageName ( ) ; } } ; chooser . addChoosableFileFilter ( filter ) ; if ( resp == JFileChooser . APPROVE_OPTION ) { File image = chooser . getSelectedFile ( ) ; emitter . setImageName ( image . getAbsolutePath ( ) ) ; path = image . getParentFile ( ) ; } chooser . resetChoosableFileFilters ( ) ; chooser . addChoosableFileFilter ( xmlFileFilter ) ; } } addEmitter ( emitter ) ; emitters . setSelected ( emitter ) ; } catch ( IOException e ) { Log . error ( e ) ; JOptionPane . showMessageDialog ( this , e . getMessage ( ) ) ; } } }
Import an emitter XML file
37,907
public void cloneEmitter ( ) { if ( selected == null ) { return ; } try { ByteArrayOutputStream bout = new ByteArrayOutputStream ( ) ; ParticleIO . saveEmitter ( bout , selected ) ; ByteArrayInputStream bin = new ByteArrayInputStream ( bout . toByteArray ( ) ) ; ConfigurableEmitter emitter = ParticleIO . loadEmitter ( bin ) ; emitter . name = emitter . name + "_clone" ; addEmitter ( emitter ) ; emitters . setSelected ( emitter ) ; } catch ( IOException e ) { Log . error ( e ) ; JOptionPane . showMessageDialog ( this , e . getMessage ( ) ) ; } }
Clone the selected emitter
37,908
public void exportEmitter ( ) { if ( selected == null ) { return ; } chooser . setDialogTitle ( "Save" ) ; int resp = chooser . showSaveDialog ( this ) ; if ( resp == JFileChooser . APPROVE_OPTION ) { File file = chooser . getSelectedFile ( ) ; if ( ! file . getName ( ) . endsWith ( ".xml" ) ) { file = new File ( file . getAbsolutePath ( ) + ".xml" ) ; } try { ParticleIO . saveEmitter ( file , selected ) ; } catch ( IOException e ) { Log . error ( e ) ; JOptionPane . showMessageDialog ( this , e . getMessage ( ) ) ; } } }
Export an emitter XML file
37,909
public void createNewSystem ( ) { game . clearSystem ( additive . isSelected ( ) ) ; pointsEnabled . setSelected ( false ) ; emitters . clear ( ) ; }
Create a completely new particle system
37,910
public void loadSystem ( ) { chooser . setDialogTitle ( "Open" ) ; int resp = chooser . showOpenDialog ( this ) ; if ( resp == JFileChooser . APPROVE_OPTION ) { File file = chooser . getSelectedFile ( ) ; File path = file . getParentFile ( ) ; try { ParticleSystem system = ParticleIO . loadConfiguredSystem ( file ) ; game . setSystem ( system ) ; emitters . clear ( ) ; for ( int i = 0 ; i < system . getEmitterCount ( ) ; i ++ ) { final ConfigurableEmitter emitter = ( ConfigurableEmitter ) system . getEmitter ( i ) ; if ( emitter . getImageName ( ) != null ) { File possible = new File ( path , emitter . getImageName ( ) ) ; if ( possible . exists ( ) ) { emitter . setImageName ( possible . getAbsolutePath ( ) ) ; } else { chooser . setDialogTitle ( "Locate the image: " + emitter . getImageName ( ) ) ; FileFilter filter = new FileFilter ( ) { public boolean accept ( File f ) { if ( f . isDirectory ( ) ) { return true ; } return ( f . getName ( ) . equals ( emitter . getImageName ( ) ) ) ; } public String getDescription ( ) { return emitter . getImageName ( ) ; } } ; chooser . addChoosableFileFilter ( filter ) ; resp = chooser . showOpenDialog ( this ) ; if ( resp == JFileChooser . APPROVE_OPTION ) { File image = chooser . getSelectedFile ( ) ; emitter . setImageName ( image . getAbsolutePath ( ) ) ; path = image . getParentFile ( ) ; } chooser . setDialogTitle ( "Open" ) ; chooser . resetChoosableFileFilters ( ) ; chooser . addChoosableFileFilter ( xmlFileFilter ) ; } } emitters . add ( emitter ) ; } additive . setSelected ( system . getBlendingMode ( ) == ParticleSystem . BLEND_ADDITIVE ) ; pointsEnabled . setSelected ( system . usePoints ( ) ) ; emitters . setSelected ( 0 ) ; } catch ( IOException e ) { Log . error ( e ) ; JOptionPane . showMessageDialog ( this , e . getMessage ( ) ) ; } } }
Load a complete particle system XML description
37,911
public void saveSystem ( ) { int resp = chooser . showSaveDialog ( this ) ; if ( resp == JFileChooser . APPROVE_OPTION ) { File file = chooser . getSelectedFile ( ) ; if ( ! file . getName ( ) . endsWith ( ".xml" ) ) { file = new File ( file . getAbsolutePath ( ) + ".xml" ) ; } try { ParticleIO . saveConfiguredSystem ( file , game . getSystem ( ) ) ; } catch ( IOException e ) { Log . error ( e ) ; JOptionPane . showMessageDialog ( this , e . getMessage ( ) ) ; } } }
Save a complete particle system XML description
37,912
public void setCurrentEmitter ( ConfigurableEmitter emitter ) { this . selected = emitter ; if ( emitter == null ) { emissionControls . setEnabled ( false ) ; settingsPanel . setEnabled ( false ) ; positionControls . setEnabled ( false ) ; colorPanel . setEnabled ( false ) ; limitPanel . setEnabled ( false ) ; whiskasPanel . setEnabled ( false ) ; } else { emissionControls . setEnabled ( true ) ; settingsPanel . setEnabled ( true ) ; positionControls . setEnabled ( true ) ; colorPanel . setEnabled ( true ) ; limitPanel . setEnabled ( true ) ; whiskasPanel . setEnabled ( true ) ; emissionControls . setTarget ( emitter ) ; settingsPanel . setTarget ( emitter ) ; positionControls . setTarget ( emitter ) ; settingsPanel . setTarget ( emitter ) ; colorPanel . setTarget ( emitter ) ; limitPanel . setTarget ( emitter ) ; whiskasPanel . setTarget ( emitter ) ; } }
Set the currently selected and edited particle emitter
37,913
public void updateBlendMode ( ) { if ( additive . isSelected ( ) ) { game . getSystem ( ) . setBlendingMode ( ParticleSystem . BLEND_ADDITIVE ) ; } else { game . getSystem ( ) . setBlendingMode ( ParticleSystem . BLEND_COMBINE ) ; } }
Change the visual indicator for the current particle system blend mode
37,914
public static void main ( String [ ] argv ) { try { UIManager . setLookAndFeel ( UIManager . getSystemLookAndFeelClassName ( ) ) ; new ParticleEditor ( ) ; } catch ( Exception e ) { Log . error ( e ) ; } }
Entry point in the editor
37,915
public static InputStream getResourceAsStream ( String ref ) { InputStream in = null ; for ( int i = 0 ; i < locations . size ( ) ; i ++ ) { ResourceLocation location = ( ResourceLocation ) locations . get ( i ) ; in = location . getResourceAsStream ( ref ) ; if ( in != null ) { break ; } } if ( in == null ) { throw new RuntimeException ( "Resource not found: " + ref ) ; } return new BufferedInputStream ( in ) ; }
Get a resource
37,916
public static boolean resourceExists ( String ref ) { URL url = null ; for ( int i = 0 ; i < locations . size ( ) ; i ++ ) { ResourceLocation location = ( ResourceLocation ) locations . get ( i ) ; url = location . getResource ( ref ) ; if ( url != null ) { return true ; } } return false ; }
Check if a resource is available from any given resource loader
37,917
public static URL getResource ( String ref ) { URL url = null ; for ( int i = 0 ; i < locations . size ( ) ; i ++ ) { ResourceLocation location = ( ResourceLocation ) locations . get ( i ) ; url = location . getResource ( ref ) ; if ( url != null ) { break ; } } if ( url == null ) { throw new RuntimeException ( "Resource not found: " + ref ) ; } return url ; }
Get a resource as a URL
37,918
public void setPosition ( float x , float y , boolean moveParticles ) { if ( moveParticles ) { adjust = true ; adjustx -= this . x - x ; adjusty -= this . y - y ; } this . x = x ; this . y = y ; }
Set the position of this particle source
37,919
public boolean completed ( ) { if ( engine == null ) { return false ; } if ( length . isEnabled ( ) ) { if ( timeout > 0 ) { return false ; } return completed ; } if ( emitCount . isEnabled ( ) ) { if ( leftToEmit > 0 ) { return false ; } return completed ; } if ( wrapUp ) { return completed ; } return false ; }
Check if this emitter has completed it s cycle
37,920
public ConfigurableEmitter duplicate ( ) { ConfigurableEmitter theCopy = null ; try { ByteArrayOutputStream bout = new ByteArrayOutputStream ( ) ; ParticleIO . saveEmitter ( bout , this ) ; ByteArrayInputStream bin = new ByteArrayInputStream ( bout . toByteArray ( ) ) ; theCopy = ParticleIO . loadEmitter ( bin ) ; } catch ( IOException e ) { Log . error ( "Slick: ConfigurableEmitter.duplicate(): caught exception " + e . toString ( ) ) ; return null ; } return theCopy ; }
Create a duplicate of this emitter . The duplicate should be added to a ParticleSystem to be used .
37,921
public static void runAsApplication ( Game game , int width , int height , boolean fullscreen ) { try { AppGameContainer container = new AppGameContainer ( game , width , height , fullscreen ) ; container . start ( ) ; } catch ( Exception e ) { e . printStackTrace ( ) ; } }
Start the game as an application
37,922
public void setX ( float x ) { if ( x != this . x ) { float dx = x - this . x ; this . x = x ; if ( ( points == null ) || ( center == null ) ) { checkPoints ( ) ; } for ( int i = 0 ; i < points . length / 2 ; i ++ ) { points [ i * 2 ] += dx ; } center [ 0 ] += dx ; x += dx ; maxX += dx ; minX += dx ; trianglesDirty = true ; } }
Set the x position of the left side this shape .
37,923
public void setY ( float y ) { if ( y != this . y ) { float dy = y - this . y ; this . y = y ; if ( ( points == null ) || ( center == null ) ) { checkPoints ( ) ; } for ( int i = 0 ; i < points . length / 2 ; i ++ ) { points [ ( i * 2 ) + 1 ] += dy ; } center [ 1 ] += dy ; y += dy ; maxY += dy ; minY += dy ; trianglesDirty = true ; } }
Set the y position of the top of this shape .
37,924
public void setCenterX ( float centerX ) { if ( ( points == null ) || ( center == null ) ) { checkPoints ( ) ; } float xDiff = centerX - getCenterX ( ) ; setX ( x + xDiff ) ; }
Set the x center of this shape .
37,925
public void setCenterY ( float centerY ) { if ( ( points == null ) || ( center == null ) ) { checkPoints ( ) ; } float yDiff = centerY - getCenterY ( ) ; setY ( y + yDiff ) ; }
Set the y center of this shape .
37,926
public float [ ] getPoint ( int index ) { checkPoints ( ) ; float result [ ] = new float [ 2 ] ; result [ 0 ] = points [ index * 2 ] ; result [ 1 ] = points [ index * 2 + 1 ] ; return result ; }
Get a single point in this polygon
37,927
public float [ ] getNormal ( int index ) { float [ ] current = getPoint ( index ) ; float [ ] prev = getPoint ( index - 1 < 0 ? getPointCount ( ) - 1 : index - 1 ) ; float [ ] next = getPoint ( index + 1 >= getPointCount ( ) ? 0 : index + 1 ) ; float [ ] t1 = getNormal ( prev , current ) ; float [ ] t2 = getNormal ( current , next ) ; if ( ( index == 0 ) && ( ! closed ( ) ) ) { return t2 ; } if ( ( index == getPointCount ( ) - 1 ) && ( ! closed ( ) ) ) { return t1 ; } float tx = ( t1 [ 0 ] + t2 [ 0 ] ) / 2 ; float ty = ( t1 [ 1 ] + t2 [ 1 ] ) / 2 ; float len = ( float ) Math . sqrt ( ( tx * tx ) + ( ty * ty ) ) ; return new float [ ] { tx / len , ty / len } ; }
Get the combine normal of a given point
37,928
public boolean contains ( Shape other ) { if ( other . intersects ( this ) ) { return false ; } for ( int i = 0 ; i < other . getPointCount ( ) ; i ++ ) { float [ ] pt = other . getPoint ( i ) ; if ( ! contains ( pt [ 0 ] , pt [ 1 ] ) ) { return false ; } } return true ; }
Check if the shape passed is entirely contained within this shape .
37,929
private float [ ] getNormal ( float [ ] start , float [ ] end ) { float dx = start [ 0 ] - end [ 0 ] ; float dy = start [ 1 ] - end [ 1 ] ; float len = ( float ) Math . sqrt ( ( dx * dx ) + ( dy * dy ) ) ; dx /= len ; dy /= len ; return new float [ ] { - dy , dx } ; }
Get the normal of the line between two points
37,930
public boolean includes ( float x , float y ) { if ( points . length == 0 ) { return false ; } checkPoints ( ) ; Line testLine = new Line ( 0 , 0 , 0 , 0 ) ; Vector2f pt = new Vector2f ( x , y ) ; for ( int i = 0 ; i < points . length ; i += 2 ) { int n = i + 2 ; if ( n >= points . length ) { n = 0 ; } testLine . set ( points [ i ] , points [ i + 1 ] , points [ n ] , points [ n + 1 ] ) ; if ( testLine . on ( pt ) ) { return true ; } } return false ; }
Check if the given point is part of the path that forms this shape
37,931
public int indexOf ( float x , float y ) { for ( int i = 0 ; i < points . length ; i += 2 ) { if ( ( points [ i ] == x ) && ( points [ i + 1 ] == y ) ) { return i / 2 ; } } return - 1 ; }
Get the index of a given point
37,932
public boolean contains ( float x , float y ) { checkPoints ( ) ; if ( points . length == 0 ) { return false ; } boolean result = false ; float xnew , ynew ; float xold , yold ; float x1 , y1 ; float x2 , y2 ; int npoints = points . length ; xold = points [ npoints - 2 ] ; yold = points [ npoints - 1 ] ; for ( int i = 0 ; i < npoints ; i += 2 ) { xnew = points [ i ] ; ynew = points [ i + 1 ] ; if ( xnew > xold ) { x1 = xold ; x2 = xnew ; y1 = yold ; y2 = ynew ; } else { x1 = xnew ; x2 = xold ; y1 = ynew ; y2 = yold ; } if ( ( xnew < x ) == ( x <= xold ) && ( ( double ) y - ( double ) y1 ) * ( x2 - x1 ) < ( ( double ) y2 - ( double ) y1 ) * ( x - x1 ) ) { result = ! result ; } xold = xnew ; yold = ynew ; } return result ; }
Check if this polygon contains the given point
37,933
public boolean intersects ( Shape shape ) { checkPoints ( ) ; boolean result = false ; float points [ ] = getPoints ( ) ; float thatPoints [ ] = shape . getPoints ( ) ; int length = points . length ; int thatLength = thatPoints . length ; double unknownA ; double unknownB ; if ( ! closed ( ) ) { length -= 2 ; } if ( ! shape . closed ( ) ) { thatLength -= 2 ; } for ( int i = 0 ; i < length ; i += 2 ) { int iNext = i + 2 ; if ( iNext >= points . length ) { iNext = 0 ; } for ( int j = 0 ; j < thatLength ; j += 2 ) { int jNext = j + 2 ; if ( jNext >= thatPoints . length ) { jNext = 0 ; } unknownA = ( ( ( points [ iNext ] - points [ i ] ) * ( double ) ( thatPoints [ j + 1 ] - points [ i + 1 ] ) ) - ( ( points [ iNext + 1 ] - points [ i + 1 ] ) * ( thatPoints [ j ] - points [ i ] ) ) ) / ( ( ( points [ iNext + 1 ] - points [ i + 1 ] ) * ( thatPoints [ jNext ] - thatPoints [ j ] ) ) - ( ( points [ iNext ] - points [ i ] ) * ( thatPoints [ jNext + 1 ] - thatPoints [ j + 1 ] ) ) ) ; unknownB = ( ( ( thatPoints [ jNext ] - thatPoints [ j ] ) * ( double ) ( thatPoints [ j + 1 ] - points [ i + 1 ] ) ) - ( ( thatPoints [ jNext + 1 ] - thatPoints [ j + 1 ] ) * ( thatPoints [ j ] - points [ i ] ) ) ) / ( ( ( points [ iNext + 1 ] - points [ i + 1 ] ) * ( thatPoints [ jNext ] - thatPoints [ j ] ) ) - ( ( points [ iNext ] - points [ i ] ) * ( thatPoints [ jNext + 1 ] - thatPoints [ j + 1 ] ) ) ) ; if ( unknownA >= 0 && unknownA <= 1 && unknownB >= 0 && unknownB <= 1 ) { result = true ; break ; } } if ( result ) { break ; } } return result ; }
Check if this shape intersects with the shape provided .
37,934
public boolean hasVertex ( float x , float y ) { if ( points . length == 0 ) { return false ; } checkPoints ( ) ; for ( int i = 0 ; i < points . length ; i += 2 ) { if ( ( points [ i ] == x ) && ( points [ i + 1 ] == y ) ) { return true ; } } return false ; }
Check if a particular location is a vertex of this polygon
37,935
protected void findCenter ( ) { center = new float [ ] { 0 , 0 } ; int length = points . length ; for ( int i = 0 ; i < length ; i += 2 ) { center [ 0 ] += points [ i ] ; center [ 1 ] += points [ i + 1 ] ; } center [ 0 ] /= ( length / 2 ) ; center [ 1 ] /= ( length / 2 ) ; }
Get the center of this polygon .
37,936
protected void calculateRadius ( ) { boundingCircleRadius = 0 ; for ( int i = 0 ; i < points . length ; i += 2 ) { float temp = ( ( points [ i ] - center [ 0 ] ) * ( points [ i ] - center [ 0 ] ) ) + ( ( points [ i + 1 ] - center [ 1 ] ) * ( points [ i + 1 ] - center [ 1 ] ) ) ; boundingCircleRadius = ( boundingCircleRadius > temp ) ? boundingCircleRadius : temp ; } boundingCircleRadius = ( float ) Math . sqrt ( boundingCircleRadius ) ; }
Calculate the radius of a circle that can completely enclose this shape .
37,937
protected void calculateTriangles ( ) { if ( ( ! trianglesDirty ) && ( tris != null ) ) { return ; } if ( points . length >= 6 ) { boolean clockwise = true ; float area = 0 ; for ( int i = 0 ; i < ( points . length / 2 ) - 1 ; i ++ ) { float x1 = points [ ( i * 2 ) ] ; float y1 = points [ ( i * 2 ) + 1 ] ; float x2 = points [ ( i * 2 ) + 2 ] ; float y2 = points [ ( i * 2 ) + 3 ] ; area += ( x1 * y2 ) - ( y1 * x2 ) ; } area /= 2 ; clockwise = area > 0 ; tris = new NeatTriangulator ( ) ; for ( int i = 0 ; i < points . length ; i += 2 ) { tris . addPolyPoint ( points [ i ] , points [ i + 1 ] ) ; } tris . triangulate ( ) ; } trianglesDirty = false ; }
Calculate the triangles that can fill this shape
37,938
protected final void checkPoints ( ) { if ( pointsDirty ) { createPoints ( ) ; findCenter ( ) ; calculateRadius ( ) ; if ( points . length > 0 ) { maxX = points [ 0 ] ; maxY = points [ 1 ] ; minX = points [ 0 ] ; minY = points [ 1 ] ; for ( int i = 0 ; i < points . length / 2 ; i ++ ) { maxX = Math . max ( points [ i * 2 ] , maxX ) ; maxY = Math . max ( points [ ( i * 2 ) + 1 ] , maxY ) ; minX = Math . min ( points [ i * 2 ] , minX ) ; minY = Math . min ( points [ ( i * 2 ) + 1 ] , minY ) ; } } pointsDirty = false ; trianglesDirty = true ; } }
Check the dirty flag and create points as necessary .
37,939
public Shape prune ( ) { Polygon result = new Polygon ( ) ; for ( int i = 0 ; i < getPointCount ( ) ; i ++ ) { int next = i + 1 >= getPointCount ( ) ? 0 : i + 1 ; int prev = i - 1 < 0 ? getPointCount ( ) - 1 : i - 1 ; float dx1 = getPoint ( i ) [ 0 ] - getPoint ( prev ) [ 0 ] ; float dy1 = getPoint ( i ) [ 1 ] - getPoint ( prev ) [ 1 ] ; float dx2 = getPoint ( next ) [ 0 ] - getPoint ( i ) [ 0 ] ; float dy2 = getPoint ( next ) [ 1 ] - getPoint ( i ) [ 1 ] ; float len1 = ( float ) Math . sqrt ( ( dx1 * dx1 ) + ( dy1 * dy1 ) ) ; float len2 = ( float ) Math . sqrt ( ( dx2 * dx2 ) + ( dy2 * dy2 ) ) ; dx1 /= len1 ; dy1 /= len1 ; dx2 /= len2 ; dy2 /= len2 ; if ( ( dx1 != dx2 ) || ( dy1 != dy2 ) ) { result . addPoint ( getPoint ( i ) [ 0 ] , getPoint ( i ) [ 1 ] ) ; } } return result ; }
Prune any required points in this shape
37,940
public void setImageColor ( float r , float g , float b ) { setColor ( TOP_LEFT , r , g , b ) ; setColor ( TOP_RIGHT , r , g , b ) ; setColor ( BOTTOM_LEFT , r , g , b ) ; setColor ( BOTTOM_RIGHT , r , g , b ) ; }
Set the filter to apply when drawing this image
37,941
public void setColor ( int corner , float r , float g , float b , float a ) { if ( corners == null ) { corners = new Color [ ] { new Color ( 1 , 1 , 1 , 1f ) , new Color ( 1 , 1 , 1 , 1f ) , new Color ( 1 , 1 , 1 , 1f ) , new Color ( 1 , 1 , 1 , 1f ) } ; } corners [ corner ] . r = r ; corners [ corner ] . g = g ; corners [ corner ] . b = b ; corners [ corner ] . a = a ; }
Set the color of the given corner when this image is rendered . This is useful lots of visual effect but especially light maps
37,942
public void clampTexture ( ) { if ( GL . canTextureMirrorClamp ( ) ) { GL . glTexParameteri ( SGL . GL_TEXTURE_2D , SGL . GL_TEXTURE_WRAP_S , SGL . GL_MIRROR_CLAMP_TO_EDGE_EXT ) ; GL . glTexParameteri ( SGL . GL_TEXTURE_2D , SGL . GL_TEXTURE_WRAP_T , SGL . GL_MIRROR_CLAMP_TO_EDGE_EXT ) ; } else { GL . glTexParameteri ( SGL . GL_TEXTURE_2D , SGL . GL_TEXTURE_WRAP_S , SGL . GL_CLAMP ) ; GL . glTexParameteri ( SGL . GL_TEXTURE_2D , SGL . GL_TEXTURE_WRAP_T , SGL . GL_CLAMP ) ; } }
Clamp the loaded texture to it s edges
37,943
private void load ( InputStream in , String ref , boolean flipped , int f , Color transparent ) throws SlickException { this . filter = f == FILTER_LINEAR ? SGL . GL_LINEAR : SGL . GL_NEAREST ; try { this . ref = ref ; int [ ] trans = null ; if ( transparent != null ) { trans = new int [ 3 ] ; trans [ 0 ] = ( int ) ( transparent . r * 255 ) ; trans [ 1 ] = ( int ) ( transparent . g * 255 ) ; trans [ 2 ] = ( int ) ( transparent . b * 255 ) ; } texture = InternalTextureLoader . get ( ) . getTexture ( in , ref , flipped , filter , trans ) ; } catch ( IOException e ) { Log . error ( e ) ; throw new SlickException ( "Failed to load image from: " + ref , e ) ; } }
Load the image
37,944
protected final void init ( ) { if ( inited ) { return ; } inited = true ; if ( texture != null ) { width = texture . getImageWidth ( ) ; height = texture . getImageHeight ( ) ; textureOffsetX = 0 ; textureOffsetY = 0 ; textureWidth = texture . getWidth ( ) ; textureHeight = texture . getHeight ( ) ; } initImpl ( ) ; centerX = width / 2 ; centerY = height / 2 ; }
Initialise internal data
37,945
public void draw ( float x , float y ) { init ( ) ; draw ( x , y , width , height ) ; }
Draw this image at the specified location
37,946
public void drawEmbedded ( float x , float y , float width , float height ) { init ( ) ; if ( corners == null ) { GL . glTexCoord2f ( textureOffsetX , textureOffsetY ) ; GL . glVertex3f ( x , y , 0 ) ; GL . glTexCoord2f ( textureOffsetX , textureOffsetY + textureHeight ) ; GL . glVertex3f ( x , y + height , 0 ) ; GL . glTexCoord2f ( textureOffsetX + textureWidth , textureOffsetY + textureHeight ) ; GL . glVertex3f ( x + width , y + height , 0 ) ; GL . glTexCoord2f ( textureOffsetX + textureWidth , textureOffsetY ) ; GL . glVertex3f ( x + width , y , 0 ) ; } else { corners [ TOP_LEFT ] . bind ( ) ; GL . glTexCoord2f ( textureOffsetX , textureOffsetY ) ; GL . glVertex3f ( x , y , 0 ) ; corners [ BOTTOM_LEFT ] . bind ( ) ; GL . glTexCoord2f ( textureOffsetX , textureOffsetY + textureHeight ) ; GL . glVertex3f ( x , y + height , 0 ) ; corners [ BOTTOM_RIGHT ] . bind ( ) ; GL . glTexCoord2f ( textureOffsetX + textureWidth , textureOffsetY + textureHeight ) ; GL . glVertex3f ( x + width , y + height , 0 ) ; corners [ TOP_RIGHT ] . bind ( ) ; GL . glTexCoord2f ( textureOffsetX + textureWidth , textureOffsetY ) ; GL . glVertex3f ( x + width , y , 0 ) ; } }
Draw this image as part of a collection of images
37,947
public void draw ( float x , float y , float scale ) { init ( ) ; draw ( x , y , width * scale , height * scale , Color . white ) ; }
Draw the image with a given scale
37,948
public Image getSubImage ( int x , int y , int width , int height ) { init ( ) ; float newTextureOffsetX = ( ( x / ( float ) this . width ) * textureWidth ) + textureOffsetX ; float newTextureOffsetY = ( ( y / ( float ) this . height ) * textureHeight ) + textureOffsetY ; float newTextureWidth = ( ( width / ( float ) this . width ) * textureWidth ) ; float newTextureHeight = ( ( height / ( float ) this . height ) * textureHeight ) ; Image sub = new Image ( ) ; sub . inited = true ; sub . texture = this . texture ; sub . textureOffsetX = newTextureOffsetX ; sub . textureOffsetY = newTextureOffsetY ; sub . textureWidth = newTextureWidth ; sub . textureHeight = newTextureHeight ; sub . width = width ; sub . height = height ; sub . ref = ref ; sub . centerX = width / 2 ; sub . centerY = height / 2 ; return sub ; }
Get a sub - part of this image . Note that the create image retains a reference to the image data so should anything change it will affect sub - images too .
37,949
public void drawWarped ( float x1 , float y1 , float x2 , float y2 , float x3 , float y3 , float x4 , float y4 ) { Color . white . bind ( ) ; texture . bind ( ) ; GL . glTranslatef ( x1 , y1 , 0 ) ; if ( angle != 0 ) { GL . glTranslatef ( centerX , centerY , 0.0f ) ; GL . glRotatef ( angle , 0.0f , 0.0f , 1.0f ) ; GL . glTranslatef ( - centerX , - centerY , 0.0f ) ; } GL . glBegin ( SGL . GL_QUADS ) ; init ( ) ; GL . glTexCoord2f ( textureOffsetX , textureOffsetY ) ; GL . glVertex3f ( 0 , 0 , 0 ) ; GL . glTexCoord2f ( textureOffsetX , textureOffsetY + textureHeight ) ; GL . glVertex3f ( x2 - x1 , y2 - y1 , 0 ) ; GL . glTexCoord2f ( textureOffsetX + textureWidth , textureOffsetY + textureHeight ) ; GL . glVertex3f ( x3 - x1 , y3 - y1 , 0 ) ; GL . glTexCoord2f ( textureOffsetX + textureWidth , textureOffsetY ) ; GL . glVertex3f ( x4 - x1 , y4 - y1 , 0 ) ; GL . glEnd ( ) ; if ( angle != 0 ) { GL . glTranslatef ( centerX , centerY , 0.0f ) ; GL . glRotatef ( - angle , 0.0f , 0.0f , 1.0f ) ; GL . glTranslatef ( - centerX , - centerY , 0.0f ) ; } GL . glTranslatef ( - x1 , - y1 , 0 ) ; }
Draw the image in a warper rectangle . The effects this can have are many and varied might be interesting though .
37,950
public Image getFlippedCopy ( boolean flipHorizontal , boolean flipVertical ) { init ( ) ; Image image = copy ( ) ; if ( flipHorizontal ) { image . textureOffsetX = textureOffsetX + textureWidth ; image . textureWidth = - textureWidth ; } if ( flipVertical ) { image . textureOffsetY = textureOffsetY + textureHeight ; image . textureHeight = - textureHeight ; } return image ; }
Get a copy image flipped on potentially two axis
37,951
public Color getColor ( int x , int y ) { if ( pixelData == null ) { pixelData = texture . getTextureData ( ) ; } int xo = ( int ) ( textureOffsetX * texture . getTextureWidth ( ) ) ; int yo = ( int ) ( textureOffsetY * texture . getTextureHeight ( ) ) ; if ( textureWidth < 0 ) { x = xo - x ; } else { x = xo + x ; } if ( textureHeight < 0 ) { y = yo - y ; } else { y = yo + y ; } x %= texture . getTextureWidth ( ) ; y %= texture . getTextureHeight ( ) ; int offset = x + ( y * texture . getTextureWidth ( ) ) ; offset *= texture . hasAlpha ( ) ? 4 : 3 ; if ( texture . hasAlpha ( ) ) { return new Color ( translate ( pixelData [ offset ] ) , translate ( pixelData [ offset + 1 ] ) , translate ( pixelData [ offset + 2 ] ) , translate ( pixelData [ offset + 3 ] ) ) ; } else { return new Color ( translate ( pixelData [ offset ] ) , translate ( pixelData [ offset + 1 ] ) , translate ( pixelData [ offset + 2 ] ) ) ; } }
Get the colour of a pixel at a specified location in this image
37,952
public static void drawLeft ( Font font , String s , int x , int y ) { drawString ( font , s , Alignment . LEFT , x , y , 0 , Color . white ) ; }
Draw text left justified
37,953
public static void drawCenter ( Font font , String s , int x , int y , int width ) { drawString ( font , s , Alignment . CENTER , x , y , width , Color . white ) ; }
Draw text center justified
37,954
public static void drawRight ( Font font , String s , int x , int y , int width ) { drawString ( font , s , Alignment . RIGHT , x , y , width , Color . white ) ; }
Draw text right justified
37,955
public void load ( ) { int resp = loadChooser . showOpenDialog ( this ) ; if ( resp == JFileChooser . APPROVE_OPTION ) { lastSelected = loadChooser . getSelectedFile ( ) ; saveChooser . setCurrentDirectory ( loadChooser . getCurrentDirectory ( ) ) ; try { BufferedImage image = ImageIO . read ( lastSelected ) ; imagePanel . setImage ( image ) ; } catch ( Exception e ) { e . printStackTrace ( ) ; JOptionPane . showMessageDialog ( this , "Unable to load image " + lastSelected . getName ( ) + " " ) ; } } }
Load the current image
37,956
public void save ( ) { int resp = saveChooser . showSaveDialog ( this ) ; if ( resp == JFileChooser . APPROVE_OPTION ) { File file = saveChooser . getSelectedFile ( ) ; String type = null ; if ( file . getName ( ) . endsWith ( ".png" ) ) { type = "PNG" ; } if ( file . getName ( ) . endsWith ( ".gif" ) ) { type = "GIF" ; } if ( file . getName ( ) . endsWith ( ".jpg" ) ) { type = "JPG" ; } if ( type == null ) { file = new File ( file . getAbsolutePath ( ) + ".png" ) ; type = "PNG" ; } try { ImageIO . write ( imagePanel . getImage ( ) , type , file ) ; } catch ( Exception e ) { e . printStackTrace ( ) ; JOptionPane . showMessageDialog ( this , "Unable to save file " + file . getName ( ) ) ; } } }
Save the current image
37,957
public String [ ] getAttributeNames ( ) { NamedNodeMap map = dom . getAttributes ( ) ; String [ ] names = new String [ map . getLength ( ) ] ; for ( int i = 0 ; i < names . length ; i ++ ) { names [ i ] = map . item ( i ) . getNodeName ( ) ; } return names ; }
Get the names of the attributes specified on this element
37,958
public String getAttribute ( String name , String def ) { String value = dom . getAttribute ( name ) ; if ( ( value == null ) || ( value . length ( ) == 0 ) ) { return def ; } return value ; }
Get the value specified for a given attribute on this element
37,959
public int getIntAttribute ( String name ) throws SlickXMLException { try { return Integer . parseInt ( getAttribute ( name ) ) ; } catch ( NumberFormatException e ) { throw new SlickXMLException ( "Value read: '" + getAttribute ( name ) + "' is not an integer" , e ) ; } }
Get the value specified for a given attribute on this element as an integer .
37,960
public double getDoubleAttribute ( String name ) throws SlickXMLException { try { return Double . parseDouble ( getAttribute ( name ) ) ; } catch ( NumberFormatException e ) { throw new SlickXMLException ( "Value read: '" + getAttribute ( name ) + "' is not a double" , e ) ; } }
Get the value specified for a given attribute on this element as an double .
37,961
public boolean getBooleanAttribute ( String name ) throws SlickXMLException { String value = getAttribute ( name ) ; if ( value . equalsIgnoreCase ( "true" ) ) { return true ; } if ( value . equalsIgnoreCase ( "false" ) ) { return false ; } throw new SlickXMLException ( "Value read: '" + getAttribute ( name ) + "' is not a boolean" ) ; }
Get the value specified for a given attribute on this element as a boolean .
37,962
public String getContent ( ) { String content = "" ; NodeList list = dom . getChildNodes ( ) ; for ( int i = 0 ; i < list . getLength ( ) ; i ++ ) { if ( list . item ( i ) instanceof Text ) { content += ( list . item ( i ) . getNodeValue ( ) ) ; } } return content ; }
Get the text content of the element i . e . the bit between the tags
37,963
public XMLElementList getChildren ( ) { if ( children != null ) { return children ; } NodeList list = dom . getChildNodes ( ) ; children = new XMLElementList ( ) ; for ( int i = 0 ; i < list . getLength ( ) ; i ++ ) { if ( list . item ( i ) instanceof Element ) { children . add ( new XMLElement ( ( Element ) list . item ( i ) ) ) ; } } return children ; }
Get the complete list of children for this node
37,964
public XMLElementList getChildrenByName ( String name ) { XMLElementList selected = new XMLElementList ( ) ; XMLElementList children = getChildren ( ) ; for ( int i = 0 ; i < children . size ( ) ; i ++ ) { if ( children . get ( i ) . getName ( ) . equals ( name ) ) { selected . add ( children . get ( i ) ) ; } } return selected ; }
Get a list of children with a given element name
37,965
protected void createPoints ( ) { ArrayList tempPoints = new ArrayList ( ) ; maxX = - Float . MIN_VALUE ; maxY = - Float . MIN_VALUE ; minX = Float . MAX_VALUE ; minY = Float . MAX_VALUE ; float start = 0 ; float end = 359 ; float cx = x + radius1 ; float cy = y + radius2 ; int step = 360 / segmentCount ; for ( float a = start ; a <= end + step ; a += step ) { float ang = a ; if ( ang > end ) { ang = end ; } float newX = ( float ) ( cx + ( FastTrig . cos ( Math . toRadians ( ang ) ) * radius1 ) ) ; float newY = ( float ) ( cy + ( FastTrig . sin ( Math . toRadians ( ang ) ) * radius2 ) ) ; if ( newX > maxX ) { maxX = newX ; } if ( newY > maxY ) { maxY = newY ; } if ( newX < minX ) { minX = newX ; } if ( newY < minY ) { minY = newY ; } tempPoints . add ( new Float ( newX ) ) ; tempPoints . add ( new Float ( newY ) ) ; } points = new float [ tempPoints . size ( ) ] ; for ( int i = 0 ; i < points . length ; i ++ ) { points [ i ] = ( ( Float ) tempPoints . get ( i ) ) . floatValue ( ) ; } }
Generate the points to outline this ellipse .
37,966
public Space findSpace ( float x , float y ) { for ( int i = 0 ; i < spaces . size ( ) ; i ++ ) { Space space = getSpace ( i ) ; if ( space . contains ( x , y ) ) { return space ; } } return null ; }
Find the space at a given location
37,967
public NavPath findPath ( float sx , float sy , float tx , float ty , boolean optimize ) { Space source = findSpace ( sx , sy ) ; Space target = findSpace ( tx , ty ) ; if ( ( source == null ) || ( target == null ) ) { return null ; } for ( int i = 0 ; i < spaces . size ( ) ; i ++ ) { ( ( Space ) spaces . get ( i ) ) . clearCost ( ) ; } target . fill ( source , tx , ty , 0 ) ; if ( target . getCost ( ) == Float . MAX_VALUE ) { return null ; } if ( source . getCost ( ) == Float . MAX_VALUE ) { return null ; } NavPath path = new NavPath ( ) ; path . push ( new Link ( sx , sy , null ) ) ; if ( source . pickLowestCost ( target , path ) ) { path . push ( new Link ( tx , ty , null ) ) ; if ( optimize ) { optimize ( path ) ; } return path ; } return null ; }
Find a path from the source to the target coordinates
37,968
private boolean isClear ( float x1 , float y1 , float x2 , float y2 , float step ) { float dx = ( x2 - x1 ) ; float dy = ( y2 - y1 ) ; float len = ( float ) Math . sqrt ( ( dx * dx ) + ( dy * dy ) ) ; dx *= step ; dx /= len ; dy *= step ; dy /= len ; int steps = ( int ) ( len / step ) ; for ( int i = 0 ; i < steps ; i ++ ) { float x = x1 + ( dx * i ) ; float y = y1 + ( dy * i ) ; if ( findSpace ( x , y ) == null ) { return false ; } } return true ; }
Check if a particular path is clear
37,969
private void optimize ( NavPath path ) { int pt = 0 ; while ( pt < path . length ( ) - 2 ) { float sx = path . getX ( pt ) ; float sy = path . getY ( pt ) ; float nx = path . getX ( pt + 2 ) ; float ny = path . getY ( pt + 2 ) ; if ( isClear ( sx , sy , nx , ny , 0.1f ) ) { path . remove ( pt + 1 ) ; } else { pt ++ ; } } }
Optimize a path by removing segments that arn t required to reach the end point
37,970
public static double sin ( double radians ) { radians = reduceSinAngle ( radians ) ; if ( Math . abs ( radians ) <= Math . PI / 4 ) { return Math . sin ( radians ) ; } else { return Math . cos ( Math . PI / 2 - radians ) ; } }
Get the sine of an angle
37,971
private boolean tryMove ( float x , float y ) { float newx = playerX + x ; float newy = playerY + y ; if ( blocked ( newx , newy ) ) { if ( blocked ( newx , playerY ) ) { if ( blocked ( playerX , newy ) ) { return false ; } else { playerY = newy ; return true ; } } else { playerX = newx ; return true ; } } else { playerX = newx ; playerY = newy ; return true ; } }
Try to move in the direction specified . If it s blocked try sliding . If that doesn t work just don t bother
37,972
private void updateMovementVector ( ) { dirX = ( float ) Math . sin ( Math . toRadians ( ang ) ) ; dirY = ( float ) - Math . cos ( Math . toRadians ( ang ) ) ; }
Update the direction that will be moved in based on the current angle of rotation
37,973
public void drawTank ( Graphics g , float xpos , float ypos , float rot ) { int cx = ( int ) ( xpos * 32 ) ; int cy = ( int ) ( ypos * 32 ) ; g . rotate ( cx , cy , rot ) ; player . draw ( cx - 16 , cy - 16 ) ; g . rotate ( cx , cy , - rot ) ; }
Draw a single tank to the game
37,974
public static void main ( String [ ] argv ) { try { AppGameContainer container = new AppGameContainer ( new Scroller ( ) , 800 , 600 , false ) ; container . start ( ) ; } catch ( Exception e ) { e . printStackTrace ( ) ; } }
Entry point to the scroller example
37,975
private void browseForImage ( ) { if ( emitter != null ) { int resp = chooser . showOpenDialog ( this ) ; if ( resp == JFileChooser . APPROVE_OPTION ) { File file = chooser . getSelectedFile ( ) ; String path = file . getParentFile ( ) . getAbsolutePath ( ) ; String name = file . getName ( ) ; ConfigurableEmitter . setRelativePath ( path ) ; emitter . setImageName ( name ) ; imageName . setText ( name ) ; } } }
Browse for a particle image and set the value into both the emitter and text field on successful completion
37,976
public static final int getMaxSingleImageSize ( ) { IntBuffer buffer = BufferUtils . createIntBuffer ( 16 ) ; GL . glGetInteger ( SGL . GL_MAX_TEXTURE_SIZE , buffer ) ; return buffer . get ( 0 ) ; }
Get the maximum size of an image supported by the underlying hardware .
37,977
private void build ( String ref , int filter , int tileSize ) throws SlickException { try { final LoadableImageData data = ImageDataFactory . getImageDataFor ( ref ) ; final ByteBuffer imageBuffer = data . loadImage ( ResourceLoader . getResourceAsStream ( ref ) , false , null ) ; build ( data , imageBuffer , filter , tileSize ) ; } catch ( IOException e ) { throw new SlickException ( "Failed to load: " + ref , e ) ; } }
Create a new big image by loading it from the specified reference
37,978
public void destroy ( ) throws SlickException { for ( int tx = 0 ; tx < xcount ; tx ++ ) { for ( int ty = 0 ; ty < ycount ; ty ++ ) { Image image = images [ tx ] [ ty ] ; image . destroy ( ) ; } } }
Destroy the image and release any native resources . Calls on a destroyed image have undefined results
37,979
private void copyArea ( BufferedImage image , int x , int y , int width , int height , int dx , int dy ) { Graphics2D g = ( Graphics2D ) image . getGraphics ( ) ; g . drawImage ( image . getSubimage ( x , y , width , height ) , x + dx , y + dy , null ) ; }
Implement of transform copy area for 1 . 4
37,980
public static Texture getTexture ( String resourceName , BufferedImage resourceImage ) throws IOException { Texture tex = getTexture ( resourceName , resourceImage , SGL . GL_TEXTURE_2D , SGL . GL_RGBA8 , SGL . GL_LINEAR , SGL . GL_LINEAR ) ; return tex ; }
Load a texture
37,981
public static Texture getTexture ( String resourceName , BufferedImage resourceimage , int target , int dstPixelFormat , int minFilter , int magFilter ) throws IOException { ImageIOImageData data = new ImageIOImageData ( ) ; int srcPixelFormat = 0 ; int textureID = InternalTextureLoader . createTextureID ( ) ; TextureImpl texture = new TextureImpl ( resourceName , target , textureID ) ; Renderer . get ( ) . glEnable ( SGL . GL_TEXTURE_2D ) ; Renderer . get ( ) . glBindTexture ( target , textureID ) ; BufferedImage bufferedImage = resourceimage ; texture . setWidth ( bufferedImage . getWidth ( ) ) ; texture . setHeight ( bufferedImage . getHeight ( ) ) ; if ( bufferedImage . getColorModel ( ) . hasAlpha ( ) ) { srcPixelFormat = SGL . GL_RGBA ; } else { srcPixelFormat = SGL . GL_RGB ; } ByteBuffer textureBuffer = data . imageToByteBuffer ( bufferedImage , false , false , null ) ; texture . setTextureHeight ( data . getTexHeight ( ) ) ; texture . setTextureWidth ( data . getTexWidth ( ) ) ; texture . setAlpha ( data . getDepth ( ) == 32 ) ; if ( target == SGL . GL_TEXTURE_2D ) { Renderer . get ( ) . glTexParameteri ( target , SGL . GL_TEXTURE_MIN_FILTER , minFilter ) ; Renderer . get ( ) . glTexParameteri ( target , SGL . GL_TEXTURE_MAG_FILTER , magFilter ) ; if ( Renderer . get ( ) . canTextureMirrorClamp ( ) ) { Renderer . get ( ) . glTexParameteri ( SGL . GL_TEXTURE_2D , SGL . GL_TEXTURE_WRAP_S , SGL . GL_MIRROR_CLAMP_TO_EDGE_EXT ) ; Renderer . get ( ) . glTexParameteri ( SGL . GL_TEXTURE_2D , SGL . GL_TEXTURE_WRAP_T , SGL . GL_MIRROR_CLAMP_TO_EDGE_EXT ) ; } else { Renderer . get ( ) . glTexParameteri ( SGL . GL_TEXTURE_2D , SGL . GL_TEXTURE_WRAP_S , SGL . GL_CLAMP ) ; Renderer . get ( ) . glTexParameteri ( SGL . GL_TEXTURE_2D , SGL . GL_TEXTURE_WRAP_T , SGL . GL_CLAMP ) ; } } Renderer . get ( ) . glTexImage2D ( target , 0 , dstPixelFormat , texture . getTextureWidth ( ) , texture . getTextureHeight ( ) , 0 , srcPixelFormat , SGL . GL_UNSIGNED_BYTE , textureBuffer ) ; return texture ; }
Load a texture into OpenGL from a BufferedImage
37,982
static public BufferedImage getScratchImage ( ) { Graphics2D g = ( Graphics2D ) scratchImage . getGraphics ( ) ; g . setComposite ( AlphaComposite . Clear ) ; g . fillRect ( 0 , 0 , GlyphPage . MAX_GLYPH_SIZE , GlyphPage . MAX_GLYPH_SIZE ) ; g . setComposite ( AlphaComposite . SrcOver ) ; g . setColor ( java . awt . Color . white ) ; return scratchImage ; }
Returns an image that can be used by effects as a temp image .
37,983
static public Value colorValue ( String name , Color currentValue ) { return new DefaultValue ( name , EffectUtil . toString ( currentValue ) ) { public void showDialog ( ) { Color newColor = JColorChooser . showDialog ( null , "Choose a color" , EffectUtil . fromString ( value ) ) ; if ( newColor != null ) value = EffectUtil . toString ( newColor ) ; } public Object getObject ( ) { return EffectUtil . fromString ( value ) ; } } ; }
Prompts the user for a colour value
37,984
static public Value intValue ( String name , final int currentValue , final String description ) { return new DefaultValue ( name , String . valueOf ( currentValue ) ) { public void showDialog ( ) { JSpinner spinner = new JSpinner ( new SpinnerNumberModel ( currentValue , Short . MIN_VALUE , Short . MAX_VALUE , 1 ) ) ; if ( showValueDialog ( spinner , description ) ) value = String . valueOf ( spinner . getValue ( ) ) ; } public Object getObject ( ) { return Integer . valueOf ( value ) ; } } ; }
Prompts the user for int value
37,985
static public Value floatValue ( String name , final float currentValue , final float min , final float max , final String description ) { return new DefaultValue ( name , String . valueOf ( currentValue ) ) { public void showDialog ( ) { JSpinner spinner = new JSpinner ( new SpinnerNumberModel ( currentValue , min , max , 0.1f ) ) ; if ( showValueDialog ( spinner , description ) ) value = String . valueOf ( ( ( Double ) spinner . getValue ( ) ) . floatValue ( ) ) ; } public Object getObject ( ) { return Float . valueOf ( value ) ; } } ; }
Prompts the user for float value
37,986
static public Value booleanValue ( String name , final boolean currentValue , final String description ) { return new DefaultValue ( name , String . valueOf ( currentValue ) ) { public void showDialog ( ) { JCheckBox checkBox = new JCheckBox ( ) ; checkBox . setSelected ( currentValue ) ; if ( showValueDialog ( checkBox , description ) ) value = String . valueOf ( checkBox . isSelected ( ) ) ; } public Object getObject ( ) { return Boolean . valueOf ( value ) ; } } ; }
Prompts the user for boolean value
37,987
static public Value optionValue ( String name , final String currentValue , final String [ ] [ ] options , final String description ) { return new DefaultValue ( name , currentValue . toString ( ) ) { public void showDialog ( ) { int selectedIndex = - 1 ; DefaultComboBoxModel model = new DefaultComboBoxModel ( ) ; for ( int i = 0 ; i < options . length ; i ++ ) { model . addElement ( options [ i ] [ 0 ] ) ; if ( getValue ( i ) . equals ( currentValue ) ) selectedIndex = i ; } JComboBox comboBox = new JComboBox ( model ) ; comboBox . setSelectedIndex ( selectedIndex ) ; if ( showValueDialog ( comboBox , description ) ) value = getValue ( comboBox . getSelectedIndex ( ) ) ; } private String getValue ( int i ) { if ( options [ i ] . length == 1 ) return options [ i ] [ 0 ] ; return options [ i ] [ 1 ] ; } public String toString ( ) { for ( int i = 0 ; i < options . length ; i ++ ) if ( getValue ( i ) . equals ( value ) ) return options [ i ] [ 0 ] . toString ( ) ; return "" ; } public Object getObject ( ) { return value ; } } ; }
Prompts the user for a value that represents a fixed number of options . All options are strings .
37,988
static public Color fromString ( String rgb ) { if ( rgb == null || rgb . length ( ) != 6 ) return Color . white ; return new Color ( Integer . parseInt ( rgb . substring ( 0 , 2 ) , 16 ) , Integer . parseInt ( rgb . substring ( 2 , 4 ) , 16 ) , Integer . parseInt ( rgb . substring ( 4 , 6 ) , 16 ) ) ; }
Converts a string to a color .
37,989
private void addKeyListenerImpl ( KeyListener listener ) { if ( keyListeners . contains ( listener ) ) { return ; } keyListeners . add ( listener ) ; allListeners . add ( listener ) ; }
Add a key listener to be notified of key input events
37,990
private void addMouseListenerImpl ( MouseListener listener ) { if ( mouseListeners . contains ( listener ) ) { return ; } mouseListeners . add ( listener ) ; allListeners . add ( listener ) ; }
Add a mouse listener to be notified of mouse input events
37,991
public void addControllerListener ( ControllerListener listener ) { if ( controllerListeners . contains ( listener ) ) { return ; } controllerListeners . add ( listener ) ; allListeners . add ( listener ) ; }
Add a controller listener to be notified of controller input events
37,992
public void addPrimaryListener ( InputListener listener ) { removeListener ( listener ) ; keyListeners . add ( 0 , listener ) ; mouseListeners . add ( 0 , listener ) ; controllerListeners . add ( 0 , listener ) ; allListeners . add ( listener ) ; }
Add a listener to be notified of input events . This listener will get events before others that are currently registered
37,993
public void removeKeyListener ( KeyListener listener ) { keyListeners . remove ( listener ) ; keyListenersToAdd . remove ( listener ) ; if ( ! mouseListeners . contains ( listener ) && ! controllerListeners . contains ( listener ) ) { allListeners . remove ( listener ) ; } }
Remove a key listener that will no longer be notified
37,994
public void removeControllerListener ( ControllerListener listener ) { controllerListeners . remove ( listener ) ; if ( ! mouseListeners . contains ( listener ) && ! keyListeners . contains ( listener ) ) { allListeners . remove ( listener ) ; } }
Remove a controller listener that will no longer be notified
37,995
public void removeMouseListener ( MouseListener listener ) { mouseListeners . remove ( listener ) ; mouseListenersToAdd . remove ( listener ) ; if ( ! controllerListeners . contains ( listener ) && ! keyListeners . contains ( listener ) ) { allListeners . remove ( listener ) ; } }
Remove a mouse listener that will no longer be notified
37,996
public boolean isControlPressed ( int button , int controller ) { if ( controllerPressed [ controller ] [ button ] ) { controllerPressed [ controller ] [ button ] = false ; return true ; } return false ; }
Check if a controller button has been pressed since last time
37,997
public void clearControlPressedRecord ( ) { for ( int i = 0 ; i < controllers . size ( ) ; i ++ ) { Arrays . fill ( controllerPressed [ i ] , false ) ; } }
Clear the state for isControlPressed method . This will reset all controls to not pressed
37,998
public String getAxisName ( int controller , int axis ) { return ( ( Controller ) controllers . get ( controller ) ) . getAxisName ( axis ) ; }
Get the name of the axis with the given index
37,999
public boolean isControllerLeft ( int controller ) { if ( controller >= getControllerCount ( ) ) { return false ; } if ( controller == ANY_CONTROLLER ) { for ( int i = 0 ; i < controllers . size ( ) ; i ++ ) { if ( isControllerLeft ( i ) ) { return true ; } } return false ; } return ( ( Controller ) controllers . get ( controller ) ) . getXAxisValue ( ) < - 0.5f || ( ( Controller ) controllers . get ( controller ) ) . getPovX ( ) < - 0.5f ; }
Check if the controller has the left direction pressed