Technical Documentation (API — Window) - Software-Engineering-Spring-2020/PollyPaint GitHub Wiki

This is the main class that interfaces with the front end.

The only class accessible from the frontend is Window. All needed DrawSpace functionality is in this class. Other classes are protected and only accessible within the backend package.

Note that the x and y positions in the backend are different from the frontend. The backend uses relational fractions, and the frontend uses coordinates. See "translateCoordinates()" in the DrawSpace class for information on how positions are translated from the frontend to backend.

xo, yo, and basically any letter +o is represents translation or distance of change. Oftentimes, a function needing to be passed xo will require this.mousex-this.pmousex

Window

public class Window

Window()

Description: A constructor that creates a new Window object
Parameters: sketch, float x (x position), float y (y position), float w (width), float h (height) Returns: A Window object

display()

Description: Displays drawSpace
Parameters: none Returns: void

translate()

Description: Translates frontend coordinates to the back-end DrawSpace coordinates
Parameters: float x, float y
Returns: float[]

newToolSelection()

Description: Clears PollyGon points, curve points, and freeform points when the user clicks on a new tool.
Paramenters: None
Returns: Void

DRAWSPACE RELATED FUNCTIONALITY

createDrawSpace()

Description: Creates a new DrawSpace object
Parameters: sketch, float x (x position), float y (y position), float w (width), float h (height)
Returns: A DrawSpace object

zoom()

Description: Draws the DrawSpace off-center once zoomed
Parameters: float factor
Returns: void

withinCanvas()

Description: Determines if an x and y position is within the DrawSpace
Parameters: float x, float y
Returns: boolean

canvasPan()

Description: Pans the DrawSpace Parameters: float xo, float yo
Returns: void

reCenter()

Description: Re-centers the DrawSpace to its initial position
Parameters: None
Returns: Void

toggleGrid()

Description: Toggles grid from "on" to "off" and "off" to "on" Parameters: none Returns: void

setGridSpacing()

Description: Set the size of spacing on the grid
Parameters: float spacing
Returns: void

toggleComments()

Description: Toggles comments from "on" to "off" and "off" to "on"
Parameters: None Returns: void

OBJECT CREATION RELATED FUNCTIONALITY

createEllipse()

Description: Creates an Ellipse object. Returns boolean of if action was successful.
Parameters: float x, float y, float w, float h
Returns: boolean

createEllipse()

Description: Creates an Ellipse object. Returns boolean of if action was successful.
Parameters: float x, float y, float d
Returns: boolean

createEllipse()

Description: Creates an Ellipse object. Returns boolean of if action was successful.
Parameters: float x, float y | Defaults to 20 and 20 with and height
Returns: boolean
Note: Commented out

createRect()

Description: Creates a Rectangle object. Returns boolean of if action was successful.
Parameters: float x, float y, float w, float h
Returns: boolean

createRect()

Description: Creates a Rectangle object. Returns boolean of if action was successful.
Parameters: float x, float y, float d
Returns: boolean

createRect()

Description: Creates a Rectangle object. Returns boolean of if action was successful.
Parameters: float x, float y | defaults to 100 width, 50 height
Returns: boolean

createTextBox()

Description: Creates a text box. Returns boolean of if action was successful.
Parameters: float x, float y, String str, String font, float textSize
Returns: boolean

createComment()

Description: Creates a comment. They should only be shown or not shown based on the comment toggle status. Returns boolean of if action was successful.
Parameters: float x, float y, String str, String font, float textSize
Returns: boolean

###importImage()
Description: Imports an image into the DrawSpace. Returns boolean of if action was successful.
Parameters: float x, float y, String filename, String extension
Returns: boolean

TOOLBAR RELATED FUNCTIONALITY

resizeSelected()

Description: Resizes objects that are selected by a certain factor
Parameters: float factor
Returns: void

##toggleGroup()
Description: Toggles whether selected objects are or aren't in a group
Paramters: None
Returns: Void

group()

Description: Creates a group from objects that are selected
Parameters: None
Returns: Void

unGroup()

Description: Removes selected objects from their groups
Parameters: None
Returns: Void

pan()

Description: Shifts all selected objects. Can also be used for the DrawSpace
Parameters: float mouseX, float mouseY, float pmouseX, float pmouseY
Returns: void

setFillColor()

Description: Sets the inner color of new objects to be created, not including the border
Parameters: int r (red value), int g (green value), int b (blue value), int a (alpha)
Returns: Void

setBoarderColor()

Description: Sets the color of the border, of new objects to be created Parameters: int r (red value), int g (green value), int b (blue value)
Returns: Void

setSelectedFillColor()

Description: Sets the inner color of selected objects, not including the border
Parameters: int r (red value), int g (green value), int b (blue value), int a (alpha)
Returns: Void

setSelectedBorderColor()

Description: Sets the color of the border, of new objects to be created Parameters: int r (red value), int g (green value), int b (blue value)
Returns: Void

getSelectedFillColors()

Description: Returns an ArrayList of int[] representing fill colors of selected objects
Parameters: None
Returns: ArrayList<int[]>

getSelectedBoarderColors()

Description: Returns an ArrayList of int[] representing border colors of selected objects
Parameters: None
Returns: ArrayList<int[]>

rotate()

Description: Rotates a selected shape by a certain number of degrees
Parameters: float ao
Returns: Void

singleSelect()

Description: Selects an object at the position of the user's mouse. Only one object can be selected.
Parameters: float x, float y
Returns: Void

multiSelect()

Description: Selects an object at the position of the user's mouse. Multiple objects can be selected.
Parameters: float x, float y
Returns: Void

select()

Description: Used instead of single- or multi- select. It selects objects that are clicked. If the canvas is clicked, it de-selects objects.
Parameters: float x, float y
Returns: void

delete()

Description: Deletes objects selected. Returns boolean of if action was successful. Parameters: None
Returns: boolean

deleteSelected()

Description: Deletes objects selected. Returns boolean of if action was successful. Parameters: None
Returns: boolean
Note: Exact copy of delete() function

duplicateSelected()

Description: Duplicates objects that are selected.
Parameters: None
Returns: void

duplicate()

Description: Duplicates objects that are selected.
Parameters: None
Returns: void
Note: Exact copy of duplicateSelected() function

deleteLast()

Description: Deletes the last object created
Parameters: None
Returns: void

restoreLast()

Description: Restores the last object trashed
Parameters: None
Returns: void

clear()

Description: Deletes all objects on the DrawSpace
Parameters: None
Returns: Void

copy()

Description: Copies a shape that is selected. Returns boolean of if action was successful.
Parameters: None
Returns: boolean

cut()

Description: Copies a shape that is successful and then deletes it. Returns boolean of if action was successful.
Parmeters: None
Returns: boolean

paste()

Description: Pastes a shape that has been copied.
Parameters: None Returns: Void

DRAWING RELATED FUNCTIONALITY

setThickness()

Description: Sets the thickness of shape borders for newly-drawn shapes
Parameters: int size
Returns: void

freeDraw()

Description: Allows the user to free-draw a shape. It takes in the users' mouse coordinates as they drag the mouse along the screen. You must call createFreeForm() on mouseRelease() for freeDraw object to be created correctly.
Parameters: float pmousex, floatpmousey
Returns: void

createPollyGon()

Description: Creates a PollyGon object based on points the user clicks on the canvas.
Parameters: float pmousex, float pmousey, int numberVertex
Returns: void

createCurve()

Description: Creates a curve out of points the user clicks. A curve has four total points.
Parameters: float pmousex, float pmousey
Returns: void

createLine()

Description: Creates a line based on two points the user clicks.
Parameters: float pmousex, float pmousey
Returns: void

createFreeForm()

Description: Creates a freeForm object based on points gathered by the freeDraw() function. This function must be called on mouseReleased()
Parameters: None
*Returns: void

SAVE/LOAD/EXPORT RELATED FUNCTIONALITY

exportAs()

Description: Export an image of the DrawSpace
Parameters: String saveName, String extension | make sure to include the dot in the extension
Returns: void

save()

Description: Saves DrawSpace so it can be re-loaded later
Parameters: String filename
Returns: void | Throws IOException

open()

Description: Opens a file containing a DrawSpace()
Parameters: String filename
Returns: void | Throws IOException, ClassNotFoundException

⚠️ **GitHub.com Fallback** ⚠️