libtcod
Loading...
Searching...
No Matches
console_drawing.h
Go to the documentation of this file.
1/* BSD 3-Clause License
2 *
3 * Copyright © 2008-2025, Jice and the libtcod contributors.
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright notice,
10 * this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright notice,
13 * this list of conditions and the following disclaimer in the documentation
14 * and/or other materials provided with the distribution.
15 *
16 * 3. Neither the name of the copyright holder nor the names of its
17 * contributors may be used to endorse or promote products derived from
18 * this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
24 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
31 */
34#pragma once
35#ifndef TCOD_CONSOLE_DRAWING_H_
36#define TCOD_CONSOLE_DRAWING_H_
37#ifdef __cplusplus
38#include <array>
39#include <optional>
40#endif // __cplusplus
41#include "config.h"
42#include "console_types.h"
45#ifdef __cplusplus
46extern "C" {
47#endif // __cplusplus
59TCOD_DEPRECATED("Use TCOD_console_draw_rect_rgb instead.")
60TCOD_PUBLIC void TCOD_console_rect(TCOD_Console* con, int x, int y, int rw, int rh, bool clear, TCOD_bkgnd_flag_t flag);
73TCOD_DEPRECATED("Use TCOD_console_draw_rect_rgb instead.")
74TCOD_PUBLIC void TCOD_console_hline(TCOD_Console* con, int x, int y, int l, TCOD_bkgnd_flag_t flag);
87TCOD_DEPRECATED("Use TCOD_console_draw_rect_rgb instead.")
88TCOD_PUBLIC void TCOD_console_vline(TCOD_Console* con, int x, int y, int l, TCOD_bkgnd_flag_t flag);
89// Next functions are provisional unless given an added version.
97TCOD_PUBLIC void TCOD_console_put_rgb(
98 TCOD_Console* __restrict console,
99 int x,
100 int y,
101 int ch,
102 const TCOD_color_t* fg,
103 const TCOD_color_t* bg,
104 TCOD_bkgnd_flag_t flag);
113 TCOD_Console* __restrict console,
114 int x,
115 int y,
116 int width,
117 int height,
118 int ch,
119 const TCOD_color_t* fg,
120 const TCOD_color_t* bg,
121 TCOD_bkgnd_flag_t flag);
143 struct TCOD_Console* __restrict con,
144 int x,
145 int y,
146 int width,
147 int height,
148 const int* __restrict decoration,
149 const TCOD_ColorRGB* __restrict fg,
150 const TCOD_ColorRGB* __restrict bg,
152 bool clear);
154#ifdef __cplusplus
155} // extern "C"
156namespace tcod {
159
182inline void draw_rect(
183 TCOD_Console& console,
184 const std::array<int, 4>& rect,
185 int ch,
186 std::optional<TCOD_ColorRGB> fg,
187 std::optional<TCOD_ColorRGB> bg,
188 TCOD_bkgnd_flag_t flag = TCOD_BKGND_SET) {
189 const TCOD_ColorRGB* fg_ptr = fg ? &fg.value() : nullptr;
190 const TCOD_ColorRGB* bg_ptr = bg ? &bg.value() : nullptr;
192 TCOD_console_draw_rect_rgb(&console, rect.at(0), rect.at(1), rect.at(2), rect.at(3), ch, fg_ptr, bg_ptr, flag));
193}
194
222inline void draw_frame(
223 TCOD_Console& console,
224 const std::array<int, 4>& rect,
225 const std::array<int, 9>& decoration,
226 std::optional<TCOD_ColorRGB> fg,
227 std::optional<TCOD_ColorRGB> bg,
228 TCOD_bkgnd_flag_t flag = TCOD_BKGND_SET,
229 bool clear = true) {
230 const TCOD_ColorRGB* fg_ptr = fg ? &fg.value() : nullptr;
231 const TCOD_ColorRGB* bg_ptr = bg ? &bg.value() : nullptr;
233 &console, rect.at(0), rect.at(1), rect.at(2), rect.at(3), decoration.data(), fg_ptr, bg_ptr, flag, clear));
234}
235
236} // namespace tcod
237#endif // __cplusplus
238#endif // TCOD_CONSOLE_DRAWING_H_
Libtcod config header.
C types for console functions.
TCOD_Error
An enum of libtcod error codes.
Definition error.h:48
void draw_frame(TCOD_Console &console, const std::array< int, 4 > &rect, const std::array< int, 9 > &decoration, std::optional< TCOD_ColorRGB > fg, std::optional< TCOD_ColorRGB > bg, TCOD_bkgnd_flag_t flag=TCOD_BKGND_SET, bool clear=true)
Draw a decorative frame.
Definition console_drawing.h:222
void draw_rect(TCOD_Console &console, const std::array< int, 4 > &rect, int ch, std::optional< TCOD_ColorRGB > fg, std::optional< TCOD_ColorRGB > bg, TCOD_bkgnd_flag_t flag=TCOD_BKGND_SET)
Fill a region with the given graphic.
Definition console_drawing.h:182
TCOD_Error TCOD_console_draw_rect_rgb(TCOD_Console *console, int x, int y, int width, int height, int ch, const TCOD_color_t *fg, const TCOD_color_t *bg, TCOD_bkgnd_flag_t flag)
Draw a rectangle on a console with a shape of x,y,width,height.
void TCOD_console_put_rgb(TCOD_Console *console, int x, int y, int ch, const TCOD_color_t *fg, const TCOD_color_t *bg, TCOD_bkgnd_flag_t flag)
Place a single tile on a console at x,y.
void TCOD_console_hline(TCOD_Console *con, int x, int y, int l, TCOD_bkgnd_flag_t flag)
Draw a horizontal line using the default colors.
TCOD_bkgnd_flag_t
Background color blend modes.
Definition console.h:60
TCOD_Error TCOD_console_draw_frame_rgb(struct TCOD_Console *con, int x, int y, int width, int height, const int *decoration, const TCOD_ColorRGB *fg, const TCOD_ColorRGB *bg, TCOD_bkgnd_flag_t flag, bool clear)
Draw a decorated frame onto console with the shape of x, y, width, height.
void TCOD_console_vline(TCOD_Console *con, int x, int y, int l, TCOD_bkgnd_flag_t flag)
Draw a vertical line using the default colors.
void TCOD_console_rect(TCOD_Console *con, int x, int y, int rw, int rh, bool clear, TCOD_bkgnd_flag_t flag)
Draw a rectangle onto a console.
The libtcod namespace.
Definition bresenham.hpp:157
int check_throw_error(int error)
Check and throw error messages.
Definition error.hpp:57
A 3-channel RGB color struct.
Definition color.h:50
A libtcod console containing a grid of tiles with {ch, fg, bg} information.
Definition console.h:125