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 
168 class SceneRenderer : public MultiRenderer
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:
203  GfxLineRenderer(const Location& location, const LineObject& object)
204  : GfxLineRenderer(location, object.pen, object.pt1, object.pt2)
205  {
206  }
207 
208  GfxLineRenderer(const Location& location, Pen pen, Point pt1, Point pt2)
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;
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 
295 class PolylineRenderer : public Renderer
296 {
297 public:
298  PolylineRenderer(const Location& location, const PolylineObject& object) : Renderer(location), object(object)
299  {
300  }
301 
302  bool execute(Surface& surface) override;
303 
304 protected:
305  const PolylineObject& object;
306  LineObject line;
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 
352 class FilledRectRenderer : public Renderer
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 
365  FilledRectRenderer(const Location& location, const PointObject& object)
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 
407 class RoundedRectRenderer : public Renderer
408 {
409 public:
410  RoundedRectRenderer(const Location& location, const RectObject& object)
411  : Renderer(location), polyline(object), pen(object.pen), rect(object.rect),
412  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  renderer.reset(new PolylineRenderer(location, polyline));
418  }
419 
420  bool execute(Surface& surface) override;
421 
422 private:
423  std::unique_ptr<Renderer> renderer;
424  PolylineObject polyline;
425  Pen pen;
426  Rect rect;
427  uint8_t radius;
428  uint8_t state{0};
429  Point corners[4];
430 };
431 
437 class FilledRoundedRectRenderer : public Renderer
438 {
439 public:
441  : Renderer(location), object(object)
442  {
443  auto& rect = this->object.rect;
444  auto r = object.radius;
445  corners[0] = Point(rect.x + r, rect.y + r);
446  corners[1] = Point(rect.x + r, rect.bottom() - r);
447  }
448 
449  bool execute(Surface& surface) override;
450 
451 private:
452  std::unique_ptr<Renderer> renderer;
453  FilledRectObject object;
454  uint8_t state{0};
455  Point corners[2];
456 };
457 
463 class CircleRenderer : public Renderer
464 {
465 public:
466  CircleRenderer(const Location& location, const CircleObject& object)
467  : CircleRenderer(location, object.pen, object.centre, object.radius, 0, 0x0f)
468  {
469  pixels.add(x0, y0 + y);
470  pixels.add(x0, y0 - y);
471  pixels.add(x0 + y, y0);
472  pixels.add(x0 - y, y0);
473  }
474 
478  CircleRenderer(const Location& location, const Pen& pen, Point centre, uint16_t radius, uint16_t delta,
479  uint8_t corners)
480  : Renderer(location), pixels(location.dest, pen, 8), x0(centre.x), y0(centre.y), f(1 - radius), ddF_x(1),
481  ddF_y(-2 * radius), x(0), y(radius), delta(delta), corners(corners)
482  {
483  }
484 
485  bool execute(Surface& surface) override;
486 
487 private:
488  PointList pixels;
489  int16_t x0;
490  int16_t y0;
491  int16_t f;
492  int16_t ddF_x;
493  int16_t ddF_y;
494  int16_t x;
495  int16_t y;
496  uint16_t delta;
497  uint8_t corners;
498 };
499 
505 class FilledCircleRenderer : public Renderer
506 {
507 public:
509  : FilledCircleRenderer(location, object.brush, object.centre, object.radius, 0, 0x03)
510  {
511  addLine(x0 - x, x0 + x, y0);
512  }
513 
518  FilledCircleRenderer(const Location& location, const Brush& brush, Point centre, uint16_t radius, uint16_t delta,
519  uint8_t quadrants)
520  : Renderer(location), rectangles(location.dest, brush, 4), x0(centre.x), y0(centre.y), f(1 - radius),
521  ddF_x(-2 * radius), ddF_y(1), x(radius), y(0), px(x), py(y), delta(delta), quadrants(quadrants)
522  {
523  }
524 
525  bool execute(Surface& surface) override;
526 
527 private:
528  void addLine(uint16_t x0, uint16_t x1, uint16_t y)
529  {
530  rectangles.add(Rect(x0, y, 1 + x1 - x0, 1));
531  }
532 
533  RectList rectangles;
534  int16_t x0;
535  int16_t y0;
536  int16_t f;
537  int16_t ddF_x;
538  int16_t ddF_y;
539  int16_t x;
540  int16_t y;
541  int16_t px;
542  int16_t py;
543  uint16_t delta;
544  uint8_t quadrants;
545  Location loc;
546  uint16_t pixelsToWrite{0};
547 };
548 
552 struct Ellipse {
553  Ellipse()
554  {
555  }
556 
557  /* ellipse: e(x,y) = b*b*x*x + a*a*y*y - a*a*b*b */
558  Ellipse(Size size)
559  : a(size.w / 2), b(size.h / 2), x(0), y(b), a2(a * a), b2(b * b), xcrit((3 * a2 / 4) + 1),
560  ycrit((3 * b2 / 4) + 1), t(b2 + a2 - 2 * a2 * b), dxt(b2 * (3 + x + x)), dyt(a2 * (3 - y - y)), d2xt(b2 + b2),
561  d2yt(a2 + a2)
562  {
563  }
564 
565  enum class Move {
566  down,
567  out,
568  };
570 
572 
573  uint16_t a; // semi-major axis length
574  uint16_t b; // semi-minor axis length
575  uint16_t x;
576  uint16_t y;
577  int32_t a2;
578  int32_t b2;
579  int32_t xcrit;
580  int32_t ycrit;
581  int32_t t;
582  int32_t dxt;
583  int32_t dyt;
584  int32_t d2xt;
585  int32_t d2yt;
586 };
587 
588 class ArcRectList : public RectList
589 {
590 public:
591  using RectList::RectList;
592 
593  void fill(const Rect& r, Point p0, Point p1, Point p2, int start_angle, int end_angle);
594 };
595 
603 class EllipseRenderer : public Renderer
604 {
605 public:
606  EllipseRenderer(const Location& location, const Pen& pen, const Rect& rect)
607  : Renderer(location), r(rect), rectangles(location.dest, pen, 8), w(pen.width)
608  {
609  }
610 
611  EllipseRenderer(const Location& location, const EllipseObject& object)
612  : EllipseRenderer(location, object.pen, object.rect)
613  {
614  }
615 
616  EllipseRenderer(const Location& location, const CircleObject& object)
617  : EllipseRenderer(location, object.pen, object.getRect())
618  {
619  }
620 
621  bool execute(Surface& surface) override;
622 
623 protected:
624  enum class State {
626  running,
627  final1,
628  final2,
629  done,
630  };
631 
632  virtual void addRectangles1();
633  virtual void addRectangles2();
634  virtual void final();
635 
636  const Rect r;
637  Rect r1;
638  Rect r2;
640  const uint16_t w;
641  uint16_t W;
642  State state{};
643 
644 private:
645  Ellipse outer;
646  Ellipse inner;
647  Point prev;
648  uint16_t innerX{0};
649 };
650 
657 {
658 public:
659  FilledEllipseRenderer(const Location& location, const Brush& brush, const Rect& rect)
660  : Renderer(location), r(rect), rectangles(location.dest, brush, 4)
661  {
662  }
663 
665  : FilledEllipseRenderer(location, object.brush, object.rect)
666  {
667  }
668 
669  FilledEllipseRenderer(const Location& location, const FilledCircleObject& object)
670  : FilledEllipseRenderer(location, object.brush, object.getRect())
671  {
672  }
673 
674  bool execute(Surface& surface) override;
675 
676 protected:
677  virtual void doStep(Ellipse::Step step);
678  virtual void final();
679 
680  enum class State {
681  init,
682  running,
683  final,
684  done,
685  };
686 
687  const Rect r;
689  Ellipse e;
690  Rect r1;
691  Rect r2;
692  State state{};
693 };
694 
698 class ArcRenderer : public EllipseRenderer
699 {
700 public:
701  ArcRenderer(const Location& location, const Pen& pen, const Rect& rect, int start_angle, int end_angle)
702  : EllipseRenderer(location, pen, rect), start_angle(normaliseAngle(start_angle)),
703  end_angle(normaliseAngle(end_angle))
704  {
705  }
706 
707  bool execute(Surface& surface) override;
708 
709 protected:
710  void addRectangles1() override;
711  void addRectangles2() override;
712  void final() override;
713 
714 private:
715  /* Input parameters */
716  uint16_t start_angle;
717  uint16_t end_angle;
718 
719  /* arc wedge line end points */
720  Point p0;
721  Point p1;
722  Point p2;
723 };
724 
729 {
730 public:
731  FilledArcRenderer(const Location& location, const Brush& brush, const Rect& rect, int start_angle, int end_angle)
732  : FilledEllipseRenderer(location, brush, rect), start_angle(normaliseAngle(start_angle)),
733  end_angle(normaliseAngle(end_angle))
734  {
735  }
736 
737  bool execute(Surface& surface) override;
738 
739 protected:
740  void doStep(Ellipse::Step step) override;
741  void final() override;
742 
743 private:
744  int16_t start_angle;
745  int16_t end_angle;
746  Point p0;
747  Point p1;
748  Point p2;
749 };
750 
754 class ImageRenderer : public Renderer
755 {
756 public:
757  ImageRenderer(const Location& location, const ImageObject& object) : Renderer(location), object(object)
758  {
759  }
760 
761  bool execute(Surface& surface) override;
762 
763 private:
764  const ImageObject& object;
765  uint8_t bytesPerPixel{0};
766  PixelFormat pixelFormat{};
767 };
768 
774 class SurfaceRenderer : public Renderer
775 {
776 public:
777  SurfaceRenderer(const Location& location, const SurfaceObject& object)
778  : SurfaceRenderer(location, object.surface, object.dest, object.source)
779  {
780  }
781 
782  SurfaceRenderer(const Location& location, Surface& target, const Rect& dest, Point source)
783  : Renderer(location), target(target), dest(dest), source(source)
784  {
785  }
786 
787  bool execute(Surface& surface) override;
788 
789 private:
790  static constexpr uint16_t bufSize{512};
791  ReadBuffer buffers[2];
792  Surface& target;
793  Rect dest;
794  Point source;
795  PixelFormat pixelFormat{};
796  uint8_t bufIndex{0};
797  bool done{false};
798  uint8_t busyCount{0};
799 };
800 
804 class CopyRenderer : public Renderer
805 {
806 public:
807  using Renderer::Renderer;
808 
809  CopyRenderer(const Location& location, const CopyObject& object) : Renderer(location)
810  {
811  Rect src = object.source;
812  Rect dst(object.dest, object.source.size());
813  src += this->location.dest.topLeft();
814  dst += this->location.dest.topLeft();
815  // TODO: Do X/Y separately
816  src.clip(location.dest);
817  dst.clip(location.dest);
818  src.w = dst.w = std::min(src.w, dst.w);
819  src.h = dst.h = std::min(src.h, dst.h);
820  this->location.dest = dst;
821  this->location.source = src;
822  }
823 
824  bool execute(Surface& surface) override;
825 
826 protected:
827  void init();
828  void startRead(Surface& surface);
829 
830  /* Position is given in `location` */
831  virtual void readComplete(uint8_t* data, size_t length)
832  {
833  }
834 
837  bool vertical;
838 
839 private:
840  using LineBuffer = ReadStatusBuffer;
841  LineBuffer lineBuffers[2];
842  uint16_t lineSize; // Width or height
843  uint16_t lineCount;
844  uint16_t readIndex{0};
845  uint16_t writeIndex{0};
846  TPoint<int8_t> shift{};
847 };
848 
849 class ImageCopyRenderer : public CopyRenderer
850 {
851 public:
852  ImageCopyRenderer(const Location& location, const ImageObject& image, const Blend* blend)
853  : CopyRenderer({location.dest, location.dest}), image(image), blend(blend)
854  {
855  auto& dst = location.dest;
856  this->location.source.w = this->location.dest.w = std::min(dst.w, image.width());
857  this->location.source.h = this->location.dest.h = std::min(dst.h, image.height());
858  }
859 
860 protected:
861  void readComplete(uint8_t* data, size_t length) override;
862 
863 private:
864  const ImageObject& image;
865  const Blend* blend;
866 };
867 
871 class ScrollRenderer : public Renderer
872 {
873 public:
874  ScrollRenderer(const Location& location, const ScrollObject& object) : Renderer(location), object(object)
875  {
876  }
877 
878  bool execute(Surface& surface) override;
879 
880 private:
881  void init();
882  bool startRead(Surface& surface);
883  int16_t checkx(int16_t x);
884  int16_t checky(int16_t y);
885  void stepx(uint16_t& index, int16_t& x);
886  void stepy(uint16_t& index, int16_t& y);
887 
889 
890  const ScrollObject& object;
891  Rect src{};
892  Rect dst{};
893  int16_t cx;
894  int16_t cy;
895  uint16_t readOffset{0};
896  uint16_t writeOffset{0};
897  LineBuffer lineBuffers[2];
898  uint16_t lineCount;
899  uint16_t readIndex{0};
900  uint16_t writeIndex{0};
901  Rect readArea;
902  Rect writeArea;
903  PackedColor fill;
904  PixelFormat pixelFormat{};
905  uint8_t bytesPerPixel;
906  bool vertical; // If true, copy vertical lines
907  uint8_t state{0};
908 };
909 
913 class BlendRenderer : public Renderer
914 {
915 public:
916  BlendRenderer(const Location& location, const Object& object, const Blend* blend)
917  : Renderer(location), object(object), blend(blend)
918  {
919  }
920 
921  bool execute(Surface& surface) override;
922 
923 private:
924  enum class State {
925  init,
926  draw,
927  done,
928  };
929 
930  const Object& object;
931  std::unique_ptr<Renderer> renderer;
932  std::unique_ptr<MemoryImageObject> image;
933  std::unique_ptr<Surface> imageSurface;
934  PixelFormat pixelFormat;
935  const Blend* blend;
936  State nextState{};
937 };
938 
944 class TextRenderer : public Renderer
945 {
946 public:
947  TextRenderer(const Location& location, const TextObject& object)
948  : Renderer(location), object(object), alphaBuffer(object, location.dest.h - location.pos.y),
949  element(alphaBuffer.element)
950  {
951  this->location.dest += object.bounds.topLeft();
952  this->location.pos = Point{};
953  }
954 
955  bool execute(Surface& surface) override;
956 
957 private:
958  struct AlphaBuffer {
959  const TextObject::Element* element;
960  const TextAsset* text{nullptr};
961  const TextObject::FontElement* font{nullptr};
962  std::unique_ptr<uint8_t[]> data;
963  Size size{};
964  uint16_t charIndex{0};
965  uint16_t x{0};
966  uint16_t xo{0};
967  uint16_t ymax;
968  uint8_t advdiff{0};
969 
970  AlphaBuffer(const TextObject& object, uint16_t ymax) : element{object.elements.head()}, ymax(ymax)
971  {
972  }
973 
974  void init(Size size)
975  {
976  data.reset(new uint8_t[size.w * size.h]{});
977  this->size = size;
978  }
979 
980  void clear()
981  {
982  memset(data.get(), 0, size.w * size.h);
983  }
984 
985  void fill();
986 
987  bool finished()
988  {
989  return element == nullptr;
990  }
991 
992  // Shift content from given position to start of buffer, clear the vacated space
993  void shift(uint16_t count)
994  {
995  count = std::min(count, x);
996  auto row = data.get();
997  for(unsigned i = 0; i < size.h; ++i) {
998  memmove(row, &row[count], size.w - count);
999  memset(&row[size.w - count], 0, count);
1000  row += size.w;
1001  }
1002  xo += count;
1003  x -= count;
1004  }
1005  };
1006 
1007  struct BackBuffer : public ReadStatusBuffer {
1008  static constexpr size_t bufSize{512};
1009 
1010  BackBuffer() : ReadStatusBuffer(PixelFormat::None, bufSize)
1011  {
1012  }
1013 
1014  Rect r{};
1015  Point pos{};
1016  const TextObject::RunElement* run{nullptr};
1017  TextOptions options;
1018  uint16_t glyphPixels;
1019  bool lastRow{false};
1020  };
1021 
1022  void getNextRun();
1023  bool startRead(Surface& surface);
1024  bool renderBuffer(Surface& surface, BackBuffer& backBuffer);
1025 
1026  const TextObject& object;
1027  AlphaBuffer alphaBuffer;
1028  const TextObject::RunElement* run{nullptr};
1029  const TextObject::Element* element;
1030  GlyphObject::Options options;
1031  BackBuffer backBuffers[2];
1032  uint8_t readIndex{0};
1033  uint8_t writeIndex{0};
1034  const TypeFace* typeface{nullptr};
1035  PixelFormat pixelFormat{};
1036  uint8_t bytesPerPixel;
1037  uint8_t busyCount{0};
1038 };
1039 
1040 } // namespace Graphics
int16_t bottom() const
Definition: Libraries/Graphics/src/include/Graphics/Types.h:431
std::unique_ptr< Renderer > renderer
Definition: Renderer.h:326
bool contains(Point pt) const
Definition: Libraries/Graphics/src/include/Graphics/Types.h:500
virtual void readComplete(uint8_t *data, size_t length)
Definition: Renderer.h:850
uint16_t index
Definition: Renderer.h:327
SurfaceRenderer(const Location &location, const SurfaceObject &object)
Definition: Renderer.h:796
bool render(Surface &surface)
bool execute(Surface &surface) override
Called to do some writing to the surface.
Rect r1
Definition: Renderer.h:656
ItemList(uint8_t capacity)
Definition: Renderer.h:78
Draws a filled rectangle with rounded corners.
Definition: Renderer.h:456
A drawn line.
Definition: Libraries/Graphics/src/include/Graphics/Object.h:276
uint16_t normaliseAngle(int angle)
Make 0 <= angle < 360.
FilledCircleRenderer(const Location &location, const FilledCircleObject &object)
Definition: Renderer.h:527
State state
Definition: Renderer.h:661
int32_t xcrit
Definition: Renderer.h:598
bool execute(Surface &surface) override
Called to do some writing to the surface.
Copy an area to another surface.
Definition: Renderer.h:793
FilledRoundedRectRenderer(const Location &location, const FilledRectObject &object)
Definition: Renderer.h:459
Render an image object.
Definition: Renderer.h:773
const Rect r
Definition: Renderer.h:655
uint16_t x
Definition: Renderer.h:594
bool execute(Surface &surface) override
Called to do some writing to the surface.
A circle outline.
Definition: Libraries/Graphics/src/include/Graphics/Object.h:389
int16_t right() const
Definition: Libraries/Graphics/src/include/Graphics/Types.h:421
ObjectType * getNext() const
Definition: LinkedObject.h:130
bool execute(Surface &surface) override
Called to do some writing to the surface.
A filled rectangle.
Definition: Libraries/Graphics/src/include/Graphics/Object.h:245
LineObject line
Definition: Renderer.h:325
bool execute(Surface &surface) override
Called to do some writing to the surface.
Location and size of rectangular area (x, y, w, h)
Definition: Libraries/Graphics/src/include/Graphics/Types.h:306
const Rect r
Definition: Renderer.h:706
virtual const Object * getNextObject()=0
bool execute(Surface &surface) override
Called to do some writing to the surface.
ImageCopyRenderer(const Location &location, const ImageObject &image, const Blend *blend)
Definition: Renderer.h:871
Virtual base class to manage rendering of various types of information to a surface.
Definition: Libraries/Graphics/src/include/Graphics/Object.h:84
ImageRenderer(const Location &location, const ImageObject &object)
Definition: Renderer.h:776
bool vertical
Definition: Renderer.h:856
int32_t d2yt
Definition: Renderer.h:604
Render arc outline with adjustable line width.
Definition: Renderer.h:747
Scroll an area.
Definition: Renderer.h:890
Draws a filled ellipse.
Definition: Renderer.h:675
void add(const Rect &rect)
Definition: Renderer.h:146
TextOptions Options
Definition: Libraries/Graphics/src/include/Graphics/Object.h:874
A filled ellipse.
Definition: Libraries/Graphics/src/include/Graphics/Object.h:500
void init(IDataSourceStream *stream)
Application calls this method to set source for graphics resourcess.
Composite ReadBuffer with status.
Definition: Graphics/src/include/Graphics/Buffer.h:241
bool execute(Surface &surface) override
Called to do some writing to the surface.
A single pixel == 1x1 rectangle.
Definition: Libraries/Graphics/src/include/Graphics/Object.h:193
Definition: Asset.h:421
bool execute(Surface &surface) override
Called to do some writing to the surface.
Identifies position within bounding rectangle.
Definition: Libraries/Graphics/src/include/Graphics/Types.h:702
Draws an ellipse outline.
Definition: Renderer.h:622
Interface for a drawing surface.
Definition: Surface.h:60
uint16_t width() const
Definition: Libraries/Graphics/src/include/Graphics/Object.h:600
CopyRenderer(const Location &location, const CopyObject &object)
Definition: Renderer.h:828
State state
Definition: Renderer.h:711
State
Definition: Renderer.h:699
The source of colour for drawing.
Definition: Asset.h:271
void addRectangles2() override
BitSet< uint8_t, Move, 2 > Step
Definition: Renderer.h:588
Fixed list of types.
Definition: Renderer.h:56
virtual void renderDone(const Object *object)=0
bool execute(Surface &surface) override
Called to do some writing to the surface.
void add(T value)
Definition: Renderer.h:83
Size of rectangular area (width x height)
Definition: Libraries/Graphics/src/include/Graphics/Types.h:124
PixelFormat pixelFormat
Definition: Renderer.h:854
const uint16_t w
Definition: Renderer.h:659
uint16_t y
Definition: Renderer.h:595
uint16_t W
Definition: Renderer.h:660
Move
Definition: Renderer.h:584
PointList(const Rect &bounds, const Brush &brush, uint8_t capacity)
Definition: Renderer.h:109
uint16_t width
Definition: Asset.h:452
int32_t a2
Definition: Renderer.h:596
Definition: Virtual.h:30
Ellipse e
Definition: Renderer.h:708
TPoint< int16_t > Point
Definition: Libraries/Graphics/src/include/Graphics/Types.h:299
uint8_t bytesPerPixel
Definition: Renderer.h:855
bool execute(Surface &surface) override
Called to do some writing to the surface.
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:750
A drawable object inherits from this virtual base class.
Definition: Libraries/Graphics/src/include/Graphics/Object.h:115
Draws a filled circle.
Definition: Renderer.h:524
int16_t x
Definition: Libraries/Graphics/src/include/Graphics/Types.h:307
Rect r2
Definition: Renderer.h:710
int16_t y
Definition: Libraries/Graphics/src/include/Graphics/Types.h:308
const PolylineObject & object
Definition: Renderer.h:324
ObjectType * head()
Definition: LinkedObjectList.h:104
RectList(const Rect &bounds, const Brush &brush, uint8_t capacity)
Definition: Renderer.h:141
Manage a set of bit values using enumeration.
Definition: BitSet.h:44
An ellipse outline.
Definition: Libraries/Graphics/src/include/Graphics/Object.h:473
bool execute(Surface &surface) override
Called to do some writing to the surface.
Rect r2
Definition: Renderer.h:657
uint16_t height() const
Definition: Libraries/Graphics/src/include/Graphics/Object.h:605
FilledEllipseRenderer(const Location &location, const Brush &brush, const Rect &rect)
Definition: Renderer.h:678
bool execute(Surface &surface) override
Called to do some writing to the surface.
void readComplete(uint8_t *data, size_t length) override
virtual void doStep(Ellipse::Step step)
BlendRenderer(const Location &location, const Object &object, const Blend *blend)
Definition: Renderer.h:935
int32_t dyt
Definition: Renderer.h:602
A Scene containing multiple objects.
Definition: Scene.h:50
int32_t d2xt
Definition: Renderer.h:603
void reset()
Definition: Renderer.h:100
SceneRenderer(const Location &location, const SceneObject &scene)
Definition: Renderer.h:190
ArcRectList rectangles
Definition: Renderer.h:658
A filled circle.
Definition: Libraries/Graphics/src/include/Graphics/Object.h:430
EllipseRenderer(const Location &location, const Pen &pen, const Rect &rect)
Definition: Renderer.h:625
PolylineRenderer(const Location &location, const PolylineObject &object)
Definition: Renderer.h:317
void add(int16_t x, int16_t y)
Definition: Renderer.h:114
T * get()
Definition: Renderer.h:89
void renderDone(const Object *object) override
Definition: Renderer.h:195
void fill(const Rect &r, Point p0, Point p1, Point p2, int start_angle, int end_angle)
A scene is a list of other objects, so we just iterate through the list and draw each in turn.
Definition: Renderer.h:187
Rect r1
Definition: Renderer.h:709
ArcRectList rectangles
Definition: Renderer.h:707
uint16_t a
Definition: Renderer.h:592
int16_t left() const
Definition: Libraries/Graphics/src/include/Graphics/Types.h:416
Blend operations.
Definition: Blend.h:60
const Object * getNextObject() override
Definition: Renderer.h:199
PixelFormat
Definition: Colors.h:295
int32_t ycrit
Definition: Renderer.h:599
virtual void addRectangles1()
bool execute(Surface &surface) override
Called to do some writing to the surface.
Rect dest
Where to write pixels on surface.
Definition: Libraries/Graphics/src/include/Graphics/Types.h:706
Small list of points for drawing.
Definition: Renderer.h:104
bool execute(Surface &surface) override
Called to do some writing to the surface.
TextRenderer(const Location &location, const TextObject &object)
Definition: Renderer.h:966
Size size() const
Definition: Libraries/Graphics/src/include/Graphics/Types.h:466
uint16_t w
Definition: Libraries/Graphics/src/include/Graphics/Types.h:309
Rect source
Reference source area.
Definition: Libraries/Graphics/src/include/Graphics/Types.h:716
Describes a target surface and corresponding source location.
Definition: Libraries/Graphics/src/include/Graphics/Object.h:1115
bool execute(Surface &surface) override
Called to do some writing to the surface.
FilledRectRenderer(const Location &location, const Brush &brush, const Rect &rect, const Blend *blender=nullptr)
Definition: Renderer.h:374
T * next()
Definition: Renderer.h:94
ScrollRenderer(const Location &location, const ScrollObject &object)
Definition: Renderer.h:893
CircleRenderer(const Location &location, const CircleObject &object)
Definition: Renderer.h:485
State information for tracing an ellipse outline.
Definition: Renderer.h:571
Class to enable buffering of a single line of text, with simple editing.
Definition: LineBuffer.h:22
int32_t dxt
Definition: Renderer.h:601
Describes a scrolling operation.
Definition: Libraries/Graphics/src/include/Graphics/Object.h:1166
void startRead(Surface &surface)
Virtual base class for an image.
Definition: Libraries/Graphics/src/include/Graphics/Object.h:581
Renderer(const Location &location)
Constructor.
Definition: Libraries/Graphics/src/include/Graphics/Object.h:94
Definition: Renderer.h:607
A rectangular outline.
Definition: Libraries/Graphics/src/include/Graphics/Object.h:215
int32_t b2
Definition: Renderer.h:597
uint16_t h
Definition: Libraries/Graphics/src/include/Graphics/Types.h:310
int32_t t
Definition: Renderer.h:600
GfxLineRenderer(const Location &location, const LineObject &object)
Definition: Renderer.h:222
Base class to render multiple objects.
Definition: Renderer.h:165
virtual void addRectangles2()
bool execute(Surface &surface) override
Called to do some writing to the surface.
Definition: Renderer.h:357
uint16_t b
Definition: Renderer.h:593
State
Definition: Renderer.h:643
Ellipse()
Definition: Renderer.h:572
Draws a rectangle as a polyline.
Definition: Renderer.h:333
void addRectangles1() override
bool render(Surface &surface)
Render each point.
Draws lines.
Definition: Renderer.h:257
bool execute(Surface &surface) override
Called to do some writing to the surface.
int16_t top() const
Definition: Libraries/Graphics/src/include/Graphics/Types.h:426
RoundedRectRenderer(const Location &location, const RectObject &object)
Definition: Renderer.h:429
bool execute(Surface &surface) override
Called to do some writing to the surface.
ArcRenderer(const Location &location, const Pen &pen, const Rect &rect, int start_angle, int end_angle)
Definition: Renderer.h:720
LineRenderer(const Location &location, const LineObject &object)
Definition: Renderer.h:260
OwnedList objects
Definition: Scene.h:267
Small list of rectangles, similar to PointList.
Definition: Renderer.h:138
Location location
Definition: Libraries/Graphics/src/include/Graphics/Object.h:109
Draws a circle outline.
Definition: Renderer.h:482
RectRenderer(const Location &location, const Pen &pen, const Rect &rect)
Definition: Renderer.h:336
void doStep(Ellipse::Step step) override
bool execute(Surface &surface) override
Called to do some writing to the surface.
Rect intersect(Rect r1, const Rect &r2)
Definition: Libraries/Graphics/src/include/Graphics/Types.h:601