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/
Rectangle.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 "Rectangle.h" |
adelino | 1:a74e42cf52b2 | 2 | |
adelino | 1:a74e42cf52b2 | 3 | |
adelino | 1:a74e42cf52b2 | 4 | Rectangle::Rectangle(Screen* mScreen,UINT16 _x,UINT16 _y,UINT16 _w,UINT16 _h,Color _color): |
adelino | 1:a74e42cf52b2 | 5 | Sprite(mScreen,0,_x,_y,_w,_h,_color) |
adelino | 1:a74e42cf52b2 | 6 | |
adelino | 1:a74e42cf52b2 | 7 | { |
adelino | 1:a74e42cf52b2 | 8 | myType=OBJ_RECTANGLE; |
adelino | 1:a74e42cf52b2 | 9 | |
adelino | 1:a74e42cf52b2 | 10 | myScreen->addWidget((Widget*) this); |
adelino | 1:a74e42cf52b2 | 11 | } |
adelino | 1:a74e42cf52b2 | 12 | //------------------------------------ |
adelino | 1:a74e42cf52b2 | 13 | Rectangle::~Rectangle(void) |
adelino | 1:a74e42cf52b2 | 14 | { |
adelino | 1:a74e42cf52b2 | 15 | |
adelino | 1:a74e42cf52b2 | 16 | } |
adelino | 1:a74e42cf52b2 | 17 | //------------------------------------ |
adelino | 1:a74e42cf52b2 | 18 | void Rectangle::draw(void) |
adelino | 1:a74e42cf52b2 | 19 | { |
adelino | 1:a74e42cf52b2 | 20 | // isVisible ? |
adelino | 1:a74e42cf52b2 | 21 | if(myIsVisible==false) { |
adelino | 1:a74e42cf52b2 | 22 | return; |
adelino | 1:a74e42cf52b2 | 23 | } |
adelino | 1:a74e42cf52b2 | 24 | // |
adelino | 1:a74e42cf52b2 | 25 | PicasoSerial* ps=0; |
adelino | 1:a74e42cf52b2 | 26 | ps=myScreen->getPicasoSerial(); |
adelino | 1:a74e42cf52b2 | 27 | |
adelino | 1:a74e42cf52b2 | 28 | if(ps!=0) { |
adelino | 1:a74e42cf52b2 | 29 | ps->draw_filled_rectangle(myX,myY,myX+myWidth,myY+myHeight,myColor); |
adelino | 1:a74e42cf52b2 | 30 | } |
adelino | 1:a74e42cf52b2 | 31 | } |
adelino | 1:a74e42cf52b2 | 32 | //------------------------------------- |
adelino | 1:a74e42cf52b2 | 33 | void Rectangle::setInvisible(bool _state) |
adelino | 1:a74e42cf52b2 | 34 | { |
adelino | 1:a74e42cf52b2 | 35 | // element devient invisible |
adelino | 1:a74e42cf52b2 | 36 | if(_state==true) { |
adelino | 1:a74e42cf52b2 | 37 | if(myIsVisible==false) |
adelino | 1:a74e42cf52b2 | 38 | return; |
adelino | 1:a74e42cf52b2 | 39 | |
adelino | 1:a74e42cf52b2 | 40 | myIsVisible=false; |
adelino | 1:a74e42cf52b2 | 41 | |
adelino | 1:a74e42cf52b2 | 42 | Color c= myScreen->getColorBkg(); |
adelino | 1:a74e42cf52b2 | 43 | |
adelino | 1:a74e42cf52b2 | 44 | PicasoSerial* ps=0; |
adelino | 1:a74e42cf52b2 | 45 | ps=myScreen->getPicasoSerial(); |
adelino | 1:a74e42cf52b2 | 46 | |
adelino | 1:a74e42cf52b2 | 47 | if(ps!=0) { |
adelino | 1:a74e42cf52b2 | 48 | ps->draw_filled_rectangle(myX,myY,myX+myWidth,myY+myHeight,c); |
adelino | 1:a74e42cf52b2 | 49 | } |
adelino | 1:a74e42cf52b2 | 50 | } |
adelino | 1:a74e42cf52b2 | 51 | |
adelino | 1:a74e42cf52b2 | 52 | // element devient visible |
adelino | 1:a74e42cf52b2 | 53 | else { |
adelino | 1:a74e42cf52b2 | 54 | myIsVisible=true; |
adelino | 1:a74e42cf52b2 | 55 | |
adelino | 1:a74e42cf52b2 | 56 | this->draw(); |
adelino | 1:a74e42cf52b2 | 57 | } |
adelino | 1:a74e42cf52b2 | 58 | } |
adelino | 1:a74e42cf52b2 | 59 | //-------------------------------------- |
adelino | 1:a74e42cf52b2 | 60 | void Rectangle::setNewPosition(INT16 _xnew,INT16 _ynew) |
adelino | 1:a74e42cf52b2 | 61 | { |
adelino | 1:a74e42cf52b2 | 62 | setNewPosition(_xnew,_ynew,true); |
adelino | 1:a74e42cf52b2 | 63 | } |
adelino | 1:a74e42cf52b2 | 64 | //-------------------------------------- |
adelino | 1:a74e42cf52b2 | 65 | void Rectangle::setNewPosition(INT16 _xnew,INT16 _ynew,bool isScreenLimits) |
adelino | 1:a74e42cf52b2 | 66 | { |
adelino | 1:a74e42cf52b2 | 67 | if(myIsVisible==false) |
adelino | 1:a74e42cf52b2 | 68 | return; |
adelino | 1:a74e42cf52b2 | 69 | |
adelino | 1:a74e42cf52b2 | 70 | // |
adelino | 1:a74e42cf52b2 | 71 | if(myX==_xnew && myY==_ynew) |
adelino | 1:a74e42cf52b2 | 72 | return; |
adelino | 1:a74e42cf52b2 | 73 | |
adelino | 1:a74e42cf52b2 | 74 | setInvisible(true); // colorie le rec avec couleur de la screen |
adelino | 1:a74e42cf52b2 | 75 | |
adelino | 1:a74e42cf52b2 | 76 | myIsVisible=true; |
adelino | 1:a74e42cf52b2 | 77 | |
adelino | 1:a74e42cf52b2 | 78 | if(isScreenLimits) { |
adelino | 1:a74e42cf52b2 | 79 | //test Xmax |
adelino | 1:a74e42cf52b2 | 80 | if(_xnew+myWidth >= myXMoveMax) { |
adelino | 1:a74e42cf52b2 | 81 | _xnew=myXMoveMax-myWidth; |
adelino | 1:a74e42cf52b2 | 82 | |
adelino | 1:a74e42cf52b2 | 83 | if(myState==STATE_ON) |
adelino | 1:a74e42cf52b2 | 84 | myState=BUMP_RIGHT; |
adelino | 1:a74e42cf52b2 | 85 | |
adelino | 1:a74e42cf52b2 | 86 | } |
adelino | 1:a74e42cf52b2 | 87 | |
adelino | 1:a74e42cf52b2 | 88 | //test Xmin |
adelino | 1:a74e42cf52b2 | 89 | if(_xnew <= myXMoveMin) { |
adelino | 1:a74e42cf52b2 | 90 | _xnew=myXMoveMin; |
adelino | 1:a74e42cf52b2 | 91 | |
adelino | 1:a74e42cf52b2 | 92 | if(myState==STATE_ON) |
adelino | 1:a74e42cf52b2 | 93 | myState=BUMP_LEFT; |
adelino | 1:a74e42cf52b2 | 94 | |
adelino | 1:a74e42cf52b2 | 95 | } |
adelino | 1:a74e42cf52b2 | 96 | //test Ymax |
adelino | 1:a74e42cf52b2 | 97 | if(_ynew +myHeight >= myYMoveMax && _ynew >0) { |
adelino | 1:a74e42cf52b2 | 98 | _ynew = myYMoveMax- myHeight; |
adelino | 1:a74e42cf52b2 | 99 | |
adelino | 1:a74e42cf52b2 | 100 | if(myState==STATE_ON) |
adelino | 1:a74e42cf52b2 | 101 | myState=BUMP_DOWN; |
adelino | 1:a74e42cf52b2 | 102 | } |
adelino | 1:a74e42cf52b2 | 103 | //test yminMin; |
adelino | 1:a74e42cf52b2 | 104 | if(_ynew <= myYMoveMin) { |
adelino | 1:a74e42cf52b2 | 105 | _ynew=myYMoveMin; |
adelino | 1:a74e42cf52b2 | 106 | |
adelino | 1:a74e42cf52b2 | 107 | if(myState==STATE_ON) |
adelino | 1:a74e42cf52b2 | 108 | myState=BUMP_UP; |
adelino | 1:a74e42cf52b2 | 109 | |
adelino | 1:a74e42cf52b2 | 110 | } |
adelino | 1:a74e42cf52b2 | 111 | } |
adelino | 1:a74e42cf52b2 | 112 | // |
adelino | 1:a74e42cf52b2 | 113 | myX=_xnew; |
adelino | 1:a74e42cf52b2 | 114 | myY=_ynew; |
adelino | 1:a74e42cf52b2 | 115 | |
adelino | 1:a74e42cf52b2 | 116 | |
adelino | 1:a74e42cf52b2 | 117 | this->draw(); |
adelino | 1:a74e42cf52b2 | 118 | } |
adelino | 1:a74e42cf52b2 | 119 | //-------------------------------------- |
adelino | 1:a74e42cf52b2 | 120 | void Rectangle::update(float delta) |
adelino | 1:a74e42cf52b2 | 121 | { |
adelino | 1:a74e42cf52b2 | 122 | if(myIsUpdateAutomatic) |
adelino | 1:a74e42cf52b2 | 123 | elementUpdate(); |
adelino | 1:a74e42cf52b2 | 124 | // |
adelino | 1:a74e42cf52b2 | 125 | float xnew=myX+mySpeedX*delta; |
adelino | 1:a74e42cf52b2 | 126 | float ynew=myY+mySpeedY*delta; |
adelino | 1:a74e42cf52b2 | 127 | |
adelino | 1:a74e42cf52b2 | 128 | this->setNewPosition((INT16)xnew,(INT16)ynew,true); |
adelino | 1:a74e42cf52b2 | 129 | |
adelino | 1:a74e42cf52b2 | 130 | } |