EmbeddedArtists AB / ewgui

Dependents:   app_emwin1 app_emwin2_pos lpc4088_ebb_gui_emwin

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers EwButton.h Source File

EwButton.h

00001 
00002 #ifndef EWBUTTON_H
00003 #define EWBUTTON_H
00004 
00005 #include "EwPainter.h"
00006 #include "EwWindow.h"
00007 #include "EwFunctionPointer.h"
00008 
00009 #include "BUTTON.h"
00010 
00011 enum ewButtonColorIndex_t {
00012     ButtonColorIndexDisabled = BUTTON_CI_DISABLED,
00013     ButtonColorIndexPressed = BUTTON_CI_PRESSED,
00014     ButtonColorIndexUnpressed = BUTTON_CI_UNPRESSED,
00015 };
00016 
00017 /**
00018  * This is a wrapper class for the emwin BUTTON interface.
00019  */
00020 class EwButton : public EwWindow {
00021 public:
00022 
00023     EwButton(EwWindow* parent = 0);
00024     EwButton(int x, int y, int width, int height, EwWindow* parent = 0);
00025 
00026 
00027     void setText(const char* text);
00028     void getText(char* pBuf, int bufSz);
00029 
00030     ewColor_t getBackgroundColor(ewButtonColorIndex_t idx);
00031     void setBackgroundColor(ewButtonColorIndex_t idx, ewColor_t c);
00032     const ewFont_t* getFont();
00033     void setFont(const ewFont_t* pFont);
00034 
00035     ewTextAlign_t getTextAlign();
00036     void setTextAlign(ewTextAlign_t align);
00037     ewColor_t getTextColor(ewButtonColorIndex_t idx);
00038     void setTextColor(ewButtonColorIndex_t idx, ewColor_t c);
00039 
00040     void setFocusColor(ewColor_t c);
00041     void setFocussable(bool focussable);
00042     void setPressed(bool pressed);
00043     bool isPressed();
00044 
00045     void setTextOffset(int32_t xPos, int32_t yPos);
00046 
00047     const ewBitmap_t* getBitmap(ewButtonColorIndex_t idx);
00048     void setBitmap(ewButtonColorIndex_t idx, const ewBitmap_t* pBitmap);
00049     void setBitmap(ewButtonColorIndex_t idx, const ewBitmap_t* pBitmap, int32_t x, int32_t y);
00050 
00051     /**
00052      * Register a member function that will called when the button
00053      * is pressed.
00054      *
00055      * @param tptr pointer to the object to call the member function on
00056      * @param mptr pointer to the member function to be called
00057      */
00058     template<typename T>
00059     void setPressedListener(T* tptr, void (T::*mptr)(EwWindow* w)) {
00060         if((mptr != NULL) && (tptr != NULL)) {
00061             _pressedListener.attach(tptr, mptr);
00062         }
00063     }
00064 
00065     /**
00066      * Register a function that will called when the button
00067      * is pressed.
00068      *
00069      * @param fptr A pointer to a void function that will be called
00070      * when the button is pressed
00071      */
00072     void setPressedListener(void (*fptr)(EwWindow* w));
00073 
00074     /**
00075      * Register a member function that will called when the button
00076      * is released.
00077      *
00078      * @param tptr pointer to the object to call the member function on
00079      * @param mptr pointer to the member function to be called
00080      */
00081     template<typename T>
00082     void setReleasedListener(T* tptr, void (T::*mptr)(EwWindow* w)) {
00083         if((mptr != NULL) && (tptr != NULL)) {
00084             _releasedListener.attach(tptr, mptr);
00085         }
00086     }
00087 
00088     /**
00089      * Register a function that will called when the button
00090      * is released.
00091      *
00092      * @param fptr A pointer to a void function that will be called
00093      * when the button is released
00094      */
00095     void setReleasedListener(void (*fptr)(EwWindow* w));
00096 
00097     /**
00098      * Register a member function that will called when the button
00099      * is clicked.
00100      *
00101      * @param tptr pointer to the object to call the member function on
00102      * @param mptr pointer to the member function to be called
00103      */
00104     template<typename T>
00105     void setClickedListener(T* tptr, void (T::*mptr)(EwWindow* w)) {
00106         if((mptr != NULL) && (tptr != NULL)) {
00107             _clickedListener.attach(tptr, mptr);
00108         }
00109     }
00110 
00111     /**
00112      * Register a function that will called when the button
00113      * is clicked.
00114      *
00115      * @param fptr A pointer to a void function that will be called
00116      * when the button is clicked
00117      */
00118     void setClickedListener(void (*fptr)(EwWindow* w));
00119 
00120     static ewColor_t getDefaultBackgroundColor(ewButtonColorIndex_t idx);
00121     static void setDefaultBackgroundColor(ewButtonColorIndex_t idx, ewColor_t c);
00122     static const ewFont_t* getDefaultFont();
00123     static void setDefaultFont(const ewFont_t* pFont);
00124     static ewTextAlign_t getDefaultTextAlign();
00125     static void setDefaultTextAlign(ewTextAlign_t align);
00126     static ewColor_t getDefaultTextColor(ewButtonColorIndex_t idx);
00127     static void setDefaultTextColor(ewButtonColorIndex_t idx, ewColor_t c);
00128 
00129     static void setDefaultFocusColor(ewColor_t c);
00130 
00131 
00132 
00133 
00134 private:
00135 
00136     bool _inputStatePressed;
00137     EwFunctionPointer _pressedListener;
00138     EwFunctionPointer _releasedListener;
00139     EwFunctionPointer _clickedListener;
00140 
00141     void init(int x, int y, int width, int height, EwWindow* parent);
00142     void handleInput(bool pressed, bool onWidget);
00143 
00144     static void _callback(WM_MESSAGE* pMsg, EwWindow* w);
00145 
00146 
00147 };
00148 
00149 #endif