mirror of https://github.com/adamdruppe/arsd.git
finally implement takeScreenshot
This commit is contained in:
parent
aa5d0bfb54
commit
cce50f56a0
|
@ -1432,24 +1432,33 @@ float[2] getDpi() {
|
||||||
}
|
}
|
||||||
|
|
||||||
TrueColorImage trueColorImageFromNativeHandle(NativeWindowHandle handle, int width, int height) {
|
TrueColorImage trueColorImageFromNativeHandle(NativeWindowHandle handle, int width, int height) {
|
||||||
throw new Exception("not implemented");
|
TrueColorImage got;
|
||||||
version(none) {
|
|
||||||
version(X11) {
|
version(X11) {
|
||||||
auto display = XDisplayConnection.get;
|
auto display = XDisplayConnection.get;
|
||||||
auto image = XGetImage(display, handle, 0, 0, width, height, (cast(c_ulong) ~0) /*AllPlanes*/, ZPixmap);
|
auto image = XGetImage(display, handle, 0, 0, width, height, (cast(c_ulong) ~0) /*AllPlanes*/, ImageFormat.ZPixmap);
|
||||||
|
|
||||||
// https://github.com/adamdruppe/arsd/issues/98
|
// https://github.com/adamdruppe/arsd/issues/98
|
||||||
|
|
||||||
// FIXME: copy that shit
|
auto i = new Image(image);
|
||||||
|
got = i.toTrueColorImage();
|
||||||
|
|
||||||
XDestroyImage(image);
|
XDestroyImage(image);
|
||||||
} else version(Windows) {
|
} else version(Windows) {
|
||||||
// I just need to BitBlt that shit... BUT WAIT IT IS ALREADY IN A DIB!!!!!!!
|
// I just need to BitBlt that shit... BUT WAIT IT IS ALREADY IN A DIB!!!!!!!
|
||||||
|
|
||||||
|
auto hdc = GetDC(handle);
|
||||||
|
scope(exit) ReleaseDC(handle, hdc);
|
||||||
|
auto i = new Image(width, height);
|
||||||
|
HDC hdcMem = CreateCompatibleDC(hdc);
|
||||||
|
HBITMAP hbmOld = SelectObject(hdcMem, i.handle);
|
||||||
|
BitBlt(hdcMem, 0, 0, width, height, hdc, 0, 0, SRCCOPY);
|
||||||
|
SelectObject(hdcMem, hbmOld);
|
||||||
|
DeleteDC(hdcMem);
|
||||||
|
|
||||||
|
got = i.toTrueColorImage();
|
||||||
} else featureNotImplemented();
|
} else featureNotImplemented();
|
||||||
|
|
||||||
return null;
|
return got;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/++
|
/++
|
||||||
|
@ -1473,8 +1482,14 @@ TrueColorImage trueColorImageFromNativeHandle(NativeWindowHandle handle, int wid
|
||||||
+/
|
+/
|
||||||
class SimpleWindow : CapableOfHandlingNativeEvent, CapableOfBeingDrawnUpon {
|
class SimpleWindow : CapableOfHandlingNativeEvent, CapableOfBeingDrawnUpon {
|
||||||
|
|
||||||
/// Be warned: this can be a very slow operation
|
/++
|
||||||
/// FIXME NOT IMPLEMENTED
|
Copies the window's current state into a [TrueColorImage].
|
||||||
|
|
||||||
|
Be warned: this can be a very slow operation
|
||||||
|
|
||||||
|
History:
|
||||||
|
Actually implemented on March 14, 2021
|
||||||
|
+/
|
||||||
TrueColorImage takeScreenshot() {
|
TrueColorImage takeScreenshot() {
|
||||||
version(Windows)
|
version(Windows)
|
||||||
return trueColorImageFromNativeHandle(impl.hwnd, width, height);
|
return trueColorImageFromNativeHandle(impl.hwnd, width, height);
|
||||||
|
@ -2359,7 +2374,7 @@ class SimpleWindow : CapableOfHandlingNativeEvent, CapableOfBeingDrawnUpon {
|
||||||
|
|
||||||
SelectObject(hdcMem, hbmOld);
|
SelectObject(hdcMem, hbmOld);
|
||||||
DeleteDC(hdcMem);
|
DeleteDC(hdcMem);
|
||||||
DeleteDC(hwnd);
|
ReleaseDC(hwnd, hdc);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
RECT r;
|
RECT r;
|
||||||
|
@ -6867,7 +6882,19 @@ final class Image {
|
||||||
this(size.width, size.height, forcexshm);
|
this(size.width, size.height, forcexshm);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private bool suppressDestruction;
|
||||||
|
|
||||||
|
version(X11)
|
||||||
|
this(XImage* handle) {
|
||||||
|
this.handle = handle;
|
||||||
|
this.rawData = cast(ubyte*) handle.data;
|
||||||
|
this.width = handle.width;
|
||||||
|
this.height = handle.height;
|
||||||
|
suppressDestruction = true;
|
||||||
|
}
|
||||||
|
|
||||||
~this() {
|
~this() {
|
||||||
|
if(suppressDestruction) return;
|
||||||
impl.dispose();
|
impl.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8162,8 +8189,14 @@ class Sprite : CapableOfBeingDrawnUpon {
|
||||||
return ScreenPainter(this, handle);
|
return ScreenPainter(this, handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Be warned: this can be a very slow operation
|
/++
|
||||||
/// FIXME NOT IMPLEMENTED
|
Copies the sprite's current state into a [TrueColorImage].
|
||||||
|
|
||||||
|
Be warned: this can be a very slow operation
|
||||||
|
|
||||||
|
History:
|
||||||
|
Actually implemented on March 14, 2021
|
||||||
|
+/
|
||||||
TrueColorImage takeScreenshot() {
|
TrueColorImage takeScreenshot() {
|
||||||
return trueColorImageFromNativeHandle(handle, width, height);
|
return trueColorImageFromNativeHandle(handle, width, height);
|
||||||
}
|
}
|
||||||
|
@ -8301,6 +8334,8 @@ class Sprite : CapableOfBeingDrawnUpon {
|
||||||
}
|
}
|
||||||
|
|
||||||
/++
|
/++
|
||||||
|
NOT IMPLEMENTED
|
||||||
|
|
||||||
A display-stored image optimized for relatively quick drawing, like
|
A display-stored image optimized for relatively quick drawing, like
|
||||||
[Sprite], but this one supports alpha channel blending and does NOT
|
[Sprite], but this one supports alpha channel blending and does NOT
|
||||||
support direct drawing upon it with a [ScreenPainter].
|
support direct drawing upon it with a [ScreenPainter].
|
||||||
|
@ -8312,7 +8347,7 @@ class Sprite : CapableOfBeingDrawnUpon {
|
||||||
almost everywhere though.
|
almost everywhere though.
|
||||||
|
|
||||||
History:
|
History:
|
||||||
Added November 14, 2020.
|
Added November 14, 2020 but NOT ACTUALLY IMPLEMENTED
|
||||||
+/
|
+/
|
||||||
version(none)
|
version(none)
|
||||||
class AlphaSprite {
|
class AlphaSprite {
|
||||||
|
@ -9513,7 +9548,7 @@ version(Windows) {
|
||||||
DeleteDC(hdc);
|
DeleteDC(hdc);
|
||||||
|
|
||||||
if(window.paintingFinishedDg !is null)
|
if(window.paintingFinishedDg !is null)
|
||||||
window.paintingFinishedDg();
|
window.paintingFinishedDg()();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool windowDc;
|
bool windowDc;
|
||||||
|
@ -10698,7 +10733,7 @@ version(X11) {
|
||||||
XFlush(display);
|
XFlush(display);
|
||||||
|
|
||||||
if(window.paintingFinishedDg !is null)
|
if(window.paintingFinishedDg !is null)
|
||||||
window.paintingFinishedDg();
|
window.paintingFinishedDg()();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool backgroundIsNotTransparent = true;
|
bool backgroundIsNotTransparent = true;
|
||||||
|
@ -13616,6 +13651,9 @@ extern(C) nothrow @nogc {
|
||||||
uint /* height */
|
uint /* height */
|
||||||
);
|
);
|
||||||
|
|
||||||
|
XImage *XGetImage(Display *display, Drawable d, int x, int y, uint width, uint height, c_ulong plane_mask, int format);
|
||||||
|
|
||||||
|
|
||||||
int XDestroyWindow(
|
int XDestroyWindow(
|
||||||
Display* /* display */,
|
Display* /* display */,
|
||||||
Window /* w */
|
Window /* w */
|
||||||
|
|
Loading…
Reference in New Issue