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/
Button.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 "Button.h" |
adelino | 1:a74e42cf52b2 | 2 | |
adelino | 1:a74e42cf52b2 | 3 | Button::Button(Screen* mScreen,UINT16 _id,UINT16 _x,UINT16 _y,string _text,Font _font, |
adelino | 1:a74e42cf52b2 | 4 | Color _colorText,Color _colorBtn,State _state): |
adelino | 1:a74e42cf52b2 | 5 | Widget(mScreen,_id,_x,_y,0,0,_colorBtn) |
adelino | 1:a74e42cf52b2 | 6 | |
adelino | 1:a74e42cf52b2 | 7 | { |
adelino | 1:a74e42cf52b2 | 8 | myText=_text; |
adelino | 1:a74e42cf52b2 | 9 | myFont=_font; |
adelino | 1:a74e42cf52b2 | 10 | myColorText=_colorText; |
adelino | 1:a74e42cf52b2 | 11 | |
adelino | 1:a74e42cf52b2 | 12 | myState=_state; |
adelino | 1:a74e42cf52b2 | 13 | myType=OBJ_BUTTON; |
adelino | 1:a74e42cf52b2 | 14 | |
adelino | 1:a74e42cf52b2 | 15 | // |
adelino | 1:a74e42cf52b2 | 16 | UINT16 largeur=0; |
adelino | 1:a74e42cf52b2 | 17 | UINT16 hauteur=16; |
adelino | 1:a74e42cf52b2 | 18 | UINT16 taille=0; |
adelino | 1:a74e42cf52b2 | 19 | UINT16 incLargeur=12; |
adelino | 1:a74e42cf52b2 | 20 | |
adelino | 1:a74e42cf52b2 | 21 | switch(_font) { |
adelino | 1:a74e42cf52b2 | 22 | // |
adelino | 1:a74e42cf52b2 | 23 | case FONT_2: |
adelino | 1:a74e42cf52b2 | 24 | incLargeur=8; |
adelino | 1:a74e42cf52b2 | 25 | hauteur=8; |
adelino | 1:a74e42cf52b2 | 26 | largeur=8; |
adelino | 1:a74e42cf52b2 | 27 | break; |
adelino | 1:a74e42cf52b2 | 28 | |
adelino | 1:a74e42cf52b2 | 29 | // |
adelino | 1:a74e42cf52b2 | 30 | case FONT_3: |
adelino | 1:a74e42cf52b2 | 31 | incLargeur=8; |
adelino | 1:a74e42cf52b2 | 32 | hauteur=12; |
adelino | 1:a74e42cf52b2 | 33 | largeur=8; |
adelino | 1:a74e42cf52b2 | 34 | break; |
adelino | 1:a74e42cf52b2 | 35 | // |
adelino | 1:a74e42cf52b2 | 36 | case FONT_1: |
adelino | 1:a74e42cf52b2 | 37 | incLargeur=5; |
adelino | 1:a74e42cf52b2 | 38 | hauteur=7; |
adelino | 1:a74e42cf52b2 | 39 | largeur=5; |
adelino | 1:a74e42cf52b2 | 40 | break; |
adelino | 1:a74e42cf52b2 | 41 | |
adelino | 1:a74e42cf52b2 | 42 | // |
adelino | 1:a74e42cf52b2 | 43 | default: |
adelino | 1:a74e42cf52b2 | 44 | incLargeur=12; |
adelino | 1:a74e42cf52b2 | 45 | hauteur=16; |
adelino | 1:a74e42cf52b2 | 46 | largeur=8; |
adelino | 1:a74e42cf52b2 | 47 | break; |
adelino | 1:a74e42cf52b2 | 48 | } |
adelino | 1:a74e42cf52b2 | 49 | |
adelino | 1:a74e42cf52b2 | 50 | //cherche taille |
adelino | 1:a74e42cf52b2 | 51 | |
adelino | 1:a74e42cf52b2 | 52 | taille=_text.size(); |
adelino | 1:a74e42cf52b2 | 53 | |
adelino | 1:a74e42cf52b2 | 54 | largeur=taille*incLargeur; |
adelino | 1:a74e42cf52b2 | 55 | |
adelino | 1:a74e42cf52b2 | 56 | if(largeur > incLargeur) |
adelino | 1:a74e42cf52b2 | 57 | largeur=largeur-incLargeur; |
adelino | 1:a74e42cf52b2 | 58 | |
adelino | 1:a74e42cf52b2 | 59 | myWidth=largeur+incLargeur+incLargeur; |
adelino | 1:a74e42cf52b2 | 60 | myHeight=hauteur+incLargeur+incLargeur; |
adelino | 1:a74e42cf52b2 | 61 | |
adelino | 1:a74e42cf52b2 | 62 | myScreen->addWidget((Widget*) this); |
adelino | 1:a74e42cf52b2 | 63 | |
adelino | 1:a74e42cf52b2 | 64 | // |
adelino | 1:a74e42cf52b2 | 65 | |
adelino | 1:a74e42cf52b2 | 66 | } |
adelino | 1:a74e42cf52b2 | 67 | //-------------------------------------- |
adelino | 1:a74e42cf52b2 | 68 | Button::~Button(void) |
adelino | 1:a74e42cf52b2 | 69 | { |
adelino | 1:a74e42cf52b2 | 70 | } |
adelino | 1:a74e42cf52b2 | 71 | //--------------------------------------- |
adelino | 1:a74e42cf52b2 | 72 | void Button::draw(void) |
adelino | 1:a74e42cf52b2 | 73 | { |
adelino | 1:a74e42cf52b2 | 74 | if(myIsVisible==false) |
adelino | 1:a74e42cf52b2 | 75 | return; |
adelino | 1:a74e42cf52b2 | 76 | |
adelino | 1:a74e42cf52b2 | 77 | State state=getState(); |
adelino | 1:a74e42cf52b2 | 78 | |
adelino | 1:a74e42cf52b2 | 79 | PicasoSerial* ps=0; |
adelino | 1:a74e42cf52b2 | 80 | ps=myScreen->getPicasoSerial(); |
adelino | 1:a74e42cf52b2 | 81 | |
adelino | 1:a74e42cf52b2 | 82 | switch(state) { |
adelino | 1:a74e42cf52b2 | 83 | // |
adelino | 1:a74e42cf52b2 | 84 | case BUTTON_STATE_PRESSED: |
adelino | 1:a74e42cf52b2 | 85 | if(ps!=0) { |
adelino | 1:a74e42cf52b2 | 86 | ps->draw_button(myText,myX,myY,myFont,BUTTON_STATE_PRESSED,myColor,WHITE); |
adelino | 1:a74e42cf52b2 | 87 | |
adelino | 1:a74e42cf52b2 | 88 | } |
adelino | 1:a74e42cf52b2 | 89 | ps=0; |
adelino | 1:a74e42cf52b2 | 90 | return; |
adelino | 1:a74e42cf52b2 | 91 | // |
adelino | 1:a74e42cf52b2 | 92 | case BUTTON_STATE_RELEASED: |
adelino | 1:a74e42cf52b2 | 93 | if(ps!=0) { |
adelino | 1:a74e42cf52b2 | 94 | ps->draw_button(myText,myX,myY,myFont,BUTTON_STATE_RELEASED,myColor,myColorText); |
adelino | 1:a74e42cf52b2 | 95 | |
adelino | 1:a74e42cf52b2 | 96 | } |
adelino | 1:a74e42cf52b2 | 97 | ps=0; |
adelino | 1:a74e42cf52b2 | 98 | return; |
adelino | 1:a74e42cf52b2 | 99 | // |
adelino | 1:a74e42cf52b2 | 100 | default: |
adelino | 1:a74e42cf52b2 | 101 | break; |
adelino | 1:a74e42cf52b2 | 102 | } |
adelino | 1:a74e42cf52b2 | 103 | } |
adelino | 1:a74e42cf52b2 | 104 | |
adelino | 1:a74e42cf52b2 | 105 | //----------------------------------- |
adelino | 1:a74e42cf52b2 | 106 | void Button::setInvisible(bool _state) |
adelino | 1:a74e42cf52b2 | 107 | { |
adelino | 1:a74e42cf52b2 | 108 | // element devient invisible |
adelino | 1:a74e42cf52b2 | 109 | if(_state==true) { |
adelino | 1:a74e42cf52b2 | 110 | if(myIsVisible==false) |
adelino | 1:a74e42cf52b2 | 111 | return; |
adelino | 1:a74e42cf52b2 | 112 | |
adelino | 1:a74e42cf52b2 | 113 | myIsVisible=false; |
adelino | 1:a74e42cf52b2 | 114 | |
adelino | 1:a74e42cf52b2 | 115 | Color c= myScreen->getColorBkg(); |
adelino | 1:a74e42cf52b2 | 116 | |
adelino | 1:a74e42cf52b2 | 117 | PicasoSerial* ps=0; |
adelino | 1:a74e42cf52b2 | 118 | ps=myScreen->getPicasoSerial(); |
adelino | 1:a74e42cf52b2 | 119 | |
adelino | 1:a74e42cf52b2 | 120 | if(ps!=0) { |
adelino | 1:a74e42cf52b2 | 121 | ps->draw_filled_rectangle(myX,myY,myX+myWidth,myY+myHeight,c); |
adelino | 1:a74e42cf52b2 | 122 | } |
adelino | 1:a74e42cf52b2 | 123 | ps=0; |
adelino | 1:a74e42cf52b2 | 124 | } |
adelino | 1:a74e42cf52b2 | 125 | |
adelino | 1:a74e42cf52b2 | 126 | // element devient visible |
adelino | 1:a74e42cf52b2 | 127 | else { |
adelino | 1:a74e42cf52b2 | 128 | myIsVisible=true; |
adelino | 1:a74e42cf52b2 | 129 | |
adelino | 1:a74e42cf52b2 | 130 | |
adelino | 1:a74e42cf52b2 | 131 | this->draw(); |
adelino | 1:a74e42cf52b2 | 132 | } |
adelino | 1:a74e42cf52b2 | 133 | } |
adelino | 1:a74e42cf52b2 | 134 | //------------------------------------ |
adelino | 1:a74e42cf52b2 | 135 | void Button::setState(State _state) |
adelino | 1:a74e42cf52b2 | 136 | { |
adelino | 1:a74e42cf52b2 | 137 | if(myIsVisible==false) |
adelino | 1:a74e42cf52b2 | 138 | return; |
adelino | 1:a74e42cf52b2 | 139 | |
adelino | 1:a74e42cf52b2 | 140 | if(myState==_state) |
adelino | 1:a74e42cf52b2 | 141 | return; |
adelino | 1:a74e42cf52b2 | 142 | |
adelino | 1:a74e42cf52b2 | 143 | myState=_state; |
adelino | 1:a74e42cf52b2 | 144 | |
adelino | 1:a74e42cf52b2 | 145 | this->draw(); |
adelino | 1:a74e42cf52b2 | 146 | } |