83 lines
2.4 KiB
C++
83 lines
2.4 KiB
C++
#pragma once
|
|
#include "../base/Color.h"
|
|
#include "../base/Geometry.h"
|
|
#include "../base/Style.h"
|
|
#include "../base/Text.h"
|
|
#include "Image_Interpolation_Mode.h"
|
|
#include "Image_View.h"
|
|
#include <memory>
|
|
#include <span>
|
|
#include <string>
|
|
#include <string_view>
|
|
|
|
namespace renderive {
|
|
|
|
class Image;
|
|
class Font_Face;
|
|
|
|
class Canvas {
|
|
public:
|
|
struct Font_Diagnostics {
|
|
bool face_valid{};
|
|
bool font_valid{};
|
|
double test_width{};
|
|
double test_height{};
|
|
std::string source;
|
|
};
|
|
|
|
explicit Canvas(Image& image);
|
|
~Canvas();
|
|
|
|
void save();
|
|
void restore();
|
|
|
|
void set_pen(const Pen& pen);
|
|
void set_brush(const Brush& brush);
|
|
void set_font(const Font& font);
|
|
void set_antialias(bool enabled);
|
|
void set_image_interpolation(Image_Interpolation_Mode mode);
|
|
|
|
void translate(double x, double y);
|
|
void scale(double x, double y);
|
|
void rotate(double radians);
|
|
void transform(double m00, double m01, double m10, double m11, double m20, double m21);
|
|
void reset_transform();
|
|
|
|
void set_clip_rect(const RectF& rect);
|
|
void reset_clip();
|
|
|
|
void draw_line(PointF first, PointF second);
|
|
void draw_polyline(std::span<const PointF> points);
|
|
void draw_point(PointF point);
|
|
void draw_points(std::span<const PointF> points);
|
|
void draw_rect(const RectF& rect);
|
|
void fill_rect(const RectF& rect);
|
|
void draw_ellipse(PointF center, double radius_x, double radius_y);
|
|
void draw_polygon(std::span<const PointF> points, bool fill = false);
|
|
void fill_polygon(std::span<const PointF> points);
|
|
|
|
void draw_image(const RectF& target, const Image& image);
|
|
void draw_image(const RectF& target, const Image& image, const RectF& source);
|
|
|
|
void draw_text(PointF position, std::string_view text);
|
|
void draw_text(const RectF& rect, Text_Align align, std::string_view text);
|
|
|
|
[[nodiscard]] Text_Metrics measure_text(std::string_view text) const;
|
|
[[nodiscard]] Text_Metrics measure_text(const Font& font, std::string_view text) const;
|
|
|
|
Image& image() const;
|
|
|
|
[[nodiscard]] static Font_Diagnostics default_font_diagnostics();
|
|
static void diagnose_default_font_once();
|
|
|
|
private:
|
|
static std::shared_ptr<Font_Face> default_font_face();
|
|
static Font resolve_font(Font font);
|
|
static bool can_use_font(const Font& font);
|
|
|
|
struct Impl;
|
|
std::unique_ptr<Impl> impl_;
|
|
};
|
|
|
|
} // namespace renderive
|