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 EmbeddedArtists AB

Committer:
embeddedartists
Date:
Tue Feb 17 10:34:13 2015 +0100
Revision:
11:265884fa7fdd
Parent:
8:19a6b70d42b1
Child:
17:6e2abf107800
- Replaced wait_ms with Thread::wait in SlideShow
- Fixed fade transition in SlideShow
- Added repeat/end buttons to AppSlideShow
- Added very basic transparent image rendering to SWIM
- Fixed errors in lpc_colors.h
- Added support for button captions to the ImageButton
- Added back buffering to the AppColorPicker
- Added basic_image_data.h/c with the ok/cancel/repeat buttons
- Moved the slideshow parameters to the constructor of AppSlideShow

Who changed what in which revision?

UserRevisionLine numberNew contents of line
embeddedartists 0:4977187e90c7 1 /*
embeddedartists 0:4977187e90c7 2 * Copyright 2014 Embedded Artists AB
embeddedartists 0:4977187e90c7 3 *
embeddedartists 0:4977187e90c7 4 * Licensed under the Apache License, Version 2.0 (the "License");
embeddedartists 0:4977187e90c7 5 * you may not use this file except in compliance with the License.
embeddedartists 0:4977187e90c7 6 * You may obtain a copy of the License at
embeddedartists 0:4977187e90c7 7 *
embeddedartists 0:4977187e90c7 8 * http://www.apache.org/licenses/LICENSE-2.0
embeddedartists 0:4977187e90c7 9 *
embeddedartists 0:4977187e90c7 10 * Unless required by applicable law or agreed to in writing, software
embeddedartists 0:4977187e90c7 11 * distributed under the License is distributed on an "AS IS" BASIS,
embeddedartists 0:4977187e90c7 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
embeddedartists 0:4977187e90c7 13 * See the License for the specific language governing permissions and
embeddedartists 0:4977187e90c7 14 * limitations under the License.
embeddedartists 0:4977187e90c7 15 */
embeddedartists 0:4977187e90c7 16
embeddedartists 0:4977187e90c7 17
embeddedartists 0:4977187e90c7 18 #include "mbed.h"
embeddedartists 0:4977187e90c7 19 #include "EthernetInterface.h"
embeddedartists 0:4977187e90c7 20 #include "AppColorPicker.h"
embeddedartists 0:4977187e90c7 21 #include "lpc_swim_font.h"
embeddedartists 11:265884fa7fdd 22 #include "basic_image_data.h"
embeddedartists 0:4977187e90c7 23
embeddedartists 0:4977187e90c7 24 /******************************************************************************
embeddedartists 0:4977187e90c7 25 * Defines and typedefs
embeddedartists 0:4977187e90c7 26 *****************************************************************************/
embeddedartists 0:4977187e90c7 27
embeddedartists 0:4977187e90c7 28 #define BOX_SIDE 192 //256
embeddedartists 0:4977187e90c7 29
embeddedartists 0:4977187e90c7 30 #define BTN_WIDTH 65
embeddedartists 0:4977187e90c7 31 #define BTN_HEIGHT 40
embeddedartists 0:4977187e90c7 32 #define BTN_OFF 20
embeddedartists 0:4977187e90c7 33
embeddedartists 0:4977187e90c7 34 /******************************************************************************
embeddedartists 0:4977187e90c7 35 * Global variables
embeddedartists 0:4977187e90c7 36 *****************************************************************************/
embeddedartists 0:4977187e90c7 37
embeddedartists 0:4977187e90c7 38 /******************************************************************************
embeddedartists 0:4977187e90c7 39 * Private functions
embeddedartists 0:4977187e90c7 40 *****************************************************************************/
embeddedartists 0:4977187e90c7 41
embeddedartists 0:4977187e90c7 42 static void buttonClicked(uint32_t x)
embeddedartists 0:4977187e90c7 43 {
embeddedartists 0:4977187e90c7 44 bool* done = (bool*)x;
embeddedartists 0:4977187e90c7 45 *done = true;
embeddedartists 0:4977187e90c7 46 }
embeddedartists 0:4977187e90c7 47
embeddedartists 0:4977187e90c7 48 void AppColorPicker::draw()
embeddedartists 0:4977187e90c7 49 {
embeddedartists 0:4977187e90c7 50 // Prepare fullscreen
embeddedartists 0:4977187e90c7 51 swim_window_open(_win,
embeddedartists 0:4977187e90c7 52 _disp->width(), _disp->height(), // full size
embeddedartists 11:265884fa7fdd 53 _fb,
embeddedartists 0:4977187e90c7 54 0,0,_disp->width()-1, _disp->height()-1, // window position and size
embeddedartists 0:4977187e90c7 55 1, // border
embeddedartists 0:4977187e90c7 56 WHITE, WHITE, BLACK); // colors: pen, backgr, forgr
embeddedartists 0:4977187e90c7 57 swim_set_title(_win, "Color Picker", BLACK);
embeddedartists 0:4977187e90c7 58
embeddedartists 0:4977187e90c7 59 swim_window_open(_colorwin,
embeddedartists 0:4977187e90c7 60 _disp->width(), _disp->height(), // full size
embeddedartists 11:265884fa7fdd 61 _fb,
embeddedartists 0:4977187e90c7 62 50,(_disp->height()-BOX_SIDE)/2,50+BOX_SIDE-1, BOX_SIDE+(_disp->height()-BOX_SIDE)/2, // window position and size
embeddedartists 0:4977187e90c7 63 0, // border
embeddedartists 0:4977187e90c7 64 WHITE, WHITE, BLACK); // colors: pen, backgr, forgr
embeddedartists 0:4977187e90c7 65
embeddedartists 0:4977187e90c7 66
embeddedartists 0:4977187e90c7 67 uint16_t r, g, b;
embeddedartists 0:4977187e90c7 68 uint16_t rx = BOX_SIDE/32;
embeddedartists 0:4977187e90c7 69 //uint16_t gx = BOX_SIDE/64;
embeddedartists 0:4977187e90c7 70 uint16_t bx = BOX_SIDE/32;
embeddedartists 0:4977187e90c7 71 //uint16_t ry = BOX_SIDE/32;
embeddedartists 0:4977187e90c7 72 uint16_t gy = BOX_SIDE/64;
embeddedartists 0:4977187e90c7 73 //uint16_t by = BOX_SIDE/32;
embeddedartists 0:4977187e90c7 74 uint16_t color;
embeddedartists 0:4977187e90c7 75 for (int x = 0; x < BOX_SIDE; x++) {
embeddedartists 0:4977187e90c7 76 r = (x/rx);
embeddedartists 0:4977187e90c7 77 b = 0x1f - (x/bx);
embeddedartists 0:4977187e90c7 78 color = ((r & 0x1f) << 11) | ((b & 0x1f) << 0);
embeddedartists 0:4977187e90c7 79 for (int y = 0; y < BOX_SIDE; y++) {
embeddedartists 0:4977187e90c7 80 g = (y/gy);
embeddedartists 0:4977187e90c7 81 _colorwin->pen = color | ((g & 0x3f) << 5);
embeddedartists 0:4977187e90c7 82 swim_put_pixel(_colorwin, x, y);
embeddedartists 0:4977187e90c7 83 }
embeddedartists 0:4977187e90c7 84 }
embeddedartists 0:4977187e90c7 85
embeddedartists 11:265884fa7fdd 86 _btn = new ImageButton(_win->fb, _win->xpmax - BTN_OFF - BTN_WIDTH, _win->ypmax - BTN_OFF - BTN_HEIGHT, BTN_WIDTH, BTN_HEIGHT);
embeddedartists 11:265884fa7fdd 87 _btn->loadImages(img_ok, img_size_ok);
embeddedartists 0:4977187e90c7 88 _btn->draw();
embeddedartists 11:265884fa7fdd 89
embeddedartists 11:265884fa7fdd 90 // Copy everything onto the back buffer
embeddedartists 11:265884fa7fdd 91 memcpy(_fb2, _fb, _disp->fbSize());
embeddedartists 0:4977187e90c7 92 }
embeddedartists 0:4977187e90c7 93
embeddedartists 0:4977187e90c7 94 /******************************************************************************
embeddedartists 0:4977187e90c7 95 * Public functions
embeddedartists 0:4977187e90c7 96 *****************************************************************************/
embeddedartists 0:4977187e90c7 97
embeddedartists 11:265884fa7fdd 98 AppColorPicker::AppColorPicker() : _disp(NULL), _win(NULL), _colorwin(NULL),
embeddedartists 11:265884fa7fdd 99 _fb(NULL), _fb2(NULL), _btn(NULL)
embeddedartists 0:4977187e90c7 100 {
embeddedartists 0:4977187e90c7 101 }
embeddedartists 0:4977187e90c7 102
embeddedartists 0:4977187e90c7 103 AppColorPicker::~AppColorPicker()
embeddedartists 0:4977187e90c7 104 {
embeddedartists 0:4977187e90c7 105 teardown();
embeddedartists 0:4977187e90c7 106 }
embeddedartists 0:4977187e90c7 107
embeddedartists 0:4977187e90c7 108 bool AppColorPicker::setup()
embeddedartists 0:4977187e90c7 109 {
embeddedartists 0:4977187e90c7 110 _disp = DMBoard::instance().display();
embeddedartists 0:4977187e90c7 111 _win = (SWIM_WINDOW_T*)malloc(sizeof(SWIM_WINDOW_T));
embeddedartists 0:4977187e90c7 112 _colorwin = (SWIM_WINDOW_T*)malloc(sizeof(SWIM_WINDOW_T));
embeddedartists 11:265884fa7fdd 113 _fb = (COLOR_T*)_disp->allocateFramebuffer();
embeddedartists 11:265884fa7fdd 114 _fb2 = (COLOR_T*)_disp->allocateFramebuffer();
embeddedartists 0:4977187e90c7 115
embeddedartists 11:265884fa7fdd 116 return (_win != NULL && _colorwin != NULL && _fb != NULL && _fb2 != NULL);
embeddedartists 0:4977187e90c7 117 }
embeddedartists 0:4977187e90c7 118
embeddedartists 0:4977187e90c7 119 void AppColorPicker::runToCompletion()
embeddedartists 0:4977187e90c7 120 {
embeddedartists 0:4977187e90c7 121 bool done = false;
embeddedartists 0:4977187e90c7 122 draw();
embeddedartists 0:4977187e90c7 123 _btn->setAction(buttonClicked, (uint32_t)&done);
embeddedartists 11:265884fa7fdd 124 void* oldFB = _disp->swapFramebuffer(_fb2);
embeddedartists 0:4977187e90c7 125
embeddedartists 0:4977187e90c7 126 // Wait for touches
embeddedartists 0:4977187e90c7 127 TouchPanel* touch = DMBoard::instance().touchPanel();
embeddedartists 8:19a6b70d42b1 128 touch_coordinate_t coord;
embeddedartists 0:4977187e90c7 129 char buf[10];
embeddedartists 0:4977187e90c7 130 swim_set_pen_color(_win, BLACK);
embeddedartists 11:265884fa7fdd 131 bool showingFB2 = true;
embeddedartists 11:265884fa7fdd 132 COLOR_T lastColor = WHITE;
embeddedartists 0:4977187e90c7 133 while(!done) {
embeddedartists 8:19a6b70d42b1 134 // wait for a new touch signal (signal is sent from AppLauncher,
embeddedartists 8:19a6b70d42b1 135 // which listens for touch events)
embeddedartists 8:19a6b70d42b1 136 Thread::signal_wait(0x1);
embeddedartists 3:3fabfe3339b8 137 if (touch->read(coord) == TouchPanel::TouchError_Ok) {
embeddedartists 3:3fabfe3339b8 138 if (coord.z > 0 &&
embeddedartists 3:3fabfe3339b8 139 coord.x >= _colorwin->xpmin && coord.x <= _colorwin->xpmax &&
embeddedartists 3:3fabfe3339b8 140 coord.y >= _colorwin->ypmin && coord.y <= _colorwin->ypmax) {
embeddedartists 3:3fabfe3339b8 141 int x = coord.x - _colorwin->xpmin;
embeddedartists 3:3fabfe3339b8 142 int y = coord.y - _colorwin->ypmin;
embeddedartists 3:3fabfe3339b8 143 COLOR_T c = ((x/(BOX_SIDE/32))<<11) | ((y/(BOX_SIDE/64))<<5) | ((0x1f-(x/(BOX_SIDE/32)))<<0);
embeddedartists 11:265884fa7fdd 144 if (c != lastColor) {
embeddedartists 3:3fabfe3339b8 145 swim_set_fill_color(_win, c);
embeddedartists 3:3fabfe3339b8 146 swim_put_box(_win, 350, 70, 430, 150);
embeddedartists 3:3fabfe3339b8 147 sprintf(buf, "0x%04x ", c);
embeddedartists 3:3fabfe3339b8 148 swim_put_text_xy(_win, buf, 350, 160);
embeddedartists 11:265884fa7fdd 149
embeddedartists 11:265884fa7fdd 150 // Swap what is shown and what is drawn on
embeddedartists 11:265884fa7fdd 151 if (showingFB2) {
embeddedartists 11:265884fa7fdd 152 _disp->setFramebuffer(_fb);
embeddedartists 11:265884fa7fdd 153 _win->fb = _fb2;
embeddedartists 11:265884fa7fdd 154 } else {
embeddedartists 11:265884fa7fdd 155 _disp->setFramebuffer(_fb2);
embeddedartists 11:265884fa7fdd 156 _win->fb = _fb;
embeddedartists 11:265884fa7fdd 157 }
embeddedartists 11:265884fa7fdd 158 Thread::wait(20);
embeddedartists 11:265884fa7fdd 159 showingFB2 = !showingFB2;
embeddedartists 11:265884fa7fdd 160 lastColor = c;
embeddedartists 11:265884fa7fdd 161 }
embeddedartists 3:3fabfe3339b8 162 }
embeddedartists 3:3fabfe3339b8 163 if (_btn->handle(coord.x, coord.y, coord.z > 0)) {
embeddedartists 11:265884fa7fdd 164 _btn->draw(showingFB2 ? _fb2 : _fb);
embeddedartists 3:3fabfe3339b8 165 }
embeddedartists 0:4977187e90c7 166 }
embeddedartists 0:4977187e90c7 167 }
embeddedartists 0:4977187e90c7 168
embeddedartists 0:4977187e90c7 169 // User has clicked the button, restore the original FB
embeddedartists 0:4977187e90c7 170 _disp->swapFramebuffer(oldFB);
embeddedartists 0:4977187e90c7 171 swim_window_close(_win);
embeddedartists 0:4977187e90c7 172 swim_window_close(_colorwin);
embeddedartists 0:4977187e90c7 173 }
embeddedartists 0:4977187e90c7 174
embeddedartists 0:4977187e90c7 175 bool AppColorPicker::teardown()
embeddedartists 0:4977187e90c7 176 {
embeddedartists 0:4977187e90c7 177 if (_win != NULL) {
embeddedartists 0:4977187e90c7 178 free(_win);
embeddedartists 0:4977187e90c7 179 _win = NULL;
embeddedartists 0:4977187e90c7 180 }
embeddedartists 0:4977187e90c7 181 if (_colorwin != NULL) {
embeddedartists 0:4977187e90c7 182 free(_colorwin);
embeddedartists 0:4977187e90c7 183 _colorwin = NULL;
embeddedartists 0:4977187e90c7 184 }
embeddedartists 0:4977187e90c7 185 if (_fb != NULL) {
embeddedartists 0:4977187e90c7 186 free(_fb);
embeddedartists 0:4977187e90c7 187 _fb = NULL;
embeddedartists 0:4977187e90c7 188 }
embeddedartists 11:265884fa7fdd 189 if (_fb2 != NULL) {
embeddedartists 11:265884fa7fdd 190 free(_fb2);
embeddedartists 11:265884fa7fdd 191 _fb2 = NULL;
embeddedartists 11:265884fa7fdd 192 }
embeddedartists 0:4977187e90c7 193 if (_btn != NULL) {
embeddedartists 0:4977187e90c7 194 delete _btn;
embeddedartists 0:4977187e90c7 195 _btn = NULL;
embeddedartists 0:4977187e90c7 196 }
embeddedartists 0:4977187e90c7 197 return true;
embeddedartists 0:4977187e90c7 198 }
embeddedartists 0:4977187e90c7 199
embeddedartists 0:4977187e90c7 200