Skip to content
Permalink
Browse files

updates

  • Loading branch information
adamdruppe committed Apr 13, 2017
1 parent 1dd38e2 commit 3089c455b68b988210df2f33730921ce950f6c6a
Showing with 175 additions and 38 deletions.
  1. +85 −7 color.d
  2. +2 −1 comment.d
  3. +3 −0 doc2.d
  4. +38 −2 dom.d
  5. +47 −28 jsvar.d
92 color.d
@@ -154,11 +154,7 @@ struct Color {
/// Construct a color with the given values. They should be in range 0 <= x <= 255, where 255 is maximum intensity and 0 is minimum intensity.
nothrow pure @nogc
this(int red, int green, int blue, int alpha = 255) {
// workaround dmd bug 10937
if(__ctfe)
this.components[0] = cast(ubyte) red;
else
this.r = cast(ubyte) red;
this.r = cast(ubyte) red;
this.g = cast(ubyte) green;
this.b = cast(ubyte) blue;
this.a = cast(ubyte) alpha;
@@ -172,6 +168,9 @@ struct Color {
static Color white() { return Color(255, 255, 255); }
/// Ditto
nothrow pure @nogc
static Color gray() { return Color(128, 128, 128); }
/// Ditto
nothrow pure @nogc
static Color black() { return Color(0, 0, 0); }
/// Ditto
nothrow pure @nogc
@@ -191,14 +190,17 @@ struct Color {
/// Ditto
nothrow pure @nogc
static Color purple() { return Color(255, 0, 255); }
/// Ditto
nothrow pure @nogc
static Color brown() { return Color(128, 64, 0); }

/*
ubyte[4] toRgbaArray() {
return [r,g,b,a];
}
*/

/// Return black-and-white color
/// Return black-and-white color
Color toBW() () {
int intens = cast(int)(0.2126*r+0.7152*g+0.0722*b);
if (intens < 0) intens = 0; else if (intens > 255) intens = 255;
@@ -1256,6 +1258,16 @@ void floydSteinbergDither(IndexedImage img, in TrueColorImage original) {
struct Point {
int x; ///
int y; ///

pure const nothrow @safe:

Point opBinary(string op)(in Point rhs) {
return Point(mixin("x" ~ op ~ "rhs.x"), mixin("y" ~ op ~ "rhs.y"));
}

Point opBinary(string op)(int rhs) {
return Point(mixin("x" ~ op ~ "rhs"), mixin("y" ~ op ~ "rhs"));
}
}

///
@@ -1270,6 +1282,67 @@ struct Rectangle {
int top; ///
int right; ///
int bottom; ///

pure const nothrow @safe:

///
this(int left, int top, int right, int bottom) {
this.left = left;
this.top = top;
this.right = right;
this.bottom = bottom;
}

///
this(in Point upperLeft, in Point lowerRight) {
this(upperLeft.x, upperLeft.y, lowerRight.x, lowerRight.y);
}

///
this(in Point upperLeft, in Size size) {
this(upperLeft.x, upperLeft.y, upperLeft.x + size.width, upperLeft.y + size.height);
}

///
@property Point upperLeft() {
return Point(left, top);
}

///
@property Point lowerRight() {
return Point(right, bottom);
}

///
@property Size size() {
return Size(width, height);
}

///
@property int width() {
return right - left;
}

///
@property int height() {
return bottom - top;
}

/// Returns true if this rectangle entirely contains the other
bool contains(in Rectangle r) {
return contains(r.upperLeft) && contains(r.lowerRight);
}

/// ditto
bool contains(in Point p) {
return (p.x >= left && p.y < right && p.y >= top && p.y < bottom);
}

/// Returns true of the two rectangles at any point overlap
bool overlaps(in Rectangle r) {
// the -1 in here are because right and top are exclusive
return !((right-1) < r.left || (r.right-1) < left || (bottom-1) < r.top || (r.bottom-1) < top);
}
}

/++
@@ -1289,14 +1362,17 @@ struct Rectangle {
void floodFill(T)(
T[] what, int width, int height, // the canvas to inspect
T target, T replacement, // fill params
int x, int y, bool delegate(int x, int y) additionalCheck) // the node
int x, int y, bool delegate(int x, int y) @safe additionalCheck) // the node
{
T node = what[y * width + x];

if(target == replacement) return;

if(node != target) return;

if(additionalCheck is null)
additionalCheck = (int, int) => true;

if(!additionalCheck(x, y))
return;

@@ -1319,3 +1395,5 @@ void floodFill(T)(
x, y + 1, additionalCheck);
}

// for scripting, so you can tag it without strictly needing to import arsd.jsvar
enum arsd_jsvar_compatible = "arsd_jsvar_compatible";
@@ -1496,7 +1496,7 @@ static this() {
"SCRIPT" : "",

// Useless crap that should just be replaced
"SUBMODULE" : `<a href="$(FULLY_QUALIFIED_NAME).$0.html">$0</a>`,
"SUBMODULE" : `<a href="$(FULLY_QUALIFIED_NAME).$2.html">$1</a>`,
"SHORTXREF" : `<a href="std.$1.$2.html">$2</a>`,
"SHORTXREF_PACK" : `<a href="std.$1.$2.$3.html">$3</a>`,
"XREF" : `<a href="std.$1.$2.html">std.$1.$2</a>`,
@@ -1565,6 +1565,7 @@ static this() {
"XREF" : 2,
"CXREF" : 2,
"SHORTXREF" : 2,
"SUBMODULE" : 2,
"SHORTXREF_PACK" : 3,
"XREF_PACK" : 3,
"MREF" : 1,
3 doc2.d
@@ -1075,6 +1075,9 @@ abstract class Decl {
return protection == tok!"private";
}

// FIXME: isFinal and isVirtual
// FIXME: it would be nice to inherit documentation from interfaces too.

bool isProperty() {
foreach (a; attributes) {
if(a.attr && a.attr.atAttribute && a.attr.atAttribute.identifier.text == "property")
40 dom.d
@@ -6904,12 +6904,48 @@ void fillForm(T)(Form form, T obj, string name) {
fillData((k, v) => form.setValue(k, v), obj, name);
}


/+
Syntax:
Tag: tagname#id.class
Tree: Tag(Children, comma, separated...)
Children: Tee or Variable
Variable: $varname with optional |funcname following.
If a variable has a tree after it, it breaks the variable down:
* if array, foreach it does the tree
* if struct, it breaks down the member variables
stolen from georgy on irc, see: https://github.com/georgy7/stringplate
+/
struct Stringplate {
/++
+/
this(string s) {

}

/++
+/
Element expand(T...)(T vars) {
return null;
}
}
///
unittest {
auto stringplate = Stringplate("#bar(.foo($foo), .baz($baz))");
assert(stringplate.expand.innerHTML == `<div id="bar"><div class="foo">$foo</div><div class="baz">$baz</div></div>`);
}

/*
Copyright: Adam D. Ruppe, 2010 - 2016
Copyright: Adam D. Ruppe, 2010 - 2017
License: <a href="http://www.boost.org/LICENSE_1_0.txt">Boost License 1.0</a>.
Authors: Adam D. Ruppe, with contributions by Nick Sabalausky, Trass3r, and ketmar among others
Copyright Adam D. Ruppe 2010-2016.
Copyright Adam D. Ruppe 2010-2017.
Distributed under the Boost Software License, Version 1.0.
(See accompanying file LICENSE_1_0.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
75 jsvar.d
@@ -72,7 +72,7 @@ import std.conv;
import std.json;

// uda for wrapping classes
enum Scriptable;
enum scriptable = "arsd_jsvar_compatible";

/*
PrototypeObject FIXME:
@@ -836,25 +836,29 @@ struct var {
if(no !is null)
return no;
}
}

// failing that, generic struct or class getting: try to fill in the fields by name
T t;
bool initialized = true;
static if(is(T == class)) {
static if(__traits(compiles, new T()))
t = new T();
else
initialized = false;
}
// FIXME: this is kinda weird.
return null;
} else {

// failing that, generic struct or class getting: try to fill in the fields by name
T t;
bool initialized = true;
static if(is(T == class)) {
static if(__traits(compiles, new T()))
t = new T();
else
initialized = false;
}

if(initialized)
foreach(i, a; t.tupleof) {
cast(Unqual!(typeof((a)))) t.tupleof[i] = this[t.tupleof[i].stringof[2..$]].get!(typeof(a));
}

return t;
if(initialized)
foreach(i, a; t.tupleof) {
cast(Unqual!(typeof((a)))) t.tupleof[i] = this[t.tupleof[i].stringof[2..$]].get!(typeof(a));
}

return t;
}
} else static if(isSomeString!T) {
if(this._object !is null)
return this._object.toString();
@@ -1664,6 +1668,7 @@ template helper(alias T) { alias helper = T; }
///
/// That may be done automatically with opAssign in the future.
WrappedNativeObject wrapNativeObject(Class)(Class obj) if(is(Class == class)) {
import std.meta;
return new class WrappedNativeObject {
override Object getObject() {
return obj;
@@ -1674,25 +1679,39 @@ WrappedNativeObject wrapNativeObject(Class)(Class obj) if(is(Class == class)) {
// wrap the other methods
// and wrap members as scriptable properties

foreach(memberName; __traits(allMembers, Class)) {
static if(is(typeof(__traits(getMember, obj, memberName)) type))
static if(is(typeof(__traits(getMember, obj, memberName)))) {
static if(is(type == function)) {
_properties[memberName] = &__traits(getMember, obj, memberName);
} else {
// if it has a type but is not a function, it is prolly a member
_properties[memberName] = new PropertyPrototype(
() => var(__traits(getMember, obj, memberName)),
(var v) {
__traits(getMember, obj, memberName) = v.get!(type);
});
foreach(memberName; __traits(allMembers, Class)) static if(is(typeof(__traits(getMember, obj, memberName)) type)) {
static if(is(type == function)) {
foreach(idx, overload; AliasSeq!(__traits(getOverloads, obj, memberName))) static if(.isScriptable!(__traits(getAttributes, overload))()) {
auto helper = &__traits(getOverloads, obj, memberName)[idx];
_properties[memberName] = (Parameters!helper args) {
return __traits(getOverloads, obj, memberName)[idx](args);
};
}
} else {
static if(.isScriptable!(__traits(getAttributes, __traits(getMember, Class, memberName)))())
// if it has a type but is not a function, it is prolly a member
_properties[memberName] = new PropertyPrototype(
() => var(__traits(getMember, obj, memberName)),
(var v) {
__traits(getMember, obj, memberName) = v.get!(type);
});
}
}
}
};
}

bool isScriptable(attributes...)() {
foreach(attribute; attributes) {
static if(is(typeof(attribute) == string)) {
static if(attribute == scriptable) {
return true;
}
}
}
return false;
}

/// Wraps a struct by reference. The pointer is stored - be sure the struct doesn't get freed or go out of scope!
///
/// BTW: structs by value can be put in vars with var.opAssign and var.get. It will generate an object with the same fields. The difference is changes to the jsvar won't be reflected in the original struct and native methods won't work if you do it that way.

0 comments on commit 3089c45

Please sign in to comment.
You can’t perform that action at this time.