Multiple queries regarding BUTTON

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

  • Multiple queries regarding BUTTON

    Hello all,

    I am a newbie in emWin library. I have installed Visual Studio 2015 and with the help of GUIBuilder tool, created a simple dialog with a button.
    I am trying to experiment actions on various button states like enabled, disabled, mouse hover, mouse clicked.
    For enabled and button clicked, I successfully tried using BUTTON_SKINPROPS_PRESSED.

    But for disabled and mouse hover, I haven't succeeded yet.
    Tried multiple options - BUTTON_SetFocussable(hButton, 0); or BUTTON_SKINFLEX_PI_DISABLED option.

    Could anyone please help me with a sample code snippet on how to set a button in disabled state and how to implement mouse hover action on a button?
    Looking forward to your valuable response


    Thanking you in advance,

    Lullaby
  • Hi Lullaby,

    Try the following code. There I set a diffrent skin if the mouse hovers over the button. The general style of the button keeps the same, only the colors are changing. For a disable button just uncomment the code at the end of the MainTask().

    C Source Code

    1. #include "DIALOG.h"
    2. /*********************************************************************
    3. *
    4. * Local code
    5. *
    6. **********************************************************************
    7. */
    8. /*********************************************************************
    9. *
    10. * _cbButton
    11. */
    12. static void _cbButton(WM_MESSAGE * pMsg) {
    13. BUTTON_SKINFLEX_PROPS Props;
    14. static BUTTON_SKINFLEX_PROPS DefaultProps;
    15. static int Once;
    16. GUI_RECT Rect;
    17. static int MouseOver;
    18. if (Once == 0) {
    19. //
    20. // Get the default button properties, but only once
    21. //
    22. BUTTON_GetSkinFlexProps(&DefaultProps, BUTTON_SKINFLEX_PI_ENABLED);
    23. Once = 1;
    24. }
    25. switch(pMsg->MsgId) {
    26. case WM_PAINT:
    27. //
    28. // Handle the drawing by the default callback of the button
    29. //
    30. BUTTON_Callback(pMsg);
    31. //
    32. // Get the area of the button to display some text centered in it
    33. //
    34. WM_GetClientRect(&Rect);
    35. GUI_SetTextMode(GUI_TM_TRANS);
    36. GUI_SetColor(GUI_BLACK);
    37. //
    38. // Check if mouse is inside button area or not, display proper text
    39. //
    40. if (MouseOver) {
    41. GUI_DispStringInRect("Mouse over button", &Rect, GUI_TA_HCENTER | GUI_TA_VCENTER);
    42. } else {
    43. GUI_DispStringInRect("Mouse not over button", &Rect, GUI_TA_HCENTER | GUI_TA_VCENTER);
    44. }
    45. break;
    46. case WM_MOUSEOVER:
    47. //
    48. // Configure the properties and set them, but only on the first time the mouse gets inside the button area
    49. //
    50. if (MouseOver == 0) {
    51. Props = DefaultProps;
    52. Props.aColorFrame[0] = GUI_DARKRED;
    53. Props.aColorFrame[1] = GUI_RED;
    54. BUTTON_SetSkinFlexProps(&Props, BUTTON_SKINFLEX_PI_ENABLED);
    55. BUTTON_SetSkinFlexProps(&Props, BUTTON_SKINFLEX_PI_FOCUSSED);
    56. //
    57. // Tell the button something has changed and trigger a redraw
    58. //
    59. WM_Invalidate(pMsg->hWin);
    60. }
    61. //
    62. // Set the mouseover flag
    63. //
    64. MouseOver = 1;
    65. break;
    66. case WM_MOUSEOVER_END:
    67. //
    68. // Set back to default properties
    69. //
    70. if (MouseOver == 1) {
    71. BUTTON_SetSkinFlexProps(&DefaultProps, BUTTON_SKINFLEX_PI_ENABLED);
    72. BUTTON_SetSkinFlexProps(&DefaultProps, BUTTON_SKINFLEX_PI_FOCUSSED);
    73. //
    74. // Tell the button something has changed and trigger a redraw
    75. //
    76. WM_Invalidate(pMsg->hWin);
    77. }
    78. //
    79. // Set the mouseover flag
    80. //
    81. MouseOver = 0;
    82. break;
    83. default:
    84. //
    85. // Any messages not handled by this callback are getting passed to the default callback of the button
    86. //
    87. BUTTON_Callback(pMsg);
    88. break;
    89. }
    90. }
    91. /*********************************************************************
    92. *
    93. * Public code
    94. *
    95. **********************************************************************
    96. */
    97. /*********************************************************************
    98. *
    99. * MainTask
    100. */
    101. void MainTask(void) {
    102. WM_HWIN hButton;
    103. BUTTON_SKINFLEX_PROPS Props;
    104. #if WIN32
    105. WM_SetCreateFlags(WM_CF_MEMDEV); // Automatic use of memory devices only in simulation, on hardware multibuffering should be used
    106. #endif
    107. //
    108. // Initialize GUI
    109. //
    110. GUI_Init();
    111. //
    112. // Set a BK color for the desktop window
    113. //
    114. WM_SetBkWindowColor(GUI_BLACK);
    115. //
    116. // Create a button and set a callback
    117. //
    118. hButton = BUTTON_CreateAsChild(10, 10, 150, 150, WM_HBKWIN, 0, WM_CF_SHOW);
    119. WM_SetCallback(hButton, _cbButton);
    120. //
    121. // Uncomment the code below to see what is happening for a disabled button
    122. //
    123. /*
    124. //
    125. // Fill Props structure
    126. //
    127. BUTTON_GetSkinFlexProps(&Props, BUTTON_SKINFLEX_PI_DISABLED);
    128. //
    129. // Re-set some values
    130. //
    131. Props.aColorFrame[0] = GUI_DARKGREEN;
    132. Props.aColorFrame[1] = GUI_GREEN;
    133. //
    134. // Set properties again and disable button
    135. //
    136. BUTTON_SetSkinFlexProps(&Props, BUTTON_SKINFLEX_PI_DISABLED);
    137. WM_DisableWindow(hButton);
    138. */
    139. while (1) {
    140. GUI_Delay(100);
    141. }
    142. }
    Display All


    Regards,
    Sven
    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.