CPI_InterfacePart_Indicator.c
上传用户:tuheem
上传日期:2007-05-01
资源大小:21889k
文件大小:3k
源码类别:

多媒体编程

开发平台:

Visual C++

  1. ////////////////////////////////////////////////////////////////////////////////
  2. #include "stdafx.h"
  3. #include "globals.h"
  4. #include "CPI_InterfacePart.h"
  5. #include "CPI_Indicators.h"
  6. ////////////////////////////////////////////////////////////////////////////////
  7. //
  8. typedef struct _CPs_IPIndicator
  9. {
  10.     char* m_pcName;
  11. } CPs_IPIndicator;
  12. //
  13. ////////////////////////////////////////////////////////////////////////////////
  14. void IPIC_Destroy_PrivateData(CP_HINTERFACEPART hPart);
  15. void IPIC_Draw(CP_HINTERFACEPART hPart, CPs_DrawContext* pContext);
  16. ////////////////////////////////////////////////////////////////////////////////
  17. //
  18. //
  19. //
  20. CP_HINTERFACEPART IP_Create_Indicator(const char* pcName)
  21. {
  22.     CPs_InterfacePart* pNewPart;
  23.     CPs_IPIndicator* pCustomData;
  24.     // Setup custom data
  25.     pCustomData = (CPs_IPIndicator*)malloc(sizeof(*pCustomData));
  26.     STR_AllocSetString(&pCustomData->m_pcName, pcName, FALSE);
  27.     // Create new part and setup callbacks
  28.     pNewPart = (CPs_InterfacePart*)malloc(sizeof(*pNewPart));
  29.     memset(pNewPart, 0, sizeof(*pNewPart));
  30.     pNewPart->Destroy_PrivateData = IPIC_Destroy_PrivateData;
  31.     pNewPart->Draw = IPIC_Draw;
  32.     pNewPart->m_pPrivateData = pCustomData;
  33.     CPIC_BindIndicatorToControl(pcName, pNewPart);
  34.     return pNewPart;
  35. }
  36. //
  37. //
  38. //
  39. void IPIC_Draw(CP_HINTERFACEPART hPart, CPs_DrawContext* pContext)
  40. {
  41.     CPs_InterfacePart* pIP;
  42.     const char* pcValue;
  43.     CPs_IPIndicator* pIPIC;
  44.     // Init
  45.     pIP = (CPs_InterfacePart*)hPart;
  46.     CP_CHECKOBJECT(pIP);
  47.     pIPIC = (CPs_IPIndicator*)pIP->m_pPrivateData;
  48.     CP_CHECKOBJECT(pIPIC);
  49.     // Draw the window background
  50.     CPIG_TiledFill(pContext, &pIP->m_rLocation, &glb_pSkin->mpl_rListHeader_SourceTile, glb_pSkin->mpl_pListHeader_Down, CIC_TILEDFILOPTIONS_NONE);
  51.     pcValue = CPIC_GetIndicatorValue(pIPIC->m_pcName);
  52.     if(pcValue)
  53.     {
  54.         HFONT hfOld;
  55.         RECT rText;
  56.         rText = pIP->m_rLocation;
  57.         rText.left += glb_pSkin->mpl_rListHeader_SourceTile.left;
  58.         rText.right -= glb_pSkin->mpl_rListHeader_SourceTile.right;
  59.         hfOld = (HFONT)SelectObject(pContext->m_dcDraw, glb_pSkin->mpl_hfFont);
  60.         SetTextColor(pContext->m_dcDraw, glb_pSkin->mpl_ListHeaderColour);
  61.         SetBkMode(pContext->m_dcDraw, TRANSPARENT);
  62.         DrawText(pContext->m_dcDraw, pcValue, -1, &rText, DT_WORD_ELLIPSIS | DT_NOPREFIX | DT_VCENTER);
  63.         SelectObject(pContext->m_dcDraw, hfOld);
  64.     }
  65. }
  66. //
  67. //
  68. //
  69. void IPIC_Destroy_PrivateData(CP_HINTERFACEPART hPart)
  70. {
  71.     CPs_InterfacePart* pIP;
  72.     CPs_IPIndicator* pIPIC;
  73.     // Init
  74.     pIP = (CPs_InterfacePart*)hPart;
  75.     CP_CHECKOBJECT(pIP);
  76.     pIPIC = (CPs_IPIndicator*)pIP->m_pPrivateData;
  77.     CP_CHECKOBJECT(pIPIC);
  78.     free(pIPIC->m_pcName);
  79.     free(pIPIC);
  80.     CPIC_UnBindControl(hPart);
  81. }
  82. //
  83. //
  84. //