Euphoria
image_canvas.cc
Go to the documentation of this file.
1 #include "core/image_canvas.h"
2 
3 #include "core/image.h"
4 #include "assert/assert.h"
5 #include "base/numeric.h"
6 #include "base/mat2.h"
7 #include "core/image_draw.h"
8 
9 #include "base/stringutils.h"
10 #include "base/stringmerger.h"
11 
12 #include "log/log.h"
13 
14 
15 namespace eu::core
16 {
17  vec2f
19  {
20  const auto vv = transform * vec3f {v, 1};
21  return vec2f
22  {
23  vv.x,
24  static_cast<float>(target_image->height) - vv.y
25  };
26  }
27 
29  : fill_style(NamedColor::black)
30  , target_image(i)
31  , transform(m3_identity)
32  , building_path(false)
33  {
34  }
35 
36  void
37  Canvas::fill_rect(int x, int y, int w, int h) const
38  {
39  ASSERTX(w > 0, w);
40  ASSERTX(h > 0, h);
41  draw_rect
42  (
44  fill_style,
46  (
48  w, h
49  )
50  );
51  }
52 
53  void
54  Canvas::translate(float x, float y)
55  {
56  const auto m = mat3f::from_translation2d(vec2f {x, y});
57  transform = transform * m;
58  }
59 
60  void
61  Canvas::rotate(float r)
62  {
64  }
65 
66  void
68  {
70  path.resize(0);
71  building_path = true;
72  }
73 
74  void
76  {
78  building_path = false;
79  }
80 
81  void
82  Canvas::move_to(float x, float y)
83  {
85  ASSERT(path.empty());
86  path.push_back(transform_position(vec2f(x, y)));
87  }
88 
89  void
90  Canvas::draw_line_to(float dx, float dy)
91  {
93  if(path.empty())
94  {
95  path.push_back(transform_position(zero2f));
96  }
97  path.push_back(transform_position(vec2f(dx, dy)));
98  }
99 
100  void
101  Canvas::fill() const
102  {
105  }
106 }
107 
#define ASSERTX(x,...)
Definition: assert.h:48
#define ASSERT(x)
Definition: assert.h:29
void fill_poly(Image *image, const Rgbai &color, const std::vector< vec2f > &poly)
Definition: image_draw.cc:146
void draw_rect(Image *image, const Rgbai &color, const Recti &rect)
Definition: image_draw.cc:39
constexpr vec2f zero2f
Definition: vec2.h:68
NamedColor
Definition: colors.h:12
constexpr mat3f m3_identity
Definition: mat3.h:97
String utility functions.
constexpr static Angle from_radians(float radians)
Definition: angle.h:22
static Recti from_top_left_width_height(const vec2i &topleft, int width, int height)
Definition: rect.cc:561
std::vector< vec2f > path
Definition: image_canvas.h:21
vec2f transform_position(const vec2f &v) const
Definition: image_canvas.cc:18
void translate(float x, float y)
Definition: image_canvas.cc:54
void fill() const
void move_to(float x, float y)
Definition: image_canvas.cc:82
void rotate(float r)
Definition: image_canvas.cc:61
void draw_line_to(float dx, float dy)
should be named line_to but that name is horrible
Definition: image_canvas.cc:90
Image * target_image
Definition: image_canvas.h:18
void fill_rect(int x, int y, int w, int h) const
Definition: image_canvas.cc:37
Canvas(Image *i)
Definition: image_canvas.cc:28
int height
Definition: image.h:33
static mat2f from_rotation(const Angle &a)
Definition: mat2.cc:40
Definition: mat3.h:12
static mat3f from_translation2d(const vec2f &t)
Definition: mat3.cc:60
Definition: vec2.h:33
float x
Definition: vec2.h:34
Definition: vec2.h:72
Definition: vec3.h:48