2024-01-16 05:17 AM
I'm currently switching from the emWin 5 graphics library to TouchGFX and have a question.
I have an IMAGE widget that reacts to an event: 1) click (calls a function to play sound) and 2) release (calls a function to send data to change status: SET_STOP_WORK, SET_WORK).
The IMAGE widget can display 3 pictures, depending on the state, bmSTOP_WORK.png, bmPAUSE_WORK.png, bmIS_WORKING.png. To display these pictures, the function is used:
void IMAGE_SetBitmap(IMAGE_Handle hWin, const GUI_BITMAP * pBitmap);
The pBitmap pointer receives the address of the corresponding picture, depending on the state. These images are precompiled into "C code" as a separate src file.
Code Main_window:
const GUI_BITMAP *pBitmap = &bmSTOP_WORK;
// Init widget
case WM_INIT_DIALOG::
hItem = WM_GetDialogItem(pMsg->hWin, ID_IMAGE_4);
IMAGE_SetBitmap(hItem, pBitmap);
// Paint widget - update
case WM_PAINT:
hItem = WM_GetDialogItem(pMsg->hWin, ID_IMAGE_4);
IMAGE_SetBitmap(hItem, pBitmap);
Code Receive_Task:
// ...
if (rxStatus != (Status_t) fValue) {
rxStatus = (Status_t) fValue;
if (rxStatus == IS_STOP_WORK) {
pBitmap = &bmSTOP_WORK;
} else if (rxStatus == IS_PAUSE_WORK) {
pBitmap = &bmPAUSE_WORK;
} else if (rxStatus == IS_WORKING) {
pBitmap = &bmIS_WORKING;
}
}
// ...
How to implement a similar mechanism with TouchGFX?
I will appreciate your help.
2024-01-26 02:37 AM
Hello @slavaglow ,
I'm glad to hear that you are trying TouchGFX.
To start with the pictures, you need to use Dynamic Bitmaps since the bitmaps you are going to use are pre-compiled. You can read about it here .
For having different functions based on the state of the click, first you need to enable the ClickListener option under the Mixins for the image widget that you are using. The description for how to implement this can be found here .
This means that you are going to deal with a ClickEvent and the attributes of the event is available at this web page .
I hope this helps you, don't hesitate to ask more questions