A basic graphics package for the LPC4088 Display Module.
Dependents: lpc4088_displaymodule_demo_sphere sampleGUI sampleEmptyGUI lpc4088_displaymodule_fs_aid ... more
Fork of DMBasicGUI by
Application/Resource.h@22:f0d00f29bfeb, 2019-11-04 (annotated)
- Committer:
- embeddedartists
- Date:
- Mon Nov 04 14:31:50 2019 +0000
- Revision:
- 22:f0d00f29bfeb
- Parent:
- 18:d41537a70189
More updates related to mbed OS 5
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
embeddedartists | 17:6e2abf107800 | 1 | /* |
embeddedartists | 17:6e2abf107800 | 2 | * Copyright 2014 Embedded Artists AB |
embeddedartists | 17:6e2abf107800 | 3 | * |
embeddedartists | 17:6e2abf107800 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
embeddedartists | 17:6e2abf107800 | 5 | * you may not use this file except in compliance with the License. |
embeddedartists | 17:6e2abf107800 | 6 | * You may obtain a copy of the License at |
embeddedartists | 17:6e2abf107800 | 7 | * |
embeddedartists | 17:6e2abf107800 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
embeddedartists | 17:6e2abf107800 | 9 | * |
embeddedartists | 17:6e2abf107800 | 10 | * Unless required by applicable law or agreed to in writing, software |
embeddedartists | 17:6e2abf107800 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
embeddedartists | 17:6e2abf107800 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
embeddedartists | 17:6e2abf107800 | 13 | * See the License for the specific language governing permissions and |
embeddedartists | 17:6e2abf107800 | 14 | * limitations under the License. |
embeddedartists | 17:6e2abf107800 | 15 | */ |
embeddedartists | 17:6e2abf107800 | 16 | |
embeddedartists | 17:6e2abf107800 | 17 | #ifndef RESOURCE_H |
embeddedartists | 17:6e2abf107800 | 18 | #define RESOURCE_H |
embeddedartists | 17:6e2abf107800 | 19 | |
embeddedartists | 17:6e2abf107800 | 20 | #include "mbed.h" |
embeddedartists | 17:6e2abf107800 | 21 | #include "Image.h" |
embeddedartists | 17:6e2abf107800 | 22 | |
embeddedartists | 17:6e2abf107800 | 23 | /** |
embeddedartists | 17:6e2abf107800 | 24 | * A resource container to pass around instead of using hardcoded data. |
embeddedartists | 17:6e2abf107800 | 25 | * |
embeddedartists | 17:6e2abf107800 | 26 | * Having a Resource class makes it possible to hide the source from the |
embeddedartists | 17:6e2abf107800 | 27 | * user so that e.g. AppColorPicker doesn't need to know if the OK button |
embeddedartists | 17:6e2abf107800 | 28 | * is loaded from an array or from a file system. The AppColorPicker only |
embeddedartists | 17:6e2abf107800 | 29 | * need the resource. The Image class takes care of the loading. |
embeddedartists | 17:6e2abf107800 | 30 | * |
embeddedartists | 17:6e2abf107800 | 31 | * @code |
embeddedartists | 17:6e2abf107800 | 32 | * #include "mbed.h" |
embeddedartists | 17:6e2abf107800 | 33 | * #include "Resource.h" |
embeddedartists | 17:6e2abf107800 | 34 | * #include "Image.h" |
embeddedartists | 17:6e2abf107800 | 35 | * |
embeddedartists | 17:6e2abf107800 | 36 | * const unsigned char ok_image1[] = { 137,80,78,71, ... }; |
embeddedartists | 17:6e2abf107800 | 37 | * int ok_image1_sz = sizeof(ok_image1); |
embeddedartists | 17:6e2abf107800 | 38 | * |
embeddedartists | 17:6e2abf107800 | 39 | * int main(void) { |
embeddedartists | 17:6e2abf107800 | 40 | * // initialize the display |
embeddedartists | 17:6e2abf107800 | 41 | * ... |
embeddedartists | 17:6e2abf107800 | 42 | * |
embeddedartists | 17:6e2abf107800 | 43 | * // create the resources |
embeddedartists | 17:6e2abf107800 | 44 | * Resource resOk(ok_image1, ok_image1_sz, 40, 40); |
embeddedartists | 17:6e2abf107800 | 45 | * Resource resCancel("/qspi/cancel.png", 40, 40); |
embeddedartists | 17:6e2abf107800 | 46 | * |
embeddedartists | 17:6e2abf107800 | 47 | * // add resource to application |
embeddedartists | 17:6e2abf107800 | 48 | * AppNetwork app ...; |
embeddedartists | 17:6e2abf107800 | 49 | * app.setResource(AppNetwork::Resource_Ok_Button, &resOk); |
embeddedartists | 17:6e2abf107800 | 50 | * app.setResource(AppNetwork::Resource_Cancel_Button, &resCancel); |
embeddedartists | 17:6e2abf107800 | 51 | * |
embeddedartists | 17:6e2abf107800 | 52 | * // run application |
embeddedartists | 17:6e2abf107800 | 53 | * app.setup(); |
embeddedartists | 17:6e2abf107800 | 54 | * app.runToCompletion(); |
alindvall | 18:d41537a70189 | 55 | * |
embeddedartists | 17:6e2abf107800 | 56 | * ... |
embeddedartists | 17:6e2abf107800 | 57 | * } |
embeddedartists | 17:6e2abf107800 | 58 | * @endcode |
embeddedartists | 17:6e2abf107800 | 59 | */ |
embeddedartists | 17:6e2abf107800 | 60 | class Resource { |
embeddedartists | 17:6e2abf107800 | 61 | public: |
embeddedartists | 17:6e2abf107800 | 62 | |
embeddedartists | 17:6e2abf107800 | 63 | /** Create a new file resource. |
embeddedartists | 17:6e2abf107800 | 64 | * |
embeddedartists | 17:6e2abf107800 | 65 | * The width and height are only guidelines and are often not used. |
embeddedartists | 17:6e2abf107800 | 66 | * The purpose is to allow e.g. the AppColorPicker to know the size |
embeddedartists | 17:6e2abf107800 | 67 | * of the image before it is loaded from the file system. It can also |
embeddedartists | 17:6e2abf107800 | 68 | * be used as a guide by the AppLauncher. |
embeddedartists | 17:6e2abf107800 | 69 | * |
embeddedartists | 17:6e2abf107800 | 70 | * @param filename the resource location |
embeddedartists | 17:6e2abf107800 | 71 | * @param width the width of the image |
embeddedartists | 17:6e2abf107800 | 72 | * @param height the height of the image |
embeddedartists | 17:6e2abf107800 | 73 | */ |
embeddedartists | 17:6e2abf107800 | 74 | Resource(const char* filename, int width, int height); |
embeddedartists | 17:6e2abf107800 | 75 | |
embeddedartists | 17:6e2abf107800 | 76 | /** Create a new resource from a data array. |
embeddedartists | 17:6e2abf107800 | 77 | * |
embeddedartists | 17:6e2abf107800 | 78 | * The width and height are only guidelines and are often not used. |
embeddedartists | 17:6e2abf107800 | 79 | * The purpose is to allow e.g. the AppColorPicker to know the size |
embeddedartists | 17:6e2abf107800 | 80 | * of the image before it is loaded from the file system. It can also |
embeddedartists | 17:6e2abf107800 | 81 | * be used as a guide by the AppLauncher. |
embeddedartists | 17:6e2abf107800 | 82 | * |
embeddedartists | 17:6e2abf107800 | 83 | * @param data the resource |
embeddedartists | 17:6e2abf107800 | 84 | * @param dataSize number of bytes in data |
embeddedartists | 17:6e2abf107800 | 85 | * @param width the width of the image |
embeddedartists | 17:6e2abf107800 | 86 | * @param height the height of the image |
embeddedartists | 17:6e2abf107800 | 87 | */ |
embeddedartists | 17:6e2abf107800 | 88 | Resource(const unsigned char* data, const unsigned int dataSize, int width, int height); |
embeddedartists | 17:6e2abf107800 | 89 | ~Resource(); |
embeddedartists | 17:6e2abf107800 | 90 | |
embeddedartists | 17:6e2abf107800 | 91 | /** Returns the width of the resource. |
embeddedartists | 17:6e2abf107800 | 92 | * |
embeddedartists | 17:6e2abf107800 | 93 | * The width and height are only guidelines and are often not used. |
embeddedartists | 17:6e2abf107800 | 94 | * The purpose is to allow e.g. the AppColorPicker to know the size |
embeddedartists | 17:6e2abf107800 | 95 | * of the image before it is loaded from the file system. It can also |
embeddedartists | 17:6e2abf107800 | 96 | * be used as a guide by the AppLauncher. |
embeddedartists | 17:6e2abf107800 | 97 | * |
embeddedartists | 17:6e2abf107800 | 98 | * @return the width |
embeddedartists | 17:6e2abf107800 | 99 | */ |
embeddedartists | 17:6e2abf107800 | 100 | int width() { return _width; } |
embeddedartists | 17:6e2abf107800 | 101 | |
embeddedartists | 17:6e2abf107800 | 102 | /** Returns the height of the resource. |
embeddedartists | 17:6e2abf107800 | 103 | * |
embeddedartists | 17:6e2abf107800 | 104 | * The width and height are only guidelines and are often not used. |
embeddedartists | 17:6e2abf107800 | 105 | * The purpose is to allow e.g. the AppColorPicker to know the size |
embeddedartists | 17:6e2abf107800 | 106 | * of the image before it is loaded from the file system. It can also |
embeddedartists | 17:6e2abf107800 | 107 | * be used as a guide by the AppLauncher. |
embeddedartists | 17:6e2abf107800 | 108 | * |
embeddedartists | 17:6e2abf107800 | 109 | * @return the height |
embeddedartists | 17:6e2abf107800 | 110 | */ |
embeddedartists | 17:6e2abf107800 | 111 | int height() { return _height; } |
embeddedartists | 17:6e2abf107800 | 112 | |
embeddedartists | 17:6e2abf107800 | 113 | private: |
embeddedartists | 17:6e2abf107800 | 114 | friend class Image; |
embeddedartists | 17:6e2abf107800 | 115 | |
embeddedartists | 17:6e2abf107800 | 116 | int _width; |
embeddedartists | 17:6e2abf107800 | 117 | int _height; |
embeddedartists | 17:6e2abf107800 | 118 | bool _isFile; |
embeddedartists | 17:6e2abf107800 | 119 | char* _filename; |
embeddedartists | 17:6e2abf107800 | 120 | const unsigned char* _data; |
embeddedartists | 17:6e2abf107800 | 121 | unsigned int _dataSize; |
embeddedartists | 17:6e2abf107800 | 122 | |
embeddedartists | 17:6e2abf107800 | 123 | Image::ImageData_t _img; |
embeddedartists | 17:6e2abf107800 | 124 | }; |
embeddedartists | 17:6e2abf107800 | 125 | |
embeddedartists | 17:6e2abf107800 | 126 | #endif |