static void addCreditsLine(std::string & phrase, float & drawpos) { //Create a data containers CreditsTextInformations infomations; infomations.fColors = ExtractPhraseColor(phrase); //int linesize = hFontCredits->GetTextSize(phrase).x; static const int MARGIN_WIDTH = 20; Rect linerect(g_size.width() - MARGIN_WIDTH - MARGIN_WIDTH, hFontCredits->getLineHeight()); while(!phrase.empty()) { // Split long lines long n = ARX_UNICODE_ForceFormattingInRect(hFontCredits, phrase, linerect); arx_assert(n >= 0 && size_t(n) < phrase.length()); infomations.sText = phrase.substr(0, size_t(n + 1) == phrase.length() ? n + 1 : n); phrase = phrase.substr(n + 1); // Center the text on the screen int linesize = hFontCredits->getTextSize(infomations.sText).x; infomations.sPos.x = (g_size.width() - linesize) / 2; LogDebug("credit line: '" << infomations.sText << "' (" << linesize << "," << infomations.sText.length() << ")"); // Calculate height position infomations.sPos.y = static_cast<int>(drawpos); drawpos += CreditsData.iFontAverageHeight; CreditsData.aCreditsInformations.push_back(infomations); } }
void QtBasicGraph::paintEvent(QPaintEvent *e) { QPainter p(this); if (m_render_hints) p.setRenderHints(m_render_hints); p.fillRect(e->rect(), palette().background()); if (m_values.size() < 2) return; p.setPen(palette().color(QPalette::Text)); qreal scalex = qreal(width()) / m_xrange; qreal scaley = qreal(height()) / (m_ymax - m_ymin); qreal dx = qreal(3) / scalex; qreal dy = qreal(3) / scaley; QRectF bound(e->rect().x() / scalex, m_ymin + e->rect().y() / scaley, e->rect().width() / scalex, e->rect().height() / scaley); QPointF last = m_values.last(); qreal tx = m_xrange - last.x(); qreal ty = m_ymin; p.scale(scalex, -scaley); p.translate(tx, ty); QVarLengthArray<QLineF> lines; for (int i = m_values.size() - 1; i >= 0; --i) { QPointF pt = m_values[i]; QRectF linerect(last, pt); linerect = linerect.normalized().translated(tx, 0); linerect.adjust(-dx, -dy, dx, dy); if (bound.intersects(linerect)) lines.append(QLineF(last, pt)); last = pt; } // if (lines.size() < (m_values.size()-1)) // qWarning("skipped %d lines", (m_values.size()-1) -lines.size()); p.drawLines(lines.constData(), lines.size()); }