2
0
mirror of https://github.com/telegramdesktop/tdesktop synced 2025-08-30 22:16:14 +00:00

new flat boxes started

This commit is contained in:
John Preston
2015-10-03 13:09:09 +03:00
parent bd4d43daaf
commit e3e774176e
62 changed files with 785 additions and 645 deletions

View File

@@ -93,7 +93,15 @@ namespace {
QPixmap *sprite = 0, *emojis = 0, *emojisLarge = 0;
QPixmap *corners[RoundCornersCount][4] = { { 0 } };
struct CornersPixmaps {
CornersPixmaps() {
memset(p, 0, sizeof(p));
}
QPixmap *p[4];
};
CornersPixmaps corners[RoundCornersCount];
typedef QMap<uint32, CornersPixmaps> CornersMap;
CornersMap cornersMap;
QImage *cornersMask[4] = { 0 };
typedef QMap<uint64, QPixmap> EmojisMap;
@@ -1887,9 +1895,11 @@ namespace App {
cors[1] = rect.copy(r * 2, 0, r, r);
cors[2] = rect.copy(0, r * 2, r, r + (shadow ? s : 0));
cors[3] = rect.copy(r * 2, r * 2, r, r + (shadow ? s : 0));
for (int i = 0; i < 4; ++i) {
::corners[index][i] = new QPixmap(QPixmap::fromImage(cors[i], Qt::ColorOnly));
::corners[index][i]->setDevicePixelRatio(cRetinaFactor());
if (index != NoneCorners) {
for (int i = 0; i < 4; ++i) {
::corners[index].p[i] = new QPixmap(QPixmap::fromImage(cors[i], Qt::ColorOnly));
::corners[index].p[i]->setDevicePixelRatio(cRetinaFactor());
}
}
}
@@ -1916,7 +1926,7 @@ namespace App {
}
QImage mask[4];
prepareCorners(MaskCorners, st::msgRadius, st::white, 0, mask);
prepareCorners(NoneCorners, st::msgRadius, st::white, 0, mask);
for (int i = 0; i < 4; ++i) {
::cornersMask[i] = new QImage(mask[i].convertToFormat(QImage::Format_ARGB32_Premultiplied));
::cornersMask[i]->setDevicePixelRatio(cRetinaFactor());
@@ -1968,10 +1978,16 @@ namespace App {
::emojisLarge = 0;
for (int32 j = 0; j < 4; ++j) {
for (int32 i = 0; i < RoundCornersCount; ++i) {
delete ::corners[i][j]; ::corners[i][j] = 0;
delete ::corners[i].p[j]; ::corners[i].p[j] = 0;
}
delete ::cornersMask[j]; ::cornersMask[j] = 0;
}
for (CornersMap::const_iterator i = ::cornersMap.cbegin(), e = ::cornersMap.cend(); i != e; ++i) {
for (int32 j = 0; j < 4; ++j) {
delete i->p[j];
}
}
::cornersMap.clear();
mainEmojisMap.clear();
otherEmojisMap.clear();
@@ -2394,13 +2410,8 @@ namespace App {
QImage **cornersMask() {
return ::cornersMask;
}
QPixmap **corners(RoundCorners index) {
return ::corners[index];
}
void roundRect(Painter &p, int32 x, int32 y, int32 w, int32 h, const style::color &bg, RoundCorners index, const style::color *sh) {
QPixmap **c = ::corners[index];
int32 cw = c[0]->width() / cIntRetinaFactor(), ch = c[0]->height() / cIntRetinaFactor();
void roundRect(Painter &p, int32 x, int32 y, int32 w, int32 h, const style::color &bg, const CornersPixmaps &c, const style::color *sh) {
int32 cw = c.p[0]->width() / cIntRetinaFactor(), ch = c.p[0]->height() / cIntRetinaFactor();
if (w < 2 * cw || h < 2 * ch) return;
if (w > 2 * cw) {
p.fillRect(QRect(x + cw, y, w - 2 * cw, ch), bg->b);
@@ -2410,20 +2421,41 @@ namespace App {
if (h > 2 * ch) {
p.fillRect(QRect(x, y + ch, w, h - 2 * ch), bg->b);
}
p.drawPixmap(QPoint(x, y), *c[0]);
p.drawPixmap(QPoint(x + w - cw, y), *c[1]);
p.drawPixmap(QPoint(x, y + h - ch), *c[2]);
p.drawPixmap(QPoint(x + w - cw, y + h - ch), *c[3]);
p.drawPixmap(QPoint(x, y), *c.p[0]);
p.drawPixmap(QPoint(x + w - cw, y), *c.p[1]);
p.drawPixmap(QPoint(x, y + h - ch), *c.p[2]);
p.drawPixmap(QPoint(x + w - cw, y + h - ch), *c.p[3]);
}
void roundRect(Painter &p, int32 x, int32 y, int32 w, int32 h, const style::color &bg, RoundCorners index, const style::color *sh) {
roundRect(p, x, y, w, h, bg, ::corners[index], sh);
}
void roundShadow(Painter &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();
const CornersPixmaps &c = ::corners[index];
int32 cw = c.p[0]->width() / cIntRetinaFactor(), ch = c.p[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]);
p.drawPixmap(x, y + h - ch + st::msgShadow, *c.p[2]);
p.drawPixmap(x + w - cw, y + h - ch + st::msgShadow, *c.p[3]);
}
void roundRect(Painter &p, int32 x, int32 y, int32 w, int32 h, const style::color &bg) {
uint32 colorKey = ((uint32(bg->c.alpha()) & 0xFF) << 24) | ((uint32(bg->c.red()) & 0xFF) << 16) | ((uint32(bg->c.green()) & 0xFF) << 8) | ((uint32(bg->c.blue()) & 0xFF) << 24);
CornersMap::const_iterator i = cornersMap.find(colorKey);
if (i == cornersMap.cend()) {
QImage images[4];
prepareCorners(NoneCorners, st::msgRadius, bg, 0, images);
CornersPixmaps pixmaps;
for (int j = 0; j < 4; ++j) {
pixmaps.p[j] = new QPixmap(QPixmap::fromImage(images[j], Qt::ColorOnly));
pixmaps.p[j]->setDevicePixelRatio(cRetinaFactor());
}
i = cornersMap.insert(colorKey, pixmaps);
}
roundRect(p, x, y, w, h, bg, i.value(), 0);
}
void initBackground(int32 id, const QImage &p, bool nowrite) {