bool Float::fillFrame() { auto creating = _frame.isNull(); if (creating) { _frame = QImage(getInnerRect().size() * cIntRetinaFactor(), QImage::Format_ARGB32_Premultiplied); _frame.setDevicePixelRatio(cRetinaFactor()); } auto frameInner = [this] { return QRect(0, 0, _frame.width() / cIntRetinaFactor(), _frame.height() / cIntRetinaFactor()); }; if (auto reader = getReader()) { updatePlayback(); auto frame = reader->current(); if (!frame.isNull()) { _frame.fill(Qt::transparent); Painter p(&_frame); PainterHighQualityEnabler hq(p); p.drawPixmap(frameInner(), frame); return true; } } if (creating) { _frame.fill(Qt::transparent); Painter p(&_frame); PainterHighQualityEnabler hq(p); p.setPen(Qt::NoPen); p.setBrush(st::imageBg); p.drawEllipse(frameInner()); } return false; }
bool FadeAnimation::paint(Painter &p) { if (_cache.isNull()) return false; const auto cache = _cache; auto opacity = _animation.value(_visible ? 1. : 0.); p.setOpacity(opacity); if (_scale < 1.) { PainterHighQualityEnabler hq(p); auto targetRect = QRect( (1 - kWideScale) / 2 * _size.width(), (1 - kWideScale) / 2 * _size.height(), kWideScale * _size.width(), kWideScale * _size.height()); auto scale = opacity + (1. - opacity) * _scale; auto shownWidth = anim::interpolate( (1 - kWideScale) / 2 * _size.width(), 0, scale); auto shownHeight = anim::interpolate( (1 - kWideScale) / 2 * _size.height(), 0, scale); auto margins = QMargins( shownWidth, shownHeight, shownWidth, shownHeight); p.drawPixmap(targetRect.marginsAdded(margins), cache); } else { p.drawPixmap(0, 0, cache); } return true; }
void EmojiButton::paintEvent(QPaintEvent *e) { Painter p(this); auto ms = getms(); p.fillRect(e->rect(), st::historyComposeAreaBg); paintRipple(p, _st.rippleAreaPosition.x(), _st.rippleAreaPosition.y(), ms); auto loading = a_loading.current(ms, _loading ? 1 : 0); p.setOpacity(1 - loading); auto over = isOver(); auto icon = &(over ? _st.iconOver : _st.icon); icon->paint(p, _st.iconPosition, width()); p.setOpacity(1.); auto pen = (over ? st::historyEmojiCircleFgOver : st::historyEmojiCircleFg)->p; pen.setWidth(st::historyEmojiCircleLine); pen.setCapStyle(Qt::RoundCap); p.setPen(pen); p.setBrush(Qt::NoBrush); PainterHighQualityEnabler hq(p); QRect inner(QPoint((width() - st::historyEmojiCircle.width()) / 2, st::historyEmojiCircleTop), st::historyEmojiCircle); if (loading > 0) { int32 full = FullArcLength; int32 start = qRound(full * float64(ms % st::historyEmojiCirclePeriod) / st::historyEmojiCirclePeriod), part = qRound(loading * full / st::historyEmojiCirclePart); p.drawArc(inner, start, full - part); } else { p.drawEllipse(inner); } }
void FilledSlider::paintEvent(QPaintEvent *e) { Painter p(this); PainterHighQualityEnabler hq(p); p.setPen(Qt::NoPen); auto masterOpacity = fadeOpacity(); auto ms = getms(); auto disabled = isDisabled(); auto over = getCurrentOverFactor(ms); auto lineWidth = _st.lineWidth + ((_st.fullWidth - _st.lineWidth) * over); auto lineWidthRounded = qFloor(lineWidth); auto lineWidthPartial = lineWidth - lineWidthRounded; auto seekRect = getSeekRect(); auto value = getCurrentValue(ms); auto from = seekRect.x(), mid = qRound(from + value * seekRect.width()), end = from + seekRect.width(); if (mid > from) { p.setOpacity(masterOpacity); p.fillRect(from, height() - lineWidthRounded, (mid - from), lineWidthRounded, disabled ? _st.disabledFg : _st.activeFg); if (lineWidthPartial > 0.01) { p.setOpacity(masterOpacity * lineWidthPartial); p.fillRect(from, height() - lineWidthRounded - 1, (mid - from), 1, disabled ? _st.disabledFg : _st.activeFg); } } if (end > mid && over > 0) { p.setOpacity(masterOpacity * over); p.fillRect(mid, height() - lineWidthRounded, (end - mid), lineWidthRounded, _st.inactiveFg); if (lineWidthPartial > 0.01) { p.setOpacity(masterOpacity * over * lineWidthPartial); p.fillRect(mid, height() - lineWidthRounded - 1, (end - mid), 1, _st.inactiveFg); } } }
void Float::paintEvent(QPaintEvent *e) { Painter p(this); p.setOpacity(_opacity); p.drawPixmap(0, 0, _shadow); if (!fillFrame() && _toggleCallback) { _toggleCallback(false); } auto inner = getInnerRect(); p.drawImage(inner.topLeft(), _frame); auto progress = _roundPlayback ? _roundPlayback->value(getms()) : 1.; if (progress > 0.) { auto pen = st::historyVideoMessageProgressFg->p; auto was = p.pen(); pen.setWidth(st::radialLine); pen.setCapStyle(Qt::RoundCap); p.setPen(pen); p.setOpacity(_opacity * st::historyVideoMessageProgressOpacity); auto from = QuarterArcLength; auto len = -qRound(FullArcLength * progress); auto stepInside = st::radialLine / 2; { PainterHighQualityEnabler hq(p); p.drawArc(inner.marginsRemoved(QMargins(stepInside, stepInside, stepInside, stepInside)), from, len); } //p.setPen(was); //p.setOpacity(_opacity); } }
void DrawStaticLoading( QPainter &p, QRectF rect, int stroke, QPen pen, QBrush brush) { PainterHighQualityEnabler hq(p); p.setBrush(brush); pen.setWidthF(stroke); pen.setCapStyle(Qt::RoundCap); pen.setJoinStyle(Qt::RoundJoin); p.setPen(pen); p.drawEllipse(rect); const auto center = rect.center(); const auto first = QPointF(center.x(), rect.y() + 1.5 * stroke); const auto delta = center.y() - first.y(); const auto second = QPointF(center.x() + delta * 2 / 3., center.y()); if (delta > 0) { QPainterPath path; path.moveTo(first); path.lineTo(center); path.lineTo(second); p.drawPath(path); } }
void MediaSlider::paintEvent(QPaintEvent *e) { Painter p(this); PainterHighQualityEnabler hq(p); p.setPen(Qt::NoPen); p.setOpacity(fadeOpacity()); auto horizontal = isHorizontal(); auto ms = getms(); auto radius = _st.width / 2; auto disabled = isDisabled(); auto over = getCurrentOverFactor(ms); auto seekRect = getSeekRect(); auto value = getCurrentValue(ms); // invert colors and value for vertical if (!horizontal) value = 1. - value; auto markerFrom = (horizontal ? seekRect.x() : seekRect.y()); auto markerLength = (horizontal ? seekRect.width() : seekRect.height()); auto from = _alwaysDisplayMarker ? 0 : markerFrom; auto length = _alwaysDisplayMarker ? (horizontal ? width() : height()) : markerLength; auto mid = qRound(from + value * length); auto end = from + length; auto activeFg = disabled ? _st.activeFgDisabled : anim::brush(_st.activeFg, _st.activeFgOver, over); auto inactiveFg = disabled ? _st.inactiveFgDisabled : anim::brush(_st.inactiveFg, _st.inactiveFgOver, over); if (mid > from) { auto fromClipRect = horizontal ? QRect(0, 0, mid, height()) : QRect(0, 0, width(), mid); auto fromRect = horizontal ? QRect(from, (height() - _st.width) / 2, mid + radius - from, _st.width) : QRect((width() - _st.width) / 2, from, _st.width, mid + radius - from); p.setClipRect(fromClipRect); p.setBrush(horizontal ? activeFg : inactiveFg); p.drawRoundedRect(fromRect, radius, radius); } if (end > mid) { auto endClipRect = horizontal ? QRect(mid, 0, width() - mid, height()) : QRect(0, mid, width(), height() - mid); auto endRect = horizontal ? QRect(mid - radius, (height() - _st.width) / 2, end - (mid - radius), _st.width) : QRect((width() - _st.width) / 2, mid - radius, _st.width, end - (mid - radius)); p.setClipRect(endClipRect); p.setBrush(horizontal ? inactiveFg : activeFg); p.drawRoundedRect(endRect, radius, radius); } auto markerSizeRatio = disabled ? 0. : (_alwaysDisplayMarker ? 1. : over); if (markerSizeRatio > 0) { auto position = qRound(markerFrom + value * markerLength) - (horizontal ? seekRect.x() : seekRect.y()); auto seekButton = horizontal ? QRect(position, (height() - _st.seekSize.height()) / 2, _st.seekSize.width(), _st.seekSize.height()) : QRect((width() - _st.seekSize.width()) / 2, position, _st.seekSize.width(), _st.seekSize.height()); auto size = horizontal ? _st.seekSize.width() : _st.seekSize.height(); auto remove = static_cast<int>(((1. - markerSizeRatio) * size) / 2.); if (remove * 2 < size) { p.setClipRect(rect()); p.setBrush(activeFg); p.drawEllipse(seekButton.marginsRemoved(QMargins(remove, remove, remove, remove))); } } }
void CalendarBox::Inner::paintRows(Painter &p, QRect clip) { p.setFont(st::calendarDaysFont); auto ms = getms(); auto y = rowsTop(); auto index = -_context->daysShift(); auto highlightedIndex = _context->highlightedIndex(); for (auto row = 0, rowsCount = _context->rowsCount(), daysCount = _context->daysCount() ; row != rowsCount ; ++row, y += st::calendarCellSize.height()) { auto x = rowsLeft(); if (!myrtlrect(x, y, st::calendarCellSize.width() * kDaysInWeek, st::calendarCellSize.height()).intersects(clip)) { index += kDaysInWeek; continue; } for (auto col = 0; col != kDaysInWeek; ++col, ++index, x += st::calendarCellSize.width()) { auto rect = myrtlrect(x, y, st::calendarCellSize.width(), st::calendarCellSize.height()); auto grayedOut = (index < 0 || index >= daysCount || !rect.intersects(clip)); auto highlighted = (index == highlightedIndex); auto enabled = _context->isEnabled(index); auto innerLeft = x + (st::calendarCellSize.width() - st::calendarCellInner) / 2; auto innerTop = y + (st::calendarCellSize.height() - st::calendarCellInner) / 2; if (highlighted) { PainterHighQualityEnabler hq(p); p.setPen(Qt::NoPen); p.setBrush(grayedOut ? st::windowBgOver : st::dialogsBgActive); p.drawEllipse(myrtlrect(innerLeft, innerTop, st::calendarCellInner, st::calendarCellInner)); p.setBrush(Qt::NoBrush); } auto it = _ripples.find(index); if (it != _ripples.cend()) { auto colorOverride = [highlighted, grayedOut] { if (highlighted) { return grayedOut ? st::windowBgRipple : st::dialogsRippleBgActive; } return st::windowBgOver; }; it->second->paint(p, innerLeft, innerTop, width(), ms, &(colorOverride()->c)); if (it->second->empty()) { _ripples.erase(it); } } if (highlighted) { p.setPen(grayedOut ? st::windowSubTextFg : st::dialogsNameFgActive); } else if (enabled) { p.setPen(grayedOut ? st::windowSubTextFg : st::boxTextFg); } else { p.setPen(st::windowSubTextFg); } p.drawText(rect, _context->labelFromIndex(index), style::al_center); } } }
double *iter(double *y0, double x0, double a, double h, double *y, int cnt) { int i; double tmp; double *hlp = malloc (cnt * sizeof(double)); for (i = 0; i < cnt; i++) { tmp = func[i](x0, y0); y[i] = y0[i] + ((1 - a) * tmp + a * func[i](x0 + h / (2 * a), hq(y0, h,tmp, a, cnt, hlp))) * h; } free(hlp); return y; }
bool MultiSelect::Inner::Item::paintCached(Painter &p, int x, int y, int outerWidth) { PainterHighQualityEnabler hq(p); auto opacity = _visibility.current(_hiding ? 0. : 1.); auto scale = opacity + _st.minScale * (1. - opacity); auto height = opacity * _cache.height() / _cache.devicePixelRatio(); auto width = opacity * _cache.width() / _cache.devicePixelRatio(); p.setOpacity(opacity); p.drawPixmap(rtlrect(x + (_width - width) / 2., y + (_st.height - height) / 2., width, height, outerWidth), _cache); p.setOpacity(1.); return true; }
void MultiSelect::Inner::Item::paintDeleteButton(Painter &p, int x, int y, int outerWidth, float64 overOpacity) { p.setOpacity(overOpacity); p.setPen(Qt::NoPen); p.setBrush(_color); { PainterHighQualityEnabler hq(p); p.drawEllipse(rtlrect(x, y, _st.height, _st.height, outerWidth)); } CrossAnimation::paint(p, _st.deleteCross, _st.deleteFg, x, y, outerWidth, overOpacity); p.setOpacity(1.); }
QImage RippleAnimation::maskByDrawer(QSize size, bool filled, Fn<void(QPainter &p)> drawer) { auto result = QImage(size * cIntRetinaFactor(), QImage::Format_ARGB32_Premultiplied); result.setDevicePixelRatio(cRetinaFactor()); result.fill(filled ? QColor(255, 255, 255) : Qt::transparent); if (drawer) { Painter p(&result); PainterHighQualityEnabler hq(p); p.setPen(Qt::NoPen); p.setBrush(QColor(255, 255, 255)); drawer(p); } return result; }
void Float::prepareShadow() { auto shadow = QImage(size() * cIntRetinaFactor(), QImage::Format_ARGB32_Premultiplied); shadow.fill(Qt::transparent); shadow.setDevicePixelRatio(cRetinaFactor()); { Painter p(&shadow); PainterHighQualityEnabler hq(p); p.setPen(Qt::NoPen); p.setBrush(st::shadowFg); auto extend = 2 * st::lineWidth; p.drawEllipse(getInnerRect().marginsAdded(QMargins(extend, extend, extend, extend))); } _shadow = App::pixmapFromImageInPlace(Images::prepareBlur(std::move(shadow))); }
void SendButton::paintEvent(QPaintEvent *e) { Painter p(this); auto ms = getms(); auto over = (isDown() || isOver()); auto changed = _a_typeChanged.current(ms, 1.); if (changed < 1.) { PainterHighQualityEnabler hq(p); p.setOpacity(1. - changed); auto targetRect = QRect((1 - kWideScale) / 2 * width(), (1 - kWideScale) / 2 * height(), kWideScale * width(), kWideScale * height()); auto hiddenWidth = anim::interpolate(0, (1 - kWideScale) / 2 * width(), changed); auto hiddenHeight = anim::interpolate(0, (1 - kWideScale) / 2 * height(), changed); p.drawPixmap(targetRect.marginsAdded(QMargins(hiddenWidth, hiddenHeight, hiddenWidth, hiddenHeight)), _contentFrom); p.setOpacity(changed); auto shownWidth = anim::interpolate((1 - kWideScale) / 2 * width(), 0, changed); auto shownHeight = anim::interpolate((1 - kWideScale) / 2 * height(), 0, changed); p.drawPixmap(targetRect.marginsAdded(QMargins(shownWidth, shownHeight, shownWidth, shownHeight)), _contentTo); } else if (_type == Type::Record) { auto recordActive = recordActiveRatio(); auto rippleColor = anim::color(st::historyAttachEmoji.ripple.color, st::historyRecordVoiceRippleBgActive, recordActive); paintRipple(p, (width() - st::historyAttachEmoji.rippleAreaSize) / 2, st::historyAttachEmoji.rippleAreaPosition.y(), ms, &rippleColor); auto fastIcon = [recordActive, over, this] { if (recordActive == 1.) { return &st::historyRecordVoiceActive; } else if (over) { return &st::historyRecordVoiceOver; } return &st::historyRecordVoice; }; fastIcon()->paintInCenter(p, rect()); if (recordActive > 0. && recordActive < 1.) { p.setOpacity(recordActive); st::historyRecordVoiceActive.paintInCenter(p, rect()); p.setOpacity(1.); } } else if (_type == Type::Save) { auto &saveIcon = over ? st::historyEditSaveIconOver : st::historyEditSaveIcon; saveIcon.paint(p, st::historySendIconPosition, width()); } else if (_type == Type::Cancel) { paintRipple(p, (width() - st::historyAttachEmoji.rippleAreaSize) / 2, st::historyAttachEmoji.rippleAreaPosition.y(), ms); auto &cancelIcon = over ? st::historyReplyCancelIconOver : st::historyReplyCancelIcon; cancelIcon.paintInCenter(p, rect()); } else { auto &sendIcon = over ? st::historySendIconOver : st::historySendIcon; sendIcon.paint(p, st::historySendIconPosition, width()); } }
void PlayButtonLayout::paintPlayToCancel(Painter &p, const QBrush &brush, float64 progress) { static const auto sqrt2 = sqrt(2.); auto playLeft = 0. + _st.playPosition.x(); auto playTop = 0. + _st.playPosition.y(); auto playWidth = _st.playOuter.width() - 2 * playLeft; auto playHeight = _st.playOuter.height() - 2 * playTop; auto cancelLeft = 0. + _st.cancelPosition.x(); auto cancelTop = 0. + _st.cancelPosition.y(); auto cancelWidth = _st.cancelOuter.width() - 2 * cancelLeft; auto cancelHeight = _st.cancelOuter.height() - 2 * cancelTop; auto cancelStroke = (0. + _st.cancelStroke) / sqrt2; p.setPen(Qt::NoPen); PainterHighQualityEnabler hq(p); QPointF pathPlay[] = { { playLeft, playTop }, { playLeft, playTop }, { playLeft + (playWidth / 2.), playTop + (playHeight / 4.) }, { playLeft + playWidth, playTop + (playHeight / 2.) }, { playLeft + playWidth, playTop + (playHeight / 2.) }, { playLeft + playWidth, playTop + (playHeight / 2.) }, { playLeft + playWidth, playTop + (playHeight / 2.) }, { playLeft + playWidth, playTop + (playHeight / 2.) }, { playLeft + (playWidth / 2.), playTop + (3 * playHeight / 4.) }, { playLeft, playTop + playHeight }, { playLeft, playTop + playHeight }, { playLeft, playTop + (playHeight / 2.) }, }; QPointF pathCancel[] = { { cancelLeft, cancelTop + cancelStroke }, { cancelLeft + cancelStroke, cancelTop }, { cancelLeft + (cancelWidth / 2.), cancelTop + (cancelHeight / 2.) - cancelStroke }, { cancelLeft + cancelWidth - cancelStroke, cancelTop }, { cancelLeft + cancelWidth, cancelTop + cancelStroke }, { cancelLeft + (cancelWidth / 2.) + cancelStroke, cancelTop + (cancelHeight / 2.) }, { cancelLeft + cancelWidth, cancelTop + cancelHeight - cancelStroke }, { cancelLeft + cancelWidth - cancelStroke, cancelTop + cancelHeight }, { cancelLeft + (cancelWidth / 2.), cancelTop + (cancelHeight / 2.) + cancelStroke }, { cancelLeft + cancelStroke, cancelTop + cancelHeight }, { cancelLeft, cancelTop + cancelHeight - cancelStroke }, { cancelLeft + (cancelWidth / 2.) - cancelStroke, cancelTop + (cancelHeight / 2.) }, }; p.fillPath(interpolatePaths(pathPlay, pathCancel, progress), brush); }
void PlayButtonLayout::paintPlay(Painter &p, const QBrush &brush) { auto playLeft = 0. + _st.playPosition.x(); auto playTop = 0. + _st.playPosition.y(); auto playWidth = _st.playOuter.width() - 2 * playLeft; auto playHeight = _st.playOuter.height() - 2 * playTop; PainterHighQualityEnabler hq(p); p.setPen(Qt::NoPen); QPainterPath pathPlay; pathPlay.moveTo(playLeft, playTop); pathPlay.lineTo(playLeft + playWidth, playTop + (playHeight / 2.)); pathPlay.lineTo(playLeft, playTop + playHeight); pathPlay.lineTo(playLeft, playTop); p.fillPath(pathPlay, brush); }
void PlayButtonLayout::paintPauseToCancel(Painter &p, const QBrush &brush, float64 progress) { static const auto sqrt2 = sqrt(2.); auto pauseLeft = 0. + _st.pausePosition.x(); auto pauseTop = 0. + _st.pausePosition.y(); auto pauseWidth = _st.pauseOuter.width() - 2 * pauseLeft; auto pauseHeight = _st.pauseOuter.height() - 2 * pauseTop; auto pauseStroke = 0. + _st.pauseStroke; auto cancelLeft = 0. + _st.cancelPosition.x(); auto cancelTop = 0. + _st.cancelPosition.y(); auto cancelWidth = _st.cancelOuter.width() - 2 * cancelLeft; auto cancelHeight = _st.cancelOuter.height() - 2 * cancelTop; auto cancelStroke = (0. + _st.cancelStroke) / sqrt2; p.setPen(Qt::NoPen); PainterHighQualityEnabler hq(p); QPointF pathLeftPause[] = { { pauseLeft, pauseTop }, { pauseLeft + pauseStroke, pauseTop }, { pauseLeft + pauseStroke, pauseTop + pauseHeight }, { pauseLeft, pauseTop + pauseHeight }, }; QPointF pathLeftCancel[] = { { cancelLeft, cancelTop + cancelStroke }, { cancelLeft + cancelStroke, cancelTop }, { cancelLeft + cancelWidth, cancelTop + cancelHeight - cancelStroke }, { cancelLeft + cancelWidth - cancelStroke, cancelTop + cancelHeight }, }; p.fillPath(interpolatePaths(pathLeftPause, pathLeftCancel, progress), brush); QPointF pathRightPause[] = { { pauseLeft + pauseWidth - pauseStroke, pauseTop }, { pauseLeft + pauseWidth, pauseTop }, { pauseLeft + pauseWidth, pauseTop + pauseHeight }, { pauseLeft + pauseWidth - pauseStroke, pauseTop + pauseHeight }, }; QPointF pathRightCancel[] = { { cancelLeft + cancelWidth - cancelStroke, cancelTop }, { cancelLeft + cancelWidth, cancelTop + cancelStroke }, { cancelLeft + cancelStroke, cancelTop + cancelHeight }, { cancelLeft, cancelTop + cancelHeight - cancelStroke }, }; p.fillPath(interpolatePaths(pathRightPause, pathRightCancel, progress), brush); }
inline void fromCoordAToCoordB(const Vec3r&p, Vec3r& q, const real transform[4][4]) { HVec3r hp(p); HVec3r hq(0, 0, 0, 0); for (unsigned i = 0; i < 4; i++) for (unsigned j = 0; j < 4; j++) hq[i] += transform[i][j] * hp[j]; if(hq[3] == 0) { q = p; return; } for (unsigned k = 0; k < 3; k++) q[k] = hq[k] / hq[3]; }
void NewAvatarButton::paintEvent(QPaintEvent *e) { Painter p(this); if (!_image.isNull()) { p.drawPixmap(0, 0, _image); return; } p.setPen(Qt::NoPen); p.setBrush(isOver() ? st::defaultActiveButton.textBgOver : st::defaultActiveButton.textBg); { PainterHighQualityEnabler hq(p); p.drawEllipse(rect()); } paintRipple(p, 0, 0, getms()); st::newGroupPhotoIcon.paint(p, _position, width()); }
void PlayButtonLayout::paintPlayToPause(Painter &p, const QBrush &brush, float64 progress) { auto playLeft = 0. + _st.playPosition.x(); auto playTop = 0. + _st.playPosition.y(); auto playWidth = _st.playOuter.width() - 2 * playLeft; auto playHeight = _st.playOuter.height() - 2 * playTop; auto pauseLeft = 0. + _st.pausePosition.x(); auto pauseTop = 0. + _st.pausePosition.y(); auto pauseWidth = _st.pauseOuter.width() - 2 * pauseLeft; auto pauseHeight = _st.pauseOuter.height() - 2 * pauseTop; auto pauseStroke = 0. + _st.pauseStroke; p.setPen(Qt::NoPen); PainterHighQualityEnabler hq(p); QPointF pathLeftPause[] = { { pauseLeft, pauseTop }, { pauseLeft + pauseStroke, pauseTop }, { pauseLeft + pauseStroke, pauseTop + pauseHeight }, { pauseLeft, pauseTop + pauseHeight }, }; QPointF pathLeftPlay[] = { { playLeft, playTop }, { playLeft + (playWidth / 2.), playTop + (playHeight / 4.) }, { playLeft + (playWidth / 2.), playTop + (3 * playHeight / 4.) }, { playLeft, playTop + playHeight }, }; p.fillPath(interpolatePaths(pathLeftPlay, pathLeftPause, progress), brush); QPointF pathRightPause[] = { { pauseLeft + pauseWidth - pauseStroke, pauseTop }, { pauseLeft + pauseWidth, pauseTop }, { pauseLeft + pauseWidth, pauseTop + pauseHeight }, { pauseLeft + pauseWidth - pauseStroke, pauseTop + pauseHeight }, }; QPointF pathRightPlay[] = { { playLeft + (playWidth / 2.), playTop + (playHeight / 4.) }, { playLeft + playWidth, playTop + (playHeight / 2.) }, { playLeft + playWidth, playTop + (playHeight / 2.) }, { playLeft + (playWidth / 2.), playTop + (3 * playHeight / 4.) }, }; p.fillPath(interpolatePaths(pathRightPlay, pathRightPause, progress), brush); }
// Emulates Ui::RoundImageCheckbox::paint() in a checked state. void PeerListRow::paintDisabledCheckUserpic( Painter &p, const style::PeerListItem &st, int x, int y, int outerWidth) const { auto userpicRadius = st::contactsPhotoCheckbox.imageSmallRadius; auto userpicShift = st::contactsPhotoCheckbox.imageRadius - userpicRadius; auto userpicDiameter = st::contactsPhotoCheckbox.imageRadius * 2; auto userpicLeft = x + userpicShift; auto userpicTop = y + userpicShift; auto userpicEllipse = rtlrect(x, y, userpicDiameter, userpicDiameter, outerWidth); auto userpicBorderPen = st::contactsPhotoDisabledCheckFg->p; userpicBorderPen.setWidth(st::contactsPhotoCheckbox.selectWidth); auto iconDiameter = st::contactsPhotoCheckbox.check.size; auto iconLeft = x + userpicDiameter + st::contactsPhotoCheckbox.selectWidth - iconDiameter; auto iconTop = y + userpicDiameter + st::contactsPhotoCheckbox.selectWidth - iconDiameter; auto iconEllipse = rtlrect(iconLeft, iconTop, iconDiameter, iconDiameter, outerWidth); auto iconBorderPen = st::contactsPhotoCheckbox.check.border->p; iconBorderPen.setWidth(st::contactsPhotoCheckbox.selectWidth); if (_isSavedMessagesChat) { Ui::EmptyUserpic::PaintSavedMessages(p, userpicLeft, userpicTop, outerWidth, userpicRadius * 2); } else { peer()->paintUserpicLeft(p, userpicLeft, userpicTop, outerWidth, userpicRadius * 2); } { PainterHighQualityEnabler hq(p); p.setPen(userpicBorderPen); p.setBrush(Qt::NoBrush); p.drawEllipse(userpicEllipse); p.setPen(iconBorderPen); p.setBrush(st::contactsPhotoDisabledCheckFg); p.drawEllipse(iconEllipse); } st::contactsPhotoCheckbox.check.check.paint(p, iconEllipse.topLeft(), outerWidth); }
void PaintInterpolatedIcon( Painter &p, const style::icon &a, const style::icon &b, float64 b_ratio, QRect rect) { PainterHighQualityEnabler hq(p); p.save(); p.translate(rect.center()); p.setOpacity(b_ratio); p.scale(b_ratio, b_ratio); b.paintInCenter(p, rect.translated(-rect.center())); p.restore(); p.save(); p.translate(rect.center()); p.setOpacity(1. - b_ratio); p.scale(1. - b_ratio, 1. - b_ratio); a.paintInCenter(p, rect.translated(-rect.center())); p.restore(); }
void MultiSelect::Inner::Item::paintOnce(Painter &p, int x, int y, int outerWidth, TimeMs ms) { if (!_cache.isNull()) { paintCached(p, x, y, outerWidth); return; } auto radius = _st.height / 2; auto inner = rtlrect(x + radius, y, _width - radius, _st.height, outerWidth); auto clipEnabled = p.hasClipping(); auto clip = clipEnabled ? p.clipRegion() : QRegion(); p.setClipRect(inner); p.setPen(Qt::NoPen); p.setBrush(_active ? _st.textActiveBg : _st.textBg); { PainterHighQualityEnabler hq(p); p.drawRoundedRect(rtlrect(x, y, _width, _st.height, outerWidth), radius, radius); } if (clipEnabled) { p.setClipRegion(clip); } else { p.setClipping(false); } auto overOpacity = _overOpacity.current(ms, _over ? 1. : 0.); if (overOpacity < 1.) { _paintRoundImage(p, x, y, outerWidth, _st.height); } if (overOpacity > 0.) { paintDeleteButton(p, x, y, outerWidth, overOpacity); } auto textLeft = _st.height + _st.padding.left(); auto textWidth = _width - textLeft - _st.padding.right(); p.setPen(_active ? _st.textActiveFg : _st.textFg); _text.drawLeftElided(p, x + textLeft, y + _st.padding.top(), textWidth, outerWidth); }
void InfiniteRadialAnimation::draw( Painter &p, QPoint position, QSize size, int outerWidth) { const auto state = computeState(); auto o = p.opacity(); p.setOpacity(o * state.shown); const auto rect = rtlrect( position.x(), position.y(), size.width(), size.height(), outerWidth); const auto was = p.pen(); const auto brush = p.brush(); if (anim::Disabled()) { anim::DrawStaticLoading(p, rect, _st.thickness, _st.color); } else { auto pen = _st.color->p; pen.setWidth(_st.thickness); pen.setCapStyle(Qt::RoundCap); p.setPen(pen); { PainterHighQualityEnabler hq(p); p.drawArc( rect, state.arcFrom, state.arcLength); } } p.setPen(was); p.setBrush(brush); p.setOpacity(o); }
void RippleAnimation::Ripple::paint(QPainter &p, const QPixmap &mask, const QColor *colorOverride) { auto opacity = _hide.value(_hiding ? 0. : 1.); if (opacity == 0.) { return; } if (_cache.isNull() || colorOverride != nullptr) { auto radius = anim::interpolate(_radiusFrom, _radiusTo, _show.value(1.)); _frame.fill(Qt::transparent); { Painter p(&_frame); p.setPen(Qt::NoPen); if (colorOverride) { p.setBrush(*colorOverride); } else { p.setBrush(_st.color); } { PainterHighQualityEnabler hq(p); p.drawEllipse(_origin, radius, radius); } p.setCompositionMode(QPainter::CompositionMode_DestinationIn); p.drawPixmap(0, 0, mask); } if (radius == _radiusTo && colorOverride == nullptr) { _cache = App::pixmapFromImageInPlace(std::move(_frame)); } } auto saved = p.opacity(); if (opacity != 1.) p.setOpacity(saved * opacity); if (_cache.isNull()) { p.drawImage(0, 0, _frame); } else { p.drawPixmap(0, 0, _cache); } if (opacity != 1.) p.setOpacity(saved); }
void UploadAnimation::paintFrame(Painter &p, style::color color, int x, int y, int outerWidth, int frameMs) { PainterHighQualityEnabler hq(p); auto pen = color->p; pen.setWidth(st::historySendActionUploadStrokeNumerator / st::historySendActionUploadDenominator); pen.setJoinStyle(Qt::RoundJoin); pen.setCapStyle(Qt::RoundCap); p.setPen(pen); p.setBrush(Qt::NoBrush); auto progress = frameMs / float64(st::historySendActionUploadDuration); auto position = QPointF(x + st::historySendActionUploadDelta * progress, y) + st::historySendActionUploadPosition; auto path = QPainterPath(); path.moveTo(0., -st::historySendActionUploadSizeNumerator / st::historySendActionUploadDenominator); path.lineTo(st::historySendActionUploadSizeNumerator / st::historySendActionUploadDenominator, 0.); path.lineTo(0., st::historySendActionUploadSizeNumerator / st::historySendActionUploadDenominator); p.translate(position); for (auto i = 0; i != kUploadArrowsCount; ++i) { p.setOpacity((i == 0) ? progress : (i == kUploadArrowsCount - 1) ? (1. - progress) : 1.); p.drawPath(path); position.setX(position.x() + st::historySendActionUploadDelta); p.translate(st::historySendActionUploadDelta, 0); } p.setOpacity(1.); p.translate(-position); }
void RadialAnimation::draw( Painter &p, const QRect &inner, int32 thickness, style::color color) { const auto state = computeState(); auto o = p.opacity(); p.setOpacity(o * state.shown); auto pen = color->p; auto was = p.pen(); pen.setWidth(thickness); pen.setCapStyle(Qt::RoundCap); p.setPen(pen); { PainterHighQualityEnabler hq(p); p.drawArc(inner, state.arcFrom, state.arcLength); } p.setPen(was); p.setOpacity(o); }
void RadialAnimation::draw(Painter &p, const QRect &inner, int32 thickness, style::color color) { float64 o = p.opacity(); p.setOpacity(o * _opacity); QPen pen(color->p), was(p.pen()); pen.setWidth(thickness); pen.setCapStyle(Qt::RoundCap); p.setPen(pen); auto len = MinArcLength + qRound(a_arcEnd.current()); auto from = QuarterArcLength - qRound(a_arcStart.current()) - len; if (rtl()) { from = QuarterArcLength - (from - QuarterArcLength) - len; if (from < 0) from += FullArcLength; } { PainterHighQualityEnabler hq(p); p.drawArc(inner, from, len); } p.setPen(was); p.setOpacity(o); }
void HistoryPhoto::drawGrouped( Painter &p, const QRect &clip, TextSelection selection, crl::time ms, const QRect &geometry, RectParts corners, not_null<uint64*> cacheKey, not_null<QPixmap*> cache) const { _data->automaticLoad(_realParent->fullId(), _parent->data()); validateGroupedCache(geometry, corners, cacheKey, cache); const auto selected = (selection == FullSelection); const auto loaded = _data->loaded(); const auto displayLoading = _data->displayLoading(); const auto bubble = _parent->hasBubble(); if (displayLoading) { ensureAnimation(); if (!_animation->radial.animating()) { _animation->radial.start(_data->progress()); } } const auto radial = isRadialAnimation(); if (!bubble) { // App::roundShadow(p, 0, 0, paintw, painth, selected ? st::msgInShadowSelected : st::msgInShadow, selected ? InSelectedShadowCorners : InShadowCorners); } p.drawPixmap(geometry.topLeft(), *cache); if (selected) { const auto roundRadius = ImageRoundRadius::Large; App::complexOverlayRect(p, geometry, roundRadius, corners); } const auto displayState = radial || (!loaded && !_data->loading()) || _data->waitingForAlbum(); if (displayState) { const auto radialOpacity = radial ? _animation->radial.opacity() : 1.; const auto backOpacity = (loaded && !_data->uploading()) ? radialOpacity : 1.; const auto radialSize = st::historyGroupRadialSize; const auto inner = QRect( geometry.x() + (geometry.width() - radialSize) / 2, geometry.y() + (geometry.height() - radialSize) / 2, radialSize, radialSize); p.setPen(Qt::NoPen); if (selected) { p.setBrush(st::msgDateImgBgSelected); } else if (isThumbAnimation()) { auto over = _animation->a_thumbOver.value(1.); p.setBrush(anim::brush(st::msgDateImgBg, st::msgDateImgBgOver, over)); } else { auto over = ClickHandler::showAsActive(_data->loading() ? _cancell : _savel); p.setBrush(over ? st::msgDateImgBgOver : st::msgDateImgBg); } p.setOpacity(backOpacity * p.opacity()); { PainterHighQualityEnabler hq(p); p.drawEllipse(inner); } const auto icon = [&]() -> const style::icon* { if (_data->waitingForAlbum()) { return &(selected ? st::historyFileThumbWaitingSelected : st::historyFileThumbWaiting); } else if (radial || _data->loading()) { if (_data->uploading() || _data->large()->location().valid()) { return &(selected ? st::historyFileThumbCancelSelected : st::historyFileThumbCancel); } return nullptr; } return &(selected ? st::historyFileThumbDownloadSelected : st::historyFileThumbDownload); }(); const auto previous = [&]() -> const style::icon* { if (_data->waitingForAlbum()) { return &(selected ? st::historyFileThumbCancelSelected : st::historyFileThumbCancel); } return nullptr; }(); p.setOpacity(backOpacity); if (icon) { if (previous && radialOpacity > 0. && radialOpacity < 1.) { PaintInterpolatedIcon(p, *icon, *previous, radialOpacity, inner); } else { icon->paintInCenter(p, inner); } } p.setOpacity(1); if (radial) { const auto line = st::historyGroupRadialLine; const auto rinner = inner.marginsRemoved({ line, line, line, line }); const auto color = selected ? st::historyFileThumbRadialFgSelected : st::historyFileThumbRadialFg; _animation->radial.draw(p, rinner, line, color); } } }
/* Returns the normalized MI scores. * * Parameters * dx (IN) : x-data sorted in increasing order by dx-values * dy (IN) : y-data sorted in increasing order by dx-values * n (IN) : number of elements in dx and dy * Q_map (IN) : the map Q computed by EquipartitionYAxis() sorted in * increasing order by dx-values * q (IN) : number of partitions in Q_map * P_map (IN) : the map P computed by GetSuperclumpsPartition() sorted * in increasing order by Dx-values * p (IN) : number of partitions in P_map * x (IN) : maximum grid size on dx-values * score (OUT) : mutual information scores. score must be a * preallocated array of dimension x-1 * Returns * 0 on success, 1 if an error occurs */ int OptimizeXAxis(double *dx, double *dy, int n, int *Q_map, int q, int *P_map, int p, int x, double *score) { int i, s, t, l; int *c; int **cumhist; double **I, **HP2Q; double F, F_max, HQ, ct, cs; /* return score=0 if p=1 */ if (p == 1) { for (i=0; i<x-1; i++) score[i] = 0.0; return 0; } /* compute c */ c = compute_c(P_map, p, n); if (c == NULL) goto error_c; /* compute the cumulative histogram matrix along P_map */ cumhist = compute_cumhist(Q_map, q, P_map, p, n); if (cumhist == NULL) goto error_cumhist; /* I matrix initialization */ I = init_I(p, x); if (I == NULL) goto error_I; /* Precomputes the HP2Q matrix */ HP2Q = compute_HP2Q(cumhist, c, q, p); if (HP2Q == NULL) goto error_HP2Q; /* compute H(Q) */ HQ = hq(cumhist, q, p, n); /* * Find the optimal partitions of size 2 * Algorithm 2 in SOM, lines 3-8 */ for (t=2; t<=p; t++) { F_max = -DBL_MAX; for (s=1; s<=t; s++) { F = hp3(c, s, t) - hp3q(cumhist, c, q, p, s, t); if (F > F_max) { I[t][2] = HQ + F; F_max = F; } } } /* * Inductively build the rest of the table of * optimal partitions * Algorithm 2 in SOM, lines 10-17 */ for (l=3; l<=x; l++) { for (t=l; t<=p; t++) { ct = (double) c[t-1]; F_max = -DBL_MAX; for (s=l-1; s<=t; s++) { cs = (double) c[s-1]; F = ((cs/ct) * (I[s][l-1]-HQ)) - (((ct-cs)/ct) * HP2Q[s][t]); if (F > F_max) { I[t][l] = HQ + F; F_max = F; } } } } /* Algorithm 2 in SOM, line 19 */ for (i=p+1; i<=x; i++) I[p][i] = I[p][p]; /* score */ for (i=2; i<=x; i++) score[i-2] = I[p][i] / MIN(log(i), log(q)); /* start frees */ for (i=0; i<=p; i++) free(HP2Q[i]); free(HP2Q); for (i=0; i<=p; i++) free(I[i]); free(I); for (i=0; i<q; i++) free(cumhist[i]); free(cumhist); free (c); /* end frees*/ return 0; /* gotos*/ error_HP2Q: for (i=0; i<=p; i++) free(I[i]); free(I); error_I: for (i=0; i<q; i++) free(cumhist[i]); free(cumhist); error_cumhist: free(c); error_c: return 1; }