Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: MaximInterface
src/WindowManager.cpp@16:a004191a79ab, 2019-10-03 (annotated)
- Committer:
- IanBenzMaxim
- Date:
- Thu Oct 03 11:40:13 2019 -0500
- Revision:
- 16:a004191a79ab
- Parent:
- WindowManager.cpp@13:6a6225690c2e
Updated MaximInterface to version 2.0. Updated mbed-os to version 5.5.7. Cleaned up code styling.
Who changed what in which revision?
| User | Revision | Line number | New contents of line | 
|---|---|---|---|
| IanBenzMaxim | 0:33d4e66780c0 | 1 | /******************************************************************************* | 
| IanBenzMaxim | 16:a004191a79ab | 2 | * Copyright (C) Maxim Integrated Products, Inc., All Rights Reserved. | 
| IanBenzMaxim | 0:33d4e66780c0 | 3 | * | 
| IanBenzMaxim | 0:33d4e66780c0 | 4 | * Permission is hereby granted, free of charge, to any person obtaining a | 
| IanBenzMaxim | 0:33d4e66780c0 | 5 | * copy of this software and associated documentation files (the "Software"), | 
| IanBenzMaxim | 0:33d4e66780c0 | 6 | * to deal in the Software without restriction, including without limitation | 
| IanBenzMaxim | 0:33d4e66780c0 | 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, | 
| IanBenzMaxim | 0:33d4e66780c0 | 8 | * and/or sell copies of the Software, and to permit persons to whom the | 
| IanBenzMaxim | 0:33d4e66780c0 | 9 | * Software is furnished to do so, subject to the following conditions: | 
| IanBenzMaxim | 0:33d4e66780c0 | 10 | * | 
| IanBenzMaxim | 0:33d4e66780c0 | 11 | * The above copyright notice and this permission notice shall be included | 
| IanBenzMaxim | 0:33d4e66780c0 | 12 | * in all copies or substantial portions of the Software. | 
| IanBenzMaxim | 0:33d4e66780c0 | 13 | * | 
| IanBenzMaxim | 0:33d4e66780c0 | 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS | 
| IanBenzMaxim | 0:33d4e66780c0 | 15 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | 
| IanBenzMaxim | 0:33d4e66780c0 | 16 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | 
| IanBenzMaxim | 0:33d4e66780c0 | 17 | * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES | 
| IanBenzMaxim | 0:33d4e66780c0 | 18 | * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, | 
| IanBenzMaxim | 0:33d4e66780c0 | 19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR | 
| IanBenzMaxim | 0:33d4e66780c0 | 20 | * OTHER DEALINGS IN THE SOFTWARE. | 
| IanBenzMaxim | 0:33d4e66780c0 | 21 | * | 
| IanBenzMaxim | 0:33d4e66780c0 | 22 | * Except as contained in this notice, the name of Maxim Integrated | 
| IanBenzMaxim | 0:33d4e66780c0 | 23 | * Products, Inc. shall not be used except as stated in the Maxim Integrated | 
| IanBenzMaxim | 0:33d4e66780c0 | 24 | * Products, Inc. Branding Policy. | 
| IanBenzMaxim | 0:33d4e66780c0 | 25 | * | 
| IanBenzMaxim | 0:33d4e66780c0 | 26 | * The mere transfer of this software does not imply any licenses | 
| IanBenzMaxim | 0:33d4e66780c0 | 27 | * of trade secrets, proprietary technology, copyrights, patents, | 
| IanBenzMaxim | 0:33d4e66780c0 | 28 | * trademarks, maskwork rights, or any other form of intellectual | 
| IanBenzMaxim | 0:33d4e66780c0 | 29 | * property whatsoever. Maxim Integrated Products, Inc. retains all | 
| IanBenzMaxim | 0:33d4e66780c0 | 30 | * ownership rights. | 
| IanBenzMaxim | 0:33d4e66780c0 | 31 | *******************************************************************************/ | 
| IanBenzMaxim | 0:33d4e66780c0 | 32 | |
| IanBenzMaxim | 0:33d4e66780c0 | 33 | #include <algorithm> | 
| IanBenzMaxim | 0:33d4e66780c0 | 34 | #include <functional> | 
| IanBenzMaxim | 0:33d4e66780c0 | 35 | #include "Bitmap.hpp" | 
| IanBenzMaxim | 0:33d4e66780c0 | 36 | #include "WindowManager.hpp" | 
| IanBenzMaxim | 0:33d4e66780c0 | 37 | |
| IanBenzMaxim | 13:6a6225690c2e | 38 | static void deleteWindow(Window * window) { delete window; } | 
| IanBenzMaxim | 0:33d4e66780c0 | 39 | |
| IanBenzMaxim | 13:6a6225690c2e | 40 | WindowManager::~WindowManager() { | 
| IanBenzMaxim | 13:6a6225690c2e | 41 | // Free all windows. | 
| IanBenzMaxim | 13:6a6225690c2e | 42 | std::for_each(windowStack.begin(), windowStack.end(), deleteWindow); | 
| IanBenzMaxim | 13:6a6225690c2e | 43 | std::for_each(actionQueue.begin(), actionQueue.end(), deleteWindow); | 
| IanBenzMaxim | 0:33d4e66780c0 | 44 | } | 
| IanBenzMaxim | 0:33d4e66780c0 | 45 | |
| IanBenzMaxim | 13:6a6225690c2e | 46 | void WindowManager::processAction(Window * window) { | 
| IanBenzMaxim | 16:a004191a79ab | 47 | if (window) { | 
| IanBenzMaxim | 13:6a6225690c2e | 48 | windowStack.push_back(window); | 
| IanBenzMaxim | 16:a004191a79ab | 49 | } else if (!windowStack.empty()) { | 
| IanBenzMaxim | 16:a004191a79ab | 50 | delete windowStack.back(); | 
| IanBenzMaxim | 16:a004191a79ab | 51 | windowStack.pop_back(); | 
| IanBenzMaxim | 13:6a6225690c2e | 52 | } | 
| IanBenzMaxim | 0:33d4e66780c0 | 53 | } | 
| IanBenzMaxim | 0:33d4e66780c0 | 54 | |
| IanBenzMaxim | 13:6a6225690c2e | 55 | void WindowManager::push(std::auto_ptr<Window> & window) { | 
| IanBenzMaxim | 16:a004191a79ab | 56 | if (window.get()) { | 
| IanBenzMaxim | 13:6a6225690c2e | 57 | window->resize(canvas.width(), canvas.height()); | 
| IanBenzMaxim | 13:6a6225690c2e | 58 | window->move(0, 0); | 
| IanBenzMaxim | 13:6a6225690c2e | 59 | window->setWindowManager(NULL); | 
| IanBenzMaxim | 13:6a6225690c2e | 60 | actionQueue.push_back(window.release()); | 
| IanBenzMaxim | 13:6a6225690c2e | 61 | } | 
| IanBenzMaxim | 0:33d4e66780c0 | 62 | } | 
| IanBenzMaxim | 0:33d4e66780c0 | 63 | |
| IanBenzMaxim | 13:6a6225690c2e | 64 | void WindowManager::pop() { actionQueue.push_back(NULL); } | 
| IanBenzMaxim | 13:6a6225690c2e | 65 | |
| IanBenzMaxim | 13:6a6225690c2e | 66 | bool WindowManager::update() { | 
| IanBenzMaxim | 13:6a6225690c2e | 67 | bool redraw = false; | 
| IanBenzMaxim | 13:6a6225690c2e | 68 | |
| IanBenzMaxim | 13:6a6225690c2e | 69 | // Perform all queued push / pop actions. | 
| IanBenzMaxim | 13:6a6225690c2e | 70 | if (!actionQueue.empty()) { | 
| IanBenzMaxim | 13:6a6225690c2e | 71 | if (!windowStack.empty()) { | 
| IanBenzMaxim | 13:6a6225690c2e | 72 | windowStack.back()->setWindowManager(NULL); | 
| IanBenzMaxim | 0:33d4e66780c0 | 73 | } | 
| IanBenzMaxim | 13:6a6225690c2e | 74 | std::for_each( | 
| IanBenzMaxim | 13:6a6225690c2e | 75 | actionQueue.begin(), actionQueue.end(), | 
| IanBenzMaxim | 13:6a6225690c2e | 76 | std::bind1st(std::mem_fun(&WindowManager::processAction), this)); | 
| IanBenzMaxim | 13:6a6225690c2e | 77 | actionQueue.clear(); | 
| IanBenzMaxim | 13:6a6225690c2e | 78 | if (windowStack.empty()) { | 
| IanBenzMaxim | 13:6a6225690c2e | 79 | canvas.clear(); | 
| IanBenzMaxim | 13:6a6225690c2e | 80 | redraw = true; | 
| IanBenzMaxim | 13:6a6225690c2e | 81 | } else { | 
| IanBenzMaxim | 13:6a6225690c2e | 82 | windowStack.back()->setWindowManager(this); | 
| IanBenzMaxim | 0:33d4e66780c0 | 83 | } | 
| IanBenzMaxim | 13:6a6225690c2e | 84 | } | 
| IanBenzMaxim | 13:6a6225690c2e | 85 | |
| IanBenzMaxim | 13:6a6225690c2e | 86 | if (!windowStack.empty()) { | 
| IanBenzMaxim | 13:6a6225690c2e | 87 | // Update all windows. Only allow redraw of the top window. | 
| IanBenzMaxim | 13:6a6225690c2e | 88 | for (std::vector<Window *>::reverse_iterator it = windowStack.rbegin(); | 
| IanBenzMaxim | 16:a004191a79ab | 89 | it != windowStack.rend(); ++it) { | 
| IanBenzMaxim | 13:6a6225690c2e | 90 | if ((*it)->update(it == windowStack.rbegin() ? &canvas : NULL)) { | 
| IanBenzMaxim | 13:6a6225690c2e | 91 | redraw = true; | 
| IanBenzMaxim | 13:6a6225690c2e | 92 | } | 
| IanBenzMaxim | 13:6a6225690c2e | 93 | } | 
| IanBenzMaxim | 13:6a6225690c2e | 94 | } | 
| IanBenzMaxim | 13:6a6225690c2e | 95 | |
| IanBenzMaxim | 13:6a6225690c2e | 96 | return redraw; | 
| IanBenzMaxim | 0:33d4e66780c0 | 97 | } | 
| IanBenzMaxim | 0:33d4e66780c0 | 98 | |
| IanBenzMaxim | 13:6a6225690c2e | 99 | void WindowManager::processKey(Key key) { | 
| IanBenzMaxim | 13:6a6225690c2e | 100 | if (!windowStack.empty()) { | 
| IanBenzMaxim | 13:6a6225690c2e | 101 | windowStack.back()->processKey(key); | 
| IanBenzMaxim | 13:6a6225690c2e | 102 | } | 
| IanBenzMaxim | 0:33d4e66780c0 | 103 | } |