Pi-XPlane-FMC-CDU
Screen.h
1 /*
2  This file is part of Pi-XPlane-FMC-CDU
3  A Raspberry Pi-based External FMC for XPlane
4 
5  Copyright (C) 2017-2018 shahada abubakar
6  <shahada@abubakar.net>
7 
8  This program is free software: you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation, either version 3 of the License, or
11  (at your option) any later version.
12 
13  This program is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with this program. If not, see <https://www.gnu.org/licenses/>.
20 
21  */
22 
23 #ifndef PIXPLANEFMCCDU_SRC_SCREEN_H_
24 #define PIXPLANEFMCCDU_SRC_SCREEN_H_
25 
26 #include <iostream>
27 #include <syslog.h>
28 #include <SDL2/SDL.h>
29 #include <SDL2/SDL_ttf.h>
30 #include <list>
31 #include <mutex>
32 
33 
57 class Screen {
58 private:
59  // private so it cannot be called publicly
60  Screen();
61 
62  // private so it cannot be called publicly
63  Screen(Screen const &) {
64  }
65 
66  // assignment operator is private
67  Screen & operator=(Screen const &) {
68  abort();
69  }
70 
71 protected:
72  static Screen * instance;
73 
74  bool isRunning = false;
75  bool stopRequested = false;
76 
78  SDL_Window* window = NULL;
79 
81  SDL_Renderer * renderer = NULL;
82 
84  int numCols = 0;
85 
87  int numRows = 14;
88 
90  int cellWidth = 0;
91 
93  int tallCellHeight = 0;
94 
96  int shortCellHeight = 0;
97 
101  int winLeftBorder = 0;
102 
106  int winTopBorder = 0;
107 
113 
115  int linePos[15];
116 
118  SDL_Texture * tallChars = NULL;
119 
121  SDL_Texture * shortChars = NULL;
122 
124  SDL_Texture * screenBufferTexture = NULL;
125 
138  Uint32 screenRefreshTimerMs = 10;
139 
145  Uint32 interPollDelayMs = 1;
146 
147  Uint32 SDLUserEventBase;
148 
154  : int {
155  init = 0, LineUpdate = 1, clear = 2, quit = 4
156  };
157 
165  class ScreenEvent {
166  public:
167  int col; // used by init and drawLine
168  int line; // used by drawLine
169  std::string text; // used by drawLine
170  bool spaceErases; // space erases if true, skips if false
171  char color; // G=Green
172  bool smallInBig; // small font in Large line
173  };
174 
175  bool isx737FMCLegsPage = false;
176 
177  virtual ~Screen();
178 
179 
184  void doInit(SDL_Event * event);
185 
190  void doClear();
191 
196  void doDrawLine(SDL_Event * event);
197 
199  void transferBufferToDisplay ();
200 
202  SDL_Texture * generateCharacterTexture (std::string fontPath, int cellWidth, int maxHeight, SDL_Renderer * renderer);
203 
204 
206  TTF_Font * getFont (std::string fontPath, int maxWidth ,int maxHeight, SDL_Renderer * renderer);
207 
208 
209 
210  // == old stuff ==
211  /*
212  void calculateDimensions(int numCols, bool drawGrid = false);
213 
253 
261 
275 
284 
294 
306 
316 
TTF_Font * getFont(std::string fontPath, int maxWidth, int maxHeight, SDL_Renderer *renderer)
generate a font that fits within a cell&#39;s width and height
Definition: Screen.cpp:607
int shortCellHeight
the height of a short character.
Definition: Screen.h:96
SDL_Texture * tallChars
a texture holding pre-generated tall characters
Definition: Screen.h:118
int tallCellHeight
the height of a tall character.
Definition: Screen.h:93
Manage the FMC CDU display.
Definition: Screen.h:57
SDL_Window * window
SDL Window.
Definition: Screen.h:78
int cellWidth
width of a character cell on the screen.
Definition: Screen.h:90
void doClear()
implement a "clear" action
Definition: Screen.cpp:383
void doDrawLine(SDL_Event *event)
implement a "lineUpdate" action
Definition: Screen.cpp:393
SDL_Texture * screenBufferTexture
ready-composited complete screen texture
Definition: Screen.h:124
Event Data.
Definition: Screen.h:165
int winLeftBorder
left border of the screen.
Definition: Screen.h:101
ScreenEventType
enum of possible event types
Definition: Screen.h:153
int numCols
current number of columns.
Definition: Screen.h:84
int numRows
current number of rows.
Definition: Screen.h:87
SDL_Renderer * renderer
SDL renderer.
Definition: Screen.h:81
int shortCharVertOffset
vertical offset for short chars.
Definition: Screen.h:112
SDL_Texture * shortChars
a texture holding pre-generated short characters
Definition: Screen.h:121
int linePos[15]
screen offsets for each row.
Definition: Screen.h:115
void doInit(SDL_Event *event)
implement an "init" action
Definition: Screen.cpp:277
void transferBufferToDisplay()
transfer buffer to display
Definition: Screen.cpp:510
Uint32 interPollDelayMs
how long to delay in between polls of the update queue.
Definition: Screen.h:145
SDL_Texture * generateCharacterTexture(std::string fontPath, int cellWidth, int maxHeight, SDL_Renderer *renderer)
generate the texture containing all characters for a given cell width and height
Definition: Screen.cpp:516
Uint32 screenRefreshTimerMs
How many ms to wait after a line changes before repainting the screen.
Definition: Screen.h:138
int winTopBorder
top border of the screen.
Definition: Screen.h:106