@@ -19,10 +19,7 @@ public class RegionScenario : Scenario
19
19
private Point ? _dragStart ;
20
20
private bool _isDragging ;
21
21
22
-
23
- public Rune ? _previewFillRune = Glyphs . Stipple ;
24
-
25
- public Rune ? _fillRune = Glyphs . Dot ;
22
+ private readonly Rune ? _previewFillRune = Glyphs . Stipple ;
26
23
27
24
private RegionDrawStyles _drawStyle ;
28
25
private RegionOp _regionOp ;
@@ -34,25 +31,22 @@ public override void Main ()
34
31
Window app = new ( )
35
32
{
36
33
Title = GetQuitKeyAndName ( ) ,
37
- TabStop = TabBehavior . TabGroup ,
38
-
34
+ TabStop = TabBehavior . TabGroup
39
35
} ;
40
- app . Padding . Thickness = new ( 1 ) ;
36
+ app . Padding ! . Thickness = new ( 1 ) ;
41
37
42
38
var tools = new ToolsView { Title = "Tools" , X = Pos . AnchorEnd ( ) , Y = 2 } ;
43
39
44
- tools . CurrentAttribute = app . ColorScheme . HotNormal ;
40
+ tools . CurrentAttribute = app . ColorScheme ! . HotNormal ;
45
41
46
42
tools . SetStyle += b =>
47
43
{
48
44
_drawStyle = ( RegionDrawStyles ) b ;
49
- app . SetNeedsDraw ( ) ;
45
+ app . SetNeedsDraw ( ) ;
50
46
} ;
51
47
52
- tools . RegionOpChanged += ( s , e ) =>
53
- {
54
- _regionOp = e ;
55
- } ;
48
+ tools . RegionOpChanged += ( s , e ) => { _regionOp = e ; } ;
49
+
56
50
//tools.AddLayer += () => canvas.AddLayer ();
57
51
58
52
app . Add ( tools ) ;
@@ -87,7 +81,7 @@ public override void Main ()
87
81
_dragStart = null ;
88
82
}
89
83
90
- app . SetNeedsDraw ( ) ;
84
+ app . SetNeedsDraw ( ) ;
91
85
}
92
86
} ;
93
87
@@ -120,12 +114,17 @@ public override void Main ()
120
114
if ( _isDragging && _dragStart . HasValue )
121
115
{
122
116
Point currentMousePos = Application . GetLastMousePosition ( ) ! . Value ;
123
- var previewRect = GetRectFromPoints ( _dragStart . Value , currentMousePos ) ;
117
+ Rectangle previewRect = GetRectFromPoints ( _dragStart . Value , currentMousePos ) ;
124
118
var previewRegion = new Region ( previewRect ) ;
125
119
126
120
previewRegion . FillRectangles ( tools . CurrentAttribute ! . Value , ( Rune ) ' ' ) ;
127
121
128
- previewRegion . DrawBoundaries ( app . LineCanvas , LineStyle . Dashed , new ( tools . CurrentAttribute ! . Value . Foreground . GetHighlightColor ( ) , tools . CurrentAttribute ! . Value . Background ) ) ;
122
+ previewRegion . DrawBoundaries (
123
+ app . LineCanvas ,
124
+ LineStyle . Dashed ,
125
+ new (
126
+ tools . CurrentAttribute ! . Value . Foreground . GetHighlightColor ( ) ,
127
+ tools . CurrentAttribute ! . Value . Background ) ) ;
129
128
}
130
129
} ;
131
130
@@ -138,7 +137,7 @@ public override void Main ()
138
137
139
138
private void AddRectangleFromPoints ( Point start , Point end , RegionOp op )
140
139
{
141
- var rect = GetRectFromPoints ( start , end ) ;
140
+ Rectangle rect = GetRectFromPoints ( start , end ) ;
142
141
var region = new Region ( rect ) ;
143
142
_region . Combine ( region , op ) ; // Or RegionOp.MinimalUnion if you want minimal rectangles
144
143
}
@@ -154,7 +153,7 @@ private Rectangle GetRectFromPoints (Point start, Point end)
154
153
int width = Math . Max ( 1 , right - left + 1 ) ;
155
154
int height = Math . Max ( 1 , bottom - top + 1 ) ;
156
155
157
- return new Rectangle ( left , top , width , height ) ;
156
+ return new ( left , top , width , height ) ;
158
157
}
159
158
}
160
159
@@ -165,15 +164,14 @@ public enum RegionDrawStyles
165
164
InnerBoundaries = 1 ,
166
165
167
166
OuterBoundary = 2
168
-
169
167
}
170
168
171
169
public class ToolsView : Window
172
170
{
173
171
//private Button _addLayerBtn;
174
172
private readonly AttributeView _attributeView = new ( ) ;
175
- private RadioGroup _stylePicker ;
176
- private RegionOpSelector _regionOpSelector ;
173
+ private RadioGroup ? _stylePicker ;
174
+ private RegionOpSelector ? _regionOpSelector ;
177
175
178
176
public Attribute ? CurrentAttribute
179
177
{
@@ -187,7 +185,6 @@ public ToolsView ()
187
185
Border ! . Thickness = new ( 1 , 2 , 1 , 1 ) ;
188
186
Height = Dim . Auto ( ) ;
189
187
Width = Dim . Auto ( ) ;
190
-
191
188
}
192
189
193
190
//public event Action AddLayer;
@@ -200,11 +197,11 @@ public override void BeginInit ()
200
197
201
198
_stylePicker = new ( )
202
199
{
203
- Width = Dim . Fill ( ) ,
204
- X = 0 , Y = Pos . Bottom ( _attributeView ) + 1 , RadioLabels = Enum . GetNames < RegionDrawStyles > ( ) . Select ( n => n = "_" + n ) . ToArray ( )
200
+ Width = Dim . Fill ( ) ,
201
+ X = 0 , Y = Pos . Bottom ( _attributeView ) + 1 , RadioLabels = Enum . GetNames < RegionDrawStyles > ( ) . Select ( n => n = "_" + n ) . ToArray ( )
205
202
} ;
206
203
_stylePicker . BorderStyle = LineStyle . Single ;
207
- _stylePicker . Border . Thickness = new ( 0 , 1 , 0 , 0 ) ;
204
+ _stylePicker . Border ! . Thickness = new ( 0 , 1 , 0 , 0 ) ;
208
205
_stylePicker . Title = "Draw Style" ;
209
206
210
207
_stylePicker . SelectedItemChanged += ( s , a ) => { SetStyle ? . Invoke ( ( LineStyle ) a . SelectedItem ) ; } ;
@@ -221,7 +218,7 @@ public override void BeginInit ()
221
218
//_addLayerBtn = new () { Text = "New Layer", X = Pos.Center (), Y = Pos.Bottom (_stylePicker) };
222
219
223
220
//_addLayerBtn.Accepting += (s, a) => AddLayer?.Invoke ();
224
- Add ( _attributeView , _stylePicker , _regionOpSelector ) ; //, _addLayerBtn);
221
+ Add ( _attributeView , _stylePicker , _regionOpSelector ) ; //, _addLayerBtn);
225
222
}
226
223
227
224
public event EventHandler < Attribute ? > ? AttributeChanged ;
@@ -231,14 +228,15 @@ public override void BeginInit ()
231
228
232
229
public class RegionOpSelector : View
233
230
{
234
- private RadioGroup _radioGroup ;
231
+ private readonly RadioGroup _radioGroup ;
232
+
235
233
public RegionOpSelector ( )
236
234
{
237
235
Width = Dim . Auto ( ) ;
238
236
Height = Dim . Auto ( ) ;
239
237
240
238
BorderStyle = LineStyle . Single ;
241
- Border . Thickness = new ( 0 , 1 , 0 , 0 ) ;
239
+ Border ! . Thickness = new ( 0 , 1 , 0 , 0 ) ;
242
240
Title = "RegionOp" ;
243
241
244
242
_radioGroup = new ( )
@@ -250,14 +248,14 @@ public RegionOpSelector ()
250
248
_radioGroup . SelectedItemChanged += ( s , a ) => { SelectedItemChanged ? . Invoke ( this , ( RegionOp ) a . SelectedItem ) ; } ;
251
249
Add ( _radioGroup ) ;
252
250
}
251
+
253
252
public event EventHandler < RegionOp > ? SelectedItemChanged ;
254
253
255
254
public RegionOp SelectedItem
256
255
{
257
256
get => ( RegionOp ) _radioGroup . SelectedItem ;
258
- set => _radioGroup . SelectedItem = ( int ) value ;
257
+ set => _radioGroup . SelectedItem = ( int ) value ;
259
258
}
260
-
261
259
}
262
260
263
261
public class AttributeView : View
@@ -289,11 +287,11 @@ public Attribute? Value
289
287
290
288
public AttributeView ( )
291
289
{
292
- Width = Dim . Fill ( ) ;
290
+ Width = Dim . Fill ( ) ;
293
291
Height = 4 ;
294
292
295
293
BorderStyle = LineStyle . Single ;
296
- Border . Thickness = new ( 0 , 1 , 0 , 0 ) ;
294
+ Border ! . Thickness = new ( 0 , 1 , 0 , 0 ) ;
297
295
Title = "Attribute" ;
298
296
}
299
297
@@ -366,8 +364,8 @@ protected override bool OnMouseEvent (MouseEventArgs mouseEvent)
366
364
{
367
365
ClickedInBackground ( ) ;
368
366
}
369
-
370
367
}
368
+
371
369
mouseEvent . Handled = true ;
372
370
373
371
return mouseEvent . Handled ;
@@ -394,4 +392,4 @@ private void ClickedInForeground ()
394
392
SetNeedsDraw ( ) ;
395
393
}
396
394
}
397
- }
395
+ }
0 commit comments