@@ -3,6 +3,9 @@ package sketchy
3
3
import (
4
4
"encoding/json"
5
5
"fmt"
6
+ "image"
7
+ "image/color"
8
+ "image/png"
6
9
"io/ioutil"
7
10
"log"
8
11
"os"
@@ -13,10 +16,11 @@ import (
13
16
)
14
17
15
18
const (
16
- DefaultTitle = "Sketch"
17
- DefaultPrefix = "sketch"
18
- DefaultBackgroundColor = "#1e1e1e"
19
- DefaultOutlineColor = "#ffdb00"
19
+ DefaultTitle = "Sketch"
20
+ DefaultPrefix = "sketch"
21
+ DefaultBackgroundColor = "#1e1e1e"
22
+ DefaultOutlineColor = "#ffdb00"
23
+ DefaultSketchOutlineColor = ""
20
24
)
21
25
22
26
type SketchUpdater func (s * Sketch )
@@ -43,6 +47,7 @@ type Sketch struct {
43
47
controlColorConfig ColorConfig `json:"-"`
44
48
sketchColorConfig ColorConfig `json:"-"`
45
49
isSavingPNG bool `json:"-"`
50
+ isSavingScreen bool `json:"-"`
46
51
needToClear bool `json:"-"`
47
52
}
48
53
@@ -77,6 +82,7 @@ func (s *Sketch) Init() {
77
82
if s .DisableClearBetweenFrames {
78
83
ebiten .SetScreenClearedEveryFrame (false )
79
84
}
85
+ os .Setenv ("EBITEN_SCREENSHOT_KEY" ,"escape" )
80
86
}
81
87
82
88
func (s * Sketch )Var (name string )float64 {
@@ -92,6 +98,9 @@ func (s *Sketch) UpdateControls() {
92
98
if inpututil .IsKeyJustReleased (ebiten .KeyS ) {
93
99
s .isSavingPNG = true
94
100
}
101
+ if inpututil .IsKeyJustReleased (ebiten .KeyQ ) {
102
+ s .isSavingScreen = true
103
+ }
95
104
if inpututil .IsKeyJustReleased (ebiten .KeyC ) {
96
105
s .saveConfig ()
97
106
}
@@ -158,9 +167,11 @@ func (s *Sketch) Draw(screen *ebiten.Image) {
158
167
cc .Fill ()
159
168
s .needToClear = false
160
169
}
161
- cc .SetColor (s .sketchColorConfig .Outline )
162
- cc .DrawRectangle (s .ControlWidth + 2.5 ,2.5 ,s .SketchWidth - 5 ,s .SketchHeight - 5 )
163
- cc .Stroke ()
170
+ if s .sketchColorConfig .Outline != color .Transparent {
171
+ cc .SetColor (s .sketchColorConfig .Outline )
172
+ cc .DrawRectangle (s .ControlWidth + 2.5 ,2.5 ,s .SketchWidth - 5 ,s .SketchHeight - 5 )
173
+ cc .Stroke ()
174
+ }
164
175
screen .DrawImage (ebiten .NewImageFromImage (cc .Image ()),nil )
165
176
ctx := gg .NewContext (int (s .SketchWidth ),H )
166
177
ctx .Push ()
@@ -172,6 +183,23 @@ func (s *Sketch) Draw(screen *ebiten.Image) {
172
183
fmt .Println ("Saved " ,fname )
173
184
s .isSavingPNG = false
174
185
}
186
+ if s .isSavingScreen {
187
+ fname := s .Prefix + "_" + GetTimestampString ()+ ".png"
188
+ sketchImage := screen .SubImage (s .getSketchImageRect ())
189
+ f ,err := os .Create (fname )
190
+ if err != nil {
191
+ log .Fatal ("error while trying to create screenshot file" ,err )
192
+ }
193
+ if err := png .Encode (f ,sketchImage );err != nil {
194
+ f .Close ()
195
+ log .Fatal ("error while trying to encode screenshot image" ,err )
196
+ }
197
+ if err := f .Close ();err != nil {
198
+ log .Fatal ("error while trying to close screenshot file" ,err )
199
+ }
200
+ fmt .Println ("Saved " ,fname )
201
+ s .isSavingScreen = false
202
+ }
175
203
op := & ebiten.DrawImageOptions {}
176
204
op .GeoM .Translate (s .ControlWidth ,0 )
177
205
screen .DrawImage (ebiten .NewImageFromImage (ctx .Image ()),op )
@@ -196,7 +224,7 @@ func (s *Sketch) parseColors() {
196
224
s .controlColorConfig .Set (s .ControlBackgroundColor ,BackgroundColorType ,DefaultBackgroundColor )
197
225
s .controlColorConfig .Set (s .ControlOutlineColor ,OutlineColorType ,DefaultOutlineColor )
198
226
s .sketchColorConfig .Set (s .SketchBackgroundColor ,BackgroundColorType ,DefaultBackgroundColor )
199
- s .sketchColorConfig .Set (s .SketchOutlineColor ,OutlineColorType ,DefaultOutlineColor )
227
+ s .sketchColorConfig .Set (s .SketchOutlineColor ,OutlineColorType ,DefaultSketchOutlineColor )
200
228
for i := range s .Controls {
201
229
s .Controls [i ].parseColors ()
202
230
}
@@ -211,3 +239,11 @@ func (s *Sketch) saveConfig() {
211
239
}
212
240
fmt .Println ("Saved config " ,fname )
213
241
}
242
+
243
+ func (s * Sketch )getSketchImageRect () image.Rectangle {
244
+ left := int (s .ControlWidth )
245
+ top := 0
246
+ right := left + int (s .SketchWidth )
247
+ bottom := int (s .SketchHeight )
248
+ return image .Rect (left ,top ,right ,bottom )
249
+ }