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