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