Thursday, April 26th 2018, 7:07pm UTC+2

You are not logged in.

  • Login
  • Register

Date of registration: Nov 30th 2017

Posts: 13

1

Tuesday, March 27th 2018, 9:31am

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?

SEGGER - Schoenen

Super Moderator

Date of registration: Aug 13th 2015

Posts: 562

2

Thursday, March 29th 2018, 3:07pm

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

Date of registration: Nov 30th 2017

Posts: 13

3

Friday, March 30th 2018, 7:35pm

Hi Schoenen thanks for your reply I will give it a try. :)

Date of registration: Nov 30th 2017

Posts: 13

4

Monday, April 2nd 2018, 7:04am

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
Adding GUI_Clear() also not solving the problem.

Selso

Beginner

Date of registration: Jul 19th 2017

Posts: 22

5

Tuesday, April 3rd 2018, 3:48pm

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 ?

SEGGER - Schoenen

Super Moderator

Date of registration: Aug 13th 2015

Posts: 562

6

Wednesday, April 4th 2018, 9:50am

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
SEGGER - Schoenen has attached the following file:

Date of registration: Nov 30th 2017

Posts: 13

7

Thursday, April 5th 2018, 6:25am

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.

SEGGER - Schoenen

Super Moderator

Date of registration: Aug 13th 2015

Posts: 562

8

Thursday, April 5th 2018, 9:38am

Hi,

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

C/C++ Source code

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


Sven

Selso

Beginner

Date of registration: Jul 19th 2017

Posts: 22

9

Thursday, April 5th 2018, 7:43pm

As an alternative the WINDOW_SetBkColor() function could be used ?

Date of registration: Nov 30th 2017

Posts: 13

10

Tuesday, April 17th 2018, 11:12am

Unfortunately that example also not helping out. Once any window(in this case child window) comes on top that button background is changing to black automatically.