tentone 5 năm trước cách đây
mục cha
commit
844fc22e57

+ 20 - 5
source/objects/style/LinearGradientStyle.js

@@ -14,7 +14,20 @@ import {GradientStyle} from "./GradientStyle";
 function LinearGradientStyle()
 {
     GradientStyle.call(this);
-    // TODO <ADD CODE HERE>
+
+    /**
+     * The coordinates of the starting point of the gradient.
+     *
+     * @type {Vector2}
+     */
+    this.start = new Vector2(0, 0);
+
+    /**
+     * The coordinates of the ending point of the gradient.
+     *
+     * @type {Vector2}
+     */
+    this.end = new Vector2(0, 0);
 }
 
 LinearGradientStyle.prototype = Object.create(GradientStyle.prototype);
@@ -22,14 +35,15 @@ Style.register(LinearGradientStyle, "LinearGradient");
 
 LinearGradientStyle.prototype.get = function(context)
 {
-    // TODO <ADD CODE HERE>
-    // return context.createLinearGradient();
+    return context.createLinearGradient(this.start.x, this.start.y, this.end.x, this.end.y);
 };
 
 LinearGradientStyle.prototype.serialize = function ()
 {
     return {
-        type: "LinearGradient"
+        type: "LinearGradient",
+        start: this.start.toArray(),
+        end: this.end.toArray()
     };
 };
 
@@ -48,7 +62,8 @@ LinearGradientStyle.prototype.parse = function (data)
 {
     GradientStyle.prototype.parse.call(this, data);
 
-    // TODO <ADD CODE HERE>
+    this.start.fromArray(data.start);
+    this.end.fromArray(data.end);
 };
 
 export {LinearGradientStyle};

+ 5 - 1
source/objects/style/PatternStyle.js

@@ -56,7 +56,11 @@ PatternStyle.prototype.setTransform = function(transform)
 
 PatternStyle.prototype.get = function(context)
 {
-    return context.createPattern(this.source, this.repetition);
+    var style = context.createPattern(this.source, this.repetition);
+
+    // style.setTransform(this.transform);
+
+    return style;
 };
 
 PatternStyle.prototype.serialize = function ()

+ 18 - 1
source/objects/style/Style.js

@@ -5,7 +5,24 @@
  *
  * @class
  */
-function Style() {}
+function Style()
+{
+    /**
+     * Cached style object pre-generated from previous calls. To avoid regenerating the same style object every cycle.
+     *
+     * @type {string | CanvasGradient | CanvasPattern}
+     */
+    this.cache = null;
+    // TODO <USE THIS>
+
+    /**
+     * Indicates if the style object needs to be updated, should be used after applying changed to the style in order to generate a new object.
+     *
+     * @type {boolean}
+     */
+    this.needsUpdate = true;
+    // TODO <USE THIS>
+}
 
 /**
  * Get generated style object from style data and the drawing context.