-
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: move mce::Color into separate source file
- Loading branch information
1 parent
a49bb23
commit 08a4940
Showing
4 changed files
with
46 additions
and
28 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 |
---|---|---|
|
@@ -15,6 +15,6 @@ | |
#pragma once | ||
|
||
struct IntRange { | ||
int min; | ||
int max; | ||
int range_min; | ||
int range_max; | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Copyright (c) 2024, The Endstone Project. (https://endstone.dev) All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#include "bedrock/core/math/color.h" | ||
|
||
std::string mce::Color::toHexString() const | ||
{ | ||
std::stringstream stream; | ||
stream << "#" << std::setfill('0') << std::hex // | ||
<< std::setw(2) << static_cast<int>(r * 255) // | ||
<< std::setw(2) << static_cast<int>(g * 255) // | ||
<< std::setw(2) << static_cast<int>(b * 255) // | ||
<< std::setw(2) << static_cast<int>(a * 255); | ||
return stream.str(); | ||
} | ||
|
||
mce::Color mce::Color::fromHexString(const std::string &hex_string) | ||
{ | ||
Color color{}; | ||
if (hex_string.length() != 8) { | ||
return color; | ||
} | ||
|
||
const auto value = std::strtoul(hex_string.c_str(), nullptr, 16); | ||
color.r = static_cast<float>((value >> 24) & 0xFF) / 255.0F; | ||
color.g = static_cast<float>((value >> 16) & 0xFF) / 255.0F; | ||
color.b = static_cast<float>((value >> 8) & 0xFF) / 255.0F; | ||
color.a = static_cast<float>(value & 0xFF) / 255.0F; | ||
return color; | ||
} |