Package ch.epfl.cs107.play.window
Interface Canvas
- All Superinterfaces:
Positionable
- All Known Subinterfaces:
Window
- All Known Implementing Classes:
SwingWindow
Represents a rendering context, with various drawing capabilities.
-
Method Summary
Modifier and TypeMethodDescriptionconvertPositionOnScreen(Vector coord) Convert a coordinate in the canvas to a coordinate in the screenvoidDraws 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.intReturn the canvas heightgetImage(String name, RegionOfInterest roi, boolean removeBackground) Gets image from file system.floatReturn the canvas scaled height after adjusting to ratiofloatReturn the canvas scaled width after adjusting to ratiointgetWidth()Return the canvas widthfloatReturn the canvas scaled widthfloatReturn the canvas scaled heightvoidregisterFonts(String directoryName) Register all the font in a directoryMethods inherited from interface ch.epfl.cs107.play.math.Positionable
getPosition, getTransform, getVelocity
-
Method Details
-
getImage
Gets image from file system.- Parameters:
name- (String): full name of image, not nullroi- (RegionOfInterest): region of interestremoveBackground- (boolean): which indicate if we need to remove an uniform background- Returns:
- an image object, null on error
-
drawImage
Draws specified image.- 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
void drawShape(Shape shape, Transform transform, Color fillColor, Color outlineColor, float thickness, float alpha, float depth) Draws specified image- 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
Register all the font in a directory- Parameters:
directoryName- (String): the name of the directory
-
drawText
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) Creates a new text graphics.- 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
-
convertPositionOnScreen
Convert a coordinate in the canvas to a coordinate in the screen- Parameters:
coord- the coordinate in the canvas- Returns:
- the coordinate in the screen
-
getWidth
int getWidth()Return the canvas width- Returns:
- width (int): the canvas width
-
getHeight
int getHeight()Return the canvas height- Returns:
- height (int): the canvas height
-
getXScale
float getXScale()Return the canvas scaled width- Returns:
- width (float): the canvas scaled width
-
getYScale
float getYScale()Return the canvas scaled height- Returns:
- height (float): the canvas scaled height
-
getScaledWidth
float getScaledWidth()Return the canvas scaled width after adjusting to ratio- Returns:
- width (float): the canvas scaled width
-
getScaledHeight
float getScaledHeight()Return the canvas scaled height after adjusting to ratio- Returns:
- height (float): the canvas scaled height
-