Esempio n. 1
0
EnrichedText* JMChattControl::StringToEnrichedText(String strText, Color colorText)
{
	result r = E_SUCCESS;


	int nTextWidth = __stScreenInfo.nTextBoxWidth - (__stScreenInfo.nTextBoxInsideGap * 2);
	Dimension dimText;

	__stScreenInfo.fontText.GetTextExtent(strText, strText.GetLength(), dimText);
	if( dimText.width < nTextWidth )
		nTextWidth = dimText.width;

	EnrichedText* pEnrichedText = null;
	TextElement* pTextElement1 = null;
	pEnrichedText = new EnrichedText();
	r = pEnrichedText->Construct(Dimension(nTextWidth, __stScreenInfo.rtScreen.height));
	if (IsFailed(r)) {
		return null;
	}
	pEnrichedText->SetHorizontalAlignment(TEXT_ALIGNMENT_LEFT);
	pEnrichedText->SetVerticalAlignment(TEXT_ALIGNMENT_TOP);
	pEnrichedText->SetTextWrapStyle(TEXT_WRAP_WORD_WRAP);
	pEnrichedText->SetTextAbbreviationEnabled(false);

	// Create a TextElement and set attributes.
	pTextElement1 = new TextElement();
	r = pTextElement1->Construct(strText);
	if (IsFailed(r)) {
		return null;
	}
	pTextElement1->SetTextColor(colorText);
	pTextElement1->SetFont(__stScreenInfo.fontText);
	// Add the TextElement to the EnrichedText
	pEnrichedText->Add(*pTextElement1);


	pEnrichedText->SetSize(nTextWidth, pEnrichedText->GetTotalLineHeight());

	return pEnrichedText;
}
Esempio n. 2
0
void JMChattControl::DrawMultiLineText(Canvas* pCanvas, String strText, Rectangle rtArea, Color colorText, Color colorBack)
{
	AppLog("3333DrawMultiLineText");
	result r = E_SUCCESS;

	EnrichedText* pEnrichedText = null;
	TextElement* pTextElement1 = null;
	pEnrichedText = new EnrichedText();
	r = pEnrichedText->Construct(Dimension(rtArea.width, rtArea.height));
    if (IsFailed(r)) {
		return;
    }
    pEnrichedText->SetHorizontalAlignment(TEXT_ALIGNMENT_LEFT);
    pEnrichedText->SetVerticalAlignment(TEXT_ALIGNMENT_TOP);
    pEnrichedText->SetTextWrapStyle(TEXT_WRAP_CHARACTER_WRAP);
    pEnrichedText->SetTextAbbreviationEnabled(false);

	// Create a TextElement and set attributes.
	pTextElement1 = new TextElement();
	r = pTextElement1->Construct(strText);
	if (IsFailed(r)) {
		return;
	}
	pTextElement1->SetTextColor(colorText);
    pTextElement1->SetFont(__stScreenInfo.fontText);
    // Add the TextElement to the EnrichedText
    pEnrichedText->Add(*pTextElement1);
    pCanvas->SetBackgroundColor(colorBack);



    // Draw the EnrichedText at the specified Point
    pCanvas->DrawText(Point(rtArea.x, rtArea.y), *pEnrichedText);
    // Clean up
    pEnrichedText->RemoveAllTextElements(true);
    delete pEnrichedText;
}
 result DrawElement(const Osp::Graphics::Canvas& canvas, const Osp::Graphics::Rectangle& rect, CustomListItemStatus itemStatus)
 {
     result r = E_SUCCESS;

     Canvas* pCanvas = const_cast<Canvas*>(&canvas);

     Font textfont;
     textfont.Construct(Osp::Graphics::FONT_STYLE_PLAIN, 28);

     EnrichedText texteel;
     texteel.Construct(Dimension(rect.width, rect.height));
   	 texteel.SetHorizontalAlignment(Osp::Graphics::TEXT_ALIGNMENT_LEFT);
     texteel.SetVerticalAlignment(Osp::Graphics::TEXT_ALIGNMENT_MIDDLE);
     texteel.SetTextWrapStyle(TEXT_WRAP_CHARACTER_WRAP);
     texteel.SetTextAbbreviationEnabled(true);
     TextElement textelcol;
     textelcol.Construct(text);
     textelcol.SetTextColor(Color::COLOR_WHITE);
     textelcol.SetFont(textfont);
     texteel.Add(textelcol);
     pCanvas->DrawText(Point(0,0), texteel);

     return r;
 }