Color
struct Color {
float r, g, b, a; // 分量范围 [0,1],不是 0..255
Color(float r=0, float g=0, float b=0, float a=1.0f);
static Color FromArgb(uint8_t a, uint8_t r, uint8_t g, uint8_t b);
D2D1_COLOR_F ToD2D() const;
static Color Lerp(const Color& c1, const Color& c2, float t);
};
易错
- 分量是浮点 [0,1];写
Color(255,0,0)会得到“超亮”的错色。整数入参请用Color::FromArgb(255,255,0,0)。
Rect
struct Rect {
float x, y, width, height;
Rect(float x=0, float y=0, float w=0, float h=0);
bool Contains(float px, float py) const; // 半开区间:x<=px<x+w
D2D1_RECT_F ToD2D() const;
};
Contains是左闭右开。命中测试多处依赖它。
Thickness
struct Thickness { float left, top, right, bottom; Thickness(float l=0,float t=0,float r=0,float b=0); };
Size
struct Size { float width, height; Size(float w=0, float h=0); };