on master help sign in
Minor bug fixes in RTS and libraries.
commitd31acc5c9d1f9f2f78398d75818306f17a29e54f authorevancz <info@elm-lang.org> dateTue 21 May 2013, 10:03 (13 years ago) parent1f1187c
6 files changed+25−17
libraries/Graphics/Collage.elm+7−7 libraries/Native/Matrix2D.js+8−1 libraries/Native/Prelude.js+1−1 libraries/Native/Signal/Touch.js+1−1 runtime/Init.js+5−4 runtime/Render/Collage.js+3−3
libraries/Graphics/Collage.elm+7−7
@@ -7,7 +7,7 @@ import Either
77import Native.Matrix2D as Matrix
88import Native.Graphics.Collage as N
99import Graphics.Element
10−import Color as Color
10+import Color
1111
1212type Form = {
1313 theta : Float,
@@ -53,7 +53,7 @@ defaultLine = {
5353 cap = Flat,
5454 join = Sharp 10,
5555 dashing = [],
56− dashOffset = 0,
56+ dashOffset = 0
5757 }
5858
5959-- Create a solid line style with a given color.
@@ -73,11 +73,11 @@ data BasicForm
7373 | FShape (Either LineStyle FillStyle) Shape
7474 | FImage Int Int (Int,Int) String
7575 | FElement Element
76− | FGroup Matrix [Form]
76+ | FGroup Matrix2D [Form]
7777
7878form f = { theta = 0, scale = 1, x = 0, y = 0, form = f }
7979
80−fill style shape = form (FShape (Right style) shape)
80+fill style shape = form (FShape (Either.Right style) shape)
8181
8282-- Create a filled in shape.
8383filled : Color -> Shape -> Form
@@ -94,7 +94,7 @@ gradient grad shape = fill (Gradient grad) shape
9494
9595-- Outline a shape with a given line style.
9696outlined : LineStyle -> Shape -> Form
97−outlined style shape = form (FShape (Left style) shape)
97+outlined style shape = form (FShape (Either.Left style) shape)
9898
9999-- Trace a path with a given line style.
100100traced : LineStyle -> Path -> Form
@@ -186,7 +186,7 @@ oval w h =
186186 hw = w/2
187187 hh = h/2
188188 f i = (hw * Math.cos (t*i), hh * Math.sin (t*i))
189− in map f [0..n-1]
189+ in List.map f [0..n-1]
190190
191191-- A circle with a given radius.
192192circle : Number a -> Shape
@@ -202,4 +202,4 @@ ngon n r =
202202 let m = toFloat n
203203 t = 2 * Math.PI / m
204204 f i = ( r * Math.cos (t*i), r * Math.sin (t*i) )
205− in map f [0..n-1]
205+ in List.map f [0..n-1]
libraries/Native/Matrix2D.js+8−1
@@ -58,7 +58,14 @@ Elm.Native.Matrix2D = function(elm) {
5858 }
5959 */
6060 function multiply(m, n) {
61− return transform(m[0], m[3], m[1], m[4], m[2], m[5], n);
61+ var m11 = m[0], m12 = m[1], m21 = m[3], m22 = m[4], mdx = m[2], mdy = m[5];
62+ var n11 = n[0], n12 = n[1], n21 = n[3], n22 = n[4], ndx = n[2], ndy = n[5];
63+ return new A([m11*n11 + m12*n21,
64+ m11*n12 + m12*n22,
65+ m11*ndx + m12*ndy + mdx,
66+ m21*n11 + m22*n21,
67+ m21*n12 + m22*n22,
68+ m21*ndx + m22*ndy + mdy]);
6269 }
6370
6471 return elm.Native.Matrix2D = {
libraries/Native/Prelude.js+1−1
@@ -67,7 +67,7 @@ Elm.Native.Prelude = function(elm) {
6767 var prelude = {
6868 div:F2(div),
6969 rem:F2(rem),
70− mod:F2(mod),
70+ mod:mod,
7171
7272 pi:Math.PI,
7373 e:Math.e,
libraries/Native/Signal/Touch.js+1−1
@@ -101,8 +101,8 @@ Elm.Native.Touch = function(elm) {
101101 node.addEventListener("mousedown", function(e) {
102102 node.addEventListener("mousemove", move);
103103 e.identifier = mouseID;
104− root.value.push(touch(e));
105104 start(e);
105+ root.value.push(touch(e));
106106 elm.notify(root.id, root.value);
107107 });
108108 node.addEventListener("mouseup", function(e) {
runtime/Init.js+5−4
@@ -8,7 +8,9 @@ Elm.fullscreen = function(module) {
88 style.innerHTML = "html,head,body { padding:0; margin:0; }" +
99 "body { font-family: calibri, helvetica, arial, sans-serif; }";
1010 document.head.appendChild(style);
11− return init(ElmRuntime.Display.FULLSCREEN, document.body, module);
11+ var container = document.createElement('div');
12+ document.body.appendChild(container);
13+ return init(ElmRuntime.Display.FULLSCREEN, container, module);
1214};
1315
1416Elm.byId = function(id, module) {
@@ -92,15 +94,14 @@ function init(display, container, module) {
9294 inputs = ElmRuntime.filterDeadInputs(inputs);
9395
9496 // Add the visualModel to the DOM
95− var renderNode = Render.render(visualModel)
96− container.appendChild(renderNode);
97+ container.appendChild(Render.render(visualModel));
9798 if (elm.Native.Window) elm.Native.Window.resizeIfNeeded();
9899
99100 // set up updates so that the DOM is adjusted as necessary.
100101 var update = Render.update;
101102 function domUpdate(value) {
102103 ElmRuntime.draw(function(_) {
103− update(renderNode, visualModel, value);
104+ update(container.firstChild, visualModel, value);
104105 visualModel = value;
105106 if (elm.Native.Window) elm.Native.Window.resizeIfNeeded();
106107 });
runtime/Render/Collage.js+3−3
@@ -86,11 +86,11 @@ function gradient(ctx, grad) {
8686 var stops = [];
8787 if (grad.ctor === 'Linear') {
8888 var p0 = grad._0, p1 = grad._1;
89− g = ctx.createLinearGradient(p0._0, p0._1, p1._0, p1._1);
89+ g = ctx.createLinearGradient(p0._0, -p0._1, p1._0, -p1._1);
9090 stops = fromList(grad._2);
9191 } else {
9292 var p0 = grad._0, p2 = grad._2;
93− g = ctx.createRadialGradient(p0._0, p0._1, grad._1, p2._0, p2._1, grad._3);
93+ g = ctx.createRadialGradient(p0._0, -p0._1, grad._1, p2._0, -p2._1, grad._3);
9494 stops = fromList(grad._4);
9595 }
9696 var len = stops.length;
@@ -158,7 +158,7 @@ function formToMatrix(form) {
158158
159159 var theta = form.theta
160160 if (theta !== 0)
161− matrix = A2( Matrix.multiply, Matrix.rotation(theta), matrix );
161+ matrix = A2( Matrix.multiply, matrix, Matrix.rotation(theta) );
162162
163163 return matrix;
164164}