diff --git a/color.d b/color.d index 9c2504d..1396f88 100644 --- a/color.d +++ b/color.d @@ -823,6 +823,9 @@ interface MemoryImage { /// Set image pixel. void setPixel(int x, int y, in Color clr); + /// Returns a copy of the image + MemoryImage clone() const; + /// Load image from file. This will import arsd.image to do the actual work, and cost nothing if you don't use it. static MemoryImage fromImage(T : const(char)[]) (T filename) @trusted { static if (__traits(compiles, (){import arsd.image;})) { @@ -857,6 +860,15 @@ class IndexedImage : MemoryImage { return _height; } + /// . + override IndexedImage clone() const { + auto n = new IndexedImage(width, height); + n.data[] = this.data[]; // the data member is already there, so array copy + n.palette = this.palette.dup; // and here we need to allocate too, so dup + n.hasAlpha = this.hasAlpha; + return n; + } + override Color getPixel(int x, int y) const @trusted { if (x >= 0 && y >= 0 && x < _width && y < _height) { uint pos = y*_width+x; @@ -976,6 +988,13 @@ class TrueColorImage : MemoryImage { int _width; int _height; + /// . + override TrueColorImage clone() const { + auto n = new TrueColorImage(width, height); + n.imageData.bytes[] = this.imageData.bytes[]; // copy into existing array ctor allocated + return n; + } + /// . override int width() const { return _width; } ///. diff --git a/minigui.d b/minigui.d index 141cda3..813e6e2 100644 --- a/minigui.d +++ b/minigui.d @@ -5158,6 +5158,14 @@ int[2] getChildPositionRelativeToParentHwnd(Widget c) nothrow { class ImageBox : Widget { private MemoryImage image_; + /// + public void setImage(MemoryImage image){ + this.image_ = image; + if(this.parentWindow && this.parentWindow.win) + sprite = new Sprite(this.parentWindow.win, Image.fromMemoryImage(image_)); + redraw(); + } + /// How to fit the image in the box if they aren't an exact match in size? enum HowToFit { center, /// centers the image, cropping around all the edges as needed @@ -5181,7 +5189,7 @@ class ImageBox : Widget { } private void updateSprite() { - if(this.parentWindow && this.parentWindow.win) + if(sprite is null && this.parentWindow && this.parentWindow.win) sprite = new Sprite(this.parentWindow.win, Image.fromMemoryImage(image_)); }