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.tools; 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 Document 29 { 30 public RTree!(Line, Cuboid!2, 127, 64) data; 31 32 public this() 33 { 34 this.data = new RTree!(Line, Cuboid!2, 127, 64)(); 35 } 36 37 public void redraw(Square area, Draw target) 38 { 39 foreach(Line line; this.data.query(area)) 40 { 41 target.drawLine(line.a, line.b, line.size, line.color); 42 } 43 } 44 } 45 46 public interface Tool 47 { 48 void cursorDown(Document doc, Point2D point, CURSOR_TYPE cursor, double pressure, string cursorID); 49 void cursorContin(Document doc, Point2D point, CURSOR_TYPE cursor, double pressure, string cursorID); 50 void cursorUp(Document doc, Point2D point, CURSOR_TYPE cursor, double pressure, string cursorID); 51 } 52 53 private class VoidTool : Tool 54 { 55 void cursorDown(Document doc, Point2D point, CURSOR_TYPE cursor, double pressure, string cursorID) {} 56 void cursorContin(Document doc, Point2D point, CURSOR_TYPE cursor, double pressure, string cursorID) {} 57 void cursorUp(Document doc, Point2D point, CURSOR_TYPE cursor, double pressure, string cursorID) {} 58 } 59 60 public __gshared Tool voidTool = new VoidTool(); 61 62 public mixin template CURSOR_FROM_TO() 63 { 64 private Point2D __cursorPosition; 65 private double __cursorPressure; 66 67 public void cursorDown(Document doc, Point2D point, CURSOR_TYPE cursor, double pressure, string cursorID) 68 { 69 this.__cursorPosition = point; 70 this.__cursorPressure = pressure; 71 } 72 public void cursorContin(Document doc, Point2D point, CURSOR_TYPE cursor, double pressure, string cursorID) 73 { 74 this._cursorFromTo(doc, this.__cursorPosition, this.__cursorPressure, point, pressure, cursor, cursorID); 75 this.__cursorPosition = point; 76 this.__cursorPressure = pressure; 77 } 78 public void cursorUp(Document doc, Point2D point, CURSOR_TYPE cursor, double pressure, string cursorID) 79 { 80 this._cursorFromTo(doc, this.__cursorPosition, this.__cursorPressure, point, pressure, cursor, cursorID); 81 } 82 private void _cursorFromTo(Document doc, Point2D from, double fromPressure, Point2D to, double toPressure, CURSOR_TYPE cursor, string cursorID); 83 }