Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Button : TaggedObject, Drawable, Updatable {
- vec2i pos; string text;
- vec2i to;
- float delegate(TransitionMode) dg;
- vec4f fill;
- void delegate() onClick;
- void init(string s, vec2i p, void delegate() dg) {
- (text, pos, onClick) = (s, p, dg);
- this.dg = genTransition(0, 1, transferTime => 0.3);
- fill = vec4f(0.2, 0.4, 0.8, 0.7);
- }
- string ident() return "Button";
- Tag offers(string s) {
- if s == "Button" || s == "Drawable" || s == "Updatable" return this;
- return super.offers s;
- }
- void draw() {
- auto leaf = parseText text;
- auto h = printAt(overlay, pos, leaf, width => 90, radius => 7, fill => fill);
- to = pos + vec2i(90, h);
- }
- void update(void delegate(Drawable) addDrawable) {
- bool inside, active;
- if (mouse-pos.(x >= pos.x && y >= pos.y && x < to.x && y < to.y)) {
- inside = true;
- if mouse-released onClick();
- if mouse-pressed active = true;
- }
- auto factor = dg([TransitionMode.Down, TransitionMode.Up][inside]);
- fill = vec4f(0.2, 0.4, 0.8, 0.6) * (1 - factor)
- + vec4f(0.2, 0.4, 0.8, [float:0.8, 1][active]) * factor;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement