C++ Color Picker Source

R

ravex

Ultra Member
Joined
Jul 30, 2019
Messages
661
Reaction score
356
Location
Turkey
cColorPicker.h
C++:
LPDIRECT3DTEXTURE9 ColorPickerTexture;
LPD3DXSPRITE ColorPickerSprite;
int ColorPickerWidth;
int ColorPickerHeight;
 
D3DCOLOR HSLToRGB(float H, float S, float L)
{
    float Q;
 
    if (L < 0.5f)
        Q = L * (S + 1.0f);
    else
        Q = L + S - (L * S);
 
    float P = 2 * L - Q;
 
    float RGBs[3];
 
    RGBs[0] = H + (1.0f / 3.0f);
    RGBs[1] = H;
    RGBs[2] = H - (1.0f / 3.0f);
 
    for (int i = 0; i < 3; ++i)
    {
        if (RGBs[i] < 0)
            RGBs[i] += 1.0f;
 
        if (RGBs[i] > 1)
            RGBs[i] -= 1.0f;
 
        if (RGBs[i] < (1.0f / 6.0f))
            RGBs[i] = P + ((Q - P) * 6 * RGBs[i]);
        else if (RGBs[i] < 0.5f)
            RGBs[i] = Q;
        else if (RGBs[i] < (2.0f / 3.0f))
            RGBs[i] = P + ((Q - P) * 6 * ((2.0f / 3.0f) - RGBs[i]));
        else
            RGBs[i] = P;
    }
 
    return D3DCOLOR_XRGB(int(RGBs[0] * 255.0f), int(RGBs[1] * 255.0f), int(RGBs[2] * 255.0f));
}
 
void ColorPicker_Destroy()
{
    if (ColorPickerSprite != NULL)
    {
        ColorPickerSprite->Release();
        ColorPickerSprite = NULL;
    }
 
    if (ColorPickerTexture != NULL)
    {
        ColorPickerTexture->Release();
        ColorPickerTexture = NULL;
    }
}
 
HRESULT ColorPicker_Init(LPDIRECT3DDEVICE9 Device, int Width, int Height)
{
    ColorPickerWidth = Width;
    ColorPickerHeight = Height;
 
    bool Bits32 = true;
    ColorPicker_Destroy();
 
    HRESULT CreateTextureReturn;
 
    CreateTextureReturn = Device->CreateTexture(Width, Height, 1, 0, D3DFMT_X8R8G8B8, D3DPOOL_MANAGED, &ColorPickerTexture, 0);
 
    if (FAILED(CreateTextureReturn))
    {
        Bits32 = false;
 
        CreateTextureReturn = Device->CreateTexture(Width, Height, 1, 0, D3DFMT_X4R4G4B4, D3DPOOL_MANAGED, &ColorPickerTexture, 0);
 
        if (FAILED(CreateTextureReturn))
            return CreateTextureReturn;
    }
 
    D3DLOCKED_RECT Palette;
    
    CreateTextureReturn = ColorPickerTexture->LockRect(0, &Palette, 0, 0);
 
    if (FAILED(CreateTextureReturn))
    {
        ColorPicker_Destroy();
        return CreateTextureReturn;
    }
 
    float H = 0;
    float S = 0.99f;
    float L = 1.0f;
 
    D3DCOLOR Color;
 
    BYTE R;
    BYTE G;
    BYTE B;
 
    DWORD* Colors32 = ((DWORD*)Palette.pBits) - 1;
    WORD* Colors = ((WORD*)Palette.pBits) - 1;
 
    for (int i = 0; i < Width; ++i)
    {
        for (int j = 0; j < Height; ++j)
        {
            Color = HSLToRGB(H, S, L);
 
            if (Bits32)
            {
                Colors32++;
                *Colors32 = Color;
            }
            else
            {
                R = ((Color >> 16) & 0xFF) / 0x10;
                G = ((Color >> 8) & 0xFF) / 0x10;
                B = ((Color >> 0) & 0xFF) / 0x10;
 
                Colors++;
 
                *Colors = (0xFF << 12) | (R << 8) | (G << 4) | (B << 0);
            }
 
            H += (1.0f / Width);
        }
 
        L -= (1.0f / Height);
        H = 0.0f;
    }
 
    ColorPickerTexture->UnlockRect(0);
 
    if (ColorPickerSprite == NULL)
        D3DXCreateSprite(Device, &ColorPickerSprite);
 
    return S_OK;
}
 
LPDIRECT3DTEXTURE9 ColorPicker_GetTexture()
{
    return ColorPickerTexture;
}
 
void DrawColorPicker(float X, float Y, LPDIRECT3DDEVICE9 Device)
{
    if (ColorPickerSprite != NULL)
    {
        ColorPickerSprite->Begin(D3DXSPRITE_ALPHABLEND);
        ColorPickerSprite->Draw(ColorPicker_GetTexture(), NULL, NULL, &D3DXVECTOR3(X, Y, 0.0f), 0xFFFFFFFF);
        ColorPickerSprite->End();
    }
}
 
D3DCOLOR GetPickedColor(int X, int Y)
{
    float H = X * (1.0f / ColorPickerWidth);
    float S = 0.99f;
    float L = 1.0f - Y * (1.0f / ColorPickerHeight);
 
    return HSLToRGB(H, S, L);
}
cColors.h
C++:
#define  BLUEMAZAY        D3DCOLOR_ARGB(255, 21,  56,  128)
#define     ORANGE              D3DCOLOR_ARGB(255,255,125,0)
#define     YELLOW           D3DCOLOR_ARGB(255,255,255,0)
#define     GREY             D3DCOLOR_ARGB(255,128,128,128)
#define     PURPLE           D3DCOLOR_ARGB(255,125,0,255)
#define     WHITE              D3DCOLOR_ARGB(255, 255, 255, 255)
#define     RED              D3DCOLOR_ARGB(255, 255, 000, 000)
#define     GREEN              D3DCOLOR_ARGB(255, 000, 255, 000)
#define     BLUE                D3DCOLOR_ARGB(255, 000, 000, 255)
#define     BLACK              D3DCOLOR_ARGB(255, 000, 000, 000)
#define  DARK1            D3DCOLOR_ARGB(255, 10, 10, 10)
#define  DARK2            D3DCOLOR_ARGB(255, 15, 15, 15)
#define  DARK3            D3DCOLOR_ARGB(255, 20, 20, 20)
#define  DARK4            D3DCOLOR_ARGB(255, 25, 25, 25)
#define  DARK5            D3DCOLOR_ARGB(255, 30, 30, 30)
#define  DARK6            D3DCOLOR_ARGB(255, 35, 35, 35)
#define  DARK7            D3DCOLOR_ARGB(255, 40, 40, 40)
#define  DARK8            D3DCOLOR_ARGB(255, 45, 45, 45)
#define  DARK9            D3DCOLOR_ARGB(255, 50, 50, 50)
#define  DARK10           D3DCOLOR_ARGB(255, 60, 60, 60)
#define  DARK11           D3DCOLOR_ARGB(255, 65, 65, 65)
#define  DARK12           D3DCOLOR_ARGB(255, 70, 70, 70)
#define  DARK13           D3DCOLOR_ARGB(255, 75, 75, 75)
#define  DARK14           D3DCOLOR_ARGB(255, 80, 80, 80)
#define  DARK15           D3DCOLOR_ARGB(255, 85, 85, 85)
#define  DARK16           D3DCOLOR_ARGB(255, 90, 90, 90)
#define  DARK18           D3DCOLOR_ARGB(255, 130, 130, 130)
#define  DARK20           D3DCOLOR_ARGB(255, 150, 150, 150)
#define  WINDOWS          D3DCOLOR_ARGB(255, 176 ,  30 ,  58 )
#define  WINDOWS2         D3DCOLOR_ARGB(255, 176 ,  20 ,  48 )
#define  DARK30           D3DCOLOR_ARGB(255, 62, 62, 62)
#define  DARK17            D3DCOLOR_ARGB(220, 40, 40, 40)
#define  DARK27            D3DCOLOR_ARGB(200, 40, 40, 40)
#define  DARK37            D3DCOLOR_ARGB(160, 40, 40, 40)


enum Colors : D3DCOLOR
{
     Background = 0x21242B,
     Title = 0x333845,
     Red = 0xBD2E46,
     Yellow = 0xF1B500,
     AliceBlue = 0xFFF0F8FF,
     AntiqueWhite = 0xFFFAEBD7,
     Aqua = 0xFF00FFFF,
     Aquamarine = 0xFF7FFFD4,
     Azure = 0xFFF0FFFF,
     Beige = 0xFFF5F5DC,
     Bisque = 0xFFFFE4C4,
     BlanchedAlmond = 0xFFFFEBCD,
     BlueViolet = 0xFF8A2BE2,
     Brown = 0xFFA52A2A,
     BurlyWood = 0xFFDEB887,
     CadetBlue = 0xFF5F9EA0,
     Chartreuse = 0xFF7FFF00,
     Chocolate = 0xFFD2691E,
     Coral = 0xFFFF7F50,
     CornflowerBlue = 0xFF6495ED,
     Cornsilk = 0xFFFFF8DC,
     Crimson = 0xFFDC143C,
     Cyan = 0xFF00FFFF,
     DarkBlue = 0xFF00008B,
     DarkCyan = 0xFF008B8B,
     DarkGoldenrod = 0xFFB8860B,
     DarkGray = 0xFFA9A9A9,
     DarkGreen = 0xFF006400,
     DarkKhaki = 0xFFBDB76B,
     DarkMagenta = 0xFF8B008B,
     DarkOliveGreen = 0xFF556B2F,
     DarkOrange = 0xFFFF8C00,
     DarkOrchid = 0xFF9932CC,
     DarkRed = 0xFF8B0000,
     DarkSalmon = 0xFFE9967A,
     DarkSeaGreen = 0xFF8FBC8B,
     DarkSlateBlue = 0xFF483D8B,
     DarkSlateGray = 0xFF2F4F4F,
     DarkTurquoise = 0xFF00CED1,
     DarkViolet = 0xFF9400D3,
     DeepPink = 0xFFFF1493,
     DeepSkyBlue = 0xFF00BFFF,
     DimGray = 0xFF696969,
     DodgerBlue = 0xFF1E90FF,
     Firebrick = 0xFFB22222,
     FloralWhite = 0xFFFFFAF0,
     ForestGreen = 0xFF228B22,
     Fuchsia = 0xFFFF00FF,
     Gainsboro = 0xFFDCDCDC,
     GhostWhite = 0xFFF8F8FF,
     GOLD = 0xFFFFD700,
     Goldenrod = 0xFFDAA520,
     GreenYellow = 0xFFADFF2F,
     Honeydew = 0xFFF0FFF0,
     HotPink = 0xFFFF69B4,
     IndianRed = 0xFFCD5C5C,
     Indigo = 0xFF4B0082,
     Ivory = 0xFFFFFFF0,
     Khaki = 0xFFF0E68C,
     Lavender = 0xFFE6E6FA,
     LavenderBlush = 0xFFFFF0F5,
     LawnGreen = 0xFF7CFC00,
     LemonChiffon = 0xFFFFFACD,
     LightBlue = 0xFFADD8E6,
     LightCoral = 0xFFF08080,
     LightCyan = 0xFFE0FFFF,
     LightGoldenrodYellow = 0xFFFAFAD2,
     LightGray = 0xFFD3D3D3,
     LightGreen = 0xFF90EE90,
     LightPink = 0xFFFFB6C1,
     LightSalmon = 0xFFFFA07A,
     LightSeaGreen = 0xFF20B2AA,
     LightSkyBlue = 0xFF87CEFA,
     LightSlateGray = 0xFF778899,
     LightSteelBlue = 0xFFB0C4DE,
     LightYellow = 0xFFFFFFE0,
     Lime = 0xFF00FF00,
     LimeGreen = 0xFF32CD32,
     Linen = 0xFFFAF0E6,
     Magenta = 0xFFFF00FF,
     Maroon = 0xFF800000,
     MediumAquamarine = 0xFF66CDAA,
     MediumBlue = 0xFF0000CD,
     MediumOrchid = 0xFFBA55D3,
     MediumPurple = 0xFF9370DB,
     MediumSeaGreen = 0xFF3CB371,
     MediumSlateBlue = 0xFF7B68EE,
     MediumSpringGreen = 0xFF00FA9A,
     MediumTurquoise = 0xFF48D1CC,
     MediumVioletRed = 0xFFC71585,
     MidnightBlue = 0xFF191970,
     MintCream = 0xFFF5FFFA,
     MistyRose = 0xFFFFE4E1,
     Moccasin = 0xFFFFE4B5,
     NavajoWhite = 0xFFFFDEAD,
     Navy = 0xFF000080,
     OldLace = 0xFFFDF5E6,
     Olive = 0xFF808000,
     OliveDrab = 0xFF6B8E23,
     Orange = 0xFFFFA500,
     OrangeRed = 0xFFFF4500,
     Orchid = 0xFFDA70D6,
     PaleGoldenrod = 0xFFEEE8AA,
     PaleGreen = 0xFF98FB98,
     PaleTurquoise = 0xFFAFEEEE,
     PaleVioletRed = 0xFFDB7093,
     PapayaWhip = 0xFFFFEFD5,
     PeachPuff = 0xFFFFDAB9,
     Peru = 0xFFCD853F,
     Pink = 0xFFFFC0CB,
     Plum = 0xFFDDA0DD,
     PowderBlue = 0xFFB0E0E6,
     RosyBrown = 0xFFBC8F8F,
     RoyalBlue = 0xFF4169E1,
     SaddleBrown = 0xFF8B4513,
     Salmon = 0xFFFA8072,
     SandyBrown = 0xFFF4A460,
     SeaGreen = 0xFF2E8B57,
     SeaShell = 0xFFFFF5EE,
     Sienna = 0xFFA0522D,
     Silver = 0xFFC0C0C0,
     SkyBlue = 0xFF87CEEB,
     SlateBlue = 0xFF6A5ACD,
     SlateGray = 0xFF708090,
     Snow = 0xFFFFFAFA,
     SpringGreen = 0xFF00FF7F,
     SteelBlue = 0xFF4682B4,
     Tan = 0xFFD2B48C,
     Teal = 0xFF008080,
     Thistle = 0xFFD8BFD8,
     Tomato = 0xFFFF6347,
     Transparent = 0x00FFFFFF,
     Turquoise = 0xFF40E0D0,
     Violet = 0xFFEE82EE,
     Wheat = 0xFFF5DEB3,
     WhiteSmoke = 0xFFF5F5F5,
     YellowGreen = 0xFF9ACD32
};
 
SPAM IS FORBIDDEN!
  • SPAMMERS ARE BANNED FROM THE FORUM AND CANNOT USE ANY OF THE CHEATS
  • For example: thanks, thx, very good, asdqwe, working, ty and so on!
  • For example: Writing the same message over and over. thanks, thx and so on!
  • Copying and copying someone else's message is prohibited.
  • It is forbidden to send messages to increase the number of comments on threads that you have no knowledge of.
  • Write your own opinion when commenting!
  • If you see spam message, please let us know with the REPORT button!

Tema düzenleyici

Top Bottom