From: Arnaud Giersch Date: Wed, 1 Dec 2010 12:22:01 +0000 (+0100) Subject: Allow std::string arguments for drawText and drawTextBg. X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/graphlib.git/commitdiff_plain/ba95ae86a1edaa7af7e576bf30b39a3934693bd4?hp=5094246bbd6b66b06521cf1c1a08578f8c16d0de Allow std::string arguments for drawText and drawTextBg. --- diff --git a/CHANGES b/CHANGES index 99f58e8..158afc6 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,7 @@ +-- Wed, 01 Dec 2010 12:11:36 +0100 + + * Allow std::string arguments for drawText and drawTextBg. + -- Mon, 22 Nov 2010 21:27:00 +0100 * Add methods drawTriangle and fillTriangle. diff --git a/DrawingWindow.cpp b/DrawingWindow.cpp index 6fad2c0..f68f43b 100644 --- a/DrawingWindow.cpp +++ b/DrawingWindow.cpp @@ -545,6 +545,7 @@ void DrawingWindow::fillTriangle(int x1, int y1, int x2, int y2, int x3, int y3) * \param text texte à écrire * \param flags paramètres d'alignement * + * \see drawText(int, int, const std::string &, int) * \see drawTextBg, setColor * \see QPainter::drawText */ @@ -558,6 +559,15 @@ void DrawingWindow::drawText(int x, int y, const char *text, int flags) safeUnlock(syncMutex); } +//! Écrit du texte. +/*! + * \see drawText(int, int, const char *, int) + */ +void DrawingWindow::drawText(int x, int y, const std::string &text, int flags) +{ + drawText(x, y, text.c_str(), flags); +} + //! Écrit du texte sur fond coloré. /*! * Écrit du texte comme drawText, mais l'arrière-plan est coloré avec @@ -567,6 +577,7 @@ void DrawingWindow::drawText(int x, int y, const char *text, int flags) * \param text texte à écrire * \param flags paramètres d'alignement * + * \see drawTextBg(int, int, const std::string &, int) * \see drawText, setColor, setColorBg */ void DrawingWindow::drawTextBg(int x, int y, const char *text, int flags) @@ -576,6 +587,15 @@ void DrawingWindow::drawTextBg(int x, int y, const char *text, int flags) painter->setBackgroundMode(Qt::TransparentMode); } +//! Écrit du texte sur fond coloré. +/*! + * \see drawTextBg(int, int, const char *, int) + */ +void DrawingWindow::drawTextBg(int x, int y, const std::string &text, int flags) +{ + drawTextBg(x, y, text.c_str(), flags); +} + //! Retourne la couleur d'un pixel. /*! * Retourne la couleur du pixel de coordonnées (x, y). La valeur diff --git a/DrawingWindow.h b/DrawingWindow.h index 5bb8cb5..e44ea3b 100644 --- a/DrawingWindow.h +++ b/DrawingWindow.h @@ -12,6 +12,7 @@ #include #include #include +#include class DrawingThread; @@ -59,7 +60,9 @@ public: void fillTriangle(int x1, int y1, int x2, int y2, int x3, int y3); void drawText(int x, int y, const char *text, int flags = 0); + void drawText(int x, int y, const std::string &text, int flags = 0); void drawTextBg(int x, int y, const char *text, int flags = 0); + void drawTextBg(int x, int y, const std::string &text, int flags = 0); unsigned int getPointColor(int x, int y); diff --git a/chateaux/chateaux.cpp b/chateaux/chateaux.cpp index 8726d26..6ad81b7 100644 --- a/chateaux/chateaux.cpp +++ b/chateaux/chateaux.cpp @@ -218,7 +218,7 @@ void initialise(DrawingWindow& w) Qt::AlignHCenter); std::stringstream s; s << score1 << " / " << score2; - w.drawText(rtowX(w, 0), rtowY(w, 0) + 8, s.str().c_str(), + w.drawText(rtowX(w, 0), rtowY(w, 0) + 8, s.str(), Qt::AlignHCenter); } @@ -322,7 +322,7 @@ int jeu1(DrawingWindow& w) msg << " a perdu ! "; w.setColor("darkred"); w.setBgColor("white"); - w.drawTextBg(w.width / 2, w.height / 3, msg.str().c_str(), + w.drawTextBg(w.width / 2, w.height / 3, msg.str(), Qt::AlignCenter); w.sync(); std::cout << msg.str() << std::endl;