Saturday, February 24th 2018, 2:46am UTC+1

You are not logged in.

  • Login
  • Register

Dear visitor, welcome to SEGGER Forum. If this is your first visit here, please read the Help. It explains how this page works. You must be registered before you can use all the page's features. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

mastupristi

Beginner

Date of registration: Feb 18th 2016

Posts: 21

1

Sunday, February 11th 2018, 10:10pm

TEXT widget does not draw text

ho have a custom widget that is a window whit a TEXT widget child. here is the source code:

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
#include "CogWheelWidget.h"

#include <string.h>
#include "GUI.h"
#include "WM.h"
#include "TEXT.h"

#include "GuiLocal.h"

static GUI_CONST_STORAGE unsigned long _acCogWheel[] = {
  0xFF000000, 0xFF000000, 0xF7FF0000, 0xD1FF0000, 0xFF000000, 0x74FF0000, 0x74FF0000, 0xFF000000, 0xD1FF0000, 0xF7FF0000, 0xFF000000, 0xFF000000,
  0xFF000000, 0xFF000000, 0xC7FF0000, 0x07FF0000, 0xD0FF0000, 0x4FFF0000, 0x4FFF0000, 0xD0FF0000, 0x07FF0000, 0xC7FF0000, 0xFF000000, 0xFF000000,
  0xF7FF0000, 0xC7FF0000, 0xFDFF0000, 0x2AFF0000, 0x00FF0000, 0x00FF0000, 0x00FF0000, 0x00FF0000, 0x2AFF0000, 0xFDFF0000, 0xC7FF0000, 0xF7FF0000,
  0xD1FF0000, 0x06FF0000, 0x2AFF0000, 0x00FF0000, 0x34FF0000, 0x99FF0000, 0x99FF0000, 0x33FF0000, 0x00FF0000, 0x2AFF0000, 0x06FF0000, 0xD1FF0000,
  0xFF000000, 0xD0FF0000, 0x01FF0000, 0x34FF0000, 0xFAFF0000, 0xFF000000, 0xFF000000, 0xFAFF0000, 0x33FF0000, 0x01FF0000, 0xD0FF0000, 0xFF000000,
  0x75FF0000, 0x4EFF0000, 0x00FF0000, 0x99FF0000, 0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000, 0x98FF0000, 0x00FF0000, 0x4EFF0000, 0x75FF0000,
  0x75FF0000, 0x4EFF0000, 0x00FF0000, 0x99FF0000, 0xFF000000, 0xFF000000, 0xFF000000, 0xFF000000, 0x98FF0000, 0x00FF0000, 0x4EFF0000, 0x75FF0000,
  0xFF000000, 0xD0FF0000, 0x01FF0000, 0x33FF0000, 0xFAFF0000, 0xFF000000, 0xFF000000, 0xFAFF0000, 0x32FF0000, 0x01FF0000, 0xD0FF0000, 0xFF000000,
  0xD1FF0000, 0x06FF0000, 0x2AFF0000, 0x00FF0000, 0x33FF0000, 0x98FF0000, 0x98FF0000, 0x32FF0000, 0x00FF0000, 0x2AFF0000, 0x06FF0000, 0xD1FF0000,
  0xF7FF0000, 0xC7FF0000, 0xFDFF0000, 0x2AFF0000, 0x00FF0000, 0x00FF0000, 0x00FF0000, 0x00FF0000, 0x2AFF0000, 0xFDFF0000, 0xC7FF0000, 0xF7FF0000,
  0xFF000000, 0xFF000000, 0xC7FF0000, 0x07FF0000, 0xD0FF0000, 0x4FFF0000, 0x4FFF0000, 0xD0FF0000, 0x07FF0000, 0xC7FF0000, 0xFF000000, 0xFF000000,
  0xFF000000, 0xFF000000, 0xF7FF0000, 0xD1FF0000, 0xFF000000, 0x74FF0000, 0x74FF0000, 0xFF000000, 0xD1FF0000, 0xF7FF0000, 0xFF000000, 0xFF000000
};

GUI_CONST_STORAGE GUI_BITMAP bmCogWheel = {
  12, // xSize
  12, // ySize
  48, // BytesPerLine
  32, // BitsPerPixel
  (unsigned char *)_acCogWheel,  // Pointer to picture data
  NULL,  // Pointer to palette
  GUI_DRAW_BMP8888
};

typedef struct COGWHEELWIDGET_Obj_s
{
	TEXT_Handle	hText;
	char		strText[20];
}COGWHEELWIDGET_Obj;


COGWHEELWIDGET_Handle COGWHEELWIDGET_Create(int x0, int y0, int xSize, int ySize,
		WM_HWIN hWinParent, U32 Style, WM_CALLBACK * pfCallback)
{
	WM_HWIN hWin;
	WM_CALLBACK * pfUsed;

	if (pfCallback)
	{
		pfUsed = pfCallback;
	}
	else
	{
		pfUsed = COGWHEELWIDGET_Callback;
	}

	hWin = WM_CreateWindowAsChild(x0, y0, xSize, ySize, hWinParent,
					Style, pfUsed, sizeof(COGWHEELWIDGET_Obj *));

	return hWin;
}

/* defined only to put a break point into WM_PAINT */
void _cbcb(WM_MESSAGE * pMsg)
{
	switch (pMsg->MsgId)
	{
	case WM_PAINT:
    	TEXT_Callback(pMsg); // breakpoint here is never triggered
		break;
	default:
    	TEXT_Callback(pMsg);
    	break;
	}
}

void COGWHEELWIDGET_Callback(WM_MESSAGE * pMsg)
{
	WM_HWIN hWin;
	hWin = pMsg->hWin;
	COGWHEELWIDGET_Obj *CogWheelWidgetObj;

	switch (pMsg->MsgId)
	{
	case MESSAGE_SETTEXT:
		WM_GetUserData(hWin, &CogWheelWidgetObj, sizeof(COGWHEELWIDGET_Obj *));
		strncpy(CogWheelWidgetObj->strText, (const char *)pMsg->Data.p, PAGE_TITLE_STRLEN); // non necessario
		CogWheelWidgetObj->strText[20-1] = '\0';
		TEXT_SetText(CogWheelWidgetObj->hText, CogWheelWidgetObj->strText);
		break;

	case WM_CREATE:
		{
			CogWheelWidgetObj = (COGWHEELWIDGET_Obj *)MALLOC(sizeof(COGWHEELWIDGET_Obj));
			CogWheelWidgetObj->hText = TEXT_CreateEx(159 - 50, 0, 50, 13, hWin, WM_CF_SHOW | WM_CF_MEMDEV, TEXT_CF_VCENTER | TEXT_CF_LEFT, GUI_ID_TEXT0, "");
			TEXT_SetTextColor(CogWheelWidgetObj->hText, GUI_BLUE);
			TEXT_SetBkColor(CogWheelWidgetObj->hText, GUI_BLACK);
			WM_SetCallback(CogWheelWidgetObj->hText, _cbcb);
			WM_SetUserData(hWin, &CogWheelWidgetObj, sizeof(COGWHEELWIDGET_Obj *));
		}
		break;

	case WM_DELETE:
		WM_GetUserData(hWin, &CogWheelWidgetObj, sizeof(COGWHEELWIDGET_Obj *));
		FREE(CogWheelWidgetObj);
		CogWheelWidgetObj = NULL;
		WM_SetUserData(hWin, &CogWheelWidgetObj, sizeof(COGWHEELWIDGET_Obj *));
		break;

	case WM_PAINT:
		{
			GUI_RECT Rect;
			WM_GetInsideRect(&Rect);
			GUI_SetBkColor(GUI_TRANSPARENT);
			GUI_ClearRectEx(&Rect);
			GUI_DrawBitmap(&bmCogWheel, WM_GetWindowSizeX(hWin) - bmCogWheel.XSize - 1, 1);
		}
		break;

	default:
		WM_DefaultProc(pMsg);
	}
}

void COGWHEELWIDGET_SetText(COGWHEELWIDGET_Handle hWin, const char *title)
{
	WM_MESSAGE pMsgS;
	pMsgS.MsgId = MESSAGE_SETTEXT;
	pMsgS.hWin = hWin;
	pMsgS.Data.p = title;

	WM_SendMessage(hWin, &pMsgS);
}



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
34
35
#include "GUI.h"
#include "CogWheelWidget.h"
#include "TEXT.h"
#include <stdio.h>


void MainTask(void)
{
  GUI_Init();

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

  COGWHEELWIDGET_Handle hWin;

  hWin = COGWHEELWIDGET_Create(10, 10, 60, 14, WM_HBKWIN, WM_CF_HIDE | WM_CF_HASTRANS, NULL);

  COGWHEELWIDGET_SetText(hWin, "gear");
  WM_ShowWindow(hWin);

  TEXT_Handle hText;
  hText = TEXT_CreateEx(10, 24, 60, 14, WM_HBKWIN, WM_CF_HIDE | WM_CF_HASTRANS, TEXT_CF_VCENTER | TEXT_CF_LEFT, GUI_ID_TEXT0, "");
  TEXT_SetBkColor(hText, GUI_TRANSPARENT);
  TEXT_SetTextColor(hText, GUI_BLUE);
  TEXT_SetText(hText, "text");
  WM_ShowWindow(hText);

  WM_PaintWindowAndDescs(WM_HBKWIN); // try but does not solve

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


the result is:



I cannot figure out why the TEXT widget called directly works, and, instead, the one nested into anothe window does not. It seems that WM_PAINT for the inner TEXT widget is never send.
Where am I wrong? How to make it works?

best regards
Max

mastupristi

Beginner

Date of registration: Feb 18th 2016

Posts: 21

2

Monday, February 12th 2018, 2:56pm

[SOLVED] TEXT widget does not draw text

The inner text widget was placed outside its parent area.

I apologise for my haste in writing the previous post.

best regards
Max