void ToasterBoxWindow::DrawText() { DCType dc(this); //width and height of text wxCoord w = 0, h = 0; //where we will set the text wxCoord x = 0, y = 0; //border from sides and top to text (in pixels) int border_right = 7; int border_left = 102; if (sbm.GetBitmap().IsOk()) { border_left += sbm.GetBitmap().GetWidth(); } //how much space between text lines int textPadding = 4; //how much can we have on a line? int textColumns = 0; //how many lines can we fit vertically float textLines = 1; //the popupText after our transformations (if we do any) wxString pText = GetPopupText(); wxFont outFont(9, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_BOLD); dc.SetFont(outFont); dc.GetMultiLineTextExtent(pText, &w, &h); //shrink the text to fit in the popup box if (shrink) { while ((w + (border_right + border_left)) > GetSize().GetWidth()) { pText = pText.Left(pText.Length() - 1); dc.GetMultiLineTextExtent(pText, &w, &h); } textColumns = pText.Length(); //figure out how many lines of text we have textLines = (GetPopupText().Length() / textColumns) + .9; } bool haveHeader = false; if (popupHeaderText.IsEmpty() == false) { textLines++; haveHeader = true; } //center the text // if(w < GetSize().GetWidth()) // x = (GetSize().GetWidth() - w) / 2; // if(h < GetSize().GetHeight()) // y = (GetSize().GetHeight() - h) / 2; // //if we have multiple lines if (textLines > 1) { if (haveHeader) { //Draw header text with a shadow effect dc.SetTextForeground(*wxGREEN); //Try to center header text auto textSize = dc.GetTextExtent(popupHeaderText); int headerX = (GetSize().GetWidth() / 2) - (textSize.GetWidth() / 2); const int headerY = 3; dc.DrawText(popupHeaderText, headerX, headerY); dc.SetTextForeground(headerTextColor); dc.DrawText(popupHeaderText, headerX + 1, headerY + 1); //This makes "shadow" effect } dc.SetTextForeground(textColor); //how many lines we can fit in the height available float howManyLinesFit = GetSize().GetHeight() / (h + textPadding); if (textLines < howManyLinesFit) howManyLinesFit = textLines; y = (GetSize().GetHeight() - ((h + textPadding) * howManyLinesFit)) / 2; //Move text down a bit to get place for header if (haveHeader) { y += 15; } for (int i = 0; i < howManyLinesFit; i++) { dc.DrawText(GetPopupText().Mid((i * textColumns), textColumns), x + border_left, y); //move the text down a line y += h + textPadding; } } else { dc.SetTextForeground(textColor); dc.DrawText(pText, x, y); } }
void ToasterBoxWindow::DrawText() { DCType dc( this ); #ifdef __WXMSW__ // dc.SetBackground( *wxBLACK_BRUSH ); // dc.Clear(); dc.DrawBitmap(charArr2wxBitmap( notif_bg_png, sizeof(notif_bg_png) ), 0, 0, false); #endif //width and height of text wxCoord w = 0, h = 0; //where we will set the text wxCoord x = 0, y = 0; //border from sides and top to text (in pixels) int border_right = 7; int border_left = sbm.GetBitmap().GetWidth() + 102; //how much space between text lines int textPadding = 4; //how much can we have on a line? int textColumns = 0; //how many lines can we fit vertically float textLines = 1; //the popupText after our transformations (if we do any) wxString pText = GetPopupText(); wxFont outFont( 9, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_BOLD ); dc.SetFont( outFont ); dc.GetTextExtent(pText, &w, &h); //shrink the text to fit in the popup box if(shrink) { while((w +(border_right + border_left))> GetSize().GetWidth()) { pText = pText.Left(pText.Length()-1); dc.GetTextExtent(pText, &w, &h); } textColumns = pText.Length(); //figure out how many lines of text we have textLines = (GetPopupText().Length() / textColumns) +.9; } //center the text // if(w < GetSize().GetWidth()) // x = (GetSize().GetWidth() - w) / 2; // if(h < GetSize().GetHeight()) // y = (GetSize().GetHeight() - h) / 2; dc.SetTextForeground(textColor); // //if we have multiple lines if(textLines > 1) { //how many lines we can fit in the height available float howManyLinesFit = GetSize().GetHeight() / (h+textPadding); if(textLines < howManyLinesFit) howManyLinesFit = textLines; y = (GetSize().GetHeight() - ((h+textPadding) * howManyLinesFit)) / 2; for(int i = 0; i < howManyLinesFit; i++) { dc.DrawText(GetPopupText().Mid((i*textColumns), textColumns), x + border_left,y); //move the text down a line y += h+textPadding; } } else dc.DrawText(pText, x,y); }