Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef HTCW_GFX_CANVAS_HPP
- #define HTCW_GFX_CANVAS_HPP
- #include "gfx_core.hpp"
- #include "gfx_pixel.hpp"
- #include "gfx_palette.hpp"
- #include "gfx_bitmap.hpp"
- #include "gfx_font.hpp"
- #include "gfx_encoding.hpp"
- #include "gfx_vector_core.hpp"
- namespace gfx {
- enum struct canvas_paint_type {
- none = 0,
- solid,
- gradient,
- texture
- };
- enum struct canvas_texture_type {
- plain = 0,
- tiled
- };
- struct canvas_texture {
- canvas_texture_type type;
- float opacity;
- ::gfx::matrix matrix;
- const_bitmap<rgba_pixel<32>>* source;
- };
- struct canvas_gradient_stop {
- float offset;
- rgba_pixel<32> color;
- };
- enum struct canvas_gradient_type {
- linear = 0,
- radial = 1
- };
- enum struct canvas_spread_method {
- pad = 0,
- reflect,
- repeat
- };
- struct canvas_gradient {
- canvas_gradient_type type;
- canvas_spread_method spread;
- ::gfx::matrix matrix;
- float values[6];
- canvas_gradient_stop* stops;
- size_t stops_size;
- };
- struct canvas_dash {
- float offset;
- float* values;
- size_t values_size;
- };
- enum struct canvas_line_cap {
- butt = 0, ///< Flat edge at the end of the stroke.
- rount, ///< Rounded ends at the end of the stroke.
- square ///< Square ends at the end of the stroke.
- };
- enum struct canvas_line_join {
- miter=0, ///< Miter join with sharp corners.
- round, ///< Rounded join.
- bevel ///< Beveled join with a flattened corner.
- };
- struct canvas_stroke_style {
- float width;
- canvas_line_cap cap;
- canvas_line_join join;
- float miter_limit;
- };
- enum struct canvas_fill_rule {
- non_zero = 0,
- even_odd
- };
- enum canvas_compositing_mode {
- source = 0,
- source_over,
- destination_inside,
- destination_outside
- };
- class canvas final {
- public:
- typedef gfx_result(*on_write_callback_type)(const rect16& bounds, rgba_pixel<32> color, void* state);
- private:
- struct canvas_data {
- rgba_pixel<32> stroke_color;
- canvas_gradient stroke_gradient;
- canvas_texture stroke_texture;
- canvas_stroke_style stroke_style;
- canvas_dash stroke_dash;
- canvas_paint_type stroke_paint_type;
- rgba_pixel<32> fill_color;
- canvas_gradient fill_gradient;
- canvas_texture fill_texture;
- canvas_paint_type fill_paint_type;
- stream* font_stream;
- size_t font_index;
- float font_size;
- canvas_fill_rule fill_rule;
- canvas_compositing_mode compositing_mode;
- float opacity;
- ::gfx::matrix matrix;
- };
- void* m_info;
- canvas_data* m_data;
- size16 m_dimensions;
- on_write_callback_type m_write_callback;
- void* m_callback_state;
- static bool write_callback(int x, int y, int length, uint32_t color, void* state);
- canvas(const canvas& rhs)=delete;
- canvas& operator=(const canvas& rhs)=delete;
- public:
- canvas();
- canvas(size16 dimensions);
- canvas(canvas&& rhs);
- ~canvas();
- canvas& operator=(canvas&& rhs);
- gfx_result initialize();
- bool initialized() const;
- void deinitialize();
- on_write_callback_type on_write_callback() const;
- void* on_write_callback_state() const;
- void on_write_callback(on_write_callback_type callback, void* state=nullptr);
- size16 dimensions() const;
- void dimensions(size16 value);
- rect16 bounds() const;
- rgba_pixel<32> stroke_color() const;
- void stroke_color(rgba_pixel<32> value);
- canvas_gradient stroke_gradient() const;
- void stroke_gradient(const canvas_gradient& value);
- canvas_texture stroke_texture() const;
- void stroke_texture(const canvas_texture& value);
- canvas_stroke_style stroke_style() const;
- void stroke_style(const canvas_stroke_style& value);
- canvas_dash stroke_dash() const;
- void stroke_dash(const canvas_dash& value);
- canvas_paint_type stroke_paint_type() const;
- void stroke_paint_type(canvas_paint_type value);
- rgba_pixel<32> fill_color() const;
- void fill_color(rgba_pixel<32> value);
- canvas_gradient fill_gradient() const;
- void fill_gradient(const canvas_gradient& value);
- canvas_texture fill_texture() const;
- void fill_texture(const canvas_texture& value);
- canvas_paint_type fill_paint_type() const;
- void fill_paint_type(canvas_paint_type value);
- stream* font() const;
- void font(stream& ttf_stream, size_t index);
- float font_size() const;
- void font_size(float value);
- canvas_fill_rule fill_rule() const;
- void fill_rule(canvas_fill_rule value);
- canvas_compositing_mode compositing_mode() const;
- void compositing_mode(canvas_compositing_mode value);
- float opacity() const;
- void opacity(float value);
- ::gfx::matrix matrix() const;
- void matrix(const ::gfx::matrix& value);
- rectf fill_bounds() const;
- rectf stroke_bounds() const;
- rectf clip_bounds() const;
- // path builder - separate class?
- gfx_result move_to(pointf location);
- gfx_result line_to(pointf location);
- gfx_result quad_to(pointf point1, pointf point2);
- gfx_result cubic_to(pointf point1, pointf point2, pointf point3);
- gfx_result arc_to(sizef radiuses,float angle, bool large_arc, bool sweep, pointf location);
- gfx_result close_path();
- gfx_result rectangle(const rectf& bounds);
- gfx_result rounded_rectangle(const rectf bounds, sizef radiuses);
- gfx_result ellipse(pointf center, sizef radiuses);
- gfx_result circle(pointf center, float radius);
- gfx_result arc(pointf center, float radius, float a0, float a1, bool ccw);
- gfx_result path();
- gfx_result text(pointf location, const text_info& info);
- gfx_result clip();
- };
- };
- #endif
Add Comment
Please, Sign In to add comment