Renderer.h
Go to the documentation of this file.
1 /****
2  * Renderer.h
3  *
4  * Copyright 2021 mikee47 <mike@sillyhouse.net>
5  *
6  * This file is part of the Sming-Graphics Library
7  *
8  * This library is free software: you can redistribute it and/or modify it under the terms of the
9  * GNU General Public License as published by the Free Software Foundation, version 3 or later.
10  *
11  * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
12  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13  * See the GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along with this library.
16  * If not, see <https://www.gnu.org/licenses/>.
17  *
18  * @author: May 2021 - mikee47 <mike@sillyhouse.net>
19  *
20  ****/
21 
22 #pragma once
23 
24 #include "Scene.h"
25 #include "Buffer.h"
26 #include "Surface.h"
27 #include <Delegate.h>
28 
29 namespace Graphics
30 {
37 template <typename T> class ItemList
38 {
39 public:
40  ItemList(uint8_t capacity) : capacity(capacity)
41  {
42  items.reset(new T[capacity]);
43  }
44 
45  void add(T value)
46  {
47  assert(count < capacity);
48  items[count++] = value;
49  }
50 
51  T* get()
52  {
53  return (index < count) ? &items[index] : nullptr;
54  }
55 
56  T* next()
57  {
58  ++index;
59  return get();
60  }
61 
62  void reset()
63  {
64  index = count = 0;
65  }
66 
67  explicit operator bool() const
68  {
69  return count != 0;
70  }
71 
72 private:
73  std::unique_ptr<T[]> items;
74  uint8_t capacity;
75  uint8_t count{0};
76  uint8_t index{0};
77 };
78 
85 class PointList : public ItemList<Point>
86 {
87 public:
88  using ItemList::ItemList;
89 
90  PointList(const Rect& bounds, const Brush& brush, uint8_t capacity)
91  : ItemList(capacity), bounds(bounds), object(brush, {})
92  {
93  }
94 
95  void add(int16_t x, int16_t y)
96  {
97  Point pt{x, y};
98  if(Rect(bounds.size()).contains(pt)) {
99  ItemList::add(pt);
100  }
101  }
102 
108  bool render(Surface& surface);
109 
110 private:
111  Rect bounds;
112  PointObject object;
113  std::unique_ptr<Renderer> renderer;
114 };
115 
119 class RectList : public ItemList<Rect>
120 {
121 public:
122  RectList(const Rect& bounds, const Brush& brush, uint8_t capacity)
123  : ItemList(capacity), bounds(bounds), object(brush, {})
124  {
125  }
126 
127  void add(const Rect& rect)
128  {
129  auto r = intersect(rect, bounds.size());
130  if(r) {
131  ItemList::add(r);
132  }
133  }
134 
135  bool render(Surface& surface);
136 
137 private:
138  Rect bounds;
139  FilledRectObject object;
140  std::unique_ptr<Renderer> renderer;
141 };
142 
146 class MultiRenderer : public Renderer
147 {
148 public:
149  using Renderer::Renderer;
150 
151  bool execute(Surface& surface) override;
152 
153 protected:
154  virtual void renderDone(const Object* object) = 0;
155  virtual const Object* getNextObject() = 0;
156 
157 private:
158  std::unique_ptr<Renderer> renderer;
159  const Object* object{nullptr};
160 };
161 
169 {
170 public:
171  SceneRenderer(const Location& location, const SceneObject& scene) : MultiRenderer(location), scene(scene)
172  {
173  }
174 
175 protected:
176  void renderDone(const Object* object) override
177  {
178  }
179 
180  const Object* getNextObject() override
181  {
182  if(nextObject) {
183  nextObject = nextObject->getNext();
184  } else {
185  nextObject = scene.objects.head();
186  }
187  return nextObject;
188  }
189 
190 private:
191  const SceneObject& scene;
192  const Object* nextObject{};
193 };
194 
200 class GfxLineRenderer : public Renderer
201 {
202 public:
204  : GfxLineRenderer(location, object.pen, object.pt1, object.pt2)
205  {
206  }
207 
209  : Renderer(location), pen(pen), x0(pt1.x), y0(pt1.y), x1(pt2.x), y1(pt2.y)
210  {
211  init();
212  }
213 
214  bool execute(Surface& surface) override;
215 
216 private:
217  void init();
218 
219  Point pos{};
220  Pen pen;
221  uint16_t x0;
222  uint16_t y0;
223  uint16_t x1;
224  uint16_t y1;
225  uint16_t xaddr;
226  int16_t dx;
227  int16_t dy;
228  int16_t err;
229  int8_t ystep;
230  bool steep;
231 };
232 
238 class LineRenderer : public Renderer
239 {
240 public:
241  LineRenderer(const Location& location, const LineObject& object)
242  : LineRenderer(location, object.pen, object.pt1, object.pt2)
243  {
244  }
245 
246  LineRenderer(const Location& location, Pen pen, Point pt1, Point pt2)
247  : Renderer(location), rectangles(location.dest, pen, 1), w(pen.width), x1(pt1.x), y1(pt1.y), x2(pt2.x),
248  y2(pt2.y)
249  {
250  init();
251  }
252 
253  bool execute(Surface& surface) override;
254 
255 private:
256  enum class Mode {
257  simple,
258  diagonal,
259  horizontal,
260  vertical,
261  done,
262  };
263 
264  void init();
265  void drawDiagonal();
266  void initHorizontal();
267  void drawHorizontal();
268  void initVertical();
269  void drawVertical();
270 
271  RectList rectangles;
272  const uint16_t w;
273  uint16_t x1;
274  uint16_t y1;
275  uint16_t x2;
276  uint16_t y2;
277  Rect r;
278  uint16_t dx;
279  uint16_t dy;
280  uint16_t adj_up;
281  uint16_t adj_down;
282  uint16_t whole_step;
283  uint16_t initial_run;
284  uint16_t final_run;
285  uint16_t run_length;
286  uint16_t run_pos{0};
287  int16_t error_term;
288  int8_t xadvance;
289  Mode mode{};
290 };
291 
296 {
297 public:
299  {
300  }
301 
302  bool execute(Surface& surface) override;
303 
304 protected:
307  std::unique_ptr<Renderer> renderer;
308  uint16_t index{0};
309 };
310 
314 class RectRenderer : public Renderer
315 {
316 public:
317  RectRenderer(const Location& location, const Pen& pen, const Rect& rect)
318  : Renderer(location), rectangles(location.dest, pen, 4)
319  {
320  auto w = pen.width;
321  auto& r = rect;
322 
323  auto w2 = w + w;
324  if(w2 >= r.w || w2 >= r.h)
325  rectangles.add(r);
326  else {
327  rectangles.add(Rect(r.x, r.y, r.w - w, w));
328  rectangles.add(Rect(r.x, r.y + w, w, r.h - w));
329  rectangles.add(Rect(r.x + r.w - w, r.y, w, r.h - w));
330  rectangles.add(Rect(r.x + w, r.y + r.h - w, r.w - w, w));
331  }
332  }
333 
334  RectRenderer(const Location& location, const RectObject& object) : RectRenderer(location, object.pen, object.rect)
335  {
336  }
337 
338  bool execute(Surface& surface) override
339  {
340  return rectangles.render(surface);
341  }
342 
343 private:
344  RectList rectangles;
345 };
346 
353 {
354 public:
355  FilledRectRenderer(const Location& location, const Brush& brush, const Rect& rect, const Blend* blender = nullptr)
356  : Renderer(location), brush(brush), rect{rect}, blender(blender)
357  {
358  }
359 
361  : Renderer(location), brush(object.brush), rect(object.rect + location.dest.topLeft()), blender(object.blender)
362  {
363  }
364 
366  : Renderer(location), brush(object.brush), rect{object.point, 1, 1}
367  {
368  }
369 
370  bool execute(Surface& surface) override;
371 
372 private:
373  struct Buffer : public ReadStatusBuffer {
374  enum class State {
375  empty,
376  reading,
377  writing,
378  };
379  static constexpr size_t bufSize{256};
380  static constexpr size_t bufPixels{bufSize / 3};
381 
382  Rect r;
383 
384  Buffer() : ReadStatusBuffer{PixelFormat::None, bufSize}
385  {
386  }
387  };
388 
389  int queueRead(Surface& surface);
390 
391  Brush brush;
392  Rect rect;
393  Point pos{};
394  Size blockSize;
395  const Blend* blender{nullptr};
396  Buffer buffers[2];
397  uint8_t index{0};
398  uint8_t busyCount{0};
399  bool done{false};
400 };
401 
408 {
409 public:
411  : Renderer(location), renderer(new PolylineRenderer(location, polyline)), polyline(object), pen(object.pen),
412  rect(object.rect), radius(object.radius), corners{Point(rect.left() + radius, rect.top() + radius),
413  Point(rect.right() - radius, rect.top() + radius),
414  Point(rect.right() - radius, rect.bottom() - radius),
415  Point(rect.left() + radius, rect.bottom() - radius)}
416  {
417  }
418 
419  bool execute(Surface& surface) override;
420 
421 private:
422  std::unique_ptr<Renderer> renderer;
423  PolylineObject polyline;
424  Pen pen;
425  Rect rect;
426  uint8_t radius;
427  uint8_t state{0};
428  Point corners[4];
429 };
430 
437 {
438 public:
440  : Renderer(location), object(object)
441  {
442  auto& rect = this->object.rect;
443  auto r = object.radius;
444  corners[0] = Point(rect.x + r, rect.y + r);
445  corners[1] = Point(rect.x + r, rect.bottom() - r);
446  }
447 
448  bool execute(Surface& surface) override;
449 
450 private:
451  std::unique_ptr<Renderer> renderer;
452  FilledRectObject object;
453  uint8_t state{0};
454  Point corners[2];
455 };
456 
462 class CircleRenderer : public Renderer
463 {
464 public:
466  : CircleRenderer(location, object.pen, object.centre, object.radius, 0x0f)
467  {
468  pixels.add(x0, y0 + y);
469  pixels.add(x0, y0 - y);
470  pixels.add(x0 + y, y0);
471  pixels.add(x0 - y, y0);
472  }
473 
477  CircleRenderer(const Location& location, const Pen& pen, Point centre, uint16_t radius, uint8_t corners)
478  : Renderer(location), pixels(location.dest, pen, 8), x0(centre.x), y0(centre.y), f(1 - radius), ddF_x(1),
479  ddF_y(-2 * radius), x(0), y(radius), corners(corners)
480  {
481  }
482 
483  bool execute(Surface& surface) override;
484 
485 private:
486  PointList pixels;
487  int16_t x0;
488  int16_t y0;
489  int16_t f;
490  int16_t ddF_x;
491  int16_t ddF_y;
492  int16_t x;
493  int16_t y;
494  uint8_t corners;
495 };
496 
503 {
504 public:
506  : FilledCircleRenderer(location, object.brush, object.centre, object.radius, 0, 0x03)
507  {
508  addLine(x0 - x, x0 + x, y0);
509  }
510 
515  FilledCircleRenderer(const Location& location, const Brush& brush, Point centre, uint16_t radius, uint16_t delta,
516  uint8_t quadrants)
517  : Renderer(location), rectangles(location.dest, brush, 4), x0(centre.x), y0(centre.y), f(1 - radius),
518  ddF_x(-2 * radius), ddF_y(1), x(radius), y(0), px(x), py(y), delta(delta), quadrants(quadrants)
519  {
520  }
521 
522  bool execute(Surface& surface) override;
523 
524 private:
525  void addLine(uint16_t x0, uint16_t x1, uint16_t y)
526  {
527  rectangles.add(Rect(x0, y, 1 + x1 - x0, 1));
528  }
529 
530  RectList rectangles;
531  int16_t x0;
532  int16_t y0;
533  int16_t f;
534  int16_t ddF_x;
535  int16_t ddF_y;
536  int16_t x;
537  int16_t y;
538  int16_t px;
539  int16_t py;
540  uint16_t delta;
541  uint8_t quadrants;
542  Location loc;
543 };
544 
548 struct Ellipse {
550  {
551  }
552 
553  /* ellipse: e(x,y) = b*b*x*x + a*a*y*y - a*a*b*b */
554  Ellipse(Size size)
555  : a(size.w / 2), b(size.h / 2), x(0), y(b), a2(a * a), b2(b * b), xcrit((3 * a2 / 4) + 1),
556  ycrit((3 * b2 / 4) + 1), t(b2 + a2 - 2 * a2 * b), dxt(b2 * (3 + x + x)), dyt(a2 * (3 - y - y)), d2xt(b2 + b2),
557  d2yt(a2 + a2)
558  {
559  }
560 
561  enum class Move {
562  down,
563  out,
564  };
566 
568 
569  uint16_t a; // semi-major axis length
570  uint16_t b; // semi-minor axis length
571  uint16_t x;
572  uint16_t y;
573  int32_t a2;
574  int32_t b2;
575  int32_t xcrit;
576  int32_t ycrit;
577  int32_t t;
578  int32_t dxt;
579  int32_t dyt;
580  int32_t d2xt;
581  int32_t d2yt;
582 };
583 
584 class ArcRectList : public RectList
585 {
586 public:
587  using RectList::RectList;
588 
589  void fill(const Rect& r, Point p0, Point p1, Point p2, int start_angle, int end_angle);
590 };
591 
599 class EllipseRenderer : public Renderer
600 {
601 public:
602  EllipseRenderer(const Location& location, const Pen& pen, const Rect& rect)
603  : Renderer(location), r(rect), rectangles(location.dest, pen, 8), w(pen.width)
604  {
605  }
606 
608  : EllipseRenderer(location, object.pen, object.rect)
609  {
610  }
611 
613  : EllipseRenderer(location, object.pen, object.getRect())
614  {
615  }
616 
617  bool execute(Surface& surface) override;
618 
619 protected:
620  enum class State {
621  init,
622  running,
623  final1,
624  final2,
625  done,
626  };
627 
628  virtual void addRectangles1();
629  virtual void addRectangles2();
630  virtual void final();
631 
632  const Rect r;
636  const uint16_t w;
637  uint16_t W;
639 
640 private:
641  Ellipse outer;
642  Ellipse inner;
643  Point prev;
644  uint16_t innerX{0};
645 };
646 
653 {
654 public:
655  FilledEllipseRenderer(const Location& location, const Brush& brush, const Rect& rect)
656  : Renderer(location), r(rect), rectangles(location.dest, brush, 4)
657  {
658  }
659 
661  : FilledEllipseRenderer(location, object.brush, object.rect)
662  {
663  }
664 
666  : FilledEllipseRenderer(location, object.brush, object.getRect())
667  {
668  }
669 
670  bool execute(Surface& surface) override;
671 
672 protected:
673  virtual void doStep(Ellipse::Step step);
674  virtual void final();
675 
676  enum class State {
677  init,
678  running,
679  final,
680  done,
681  };
682 
683  const Rect r;
689 };
690 
695 {
696 public:
697  ArcRenderer(const Location& location, const Pen& pen, const Rect& rect, int start_angle, int end_angle)
698  : EllipseRenderer(location, pen, rect), start_angle(normaliseAngle(start_angle)),
699  end_angle(normaliseAngle(end_angle))
700  {
701  }
702 
703  bool execute(Surface& surface) override;
704 
705 protected:
706  void addRectangles1() override;
707  void addRectangles2() override;
708  void final() override;
709 
710 private:
711  /* Input parameters */
712  uint16_t start_angle;
713  uint16_t end_angle;
714 
715  /* arc wedge line end points */
716  Point p0;
717  Point p1;
718  Point p2;
719 };
720 
725 {
726 public:
727  FilledArcRenderer(const Location& location, const Brush& brush, const Rect& rect, int start_angle, int end_angle)
728  : FilledEllipseRenderer(location, brush, rect), start_angle(normaliseAngle(start_angle)),
729  end_angle(normaliseAngle(end_angle))
730  {
731  }
732 
733  bool execute(Surface& surface) override;
734 
735 protected:
736  void doStep(Ellipse::Step step) override;
737  void final() override;
738 
739 private:
740  int16_t start_angle;
741  int16_t end_angle;
742  Point p0;
743  Point p1;
744  Point p2;
745 };
746 
750 class ImageRenderer : public Renderer
751 {
752 public:
753  ImageRenderer(const Location& location, const ImageObject& object) : Renderer(location), object(object)
754  {
755  }
756 
757  bool execute(Surface& surface) override;
758 
759 private:
760  const ImageObject& object;
761  uint8_t bytesPerPixel{0};
762  PixelFormat pixelFormat{};
763 };
764 
770 class SurfaceRenderer : public Renderer
771 {
772 public:
774  : SurfaceRenderer(location, object.surface, object.dest, object.source)
775  {
776  }
777 
778  SurfaceRenderer(const Location& location, Surface& target, const Rect& dest, Point source)
779  : Renderer(location), target(target), dest(dest), source(source)
780  {
781  }
782 
783  bool execute(Surface& surface) override;
784 
785 private:
786  static constexpr uint16_t bufSize{512};
787  ReadBuffer buffers[2];
788  Surface& target;
789  Rect dest;
790  Point source;
791  PixelFormat pixelFormat{};
792  uint8_t bufIndex{0};
793  bool done{false};
794  uint8_t busyCount{0};
795 };
796 
800 class CopyRenderer : public Renderer
801 {
802 public:
803  using Renderer::Renderer;
804 
806  {
807  Rect src = object.source;
808  Rect dst(object.dest, object.source.size());
809  src += this->location.dest.topLeft();
810  dst += this->location.dest.topLeft();
811  // TODO: Do X/Y separately
812  src.clip(location.dest);
813  dst.clip(location.dest);
814  src.w = dst.w = std::min(src.w, dst.w);
815  src.h = dst.h = std::min(src.h, dst.h);
816  this->location.dest = dst;
817  this->location.source = src;
818  }
819 
820  bool execute(Surface& surface) override;
821 
822 protected:
823  void init();
824  void startRead(Surface& surface);
825 
826  /* Position is given in `location` */
827  virtual void readComplete(uint8_t* data, size_t length)
828  {
829  }
830 
832  uint8_t bytesPerPixel;
833  bool vertical;
834 
835 private:
837  LineBuffer lineBuffers[2];
838  uint16_t lineSize; // Width or height
839  uint16_t lineCount;
840  uint16_t readIndex{0};
841  uint16_t writeIndex{0};
842  TPoint<int8_t> shift{};
843 };
844 
846 {
847 public:
848  ImageCopyRenderer(const Location& location, const ImageObject& image, const Blend* blend)
849  : CopyRenderer({location.dest, location.dest}), image(image), blend(blend)
850  {
851  auto& dst = location.dest;
852  this->location.source.w = this->location.dest.w = std::min(dst.w, image.width());
853  this->location.source.h = this->location.dest.h = std::min(dst.h, image.height());
854  }
855 
856 protected:
857  void readComplete(uint8_t* data, size_t length) override;
858 
859 private:
860  const ImageObject& image;
861  const Blend* blend;
862 };
863 
867 class ScrollRenderer : public Renderer
868 {
869 public:
870  ScrollRenderer(const Location& location, const ScrollObject& object) : Renderer(location), object(object)
871  {
872  }
873 
874  bool execute(Surface& surface) override;
875 
876 private:
877  void init();
878  bool startRead(Surface& surface);
879  int16_t checkx(int16_t x);
880  int16_t checky(int16_t y);
881  void stepx(uint16_t& index, int16_t& x);
882  void stepy(uint16_t& index, int16_t& y);
883 
885 
886  const ScrollObject& object;
887  Rect src{};
888  Rect dst{};
889  int16_t cx;
890  int16_t cy;
891  uint16_t readOffset{0};
892  uint16_t writeOffset{0};
893  LineBuffer lineBuffers[2];
894  uint16_t lineCount;
895  uint16_t readIndex{0};
896  uint16_t writeIndex{0};
897  Rect readArea;
898  Rect writeArea;
899  PackedColor fill;
900  PixelFormat pixelFormat{};
901  uint8_t bytesPerPixel;
902  bool vertical; // If true, copy vertical lines
903  uint8_t state{0};
904 };
905 
909 class BlendRenderer : public Renderer
910 {
911 public:
912  BlendRenderer(const Location& location, const Object& object, const Blend* blend)
913  : Renderer(location), object(object), blend(blend)
914  {
915  }
916 
917  bool execute(Surface& surface) override;
918 
919 private:
920  enum class State {
921  init,
922  draw,
923  done,
924  };
925 
926  const Object& object;
927  std::unique_ptr<Renderer> renderer;
928  std::unique_ptr<MemoryImageObject> image;
929  std::unique_ptr<Surface> imageSurface;
930  PixelFormat pixelFormat;
931  const Blend* blend;
932  State nextState{};
933 };
934 
940 class TextRenderer : public Renderer
941 {
942 public:
943  TextRenderer(const Location& location, const TextObject& object)
944  : Renderer(location), object(object), alphaBuffer(object, location.dest.h - location.pos.y),
945  element(alphaBuffer.element)
946  {
947  this->location.dest += object.bounds.topLeft();
948  this->location.pos = Point{};
949  }
950 
951  bool execute(Surface& surface) override;
952 
953 private:
954  struct AlphaBuffer {
955  const TextObject::Element* element;
956  const TextAsset* text{nullptr};
957  const TextObject::FontElement* font{nullptr};
958  std::unique_ptr<uint8_t[]> data;
959  Size size{};
960  uint16_t charIndex{0};
961  uint16_t x{0};
962  uint16_t xo{0};
963  uint16_t ymax;
964  uint8_t advdiff{0};
965 
966  AlphaBuffer(const TextObject& object, uint16_t ymax) : element{object.elements.head()}, ymax(ymax)
967  {
968  }
969 
970  void init(Size size)
971  {
972  data.reset(new uint8_t[size.w * size.h]{});
973  this->size = size;
974  }
975 
976  void clear()
977  {
978  memset(data.get(), 0, size.w * size.h);
979  }
980 
981  void fill();
982 
983  bool finished()
984  {
985  return element == nullptr;
986  }
987 
988  // Shift content from given position to start of buffer, clear the vacated space
989  void shift(uint16_t count)
990  {
991  count = std::min(count, x);
992  auto row = data.get();
993  for(unsigned i = 0; i < size.h; ++i) {
994  memmove(row, &row[count], size.w - count);
995  memset(&row[size.w - count], 0, count);
996  row += size.w;
997  }
998  xo += count;
999  x -= count;
1000  }
1001  };
1002 
1003  struct BackBuffer : public ReadStatusBuffer {
1004  static constexpr size_t bufSize{512};
1005 
1006  BackBuffer() : ReadStatusBuffer(PixelFormat::None, bufSize)
1007  {
1008  }
1009 
1010  Rect r{};
1011  Point pos{};
1012  const TextObject::RunElement* run{nullptr};
1013  TextOptions options;
1014  uint16_t glyphPixels;
1015  bool lastRow{false};
1016  };
1017 
1018  void getNextRun();
1019  bool startRead(Surface& surface);
1020  bool renderBuffer(Surface& surface, BackBuffer& backBuffer);
1021 
1022  const TextObject& object;
1023  AlphaBuffer alphaBuffer;
1024  const TextObject::RunElement* run{nullptr};
1025  const TextObject::Element* element;
1026  GlyphObject::Options options;
1027  BackBuffer backBuffers[2];
1028  uint8_t readIndex{0};
1029  uint8_t writeIndex{0};
1030  const TypeFace* typeface{nullptr};
1031  PixelFormat pixelFormat{};
1032  uint8_t bytesPerPixel;
1033  uint8_t busyCount{0};
1034 };
1035 
1036 } // namespace Graphics
Manage a set of bit values using enumeration.
Definition: BitSet.h:45
Definition: Renderer.h:585
void fill(const Rect &r, Point p0, Point p1, Point p2, int start_angle, int end_angle)
Render arc outline with adjustable line width.
Definition: Renderer.h:695
ArcRenderer(const Location &location, const Pen &pen, const Rect &rect, int start_angle, int end_angle)
Definition: Renderer.h:697
void addRectangles2() override
void addRectangles1() override
bool execute(Surface &surface) override
Called to do some writing to the surface.
Perform blending with draw.
Definition: Renderer.h:910
BlendRenderer(const Location &location, const Object &object, const Blend *blend)
Definition: Renderer.h:912
bool execute(Surface &surface) override
Called to do some writing to the surface.
Blend operations.
Definition: Blend.h:42
The source of colour for drawing.
Definition: Asset.h:253
A circle outline.
Definition: Libraries/Graphics/src/include/Graphics/Object.h:370
Draws a circle outline.
Definition: Renderer.h:463
bool execute(Surface &surface) override
Called to do some writing to the surface.
CircleRenderer(const Location &location, const CircleObject &object)
Definition: Renderer.h:465
CircleRenderer(const Location &location, const Pen &pen, Point centre, uint16_t radius, uint8_t corners)
Used to draw corners only.
Definition: Renderer.h:477
Describes a copy operation within the same surface.
Definition: Libraries/Graphics/src/include/Graphics/Object.h:1122
Copy an area within the same surface.
Definition: Renderer.h:801
bool execute(Surface &surface) override
Called to do some writing to the surface.
CopyRenderer(const Location &location, const CopyObject &object)
Definition: Renderer.h:805
PixelFormat pixelFormat
Definition: Renderer.h:831
bool vertical
Definition: Renderer.h:833
virtual void readComplete(uint8_t *data, size_t length)
Definition: Renderer.h:827
uint8_t bytesPerPixel
Definition: Renderer.h:832
void startRead(Surface &surface)
An ellipse outline.
Definition: Libraries/Graphics/src/include/Graphics/Object.h:454
Draws an ellipse outline.
Definition: Renderer.h:600
const uint16_t w
Definition: Renderer.h:636
uint16_t W
Definition: Renderer.h:637
bool execute(Surface &surface) override
Called to do some writing to the surface.
EllipseRenderer(const Location &location, const EllipseObject &object)
Definition: Renderer.h:607
virtual void addRectangles2()
virtual void addRectangles1()
EllipseRenderer(const Location &location, const CircleObject &object)
Definition: Renderer.h:612
Rect r2
Definition: Renderer.h:634
EllipseRenderer(const Location &location, const Pen &pen, const Rect &rect)
Definition: Renderer.h:602
ArcRectList rectangles
Definition: Renderer.h:635
const Rect r
Definition: Renderer.h:632
State
Definition: Renderer.h:620
Rect r1
Definition: Renderer.h:633
State state
Definition: Renderer.h:638
Render arc outline with adjustable line width.
Definition: Renderer.h:725
void doStep(Ellipse::Step step) override
bool execute(Surface &surface) override
Called to do some writing to the surface.
FilledArcRenderer(const Location &location, const Brush &brush, const Rect &rect, int start_angle, int end_angle)
Definition: Renderer.h:727
A filled circle.
Definition: Libraries/Graphics/src/include/Graphics/Object.h:411
Draws a filled circle.
Definition: Renderer.h:503
bool execute(Surface &surface) override
Called to do some writing to the surface.
FilledCircleRenderer(const Location &location, const Brush &brush, Point centre, uint16_t radius, uint16_t delta, uint8_t quadrants)
Used to draw rounded parts of a rounded rectangle These are handled by drawing lines between the left...
Definition: Renderer.h:515
FilledCircleRenderer(const Location &location, const FilledCircleObject &object)
Definition: Renderer.h:505
A filled ellipse.
Definition: Libraries/Graphics/src/include/Graphics/Object.h:481
Draws a filled ellipse.
Definition: Renderer.h:653
Ellipse e
Definition: Renderer.h:685
FilledEllipseRenderer(const Location &location, const FilledEllipseObject &object)
Definition: Renderer.h:660
Rect r1
Definition: Renderer.h:686
Rect r2
Definition: Renderer.h:687
FilledEllipseRenderer(const Location &location, const FilledCircleObject &object)
Definition: Renderer.h:665
virtual void doStep(Ellipse::Step step)
bool execute(Surface &surface) override
Called to do some writing to the surface.
ArcRectList rectangles
Definition: Renderer.h:684
State
Definition: Renderer.h:676
FilledEllipseRenderer(const Location &location, const Brush &brush, const Rect &rect)
Definition: Renderer.h:655
State state
Definition: Renderer.h:688
const Rect r
Definition: Renderer.h:683
A filled rectangle.
Definition: Libraries/Graphics/src/include/Graphics/Object.h:227
Rect rect
Definition: Libraries/Graphics/src/include/Graphics/Object.h:250
Draws a filled rectangle.
Definition: Renderer.h:353
FilledRectRenderer(const Location &location, const PointObject &object)
Definition: Renderer.h:365
FilledRectRenderer(const Location &location, const Brush &brush, const Rect &rect, const Blend *blender=nullptr)
Definition: Renderer.h:355
bool execute(Surface &surface) override
Called to do some writing to the surface.
FilledRectRenderer(const Location &location, const FilledRectObject &object)
Definition: Renderer.h:360
Draws a filled rectangle with rounded corners.
Definition: Renderer.h:437
bool execute(Surface &surface) override
Called to do some writing to the surface.
FilledRoundedRectRenderer(const Location &location, const FilledRectObject &object)
Definition: Renderer.h:439
Draws 1-pixel lines.
Definition: Renderer.h:201
GfxLineRenderer(const Location &location, const LineObject &object)
Definition: Renderer.h:203
GfxLineRenderer(const Location &location, Pen pen, Point pt1, Point pt2)
Definition: Renderer.h:208
bool execute(Surface &surface) override
Called to do some writing to the surface.
TextOptions Options
Definition: Libraries/Graphics/src/include/Graphics/Object.h:853
Definition: Renderer.h:846
ImageCopyRenderer(const Location &location, const ImageObject &image, const Blend *blend)
Definition: Renderer.h:848
void readComplete(uint8_t *data, size_t length) override
Virtual base class for an image.
Definition: Libraries/Graphics/src/include/Graphics/Object.h:562
uint16_t height() const
Definition: Libraries/Graphics/src/include/Graphics/Object.h:585
uint16_t width() const
Definition: Libraries/Graphics/src/include/Graphics/Object.h:580
Render an image object.
Definition: Renderer.h:751
ImageRenderer(const Location &location, const ImageObject &object)
Definition: Renderer.h:753
bool execute(Surface &surface) override
Called to do some writing to the surface.
Fixed list of types.
Definition: Renderer.h:38
T * get()
Definition: Renderer.h:51
void reset()
Definition: Renderer.h:62
void add(T value)
Definition: Renderer.h:45
ItemList(uint8_t capacity)
Definition: Renderer.h:40
T * next()
Definition: Renderer.h:56
A drawn line.
Definition: Libraries/Graphics/src/include/Graphics/Object.h:258
Draws lines.
Definition: Renderer.h:239
LineRenderer(const Location &location, Pen pen, Point pt1, Point pt2)
Definition: Renderer.h:246
bool execute(Surface &surface) override
Called to do some writing to the surface.
LineRenderer(const Location &location, const LineObject &object)
Definition: Renderer.h:241
Base class to render multiple objects.
Definition: Renderer.h:147
virtual const Object * getNextObject()=0
virtual void renderDone(const Object *object)=0
bool execute(Surface &surface) override
Called to do some writing to the surface.
A drawable object inherits from this virtual base class.
Definition: Libraries/Graphics/src/include/Graphics/Object.h:97
Definition: Asset.h:403
uint16_t width
Definition: Asset.h:433
Small list of points for drawing.
Definition: Renderer.h:86
void add(int16_t x, int16_t y)
Definition: Renderer.h:95
PointList(const Rect &bounds, const Brush &brush, uint8_t capacity)
Definition: Renderer.h:90
bool render(Surface &surface)
Render each point.
A single pixel == 1x1 rectangle.
Definition: Libraries/Graphics/src/include/Graphics/Object.h:175
A sequence of lines.
Definition: Libraries/Graphics/src/include/Graphics/Object.h:300
Draws series of lines defined by a PolylineObject
Definition: Renderer.h:296
uint16_t index
Definition: Renderer.h:308
bool execute(Surface &surface) override
Called to do some writing to the surface.
LineObject line
Definition: Renderer.h:306
std::unique_ptr< Renderer > renderer
Definition: Renderer.h:307
const PolylineObject & object
Definition: Renderer.h:305
PolylineRenderer(const Location &location, const PolylineObject &object)
Definition: Renderer.h:298
Small list of rectangles, similar to PointList.
Definition: Renderer.h:120
RectList(const Rect &bounds, const Brush &brush, uint8_t capacity)
Definition: Renderer.h:122
void add(const Rect &rect)
Definition: Renderer.h:127
bool render(Surface &surface)
A rectangular outline.
Definition: Libraries/Graphics/src/include/Graphics/Object.h:197
Draws a rectangle as a polyline.
Definition: Renderer.h:315
RectRenderer(const Location &location, const RectObject &object)
Definition: Renderer.h:334
bool execute(Surface &surface) override
Called to do some writing to the surface.
Definition: Renderer.h:338
RectRenderer(const Location &location, const Pen &pen, const Rect &rect)
Definition: Renderer.h:317
Virtual base class to manage rendering of various types of information to a surface.
Definition: Libraries/Graphics/src/include/Graphics/Object.h:66
Location location
Definition: Libraries/Graphics/src/include/Graphics/Object.h:90
Renderer(const Location &location)
Constructor.
Definition: Libraries/Graphics/src/include/Graphics/Object.h:75
Draws a rectangle outline with rounded corners.
Definition: Renderer.h:408
bool execute(Surface &surface) override
Called to do some writing to the surface.
RoundedRectRenderer(const Location &location, const RectObject &object)
Definition: Renderer.h:410
A Scene containing multiple objects.
Definition: Scene.h:32
OwnedList objects
Definition: Scene.h:230
A scene is a list of other objects, so we just iterate through the list and draw each in turn.
Definition: Renderer.h:169
const Object * getNextObject() override
Definition: Renderer.h:180
void renderDone(const Object *object) override
Definition: Renderer.h:176
SceneRenderer(const Location &location, const SceneObject &scene)
Definition: Renderer.h:171
Describes a scrolling operation.
Definition: Libraries/Graphics/src/include/Graphics/Object.h:1146
Scroll an area.
Definition: Renderer.h:868
ScrollRenderer(const Location &location, const ScrollObject &object)
Definition: Renderer.h:870
bool execute(Surface &surface) override
Called to do some writing to the surface.
Describes a target surface and corresponding source location.
Definition: Libraries/Graphics/src/include/Graphics/Object.h:1095
Copy an area to another surface.
Definition: Renderer.h:771
SurfaceRenderer(const Location &location, Surface &target, const Rect &dest, Point source)
Definition: Renderer.h:778
bool execute(Surface &surface) override
Called to do some writing to the surface.
SurfaceRenderer(const Location &location, const SurfaceObject &object)
Definition: Renderer.h:773
Interface for a drawing surface.
Definition: Surface.h:42
Definition: Asset.h:666
Definition: Libraries/Graphics/src/include/Graphics/Object.h:932
Definition: Libraries/Graphics/src/include/Graphics/Object.h:989
A block of text consisting of zero or more segments.
Definition: Libraries/Graphics/src/include/Graphics/Object.h:902
Draw a line of text.
Definition: Renderer.h:941
bool execute(Surface &surface) override
Called to do some writing to the surface.
TextRenderer(const Location &location, const TextObject &object)
Definition: Renderer.h:943
Class to enable buffering of a single line of text, with simple editing.
Definition: LineBuffer.h:139
ObjectType * head()
Definition: LinkedObjectList.h:104
ObjectType * getNext() const
Definition: LinkedObject.h:130
void init(IDataSourceStream *stream)
Application calls this method to set source for graphics resourcess.
Definition: Virtual.h:31
Rect intersect(Rect r1, const Rect &r2)
Definition: Libraries/Graphics/src/include/Graphics/Types.h:582
TPoint< int16_t > Point
Definition: Libraries/Graphics/src/include/Graphics/Types.h:280
PixelFormat
Definition: Colors.h:295
uint16_t normaliseAngle(int angle)
Make 0 <= angle < 360.
State information for tracing an ellipse outline.
Definition: Renderer.h:548
int32_t t
Definition: Renderer.h:577
int32_t d2xt
Definition: Renderer.h:580
int32_t ycrit
Definition: Renderer.h:576
int32_t dxt
Definition: Renderer.h:578
Ellipse(Size size)
Definition: Renderer.h:554
int32_t d2yt
Definition: Renderer.h:581
int32_t dyt
Definition: Renderer.h:579
uint16_t a
Definition: Renderer.h:569
uint16_t b
Definition: Renderer.h:570
int32_t xcrit
Definition: Renderer.h:575
Ellipse()
Definition: Renderer.h:549
int32_t b2
Definition: Renderer.h:574
Move
Definition: Renderer.h:561
uint16_t y
Definition: Renderer.h:572
uint16_t x
Definition: Renderer.h:571
int32_t a2
Definition: Renderer.h:573
Identifies position within bounding rectangle.
Definition: Libraries/Graphics/src/include/Graphics/Types.h:683
Point pos
Position relative to dest/source top-left corner.
Definition: Libraries/Graphics/src/include/Graphics/Types.h:702
Rect source
Reference source area.
Definition: Libraries/Graphics/src/include/Graphics/Types.h:697
Rect dest
Where to write pixels on surface.
Definition: Libraries/Graphics/src/include/Graphics/Types.h:687
Buffer used for reading pixel data from device.
Definition: Graphics/src/include/Graphics/Buffer.h:186
Composite ReadBuffer with status.
Definition: Graphics/src/include/Graphics/Buffer.h:222
Location and size of rectangular area (x, y, w, h)
Definition: Libraries/Graphics/src/include/Graphics/Types.h:287
Size size() const
Definition: Libraries/Graphics/src/include/Graphics/Types.h:447
bool contains(Point pt) const
Definition: Libraries/Graphics/src/include/Graphics/Types.h:481
uint16_t h
Definition: Libraries/Graphics/src/include/Graphics/Types.h:291
Point clip(Point pt) const
Definition: Libraries/Graphics/src/include/Graphics/Types.h:508
Point topLeft() const
Definition: Libraries/Graphics/src/include/Graphics/Types.h:417
uint16_t w
Definition: Libraries/Graphics/src/include/Graphics/Types.h:290
Size of rectangular area (width x height)
Definition: Libraries/Graphics/src/include/Graphics/Types.h:105