@@ -133,7 +133,7 @@ void Start()
133
133
// needed for binding
134
134
DataContext = this ;
135
135
136
- // TODO read settings
136
+ // defaults
137
137
lightColor . Red = 255 ;
138
138
lightColor . Green = 255 ;
139
139
lightColor . Blue = 255 ;
@@ -144,6 +144,9 @@ void Start()
144
144
darkColor . Blue = 0 ;
145
145
darkColor . Alpha = gridAlpha ;
146
146
147
+ // get values from settings
148
+ LoadSettings ( ) ;
149
+
147
150
// setup background grid
148
151
gridBitmap = new WriteableBitmap ( canvasResolutionX , canvasResolutionY , dpiX , dpiY , PixelFormats . Bgra32 , null ) ;
149
152
gridImage . Source = gridBitmap ;
@@ -237,8 +240,8 @@ void DrawPixel(int x, int y)
237
240
// draw
238
241
SetPixel ( canvasBitmap , x , y , ( int ) draw . ColorBGRA ) ;
239
242
240
- prevX = x ;
241
- prevY = y ;
243
+ // prevX = x;
244
+ // prevY = y;
242
245
} // drawpixel
243
246
244
247
void ErasePixel ( int x , int y )
@@ -426,22 +429,27 @@ void DrawingLeftButtonDown(object sender, MouseButtonEventArgs e)
426
429
switch ( CurrentTool )
427
430
{
428
431
case ToolMode . Draw :
429
-
430
432
// check if shift is down, then do line to previous point
431
433
if ( leftShiftDown == true )
432
434
{
433
- //DrawLine(prevX, prevY, x, y);
434
435
DrawLine ( prevX , prevY , x , y ) ;
435
436
}
436
-
437
- DrawPixel ( x , y ) ;
438
- prevX = x ;
439
- prevY = y ;
437
+ else
438
+ {
439
+ DrawPixel ( x , y ) ;
440
+ }
440
441
441
442
// mirror
442
443
if ( chkMirrorX . IsChecked == true )
443
444
{
444
- DrawPixel ( canvasResolutionX - x , y ) ;
445
+ if ( leftShiftDown == true )
446
+ {
447
+ DrawLine ( canvasResolutionX - prevX , prevY , canvasResolutionX - x , y ) ;
448
+ }
449
+ else
450
+ {
451
+ DrawPixel ( canvasResolutionX - x , y ) ;
452
+ }
445
453
}
446
454
break ;
447
455
case ToolMode . Fill :
@@ -466,7 +474,10 @@ void DrawingLeftButtonDown(object sender, MouseButtonEventArgs e)
466
474
break ;
467
475
default :
468
476
break ;
469
- }
477
+ } // switch-currenttool
478
+
479
+ prevX = x ;
480
+ prevY = y ;
470
481
471
482
if ( wasDoubleClick == true )
472
483
{
@@ -523,7 +534,8 @@ void DrawingAreaMouseMoved(object sender, MouseEventArgs e)
523
534
default :
524
535
break ;
525
536
}
526
-
537
+ prevX = x ;
538
+ prevY = y ;
527
539
}
528
540
else if ( e . RightButton == MouseButtonState . Pressed )
529
541
{
@@ -612,38 +624,6 @@ void WindowMouseWheel(object sender, MouseWheelEventArgs e)
612
624
lineCurrentHueLine . Margin = new Thickness ( offset , 0 , offset , 0 ) ;
613
625
}
614
626
615
- private void OnClearButton ( object sender , RoutedEventArgs e )
616
- {
617
- // show dialog for new resolution
618
- NewImageDialog dlg = new NewImageDialog ( ) ;
619
- dlg . Owner = this ;
620
- dlg . sliderResolution . Value = canvasResolutionX ;
621
- var result = dlg . ShowDialog ( ) ;
622
- switch ( result )
623
- {
624
- case true :
625
- RegisterUndo ( ) ;
626
- ClearImage ( canvasBitmap , emptyRect , emptyPixels , emptyStride ) ;
627
- UpdateOutline ( ) ;
628
- // reset title
629
- window . Title = windowTitle ;
630
- saveFile = null ;
631
-
632
- canvasResolutionX = ( int ) dlg . sliderResolution . Value ;
633
- canvasResolutionY = ( int ) dlg . sliderResolution . Value ;
634
-
635
- // re-init everything!!??
636
- Start ( ) ;
637
-
638
- break ;
639
- case false : // cancelled
640
- break ;
641
- default :
642
- Console . WriteLine ( "Unknown error.." ) ;
643
- break ;
644
- }
645
- }
646
-
647
627
// if unsaved, this is same as save as.., if already saved, then overwrite current
648
628
private void OnSaveButton ( object sender , RoutedEventArgs e )
649
629
{
@@ -1398,6 +1378,68 @@ private void btnSettings_Click(object sender, RoutedEventArgs e)
1398
1378
break ;
1399
1379
}
1400
1380
}
1401
- } // class
1402
1381
1382
+ void LoadSettings ( )
1383
+ {
1384
+ lightColor = ConvertSystemDrawingColorToPixelColor ( Properties . Settings . Default . gridLightColor ) ;
1385
+ darkColor = ConvertSystemDrawingColorToPixelColor ( Properties . Settings . Default . gridDarkColor ) ;
1386
+ gridAlpha = Properties . Settings . Default . gridAlpha ;
1387
+ canvasResolutionX = canvasResolutionY = Properties . Settings . Default . defaultResolution ;
1388
+ }
1389
+
1390
+ private void drawingImage_MouseLeave ( object sender , MouseEventArgs e )
1391
+ {
1392
+ rectPixelPos . Visibility = Visibility . Hidden ;
1393
+ }
1394
+
1395
+ private void drawingImage_MouseEnter ( object sender , MouseEventArgs e )
1396
+ {
1397
+ rectPixelPos . Visibility = Visibility . Visible ;
1398
+ }
1399
+
1400
+ private void OnClearButton ( object sender , MouseButtonEventArgs e )
1401
+ {
1402
+ // shiftdown or right button, just clear without dialog
1403
+ if ( leftShiftDown == true || e . RightButton == MouseButtonState . Pressed )
1404
+ {
1405
+ ClearImage ( canvasBitmap , emptyRect , emptyPixels , emptyStride ) ;
1406
+ UpdateOutline ( ) ;
1407
+ // reset title
1408
+ window . Title = windowTitle ;
1409
+ saveFile = null ;
1410
+
1411
+ return ;
1412
+ }
1413
+
1414
+ // show dialog for new resolution
1415
+ NewImageDialog dlg = new NewImageDialog ( ) ;
1416
+ dlg . Owner = this ;
1417
+ dlg . sliderResolution . Value = canvasResolutionX ;
1418
+ var result = dlg . ShowDialog ( ) ;
1419
+ switch ( result )
1420
+ {
1421
+ case true :
1422
+ RegisterUndo ( ) ;
1423
+ ClearImage ( canvasBitmap , emptyRect , emptyPixels , emptyStride ) ;
1424
+ UpdateOutline ( ) ;
1425
+ // reset title
1426
+ window . Title = windowTitle ;
1427
+ saveFile = null ;
1428
+
1429
+ canvasResolutionX = ( int ) dlg . sliderResolution . Value ;
1430
+ canvasResolutionY = ( int ) dlg . sliderResolution . Value ;
1431
+
1432
+ // TODO no need to do full start
1433
+ Start ( ) ;
1434
+
1435
+ break ;
1436
+ case false : // cancelled
1437
+ break ;
1438
+ default :
1439
+ Console . WriteLine ( "Unknown error.." ) ;
1440
+ break ;
1441
+ }
1442
+
1443
+ }
1444
+ } // class
1403
1445
} // namespace
0 commit comments