Button and its transparency

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

  • Button and its transparency

    Dear sirs,

    we want to obtain buttons with a trasparency level in unpressed state and another transparecy level when pressed. So the button has to show, with indicated level of transparecy, what is drawn "under" him.
    We made lots of test using all examples in emWin Simulator without result.
    Please find below my brief explanation:
    1) when button is created everything is OK: unpressed state is properly shown;
    2) button color in unpressed state is defined as GUI_BLACK | 0x80000000, and it is ok (only immediately just after button creation!!);
    3) button color in pressed state is defined as GUI_BLACK | 0x80000000, and it is ok when I press the button;

    The problem arises when I release the button, that is, when button is back to its unpressed state: it is redrawn ONTO the pressed state; the final effect is that the button color becomes darker and darker as soon as you click&release it ... until it is completely black....The button color is continuously redrawn onto previous one.
    We can understand this: if you write 2 different pure colors (without transparency) for unpressed and pressed states, as soon as the button status changes, its relative color is painted ... ok!
    But we want that when button is released, so it goes back to unpressed state, with initial transparency.
    We tried also to trigger an invalidation of button area but it didn't work. Doing tests, we realized that if you HIDE the button and then you SHOW it, it is properly shown, so, for example, we tried to HIDE the button when released and to show it back on POST_PAINT event (POST PAINT on button parent window) but it still doesn't work.
    Our impression is that there is something wrong on API calling sequence ... even though it seems correct ....

    Any suggestions?


    Thanks a lot and best regards,

    Valter Rasicci
    INIM Electronics
  • Hi Adrian,

    thanks a lot ... I solved in another way using WINDOW instead of BUTTON .. the question was not solved simply using WM_CF_HASTRANS flag.

    But I saw that the WM_GetId(Fin1) function doesn't work on WINDOW widgets; it returns always 0. Do you confirm this? I tested on Simulator software and on device also.




    If I create 2 widgets as follow:
    But1 = BUTTON_CreateEx(100,220,220,50,WM_HBKWIN,WM_CF_SHOW,0,GUI_ID_BUTTON0);
    Fin1 = WINDOW_CreateEx(100,20,220,50,WM_HBKWIN,WM_CF_SHOW,0,GUI_ID_CHECK2,cb_win);


    WM_GetId(But1) returns GUI_ID_BUTTON0 as expected, while

    WM_GetId(Fin1) returns 0 ....

    I'm working around this because I need to assing the same callback function to several WINDOWs and, in the callback, I'd like to distinguish the originator using the related ID (even I could take the originator using pMsg->hWin ...)


    Thanks again,

    Best regards,

    Valter
  • Hello Valter,

    Yes, I can confirm this behavior.

    The WINDOW widget is actually not intended to return an ID. Nevertheless it should be possible to implement this in a future emWin version.

    Please note that the features for emWin V5.18 are already fixed, so this will be part of emWin V5.20.

    Best regards,
    Adrian