Rose
Classes | Public Member Functions | Protected Types | Protected Attributes | Friends | List of all members
rose::gm::Context Class Reference

Context More...

#include <GraphicsModel.h>

Classes

class  RendererDestroy
 A functor to destroy an SDL_Renderer. More...
 

Public Member Functions

 Context (const Context &context)=delete
 
 Context (Context &&context) noexcept=default
 
Contextoperator= (const Context &context)=delete
 
Contextoperator= (Context &&context)=default
 
 Context (SdlWindow &window, int index, Uint32 flags)
 
 operator bool () const noexcept
 Test for a valid Context.
 
auto get () const
 Get an opaque pointer for API calls.
 
void setDrawBlendMode (SDL_BlendMode blendMode)
 Set the draw blend mode.
 
void copyFullTexture (Texture &source, Texture &destination)
 Copy source Texture to destination Texture and set the BlendMode on the destination Texture. More...
 
int renderClear ()
 Prepare for the start of a rendering iteration.
 
void renderPresent ()
 Complete a rendering iteration.
 
int renderCopy (const Texture &texture)
 Copy a Texture to the current render target using the size of the Texture and the size of the target. More...
 
int renderCopy (const Texture &texture, Rectangle dst)
 Copy a Texture to the current render target using the size of the Texture and specified destination rectangle. More...
 
int renderCopy (const Texture &texture, Rectangle src, Rectangle dst)
 Copy part of the Texture specified by the source Rectangle to the render target location specified by the destination Rectangle. More...
 
int renderCopyEx (Texture &texture, Rectangle src, Rectangle dst, double angle, RenderFlip renderFlip, std::optional< Position< int >> point=std::nullopt) const
 Render with extensions. More...
 
int setDrawColor (color::RGBA color)
 Set the drawing color used for drawing Rectangles, lines and clearing. More...
 
int setDrawColor (color::HSVA color)
 Set the drawing color used for drawing Rectangles, lines and clearing. More...
 
int fillRect (Rectangle rect, color::RGBA color)
 Render a filled Rectangle. More...
 
int drawPoint (const Position< int > &p, const color::RGBA &color)
 Render a pixel. More...
 
int drawLine (const Position< int > &p0, const Position< int > &p1)
 

Protected Types

using RendererPtr = std::unique_ptr< SDL_Renderer, RendererDestroy >
 An SDL_Renderer unique pointer.
 

Protected Attributes

RendererPtr mRenderer {}
 The Renderer.
 
SDL_Texture * mCurrentRenderTarget {nullptr}
 

Friends

class RenderTargetGuard
 

Detailed Description

Context

An abstraction of graphics rendering context.

Member Function Documentation

◆ copyFullTexture()

void rose::gm::Context::copyFullTexture ( Texture source,
Texture destination 
)

Copy source Texture to destination Texture and set the BlendMode on the destination Texture.

The function uses RenderTargetGuard to temporarily set the render Target to the destination, calls SDL_RenderCopy to copy the texture, and sets the BlendMode on the destination texture to SDL_BLENDMODE_BLEND.

Parameters
source
destination

◆ drawPoint()

int rose::gm::Context::drawPoint ( const Position< int > &  p,
const color::RGBA color 
)

Render a pixel.

Parameters
pThe location of the pixel.
Returns
The status return from the SDL API.

◆ fillRect()

int rose::gm::Context::fillRect ( Rectangle  rect,
color::RGBA  color 
)

Render a filled Rectangle.

Parameters
rectThe Rectangle
colorThe fill color.
Returns
The status return from the SDL API.

◆ renderCopy() [1/3]

int rose::gm::Context::renderCopy ( const Texture texture)

Copy a Texture to the current render target using the size of the Texture and the size of the target.

Parameters
textureThe texture to copy.
Returns
The return status of the API call.

◆ renderCopy() [2/3]

int rose::gm::Context::renderCopy ( const Texture texture,
Rectangle  dst 
)

Copy a Texture to the current render target using the size of the Texture and specified destination rectangle.

Parameters
textureThe source Texture.
dstThe destination Rectangle.
Returns
The return status of the API call.

◆ renderCopy() [3/3]

int rose::gm::Context::renderCopy ( const Texture texture,
Rectangle  src,
Rectangle  dst 
)

Copy part of the Texture specified by the source Rectangle to the render target location specified by the destination Rectangle.

Parameters
textureThe Texture.
srcThe source Rectangle.
dstThe destination Rectangle.
Returns
The return status of API call.

◆ renderCopyEx()

int rose::gm::Context::renderCopyEx ( Texture texture,
Rectangle  src,
Rectangle  dst,
double  angle,
RenderFlip  renderFlip,
std::optional< Position< int >>  point = std::nullopt 
) const

Render with extensions.

Parameters
srcSource Rectangle.
dstDestination Rectangle.
angleRotation Angle.
renderFlipFlip
pointRotation Position if specified.
Returns
Status code returned by SDL_RenderCopyEx()

◆ setDrawColor() [1/2]

int rose::gm::Context::setDrawColor ( color::RGBA  color)

Set the drawing color used for drawing Rectangles, lines and clearing.

Parameters
colorThe new drawing Color.
Returns
Status code returned by the API.

◆ setDrawColor() [2/2]

int rose::gm::Context::setDrawColor ( color::HSVA  color)
inline

Set the drawing color used for drawing Rectangles, lines and clearing.

Parameters
colorThe new drawing Color.
Returns
Status code returned by the API.

The documentation for this class was generated from the following files: