1 /* DrawOfPages: Take notes with touchscreen input.
2  * Copyright (C) 2019  Marko Semet
3  * 
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU Affero 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 Affero General Public License for more details.
13  * 
14  * You should have received a copy of the GNU Affero General Public License
15  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
16  */
17 module dop.processing.mainsystem;
18 
19 private
20 {
21     import dop.structures.base;
22 }
23 
24 public
25 {
26     /++
27      + Interface for the main system to communicate with platform implementation
28      +/
29     interface BaseSystemCallbacks
30     {
31         /++
32          + Callback when the color was set.
33          + Params:
34          +     color = The new color
35          +/
36         shared void setCurrentColor(ColorRGBA color);
37         /++
38          + Callback when the brush size was set.
39          + Params:
40          +     size = The new brush size
41          +/
42         shared void setCurrentSize(float size);
43 
44         /++
45          + Quit the application
46          +/
47         shared void quit();
48     }
49 
50     /++
51      + Main system that manage drawing
52      +/
53     class MainSystem
54     {
55         private
56         {
57             shared BaseSystemCallbacks __callbacks;
58 
59             ColorRGBA __currentColor;
60             float __currentSize = 1;
61 
62             this() {}
63         }
64         public
65         {
66             /++
67              + Creates a new main system
68              + Params:
69              +     callbaks = Callbacks to the base system implementation
70              +/
71             shared this(shared BaseSystemCallbacks callbacks)
72             in
73             {
74                 assert(callbacks !is null);
75             }
76             do
77             {
78                 this.__callbacks = callbacks;
79             }
80 
81             /++
82              + Finialize the initalization of the programm
83              +/
84             shared void finalizeInit()
85             {
86                 // Inform frontend of the current configuration
87                 this.__callbacks.setCurrentColor(this.__currentColor);
88                 this.__callbacks.setCurrentSize(this.__currentSize);
89             }
90 
91             /++
92              + Getter for the current color
93              + Returns: The current color
94              +/
95             @property
96             shared ColorRGBA currentColor()
97             {
98                 return this.__currentColor;
99             }
100             /++
101              + Setter for the current color
102              + Params:
103              +     color = The color to set
104              + Returns: the current color
105              +/
106             @property
107             shared synchronized ColorRGBA currentColor(ColorRGBA color)
108             {
109                 this.__currentColor = color;
110                 this.__callbacks.setCurrentColor(color);
111                 return this.__currentColor;
112             }
113 
114             /++
115              + Getter for the current brush size
116              + Returns: The current brush size
117              +/
118             @property
119             shared float currentSize()
120             {
121                 return this.__currentSize;
122             }
123             /++
124              + Setter for the current brush size
125              + Params:
126              +     size = The new brush size
127              + Returns: The new set brush size
128              +/
129             @property
130             shared synchronized float currentSize(float size)
131             {
132                 this.__currentSize = size;
133                 this.__callbacks.setCurrentSize(size);
134                 return this.__currentSize;
135             }
136 
137             /++
138              + Quit the application
139              +/
140             shared void quit()
141             {
142                 this.__callbacks.quit();
143             }
144         }
145     }
146 }