summaryrefslogtreecommitdiff
path: root/dmagick
diff options
context:
space:
mode:
Diffstat (limited to 'dmagick')
-rw-r--r--dmagick/Array.d18
-rw-r--r--dmagick/internal/Windows.d63
2 files changed, 63 insertions, 18 deletions
diff --git a/dmagick/Array.d b/dmagick/Array.d
index 62f17fa..339de5c 100644
--- a/dmagick/Array.d
+++ b/dmagick/Array.d
@@ -31,6 +31,8 @@ import dmagick.c.montage;
import dmagick.c.statistic;
import dmagick.c.quantize;
+version(Windows) import dmagick.internal.Windows;
+
/// See_Also: $(CXREF layer, _ImageLayerMethod)
public alias dmagick.c.layer.ImageLayerMethod ImageLayerMethod;
@@ -165,12 +167,20 @@ void compositeLayers(
*/
void display(Image[] images)
{
- linkImages(images);
- scope(exit) unlinkImages(images);
+ version(Windows)
+ {
+ Window win = new Window(images);
+ win.display();
+ }
+ else
+ {
+ linkImages(images);
+ scope(exit) unlinkImages(images);
- DisplayImages(images[0].options.imageInfo, images[0].imageRef);
+ DisplayImages(images[0].options.imageInfo, images[0].imageRef);
- DMagickException.throwException(&(images[0].imageRef.exception));
+ DMagickException.throwException(&(images[0].imageRef.exception));
+ }
}
/**
diff --git a/dmagick/internal/Windows.d b/dmagick/internal/Windows.d
index 50dee7b..99a2d9e 100644
--- a/dmagick/internal/Windows.d
+++ b/dmagick/internal/Windows.d
@@ -15,6 +15,8 @@ import dmagick.Geometry;
class Window
{
Image image;
+ Image[] imageList;
+ size_t index;
size_t height;
size_t width;
@@ -42,7 +44,7 @@ class Window
wndclass.hIcon = LoadIconA(null, IDI_APPLICATION);
wndclass.hCursor = LoadCursorA(null, IDC_ARROW);
wndclass.hbrBackground = null;
- wndclass.lpszMenuName = "DMagick";
+ wndclass.lpszMenuName = null;
wndclass.lpszClassName = "DMagick";
if (!RegisterClassA(&wndclass))
@@ -57,12 +59,26 @@ class Window
windows[hwnd] = this;
}
+
+ this(Image[] images)
+ {
+ this(images[0]);
+
+ imageList = images;
+ index = 0;
+ }
void display()
{
ShowWindow(hwnd, SW_SHOWNORMAL);
UpdateWindow(hwnd);
-
+
+ if ( imageList !is null )
+ {
+ UINT delay = cast(UINT)image.animationDelay.total!"msecs"();
+ SetTimer(hwnd, 0, delay, null);
+ }
+
while (GetMessageA(&msg, null, 0, 0))
{
TranslateMessage(&msg);
@@ -72,21 +88,17 @@ class Window
extern(Windows) static LRESULT WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
- HDC hdc;
- PAINTSTRUCT ps;
-
switch (message)
{
case WM_ERASEBKGND: // don't redraw bg
return 1;
case WM_PAINT:
- // Get DC for window
- hdc = BeginPaint(hwnd, &ps);
-
- windows[hwnd].DrawAlphaBlend(hwnd, hdc);
+ windows[hwnd].draw();
+ return 0;
- EndPaint(hwnd, &ps);
+ case WM_TIMER:
+ windows[hwnd].nextFrame();
return 0;
case WM_DESTROY:
@@ -100,17 +112,19 @@ class Window
return DefWindowProcA(hwnd, message, wParam, lParam);
}
- void DrawAlphaBlend(HWND hWnd, HDC hdcwnd)
+ void draw()
{
HDC hdc; // handle of the DC we will create
+ HDC hdcwnd; // DC for the window
HBITMAP hbitmap; // bitmap handle
BITMAPINFO bmi; // bitmap header
+ PAINTSTRUCT ps;
VOID* pvBits; // pointer to DIB section
ULONG ulWindowWidth, ulWindowHeight; // window width/height
RECT rt; // used for getting window dimensions
// get window dimensions
- GetClientRect(hWnd, &rt);
+ GetClientRect(hwnd, &rt);
// calculate window width/height
ulWindowWidth = rt.right - rt.left;
@@ -119,8 +133,11 @@ class Window
// make sure we have at least some window size
if (ulWindowWidth < 1 || ulWindowHeight < 1)
return;
+
+ // Get DC for window
+ hdcwnd = BeginPaint(hwnd, &ps);
- // create a DC for our bitmap -- the source DC for GdiAlphaBlend
+ // create a DC for our bitmap -- the source DC for BitBlt
hdc = CreateCompatibleDC(hdcwnd);
// setup bitmap info
@@ -145,6 +162,23 @@ class Window
DeleteObject(hbitmap);
DeleteDC(hdc);
+ EndPaint(hwnd, &ps);
+ }
+
+ /**
+ * Setup the next frame, and invalidate the window so its repainted.
+ */
+ void nextFrame()
+ {
+ if (++index == imageList.length)
+ index = 0;
+
+ image = imageList[index];
+
+ UINT delay = cast(UINT)image.animationDelay.total!"msecs"();
+ SetTimer(hwnd, 0, delay, null);
+
+ InvalidateRect(hwnd,null,false);
}
}
@@ -158,4 +192,5 @@ enum UINT DIB_RGB_COLORS = 0;
extern(Windows) BOOL BitBlt(HDC, int, int, int, int, HDC, int, int, DWORD);
extern(Windows) HBITMAP CreateCompatibleBitmap(HDC, int, int);
-extern(Windows) HBITMAP CreateDIBSection(HDC, const(BITMAPINFO)*, UINT, void**, HANDLE, DWORD); \ No newline at end of file
+extern(Windows) HBITMAP CreateDIBSection(HDC, const(BITMAPINFO)*, UINT, void**, HANDLE, DWORD);
+extern(Windows) UINT_PTR SetTimer(HWND, UINT_PTR, UINT, TIMERPROC); \ No newline at end of file