rendered paste bodyIndex: libs/libmythui/mythpainter.cpp
===================================================================
--- libs/libmythui/mythpainter.cpp (revision 21131)
+++ libs/libmythui/mythpainter.cpp (working copy)
@@ -9,16 +9,16 @@
{
}
-void MythPainter::DrawImage(int x, int y, MythImage *im, int alpha)
+void MythPainter::DrawImage(int x, int y, MythImage *im, int alpha, Effects fx)
{
assert(im);
QRect dest = QRect(x, y, im->width(), im->height());
QRect src = im->rect();
- DrawImage(dest, im, src, alpha);
+ DrawImage(dest, im, src, alpha, fx);
}
-void MythPainter::DrawImage(const QPoint &topLeft, MythImage *im, int alpha)
+void MythPainter::DrawImage(const QPoint &topLeft, MythImage *im, int alpha, Effects fx)
{
- DrawImage(topLeft.x(), topLeft.y(), im, alpha);
+ DrawImage(topLeft.x(), topLeft.y(), im, alpha, fx);
}
Index: libs/libmythui/mythpainter_qt.cpp
===================================================================
--- libs/libmythui/mythpainter_qt.cpp (revision 21131)
+++ libs/libmythui/mythpainter_qt.cpp (working copy)
@@ -72,13 +72,13 @@
}
void MythQtPainter::DrawImage(const QRect &r, MythImage *im,
- const QRect &src, int alpha)
+ const QRect &src, int alpha, Effects fx)
{
assert(painter);
(void)alpha;
-
+ int angle = fx.rotate;
MythQtImage *qim = reinterpret_cast<MythQtImage *>(im);
-
+ // if (angle) qim->Rotate(angle);
painter->drawPixmap(r.topLeft(), *(qim->GetPixmap()), src);
}
Index: libs/libmythui/mythimage.cpp
===================================================================
--- libs/libmythui/mythimage.cpp (revision 21131)
+++ libs/libmythui/mythimage.cpp (working copy)
@@ -117,7 +117,25 @@
Assign(scaled(newSize, mode, Qt::SmoothTransformation));
}
}
-
+void MythImage::Rotate(int angle)
+{
+ if (m_isRotated)
+ return;
+ int mywidth = int(width());
+ int myheight = int(height());
+ //float scalefactor = mywidth / (sqrt((mywidth * mywidth) + (myheight * myheight)));
+ QImage rotatedImage;
+ QMatrix rotateMatrix;
+
+ rotateMatrix.rotate(angle);
+ //rotateMatrix.scale(scalefactor,scalefactor);
+
+ rotatedImage = rotatedImage.transformed(rotateMatrix, Qt::SmoothTransformation);
+
+ Assign(transformed(rotateMatrix, Qt::SmoothTransformation));
+ m_isRotated = true;
+
+}
void MythImage::Reflect(ReflectAxis axis, int shear, int scale, int length,
int spacing)
{
Index: libs/libmythui/mythuishape.cpp
===================================================================
--- libs/libmythui/mythuishape.cpp (revision 21131)
+++ libs/libmythui/mythuishape.cpp (working copy)
@@ -58,8 +58,9 @@
DrawRoundRect(area, m_cornerRadius, m_drawFill, m_fillColor,
m_drawLine, m_lineWidth, m_lineColor);
}
-
- p->DrawImage(area.x(), area.y(), m_image, alphaMod);
+MythPainter::Effects effex;
+ effex.rotate = 0;
+ p->DrawImage(area.x(), area.y(), m_image, alphaMod, effex);
}
void MythUIShape::DrawRect(const QRect &area,
Index: libs/libmythui/mythpainter.h
===================================================================
--- libs/libmythui/mythpainter.h (revision 21131)
+++ libs/libmythui/mythpainter.h (working copy)
@@ -20,6 +20,11 @@
public:
MythPainter() : m_Parent(0) { }
virtual ~MythPainter() { }
+ struct Effects
+{
+ int rotate;
+ int reflectionAxis;
+};
virtual QString GetName(void) = 0;
virtual bool SupportsAnimation(void) = 0;
@@ -34,10 +39,10 @@
QWidget *GetParent(void) { return m_Parent; }
virtual void DrawImage(const QRect &dest, MythImage *im, const QRect &src,
- int alpha) = 0;
+ int alpha, Effects) = 0;
- void DrawImage(int x, int y, MythImage *im, int alpha);
- void DrawImage(const QPoint &topLeft, MythImage *im, int alph);
+ void DrawImage(int x, int y, MythImage *im, int alpha, Effects effect);
+ void DrawImage(const QPoint &topLeft, MythImage *im, int alph, Effects);
virtual void DrawText(const QRect &dest, const QString &msg, int flags,
const MythFontProperties &font, int alpha,
Index: libs/libmythui/mythpainter_qt.h
===================================================================
--- libs/libmythui/mythpainter_qt.h (revision 21131)
+++ libs/libmythui/mythpainter_qt.h (working copy)
@@ -25,7 +25,7 @@
virtual void SetClipRect(const QRect &clipRect);
virtual void DrawImage(const QRect &dest, MythImage *im, const QRect &src,
- int alpha);
+ int alpha, Effects fx);
virtual void DrawText(const QRect &dest, const QString &msg, int flags,
const MythFontProperties &font, int alpha,
const QRect &boundRect);
Index: libs/libmythui/mythimage.h
===================================================================
--- libs/libmythui/mythimage.h (revision 21131)
+++ libs/libmythui/mythimage.h (working copy)
@@ -28,7 +28,7 @@
bool IsGradient() const { return m_isGradient; }
bool IsReflected() const { return m_isReflected; }
-
+bool IsRotated() const { return m_isRotated; }
void Assign(const QImage &img);
void Assign(const QPixmap &pix);
@@ -38,6 +38,7 @@
bool Load(const QString &filename, bool scale = true);
void Resize(const QSize &newSize, bool preserveAspect = false);
+ void Rotate(int angle);
void Reflect(ReflectAxis axis, int shear, int scale, int length,
int spacing = 0);
void ToGreyscale();
@@ -60,7 +61,7 @@
QString GetFileName(void) const { return m_FileName; }
void setIsReflected(bool reflected) { m_isReflected = reflected; }
-
+void setIsRotated(bool rotated) { m_isRotated = rotated; }
void SetIsInCache(bool bCached);
protected:
@@ -83,7 +84,7 @@
FillDirection m_gradDirection;
bool m_isReflected;
-
+ bool m_isRotated;
unsigned int m_imageId;
QString m_FileName;
Index: libs/libmythui/mythpainter_ogl.h
===================================================================
--- libs/libmythui/mythpainter_ogl.h (revision 21131)
+++ libs/libmythui/mythpainter_ogl.h (working copy)
@@ -21,7 +21,7 @@
virtual void End();
virtual void DrawImage(const QRect &dest, MythImage *im, const QRect &src,
- int alpha);
+ int alpha, Effects fx);
virtual void DrawText(const QRect &dest, const QString &msg, int flags,
const MythFontProperties &font, int alpha,
const QRect &boundRect);
Index: libs/libmythui/mythuiimage.cpp
===================================================================
--- libs/libmythui/mythuiimage.cpp (revision 21131)
+++ libs/libmythui/mythuiimage.cpp (working copy)
@@ -101,7 +101,8 @@
m_reflectScale = m_reflectLength = 100;
m_reflectAxis = ReflectVertical;
m_reflectSpacing = 0;
-
+m_rotate = 0;
+m_isRotated = false;
m_gradient = false;
m_gradientStart = QColor("#505050");
m_gradientEnd = QColor("#000000");
@@ -330,6 +331,9 @@
if (m_isGreyscale)
s_Attrib += "greyscale";
+
+ if (m_isReflected)
+ s_Attrib += "rotated";
imagelabel = QString("%1-%2-%3x%4.png")
.arg(filename)
@@ -477,7 +481,11 @@
if (m_isGreyscale)
image->ToGreyscale();
-
+if (!GetMythPainter()->SupportsAnimation())
+{
+image->Rotate(m_rotate);
+VERBOSE(VB_IMPORTANT, QString("Rotating %1 degrees").arg(m_rotate));
+}
// Save scaled copy to cache
if (bNeedLoad)
GetMythUI()->CacheImage(imagelabel, image);
@@ -564,8 +572,10 @@
srcRect = m_cropRect.toQRect();
else
srcRect = currentImageArea;
-
- p->DrawImage(area, currentImage, srcRect, alpha);
+ MythPainter::Effects fx;
+ fx.rotate = m_rotate;
+ p->DrawImage(area, currentImage, srcRect, alpha, fx);
+ fx.rotate = 0;
}
}
@@ -685,6 +695,10 @@
{
m_isGreyscale = parseBool(element);
}
+ else if (element.tagName() == "rotate")
+ {
+ m_rotate = getFirstText(element).toInt();
+ }
else
return MythUIType::ParseElement(element);
@@ -710,7 +724,8 @@
m_Filename = im->m_Filename;
m_OrigFilename = im->m_OrigFilename;
-
+m_rotate = im->m_rotate;
+m_isRotated = im->m_isRotated;
m_cropRect = im->m_cropRect;
m_ForceSize = im->m_ForceSize;
Index: libs/libmythui/mythuiguidegrid.cpp
===================================================================
--- libs/libmythui/mythuiguidegrid.cpp (revision 21131)
+++ libs/libmythui/mythuiguidegrid.cpp (working copy)
@@ -345,16 +345,20 @@
arrowImg = &m_arrowImages[2];
MythImage *im = GetMythMainWindow()->GetCurrentPainter()->GetFormatImage();
im->Assign(*arrowImg);
+ MythPainter::Effects effex;
+ effex.rotate = 0;
p->DrawImage(area.left() + (area.width() / 2) - (arrowImg->height() / 2),
- area.top() , im, alphaMod);
+ area.top() , im, alphaMod, effex);
}
else
{
arrowImg = &m_arrowImages[0];
MythImage *im = GetMythMainWindow()->GetCurrentPainter()->GetFormatImage();
im->Assign(*arrowImg);
+ MythPainter::Effects effex;
+ effex.rotate = 0;
p->DrawImage(area.left(), area.top() + (area.height() / 2) -
- (arrowImg->height() / 2), im, alphaMod);
+ (arrowImg->height() / 2), im, alphaMod, effex);
}
}
if (data->arrow == 2 || data->arrow == 3)
@@ -365,8 +369,10 @@
MythImage *im = GetMythMainWindow()->GetCurrentPainter()->GetFormatImage();
im->Assign(*arrowImg);
recTypeOffset = arrowImg->width();
+ MythPainter::Effects effex;
+ effex.rotate = 0;
p->DrawImage(area.left() + (area.width() / 2) - (arrowImg->height() / 2),
- area.top() + area.height() - arrowImg->height(), im, alphaMod);
+ area.top() + area.height() - arrowImg->height(), im, alphaMod, effex);
}
else
{
@@ -374,9 +380,11 @@
MythImage *im = GetMythMainWindow()->GetCurrentPainter()->GetFormatImage();
im->Assign(*arrowImg);
recTypeOffset = arrowImg->width();
+ MythPainter::Effects effex;
+ effex.rotate = 0;
p->DrawImage(area.right() - arrowImg->width(),
area.top() + (area.height() / 2) -
- (arrowImg->height() / 2), im, alphaMod);
+ (arrowImg->height() / 2), im, alphaMod, effex);
}
}
}
@@ -387,8 +395,10 @@
QPixmap *recImg = &m_recImages[data->recType];
MythImage *im = GetMythMainWindow()->GetCurrentPainter()->GetFormatImage();
im->Assign(*recImg);
+ MythPainter::Effects effex;
+ effex.rotate = 0;
p->DrawImage(area.right() - recImg->width(),
- area.bottom() - recImg->height(), im, alphaMod);
+ area.bottom() - recImg->height(), im, alphaMod, effex);
}
}
Index: libs/libmythui/mythpainter_ogl.cpp
===================================================================
--- libs/libmythui/mythpainter_ogl.cpp (revision 21131)
+++ libs/libmythui/mythpainter_ogl.cpp (working copy)
@@ -99,6 +99,7 @@
realParent->makeCurrent();
glFlush();
+ //glLoadIdentity();
realParent->swapBuffers();
MythPainter::End();
@@ -224,6 +225,10 @@
glGenTextures(1, &tx_id);
glBindTexture(q_gl_texture, tx_id);
glTexParameteri(q_gl_texture, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ //the following 2 lines were put here to fix a texture smearing problem which can be seen when
+ //rotating a texture
+glTexParameteri(q_gl_texture, GL_TEXTURE_WRAP_S, GL_CLAMP);
+glTexParameteri(q_gl_texture, GL_TEXTURE_WRAP_T, GL_CLAMP);
if (generate_mipmaps)
{
@@ -249,25 +254,28 @@
}
void MythOpenGLPainter::DrawImage(const QRect &r, MythImage *im,
- const QRect &src, int alpha)
+ const QRect &src, int alpha, Effects fx)
{
+ // glMatrixMode(GL_MODELVIEW);
+ // glLoadIdentity();
double x1, y1, x2, y2;
-
+ int angle = 0;
+ angle = fx.rotate;
glClearDepth(1.0f);
-
- // see if we have this pixmap cached as a texture - if not cache it
+ // see if we have this pixmap cached as a texture - if not cache it
BindTextureFromCache(im);
-
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
-
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+
glPushAttrib(GL_CURRENT_BIT);
+ glColor4f(1.0, 1.0, 1.0, alpha / 255.0);
+ int xTrans = r.x();
+ int yTrans = r.y();
+
+ glPushMatrix();
- glColor4f(1.0, 1.0, 1.0, alpha / 255.0);
glEnable(q_gl_texture);
glEnable(GL_BLEND);
-
- glBegin(GL_QUADS);
- {
+
if (!texture_rects)
{
x1 = src.x() / (double)im->width();
@@ -285,17 +293,25 @@
int width = std::min(src.width(), r.width());
int height = std::min(src.height(), r.height());
-
- glTexCoord2f(x1, y2); glVertex2f(r.x(), r.y());
- glTexCoord2f(x2, y2); glVertex2f(r.x() + width, r.y());
- glTexCoord2f(x2, y1); glVertex2f(r.x() + width, r.y() + height);
- glTexCoord2f(x1, y1); glVertex2f(r.x(), r.y()+height);
- }
- glEnd();
-
+// move the matrix origin to (xTrans + width/2), (yTrans + height/2), rotate by [angle]
+// then move the matrix back so we can rotate around the image centre
+ glTranslatef(width/2, height/2, 0);
+ glTranslatef(xTrans, yTrans, 0);
+ glRotatef(angle, 0.0, 0.0, 1.0); // do rotate op
+ glTranslatef(-width/2, -height/2,0);
+
+ glBegin(GL_QUADS);
+ {
+ glTexCoord2f(x1, y2); glVertex2f(0, 0); //actually r.x()-(width/2), r.y()-(height/2) since it's translated
+ glTexCoord2f(x2, y2); glVertex2f(width, 0);
+ glTexCoord2f(x2, y1); glVertex2f(width, height);
+ glTexCoord2f(x1, y1); glVertex2f(0, height);
+ }
+ glEnd();
glDisable(GL_BLEND);
- glDisable(q_gl_texture);
+ glDisable(q_gl_texture);
glPopAttrib();
+ glPopMatrix();
}
int MythOpenGLPainter::CalcAlpha(int alpha1, int alpha2)
@@ -498,8 +514,9 @@
srcRect.setRect(x,y,width,height);
}
-
- DrawImage(destRect, im, srcRect, alpha);
+ MythPainter::Effects effex;
+ effex.rotate = 0;
+ DrawImage(destRect, im, srcRect, alpha, effex);
}
void MythOpenGLPainter::DrawRect(const QRect &area,
@@ -586,7 +603,9 @@
MythImage *im = GetFormatImage();
im->Assign(image);
- MythPainter::DrawImage(area.x(), area.y(), im, 255);
+ MythPainter::Effects effex;
+ effex.rotate = 0;
+ MythPainter::DrawImage(area.x(), area.y(), im, 255, effex);
im->DownRef();
}
Index: libs/libmythui/mythuiwebbrowser.cpp
===================================================================
--- libs/libmythui/mythuiwebbrowser.cpp (revision 21131)
+++ libs/libmythui/mythuiwebbrowser.cpp (working copy)
@@ -549,8 +549,9 @@
QRect area = m_Area;
area.translate(xoffset, yoffset);
-
- p->DrawImage(area.x(), area.y(), m_image, alphaMod);
+MythPainter::Effects effex;
+ effex.rotate = 0;
+ p->DrawImage(area.x(), area.y(), m_image, alphaMod, effex);
}
/** \brief Key event handler
Index: libs/libmythui/mythuiimage.h
===================================================================
--- libs/libmythui/mythuiimage.h (revision 21131)
+++ libs/libmythui/mythuiimage.h (working copy)
@@ -24,7 +24,7 @@
/** Must be followed by a call to Load() to load the image. */
void SetFilename(const QString &filename);
-
+
/** Must be followed by a call to Load() to load the image. */
void SetFilepattern(const QString &filepattern, int low, int high);
@@ -96,7 +96,8 @@
int m_reflectScale;
int m_reflectLength;
int m_reflectSpacing;
-
+ int m_rotate;
+ bool m_isRotated;
MythImage *m_maskImage;
bool m_isMasked;