#include "TextBlock.hpp" #include #include //namespace myink { namespace ui { PositionalProperties Paint_DrawString(UWORD Xstart, UWORD Ystart, const char * pString, sFONT* Font, UWORD Color_Foreground, UWORD Color_Background); TextBlock::TextBlock(const char * t, const TextBlockStyleProperties & s): text(t), style(s) { } TextBlock::~TextBlock() { } PositionalProperties TextBlock::draw(const PositionalProperties & p) { auto font = style.font; return Paint_DrawString(p.left, p.top, text, &font, style.background_color, style.font_color); } PositionalProperties Paint_DrawString(UWORD Xstart, UWORD Ystart, const char * pString, sFONT* Font, UWORD Color_Foreground, UWORD Color_Background) { UWORD Xpoint = Xstart; UWORD max_x_pos = Xstart; UWORD max_y_pos = Ystart + Font->Height; UWORD Ypoint = Ystart; while (* pString != '\0') { //if X direction filled , reposition to(Xstart,Ypoint),Ypoint is Y direction plus the Height of the character if (*pString == '\n'|| (Xpoint + Font->Width ) > Paint.Width ) { Xpoint = Xstart; Ypoint += Font->Height; if(Ypoint >= max_y_pos) { max_y_pos = Ypoint + Font->Height; } if (*pString == '\n') { pString++; } } // If the Y direction is full, reposition to(Xstart, Ystart) if ((Ypoint + Font->Height ) > Paint.Height ) { Xpoint = Xstart; Ypoint = Ystart; } Paint_DrawChar(Xpoint, Ypoint, * pString, Font, Color_Background, Color_Foreground); //The next character of the address pString ++; //The next word of the abscissa increases the font of the broadband Xpoint += Font->Width; if(Xpoint > max_x_pos) { max_x_pos = Xpoint; } } return{Xstart, Ystart, max_x_pos - Xstart, (max_y_pos - Ystart)}; } //}}