Pi-XPlane-FMC-CDU
Classes | Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Types | Protected Member Functions | Protected Attributes | Static Protected Attributes | List of all members
Screen Class Reference

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 ScreengetInstance ()
 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 Screeninstance = NULL
 

Detailed Description

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.

Member Enumeration Documentation

§ ScreenEventType

enum Screen::ScreenEventType : int
protected

enum of possible event types

Member Function Documentation

§ clearScreen()

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.

§ doClear()

void Screen::doClear ( )
protected

implement a "clear" action

§ doDrawLine()

void Screen::doDrawLine ( SDL_Event *  event)
protected

implement a "lineUpdate" action

§ doInit()

void Screen::doInit ( SDL_Event *  event)
protected

implement an "init" action

§ drawLine()

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.

§ getInstance()

Screen * Screen::getInstance ( )
static

returns the singleton intance of a Screen.

§ initialize()

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.

§ mainLoop()

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.

§ quitLoop()

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.

Member Data Documentation

§ cellWidth

int Screen::cellWidth = 0
protected

width of a character cell on the screen.

Calculated by init().

§ interPollDelayMs

Uint32 Screen::interPollDelayMs = 1
protected

how long to delay in between polls of the update queue.

Too long increases lag, too low increases CPU utilization.

§ linePos

int Screen::linePos[15]
protected

screen offsets for each row.

§ numCols

int Screen::numCols = 0
protected

current number of columns.

Set by user via init()

§ numRows

int Screen::numRows = 14
protected

current number of rows.

Fixed value 8-)

§ screenRefreshTimerMs

Uint32 Screen::screenRefreshTimerMs = 10
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).

§ shortCellHeight

int Screen::shortCellHeight = 0
protected

the height of a short character.

Calculated by init().

§ shortCharVertOffset

int Screen::shortCharVertOffset = 0
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.

§ tallCellHeight

int Screen::tallCellHeight = 0
protected

the height of a tall character.

Calculated by init().

§ winLeftBorder

int Screen::winLeftBorder = 0
protected

left border of the screen.

Calculated by init() based on the remainder after dividing by the number of columns.

§ winTopBorder

int Screen::winTopBorder = 0
protected

top border of the screen.

Calculated by init() based on the remainder after dividing by the number of rows.


The documentation for this class was generated from the following files: