6
6
using System . Globalization ;
7
7
using System . IO ;
8
8
using System . Text ;
9
+ using System . Windows . Forms ;
9
10
using System . Xml . Linq ;
10
11
11
- namespace LSPtools
12
+ namespace FpgaLcdUtils
12
13
{
13
14
public partial class BMForm : Form
14
15
{
@@ -42,6 +43,11 @@ private void BMForm_Shown(object sender, EventArgs e)
42
43
{
43
44
if ( ! isFormShown ) { panelExtendColor . BackColor = Color . Black ; timerUpdate . Enabled = true ; }
44
45
isFormShown = true ;
46
+ Font f = messagesErrorRichTextBox . Font ;
47
+ int pxFont = ( int ) Math . Ceiling ( f . GetHeight ( messagesErrorRichTextBox . CreateGraphics ( ) ) ) ;
48
+ if ( pxFont < 10 ) pxFont = 10 ;
49
+ splitContainer2 . Panel1MinSize = pxFont ;
50
+ splitContainer2 . SplitterDistance = 2 * pxFont ;
45
51
IniSettings . GeometryBMP . ApplyGeometryToForm ( this ) ;
46
52
if ( firstMRUFileOnStart != null )
47
53
{
@@ -83,14 +89,14 @@ private bool isPower2orSum(int x)
83
89
84
90
private void setNoBitmapLoaded ( )
85
91
{
92
+ messagesErrorRichTextBox . Text = " " ;
86
93
openedBitmap = null ; previewBitmap = null ;
87
94
assignFilenameOfOpenedBitmap ( null ) ;
88
95
txbLoadedSize . Text = "--" ;
89
96
txbCountOfColors . Text = "--" ;
90
97
previewBitmap = null ;
91
98
palettePanel . Invalidate ( ) ;
92
99
previewBitmapPanel . Invalidate ( ) ;
93
-
94
100
}
95
101
96
102
@@ -234,7 +240,7 @@ void assignFilenameOfOpenedBitmap(string? filename)
234
240
openedBitmap = null ;
235
241
return ;
236
242
}
237
-
243
+
238
244
string sn ;
239
245
string s = String . Format ( "{0} [{1}]" , sn = Path . GetFileName ( filename ) , Path . GetFullPath ( filename ) ) ;
240
246
this . Text = "LSPtool bitmap: " + s ;
@@ -274,17 +280,17 @@ bool testIfBitmapAccessible(string? filename)
274
280
{
275
281
displayMessage ( "!!! You do not have the required permission to access: " + filename , MessageSeverity . Error ) ;
276
282
}
277
- catch ( Exception ex )
283
+ catch ( Exception ex )
278
284
{
279
285
displayMessage ( ex . Message , MessageSeverity . Error ) ;
280
286
}
281
287
openedFilenameTextBox . ForeColor = Color . Red ;
282
288
openedFilenameTextBox . Text = messageFailToLoadBitmap ;
283
289
return false ;
284
290
}
285
-
286
-
287
-
291
+
292
+
293
+
288
294
289
295
public class BmpItem
290
296
{
@@ -337,7 +343,7 @@ void setWidthMessage(int w)
337
343
{
338
344
if ( isPower2orSum ( w ) )
339
345
{
340
- displayMessage ( "OK: The width allows calculating memory addresses without a hardware multiplier." ) ;
346
+ displayMessage ( messagesErrorRichTextBox , "OK: The width allows calculating memory addresses without a hardware multiplier." , MessageSeverity . Info ) ;
341
347
nudReloadWidth . ForeColor = SystemColors . ControlText ;
342
348
}
343
349
else
@@ -353,8 +359,8 @@ void setWidthMessage(int w)
353
359
{
354
360
if ( isPower2orSum ( max ) ) break ; max ++ ;
355
361
}
356
- displayMessage ( String . Format ( "KO: ROM width is not 2**n or (2**n+2**m)! The nearest better widths are {0} or {1}" , max , min ) ,
357
- MessageSeverity . Warning ) ;
362
+ displayMessage ( messagesErrorRichTextBox , String . Format ( "KO: ROM width is not 2**n or (2**n+2**m)! The nearest better widths are {0} or {1}" , max , min ) ,
363
+ MessageSeverity . Error ) ;
358
364
}
359
365
}
360
366
@@ -506,16 +512,8 @@ private void saveAsMemoryInitializationFileToolStripMenuItem_Click(object sender
506
512
saveFileDialog1 . Title = "Save as Memory Initialization File" ;
507
513
saveFileDialog1 . DefaultExt = "mif" ;
508
514
509
- string s = previewBitmap . Filename ;
510
- if ( ! String . IsNullOrEmpty ( s ) )
511
- {
512
- s = Path . ChangeExtension ( s , ".mif" ) ;
513
- saveFileDialog1 . FileName = Path . GetFileName ( s ) ;
514
- saveFileDialog1 . InitialDirectory = Path . GetDirectoryName ( s ) ;
515
- }
516
-
517
- if ( saveFileDialog1 . ShowDialog ( ) != System . Windows . Forms . DialogResult . OK )
518
- return ;
515
+ if ( ! IniSettings . FilesBitmap . ShowSaveDialog ( saveFileDialog1 , new string [ ] { "mif" , "vhdl" , "bmp" } ,
516
+ previewBitmap . Filename , "mif" ) ) return ;
519
517
}
520
518
catch ( Exception ex )
521
519
{
@@ -524,7 +522,6 @@ private void saveAsMemoryInitializationFileToolStripMenuItem_Click(object sender
524
522
}
525
523
string filename = saveFileDialog1 . FileName ;
526
524
527
-
528
525
// string pattern = @"
529
526
//-- Generated Memory Initialization File (.mif)
530
527
//
@@ -608,7 +605,7 @@ private void saveAsMemoryInitializationFileToolStripMenuItem_Click(object sender
608
605
private void addMemoryHeader ( StringBuilder sb , BmpItem bi , out int requiredMemorySize )
609
606
{
610
607
sb . AppendLine ( "-- CTU-FEE in Prague, Dept. of Control Eng. [Richard Susta]" ) ;
611
- sb . AppendLine ( String . Format ( "-- LSP tools generated file on {0}" , DateTime . Now ) ) ;
608
+ sb . AppendLine ( String . Format ( "-- FPGA-LCD Utils generated file on {0}" , DateTime . Now ) ) ;
612
609
int size = bi . Height * bi . Width ;
613
610
sb . AppendLine ( String . Format ( "-- from bitmap file {0}" , bi . Filename ) ) ;
614
611
int addressWidth = GetMemoryAddressWidth ( size , out requiredMemorySize ) ;
@@ -671,28 +668,18 @@ private void saveAsVHDL_toolStripMenuItem_Click(object sender, EventArgs e)
671
668
saveFileDialog1 . Filter = "VHDL (*.vhd)|*.vhd|All files(*.*)|*.*" ;
672
669
saveFileDialog1 . Title = "Save as VHDL Entity" ;
673
670
saveFileDialog1 . DefaultExt = "vhd" ;
674
- string s = previewBitmap . Filename ;
675
- if ( ! String . IsNullOrEmpty ( s ) )
676
- {
677
- s = Path . ChangeExtension ( s , ".vhd" ) ;
678
- saveFileDialog1 . FileName = Path . GetFileName ( s ) ;
679
- if ( String . IsNullOrEmpty ( saveFileDialog1 . InitialDirectory ) )
680
- saveFileDialog1 . InitialDirectory = Path . GetDirectoryName ( s ) ;
681
- }
682
-
683
- if ( saveFileDialog1 . ShowDialog ( ) != System . Windows . Forms . DialogResult . OK )
671
+ if ( ! IniSettings . FilesBitmap . ShowSaveDialog ( saveFileDialog1 , new string [ ] { "vhdl" , "mif" , "bmp" } ,
672
+ previewBitmap . Filename , "vhd" ) )
684
673
return ;
674
+
685
675
}
686
676
catch ( Exception ex )
687
677
{
688
678
Trace . WriteLine ( ex . ToString ( ) ) ;
689
679
displayStatusMessage ( ex . Message , MessageSeverity . Error ) ;
680
+ return ;
690
681
}
691
682
string filename = saveFileDialog1 . FileName ;
692
- if ( ! String . IsNullOrEmpty ( filename ) )
693
- saveFileDialog1 . InitialDirectory = Path . GetDirectoryName ( filename ) ;
694
-
695
-
696
683
697
684
// library ieee, work; use ieee.std_logic_1164.all; use ieee.numeric_std.all;
698
685
// entity romLCD10g is
@@ -972,27 +959,30 @@ private void displayMessage(string text, MessageSeverity severity)
972
959
{
973
960
if ( text == _displayMessageLastText ) return ;
974
961
else _displayMessageLastText = text ;
962
+ displayMessage ( messageRichTextBox , text , severity ) ;
963
+ }
964
+ private void displayMessage ( RichTextBox rtb , string text , MessageSeverity severity )
965
+ {
975
966
if ( text == null || text . Trim ( ) . Length == 0 ) return ;
976
967
Color foreColor = SystemColors . WindowText ;
977
968
switch ( severity )
978
969
{
979
970
case MessageSeverity . Error : foreColor = Color . Red ; break ;
980
971
case MessageSeverity . Warning : foreColor = Color . BlueViolet ; break ;
981
972
}
982
- int start = messageRichTextBox . TextLength ;
983
- messageRichTextBox . AppendText ( text + Environment . NewLine ) ;
984
- int end = messageRichTextBox . TextLength ;
973
+ int start = rtb . TextLength ;
974
+ if ( rtb != messagesErrorRichTextBox )
975
+ {
976
+ rtb . AppendText ( text + Environment . NewLine ) ;
977
+ }
978
+ else { start = 0 ; rtb . Text = text ; }
979
+ int end = rtb . TextLength ;
985
980
// Textbox may transform chars, so (end-start) != text.Length
986
- messageRichTextBox . Select ( start , end - start ) ;
981
+ rtb . Select ( start , end - start ) ;
987
982
{
988
- messageRichTextBox . SelectionColor = foreColor ;
983
+ rtb . SelectionColor = foreColor ;
989
984
}
990
- messageRichTextBox . SelectionLength = 0 ;
991
- }
992
- private void clearAllMessages_Click ( object sender , EventArgs e )
993
- {
994
- messageRichTextBox . Text = String . Empty ; // Clear() clears also font size;
995
- _displayMessageLastText = String . Empty ;
985
+ rtb . SelectionLength = 0 ;
996
986
}
997
987
998
988
private readonly TimeSpan _messageDuration = new TimeSpan ( 0 , 0 , 30 ) ; // 30 seconds
@@ -1075,15 +1065,12 @@ private void savePreviewBitmapToolStripMenuItem6_Click(object sender, EventArgs
1075
1065
if ( previewBitmap == null ) { displayMessage ( "No image loaded" ) ; return ; }
1076
1066
try
1077
1067
{
1078
- if ( String . IsNullOrEmpty ( savePreviewBitmapFileDialog . FileName ) )
1079
- savePreviewBitmapFileDialog . FileName = openFileDialog1 . FileName ;
1080
- if ( savePreviewBitmapFileDialog . ShowDialog ( ) == System . Windows . Forms . DialogResult . OK )
1081
- {
1082
- string filename = savePreviewBitmapFileDialog . FileName ;
1083
- filename = Path . ChangeExtension ( filename , ".bmp" ) ;
1084
- previewBitmap . bitmap . Save ( filename , System . Drawing . Imaging . ImageFormat . Bmp ) ;
1085
- displayMessage ( "Bitmap saved as " + filename ) ;
1086
- }
1068
+ if ( ! IniSettings . FilesBitmap . ShowSaveDialog ( savePreviewBitmapFileDialog , new string [ ] { "bmp" , "vhdl" , "mif" } ,
1069
+ null , "bmp" ) ) // do not suggest file name
1070
+ return ;
1071
+ string filename = savePreviewBitmapFileDialog . FileName ;
1072
+ previewBitmap . bitmap . Save ( filename , System . Drawing . Imaging . ImageFormat . Bmp ) ;
1073
+ displayMessage ( "Bitmap saved as " + filename ) ;
1087
1074
}
1088
1075
catch ( Exception ex )
1089
1076
{
@@ -1184,6 +1171,39 @@ private void recentBitmapsToolStripMenuItem_Click(object sender, EventArgs e)
1184
1171
1185
1172
}
1186
1173
}
1174
+ Control ? _sourceControl = null ;
1175
+
1176
+ private void messagesContextMenuStrip_Opened ( object sender , EventArgs e )
1177
+ {
1178
+ _sourceControl = messagesContextMenuStrip . SourceControl ;
1179
+ }
1180
+
1181
+ private void copySelected_messagesContextMenuStrip_Click ( object sender , EventArgs e )
1182
+ {
1183
+ ToolStripMenuItem ? menuItem = sender as ToolStripMenuItem ;
1184
+ if ( _sourceControl != null )
1185
+ {
1186
+ String ? tag = _sourceControl . Tag as String ;
1187
+ if ( tag == "E" ) messagesErrorRichTextBox . Copy ( ) ; else messageRichTextBox . Copy ( ) ;
1188
+ }
1189
+ }
1190
+
1191
+ private void deleteAll_messagesContextMenuStrip_Click ( object sender , EventArgs e )
1192
+ {
1193
+ ToolStripMenuItem ? menuItem = sender as ToolStripMenuItem ;
1194
+ if ( _sourceControl != null )
1195
+ {
1196
+ String ? tag = _sourceControl . Tag as String ;
1197
+ if ( tag == "E" ) messagesErrorRichTextBox . Text = " " ;
1198
+ else
1199
+ {
1200
+ messageRichTextBox . Text = " " ; // Clear() clears also font size;
1201
+ _displayMessageLastText = " " ;
1202
+ }
1203
+
1204
+ }
1205
+
1206
+ }
1187
1207
1188
1208
private void Color2Mesage ( Color c , string xyText )
1189
1209
{
0 commit comments