Advertisement
shiretu

Untitled

May 12th, 2024
831
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.79 KB | None | 0 0
  1. #pragma once
  2.  
  3. #include "raylib.h"
  4. #include "utils/displays/concept.hpp"
  5. #include <string>
  6.  
  7. namespace trader {
  8. namespace utils {
  9. namespace displays {
  10. namespace ray {
  11.  
  12. struct ray_system {
  13.     static constexpr size_t kLog2BoCount = 2;
  14.     static constexpr size_t kBoCount = 1 << kLog2BoCount;
  15.     static constexpr size_t kBoCountMask = kBoCount - 1;
  16.     static constexpr size_t kFontSize{16};
  17.     static constexpr size_t kFontHeight1{kFontSize};
  18.     static constexpr size_t kOptimalDepth{40};
  19.     static constexpr size_t kRowWidth{300};
  20.     static constexpr size_t kWindowWidth{std::min(kRowWidth * kBoCount, size_t{3000})};
  21.     static constexpr size_t kWindowHeight{(kOptimalDepth * 2 + 1) * kFontHeight1 + 10};
  22.     Font _fontTtf;
  23.     RenderTexture2D _target;
  24.     ray_system() {
  25.         InitWindow(kWindowWidth, kWindowHeight, "");
  26.         _fontTtf = LoadFont("/Users/shiretu/Downloads/Courier New.ttf");
  27.         _target = LoadRenderTexture(kWindowWidth, kWindowHeight);
  28.         BeginTextureMode(_target);
  29.         ClearBackground(BLACK);
  30.         EndTextureMode();
  31.     }
  32.     ~ray_system() { CloseWindow(); }
  33. };
  34.  
  35. static inline ray_system gSystem;
  36.  
  37. struct base {
  38.     using color_type = Color;
  39.     static constexpr size_t kOptimalDepth{ray_system::kOptimalDepth};
  40.     static constexpr color_type kColorBackground{BLACK};
  41.     static constexpr color_type kColorWhite{WHITE};
  42.     static constexpr color_type kColorRed{RED};
  43.     static constexpr color_type kColorYellow{YELLOW};
  44.     static constexpr color_type kColorGreen{GREEN};
  45.     void render_text_internal(const size_t windowIdx, const size_t lineIdx, auto&& color, auto&& text) {
  46.         const float x = windowIdx * ray_system::kRowWidth;
  47.         const float y = lineIdx * ray_system::kFontHeight1;
  48.         DrawTextEx(gSystem._fontTtf, text.c_str(), Vector2{x, y}, ray_system::kFontSize, 0, color);
  49.     }
  50. };
  51.  
  52. struct single_window : base {
  53.     void start_screen_render() {}
  54.     void start_window_render(const size_t windowIdx, auto&& title) {
  55.         BeginTextureMode(gSystem._target);
  56.         DrawRectangle(windowIdx * ray_system::kRowWidth, 0, ray_system::kRowWidth, ray_system::kWindowHeight, kColorBackground);
  57.         render_text_internal(windowIdx, 0, kColorWhite, std::forward<decltype(title)>(title));
  58.     }
  59.     void render_text(const size_t windowIdx, const size_t lineIdx, auto&& color, auto&& text) {
  60.         render_text_internal(windowIdx, lineIdx + 1, std::forward<decltype(color)>(color), std::forward<decltype(text)>(text));
  61.     }
  62.     void end_window_render(const size_t windowIdx) {
  63.         EndTextureMode();
  64.         BeginDrawing();
  65.         DrawTextureRec(
  66.             gSystem._target.texture, Rectangle{0, 0, (float)gSystem._target.texture.width, (float)-gSystem._target.texture.height}, Vector2{0, 0}, WHITE);
  67.         EndDrawing();
  68.     }
  69.     void end_screen_render() {}
  70. };
  71.  
  72. static_assert(display<single_window>, "Not a display");
  73.  
  74. } // namespace ray
  75. } // namespace displays
  76. } // namespace utils
  77. } // namespace trader
  78.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement