35#ifndef LIBTCOD_CONTEXT_HPP_
36#define LIBTCOD_CONTEXT_HPP_
83 struct TCOD_Context* context =
nullptr;
85 context_ = ContextPtr{context};
87 throw std::logic_error(
"Libtcod not compiled with SDL support, so it can not create its own context.");
91 explicit Context(ContextPtr&& ptr) : context_{std::move(ptr)} {}
93 explicit Context(TCOD_Context* ptr) : context_{ptr} {}
96 Context(
const Context&) =
delete;
97 Context& operator=(
const Context&) =
delete;
98 Context(Context&&) =
default;
99 Context& operator=(Context&&) =
default;
134 void present(
const TCOD_Console& console,
const TCOD_ViewportOptions& viewport) {
142 void present(
const TCOD_Console& console) {
159 [[nodiscard]]
auto get_sdl_window() noexcept -> struct SDL_Window* {
178 [[nodiscard]]
auto get_sdl_renderer() noexcept -> struct SDL_Renderer* {
184 [[nodiscard]]
auto pixel_to_tile_coordinates(
const std::array<int, 2>& xy) -> std::array<int, 2> {
185 std::array<int, 2> out{xy[0], xy[1]};
192 [[nodiscard]]
auto pixel_to_tile_coordinates(
const std::array<double, 2>& xy) -> std::array<double, 2> {
193 std::array<double, 2> out{xy[0], xy[1]};
226 void convert_event_coordinates(SDL_Event& event) {
234 void save_screenshot(
const std::filesystem::path& path) {
267 [[nodiscard]]
auto new_console(
int min_columns = 1,
int min_rows = 1,
float magnification = 1.0f) -> tcod::Console {
270 if (magnification <= 0.0f) {
271 throw std::invalid_argument(
272 std::string(
"Magnification must be greater than zero. Got ") + std::to_string(magnification));
275 return tcod::Console{std::max(columns, min_columns), std::max(rows, min_rows)};
280 auto change_tileset(tcod::Tileset& new_tileset) ->
void {
297 [[nodiscard]]
auto get_ptr() noexcept -> ContextPtr& {
return context_; }
301 [[nodiscard]]
auto get_ptr() const noexcept -> const ContextPtr& {
return context_; }
305 auto close() ->
void { *
this = Context(); }
308 ContextPtr context_ =
nullptr;
Various console functions.
C types for console functions.
TCOD_renderer_t
Libtcod rendering modes.
Definition console_types.h:491
Libtcod display management context.
struct TCOD_ContextParams TCOD_ContextParams
A struct of parameters used to create a new context with TCOD_context_new.
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.
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_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_set_mouse_transform(struct TCOD_Context *context, const TCOD_MouseTransform *transform)
Manually set the pixel-to-tile mouse position transformation.
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.
TCOD_Error TCOD_context_change_tileset(struct TCOD_Context *self, TCOD_Tileset *tileset)
Change the active tileset for this context.
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_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.
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.
Context initialization module.
TCOD_Error TCOD_context_new(const TCOD_ContextParams *params, TCOD_Context **out)
Create a new context with the given parameters.
Context viewport options.
Mouse state provided by the libtcod event system.
struct TCOD_MouseTransform TCOD_MouseTransform
Info needed to convert between mouse pixel and tile coordinates.
The libtcod namespace.
Definition bresenham.hpp:157
int check_throw_error(int error)
Check and throw error messages.
Definition error.hpp:57