From eb3a28e7335123e49b82e7fef431d2e371269d06 Mon Sep 17 00:00:00 2001 From: bbbradsmith Date: Fri, 11 Oct 2024 18:52:15 -0400 Subject: [PATCH] Clean up designer auto generate code. Use more consistent names, arrange widget functions in groups and order according to layout. (Sorry about the bad diff in the design generated code sections due to the reordering and renaming.) Simplify option form updates with common redrawOptions. Add defaultOption as a common point for resetting to default options. Add -paltype command line for full palette format selection. Add path resolution to parseOption (will be needed for INI files). Rename palette_greymask to palette_greymax (describes its use better). Store palette_path to allow saving the last used palette to INI later. Consolidate refreshPalette into redrawPalette (which is better named and was only called by refreshPalette anyway). --- BinxelviewForm.Designer.cs | 396 ++++++------ BinxelviewForm.cs | 1183 +++++++++++++++++++----------------- readme.txt | 9 +- 3 files changed, 828 insertions(+), 760 deletions(-) diff --git a/BinxelviewForm.Designer.cs b/BinxelviewForm.Designer.cs index e116173..fd8e8f5 100644 --- a/BinxelviewForm.Designer.cs +++ b/BinxelviewForm.Designer.cs @@ -32,30 +32,30 @@ private void InitializeComponent() System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(BinxelviewForm)); this.menuStripMain = new System.Windows.Forms.MenuStrip(); this.fileToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.openToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.reloadFileToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.saveAllVisibleToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.exportBinaryChunkToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator(); - this.exitToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.openFileMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.reloadFileMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.saveAllVisibleFileMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.exportBinaryChunkFileMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.fileMenuSeparator = new System.Windows.Forms.ToolStripSeparator(); + this.exitFileMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.presetToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.reloadPresetsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.presetStripMenuDash = new System.Windows.Forms.ToolStripSeparator(); + this.reloadPresetMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.presetMenuSeparator = new System.Windows.Forms.ToolStripSeparator(); this.optionsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.decimalPositionToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.hexadecimalPositionToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.optionsStripMenuDash1 = new System.Windows.Forms.ToolStripSeparator(); - this.snapScrollToNextStrideToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.optionsStripMenuDash2 = new System.Windows.Forms.ToolStripSeparator(); - this.gridToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.optionsStripMenuDash3 = new System.Windows.Forms.ToolStripSeparator(); - this.verticalLayoutToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.horizontalLayoutToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.optionsStripMenuDash4 = new System.Windows.Forms.ToolStripSeparator(); - this.twiddleZToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.twiddleNToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.decimalPositionOptionsMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.hexadecimalPositionOptionsMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.optionsMenuSeparator1 = new System.Windows.Forms.ToolStripSeparator(); + this.snapScrollToNextStrideOptionsMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.optionsMenuSeparator2 = new System.Windows.Forms.ToolStripSeparator(); + this.gridOptionsMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.optionsMenuSeparator3 = new System.Windows.Forms.ToolStripSeparator(); + this.verticalLayoutOptionsMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.horizontalLayoutOptionsMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.optionsMenuSeparator4 = new System.Windows.Forms.ToolStripSeparator(); + this.twiddleZOptionsMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.twiddleNOptionsMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.helpToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.aboutToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.aboutHelpMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.tableTop = new System.Windows.Forms.TableLayoutPanel(); this.groupPacking = new System.Windows.Forms.GroupBox(); this.buttonPixel = new System.Windows.Forms.Button(); @@ -119,10 +119,10 @@ private void InitializeComponent() this.tableBottom = new System.Windows.Forms.TableLayoutPanel(); this.pixelBox = new System.Windows.Forms.PictureBox(); this.contextMenuPixel = new System.Windows.Forms.ContextMenuStrip(this.components); - this.saveImageToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.saveAllToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.positionToPixelToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.pixelsToPaletteToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.saveImageContextItem = new System.Windows.Forms.ToolStripMenuItem(); + this.saveAllContextItem = new System.Windows.Forms.ToolStripMenuItem(); + this.positionToPixelContextItem = new System.Windows.Forms.ToolStripMenuItem(); + this.pixelsToPaletteContextItem = new System.Windows.Forms.ToolStripMenuItem(); this.pixelScroll = new System.Windows.Forms.VScrollBar(); this.toolTip = new System.Windows.Forms.ToolTip(this.components); this.menuStripMain.SuspendLayout(); @@ -175,194 +175,194 @@ private void InitializeComponent() // fileToolStripMenuItem // this.fileToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.openToolStripMenuItem, - this.reloadFileToolStripMenuItem, - this.saveAllVisibleToolStripMenuItem, - this.exportBinaryChunkToolStripMenuItem, - this.toolStripSeparator1, - this.exitToolStripMenuItem}); + this.openFileMenuItem, + this.reloadFileMenuItem, + this.saveAllVisibleFileMenuItem, + this.exportBinaryChunkFileMenuItem, + this.fileMenuSeparator, + this.exitFileMenuItem}); this.fileToolStripMenuItem.Name = "fileToolStripMenuItem"; this.fileToolStripMenuItem.Size = new System.Drawing.Size(37, 20); this.fileToolStripMenuItem.Text = "&File"; // - // openToolStripMenuItem + // openFileMenuItem // - this.openToolStripMenuItem.Name = "openToolStripMenuItem"; - this.openToolStripMenuItem.Size = new System.Drawing.Size(191, 22); - this.openToolStripMenuItem.Text = "&Open..."; - this.openToolStripMenuItem.Click += new System.EventHandler(this.openToolStripMenuItem_Click); + this.openFileMenuItem.Name = "openFileMenuItem"; + this.openFileMenuItem.Size = new System.Drawing.Size(191, 22); + this.openFileMenuItem.Text = "&Open..."; + this.openFileMenuItem.Click += new System.EventHandler(this.openFileMenuItem_Click); // - // reloadFileToolStripMenuItem + // reloadFileMenuItem // - this.reloadFileToolStripMenuItem.Name = "reloadFileToolStripMenuItem"; - this.reloadFileToolStripMenuItem.Size = new System.Drawing.Size(191, 22); - this.reloadFileToolStripMenuItem.Text = "&Reload"; - this.reloadFileToolStripMenuItem.Click += new System.EventHandler(this.reloadFileToolStripMenuItem_Click); + this.reloadFileMenuItem.Name = "reloadFileMenuItem"; + this.reloadFileMenuItem.Size = new System.Drawing.Size(191, 22); + this.reloadFileMenuItem.Text = "&Reload"; + this.reloadFileMenuItem.Click += new System.EventHandler(this.reloadFileMenuItem_Click); // - // saveAllVisibleToolStripMenuItem + // saveAllVisibleFileMenuItem // - this.saveAllVisibleToolStripMenuItem.Name = "saveAllVisibleToolStripMenuItem"; - this.saveAllVisibleToolStripMenuItem.Size = new System.Drawing.Size(191, 22); - this.saveAllVisibleToolStripMenuItem.Text = "&Save &All Visible"; - this.saveAllVisibleToolStripMenuItem.Click += new System.EventHandler(this.saveAllVisibleToolStripMenuItem_Click); + this.saveAllVisibleFileMenuItem.Name = "saveAllVisibleFileMenuItem"; + this.saveAllVisibleFileMenuItem.Size = new System.Drawing.Size(191, 22); + this.saveAllVisibleFileMenuItem.Text = "&Save &All Visible"; + this.saveAllVisibleFileMenuItem.Click += new System.EventHandler(this.saveAllVisibleFileMenuItem_Click); // - // exportBinaryChunkToolStripMenuItem + // exportBinaryChunkFileMenuItem // - this.exportBinaryChunkToolStripMenuItem.Name = "exportBinaryChunkToolStripMenuItem"; - this.exportBinaryChunkToolStripMenuItem.Size = new System.Drawing.Size(191, 22); - this.exportBinaryChunkToolStripMenuItem.Text = "Export Binary Chunk..."; - this.exportBinaryChunkToolStripMenuItem.Click += new System.EventHandler(this.exportBinaryChunkToolStripMenuItem_Click); + this.exportBinaryChunkFileMenuItem.Name = "exportBinaryChunkFileMenuItem"; + this.exportBinaryChunkFileMenuItem.Size = new System.Drawing.Size(191, 22); + this.exportBinaryChunkFileMenuItem.Text = "Export Binary Chunk..."; + this.exportBinaryChunkFileMenuItem.Click += new System.EventHandler(this.exportBinaryChunkFileMenuItem_Click); // - // toolStripSeparator1 + // fileMenuSeparator // - this.toolStripSeparator1.Name = "toolStripSeparator1"; - this.toolStripSeparator1.Size = new System.Drawing.Size(188, 6); + this.fileMenuSeparator.Name = "fileMenuSeparator"; + this.fileMenuSeparator.Size = new System.Drawing.Size(188, 6); // - // exitToolStripMenuItem + // exitFileMenuItem // - this.exitToolStripMenuItem.Name = "exitToolStripMenuItem"; - this.exitToolStripMenuItem.Size = new System.Drawing.Size(191, 22); - this.exitToolStripMenuItem.Text = "E&xit"; - this.exitToolStripMenuItem.Click += new System.EventHandler(this.exitToolStripMenuItem_Click); + this.exitFileMenuItem.Name = "exitFileMenuItem"; + this.exitFileMenuItem.Size = new System.Drawing.Size(191, 22); + this.exitFileMenuItem.Text = "E&xit"; + this.exitFileMenuItem.Click += new System.EventHandler(this.exitFileMenuItem_Click); // // presetToolStripMenuItem // this.presetToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.reloadPresetsToolStripMenuItem, - this.presetStripMenuDash}); + this.reloadPresetMenuItem, + this.presetMenuSeparator}); this.presetToolStripMenuItem.Name = "presetToolStripMenuItem"; this.presetToolStripMenuItem.Size = new System.Drawing.Size(51, 20); this.presetToolStripMenuItem.Text = "&Preset"; // - // reloadPresetsToolStripMenuItem + // reloadPresetMenuItem // - this.reloadPresetsToolStripMenuItem.Name = "reloadPresetsToolStripMenuItem"; - this.reloadPresetsToolStripMenuItem.Size = new System.Drawing.Size(110, 22); - this.reloadPresetsToolStripMenuItem.Text = "&Reload"; - this.reloadPresetsToolStripMenuItem.Click += new System.EventHandler(this.reloadPresetsToolStripMenuItem_Click); + this.reloadPresetMenuItem.Name = "reloadPresetMenuItem"; + this.reloadPresetMenuItem.Size = new System.Drawing.Size(110, 22); + this.reloadPresetMenuItem.Text = "&Reload"; + this.reloadPresetMenuItem.Click += new System.EventHandler(this.reloadPresetsToolStripMenuItem_Click); // - // presetStripMenuDash + // presetMenuSeparator // - this.presetStripMenuDash.Name = "presetStripMenuDash"; - this.presetStripMenuDash.Size = new System.Drawing.Size(107, 6); + this.presetMenuSeparator.Name = "presetMenuSeparator"; + this.presetMenuSeparator.Size = new System.Drawing.Size(107, 6); // // optionsToolStripMenuItem // this.optionsToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.decimalPositionToolStripMenuItem, - this.hexadecimalPositionToolStripMenuItem, - this.optionsStripMenuDash1, - this.snapScrollToNextStrideToolStripMenuItem, - this.optionsStripMenuDash2, - this.gridToolStripMenuItem, - this.optionsStripMenuDash3, - this.verticalLayoutToolStripMenuItem, - this.horizontalLayoutToolStripMenuItem, - this.optionsStripMenuDash4, - this.twiddleZToolStripMenuItem, - this.twiddleNToolStripMenuItem}); + this.decimalPositionOptionsMenuItem, + this.hexadecimalPositionOptionsMenuItem, + this.optionsMenuSeparator1, + this.snapScrollToNextStrideOptionsMenuItem, + this.optionsMenuSeparator2, + this.gridOptionsMenuItem, + this.optionsMenuSeparator3, + this.verticalLayoutOptionsMenuItem, + this.horizontalLayoutOptionsMenuItem, + this.optionsMenuSeparator4, + this.twiddleZOptionsMenuItem, + this.twiddleNOptionsMenuItem}); this.optionsToolStripMenuItem.Name = "optionsToolStripMenuItem"; this.optionsToolStripMenuItem.Size = new System.Drawing.Size(61, 20); this.optionsToolStripMenuItem.Text = "&Options"; // - // decimalPositionToolStripMenuItem + // decimalPositionOptionsMenuItem // - this.decimalPositionToolStripMenuItem.Name = "decimalPositionToolStripMenuItem"; - this.decimalPositionToolStripMenuItem.Size = new System.Drawing.Size(203, 22); - this.decimalPositionToolStripMenuItem.Text = "&Decimal Position"; - this.decimalPositionToolStripMenuItem.Click += new System.EventHandler(this.decimalPositionToolStripMenuItem_Click); + this.decimalPositionOptionsMenuItem.Name = "decimalPositionOptionsMenuItem"; + this.decimalPositionOptionsMenuItem.Size = new System.Drawing.Size(203, 22); + this.decimalPositionOptionsMenuItem.Text = "&Decimal Position"; + this.decimalPositionOptionsMenuItem.Click += new System.EventHandler(this.decimalPositionOptionsMenuItem_Click); // - // hexadecimalPositionToolStripMenuItem + // hexadecimalPositionOptionsMenuItem // - this.hexadecimalPositionToolStripMenuItem.Checked = true; - this.hexadecimalPositionToolStripMenuItem.CheckState = System.Windows.Forms.CheckState.Checked; - this.hexadecimalPositionToolStripMenuItem.Name = "hexadecimalPositionToolStripMenuItem"; - this.hexadecimalPositionToolStripMenuItem.Size = new System.Drawing.Size(203, 22); - this.hexadecimalPositionToolStripMenuItem.Text = "&Hexadecimal Position"; - this.hexadecimalPositionToolStripMenuItem.Click += new System.EventHandler(this.hexadecimalPositionToolStripMenuItem_Click); + this.hexadecimalPositionOptionsMenuItem.Checked = true; + this.hexadecimalPositionOptionsMenuItem.CheckState = System.Windows.Forms.CheckState.Checked; + this.hexadecimalPositionOptionsMenuItem.Name = "hexadecimalPositionOptionsMenuItem"; + this.hexadecimalPositionOptionsMenuItem.Size = new System.Drawing.Size(203, 22); + this.hexadecimalPositionOptionsMenuItem.Text = "&Hexadecimal Position"; + this.hexadecimalPositionOptionsMenuItem.Click += new System.EventHandler(this.hexadecimalPositionOptionsMenuItem_Click); // - // optionsStripMenuDash1 + // optionsMenuSeparator1 // - this.optionsStripMenuDash1.Name = "optionsStripMenuDash1"; - this.optionsStripMenuDash1.Size = new System.Drawing.Size(200, 6); + this.optionsMenuSeparator1.Name = "optionsMenuSeparator1"; + this.optionsMenuSeparator1.Size = new System.Drawing.Size(200, 6); // - // snapScrollToNextStrideToolStripMenuItem + // snapScrollToNextStrideOptionsMenuItem // - this.snapScrollToNextStrideToolStripMenuItem.Checked = true; - this.snapScrollToNextStrideToolStripMenuItem.CheckState = System.Windows.Forms.CheckState.Checked; - this.snapScrollToNextStrideToolStripMenuItem.Name = "snapScrollToNextStrideToolStripMenuItem"; - this.snapScrollToNextStrideToolStripMenuItem.Size = new System.Drawing.Size(203, 22); - this.snapScrollToNextStrideToolStripMenuItem.Text = "&Snap scroll to next stride"; - this.snapScrollToNextStrideToolStripMenuItem.Click += new System.EventHandler(this.snapScrollToNextStrideToolStripMenuItem_Click); + this.snapScrollToNextStrideOptionsMenuItem.Checked = true; + this.snapScrollToNextStrideOptionsMenuItem.CheckState = System.Windows.Forms.CheckState.Checked; + this.snapScrollToNextStrideOptionsMenuItem.Name = "snapScrollToNextStrideOptionsMenuItem"; + this.snapScrollToNextStrideOptionsMenuItem.Size = new System.Drawing.Size(203, 22); + this.snapScrollToNextStrideOptionsMenuItem.Text = "&Snap scroll to next stride"; + this.snapScrollToNextStrideOptionsMenuItem.Click += new System.EventHandler(this.snapScrollToNextStrideOptionsMenuItem_Click); // - // optionsStripMenuDash2 + // optionsMenuSeparator2 // - this.optionsStripMenuDash2.Name = "optionsStripMenuDash2"; - this.optionsStripMenuDash2.Size = new System.Drawing.Size(200, 6); + this.optionsMenuSeparator2.Name = "optionsMenuSeparator2"; + this.optionsMenuSeparator2.Size = new System.Drawing.Size(200, 6); // - // gridToolStripMenuItem + // gridOptionsMenuItem // - this.gridToolStripMenuItem.Checked = true; - this.gridToolStripMenuItem.CheckState = System.Windows.Forms.CheckState.Checked; - this.gridToolStripMenuItem.Name = "gridToolStripMenuItem"; - this.gridToolStripMenuItem.Size = new System.Drawing.Size(203, 22); - this.gridToolStripMenuItem.Text = "&Grid Padding"; - this.gridToolStripMenuItem.Click += new System.EventHandler(this.gridToolStripMenuItem_Click); + this.gridOptionsMenuItem.Checked = true; + this.gridOptionsMenuItem.CheckState = System.Windows.Forms.CheckState.Checked; + this.gridOptionsMenuItem.Name = "gridOptionsMenuItem"; + this.gridOptionsMenuItem.Size = new System.Drawing.Size(203, 22); + this.gridOptionsMenuItem.Text = "&Grid Padding"; + this.gridOptionsMenuItem.Click += new System.EventHandler(this.gridOptionsMenuItem_Click); // - // optionsStripMenuDash3 + // optionsMenuSeparator3 // - this.optionsStripMenuDash3.Name = "optionsStripMenuDash3"; - this.optionsStripMenuDash3.Size = new System.Drawing.Size(200, 6); + this.optionsMenuSeparator3.Name = "optionsMenuSeparator3"; + this.optionsMenuSeparator3.Size = new System.Drawing.Size(200, 6); // - // verticalLayoutToolStripMenuItem + // verticalLayoutOptionsMenuItem // - this.verticalLayoutToolStripMenuItem.Checked = true; - this.verticalLayoutToolStripMenuItem.CheckState = System.Windows.Forms.CheckState.Checked; - this.verticalLayoutToolStripMenuItem.Name = "verticalLayoutToolStripMenuItem"; - this.verticalLayoutToolStripMenuItem.Size = new System.Drawing.Size(203, 22); - this.verticalLayoutToolStripMenuItem.Text = "&Vertical layout"; - this.verticalLayoutToolStripMenuItem.Click += new System.EventHandler(this.verticalLayoutToolStripMenuItem_Click); + this.verticalLayoutOptionsMenuItem.Checked = true; + this.verticalLayoutOptionsMenuItem.CheckState = System.Windows.Forms.CheckState.Checked; + this.verticalLayoutOptionsMenuItem.Name = "verticalLayoutOptionsMenuItem"; + this.verticalLayoutOptionsMenuItem.Size = new System.Drawing.Size(203, 22); + this.verticalLayoutOptionsMenuItem.Text = "&Vertical layout"; + this.verticalLayoutOptionsMenuItem.Click += new System.EventHandler(this.verticalLayoutOptionsMenuItem_Click); // - // horizontalLayoutToolStripMenuItem + // horizontalLayoutOptionsMenuItem // - this.horizontalLayoutToolStripMenuItem.Name = "horizontalLayoutToolStripMenuItem"; - this.horizontalLayoutToolStripMenuItem.Size = new System.Drawing.Size(203, 22); - this.horizontalLayoutToolStripMenuItem.Text = "H&orizontal layout"; - this.horizontalLayoutToolStripMenuItem.Click += new System.EventHandler(this.horizontalLayoutToolStripMenuItem_Click); + this.horizontalLayoutOptionsMenuItem.Name = "horizontalLayoutOptionsMenuItem"; + this.horizontalLayoutOptionsMenuItem.Size = new System.Drawing.Size(203, 22); + this.horizontalLayoutOptionsMenuItem.Text = "H&orizontal layout"; + this.horizontalLayoutOptionsMenuItem.Click += new System.EventHandler(this.horizontalLayoutOptionsMenuItem_Click); // - // optionsStripMenuDash4 + // optionsMenuSeparator4 // - this.optionsStripMenuDash4.Name = "optionsStripMenuDash4"; - this.optionsStripMenuDash4.Size = new System.Drawing.Size(200, 6); + this.optionsMenuSeparator4.Name = "optionsMenuSeparator4"; + this.optionsMenuSeparator4.Size = new System.Drawing.Size(200, 6); // - // twiddleZToolStripMenuItem + // twiddleZOptionsMenuItem // - this.twiddleZToolStripMenuItem.Name = "twiddleZToolStripMenuItem"; - this.twiddleZToolStripMenuItem.Size = new System.Drawing.Size(203, 22); - this.twiddleZToolStripMenuItem.Text = "Twiddle &Z"; - this.twiddleZToolStripMenuItem.Click += new System.EventHandler(this.twiddleZToolStripMenuItem_Click); + this.twiddleZOptionsMenuItem.Name = "twiddleZOptionsMenuItem"; + this.twiddleZOptionsMenuItem.Size = new System.Drawing.Size(203, 22); + this.twiddleZOptionsMenuItem.Text = "Twiddle &Z"; + this.twiddleZOptionsMenuItem.Click += new System.EventHandler(this.twiddleZOptionsMenuItem_Click); // - // twiddleNToolStripMenuItem + // twiddleNOptionsMenuItem // - this.twiddleNToolStripMenuItem.Name = "twiddleNToolStripMenuItem"; - this.twiddleNToolStripMenuItem.Size = new System.Drawing.Size(203, 22); - this.twiddleNToolStripMenuItem.Text = "Twiddle &N"; - this.twiddleNToolStripMenuItem.Click += new System.EventHandler(this.twiddleNToolStripMenuItem_Click); + this.twiddleNOptionsMenuItem.Name = "twiddleNOptionsMenuItem"; + this.twiddleNOptionsMenuItem.Size = new System.Drawing.Size(203, 22); + this.twiddleNOptionsMenuItem.Text = "Twiddle &N"; + this.twiddleNOptionsMenuItem.Click += new System.EventHandler(this.twiddleNOptionsMenuItem_Click); // // helpToolStripMenuItem // this.helpToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.aboutToolStripMenuItem}); + this.aboutHelpMenuItem}); this.helpToolStripMenuItem.Name = "helpToolStripMenuItem"; this.helpToolStripMenuItem.Size = new System.Drawing.Size(44, 20); this.helpToolStripMenuItem.Text = "&Help"; // - // aboutToolStripMenuItem + // aboutHelpMenuItem // - this.aboutToolStripMenuItem.Name = "aboutToolStripMenuItem"; - this.aboutToolStripMenuItem.Size = new System.Drawing.Size(107, 22); - this.aboutToolStripMenuItem.Text = "&About"; - this.aboutToolStripMenuItem.Click += new System.EventHandler(this.aboutToolStripMenuItem_Click); + this.aboutHelpMenuItem.Name = "aboutHelpMenuItem"; + this.aboutHelpMenuItem.Size = new System.Drawing.Size(107, 22); + this.aboutHelpMenuItem.Text = "&About"; + this.aboutHelpMenuItem.Click += new System.EventHandler(this.aboutHelpMenuItem_Click); // // tableTop // @@ -1285,41 +1285,41 @@ private void InitializeComponent() // contextMenuPixel // this.contextMenuPixel.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.saveImageToolStripMenuItem, - this.saveAllToolStripMenuItem, - this.positionToPixelToolStripMenuItem, - this.pixelsToPaletteToolStripMenuItem}); + this.saveImageContextItem, + this.saveAllContextItem, + this.positionToPixelContextItem, + this.pixelsToPaletteContextItem}); this.contextMenuPixel.Name = "contextMenuPixel"; - this.contextMenuPixel.Size = new System.Drawing.Size(160, 92); + this.contextMenuPixel.Size = new System.Drawing.Size(181, 114); // - // saveImageToolStripMenuItem + // saveImageContextItem // - this.saveImageToolStripMenuItem.Enabled = false; - this.saveImageToolStripMenuItem.Name = "saveImageToolStripMenuItem"; - this.saveImageToolStripMenuItem.Size = new System.Drawing.Size(159, 22); - this.saveImageToolStripMenuItem.Text = "&Save &Image"; - this.saveImageToolStripMenuItem.Click += new System.EventHandler(this.saveImageContextItem_Click); + this.saveImageContextItem.Enabled = false; + this.saveImageContextItem.Name = "saveImageContextItem"; + this.saveImageContextItem.Size = new System.Drawing.Size(180, 22); + this.saveImageContextItem.Text = "&Save &Image"; + this.saveImageContextItem.Click += new System.EventHandler(this.saveImageContextItem_Click); // - // saveAllToolStripMenuItem + // saveAllContextItem // - this.saveAllToolStripMenuItem.Name = "saveAllToolStripMenuItem"; - this.saveAllToolStripMenuItem.Size = new System.Drawing.Size(159, 22); - this.saveAllToolStripMenuItem.Text = "Save &All Visible"; - this.saveAllToolStripMenuItem.Click += new System.EventHandler(this.saveAllVisibleContextItem_Click); + this.saveAllContextItem.Name = "saveAllContextItem"; + this.saveAllContextItem.Size = new System.Drawing.Size(180, 22); + this.saveAllContextItem.Text = "Save &All Visible"; + this.saveAllContextItem.Click += new System.EventHandler(this.saveAllVisibleContextItem_Click); // - // positionToPixelToolStripMenuItem + // positionToPixelContextItem // - this.positionToPixelToolStripMenuItem.Name = "positionToPixelToolStripMenuItem"; - this.positionToPixelToolStripMenuItem.Size = new System.Drawing.Size(159, 22); - this.positionToPixelToolStripMenuItem.Text = "&Position to Pixel"; - this.positionToPixelToolStripMenuItem.Click += new System.EventHandler(this.positionToPixelToolContextItem_Click); + this.positionToPixelContextItem.Name = "positionToPixelContextItem"; + this.positionToPixelContextItem.Size = new System.Drawing.Size(180, 22); + this.positionToPixelContextItem.Text = "&Position to Pixel"; + this.positionToPixelContextItem.Click += new System.EventHandler(this.positionToPixelToolContextItem_Click); // - // pixelsToPaletteToolStripMenuItem + // pixelsToPaletteContextItem // - this.pixelsToPaletteToolStripMenuItem.Name = "pixelsToPaletteToolStripMenuItem"; - this.pixelsToPaletteToolStripMenuItem.Size = new System.Drawing.Size(159, 22); - this.pixelsToPaletteToolStripMenuItem.Text = "Pi&xels to Palette"; - this.pixelsToPaletteToolStripMenuItem.Click += new System.EventHandler(this.pixelsToPaletteToolStripMenuItem_Click); + this.pixelsToPaletteContextItem.Name = "pixelsToPaletteContextItem"; + this.pixelsToPaletteContextItem.Size = new System.Drawing.Size(180, 22); + this.pixelsToPaletteContextItem.Text = "Pi&xels to Palette"; + this.pixelsToPaletteContextItem.Click += new System.EventHandler(this.pixelsToPaletteContextItem_Click); // // pixelScroll // @@ -1394,10 +1394,10 @@ private void InitializeComponent() private System.Windows.Forms.MenuStrip menuStripMain; private System.Windows.Forms.ToolStripMenuItem fileToolStripMenuItem; - private System.Windows.Forms.ToolStripMenuItem openToolStripMenuItem; - private System.Windows.Forms.ToolStripMenuItem exitToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem openFileMenuItem; + private System.Windows.Forms.ToolStripMenuItem exitFileMenuItem; private System.Windows.Forms.ToolStripMenuItem helpToolStripMenuItem; - private System.Windows.Forms.ToolStripMenuItem aboutToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem aboutHelpMenuItem; private System.Windows.Forms.TableLayoutPanel tableTop; private System.Windows.Forms.GroupBox groupPacking; private System.Windows.Forms.GroupBox groupPalette; @@ -1435,15 +1435,15 @@ private void InitializeComponent() private System.Windows.Forms.NumericUpDown numericPosBit; private System.Windows.Forms.NumericUpDown numericPosByte; private System.Windows.Forms.NumericUpDown numericZoom; - private System.Windows.Forms.ToolStripMenuItem reloadPresetsToolStripMenuItem; - private System.Windows.Forms.ToolStripSeparator presetStripMenuDash; + private System.Windows.Forms.ToolStripMenuItem reloadPresetMenuItem; + private System.Windows.Forms.ToolStripSeparator presetMenuSeparator; private System.Windows.Forms.DataGridViewTextBoxColumn order; private System.Windows.Forms.DataGridViewTextBoxColumn offByte; private System.Windows.Forms.DataGridViewTextBoxColumn offBit; private System.Windows.Forms.ContextMenuStrip contextMenuPixel; - private System.Windows.Forms.ToolStripMenuItem saveImageToolStripMenuItem; - private System.Windows.Forms.ToolStripMenuItem saveAllToolStripMenuItem; - private System.Windows.Forms.ToolStripMenuItem saveAllVisibleToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem saveImageContextItem; + private System.Windows.Forms.ToolStripMenuItem saveAllContextItem; + private System.Windows.Forms.ToolStripMenuItem saveAllVisibleFileMenuItem; private System.Windows.Forms.CheckBox checkAutoNext; private System.Windows.Forms.CheckBox checkAutoRow; private System.Windows.Forms.CheckBox checkAutoPixel; @@ -1460,8 +1460,8 @@ private void InitializeComponent() private System.Windows.Forms.Label labelTileStride; private System.Windows.Forms.Label labelTileSize; private System.Windows.Forms.ToolStripMenuItem optionsToolStripMenuItem; - private System.Windows.Forms.ToolStripMenuItem decimalPositionToolStripMenuItem; - private System.Windows.Forms.ToolStripMenuItem hexadecimalPositionToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem decimalPositionOptionsMenuItem; + private System.Windows.Forms.ToolStripMenuItem hexadecimalPositionOptionsMenuItem; private System.Windows.Forms.Button buttonBytePos; private System.Windows.Forms.ToolTip toolTip; private System.Windows.Forms.Button buttonNext; @@ -1470,23 +1470,23 @@ private void InitializeComponent() private System.Windows.Forms.Button buttonBitPos; private System.Windows.Forms.Button buttonZoom; private System.Windows.Forms.Button buttonZero; - private System.Windows.Forms.ToolStripSeparator optionsStripMenuDash1; - private System.Windows.Forms.ToolStripMenuItem snapScrollToNextStrideToolStripMenuItem; - private System.Windows.Forms.ToolStripSeparator optionsStripMenuDash3; - private System.Windows.Forms.ToolStripMenuItem verticalLayoutToolStripMenuItem; - private System.Windows.Forms.ToolStripMenuItem horizontalLayoutToolStripMenuItem; - private System.Windows.Forms.ToolStripMenuItem twiddleZToolStripMenuItem; - private System.Windows.Forms.ToolStripSeparator optionsStripMenuDash4; - private System.Windows.Forms.ToolStripMenuItem twiddleNToolStripMenuItem; - private System.Windows.Forms.ToolStripSeparator optionsStripMenuDash2; - private System.Windows.Forms.ToolStripMenuItem gridToolStripMenuItem; - private System.Windows.Forms.ToolStripMenuItem exportBinaryChunkToolStripMenuItem; - private System.Windows.Forms.ToolStripSeparator toolStripSeparator1; - private System.Windows.Forms.ToolStripMenuItem positionToPixelToolStripMenuItem; - private System.Windows.Forms.ToolStripMenuItem reloadFileToolStripMenuItem; + private System.Windows.Forms.ToolStripSeparator optionsMenuSeparator1; + private System.Windows.Forms.ToolStripMenuItem snapScrollToNextStrideOptionsMenuItem; + private System.Windows.Forms.ToolStripSeparator optionsMenuSeparator3; + private System.Windows.Forms.ToolStripMenuItem verticalLayoutOptionsMenuItem; + private System.Windows.Forms.ToolStripMenuItem horizontalLayoutOptionsMenuItem; + private System.Windows.Forms.ToolStripMenuItem twiddleZOptionsMenuItem; + private System.Windows.Forms.ToolStripSeparator optionsMenuSeparator4; + private System.Windows.Forms.ToolStripMenuItem twiddleNOptionsMenuItem; + private System.Windows.Forms.ToolStripSeparator optionsMenuSeparator2; + private System.Windows.Forms.ToolStripMenuItem gridOptionsMenuItem; + private System.Windows.Forms.ToolStripMenuItem exportBinaryChunkFileMenuItem; + private System.Windows.Forms.ToolStripSeparator fileMenuSeparator; + private System.Windows.Forms.ToolStripMenuItem positionToPixelContextItem; + private System.Windows.Forms.ToolStripMenuItem reloadFileMenuItem; private System.Windows.Forms.Button buttonAutoPal; private System.Windows.Forms.ComboBox comboBoxPalette; - private System.Windows.Forms.ToolStripMenuItem pixelsToPaletteToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem pixelsToPaletteContextItem; } } diff --git a/BinxelviewForm.cs b/BinxelviewForm.cs index a23a758..bd6d242 100644 --- a/BinxelviewForm.cs +++ b/BinxelviewForm.cs @@ -34,6 +34,8 @@ enum PaletteMode int selected_tile = -1; long selected_pos = -1; int selected_palette_filter = 0; + int option_palette_type; + string palette_path = ""; Preset preset; Preset default_preset; @@ -54,14 +56,17 @@ enum PaletteMode Random random = new Random(); // settings - int zoom = 2; - bool hidegrid = false; - Color background = SystemColors.Control; - PaletteMode palette_mode = PaletteMode.PALETTE_RGB; - bool decimal_position = false; - bool snap_scroll = true; - bool horizontal_layout = false; - int twiddle = 0; + int zoom; + bool hidegrid; + Color background; + PaletteMode palette_mode; + bool decimal_position; + bool snap_scroll; + bool horizontal_layout; + int twiddle; // Twiddle probably belongs in preset, but its use is very rare, and I didn't want it to take up panel space. + // If something more important needs a PRESET_VERSION 3, we should add it then to the preset. + // We could maybe place rare options like this into an "advanced" menu on the menu bar, + // instead of requiring UI panel space for it. // // Preset @@ -293,7 +298,19 @@ public bool loadFile(string path) // Options // - string parseOption(string optline) + void defaultOption() + { + zoom = 2; + hidegrid = false; + background = SystemColors.Control; + palette_mode = PaletteMode.PALETTE_RGB; + decimal_position = false; + snap_scroll = true; + horizontal_layout = false; + twiddle = 0; + } + + string parseOption(string optline, string base_path, bool ini_file) { int eqpos = optline.IndexOf("="); if (eqpos < 0) return "No = in option: "+optline; @@ -303,8 +320,10 @@ string parseOption(string optline) if (opt == "PRESETFILE") // load preset file to replace default { + string path = val; + if (!Path.IsPathRooted(path)) path = Path.Combine(base_path,path); Preset p = new Preset(); - if (!p.loadFile(val)) return "Could not load preset file: "+val+"\n"+Preset.last_error; + if (!p.loadFile(path)) return "Could not load preset file: "+path+"\n"+Preset.last_error; default_preset = p; preset = default_preset.copy(); return ""; @@ -321,8 +340,18 @@ string parseOption(string optline) } return "Preset not found in loaded presets: "+val; } + if (opt == "PALTYPE") // override next PAL file type detection, use before PAL + { + int v; + if (!int.TryParse(val,out v)) return "Could not parse integer for paltype: "+val; + option_palette_type = v; + return ""; + } if (opt == "PAL") // load palette file { + string path = val; + if (!Path.IsPathRooted(path)) path = Path.Combine(base_path,path); + int paltype = 0; if ( valu.EndsWith(".BMP") || @@ -332,7 +361,12 @@ string parseOption(string optline) paltype = 1; if (valu.EndsWith(".VGA")) paltype = 2; if (valu.EndsWith(".RIFF")) paltype = 3; - if (!loadPalette(val,paltype)) return "Could not load palette file: "+val+"\n"+palette_error; + if (option_palette_type != -1) + { + paltype = option_palette_type; + option_palette_type = -1; + } + if (!loadPalette(path,paltype)) return "Could not load palette file: "+path+"\n"+palette_error; return ""; } if (opt == "AUTOPAL") @@ -342,7 +376,6 @@ string parseOption(string optline) else if (valu == "GREYSCALE") { palette_mode = PaletteMode.PALETTE_GREY; } else if (valu == "CUBEHELIX") { palette_mode = PaletteMode.PALETTE_CUBEHELIX; } else return "Unknown autopal value: "+val; - comboBoxPalette.SelectedIndex = (int)palette_mode - 1; return ""; } if (opt == "BACKGROUND") @@ -360,7 +393,6 @@ string parseOption(string optline) if (!int.TryParse(val,out v)) return "Could not parse integer for zoom: "+val; if (v < 1) return "Zoom must be 1 or greater: "+val; zoom = v; - numericZoom.Value = v; return ""; } if (opt == "GRID") @@ -369,7 +401,6 @@ string parseOption(string optline) if (!int.TryParse(val,out v)) return "Could not parse integer for grid: "+val; if (v != 0 && v != 1) return "Grid value must be 0 or 1: "+val; hidegrid = (v == 0); - gridToolStripMenuItem.Checked = !hidegrid; return ""; } if (opt == "HEXPOS") @@ -378,9 +409,6 @@ string parseOption(string optline) if (!int.TryParse(val,out v)) return "Could not parse integer for hexpos: "+val; if (v != 0 && v != 1) return "Hexpos value must be 0 or 1: "+val; decimal_position = (v == 0); - decimalPositionToolStripMenuItem.Checked = decimal_position; - hexadecimalPositionToolStripMenuItem.Checked = !decimal_position; - numericPosByte.Font = decimal_position ? posfont_regular : posfont_bold; return ""; } if (opt == "SNAPSCROLL") @@ -389,7 +417,6 @@ string parseOption(string optline) if (!int.TryParse(val,out v)) return "Could not parse integer for snapscroll: "+val; if (v != 0 && v != 1) return "Snapscroll value must be 0 or 1: "+val; snap_scroll = (v != 0); - snapScrollToNextStrideToolStripMenuItem.Checked = snap_scroll; return ""; } if (opt == "HORIZONTAL") @@ -398,8 +425,6 @@ string parseOption(string optline) if (!int.TryParse(val,out v)) return "Could not parse integer for horizontal: "+val; if (v != 0 && v != 1) return "Horizontal value must be 0 or 1: "+val; horizontal_layout = (v != 0); - verticalLayoutToolStripMenuItem.Checked = !horizontal_layout; - horizontalLayoutToolStripMenuItem.Checked = horizontal_layout; return ""; } if (opt == "TWIDDLE") @@ -408,8 +433,6 @@ string parseOption(string optline) if (!int.TryParse(val,out v)) return "Could not parse integer for twiddle: "+val; if (v < 0 || v > 2) return "Twiddle value must be 0, 1 or 2: "+val; twiddle = v; - twiddleZToolStripMenuItem.Checked = twiddle == 1; - twiddleNToolStripMenuItem.Checked = twiddle == 2; return ""; } return "Invalid option: "+optline; @@ -784,7 +807,7 @@ Bitmap renderGridIndexToBitmap() // internal range values for automatic palette generation int palette_rshift=0, palette_gshift=0, palette_bshift=0; int palette_rmask=1, palette_gmask=1, palette_bmask=1; - long palette_greymask; + long palette_greymax; void setPalette(int i, int r, int g, int b) // set a palette colour { @@ -795,7 +818,7 @@ void setPalette(int i, int r, int g, int b) // set a palette colour void autoPaletteSetup() // setup range values for automatic palettes { // greyscale range - palette_greymask = (1L << preset.bpp) - 1L; + palette_greymax = (1L << preset.bpp) - 1L; // RGB range int rb = preset.bpp / 3; // assign least bits to blue @@ -816,8 +839,7 @@ unsafe int cubeHelix(long x) { // Dave Green's cubehelix as described and implemented here: // https://people.phy.cam.ac.uk/dag9/CUBEHELIX/ - // https://people.phy.cam.ac.uk/dag9/CUBEHELIX/cubetry.html - double fract = (double)x / (double)palette_greymask; + double fract = (double)x / (double)palette_greymax; const double start = 0.5; // starting colour const double rotations = -2.0; // hue cycles across gradient, default was -1.5 const double saturation = 1.8; // default was 1.0 @@ -853,7 +875,7 @@ unsafe int autoPaletteRaw(long x) // generated palettes return b | (g << 8) | (r << 16) | unchecked((int)0xFF000000); case PaletteMode.PALETTE_GREY: long lx = (x >= 0) ? x : (x + (1L << 32)); - int grey = (int)((lx * 255L) / palette_greymask); + int grey = (int)((lx * 255L) / palette_greymax); return grey | (grey << 8) | (grey << 16) | unchecked((int)0xFF000000); case PaletteMode.PALETTE_CUBEHELIX: return cubeHelix(x); @@ -885,6 +907,7 @@ void randomPalette() random.Next() & 255, random.Next() & 255); } + palette_path = ""; } void autoPalette() // regenerate automatic palettes @@ -893,6 +916,7 @@ void autoPalette() // regenerate automatic palettes if (palette_mode == PaletteMode.PALETTE_CUSTOM) return; if (palette_mode == PaletteMode.PALETTE_RANDOM) { randomPalette(); return; } if (preset.bpp > PALETTE_BITS) return; + palette_path = ""; for (int i=0; i < (1 << preset.bpp); ++i) { int p = autoPaletteRaw(i); @@ -903,17 +927,6 @@ void autoPalette() // regenerate automatic palettes } } - void refreshPalette() - { - autoPaletteSetup(); - // disable these if BPP is too high to use an actual palette - bool palenable = preset.bpp <= PALETTE_BITS; - buttonLoadPal.Enabled = palenable; - buttonSavePal.Enabled = palenable; - pixelsToPaletteToolStripMenuItem.Enabled = palenable; - redrawPalette(); - } - // // Position and Scroll // @@ -960,6 +973,29 @@ void normalizePos() updatePos(); } + void advanceClick(int inc_byte, int inc_bit) + { + if ((Control.ModifierKeys & Keys.Shift) != 0) + { + pos_byte -= inc_byte; + pos_bit -= inc_bit; + } + else + { + pos_byte += inc_byte; + pos_bit += inc_bit; + } + normalizePos(); + } + + void advanceMouseDown(MouseEventArgs e, int inc_byte, int inc_bit) + { + if (e.Button != MouseButtons.Right) return; + pos_byte -= inc_byte; + pos_bit -= inc_bit; + normalizePos(); + } + // // Files // @@ -1092,6 +1128,8 @@ bool loadPalette(string path, int filetype) setPalette(i, c.R, c.G, c.B); } img.Dispose(); + + palette_path = Path.GetFullPath(path); return true; } @@ -1191,6 +1229,8 @@ bool loadPalette(string path, int filetype) } setPalette(i, r, g, b); } + + palette_path = Path.GetFullPath(path); return true; } @@ -1293,6 +1333,7 @@ void redrawPreset() preset.next_stride_bit = bits & 7; } + bool old_disable_pixel_redraw = disable_pixel_redraw; disable_pixel_redraw = true; // prevent Value events from redrawing pixels checkEndian.Checked = !preset.little_endian; @@ -1342,11 +1383,18 @@ void redrawPreset() dataGridPixel.FirstDisplayedScrollingRowIndex = old_scroll; dataGridPixel.Enabled = !preset.chunky; - disable_pixel_redraw = false; + disable_pixel_redraw = old_disable_pixel_redraw; // restore pixel redraw } void redrawPalette() { + autoPaletteSetup(); + // disable these if BPP is too high to use an actual palette + bool palenable = preset.bpp <= PALETTE_BITS; + buttonLoadPal.Enabled = palenable; + buttonSavePal.Enabled = palenable; + pixelsToPaletteContextItem.Enabled = palenable; + int bx = preset.bpp / 2; int by = preset.bpp - bx; for (int y = 0; y < PALETTE_DIM; ++y) @@ -1363,16 +1411,28 @@ void redrawPalette() paletteBox.Refresh(); } - // - // Forms designer linked code - // - - public BinxelviewForm() + void redrawOptions() // make sure the UI state matches current options { - InitializeComponent(); + numericZoom.Value = zoom; + gridOptionsMenuItem.Checked = !hidegrid; + decimalPositionOptionsMenuItem.Checked = decimal_position; + hexadecimalPositionOptionsMenuItem.Checked = !decimal_position; + numericPosByte.Font = decimal_position ? posfont_regular : posfont_bold; + snapScrollToNextStrideOptionsMenuItem.Checked = snap_scroll; + if (palette_mode != PaletteMode.PALETTE_CUSTOM) + comboBoxPalette.SelectedIndex = (int)palette_mode - 1; + verticalLayoutOptionsMenuItem.Checked = !horizontal_layout; + horizontalLayoutOptionsMenuItem.Checked = horizontal_layout; + twiddleZOptionsMenuItem.Checked = twiddle == 1; + twiddleNOptionsMenuItem.Checked = twiddle == 2; + bgBox.BackColor = background; } - private void openToolStripMenuItem_Click(object sender, EventArgs e) + // + // Menu (Design Linked) + // + + private void openFileMenuItem_Click(object sender, EventArgs e) { OpenFileDialog d = new OpenFileDialog(); d.Title = "Load Binary File"; @@ -1382,7 +1442,7 @@ private void openToolStripMenuItem_Click(object sender, EventArgs e) } } - private void reloadFileToolStripMenuItem_Click(object sender, EventArgs e) + private void reloadFileMenuItem_Click(object sender, EventArgs e) { if (data_path.Length > 0) { @@ -1390,209 +1450,301 @@ private void reloadFileToolStripMenuItem_Click(object sender, EventArgs e) } } - private void exitToolStripMenuItem_Click(object sender, EventArgs e) + private void saveAllVisibleFileMenuItem_Click(object sender, EventArgs e) { - this.Close(); - } - - private void BinxelviewForm_Load(object sender, EventArgs e) - { - posfont_regular = new Font(numericPosByte.Font, FontStyle.Regular); - posfont_bold = new Font(numericPosByte.Font, FontStyle.Bold); - - // initialize Auto palette selection - comboBoxPalette.SelectedIndex = (int)PaletteMode.PALETTE_RGB - 1; + long pos = (pos_byte * 8) + pos_bit; - // setup presets - default_preset.empty(); - reloadPresets(); // loads "Default" preset if it exists - preset = default_preset.copy(); + SaveFileDialog d = new SaveFileDialog(); + d.Title = "Save All Visible"; + d.DefaultExt = "png"; + d.Filter = "PNG Image (*.png)|*.png|All files (*.*)|*.*"; + d.FileName = data_file + string.Format(".{0:X8}.{1:D1}.png",pos>>3,pos&7); + if (d.ShowDialog() == DialogResult.OK) + { + int w = pixel_gx * pixel_twp + pixel_padx; + int h = pixel_gy * pixel_thp + pixel_pady; + renderGrid(pos, pixel_gx, pixel_gy, pixel_padx, pixel_pady, w, h, true); - // load default palette if it exists - DirectoryInfo dir_cwd = new DirectoryInfo("."); - DirectoryInfo dir_app = new DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory); - string pal_cwd = Path.Combine(dir_cwd.ToString(),"default.pal"); - string pal_app = Path.Combine(dir_app.ToString(),"default.pal"); - bool success = true; - if (File.Exists(pal_cwd)) { success = loadPalette(pal_cwd,0); } - else if (File.Exists(pal_app)) { success = loadPalette(pal_app,0); } - if (!success) MessageBox.Show("Error opening default palette:\n" + palette_error,"Binxelview"); + Bitmap b; + if (preset.bpp <= 8) + { + b = renderGridIndexToBitmap(); + } + else + { + b = new Bitmap(w, h, PixelFormat.Format32bppArgb); + renderGridColorToBitmap(b, 1); + } - // parse the command line options - string[] args = Environment.GetCommandLineArgs(); - string arg_err = ""; - for (int i=1; i 0 && arg_err.Length > 0) arg_err += "\n"; - arg_err += opt_err; + MessageBox.Show("Unable to save image:\n" + d.FileName + "\n\n" + ex.ToString(), "Binxelview"); } - } - if (arg_err.Length > 0) MessageBox.Show("Command line error:\n" + arg_err,"Binxelview"); - scrollRange(); - redrawPreset(); - autoPalette(); - refreshPalette(); - bgBox.BackColor = background; - redrawPixels(); - numericPosByte.Font = decimal_position ? posfont_regular : posfont_bold; + redrawPixels(); + } } - private void BinxelviewForm_DragDrop(object sender, DragEventArgs e) + private void exportBinaryChunkFileMenuItem_Click(object sender, EventArgs e) { - string[] files = (string[])e.Data.GetData(DataFormats.FileDrop, false); - foreach (string file in files) openFile(file); + BinaryChunkExportForm exportForm = new BinaryChunkExportForm(pos_byte, !decimal_position, data); + exportForm.ShowDialog(); } - private void BinxelviewForm_DragEnter(object sender, DragEventArgs e) + private void exitFileMenuItem_Click(object sender, EventArgs e) { - e.Effect = (e.Data.GetDataPresent(DataFormats.FileDrop)) ? - DragDropEffects.Copy : DragDropEffects.None; + this.Close(); } - - private void aboutToolStripMenuItem_Click(object sender, EventArgs e) + private void reloadPresetsToolStripMenuItem_Click(object sender, EventArgs e) { - string about = - "Binxelview binary image explorer\n" + - System.Reflection.Assembly.GetEntryAssembly().GetName().Version.ToString() + "\n" + - "\n" + - "https://github.com/bbbradsmith/binxelview"; - MessageBox.Show(about, "Binxelview"); + reloadPresets(); } - void presetMenu_Select(object sender, EventArgs e) + void presetMenu_Select(object sender, EventArgs e) // clicking on a generated preset menu item { ToolStripMenuItem item = (ToolStripMenuItem)sender; int index = (int)item.Tag; int old_bpp = preset.bpp; preset = presets[index].copy(); - scrollRange(); - redrawPreset(); if (old_bpp != preset.bpp && palette_mode != PaletteMode.PALETTE_RANDOM) autoPalette(); - refreshPalette(); + redrawPalette(); + redrawPreset(); + scrollRange(); } - private void reloadPresetsToolStripMenuItem_Click(object sender, EventArgs e) + private void decimalPositionOptionsMenuItem_Click(object sender, EventArgs e) { - reloadPresets(); + decimal_position = true; + redrawOptions(); + updatePos(); } - private void buttonDefaultPreset_Click(object sender, EventArgs e) + private void hexadecimalPositionOptionsMenuItem_Click(object sender, EventArgs e) { - int old_bpp = preset.bpp; - preset = default_preset.copy(); - scrollRange(); - if (old_bpp != preset.bpp && palette_mode != PaletteMode.PALETTE_RANDOM) autoPalette(); - refreshPalette(); - redrawPreset(); + decimal_position = false; + redrawOptions(); + updatePos(); } - private void buttonLoadPreset_Click(object sender, EventArgs e) + private void snapScrollToNextStrideOptionsMenuItem_Click(object sender, EventArgs e) { - OpenFileDialog d = new OpenFileDialog(); - d.Title = "Load Preset"; - d.DefaultExt = "bxp"; - d.Filter = "Binxelview Preset (*.bxp)|*.bxp|All files (*.*)|*.*"; - if (d.ShowDialog() == DialogResult.OK) - { - Preset p = new Preset(); - if (p.loadFile(d.FileName)) - { - int old_bpp = preset.bpp; - preset = p; - scrollRange(); - if (old_bpp != preset.bpp && palette_mode != PaletteMode.PALETTE_RANDOM) autoPalette(); - refreshPalette(); - redrawPreset(); - } - else - { - MessageBox.Show("Unable to load preset:\n" + d.FileName + "\n\n" + Preset.last_error, "Binxelview"); - } - } + snap_scroll = !snap_scroll; + redrawOptions(); + scrollRange(); } - private void buttonSavePreset_Click(object sender, EventArgs e) + private void gridOptionsMenuItem_Click(object sender, EventArgs e) { - SaveFileDialog d = new SaveFileDialog(); - d.Title = "Save Preset"; - d.DefaultExt = "bxp"; - d.Filter = "Binxelview Preset (*.bxp)|*.bxp|All files (*.*)|*.*"; - if (d.ShowDialog() == DialogResult.OK) - { - if (!preset.saveFile(d.FileName)) - { - MessageBox.Show("Unable to save preset:\n" + d.FileName + "\n\n" + Preset.last_error, "Binxelview"); - } - else - { - reloadPresets(); - } - } + hidegrid = !hidegrid; + redrawOptions(); + redrawPixels(); } - private void checkEndian_CheckedChanged(object sender, EventArgs e) + private void verticalLayoutOptionsMenuItem_Click(object sender, EventArgs e) { - preset.little_endian = !checkEndian.Checked; + horizontal_layout = false; + redrawOptions(); redrawPixels(); } - private void checkChunky_CheckedChanged(object sender, EventArgs e) + private void horizontalLayoutOptionsMenuItem_Click(object sender, EventArgs e) { - preset.chunky = checkChunky.Checked; - redrawPreset(); + horizontal_layout = true; + redrawOptions(); redrawPixels(); } - private void numericBPP_ValueChanged(object sender, EventArgs e) + private void twiddleZOptionsMenuItem_Click(object sender, EventArgs e) { - int old_bpp = preset.bpp; - preset.bpp = (int)numericBPP.Value; - if (old_bpp != preset.bpp && palette_mode != PaletteMode.PALETTE_RANDOM) autoPalette(); - refreshPalette(); - redrawPreset(); + if (twiddle == 1) twiddle = 0; + else twiddle = 1; + redrawOptions(); redrawPixels(); } - private void numericWidth_ValueChanged(object sender, EventArgs e) + private void twiddleNOptionsMenuItem_Click(object sender, EventArgs e) { - preset.width = (int)numericWidth.Value; - redrawPreset(); + if (twiddle == 2) twiddle = 0; + else twiddle = 2; + redrawOptions(); redrawPixels(); } - private void numericHeight_ValueChanged(object sender, EventArgs e) + private void aboutHelpMenuItem_Click(object sender, EventArgs e) { - preset.height = (int)numericHeight.Value; - redrawPreset(); - redrawPixels(); + string about = + "Binxelview binary image explorer\n" + + System.Reflection.Assembly.GetEntryAssembly().GetName().Version.ToString() + "\n" + + "\n" + + "https://github.com/bbbradsmith/binxelview"; + MessageBox.Show(about, "Binxelview"); } - private void numericPixelStrideByte_ValueChanged(object sender, EventArgs e) + // + // Position Panel (Design Linked) + // + + private void buttonBytePos_Click(object sender, EventArgs e) { - preset.pixel_stride_byte = (int)numericPixelStrideByte.Value; - redrawPreset(); - redrawPixels(); - } + advanceClick(1, 0); - private void numericRowStrideByte_ValueChanged(object sender, EventArgs e) + } + private void buttonBytePos_MouseDown(object sender, MouseEventArgs e) { - preset.row_stride_byte = (int)numericRowStrideByte.Value; - redrawPreset(); - redrawPixels(); + advanceMouseDown(e, 1, 0); } - private void numericNextStrideByte_ValueChanged(object sender, EventArgs e) + private void buttonBitPos_Click(object sender, EventArgs e) + { + advanceClick(0, 1); + } + + private void buttonBitPos_MouseDown(object sender, MouseEventArgs e) + { + advanceMouseDown(e, 0, 1); + } + + private void buttonZoom_Click(object sender, EventArgs e) + { + if ((Control.ModifierKeys & Keys.Shift) != 0) + { + --zoom; + } + else + { + ++zoom; + } + if (zoom < numericZoom.Minimum) zoom = (int)numericZoom.Minimum; // TODO replace with ZOOM_MIN ZOOM_MAX + if (zoom > numericZoom.Maximum) zoom = (int)numericZoom.Maximum; + redrawOptions(); + redrawPixels(); + + } + private void buttonZoom_MouseDown(object sender, MouseEventArgs e) + { + if (e.Button != MouseButtons.Right) return; + --zoom; + if (zoom < numericZoom.Minimum) zoom = (int)numericZoom.Minimum; // TODO replace with ZOOM_MIN ZOOM_MAX + redrawOptions(); + redrawPixels(); + } + + private void buttonZero_Click(object sender, EventArgs e) + { + pos_byte = 0; + pos_bit = 0; + updatePos(); + } + + private void numericPosByte_ValueChanged(object sender, EventArgs e) + { + pos_byte = (long)numericPosByte.Value; + updatePos(); + redrawPixels(); + } + + private void numericPosBit_ValueChanged(object sender, EventArgs e) + { + pos_bit = (int)numericPosBit.Value; + redrawPixels(); + } + + private void numericZoom_ValueChanged(object sender, EventArgs e) + { + zoom = (int)numericZoom.Value; + redrawPixels(); + } + + // + // Packing Panel (Design Linked) + // + + private void checkEndian_CheckedChanged(object sender, EventArgs e) + { + preset.little_endian = !checkEndian.Checked; + redrawPixels(); + } + + private void checkChunky_CheckedChanged(object sender, EventArgs e) + { + preset.chunky = checkChunky.Checked; + redrawPreset(); + redrawPixels(); + } + + private void numericBPP_ValueChanged(object sender, EventArgs e) + { + int old_bpp = preset.bpp; + preset.bpp = (int)numericBPP.Value; + if (old_bpp != preset.bpp && palette_mode != PaletteMode.PALETTE_RANDOM) autoPalette(); + redrawPalette(); + redrawPreset(); + redrawPixels(); + } + + private void numericWidth_ValueChanged(object sender, EventArgs e) + { + preset.width = (int)numericWidth.Value; + redrawPreset(); + redrawPixels(); + } + + private void numericHeight_ValueChanged(object sender, EventArgs e) + { + preset.height = (int)numericHeight.Value; + redrawPreset(); + redrawPixels(); + } + + private void buttonPixel_Click(object sender, EventArgs e) + { + advanceClick(preset.pixel_stride_byte, preset.pixel_stride_bit); + } + + private void buttonPixel_MouseDown(object sender, MouseEventArgs e) + { + advanceMouseDown(e, preset.pixel_stride_byte, preset.pixel_stride_bit); + } + + private void buttonRow_Click(object sender, EventArgs e) + { + advanceClick(preset.row_stride_byte, preset.row_stride_bit); + } + + private void buttonRow_MouseDown(object sender, MouseEventArgs e) + { + advanceMouseDown(e, preset.row_stride_byte, preset.row_stride_bit); + } + + private void buttonNext_Click(object sender, EventArgs e) + { + advanceClick(next_increment_byte, next_increment_bit); + } + + private void buttonNext_MouseDown(object sender, MouseEventArgs e) + { + advanceMouseDown(e, next_increment_byte, next_increment_bit); + } + + private void numericPixelStrideByte_ValueChanged(object sender, EventArgs e) + { + preset.pixel_stride_byte = (int)numericPixelStrideByte.Value; + redrawPreset(); + redrawPixels(); + } + + private void numericRowStrideByte_ValueChanged(object sender, EventArgs e) + { + preset.row_stride_byte = (int)numericRowStrideByte.Value; + redrawPreset(); + redrawPixels(); + } + + private void numericNextStrideByte_ValueChanged(object sender, EventArgs e) { preset.next_stride_byte = (int)numericNextStrideByte.Value; scrollRange(); @@ -1642,6 +1794,92 @@ private void checkAutoNext_CheckedChanged(object sender, EventArgs e) redrawPixels(); } + private void buttonDefaultPreset_Click(object sender, EventArgs e) + { + int old_bpp = preset.bpp; + preset = default_preset.copy(); + if (old_bpp != preset.bpp && palette_mode != PaletteMode.PALETTE_RANDOM) autoPalette(); + redrawPalette(); + redrawPreset(); + scrollRange(); + } + + private void buttonLoadPreset_Click(object sender, EventArgs e) + { + OpenFileDialog d = new OpenFileDialog(); + d.Title = "Load Preset"; + d.DefaultExt = "bxp"; + d.Filter = "Binxelview Preset (*.bxp)|*.bxp|All files (*.*)|*.*"; + if (d.ShowDialog() == DialogResult.OK) + { + Preset p = new Preset(); + if (p.loadFile(d.FileName)) + { + int old_bpp = preset.bpp; + preset = p; + if (old_bpp != preset.bpp && palette_mode != PaletteMode.PALETTE_RANDOM) autoPalette(); + redrawPalette(); + redrawPreset(); + scrollRange(); + } + else + { + MessageBox.Show("Unable to load preset:\n" + d.FileName + "\n\n" + Preset.last_error, "Binxelview"); + } + } + } + + private void buttonSavePreset_Click(object sender, EventArgs e) + { + SaveFileDialog d = new SaveFileDialog(); + d.Title = "Save Preset"; + d.DefaultExt = "bxp"; + d.Filter = "Binxelview Preset (*.bxp)|*.bxp|All files (*.*)|*.*"; + if (d.ShowDialog() == DialogResult.OK) + { + if (!preset.saveFile(d.FileName)) + { + MessageBox.Show("Unable to save preset:\n" + d.FileName + "\n\n" + Preset.last_error, "Binxelview"); + } + else + { + reloadPresets(); + } + } + } + + private void dataGridPixel_CellValidating(object sender, DataGridViewCellValidatingEventArgs e) + { + int result; + if (!int.TryParse(e.FormattedValue.ToString(), out result)) + { + e.Cancel = true; + } + } + + private void dataGridPixel_CellValueChanged(object sender, DataGridViewCellEventArgs e) + { + int x = e.ColumnIndex; + int y = e.RowIndex; + if (x < 1) return; + if (x > 2) return; + if (y < 0) return; + if (y >= MAX_BPP) return; + + int result; + string value = (string)dataGridPixel.Rows[y].Cells[x].Value; + if (int.TryParse(value,out result)) + { + if (x == 1) preset.bit_stride_byte[y] = result; + if (x == 2) preset.bit_stride_bit[y] = result; + redrawPixels(); + } + } + + // + // Tiling Panel (Design Linked) + // + private void numericTileSizeX_ValueChanged(object sender, EventArgs e) { preset.tile_size_x = (int)numericTileSizeX.Value; @@ -1678,22 +1916,9 @@ private void numericTileStrideBitY_ValueChanged(object sender, EventArgs e) redrawPixels(); } - private void buttonAutoPal_Click(object sender, EventArgs e) - { - palette_mode = (PaletteMode)(comboBoxPalette.SelectedIndex + 1); - autoPalette(); - refreshPalette(); - redrawPixels(); - } - - private void comboBoxPalette_SelectedIndexChanged(object sender, EventArgs e) - { - // generate new palette if we were previously using an automatic palette - if (palette_mode != PaletteMode.PALETTE_CUSTOM) - { - buttonAutoPal_Click(sender, e); - } - } + // + // Palette Panel (Design Linked) + // private void paletteBox_MouseMove(object sender, MouseEventArgs e) { @@ -1728,7 +1953,7 @@ private void paletteBox_MouseClick(object sender, MouseEventArgs e) setPalette((int)index, d.Color.R, d.Color.G, d.Color.B); redrawPixels(); } - refreshPalette(); + redrawPalette(); } private void bgBox_Click(object sender, EventArgs e) @@ -1745,6 +1970,23 @@ private void bgBox_Click(object sender, EventArgs e) } } + private void buttonAutoPal_Click(object sender, EventArgs e) + { + palette_mode = (PaletteMode)(comboBoxPalette.SelectedIndex + 1); + autoPalette(); + redrawPalette(); + redrawPixels(); + } + + private void comboBoxPalette_SelectedIndexChanged(object sender, EventArgs e) + { + // generate new palette if we were previously using an automatic palette + if (palette_mode != PaletteMode.PALETTE_CUSTOM) + { + buttonAutoPal_Click(sender, e); + } + } + private void buttonLoadPal_Click(object sender, EventArgs e) { if (preset.bpp > PALETTE_BITS) return; @@ -1752,7 +1994,7 @@ private void buttonLoadPal_Click(object sender, EventArgs e) OpenFileDialog d = new OpenFileDialog(); d.Title = "Load Palette"; d.DefaultExt = "pal"; - d.Filter = + d.Filter = // filters correspond to loadPalette filetype parameter "Palette, RGB24 (*.pal)|*.pal|" + "Image (*.bmp;*.gif;*.png;*.tif)|*.bmp;*.gif;*.png;*.tif|" + "VGA Palette, 6-bit RGB18 (*.vga;*.*)|*.vga;*.*|"+ @@ -1764,7 +2006,7 @@ private void buttonLoadPal_Click(object sender, EventArgs e) selected_palette_filter = d.FilterIndex; // remember last used filter if (loadPalette(d.FileName,d.FilterIndex-1)) { - refreshPalette(); + redrawPalette(); redrawPixels(); } else @@ -1791,349 +2033,22 @@ private void buttonSavePal_Click(object sender, EventArgs e) } } - private void numericPosByte_ValueChanged(object sender, EventArgs e) - { - pos_byte = (long)numericPosByte.Value; - updatePos(); - redrawPixels(); - } - - private void numericPosBit_ValueChanged(object sender, EventArgs e) - { - pos_bit = (int)numericPosBit.Value; - redrawPixels(); - } - - private void numericZoom_ValueChanged(object sender, EventArgs e) - { - zoom = (int)numericZoom.Value; - redrawPixels(); - } - - private void decimalPositionToolStripMenuItem_Click(object sender, EventArgs e) - { - decimalPositionToolStripMenuItem.Checked = true; - hexadecimalPositionToolStripMenuItem.Checked = false; - decimal_position = true; - numericPosByte.Font = posfont_regular; - updatePos(); - } - - private void hexadecimalPositionToolStripMenuItem_Click(object sender, EventArgs e) - { - decimalPositionToolStripMenuItem.Checked = false; - hexadecimalPositionToolStripMenuItem.Checked = true; - decimal_position = false; - numericPosByte.Font = posfont_bold; - updatePos(); - } - - private void saveImageContextItem_Click(object sender, EventArgs e) - { - if (preset.width == 1 || preset.height == 1) - { - // if height is 1, we need to save everything seen anyway - saveAllVisibleContextItem_Click(sender, e); - return; - } - - if (selected_tile < 0) // shouldn't happen, but giving an error just in case - { - MessageBox.Show("No image selected?", "Binxelview"); - return; - } - - long pos = (pos_byte * 8) + pos_bit; - pos += selected_tile * ((preset.next_stride_byte * 8) + preset.next_stride_bit); - - SaveFileDialog d = new SaveFileDialog(); - d.Title = "Save Image"; - d.DefaultExt = "png"; - d.Filter = "PNG Image (*.png)|*.png|All files (*.*)|*.*"; - d.FileName = data_file + string.Format(".{0:X8}.{1:D1}.png", pos >> 3, pos & 7); - if (d.ShowDialog() == DialogResult.OK) - { - int w = preset.width; - int h = preset.height; - renderGrid(pos, 1, 1, 0, 0, w, h, true); - - Bitmap b; - if (preset.bpp <= 8) - { - b = renderGridIndexToBitmap(); - } - else - { - b = new Bitmap(w, h, PixelFormat.Format32bppArgb); - renderGridColorToBitmap(b, 1); - } - - try - { - b.Save(d.FileName); - } - catch (Exception ex) - { - MessageBox.Show("Unable to save image:\n" + d.FileName + "\n\n" + ex.ToString(), "Binxelview"); - } - - redrawPixels(); - } - } - - private void saveAllVisibleContextItem_Click(object sender, EventArgs e) - { - saveAllVisibleToolStripMenuItem_Click(sender, e); - } - - private void saveAllVisibleToolStripMenuItem_Click(object sender, EventArgs e) - { - long pos = (pos_byte * 8) + pos_bit; - - SaveFileDialog d = new SaveFileDialog(); - d.Title = "Save All Visible"; - d.DefaultExt = "png"; - d.Filter = "PNG Image (*.png)|*.png|All files (*.*)|*.*"; - d.FileName = data_file + string.Format(".{0:X8}.{1:D1}.png",pos>>3,pos&7); - if (d.ShowDialog() == DialogResult.OK) - { - int w = pixel_gx * pixel_twp + pixel_padx; - int h = pixel_gy * pixel_thp + pixel_pady; - renderGrid(pos, pixel_gx, pixel_gy, pixel_padx, pixel_pady, w, h, true); - - Bitmap b; - if (preset.bpp <= 8) - { - b = renderGridIndexToBitmap(); - } - else - { - b = new Bitmap(w, h, PixelFormat.Format32bppArgb); - renderGridColorToBitmap(b, 1); - } - - try - { - b.Save(d.FileName); - } - catch (Exception ex) - { - MessageBox.Show("Unable to save image:\n" + d.FileName + "\n\n" + ex.ToString(), "Binxelview"); - } - - redrawPixels(); - } - } - - private void positionToPixelToolContextItem_Click(object sender, EventArgs e) - { - if (selected_pos >= 0 && selected_pos < (data.Length * (long)8)) - { - pos_byte = selected_pos >> 3; - pos_bit = (int)(selected_pos & 7); - updatePos(true); - } - } - - private void pixelsToPaletteToolStripMenuItem_Click(object sender, EventArgs e) - { - long read_pos = selected_pos; - if (read_pos < 0) return; - // extract new palette - Color[] new_pal = new Color[PALETTE_DIM*PALETTE_DIM]; - int count = 0; - for (int i=0; i<(PALETTE_DIM*PALETTE_DIM); ++i) - { - long p = readPixel(read_pos); - if (p < 0) break; - Color c = getPalette(p); // can't modify the new palette because we read it here - new_pal[i] = c; - ++count; - read_pos += preset.pixel_stride_bit; - read_pos += preset.pixel_stride_byte * 8; - } - // replace old palette - for (int i=0; i numericZoom.Maximum) zoom = (int)numericZoom.Maximum; - numericZoom.Value = zoom; - redrawPixels(); - } - - private void buttonZoom_MouseDown(object sender, MouseEventArgs e) - { - if (e.Button != MouseButtons.Right) return; - --zoom; - if (zoom < numericZoom.Minimum) zoom = (int)numericZoom.Minimum; - numericZoom.Value = zoom; - redrawPixels(); - } - - private void common_AdvanceClick(int inc_byte, int inc_bit) - { - if ((Control.ModifierKeys & Keys.Shift) != 0) - { - pos_byte -= inc_byte; - pos_bit -= inc_bit; - } - else - { - pos_byte += inc_byte; - pos_bit += inc_bit; - } - normalizePos(); - } - - private void common_AdvanceMouseDown(MouseEventArgs e, int inc_byte, int inc_bit) - { - if (e.Button != MouseButtons.Right) return; - pos_byte -= inc_byte; - pos_bit -= inc_bit; - normalizePos(); - } - - private void buttonBytePos_Click(object sender, EventArgs e) - { - common_AdvanceClick(1, 0); - } - - private void buttonBitPos_Click(object sender, EventArgs e) - { - common_AdvanceClick(0, 1); - } - - private void buttonPixel_Click(object sender, EventArgs e) - { - common_AdvanceClick(preset.pixel_stride_byte, preset.pixel_stride_bit); - } - - private void buttonRow_Click(object sender, EventArgs e) - { - common_AdvanceClick(preset.row_stride_byte, preset.row_stride_bit); - } - - private void buttonNext_Click(object sender, EventArgs e) - { - common_AdvanceClick(next_increment_byte, next_increment_bit); - } - - private void buttonBytePos_MouseDown(object sender, MouseEventArgs e) - { - common_AdvanceMouseDown(e, 1, 0); - } - - private void buttonBitPos_MouseDown(object sender, MouseEventArgs e) - { - common_AdvanceMouseDown(e, 0, 1); - } - - private void buttonPixel_MouseDown(object sender, MouseEventArgs e) - { - common_AdvanceMouseDown(e, preset.pixel_stride_byte, preset.pixel_stride_bit); - } - - private void buttonRow_MouseDown(object sender, MouseEventArgs e) - { - common_AdvanceMouseDown(e, preset.row_stride_byte, preset.row_stride_bit); - } - - private void buttonNext_MouseDown(object sender, MouseEventArgs e) - { - common_AdvanceMouseDown(e, next_increment_byte, next_increment_bit); - } - - private void buttonZero_Click(object sender, EventArgs e) - { - pos_byte = 0; - pos_bit = 0; - updatePos(); - } - - private void snapScrollToNextStrideToolStripMenuItem_Click(object sender, EventArgs e) - { - snap_scroll = !snap_scroll; - snapScrollToNextStrideToolStripMenuItem.Checked = snap_scroll; - scrollRange(); - } - - private void verticalLayoutToolStripMenuItem_Click(object sender, EventArgs e) - { - horizontal_layout = false; - verticalLayoutToolStripMenuItem.Checked = true; - horizontalLayoutToolStripMenuItem.Checked = false; - redrawPixels(); - } - - private void horizontalLayoutToolStripMenuItem_Click(object sender, EventArgs e) - { - horizontal_layout = true; - verticalLayoutToolStripMenuItem.Checked = false; - horizontalLayoutToolStripMenuItem.Checked = true; - redrawPixels(); - } - - private void twiddleNToolStripMenuItem_Click(object sender, EventArgs e) - { - if (twiddle == 2) twiddle = 0; - else twiddle = 2; - twiddleZToolStripMenuItem.Checked = twiddle == 1; - twiddleNToolStripMenuItem.Checked = twiddle == 2; - redrawPixels(); - } - - private void twiddleZToolStripMenuItem_Click(object sender, EventArgs e) - { - if (twiddle == 1) twiddle = 0; - else twiddle = 1; - twiddleZToolStripMenuItem.Checked = twiddle == 1; - twiddleNToolStripMenuItem.Checked = twiddle == 2; - redrawPixels(); - } - - private void gridToolStripMenuItem_Click(object sender, EventArgs e) - { - hidegrid = !hidegrid; - gridToolStripMenuItem.Checked = !hidegrid; - redrawPixels(); - } - - private void exportBinaryChunkToolStripMenuItem_Click(object sender, EventArgs e) - { - BinaryChunkExportForm exportForm = new BinaryChunkExportForm(pos_byte, !decimal_position, data); - exportForm.ShowDialog(); - } - private void pixelBox_MouseMove(object sender, MouseEventArgs e) { // clear selection selected_tile = -1; selected_pos = -1; - saveImageToolStripMenuItem.Enabled = false; - pixelsToPaletteToolStripMenuItem.Enabled = false; + saveImageContextItem.Enabled = false; + pixelsToPaletteContextItem.Enabled = false; // grid settings from last redrawPixels int padx = pixel_padx; @@ -2198,8 +2113,8 @@ private void pixelBox_MouseMove(object sender, MouseEventArgs e) // record selection selected_tile = tile; selected_pos = pos; - saveImageToolStripMenuItem.Enabled = true; - pixelsToPaletteToolStripMenuItem.Enabled = true; + saveImageContextItem.Enabled = true; + pixelsToPaletteContextItem.Enabled = true; // pixel info labelInfoPixel.Text = String.Format("{0:D}+{1:D1} = {2:D}\n{0:X8}+{1:D1} = {2:X}", (int)(pos>>3), (int)(pos&7), p); @@ -2233,36 +2148,105 @@ private void pixelScroll_Scroll(object sender, ScrollEventArgs e) redrawPixels(); } - private void dataGridPixel_CellValidating(object sender, DataGridViewCellValidatingEventArgs e) + private void saveImageContextItem_Click(object sender, EventArgs e) { - int result; - if (!int.TryParse(e.FormattedValue.ToString(), out result)) + if (preset.width == 1 || preset.height == 1) { - e.Cancel = true; + // if height is 1, we need to save everything seen anyway + saveAllVisibleContextItem_Click(sender, e); + return; + } + + if (selected_tile < 0) // shouldn't happen, but giving an error just in case + { + MessageBox.Show("No image selected?", "Binxelview"); + return; + } + + long pos = (pos_byte * 8) + pos_bit; + pos += selected_tile * ((preset.next_stride_byte * 8) + preset.next_stride_bit); + + SaveFileDialog d = new SaveFileDialog(); + d.Title = "Save Image"; + d.DefaultExt = "png"; + d.Filter = "PNG Image (*.png)|*.png|All files (*.*)|*.*"; + d.FileName = data_file + string.Format(".{0:X8}.{1:D1}.png", pos >> 3, pos & 7); + if (d.ShowDialog() == DialogResult.OK) + { + int w = preset.width; + int h = preset.height; + renderGrid(pos, 1, 1, 0, 0, w, h, true); + + Bitmap b; + if (preset.bpp <= 8) + { + b = renderGridIndexToBitmap(); + } + else + { + b = new Bitmap(w, h, PixelFormat.Format32bppArgb); + renderGridColorToBitmap(b, 1); + } + + try + { + b.Save(d.FileName); + } + catch (Exception ex) + { + MessageBox.Show("Unable to save image:\n" + d.FileName + "\n\n" + ex.ToString(), "Binxelview"); + } + + redrawPixels(); } } - private void dataGridPixel_CellValueChanged(object sender, DataGridViewCellEventArgs e) + private void saveAllVisibleContextItem_Click(object sender, EventArgs e) { - int x = e.ColumnIndex; - int y = e.RowIndex; - if (x < 1) return; - if (x > 2) return; - if (y < 0) return; - if (y >= MAX_BPP) return; + saveAllVisibleFileMenuItem_Click(sender, e); + } - int result; - string value = (string)dataGridPixel.Rows[y].Cells[x].Value; - if (int.TryParse(value,out result)) + private void positionToPixelToolContextItem_Click(object sender, EventArgs e) + { + if (selected_pos >= 0 && selected_pos < (data.Length * (long)8)) { - if (x == 1) preset.bit_stride_byte[y] = result; - if (x == 2) preset.bit_stride_bit[y] = result; - redrawPixels(); + pos_byte = selected_pos >> 3; + pos_bit = (int)(selected_pos & 7); + updatePos(true); + } + } + + private void pixelsToPaletteContextItem_Click(object sender, EventArgs e) + { + long read_pos = selected_pos; + if (read_pos < 0) return; + // extract new palette + Color[] new_pal = new Color[PALETTE_DIM*PALETTE_DIM]; + int count = 0; + for (int i=0; i<(PALETTE_DIM*PALETTE_DIM); ++i) + { + long p = readPixel(read_pos); + if (p < 0) break; + Color c = getPalette(p); // can't modify the new palette yet because we read it here + new_pal[i] = c; + ++count; + read_pos += preset.pixel_stride_bit; + read_pos += preset.pixel_stride_byte * 8; + } + // replace old palette + for (int i=0; i 0 && arg_err.Length > 0) arg_err += "\n"; + arg_err += opt_err; + } + } + if (arg_err.Length > 0) MessageBox.Show("Command line error:\n" + arg_err,"Binxelview"); + + autoPalette(); + scrollRange(); + redrawOptions(); + redrawPreset(); + redrawPalette(); + disable_pixel_redraw = false; // finally allow redraw of pixels + redrawPixels(); + } } } diff --git a/readme.txt b/readme.txt index 93f2d26..428667a 100644 --- a/readme.txt +++ b/readme.txt @@ -172,6 +172,7 @@ To open a file, just add that file's path to the command line. Options can be set with a command line argument beginning with '-', followed by the option name, an '=' separator, and the value for the option. If a space is required in the value, you should enclose the entire argument in quotes. +Paths can be either absolute or relative to the current working directory. "-presetfile=C:\mypreset.bxp" Replaces the default preset with one from a file. @@ -179,13 +180,17 @@ If a space is required in the value, you should enclose the entire argument in q "-preset=Atari ST 4BPP" Chooses a named preset from your preset library instead of the default. - "-pal=C:\red.pal" - Loads a palette file. + "-pal=my palettes\red.pal" + Loads a palette file. If -paltype is not used (see below) it will detect the type by the file extension. If the extension is .BMP .GIF .PNG or .TIF it will load it as an palette from an image. If the extension is .VGA it will load it as 6-bit RGB18 format. If the extension is .RIFF it will load it as a Microsoft RIFF palette. Otherwise it will load it as RGB24. + -paltype=1 + Overrides the extension check for the next -pal option. (Must be used before -pal.) + 0 = RGB24, 1 = Image, 2 = VGA, 3 = RIFF, -1 = Use extension. + -autopal=Greyscale Chooses an automatic palette, one of: RGB - RGB with the current preset BPP, bits evenly divided with G bits >= R bits >= B bits. (Red is MSB.)