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
Diff: Application/AppColorPicker.cpp
- Revision:
- 11:265884fa7fdd
- Parent:
- 8:19a6b70d42b1
- Child:
- 17:6e2abf107800
diff -r 651861441108 -r 265884fa7fdd Application/AppColorPicker.cpp --- a/Application/AppColorPicker.cpp Mon Jan 26 10:06:58 2015 +0100 +++ b/Application/AppColorPicker.cpp Tue Feb 17 10:34:13 2015 +0100 @@ -19,6 +19,7 @@ #include "EthernetInterface.h" #include "AppColorPicker.h" #include "lpc_swim_font.h" +#include "basic_image_data.h" /****************************************************************************** * Defines and typedefs @@ -49,7 +50,7 @@ // Prepare fullscreen swim_window_open(_win, _disp->width(), _disp->height(), // full size - (COLOR_T*)_fb, + _fb, 0,0,_disp->width()-1, _disp->height()-1, // window position and size 1, // border WHITE, WHITE, BLACK); // colors: pen, backgr, forgr @@ -57,7 +58,7 @@ swim_window_open(_colorwin, _disp->width(), _disp->height(), // full size - (COLOR_T*)_fb, + _fb, 50,(_disp->height()-BOX_SIDE)/2,50+BOX_SIDE-1, BOX_SIDE+(_disp->height()-BOX_SIDE)/2, // window position and size 0, // border WHITE, WHITE, BLACK); // colors: pen, backgr, forgr @@ -82,15 +83,20 @@ } } - _btn = new Button("Done", _win->fb, _win->xpmax - BTN_OFF - BTN_WIDTH, _win->ypmax - BTN_OFF - BTN_HEIGHT, BTN_WIDTH, BTN_HEIGHT); + _btn = new ImageButton(_win->fb, _win->xpmax - BTN_OFF - BTN_WIDTH, _win->ypmax - BTN_OFF - BTN_HEIGHT, BTN_WIDTH, BTN_HEIGHT); + _btn->loadImages(img_ok, img_size_ok); _btn->draw(); + + // Copy everything onto the back buffer + memcpy(_fb2, _fb, _disp->fbSize()); } /****************************************************************************** * Public functions *****************************************************************************/ -AppColorPicker::AppColorPicker() : _disp(NULL), _win(NULL), _colorwin(NULL), _fb(NULL), _btn(NULL) +AppColorPicker::AppColorPicker() : _disp(NULL), _win(NULL), _colorwin(NULL), + _fb(NULL), _fb2(NULL), _btn(NULL) { } @@ -104,24 +110,26 @@ _disp = DMBoard::instance().display(); _win = (SWIM_WINDOW_T*)malloc(sizeof(SWIM_WINDOW_T)); _colorwin = (SWIM_WINDOW_T*)malloc(sizeof(SWIM_WINDOW_T)); - _fb = _disp->allocateFramebuffer(); + _fb = (COLOR_T*)_disp->allocateFramebuffer(); + _fb2 = (COLOR_T*)_disp->allocateFramebuffer(); - return (_win != NULL && _colorwin != NULL && _fb != NULL); + return (_win != NULL && _colorwin != NULL && _fb != NULL && _fb2 != NULL); } void AppColorPicker::runToCompletion() { - // Alternative 1: use the calling thread's context to run in bool done = false; draw(); _btn->setAction(buttonClicked, (uint32_t)&done); - void* oldFB = _disp->swapFramebuffer(_fb); + void* oldFB = _disp->swapFramebuffer(_fb2); // Wait for touches TouchPanel* touch = DMBoard::instance().touchPanel(); touch_coordinate_t coord; char buf[10]; swim_set_pen_color(_win, BLACK); + bool showingFB2 = true; + COLOR_T lastColor = WHITE; while(!done) { // wait for a new touch signal (signal is sent from AppLauncher, // which listens for touch events) @@ -133,13 +141,27 @@ int x = coord.x - _colorwin->xpmin; int y = coord.y - _colorwin->ypmin; COLOR_T c = ((x/(BOX_SIDE/32))<<11) | ((y/(BOX_SIDE/64))<<5) | ((0x1f-(x/(BOX_SIDE/32)))<<0); + if (c != lastColor) { swim_set_fill_color(_win, c); swim_put_box(_win, 350, 70, 430, 150); sprintf(buf, "0x%04x ", c); swim_put_text_xy(_win, buf, 350, 160); + + // Swap what is shown and what is drawn on + if (showingFB2) { + _disp->setFramebuffer(_fb); + _win->fb = _fb2; + } else { + _disp->setFramebuffer(_fb2); + _win->fb = _fb; + } + Thread::wait(20); + showingFB2 = !showingFB2; + lastColor = c; + } } if (_btn->handle(coord.x, coord.y, coord.z > 0)) { - _btn->draw(); + _btn->draw(showingFB2 ? _fb2 : _fb); } } } @@ -164,6 +186,10 @@ free(_fb); _fb = NULL; } + if (_fb2 != NULL) { + free(_fb2); + _fb2 = NULL; + } if (_btn != NULL) { delete _btn; _btn = NULL;