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