-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28 from BeomJinNa/main
Enhance renderer functionality and input delay settings
- Loading branch information
Showing
11 changed files
with
222 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
#include "ColorManager.h" | ||
|
||
ColorManager::ColorManager() | ||
: mRandomEngine(std::random_device{}()) | ||
{ | ||
} | ||
|
||
void ColorManager::AddColorToTable(ConsoleColor color) | ||
{ | ||
auto it = std::find(mColorTable.begin(), mColorTable.end(), color); | ||
|
||
if (it == mColorTable.end()) | ||
{ | ||
mColorTable.push_back(color); | ||
} | ||
} | ||
|
||
void ColorManager::RemoveColorFromTable(ConsoleColor color) | ||
{ | ||
auto it = std::find(mColorTable.begin(), mColorTable.end(), color); | ||
|
||
if (it != mColorTable.end()) | ||
{ | ||
mColorTable.erase(it); | ||
} | ||
} | ||
|
||
void ColorManager::ClearColors() | ||
{ | ||
mColorTable.clear(); | ||
} | ||
|
||
void ColorManager::AddAllColors() | ||
{ | ||
for (int i = 0; i <= static_cast<int>(ConsoleColor::BrightWhite); ++i) | ||
{ | ||
AddColorToTable(static_cast<ConsoleColor>(i)); | ||
} | ||
} | ||
|
||
void ColorManager::AddBrightColors() | ||
{ | ||
AddColorToTable(ConsoleColor::BrightBlue); | ||
AddColorToTable(ConsoleColor::BrightGreen); | ||
AddColorToTable(ConsoleColor::BrightRed); | ||
AddColorToTable(ConsoleColor::BrightCyan); | ||
AddColorToTable(ConsoleColor::BrightMagenta); | ||
AddColorToTable(ConsoleColor::BrightYellow); | ||
AddColorToTable(ConsoleColor::BrightWhite); | ||
} | ||
|
||
void ColorManager::AddDarkColors() | ||
{ | ||
AddColorToTable(ConsoleColor::Black); | ||
AddColorToTable(ConsoleColor::Blue); | ||
AddColorToTable(ConsoleColor::Green); | ||
AddColorToTable(ConsoleColor::Red); | ||
AddColorToTable(ConsoleColor::Cyan); | ||
AddColorToTable(ConsoleColor::Magenta); | ||
AddColorToTable(ConsoleColor::Yellow); | ||
AddColorToTable(ConsoleColor::White); | ||
} | ||
|
||
ConsoleColor ColorManager::GetRandomColor() const | ||
{ | ||
if (mColorTable.empty()) | ||
{ | ||
return ConsoleColor::BrightWhite; | ||
} | ||
std::uniform_int_distribution<size_t> dist(0, mColorTable.size() - 1); | ||
return mColorTable[dist(mRandomEngine)]; | ||
} | ||
|
||
WORD ColorManager::ToWord(ConsoleColor fg, ConsoleColor bg) | ||
{ | ||
return static_cast<WORD>(fg) | (static_cast<WORD>(bg) << 4); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#pragma once | ||
|
||
#include "ConsoleColor.h" | ||
#include <vector> | ||
#include <random> | ||
|
||
class ColorManager | ||
{ | ||
public: | ||
ColorManager(); | ||
~ColorManager() = default; | ||
|
||
void AddColorToTable(ConsoleColor color); | ||
void RemoveColorFromTable(ConsoleColor color); | ||
void ClearColors(); | ||
void AddAllColors(); | ||
void AddBrightColors(); | ||
void AddDarkColors(); | ||
|
||
ConsoleColor GetRandomColor() const; | ||
|
||
static WORD ToWord(ConsoleColor fg, ConsoleColor bg = ConsoleColor::Black); | ||
|
||
private: | ||
std::vector<ConsoleColor> mColorTable; | ||
mutable std::mt19937 mRandomEngine; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.