SPINBOX - Custom (Sample)

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

This sample demonstrates custom drawing of a SPINBOX widget.

Demo

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        : SPINBOX_Custom.c
Purpose     : Sample that demonstrates the custom drawing of a
              SPINBOX widget in emWin.
Requirements: WindowManager - (x)
              MemoryDevices - ( )
              AntiAliasing  - ( )
              VNC-Server    - ( )
              PNG-Library   - ( )
              TrueTypeFonts - ( )
---------------------------END-OF-HEADER------------------------------
*/

#include "DIALOG.h"

/*********************************************************************
*
*       Static data
*
**********************************************************************
*/
/*********************************************************************
*
*       bmArrowUp
*/
static GUI_CONST_STORAGE unsigned char _acArrowUp[] = {
  /* ABS: 006 Pixels @ 000,000 */ 0, 6, 0xFF, 0xFF, 0xF2, 0x40, 0x40, 0xF2, 
  /* RLE: 004 Pixels @ 006,000 */ 4, 0xFF, 
  /* ABS: 024 Pixels @ 002,001 */ 0, 24, 0x2C, 0x00, 0x00, 0x2D, 0xFF, 0xFF, 0xF2, 0x2C, 0x00, 0x3C, 0x3B, 0x00, 0x2D, 0xF2, 0x3D, 0x00, 0x30, 0xF3, 0xF3, 0x2F, 0x00, 0x3E, 0x49, 0x2C, 
  /* RLE: 004 Pixels @ 002,004 */ 4, 0xFF, 
  /* ABS: 002 Pixels @ 006,004 */ 0, 2, 0x2B, 0x49, 
  0
};  // 42 bytes for 40 pixels

GUI_CONST_STORAGE GUI_BITMAP bmArrowUp = {
  8, // xSize
  5, // ySize
  8, // BytesPerLine
  GUI_COMPRESS_RLE8, // BitsPerPixel
  (const unsigned char *)_acArrowUp,  // Pointer to picture data
  NULL,  // Pointer to palette
  GUI_DRAW_RLEALPHA
};

/*********************************************************************
*
*       bmArrowDown
*/
static GUI_CONST_STORAGE unsigned char _acArrowDown[] = {
  /* ABS: 002 Pixels @ 000,000 */ 0, 2, 0x49, 0x2B, 
  /* RLE: 004 Pixels @ 002,000 */ 4, 0xFF, 
  /* ABS: 024 Pixels @ 006,000 */ 0, 24, 0x2C, 0x49, 0x3E, 0x00, 0x2F, 0xF3, 0xF3, 0x30, 0x00, 0x3D, 0xF2, 0x2D, 0x00, 0x3B, 0x3C, 0x00, 0x2C, 0xF2, 0xFF, 0xFF, 0x2D, 0x00, 0x00, 0x2C, 
  /* RLE: 004 Pixels @ 006,003 */ 4, 0xFF, 
  /* ABS: 006 Pixels @ 002,004 */ 0, 6, 0xF2, 0x40, 0x40, 0xF2, 0xFF, 0xFF, 
  0
};  // 42 bytes for 40 pixels

GUI_CONST_STORAGE GUI_BITMAP bmArrowDown = {
  8, // xSize
  5, // ySize
  8, // BytesPerLine
  GUI_COMPRESS_RLE8, // BitsPerPixel
  (const unsigned char *)_acArrowDown,  // Pointer to picture data
  NULL,  // Pointer to palette
  GUI_DRAW_RLEALPHA
};

/*********************************************************************
*
*       Static code
*
**********************************************************************
*/
/*********************************************************************
*
*       _cbSpinboxSkin
*/
static int _cbSpinboxSkin(const WIDGET_ITEM_DRAW_INFO * pDrawItemInfo) {
  switch (pDrawItemInfo->Cmd) {
  case WIDGET_ITEM_CREATE:
    //
    // We land here immediately after creation of the widget
    // Only useful if this routine is set as the default skinning routine
    //
    return 0;
  case WIDGET_ITEM_DRAW_BACKGROUND:
    //
    // Draw background of widget
    //
    GUI_DrawGradientRoundedV(pDrawItemInfo->x0, pDrawItemInfo->y0, pDrawItemInfo->x1 + 26, pDrawItemInfo->y1 / 2, 3, GUI_GRAY_9A, GUI_GRAY_C8);
    GUI_DrawGradientRoundedV(pDrawItemInfo->x0, pDrawItemInfo->y0 + (pDrawItemInfo->y1 / 2), pDrawItemInfo->x1 + 26, pDrawItemInfo->y1, 3, GUI_GRAY_C8, GUI_GRAY_9A);
    GUI_SetColor(GUI_BLACK);
    GUI_DrawRoundedRect(pDrawItemInfo->x0, pDrawItemInfo->y0, pDrawItemInfo->x1 + 26, pDrawItemInfo->y1, 3);
    return 0;
  case WIDGET_ITEM_DRAW_BUTTON_R:
    //
    // Draw upper button
    //
    GUI_SetColor(GUI_LIGHTBLUE);
    GUI_FillRoundedRect(pDrawItemInfo->x0 + 1, pDrawItemInfo->y0 + 1, pDrawItemInfo->x1 - 1, pDrawItemInfo->y1 - 1, 3);
    GUI_SetColor(GUI_BLACK);
    GUI_DrawRoundedRect(pDrawItemInfo->x0 + 1, pDrawItemInfo->y0 + 1, pDrawItemInfo->x1 - 1, pDrawItemInfo->y1 - 1, 3);

    GUI_SetTextMode(GUI_TM_TRANS);
    GUI_SetFont(&GUI_Font16B_1);
    GUI_DrawBitmap(&bmArrowUp, pDrawItemInfo->x0 + 9, pDrawItemInfo->y0 + 4);
    return 0;
  case WIDGET_ITEM_DRAW_BUTTON_L:
    //
    // Draw lower button
    //
    GUI_SetColor(GUI_LIGHTBLUE);
    GUI_FillRoundedRect(pDrawItemInfo->x0 + 1, pDrawItemInfo->y0 + 1, pDrawItemInfo->x1 - 1, pDrawItemInfo->y1 - 1, 3);
    GUI_SetColor(GUI_BLACK);
    GUI_DrawRoundedRect(pDrawItemInfo->x0 + 1, pDrawItemInfo->y0 + 1, pDrawItemInfo->x1 - 1, pDrawItemInfo->y1 - 1, 3);
    GUI_DrawBitmap(&bmArrowDown, pDrawItemInfo->x0 + 9, pDrawItemInfo->y0 + 4);
    return 0;
  case WIDGET_ITEM_DRAW_FRAME:
    //
    // Draw item frame
    //
    return 0;
  default:
    return 0;
  }
}

/*********************************************************************
*
*       Public code
*
**********************************************************************
*/
/*********************************************************************
*
*       MainTask
*/
void MainTask(void) {
  SPINBOX_Handle hSpinbox;
  WM_HWIN        hEdit;

  //
  // Init GUI
  //
  GUI_Init();
  WM_SetDesktopColor(GUI_WHITE);
  //
  // Create spinbox widget
  //
  hSpinbox = SPINBOX_CreateEx(10, 10, 80, 30, WM_HBKWIN, WM_CF_SHOW, GUI_ID_SPINBOX0, 0, 100);
  SPINBOX_SetFont(hSpinbox, &GUI_Font16B_1);
  //
  // Set background of text area to transparent
  //
  hEdit = SPINBOX_GetEditHandle(hSpinbox);
  WM_SetHasTrans(hEdit);
  EDIT_SetBkColor(hEdit, EDIT_CI_ENABLED, GUI_INVALID_COLOR);
  //
  // Set skinning routine
  //
  SPINBOX_SetSkin(hSpinbox, _cbSpinboxSkin);

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

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