Gamedev Framework (gf)  0.6.0
A C++11 framework for 2D games
Console.h
1 /*
2  * Gamedev Framework (gf)
3  * Copyright (C) 2016-2017 Julien Bernard
4  *
5  * This software is provided 'as-is', without any express or implied
6  * warranty. In no event will the authors be held liable for any damages
7  * arising from the use of this software.
8  *
9  * Permission is granted to anyone to use this software for any purpose,
10  * including commercial applications, and to alter it and redistribute it
11  * freely, subject to the following restrictions:
12  *
13  * 1. The origin of this software must not be misrepresented; you must not
14  * claim that you wrote the original software. If you use this software
15  * in a product, an acknowledgment in the product documentation would be
16  * appreciated but is not required.
17  * 2. Altered source versions must be plainly marked as such, and must not be
18  * misrepresented as being the original software.
19  * 3. This notice may not be removed or altered from any source distribution.
20  */
21 #ifndef GF_CONSOLE_H
22 #define GF_CONSOLE_H
23 
24 #include <cstdint>
25 
26 #include "Alignment.h"
27 #include "Array2D.h"
28 #include "Blend.h"
29 #include "ConsoleFont.h"
30 #include "Flags.h"
31 #include "Path.h"
32 #include "Portability.h"
33 #include "StringRef.h"
34 #include "Texture.h"
35 #include "Transformable.h"
36 #include "Vector.h"
37 
38 namespace gf {
39 #ifndef DOXYGEN_SHOULD_SKIP_THIS
40 inline namespace v1 {
41 #endif
42 
43 
44  /**
45  * @ingroup game
46  * @brief The alignment of the text in the console
47  *
48  * @sa gf::Console
49  */
50  enum class ConsoleAlignment {
51  Left, ///< Left alignment
52  Center, ///< Centered alignment
53  Right, ///< Right alignment
54  };
55 
56  /**
57  * @ingroup game
58  * @brief A type for color controls in a console
59  *
60  * @sa gf::Console
61  */
62  using ConsoleColorControl = char;
63 
64  /**
65  * @ingroup game
66  * @brief The constant for color control #1
67  *
68  * @sa gf::Console
69  */
70  constexpr ConsoleColorControl ConsoleColorControl1 = '\x01';
71 
72  /**
73  * @ingroup game
74  * @brief The constant for color control #2
75  *
76  * @sa gf::Console
77  */
78  constexpr ConsoleColorControl ConsoleColorControl2 = '\x02';
79 
80  /**
81  * @ingroup game
82  * @brief The constant for color control #3
83  *
84  * @sa gf::Console
85  */
86  constexpr ConsoleColorControl ConsoleColorControl3 = '\x03';
87 
88  /**
89  * @ingroup game
90  * @brief The constant for color control #4
91  *
92  * @sa gf::Console
93  */
94  constexpr ConsoleColorControl ConsoleColorControl4 = '\x04';
95 
96  /**
97  * @ingroup game
98  * @brief The constant for color control #5
99  *
100  * @sa gf::Console
101  */
102  constexpr ConsoleColorControl ConsoleColorControl5 = '\x05';
103 
104  /**
105  * @ingroup game
106  * @brief The constant for color control stop
107  *
108  * @sa gf::Console
109  */
110  constexpr ConsoleColorControl ConsoleColorControlStop = '\x06';
111 
112 
113 
114  /**
115  * @brief A console effect on the background color
116  *
117  * A console effect is used to modify the background color of the console.
118  *
119  * If @f$ \textbf{b} @f$ is the current background color, and @f$ \textbf{c} @f$
120  * is the wanted color, then the result color @f$ \textbf{r} @f$ is given by
121  * the following description. Note that ConsoleEffect::AddAlpha and
122  * ConsoleEffect::Alpha need an @f$ \alpha @f$ value.
123  *
124  * @sa gf::Console
125  */
127  public:
128 
129  /**
130  * @brief The kind of console effect
131  */
132  enum Kind : uint32_t {
133  None, ///< Do not change the background color
134  Set, ///< @f[ \textbf{r} = \textbf{c} @f]
135  Multiply, ///< @f[ \textbf{r} = \textbf{b} \cdot \textbf{c} @f]
136  Lighten, ///< @f[ \textbf{r} = \max(\textbf{b}, \textbf{c}) @f]
137  Darken, ///< @f[ \textbf{r} = \min(\textbf{b}, \textbf{c}) @f]
138  Screen, ///< @f[ \textbf{r} = 1 - (1 - \textbf{b}) \cdot (1 - \textbf{c}) @f]
139  ColorDodge, ///< @f[ \textbf{r} = \frac{\textbf{c}}{1 - \textbf{b}} @f]
140  ColorBurn, ///< @f[ \textbf{r} = 1 - \frac{1 - \textbf{b}}{\textbf{c}} @f]
141  Add, ///< @f[ \textbf{r} = \textbf{b} + \textbf{c} @f]
142  AddAlpha, ///< @f[ \textbf{r} = \textbf{b} + \alpha \cdot \textbf{c} @f]
143  Burn, ///< @f[ \textbf{r} = \textbf{b} + \textbf{c} - 1 @f]
144  Overlay, ///< @f[ \textbf{r} = \begin{cases} 2 \cdot \textbf{b} \cdot \textbf{c} & \text{if } \textbf{b} \leq 0.5 \\ 1 - 2 \cdot (1 - \textbf{b}) \cdot (1 - \textbf{c}) & \text{otherwise} \end{cases} @f]
145  Alpha, ///< @f[ \textbf{r} = (1 - \alpha) \cdot \textbf{b} + \alpha \cdot \textbf{c} @f]
146  Default, ///< Use the default console effect
147  };
148 
149  /**
150  * @brief Constructor with a kind only
151  *
152  * This constructor sould be used with all the effects, except
153  * ConsoleEffect::AddAlpha and ConsoleEffect::Alpha.
154  *
155  * @param kind The kind of effect
156  */
157  constexpr ConsoleEffect(Kind kind)
158  : m_kind(kind)
159  , m_alpha(0.0f)
160  {
161 
162  }
163 
164  /**
165  * @brief Constructor with a kind and @f$ \alpha @f$
166  *
167  * This constructor should be used with ConsoleEffect::AddAlpha and
168  * ConsoleEffect::Alpha.
169  *
170  * @param kind The kind of effect
171  * @param alpha The @f$ \alpha @f$ value
172  */
173  constexpr ConsoleEffect(Kind kind, float alpha)
174  : m_kind(kind)
175  , m_alpha(alpha)
176  {
177 
178  }
179 
180  /**
181  * @brief Get the kind of effect
182  */
183  constexpr Kind getKind() const noexcept {
184  return m_kind;
185  }
186 
187  /**
188  * @brief Check if the effect if Console::Default
189  */
190  constexpr bool isDefault() const noexcept {
191  return m_kind == Default;
192  }
193 
194  /**
195  * @brief Get the alpha value
196  */
197  constexpr float getAlpha() const noexcept {
198  return m_alpha;
199  }
200 
201  private:
202  Kind m_kind;
203  float m_alpha;
204  };
205 
206  /**
207  * @ingroup game
208  * @brief A virtual console
209  *
210  * A console is a virtual terminal where you can print the characters from a
211  * console font. Each cell of the console has a background color, a
212  * foreground color and a 8-bit character.
213  *
214  * A console has a state with default values for different aspects:
215  * - a default background color (initiallly gf::Color::Black)
216  * - a default foreground color (initiallly gf::Color::White)
217  * - a default console effect (initiallly gf::ConsoleEffect::None)
218  * - a default alignment (initiallly gf::ConsoleAlignment::Left)
219  *
220  * Several functions use this state to determine actual values.
221  *
222  * @sa gf::ConsoleFont
223  */
224  class GF_API Console : public Transformable {
225  public:
226  /**
227  * @brief An action when printing
228  */
229  enum class PrintAction {
230  None, ///< No action
231  Clear, ///< Fill the area with space characters
232  };
233 
234  /**
235  * @brief Constructor
236  *
237  * @param font A console font
238  * @param size The size of the console, in characters
239  */
240  Console(const ConsoleFont& font, Vector2i size);
241 
242  /**
243  * @brief Get the width of the console
244  */
245  int getWidth() const {
246  return m_data.getSize().width;
247  }
248 
249  /**
250  * @brief Get the height of the console
251  */
252  int getHeight() const {
253  return m_data.getSize().height;
254  }
255 
256  /**
257  * @name Basic printing
258  * @{
259  */
260 
261  /**
262  * @brief Set the default background color
263  *
264  * @param color The new background color
265  * @sa getDefaultBackground()
266  */
267  void setDefaultBackground(const Color4f& color) {
268  m_background = color;
269  }
270 
271  /**
272  * @brief Get the default background color
273  *
274  * @returns The current default background color
275  * @sa setDefaultBackground()
276  */
277  const Color4f& getDefaultBackground() const {
278  return m_background;
279  }
280 
281  /**
282  * @brief Set the default foreground color
283  *
284  * @param color The new foreground color
285  * @sa getDefaultForeground()
286  */
287  void setDefaultForeground(const Color4f& color) {
288  m_foreground = color;
289  }
290 
291  /**
292  * @brief Get the default foreground color
293  *
294  * @returns The current default foreground color
295  * @sa setDefaultForeground()
296  */
297  const Color4f& getDefaultForeground() const {
298  return m_foreground;
299  }
300 
301  /**
302  * @brief Clear the console
303  *
304  * For each cell of the console, this function:
305  * - sets the background color to the default background color
306  * - sets the foreground color to the default foreground color
307  * - sets the character to space (ASCII 32)
308  */
309  void clear();
310 
311  /**
312  * @brief Set the character background color
313  *
314  * @param position The position of the cell
315  * @param color The new background color
316  * @param effect The effect to apply to background
317  *
318  * @sa getCharBackground()
319  */
320  void setCharBackground(Vector2i position, const Color4f& color, ConsoleEffect effect = ConsoleEffect::Set);
321 
322  /**
323  * @brief Get the character background color
324  *
325  * @param position The position of the cell
326  * @returns The current character background color
327  *
328  * @sa setCharBackground()
329  */
330  const Color4f& getCharBackground(Vector2i position) const;
331 
332  /**
333  * @brief Set the character foreground color
334  *
335  * @param position The position of the cell
336  * @param color The new foreground color
337  *
338  * @sa getCharForeground()
339  */
340  void setCharForeground(Vector2i position, const Color4f& color);
341 
342  /**
343  * @brief Get the character foreground color
344  *
345  * @param position The position of the cell
346  * @returns The current character foreground color
347  *
348  * @sa setCharForeground()
349  */
350  const Color4f& getCharForeground(Vector2i position) const;
351 
352  /**
353  * @brief Set a character
354  *
355  * @param position The position of the cell
356  * @param c The character
357  *
358  * @sa putChar(), getChar()
359  */
360  void setChar(Vector2i position, char16_t c);
361 
362  /**
363  * @brief Get a character
364  *
365  * @param position The position of the cell
366  * @returns The current character at the position
367  *
368  * @sa setChar()
369  */
370  char16_t getChar(Vector2i position) const;
371 
372  /**
373  * @brief Modify a cell in the console
374  *
375  * At the specified position, this function:
376  * - sets the background color thanks to the effect and the default background color
377  * - sets the foreground color thanks to the default foreground color
378  * - sets the character to a new value
379  *
380  * @param position The position of the cell
381  * @param c The character to set
382  * @param effect The effect to apply to the background
383  */
384  void putChar(Vector2i position, char16_t c, ConsoleEffect effect = ConsoleEffect::Default);
385 
386  /**
387  * @brief Modify a cell in the console
388  *
389  * At the specified position, this function:
390  * - sets the background color to the specified color
391  * - sets the foreground color to the specified color
392  * - sets the character to a new value
393  *
394  * @param position The position of the cell
395  * @param c The character to set
396  * @param foreground The foreground color to set
397  * @param background The background color to set
398  */
399  void putChar(Vector2i position, char16_t c, const Color4f& foreground, const Color4f& background);
400 
401  /**
402  * @}
403  */
404 
405  /**
406  * @name String printing
407  * @{
408  */
409 
410  /**
411  * @brief Set the default console effect
412  *
413  * @param effect The new effect
414  *
415  * @sa getDefaultConsoleEffect()
416  */
418  if (!effect.isDefault()) {
419  m_effect = effect;
420  }
421  }
422 
423  /**
424  * @brief Get the default console effect
425  *
426  * @returns The current default console effect
427  *
428  * @sa setDefaultConsoleEffect()
429  */
431  return m_effect;
432  }
433 
434  /**
435  * @brief Set the default alignment
436  *
437  * @param alignment The new alignment
438  *
439  * @sa getDefaultAlignment()
440  */
442  m_alignment = alignment;
443  }
444 
445  /**
446  * @brief Get the default alignment
447  *
448  * @returns The current default alignment
449  *
450  * @sa setDefaultAlignment()
451  */
453  return m_alignment;
454  }
455 
456  /**
457  * @brief Print a formatted string
458  *
459  * This function uses the default values for background color, foreground
460  * color, console effect and alignment.
461  *
462  * The specified position indicates:
463  * - The first character of the string if the alignment is gf::ConsoleAlignment::Left
464  * - The center character of the string if the alignment is gf::ConsoleAlignment::Center
465  * - The last character of the string if the alignment is gf::ConsoleAlignment::Right
466  *
467  * @param position The position of a cell
468  * @param fmt The [format string](http://en.cppreference.com/w/cpp/io/c/fprintf)
469  */
470  void print(Vector2i position, const char *fmt, ...) GF_FORMAT(3, 4);
471 
472  /**
473  * @brief Print a formatted string
474  *
475  * This function uses the default values for background color, foreground
476  * color but uses the specified console effect and alignment.
477  *
478  * The specified position indicates:
479  * - The first character of the string if the alignment is gf::ConsoleAlignment::Left
480  * - The center character of the string if the alignment is gf::ConsoleAlignment::Center
481  * - The last character of the string if the alignment is gf::ConsoleAlignment::Right
482  *
483  * @param position The position of a cell
484  * @param effect The effect to apply to the background
485  * @param alignment The alignment of the text
486  * @param fmt The [format string](http://en.cppreference.com/w/cpp/io/c/fprintf)
487  */
488  void print(Vector2i position, ConsoleEffect effect, ConsoleAlignment alignment, const char *fmt, ...) GF_FORMAT(5, 6);
489 
490  /**
491  * @brief Print a multi-line formatted string
492  *
493  * The string is split in paragraphs according to new lines and then split
494  * in lines to fit the width of the specified rectangle. If the specified
495  * height is reached, the string is truncated. I the height is 0, then the
496  * string is truncated at the bottom of the console.
497  *
498  * @param rect The rectangle to print the string
499  * @param fmt The [format string](http://en.cppreference.com/w/cpp/io/c/fprintf)
500  * @returns The height in console lines of the printed string
501  */
502  int printRect(const RectI& rect, const char *fmt, ...) GF_FORMAT(3, 4);
503 
504  /**
505  * @brief Print a multi-line formatted string
506  *
507  * The string is split in paragraphs according to new lines and then split
508  * in lines to fit the width of the specified rectangle. If the specified
509  * height is reached, the string is truncated. I the height is 0, then the
510  * string is truncated at the bottom of the console.
511  *
512  * @param rect The rectangle to print the string
513  * @param effect The effect to apply to the background
514  * @param alignment The alignment of the text
515  * @param fmt The [format string](http://en.cppreference.com/w/cpp/io/c/fprintf)
516  * @returns The height in console lines of the printed string
517  */
518  int printRect(const RectI& rect, ConsoleEffect effect, ConsoleAlignment alignment, const char *fmt, ...) GF_FORMAT(5, 6);
519 
520  /**
521  * @brief Get the expected number of console lines of a multi-line formatted string
522  *
523  * This function does not print anything, it only computes the number of
524  * lines that a formatted string would take if it was printed with
525  * printRect()
526  *
527  * @param rect The rectangle to print the string
528  * @param fmt The [format string](http://en.cppreference.com/w/cpp/io/c/fprintf)
529  *
530  * @sa printRect()
531  */
532  int getHeight(const RectI& rect, const char *fmt, ...) GF_FORMAT(3, 4);
533 
534  /**
535  * @brief Set a color for color control
536  *
537  * Color control codes allow to change color in a string on the fly. There
538  * are five color control codes: gf::ConsoleColorControl1,
539  * gf::ConsoleColorControl2, gf::ConsoleColorControl3,
540  * gf::ConsoleColorControl4 and gf::ConsoleColorControl5. Each one is
541  * associated with a foreground and a background color that you can set
542  * with this function. The color control code gf::ConsoleColorControlStop
543  * changes the colors back to their default.
544  *
545  * ~~~{.cc}
546  * gf::Console console(font, size);
547  * // A string with a red over black word, using predefined color control codes
548  * console.setColorControl(gf::ConsoleColorControl1, gf::Color::Red, gf::Color::Black);
549  * console.print({ 1, 1 }, "String with a %cred%c word.", gf::ConsoleColorControl1, gf::ConsoleColorControlStop);
550  * ~~~
551  */
552  void setColorControl(ConsoleColorControl ctrl, const Color4f& foreground, const Color4f& background);
553 
554  /**
555  * @}
556  */
557 
558  /**
559  * @name Advanced printing
560  * @{
561  */
562 
563  /**
564  * @brief Draw a filled rectangle
565  *
566  * This function fills the specified rectangle with the default background
567  * color. If the print action is gf::PrintAction::Clear, then the
568  * characters inside the rectangle are set to space (ASCII 32).
569  *
570  * @param rect The rectangle to print the rectangle
571  * @param action The action when drawing
572  * @param effect The effect to apply to the background
573  */
574  void drawRectangle(const RectI& rect, PrintAction action = PrintAction::None, ConsoleEffect effect = ConsoleEffect::Default);
575 
576  /**
577  * @brief Draw a horizontal line
578  *
579  * This function draws a horizontal line using gf::SpecialChar::WallHorizontalLine.
580  *
581  * @param left The left end point of the line
582  * @param width The width of the line
583  * @param effect The effect to apply to the background
584  */
585  void drawHorizontalLine(Vector2i left, int width, ConsoleEffect effect = ConsoleEffect::Default);
586 
587  /**
588  * @brief Draw a vertical line
589  *
590  * This function draws a vertical line using gf::SpecialChar::WallVerticalLine.
591  *
592  * @param top The top end point of the line
593  * @param height The height of the line
594  * @param effect The effect to apply to the background
595  */
596  void drawVerticalLine(Vector2i top, int height, ConsoleEffect effect = ConsoleEffect::Default);
597 
598  /**
599  * @brief Draw a frame
600  *
601  * This funtion first draws a rectangle using the specified action and
602  * effect. Then it draws a frame. If a title is given, it is printed on the
603  * top of the frame with inverted colors.
604  *
605  * @param rect The rectangle to print the rectangle
606  * @param action The action when drawing
607  * @param effect The effect to apply to the background
608  * @param title The [format string](http://en.cppreference.com/w/cpp/io/c/fprintf) of the title
609  */
610  void drawFrame(const RectI& rect, PrintAction action = PrintAction::None, ConsoleEffect effect = ConsoleEffect::Default, const char *title = nullptr, ...) GF_FORMAT(5, 6);
611 
612  /**
613  * @}
614  */
615 
616  /**
617  * @name Screen fading
618  * @{
619  */
620 
621  /**
622  * @brief Set the fading parameters
623  *
624  * @param amount The fading amount, with 0 meaning the fading color and 1 meaning no fading
625  * @param color The fading color
626  */
627  void setFade(float amount, const Color4f& color) {
628  m_fadingAmount = amount;
629  m_fadingColor = color;
630  }
631 
632  /**
633  * @brief Get the fading amount
634  *
635  * @returns The current fading amount
636  */
637  float getFadingAmount() const {
638  return m_fadingAmount;
639  }
640 
641  /**
642  * @brief Get the fading color
643  *
644  * @returns The current fading color
645  */
646  const Color4f& getFadingColor() const {
647  return m_fadingColor;
648  }
649 
650  /**
651  * @}
652  */
653 
654  /**
655  * @brief Blit a console on another console
656  *
657  * @param src The source rectangle on the source console
658  * @param con The destination console
659  * @param dst The destination position on the destination console
660  * @param foregroundAlpha The alpha of the blitted console foreground color, 0 is a completely transparent source console and 1 is a completely opaque source console
661  * @param backgroundAlpha The alpha of the blitted console background color, 0 is a completely transparent source console and 1 is a completely opaque source console
662  */
663  void blit(const RectI& src, Console& con, Vector2i dst, float foregroundAlpha = 1.0f, float backgroundAlpha = 1.0f) const;
664 
665  virtual void draw(RenderTarget& target, RenderStates states) override;
666 
667  private:
668  Color4f computeColor(ConsoleEffect effect, const Color4f& existing, const Color4f& current);
669 
670  int putWord(Vector2i position, ConsoleEffect effect, const std::u32string& message, const Color4f& foreground, const Color4f& background);
671 
672  enum class PrintOption {
673  Split = 0x01,
674  CountOnly = 0x02,
675  };
676 
677  using PrintOptionFlags = Flags<PrintOption>;
678 
679  int printInternal(const RectI& rect, ConsoleEffect effect, ConsoleAlignment alignment, const std::string& message, PrintOptionFlags flags = None);
680 
681  private:
682  struct Cell {
683  Color4f fg;
684  Color4f bg;
685  char16_t c;
686  };
687 
688  const ConsoleFont *m_font;
689  Array2D<Cell, int> m_data;
690  Color4f m_background;
691  Color4f m_foreground;
692 
693  ConsoleEffect m_effect;
694  ConsoleAlignment m_alignment;
695 
696  struct ColorControl {
697  Color4f fg;
698  Color4f bg;
699  };
700 
701  static constexpr char ColorControlCount = 5;
702  ColorControl m_controls[ColorControlCount];
703 
704  float m_fadingAmount;
705  Color4f m_fadingColor;
706  };
707 
708 #ifndef DOXYGEN_SHOULD_SKIP_THIS
709 }
710 #endif
711 }
712 
713 #endif // GF_CONSOLE_H
Decomposed transform defined by a position, a rotation and a scale.
Definition: Transformable.h:95
Definition: Console.h:144
PrintAction
An action when printing.
Definition: Console.h:229
const Color4f & getDefaultForeground() const
Get the default foreground color.
Definition: Console.h:297
void setDefaultForeground(const Color4f &color)
Set the default foreground color.
Definition: Console.h:287
A two-dimensional array.
Definition: Array2D.h:63
Kind
The kind of console effect.
Definition: Console.h:132
void setDefaultConsoleEffect(ConsoleEffect effect)
Set the default console effect.
Definition: Console.h:417
A virtual console.
Definition: Console.h:224
int printRect(const RectI &rect, ConsoleEffect effect, ConsoleAlignment alignment, const char *fmt,...)
Print a multi-line formatted string.
constexpr ConsoleColorControl ConsoleColorControlStop
The constant for color control stop.
Definition: Console.h:110
Definition: Console.h:135
constexpr ConsoleEffect(Kind kind)
Constructor with a kind only.
Definition: Console.h:157
Console(const ConsoleFont &font, Vector2i size)
Constructor.
Definition: Console.h:143
Base class for all render targets (window, texture, ...)
Definition: RenderTarget.h:66
Define the states used for drawing to a RenderTarget.
Definition: RenderStates.h:82
int getHeight(const RectI &rect, const char *fmt,...)
Get the expected number of console lines of a multi-line formatted string.
Bitfield relying on an enumeration.
Definition: Flags.h:68
const Color4f & getFadingColor() const
Get the fading color.
Definition: Console.h:646
void drawHorizontalLine(Vector2i left, int width, ConsoleEffect effect=ConsoleEffect::Default)
Draw a horizontal line.
constexpr ConsoleColorControl ConsoleColorControl3
The constant for color control #3.
Definition: Console.h:86
constexpr ConsoleEffect(Kind kind, float alpha)
Constructor with a kind and .
Definition: Console.h:173
void drawFrame(const RectI &rect, PrintAction action=PrintAction::None, ConsoleEffect effect=ConsoleEffect::Default, const char *title=nullptr,...)
Draw a frame.
void print(Vector2i position, const char *fmt,...)
Print a formatted string.
void print(Vector2i position, ConsoleEffect effect, ConsoleAlignment alignment, const char *fmt,...)
Print a formatted string.
constexpr ConsoleColorControl ConsoleColorControl5
The constant for color control #5.
Definition: Console.h:102
Centered alignment.
void setCharBackground(Vector2i position, const Color4f &color, ConsoleEffect effect=ConsoleEffect::Set)
Set the character background color.
constexpr ConsoleColorControl ConsoleColorControl2
The constant for color control #2.
Definition: Console.h:78
Definition: Console.h:140
void setChar(Vector2i position, char16_t c)
Set a character.
Use the default console effect.
Definition: Console.h:146
constexpr float getAlpha() const noexcept
Get the alpha value.
Definition: Console.h:197
Definition: Console.h:139
constexpr bool isDefault() const noexcept
Check if the effect if Console::Default.
Definition: Console.h:190
void setFade(float amount, const Color4f &color)
Set the fading parameters.
Definition: Console.h:627
Definition: Console.h:145
void setCharForeground(Vector2i position, const Color4f &color)
Set the character foreground color.
void drawVerticalLine(Vector2i top, int height, ConsoleEffect effect=ConsoleEffect::Default)
Draw a vertical line.
Definition: Console.h:137
const Color4f & getCharForeground(Vector2i position) const
Get the character foreground color.
ConsoleAlignment
The alignment of the text in the console.
Definition: Console.h:50
Definition: Console.h:138
Do not change the background color.
Definition: Console.h:133
The namespace for gf classes.
Definition: Action.h:34
ConsoleEffect getDefaultConsoleEffect() const
Get the default console effect.
Definition: Console.h:430
virtual void draw(RenderTarget &target, RenderStates states) override
Draw the object to a render target.
char16_t getChar(Vector2i position) const
Get a character.
void clear()
Clear the console.
constexpr ConsoleColorControl ConsoleColorControl1
The constant for color control #1.
Definition: Console.h:70
Fill the area with space characters.
constexpr ConsoleColorControl ConsoleColorControl4
The constant for color control #4.
Definition: Console.h:94
Definition: Console.h:141
void setDefaultBackground(const Color4f &color)
Set the default background color.
Definition: Console.h:267
float getFadingAmount() const
Get the fading amount.
Definition: Console.h:637
Definition: Console.h:136
void blit(const RectI &src, Console &con, Vector2i dst, float foregroundAlpha=1.0f, float backgroundAlpha=1.0f) const
Blit a console on another console.
A console font.
Definition: ConsoleFont.h:110
Definition: Console.h:142
Definition: Console.h:134
int printRect(const RectI &rect, const char *fmt,...)
Print a multi-line formatted string.
A console effect on the background color.
Definition: Console.h:126
ConsoleAlignment getDefaultAlignment() const
Get the default alignment.
Definition: Console.h:452
void setColorControl(ConsoleColorControl ctrl, const Color4f &foreground, const Color4f &background)
Set a color for color control.
constexpr Kind getKind() const noexcept
Get the kind of effect.
Definition: Console.h:183
#define GF_API
Definition: Portability.h:35
void setDefaultAlignment(ConsoleAlignment alignment)
Set the default alignment.
Definition: Console.h:441
int getHeight() const
Get the height of the console.
Definition: Console.h:252
const Color4f & getDefaultBackground() const
Get the default background color.
Definition: Console.h:277
const Color4f & getCharBackground(Vector2i position) const
Get the character background color.
int getWidth() const
Get the width of the console.
Definition: Console.h:245
#define GF_FORMAT(X, Y)
Definition: Portability.h:42
void putChar(Vector2i position, char16_t c, const Color4f &foreground, const Color4f &background)
Modify a cell in the console.
void drawRectangle(const RectI &rect, PrintAction action=PrintAction::None, ConsoleEffect effect=ConsoleEffect::Default)
Draw a filled rectangle.
void putChar(Vector2i position, char16_t c, ConsoleEffect effect=ConsoleEffect::Default)
Modify a cell in the console.