Package ch.epfl.cs107.play.window.swing
Class SwingWindow
java.lang.Object
ch.epfl.cs107.play.math.Node
ch.epfl.cs107.play.window.swing.SwingWindow
- All Implemented Interfaces:
Attachable,Positionable,Audio,Canvas,Window
Swing implementation of window context.
-
Constructor Summary
ConstructorsConstructorDescriptionSwingWindow(String title, FileSystem fileSystem, int width, int height) Creates a new window. -
Method Summary
Modifier and TypeMethodDescriptionconvertPositionOnScreen(Vector coord) Convert a coordinate in the canvas to a coordinate in the screenvoiddispose()Destroys and closes the windowvoidAdd specified item to current draw list.voidDraws specified image.voiddrawShape(Shape shape, Transform transform, Color fillColor, Color outlineColor, float thickness, float alpha, float depth) Draws specified imagevoiddrawText(String text, float fontSize, Transform transform, Color fillColor, Color outlineColor, float thickness, String fontName, boolean bold, boolean italics, Vector anchor, TextAlign.Horizontal hAlign, TextAlign.Vertical vAlign, float alpha, float depth) Creates a new text graphics.getFocus()intReturn the canvas heightgetImage(String name, RegionOfInterest roi, boolean removeBackground) Gets image from file system.getMouse()floatReturn the canvas scaled height after adjusting to ratiofloatReturn the canvas scaled width after adjusting to ratioGets sound from file system.intgetWidth()Return the canvas widthfloatReturn the canvas scaled widthfloatReturn the canvas scaled heightbooleanbooleanvoidplaySound(Sound sound, boolean randomFirstStart, float volume, boolean fadeIn, boolean loop, boolean stopOthersOnStart) Play specified sound.voidregisterFonts(String directoryName) Register all the font in a directoryvoidupdate()Methods inherited from class ch.epfl.cs107.play.math.Node
getParent, getPosition, getRelativeTransform, getTransform, getVelocity, setParent, setRelativeTransformMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface ch.epfl.cs107.play.math.Attachable
getParent, getRelativeTransform, setParent, setRelativeTransformMethods inherited from interface ch.epfl.cs107.play.math.Positionable
getPosition, getTransform, getVelocity
-
Constructor Details
-
SwingWindow
Creates a new window.- Parameters:
title- (String): window captionfileSystem- (FileSystem): source used to load imageswidth- (int): width in pixel of the windowheight- (int): height in pixel of the window
-
-
Method Details
-
getFocus
-
getMouse
-
getKeyboard
- Specified by:
getKeyboardin interfaceWindow- Returns:
- (Keyboard): associated keyboard controller
-
isCloseRequested
public boolean isCloseRequested()- Specified by:
isCloseRequestedin interfaceWindow- Returns:
- (boolean): whether the user tried to close the window
-
update
public void update() -
dispose
public void dispose()Description copied from interface:WindowDestroys and closes the window -
getImage
Description copied from interface:CanvasGets image from file system. -
draw
Add specified item to current draw list.- Parameters:
item- (Item) any item, not null
-
drawImage
Description copied from interface:CanvasDraws specified image.- Specified by:
drawImagein interfaceCanvas- Parameters:
image- (Image): any image associated to this context, may be nulltransform- (Transform): any affine transform, not nullalpha- (float): transparency, between 0.0 and 1.0depth- (float): any real, larger values are drawn afterward, i.e. above
-
drawShape
public void drawShape(Shape shape, Transform transform, Color fillColor, Color outlineColor, float thickness, float alpha, float depth) Description copied from interface:CanvasDraws specified image- Specified by:
drawShapein interfaceCanvas- Parameters:
shape- (Shape): any shape, may be nulltransform- (Transform): any affine transform, not nullfillColor- (Color): color used to fill the shape, may be nulloutlineColor- (Color): color used to draw shape border, may be nullthickness- (float): border thicknessalpha- (float): transparency, between 0.0 and 1.0depth- (float): any real, larger values are drawn afterward, i.e. above
-
registerFonts
Description copied from interface:CanvasRegister all the font in a directory- Specified by:
registerFontsin interfaceCanvas- Parameters:
directoryName- (String): the name of the directory
-
drawText
public void drawText(String text, float fontSize, Transform transform, Color fillColor, Color outlineColor, float thickness, String fontName, boolean bold, boolean italics, Vector anchor, TextAlign.Horizontal hAlign, TextAlign.Vertical vAlign, float alpha, float depth) Description copied from interface:CanvasCreates a new text graphics.- Specified by:
drawTextin interfaceCanvas- Parameters:
text- (String): content, not nullfontSize- (float): sizetransform- (Transform): affine transform, not nullfillColor- (Color): fill color, may be nulloutlineColor- (Color): outline color, may be nullthickness- (float): outline thicknessfontName- (String): the font namebold- (boolean): whether to use bold fontitalics- (boolean): whether to use italics fontanchor- (Vector): text anchorhAlign- (TextAlign.Horizontal): horizontal alignment of the text around the anchor vectorvAlign- (TextAlign.Vertical): vertical alignment of the text around the anchor vectoralpha- (float): transparency, between 0 (invisible) and 1 (opaque)depth- (float): render priority, lower-values drawn first
-
getSound
Description copied from interface:AudioGets sound from file system. -
playSound
public void playSound(Sound sound, boolean randomFirstStart, float volume, boolean fadeIn, boolean loop, boolean stopOthersOnStart) Description copied from interface:AudioPlay specified sound.- Specified by:
playSoundin interfaceAudio- Parameters:
sound- (Sound): any sound associated to this context, may be nullrandomFirstStart- (boolean): indicate if the first start is random in the soundvolume- (float): 0.0f no sound, 1.0f full audiofadeIn- (boolean): indicate if the song fade in until reaching its max volumeloop- (boolean): indicate if the sound must loop on self endingstopOthersOnStart- (boolean): indicate if all other sound are stopped on given sound's start
-
isSoundSupported
public boolean isSoundSupported()- Specified by:
isSoundSupportedin interfaceAudio- Returns:
- (boolean): true if the sound is supported by the Audio
-
convertPositionOnScreen
Description copied from interface:CanvasConvert a coordinate in the canvas to a coordinate in the screen- Specified by:
convertPositionOnScreenin interfaceCanvas- Parameters:
coord- the coordinate in the canvas- Returns:
- the coordinate in the screen
-
getWidth
public int getWidth()Description copied from interface:CanvasReturn the canvas width -
getHeight
public int getHeight()Description copied from interface:CanvasReturn the canvas height -
getXScale
public float getXScale()Description copied from interface:CanvasReturn the canvas scaled width -
getYScale
public float getYScale()Description copied from interface:CanvasReturn the canvas scaled height -
getScaledWidth
public float getScaledWidth()Description copied from interface:CanvasReturn the canvas scaled width after adjusting to ratio- Specified by:
getScaledWidthin interfaceCanvas- Returns:
- width (float): the canvas scaled width
-
getScaledHeight
public float getScaledHeight()Description copied from interface:CanvasReturn the canvas scaled height after adjusting to ratio- Specified by:
getScaledHeightin interfaceCanvas- Returns:
- height (float): the canvas scaled height
-