/********************************************************************* * * GUI_EditHex */ U32 GUI_EditHex(U32 Value, U32 Min, U32 Max, int Len, int xsize) { U32 Ret = Value; int Key, x, y, ysize, Id; EDIT_Handle hEdit; EDIT_Obj* pObj; const GUI_FONT GUI_UNI_PTR * pOldFont = GUI_SetFont(EDIT_GetDefaultFont()); x = GUI_GetDispPosX(); y = GUI_GetDispPosY(); if (xsize == 0) xsize = GUI_GetCharDistX('X') * Len + 6; ysize = GUI_GetFontSizeY(); Id = 0x1234; hEdit = EDIT_Create(x, y, xsize, ysize, Id, Len, 0); pObj = EDIT_H2P(hEdit); EDIT_SetHexMode(hEdit, Value, Min, Max); WM_SetFocus(hEdit); do { Key = GUI_WaitKey(); } while ((Key != GUI_KEY_ESCAPE) && (Key != GUI_KEY_ENTER) && (Key != 0)); GUI_SetFont(pOldFont); if (Key == GUI_KEY_ENTER) Ret = pObj->CurrentValue; EDIT_Delete(hEdit); return Ret; }
static void utf16big_dispstr(char *s, int len , int x, int y) { __u16 xdist; __u16 b, tmp; int i=0; xdist = x; while( i < len ) { b = s[i] & 0xff; tmp = s[i+1] & 0xff; tmp += b<<8; if( (tmp == 13) || (tmp == 10)) // 换行\r\n { i+=2; continue; } if( tmp == 9) tmp = 0x20; GUI_DispCharAt(tmp, xdist, y); xdist += GUI_GetCharDistX(tmp); i += 2; } }
void get_string_piexl_rect(__string_show_info_t *show_info) { int len,i; __u16 uni; __u16 CharWidth; __s32 char_size; i = 0; show_info->show_size.width = 0; show_info->show_size.height = GUI_GetFontDistY(); len = eLIBs_strlen(show_info->name); while( i < len ) { char_size = esCHS_Char2Uni( show_info->encode_id, (__u8 *)show_info->name+i, len - i, &uni ); if( char_size <= 0 ) { break; } CharWidth = GUI_GetCharDistX(uni); show_info->show_size.width += CharWidth; i += char_size; } return; }
void local_get_string_piexl_rect( const char *str, __string_show_info_t *show_info,SIZE *size) { int len,i; __u16 uni; __u16 CharWidth; __s32 char_size; i = 0; size->width = 0; len = eLIBs_strlen(str); size->height = GUI_GetFontDistY(); while( i < len ) { char_size = esCHS_Char2Uni( show_info->encode_id, (__u8 *)str+i, len - i, &uni ); if( char_size <= 0 ) break; CharWidth = GUI_GetCharDistX(uni); size->width += CharWidth; i += char_size; } return; }
static void utf16big_config(txtEncodeParser *thiz, ParserConfig *config) { __u16 tmp_chinese; config->p_dispstr = thiz->dispstr; thiz->fd = config->fd; thiz->txtLength = config->len; thiz->viewWidth = config->xScrWidth; // thiz->viewHeight = config->yScrHeight; // thiz->lineofpage = config->lineofpage; // thiz->FontHeight = config->FontHeight; thiz->bufferTxtlen = 0; thiz->start = config->startOffset; if( thiz->start <= 2 ) thiz->bof = EPDK_TRUE; else thiz->bof = EPDK_FALSE; thiz->eof = EPDK_FALSE; thiz->pFont = config->pFont; thiz->hlyr = config->hlyr; GUI_LyrWinSel(thiz->hlyr); GUI_SetTextMode(GUI_TM_TRANS); GUI_SetFont(thiz->pFont); GUI_SetFontMode(GUI_FONTMODE_8BPP256); tmp_chinese = eLIBs_GB2312_to_Unicode(0xced2); thiz->chinese_width = GUI_GetCharDistX(tmp_chinese); }
/********************************************************************* * * GUI_EditString */ void GUI_EditString(char * pString, int Len, int xsize) { int Key, x, y, ysize, Id; EDIT_Handle hEdit; EDIT_Obj* pObj; const GUI_FONT GUI_UNI_PTR * pOldFont; WM_LOCK(); pOldFont = GUI_SetFont(EDIT_GetDefaultFont()); x = GUI_GetDispPosX(); y = GUI_GetDispPosY(); if (xsize == 0) { xsize = GUI_GetCharDistX('X') * Len + 6; } ysize = GUI_GetFontSizeY(); Id = 0x1234; hEdit = EDIT_Create(x, y, xsize, ysize, Id, Len, 0); EDIT_SetText(hEdit, pString); pObj = EDIT_H2P(hEdit); WM_SetFocus(hEdit); do { Key = GUI_WaitKey(); } while ((Key != GUI_KEY_ESCAPE) && (Key != GUI_KEY_ENTER) && (Key != 0)); if (Key == GUI_KEY_ENTER) { EDIT_GetText(hEdit, pString, pObj->MaxLen); } GUI_SetFont(pOldFont); EDIT_Delete(hEdit); WM_UNLOCK(); }
/********************************************************************* * * GUI_GetTextExtend */ void GUI_GetTextExtend(GUI_RECT* pRect, const char GUI_UNI_PTR * s, int MaxNumChars) { int xMax = 0; int NumLines = 0; int LineSizeX = 0; U16 Char; pRect->x0 = GUI_Context.DispPosX[GUI_Context.SelLayer]; pRect->y0 = GUI_Context.DispPosY[GUI_Context.SelLayer]; while (MaxNumChars--) { Char = GUI_UC__GetCharCodeInc(&s); if ((Char == '\n') || (Char == 0)) { if (LineSizeX > xMax) { xMax = LineSizeX; } LineSizeX = 0; NumLines++; if (!Char) { break; } } else { LineSizeX += GUI_GetCharDistX(Char); } } if (LineSizeX > xMax) { xMax = LineSizeX; } if (!NumLines) { NumLines = 1; } pRect->x1 = pRect->x0 + xMax - 1; pRect->y1 = pRect->y0 + GUI__GetFontSizeY() * NumLines - 1; }
/* Note on usage of this routine: If at all possible, try to avoid using this, since every call will invoke the window manager. If possible, use the string routines. */ static void CL_DispChar(U16 c) { GUI_RECT r; WM_ADDORG(GUI_Context.DispPosX, GUI_Context.DispPosY); r.x1 = (r.x0 = GUI_Context.DispPosX) + GUI_GetCharDistX(c)-1; r.y1 = (r.y0 = GUI_Context.DispPosY) + GUI_GetFontSizeY()-1; WM_ITERATE_START(&r) { GL_DispChar(c); if (c != '\n') GUI_Context.DispPosX = r.x1 + 1; } WM_ITERATE_END(); WM_SUBORG(GUI_Context.DispPosX,GUI_Context.DispPosY); }
/********************************************************************* * * _GetLineDistX */ static int _GetLineDistX(const U16 GUI_UNI_PTR *s, int MaxNumChars) { int Dist =0; if (s) { U16 Char; while (((Char = *s) != 0) && MaxNumChars >= 0) { s++; MaxNumChars--; Dist += GUI_GetCharDistX(Char); } } return Dist; }
/********************************************************************* * * GUI__GetCursorPosX * * Purpose: * Returns the cursor position in pixels by the given index * * Parameters: * s : Pointer to the string * Index : Index of cursor character * MaxNumChars : Number of charaters in the string */ int GUI__GetCursorPosX(const char GUI_UNI_PTR * s, int Index, int MaxNumChars) { #if GUI_SUPPORT_ARABIC return GUI__GetCursorPosXArabic(s, Index, MaxNumChars); #else int CursorPosX = 0; U16 Char; GUI_USE_PARA(MaxNumChars); while (Index--) { Char = GUI_UC__GetCharCodeInc(&s); CursorPosX += GUI_GetCharDistX(Char); } return CursorPosX; #endif }
/********************************************************************* * * GUI_GetLineDistX * * This routine is used to calculate the length of a line in pixels. */ int GUI__GetLineDistX(const char GUI_UNI_PTR *s, int MaxNumChars) { int Dist = 0; if (s) { U16 Char; #if GUI_COMPILER_SUPPORTS_FP if (GUI_Context.pAFont->pafEncode) { return GUI_Context.pAFont->pafEncode->pfGetLineDistX(s, MaxNumChars); } #endif while (--MaxNumChars >= 0) { Char = GUI_UC__GetCharCodeInc(&s); Dist += GUI_GetCharDistX(Char); } } return Dist; }
/********************************************************************* * * _GetCharWrap */ static int _GetCharWrap(const char GUI_UNI_PTR * s, int xSize) { int xDist = 0, NumChars = 0; U16 Char; while ((Char = GUI_UC__GetCharCodeInc(&s)) != 0) { xDist += GUI_GetCharDistX(Char); if ((NumChars && (xDist > xSize)) || (Char == '\n') || (Char == '\r')) { break; } NumChars++; } return NumChars; }
/********************************************************************* * * GUI__GetCursorPosChar * * Purpose: * Returns the cursor character index by the given pixel position * * Parameters: * s : Pointer to the string * x : X position of the cursor * MaxNumChars : Number of charaters in the string */ int GUI__GetCursorPosChar(const char GUI_UNI_PTR * s, int x, int MaxNumChars) { #if GUI_SUPPORT_ARABIC return GUI__GetCursorPosCharArabic(s, x, MaxNumChars); #else int SizeX = 0; const char GUI_UNI_PTR * p; p = s; while (--MaxNumChars> 0) { U16 Char; Char = GUI_UC_GetCharCode(s); SizeX += GUI_GetCharDistX(Char); if (!Char || (SizeX > x)) { break; } s += GUI_UC_GetCharSize(s); } return GUI_UC__NumBytes2NumChars(p, s - p); #endif }
/********************************************************************* * * _ShowCursorType */ static void _ShowCursorType(const CURSORTYPE_INFO* pCursorType, int x0, int y0) { const GUI_CURSOR * pCursor; char Char; int yMax; int yHot; int i; int x; int y; yMax = 0; yHot = 0; // // Calculate height and width of biggest cursor // for (i = 0; i < NUM_CURSORS; i++) { pCursor = pCursorType->aCursor[i].pCursor; if (pCursor->pBitmap->YSize > yMax) { yMax = pCursor->pBitmap->YSize; yHot = pCursor->yHot; } } GUI_SetFont(&GUI_FontRounded16); #if (NUM_CURSORS != 3) GUI_SetLBorder(x0); #endif GUI_DispStringAt(pCursorType->pType, x0, y0); y0 += GUI_GetFontDistY() + 1; GUI_SetFont(&GUI_Font13B_ASCII); for (i = 0; i < NUM_CURSORS; i++) { pCursor = pCursorType->aCursor[i].pCursor; Char = pCursorType->aCursor[i].Size; y = y0 + yHot - pCursor->yHot; x = ((pCursor->pBitmap->XSize - GUI_GetCharDistX(Char)) / 2); GUI_DrawBitmap(pCursor->pBitmap, x0 + XMAX * i + 5, y); GUI_DispCharAt(Char, x0 + XMAX * i + 5 + x, y0 + yMax + 2); } }
/********************************************************************* * * _GetWordWrap */ static int _GetWordWrap(const char GUI_UNI_PTR * s, int xSize) { int xDist = 0, NumChars = 0, WordWrap = 0; U16 Char, PrevChar = 0; while (1) { Char = GUI_UC__GetCharCodeInc(&s); /* Similar to: *s++ */ /* Let's first check if the line end is reached. In this case we are done. */ if (_IsLineEnd(Char,s)) { WordWrap = NumChars; break; } /* If current character is a space, we found a wrap position */ if ((Char == ' ') && (Char != PrevChar)) { WordWrap = NumChars; } PrevChar = Char; xDist += GUI_GetCharDistX(Char); if ((xDist <= xSize) || (NumChars == 0)) { NumChars++; } else { break; } } if (!WordWrap) { WordWrap = NumChars; } return WordWrap; }
/********************************************************************* * * _SetCursor */ static void _SetCursor(EDIT_Handle hObj, EDIT_Obj* pObj, int x) { int xPos, xSize, PixelLen, Len; char * s = (char*) WM_HMEM2Ptr(pObj->hpText); const GUI_FONT *pOldFont = GUI_SetFont(pObj->pFont); xSize = WM_GetWindowSizeX(hObj); PixelLen = GUI_GetStringDistX(s); xPos = x; switch (pObj->Align & GUI_TA_HORIZONTAL) { case GUI_TA_CENTER: xPos -= (xSize - PixelLen + 1) / 2; break; case GUI_TA_LEFT: xPos -= (pObj->Border + EDIT_XOFF); break; case GUI_TA_RIGHT: xPos -= xSize - PixelLen - (pObj->Border + EDIT_XOFF); break; } Len = (int)strlen(s); if (xPos < 0) { pObj->CursorPos = 0; } else if (xPos > PixelLen) { pObj->CursorPos = Len; } else { int i, x; for (i = 0, x = 0; (i < Len) && (x < xPos); i++) { int xLenChar = GUI_GetCharDistX(*(s + i)); if (xPos < (x + xLenChar)) break; x += xLenChar; } pObj->CursorPos = i; EDIT_Invalidate(hObj); } GUI_SetFont(pOldFont); }
static __s32 utf16big_analysis(txtEncodeParser *thiz, MkLine *line) { __u16 CharWidth; int c = thiz->cur_offset; //buffer索引 int w = 0; //每行的字符总宽度 int l = 0; //每行包含的字符数 GUI_LyrWinSel(thiz->hlyr); GUI_SetTextMode(GUI_TM_TRANS); GUI_SetFont(thiz->pFont); GUI_SetFontMode(GUI_FONTMODE_8BPP256); while( c < thiz->bufferTxtlen ) { __u16 b = thiz->bufferTxt[c+1] & 0xff; b += (thiz->bufferTxt[c]&0xff)<<8; //大端格式,高位在前, 低位在后 if ( (b == 13) || (b == 10)) //\r 换行\r\n { __u16 tmp; tmp = thiz->bufferTxt[c+3] & 0xff; tmp += (thiz->bufferTxt[c+2]&0xff)<<8; //大端格式,高位在前, 低位在后 if( tmp == 10 ) { c+=4; l+=4; } else { c+=2; l+=2; } // tmp_line.len = l; // tmp_line.txt_off = thiz->start + c -l; //注意thiz->currentoffset的初始化,应该record一下。 // set_txt_line_value_push(lines, &tmp_line); line->start = thiz->start + c -l; line->len = l; thiz->cur_offset = c; w = 0; l = 0; //c +=2; return 0; } if( b< 0x80) CharWidth = GUI_GetCharDistX(b); else CharWidth = thiz->chinese_width; if (w + CharWidth > thiz->viewWidth) { //当前行无法显示完整 // tmp_line.len = l; // tmp_line.txt_off = thiz->start + c -l; // set_txt_line_value_push(lines, &tmp_line); line->start = thiz->start + c -l; line->len = l; thiz->cur_offset = c; w = 0; l = 0; //c +=2; return 0; } else { c += 2; l += 2; w += CharWidth; } } thiz->cur_offset = 0; if( l > 0 ) { // tmp_line.len = l; // tmp_line.txt_off = thiz->start + c -l; // set_txt_line_value_push(lines, &tmp_line); line->start = thiz->start + c -l; line->len = l; return -2; } return -1; }
/********************************************************************* * * _Paint */ static void _Paint(EDIT_Obj* pObj, EDIT_Handle hObj) { GUI_RECT rFillRect, rInside, rText, rInvert; const char GUI_UNI_PTR * pText = NULL; int IsEnabled, CursorWidth = 0; IsEnabled = WM__IsEnabled(hObj); /* Set colors and font */ LCD_SetBkColor(pObj->Props.aBkColor[IsEnabled]); LCD_SetColor(pObj->Props.aTextColor[0]); GUI_SetFont(pObj->Props.pFont); /* Calculate size */ WIDGET__GetInsideRect(&pObj->Widget, &rFillRect); if (pObj->hpText) { pText = (const char*) GUI_ALLOC_h2p(pObj->hpText); } rInside = rFillRect; rInside.x0 += pObj->Props.Border + EDIT_XOFF; rInside.x1 -= pObj->Props.Border + EDIT_XOFF; GUI__CalcTextRect(pText, &rInside, &rText, pObj->Props.Align); /* Calculate position and size of cursor */ if (pObj->Widget.State & WIDGET_STATE_FOCUS) { int NumChars; CursorWidth = ((pObj->XSizeCursor > 0) ? (pObj->XSizeCursor) : (1)); NumChars = GUI__GetNumChars(pText); if (pText) { U16 Char; int i, IsRTL = 0; if ((pObj->EditMode != GUI_EDIT_MODE_INSERT) || (pObj->SelSize)) { if (pObj->CursorPos < NumChars) { if (pObj->SelSize) { CursorWidth = 0; for (i = pObj->CursorPos; i < (int)(pObj->CursorPos + pObj->SelSize); i++) { Char = GUI__GetCursorCharacter(pText, i, NumChars, 0); CursorWidth += GUI_GetCharDistX(Char); } if (!CursorWidth) { CursorWidth = 1; } } else { Char = GUI__GetCursorCharacter(pText, pObj->CursorPos, NumChars, &IsRTL); CursorWidth = GUI_GetCharDistX(Char); } } } rInvert = rText; if (IsRTL) { rInvert.x0 -= CursorWidth; } rInvert.x0 += GUI__GetCursorPosX(pText, pObj->CursorPos, NumChars); } } /* WM loop */ WM_ITERATE_START(NULL) { /* Set clipping rectangle */ WM_SetUserClipRect(&rFillRect); /* Display text */ WIDGET__FillStringInRect(pText, &rFillRect, &rInside, &rText); /* Display cursor if needed */ if (pObj->Widget.State & WIDGET_STATE_FOCUS) { GUI_InvertRect(rInvert.x0, rInvert.y0, rInvert.x0 + CursorWidth - 1, rInvert.y1); } WM_SetUserClipRect(NULL); /* Draw the 3D effect (if configured) */ WIDGET__EFFECT_DrawDown(&pObj->Widget); } WM_ITERATE_END(); }
/********************************************************************* * * _Paint */ static void _Paint(EDIT_Obj* pObj) { int PixelLen, xSize, ySize, xPosText = 0, xPosCursor = 0, yPosText = 0, yPosCursor = 0, XSizeCursor, YSizeCursor; int IsEnabled; GUI_RECT rClient, rWindow; char * s; s = (char*) WM_HMEM2Ptr(pObj->hpText); GUI_DEBUG_LOG("BUTTON: _Paint(..)\n"); if (pObj->Border) { GUI_SetBkColor(pObj->aBkColor[0]); GUI_Clear(); } IsEnabled = WIDGET__IsEnabled(&pObj->Widget); /* Set clipping rectangle */ WIDGET__GetInsideRect(&pObj->Widget, &rWindow); WM_SetUserClipRect(&rWindow); /* Calculate size */ GUI_GetClientRect(&rClient); xSize = rClient.x1 - rClient.x0 + 1; ySize = rClient.y1 - rClient.y0 + 1; /* Draw background */ GUI_SetBkColor (pObj->aBkColor[IsEnabled]); GUI_SetColor (pObj->aTextColor[0]); GUI_Clear(); /* Calculate length */ GUI_SetFont (pObj->pFont); PixelLen = GUI_GetStringDistX(s); /* Calculate size of cursor */ YSizeCursor = GUI_GetFontDistY(); if (pObj->EditMode == GUI_EDIT_MODE_INSERT) { if (pObj->XSizeCursor != 0) { XSizeCursor = pObj->XSizeCursor; } else { XSizeCursor = GUI_GetCharDistX(' '); } } else { if (pObj->CursorPos < (int)strlen(s)) { XSizeCursor = GUI_GetCharDistX(*(s + pObj->CursorPos)); } else { XSizeCursor = pObj->XSizeCursor; } } /* Calculate X-pos */ switch (pObj->Align & GUI_TA_HORIZONTAL) { case GUI_TA_CENTER: xPosCursor = (xSize - PixelLen + 1) / 2; xPosText = xSize / 2; break; case GUI_TA_LEFT: xPosCursor = pObj->Border + EDIT_XOFF; xPosText = pObj->Border + EDIT_XOFF; break; case GUI_TA_RIGHT: xPosCursor = xSize - (pObj->Border + EDIT_XOFF) - PixelLen; xPosText = xSize - (pObj->Border + EDIT_XOFF); break; } /* Calculate Y-pos */ switch (pObj->Align & GUI_TA_VERTICAL) { case GUI_TA_TOP: yPosCursor = 0; yPosText = 0; break; case GUI_TA_BOTTOM: yPosCursor = ySize - YSizeCursor; yPosText = ySize; break; case GUI_TA_VCENTER: yPosCursor = (ySize - YSizeCursor + 1) / 2; yPosText = ySize / 2; break; } /* Display text */ GUI_SetTextAlign(pObj->Align); GUI_DispStringAt(s, xPosText, yPosText); /* Display cursor */ if (pObj->Widget.State & WIDGET_STATE_FOCUS) { int i; for (i = 0; i != pObj->CursorPos; i++) { xPosCursor += GUI_GetCharDistX(*(s + i)); } GUI_InvertRect(xPosCursor, yPosCursor, xPosCursor + XSizeCursor - 1, yPosCursor + YSizeCursor - 1); } WM_SetUserClipRect(NULL); /* Draw the 3D effect (if configured) */ WIDGET__EFFECT_DrawDown(&pObj->Widget); }
//USER_LCD_LOG_PUTCHAR void LCD_PutChar (char ch) { uint32_t idx; if(USER_LCD_Lock == DISABLE) { if(USER_LCD_ScrollActive == ENABLE) { USER_LCD_CacheBuffer_yptr_bottom = USER_LCD_CacheBuffer_yptr_bottom_bak; USER_LCD_CacheBuffer_yptr_top = USER_LCD_CacheBuffer_yptr_top_bak; USER_LCD_ScrollActive = DISABLE; USER_LCD_Scrolled = DISABLE; USER_LCD_ScrollBackStep = 0; } if(( USER_LCD_CacheBuffer[USER_LCD_CacheBuffer_yptr_bottom].len < XSIZE) && ( ch != '\n')) { USER_LCD_CacheBuffer[USER_LCD_CacheBuffer_yptr_bottom].line[USER_LCD_CacheBuffer_xptr++] = (uint16_t)ch; USER_LCD_CacheBuffer[USER_LCD_CacheBuffer_yptr_bottom].len+=GUI_GetCharDistX(ch); } else { if(USER_LCD_CacheBuffer_yptr_top >= USER_LCD_CacheBuffer_yptr_bottom) { if(USER_LCD_CacheBuffer_yptr_invert == DISABLE) { USER_LCD_CacheBuffer_yptr_top++; if(USER_LCD_CacheBuffer_yptr_top == USER_LCD_CACHE_DEPTH) { USER_LCD_CacheBuffer_yptr_top = 0; } } else { USER_LCD_CacheBuffer_yptr_invert= DISABLE; } } for(idx = USER_LCD_CacheBuffer_xptr ; idx < sizeof(USER_LCD_CacheBuffer[USER_LCD_CacheBuffer_yptr_bottom].line)/sizeof(USER_LCD_CacheBuffer[USER_LCD_CacheBuffer_yptr_bottom].line[0]); idx++) { USER_LCD_CacheBuffer[USER_LCD_CacheBuffer_yptr_bottom].line[USER_LCD_CacheBuffer_xptr++] = 0; } USER_LCD_CacheBuffer[USER_LCD_CacheBuffer_yptr_bottom].color = USER_LCD_LineColor; USER_LCD_CacheBuffer[USER_LCD_CacheBuffer_yptr_bottom].len=0; USER_LCD_CacheBuffer_xptr = 0; USER_LCD_LOG_UpdateDisplay (); USER_LCD_CacheBuffer_yptr_bottom ++; if (USER_LCD_CacheBuffer_yptr_bottom == USER_LCD_CACHE_DEPTH) { USER_LCD_CacheBuffer_yptr_bottom = 0; USER_LCD_CacheBuffer_yptr_top = 1; USER_LCD_CacheBuffer_yptr_invert = ENABLE; } if( ch != '\n') { USER_LCD_CacheBuffer[USER_LCD_CacheBuffer_yptr_bottom].line[USER_LCD_CacheBuffer_xptr++] = (uint16_t)ch; } } } //return ch; }