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/

ObjetGraphic.h

Committer:
adelino
Date:
2014-07-06
Revision:
0:65fd8b1cbf86

File content as of revision 0:65fd8b1cbf86:

#ifndef OBJET_GRAPHIC_H
#define OBJET_GRAPHIC_H

#include "PicasoSerial.h"
#include <vector>
#include <string>

/**
* Library for 3.2'' uLcd Picaso Display
* 4D system
* The Objets
* Picaso Serial Environment Command Set
* http://www.4dsystems.com.au/product/20/67/Processors_Graphics/PICASO/
* @autor A.Decarvalho
* 
* 17/04/ 2014
* 
*/

//-------------------------------------
class ObjetHeader;
//-------------------------------------
//
//
class Screen
{
public:
    /** Construct a Screen
    *
    * @param serial the PicasoSerial Obj
    * @param _x the up left
    * @params _y the up left
    * @params _w the width
    * @params _h the height
    * @param _colorBkg the background color
    */
    // constructeur
    Screen(PicasoSerial* serial,UINT16 _x,UINT16 _y,UINT16 _w,UINT16 _h,Color _colorBkg);
    //
    ~Screen(void);
    //
    //! draw all objects
    void drawAll(void);
    //------------------------------
    //! add a new Objet
    void addObj(ObjetHeader* pObj);
    //
    //! draw a particular object
    void drawObj(ObjetHeader* pObj);
    //
    //! @returns PicasoSerial the pointer to draw on the screen
    PicasoSerial* getPicasoSerial(void);
    //
    void drawCells(void);

//getter
    UINT16 getXpos(void);
    UINT16 getYpos(void);
    UINT16 getWidth(void);
    UINT16 getHeight(void);
    Color getColorBkg(void);

    bool isContent(ObjetHeader* pObj, UINT16 _x,UINT16 _y);

    //-----------------------------------------------------
    //! returns the Objet in [_x,_y] position
    ObjetHeader* getObjetPosition(UINT16 _x,UINT16 _y);
    
    //! returns the Objet by Id
    ObjetHeader* getObjetById(UINT16 _id);

    //-----------------------------------------------------
    //! returns the touch and update the GraphicMessage
    TouchEvent getTouchEvent(GraphicMessage* msg);

    //-------------------------------------------
    //! update the identifier Id of the object being touched
    void getProcessMessage(GraphicMessage* msg);

protected:
    PicasoSerial* mySerial;

    UINT16 myXpos,myYpos,myWidth,myHeight;

    Color myColorBkg;

    vector<ObjetHeader*> myVectorObjet;
};
//
//
//--------------------------------------
//
//
class ObjetHeader
{
public:
    /** Construct a ObjetHeader the father
    *
    * @param mScreen the pointer screen
    * @param _id the identifier Id
    * @params _x the up left
    * @params _y the up left
    * @params _w the width
    * @params _h the height
    * @param _color the background color
    * @params _isVisible
    */
// constructor
    //
    ObjetHeader(Screen* mScreen,UINT16 _id,UINT16 _x,UINT16 _y,UINT16 _w,UINT16 _h,Color _color,bool _isVisible);
    //
    //! draw the obj
    virtual void draw(void);
    //
    virtual ~ObjetHeader(void);
    //
    //! test a overlap
    bool overlapWith(ObjetHeader* pObj);
    //
    static bool overlap(ObjetHeader* pObj1,ObjetHeader* pObj2);
    //
    static const UINT16 CELL_DIM=80;
    static const UINT16 CELL_COL=3;
    void updateCellId(void);


//getter
    UINT16 getXpos(void);
    UINT16 getYpos(void);
    UINT16 getWidth(void);
    UINT16 getHeight(void);
    UINT16 getElementId(void);
    bool   getIsVisible(void);
    State getElementState(void);

    float getSpeedX(void);
    float getSpeedY(void);

    Color getColor(void);

    UINT16 getCellId(void);

//setter
    void setColor(Color _color);
    void setElementState(State _state);
    void setElementId(UINT16 _id);
    void setVisibility(bool _val);
    void setInvertSpeedX(void);
    void setInvertSpeedY(void);
    void setSpeedX(float _speedX);
    void setSpeedY(float _speedY);
    void setSpeedXY(float _speedX,float _speedY);

    void setXpos(UINT16 _xpos);
    void setYpos(UINT16 _ypos);

    GRAPHIC_OBJ_TYPE getElementType(void);

    void setUpdateAutomatic(bool _state);
    bool getUpdateAutomatic(void);

protected:
    Screen* myScreen;

    void elementUpdate(void);

    UINT16 myX,myY,myWidth,myHeight;
    UINT16 myElementId;
    GRAPHIC_OBJ_TYPE myElementType;

    bool myElementIsVisible;
    bool myIsUpdateAutomatic;
    float mySpeedX,mySpeedY;

    UINT16 myXMoveMin,myXMoveMax,myYMoveMin,myYMoveMax;
    UINT16 myCellId;

    State myElementState;
    Color myColor;
};
//-----------------------------------------
//
//
class Isocele:public ObjetHeader
{
public:
    Isocele(Screen* mScreen,UINT16 _id,UINT16 xc,UINT16 yc,UINT16 radius,int orientation,float _speed,Color color,bool isVisible);
    //
    virtual void draw(void);
    //
    virtual ~Isocele(void);
    //
    void setOrientation(int _orientation);
    //
    void turnLeft(void);
    //
    void turnRight(void);
    //
    void setInvisible(bool _state);
    //
    void setNewPosition(INT16 _xcnew,INT16 _ycnew);
    //
    void update(float delta);
    //
    int getOrientation(void);
    //
    UINT16 getXcenter(void);
    //
    UINT16 getYcenter(void);

    static const int ORIENTATION_UP=0;
    static const int ORIENTATION_LEFT=1;
    static const int ORIENTATION_DOWN=2;
    static const int ORIENTATION_RIGHT=3;

protected:
    UINT16 myXcenter;
    UINT16 myYcenter;
    UINT16 myRadius;
    int myOrientation;

    UINT16 myX1,myY1;
    UINT16 myX2,myY2;
    UINT16 myX3,myY3;
    float mySpeed;

    void updateOrientation(void);
    void myElementUpdate(void);
};
//----------------------------------------
//
//
class Rectangle:public ObjetHeader
{
public:
    /** Construct a filled Rectangle
    *
    * @param mScreen the pointer screen
    * @param _id the identifier Id
    * @params _x the up left
    * @params _y the up left
    * @params _w the width
    * @params _h the height
    * @param _color the background color
    * @params _isVisible
    */
    Rectangle(Screen* mScreen,UINT16 _id,UINT16 _x,UINT16 _y,UINT16 _w,UINT16 _h,Color _color,bool _isVisible);
    //
    virtual void draw(void);
    //
    virtual ~Rectangle(void);
    //
    //! updating the position of the object, in the case of a game
    void update(float delta);


//setter
    void setInvisible(bool _state);
    //
    void setNewPosition(INT16 _xcnew,INT16 _ycnew);

};
//----------------------------------------
//
//
class Circle:public ObjetHeader
{
public:
    /** Construct a filled Circle
    *
    * @param mScreen the pointer screen
    * @param _id the identifier Id
    * @params _xc the center x
    * @params _yc the center y
    * @params _radius
    * @param _color the background color
    * @params _isVisible
    */
    Circle(Screen* mScreen,UINT16 _id,UINT16 _xc,UINT16 _yc,UINT16 _radius,Color _color,bool _isVisible);
    //
    virtual void draw(void);
    //
    virtual ~Circle(void);
    //
    void update(float delta);

// getter
    UINT16 getCenterX(void);
    //
    UINT16 getCenterY(void);

//setter
    void setInvisible(bool _state);
    //
    void setNewPosition(INT16 _xnew,INT16 _ynew);
    //
    void setCenterX(UINT16 _xcenter);
    //
    void setCenterY(UINT16 _ycenter);

protected:
    UINT16 myRadius;
    UINT16 myCenterX;
    UINT16 myCenterY;
};
//-----------------------------------------
//
//
class Ellipse:public ObjetHeader
{
public:
    /** Construct a filled Ellipse
    *
    * @param mScreen the pointer screen
    * @param _id the identifier Id
    * @params _xc the center x
    * @params _yc the center y
    * @params _radiusX
    * @radius _radiusY
    * @param _color the background color
    * @params _isVisible
    */
    Ellipse(Screen* mScreen,UINT16 _id,UINT16 _xc,UINT16 _yc,UINT16 _radiusX,UINT16 _radiusY,Color _color,bool _isVisible);
    //
    virtual void draw(void);
    //
    virtual ~Ellipse(void);
    //
    void update(float delta);
// getter
    UINT16 getCenterX(void);
    //
    UINT16 getCenterY(void);

//setter
    void setInvisible(bool _state);
    //
    void setNewPosition(INT16 _xcnew,INT16 _ycnew);
    //
    void setCenterX(UINT16 _xcenter);
    //
    void setCenterY(UINT16 _ycenter);


protected:
    UINT16 myCenterX;
    UINT16 myCenterY;
    UINT16 myRadiusX;
    UINT16 myRadiusY;
};
//-----------------------------------------
//
//
class Diamond:public ObjetHeader
{
public:
    /** Construct a filled Diamond
    *
    * @param mScreen the pointer screen
    * @param _id the identifier Id
    * @params x1
    * @params y1
    * @params x2
    * @params y2
    * @params x3
    * @params y3
    * @params x4
    * @params y4
    * @param _color the background color
    * @params _isVisible
    */
    Diamond(Screen* mScreen,UINT16 _id,UINT16 x1,UINT16 y1,UINT16 x2,UINT16 y2,
            UINT16 x3,UINT16 y3,UINT16 x4,UINT16 y4,Color _color,bool _isVisible);
    //
    virtual void draw(void);
    //
    virtual ~Diamond(void);
    //
    void update(float delta);

//setter
    void setInvisible(bool _state);
    //
    void setNewPosition(INT16 _xnew,INT16 _ynew);

protected:
    UINT16 myX1,myY1;
    UINT16 myX2,myY2;
    UINT16 myX3,myY3;
    UINT16 myX4,myY4;
    UINT16 myU1,myU2;
    UINT16 myV1,myV2;

};
//---------------------------------------
//
//
class Triangle:public ObjetHeader
{
public:
    /** Construct a filled  Triangle
       *
       * @param mScreen the pointer screen
       * @param _id the identifier Id
       * @params x1
       * @params y1
       * @params x2
       * @params y2
       * @params x3
       * @params y3
       * @param _color the background color
       * @params _isVisible
       */

    Triangle(Screen* mScreen,UINT16 _id,UINT16 x1,UINT16 y1,
             UINT16 x2,UINT16 y2,
             UINT16 x3,UINT16 y3,
             Color _color,bool _isVisible);
    //
    virtual void draw(void);
    //
    virtual ~Triangle(void);
    //
    void update(float delta);


//setter
    void setInvisible(bool _state);
    //
    void setNewPosition(INT16 _xnew,INT16 _ynew);


protected:
    UINT16 myX1,myY1;
    UINT16 myX2,myY2;
    UINT16 myX3,myY3;
    UINT16 myU,myV;
};
//------------------------------------------
//
//
class Label:public ObjetHeader
{
public:
    /** Construct a label
        *
        * @param mScreen the pointer screen
        * @param _id the identifier Id
        * @params _x
        * @params _y
        * @params _text
        * @params _font
        * @params _colorText
        * @params _colorBkg
        * @params _isVisible
        */

    Label(Screen* mScreen,UINT16 _id,UINT16 _x,UINT16 _y,
          string _text,Font _font,Color _colorText,Color _colorBkg,bool _isVisible);

    //
    virtual void draw(void);
    //
    virtual ~Label(void);

//setter
    void setInvisible(bool _state);
    //
    void setNewText(string _newText);

protected:
    string myText;
    Font myFont;
    Color myColorText;

};
//-------------------------------------------
//
//
class GraphicLed:public ObjetHeader
{
public:
    /** Construct a filled Circle
        *
        * @param mScreen the pointer screen
        * @param _id the identifier Id
        * @params _xc center
        * @params _yc center
        * @params _radius
        * @params _colorOn
        * @params _colorOff
        * @params _state LED_STATE_ON or LED_STATE_OFF,
        * @params _isVisible
        */
    GraphicLed(Screen* mScreen,UINT16 _id,UINT16 _xc,UINT16 _yc,UINT16 _radius,
               Color _colorOn,Color _colorOff,State _state,bool _isVisible);
    //
    virtual void draw(void);
    //
    virtual ~GraphicLed(void);


//setter
    void setInvisible(bool _state);
    //
    void setState(State _state);

protected:
    Color myColorOn;
    Color myColorOff;
    UINT16 myRadius;
    UINT16 myCenterX;
    UINT16 myCenterY;
};
//------------------------------------------
//
//
class Button:public ObjetHeader
{
public:
    /** Construct a Button
    *
    * @param mScreen the pointer screen
    * @param _id the identifier Id
    * @params _x up left
    * @params _y up left
    * @params _text
    * @params _font
    * @params _colorText
    * @params _colorBtn
    * @params _state BUTTON_STATE_PRESSED or BUTTON_STATE_RELEASED,
    * @params _isVisible
    */
    Button(Screen* mScreen,UINT16 _id,UINT16 _x,UINT16 _y,string _text,Font _font,
           Color _colorText,Color _colorBtn,State _state,bool _isVisible);
    //
    virtual void draw(void);
    //
    virtual ~Button(void);

    //setter
    void setInvisible(bool _state);
    //
    void setState(State _state);

protected:
    string myText;
    Font myFont;
    Color myColorText;
};
//------------------------------------------
//
//
class Slider:public ObjetHeader
{
public:
    /** Construct a Slider
    *
    * @param mScreen the pointer screen
    * @param _id the identifier Id
    * @params _x up left
    * @params _y up left
    * @params _width
    * @params _height
    * @params _valMax
    * @params _value
    * @params _colorBkg
    * @params _isVisible
    */
    Slider(Screen* mScreen,UINT16 _id,UINT16 _x,UINT16 _y,UINT16 _width,UINT16 _height,int _valMax,int _value,
           Color _colorBkg,bool _isVisible);
    //
    virtual void draw(void);
    //
    virtual ~Slider(void);
    //
    void setInvisible(bool _state);
    //
    int getValue(GraphicMessage* pmsg);

protected:
    int myValueMax;
    int myValue;
};
//------------------------------------------
//
//
class Input:public ObjetHeader
{
public:
    /** Construct a Input
        *
        * @param mScreen the pointer screen
        * @param _id the identifier Id
        * @params _x up left
        * @params _y up left
        * @params _width
        * @params _height
        * @params _valMin
        * @params _valInc incrementing the value
        * @params _valMax
        * @params _isVisible
        */
    Input(Screen* mScreen,UINT16 _id,UINT16 _x,UINT16 _y,UINT16 _width,UINT16 _height,float _valMin,float _valInc,
          float _valMax,bool _isVisible);
    //
    virtual void draw(void);
    //
    virtual ~Input(void);
    //
    void setInvisible(bool _state);
    //
    float getValue(GraphicMessage* msg);
    //
    void setColorBkg(Color _color);
    //
    void setColorCursorDown(Color _color);
    //
    void setColorCursorUp(Color _color);

protected:
    float myValMin;
    float myValInc;
    float myValMax;
    float myValue;
    Color myColorBkg;
    Color myColorCursorUp;
    Color myColorCursorDown;
};
//-----------------------------------------
//
//
class Switch:public ObjetHeader
{
public:
    /** Construct a Switch
        *
        * @param mScreen the pointer screen
        * @param _id the identifier Id
        * @params _x up left
        * @params _y up left
        * @params _width
        * @params _height
        * @params _isVisible
        */
    Switch(Screen* mScreen,UINT16 _id,UINT16 _x,UINT16 _y,UINT16 _width,UINT16 _height,bool _isVisible);
    //
    virtual void draw(void);
    //
    virtual ~Switch(void);
    //
    void setInvisible(bool _state);
    //
    void setState(State _state);
    //
    void changeState(GraphicMessage* msg);

protected:
    Color myColorOn;
    Color myColorOff;
    Color myColorCursor;
};
//------------------------------------
//
//
class DigitLed:public ObjetHeader
{
public:
    /** Construct a Digit Led
        *
        * @param mScreen the pointer screen
        * @param _id the identifier Id
        * @params _x up left
        * @params _y up left
        * @params _ptVisible
        * @params _isVisible
        */
    DigitLed(Screen* mScreen,UINT16 _id,UINT16 _x,UINT16 _y,bool _ptVisible,bool _isVisible);
    //
    virtual void draw(void);
    //
    virtual ~DigitLed(void);
    //
    void setInvisible(bool _state);
    //
    void setValue(char _value);
    //
    void setColorBkg(Color _colorBkg);
    //
    void setColorSeg(Color _colorSeg);
    //
    void setPtVisible(bool _state);

protected:
    char myValue;
    Color myColorBkg;
    Color myColorSeg;
    UINT16 myIncX;
    UINT16 myIncY;
    bool isPtVisible;
    //
    void draw_seg_a(PicasoSerial* ps);
    void draw_seg_b(PicasoSerial* ps);

    void draw_seg_c(PicasoSerial* ps);

    void draw_seg_d(PicasoSerial* ps);
    void draw_seg_e(PicasoSerial* ps);
    void draw_seg_f(PicasoSerial* ps);

    void draw_seg_g(PicasoSerial* ps);
    void draw_seg_pt(PicasoSerial* ps);
};
//--------------------------------------------
//
//
class Digit3Led:public ObjetHeader
{
public:
    /** Construct a 3 Digit Led [000]
        *
        * @param mScreen the pointer screen
        * @param _id the identifier Id
        * @params _x up left
        * @params _y up left
        * @params _resolution 1[000],10[00.0],100[0.00]
        * @params _isVisible
        */
    Digit3Led(Screen* mScreen,UINT16 _id,UINT16 _x,UINT16 _y,UINT8 _resolution,bool _isVisible);
    //
    virtual void draw(void);
    //
    virtual  ~Digit3Led(void);
    //
    void setInvisible(bool _state);
    //
    void setValue(float _value);
    //
    void setColorBkg(Color _colorBkg);
    //
    void setColorSeg(Color _colorSeg);

protected:
    Color myColorBkg;
    Color myColorSeg;
    float myValue;
    UINT8 myResolution;

    DigitLed* myDigitLedCentaine;
    DigitLed* myDigitLedDizaine;
    DigitLed* myDigitLedUnite;

};
//--------------------------------------------------------
#endif