Pi-XPlane-FMC-CDU
|
Manage the FMC CDU display. More...
#include <Screen.h>
Classes | |
class | ScreenEvent |
Event Data. More... | |
Public Member Functions | |
void | initialize (int cols) |
queues an init command the the screen handler. More... | |
void | clearScreen () |
queue a screen clear More... | |
void | drawLine (int line, int col, std::string text, bool spaceErases=true, char color='W', bool smallInBig=false) |
queue a line update to the screen More... | |
void | mainLoop () |
the main loop of the screen. More... | |
void | quitLoop () |
stop the screen's mainloop More... | |
Static Public Member Functions | |
static Screen * | getInstance () |
returns the singleton intance of a Screen. More... | |
Static Public Attributes | |
static int | winWidth = 640 |
window width | |
static int | winHeight = 480 |
window height | |
Protected Types | |
enum | ScreenEventType : int { init = 0, LineUpdate = 1, clear = 2, quit = 4 } |
enum of possible event types More... | |
Protected Member Functions | |
void | doInit (SDL_Event *event) |
implement an "init" action More... | |
void | doClear () |
implement a "clear" action More... | |
void | doDrawLine (SDL_Event *event) |
implement a "lineUpdate" action More... | |
void | transferBufferToDisplay () |
transfer buffer to display | |
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 | |
TTF_Font * | getFont (std::string fontPath, int maxWidth, int maxHeight, SDL_Renderer *renderer) |
generate a font that fits within a cell's width and height | |
Protected Attributes | |
bool | isRunning = false |
bool | stopRequested = false |
SDL_Window * | window = NULL |
SDL Window. | |
SDL_Renderer * | renderer = NULL |
SDL renderer. | |
int | numCols = 0 |
current number of columns. More... | |
int | numRows = 14 |
current number of rows. More... | |
int | cellWidth = 0 |
width of a character cell on the screen. More... | |
int | tallCellHeight = 0 |
the height of a tall character. More... | |
int | shortCellHeight = 0 |
the height of a short character. More... | |
int | winLeftBorder = 0 |
left border of the screen. More... | |
int | winTopBorder = 0 |
top border of the screen. More... | |
int | shortCharVertOffset = 0 |
vertical offset for short chars. More... | |
int | linePos [15] |
screen offsets for each row. More... | |
SDL_Texture * | tallChars = NULL |
a texture holding pre-generated tall characters | |
SDL_Texture * | shortChars = NULL |
a texture holding pre-generated short characters | |
SDL_Texture * | screenBufferTexture = NULL |
ready-composited complete screen texture | |
Uint32 | screenRefreshTimerMs = 10 |
How many ms to wait after a line changes before repainting the screen. More... | |
Uint32 | interPollDelayMs = 1 |
how long to delay in between polls of the update queue. More... | |
Uint32 | SDLUserEventBase |
bool | isx737FMCLegsPage = false |
Static Protected Attributes | |
static Screen * | instance = NULL |
Manage the FMC CDU display.
This is singleton class that manages the screen of the FMC CDU.
It uses SDL2 to render the display.
The class is used by calling submit* methods, which queue activities to be rendered a screen handling thread. This ensures that only one thread is making SDL2 calls at a time.
The class managed a single texture (screenBufferTexture) that holds the current display. All drawing is done onto this texture, which is then rendered to the display in its entirety.
The screen uses truetype fonts, however for performance reasons, it pre-caches the characters used by the FMC into a texture. Whenever a character needs to drawn, a single character is copied to the appropriate position on the screenBufferTexture.
|
protected |
enum of possible event types
void Screen::clearScreen | ( | ) |
queue a screen clear
This can be called from any thread, and queues a screen clear event. The implementation of this is faster than drawing blanks in every cell.
|
protected |
implement a "clear" action
|
protected |
implement a "lineUpdate" action
|
protected |
implement an "init" action
void Screen::drawLine | ( | int | line, |
int | col, | ||
std::string | text, | ||
bool | spaceErases = true , |
||
char | color = 'W' , |
||
bool | smallInBig = false |
||
) |
queue a line update to the screen
This can be called from any thread, and queues a screen update for the main Screen thread. This results in the string "text" being drawn on the screen at the position specified by line/col.
void Screen::initialize | ( | int | cols | ) |
queues an init command the the screen handler.
This calculates the screen metrics based on how many columns are required, and regenerates the font textures.
It can be called multiple times, to handle situations where the user switches between FMCs that have a different number of rows and columns.
void Screen::mainLoop | ( | ) |
the main loop of the screen.
Runs in a loop waiting for SDL events. In then calls the action{event} method to process them.
Note: SDL really doesn't like it when we run this in a separate thread. So main() has to call this and live within it happily ever after.
void Screen::quitLoop | ( | ) |
stop the screen's mainloop
since the screen's mainLoop is also the main program's mainLoop, this will cause the program to exit gracefully.
|
protected |
width of a character cell on the screen.
Calculated by init().
|
protected |
how long to delay in between polls of the update queue.
Too long increases lag, too low increases CPU utilization.
|
protected |
screen offsets for each row.
|
protected |
current number of columns.
Set by user via init()
|
protected |
current number of rows.
Fixed value 8-)
|
protected |
How many ms to wait after a line changes before repainting the screen.
When an entire page changes, we will receive 14 separate messages from ExtPlane. To refresh the entire display for each line creates a laggy display. So it's better to wait a bit and get all the lines in before repainting the screen. Setting this too high however will result in a longer response time, which becomes obvious when a single cell changes (like when typing into the scratchpad).
|
protected |
the height of a short character.
Calculated by init().
|
protected |
vertical offset for short chars.
In some modes, we display short chars in a tall cell. This controls the vertical offset for the short char within the tall cell.
|
protected |
the height of a tall character.
Calculated by init().
|
protected |
left border of the screen.
Calculated by init() based on the remainder after dividing by the number of columns.
|
protected |
top border of the screen.
Calculated by init() based on the remainder after dividing by the number of rows.