05_C++精灵库之coloradd.h头文件源代码(2026年1月15日版)

#ifndef COLORADD_H
#define COLORADD_H

#include <SDL2/SDL.h>
#include <string>

class Color {
private:
    SDL_Color color;

public:
    // 构造函数
    Color(Uint8 r = 0, Uint8 g = 0, Uint8 b = 0, Uint8 a = 255);
    Color(const SDL_Color& sdlColor);

    // 获取SDL_Color
    SDL_Color get() const;
    std::string gethex() const;

    // 色相操作
    Color& addhue(float step=1.0);
    Color& coloradd(float step=1.0);
    
    void fromhue(int hue);  // RGB颜色从色相中来 
    void setcolor(int hue); //同上
	 
    // 饱和度操作
    Color& addsaturation(float step);
    Color& setsaturation(float sat);
    Color& addsat(float step);
    Color& setsat(float sat);

    // 亮度操作
    Color& addbrightness(float step);
    Color& setbrightness(float bri);
    Color& addbri(float step);
    Color& setbri(float bri);

    // 透明度操作
    Color& addopacity(int step);   //增加不透明度 
    Color& setopacity(int a);     //设定不透明度 

    void rgbToHsv(Uint8 r, Uint8 g, Uint8 b, float& h, float& s, float& v) const;
    void hsvToRgb(float h, float s, float v, Uint8& r, Uint8& g, Uint8& b) const;

};

#endif // COLORADD_H

关于李兴球

李兴球的博客是Python创意编程原创博客
此条目发表在C++分类目录。将固定链接加入收藏夹。

发表回复