diff options
author | Thorvald Natvig <slicer@users.sourceforge.net> | 2007-07-06 01:32:55 +0400 |
---|---|---|
committer | Thorvald Natvig <slicer@users.sourceforge.net> | 2007-07-06 01:32:55 +0400 |
commit | 25082c477ab5b59a17c760b60f689ec34eead0a3 (patch) | |
tree | c907956ebe43b0ad0ce1641c14b438282e43230d | |
parent | 43853bc9aa8edd69df100109b01506c1bc5313ec (diff) |
Custom UserTextures
git-svn-id: https://mumble.svn.sourceforge.net/svnroot/mumble/trunk@547 05730e5d-ab1b-0410-a4ac-84af385074fa
-rw-r--r-- | src/PacketDataStream.h | 1 | ||||
-rw-r--r-- | src/mumble/MainWindow.cpp | 7 | ||||
-rw-r--r-- | src/mumble/Overlay.cpp | 84 | ||||
-rw-r--r-- | 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<const unsigned char *>(t.constData());
+
+ int width = 0;
+ for(int y=0;y<TEXT_HEIGHT;y++) {
+ for(int x=0;x<TEXT_WIDTH; x++) {
+ if ((x > width) && (data[(y*TEXT_WIDTH+x)*4] != 0x00))
+ width = x;
+ }
+ }
+ qhUserTextures[s] = UserTexture(width, t);
+ qsForce.insert(s);
+}
typedef QPair<QString, quint32> 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<TextLine> &lines) {
@@ -580,17 +615,15 @@ void Overlay::setTexts(const QList<TextLine> &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<int>(qp.boundingRect().width())+4, TEXT_WIDTH);
}
}
-
+
if (! sm.tryLock())
return;
-
+
int i;
for(i=0;i<lines.count();i++) {
@@ -603,14 +636,21 @@ void Overlay::setTexts(const QList<TextLine> &lines) { wcscpy(te->text, reinterpret_cast<const wchar_t *>(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<QString, quint32> TextLine; + typedef QPair<short, QByteArray> UserTexture; QList<TextLine> qlCurrentTexts; QHash<QString, unsigned char *> qhTextures; + QHash<QString, UserTexture> qhUserTextures; QHash<QString, short> qhWidths; + QHash<int, QString> qhQueried; + QSet<QString> qsForce; QLibrary *qlOverlay; QTimer *qtTimer; float fFontBase; @@ -103,10 +107,12 @@ class Overlay : public QObject { void platformInit(); void setTexts(const QList<TextLine> &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(); |