/*********************************************************************
*                    SEGGER Microcontroller GmbH                     *
*        Solutions for real time microcontroller applications        *
**********************************************************************
*                                                                    *
*        (c) 1996 - 2020  SEGGER Microcontroller GmbH                *
*                                                                    *
*        Internet: www.segger.com    Support:  support@segger.com    *
*                                                                    *
**********************************************************************

** emWin V6.10 - Graphical user interface for embedded applications **
emWin is protected by international copyright laws.   Knowledge of the
source code may not be used to write a similar product.  This file may
only  be used  in accordance  with  a license  and should  not be  re-
distributed in any way. We appreciate your understanding and fairness.
----------------------------------------------------------------------
File        : GUI_Tutorial_CustomizingWindows.c
Purpose     : Code of the wiki tutorial on customizing windows in emWin.
Requirements: WindowManager - (x)
              MemoryDevices - ( )
              AntiAliasing  - ( )
              VNC-Server    - ( )
              PNG-Library   - ( )
              TrueTypeFonts - ( )
---------------------------END-OF-HEADER------------------------------
*/

#include "DIALOG.h"

/*********************************************************************
*
*       Defines
*
**********************************************************************
*/

/*********************************************************************
*
*       Static data
*
**********************************************************************
*/

/*********************************************************************
*
*       Static code
*
**********************************************************************
*/
/*********************************************************************
*
*       _cbWin
*/
static void _cbWin(WM_MESSAGE * pMsg) {
  WM_PID_STATE_CHANGED_INFO * pInfo;
  static int                  Pressed;

  switch(pMsg->MsgId) {
  case WM_PAINT:
    if(Pressed) {
      GUI_SetBkColor(GUI_GREEN);
    } else {
      GUI_SetBkColor(GUI_RED);
    }
    GUI_Clear();
    break;
  case WM_PID_STATE_CHANGED:
    //
    // Save pressed state.
    //
    pInfo   = (WM_PID_STATE_CHANGED_INFO *)pMsg->Data.p;
    Pressed = pInfo->State;
    //
    // Redraw this window.
    //
    WM_InvalidateWindow(pMsg->hWin);
    break;
  default:
    WM_DefaultProc(pMsg);
  }
}

/*********************************************************************
*
*       Public code
*
**********************************************************************
*/
/*********************************************************************
*
*       MainTask
*/
void MainTask(void) {  
  //
  // Init GUI.
  //
  GUI_Init();
  //
  // Create window.
  //
  WM_CreateWindowAsChild(0, 0, 100, 100, WM_HBKWIN, WM_CF_SHOW, _cbWin, 0);

  //
  // When calling the delay routine, GUI_Exec() is called which executes emWin operations.
  //
  while (1) {
    GUI_Delay(100);
  }
}

/*************************** End of file ****************************/