⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 guichar.c

📁 uCOS/II下用的图形系统源码
💻 C
📖 第 1 页 / 共 2 页
字号:
/***********************************************************************************************************                                                uC/GUI*                        Universal graphic software for embedded applications**                       (c) Copyright 2002, Micrium Inc., Weston, FL*                       (c) Copyright 2002, SEGGER Microcontroller Systeme GmbH**              礐/GUI 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 redistributed*              in any way. We appreciate your understanding and fairness.*----------------------------------------------------------------------File        : GUIChar.CPurpose     : Implementation of character and string services----------------------------------------------------------------------Version-Date---Author-Explanation---------------------------END-OF-HEADER------------------------------*/#include <stddef.h>           /* needed for definition of NULL */#include <stdio.h>#include <string.h>#include "GUI_Private.H" /**************************************************************                       Static subroutines*************************************************************//*********************************************************************  HandleEOLine  Is called when processing strings which may consist of  multiple lines after a line has been processed. It will  a) Swall the line feed character (if it is there)  b) Return 1 if end of string, otherwise 0*/int GUI__HandleEOLine(const char* *ps) {  const char *s = *ps;  char c= *s++;  if (c==0)    return 1;  if (c=='\n') {    *ps = s;  }  return 0;}/*************** GUI_GetStringDistX ****************************This routine is used to calculate the length of a string in pixels.*/int GUI_GetLineDistX(const char GUI_FAR *s, int Len) {  int Dist =0;  if (s) {    if (GUI_Context.pAFont->pafEncode) {      return GUI_Context.pAFont->pafEncode->pfGetLineDistX(s, Len);    }#if (GUI_SUPPORT_UNICODE)    {      U8 c0;      char UCActive=0;      while (((c0=*(U8*)s) !=0) && Len >0) {        s++; Len--;        if (UCActive) {          if (c0 == GUI_UC_ENDCHAR)            UCActive = 0;          else {            U8  c1 = *(U8*)s++;            Len--;            Dist += GUI_GetCharDistX(GUI_DB2UC(c0, c1));          }        } else { /* Unicode not active */          if (c0 == GUI_UC_STARTCHAR)            UCActive = 1;          else            Dist += GUI_GetCharDistX(c0);        }      }    }#else    while (--Len>=0) {      Dist += GUI_GetCharDistX(*(U8*)s++);    }#endif  }  return Dist;}int GUI__GetFontSizeY(void) {  return GUI_Context.pAFont->YSize * GUI_Context.pAFont->YMag;}/*************** GUI_GetLineLen ****************************Returns the number of characters in a stringNote: The return value can be used as offset into thestring, which means that double characters count double*/int GUI__GetLineLen(const char GUI_FAR *s, int MaxLen) {  int Len =0;  if (!s)    return 0;  if (GUI_Context.pAFont->pafEncode) {    return GUI_Context.pAFont->pafEncode->pfGetLineLen(s, MaxLen);  }#if (GUI_SUPPORT_UNICODE)  {    U8 c0;    char UCActive=0;    while (((c0=*(U8*)s) !=0) && Len < MaxLen) {      s++;      if (UCActive) {        switch (c0) {        case GUI_UC_ENDCHAR: UCActive = 0; break;        default: Len++; s++;        }      } else { /* Unicode not active */        switch (c0) {        case GUI_UC_STARTCHAR: UCActive = 1; break;        case '\n': return Len;        case '\r': return Len;        }      }      Len++;    }  }#else  for (;Len<MaxLen; Len++) {    U8 Data = *(U8*)s++;    if ((Data == 0) || (Data == '\n'))      break;  }#endif  return Len;}int GUI_GetStringDistX(const char GUI_FAR *s) {  return GUI_GetLineDistX(s, strlen(s));}/************************************************************************       "GET"   routines    (information retrieval)************************************************************************These routines all return a value like selected font, current displayposition in x/y direction, window size in x/y direction,font size and matrix in x/y.The routines prefixed with GUI_ can be called from the applicationprogram or emWin internally, while the routines without that prefixare not supposed to be called from outside emWin.The main reason is that GUI_LOCK has to be called before thesevalues can be reliably retrieved in a multitasking environment.*//*------------------------------------------------------------------  GUI_GetYAdjust  --- returns adjustment in vertical (Y) direction                  The return value needs to be subtracted from                  the y-position of the character*/int GUI_GetYAdjust(void) {  switch (GUI_Context.TextAlign&GUI_TA_VERTICAL) {	case GUI_TA_BOTTOM:		return GUI_Context.pAFont->YSize-1;	case GUI_TA_VCENTER:		return GUI_Context.pAFont->YSize/2;	case GUI_TA_BASELINE:		return GUI_Context.pAFont->YSize/2;	}  return 0;}/*  Return X-component of current display position*/int GUI_GetDispPosX(void) {  int r;  GUI_LOCK();  r = GUI_Context.DispPosX;  GUI_UNLOCK();  return r;}/*  Return Y-component of current display position*/int GUI_GetDispPosY(void) {  int r;  GUI_LOCK();  r = GUI_Context.DispPosY;  GUI_UNLOCK();  return r;}char GUI_IsInFont(const GUI_FONT*pFont, U16 c) {  if (pFont==NULL)    pFont = GUI_Context.pAFont;  return pFont->pfIsInFont((void*)pFont, c);}/*        *******************************************        *                                         *        *        Get Font Size Routines           *        *                                         *        ********************************************/int GUI_GetFontSizeY(void) {  int r;  GUI_LOCK();  r = GUI__GetFontSizeY();  GUI_UNLOCK();  return r;}int  GUI_GetYSizeOfFont(const GUI_FONT* pFont) {  return pFont->YSize * pFont->YMag;}int  GUI_GetYDistOfFont(const GUI_FONT* pFont) {  return pFont->YDist * pFont->YMag;}/*        *******************************************        *                                         *        *        Get Font Spacing routines        *        *                                         *        ********************************************/int GUI_GetFontDistY(void) {  int r;  GUI_LOCK();  r = GUI_Context.pAFont->YDist * GUI_Context.pAFont->YMag;  GUI_UNLOCK();  return r;}/*        *******************************************        *                                         *        *        Get Char spacing routines        *        *                                         *        ********************************************/int GUI_GetCharDistX(U16 c) {  int r;  GUI_LOCK();  r = GUI_Context.pAFont->pfGetCharDistX(c);  GUI_UNLOCK();  return r;}/*        *******************************************        *                                         *        *        Get selected font                *        *                                         *        ********************************************/const GUI_FONT* GUI_GetFont(void) {  const GUI_FONT* r;  GUI_LOCK();  r = GUI_Context.pAFont;  GUI_UNLOCK();  return r;}/*      **************************************************      *                                                *      *             Setting Text Mode                  *      *                                                *      ***************************************************/int GUI_SetTextMode(int Mode) {  int r;  GUI_LOCK();  r = GUI_Context.TextMode;  GUI_Context.TextMode = Mode;  GUI_UNLOCK();  return r;}int GUI_GetTextMode(void) {  int r;  GUI_LOCK();  r = GUI_Context.TextMode;  GUI_UNLOCK();  return r;}/*      **************************************************      *                                                *      *             Setting Text Mode                  *      *                                                *      ***************************************************/int GUI_SetTextAlign(int Align) {  int r;  GUI_LOCK();  r = GUI_Context.TextAlign;  GUI_Context.TextAlign = Align;  GUI_UNLOCK();  return r;}int GUI_GetTextAlign(void) {  int r;  GUI_LOCK();  r = GUI_Context.TextAlign;  GUI_UNLOCK();  return r;}/*      *********************************      *                               *      *       Clear to end of line    *      *                               *      **********************************/void GUI_DispCEOL(void) {  int y = GUI_Context.DispPosY - GUI_GetYAdjust();  GUI_ClearRect(GUI_Context.DispPosX,                y,                4000,             /* Max pos x */                y + GUI_Context.pAFont->YDist-1);}/*      *********************************      *                               *      *       Linefeed                *      *                               *      **********************************/void GUI_DispNextLine(void) {  GUI_Context.DispPosY +=GUI_GetFontDistY();  GUI_Context.DispPosX = GUI_Context.LBorder;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -