Example that shows how to use the ewgui wrapper classes in combination with Segger's emwin library.
Dependencies: EALib ewgui mbed
main.cpp@2:789b4879e22f, 2014-04-14 (annotated)
- Committer:
- embeddedartists
- Date:
- Mon Apr 14 08:39:47 2014 +0000
- Revision:
- 2:789b4879e22f
- Parent:
- 0:6b81fd4666bb
Updated ewgui to latest version
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
embeddedartists | 0:6b81fd4666bb | 1 | |
embeddedartists | 0:6b81fd4666bb | 2 | /****************************************************************************** |
embeddedartists | 0:6b81fd4666bb | 3 | * Includes |
embeddedartists | 0:6b81fd4666bb | 4 | *****************************************************************************/ |
embeddedartists | 0:6b81fd4666bb | 5 | |
embeddedartists | 0:6b81fd4666bb | 6 | #include "mbed.h" |
embeddedartists | 0:6b81fd4666bb | 7 | |
embeddedartists | 0:6b81fd4666bb | 8 | #include "sdram.h" |
embeddedartists | 0:6b81fd4666bb | 9 | |
embeddedartists | 0:6b81fd4666bb | 10 | #include "EwGuiImpl.h" |
embeddedartists | 0:6b81fd4666bb | 11 | #include "EwFrameWindow.h" |
embeddedartists | 0:6b81fd4666bb | 12 | #include "MyWindow.h" |
embeddedartists | 0:6b81fd4666bb | 13 | |
embeddedartists | 0:6b81fd4666bb | 14 | |
embeddedartists | 0:6b81fd4666bb | 15 | /****************************************************************************** |
embeddedartists | 0:6b81fd4666bb | 16 | * Typedefs and defines |
embeddedartists | 0:6b81fd4666bb | 17 | *****************************************************************************/ |
embeddedartists | 0:6b81fd4666bb | 18 | |
embeddedartists | 0:6b81fd4666bb | 19 | |
embeddedartists | 0:6b81fd4666bb | 20 | /****************************************************************************** |
embeddedartists | 0:6b81fd4666bb | 21 | * Local variables |
embeddedartists | 0:6b81fd4666bb | 22 | *****************************************************************************/ |
embeddedartists | 0:6b81fd4666bb | 23 | |
embeddedartists | 0:6b81fd4666bb | 24 | static EwGuiImpl* gui = NULL; |
embeddedartists | 0:6b81fd4666bb | 25 | |
embeddedartists | 0:6b81fd4666bb | 26 | /****************************************************************************** |
embeddedartists | 0:6b81fd4666bb | 27 | * Local functions |
embeddedartists | 0:6b81fd4666bb | 28 | *****************************************************************************/ |
embeddedartists | 0:6b81fd4666bb | 29 | |
embeddedartists | 0:6b81fd4666bb | 30 | static void pollTouch() { |
embeddedartists | 0:6b81fd4666bb | 31 | if (gui == NULL) return; |
embeddedartists | 0:6b81fd4666bb | 32 | |
embeddedartists | 0:6b81fd4666bb | 33 | gui->execTouch(); |
embeddedartists | 0:6b81fd4666bb | 34 | } |
embeddedartists | 0:6b81fd4666bb | 35 | |
embeddedartists | 0:6b81fd4666bb | 36 | /****************************************************************************** |
embeddedartists | 0:6b81fd4666bb | 37 | * Main function |
embeddedartists | 0:6b81fd4666bb | 38 | *****************************************************************************/ |
embeddedartists | 0:6b81fd4666bb | 39 | |
embeddedartists | 0:6b81fd4666bb | 40 | int main (void) { |
embeddedartists | 0:6b81fd4666bb | 41 | Ticker ticker; |
embeddedartists | 0:6b81fd4666bb | 42 | |
embeddedartists | 0:6b81fd4666bb | 43 | // Frame buffer is put in SDRAM |
embeddedartists | 0:6b81fd4666bb | 44 | if (sdram_init() == 1) { |
embeddedartists | 0:6b81fd4666bb | 45 | printf("Failed to initialize SDRAM\n"); |
embeddedartists | 0:6b81fd4666bb | 46 | return 1; |
embeddedartists | 0:6b81fd4666bb | 47 | } |
embeddedartists | 0:6b81fd4666bb | 48 | |
embeddedartists | 0:6b81fd4666bb | 49 | // instantiate and initialize GUI |
embeddedartists | 0:6b81fd4666bb | 50 | gui = new EwGuiImpl(); |
embeddedartists | 0:6b81fd4666bb | 51 | if (gui == NULL) { |
embeddedartists | 0:6b81fd4666bb | 52 | printf("Failed to instantiate EwGuiImpl\n"); |
embeddedartists | 0:6b81fd4666bb | 53 | return 1; |
embeddedartists | 0:6b81fd4666bb | 54 | } |
embeddedartists | 0:6b81fd4666bb | 55 | |
embeddedartists | 0:6b81fd4666bb | 56 | // calibrate touch screen |
embeddedartists | 0:6b81fd4666bb | 57 | gui->calibrate(); |
embeddedartists | 0:6b81fd4666bb | 58 | |
embeddedartists | 0:6b81fd4666bb | 59 | // register a callback that will check for touch events |
embeddedartists | 0:6b81fd4666bb | 60 | ticker.attach(&pollTouch, 0.10); |
embeddedartists | 0:6b81fd4666bb | 61 | |
embeddedartists | 0:6b81fd4666bb | 62 | // showing how to enable skinning |
embeddedartists | 0:6b81fd4666bb | 63 | BUTTON_SetDefaultSkin (BUTTON_SKIN_FLEX); |
embeddedartists | 0:6b81fd4666bb | 64 | CHECKBOX_SetDefaultSkin (CHECKBOX_SKIN_FLEX); |
embeddedartists | 0:6b81fd4666bb | 65 | DROPDOWN_SetDefaultSkin (DROPDOWN_SKIN_FLEX); |
embeddedartists | 0:6b81fd4666bb | 66 | FRAMEWIN_SetDefaultSkin (FRAMEWIN_SKIN_FLEX); |
embeddedartists | 0:6b81fd4666bb | 67 | |
embeddedartists | 0:6b81fd4666bb | 68 | // make sure the desktop has a color so that it is redrawn |
embeddedartists | 0:6b81fd4666bb | 69 | EwWindow::setDesktopColor(EW_BLACK); |
embeddedartists | 0:6b81fd4666bb | 70 | |
embeddedartists | 0:6b81fd4666bb | 71 | // create a frame window |
embeddedartists | 0:6b81fd4666bb | 72 | EwFrameWindow frameWin(30, 30, gui->getDisplayWidth()-60, |
embeddedartists | 0:6b81fd4666bb | 73 | gui->getDisplayHeight()-60, "Window Title"); |
embeddedartists | 0:6b81fd4666bb | 74 | frameWin.setTitleHeight(20); |
embeddedartists | 0:6b81fd4666bb | 75 | |
embeddedartists | 0:6b81fd4666bb | 76 | // create and associate a custom window with the frame window |
embeddedartists | 0:6b81fd4666bb | 77 | MyWindow myWindow(&frameWin); |
embeddedartists | 0:6b81fd4666bb | 78 | |
embeddedartists | 0:6b81fd4666bb | 79 | // application loop running the UI and checking for touch events |
embeddedartists | 0:6b81fd4666bb | 80 | while(1) { |
embeddedartists | 0:6b81fd4666bb | 81 | |
embeddedartists | 0:6b81fd4666bb | 82 | // In this example touch events are checked by interrupt |
embeddedartists | 0:6b81fd4666bb | 83 | // (pollTouch function), but we could also have done it |
embeddedartists | 0:6b81fd4666bb | 84 | // in this while loop |
embeddedartists | 0:6b81fd4666bb | 85 | //gui.execTouch(); |
embeddedartists | 0:6b81fd4666bb | 86 | gui->exec(); |
embeddedartists | 0:6b81fd4666bb | 87 | |
embeddedartists | 0:6b81fd4666bb | 88 | } |
embeddedartists | 0:6b81fd4666bb | 89 | |
embeddedartists | 0:6b81fd4666bb | 90 | } |