How to set background color for transparent image

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

    • How to set background color for transparent image

      I have an image which is transparent.For press and unpress i want background color to be changed.
      for this i am overwriting the button callback function
      I am setting that callback while dialog initialization as below\


      hBck=WM_GetDialogItem(pMsg->hWin, ID_PW_BUTTON_10);
      WM_SetHasTrans(hBck);
      BUTTON_SetFocussable(hBck,BUTTON_DISBLE_FOCUS);
      WM_SetCallback(hBack, F076_callbkdelButton);

      following is the callback function for that button


      void F076_callbkdelButton(WM_MESSAGE * pMsg){
      GUI_RECT Rect;
      switch (pMsg->MsgId) {
      case WM_PAINT:
      WM_GetClientRect(&Rect);
      if(BUTTON_IsPressed(pMsg->hWin))
      {
      GUI_SetBkColor(GUI_GREEN);
      GUI_DrawBitmap(&bm_backicon,0,0);
      }
      else
      {
      GUI_SetBkColor(GUI_RED);
      GUI_DrawBitmap(&bm_backicon,0,0);
      }
      break;
      default:
      BUTTON_Callback(pMsg); // The original callback
      break;
      }

      While initialization it is working fine but when some other window comes on that window the background color is not retained(it is changing to black)
      can anyone explain this behaviour?
    • Hi,

      Add a GUI_Clear() after calling GUI_SetBkColor(). This clears the current drawing area (which is the area of the button) with set back ground color.

      Regards
      Sven
      Please read the forum rules before posting.

      Keep in mind, this is *not* a support forum.
      Our engineers will try to answer your questions between their projects if possible but this can be delayed by longer periods of time.
      Should you be entitled to support you can contact us via our support system: segger.com/ticket/

      Or you can contact us via e-mail.
    • You are giving a button a background color whether it is pressed or not.
      Why don't you use the button skinflex properties to set the background ? It's is made for changing button color depending on its state ?
    • Hi,

      You might try the example attached. It is a simple button which changes the color and the bitmap depending on its state (pressed/unpressed).

      Regards
      Sven
      Files
      Please read the forum rules before posting.

      Keep in mind, this is *not* a support forum.
      Our engineers will try to answer your questions between their projects if possible but this can be delayed by longer periods of time.
      Should you be entitled to support you can contact us via our support system: segger.com/ticket/

      Or you can contact us via e-mail.
    • But i want same bitmap to be used for both pressed and unpressed and just change the background. Background will change in normal condition but once any other window comes above that(because some part of that window coming on top of that button).the background will change to black automatically.
    • Hi,

      Then just skip the part where I set a different bitmap and draw always the same..

      C Source Code

      1. if (BUTTON_IsPressed(pMsg->hWin)) {
      2. Color = GUI_GREEN;
      3. pBm = &bmBitmapPressed_50x50; // Don't do this
      4. } else {
      5. Color = GUI_RED;
      6. pBm = &bmBitmapUnpressed_50x50; // And also not this
      7. }
      8. GUI_SetBkColor(Color);
      9. GUI_Clear();
      10. xPos = (WM_GetWindowSizeX(pMsg->hWin) - pBm->XSize) / 2;
      11. yPos = (WM_GetWindowSizeY(pMsg->hWin) - pBm->YSize) / 2;
      12. GUI_DrawBitmap(pBm, xPos, yPos); // And draw always the same bitmap here
      Display All


      Sven
      Please read the forum rules before posting.

      Keep in mind, this is *not* a support forum.
      Our engineers will try to answer your questions between their projects if possible but this can be delayed by longer periods of time.
      Should you be entitled to support you can contact us via our support system: segger.com/ticket/

      Or you can contact us via e-mail.