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, 0, 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, uint16_t delta,
478  uint8_t corners)
479  : Renderer(location), pixels(location.dest, pen, 8), x0(centre.x), y0(centre.y), f(1 - radius), ddF_x(1),
480  ddF_y(-2 * radius), x(0), y(radius), delta(delta), corners(corners)
481  {
482  }
483 
484  bool execute(Surface& surface) override;
485 
486 private:
487  PointList pixels;
488  int16_t x0;
489  int16_t y0;
490  int16_t f;
491  int16_t ddF_x;
492  int16_t ddF_y;
493  int16_t x;
494  int16_t y;
495  uint16_t delta;
496  uint8_t corners;
497 };
498 
505 {
506 public:
508  : FilledCircleRenderer(location, object.brush, object.centre, object.radius, 0, 0x03)
509  {
510  addLine(x0 - x, x0 + x, y0);
511  }
512 
517  FilledCircleRenderer(const Location& location, const Brush& brush, Point centre, uint16_t radius, uint16_t delta,
518  uint8_t quadrants)
519  : Renderer(location), rectangles(location.dest, brush, 4), x0(centre.x), y0(centre.y), f(1 - radius),
520  ddF_x(-2 * radius), ddF_y(1), x(radius), y(0), px(x), py(y), delta(delta), quadrants(quadrants)
521  {
522  }
523 
524  bool execute(Surface& surface) override;
525 
526 private:
527  void addLine(uint16_t x0, uint16_t x1, uint16_t y)
528  {
529  rectangles.add(Rect(x0, y, 1 + x1 - x0, 1));
530  }
531 
532  RectList rectangles;
533  int16_t x0;
534  int16_t y0;
535  int16_t f;
536  int16_t ddF_x;
537  int16_t ddF_y;
538  int16_t x;
539  int16_t y;
540  int16_t px;
541  int16_t py;
542  uint16_t delta;
543  uint8_t quadrants;
544  Location loc;
545  uint16_t pixelsToWrite{0};
546 };
547 
551 struct Ellipse {
553  {
554  }
555 
556  /* ellipse: e(x,y) = b*b*x*x + a*a*y*y - a*a*b*b */
557  Ellipse(Size size)
558  : a(size.w / 2), b(size.h / 2), x(0), y(b), a2(a * a), b2(b * b), xcrit((3 * a2 / 4) + 1),
559  ycrit((3 * b2 / 4) + 1), t(b2 + a2 - 2 * a2 * b), dxt(b2 * (3 + x + x)), dyt(a2 * (3 - y - y)), d2xt(b2 + b2),
560  d2yt(a2 + a2)
561  {
562  }
563 
564  enum class Move {
565  down,
566  out,
567  };
569 
571 
572  uint16_t a; // semi-major axis length
573  uint16_t b; // semi-minor axis length
574  uint16_t x;
575  uint16_t y;
576  int32_t a2;
577  int32_t b2;
578  int32_t xcrit;
579  int32_t ycrit;
580  int32_t t;
581  int32_t dxt;
582  int32_t dyt;
583  int32_t d2xt;
584  int32_t d2yt;
585 };
586 
587 class ArcRectList : public RectList
588 {
589 public:
590  using RectList::RectList;
591 
592  void fill(const Rect& r, Point p0, Point p1, Point p2, int start_angle, int end_angle);
593 };
594 
602 class EllipseRenderer : public Renderer
603 {
604 public:
605  EllipseRenderer(const Location& location, const Pen& pen, const Rect& rect)
606  : Renderer(location), r(rect), rectangles(location.dest, pen, 8), w(pen.width)
607  {
608  }
609 
611  : EllipseRenderer(location, object.pen, object.rect)
612  {
613  }
614 
616  : EllipseRenderer(location, object.pen, object.getRect())
617  {
618  }
619 
620  bool execute(Surface& surface) override;
621 
622 protected:
623  enum class State {
624  init,
625  running,
626  final1,
627  final2,
628  done,
629  };
630 
631  virtual void addRectangles1();
632  virtual void addRectangles2();
633  virtual void final();
634 
635  const Rect r;
639  const uint16_t w;
640  uint16_t W;
642 
643 private:
644  Ellipse outer;
645  Ellipse inner;
646  Point prev;
647  uint16_t innerX{0};
648 };
649 
656 {
657 public:
658  FilledEllipseRenderer(const Location& location, const Brush& brush, const Rect& rect)
659  : Renderer(location), r(rect), rectangles(location.dest, brush, 4)
660  {
661  }
662 
664  : FilledEllipseRenderer(location, object.brush, object.rect)
665  {
666  }
667 
669  : FilledEllipseRenderer(location, object.brush, object.getRect())
670  {
671  }
672 
673  bool execute(Surface& surface) override;
674 
675 protected:
676  virtual void doStep(Ellipse::Step step);
677  virtual void final();
678 
679  enum class State {
680  init,
681  running,
682  final,
683  done,
684  };
685 
686  const Rect r;
692 };
693 
698 {
699 public:
700  ArcRenderer(const Location& location, const Pen& pen, const Rect& rect, int start_angle, int end_angle)
701  : EllipseRenderer(location, pen, rect), start_angle(normaliseAngle(start_angle)),
702  end_angle(normaliseAngle(end_angle))
703  {
704  }
705 
706  bool execute(Surface& surface) override;
707 
708 protected:
709  void addRectangles1() override;
710  void addRectangles2() override;
711  void final() override;
712 
713 private:
714  /* Input parameters */
715  uint16_t start_angle;
716  uint16_t end_angle;
717 
718  /* arc wedge line end points */
719  Point p0;
720  Point p1;
721  Point p2;
722 };
723 
728 {
729 public:
730  FilledArcRenderer(const Location& location, const Brush& brush, const Rect& rect, int start_angle, int end_angle)
731  : FilledEllipseRenderer(location, brush, rect), start_angle(normaliseAngle(start_angle)),
732  end_angle(normaliseAngle(end_angle))
733  {
734  }
735 
736  bool execute(Surface& surface) override;
737 
738 protected:
739  void doStep(Ellipse::Step step) override;
740  void final() override;
741 
742 private:
743  int16_t start_angle;
744  int16_t end_angle;
745  Point p0;
746  Point p1;
747  Point p2;
748 };
749 
753 class ImageRenderer : public Renderer
754 {
755 public:
756  ImageRenderer(const Location& location, const ImageObject& object) : Renderer(location), object(object)
757  {
758  }
759 
760  bool execute(Surface& surface) override;
761 
762 private:
763  const ImageObject& object;
764  uint8_t bytesPerPixel{0};
765  PixelFormat pixelFormat{};
766 };
767 
773 class SurfaceRenderer : public Renderer
774 {
775 public:
777  : SurfaceRenderer(location, object.surface, object.dest, object.source)
778  {
779  }
780 
781  SurfaceRenderer(const Location& location, Surface& target, const Rect& dest, Point source)
782  : Renderer(location), target(target), dest(dest), source(source)
783  {
784  }
785 
786  bool execute(Surface& surface) override;
787 
788 private:
789  static constexpr uint16_t bufSize{512};
790  ReadBuffer buffers[2];
791  Surface& target;
792  Rect dest;
793  Point source;
794  PixelFormat pixelFormat{};
795  uint8_t bufIndex{0};
796  bool done{false};
797  uint8_t busyCount{0};
798 };
799 
803 class CopyRenderer : public Renderer
804 {
805 public:
806  using Renderer::Renderer;
807 
809  {
810  Rect src = object.source;
811  Rect dst(object.dest, object.source.size());
812  src += this->location.dest.topLeft();
813  dst += this->location.dest.topLeft();
814  // TODO: Do X/Y separately
815  src.clip(location.dest);
816  dst.clip(location.dest);
817  src.w = dst.w = std::min(src.w, dst.w);
818  src.h = dst.h = std::min(src.h, dst.h);
819  this->location.dest = dst;
820  this->location.source = src;
821  }
822 
823  bool execute(Surface& surface) override;
824 
825 protected:
826  void init();
827  void startRead(Surface& surface);
828 
829  /* Position is given in `location` */
830  virtual void readComplete(uint8_t* data, size_t length)
831  {
832  }
833 
835  uint8_t bytesPerPixel;
836  bool vertical;
837 
838 private:
840  LineBuffer lineBuffers[2];
841  uint16_t lineSize; // Width or height
842  uint16_t lineCount;
843  uint16_t readIndex{0};
844  uint16_t writeIndex{0};
845  TPoint<int8_t> shift{};
846 };
847 
849 {
850 public:
851  ImageCopyRenderer(const Location& location, const ImageObject& image, const Blend* blend)
852  : CopyRenderer({location.dest, location.dest}), image(image), blend(blend)
853  {
854  auto& dst = location.dest;
855  this->location.source.w = this->location.dest.w = std::min(dst.w, image.width());
856  this->location.source.h = this->location.dest.h = std::min(dst.h, image.height());
857  }
858 
859 protected:
860  void readComplete(uint8_t* data, size_t length) override;
861 
862 private:
863  const ImageObject& image;
864  const Blend* blend;
865 };
866 
870 class ScrollRenderer : public Renderer
871 {
872 public:
873  ScrollRenderer(const Location& location, const ScrollObject& object) : Renderer(location), object(object)
874  {
875  }
876 
877  bool execute(Surface& surface) override;
878 
879 private:
880  void init();
881  bool startRead(Surface& surface);
882  int16_t checkx(int16_t x);
883  int16_t checky(int16_t y);
884  void stepx(uint16_t& index, int16_t& x);
885  void stepy(uint16_t& index, int16_t& y);
886 
888 
889  const ScrollObject& object;
890  Rect src{};
891  Rect dst{};
892  int16_t cx;
893  int16_t cy;
894  uint16_t readOffset{0};
895  uint16_t writeOffset{0};
896  LineBuffer lineBuffers[2];
897  uint16_t lineCount;
898  uint16_t readIndex{0};
899  uint16_t writeIndex{0};
900  Rect readArea;
901  Rect writeArea;
902  PackedColor fill;
903  PixelFormat pixelFormat{};
904  uint8_t bytesPerPixel;
905  bool vertical; // If true, copy vertical lines
906  uint8_t state{0};
907 };
908 
912 class BlendRenderer : public Renderer
913 {
914 public:
915  BlendRenderer(const Location& location, const Object& object, const Blend* blend)
916  : Renderer(location), object(object), blend(blend)
917  {
918  }
919 
920  bool execute(Surface& surface) override;
921 
922 private:
923  enum class State {
924  init,
925  draw,
926  done,
927  };
928 
929  const Object& object;
930  std::unique_ptr<Renderer> renderer;
931  std::unique_ptr<MemoryImageObject> image;
932  std::unique_ptr<Surface> imageSurface;
933  PixelFormat pixelFormat;
934  const Blend* blend;
935  State nextState{};
936 };
937 
943 class TextRenderer : public Renderer
944 {
945 public:
946  TextRenderer(const Location& location, const TextObject& object)
947  : Renderer(location), object(object), alphaBuffer(object, location.dest.h - location.pos.y),
948  element(alphaBuffer.element)
949  {
950  this->location.dest += object.bounds.topLeft();
951  this->location.pos = Point{};
952  }
953 
954  bool execute(Surface& surface) override;
955 
956 private:
957  struct AlphaBuffer {
958  const TextObject::Element* element;
959  const TextAsset* text{nullptr};
960  const TextObject::FontElement* font{nullptr};
961  std::unique_ptr<uint8_t[]> data;
962  Size size{};
963  uint16_t charIndex{0};
964  uint16_t x{0};
965  uint16_t xo{0};
966  uint16_t ymax;
967  uint8_t advdiff{0};
968 
969  AlphaBuffer(const TextObject& object, uint16_t ymax) : element{object.elements.head()}, ymax(ymax)
970  {
971  }
972 
973  void init(Size size)
974  {
975  data.reset(new uint8_t[size.w * size.h]{});
976  this->size = size;
977  }
978 
979  void clear()
980  {
981  memset(data.get(), 0, size.w * size.h);
982  }
983 
984  void fill();
985 
986  bool finished()
987  {
988  return element == nullptr;
989  }
990 
991  // Shift content from given position to start of buffer, clear the vacated space
992  void shift(uint16_t count)
993  {
994  count = std::min(count, x);
995  auto row = data.get();
996  for(unsigned i = 0; i < size.h; ++i) {
997  memmove(row, &row[count], size.w - count);
998  memset(&row[size.w - count], 0, count);
999  row += size.w;
1000  }
1001  xo += count;
1002  x -= count;
1003  }
1004  };
1005 
1006  struct BackBuffer : public ReadStatusBuffer {
1007  static constexpr size_t bufSize{512};
1008 
1009  BackBuffer() : ReadStatusBuffer(PixelFormat::None, bufSize)
1010  {
1011  }
1012 
1013  Rect r{};
1014  Point pos{};
1015  const TextObject::RunElement* run{nullptr};
1016  TextOptions options;
1017  uint16_t glyphPixels;
1018  bool lastRow{false};
1019  };
1020 
1021  void getNextRun();
1022  bool startRead(Surface& surface);
1023  bool renderBuffer(Surface& surface, BackBuffer& backBuffer);
1024 
1025  const TextObject& object;
1026  AlphaBuffer alphaBuffer;
1027  const TextObject::RunElement* run{nullptr};
1028  const TextObject::Element* element;
1029  GlyphObject::Options options;
1030  BackBuffer backBuffers[2];
1031  uint8_t readIndex{0};
1032  uint8_t writeIndex{0};
1033  const TypeFace* typeface{nullptr};
1034  PixelFormat pixelFormat{};
1035  uint8_t bytesPerPixel;
1036  uint8_t busyCount{0};
1037 };
1038 
1039 } // namespace Graphics
Manage a set of bit values using enumeration.
Definition: BitSet.h:45
Definition: Renderer.h:588
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:698
ArcRenderer(const Location &location, const Pen &pen, const Rect &rect, int start_angle, int end_angle)
Definition: Renderer.h:700
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:913
BlendRenderer(const Location &location, const Object &object, const Blend *blend)
Definition: Renderer.h:915
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, uint16_t delta, 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:804
bool execute(Surface &surface) override
Called to do some writing to the surface.
CopyRenderer(const Location &location, const CopyObject &object)
Definition: Renderer.h:808
PixelFormat pixelFormat
Definition: Renderer.h:834
bool vertical
Definition: Renderer.h:836
virtual void readComplete(uint8_t *data, size_t length)
Definition: Renderer.h:830
uint8_t bytesPerPixel
Definition: Renderer.h:835
void startRead(Surface &surface)
An ellipse outline.
Definition: Libraries/Graphics/src/include/Graphics/Object.h:454
Draws an ellipse outline.
Definition: Renderer.h:603
const uint16_t w
Definition: Renderer.h:639
uint16_t W
Definition: Renderer.h:640
bool execute(Surface &surface) override
Called to do some writing to the surface.
EllipseRenderer(const Location &location, const EllipseObject &object)
Definition: Renderer.h:610
virtual void addRectangles2()
virtual void addRectangles1()
EllipseRenderer(const Location &location, const CircleObject &object)
Definition: Renderer.h:615
Rect r2
Definition: Renderer.h:637
EllipseRenderer(const Location &location, const Pen &pen, const Rect &rect)
Definition: Renderer.h:605
ArcRectList rectangles
Definition: Renderer.h:638
const Rect r
Definition: Renderer.h:635
State
Definition: Renderer.h:623
Rect r1
Definition: Renderer.h:636
State state
Definition: Renderer.h:641
Render arc outline with adjustable line width.
Definition: Renderer.h:728
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:730
A filled circle.
Definition: Libraries/Graphics/src/include/Graphics/Object.h:411
Draws a filled circle.
Definition: Renderer.h:505
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:517
FilledCircleRenderer(const Location &location, const FilledCircleObject &object)
Definition: Renderer.h:507
A filled ellipse.
Definition: Libraries/Graphics/src/include/Graphics/Object.h:481
Draws a filled ellipse.
Definition: Renderer.h:656
Ellipse e
Definition: Renderer.h:688
FilledEllipseRenderer(const Location &location, const FilledEllipseObject &object)
Definition: Renderer.h:663
Rect r1
Definition: Renderer.h:689
Rect r2
Definition: Renderer.h:690
FilledEllipseRenderer(const Location &location, const FilledCircleObject &object)
Definition: Renderer.h:668
virtual void doStep(Ellipse::Step step)
bool execute(Surface &surface) override
Called to do some writing to the surface.
ArcRectList rectangles
Definition: Renderer.h:687
State
Definition: Renderer.h:679
FilledEllipseRenderer(const Location &location, const Brush &brush, const Rect &rect)
Definition: Renderer.h:658
State state
Definition: Renderer.h:691
const Rect r
Definition: Renderer.h:686
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:849
ImageCopyRenderer(const Location &location, const ImageObject &image, const Blend *blend)
Definition: Renderer.h:851
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:754
ImageRenderer(const Location &location, const ImageObject &object)
Definition: Renderer.h:756
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:871
ScrollRenderer(const Location &location, const ScrollObject &object)
Definition: Renderer.h:873
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:774
SurfaceRenderer(const Location &location, Surface &target, const Rect &dest, Point source)
Definition: Renderer.h:781
bool execute(Surface &surface) override
Called to do some writing to the surface.
SurfaceRenderer(const Location &location, const SurfaceObject &object)
Definition: Renderer.h:776
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:944
bool execute(Surface &surface) override
Called to do some writing to the surface.
TextRenderer(const Location &location, const TextObject &object)
Definition: Renderer.h:946
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:551
int32_t t
Definition: Renderer.h:580
int32_t d2xt
Definition: Renderer.h:583
int32_t ycrit
Definition: Renderer.h:579
int32_t dxt
Definition: Renderer.h:581
Ellipse(Size size)
Definition: Renderer.h:557
int32_t d2yt
Definition: Renderer.h:584
int32_t dyt
Definition: Renderer.h:582
uint16_t a
Definition: Renderer.h:572
uint16_t b
Definition: Renderer.h:573
int32_t xcrit
Definition: Renderer.h:578
Ellipse()
Definition: Renderer.h:552
int32_t b2
Definition: Renderer.h:577
Move
Definition: Renderer.h:564
uint16_t y
Definition: Renderer.h:575
uint16_t x
Definition: Renderer.h:574
int32_t a2
Definition: Renderer.h:576
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