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/
Circle.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 "Circle.h" |
adelino | 1:a74e42cf52b2 | 2 | |
adelino | 1:a74e42cf52b2 | 3 | Circle::Circle(Screen* mScreen,UINT16 _xc,UINT16 _yc,UINT16 _radius,Color _color): |
adelino | 1:a74e42cf52b2 | 4 | Sprite(mScreen,0,_xc-_radius,_yc-_radius,_radius+_radius,_radius+_radius,_color) |
adelino | 1:a74e42cf52b2 | 5 | { |
adelino | 1:a74e42cf52b2 | 6 | myRadius=_radius; |
adelino | 1:a74e42cf52b2 | 7 | myCenterX=_xc; |
adelino | 1:a74e42cf52b2 | 8 | myCenterY=_yc; |
adelino | 1:a74e42cf52b2 | 9 | myType=OBJ_CIRCLE; |
adelino | 1:a74e42cf52b2 | 10 | |
adelino | 1:a74e42cf52b2 | 11 | myScreen->addWidget((Widget*) this); |
adelino | 1:a74e42cf52b2 | 12 | |
adelino | 1:a74e42cf52b2 | 13 | } |
adelino | 1:a74e42cf52b2 | 14 | //----------------------------------------- |
adelino | 1:a74e42cf52b2 | 15 | Circle::~Circle(void) |
adelino | 1:a74e42cf52b2 | 16 | { |
adelino | 1:a74e42cf52b2 | 17 | } |
adelino | 1:a74e42cf52b2 | 18 | //------------------------------------------ |
adelino | 1:a74e42cf52b2 | 19 | void Circle::draw(void) |
adelino | 1:a74e42cf52b2 | 20 | { |
adelino | 1:a74e42cf52b2 | 21 | // isVisible ? |
adelino | 1:a74e42cf52b2 | 22 | if(myIsVisible==false) { |
adelino | 1:a74e42cf52b2 | 23 | return; |
adelino | 1:a74e42cf52b2 | 24 | } |
adelino | 1:a74e42cf52b2 | 25 | // |
adelino | 1:a74e42cf52b2 | 26 | PicasoSerial* ps=0; |
adelino | 1:a74e42cf52b2 | 27 | ps=myScreen->getPicasoSerial(); |
adelino | 1:a74e42cf52b2 | 28 | |
adelino | 1:a74e42cf52b2 | 29 | if(ps!=0) { |
adelino | 1:a74e42cf52b2 | 30 | ps->draw_filled_circle(myCenterX,myCenterY,myRadius,myColor); |
adelino | 1:a74e42cf52b2 | 31 | } |
adelino | 1:a74e42cf52b2 | 32 | ps=0; |
adelino | 1:a74e42cf52b2 | 33 | } |
adelino | 1:a74e42cf52b2 | 34 | //------------------------------------------ |
adelino | 1:a74e42cf52b2 | 35 | void Circle::setCenterX(UINT16 _xcenter) |
adelino | 1:a74e42cf52b2 | 36 | { |
adelino | 1:a74e42cf52b2 | 37 | this->myCenterX=_xcenter; |
adelino | 1:a74e42cf52b2 | 38 | } |
adelino | 1:a74e42cf52b2 | 39 | //------------------------------------------ |
adelino | 1:a74e42cf52b2 | 40 | void Circle::setCenterY(UINT16 _ycenter) |
adelino | 1:a74e42cf52b2 | 41 | { |
adelino | 1:a74e42cf52b2 | 42 | this->myCenterY=_ycenter; |
adelino | 1:a74e42cf52b2 | 43 | } |
adelino | 1:a74e42cf52b2 | 44 | //------------------------------------------ |
adelino | 1:a74e42cf52b2 | 45 | UINT16 Circle::getCenterX(void) const |
adelino | 1:a74e42cf52b2 | 46 | { |
adelino | 1:a74e42cf52b2 | 47 | return this->myCenterX; |
adelino | 1:a74e42cf52b2 | 48 | } |
adelino | 1:a74e42cf52b2 | 49 | //------------------------------------------- |
adelino | 1:a74e42cf52b2 | 50 | UINT16 Circle::getCenterY(void) const |
adelino | 1:a74e42cf52b2 | 51 | { |
adelino | 1:a74e42cf52b2 | 52 | return this->myCenterY; |
adelino | 1:a74e42cf52b2 | 53 | } |
adelino | 1:a74e42cf52b2 | 54 | //-------------------------------------------- |
adelino | 1:a74e42cf52b2 | 55 | void Circle::setInvisible(bool _state) |
adelino | 1:a74e42cf52b2 | 56 | { |
adelino | 1:a74e42cf52b2 | 57 | // element devient invisible |
adelino | 1:a74e42cf52b2 | 58 | if(_state==true) { |
adelino | 1:a74e42cf52b2 | 59 | if(myIsVisible==false) |
adelino | 1:a74e42cf52b2 | 60 | return; |
adelino | 1:a74e42cf52b2 | 61 | |
adelino | 1:a74e42cf52b2 | 62 | myIsVisible=false; |
adelino | 1:a74e42cf52b2 | 63 | |
adelino | 1:a74e42cf52b2 | 64 | Color c= myScreen->getColorBkg(); |
adelino | 1:a74e42cf52b2 | 65 | |
adelino | 1:a74e42cf52b2 | 66 | PicasoSerial* ps=0; |
adelino | 1:a74e42cf52b2 | 67 | ps=myScreen->getPicasoSerial(); |
adelino | 1:a74e42cf52b2 | 68 | |
adelino | 1:a74e42cf52b2 | 69 | if(ps!=0) { |
adelino | 1:a74e42cf52b2 | 70 | ps->draw_filled_circle(myCenterX,myCenterY,myRadius,c); |
adelino | 1:a74e42cf52b2 | 71 | } |
adelino | 1:a74e42cf52b2 | 72 | ps=0; |
adelino | 1:a74e42cf52b2 | 73 | } |
adelino | 1:a74e42cf52b2 | 74 | |
adelino | 1:a74e42cf52b2 | 75 | // element devient visible |
adelino | 1:a74e42cf52b2 | 76 | else { |
adelino | 1:a74e42cf52b2 | 77 | myIsVisible=true; |
adelino | 1:a74e42cf52b2 | 78 | |
adelino | 1:a74e42cf52b2 | 79 | |
adelino | 1:a74e42cf52b2 | 80 | this->draw(); |
adelino | 1:a74e42cf52b2 | 81 | } |
adelino | 1:a74e42cf52b2 | 82 | } |
adelino | 1:a74e42cf52b2 | 83 | //---------------------------------------------- |
adelino | 1:a74e42cf52b2 | 84 | void Circle::setNewPosition(INT16 _xcnew,INT16 _ycnew) |
adelino | 1:a74e42cf52b2 | 85 | { |
adelino | 1:a74e42cf52b2 | 86 | setNewPosition(_xcnew,_ycnew,true); |
adelino | 1:a74e42cf52b2 | 87 | } |
adelino | 1:a74e42cf52b2 | 88 | //--------------------------------------------- |
adelino | 1:a74e42cf52b2 | 89 | void Circle::setNewPosition(INT16 _xcnew,INT16 _ycnew,bool isScreenLimits) |
adelino | 1:a74e42cf52b2 | 90 | { |
adelino | 1:a74e42cf52b2 | 91 | if(myIsVisible==false) |
adelino | 1:a74e42cf52b2 | 92 | return; |
adelino | 1:a74e42cf52b2 | 93 | // |
adelino | 1:a74e42cf52b2 | 94 | if(myCenterX==_xcnew && myCenterY==_ycnew) |
adelino | 1:a74e42cf52b2 | 95 | return; |
adelino | 1:a74e42cf52b2 | 96 | // |
adelino | 1:a74e42cf52b2 | 97 | this->setInvisible(true); // colorie le cir avec couleur de la screen |
adelino | 1:a74e42cf52b2 | 98 | |
adelino | 1:a74e42cf52b2 | 99 | myIsVisible=true; |
adelino | 1:a74e42cf52b2 | 100 | |
adelino | 1:a74e42cf52b2 | 101 | if(isScreenLimits) { |
adelino | 1:a74e42cf52b2 | 102 | |
adelino | 1:a74e42cf52b2 | 103 | //test Xmax |
adelino | 1:a74e42cf52b2 | 104 | if(_xcnew+myRadius >= myXMoveMax) { |
adelino | 1:a74e42cf52b2 | 105 | _xcnew=myXMoveMax-myRadius; |
adelino | 1:a74e42cf52b2 | 106 | |
adelino | 1:a74e42cf52b2 | 107 | if(myState==STATE_ON) |
adelino | 1:a74e42cf52b2 | 108 | myState=BUMP_RIGHT; |
adelino | 1:a74e42cf52b2 | 109 | } |
adelino | 1:a74e42cf52b2 | 110 | |
adelino | 1:a74e42cf52b2 | 111 | //test Xmin |
adelino | 1:a74e42cf52b2 | 112 | if(_xcnew <= myRadius) { |
adelino | 1:a74e42cf52b2 | 113 | _xcnew=myXMoveMin+myRadius; |
adelino | 1:a74e42cf52b2 | 114 | |
adelino | 1:a74e42cf52b2 | 115 | if(myState==STATE_ON) |
adelino | 1:a74e42cf52b2 | 116 | myState=BUMP_LEFT; |
adelino | 1:a74e42cf52b2 | 117 | } |
adelino | 1:a74e42cf52b2 | 118 | //test Ymax |
adelino | 1:a74e42cf52b2 | 119 | if(_ycnew +myRadius >= myYMoveMax && _ycnew >0) { |
adelino | 1:a74e42cf52b2 | 120 | _ycnew = myYMoveMax- myRadius; |
adelino | 1:a74e42cf52b2 | 121 | |
adelino | 1:a74e42cf52b2 | 122 | if(myState==STATE_ON) |
adelino | 1:a74e42cf52b2 | 123 | myState=BUMP_DOWN; |
adelino | 1:a74e42cf52b2 | 124 | } |
adelino | 1:a74e42cf52b2 | 125 | //test yminMin; |
adelino | 1:a74e42cf52b2 | 126 | if(_ycnew <= myRadius) { |
adelino | 1:a74e42cf52b2 | 127 | _ycnew=myYMoveMin+myRadius; |
adelino | 1:a74e42cf52b2 | 128 | |
adelino | 1:a74e42cf52b2 | 129 | if(myState==STATE_ON) |
adelino | 1:a74e42cf52b2 | 130 | myState=BUMP_UP; |
adelino | 1:a74e42cf52b2 | 131 | } |
adelino | 1:a74e42cf52b2 | 132 | } |
adelino | 1:a74e42cf52b2 | 133 | // |
adelino | 1:a74e42cf52b2 | 134 | myCenterX=_xcnew; |
adelino | 1:a74e42cf52b2 | 135 | myCenterY=_ycnew; |
adelino | 1:a74e42cf52b2 | 136 | |
adelino | 1:a74e42cf52b2 | 137 | myX=_xcnew-myRadius; |
adelino | 1:a74e42cf52b2 | 138 | myY=_ycnew-myRadius; |
adelino | 1:a74e42cf52b2 | 139 | |
adelino | 1:a74e42cf52b2 | 140 | |
adelino | 1:a74e42cf52b2 | 141 | this->draw(); |
adelino | 1:a74e42cf52b2 | 142 | } |
adelino | 1:a74e42cf52b2 | 143 | //---------------------------------------------- |
adelino | 1:a74e42cf52b2 | 144 | void Circle::update(float delta) |
adelino | 1:a74e42cf52b2 | 145 | { |
adelino | 1:a74e42cf52b2 | 146 | if(myIsUpdateAutomatic) |
adelino | 1:a74e42cf52b2 | 147 | elementUpdate(); |
adelino | 1:a74e42cf52b2 | 148 | |
adelino | 1:a74e42cf52b2 | 149 | float xcnew=myCenterX+mySpeedX*delta; |
adelino | 1:a74e42cf52b2 | 150 | float ycnew=myCenterY+mySpeedY*delta; |
adelino | 1:a74e42cf52b2 | 151 | |
adelino | 1:a74e42cf52b2 | 152 | this->setNewPosition((INT16)xcnew,(INT16)ycnew,true); |
adelino | 1:a74e42cf52b2 | 153 | |
adelino | 1:a74e42cf52b2 | 154 | } |