static D4D_BOOL D4D_TextBoxGetWordSpecInt(D4D_TCHAR ch, D4D_TXTBX_WORD_DESC* wordDesc) { D4D_COOR tab; // normal char or any special char if(ch <= ' ') { // special char if(wordDesc->charCnt) // if any chars are decoded (Word loaded) finish the function return D4D_FALSE; switch(ch) { case ' ': // space wordDesc->pixLen = D4D_GetCharWidth(wordDesc->fnt, ' '); break; case '\n': // new line wordDesc->newLine = D4D_TRUE; break; case '\t': // Tab tab = D4D_GetNextTab(wordDesc->pTab, wordDesc->cur_pos); if(tab) wordDesc->pixLen = (D4D_COOR)(tab - wordDesc->cur_pos); else wordDesc->pixLen = D4D_GetCharWidth(wordDesc->fnt, '\t'); break; default: // unsupported char break; } wordDesc->charCnt++; // increament the one processed char return D4D_FALSE; }else { // normal char wordDesc->pixLen += D4D_GetCharWidth(wordDesc->fnt, ch); } return D4D_TRUE; }
/**************************************************************************/ /*! * @brief The function returns width of text in pixels * @param ix - font index * @param pText - pointer to text * @return width of text in pixels * @note The function find out the width of string printed in given font. *******************************************************************************/ D4D_COOR D4D_GetTextWidth(D4D_FONT ix, D4D_TCHAR* pText){ D4D_COOR width = 0; D4D_TCHAR* pTextInt; if(pText == NULL) return 0; pTextInt = D4D_GetInternalStringPointer(pText); #if D4D_EXTSRC_TEXT_ENABLE != D4D_FALSE if(pTextInt == NULL) { D4D_INDEX charCnt = 0; D4D_INDEX charOff = 0; D4D_INDEX charCntTmp; do { charOff += charCnt; charCnt = (D4D_INDEX)d4d_extsrcLocale.D4DLOCALE_TranslateStr(pText, (D4D_TCHAR*)d4d_extsrcBuffer, charOff, D4D_EXTSRC_BUFF_SIZE); for(charCntTmp = 0; charCntTmp < charCnt; charCntTmp++) width += D4D_GetCharWidth(ix, ((D4D_TCHAR*)d4d_extsrcBuffer)[charCntTmp]); }while(charCnt == D4D_EXTSRC_BUFF_SIZE); }else #endif { while(*(pTextInt) != 0) width += D4D_GetCharWidth(ix, *pTextInt++); } return width; }
static D4D_INDEX D4D_CnslFindMaxTextLenght(D4D_TCHAR* pText, D4D_FONT font, D4D_INDEX startOffset, D4D_INDEX maxLenght) { D4D_INDEX result;// = _calc.charArrSize.cx; D4D_COOR tmp_textWidth; result = 0; tmp_textWidth = 0; while((pText[result] != 0) && ((result + startOffset) < maxLenght)) { if(tmp_textWidth >= (_calc.txtGeom.sz.cx - 4)) break; result++; tmp_textWidth += D4D_GetCharWidth(font, pText[result]); } return result; }
/**************************************************************//*! * * Print the String in ASCII in simple format up to 8 columns * ******************************************************************/ void D4D_LCD_PrintStr(D4D_PRINT_DESC* p_StrDes) { D4D_INDEX str_len, ch_ix; D4D_COOR orig_x = p_StrDes->x; D4D_COOR base_y, base_x; D4D_FONT_TYPE* pFontType = (D4D_FONT_TYPE*)p_StrDes->pFontType; D4D_FONT_DESCRIPTOR* pFontDescriptor = (D4D_FONT_DESCRIPTOR*)(pFontType->pFontDescriptor); const D4D_TCHAR pLongTextEnd[] = D4D_DEFSTR("..."); D4D_BOOL longText = D4D_FALSE; D4D_COOR tmp_MaxLen = p_StrDes->maxWidth; D4D_COOR longTextLen; D4D_TCHAR* pTextInt; // check if fontdescriptor exist and check the font scale value if((pFontDescriptor == NULL) || (pFontType->scale.width == 0) || (pFontType->scale.height == 0)) return; // long strings restriction if(tmp_MaxLen) { // check if the text fits into enabled width D4D_STRING tmpString; D4D_COOR tmp_txtLen; tmpString.pText = p_StrDes->pText; tmpString.buffSize = 0; tmpString.fontId = p_StrDes->pFontType->ix_font; tmpString.printLen = p_StrDes->textLength; tmpString.printOff = p_StrDes->textOffset; tmp_txtLen = D4D_GetTextBuffWidthTab(&tmpString, p_StrDes->pTab); if(p_StrDes->pTab) { if(tmp_txtLen > p_StrDes->pTab->tabOffset) tmp_txtLen -= p_StrDes->pTab->tabOffset; else return; } longTextLen = D4D_GetTextWidth(tmpString.fontId, (D4D_TCHAR*)pLongTextEnd); if(tmp_txtLen > p_StrDes->maxWidth) { if(tmp_txtLen < longTextLen) return; tmp_MaxLen -= longTextLen; longText = D4D_TRUE; } } pTextInt = D4D_GetInternalStringPointer(p_StrDes->pText); #if D4D_EXTSRC_TEXT_ENABLE != D4D_FALSE if(pTextInt == NULL) { D4D_INDEX charCnt = 0; D4D_INDEX charOff = p_StrDes->textOffset; D4D_INDEX charCntTmp; do { charOff += charCnt; charCnt = (D4D_INDEX)d4d_extsrcLocale.D4DLOCALE_TranslateStr(p_StrDes->pText, (D4D_TCHAR*)d4d_extsrcBuffer, charOff, D4D_EXTSRC_BUFF_SIZE); // get the lenght of string str_len = charCnt; if(p_StrDes->textLength) if(str_len > p_StrDes->textLength) str_len = p_StrDes->textLength; str_len += (charOff - 1); for(charCntTmp = 0; charCntTmp < charCnt; charCntTmp++) { if((!((D4D_TCHAR*)d4d_extsrcBuffer)[charCntTmp]) || (str_len < (charCntTmp + charOff))) { charCnt = 0; break; } if(longText) { D4D_COOR tmp_Len; tmp_Len = D4D_GetCharWidth(p_StrDes->pFontType->ix_font, ((D4D_TCHAR*)d4d_extsrcBuffer)[charCntTmp]); if(tmp_MaxLen - tmp_Len <= 0) { charCnt = 0; break; } tmp_MaxLen -= tmp_Len; } p_StrDes->x += D4D_LCD_PrintChr(((D4D_TCHAR*)d4d_extsrcBuffer)[charCntTmp], p_StrDes); // print the char and automatically update the coordintaion of next char } }while(charCnt == D4D_EXTSRC_BUFF_SIZE); }else #endif { pTextInt = &pTextInt[p_StrDes->textOffset]; // get the lenght of string str_len = D4D_GetTextLength(pTextInt); if(p_StrDes->textLength) if(str_len > p_StrDes->textLength) str_len = p_StrDes->textLength; // Draw the text for (ch_ix=0; ch_ix<str_len; ++ch_ix) // For each character in the string { if(longText) { D4D_COOR tmp_Len; tmp_Len = D4D_GetCharWidth(p_StrDes->pFontType->ix_font, *pTextInt); if(tmp_MaxLen - tmp_Len <= 0) { break; } tmp_MaxLen -= tmp_Len; } p_StrDes->x += D4D_LCD_PrintChr(*pTextInt++, p_StrDes); // print the char and automatically update the coordintaion of next char } } if(longText) { ch_ix=0; while(pLongTextEnd[ch_ix]) p_StrDes->x += D4D_LCD_PrintChr(pLongTextEnd[ch_ix++], p_StrDes); // print the char and automatically update the coordintaion of next char if(!(p_StrDes->properties & D4D_FNT_PRTY_TRANSPARENT_MASK)) D4D_FillRectXY(p_StrDes->x, p_StrDes->y, (D4D_COOR)(orig_x + p_StrDes->maxWidth - 1), (D4D_COOR)(p_StrDes->y + D4D_GetFontHeight(p_StrDes->pFontType->ix_font) - 1), p_StrDes->colorBack); } // Draw the Underline option switch(p_StrDes->properties & D4D_FNT_PRTY_UNDERLINE_MASK) { case D4D_FNT_PRTY_UNDERLINE_LINE_MASK: // Draw the full line base_y = (D4D_COOR)(p_StrDes->y + pFontDescriptor->charBaseLine * pFontType->scale.height); base_x = p_StrDes->x; D4D_FillRectXY(orig_x, base_y, (D4D_COOR)(base_x - 1), (D4D_COOR)(base_y + pFontType->scale.height - 1), p_StrDes->colorText); break; case D4D_FNT_PRTY_UNDERLINE_DOT_MASK: // Draw the dot line base_y = (D4D_COOR)(p_StrDes->y + pFontDescriptor->charBaseLine * pFontType->scale.height); ch_ix = 0; for(base_x = orig_x; base_x < p_StrDes->x; base_x += pFontType->scale.height) { if(++ch_ix % 2) D4D_FillRectXY(base_x, base_y, (D4D_COOR)(base_x + pFontType->scale.width - 1), (D4D_COOR)(base_y + pFontType->scale.height - 1), p_StrDes->colorText); } break; default: break; } // Draw the Strike Through option if(p_StrDes->properties & D4D_FNT_PRTY_STRIKETHROUGH_MASK) { Byte line_cnt = (Byte)((p_StrDes->properties & D4D_FNT_PRTY_STRIKETHROUGH_MASK) >> D4D_FNT_PRTY_STRIKETHROUGH_SHIFT); base_y = (D4D_COOR)(p_StrDes->y + (pFontDescriptor->charBaseLine - (pFontDescriptor->charSize / 3)) * pFontType->scale.height); base_x = p_StrDes->x; // Draw Strike Through line as many as specified by parameter while(line_cnt) { D4D_FillRectXY(orig_x, base_y, (D4D_COOR)(base_x - 1), (D4D_COOR)(base_y - 1), p_StrDes->colorText); base_y -=2; line_cnt--; } }
/**************************************************************************/ /*! * @brief The function find out the maximal text length that fits to maximal pixel width * @param pString - pointer to full string descriptor (MUST be full filled) * @param maxWidth - maximal width where the text should fits * @return length of text that's fits to given maximal width * @note None. *******************************************************************************/ D4D_INDEX D4D_GetTextMaxLength(D4D_STRING* pString, D4D_COOR maxWidth) { D4D_TCHAR* pText; D4D_COOR width; D4D_INDEX cnt = 0; D4D_TCHAR* pTextInt; if(pString == NULL) return 0; pText = pString->pText; if(pText == NULL) return 0; pTextInt = D4D_GetInternalStringPointer(pText); #if D4D_EXTSRC_TEXT_ENABLE != D4D_FALSE if(pTextInt == NULL) { D4D_INDEX charCnt = 0; D4D_INDEX charOff = pString->printOff; D4D_INDEX charCntTmp; do { charOff += charCnt; charCnt = (D4D_INDEX)d4d_extsrcLocale.D4DLOCALE_TranslateStr(pText, (D4D_TCHAR*)d4d_extsrcBuffer, charOff, D4D_EXTSRC_BUFF_SIZE); for(charCntTmp = 0; charCntTmp < charCnt; charCntTmp++) { if(((D4D_TCHAR*)d4d_extsrcBuffer)[charCntTmp] == 0) return cnt; if(cnt >= pString->printLen) return cnt; width = D4D_GetCharWidth(pString->fontId, *pText); if(width > maxWidth) return cnt; maxWidth -= width; cnt++; } }while(charCnt == D4D_EXTSRC_BUFF_SIZE); } else #endif { pTextInt += pString->printOff; while(*pTextInt != 0) { if(cnt >= pString->printLen) break; width = D4D_GetCharWidth(pString->fontId, *pTextInt); if(width > maxWidth) break; maxWidth -= width; pTextInt++; cnt++; } } return cnt; }
/**************************************************************************/ /*! * @brief The function returns width of text in pixels, also with tab table * @param text_buffer - pointer to full string descriptor (MUST be full filled) * @param pTab - pointer to teb table * @return width of text in pixels * @note The function find out the width of string printed with all specified properties in string descriptor. *******************************************************************************/ D4D_COOR D4D_GetTextBuffWidthTab(D4D_STRING* text_buffer, D4D_TAB* pTab){ D4D_COOR width = 0; D4D_COOR tab; D4D_INDEX char_ix = 0; D4D_TCHAR* pText = text_buffer->pText; D4D_TCHAR* pTextInt; if(pText == NULL) return 0; pTextInt = D4D_GetInternalStringPointer(pText); #if D4D_EXTSRC_TEXT_ENABLE != D4D_FALSE if(pTextInt == NULL) { D4D_INDEX charCnt = 0; D4D_INDEX charOff = text_buffer->printOff; D4D_INDEX charCntTmp; do { charOff += charCnt; charCnt = (D4D_INDEX)d4d_extsrcLocale.D4DLOCALE_TranslateStr(pText, (D4D_TCHAR*)d4d_extsrcBuffer, charOff, D4D_EXTSRC_BUFF_SIZE); for(charCntTmp = 0; charCntTmp < charCnt; charCntTmp++) { if(++char_ix > text_buffer->printLen) return width; if(((D4D_TCHAR*)d4d_extsrcBuffer)[charCntTmp] == '\t') { tab = D4D_GetNextTab(pTab, width); if(tab) { width = (D4D_COOR)(tab - (pTab->tabOffset)); continue; } } width += D4D_GetCharWidth(text_buffer->fontId, ((D4D_TCHAR*)d4d_extsrcBuffer)[charCntTmp]); } }while(charCnt == D4D_EXTSRC_BUFF_SIZE); }else #endif { pTextInt += text_buffer->printOff; while(*pTextInt != 0) { if(++char_ix > text_buffer->printLen) break; if(*pTextInt == '\t') { tab = D4D_GetNextTab(pTab, width); if(tab) { width = (D4D_COOR)(tab - (pTab->tabOffset)); pTextInt++; continue; } } width += D4D_GetCharWidth(text_buffer->fontId, *pTextInt); pTextInt++; } } return width; }
static D4D_BOOL D4D_TextBoxGetCharsToLine(D4D_TXTBX_WORD_DESC* wordDesc) { D4D_TCHAR* pTmpWord = wordDesc->pWord; D4D_COOR len, tmp_len; len = wordDesc->pixLen; wordDesc->pixLen = 0; wordDesc->newLine = D4D_FALSE; wordDesc->charCnt = 0; if(pTmpWord == NULL) return D4D_FALSE; pTmpWord = D4D_GetInternalStringPointer(pTmpWord); #if D4D_EXTSRC_TEXT_ENABLE != D4D_FALSE if(pTmpWord == NULL) { D4D_INDEX charCnt = 0; D4D_INDEX charOff = wordDesc->offset; D4D_INDEX charCntTmp; do { charOff += charCnt; charCnt = (D4D_INDEX)d4d_extsrcLocale.D4DLOCALE_TranslateStr(pTmpWord, (D4D_TCHAR*)d4d_extsrcBuffer, charOff, D4D_EXTSRC_BUFF_SIZE); for(charCntTmp = 0; charCntTmp < charCnt; charCntTmp++) { tmp_len = D4D_GetCharWidth(wordDesc->fnt, ((D4D_TCHAR*)d4d_extsrcBuffer)[charCntTmp]); // normal char if((wordDesc->pixLen + tmp_len) > len) return D4D_TRUE; wordDesc->pixLen += tmp_len; wordDesc->charCnt++; // increament the one processed char } }while(charCnt == D4D_EXTSRC_BUFF_SIZE); } else #endif { pTmpWord += wordDesc->offset; while(*pTmpWord) // check if the tested strings isn't on end { tmp_len = D4D_GetCharWidth(wordDesc->fnt, *pTmpWord); // normal char if((wordDesc->pixLen + tmp_len) > len) return D4D_TRUE; wordDesc->pixLen += tmp_len; wordDesc->charCnt++; // increament the one processed char pTmpWord++; // increment WORD pointer to next char } } return D4D_TRUE; }
static void D4D_ConsoleOnDraw(D4D_MESSAGE* pMsg) { D4D_OBJECT* pThis = pMsg->pObject; D4D_CONSOLE* pCnsl = D4D_GET_CONSOLE(pThis); D4D_CNSL_DATA* pData = pCnsl->pData; D4D_OBJECT_DRAWFLAGS draw = pMsg->prm.draw; D4D_COLOR clrT, clrB; D4D_INDEX line_cnt, tmp_realLine; D4D_POINT tmp_point; D4D_SIZE tmp_size, tmp_winOff; D4D_STRING tmp_txtbuff; D4D_STR_PROPERTIES tmp_strPrties; D4D_BOOL tmp_font_proporcional = D4D_FALSE; D4D_CnslValue2Coor(pThis); clrT = D4D_ObjectGetForeFillColor(pThis); clrB = D4D_ObjectGetBckgFillColor(pThis); // draw the rectangle around the text if(draw & D4D_OBJECT_DRAWFLAGS_COMPLETE) { D4D_FillRRect(&_calc.position, &pThis->size, clrB, pThis->radius); pData->flags |= (D4D_CNSL_FLAGS_REDRAWALL | D4D_CNSL_FLAGS_REDRAWLINE | D4D_CNSL_FLAGS_REDRAWCURSOR); } // Draw the frame if(draw & (D4D_OBJECT_DRAWFLAGS_COMPLETE | D4D_OBJECT_DRAWFLAGS_STATE)) D4D_DrawFrame(pThis, clrT, clrB); tmp_winOff.cx = (D4D_COOR)D4D_ScrlBrGetPosition(D4D_GET_LIST_BOX_SCROLL_BAR_HOR(pThis)); tmp_winOff.cy = (D4D_COOR)D4D_ScrlBrGetPosition(D4D_GET_LIST_BOX_SCROLL_BAR_VER(pThis)); tmp_strPrties.font_properties = 0; tmp_strPrties.text_properties = 0; tmp_txtbuff.fontId = pCnsl->textFontId; tmp_txtbuff.str_properties = &tmp_strPrties; tmp_txtbuff.printOff = 0; if(pData->flags & (D4D_CNSL_FLAGS_REDRAWALL | D4D_CNSL_FLAGS_REDRAWLINE)) { // Draw all lines of console tmp_point = _calc.txtGeom.pnt; tmp_size.cx = _calc.txtGeom.sz.cx; tmp_size.cy = D4D_GetFontHeight(pCnsl->textFontId); if(D4D_GetFont(pCnsl->textFontId)->pFontDescriptor->flags & D4D_FONT_FLAGS_FNT_WIDTH_PROPORTIONAL) tmp_font_proporcional = D4D_TRUE; for(line_cnt = 0; line_cnt < _calc.charArrSize.cy; line_cnt++) { if(!(pData->flags & D4D_CNSL_FLAGS_REDRAWALL)) if(line_cnt != pData->cursorPos.y) { tmp_point.y += tmp_size.cy; continue; } // Compute the real line in memory tmp_realLine = (D4D_INDEX)((pData->lastLineIx + line_cnt + tmp_winOff.cy) % pCnsl->txtArrSize.cy); // found the right pointer of the text to draw in the text array tmp_txtbuff.pText = (D4D_TCHAR*)(pCnsl->pTxtArr + tmp_realLine * (pCnsl->txtArrSize.cx + 1) + tmp_winOff.cx); if((tmp_winOff.cx + _calc.charArrSize.cx) <= pCnsl->txtArrSize.cx) { if(tmp_font_proporcional) tmp_txtbuff.printLen = D4D_CnslFindMaxTextLenght(tmp_txtbuff.pText, pCnsl->textFontId, tmp_winOff.cx, pCnsl->txtArrSize.cx); else tmp_txtbuff.printLen = _calc.charArrSize.cx; tmp_txtbuff.buffSize = 0; } D4D_DrawTextRect(&tmp_point, &tmp_size, &tmp_txtbuff, clrT, clrB); tmp_point.y += tmp_size.cy; } } // redraw cursor if(((D4D_INDEX_DELTA)(pData->cursorPos.y - tmp_winOff.cy) >= 0) && ((pData->cursorPos.y - tmp_winOff.cy) < _calc.charArrSize.cy) && (pData->cursorPos.x >= tmp_winOff.cx)) //cursor is on screen - check line and also and check the axis X { D4D_BOOL cursorVisible = D4D_FALSE; // Compute the real line in memory tmp_realLine = (D4D_INDEX)((pData->lastLineIx + pData->cursorPos.y) % pCnsl->txtArrSize.cy); // found the right pointer of the text to draw in the text array tmp_txtbuff.pText = (D4D_TCHAR*)(pCnsl->pTxtArr + tmp_realLine * (pCnsl->txtArrSize.cx + 1) + tmp_winOff.cx); // Check if the cursor is visible on the line tmp_txtbuff.printLen = D4D_CnslFindMaxTextLenght(tmp_txtbuff.pText, pCnsl->textFontId, tmp_winOff.cx, pData->cursorPos.x); if(*(tmp_txtbuff.pText + pData->cursorPos.x)) tmp_size.cx = D4D_GetCharWidth(pCnsl->textFontId, *(tmp_txtbuff.pText + pData->cursorPos.x)); else tmp_size.cx = D4D_GetCharWidth(pCnsl->textFontId, ' '); tmp_point.x = D4D_GetTextBuffWidthTab(&tmp_txtbuff, NULL); if(tmp_font_proporcional) { if(tmp_point.x < (D4D_COOR)( _calc.txtGeom.sz.cx - tmp_size.cx)) cursorVisible = D4D_TRUE; } else { if(pData->cursorPos.x < (D4D_INDEX)(_calc.charArrSize.cx + tmp_winOff.cx)) cursorVisible = D4D_TRUE; } if(cursorVisible) { tmp_point.y = (D4D_COOR)((pData->cursorPos.y - tmp_winOff.cy) * D4D_GetFontHeight(pCnsl->textFontId) + _calc.txtGeom.pnt.y);//??+1 tmp_point.x += _calc.txtGeom.pnt.x; tmp_size.cy = (D4D_COOR)((D4D_CNSL_CURSOR_HEIGHT > D4D_GetFontHeight(pCnsl->textFontId))? D4D_CNSL_CURSOR_HEIGHT : D4D_GetFontHeight(pCnsl->textFontId)); // check the state of cursor and selected right color if((!(pData->flags & D4D_CNSL_FLAGS_CURSORSTATE)) || (!tmp_txtbuff.pText[0])) { // draw cursor D4D_COLOR clr; if(pData->flags & D4D_CNSL_FLAGS_CURSORSTATE) clr = clrB; else clr = clrT; tmp_point.y += (D4D_GetFontHeight(pCnsl->textFontId) - D4D_CNSL_CURSOR_HEIGHT - 1); tmp_size.cy = D4D_CNSL_CURSOR_HEIGHT; D4D_FillRect(&tmp_point, &tmp_size, clr); } else { // Draw the original char tmp_txtbuff.printOff = pData->cursorPos.x; tmp_txtbuff.printLen = 1; D4D_DrawTextRect(&tmp_point, &tmp_size, &tmp_txtbuff, clrT, clrB); } } } pData->flags &= ~(D4D_CNSL_FLAGS_REDRAWALL | D4D_CNSL_FLAGS_REDRAWLINE | D4D_CNSL_FLAGS_REDRAWCURSOR); }