FRAMEWIN - Custom (Sample)

From SEGGER Wiki
Jump to: navigation, search
FRAMEWIN_Custom.c
FRAMEWIN Custom.png
File(s) required
  • FRAMEWIN_Custom.c
Runs in simulation Yes
Runs on target Yes
Download FRAMEWIN_Custom.c

This sample demonstrates custom drawing of a FRAMEWIN widget.

Code

/*********************************************************************
*                    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        : FRAMEWIN_Custom.c
Purpose     : Sample that demonstrates how to draw a FRAMEWIN widget
              yourself using a skinning routine in emWin.
Requirements: WindowManager - (x)
              MemoryDevices - ( )
              AntiAliasing  - ( )
              VNC-Server    - ( )
              PNG-Library   - ( )
              TrueTypeFonts - ( )
---------------------------END-OF-HEADER------------------------------
*/

#include "DIALOG.h"

/*********************************************************************
*
*       Defines
*
**********************************************************************
*/

#define ID_FRAMEWIN 0

/*********************************************************************
*
*       Static code
*
**********************************************************************
*/
/*********************************************************************
*
*       _cbFramewinSkin
*/
static int _cbFramewinSkin(const WIDGET_ITEM_DRAW_INFO * pDrawItemInfo) {
  char     acBuffer[32];
  GUI_RECT Rect;

  switch (pDrawItemInfo->Cmd) {
  case WIDGET_ITEM_CREATE:
    //
    // Do something immediately after creation of the widget
    // Only useful if this skinning routine is set as default for all framewin widgets.
    //
    return FRAMEWIN_DrawSkinFlex(pDrawItemInfo);
  case WIDGET_ITEM_DRAW_BACKGROUND:
    //
    // Draw background of title
    //
    GUI_DrawGradientH(pDrawItemInfo->x0, pDrawItemInfo->y0, pDrawItemInfo->x1, pDrawItemInfo->y1, GUI_BLUE, GUI_GREEN);
    return 0;
  case WIDGET_ITEM_DRAW_FRAME:
    //
    // Draw frame
    //
    GUI_SetColor(GUI_BLACK);
    GUI_SetPenSize(2);
    GUI_DrawRect(pDrawItemInfo->x0 + 3, pDrawItemInfo->y0, pDrawItemInfo->x1 - 3, pDrawItemInfo->y1 - 2);
    return 0;
  case WIDGET_ITEM_DRAW_SEP:
    //
    // Draw separator
    //
    GUI_SetColor(GUI_BLACK);
    GUI_DrawHLine(pDrawItemInfo->y0, pDrawItemInfo->x0, pDrawItemInfo->x1);
    return 0;
  case WIDGET_ITEM_DRAW_TEXT:
    //
    // Draw title text
    //
    Rect.x0 = pDrawItemInfo->x0;
    Rect.x1 = pDrawItemInfo->x1;
    Rect.y0 = pDrawItemInfo->y0;
    Rect.y1 = pDrawItemInfo->y1;
    FRAMEWIN_GetText(pDrawItemInfo->hWin, acBuffer, sizeof(acBuffer));
    GUI_SetTextMode(GUI_TM_TRANS);
    GUI_SetColor(GUI_WHITE);
    GUI_DispStringInRect(acBuffer, &Rect, GUI_TA_CENTER);
    return 0;
  case WIDGET_ITEM_GET_BORDERSIZE_L:
    //
    // Return left border size
    //
    return FRAMEWIN_DrawSkinFlex(pDrawItemInfo);
  case WIDGET_ITEM_GET_BORDERSIZE_R:
    //
    // Return right border size
    //
    return FRAMEWIN_DrawSkinFlex(pDrawItemInfo);
  case WIDGET_ITEM_GET_BORDERSIZE_T:
    //
    // Return top border size
    //
    return FRAMEWIN_DrawSkinFlex(pDrawItemInfo);
  case WIDGET_ITEM_GET_BORDERSIZE_B:
    //
    // Return bottom border size
    //
    return FRAMEWIN_DrawSkinFlex(pDrawItemInfo);
  case WIDGET_ITEM_GET_RADIUS:
    //
    // Return radius of the corners
    //
    return FRAMEWIN_DrawSkinFlex(pDrawItemInfo);
  default:
    return FRAMEWIN_DrawSkinFlex(pDrawItemInfo);
  }
}

/*********************************************************************
*
*       Public code
*
**********************************************************************
*/
/*********************************************************************
*
*       MainTask
*/
void MainTask(void) {
  FRAMEWIN_Handle hFrame;

  //
  // Init GUI
  //
  GUI_Init();
  //
  // Enable multi-buffering to avoid flickering during movement of a framewin
  //
  WM_MULTIBUF_Enable(1);
  //
  // Set desktop color so that the background window will be cleared.
  //
  WM_SetDesktopColor(GUI_WHITE);
  //
  // Create FRAMEWIN with user callback
  //
  hFrame = FRAMEWIN_CreateEx(10, 10, 250, 150, WM_HBKWIN, WM_CF_SHOW, FRAMEWIN_CF_MOVEABLE, ID_FRAMEWIN, "Sample Framewin", NULL);
  //
  // Set skinning routine
  //
  FRAMEWIN_SetSkin(hFrame, _cbFramewinSkin);

  while (1) {
    GUI_Delay(100);
  }
}

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