Library for 3.2'' uLcd Picaso Display4D system Picaso Serial Environment Command Set web: http://www.4dsystems.com.au/product/20/67/Processors_Graphics/PICASO/
Screen.cpp@1:a74e42cf52b2, 2015-04-05 (annotated)
- Committer:
- adelino
- Date:
- Sun Apr 05 13:54:48 2015 +0000
- Revision:
- 1:a74e42cf52b2
PicasoLib version 2
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
adelino | 1:a74e42cf52b2 | 1 | #include "Screen.h" |
adelino | 1:a74e42cf52b2 | 2 | |
adelino | 1:a74e42cf52b2 | 3 | Screen::Screen(PicasoSerial* serial,UINT16 _x,UINT16 _y,UINT16 _w,UINT16 _h,Color _colorBkg): |
adelino | 1:a74e42cf52b2 | 4 | myXpos(_x),myYpos(_y),myWidth(_w),myHeight(_h),myColorBkg(_colorBkg) |
adelino | 1:a74e42cf52b2 | 5 | { |
adelino | 1:a74e42cf52b2 | 6 | mySerial=serial; |
adelino | 1:a74e42cf52b2 | 7 | } |
adelino | 1:a74e42cf52b2 | 8 | //------------------------------------ |
adelino | 1:a74e42cf52b2 | 9 | Screen::~Screen(void) |
adelino | 1:a74e42cf52b2 | 10 | { |
adelino | 1:a74e42cf52b2 | 11 | |
adelino | 1:a74e42cf52b2 | 12 | |
adelino | 1:a74e42cf52b2 | 13 | for(int i=0; i<myVectorObjet.size(); i++) { |
adelino | 1:a74e42cf52b2 | 14 | delete myVectorObjet[i]; |
adelino | 1:a74e42cf52b2 | 15 | myVectorObjet[i]=0; |
adelino | 1:a74e42cf52b2 | 16 | } |
adelino | 1:a74e42cf52b2 | 17 | } |
adelino | 1:a74e42cf52b2 | 18 | //------------------------------------ |
adelino | 1:a74e42cf52b2 | 19 | UINT16 Screen::getXpos(void) const |
adelino | 1:a74e42cf52b2 | 20 | { |
adelino | 1:a74e42cf52b2 | 21 | return this->myXpos; |
adelino | 1:a74e42cf52b2 | 22 | } |
adelino | 1:a74e42cf52b2 | 23 | //---------------------------------- |
adelino | 1:a74e42cf52b2 | 24 | UINT16 Screen::getYpos(void) const |
adelino | 1:a74e42cf52b2 | 25 | { |
adelino | 1:a74e42cf52b2 | 26 | return this->myYpos; |
adelino | 1:a74e42cf52b2 | 27 | } |
adelino | 1:a74e42cf52b2 | 28 | //------------------------------------ |
adelino | 1:a74e42cf52b2 | 29 | UINT16 Screen::getWidth(void) const |
adelino | 1:a74e42cf52b2 | 30 | { |
adelino | 1:a74e42cf52b2 | 31 | return this->myWidth; |
adelino | 1:a74e42cf52b2 | 32 | } |
adelino | 1:a74e42cf52b2 | 33 | //------------------------------------- |
adelino | 1:a74e42cf52b2 | 34 | UINT16 Screen::getHeight(void) const |
adelino | 1:a74e42cf52b2 | 35 | { |
adelino | 1:a74e42cf52b2 | 36 | return this->myHeight; |
adelino | 1:a74e42cf52b2 | 37 | } |
adelino | 1:a74e42cf52b2 | 38 | //------------------------------------ |
adelino | 1:a74e42cf52b2 | 39 | void Screen::drawWidget(Widget* pObj) |
adelino | 1:a74e42cf52b2 | 40 | { |
adelino | 1:a74e42cf52b2 | 41 | pObj->draw(); |
adelino | 1:a74e42cf52b2 | 42 | |
adelino | 1:a74e42cf52b2 | 43 | } |
adelino | 1:a74e42cf52b2 | 44 | //------------------------------------ |
adelino | 1:a74e42cf52b2 | 45 | void Screen::drawAllWidget(void) |
adelino | 1:a74e42cf52b2 | 46 | { |
adelino | 1:a74e42cf52b2 | 47 | mySerial->draw_filled_rectangle(myXpos,myYpos,myXpos+myWidth,myYpos+myHeight,myColorBkg); |
adelino | 1:a74e42cf52b2 | 48 | |
adelino | 1:a74e42cf52b2 | 49 | // |
adelino | 1:a74e42cf52b2 | 50 | for(int i=0; i<myVectorObjet.size(); i++) { |
adelino | 1:a74e42cf52b2 | 51 | drawWidget(myVectorObjet[i]); |
adelino | 1:a74e42cf52b2 | 52 | } |
adelino | 1:a74e42cf52b2 | 53 | } |
adelino | 1:a74e42cf52b2 | 54 | //------------------------------------- |
adelino | 1:a74e42cf52b2 | 55 | void Screen::addWidget(Widget* pObj) |
adelino | 1:a74e42cf52b2 | 56 | { |
adelino | 1:a74e42cf52b2 | 57 | myVectorObjet.push_back(pObj); |
adelino | 1:a74e42cf52b2 | 58 | } |
adelino | 1:a74e42cf52b2 | 59 | //--------------------------------------- |
adelino | 1:a74e42cf52b2 | 60 | PicasoSerial* Screen::getPicasoSerial(void) const |
adelino | 1:a74e42cf52b2 | 61 | { |
adelino | 1:a74e42cf52b2 | 62 | return mySerial; |
adelino | 1:a74e42cf52b2 | 63 | } |
adelino | 1:a74e42cf52b2 | 64 | //--------------------------------------- |
adelino | 1:a74e42cf52b2 | 65 | Color Screen::getColorBkg(void) const |
adelino | 1:a74e42cf52b2 | 66 | { |
adelino | 1:a74e42cf52b2 | 67 | return myColorBkg; |
adelino | 1:a74e42cf52b2 | 68 | } |
adelino | 1:a74e42cf52b2 | 69 | //-------------------------------------- |
adelino | 1:a74e42cf52b2 | 70 | bool Screen::isContent(Widget* pObj, UINT16 _x,UINT16 _y) |
adelino | 1:a74e42cf52b2 | 71 | { |
adelino | 1:a74e42cf52b2 | 72 | UINT16 xd=pObj->getXposition(); |
adelino | 1:a74e42cf52b2 | 73 | UINT16 w=pObj->getWidth(); |
adelino | 1:a74e42cf52b2 | 74 | UINT16 xf=xd+w; |
adelino | 1:a74e42cf52b2 | 75 | |
adelino | 1:a74e42cf52b2 | 76 | UINT16 yd=pObj->getYposition(); |
adelino | 1:a74e42cf52b2 | 77 | UINT16 h=pObj->getHeight(); |
adelino | 1:a74e42cf52b2 | 78 | UINT16 yf=yd+h; |
adelino | 1:a74e42cf52b2 | 79 | |
adelino | 1:a74e42cf52b2 | 80 | if(_x >= xd && _x<= xf && _y>=yd && _y<= yf) { |
adelino | 1:a74e42cf52b2 | 81 | return true; |
adelino | 1:a74e42cf52b2 | 82 | } |
adelino | 1:a74e42cf52b2 | 83 | |
adelino | 1:a74e42cf52b2 | 84 | return false; |
adelino | 1:a74e42cf52b2 | 85 | |
adelino | 1:a74e42cf52b2 | 86 | } |
adelino | 1:a74e42cf52b2 | 87 | //------------------------------------- |
adelino | 1:a74e42cf52b2 | 88 | Widget* Screen::getWidgetPosition(UINT16 _x,UINT16 _y) |
adelino | 1:a74e42cf52b2 | 89 | { |
adelino | 1:a74e42cf52b2 | 90 | |
adelino | 1:a74e42cf52b2 | 91 | if(myVectorObjet.size()==0) |
adelino | 1:a74e42cf52b2 | 92 | return NULL; |
adelino | 1:a74e42cf52b2 | 93 | |
adelino | 1:a74e42cf52b2 | 94 | // |
adelino | 1:a74e42cf52b2 | 95 | for(int i=0; i<myVectorObjet.size(); i++) { |
adelino | 1:a74e42cf52b2 | 96 | if(isContent(myVectorObjet[i],_x,_y)) |
adelino | 1:a74e42cf52b2 | 97 | return myVectorObjet[i]; |
adelino | 1:a74e42cf52b2 | 98 | } |
adelino | 1:a74e42cf52b2 | 99 | return NULL; |
adelino | 1:a74e42cf52b2 | 100 | } |
adelino | 1:a74e42cf52b2 | 101 | //------------------------------------- |
adelino | 1:a74e42cf52b2 | 102 | Widget* Screen::getWidgetById(UINT16 _id) |
adelino | 1:a74e42cf52b2 | 103 | { |
adelino | 1:a74e42cf52b2 | 104 | if(myVectorObjet.size()==0) |
adelino | 1:a74e42cf52b2 | 105 | return NULL; |
adelino | 1:a74e42cf52b2 | 106 | |
adelino | 1:a74e42cf52b2 | 107 | // |
adelino | 1:a74e42cf52b2 | 108 | for(int i=0; i<myVectorObjet.size(); i++) { |
adelino | 1:a74e42cf52b2 | 109 | if((myVectorObjet[i]->getId())== _id) |
adelino | 1:a74e42cf52b2 | 110 | return myVectorObjet[i]; |
adelino | 1:a74e42cf52b2 | 111 | } |
adelino | 1:a74e42cf52b2 | 112 | return NULL; |
adelino | 1:a74e42cf52b2 | 113 | |
adelino | 1:a74e42cf52b2 | 114 | } |
adelino | 1:a74e42cf52b2 | 115 | //------------------------------------- |
adelino | 1:a74e42cf52b2 | 116 | TouchEvent Screen::getTouchEvent(GraphicMessage* msg) |
adelino | 1:a74e42cf52b2 | 117 | { |
adelino | 1:a74e42cf52b2 | 118 | TouchEvent ev=EVENT_NO_ACTIVITY; |
adelino | 1:a74e42cf52b2 | 119 | UINT16 xp=0; |
adelino | 1:a74e42cf52b2 | 120 | UINT16 yp=0; |
adelino | 1:a74e42cf52b2 | 121 | |
adelino | 1:a74e42cf52b2 | 122 | ev=mySerial->touch_get_status(); |
adelino | 1:a74e42cf52b2 | 123 | |
adelino | 1:a74e42cf52b2 | 124 | // |
adelino | 1:a74e42cf52b2 | 125 | if(ev >EVENT_NO_ACTIVITY) { |
adelino | 1:a74e42cf52b2 | 126 | xp=mySerial->touch_get_x(); |
adelino | 1:a74e42cf52b2 | 127 | yp=mySerial->touch_get_y(); |
adelino | 1:a74e42cf52b2 | 128 | |
adelino | 1:a74e42cf52b2 | 129 | msg->event=ev; |
adelino | 1:a74e42cf52b2 | 130 | msg->posiX=xp; |
adelino | 1:a74e42cf52b2 | 131 | msg->posiY=yp; |
adelino | 1:a74e42cf52b2 | 132 | msg->objId=0; |
adelino | 1:a74e42cf52b2 | 133 | |
adelino | 1:a74e42cf52b2 | 134 | return ev; |
adelino | 1:a74e42cf52b2 | 135 | } else { |
adelino | 1:a74e42cf52b2 | 136 | |
adelino | 1:a74e42cf52b2 | 137 | msg->event=EVENT_NO_ACTIVITY; |
adelino | 1:a74e42cf52b2 | 138 | msg->posiX=0; |
adelino | 1:a74e42cf52b2 | 139 | msg->posiY=0; |
adelino | 1:a74e42cf52b2 | 140 | msg->objId=0; |
adelino | 1:a74e42cf52b2 | 141 | } |
adelino | 1:a74e42cf52b2 | 142 | // |
adelino | 1:a74e42cf52b2 | 143 | return ev; |
adelino | 1:a74e42cf52b2 | 144 | } |
adelino | 1:a74e42cf52b2 | 145 | //------------------------------------- |
adelino | 1:a74e42cf52b2 | 146 | void Screen::getProcessMessage(GraphicMessage* msg) |
adelino | 1:a74e42cf52b2 | 147 | { |
adelino | 1:a74e42cf52b2 | 148 | UINT16 xt=msg->posiX; |
adelino | 1:a74e42cf52b2 | 149 | UINT16 yt=msg->posiY; |
adelino | 1:a74e42cf52b2 | 150 | UINT16 res=0; |
adelino | 1:a74e42cf52b2 | 151 | |
adelino | 1:a74e42cf52b2 | 152 | Widget* obj=NULL; |
adelino | 1:a74e42cf52b2 | 153 | |
adelino | 1:a74e42cf52b2 | 154 | obj=getWidgetPosition(xt,yt); |
adelino | 1:a74e42cf52b2 | 155 | |
adelino | 1:a74e42cf52b2 | 156 | if(obj!=NULL && obj->getIsVisible()==true) { |
adelino | 1:a74e42cf52b2 | 157 | res=obj->getId(); |
adelino | 1:a74e42cf52b2 | 158 | msg->objId=res; |
adelino | 1:a74e42cf52b2 | 159 | } else { |
adelino | 1:a74e42cf52b2 | 160 | msg->objId=0; |
adelino | 1:a74e42cf52b2 | 161 | } |
adelino | 1:a74e42cf52b2 | 162 | |
adelino | 1:a74e42cf52b2 | 163 | } |
adelino | 1:a74e42cf52b2 | 164 | //------------------------------------ |
adelino | 1:a74e42cf52b2 | 165 | void Screen::setClear() |
adelino | 1:a74e42cf52b2 | 166 | { |
adelino | 1:a74e42cf52b2 | 167 | mySerial->draw_filled_rectangle(myXpos,myYpos,myXpos+myWidth,myYpos+myHeight,myColorBkg); |
adelino | 1:a74e42cf52b2 | 168 | } |
adelino | 1:a74e42cf52b2 | 169 | /////////////////////////////////////// |
adelino | 1:a74e42cf52b2 | 170 | |
adelino | 1:a74e42cf52b2 | 171 | Widget::Widget(Screen* mScreen,UINT16 _id,UINT16 _x,UINT16 _y,UINT16 _w,UINT16 _h,Color _color): |
adelino | 1:a74e42cf52b2 | 172 | myScreen(mScreen),myId(_id),myX(_x),myY(_y),myWidth(_w),myHeight(_h),myColor(_color) |
adelino | 1:a74e42cf52b2 | 173 | { |
adelino | 1:a74e42cf52b2 | 174 | |
adelino | 1:a74e42cf52b2 | 175 | myState=STATE_ON; |
adelino | 1:a74e42cf52b2 | 176 | myIsVisible=true; |
adelino | 1:a74e42cf52b2 | 177 | } |
adelino | 1:a74e42cf52b2 | 178 | //------------------------------------- |
adelino | 1:a74e42cf52b2 | 179 | Widget::~Widget(void) |
adelino | 1:a74e42cf52b2 | 180 | { |
adelino | 1:a74e42cf52b2 | 181 | } |
adelino | 1:a74e42cf52b2 | 182 | //------------------------------------- |
adelino | 1:a74e42cf52b2 | 183 | //------------------------------------- |
adelino | 1:a74e42cf52b2 | 184 | void Widget::draw(void) |
adelino | 1:a74e42cf52b2 | 185 | { |
adelino | 1:a74e42cf52b2 | 186 | //to do |
adelino | 1:a74e42cf52b2 | 187 | } |
adelino | 1:a74e42cf52b2 | 188 | //------------------------------------- |
adelino | 1:a74e42cf52b2 | 189 | UINT16 Widget::getXposition(void) const |
adelino | 1:a74e42cf52b2 | 190 | { |
adelino | 1:a74e42cf52b2 | 191 | return this->myX; |
adelino | 1:a74e42cf52b2 | 192 | } |
adelino | 1:a74e42cf52b2 | 193 | //--------------------------------------- |
adelino | 1:a74e42cf52b2 | 194 | UINT16 Widget::getYposition(void) const |
adelino | 1:a74e42cf52b2 | 195 | { |
adelino | 1:a74e42cf52b2 | 196 | return this->myY; |
adelino | 1:a74e42cf52b2 | 197 | } |
adelino | 1:a74e42cf52b2 | 198 | //---------------------------------------- |
adelino | 1:a74e42cf52b2 | 199 | UINT16 Widget::getWidth(void) const |
adelino | 1:a74e42cf52b2 | 200 | { |
adelino | 1:a74e42cf52b2 | 201 | return this->myWidth; |
adelino | 1:a74e42cf52b2 | 202 | } |
adelino | 1:a74e42cf52b2 | 203 | //---------------------------------------- |
adelino | 1:a74e42cf52b2 | 204 | UINT16 Widget::getHeight(void) const |
adelino | 1:a74e42cf52b2 | 205 | { |
adelino | 1:a74e42cf52b2 | 206 | return this->myHeight; |
adelino | 1:a74e42cf52b2 | 207 | } |
adelino | 1:a74e42cf52b2 | 208 | //---------------------------------------- |
adelino | 1:a74e42cf52b2 | 209 | UINT16 Widget::getId(void) const |
adelino | 1:a74e42cf52b2 | 210 | { |
adelino | 1:a74e42cf52b2 | 211 | return this->myId; |
adelino | 1:a74e42cf52b2 | 212 | } |
adelino | 1:a74e42cf52b2 | 213 | //---------------------------------------- |
adelino | 1:a74e42cf52b2 | 214 | WIDGET_TYPE Widget::getType(void) const |
adelino | 1:a74e42cf52b2 | 215 | { |
adelino | 1:a74e42cf52b2 | 216 | return this->myType; |
adelino | 1:a74e42cf52b2 | 217 | } |
adelino | 1:a74e42cf52b2 | 218 | //---------------------------------------- |
adelino | 1:a74e42cf52b2 | 219 | bool Widget::getIsVisible(void) const |
adelino | 1:a74e42cf52b2 | 220 | { |
adelino | 1:a74e42cf52b2 | 221 | return this->myIsVisible; |
adelino | 1:a74e42cf52b2 | 222 | } |
adelino | 1:a74e42cf52b2 | 223 | //---------------------------------------- |
adelino | 1:a74e42cf52b2 | 224 | Color Widget::getColor(void) const |
adelino | 1:a74e42cf52b2 | 225 | { |
adelino | 1:a74e42cf52b2 | 226 | return myColor; |
adelino | 1:a74e42cf52b2 | 227 | } |
adelino | 1:a74e42cf52b2 | 228 | //---------------------------------------- |
adelino | 1:a74e42cf52b2 | 229 | void Widget::setVisibility(bool _val) |
adelino | 1:a74e42cf52b2 | 230 | { |
adelino | 1:a74e42cf52b2 | 231 | (this->myIsVisible)=_val; |
adelino | 1:a74e42cf52b2 | 232 | } |
adelino | 1:a74e42cf52b2 | 233 | //---------------------------------------- |
adelino | 1:a74e42cf52b2 | 234 | State Widget::getState(void) const |
adelino | 1:a74e42cf52b2 | 235 | { |
adelino | 1:a74e42cf52b2 | 236 | return this->myState; |
adelino | 1:a74e42cf52b2 | 237 | } |
adelino | 1:a74e42cf52b2 | 238 | //------------------------------------------ |
adelino | 1:a74e42cf52b2 | 239 | void Widget::setColor(Color _color) |
adelino | 1:a74e42cf52b2 | 240 | { |
adelino | 1:a74e42cf52b2 | 241 | myColor=_color; |
adelino | 1:a74e42cf52b2 | 242 | } |
adelino | 1:a74e42cf52b2 | 243 | //------------------------------------------ |
adelino | 1:a74e42cf52b2 | 244 | void Widget::setState(State _state) |
adelino | 1:a74e42cf52b2 | 245 | { |
adelino | 1:a74e42cf52b2 | 246 | myState=_state; |
adelino | 1:a74e42cf52b2 | 247 | } |
adelino | 1:a74e42cf52b2 | 248 | //------------------------------------------ |
adelino | 1:a74e42cf52b2 | 249 | void Widget::setId(UINT16 _id) |
adelino | 1:a74e42cf52b2 | 250 | { |
adelino | 1:a74e42cf52b2 | 251 | myId=_id; |
adelino | 1:a74e42cf52b2 | 252 | } |
adelino | 1:a74e42cf52b2 | 253 | //------------------------------------------ |
adelino | 1:a74e42cf52b2 | 254 | void Widget::setXposition(UINT16 _xpos) |
adelino | 1:a74e42cf52b2 | 255 | { |
adelino | 1:a74e42cf52b2 | 256 | this->myX=_xpos; |
adelino | 1:a74e42cf52b2 | 257 | } |
adelino | 1:a74e42cf52b2 | 258 | //------------------------------------------ |
adelino | 1:a74e42cf52b2 | 259 | void Widget::setYposition(UINT16 _ypos) |
adelino | 1:a74e42cf52b2 | 260 | { |
adelino | 1:a74e42cf52b2 | 261 | this->myY=_ypos; |
adelino | 1:a74e42cf52b2 | 262 | } |
adelino | 1:a74e42cf52b2 | 263 | //---------------------------------------- |
adelino | 1:a74e42cf52b2 | 264 |