名称优化
This commit is contained in:
+11
-19
@@ -1,14 +1,11 @@
|
||||
#pragma once
|
||||
#include <cstdint>
|
||||
|
||||
namespace renderive {
|
||||
|
||||
struct Color {
|
||||
std::uint8_t red{};
|
||||
std::uint8_t green{};
|
||||
std::uint8_t blue{};
|
||||
std::uint8_t alpha{255};
|
||||
|
||||
std::uint8_t r{};
|
||||
std::uint8_t g{};
|
||||
std::uint8_t b{};
|
||||
std::uint8_t a{255};
|
||||
static constexpr Color transparent() {
|
||||
return {0, 0, 0, 0};
|
||||
}
|
||||
@@ -18,36 +15,32 @@ struct Color {
|
||||
static constexpr Color white() {
|
||||
return {255, 255, 255, 255};
|
||||
}
|
||||
static constexpr Color red_color() {
|
||||
static constexpr Color red() {
|
||||
return {255, 0, 0, 255};
|
||||
}
|
||||
static constexpr Color green_color() {
|
||||
static constexpr Color green() {
|
||||
return {0, 255, 0, 255};
|
||||
}
|
||||
static constexpr Color yellow() {
|
||||
return {255, 255, 0, 255};
|
||||
}
|
||||
bool operator==(const Color& other) const {
|
||||
return red == other.red && green == other.green && blue == other.blue && alpha == other.alpha;
|
||||
return r == other.r && g == other.g && b == other.b && a == other.a;
|
||||
}
|
||||
bool operator!=(const Color& other) const {
|
||||
return !(*this == other);
|
||||
}
|
||||
};
|
||||
|
||||
using Pixel = std::uint32_t;
|
||||
|
||||
constexpr Pixel premultiply(Color color) {
|
||||
auto r = static_cast<std::uint32_t>((color.red * color.alpha + 127) / 255);
|
||||
auto g = static_cast<std::uint32_t>((color.green * color.alpha + 127) / 255);
|
||||
auto b = static_cast<std::uint32_t>((color.blue * color.alpha + 127) / 255);
|
||||
return (static_cast<std::uint32_t>(color.alpha) << 24) | (r << 16) | (g << 8) | b;
|
||||
auto r = static_cast<std::uint32_t>((color.r * color.a + 127) / 255);
|
||||
auto g = static_cast<std::uint32_t>((color.g * color.a + 127) / 255);
|
||||
auto b = static_cast<std::uint32_t>((color.b * color.a + 127) / 255);
|
||||
return (static_cast<std::uint32_t>(color.a) << 24) | (r << 16) | (g << 8) | b;
|
||||
}
|
||||
|
||||
constexpr Pixel pack_rgba(std::uint8_t r, std::uint8_t g, std::uint8_t b, std::uint8_t a = 255) {
|
||||
return (static_cast<std::uint32_t>(a) << 24) | (static_cast<std::uint32_t>(r) << 16) | (static_cast<std::uint32_t>(g) << 8) | static_cast<std::uint32_t>(b);
|
||||
}
|
||||
|
||||
constexpr Color premultiplied_to_color(Pixel pixel) {
|
||||
auto a = static_cast<std::uint8_t>(pixel >> 24);
|
||||
if (a == 0)
|
||||
@@ -62,5 +55,4 @@ constexpr Color premultiplied_to_color(Pixel pixel) {
|
||||
a
|
||||
};
|
||||
}
|
||||
|
||||
} // namespace renderive
|
||||
|
||||
+9
-19
@@ -2,19 +2,15 @@
|
||||
#include <algorithm>
|
||||
#include <cstdint>
|
||||
#include <iosfwd>
|
||||
|
||||
namespace renderive {
|
||||
|
||||
struct Point {
|
||||
int x{};
|
||||
int y{};
|
||||
};
|
||||
|
||||
struct PointF {
|
||||
double x{};
|
||||
double y{};
|
||||
};
|
||||
|
||||
struct Size {
|
||||
int width{};
|
||||
int height{};
|
||||
@@ -28,7 +24,6 @@ struct Size {
|
||||
return !(*this == other);
|
||||
}
|
||||
};
|
||||
|
||||
struct Rect {
|
||||
int x{};
|
||||
int y{};
|
||||
@@ -50,18 +45,17 @@ struct Rect {
|
||||
return point.x >= x && point.x <= right() && point.y >= y && point.y <= bottom();
|
||||
}
|
||||
[[nodiscard]] Rect intersected(const Rect& other) const {
|
||||
int r = std::min(right(), other.right());
|
||||
int b = std::min(bottom(), other.bottom());
|
||||
int r = std::min(right(), other.right());
|
||||
int b = std::min(bottom(), other.bottom());
|
||||
int nx = std::max(x, other.x);
|
||||
int ny = std::max(y, other.y);
|
||||
int w = r - nx;
|
||||
int h = b - ny;
|
||||
int w = r - nx;
|
||||
int h = b - ny;
|
||||
if (w <= 0 || h <= 0)
|
||||
return {};
|
||||
return {nx, ny, w, h};
|
||||
}
|
||||
};
|
||||
|
||||
struct RectF {
|
||||
double x{};
|
||||
double y{};
|
||||
@@ -98,23 +92,21 @@ struct RectF {
|
||||
return {nx, ny, nw, nh};
|
||||
}
|
||||
[[nodiscard]] RectF intersected(const RectF& other) const {
|
||||
double r = std::min(right(), other.right());
|
||||
double b = std::min(bottom(), other.bottom());
|
||||
double r = std::min(right(), other.right());
|
||||
double b = std::min(bottom(), other.bottom());
|
||||
double nx = std::max(x, other.x);
|
||||
double ny = std::max(y, other.y);
|
||||
double w = r - nx;
|
||||
double h = b - ny;
|
||||
double w = r - nx;
|
||||
double h = b - ny;
|
||||
if (w <= 0.0 || h <= 0.0)
|
||||
return {};
|
||||
return {nx, ny, w, h};
|
||||
}
|
||||
};
|
||||
|
||||
enum class Orientation : std::uint8_t {
|
||||
Horizontal,
|
||||
Vertical
|
||||
};
|
||||
|
||||
struct Range {
|
||||
double origin;
|
||||
double target;
|
||||
@@ -124,7 +116,7 @@ struct Range {
|
||||
[[nodiscard]] double length() const {
|
||||
return target - origin;
|
||||
}
|
||||
[[nodiscard]] double middle() const {
|
||||
[[nodiscard]] double center() const {
|
||||
return origin + (target - origin) / 2.0;
|
||||
}
|
||||
bool operator==(const Range& other) const {
|
||||
@@ -139,7 +131,5 @@ struct Range {
|
||||
return value > target - 0.0001 && value < origin + 0.0001;
|
||||
}
|
||||
};
|
||||
|
||||
std::ostream& operator<<(std::ostream& stream, const Range& range);
|
||||
|
||||
} // namespace renderive
|
||||
|
||||
+2
-2
@@ -30,7 +30,7 @@ struct Pen {
|
||||
Line_Cap cap = Line_Cap::Butt;
|
||||
Line_Join join = Line_Join::Miter;
|
||||
[[nodiscard]] bool enabled() const {
|
||||
return style != Line_Style::None && width > 0.0 && color.alpha != 0;
|
||||
return style != Line_Style::None && width > 0.0 && color.a != 0;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -43,7 +43,7 @@ struct Brush {
|
||||
Color color = Color::transparent();
|
||||
Brush_Style style = Brush_Style::None;
|
||||
[[nodiscard]] bool enabled() const {
|
||||
return style != Brush_Style::None && color.alpha != 0;
|
||||
return style != Brush_Style::None && color.a != 0;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
+8
-15
@@ -2,22 +2,18 @@
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
#include "Bitmask.h"
|
||||
|
||||
namespace renderive {
|
||||
|
||||
enum class Text_Align : std::uint16_t {
|
||||
None = 0,
|
||||
Left = 1 << 0,
|
||||
Right = 1 << 1,
|
||||
HCenter = 1 << 2,
|
||||
Top = 1 << 3,
|
||||
Bottom = 1 << 4,
|
||||
VCenter = 1 << 5,
|
||||
Center = HCenter | VCenter
|
||||
None = 0,
|
||||
Left = 1 << 0,
|
||||
Right = 1 << 1,
|
||||
Horizontal_Center = 1 << 2,
|
||||
Top = 1 << 3,
|
||||
Bottom = 1 << 4,
|
||||
Vertical_Center = 1 << 5,
|
||||
Center = Horizontal_Center | Vertical_Center
|
||||
};
|
||||
|
||||
struct Font_Face;
|
||||
|
||||
struct Font {
|
||||
std::shared_ptr<Font_Face> face;
|
||||
double size = 12.0;
|
||||
@@ -27,7 +23,6 @@ struct Font {
|
||||
return face != nullptr && size > 0.0;
|
||||
}
|
||||
};
|
||||
|
||||
struct Text_Metrics {
|
||||
double width{};
|
||||
double height{};
|
||||
@@ -38,7 +33,5 @@ struct Text_Metrics {
|
||||
return ascent + descent + line_gap;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace renderive
|
||||
|
||||
RENDERIVE_ENABLE_BITMASK(renderive::Text_Align)
|
||||
|
||||
Reference in New Issue
Block a user