How to implement? - Lower underscore and blinking, as well as blinking character

This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

  • How to implement? - Lower underscore and blinking, as well as blinking character

    Hi, Segger

    How to implement? - Lower underscore and blinking, as well as blinking character in EDIT. And the movement of the symbol and the lower support is independent of each other.


    Sorry my English is not very good, so I drew, what I need to get in the EDIT window.

    How to implement it programmatically.

    [img]https://scontent-frt3-1.xx.fbcdn.net/v/t1.0-9/22552535_1896558620356093_4505525865695238324_n.jpg?oh=f3635ca2c0454901d7b75a706f472a36&oe=5A701A24[/img]
    Images
    • Безымянный.png

      17.97 kB, 1,000×431, viewed 2,530 times

    The post was edited 1 time, last by Geryhold ().

  • Hi,

    This is not that easy, because it is necessary to overwrite the callback function of the EDIT widget and take care about the whole drawing process.

    Attached is an example on how you can overwrite the callback and achieve a blinking cursor. A blinking character independent of the cursor is even harder to achieve, but you might use the example as a starting point.

    Regards
    Sven
    Files
    Please read the forum rules before posting.

    Keep in mind, this is *not* a support forum.
    Our engineers will try to answer your questions between their projects if possible but this can be delayed by longer periods of time.
    Should you be entitled to support you can contact us via our support system: segger.com/ticket/

    Or you can contact us via e-mail.
  • SEGGER - Schoenen wrote:

    Hi,

    This is not that easy, because it is necessary to overwrite the callback function of the EDIT widget and take care about the whole drawing process.

    Attached is an example on how you can overwrite the callback and achieve a blinking cursor. A blinking character independent of the cursor is even harder to achieve, but you might use the example as a starting point.

    Regards
    Sven

    Thank you for your help. I managed to get the lower cursor flashing. I also entered a few additional variables (int16_t Cursor_Position to move the cursor, and then I will int16_t Char_Position to select the symbol and its flashing) with the type extern to transfer data from the main program.
    Look at how I moved the bottom cursor, maybe I did not do it correctly or not optimally.
    Also I can not make a choice of a symbol and its blinking. Help make the choice of the symbol and its blinking.

    C Source Code

    1. /*********************************************************************** _cbEdit*/static void _cbEdit(WM_MESSAGE * pMsg) { char acBuffer[128]; GUI_COLOR BkColor; GUI_COLOR FgColor; GUI_RECT Rect; const GUI_FONT * pFont; int Align; int xPos; int yPos; int Length; int CharIndex; WM_HTIMER hTimer; WM_HWIN hEdit; WM_HWIN hItem; int Id; static int OnOff, OnOffChar;
    2. switch (pMsg->MsgId) { case WM_TIMER: hTimer = (WM_HTIMER)pMsg->Data.v; Id = WM_GetTimerId(hTimer); switch (Id) { case ID_TIMER_CURSOR: OnOff ^= 1; WM_Invalidate(pMsg->hWin); WM_RestartTimer(hTimer, 0); break; case ID_TIMER_CHAR: OnOffChar ^= 1; WM_Invalidate(pMsg->hWin); WM_RestartTimer(hTimer, 0); break; } break; case WM_PAINT: BkColor = EDIT_GetBkColor(pMsg->hWin, EDIT_CI_ENABLED); FgColor = EDIT_GetTextColor(pMsg->hWin, EDIT_CI_ENABLED); Align = GUI_TA_HCENTER | GUI_TA_VCENTER; pFont = EDIT_GetFont(pMsg->hWin); EDIT_GetText(pMsg->hWin, acBuffer, sizeof(acBuffer));
    3. GUI_SetBkColor(BkColor); GUI_SetColor(FgColor); GUI_SetFont(pFont); GUI_Clear(); WM_GetClientRect(&Rect); GUI_DispStringInRect(acBuffer, &Rect, Align); GUI_DrawRectEx(&Rect); EDIT_GetCursorPixelPos(pMsg->hWin, &xPos, &yPos); yPos += GUI_GetFontDistY(); xPos -= 1; CharIndex = EDIT_GetCursorCharPos(pMsg->hWin); Length = GUI_GetCharDistX(acBuffer[CharIndex]); /**** Drawing Cursor and blink *******/ if (Length) { if (OnOff) { GUI_DrawHLine(yPos +5, xPos + Cursor_Position * Length, xPos + (Cursor_Position + 1) * Length - 1); GUI_DrawHLine(yPos +4, xPos + Cursor_Position * Length, xPos + (Cursor_Position + 1) * Length - 1); GUI_DrawHLine(yPos +3, xPos + Cursor_Position * Length, xPos + (Cursor_Position + 1) * Length - 1); GUI_DrawHLine(yPos +2, xPos + Cursor_Position * Length, xPos + (Cursor_Position + 1) * Length - 1); } } /**** Drawing Char and blink *******/ hEdit = WM_GetDialogItem(pMsg->hWin, ID_EDIT_0); // EDIT_SetInsertMode(hEdit, 1); //EDIT_SetBkColor (hEdit, EDIT_CI_DISABLED , GUI_GRAY); //EDIT_SetBkColor (hEdit, EDIT_CI_ENABLED , GUI_WHITE); //EDIT_SetDecMode(hItem, 1234567, 0, 9999999, 0, GUI_EDIT_NORMAL); //EDIT_SetTextColor(hEdit,EDIT_CI_ENABLED ,GUI_BLACK); //EDIT_EnableBlink(hEdit, 500, 1); //EDIT_SetCursorAtChar(hEdit, 2); sprintf(str01,"%05d", kolobok); //acBuffer[2] = 0; EDIT_SetText(hEdit, str01); //EDIT_SetTextAlign(hEdit, GUI_TA_HCENTER| GUI_TA_VCENTER); //EDIT_SetFloatMode(hEdit, 555, 0.001, 999, 2, GUI_EDIT_NORMAL | GUI_EDIT_SUPPRESS_LEADING_ZEROES); // WM_SetFocus(hEdit); if (OnOffChar) { } break; default: EDIT_Callback(pMsg); break; }}
    4. // USER END
    5. /*********************************************************************** _cbDialog*/static void _cbDialog(WM_MESSAGE * pMsg) { WM_HWIN hItem; WM_HWIN hEdit; int NCode; int Id; // USER START (Optionally insert additional variables) // USER END
    6. switch (pMsg->MsgId) { case WM_INIT_DIALOG: // // Initialization of 'Window' // hItem = pMsg->hWin; WINDOW_SetBkColor(hItem, GUI_MAKE_COLOR(0x00FF8000)); // // Initialization of 'Edit' // hItem = WM_GetDialogItem(pMsg->hWin, ID_EDIT_0); //EDIT_SetText(hItem, "0"); EDIT_SetFont(hItem, GUI_FONT_D36X48); //EDIT_SetTextAlign(hItem, GUI_TA_RIGHT | GUI_TA_VCENTER); EDIT_SetDecMode(hItem, 1234567, 0, 9999999, 0, GUI_EDIT_NORMAL); EDIT_SetTextAlign(hItem, GUI_TA_HCENTER | GUI_TA_VCENTER); //EDIT_SetFont(hItem, &GUI_Font24B_1); WM_SetCallback(hItem, _cbEdit); WM_CreateTimer(hItem, ID_TIMER_CURSOR, 600, 0); WM_CreateTimer(hItem, ID_TIMER_CHAR, 600, 0); // Timer for char // Initialization of 'KLEYMAN' // hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_0); BUTTON_SetText(hItem, "KLEYMAN"); BUTTON_SetFont(hItem, GUI_FONT_8X18); // USER START (Optionally insert additional code for further widget initialization) //hTimer1 = WM_CreateTimer(pMsg->hWin, 0, 100, 0); // 100mS INIT Timer // USER END break; /*** IT IS MY CASE***************************************/// case WM_TIMER:// hEdit = WM_GetDialogItem(pMsg->hWin, ID_EDIT_0);// // //WM_SetTransState(hEdit,WM_CF_HASTRANS);// EDIT_SetInsertMode(hEdit, 1);// EDIT_SetBkColor (hEdit, EDIT_CI_DISABLED , GUI_GRAY); // EDIT_SetBkColor (hEdit, EDIT_CI_ENABLED , GUI_WHITE); // // EDIT_SetTextColor(hEdit,EDIT_CI_ENABLED ,GUI_BLACK); // EDIT_EnableBlink(hEdit, 500, 1);// EDIT_SetCursorAtChar(hEdit, 2);// sprintf(str01,"%05d", kolobok); // EDIT_SetText(hEdit, str01);// EDIT_SetTextAlign(hEdit, GUI_TA_HCENTER| GUI_TA_VCENTER);// //EDIT_SetFloatMode(hEdit, 555, 0.001, 999, 2, GUI_EDIT_NORMAL | GUI_EDIT_SUPPRESS_LEADING_ZEROES);// WM_SetFocus(hEdit);// // // // //EDIT_SetSel(hEdit, 5, 5);// //sprintf(str01,"Z: %05d", kolobok); // //EDIT_SetText(hEdit, str01);// // GUI_Exec();// data_v = pMsg->Data.v;// WM_RestartTimer(data_v, 10);// break; /*** IT IS MY CASE***************************************/ case WM_NOTIFY_PARENT: Id = WM_GetId(pMsg->hWinSrc); NCode = pMsg->Data.v; switch(Id) { case ID_EDIT_0: // Notifications sent by 'Edit' switch(NCode) { case WM_NOTIFICATION_CLICKED: // USER START (Optionally insert code for reacting on notification message) // USER END break; case WM_NOTIFICATION_RELEASED: // USER START (Optionally insert code for reacting on notification message) // USER END break; case WM_NOTIFICATION_VALUE_CHANGED: // USER START (Optionally insert code for reacting on notification message) //hItem = WM_GetDialogItem(pMsg->hWin, ID_EDIT_0); //EDIT_SetText(hItem, "5"); // USER END break; // USER START (Optionally insert additional code for further notification handling) // USER END } break; case ID_BUTTON_0: // Notifications sent by 'KLEYMAN' switch(NCode) { case WM_NOTIFICATION_CLICKED: // USER START (Optionally insert code for reacting on notification message) // USER END break; case WM_NOTIFICATION_RELEASED: // USER START (Optionally insert code for reacting on notification message) // USER END break; // USER START (Optionally insert additional code for further notification handling) // USER END } break; case ID_BUTTON_1: // Notifications sent by 'BREZMAN' switch(NCode) { case WM_NOTIFICATION_CLICKED: // USER START (Optionally insert code for reacting on notification message) // USER END break; case WM_NOTIFICATION_RELEASED: // USER START (Optionally insert code for reacting on notification message) // USER END break; // USER START (Optionally insert additional code for further notification handling) // USER END } break; // USER START (Optionally insert additional code for further Ids) // USER END } break; // USER START (Optionally insert additional message handling) // USER END default: WM_DefaultProc(pMsg); break; }}
    7. /*********************************************************************** _cbBk*/static void _cbBk(WM_MESSAGE * pMsg) { switch (pMsg->MsgId) { case WM_PAINT: GUI_SetBkColor(GUI_BLACK); GUI_Clear(); break; default: WM_DefaultProc(pMsg); break; }}


    ..............................................................MAIN CODE
    .........................
    while (1) { GUI_Delay(100); Cursor_Position=3; }
    Files
    • WindowDLG.zip

      (2.75 kB, downloaded 2,320 times, last: )
    • WindowDLG.zip

      (301 Byte, downloaded 2,319 times, last: )