📄 guichar.c
字号:
/*
*********************************************************************************************************
* 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.C
* Purpose : Implementation of character and string services
*
*
* Version-Date---Author-Explanation
*
* 1.00.00 020517 RS First release
*
*
* Known problems or limitations with current version
*
* None.
*
*
* Open issues
*
* None
*********************************************************************************************************
*/
#include <stddef.h> /* needed for definition of NULL */
#include <stdio.h>
#include <string.h>
#include "GUI_Private.H"
/*
***********************************************************
*
* Static subroutines
*
***********************************************************
*/
static int _GetFontSizeY(void) {
return GUI_Context.pAFont->YSize * GUI_Context.pAFont->YMag;
}
/*********************************************************************
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
*/
static int 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;
}
/*************** GUI_GetLineLen ****************************
Returns the number of characters in a string
Note: The return value can be used as offset into the
string, which means that double characters count double
*/
static int 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));
}
/*------------------------------------------------------------------
GUI_GetTextExtend --- returns adjustment in vertical (Y) direction
The return value needs to be subtracted from
the y-position of the character
*/
void GUI_GetTextExtend(GUI_RECT* pRect, const char* s, int Len) {
int xMax =0;
int NumLines =0;
int LineLen;
pRect->x0 = GUI_Context.DispPosX;
pRect->y0 = GUI_Context.DispPosY;
while (((LineLen=GetLineLen(s, Len)) !=0) && (Len>0)) {
int xSize = GUI_GetLineDistX(s, LineLen);
if (xSize > xMax)
xMax= xSize;
s += LineLen;
while (*s == '\n')
s++;
Len -= LineLen;
NumLines++;
}
pRect->x1 = pRect->x0 + xMax-1;
pRect->y1 = pRect->y0 + _GetFontSizeY()*NumLines-1;
}
/*
***********************************************************************
* *
* "GET" routines (information retrieval) *
* *
***********************************************************************
These routines all return a value like selected font, current display
position 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 application
program or emWin internally, while the routines without that prefix
are not supposed to be called from outside emWin.
The main reason is that GUI_LOCK has to be called before these
values 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 = _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 =0;
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;
}
/*
************************************************************
*
* GL/CL DispChar
*
************************************************************
*/
void GL_DispChar(U16 c) {
/* check for control characters */
if (c == '\n') {
GUI_DispNextLine();
} else {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -