How to manage a transparent button (and why IMAGE widget doesn't draw alpha-channel images in other colors but white)

This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

  • How to manage a transparent button (and why IMAGE widget doesn't draw alpha-channel images in other colors but white)

    I have a single-color black background. At the center, I want a transparent image.
    On top of this image, there is a second image. It is an alpha channel image. Depending on some variables, this should be drawn in different colors. This second image is smaller than the first and completely inside the first.

    The system should react when the user touches the first bigger image.

    How to achieve this? I can use GUI_DrawBitmap() for both images, but I have to manage myself the user touch.

    Another possibility is to use an IMAGE widget for the second image. In this way, emWin library notify my code on user touch. But I don't know how can I assign and draw an alpha-channel image to an IMAGE widget. It seems it is drawn always with white color.

    Another possibility is to use a BUTTON widget with a custom skin. Could it be transparent? How to assign and draw an alpha channel image with whatever color?

    The post was edited 1 time, last by giusloq ().

  • Hello,

    The following code can be used to change the color of an alpha bitmap displayed by the IMAGE image widget:

    C Source Code

    1. static void _cbImage(WM_MESSAGE * pMsg) {
    2. switch (pMsg->MsgId) {
    3. case WM_PAINT:
    4. GUI_SetColor(GUI_LIGHTBLUE);
    5. default:
    6. IMAGE_Callback(pMsg);
    7. }
    8. }

    Best regards,
    Adrian
  • The following code can be used to change the color of an alpha bitmap displayed by the IMAGE image widget:
    I have tried the same trick for a BUTTON widget that should show an alpha bitmap inside with a custom color... but it doesn't work. The bitmap is always drawn with black color.

    Source Code

    1. void cbButtonAlphaRed(WM_MESSAGE * pMsg) {
    2. switch(pMsg->MsgId) {
    3. case WM_PAINT:
    4. GUI_SetColor(GUI_RED);
    5. default:
    6. BUTTON_Callback(pMsg);
    7. }
    8. }
  • Hello,

    The BUTTON widget sets the color as it draws itself. Therefor setting the color using below implementation can not have an effect. I would recommend drawing the bitmap in the custom callback function on top of the BUTTON:

    C Source Code

    1. void cbButtonAlphaRed(WM_MESSAGE * pMsg) {
    2. switch (pMsg->MsgId) {
    3. case WM_PAINT:
    4. BUTTON_Callback(pMsg);
    5. GUI_SetColor(GUI_RED);
    6. GUI_DrawBitmap(...);
    7. break;
    8. default:
    9. BUTTON_Callback(pMsg);
    10. }
    11. }
    Display All

    Best regards,
    Adrian