From 25082c477ab5b59a17c760b60f689ec34eead0a3 Mon Sep 17 00:00:00 2001 From: Thorvald Natvig Date: Thu, 5 Jul 2007 21:32:55 +0000 Subject: [PATCH] Custom UserTextures git-svn-id: https://mumble.svn.sourceforge.net/svnroot/mumble/trunk@547 05730e5d-ab1b-0410-a4ac-84af385074fa --- src/PacketDataStream.h | 1 - src/mumble/MainWindow.cpp | 7 +++- src/mumble/Overlay.cpp | 84 +++++++++++++++++++++++++++++---------- src/mumble/Overlay.h | 6 +++ 4 files changed, 74 insertions(+), 24 deletions(-) diff --git a/src/PacketDataStream.h b/src/PacketDataStream.h index 713793631..56f901d88 100644 --- a/src/PacketDataStream.h +++ b/src/PacketDataStream.h @@ -188,7 +188,6 @@ class PacketDataStream { PacketDataStream &operator >>(QByteArray &a) { quint32 len; *this >> len; - qWarning("Looking for %d bytes with %d left", len, left()); if (len > left()) { len = left(); ok = false; diff --git a/src/mumble/MainWindow.cpp b/src/mumble/MainWindow.cpp index a9ed54b56..511125f97 100644 --- a/src/mumble/MainWindow.cpp +++ b/src/mumble/MainWindow.cpp @@ -452,7 +452,7 @@ void MainWindow::on_ServerDisconnect_triggered() { if (qtReconnect->isActive()) qtReconnect->stop(); - if (g.sh && g.sh->isRunning()) + if (g.sh && g.sh->isRunning()) g.sh->disconnect(); } @@ -1211,3 +1211,8 @@ void MessageQueryUsers::process(Connection *) { void MessagePing::process(Connection *) { } + +void MessageTexture::process(Connection *) { + if (! qbaTexture.isEmpty()) + g.o->textureResponse(iPlayerId,qbaTexture); +} diff --git a/src/mumble/Overlay.cpp b/src/mumble/Overlay.cpp index 45e9bd703..71464540a 100644 --- a/src/mumble/Overlay.cpp +++ b/src/mumble/Overlay.cpp @@ -32,6 +32,8 @@ #include "Channel.h" #include "Overlay.h" #include "Global.h" +#include "Message.h" +#include "ServerHandler.h" static ConfigWidget *OverlayConfigDialogNew() { return new OverlayConfig(); @@ -358,27 +360,20 @@ Overlay::Overlay() : QObject() { #else QString path=QString("%1/mumble_ol.dll").arg(qApp->applicationDirPath()); #endif -#else - QString path=QString("%1/libmumble_ol.so").arg(qApp->applicationDirPath()); -#endif qlOverlay->setFileName(path); if (! qlOverlay->load()) { -#ifdef Q_OS_WIN QMessageBox::critical(NULL, tr("Mumble"), tr("Failed to load overlay library. This means either that:\n" "- the library (mumble_ol.dll) wasn't found in the directory you ran Mumble from\n" "- you're on an OS earlier than WinXP SP2\n" "- you do not have the June 2007 updated version of DX9.0c"), QMessageBox::Ok, QMessageBox::NoButton); -#else - QMessageBox::critical(NULL, tr("Mumble"), tr("Failed to load overlay library. This means either that:\n" - "- you don't have libmumble_ol.so \n" - "- this isn't Linux with glibc2.3\n" - "- you have discovered a new and interesting bug"), QMessageBox::Ok, QMessageBox::NoButton); -#endif qWarning("Overlay failure"); } else { sm.resolve(qlOverlay); } +#else + sm.resolve(qlOverlay); +#endif #ifndef QT_NO_DEBUG if (sm.sm) @@ -456,7 +451,33 @@ void Overlay::forceSettings() { updateOverlay(); } -#define SAFE_INC_IDX(x) x=(x < NUM_TEXTS) ? (x+1) : (NUM_TEXTS-1) +void Overlay::textureResponse(int id, const QByteArray &texture) { + qWarning("Response for %d", id); + QString s = qhQueried.value(id); + if (s.isEmpty()) + return; + + qWarning("Which we're waiting for"); + + QByteArray t = qUncompress(texture); + + qWarning("decompressed to %d", t.size()); + + if (t.size() != TEXTURE_SIZE) + return; + + const unsigned char *data = reinterpret_cast(t.constData()); + + int width = 0; + for(int y=0;y width) && (data[(y*TEXT_WIDTH+x)*4] != 0x00)) + width = x; + } + } + qhUserTextures[s] = UserTexture(width, t); + qsForce.insert(s); +} typedef QPair qpChanCol; @@ -471,7 +492,7 @@ void Overlay::updateOverlay() { if (! isActive()) return; - + if (g.sId) { Channel *home = Player::get(g.sId)->cChannel; foreach(Channel *c, home->allLinks()) { @@ -507,6 +528,12 @@ void Overlay::updateOverlay() { foreach(Player *p, Player::get(g.sId)->cChannel->qlPlayers) { if ((g.s.osOverlay == Settings::All) || p->bTalking || ((p == Player::get(g.sId)) && g.s.bOverlayAlwaysSelf)) { + if ((p->iId >= 0) && (! qhQueried.contains(p->iId))) { + qhQueried.insert(p->iId, p->qsName); + MessageTexture mt; + mt.iPlayerId = p->iId; + g.sh->sendMessage(&mt); + } QString name = p->qsName; if (p->bDeaf || p->bSelfDeaf) name = name + QString("(D)"); @@ -526,6 +553,8 @@ void Overlay::updateOverlay() { } } } + } else { + clearCache(); } setTexts(lines); } @@ -550,17 +579,23 @@ void Overlay::fixFont() { qp.addText(0, 0, g.s.qfOverlayFont, QLatin1String("Üy")); br=qp.boundingRect(); qWarning("Overlay: Attempt for pixelsize %d gave actual sizes %f %f", psize+1, br.height(),br.top()); - } while ((br.height()+2) > TEXT_HEIGHT); + } while ((br.height()+2) > TEXT_HEIGHT); fFontBase = fabs(br.top()); + clearCache(); + + qlCurrentTexts.clear(); +} + +void Overlay::clearCache() { foreach(unsigned char *ptr, qhTextures) delete [] ptr; qhTextures.clear(); qhWidths.clear(); - - qlCurrentTexts.clear(); + qhQueried.clear(); + qhUserTextures.clear(); } void Overlay::setTexts(const QList &lines) { @@ -580,17 +615,15 @@ void Overlay::setTexts(const QList &lines) { p.setBrush(Qt::white); p.setPen(QPen(Qt::black, 2, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin)); p.drawPath(qp); -// p.setFont(g.s.qfOverlayFont); -// p.drawText(0, fm.ascent(), e.first); qhTextures[e.first] = td; qhWidths[e.first] = qMin(static_cast(qp.boundingRect().width())+4, TEXT_WIDTH); } } - + if (! sm.tryLock()) return; - + int i; for(i=0;i &lines) { wcscpy(te->text, reinterpret_cast(tl.first.left(127).utf16())); te->color = lines[i].second; - if ((i >= qlCurrentTexts.count()) || (qlCurrentTexts[i].first != tl.first)) { + if ((i >= qlCurrentTexts.count()) || (qlCurrentTexts[i].first != tl.first) || qsForce.contains(tl.first)) { if (tl.first.isNull()) { te->width = 0; } else { - memcpy(sm.sm->texts[i].texture, qhTextures[tl.first], TEXTURE_SIZE); - te->width = qhWidths[tl.first]; + if (qhUserTextures.contains(tl.first)) { + const UserTexture &ut=qhUserTextures.value(tl.first); + memcpy(sm.sm->texts[i].texture, ut.second.constData(), TEXTURE_SIZE); + te->width = ut.first; + } else { + memcpy(sm.sm->texts[i].texture, qhTextures[tl.first], TEXTURE_SIZE); + te->width = qhWidths[tl.first]; + } te->bUpdated = true; } + qsForce.remove(tl.first); } } diff --git a/src/mumble/Overlay.h b/src/mumble/Overlay.h index faa0205bc..f6c42747f 100644 --- a/src/mumble/Overlay.h +++ b/src/mumble/Overlay.h @@ -93,9 +93,13 @@ class Overlay : public QObject { OverlayPrivate *d; typedef QPair TextLine; + typedef QPair UserTexture; QList qlCurrentTexts; QHash qhTextures; + QHash qhUserTextures; QHash qhWidths; + QHash qhQueried; + QSet qsForce; QLibrary *qlOverlay; QTimer *qtTimer; float fFontBase; @@ -103,10 +107,12 @@ class Overlay : public QObject { void platformInit(); void setTexts(const QList &lines); void fixFont(); + void clearCache(); public: Overlay(); ~Overlay(); bool isActive() const; + void textureResponse(int id, const QByteArray &texture); public slots: void on_Timer_timeout(); void updateOverlay();