MXVK Vulkan Framework 0.24.0
C++20 Vulkan rendering framework for practical 2D and 3D application development with SDL3.
Loading...
Searching...
No Matches
mxvk_io_window.cpp
Go to the documentation of this file.
2
3#include <format>
4
5namespace mxvk {
6
7 VK_IOWindow::VK_IOWindow(const std::string &path, const std::string &title, const int width, const int height, const bool fullscreen, const bool enableVsync) : mxvk::VK_Window(title, width, height, fullscreen, MXVK_VALIDATION, enableVsync) {
8 const std::string base_path = path;
9 console.attach(*this, base_path + "/data/font.ttf", 20);
10 console.setSpriteYOriginTopLeft(true);
11 console.setPrompt("$> ");
12 console.printLine("Press F3 to open/close the console.");
13 console.printLine("Type 'help' for built-in commands.");
14 console.setCommandCallback([this](mxvk::VK_Window &, const std::vector<std::string> &args, std::ostream &out) {
15 if (args.empty()) {
16 return true;
17 }
18
19 if (args[0] == "help") {
20 out << "Built-in commands:\n"
21 << " help Show this help message\n"
22 << " clear Clear the console output\n"
23 << " echo <text> Print text to the console\n"
24 << " about Show sample/about information\n"
25 << " quit | exit Close the current window";
27 return true;
28 }
29
30 if (args[0] == "echo") {
31 for (std::size_t i = 1; i < args.size(); ++i) {
32 if (i > 1) {
33 out << ' ';
34 }
35 out << args[i];
36 }
37 return true;
38 }
39
40 if (args[0] == "quit" || args[0] == "exit") {
41 out << "Closing window...";
42 exit();
43 return true;
44 }
45
46 if (args[0] == "about") {
47 out << "console_demo: MXVK Vulkan console sample.\n(C) 2026 LostSideDead Software\n";
48 return true;
49 }
50
51 if (handleConsoleCommand(args, out)) {
52 return true;
53 }
54
55 return false;
56 });
57 }
58
59 bool VK_IOWindow::handleConsoleCommand([[maybe_unused]] const std::vector<std::string> &args,
60 [[maybe_unused]] std::ostream &out) {
61 return false;
62 }
63
64 void VK_IOWindow::appendConsoleHelp([[maybe_unused]] std::ostream &out) const {
65 }
66
67 void VK_IOWindow::event(SDL_Event &e) {
68 const bool is_escape_down = (e.type == SDL_EVENT_KEY_DOWN && e.key.key == SDLK_ESCAPE);
69 const bool was_console_visible = console.isVisible();
70 if (is_escape_down && was_console_visible && SDL_GetWindowRelativeMouseMode(getSDLWindow())) {
72 return;
73 }
74
75 console.handleEvent(e);
76
77 if (is_escape_down && was_console_visible && !console.isVisible()) {
78 return;
79 }
80
81 if (console.isVisible()) {
82 return;
83 }
84
86 }
87
88 void VK_IOWindow::print(const std::string &text, SDL_Color col) {
89 console.printLine(text, col);
90 }
91
94 console.draw();
95 }
96
97} // namespace mxvk
virtual void appendConsoleHelp(std::ostream &out) const
Append app-specific help lines to the console help output.
virtual void console_event(SDL_Event &e)=0
virtual void console_proc()=0
virtual bool handleConsoleCommand(const std::vector< std::string > &args, std::ostream &out)
Handle app-specific console commands.
void event(SDL_Event &e) override
Handle one SDL event.
void print(const std::string &text, SDL_Color col={255, 255, 255, 255})
void proc() override
Execute one processing/update step.
VK_IOWindow(const std::string &path, const std::string &title, const int width, const int height, const bool fullscreen, const bool enableVsync=false)
Main Vulkan window wrapper for MXVK.
Definition mxvk.hpp:37
SDL_Window * getSDLWindow() const noexcept
Get the underlying SDL window handle.
Definition mxvk.hpp:165
void exit()
Request loop termination.
Definition mxvk.cpp:1126
VK_Window()=default
Construct an empty window object.
#define MXVK_VALIDATION
Definition mxvk.hpp:27
Utilities for loading and saving PNG images.
Definition mxvk.hpp:30