ChaiLove API  0.28.0
Public Member Functions
love::graphics Class Reference

The primary purpose of the graphics module is to draw to the screen. More...

Public Member Functions

graphicsrectangle (const std::string &drawmode, int x, int y, int width, int height)
 Draws a rectangle. More...
 
graphicsclear ()
 Clears the screen to the set background color.
 
graphicsclear (int r, int g, int b, int a)
 Clears the screen to the given background color. More...
 
graphicspoint (int x, int y)
 Draws a point. More...
 
graphicspoint (Point *p)
 Draws a point. More...
 
graphicsline (int x1, int y1, int x2, int y2)
 Draws a line. More...
 
Quad newQuad (int x, int y, int width, int height, int sw, int sh)
 Creates a new Quad.
 
ImagenewImage (const std::string &filename)
 Creates a new Image from a given filepath. More...
 
FontnewFont (const std::string &filename, int size)
 Creates a new TrueType font, with the given font size. More...
 
FontnewFont (const std::string &filename, int glyphWidth, int glyphHeight, const std::string &letters)
 Creates a new BMFont with the given spec. More...
 
graphicssetFont (Font *font)
 Set an already-loaded Font as the current font. More...
 
FontgetFont ()
 Retrieve th currently active font. More...
 
graphicsprint (const std::string &text, int x, int y)
 Prints the given text to the screen. More...
 
graphicssetColor (int red, int green, int blue, int alpha)
 Sets the active drawing color to the given color. More...
 
Color getColor ()
 Gets the current color. More...
 
Color getBackgroundColor ()
 Retrieves the active background color. More...
 
graphicssetBackgroundColor (int red, int green, int blue, int alpha)
 Sets the background color to the given color. More...
 
graphicssetDefaultFilter (const std::string &filter)
 Sets the default scaling filters used with images, and fonts. More...
 
std::string getDefaultFilter ()
 Returns the default scaling filters used with images and fonts. More...
 
int getWidth ()
 Retrieve the width of the screen.
 
int getHeight ()
 Retrieve the height of the screen.
 
Point getDimensions ()
 Gets the width and height of the window. More...
 
graphicscircle (const std::string &drawmode, int x, int y, int radius)
 Draws a circle. More...
 
graphicsellipse (const std::string &drawmode, int x, int y, int radiusx, int radiusy)
 Draws an ellipse. More...
 
graphicsdraw (Image *image, int x, int y, float r, float sx, float sy, float ox, float oy)
 Draws an image with the given angle, zoom, and origin. More...
 
graphicsdraw (Image *image, Quad quad, int x, int y)
 Draws an image on screen, using the given Quad as a source. More...
 
graphicsarc (const std::string &drawmode, int x, int y, int radius, int angle1, int angle2)
 Draws an arc. More...
 

Detailed Description

The primary purpose of the graphics module is to draw to the screen.

Member Function Documentation

◆ arc()

graphics& love::graphics::arc ( const std::string &  drawmode,
int  x,
int  y,
int  radius,
int  angle1,
int  angle2 
)

Draws an arc.

Parameters
drawmodeHow to draw the arc. Can be "fill" or "line".
xThe position to draw the object (x-axis).
yThe position to draw the object (y-axis).
radiusThe radius of the arc.
angle1The angle of the first
angle2The angle of the second.

◆ circle()

graphics& love::graphics::circle ( const std::string &  drawmode,
int  x,
int  y,
int  radius 
)

Draws a circle.

Parameters
drawmodeHow to draw the circle. Can be "fill" or "line".
xThe position of the center along x-axis.
yThe position of the center along y-axis.
radiusThe radius of the circle.

◆ clear()

graphics& love::graphics::clear ( int  r,
int  g,
int  b,
int  a 
)

Clears the screen to the given background color.

Parameters
rRed value.
gGreen value.
bBlue value.
a(255) Alpha value.

◆ draw() [1/2]

graphics& love::graphics::draw ( Image image,
int  x,
int  y,
float  r,
float  sx,
float  sy,
float  ox,
float  oy 
)

Draws an image with the given angle, zoom, and origin.

Parameters
imageThe image to draw on the screen.
x(0) The position to draw the object (x-axis).
y(0) The position to draw the object (y-axis).
r(0) Orientation (radians).
sx(1) Scale factor (x-axis).
sy(sx) Scale factor (y-axis).
ox(0) Origin offset (x-axis).
oy(0) Origin offset (y-axis).

◆ draw() [2/2]

graphics& love::graphics::draw ( Image image,
Quad  quad,
int  x,
int  y 
)

Draws an image on screen, using the given Quad as a source.

Parameters
imageThe image to draw on the screen.
quadThe source quad of the image.
x(0) The position to draw the object (x-axis).
y(0) The position to draw the object (y-axis).

◆ ellipse()

graphics& love::graphics::ellipse ( const std::string &  drawmode,
int  x,
int  y,
int  radiusx,
int  radiusy 
)

Draws an ellipse.

Parameters
drawmodeHow to draw the ellipse. Can be "fill" or "line".
xThe position of the center along x-axis.
yThe position of the center along y-axis.
radiusxThe radius of the ellipse along the x-axis (half the ellipse's width).
radiusyThe radius of the ellipse along the y-axis (half the ellipse's height).

◆ getBackgroundColor()

Color love::graphics::getBackgroundColor ( )

Retrieves the active background color.

See also
love.graphics.setBackgroundColor

◆ getColor()

Color love::graphics::getColor ( )

Gets the current color.

Returns
The active color.

◆ getDefaultFilter()

std::string love::graphics::getDefaultFilter ( )

Returns the default scaling filters used with images and fonts.

See also
love.graphics.setDefaultFilter

◆ getDimensions()

Point love::graphics::getDimensions ( )

Gets the width and height of the window.

See also
love.graphics.getWidth
love.graphics.getHeight
Returns
A Point refering the x and y size of the window.

◆ getFont()

Font* love::graphics::getFont ( )

Retrieve th currently active font.

See also
setFont

◆ line()

graphics& love::graphics::line ( int  x1,
int  y1,
int  x2,
int  y2 
)

Draws a line.

Parameters
x1The position of first point on the x-axis.
y1The position of first point on the y-axis.
x2The position of second point on the x-axis.
y2The position of second point on the y-axis.

◆ newFont() [1/2]

Font* love::graphics::newFont ( const std::string &  filename,
int  size 
)

Creates a new TrueType font, with the given font size.

Parameters
filename(default) The path to the TrueType .ttf font. When not provided, will return the default font.
size(12) The size of the font to create.
Returns
The created TrueType font.

◆ newFont() [2/2]

Font* love::graphics::newFont ( const std::string &  filename,
int  glyphWidth,
int  glyphHeight,
const std::string &  letters 
)

Creates a new BMFont with the given spec.

Parameters
filenameThe path to the font image.
glyphWidthThe width of each character.
glyphHeightThe height of each character.
lettersThe letters presented in the font image.
Returns
The created BMFont.

◆ newImage()

Image* love::graphics::newImage ( const std::string &  filename)

Creates a new Image from a given filepath.

Parameters
filenameThe filepath to the image file.
Returns
An image object which can be drawn to the screen.
var logo = love.graphics.newImage("logo.png")

◆ point() [1/2]

graphics& love::graphics::point ( int  x,
int  y 
)

Draws a point.

Parameters
xThe position on the x-axis.
yThe position on the y-axis.

◆ point() [2/2]

graphics& love::graphics::point ( Point p)

Draws a point.

Parameters
pThe point to draw on the screen.

◆ print()

graphics& love::graphics::print ( const std::string &  text,
int  x,
int  y 
)

Prints the given text to the screen.

Parameters
textThe text to draw.
x(0) The position to draw the object (x-axis).
y(0) The position to draw the object (y-axis).
love.graphics.print("Hello World", 100, 100)

◆ rectangle()

graphics& love::graphics::rectangle ( const std::string &  drawmode,
int  x,
int  y,
int  width,
int  height 
)

Draws a rectangle.

Parameters
drawmodeHow to draw the rectangle. Can be "fill" or "line".
xThe position of top-left corner along the x-axis.
yThe position of top-left corner along the y-axis.
widthWidth of the rectangle.
heightHeight of the rectangle.
love.graphics.rectangle("fill", 100, 100, 50, 50)

◆ setBackgroundColor()

graphics& love::graphics::setBackgroundColor ( int  red,
int  green,
int  blue,
int  alpha 
)

Sets the background color to the given color.

Parameters
redThe r value.
greenThe g value.
blueThe b value.
alpha(255) The a value.
See also
love.graphics.getBackgroundColor

◆ setColor()

graphics& love::graphics::setColor ( int  red,
int  green,
int  blue,
int  alpha 
)

Sets the active drawing color to the given color.

Parameters
redThe amount of red.
greenThe amount of green.
blueThe amount of blue.
alpha(255) The amount of alpha.
See also
getColor

◆ setDefaultFilter()

graphics& love::graphics::setDefaultFilter ( const std::string &  filter)

Sets the default scaling filters used with images, and fonts.

Parameters
filterThe filter mode to apply when rotating or scaling graphics. This can be either "linear" (default), or "nearest".
See also
love.graphics.getDefaultFilter
https://love2d.org/wiki/FilterMode

◆ setFont()

graphics& love::graphics::setFont ( Font font)

Set an already-loaded Font as the current font.

Parameters
(font)The font to set as the active font. When not provided will set the default font.
See also
getFont