mbed Window Dragging demo for TFT-320QVT module with SSD1289 and XPT2046 touchscreen. copyright GNU Public License, v2. or later Creates a window, which can be dragged within the screen, and can be closed with the standard WIndows-style "x"-button. Window appearance: initial position, size and colors can be changed via defines. Window in this demo can not be moved beyond the screen area except of the right side. May require a touchscreen calibration procedure using UTouchCD.h Made by Dmitry Shtatnov, SSSR Labs http://modularsynth.ru/

Dependencies:   TFTLCD UTouch mbed

Committer:
rpocc
Date:
Mon Jan 11 09:35:50 2016 +0000
Revision:
0:dc51da7c52b1
The first version

Who changed what in which revision?

UserRevisionLine numberNew contents of line
rpocc 0:dc51da7c52b1 1 /** \file main.cpp
rpocc 0:dc51da7c52b1 2 * \brief mbed Window Dragging demo for TFT-320QVT module with SSD1289 and XPT2046 touchscreen.
rpocc 0:dc51da7c52b1 3 *
rpocc 0:dc51da7c52b1 4 * \copyright GNU Public License, v2. or later
rpocc 0:dc51da7c52b1 5 * Creates a window, which can be dragged within the screen, and can be closed
rpocc 0:dc51da7c52b1 6 * with the standard WIndows-style "x"-button.
rpocc 0:dc51da7c52b1 7 * Window appearance: initial position, size and colors can be changed via defines
rpocc 0:dc51da7c52b1 8 * Window in this demo can not be moved beyond the screen area except of the right side.
rpocc 0:dc51da7c52b1 9 * May require a touchscreen calibration procedure using UTouchCD.h
rpocc 0:dc51da7c52b1 10 *
rpocc 0:dc51da7c52b1 11 * Made by Dmitry Shtatnov, SSSR Labs
rpocc 0:dc51da7c52b1 12 * http://modularsynth.ru/
rpocc 0:dc51da7c52b1 13 ***************************************************************************************/
rpocc 0:dc51da7c52b1 14
rpocc 0:dc51da7c52b1 15 #include "mbed.h"
rpocc 0:dc51da7c52b1 16 #include "ssd1289.h"
rpocc 0:dc51da7c52b1 17 #include "UTouch.h"
rpocc 0:dc51da7c52b1 18
rpocc 0:dc51da7c52b1 19 #define C_WINDOW_BODY 0xCCCCCC
rpocc 0:dc51da7c52b1 20 #define C_WINDOW_HIGHLIGHT 0xDDDDDD
rpocc 0:dc51da7c52b1 21 #define C_WINDOW_SHADOW 0xBBBBBB
rpocc 0:dc51da7c52b1 22 #define C_WINDOW_TITLE_BAR 0x0066DD
rpocc 0:dc51da7c52b1 23
rpocc 0:dc51da7c52b1 24 #define WINDOW_WIDTH 150
rpocc 0:dc51da7c52b1 25 #define WINDOW_HEIGHT 100
rpocc 0:dc51da7c52b1 26
rpocc 0:dc51da7c52b1 27 PortOut LCDPA(PortA,0xFF00);
rpocc 0:dc51da7c52b1 28 PortOut LCDPC(PortC,0x00FF);
rpocc 0:dc51da7c52b1 29 // CS, REST, RS, WR, DATA, BL, RD
rpocc 0:dc51da7c52b1 30 SSD1289_LCD myGLCD(PB_3, PB_4, PB_0, PB_1, &LCDPA, &LCDPC, NC, PB_2);
rpocc 0:dc51da7c52b1 31
rpocc 0:dc51da7c52b1 32 UTouch myTouch(PB_9, PB_8, PB_7, PB_6, PB_5);
rpocc 0:dc51da7c52b1 33 long x, y, oldx, oldy, wx = 100, wy = 100;
rpocc 0:dc51da7c52b1 34 float p;
rpocc 0:dc51da7c52b1 35 uint8_t av_cnt;
rpocc 0:dc51da7c52b1 36 int16_t rx, ry, rz1, rz2, pressure;
rpocc 0:dc51da7c52b1 37 char xc[10], yc[10], z1c[10], z2c[10], str[15];
rpocc 0:dc51da7c52b1 38 bool drag = false;
rpocc 0:dc51da7c52b1 39
rpocc 0:dc51da7c52b1 40 bool title(uint16_t xcur, uint16_t ycur, uint16_t xwin, uint16_t ywin) {
rpocc 0:dc51da7c52b1 41 if((xcur>xwin+2)&&(xcur<xwin+WINDOW_WIDTH-18)&&(ycur>ywin+2)&&(ycur<ywin+22)) return true;
rpocc 0:dc51da7c52b1 42 else return false;
rpocc 0:dc51da7c52b1 43 }
rpocc 0:dc51da7c52b1 44
rpocc 0:dc51da7c52b1 45 bool close(uint16_t xcur, uint16_t ycur, uint16_t xwin, uint16_t ywin) {
rpocc 0:dc51da7c52b1 46 if((xcur>xwin+WINDOW_WIDTH-19)&&(xcur<xwin+WINDOW_WIDTH-1)&&(ycur>ywin+2)&&(ycur<ywin+21)) return true;
rpocc 0:dc51da7c52b1 47 else return false;
rpocc 0:dc51da7c52b1 48 }
rpocc 0:dc51da7c52b1 49
rpocc 0:dc51da7c52b1 50 void drawBox(uint16_t xpos, uint16_t ypos, uint16_t xsize, uint16_t ysize) {
rpocc 0:dc51da7c52b1 51 myGLCD.FillRect(xpos,ypos,xpos+xsize-1,ypos+ysize-1,C_WINDOW_BODY);
rpocc 0:dc51da7c52b1 52 myGLCD.DrawHLine(xpos,ypos,xsize,C_WINDOW_HIGHLIGHT);
rpocc 0:dc51da7c52b1 53 myGLCD.DrawHLine(xpos+1,ypos+ysize-1,xsize-1,C_WINDOW_SHADOW);
rpocc 0:dc51da7c52b1 54 myGLCD.DrawVLine(xpos,ypos,ysize,C_WINDOW_HIGHLIGHT);
rpocc 0:dc51da7c52b1 55 myGLCD.DrawVLine(xpos+xsize-1,ypos,ysize-1,C_WINDOW_SHADOW);
rpocc 0:dc51da7c52b1 56 }
rpocc 0:dc51da7c52b1 57
rpocc 0:dc51da7c52b1 58 void drawWindow(uint16_t xpos, uint16_t ypos, uint16_t xsize, uint16_t ysize) {
rpocc 0:dc51da7c52b1 59 drawBox(xpos, ypos, xsize, ysize);
rpocc 0:dc51da7c52b1 60 myGLCD.FillRect(xpos+2,ypos+2,xpos+xsize-3,ypos+21,C_WINDOW_TITLE_BAR);
rpocc 0:dc51da7c52b1 61 drawBox(xpos+xsize-21,ypos+3,18,18);
rpocc 0:dc51da7c52b1 62 myGLCD.DrawLine(xpos+xsize-18,ypos+6,xpos+xsize-7,ypos+17,COLOR_BLACK);
rpocc 0:dc51da7c52b1 63 myGLCD.DrawLine(xpos+xsize-18,ypos+17,xpos+xsize-7,ypos+6,COLOR_BLACK);
rpocc 0:dc51da7c52b1 64 }
rpocc 0:dc51da7c52b1 65 int main() {
rpocc 0:dc51da7c52b1 66 myGLCD.Initialize();
rpocc 0:dc51da7c52b1 67 myGLCD.SetBackground(COLOR_WHITE);
rpocc 0:dc51da7c52b1 68 myGLCD.SetForeground(COLOR_BLACK);
rpocc 0:dc51da7c52b1 69 myGLCD.FillScreen(COLOR_WHITE);
rpocc 0:dc51da7c52b1 70
rpocc 0:dc51da7c52b1 71 drawWindow(wx,wy,WINDOW_WIDTH,WINDOW_HEIGHT);
rpocc 0:dc51da7c52b1 72
rpocc 0:dc51da7c52b1 73 myGLCD.SetFont(&TerminusFont);
rpocc 0:dc51da7c52b1 74 myTouch.InitTouch();
rpocc 0:dc51da7c52b1 75 myTouch.SetPrecision(PREC_HI);
rpocc 0:dc51da7c52b1 76
rpocc 0:dc51da7c52b1 77 while(1==1) {
rpocc 0:dc51da7c52b1 78 if (myTouch.DataAvailable() == true)
rpocc 0:dc51da7c52b1 79 {
rpocc 0:dc51da7c52b1 80 if(myTouch.Read()) {
rpocc 0:dc51da7c52b1 81 x = myTouch.GetX();
rpocc 0:dc51da7c52b1 82 y = myTouch.GetY();
rpocc 0:dc51da7c52b1 83 if((oldx!=x)&&(oldy!=y)) {
rpocc 0:dc51da7c52b1 84 if(drag) {
rpocc 0:dc51da7c52b1 85 myGLCD.FillRect(wx, wy, wx+WINDOW_WIDTH-1, wy+WINDOW_HEIGHT-1, COLOR_WHITE);
rpocc 0:dc51da7c52b1 86 wx=wx+x-oldx;
rpocc 0:dc51da7c52b1 87 wy=wy+y-oldy;
rpocc 0:dc51da7c52b1 88 drawWindow(wx,wy,WINDOW_WIDTH,WINDOW_HEIGHT);
rpocc 0:dc51da7c52b1 89 }
rpocc 0:dc51da7c52b1 90 if(title(x, y, wx, wy)) {
rpocc 0:dc51da7c52b1 91 drag = true;
rpocc 0:dc51da7c52b1 92 }
rpocc 0:dc51da7c52b1 93 if(close(x, y, wx, wy)) {
rpocc 0:dc51da7c52b1 94 myGLCD.FillRect(wx, wy, wx+WINDOW_WIDTH-1, wy+WINDOW_HEIGHT-1, COLOR_WHITE);
rpocc 0:dc51da7c52b1 95 wx=320; wy=240;
rpocc 0:dc51da7c52b1 96 }
rpocc 0:dc51da7c52b1 97 oldx = x;
rpocc 0:dc51da7c52b1 98 oldy = y;
rpocc 0:dc51da7c52b1 99 }
rpocc 0:dc51da7c52b1 100 }
rpocc 0:dc51da7c52b1 101 }
rpocc 0:dc51da7c52b1 102 else {
rpocc 0:dc51da7c52b1 103 drag = false;
rpocc 0:dc51da7c52b1 104 }
rpocc 0:dc51da7c52b1 105 }
rpocc 0:dc51da7c52b1 106 }