/*********************************************************************
*
*       MYWIDGET_Callback
*/
void MYWIDGET_Callback(WM_MESSAGE * pMsg) {
    MYWIDGET_Handle   hWin;
    GUI_PID_STATE   * pState;
    MYWIDGET_Obj      MyWidget;
    GUI_RECT          WinRect;
    int               ColorIndex;
    U8                Pressed;

    hWin = pMsg->hWin;
    WM_GetWindowRectEx(hWin, &WinRect);
    GUI_MoveRect(&WinRect, -WinRect.x0, -WinRect.y0);
    WM_GetUserData(hWin, &MyWidget, sizeof(MYWIDGET_Obj));
    switch (pMsg->MsgId) {
    case WM_PAINT:
        if (WM_IsEnabled(hWin)) {
            if (MyWidget.Pressed) {
                ColorIndex = MYWIDGET_CI_PRESSED;
            } else {
                ColorIndex = MYWIDGET_CI_UNPRESSED;
            }
        } else {
            ColorIndex = MYWIDGET_CI_DISABLED;
        }
        GUI_SetColor(MyWidget.aBkColor[ColorIndex]);
        GUI_FillRectEx(&WinRect);
        if (WM_HasFocus(hWin)) {
            GUI_SetColor(MyWidget.FocusColor);
            GUI_DrawRectEx(&WinRect);
        }
        GUI_SetColor(MyWidget.aTextColor[ColorIndex]);
        GUI_SetTextMode(GUI_TM_TRANS);
        GUI_DispStringInRect(MyWidget.pText, &WinRect, GUI_TA_HCENTER | GUI_TA_VCENTER);
        break;
    case WM_TOUCH:
        pState = (GUI_PID_STATE *)pMsg->Data.p;
        if (pState) {
            Pressed = pState->Pressed;
        } else {
            Pressed = 0;
        }
        if (MyWidget.Pressed != Pressed) {
            MyWidget.Pressed = Pressed;
            WM_SetUserData(hWin, &MyWidget, sizeof(MYWIDGET_Obj));
            if (Pressed) {
                WM_SetFocus(hWin);
            }
            WM_InvalidateWindow(hWin);
        }
        break;
    case WM_SET_FOCUS:
        if (pMsg->Data.v) {
            pMsg->Data.v = 0;
        }
        WM_InvalidateWindow(hWin);
        break;
    default:
        WM_DefaultProc(pMsg);
    }
}
Exemple #2
0
/*********************************************************************
*
*       xIconSelBtn_UpdateIndex
*/
void xIconSelBtn_UpdateIndex(WM_HWIN hWin)
{
    xIconSelBtn_OBJ   *pWidget;
    
    if(!hWin) return;
    
    WM_GetUserData(hWin, &pWidget, sizeof(xIconSelBtn_OBJ*));
    pWidget->SelectedIndex = pWidget->MovingIndex;
}
/*********************************************************************
*
*       MYWIDGET_GetUserData
*/
int MYWIDGET_GetUserData(MYWIDGET_Handle hWin, void * pDest, int SizeOfBuffer) {
    MYWIDGET_Obj   MyWidget;
    int            NumBytes;
    U8           * pExtraBytes;

    if (SizeOfBuffer <= 0) {
        return 0;
    }
    WM_GetUserData(hWin, &MyWidget, sizeof(MYWIDGET_Obj));
    pExtraBytes = (U8 *)malloc(sizeof(MYWIDGET_Obj) + MyWidget.NumExtraBytes);
    if (pExtraBytes) {
        WM_GetUserData(hWin, pExtraBytes, sizeof(MYWIDGET_Obj) + MyWidget.NumExtraBytes);
        if (SizeOfBuffer >= MyWidget.NumExtraBytes) {
            NumBytes = MyWidget.NumExtraBytes;
        } else {
            NumBytes = SizeOfBuffer;
        }
        GUI_MEMCPY(pDest, pExtraBytes + sizeof(MYWIDGET_Obj), NumBytes);
        free(pExtraBytes);
        return NumBytes;
    }
    return 0;
}
Exemple #4
0
/*********************************************************************
*
*       _Paint
*/
static void _Paint_PopupWin(WM_HWIN hWin)
{
    GUI_RECT          WinRect;
    xIconSelBtn_OBJ   *pWidget;
    xICON *pIcon;
    xICON_CHECK_XY *pIconChkXY;
    int i;
    
    if(!hWin) return;
    
    DEBUGOUT("xIconSelBtn::PopupWin hWin = 0x%08x\r\n", hWin);
    WM_GetClientRect(&WinRect);
    DEBUGOUT("xIconSelBtn::PopupWin Paint(%d,%d,%d,%d)\r\n",WinRect.x0, WinRect.y0, WinRect.x1, WinRect.y1);
    
    WM_GetUserData(hWin, &pWidget, sizeof(xIconSelBtn_OBJ*));
    
    //Draw Window Background area
    GUI_SetColor(pWidget->PopupWinBkColor[1]); //Base Color
    GUI_FillRoundedRect(WinRect.x0+1,WinRect.y0+1,WinRect.x1-1,WinRect.y1-1, 2);
    GUI_SetColor(pWidget->PopupWinBkColor[0]); //OutLine Color
    GUI_DrawRoundedRect(WinRect.x0,WinRect.y0,WinRect.x1,WinRect.y1, 2);
    
    //Draw icons BMP
    for(i=0; i<pWidget->NumItems; i++)
    {
        pIcon= &pWidget->xIconArray[i];
        pIconChkXY = &pWidget->xIconCheckXyArray[i];
        
        if(pIcon->pBMP)
        {
            if(i == pWidget->MovingIndex)
            {
                //Draw Forcus Frame on Icon BMP outside
                int x0 = pIcon->x0 - pWidget->IconFocusFrameHWidth;
                int y0 = pIcon->y0 - pWidget->IconFocusFrameVWidth;
                int x1, y1;
                x1 = x0 + pIcon->pBMP->XSize + (pWidget->IconFocusFrameHWidth*2);
                y1 = y0 + pIcon->pBMP->YSize + (pWidget->IconFocusFrameVWidth*2);
                GUI_SetColor(pWidget->PopupWinIconFocusColor);
                GUI_FillRect(x0, y0, x1, y1);
            }
            GUI_DrawBitmap(pIcon->pBMP, pIcon->x0, pIcon->y0);
        }
        if( (pWidget->pCheckedBMP) && (i == pWidget->SelectedIndex) )
        {
            GUI_DrawBitmap(pWidget->pCheckedBMP, pIconChkXY->x0, pIconChkXY->y0);
        }
    }
}
Exemple #5
0
/*********************************************************************
*
*       xIconSelBtn_Dec_MoveIndex
*/
void xIconSelBtn_Dec_MoveIndex(WM_HWIN hWin)
{
    xIconSelBtn_OBJ   *pWidget;
    
    if(!hWin) return;
    
    WM_GetUserData(hWin, &pWidget, sizeof(xIconSelBtn_OBJ*));
    
    if(pWidget->MovingIndex > 0)
    {
        pWidget->MovingIndex--;
    }
    else
    {
        pWidget->MovingIndex = pWidget->NumItems - 1;
    }
    WM_InvalidateWindow(hWin);
}
Exemple #6
0
/*********************************************************************
*
*       xIconSelBtn_PopupWin_Callback
*/
void xIconSelBtn_PopupWin_Callback(WM_MESSAGE * pMsg)
{
  WM_HWIN     hWin;
  WM_KEY_INFO *pKeyInfo;
  int Notification;
  xIconSelBtn_OBJ *pWidget;
  
  hWin = pMsg->hWin;
  
  if(!hWin) return;
  
  WM_GetUserData(hWin, &pWidget, sizeof(xIconSelBtn_OBJ*));
  
  switch (pMsg->MsgId)
  {
  case WM_PAINT:
    _Paint_PopupWin(hWin);
    break;
    
  case WM_KEY:
    pKeyInfo = (WM_KEY_INFO *)pMsg->Data.p;
    
    switch(pKeyInfo->Key)
    {
      case GUI_KEY_ESCAPE:
        if(pKeyInfo->PressedCnt >0)
        {
            DEBUGOUT("xIconSelBtn::PopupWin(0x%08x) <- KEY_ESCAPE\r\n",hWin);
            BUTTON_SetUserData(pWidget->hThis, pWidget, sizeof(xIconSelBtn_OBJ));
            WM_SetFocus(pWidget->hThis);
            WM_InvalidateWindow(pWidget->hThis);
            WM_HideWindow(hWin);
        }
        break;
      
      case GUI_KEY_ENTER:
        if(pKeyInfo->PressedCnt >0)
        {
            DEBUGOUT("xIconSelBtn::PopupWin(0x%08x) <- KEY_ENTER\r\n",hWin);
            xIconSelBtn_UpdateIndex(hWin);
            BUTTON_SetUserData(pWidget->hThis, pWidget, sizeof(xIconSelBtn_OBJ));
            WM_SetFocus(pWidget->hThis);
            WM_InvalidateWindow(pWidget->hThis);
            WM_HideWindow(hWin);
        }
        break;
        
      case GUI_KEY_LEFT:
        if(pKeyInfo->PressedCnt >0)
        {
            DEBUGOUT("xIconSelBtn::PopupWin(0x%08x) <- KEY_LEFT\r\n",hWin);
            xIconSelBtn_Dec_MoveIndex(hWin);
        }
        break;
        
      case GUI_KEY_RIGHT:
        if(pKeyInfo->PressedCnt >0)
        {
            DEBUGOUT("xIconSelBtn::PopupWin(0x%08x) <- KEY_RIGHT\r\n",hWin);
            xIconSelBtn_Inc_MoveIndex(hWin);
        }
        break;
        
      default:
        WM_DefaultProc(pMsg);
        break;
    }
    break;
    
  default:
    WM_DefaultProc(pMsg);
  }
}