Virtual.h
Go to the documentation of this file.
1 /****
2  * Virtual.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 <Graphics/Device.h>
25 #include <Graphics/AddressWindow.h>
27 
28 class CSocket;
29 
30 namespace Graphics
31 {
32 namespace Display
33 {
34 class VirtualSurface;
35 
41 class Virtual : public AbstractDisplay
42 {
43 public:
44  enum class Mode {
45  Normal,
46  Debug,
47  };
48 
49  Virtual();
50  ~Virtual();
51 
52  bool begin(uint16_t width = 240, uint16_t height = 320);
53  bool begin(const String& ipaddr, uint16_t port, uint16_t width = 240, uint16_t height = 320);
54 
55  void setMode(Mode mode)
56  {
57  this->mode = mode;
58  }
59 
60  Mode getMode() const
61  {
62  return mode;
63  }
64 
65  /* Device */
66 
67  String getName() const override
68  {
69  return F("Virtual Screen");
70  }
71  Size getNativeSize() const override
72  {
73  return nativeSize;
74  }
75  bool setOrientation(Orientation orientation) override;
76 
77  /* RenderTarget */
78 
79  Size getSize() const override
80  {
81  return rotate(nativeSize, orientation);
82  }
83 
84  PixelFormat getPixelFormat() const override
85  {
86  return PixelFormat::BGR24;
87  }
88 
89  bool setScrollMargins(uint16_t top, uint16_t bottom) override;
90  bool scroll(int16_t y) override;
91 
92  Surface* createSurface(size_t bufferSize = 0) override;
93 
94 private:
95  class NetworkThread;
96  friend NetworkThread;
97  friend VirtualSurface;
98 
99  struct ScrollMargins {
100  uint16_t top;
101  uint16_t bottom;
102  };
103 
104  bool sizeChanged();
105 
106  std::unique_ptr<NetworkThread> thread;
107  Size nativeSize{};
108  AddressWindow addrWindow{};
109  ScrollMargins scrollMargins;
110  Mode mode;
111 };
112 
113 } // namespace Display
114 } // namespace Graphics
Size getNativeSize() const override
Get physical size of display.
Definition: Virtual.h:71
Orientation orientation
Definition: Libraries/Graphics/src/include/Graphics/Device.h:79
PixelFormat getPixelFormat() const override
All surfaces support the same pixel format.
Definition: Virtual.h:84
bool setScrollMargins(uint16_t top, uint16_t bottom) override
Set margins for hardware scrolling.
String getName() const override
Get name of display.
Definition: Virtual.h:67
Size getSize() const override
Get target dimensions.
Definition: Virtual.h:79
Virtual display device for Host.
Definition: Virtual.h:41
Mode
Definition: Virtual.h:44
The String class.
Definition: WString.h:136
bool setOrientation(Orientation orientation) override
Set display orientation.
#define F(string_literal)
Wrap a string literal stored in flash and access it using a String object.
Definition: WString.h:113
bool scroll(int16_t y) override
Scroll region of display up or down using hardware scrolling.
Surface * createSurface(size_t bufferSize=0) override
Create a surface for use with this render target.
Aim to produce similar performance to real display.
Size of rectangular area (width x height)
Definition: Libraries/Graphics/src/include/Graphics/Types.h:105
bool begin(uint16_t width=240, uint16_t height=320)
Definition: Display.h:21
Manages a rectangular area of display memory with position information.
Definition: AddressWindow.h:37
PixelFormat
Definition: Colors.h:295
Interface for a drawing surface.
Definition: Surface.h:41
Definition: Virtual.h:30
void setMode(Mode mode)
Definition: Virtual.h:55
Orientation
Defines orientation of display.
Definition: Libraries/Graphics/src/include/Graphics/Types.h:47
constexpr Size rotate(Size size, Orientation orientation)
Definition: Libraries/Graphics/src/include/Graphics/Types.h:122
Mode getMode() const
Definition: Virtual.h:60
Definition: AbstractDisplay.h:30
Use standard software renderers, may run slower and less smoothly.