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