66using System . Globalization ;
77using System . IO ;
88using System . Text ;
9+ using System . Windows . Forms ;
910using System . Xml . Linq ;
1011
11- namespace LSPtools
12+ namespace FpgaLcdUtils
1213{
1314 public partial class BMForm : Form
1415 {
@@ -42,6 +43,11 @@ private void BMForm_Shown(object sender, EventArgs e)
4243 {
4344 if ( ! isFormShown ) { panelExtendColor . BackColor = Color . Black ; timerUpdate . Enabled = true ; }
4445 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 ;
4551 IniSettings . GeometryBMP . ApplyGeometryToForm ( this ) ;
4652 if ( firstMRUFileOnStart != null )
4753 {
@@ -83,14 +89,14 @@ private bool isPower2orSum(int x)
8389
8490 private void setNoBitmapLoaded ( )
8591 {
92+ messagesErrorRichTextBox . Text = " " ;
8693 openedBitmap = null ; previewBitmap = null ;
8794 assignFilenameOfOpenedBitmap ( null ) ;
8895 txbLoadedSize . Text = "--" ;
8996 txbCountOfColors . Text = "--" ;
9097 previewBitmap = null ;
9198 palettePanel . Invalidate ( ) ;
9299 previewBitmapPanel . Invalidate ( ) ;
93-
94100 }
95101
96102
@@ -234,7 +240,7 @@ void assignFilenameOfOpenedBitmap(string? filename)
234240 openedBitmap = null ;
235241 return ;
236242 }
237-
243+
238244 string sn ;
239245 string s = String . Format ( "{0} [{1}]" , sn = Path . GetFileName ( filename ) , Path . GetFullPath ( filename ) ) ;
240246 this . Text = "LSPtool bitmap: " + s ;
@@ -274,17 +280,17 @@ bool testIfBitmapAccessible(string? filename)
274280 {
275281 displayMessage ( "!!! You do not have the required permission to access: " + filename , MessageSeverity . Error ) ;
276282 }
277- catch ( Exception ex )
283+ catch ( Exception ex )
278284 {
279285 displayMessage ( ex . Message , MessageSeverity . Error ) ;
280286 }
281287 openedFilenameTextBox . ForeColor = Color . Red ;
282288 openedFilenameTextBox . Text = messageFailToLoadBitmap ;
283289 return false ;
284290 }
285-
286-
287-
291+
292+
293+
288294
289295 public class BmpItem
290296 {
@@ -337,7 +343,7 @@ void setWidthMessage(int w)
337343 {
338344 if ( isPower2orSum ( w ) )
339345 {
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 ) ;
341347 nudReloadWidth . ForeColor = SystemColors . ControlText ;
342348 }
343349 else
@@ -353,8 +359,8 @@ void setWidthMessage(int w)
353359 {
354360 if ( isPower2orSum ( max ) ) break ; max ++ ;
355361 }
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 ) ;
358364 }
359365 }
360366
@@ -506,16 +512,8 @@ private void saveAsMemoryInitializationFileToolStripMenuItem_Click(object sender
506512 saveFileDialog1 . Title = "Save as Memory Initialization File" ;
507513 saveFileDialog1 . DefaultExt = "mif" ;
508514
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 ;
519517 }
520518 catch ( Exception ex )
521519 {
@@ -524,7 +522,6 @@ private void saveAsMemoryInitializationFileToolStripMenuItem_Click(object sender
524522 }
525523 string filename = saveFileDialog1 . FileName ;
526524
527-
528525 // string pattern = @"
529526 //-- Generated Memory Initialization File (.mif)
530527 //
@@ -608,7 +605,7 @@ private void saveAsMemoryInitializationFileToolStripMenuItem_Click(object sender
608605 private void addMemoryHeader ( StringBuilder sb , BmpItem bi , out int requiredMemorySize )
609606 {
610607 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 ) ) ;
612609 int size = bi . Height * bi . Width ;
613610 sb . AppendLine ( String . Format ( "-- from bitmap file {0}" , bi . Filename ) ) ;
614611 int addressWidth = GetMemoryAddressWidth ( size , out requiredMemorySize ) ;
@@ -671,28 +668,18 @@ private void saveAsVHDL_toolStripMenuItem_Click(object sender, EventArgs e)
671668 saveFileDialog1 . Filter = "VHDL (*.vhd)|*.vhd|All files(*.*)|*.*" ;
672669 saveFileDialog1 . Title = "Save as VHDL Entity" ;
673670 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" ) )
684673 return ;
674+
685675 }
686676 catch ( Exception ex )
687677 {
688678 Trace . WriteLine ( ex . ToString ( ) ) ;
689679 displayStatusMessage ( ex . Message , MessageSeverity . Error ) ;
680+ return ;
690681 }
691682 string filename = saveFileDialog1 . FileName ;
692- if ( ! String . IsNullOrEmpty ( filename ) )
693- saveFileDialog1 . InitialDirectory = Path . GetDirectoryName ( filename ) ;
694-
695-
696683
697684 // library ieee, work; use ieee.std_logic_1164.all; use ieee.numeric_std.all;
698685 // entity romLCD10g is
@@ -972,27 +959,30 @@ private void displayMessage(string text, MessageSeverity severity)
972959 {
973960 if ( text == _displayMessageLastText ) return ;
974961 else _displayMessageLastText = text ;
962+ displayMessage ( messageRichTextBox , text , severity ) ;
963+ }
964+ private void displayMessage ( RichTextBox rtb , string text , MessageSeverity severity )
965+ {
975966 if ( text == null || text . Trim ( ) . Length == 0 ) return ;
976967 Color foreColor = SystemColors . WindowText ;
977968 switch ( severity )
978969 {
979970 case MessageSeverity . Error : foreColor = Color . Red ; break ;
980971 case MessageSeverity . Warning : foreColor = Color . BlueViolet ; break ;
981972 }
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 ;
985980 // Textbox may transform chars, so (end-start) != text.Length
986- messageRichTextBox . Select ( start , end - start ) ;
981+ rtb . Select ( start , end - start ) ;
987982 {
988- messageRichTextBox . SelectionColor = foreColor ;
983+ rtb . SelectionColor = foreColor ;
989984 }
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 ;
996986 }
997987
998988 private readonly TimeSpan _messageDuration = new TimeSpan ( 0 , 0 , 30 ) ; // 30 seconds
@@ -1075,15 +1065,12 @@ private void savePreviewBitmapToolStripMenuItem6_Click(object sender, EventArgs
10751065 if ( previewBitmap == null ) { displayMessage ( "No image loaded" ) ; return ; }
10761066 try
10771067 {
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 ) ;
10871074 }
10881075 catch ( Exception ex )
10891076 {
@@ -1184,6 +1171,39 @@ private void recentBitmapsToolStripMenuItem_Click(object sender, EventArgs e)
11841171
11851172 }
11861173 }
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+ }
11871207
11881208 private void Color2Mesage ( Color c , string xyText )
11891209 {
0 commit comments