70 lines
2.0 KiB
C++
70 lines
2.0 KiB
C++
#include "TextBlock.hpp"
|
|
|
|
#include <string.h>
|
|
#include <GUI_Paint.h>
|
|
|
|
|
|
//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): style(s), text(t)
|
|
{
|
|
}
|
|
|
|
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;
|
|
UWORD max_width = 2*Paint.Width;
|
|
|
|
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 ) > max_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)};
|
|
}
|
|
|
|
//}}
|