Tuesday, May 22nd 2018, 10:04am UTC+2

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.

himsha

Beginner

Date of registration: Feb 21st 2018

Posts: 12

1

Thursday, March 1st 2018, 9:52am

text click acknowledgement

i had created text as a child with below syntax. how to create text touch acknowledgement?

hText = TEXT_CreateAsChild(75, 25, 400, 100, WM_HBKWIN, 0, WM_CF_SHOW, ForceTextCall, GUI_TA_LEFT | GUI_TA_VCENTER);

SEGGER - Schoenen

Super Moderator

Date of registration: Aug 13th 2015

Posts: 584

2

Thursday, March 1st 2018, 2:42pm

Hi,

Please note that the TEXT widget does not react on touch normally. Alos, this means that it will send no message to its parent window regarding touch input.

But you can add reacting on touch manually. Add the code from 'case WM_TOUCH' to your TEXT widget callback 'ForceTextCallback'.

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

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

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

/*********************************************************************
*
*   	Static data
*
**********************************************************************
*/
/*********************************************************************
*
*   	_aDialogCreate
*/
static const GUI_WIDGET_CREATE_INFO _aDialogCreate[] = {
  { WINDOW_CreateIndirect, "Window", ID_WINDOW_0, 0, 0, 320, 240, 0, 0x0, 0 },
  { TEXT_CreateIndirect, "Click On Text", ID_TEXT_0, 20, 60, 120, 30, 0, 0x0, 0 },
};

/*********************************************************************
*
*   	Static code
*
**********************************************************************
*/
/*********************************************************************
*
*   	_cbText
*/
static void _cbText(WM_MESSAGE * pMsg) {
  GUI_PID_STATE * pState;
  static int  	Pressed;
  WM_MESSAGE  	Message;

  switch (pMsg->MsgId) {
  case WM_TOUCH:
	pState = (GUI_PID_STATE *)pMsg->Data.p;
	if (pState) {
  	if (pState->Pressed) {
    	if (Pressed == 0) {
      	Message.Data.v = WM_NOTIFICATION_CLICKED;
      	Message.hWinSrc = pMsg->hWin;
      	Message.MsgId = WM_NOTIFY_PARENT;
      	WM_SendMessage(WM_GetParent(pMsg->hWin), &Message);
    	}
    	Pressed = 1;
  	} else if (Pressed) {
    	Pressed = 0;
    	Message.Data.v = WM_NOTIFICATION_RELEASED;
    	Message.hWinSrc = pMsg->hWin;
    	Message.MsgId = WM_NOTIFY_PARENT;
    	WM_SendMessage(WM_GetParent(pMsg->hWin), &Message);
  	}
	}
	break;
  default:
	TEXT_Callback(pMsg);
	break;
  }
}

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

  switch (pMsg->MsgId) {
  case WM_INIT_DIALOG:
	//
	// Initialization of 'Window'
	//
	hItem = pMsg->hWin;
	WINDOW_SetBkColor(hItem, GUI_MAKE_COLOR(0x004080FF));
	//
	// Initialization of 'Click On Text'
	//
	hItem = WM_GetDialogItem(pMsg->hWin, ID_TEXT_0);
	TEXT_SetTextAlign(hItem, GUI_TA_HCENTER | GUI_TA_VCENTER);
	TEXT_SetFont(hItem, GUI_FONT_20_1);
	//
	// Set a callback for the text widget to react on touch
	//
	WM_SetCallback(hItem, _cbText);
	break;
  case WM_NOTIFY_PARENT:
	Id	= WM_GetId(pMsg->hWinSrc);
	NCode = pMsg->Data.v;
	switch (Id) {
	case ID_TEXT_0:
  	switch (NCode) {
  	case WM_NOTIFICATION_CLICKED:
    	WINDOW_SetBkColor(pMsg->hWin, GUI_MAKE_COLOR(0x00FF8004));
    	break;
  	case WM_NOTIFICATION_RELEASED:
    	WINDOW_SetBkColor(pMsg->hWin, GUI_MAKE_COLOR(0x004080FF));
    	break;
  	}
  	break;
	}
	break;
  default:
	WM_DefaultProc(pMsg);
	break;
  }
}

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

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


Regards
Sven

himsha

Beginner

Date of registration: Feb 21st 2018

Posts: 12

3

Tuesday, March 6th 2018, 2:21pm

thanks for the code but is it not possible to create TEXT_CreateAsChild and than create touch acknowledgement?

SEGGER - Schoenen

Super Moderator

Date of registration: Aug 13th 2015

Posts: 584

4

Tuesday, March 6th 2018, 4:48pm

Hi,

Simply call one of the TEXT create functions, like TEXT_CreateEx() and set the callback function _cbText() from my example.

To set the callback function call WM_SetCallback() with the handle of the TEXT widget and the function as parameter.

Regards
Sven