Skip to content

Commit a2b8ee3

Browse files
committed
add gf::ConsoleStyle and remove internal default style from gf::Console
1 parent f51e77d commit a2b8ee3

File tree

6 files changed

+132
-278
lines changed

6 files changed

+132
-278
lines changed

TODO.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ This file is a list of ideas for gf. Some of them will eventually be in gf. Othe
2424
- (scene) integrate post-processing in `Scene`/`SceneManager`
2525
- remove `RenderPipeline`
2626
- rename `Effect` in `PostProcEffect`
27-
- (console) make style a class and remove internal style state
2827
- (drawable) Remove `Drawable`, make it a named requirement (or a concept in the future)
2928

3029
## net

docs/snippets/doc_class_console.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@ void dummyConsoleUsage(gf::ConsoleFont& font) {
2828
/// [console]
2929
gf::Console console(font, size);
3030
// A string with a red over black word, using predefined color control codes
31+
gf::ConsoleStyle style;
3132
console.setColorControl(gf::ConsoleColorControl1, gf::Color::Red, gf::Color::Black);
32-
console.print({ 1, 1 }, "String with a %cred%c word.", gf::ConsoleColorControl1, gf::ConsoleColorControlStop);
33+
console.print({ 1, 1 }, style, "String with a %cred%c word.", gf::ConsoleColorControl1, gf::ConsoleColorControlStop);
3334
/// [console]
3435

3536
gf::unused(console);

examples/27_console.cc

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,11 @@
3131
#include <gf/Window.h>
3232

3333
int main() {
34+
static constexpr float Scale = 2.0f;
3435
static constexpr gf::Vector2i CharacterSize(12, 12);
3536
static constexpr gf::Vector2i ConsoleSize(80, 50);
3637

37-
const gf::Vector2i ScreenSize = CharacterSize * ConsoleSize;
38+
const gf::Vector2i ScreenSize = CharacterSize * ConsoleSize * Scale;
3839

3940
gf::Window window("27_console", ScreenSize, ~gf::WindowHints::Resizable);
4041
gf::RenderWindow renderer(window);
@@ -48,27 +49,35 @@ int main() {
4849
gf::BitmapConsoleFont font("assets/terminal.png", { gf::ConsoleFontFormat::Grayscale, gf::ConsoleFontFormat::InRow, gf::ConsoleFontFormat::ModifiedCodePage437 });
4950
assert(CharacterSize == font.getCharacterSize());
5051

52+
gf::ConsoleStyle style;
53+
style.background = gf::Color::Gray(0.25f);
54+
5155
gf::Console console(font, ConsoleSize);
52-
console.setDefaultBackground(gf::Color::Gray(0.25f));
5356

54-
console.putChar({ 40, 25 }, '@');
55-
console.putChar({ 42, 25 }, gf::ConsoleChar::WhiteSmilingFace);
57+
console.putChar({ 40, 25 }, '@', style);
58+
console.putChar({ 42, 25 }, gf::ConsoleChar::WhiteSmilingFace, style);
5659

5760
console.setColorControl(gf::ConsoleColorControl1, gf::Color::Red, gf::Color::Black);
58-
console.print({ 1, 1 }, "String with a %cred%c word.", gf::ConsoleColorControl1, gf::ConsoleColorControlStop);
61+
console.print({ 1, 1 }, style, "String with a %cred%c word.", gf::ConsoleColorControl1, gf::ConsoleColorControlStop);
5962

63+
style.alignment = gf::ConsoleAlignment::Right;
6064
console.setColorControl(gf::ConsoleColorControl2, gf::Color::Orange, gf::Color::Azure);
61-
console.print(ConsoleSize - 2, gf::ConsoleEffect::Set, gf::ConsoleAlignment::Right, "Made with %cgf%c!", gf::ConsoleColorControl2, gf::ConsoleColorControlStop);
65+
console.print(ConsoleSize - 2, style, "Made with %cgf%c!", gf::ConsoleColorControl2, gf::ConsoleColorControlStop);
6266

6367
console.setColorControl(gf::ConsoleColorControl3, gf::Color::Black, gf::Color::Yellow);
6468
const char *text = "This is a simple but long text with %cmultiple%c lines.";
6569

66-
console.printRect(gf::RectI::fromPositionSize({ 2, 5 }, { 16, 5 }), gf::ConsoleEffect::Set, gf::ConsoleAlignment::Left, text, gf::ConsoleColorControl3, gf::ConsoleColorControlStop);
67-
console.printRect(gf::RectI::fromPositionSize({ 2, 15 }, { 16, 5 }), gf::ConsoleEffect::Set, gf::ConsoleAlignment::Center, text, gf::ConsoleColorControl3, gf::ConsoleColorControlStop);
68-
console.printRect(gf::RectI::fromPositionSize({ 2, 25 }, { 16, 5 }), gf::ConsoleEffect::Set, gf::ConsoleAlignment::Right, text, gf::ConsoleColorControl3, gf::ConsoleColorControlStop);
70+
style.alignment = gf::ConsoleAlignment::Left;
71+
console.printRect(gf::RectI::fromPositionSize({ 2, 5 }, { 16, 5 }), style, text, gf::ConsoleColorControl3, gf::ConsoleColorControlStop);
72+
style.alignment = gf::ConsoleAlignment::Center;
73+
console.printRect(gf::RectI::fromPositionSize({ 2, 15 }, { 16, 5 }), style, text, gf::ConsoleColorControl3, gf::ConsoleColorControlStop);
74+
style.alignment = gf::ConsoleAlignment::Right;
75+
console.printRect(gf::RectI::fromPositionSize({ 2, 25 }, { 16, 5 }), style, text, gf::ConsoleColorControl3, gf::ConsoleColorControlStop);
76+
77+
console.drawFrame(gf::RectI::fromPositionSize({ 30, 5 }, { 16, 5 }), style);
78+
console.drawFrame(gf::RectI::fromPositionSize({ 30, 15 }, { 16, 5 }), style, gf::Console::PrintAction::None, "Frame title");
6979

70-
console.drawFrame(gf::RectI::fromPositionSize({ 30, 5 }, { 16, 5 }));
71-
console.drawFrame(gf::RectI::fromPositionSize({ 30, 15 }, { 16, 5 }), gf::Console::PrintAction::None, gf::ConsoleEffect::Set, "Frame title");
80+
console.scale(Scale);
7281

7382
renderer.clear(gf::Color::White);
7483

0 commit comments

Comments
 (0)