Asset.h
Go to the documentation of this file.
1 /****
2  * Asset.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 "Meta.h"
26 #include <FlashString/Stream.hpp>
27 #include "resource.h"
28 
29 // Verify structure size is as expected. This is an optimisation; we don't care for Host builds.
30 #ifdef ARCH_HOST
31 #define GRAPHICS_VERIFY_SIZE(type_name, size)
32 #else
33 #define GRAPHICS_VERIFY_SIZE(type_name, size) static_assert(sizeof(type_name) == size, "Bad " #type_name " size");
34 #endif
35 
36 namespace Graphics
37 {
38 class Object;
39 class ImageObject;
40 class GlyphObject;
41 class Surface;
42 
43 #define GRAPHICS_ASSET_TYPE_LIST(XX) \
44  XX(Pen) \
45  XX(SolidBrush) \
46  XX(TextureBrush) \
47  XX(Text) \
48  XX(Font) \
49  XX(Typeface) \
50  XX(Blend) \
51  XX(Surface) \
52  XX(Object)
53 
54 namespace Resource
55 {
65 void init(IDataSourceStream* stream);
66 
76 IDataSourceStream* createSubStream(uint32_t offset, size_t size);
77 } // namespace Resource
78 
82 class Asset : public LinkedObjectTemplate<Asset>, public Meta
83 {
84 public:
87  using ID = AssetID;
88 
89  enum class Type {
90 #define XX(tag) tag,
92 #undef XX
93  };
94 
95  Asset() : mId(nextId++)
96  {
97  }
98 
99  Asset(ID id) : mId(id)
100  {
101  nextId = std::max(nextId, ID(id + 1));
102  }
103 
104  using LinkedObjectTemplate::operator==;
105 
106  bool operator==(ID id) const
107  {
108  return this->mId == id;
109  }
110 
111  ID id() const
112  {
113  return mId;
114  }
115 
116  virtual Type type() const = 0;
117 
118  /* Meta */
119 
120  virtual String getTypeStr() const;
121  virtual void write(MetaWriter& meta) const;
122 
123 private:
124  ID mId;
125  static ID nextId;
126 };
127 
129 
131 
132 template <Asset::Type asset_type> class AssetTemplate : public Asset
133 {
134 public:
135  static constexpr Asset::Type assetType{asset_type};
136 
138 
139  virtual Type type() const override
140  {
141  return asset_type;
142  }
143 };
144 
145 enum class BrushStyle {
146  FullScreen,
147  SourceLocal,
148 };
149 
150 class SolidBrush : public AssetTemplate<AssetType::SolidBrush>
151 {
152 public:
154  {
155  }
156 
157  void write(MetaWriter& meta) const override
158  {
159  AssetTemplate::write(meta);
160  return meta.write("color", color);
161  }
162 
164 };
165 
166 class TextureBrush : public AssetTemplate<AssetType::TextureBrush>
167 {
168 public:
170  {
171  }
172 
174  {
175  }
176 
177  virtual PixelFormat getPixelFormat() const
178  {
179  return PixelFormat::None;
180  }
181 
182  virtual size_t readPixels(const Location& loc, PixelFormat format, void* buffer, uint16_t width) const = 0;
183 
184  void write(MetaWriter& meta) const override
185  {
186  AssetTemplate::write(meta);
187  // meta.write("style", style);
188  }
189 
190 protected:
192 };
193 
195 {
196 public:
197  GradientBrush(BrushStyle style, Color color1, Color color2) : TextureBrush(style), color1(color1), color2(color2)
198  {
199  }
200 
202  : TextureBrush(id, style), color1(color1), color2(color2)
203  {
204  }
205 
206  void write(MetaWriter& meta) const override
207  {
208  TextureBrush::write(meta);
209  meta.write("color1", color1);
210  meta.write("color2", color2);
211  }
212 
213  size_t readPixels(const Location& loc, PixelFormat format, void* buffer, uint16_t pixelCount) const override;
214 
215  String getTypeStr() const override
216  {
217  return F("GradientBrush");
218  }
219 
220 private:
221  Color color1;
222  Color color2;
223 };
224 
228 class ImageBrush : public TextureBrush
229 {
230 public:
232  {
233  }
234 
236  {
237  }
238 
239  PixelFormat getPixelFormat() const override;
240 
241  size_t readPixels(const Location& loc, PixelFormat format, void* buffer, uint16_t width) const override;
242 
243  /* Meta */
244 
245  String getTypeStr() const override
246  {
247  return F("ImageBrush");
248  }
249 
250  void write(MetaWriter& meta) const override;
251 
252 private:
253  ImageObject& image;
254 };
255 
259 class Brush : public Meta
260 {
261 public:
262 #define GRAPHICS_BRUSH_KIND_MAP(XX) \
263  XX(None) \
264  XX(Color) \
265  XX(PackedColor) \
266  XX(Texture)
267 
268  enum class Kind : uint8_t {
269 #define XX(name) name,
271 #undef XX
272  };
273 
274  Brush() : brush(nullptr), kind(Kind::None)
275  {
276  }
277 
279  {
280  }
281 
282  Brush(const Brush& other) : brush(other.brush), kind(other.kind)
283  {
284  }
285 
286  Brush(const Brush& other, PixelFormat format) : Brush(other)
287  {
289  }
290 
292  {
293  }
294 
295  Brush(const TextureBrush* brush) : brush(brush), kind(Kind::Texture)
296  {
297  }
298 
300  {
301  this->color = color;
302  this->kind = Kind::Color;
303  }
304 
306  {
307  if(kind == Kind::Color) {
309  kind = Kind::PackedColor;
310  }
311  pixelFormat = format;
312  }
313 
314  Kind getKind() const
315  {
316  return kind;
317  }
318 
319  explicit operator bool() const
320  {
321  return kind != Kind::None;
322  }
323 
324  bool isSolid() const
325  {
326  return kind == Kind::Color || kind == Kind::PackedColor;
327  }
328 
329  bool isTransparent() const
330  {
331  if(kind == Kind::Color) {
332  return getAlpha(color) < 255;
333  }
334  if(kind == Kind::PackedColor) {
335  return packedColor.alpha < 255;
336  }
337  return false;
338  }
339 
340  bool operator==(Color color) const
341  {
342  return kind == Kind::Color && this->color == color;
343  }
344 
345  bool operator!=(Color color) const
346  {
347  return !operator==(color);
348  }
349 
350  bool operator==(const Brush& other) const
351  {
352  return kind == other.kind && brush == other.brush;
353  }
354 
355  bool operator!=(const Brush& other) const
356  {
357  return !operator==(other);
358  }
359 
360  Color getColor() const
361  {
362  if(kind == Kind::Color) {
363  return color;
364  }
365  if(kind == Kind::PackedColor) {
366  return unpack(packedColor, pixelFormat);
367  }
368  assert(false);
369  return Color::Black;
370  }
371 
373  {
374  assert(kind == Kind::PackedColor);
375  return packedColor;
376  }
377 
380 
381  const TextureBrush& getObject() const
382  {
383  assert(kind == Kind::Texture);
384  return *brush;
385  }
386 
387  bool setPixel(Surface& surface, const Location& loc) const;
388  uint16_t setPixels(Surface& surface, const Location& loc, uint16_t pixelCount) const;
389  uint16_t writePixel(const Location& loc, void* buffer) const;
390  uint16_t writePixels(const Location& loc, void* buffer, uint16_t pixelCount) const;
391 
392  /* Meta */
393 
395  void write(MetaWriter& meta) const;
396 
397 private:
398  union {
402  };
403  Kind kind;
404  PixelFormat pixelFormat{};
405 };
406 
408 
409 class Pen : public Brush
410 {
411 public:
412  Pen() = default;
413 
414  Pen(const Pen& other) : Brush(other), width(other.width)
415  {
416  }
417 
418  Pen(const Brush& brush, uint16_t width = 1) : Brush(brush), width(width)
419  {
420  }
421 
422  Pen(Color color, uint16_t width = 1) : Brush(color), width(width)
423  {
424  }
425 
426  Pen(const Pen& other, PixelFormat format) : Brush(other, format), width(other.width)
427  {
428  }
429 
430  Pen(const TextureBrush& brush, uint16_t width = 1) : Brush(&brush), width(width)
431  {
432  }
433 
434  void write(MetaWriter& meta) const
435  {
436  Brush::write(meta);
437  meta.write(F("width"), width);
438  }
439 
440  uint16_t width{1};
441 };
442 
444 
445 class PenAsset : public AssetTemplate<AssetType::Pen>, public Pen
446 {
447 public:
448  template <typename... ParamTypes> PenAsset(AssetID id, ParamTypes... params) : AssetTemplate(id), Pen(params...)
449  {
450  }
451 
452  void write(MetaWriter& meta) const override
453  {
454  AssetTemplate::write(meta);
455  return Pen::write(meta);
456  }
457 };
458 
459 class TextOptions : public Meta
460 {
461 public:
462  Brush fore{Color::WHITE};
463  Brush back{Color::BLACK};
466 
468  {
469  }
470 
473  {
474  }
475 
477  {
480  }
481 
482  bool isTransparent() const
483  {
484  return !back || fore == back;
485  }
486 
487  /* Meta */
488 
489  virtual String getTypeStr() const
490  {
491  return F("TextOptions");
492  }
493 
494  void write(MetaWriter& meta) const
495  {
496  meta.write("fore", fore);
497  meta.write("back", back);
498  if(scale) {
499  meta.write("scale", scale);
500  }
501  if(style) {
502  meta.write("style", style);
503  }
504  }
505 };
506 
508 
512 class TypeFace : public AssetTemplate<AssetType::Typeface>
513 {
514 public:
518  virtual FontStyles getStyle() const = 0;
519 
523  virtual uint8_t height() const = 0;
524 
528  virtual uint8_t descent() const = 0;
529 
533  virtual GlyphMetrics getMetrics(char ch) const = 0;
534 
543  virtual std::unique_ptr<GlyphObject> getGlyph(char ch, const GlyphOptions& options) const = 0;
544 
548  uint8_t baseline() const
549  {
550  return height() - descent();
551  }
552 
556  uint16_t getTextWidth(const char* text, uint16_t length) const;
557 
558  /* Meta */
559 
560  void write(MetaWriter& meta) const override
561  {
562  AssetTemplate::write(meta);
563  meta.write("style", getStyle());
564  meta.write("height", height());
565  meta.write("descent", descent());
566  }
567 };
568 
578 class Font : public AssetTemplate<AssetType::Font>
579 {
580 public:
581  using AssetTemplate::AssetTemplate;
582 
583  virtual String name() const = 0;
584 
585  virtual uint16_t height() const = 0;
586 
587  virtual const TypeFace* getFace(FontStyles style) const = 0;
588 
589  /* Meta */
590 
591  void write(MetaWriter& meta) const override
592  {
593  AssetTemplate::write(meta);
594  meta.write("font", name());
595  }
596 };
597 
599 {
600 public:
602  : font(font), typeface(typeface)
603  {
604  }
605 
606  FontStyles getStyle() const override
607  {
608  return FSTR::readValue(&typeface.style);
609  }
610 
611  uint8_t height() const override
612  {
613  return FSTR::readValue(&font.yAdvance);
614  }
615 
616  uint8_t descent() const override
617  {
618  return FSTR::readValue(&font.descent);
619  }
620 
621  GlyphMetrics getMetrics(char ch) const override;
622 
623  std::unique_ptr<GlyphObject> getGlyph(char ch, const GlyphOptions& options) const override;
624 
625 private:
626  bool findGlyph(uint16_t codePoint, Resource::GlyphResource& res) const;
627 
628  const Resource::FontResource& font;
629  const Resource::TypefaceResource& typeface;
630 };
631 
633 {
634 public:
635  // TODO: Call Font(id)
636  ResourceFont(const Resource::FontResource& font) : Font(), font(font)
637  {
638  init();
639  }
640 
641  ResourceFont(AssetID id, const Resource::FontResource& font) : Font(id), font(font)
642  {
643  init();
644  }
645 
646  String name() const override
647  {
648  return *font.name;
649  }
650 
651  uint16_t height() const override
652  {
653  return FSTR::readValue(&font.yAdvance);
654  }
655 
656  const TypeFace* getFace(FontStyles style) const override;
657 
658 private:
659  void init()
660  {
661  for(auto& face : font.faces) {
662  if(face != nullptr) {
663  typefaces.add(new ResourceTypeface(font, *face));
664  }
665  }
666  }
667 
668  const Resource::FontResource& font;
669  TypeFace::OwnedList typefaces;
670 };
671 
672 class TextAsset : public AssetTemplate<AssetType::Text>
673 {
674 public:
675  TextAsset(String&& content) : AssetTemplate(), stream(new MemoryDataStream(std::move(content)))
676  {
677  }
678 
680  {
681  }
682 
683  TextAsset(IDataSourceStream* stream) : AssetTemplate(), stream(stream)
684  {
685  }
686 
687  TextAsset(AssetID id, IDataSourceStream* stream) : AssetTemplate(id), stream(stream)
688  {
689  }
690 
691  TextAsset(const FSTR::String& fstr) : TextAsset(new FSTR::Stream(fstr))
692  {
693  }
694 
695  TextAsset(AssetID id, const char* text, size_t length) : TextAsset(id)
696  {
697  reinterpret_cast<MemoryDataStream*>(stream.get())->write(text, length);
698  }
699 
700  TextAsset(AssetID id, const String& s) : TextAsset(id, s.c_str(), s.length())
701  {
702  }
703 
704  TextAsset(AssetID id, String&& s) : AssetTemplate(id), stream(new MemoryDataStream(std::move(s)))
705  {
706  }
707 
708  size_t getLength() const
709  {
710  return stream ? stream->seekFrom(0, SeekOrigin::End) : 0;
711  }
712 
713  size_t read(uint32_t offset, char* buffer, size_t length) const
714  {
715  if(!stream) {
716  return 0;
717  }
718  stream->seekFrom(offset, SeekOrigin::Start);
719  return stream->readBytes(buffer, length);
720  }
721 
722  char read(uint32_t offset) const
723  {
724  char ch{'\0'};
725  read(offset, &ch, 1);
726  return ch;
727  }
728 
729  String readString(size_t maxlen) const
730  {
731  return stream ? stream->readString(maxlen) : nullptr;
732  }
733 
734  /* Meta */
735 
736  void write(MetaWriter& meta) const override
737  {
738  AssetTemplate::write(meta);
739  meta.write("length", getLength());
740  if(stream) {
741  meta.write("content", *stream);
742  }
743  }
744 
745 private:
746  std::unique_ptr<IDataSourceStream> stream;
747 };
748 
749 class ObjectAsset : public AssetTemplate<AssetType::Object>
750 {
751 public:
752  ObjectAsset(const Object* object);
753  ObjectAsset(AssetID id, const Object* object);
755 
756  std::unique_ptr<const Object> object;
757 };
758 
760 {
761 public:
763  {
764  return std::find(begin(), end(), id);
765  }
766 
767  const Asset* find(AssetID id) const
768  {
769  return std::find(begin(), end(), id);
770  }
771 
773 
774  const Asset* find(AssetType type, AssetID id) const
775  {
776  return const_cast<AssetList*>(this)->find(type, id);
777  }
778 
779  template <typename T> T* find(AssetID id)
780  {
781  return static_cast<T*>(find(T::assetType, id));
782  }
783 
784  template <typename T> const T* find(AssetID id) const
785  {
786  return static_cast<const T*>(find(T::assetType, id));
787  }
788 
789  void store(Asset* asset);
790 
791  void store(AssetID id, Pen pen)
792  {
793  store(new PenAsset(id, pen));
794  }
795 
796  // void store(AssetID id, Brush brush)
797  // {
798  // if(brush.isSolid()) {
799  // store(new SolidBrush(id, brush.getColor()));
800  // } else {
801  // auto b = new TextureBrush(brush.getObject());
802  // b->id = id;
803  // store(b);
804  // }
805  // }
806 };
807 
808 } // namespace Graphics
809 
#define GRAPHICS_BRUSH_KIND_MAP(XX)
Definition: Asset.h:262
String toString(Graphics::AssetType type)
#define GRAPHICS_ASSET_TYPE_LIST(XX)
Definition: Asset.h:43
@ End
SEEK_END: End of file.
@ Start
SEEK_SET: Start of file.
#define F(string_literal)
Wrap a string literal stored in flash and access it using a String object.
Definition: WString.h:109
describes a counted string stored in flash memory
Definition: String.hpp:174
Definition: Asset.h:760
const T * find(AssetID id) const
Definition: Asset.h:784
void store(Asset *asset)
Asset * find(AssetID id)
Definition: Asset.h:762
Asset * find(AssetType type, AssetID id)
T * find(AssetID id)
Definition: Asset.h:779
const Asset * find(AssetID id) const
Definition: Asset.h:767
const Asset * find(AssetType type, AssetID id) const
Definition: Asset.h:774
void store(AssetID id, Pen pen)
Definition: Asset.h:791
Definition: Asset.h:133
virtual Type type() const override
Definition: Asset.h:139
An asset is used to render an Object, but is not itself drawable.
Definition: Asset.h:83
Asset()
Definition: Asset.h:95
bool operator==(ID id) const
Definition: Asset.h:106
OwnedLinkedObjectListTemplate< Asset > OwnedList
Definition: Asset.h:86
virtual Type type() const =0
ID id() const
Definition: Asset.h:111
AssetID ID
Definition: Asset.h:87
Asset(ID id)
Definition: Asset.h:99
Type
Definition: Asset.h:89
virtual void write(MetaWriter &meta) const
virtual String getTypeStr() const
The source of colour for drawing.
Definition: Asset.h:260
Brush(const TextureBrush *brush)
Definition: Asset.h:295
bool setPixel(Surface &surface, const Location &loc) const
void setColor(Color color)
Definition: Asset.h:299
uint16_t writePixel(const Location &loc, void *buffer) const
bool isSolid() const
Definition: Asset.h:324
PackedColor getPackedColor(Point pt) const
Brush(const Brush &other)
Definition: Asset.h:282
Kind getKind() const
Definition: Asset.h:314
PackedColor getPackedColor() const
Definition: Asset.h:372
Kind
Definition: Asset.h:268
bool operator==(const Brush &other) const
Definition: Asset.h:350
Color getColor() const
Definition: Asset.h:360
uint16_t setPixels(Surface &surface, const Location &loc, uint16_t pixelCount) const
const TextureBrush & getObject() const
Definition: Asset.h:381
void write(MetaWriter &meta) const
Color color
Definition: Asset.h:399
const TextureBrush * brush
Definition: Asset.h:401
Brush(PackedColor color)
Definition: Asset.h:291
String getTypeStr() const
bool isTransparent() const
Definition: Asset.h:329
Brush(const Brush &other, PixelFormat format)
Definition: Asset.h:286
bool operator==(Color color) const
Definition: Asset.h:340
PackedColor packedColor
Definition: Asset.h:400
Brush()
Definition: Asset.h:274
Brush(Color color)
Definition: Asset.h:278
void setPixelFormat(PixelFormat format)
Definition: Asset.h:305
uint16_t writePixels(const Location &loc, void *buffer, uint16_t pixelCount) const
PackedColor getPackedColor(PixelFormat format) const
bool operator!=(Color color) const
Definition: Asset.h:345
bool operator!=(const Brush &other) const
Definition: Asset.h:355
Base class for a loaded font.
Definition: Asset.h:579
virtual String name() const =0
void write(MetaWriter &meta) const override
Definition: Asset.h:591
virtual uint16_t height() const =0
virtual const TypeFace * getFace(FontStyles style) const =0
Definition: Asset.h:195
size_t readPixels(const Location &loc, PixelFormat format, void *buffer, uint16_t pixelCount) const override
GradientBrush(AssetID id, BrushStyle style, Color color1, Color color2)
Definition: Asset.h:201
void write(MetaWriter &meta) const override
Definition: Asset.h:206
GradientBrush(BrushStyle style, Color color1, Color color2)
Definition: Asset.h:197
String getTypeStr() const override
Definition: Asset.h:215
Brush using pixels from image.
Definition: Asset.h:229
String getTypeStr() const override
Definition: Asset.h:245
ImageBrush(BrushStyle style, ImageObject &image)
Definition: Asset.h:231
size_t readPixels(const Location &loc, PixelFormat format, void *buffer, uint16_t width) const override
PixelFormat getPixelFormat() const override
void write(MetaWriter &meta) const override
ImageBrush(AssetID id, BrushStyle style, ImageObject &image)
Definition: Asset.h:235
Virtual base class for an image.
Definition: Libraries/Graphics/src/include/Graphics/Object.h:568
Writes object content in readable format for debugging.
Definition: Meta.h:48
std::enable_if< std::is_base_of< Meta, T >::value, void >::type write(const String &name, const T &value)
Definition: Meta.h:55
Empty base class to support object enumeration Non-virtual to avoid bloat.
Definition: Meta.h:39
Definition: Asset.h:750
std::unique_ptr< const Object > object
Definition: Asset.h:756
ObjectAsset(AssetID id, const Object *object)
ObjectAsset(const Object *object)
A drawable object inherits from this virtual base class.
Definition: Libraries/Graphics/src/include/Graphics/Object.h:97
Definition: Asset.h:446
void write(MetaWriter &meta) const override
Definition: Asset.h:452
PenAsset(AssetID id, ParamTypes... params)
Definition: Asset.h:448
Definition: Asset.h:410
Pen(const Pen &other, PixelFormat format)
Definition: Asset.h:426
Pen()=default
Pen(Color color, uint16_t width=1)
Definition: Asset.h:422
Pen(const Pen &other)
Definition: Asset.h:414
Pen(const Brush &brush, uint16_t width=1)
Definition: Asset.h:418
void write(MetaWriter &meta) const
Definition: Asset.h:434
Pen(const TextureBrush &brush, uint16_t width=1)
Definition: Asset.h:430
uint16_t width
Definition: Asset.h:440
Definition: Asset.h:633
ResourceFont(const Resource::FontResource &font)
Definition: Asset.h:636
String name() const override
Definition: Asset.h:646
const TypeFace * getFace(FontStyles style) const override
uint16_t height() const override
Definition: Asset.h:651
ResourceFont(AssetID id, const Resource::FontResource &font)
Definition: Asset.h:641
Definition: Asset.h:599
uint8_t height() const override
Get height of typeface, same for all characters.
Definition: Asset.h:611
uint8_t descent() const override
Definition: Asset.h:616
std::unique_ptr< GlyphObject > getGlyph(char ch, const GlyphOptions &options) const override
Get the glyph for a character.
FontStyles getStyle() const override
Style of this typeface (bold, italic, etc.)
Definition: Asset.h:606
GlyphMetrics getMetrics(char ch) const override
Get metrics for a character.
ResourceTypeface(const Resource::FontResource &font, const Resource::TypefaceResource &typeface)
Definition: Asset.h:601
Definition: Libraries/Graphics/src/include/Graphics/Types.h:733
Definition: Asset.h:151
SolidBrush(AssetID id, Color color)
Definition: Asset.h:153
void write(MetaWriter &meta) const override
Definition: Asset.h:157
Color color
Definition: Asset.h:163
Interface for a drawing surface.
Definition: Surface.h:42
Definition: Asset.h:673
TextAsset(IDataSourceStream *stream)
Definition: Asset.h:683
TextAsset(AssetID id, String &&s)
Definition: Asset.h:704
char read(uint32_t offset) const
Definition: Asset.h:722
TextAsset(AssetID id, IDataSourceStream *stream)
Definition: Asset.h:687
TextAsset(AssetID id, const char *text, size_t length)
Definition: Asset.h:695
TextAsset(String &&content)
Definition: Asset.h:675
size_t read(uint32_t offset, char *buffer, size_t length) const
Definition: Asset.h:713
TextAsset(AssetID id)
Definition: Asset.h:679
TextAsset(AssetID id, const String &s)
Definition: Asset.h:700
void write(MetaWriter &meta) const override
Definition: Asset.h:736
String readString(size_t maxlen) const
Definition: Asset.h:729
TextAsset(const FSTR::String &fstr)
Definition: Asset.h:691
size_t getLength() const
Definition: Asset.h:708
Definition: Asset.h:460
bool isTransparent() const
Definition: Asset.h:482
Brush back
Definition: Asset.h:463
TextOptions(Brush fore, Brush back, Scale scale, FontStyles style)
Definition: Asset.h:471
void write(MetaWriter &meta) const
Definition: Asset.h:494
void setPixelFormat(PixelFormat format)
Definition: Asset.h:476
FontStyles style
Definition: Asset.h:465
virtual String getTypeStr() const
Definition: Asset.h:489
Brush fore
Definition: Asset.h:462
Scale scale
Definition: Asset.h:464
TextOptions()
Definition: Asset.h:467
Definition: Asset.h:167
BrushStyle style
Definition: Asset.h:191
void write(MetaWriter &meta) const override
Definition: Asset.h:184
virtual PixelFormat getPixelFormat() const
Definition: Asset.h:177
TextureBrush(AssetID id, BrushStyle style)
Definition: Asset.h:173
virtual size_t readPixels(const Location &loc, PixelFormat format, void *buffer, uint16_t width) const =0
TextureBrush(BrushStyle style)
Definition: Asset.h:169
Base class for a loaded typeface, e.g. Sans 16pt bold.
Definition: Asset.h:513
virtual FontStyles getStyle() const =0
Style of this typeface (bold, italic, etc.)
virtual std::unique_ptr< GlyphObject > getGlyph(char ch, const GlyphOptions &options) const =0
Get the glyph for a character.
uint8_t baseline() const
Get baseline relative to top of mbox.
Definition: Asset.h:548
virtual uint8_t descent() const =0
uint16_t getTextWidth(const char *text, uint16_t length) const
Compute displayed width for a text string.
virtual uint8_t height() const =0
Get height of typeface, same for all characters.
virtual GlyphMetrics getMetrics(char ch) const =0
Get metrics for a character.
void write(MetaWriter &meta) const override
Definition: Asset.h:560
Base class for read-only stream.
Definition: DataSourceStream.h:46
Definition: LinkedObjectList.h:88
Iterator begin()
Definition: LinkedObjectList.h:112
bool add(ObjectType *object)
Definition: LinkedObjectList.h:132
Iterator end()
Definition: LinkedObjectList.h:117
Base class template for linked items with type casting.
Definition: LinkedObject.h:60
Read/write stream using expandable memory buffer.
Definition: MemoryDataStream.h:27
Base Stream class.
Definition: Wiring/Stream.h:33
The String class.
Definition: WString.h:133
Definition: Array.hpp:118
std::enable_if< sizeof(T)==1, T >::type readValue(const T *ptr)
Read a typed value from flash memory ensuring correct alignment of access.
Definition: Utility.hpp:134
void init(IDataSourceStream *stream)
Application calls this method to set source for graphics resourcess.
IDataSourceStream * createSubStream(uint32_t offset, size_t size)
Graphics objects call this method to obtain access to resource data.
Definition: Virtual.h:31
GRAPHICS_VERIFY_SIZE(Brush, 8)
PixelBuffer unpack(PixelBuffer src, PixelFormat format)
Convert packed colour into RGB.
BrushStyle
Definition: Asset.h:145
PixelBuffer pack(PixelBuffer src, PixelFormat format)
Convert RGB colour into packed format.
constexpr uint8_t getAlpha(Color color)
Definition: Colors.h:257
uint16_t AssetID
Numeric identifiers for re-useable objects.
Definition: Libraries/Graphics/src/include/Graphics/Types.h:42
PixelFormat
Definition: Colors.h:295
Color
Standard colour definitions.
Definition: Colors.h:227
Type
Definition: Resource.h:41
Glyph metrics.
Definition: Libraries/Graphics/src/include/Graphics/Types.h:838
Identifies position within bounding rectangle.
Definition: Libraries/Graphics/src/include/Graphics/Types.h:683
Colour in device pixel format.
Definition: Colors.h:339
uint32_t alpha
Definition: Colors.h:341
Definition: resource.h:93
uint8_t descent
Definition: resource.h:96
const FSTR::String * name
Definition: resource.h:94
uint8_t yAdvance
Definition: resource.h:95
const TypefaceResource * faces[4]
Definition: resource.h:98
Describes glyph bitmap and position.
Definition: resource.h:34
Definition: resource.h:83
uint8_t style
Definition: resource.h:85