Null.h
Go to the documentation of this file.
1 /****
2  * Null.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 
25 #include <Graphics/AddressWindow.h>
26 
27 namespace Graphics
28 {
29 namespace Display
30 {
36 class NullDevice : public AbstractDisplay
37 {
38 public:
39  NullDevice(uint16_t width = 240, uint16_t height = 320, PixelFormat format = PixelFormat::RGB565)
40  : nativeSize(width, height), pixelFormat(format)
41  {
42  }
43 
44  bool begin()
45  {
46  return true;
47  }
48 
49  bool begin(uint16_t width, uint16_t height, PixelFormat format)
50  {
51  nativeSize = Size{width, height};
52  pixelFormat = format;
53  return true;
54  }
55 
56  /* Device */
57 
58  String getName() const override
59  {
60  return F("Null Display Device");
61  }
62  Size getNativeSize() const override
63  {
64  return nativeSize;
65  }
67  {
68  this->orientation = orientation;
69  return true;
70  }
71 
72  bool setScrollMargins(uint16_t top, uint16_t bottom) override
73  {
74  (void)top;
75  (void)bottom;
76  return true;
77  }
78 
79  bool scroll(int16_t y) override
80  {
81  (void)y;
82  return true;
83  }
84 
85  /* RenderTarget */
86 
87  Size getSize() const override
88  {
89  return rotate(nativeSize, orientation);
90  }
91 
92  PixelFormat getPixelFormat() const override
93  {
94  return pixelFormat;
95  }
96 
97  Surface* createSurface(size_t bufferSize = 0) override;
98 
99 private:
100  friend class NullSurface;
101 
102  Size nativeSize{};
103  PixelFormat pixelFormat{};
104  AddressWindow addrWindow{};
105 };
106 
107 } // namespace Display
108 } // namespace Graphics
bool setScrollMargins(uint16_t top, uint16_t bottom) override
Set margins for hardware scrolling.
Definition: Null.h:129
bool begin()
Definition: Null.h:101
Manages a rectangular area of display memory with position information.
Definition: AddressWindow.h:56
PixelFormat getPixelFormat() const override
All surfaces support the same pixel format.
Definition: Null.h:149
Orientation orientation
Definition: Libraries/Graphics/src/include/Graphics/Device.h:117
Size getNativeSize() const override
Get physical size of display.
Definition: Null.h:119
The String class.
Definition: WString.h:136
Interface for a drawing surface.
Definition: Surface.h:60
Size of rectangular area (width x height)
Definition: Libraries/Graphics/src/include/Graphics/Types.h:124
Definition: Virtual.h:30
friend class NullSurface
Definition: Null.h:157
Size getSize() const override
Get target dimensions.
Definition: Null.h:144
Surface * createSurface(size_t bufferSize=0) override
Create a surface for use with this render target.
bool scroll(int16_t y) override
Scroll region of display up or down using hardware scrolling.
Definition: Null.h:136
Orientation
Defines orientation of display.
Definition: Libraries/Graphics/src/include/Graphics/Types.h:66
PixelFormat
Definition: Colors.h:295
constexpr Size rotate(Size size, Orientation orientation)
Definition: Libraries/Graphics/src/include/Graphics/Types.h:141
#define F(string_literal)
Wrap a string literal stored in flash and access it using a String object.
Definition: WString.h:113
NullDevice(uint16_t width=240, uint16_t height=320, PixelFormat format=PixelFormat::RGB565)
Definition: Null.h:96
String getName() const override
Get name of display.
Definition: Null.h:115
Definition: Display.h:21
bool setOrientation(Orientation orientation) override
Set display orientation.
Definition: Null.h:123