Last active
February 14, 2018 16:42
-
-
Save thedeemon/9d05b7e7315ba2f4a54cc11b79dabaa0 to your computer and use it in GitHub Desktop.
dlangui motion picture
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module motionpicture; | |
import std.stdio, std.algorithm : min; | |
import dlangui, dlangui.widgets.metadata; | |
class MotionPicture : ImageWidget { | |
ColorDrawBuf cdbuf; | |
int W = 16*30, H = 9*30; //current size | |
this() { | |
setSize(W, H, true); | |
} | |
override void measure(int parentWidth, int parentHeight) { | |
DrawableRef img = drawable; | |
int w = 0; | |
int h = 0; | |
if (!img.isNull) { | |
w = showW; | |
h = showH; | |
if (fitImage) { | |
auto mgs = margins; | |
auto sz = imgSizeScaled(parentWidth, parentHeight - mgs.top - mgs.bottom); | |
w = sz.x; h = sz.y + mgs.top + mgs.bottom; | |
} | |
} | |
measuredContent(parentWidth, parentHeight, w, h); | |
} | |
override void onDraw(DrawBuf buf) { | |
if (visibility != Visibility.Visible) | |
return; | |
super.onDraw(buf); | |
Rect rc = _pos; | |
applyMargins(rc); | |
auto saver = ClipRectSaver(buf, rc, alpha); | |
applyPadding(rc); | |
DrawableRef img = drawable; | |
if (!img.isNull) { | |
auto sz = Point(showW, showH); | |
if (fitImage) | |
sz = imgSizeScaled(rc.width, rc.height); | |
applyAlign(rc, sz, Align.HCenter, valign); | |
uint st = state; | |
img.drawTo(buf, rc, st); | |
} | |
} | |
void setSize(int w, int h, bool draw = false) { | |
if (cdbuf is null) { | |
stderr.writeln("new cdbuf"); | |
cdbuf = new ColorDrawBuf(w, h); | |
} | |
else { | |
assumeSafeAppend(cdbuf._buf); | |
stderr.writefln("_buf capacity=%d length=%d start=%X", cdbuf._buf.capacity, cdbuf._buf.length, cdbuf._buf.ptr); | |
cdbuf.resize(w, h); | |
} | |
W = w; H = h; | |
if (draw) fillBytes(0); | |
Ref!DrawBuf r = cdbuf; | |
this.drawable = new ImageDrawable(r); | |
this.margins = 0;// Rect(0, 10, 0, 10);//10 | |
} | |
}//class MotionPicture |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment