Skip to content

[ALL] Allow the Color class to accept hex code strings and Color1 variables as colors + Basic KeyValues support. #1288

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 12 commits into
base: master
Choose a base branch
from

Conversation

Bitl
Copy link
Contributor

@Bitl Bitl commented May 17, 2025

Description

This PR aims to implement a constructor to the Color class that allows users to define hex code strings for colors instead of RGB(A) values. This implementation is similar to hud_basechat's, and as such supports alpha channels.

Due to the nature of the Color class, the default alpha is set to 0, so passing in any normal hex code will result in a transparent color if whatever we put this in uses the full RGBA values.

Usage:

This example defines a color macro named COLOR_GENUINE with a hex code of #4D7455, the TF2 Genuine color hex code provided by the TF2 Wiki (https://wiki.teamfortress.com/wiki/Item_quality). FF was added to ensure the color is opaque.

#define COLOR_GENUINE		Color("#4D7455FF")

image

The COLOR_GENUINE color macro, but it is transparent

#define COLOR_GENUINE		Color("#4D745580")

image

UPDATE: this PR now supports Color1 by the request of people in the Source Modding Community. You may now enter in the above value as the following:

#define COLOR_GENUINE		Color(0.3, 0.45, 0.33)

Shout out to @KaleiAlma for suggesting I do hex codes 😄

@Bitl Bitl changed the title [ALL} Allow the Color class to accept hex code strings as colors. [ALL] Allow the Color class to accept hex code strings as colors. May 17, 2025
@Bitl
Copy link
Contributor Author

Bitl commented May 17, 2025

The newest version of this PR now supports wchar_t strings and also deals with syntax

The above example can now work with proper hex code strings!

#define COLOR_GENUINE		Color("#4D7455FF")

@Bitl
Copy link
Contributor Author

Bitl commented May 17, 2025

The latest version now adds KeyValues support, allowing for the use of hex color values in KeyValues scripts!

@Bitl
Copy link
Contributor Author

Bitl commented May 17, 2025

Due to the new null pointer check, "4D7455FF" is no longer considered a valid value

The original post will be updated.

@Bitl
Copy link
Contributor Author

Bitl commented May 17, 2025

additional note: this modification doesn't work for schemes as the override for IScheme::GetColor needs to be modified to support it in-engine.

@Bitl Bitl changed the title [ALL] Allow the Color class to accept hex code strings as colors. [ALL] Allow the Color class to accept hex code strings and Color1 variables as colors. May 18, 2025
@Bitl
Copy link
Contributor Author

Bitl commented May 18, 2025

UPDATE: this PR now supports Color1 by the request of people in the Source Modding Community. You may now enter in the above value as the following:

#define COLOR_GENUINE		Color(0.3, 0.45, 0.33)

@Bitl
Copy link
Contributor Author

Bitl commented May 18, 2025

Fixed an issue where 3 digit hex codes didn't work as expected.

@Bitl Bitl changed the title [ALL] Allow the Color class to accept hex code strings and Color1 variables as colors. [ALL] Allow the Color class to accept hex code strings and Color1 variables as colors. + Basic KeyValues support. May 18, 2025
@Bitl Bitl changed the title [ALL] Allow the Color class to accept hex code strings and Color1 variables as colors. + Basic KeyValues support. [ALL] Allow the Color class to accept hex code strings and Color1 variables as colors + Basic KeyValues support. May 18, 2025
@Bitl
Copy link
Contributor Author

Bitl commented May 19, 2025

Currently, Color1 values don't work with the current keyvalues implementation and would require a rewrite of how colors are handled in KeyValues. i'll probably be leaving it alone in case this gets implemented as it is.

hex values still work though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant