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 "Slider.h"
adelino 1:a74e42cf52b2 2
adelino 1:a74e42cf52b2 3 Slider::Slider(Screen* mScreen,UINT16 _id,UINT16 _x,UINT16 _y,UINT16 _width,UINT16 _height,int _valMax,int _value,
adelino 1:a74e42cf52b2 4 Color _colorBkg):
adelino 1:a74e42cf52b2 5 Widget(mScreen,_id,_x,_y,_width,_height,_colorBkg)
adelino 1:a74e42cf52b2 6 {
adelino 1:a74e42cf52b2 7
adelino 1:a74e42cf52b2 8 myValueMax=_valMax;
adelino 1:a74e42cf52b2 9 myValue=_value;
adelino 1:a74e42cf52b2 10
adelino 1:a74e42cf52b2 11 myType=OBJ_SLIDER;
adelino 1:a74e42cf52b2 12 myState=SLIDER_STATE_RELEASED;
adelino 1:a74e42cf52b2 13
adelino 1:a74e42cf52b2 14 myScreen->addWidget((Widget*) this);
adelino 1:a74e42cf52b2 15 }
adelino 1:a74e42cf52b2 16 //---------------------------------------
adelino 1:a74e42cf52b2 17 Slider::~Slider(void)
adelino 1:a74e42cf52b2 18 {
adelino 1:a74e42cf52b2 19 }
adelino 1:a74e42cf52b2 20 //---------------------------------------
adelino 1:a74e42cf52b2 21 void Slider::draw(void)
adelino 1:a74e42cf52b2 22 {
adelino 1:a74e42cf52b2 23 if(myIsVisible==false)
adelino 1:a74e42cf52b2 24 return;
adelino 1:a74e42cf52b2 25
adelino 1:a74e42cf52b2 26 PicasoSerial* ps=0;
adelino 1:a74e42cf52b2 27 ps=myScreen->getPicasoSerial();
adelino 1:a74e42cf52b2 28
adelino 1:a74e42cf52b2 29 if(ps!=0) {
adelino 1:a74e42cf52b2 30 ps->draw_slider(0x0000,myX,myY,myX+myWidth,myY+myHeight,myColor,myValueMax,myValue);
adelino 1:a74e42cf52b2 31 }
adelino 1:a74e42cf52b2 32 ps=0;
adelino 1:a74e42cf52b2 33
adelino 1:a74e42cf52b2 34 }
adelino 1:a74e42cf52b2 35 //--------------------------------------
adelino 1:a74e42cf52b2 36 void Slider::setInvisible(bool _state)
adelino 1:a74e42cf52b2 37 {
adelino 1:a74e42cf52b2 38 // element devient invisible
adelino 1:a74e42cf52b2 39 if(_state==true) {
adelino 1:a74e42cf52b2 40 if(myIsVisible==false)
adelino 1:a74e42cf52b2 41 return;
adelino 1:a74e42cf52b2 42
adelino 1:a74e42cf52b2 43 myIsVisible=false;
adelino 1:a74e42cf52b2 44
adelino 1:a74e42cf52b2 45 Color c= myScreen->getColorBkg();
adelino 1:a74e42cf52b2 46
adelino 1:a74e42cf52b2 47 PicasoSerial* ps=0;
adelino 1:a74e42cf52b2 48 ps=myScreen->getPicasoSerial();
adelino 1:a74e42cf52b2 49
adelino 1:a74e42cf52b2 50 if(ps!=0) {
adelino 1:a74e42cf52b2 51 ps->draw_filled_rectangle(myX,myY,myX+myWidth,myY+myHeight,c);
adelino 1:a74e42cf52b2 52 }
adelino 1:a74e42cf52b2 53 ps=0;
adelino 1:a74e42cf52b2 54 }
adelino 1:a74e42cf52b2 55
adelino 1:a74e42cf52b2 56 // element devient visible
adelino 1:a74e42cf52b2 57 else {
adelino 1:a74e42cf52b2 58 myIsVisible=true;
adelino 1:a74e42cf52b2 59
adelino 1:a74e42cf52b2 60
adelino 1:a74e42cf52b2 61 this->draw();
adelino 1:a74e42cf52b2 62 }
adelino 1:a74e42cf52b2 63 }
adelino 1:a74e42cf52b2 64 //-------------------------------------
adelino 1:a74e42cf52b2 65 int Slider::getValue(GraphicMessage* pmsg)
adelino 1:a74e42cf52b2 66 {
adelino 1:a74e42cf52b2 67 TouchEvent msgEvent=pmsg->event;
adelino 1:a74e42cf52b2 68
adelino 1:a74e42cf52b2 69 UINT16 xn=pmsg->posiX;
adelino 1:a74e42cf52b2 70
adelino 1:a74e42cf52b2 71
adelino 1:a74e42cf52b2 72 if(myIsVisible==false)
adelino 1:a74e42cf52b2 73 return 0;
adelino 1:a74e42cf52b2 74 //
adelino 1:a74e42cf52b2 75
adelino 1:a74e42cf52b2 76 if(msgEvent==EVENT_RELEASE) {
adelino 1:a74e42cf52b2 77 myState=SLIDER_STATE_RELEASED;
adelino 1:a74e42cf52b2 78 }
adelino 1:a74e42cf52b2 79 //
adelino 1:a74e42cf52b2 80 if(msgEvent==EVENT_MOVE) {
adelino 1:a74e42cf52b2 81 myState=SLIDER_STATE_MOVE;
adelino 1:a74e42cf52b2 82 UINT16 dis=xn-myX;
adelino 1:a74e42cf52b2 83 UINT16 a=dis*myValueMax;
adelino 1:a74e42cf52b2 84 myValue=(a/myWidth);
adelino 1:a74e42cf52b2 85
adelino 1:a74e42cf52b2 86 this->draw();
adelino 1:a74e42cf52b2 87 }
adelino 1:a74e42cf52b2 88 return myValue;
adelino 1:a74e42cf52b2 89 }