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/

Committer:
adelino
Date:
Sun Apr 05 13:54:48 2015 +0000
Revision:
1:a74e42cf52b2
PicasoLib version 2

Who changed what in which revision?

UserRevisionLine numberNew contents of line
adelino 1:a74e42cf52b2 1 #include "Switcher.h"
adelino 1:a74e42cf52b2 2
adelino 1:a74e42cf52b2 3 Switcher::Switcher(Screen* mScreen,UINT16 _id,UINT16 _x,UINT16 _y,UINT16 _width,UINT16 _height):
adelino 1:a74e42cf52b2 4 Widget(mScreen,_id,_x,_y,_width,_height,WHITE)
adelino 1:a74e42cf52b2 5 {
adelino 1:a74e42cf52b2 6 myColorOn=GREEN;
adelino 1:a74e42cf52b2 7 myColorOff=RED;
adelino 1:a74e42cf52b2 8 myColorCursor=WHITE;
adelino 1:a74e42cf52b2 9
adelino 1:a74e42cf52b2 10 myType=OBJ_SWITCHER;
adelino 1:a74e42cf52b2 11 myState=SWITCHER_STATE_OFF;
adelino 1:a74e42cf52b2 12
adelino 1:a74e42cf52b2 13 myScreen->addWidget((Widget*) this);
adelino 1:a74e42cf52b2 14 }
adelino 1:a74e42cf52b2 15 //---------------------------------------
adelino 1:a74e42cf52b2 16 Switcher::~Switcher(void)
adelino 1:a74e42cf52b2 17 {
adelino 1:a74e42cf52b2 18 }
adelino 1:a74e42cf52b2 19 //---------------------------------------
adelino 1:a74e42cf52b2 20 void Switcher::draw(void)
adelino 1:a74e42cf52b2 21 {
adelino 1:a74e42cf52b2 22 if(myIsVisible==false)
adelino 1:a74e42cf52b2 23 return;
adelino 1:a74e42cf52b2 24 //
adelino 1:a74e42cf52b2 25 PicasoSerial* ps=0;
adelino 1:a74e42cf52b2 26 ps=myScreen->getPicasoSerial();
adelino 1:a74e42cf52b2 27
adelino 1:a74e42cf52b2 28 State state=myState;
adelino 1:a74e42cf52b2 29
adelino 1:a74e42cf52b2 30 Color gauche=WHITE;
adelino 1:a74e42cf52b2 31 Color droite=WHITE;
adelino 1:a74e42cf52b2 32
adelino 1:a74e42cf52b2 33 switch(state) {
adelino 1:a74e42cf52b2 34 //
adelino 1:a74e42cf52b2 35 case SWITCHER_STATE_ON:
adelino 1:a74e42cf52b2 36 droite=myColorOn;
adelino 1:a74e42cf52b2 37 gauche=myColorCursor;
adelino 1:a74e42cf52b2 38 break;
adelino 1:a74e42cf52b2 39
adelino 1:a74e42cf52b2 40 //
adelino 1:a74e42cf52b2 41 case SWITCHER_STATE_OFF:
adelino 1:a74e42cf52b2 42 droite=myColorCursor;
adelino 1:a74e42cf52b2 43 gauche=myColorOff;
adelino 1:a74e42cf52b2 44 break;
adelino 1:a74e42cf52b2 45
adelino 1:a74e42cf52b2 46 //
adelino 1:a74e42cf52b2 47 default:
adelino 1:a74e42cf52b2 48 break;
adelino 1:a74e42cf52b2 49 }
adelino 1:a74e42cf52b2 50 //
adelino 1:a74e42cf52b2 51
adelino 1:a74e42cf52b2 52 //rect gauche
adelino 1:a74e42cf52b2 53 if(ps!=0)
adelino 1:a74e42cf52b2 54 ps->draw_filled_rectangle(myX,myY,myX+myWidth/2,myY+myHeight,gauche);
adelino 1:a74e42cf52b2 55
adelino 1:a74e42cf52b2 56 //rect droite
adelino 1:a74e42cf52b2 57 if(ps!=0)
adelino 1:a74e42cf52b2 58 ps->draw_filled_rectangle(myX+myWidth/2,myY,myX+myWidth,myY+myHeight,droite);
adelino 1:a74e42cf52b2 59
adelino 1:a74e42cf52b2 60 //cadre
adelino 1:a74e42cf52b2 61 if(ps!=0) {
adelino 1:a74e42cf52b2 62 ps->draw_rectangle(myX,myY,myX+myWidth,myY+myHeight,BLACK);
adelino 1:a74e42cf52b2 63 ps->draw_rectangle(myX,myY,myX+myWidth/2,myY+myHeight,BLACK);
adelino 1:a74e42cf52b2 64
adelino 1:a74e42cf52b2 65 }
adelino 1:a74e42cf52b2 66 ps=0;
adelino 1:a74e42cf52b2 67
adelino 1:a74e42cf52b2 68 }
adelino 1:a74e42cf52b2 69 //----------------------------------------
adelino 1:a74e42cf52b2 70 void Switcher::setInvisible(bool _state)
adelino 1:a74e42cf52b2 71 {
adelino 1:a74e42cf52b2 72 // element devient invisible
adelino 1:a74e42cf52b2 73 if(_state==true) {
adelino 1:a74e42cf52b2 74 if(myIsVisible==false)
adelino 1:a74e42cf52b2 75 return;
adelino 1:a74e42cf52b2 76
adelino 1:a74e42cf52b2 77 myIsVisible=false;
adelino 1:a74e42cf52b2 78
adelino 1:a74e42cf52b2 79 Color c= myScreen->getColorBkg();
adelino 1:a74e42cf52b2 80 PicasoSerial* ps=0;
adelino 1:a74e42cf52b2 81
adelino 1:a74e42cf52b2 82 ps=myScreen->getPicasoSerial();
adelino 1:a74e42cf52b2 83
adelino 1:a74e42cf52b2 84 if(ps!=0) {
adelino 1:a74e42cf52b2 85 ps->draw_filled_rectangle(myX,myY,myX+myWidth,myY+myHeight,c);
adelino 1:a74e42cf52b2 86 }
adelino 1:a74e42cf52b2 87 ps=0;
adelino 1:a74e42cf52b2 88 }
adelino 1:a74e42cf52b2 89
adelino 1:a74e42cf52b2 90 // element devient visible
adelino 1:a74e42cf52b2 91 else {
adelino 1:a74e42cf52b2 92 myIsVisible=true;
adelino 1:a74e42cf52b2 93
adelino 1:a74e42cf52b2 94
adelino 1:a74e42cf52b2 95 this->draw();
adelino 1:a74e42cf52b2 96 }
adelino 1:a74e42cf52b2 97 }
adelino 1:a74e42cf52b2 98 //-----------------------------------------
adelino 1:a74e42cf52b2 99 void Switcher::setState(State _state)
adelino 1:a74e42cf52b2 100 {
adelino 1:a74e42cf52b2 101 if(myIsVisible==false)
adelino 1:a74e42cf52b2 102 return;
adelino 1:a74e42cf52b2 103
adelino 1:a74e42cf52b2 104 if(myState==_state)
adelino 1:a74e42cf52b2 105 return;
adelino 1:a74e42cf52b2 106
adelino 1:a74e42cf52b2 107 myState=_state;
adelino 1:a74e42cf52b2 108
adelino 1:a74e42cf52b2 109 this->draw();
adelino 1:a74e42cf52b2 110 }
adelino 1:a74e42cf52b2 111 //-----------------------------------------
adelino 1:a74e42cf52b2 112 void Switcher::changeState(GraphicMessage* msg)
adelino 1:a74e42cf52b2 113 {
adelino 1:a74e42cf52b2 114 TouchEvent ev=msg->event;
adelino 1:a74e42cf52b2 115
adelino 1:a74e42cf52b2 116 if(myIsVisible==false)
adelino 1:a74e42cf52b2 117 return;
adelino 1:a74e42cf52b2 118
adelino 1:a74e42cf52b2 119 if(ev==EVENT_PRESS && myState==SWITCHER_STATE_OFF) {
adelino 1:a74e42cf52b2 120 this->setState(SWITCHER_STATE_ON);
adelino 1:a74e42cf52b2 121 return;
adelino 1:a74e42cf52b2 122 }
adelino 1:a74e42cf52b2 123 //
adelino 1:a74e42cf52b2 124 if(ev==EVENT_PRESS && myState==SWITCHER_STATE_ON) {
adelino 1:a74e42cf52b2 125 this->setState(SWITCHER_STATE_OFF);
adelino 1:a74e42cf52b2 126 return;
adelino 1:a74e42cf52b2 127 }
adelino 1:a74e42cf52b2 128 //
adelino 1:a74e42cf52b2 129 if(ev==EVENT_MOVE || ev==EVENT_RELEASE)
adelino 1:a74e42cf52b2 130 return;
adelino 1:a74e42cf52b2 131 }