libtcod
Loading...
Searching...
No Matches
context.h File Reference

Libtcod display management context. More...

#include <algorithm>
#include <array>
#include <memory>
#include <stdexcept>
#include "console_types.hpp"
#include "error.hpp"
#include "config.h"
#include "console.h"
#include "context_viewport.h"
#include "error.h"
#include "mouse_types.h"
#include "tileset.h"

Go to the source code of this file.

Classes

struct  TCOD_ContextParams
 A struct of parameters used to create a new context with TCOD_context_new. More...
struct  TCOD_Context
 A rendering context for libtcod. More...
struct  tcod::ContextDeleter

Namespaces

namespace  tcod
 The libtcod namespace.

Typedefs

typedef struct TCOD_Context TCOD_Context
typedef struct TCOD_ContextParams TCOD_ContextParams
 A struct of parameters used to create a new context with TCOD_context_new.
typedef std::unique_ptr< TCOD_Context, ContextDeletertcod::ContextPtr
typedef std::shared_ptr< TCOD_Contexttcod::ContextSharedPtr

Functions

void TCOD_context_delete (struct TCOD_Context *renderer)
 Delete a rendering context.
TCOD_Error TCOD_context_present (struct TCOD_Context *context, const struct TCOD_Console *console, const struct TCOD_ViewportOptions *viewport)
 Present a console to the screen, using a rendering context.
TCOD_Error TCOD_context_screen_pixel_to_tile_d (struct TCOD_Context *context, double *x, double *y)
 Convert the screen coordinates to tile coordinates for this context.
TCOD_Error TCOD_context_screen_pixel_to_tile_i (struct TCOD_Context *context, int *x, int *y)
 Convert the screen coordinates to integer tile coordinates for this context.
TCOD_Error TCOD_context_convert_event_coordinates (struct TCOD_Context *context, union SDL_Event *event)
 Convert the pixel coordinates of SDL mouse events to the tile coordinates of the current context.
TCOD_Error TCOD_context_save_screenshot (struct TCOD_Context *context, const char *filename)
 Save the last presented console to a PNG file.
struct SDL_Window * TCOD_context_get_sdl_window (struct TCOD_Context *context)
 Return a pointer the SDL_Window for this context if it uses one.
struct SDL_Renderer * TCOD_context_get_sdl_renderer (struct TCOD_Context *context)
 Return a pointer the SDL_Renderer for this context if it uses one.
TCOD_Error TCOD_context_change_tileset (struct TCOD_Context *self, TCOD_Tileset *tileset)
 Change the active tileset for this context.
int TCOD_context_get_renderer_type (struct TCOD_Context *context)
 Return the TCOD_renderer_t renderer type for this context.
TCOD_Error TCOD_context_recommended_console_size (struct TCOD_Context *context, float magnification, int *columns, int *rows)
 Set columns and rows to the recommended console size for this context.
TCOD_Error TCOD_context_screen_capture (struct TCOD_Context *context, TCOD_ColorRGBA *out_pixels, int *width, int *height)
 Fill out_pixels with a screen capture.
TCOD_ColorRGBATCOD_context_screen_capture_alloc (struct TCOD_Context *context, int *width, int *height)
 Allocate and return a screen capture.
TCOD_Error TCOD_context_set_mouse_transform (struct TCOD_Context *context, const TCOD_MouseTransform *transform)
 Manually set the pixel-to-tile mouse position transformation.

Detailed Description

Libtcod display management context.

Typedef Documentation

◆ TCOD_ContextParams

typedef struct TCOD_ContextParams TCOD_ContextParams

A struct of parameters used to create a new context with TCOD_context_new.

embed:rst:leading-asterisk 
.. versionadded:: 1.19

Function Documentation

◆ TCOD_context_change_tileset()

TCOD_Error TCOD_context_change_tileset ( struct TCOD_Context * self,
TCOD_Tileset * tileset )

Change the active tileset for this context.

embed:rst:leading-asterisk 
.. versionadded:: 1.16

◆ TCOD_context_convert_event_coordinates()

TCOD_Error TCOD_context_convert_event_coordinates ( struct TCOD_Context * context,
union SDL_Event * event )

Convert the pixel coordinates of SDL mouse events to the tile coordinates of the current context.

embed:rst:leading-asterisk 
.. versionadded:: 1.19

◆ TCOD_context_delete()

void TCOD_context_delete ( struct TCOD_Context * renderer)

Delete a rendering context.

embed:rst:leading-asterisk 
*  .. versionadded:: 1.16
*  

◆ TCOD_context_get_renderer_type()

int TCOD_context_get_renderer_type ( struct TCOD_Context * context)

Return the TCOD_renderer_t renderer type for this context.

Returns a negative number on error, such as context being NULL.

embed:rst:leading-asterisk 
.. versionadded:: 1.16

◆ TCOD_context_get_sdl_renderer()

struct SDL_Renderer * TCOD_context_get_sdl_renderer ( struct TCOD_Context * context)

Return a pointer the SDL_Renderer for this context if it uses one.

embed:rst:leading-asterisk 
.. versionadded:: 1.16

◆ TCOD_context_get_sdl_window()

struct SDL_Window * TCOD_context_get_sdl_window ( struct TCOD_Context * context)

Return a pointer the SDL_Window for this context if it uses one.

embed:rst:leading-asterisk 
.. versionadded:: 1.16

◆ TCOD_context_present()

TCOD_Error TCOD_context_present ( struct TCOD_Context * context,
const struct TCOD_Console * console,
const struct TCOD_ViewportOptions * viewport )

Present a console to the screen, using a rendering context.

console is the console to present, the console can be any size.

viewport is the optional viewport options to use. This will affect the scaling of the console with the current context. This can be NULL to use the default options, which are to stretch the console to fit the screen.

embed:rst:leading-asterisk 
.. versionadded:: 1.16

◆ TCOD_context_recommended_console_size()

TCOD_Error TCOD_context_recommended_console_size ( struct TCOD_Context * context,
float magnification,
int * columns,
int * rows )

Set columns and rows to the recommended console size for this context.

magnification determines the apparent size of the tiles on the output. Values of 0.0f or lower will default to 1.0f.

embed:rst:leading-asterisk 
.. versionadded:: 1.16

◆ TCOD_context_save_screenshot()

TCOD_Error TCOD_context_save_screenshot ( struct TCOD_Context * context,
const char * filename )

Save the last presented console to a PNG file.

embed:rst:leading-asterisk 
.. versionadded:: 1.16

◆ TCOD_context_screen_capture()

TCOD_Error TCOD_context_screen_capture ( struct TCOD_Context * context,
TCOD_ColorRGBA * out_pixels,
int * width,
int * height )

Fill out_pixels with a screen capture.

Parameters
contextA non-NULL TCOD_Context object.
out_pixelsIf NULL then width and height are filled with the output dimensions. If not NULL then width and height are verified and the capture will be written out.
widthPointer to fill with the expected image width.
heightPointer to fill with the expected image height.
Returns
A negative error value is returned on errors, otherwise returns TCOD_E_OK.
embed:rst:leading-asterisk 
.. versionadded:: 1.22

◆ TCOD_context_screen_capture_alloc()

TCOD_ColorRGBA * TCOD_context_screen_capture_alloc ( struct TCOD_Context * context,
int * width,
int * height )

Allocate and return a screen capture.

The returned array must be freed with free().

Parameters
contextA non-NULL TCOD_Context object.
widthPointer to fill with the allocated image width.
heightPointer to fill with the allocated image height.
Returns
An allocated array of RGBA pixels which must be manually freed.
embed:rst:leading-asterisk 
.. versionadded:: 1.22

◆ TCOD_context_screen_pixel_to_tile_d()

TCOD_Error TCOD_context_screen_pixel_to_tile_d ( struct TCOD_Context * context,
double * x,
double * y )

Convert the screen coordinates to tile coordinates for this context.

x and y are the pointers to the screen coordinates, these will be converted to tile coordinates after the call to this function.

The parameters given to the last call to TCOD_context_present will determine where the tiles are for this call.

embed:rst:leading-asterisk 
.. versionadded:: 1.16

◆ TCOD_context_screen_pixel_to_tile_i()

TCOD_Error TCOD_context_screen_pixel_to_tile_i ( struct TCOD_Context * context,
int * x,
int * y )

Convert the screen coordinates to integer tile coordinates for this context.

Save as TCOD_context_screen_pixel_to_tile but the inputs and results are integers. This is useful if you don't need sub-tile coordinates.

embed:rst:leading-asterisk 
.. versionadded:: 1.16

◆ TCOD_context_set_mouse_transform()

TCOD_Error TCOD_context_set_mouse_transform ( struct TCOD_Context * context,
const TCOD_MouseTransform * transform )

Manually set the pixel-to-tile mouse position transformation.

Parameters
contextA non-NULL TCOD_Context object.
transformThe transform to assign to the context.
Returns
A negative error value is returned on errors, otherwise returns TCOD_E_OK.
embed:rst:leading-asterisk
 .. versionadded:: 1.24