MDL-42023 assign: Edit PDF plugin - Jerome's contributions
[moodle.git] / mod / assign / feedback / editpdf / yui / src / editor / js / annotationrectangle.js
1 // This file is part of Moodle - http://moodle.org/
2 //
3 // Moodle is free software: you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation, either version 3 of the License, or
6 // (at your option) any later version.
7 //
8 // Moodle is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 // GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
16 /**
17  * Class representing a rectangle.
18  *
19  * @namespace M.assignfeedback_editpdf
20  * @class annotationrectangle
21  * @extends annotation
22  * @module moodle-assignfeedback_editpdf-editor
23  */
24 ANNOTATIONRECTANGLE = function(config) {
25     ANNOTATIONRECTANGLE.superclass.constructor.apply(this, [config]);
26 };
28 ANNOTATIONRECTANGLE.NAME = "annotationrectangle";
29 ANNOTATIONRECTANGLE.ATTRS = {};
31 Y.extend(ANNOTATIONRECTANGLE, M.assignfeedback_editpdf.annotation, {
32     /**
33      * Draw a rectangle annotation
34      * @protected
35      * @method draw
36      * @return M.assignfeedback_editpdf.drawable
37      */
38     draw : function() {
39         var drawable,
40             shape;
42         drawable = new M.assignfeedback_editpdf.drawable(this.editor);
44         bounds = new M.assignfeedback_editpdf.rect();
45         bounds.bound([new M.assignfeedback_editpdf.point(this.x, this.y),
46                       new M.assignfeedback_editpdf.point(this.endx, this.endy)]);
48         shape = this.editor.graphic.addShape({
49             type: Y.Rect,
50             width: bounds.width,
51             height: bounds.height,
52             stroke: {
53                weight: STROKEWEIGHT,
54                color: ANNOTATIONCOLOUR[this.colour]
55             },
56             x: bounds.x,
57             y: bounds.y
58         });
59         drawable.shapes.push(shape);
60         this.drawable = drawable;
62         return ANNOTATIONRECTANGLE.superclass.draw.apply(this);
63     },
65     /**
66      * Draw the in progress edit.
67      *
68      * @public
69      * @method draw_current_edit
70      * @param M.assignfeedback_editpdf.edit edit
71      */
72     draw_current_edit : function(edit) {
73         var drawable = new M.assignfeedback_editpdf.drawable(this.editor),
74             shape,
75             bounds;
77         bounds = new M.assignfeedback_editpdf.rect();
78         bounds.bound([new M.assignfeedback_editpdf.point(edit.start.x, edit.start.y),
79                       new M.assignfeedback_editpdf.point(edit.end.x, edit.end.y)]);
81         shape = this.editor.graphic.addShape({
82             type: Y.Rect,
83             width: bounds.width,
84             height: bounds.height,
85             stroke: {
86                weight: STROKEWEIGHT,
87                color: ANNOTATIONCOLOUR[edit.annotationcolour]
88             },
89             x: bounds.x,
90             y: bounds.y
91         });
93         drawable.shapes.push(shape);
95         return drawable;
96     }
97 });
99 M.assignfeedback_editpdf = M.assignfeedback_editpdf || {};
100 M.assignfeedback_editpdf.annotationrectangle = ANNOTATIONRECTANGLE;