1 /* DrawOfPages: Take notes with touchscreen input. 2 * Copyright (C) 2017 Marko Semet(Marko10_000) 3 * 4 * This program is free software: you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation, either version 3 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program. If not, see <https://www.gnu.org/licenses/>. 16 */ 17 module drawofpages.elements; 18 19 private 20 { 21 import drawofpages.draw; 22 import drawofpages.elements.basetypes; 23 import drawofpages.gui; 24 import structuresd.dimension; 25 import structuresd.dimension.rtree; 26 } 27 28 public class Interaction : GuiInteraction 29 { 30 private Point2D c; 31 private Draw draw; 32 private RTree!(Line, Cuboid!2, 127, 64) data; 33 34 public this(Draw draw) 35 { 36 this.draw = draw; 37 this.data = new RTree!(Line, Cuboid!2, 127, 64); 38 } 39 40 public void down(Point2D point, CURSOR_TYPE cursor, double pressure, string cursorID) 41 { 42 this.c = point; 43 } 44 public void contin(Point2D point, CURSOR_TYPE cursor, double pressure, string cursorID) 45 { 46 this.draw.drawLine(this.c, point, 2, Color.BLUE); 47 this.data.insert(Line(Point!2([this.c.dims[0], this.c.dims[1]]), Point!2([point.dims[0], point.dims[1]]), 2)); 48 this.draw.redraw(); 49 this.c = point; 50 } 51 public void up(Point2D point, CURSOR_TYPE cursor, double pressure, string cursorID) 52 { 53 this.draw.drawLine(this.c, point, 2, Color.BLUE); 54 this.data.insert(Line(Point!2([this.c.dims[0], this.c.dims[1]]), Point!2([point.dims[0], point.dims[1]]), 2)); 55 this.draw.redraw(); 56 } 57 public void redraw(Square area, Draw target) 58 { 59 foreach(Line line; this.data.query(area)) 60 { 61 target.drawLine(line.a, line.b, line.size, Color.RED); 62 } 63 } 64 }