Advertisement
Guest User

Untitled

a guest
Aug 2nd, 2022
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.98 KB | None | 0 0
  1. #include <fstream>
  2. #include <iostream>
  3. #include <nlohmann/json.hpp>
  4. #include <string>
  5.  
  6.  
  7. namespace fallow
  8. {
  9.     namespace video
  10.     {
  11.         class WindowLayout
  12.         {
  13.         public:
  14.             std::pair<int, int> getPosition() const { return windowPos; }
  15.             std::pair<int, int> getSize() const { return windowSize; }
  16.             std::string         getTitle() const { return windowTitle; }
  17.             std::uint32_t       getFlags() const { return windowFlags; }
  18.  
  19.             /**
  20.              * @brief Set the Position object
  21.              *
  22.              * @param [in] newPos New window position x and y coordinates. Support only integer values
  23.              */
  24.             void setPosition(const std::pair<int, int>& newPos) { windowPos = newPos; }
  25.             /**
  26.              * @brief Set the Size object
  27.              *
  28.              * @param [in] newSize New window size.
  29.              */
  30.             void setSize(const std::pair<int, int>& newSize) { windowSize = newSize; }
  31.             /**
  32.              * @brief Set the Title object
  33.              *
  34.              * @param [in] newTitle The new window title.
  35.              */
  36.             void setTitle(const std::string& newTitle) { windowTitle = newTitle; }
  37.             /**
  38.              * @brief Set the Flags object for Window
  39.              *
  40.              * @param [in] newFlags This param should contain all flags what you want to set. Example : Fullscreen |
  41.              * Resizable
  42.              */
  43.             void setFlags(std::uint32_t newFlags) { windowFlags = newFlags; }
  44.  
  45.             void buildLayout(std::pair<int, int> pos   = {0, 0},
  46.                              std::pair<int, int> size  = {1920, 1080},
  47.                              const std::string&  title = "Engine",
  48.                              std::uint32_t       flags = {0})
  49.             {
  50.                 windowPos   = pos;
  51.                 windowSize  = size;
  52.                 windowTitle = std::move(title);
  53.                 windowFlags = flags;
  54.             }
  55.  
  56.             void buildLayout(const std::pair<int, int>& pos,
  57.                              const std::pair<int, int>& size,
  58.                              const std::string&         title,
  59.                              std::uint32_t              flags)
  60.             {
  61.                 windowPos   = pos;
  62.                 windowSize  = size;
  63.                 windowTitle = title;
  64.                 windowFlags = flags;
  65.             }
  66.  
  67.         private:
  68.             std::pair<int, int> windowPos;  // first - xPosition | second - yPosition
  69.             std::pair<int, int> windowSize; // first - width | second - height
  70.             std::string         windowTitle;
  71.             std::uint32_t       windowFlags;
  72.  
  73.         public:
  74.             NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(WindowLayout,
  75.                                                             windowPos,
  76.                                                             windowSize,
  77.                                                             windowTitle,
  78.                                                             windowFlags);
  79.         };
  80.     } // namespace video
  81. } // namespace fallow
  82.  
  83.  
  84. int main(int, char**)
  85. {
  86.     std::ofstream stream("C:\\Users\\Sakhil Kuliev\\source\\repos\\Serializator\\log.json");
  87.     // std::ifstream istream("C:\\Users\\Sakhil Kuliev\\source\\repos\\Serializator\\log.json");
  88.  
  89.     fallow::video::WindowLayout window;
  90.     window.buildLayout();
  91.  
  92.     nlohmann::json data;
  93.     window.to_json(data, window);
  94.     stream << std::setw(4) << data;
  95.  
  96.     // nlohmann::json data = nlohmann::json::parse(istream);
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement