Repository for import to local machine
Dependencies: DMBasicGUI DMSupport
SwimDraw.cpp@8:26e49e6955bd, 2017-07-31 (annotated)
- Committer:
- jmitc91516
- Date:
- Mon Jul 31 15:37:57 2017 +0000
- Revision:
- 8:26e49e6955bd
- Parent:
- 1:a5258871b33d
Method ramp scrolling improved, and more bitmaps moved to QSPI memory
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jmitc91516 | 1:a5258871b33d | 1 | #include "mbed.h" |
jmitc91516 | 1:a5258871b33d | 2 | #include "DMBoard.h" |
jmitc91516 | 1:a5258871b33d | 3 | #include "lpc_swim.h" |
jmitc91516 | 1:a5258871b33d | 4 | #include "lpc_swim_font.h" |
jmitc91516 | 1:a5258871b33d | 5 | |
jmitc91516 | 1:a5258871b33d | 6 | #include "SwimDraw.h" |
jmitc91516 | 1:a5258871b33d | 7 | |
jmitc91516 | 1:a5258871b33d | 8 | /* |
jmitc91516 | 1:a5258871b33d | 9 | Note that this class is a singleton - we do not need or want there to be more than one instance of it |
jmitc91516 | 1:a5258871b33d | 10 | (we do not want multiple values for the carrier gas selection, etc, and nor will we show |
jmitc91516 | 1:a5258871b33d | 11 | more than one easyGUI 'GasCalibrationPage' to the user at the same time). |
jmitc91516 | 1:a5258871b33d | 12 | */ |
jmitc91516 | 1:a5258871b33d | 13 | SwimDraw * SwimDraw::theSwimDrawInstance = NULL; |
jmitc91516 | 1:a5258871b33d | 14 | |
jmitc91516 | 1:a5258871b33d | 15 | |
jmitc91516 | 1:a5258871b33d | 16 | /* |
jmitc91516 | 1:a5258871b33d | 17 | Singleton class - return the one and only instance, first creating it if necessary. |
jmitc91516 | 1:a5258871b33d | 18 | */ |
jmitc91516 | 1:a5258871b33d | 19 | SwimDraw * SwimDraw::GetInstance(void) |
jmitc91516 | 1:a5258871b33d | 20 | { |
jmitc91516 | 1:a5258871b33d | 21 | if (theSwimDrawInstance == NULL) { |
jmitc91516 | 1:a5258871b33d | 22 | theSwimDrawInstance = new SwimDraw(); |
jmitc91516 | 1:a5258871b33d | 23 | } |
jmitc91516 | 1:a5258871b33d | 24 | |
jmitc91516 | 1:a5258871b33d | 25 | return theSwimDrawInstance; |
jmitc91516 | 1:a5258871b33d | 26 | } |
jmitc91516 | 1:a5258871b33d | 27 | |
jmitc91516 | 1:a5258871b33d | 28 | // Singleton class - private constructor |
jmitc91516 | 1:a5258871b33d | 29 | SwimDraw::SwimDraw() |
jmitc91516 | 1:a5258871b33d | 30 | { |
jmitc91516 | 1:a5258871b33d | 31 | initialised = false; |
jmitc91516 | 1:a5258871b33d | 32 | } |
jmitc91516 | 1:a5258871b33d | 33 | |
jmitc91516 | 1:a5258871b33d | 34 | // Private destructor also |
jmitc91516 | 1:a5258871b33d | 35 | SwimDraw::~SwimDraw() |
jmitc91516 | 1:a5258871b33d | 36 | { |
jmitc91516 | 1:a5258871b33d | 37 | |
jmitc91516 | 1:a5258871b33d | 38 | } |
jmitc91516 | 1:a5258871b33d | 39 | |
jmitc91516 | 1:a5258871b33d | 40 | |
jmitc91516 | 1:a5258871b33d | 41 | /* |
jmitc91516 | 1:a5258871b33d | 42 | Initialise the SwimDraw instance to match the display. |
jmitc91516 | 1:a5258871b33d | 43 | |
jmitc91516 | 1:a5258871b33d | 44 | Args: pointer to the current DMBoard |
jmitc91516 | 1:a5258871b33d | 45 | pointer to the frame buffer |
jmitc91516 | 1:a5258871b33d | 46 | |
jmitc91516 | 1:a5258871b33d | 47 | No return code |
jmitc91516 | 1:a5258871b33d | 48 | */ |
jmitc91516 | 1:a5258871b33d | 49 | void SwimDraw::Initialise(DMBoard* board, void* frameBuffer) |
jmitc91516 | 1:a5258871b33d | 50 | { |
jmitc91516 | 1:a5258871b33d | 51 | // We only initialise once |
jmitc91516 | 1:a5258871b33d | 52 | |
jmitc91516 | 1:a5258871b33d | 53 | if(!initialised) { |
jmitc91516 | 1:a5258871b33d | 54 | |
jmitc91516 | 1:a5258871b33d | 55 | Display* disp = board->display(); |
jmitc91516 | 1:a5258871b33d | 56 | |
jmitc91516 | 1:a5258871b33d | 57 | swim_window_open_noclear(&swimWindowT, |
jmitc91516 | 1:a5258871b33d | 58 | disp->width(), disp->height(), // full size |
jmitc91516 | 1:a5258871b33d | 59 | (COLOR_T*)frameBuffer, |
jmitc91516 | 1:a5258871b33d | 60 | 0,0,disp->width()-1, disp->height()-1, // window position and size |
jmitc91516 | 1:a5258871b33d | 61 | 1, // border |
jmitc91516 | 1:a5258871b33d | 62 | WHITE, BLUE, BLACK); // colors: pen, backgr, forgr |
jmitc91516 | 1:a5258871b33d | 63 | |
jmitc91516 | 1:a5258871b33d | 64 | initialised = true; |
jmitc91516 | 1:a5258871b33d | 65 | } |
jmitc91516 | 1:a5258871b33d | 66 | } |
jmitc91516 | 1:a5258871b33d | 67 | |
jmitc91516 | 1:a5258871b33d | 68 | |
jmitc91516 | 1:a5258871b33d | 69 | /* |
jmitc91516 | 1:a5258871b33d | 70 | Draws a line on the display, using the relevant 'lpc_swim' functions. |
jmitc91516 | 1:a5258871b33d | 71 | Caller specifies the line colour and position. |
jmitc91516 | 1:a5258871b33d | 72 | |
jmitc91516 | 1:a5258871b33d | 73 | Args: colour |
jmitc91516 | 1:a5258871b33d | 74 | start X coord |
jmitc91516 | 1:a5258871b33d | 75 | start Y coord |
jmitc91516 | 1:a5258871b33d | 76 | end X coord |
jmitc91516 | 1:a5258871b33d | 77 | end Y coord |
jmitc91516 | 1:a5258871b33d | 78 | |
jmitc91516 | 1:a5258871b33d | 79 | Returns true if successful, false if not. |
jmitc91516 | 1:a5258871b33d | 80 | */ |
jmitc91516 | 1:a5258871b33d | 81 | bool SwimDraw::DrawLine(COLOR_T lineColour, int32_t xStart, int32_t yStart, int32_t xEnd, int32_t yEnd) |
jmitc91516 | 1:a5258871b33d | 82 | { |
jmitc91516 | 1:a5258871b33d | 83 | if (!initialised) { |
jmitc91516 | 1:a5258871b33d | 84 | return false; |
jmitc91516 | 1:a5258871b33d | 85 | } |
jmitc91516 | 1:a5258871b33d | 86 | |
jmitc91516 | 1:a5258871b33d | 87 | swim_set_pen_color(&swimWindowT, lineColour); |
jmitc91516 | 1:a5258871b33d | 88 | |
jmitc91516 | 1:a5258871b33d | 89 | swim_put_line(&swimWindowT, xStart, yStart, xEnd, yEnd); |
jmitc91516 | 1:a5258871b33d | 90 | |
jmitc91516 | 1:a5258871b33d | 91 | return true; |
jmitc91516 | 1:a5258871b33d | 92 | } |
jmitc91516 | 1:a5258871b33d | 93 | |
jmitc91516 | 1:a5258871b33d | 94 | |
jmitc91516 | 1:a5258871b33d | 95 | /* |
jmitc91516 | 1:a5258871b33d | 96 | Draws a solid rectangle on the display, using the relevant 'lpc_swim' functions. |
jmitc91516 | 1:a5258871b33d | 97 | Caller specifies the rectangle colour and position. |
jmitc91516 | 1:a5258871b33d | 98 | |
jmitc91516 | 1:a5258871b33d | 99 | Args: colour |
jmitc91516 | 1:a5258871b33d | 100 | start X coord |
jmitc91516 | 1:a5258871b33d | 101 | start Y coord |
jmitc91516 | 1:a5258871b33d | 102 | end X coord |
jmitc91516 | 1:a5258871b33d | 103 | end Y coord |
jmitc91516 | 1:a5258871b33d | 104 | |
jmitc91516 | 1:a5258871b33d | 105 | Returns true if successful, false if not. |
jmitc91516 | 1:a5258871b33d | 106 | */ |
jmitc91516 | 1:a5258871b33d | 107 | bool SwimDraw::DrawRectangle(COLOR_T rectColour, int32_t xStart, int32_t yStart, int32_t xEnd, int32_t yEnd) |
jmitc91516 | 1:a5258871b33d | 108 | { |
jmitc91516 | 1:a5258871b33d | 109 | if (!initialised) { |
jmitc91516 | 1:a5258871b33d | 110 | return false; |
jmitc91516 | 1:a5258871b33d | 111 | } |
jmitc91516 | 1:a5258871b33d | 112 | |
jmitc91516 | 1:a5258871b33d | 113 | swim_set_pen_color(&swimWindowT, rectColour); |
jmitc91516 | 1:a5258871b33d | 114 | swim_set_fill_color(&swimWindowT, rectColour); |
jmitc91516 | 1:a5258871b33d | 115 | |
jmitc91516 | 1:a5258871b33d | 116 | swim_put_box(&swimWindowT, xStart, yStart, xEnd, yEnd); |
jmitc91516 | 1:a5258871b33d | 117 | |
jmitc91516 | 1:a5258871b33d | 118 | return true; |
jmitc91516 | 1:a5258871b33d | 119 | } |
jmitc91516 | 1:a5258871b33d | 120 |