Monday, February 19th 2018, 8:14pm UTC+1

You are not logged in.

  • Login
  • Register

mastupristi

Beginner

Date of registration: Feb 18th 2016

Posts: 19

1

Thursday, February 8th 2018, 11:05pm

LISTWHEEL with semitransparent background

How can I get the selected item of a LISTWHEEL item to have a semi-transparent background color?

I tried this:

C/C++ Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include "GUI.h"
#include "LISTWHEEL.h"
#include <stdio.h>

const char *pList[] =
{
	"1st",
	"2nd",
	"3rd",
	"4th",
	NULL,
};

void MainTask(void)
{
  GUI_Init();

//  GUI_EnableAlpha(1);
  GUI_SetBkColor(GUI_WHITE);
  GUI_Clear();

  GUI_DrawGradientV(13, 5, 70, 65, GUI_YELLOW, GUI_GREEN);
  LISTWHEEL_Handle hWin;

  hWin = LISTWHEEL_CreateEx(10, 10, 50, 45, WM_HBKWIN, WM_CF_SHOW | WM_CF_HASTRANS, 0, GUI_ID_LISTWHEEL0, pList);
  LISTWHEEL_SetBkColor(hWin, LISTWHEEL_CI_SEL, GUI_MAKE_COLOR((0x70uL << 24) | 0x0000FF));
  LISTWHEEL_SetBkColor(hWin, LISTWHEEL_CI_UNSEL, GUI_TRANSPARENT);

  while(1)
  {
   	GUI_Delay(100);
  }
}


and the result is:



instead, I can get the text semi-transparent if I try to get it.

best regards
Max

SEGGER - Schoenen

Super Moderator

Date of registration: Aug 13th 2015

Posts: 491

2

Wednesday, February 14th 2018, 3:27pm

Hi,

Unfortunately, it is not that easy.

If the LISTWHEEL gets created with the transparency flag set it will be completely transparent and does not fill its background.

If you want a semi transparent background you have to set a owner draw function. Within that owner draw function you check for the item which background should be drawn. Then call GUI_EnableAlpha(1) to enable the use of the alpha bits of a color, perform a clear, and disable the use of the alpha bits again. After that call LISTWHEEL_OwnerDraw() to draw the rest of the widget.

Here is an example on you this can be achieved.

C/C++ Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#include "DIALOG.h"

/*********************************************************************
*
*   	Externals
*
**********************************************************************
*/

/*********************************************************************
*
*   	Defines
*
**********************************************************************
*/
#define ID_WINDOW_0   	(GUI_ID_USER + 0x00)
#define ID_LISTWHEEL_0	(GUI_ID_USER + 0x01)

/*********************************************************************
*
*   	Static data
*
**********************************************************************
*/
/*********************************************************************
*
*   	_aDialogCreate
*/
static const GUI_WIDGET_CREATE_INFO _aDialogCreate[] = {
  { WINDOW_CreateIndirect,	"Window",	ID_WINDOW_0,  	0,  0, 480, 272, 0, 0x0, 0 },
  { LISTWHEEL_CreateIndirect, "Listwheel", ID_LISTWHEEL_0, 200, 20,  80, 120, 0, 0x0, 0 },
};

/*********************************************************************
*
*   	Static code
*
**********************************************************************
*/
/*********************************************************************
*
*   	_OwnerDraw
*/
static int _OwnerDraw(const WIDGET_ITEM_DRAW_INFO * pDrawItemInfo) {
  switch (pDrawItemInfo->Cmd) {
  case WIDGET_ITEM_DRAW:
	//
	// Check if the current item is the selected
	//
	if (pDrawItemInfo->ItemIndex == LISTWHEEL_GetSel(pDrawItemInfo->hWin)) {
  	//
  	// Enable alpha, the upper 8 bits (most significant) will be taken into account
  	//
  	GUI_EnableAlpha(1);
  	//
  	// Get LISTWHEEL color and set it as current bk color
  	//
  	GUI_SetBkColor(LISTWHEEL_GetBkColor(pDrawItemInfo->hWin, LISTWHEEL_CI_SEL));
  	//
  	// Clear item area with the color
  	//
  	GUI_ClearRect(pDrawItemInfo->x0, pDrawItemInfo->y0, pDrawItemInfo->x1, pDrawItemInfo->y1);
  	//
  	// Disable alpha again.
  	//
  	GUI_EnableAlpha(0);
	}
	return LISTWHEEL_OwnerDraw(pDrawItemInfo);
  case WIDGET_ITEM_DRAW_BACKGROUND:
	return LISTWHEEL_OwnerDraw(pDrawItemInfo);
  default:
	return LISTWHEEL_OwnerDraw(pDrawItemInfo);
  }
}

/*********************************************************************
*
*   	_cbDialog
*/
static void _cbDialog(WM_MESSAGE * pMsg) {
  WM_HWIN  hItem;
  int  	NCode;
  int  	Id;
  GUI_RECT Rect;

  switch (pMsg->MsgId) {
  case WM_INIT_DIALOG:
	//
	// Initialization of 'Listwheel'
	//
	hItem = WM_GetDialogItem(pMsg->hWin, ID_LISTWHEEL_0);
	LISTWHEEL_AddString(hItem, "String0");
	LISTWHEEL_AddString(hItem, "String1");
	LISTWHEEL_AddString(hItem, "String2");
	LISTWHEEL_AddString(hItem, "String3");
	LISTWHEEL_AddString(hItem, "String4");
	LISTWHEEL_AddString(hItem, "String5");
	LISTWHEEL_AddString(hItem, "String6");
	LISTWHEEL_AddString(hItem, "String7");
	LISTWHEEL_AddString(hItem, "String8");
	LISTWHEEL_AddString(hItem, "String9");
	LISTWHEEL_AddString(hItem, "String10");

	WM_SetHasTrans(hItem);                  	// Same as if created with WM_CF_HASTRANS
	LISTWHEEL_SetOwnerDraw(hItem, _OwnerDraw);  // Set a owner draw
	LISTWHEEL_SetBkColor(hItem, LISTWHEEL_CI_SEL, GUI_MAKE_COLOR((0x70uL << 24) | 0x0000FF));
	LISTWHEEL_SetBkColor(hItem, LISTWHEEL_CI_UNSEL, GUI_TRANSPARENT);

	break;
  case WM_NOTIFY_PARENT:
	Id	= WM_GetId(pMsg->hWinSrc);
	NCode = pMsg->Data.v;
	switch(Id) {
	case ID_LISTWHEEL_0: // Notifications sent by 'Listwheel'
  	switch(NCode) {
  	case WM_NOTIFICATION_CLICKED:
    	break;
  	case WM_NOTIFICATION_RELEASED:
    	break;
  	case WM_NOTIFICATION_SEL_CHANGED:
    	break;
  	}
  	break;
	}
	break;
  case WM_PAINT:
	WM_GetClientRect(&Rect);
	GUI_DrawGradientH(Rect.x0, Rect.y0, Rect.x1, Rect.y1, GUI_WHITE, GUI_BLACK);
	GUI_DrawLine(Rect.x0, Rect.y0, Rect.x1, Rect.y1);
	GUI_DrawLine(Rect.x0, Rect.y1, Rect.x1, Rect.y0);
	break;
  default:
	WM_DefaultProc(pMsg);
	break;
  }
}

/*********************************************************************
*
*   	Public code
*
**********************************************************************
*/
/*********************************************************************
*
*   	MainTask
*/
void MainTask(void) {
  GUI_Init();
  WM_MULTIBUF_Enable(1);
  GUI_CreateDialogBox(_aDialogCreate, GUI_COUNTOF(_aDialogCreate), _cbDialog, WM_HBKWIN, 0, 0);
  while (1) {
	GUI_Delay(100);
  }
}

/*************************** End of file ****************************/


Regards
Sven