box shadows and bg changed, retina shadow draw fixed

This commit is contained in:
John Preston 2015-05-22 14:14:52 +03:00
parent 8ed1961886
commit 7ca4ec1bed
16 changed files with 111 additions and 93 deletions

View file

@ -54,7 +54,7 @@ wndBG: #FFF;
wndShadow: sprite(209px, 46px, 19px, 19px);
wndShadowShift: 1px;
layerAlpha: 0.3;
layerAlpha: 0.5;
layerBG: #000;
titleBG: #6389a8;
@ -390,7 +390,8 @@ btnIntroNext: flatButton(btnDefNext, btnDefBig) {
width: 300px;
}
boxShadow: sprite(230px, 46px, 9px, 9px);
boxShadow: sprite(363px, 50px, 15px, 15px);
boxShadowShift: 2px;
introCountry: countryInput {
width: 300px;
@ -776,7 +777,7 @@ activeFadeOutDuration: 3000;
msgRadius: 3px;
msgMaxWidth: 550px;
msgMaxWidth: 430px;
msgFont: font(fsize);
msgNameFont: font(fsize semibold);
msgServiceFont: font(fsize semibold);
@ -1375,6 +1376,7 @@ dropdownDef: dropdown {
padding: margins(10px, 10px, 10px, 10px);
shadow: sprite(241px, 46px, 6px, 6px);
shadowShift: 1px;
duration: 150;
width: 0px;
@ -1796,7 +1798,7 @@ radialBgOpacity: 0.4;
radialDownload: sprite(346px, 0px, 50px, 50px);
radialDownloadOpacity: 0.8;
radialCancel: sprite(378px, 50px, 18px, 18px);
radialCancelOpacity: 0.7;
radialCancelOpacity: 1.0;
overviewLoader: size(34px, 14px);
overviewLoaderPoint: size(4px, 4px);

View file

@ -254,6 +254,7 @@ dropdown {
padding: margins;
shadow: sprite;
shadowShift: number;
duration: number;
width: number;

View file

@ -2016,6 +2016,16 @@ namespace App {
p.drawPixmap(QPoint(x + w - cw, y + h - ch), *c[3]);
}
void roundShadow(QPainter &p, int32 x, int32 y, int32 w, int32 h, const style::color &sh, RoundCorners index) {
QPixmap **c = App::corners(index);
int32 cw = c[0]->width() / cIntRetinaFactor(), ch = c[0]->height() / cIntRetinaFactor();
p.fillRect(x + cw, y + h, w - 2 * cw, st::msgShadow, sh->b);
p.fillRect(x, y + h - ch, cw, st::msgShadow, sh->b);
p.fillRect(x + w - cw, y + h - ch, cw, st::msgShadow, sh->b);
p.drawPixmap(x, y + h - ch + st::msgShadow, *c[2]);
p.drawPixmap(x + w - cw, y + h - ch + st::msgShadow, *c[3]);
}
void initBackground(int32 id, const QImage &p, bool nowrite) {
if (Local::readBackground()) return;

View file

@ -236,6 +236,10 @@ namespace App {
inline void roundRect(QPainter &p, const QRect &rect, const style::color &bg, RoundCorners index, const style::color *sh = 0) {
return roundRect(p, rect.x(), rect.y(), rect.width(), rect.height(), bg, index, sh);
}
void roundShadow(QPainter &p, int32 x, int32 y, int32 w, int32 h, const style::color &sh, RoundCorners index);
inline void roundShadow(QPainter &p, const QRect &rect, const style::color &sh, RoundCorners index) {
return roundShadow(p, rect.x(), rect.y(), rect.width(), rect.height(), sh, index);
}
void initBackground(int32 id = DefaultChatBackground, const QImage &p = QImage(), bool nowrite = false);

Binary file not shown.

Before

Width:  |  Height:  |  Size: 165 KiB

After

Width:  |  Height:  |  Size: 165 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 215 KiB

After

Width:  |  Height:  |  Size: 215 KiB

View file

@ -120,7 +120,7 @@ void Dropdown::paintEvent(QPaintEvent *e) {
// draw shadow
QRect r(_st.padding.left(), _st.padding.top(), _width - _st.padding.left() - _st.padding.right(), _height - _st.padding.top() - _st.padding.bottom());
_shadow.paint(p, r);
_shadow.paint(p, r, _st.shadowShift);
if (!_buttons.isEmpty() && _st.border > 0) { // paint separators
p.setPen(_st.borderColor->p);
@ -308,7 +308,7 @@ bool Dropdown::eventFilter(QObject *obj, QEvent *e) {
}
DragArea::DragArea(QWidget *parent) : TWidget(parent),
_hiding(false), _in(false), a_opacity(0), a_color(st::dragColor->c), _shadow(st::boxShadow) {
_hiding(false), _in(false), a_opacity(0), a_color(st::dragColor->c), _shadow(st::boxShadow) {
setMouseTracking(true);
setAcceptDrops(true);
}
@ -354,7 +354,7 @@ void DragArea::paintEvent(QPaintEvent *e) {
QRect r(st::dragPadding.left(), st::dragPadding.top(), width() - st::dragPadding.left() - st::dragPadding.right(), height() - st::dragPadding.top() - st::dragPadding.bottom());
// draw shadow
_shadow.paint(p, r);
_shadow.paint(p, r, st::boxShadowShift);
p.fillRect(r, st::white->b);
@ -487,7 +487,7 @@ void EmojiColorPicker::paintEvent(QPaintEvent *e) {
int32 w = st::dropdownDef.shadow.pxWidth(), h = st::dropdownDef.shadow.pxHeight();
QRect r = QRect(w, h, width() - 2 * w, height() - 2 * h);
_shadow.paint(p, r);
_shadow.paint(p, r, st::dropdownDef.shadowShift);
if (_cache.isNull()) {
p.fillRect(r, st::white->b);
@ -1697,7 +1697,7 @@ void EmojiPan::paintEvent(QPaintEvent *e) {
QRect r(st::dropdownDef.padding.left(), st::dropdownDef.padding.top(), _width - st::dropdownDef.padding.left() - st::dropdownDef.padding.right(), _height - st::dropdownDef.padding.top() - st::dropdownDef.padding.bottom());
_shadow.paint(p, r);
_shadow.paint(p, r, st::dropdownDef.shadowShift);
if (_toCache.isNull()) {
if (_cache.isNull()) {

View file

@ -19,13 +19,14 @@ Copyright (c) 2014 John Preston, https://desktop.telegram.org
#include "boxshadow.h"
BoxShadow::BoxShadow(const style::rect &topLeft) : _size(topLeft.width() / cIntRetinaFactor()) {
BoxShadow::BoxShadow(const style::sprite &topLeft) : _size(topLeft.pxWidth()), _pixsize(_size * cIntRetinaFactor()) {
if (!_size) return;
QImage cornersImage(_size * 2, _size * 2, QImage::Format_ARGB32_Premultiplied);
QImage cornersImage(_pixsize * 2, _pixsize * 2, QImage::Format_ARGB32_Premultiplied);
cornersImage.setDevicePixelRatio(cRetinaFactor());
{
QPainter p(&cornersImage);
p.drawPixmap(QPoint(rtl() ? _size : 0, 0), App::sprite(), topLeft);
p.drawPixmap(QPoint(rtl() ? _pixsize : 0, 0), App::sprite(), topLeft);
}
if (rtl()) cornersImage = cornersImage.mirrored(true, false);
uchar *bits = cornersImage.bits();
@ -41,39 +42,61 @@ BoxShadow::BoxShadow(const style::rect &topLeft) : _size(topLeft.width() / cIntR
{
QPainter p(&cornersImage);
p.setCompositionMode(QPainter::CompositionMode_Source);
p.drawImage(0, _size, cornersImage.mirrored(), 0, _size, _size, _size);
p.drawImage(0, _pixsize, cornersImage.mirrored(), 0, _pixsize, _pixsize, _pixsize);
}
{
QPainter p(&cornersImage);
p.setCompositionMode(QPainter::CompositionMode_Source);
p.drawImage(_size, 0, cornersImage.mirrored(true, false), _size, 0, _size, _size * 2);
p.drawImage(_pixsize, 0, cornersImage.mirrored(true, false), _pixsize, 0, _pixsize, _pixsize * 2);
}
_corners = QPixmap::fromImage(cornersImage, Qt::ColorOnly);
_colors.reserve(_size);
_corners.setDevicePixelRatio(cRetinaFactor());
_colors.reserve(_pixsize);
uchar prev = 0;
for (int32 i = 0; i < _size; ++i) {
uchar a = (cornersImage.pixel(QPoint(i, _size - 1)) >> 24);
for (int32 i = 0; i < _pixsize; ++i) {
uchar a = (cornersImage.pixel(QPoint(i, _pixsize - 1)) >> 24);
if (a < prev) break;
_colors.push_back(style::color(0, 0, 0, a));
prev = a;
}
}
void BoxShadow::paint(QPainter &p, const QRect &box, const QPoint &shift, int32 flags) {
if (!_size) return;
int32 count = _colors.size(), minus = _size - count + 1;
bool left = (flags & Left), top = (flags & Top), right = (flags & Right), bottom = (flags & Bottom);
if (left && top) p.drawPixmap(box.left() - _size + minus + shift.x(), box.top() - _size + minus + shift.y(), _corners, 0, 0, _size, _size);
if (right && top) p.drawPixmap(box.right() - minus + 1 + shift.x(), box.top() - _size + minus + shift.y(), _corners, _size, 0, _size, _size);
if (right && bottom) p.drawPixmap(box.right() - minus + 1 + shift.x(), box.bottom() - minus + 1 + shift.y(), _corners, _size, _size, _size, _size);
if (left && bottom) p.drawPixmap(box.left() - _size + minus + shift.x(), box.bottom() - minus + 1 + shift.y(), _corners, 0, _size, _size, _size);
for (int32 i = 1; i <= count; ++i) {
p.setPen(_colors[i - 1]->p);
if (top) p.fillRect(box.left() + (left ? minus : 0) + shift.x(), box.top() - count + i + shift.y(), box.width() - (right ? minus : 0) - (left ? minus : 0), cIntRetinaFactor(), _colors[i - 1]->b);
if (right) p.fillRect(box.right() + count - i + shift.x(), box.top() + (top ? minus : 0) + shift.y(), cIntRetinaFactor(), box.height() - (bottom ? minus : 0) - (top ? minus : 0), _colors[i - 1]->b);
if (bottom) p.fillRect(box.left() + (left ? minus : 0) + shift.x(), box.bottom() + count - i + shift.y(), box.width() - (right ? minus : 0) - (left ? minus : 0), cIntRetinaFactor(), _colors[i - 1]->b);
if (left) p.fillRect(box.left() - count + i + shift.x(), box.top() + (top ? minus : 0) + shift.y(), cIntRetinaFactor(), box.height() - (bottom ? minus : 0) - (top ? minus : 0), _colors[i - 1]->b);
if (cRetina()) {
_left = QPixmap::fromImage(cornersImage.copy(0, _pixsize - 1, _colors.size(), 1), Qt::ColorOnly);
_left.setDevicePixelRatio(cRetinaFactor());
_top = QPixmap::fromImage(cornersImage.copy(_pixsize - 1, 0, 1, _colors.size()), Qt::ColorOnly);
_top.setDevicePixelRatio(cRetinaFactor());
_right = QPixmap::fromImage(cornersImage.copy(_pixsize * 2 - _colors.size(), _pixsize, _colors.size(), 1), Qt::ColorOnly);
_right.setDevicePixelRatio(cRetinaFactor());
_bottom = QPixmap::fromImage(cornersImage.copy(_pixsize, _pixsize * 2 - _colors.size(), 1, _colors.size()), Qt::ColorOnly);
_bottom.setDevicePixelRatio(cRetinaFactor());
}
}
void BoxShadow::paint(QPainter &p, const QRect &box, int32 shifty, int32 flags) {
if (!_size) return;
int32 add = shifty;
int32 count = _colors.size(), minus = _size - count + add;
bool left = (flags & Left), top = (flags & Top), right = (flags & Right), bottom = (flags & Bottom);
if (left && top) p.drawPixmap(box.left() - _size + minus, box.top() - _size + minus + shifty, _corners, 0, 0, _size, _size);
if (right && top) p.drawPixmap(box.left() + box.width() - minus, box.top() - _size + minus + shifty, _corners, _size, 0, _size, _size);
if (right && bottom) p.drawPixmap(box.left() + box.width() - minus, box.top() + box.height() - minus + shifty, _corners, _size, _size, _size, _size);
if (left && bottom) p.drawPixmap(box.left() - _size + minus, box.top() + box.height() - minus + shifty, _corners, 0, _size, _size, _size);
if (cRetina()) {
bool wasSmooth = p.renderHints().testFlag(QPainter::SmoothPixmapTransform);
if (wasSmooth) p.setRenderHint(QPainter::SmoothPixmapTransform, false);
if (left) p.drawPixmap(box.left() - count + add, box.top() + (top ? minus : 0) + shifty, count - add, box.height() - (bottom ? minus : 0) - (top ? minus : 0), _left, 0, 0, count - add, 1);
if (top) p.drawPixmap(box.left() + (left ? minus : 0), box.top() - count + add + shifty, box.width() - (right ? minus : 0) - (left ? minus : 0), count - add - shifty, _top, 0, 0, 1, count - add - shifty);
if (right) p.drawPixmap(box.left() + box.width(), box.top() + (top ? minus : 0) + shifty, count - add, box.height() - (bottom ? minus : 0) - (top ? minus : 0), _right, add, 0, count - add, 1);
if (bottom) p.drawPixmap(box.left() + (left ? minus : 0), box.top() + box.height(), box.width() - (right ? minus : 0) - (left ? minus : 0), count, _bottom, 0, 0, 1, count);
if (wasSmooth) p.setRenderHint(QPainter::SmoothPixmapTransform);
} else {
p.setPen(Qt::NoPen);
for (int32 i = 0; i < count; ++i) {
if (left && i + add < count) p.fillRect(box.left() - count + i + add, box.top() + (top ? minus : 0) + shifty, 1, box.height() - (bottom ? minus : 0) - (top ? minus : 0), _colors[i]->b);
if (top && i + add + shifty < count) p.fillRect(box.left() + (left ? minus : 0), box.top() - count + i + add + shifty, box.width() - (right ? minus : 0) - (left ? minus : 0), 1, _colors[i]->b);
if (right && i + add < count) p.fillRect(box.left() + box.width() + count - i - add - 1, box.top() + (top ? minus : 0) + shifty, 1, box.height() - (bottom ? minus : 0) - (top ? minus : 0), _colors[i]->b);
if (bottom && i + add - shifty < count) p.fillRect(box.left() + (left ? minus : 0), box.top() + box.height() + count - i - add + shifty - 1, box.width() - (right ? minus : 0) - (left ? minus : 0), 1, _colors[i]->b);
}
}
}

View file

@ -27,14 +27,14 @@ public:
Bottom = 8
};
BoxShadow(const style::rect &topLeft);
BoxShadow(const style::sprite &topLeft);
void paint(QPainter &p, const QRect &box, const QPoint &shift = QPoint(0, 1), int32 flags = Left | Top | Right | Bottom);
void paint(QPainter &p, const QRect &box, int32 shifty, int32 flags = Left | Top | Right | Bottom);
private:
int32 _size;
QPixmap _corners;
int32 _size, _pixsize;
QPixmap _corners, _left, _top, _right, _bottom;
QVector<style::color> _colors;
};

View file

@ -144,7 +144,7 @@ void ContextMenu::paintEvent(QPaintEvent *e) {
QRect r(_st.padding.left(), _st.padding.top(), _width - _st.padding.left() - _st.padding.right(), _height - _st.padding.top() - _st.padding.bottom());
// draw shadow
_shadow.paint(p, r);
_shadow.paint(p, r, _st.shadowShift);
}
void ContextMenu::keyPressEvent(QKeyEvent *e) {

View file

@ -485,7 +485,7 @@ void CountrySelect::paintEvent(QPaintEvent *e) {
p.setOpacity(1);
QRect inner(_innerLeft, _innerTop, _innerWidth, _innerHeight);
_shadow.paint(p, inner);
_shadow.paint(p, inner, st::boxShadowShift);
if (trivial || e->rect().intersects(inner)) {
// fill bg
p.fillRect(inner, st::white->b);

View file

@ -1807,14 +1807,7 @@ void HistoryPhoto::draw(QPainter &p, const HistoryItem *parent, bool selected, i
height -= st::webPagePhotoSkip + _caption.countHeight(width);
}
} else {
QPixmap **cors = App::corners(selected ? InSelectedShadowCorners : InShadowCorners);
int32 cw = cors[0]->width() / cIntRetinaFactor(), ch = cors[0]->height() / cIntRetinaFactor();
style::color shadow(selected ? st::msgInSelectShadow : st::msgInShadow);
p.fillRect(cw, _height, width - 2 * cw, st::msgShadow, shadow->b);
p.fillRect(0, _height - ch, cw, st::msgShadow, shadow->b);
p.fillRect(width - cw, _height - ch, cw, st::msgShadow, shadow->b);
p.drawPixmap(0, _height - ch + st::msgShadow, *cors[2]);
p.drawPixmap(width - cw, _height - ch + st::msgShadow, *cors[3]);
App::roundShadow(p, 0, 0, width, _height, selected ? st::msgInSelectShadow : st::msgInShadow, selected ? InSelectedShadowCorners : InShadowCorners);
}
data->full->load(false, false);
bool full = data->full->loaded();
@ -2657,14 +2650,7 @@ void HistoryDocument::draw(QPainter &p, const HistoryItem *parent, bool selected
if (ph < 1) ph = 1;
}
QPixmap **cors = App::corners(selected ? InSelectedShadowCorners : InShadowCorners);
int32 cw = cors[0]->width() / cIntRetinaFactor(), ch = cors[0]->height() / cIntRetinaFactor();
style::color shadow(selected ? st::msgInSelectShadow : st::msgInShadow);
p.fillRect(cw, ph, pw - 2 * cw, st::msgShadow, shadow->b);
p.fillRect(0, ph - ch, cw, st::msgShadow, shadow->b);
p.fillRect(pw - cw, ph - ch, cw, st::msgShadow, shadow->b);
p.drawPixmap(0, ph - ch + st::msgShadow, *cors[2]);
p.drawPixmap(pw - cw, ph - ch + st::msgShadow, *cors[3]);
App::roundShadow(p, 0, 0, pw, ph, selected ? st::msgInSelectShadow : st::msgInShadow, selected ? InSelectedShadowCorners : InShadowCorners);
p.drawPixmap(0, 0, animated.current(pw, ph, true));
if (selected) {
@ -4305,14 +4291,7 @@ void HistoryImageLink::draw(QPainter &p, const HistoryItem *parent, bool selecte
}
height -= skipy + st::mediaPadding.bottom();
} else {
QPixmap **cors = App::corners(selected ? InSelectedShadowCorners : InShadowCorners);
int32 cw = cors[0]->width() / cIntRetinaFactor(), ch = cors[0]->height() / cIntRetinaFactor();
style::color shadow(selected ? st::msgInSelectShadow : st::msgInShadow);
p.fillRect(cw, _height, width - 2 * cw, st::msgShadow, shadow->b);
p.fillRect(0, _height - ch, cw, st::msgShadow, shadow->b);
p.fillRect(width - cw, _height - ch, cw, st::msgShadow, shadow->b);
p.drawPixmap(0, _height - ch + st::msgShadow, *cors[2]);
p.drawPixmap(width - cw, _height - ch + st::msgShadow, *cors[3]);
App::roundShadow(p, 0, 0, width, _height, selected ? st::msgInSelectShadow : st::msgInShadow, selected ? InSelectedShadowCorners : InShadowCorners);
}
data->load();

View file

@ -34,7 +34,6 @@ extern TextParseOptions _textNameOptions, _textDlgOptions;
#include "structs.h"
struct History;
struct Histories : public QHash<PeerId, History*>, public Animated {
typedef QHash<PeerId, History*> Parent;

View file

@ -1316,35 +1316,35 @@ void MessageField::focusInEvent(QFocusEvent *e) {
}
HistoryHider::HistoryHider(MainWidget *parent, bool forwardSelected) : QWidget(parent)
, _sharedContact(0)
, _forwardSelected(forwardSelected)
, _sendPath(false)
, forwardButton(this, lang(lng_forward), st::btnSelectDone)
, cancelButton(this, lang(lng_cancel), st::btnSelectCancel)
, offered(0)
, aOpacity(0, 1)
, aOpacityFunc(anim::easeOutCirc)
, hiding(false)
, _forwardRequest(0)
, toTextWidth(0)
, shadow(st::boxShadow)
, _sharedContact(0)
, _forwardSelected(forwardSelected)
, _sendPath(false)
, forwardButton(this, lang(lng_forward), st::btnSelectDone)
, cancelButton(this, lang(lng_cancel), st::btnSelectCancel)
, offered(0)
, aOpacity(0, 1)
, aOpacityFunc(anim::easeOutCirc)
, hiding(false)
, _forwardRequest(0)
, toTextWidth(0)
, shadow(st::boxShadow)
{
init();
}
HistoryHider::HistoryHider(MainWidget *parent, UserData *sharedContact) : QWidget(parent)
, _sharedContact(sharedContact)
, _forwardSelected(false)
, _sendPath(false)
, forwardButton(this, lang(lng_forward_send), st::btnSelectDone)
, cancelButton(this, lang(lng_cancel), st::btnSelectCancel)
, offered(0)
, aOpacity(0, 1)
, aOpacityFunc(anim::easeOutCirc)
, hiding(false)
, _forwardRequest(0)
, toTextWidth(0)
, shadow(st::boxShadow)
, _sharedContact(sharedContact)
, _forwardSelected(false)
, _sendPath(false)
, forwardButton(this, lang(lng_forward_send), st::btnSelectDone)
, cancelButton(this, lang(lng_cancel), st::btnSelectCancel)
, offered(0)
, aOpacity(0, 1)
, aOpacityFunc(anim::easeOutCirc)
, hiding(false)
, _forwardRequest(0)
, toTextWidth(0)
, shadow(st::boxShadow)
{
init();
}
@ -1410,7 +1410,7 @@ void HistoryHider::paintEvent(QPaintEvent *e) {
if (cacheForAnim.isNull() || !offered) {
p.setFont(st::forwardFont->f);
if (offered) {
shadow.paint(p, box);
shadow.paint(p, box, st::boxShadowShift);
// fill bg
p.fillRect(box, st::boxBG->b);

View file

@ -25,7 +25,7 @@ Copyright (c) 2014 John Preston, https://desktop.telegram.org
#include "gui/filedialog.h"
BackgroundWidget::BackgroundWidget(QWidget *parent, LayeredWidget *w) : QWidget(parent), w(w), _hidden(0),
aBackground(0), aBackgroundFunc(anim::easeOutCirc), hiding(false), shadow(st::boxShadow) {
aBackground(0), aBackgroundFunc(anim::easeOutCirc), hiding(false), shadow(st::boxShadow) {
w->setParent(this);
setGeometry(0, 0, App::wnd()->width(), App::wnd()->height());
aBackground.start(1);
@ -54,7 +54,7 @@ void BackgroundWidget::paintEvent(QPaintEvent *e) {
p.fillRect(rect(), st::layerBG->b);
p.setOpacity(aBackground.current());
shadow.paint(p, w->boxRect());
shadow.paint(p, w->boxRect(), st::boxShadowShift);
}
void BackgroundWidget::keyPressEvent(QKeyEvent *e) {

View file

@ -57,7 +57,7 @@ void ConnectingWidget::set(const QString &text, const QString &reconnect) {
void ConnectingWidget::paintEvent(QPaintEvent *e) {
QPainter p(this);
_shadow.paint(p, QRect(0, st::boxShadow.pxHeight(), width() - st::boxShadow.pxWidth(), height() - st::boxShadow.pxHeight()), QPoint(0, 0), BoxShadow::Top | BoxShadow::Right);
_shadow.paint(p, QRect(0, st::boxShadow.pxHeight(), width() - st::boxShadow.pxWidth(), height() - st::boxShadow.pxHeight()), 0, BoxShadow::Top | BoxShadow::Right);
p.fillRect(0, st::boxShadow.pxHeight(), width() - st::boxShadow.pxWidth(), height() - st::boxShadow.pxHeight(), st::connectingBG->b);
p.setFont(st::linkFont->f);
p.setPen(st::connectingColor->p);