diff options
author | Vadim Dashevskiy <watcherhd@gmail.com> | 2012-05-15 10:38:20 +0000 |
---|---|---|
committer | Vadim Dashevskiy <watcherhd@gmail.com> | 2012-05-15 10:38:20 +0000 |
commit | 48540940b6c28bb4378abfeb500ec45a625b37b6 (patch) | |
tree | 2ef294c0763e802f91d868bdef4229b6868527de /plugins/Popup/src/avatars_gif.cpp | |
parent | 5c350913f011e119127baeb32a6aedeb4f0d33bc (diff) |
initial commit
git-svn-id: http://svn.miranda-ng.org/main/trunk@2 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/Popup/src/avatars_gif.cpp')
-rw-r--r-- | plugins/Popup/src/avatars_gif.cpp | 143 |
1 files changed, 143 insertions, 0 deletions
diff --git a/plugins/Popup/src/avatars_gif.cpp b/plugins/Popup/src/avatars_gif.cpp new file mode 100644 index 0000000000..24ee798e93 --- /dev/null +++ b/plugins/Popup/src/avatars_gif.cpp @@ -0,0 +1,143 @@ +/*
+Popup Plus plugin for Miranda IM
+
+Copyright © 2002 Luca Santarelli,
+ © 2004-2007 Victor Pavlychko
+ © 2010 MPK
+ © 2010 Merlin_de
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+===============================================================================
+
+File name : $HeadURL: http://svn.miranda.im/mainrepo/popup/trunk/src/avatars_gif.cpp $
+Revision : $Revision: 1624 $
+Last change on : $Date: 2010-06-24 19:39:34 +0300 (Чт, 24 июн 2010) $
+Last change by : $Author: Merlin_de $
+
+===============================================================================
+*/
+
+#include "headers.h"
+
+GifAvatar::GifAvatar(HANDLE hContact): PopupAvatar(hContact)
+{
+ av = (avatarCacheEntry *)CallService(MS_AV_GETAVATARBITMAP, (WPARAM)hContact, 0);
+ bIsAnimated = true;
+ bIsValid = true;
+ GDIPlus_GetGIFSize(av->szFilename, &this->width, &this->height);
+
+ hBitmap = NULL;
+ frameDelays = NULL;
+ frameCount = 0;
+ frameSize.cx = frameSize.cy = 0;
+
+ cachedHeight = cachedWidth = -1;
+
+ activeFrame = 0;
+}
+
+GifAvatar::~GifAvatar()
+{
+ if (frameDelays) {
+ mir_free(frameDelays);
+ frameDelays = NULL;
+ }
+ if (hBitmap) DeleteObject(hBitmap);
+}
+
+int GifAvatar::activeFrameDelay()
+{
+ if (!av || !frameCount || !frameDelays || !hBitmap || (activeFrame < 0) || (activeFrame >= frameCount))
+ return -1;
+ return frameDelays[activeFrame];
+}
+
+void GifAvatar::draw(MyBitmap *bmp, int x, int y, int w, int h, POPUPOPTIONS *options)
+{
+ if (!av || (w <= 0) || (h <= 0)) return;
+
+ if (!frameCount || !frameDelays || !hBitmap || (cachedWidth != w) || (cachedHeight != h))
+ {
+ cachedWidth = w;
+ cachedHeight = h;
+ if (frameDelays) {
+ mir_free(frameDelays);
+ frameDelays = NULL;
+ }
+ if (hBitmap) DeleteObject(hBitmap);
+ GDIPlus_ExtractAnimatedGIF(av->szFilename, w, h, &hBitmap, &frameDelays, &frameCount, &frameSize);
+ }
+
+ if (!frameCount) return;
+
+ HRGN rgn;
+ if (options->avatarRadius)
+ {
+ rgn = CreateRoundRectRgn(x, y, x+w, y+h, 2 * options->avatarRadius, 2 * options->avatarRadius);
+ SelectClipRgn(bmp->getDC(), rgn);
+ } else
+ {
+ rgn = CreateRectRgn(x, y, x+w, y+h);
+ }
+
+ HDC hdcTmp = CreateCompatibleDC(bmp->getDC());
+ SelectObject(hdcTmp, hBitmap);
+ SetStretchBltMode(bmp->getDC(), HALFTONE);
+
+#if defined(_UNICODE)
+ if (av->dwFlags & AVS_PREMULTIPLIED)
+ {
+ BLENDFUNCTION bf;
+ bf.BlendOp = AC_SRC_OVER;
+ bf.BlendFlags = 0;
+ bf.SourceConstantAlpha = 255;
+ bf.AlphaFormat = AC_SRC_ALPHA;
+ AlphaBlend(bmp->getDC(), x, y, w, h, hdcTmp, frameSize.cx*activeFrame, 0, frameSize.cx, frameSize.cy, bf);
+#else
+ if (MyAlphaBlend && (av->dwFlags & AVS_PREMULTIPLIED))
+ {
+ BLENDFUNCTION bf;
+ bf.BlendOp = AC_SRC_OVER;
+ bf.BlendFlags = 0;
+ bf.SourceConstantAlpha = 255;
+ bf.AlphaFormat = AC_SRC_ALPHA;
+ MyAlphaBlend(bmp->getDC(), x, y, w, h, hdcTmp, frameSize.cx*activeFrame, 0, frameSize.cx, frameSize.cy, bf);
+#endif
+ if (options->avatarBorders && options->avatarPNGBorders)
+ {
+ HBRUSH hbr = CreateSolidBrush(fonts.clAvatarBorder);
+ bmp->saveAlpha(x, y, w, h);
+ FrameRgn(bmp->getDC(), rgn, hbr, 1, 1);
+ DeleteObject(hbr);
+ bmp->restoreAlpha(x, y, w, h);
+ }
+ }
+ else {
+ bmp->saveAlpha(x, y, w, h);
+ StretchBlt(bmp->getDC(), x, y, w, h, hdcTmp, frameSize.cx*activeFrame, 0, frameSize.cx, frameSize.cy, SRCCOPY);
+ if (options->avatarBorders) {
+ HBRUSH hbr = CreateSolidBrush(fonts.clAvatarBorder);
+ FrameRgn(bmp->getDC(), rgn, hbr, 1, 1);
+ DeleteObject(hbr);
+ }
+ bmp->restoreAlpha(x, y, w, h);
+ }
+ DeleteObject(rgn);
+ SelectClipRgn(bmp->getDC(), NULL);
+ DeleteDC(hdcTmp);
+
+ activeFrame = (activeFrame + 1) % frameCount;
+}
|