Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma once
- #include "raylib.h"
- #include "utils/displays/concept.hpp"
- #include <string>
- namespace trader {
- namespace utils {
- namespace displays {
- namespace ray {
- struct ray_system {
- static constexpr size_t kLog2BoCount = 2;
- static constexpr size_t kBoCount = 1 << kLog2BoCount;
- static constexpr size_t kBoCountMask = kBoCount - 1;
- static constexpr size_t kFontSize{16};
- static constexpr size_t kFontHeight1{kFontSize};
- static constexpr size_t kOptimalDepth{40};
- static constexpr size_t kRowWidth{300};
- static constexpr size_t kWindowWidth{std::min(kRowWidth * kBoCount, size_t{3000})};
- static constexpr size_t kWindowHeight{(kOptimalDepth * 2 + 1) * kFontHeight1 + 10};
- Font _fontTtf;
- RenderTexture2D _target;
- ray_system() {
- InitWindow(kWindowWidth, kWindowHeight, "");
- _fontTtf = LoadFont("/Users/shiretu/Downloads/Courier New.ttf");
- _target = LoadRenderTexture(kWindowWidth, kWindowHeight);
- BeginTextureMode(_target);
- ClearBackground(BLACK);
- EndTextureMode();
- }
- ~ray_system() { CloseWindow(); }
- };
- static inline ray_system gSystem;
- struct base {
- using color_type = Color;
- static constexpr size_t kOptimalDepth{ray_system::kOptimalDepth};
- static constexpr color_type kColorBackground{BLACK};
- static constexpr color_type kColorWhite{WHITE};
- static constexpr color_type kColorRed{RED};
- static constexpr color_type kColorYellow{YELLOW};
- static constexpr color_type kColorGreen{GREEN};
- void render_text_internal(const size_t windowIdx, const size_t lineIdx, auto&& color, auto&& text) {
- const float x = windowIdx * ray_system::kRowWidth;
- const float y = lineIdx * ray_system::kFontHeight1;
- DrawTextEx(gSystem._fontTtf, text.c_str(), Vector2{x, y}, ray_system::kFontSize, 0, color);
- }
- };
- struct single_window : base {
- void start_screen_render() {}
- void start_window_render(const size_t windowIdx, auto&& title) {
- BeginTextureMode(gSystem._target);
- DrawRectangle(windowIdx * ray_system::kRowWidth, 0, ray_system::kRowWidth, ray_system::kWindowHeight, kColorBackground);
- render_text_internal(windowIdx, 0, kColorWhite, std::forward<decltype(title)>(title));
- }
- void render_text(const size_t windowIdx, const size_t lineIdx, auto&& color, auto&& text) {
- render_text_internal(windowIdx, lineIdx + 1, std::forward<decltype(color)>(color), std::forward<decltype(text)>(text));
- }
- void end_window_render(const size_t windowIdx) {
- EndTextureMode();
- BeginDrawing();
- DrawTextureRec(
- gSystem._target.texture, Rectangle{0, 0, (float)gSystem._target.texture.width, (float)-gSystem._target.texture.height}, Vector2{0, 0}, WHITE);
- EndDrawing();
- }
- void end_screen_render() {}
- };
- static_assert(display<single_window>, "Not a display");
- } // namespace ray
- } // namespace displays
- } // namespace utils
- } // namespace trader
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement