Changeset - 9d927a271fbb
[Not reviewed]
default
0 1 0
Jason Maltzen (jmaltzen) - 6 years ago 2018-05-17 19:11:12
jason.maltzen@unsanctioned.net
Turn off record button when captured color is clipped.
1 file changed with 4 insertions and 1 deletions:
0 comments (0 inline, 0 general)
UI/CaptureView.cs
Show inline comments
...
 
@@ -306,208 +306,211 @@ namespace DesertPaintLab
 

	
 
            notifyCaptureComplete.WakeupMain();
 
        }
 

	
 
        private void OnCaptureProgress(int x, int y)
 
        {
 
            notifyCaptureProgress.WakeupMain();
 
        }
 

	
 
        private void NotifyCaptureProgress()
 
        {
 
            // TODO: progress bar
 
            //ReactionRecorder.Instance.X;
 
            //ReactionRecorder.Instance.Y;
 
            progressBar.Fraction = ((double)(ReactionRecorder.Instance.X) / (double)(ReactionRecorder.Instance.ScreenWidth - ReactionRecorder.Instance.ColorBarWidth));
 
        }
 

	
 
        void OnCaptureComplete(bool isCaptured, PaintColor reactedColor, int swatchX, int swatchY)
 
        {
 
            int screenWidth = screenBuffer.Width;
 
            int screenHeight = screenBuffer.Height;
 
            int stride = screenBuffer.Rowstride;
 

	
 
            StreamWriter log = ReactionRecorder.Instance.Log;
 
            if (log != null)
 
            {
 
                log.Flush();
 
                log.Close();
 
                log = null;
 
                ReactionRecorder.Instance.Log = null;
 
            }
 

	
 
            bool enableDebugMenu = false;
 
            DesertPaintLab.AppSettings.Get("EnableDebugMenu", out enableDebugMenu);
 
            bool debugScreenshot = false;
 
            DesertPaintLab.AppSettings.Get("DebugScreenshot", out debugScreenshot);
 
            if (enableDebugMenu && debugScreenshot)
 
            {
 
                if (!isCaptured)
 
                {
 
                    // write out the whole screenshot on a failure to capture
 
                    string screenshotDir = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
 
                    string filename = FileUtils.FindNumberedFile("DesertPaintLab_Colormatch", "png", screenshotDir);
 
                    screenBuffer.Save(filename, "png");
 
                }
 
                else
 
                {
 
                    // record the swatch that was captured
 
                    // write out the screenshot
 
                    string screenshotDir = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
 
                    string filename = FileUtils.FindNumberedFile("DesertPaintLab_Colormatch", "png", screenshotDir);
 
                    int x = swatchX - 16;
 
                    int captureAreaWidth = ReactionRecorder.Instance.ColorBarWidth + 32;
 
                    captureAreaWidth = Math.Min(screenWidth - x, captureAreaWidth);
 
                    int y = swatchY - 16;
 
                    int captureAreaHeight = ReactionRecorder.Instance.BlueBarSpacing + 42;
 
                    captureAreaHeight = Math.Min(screenHeight - y, captureAreaHeight);
 

	
 
                    Gdk.Pixbuf outPixBuf = new Gdk.Pixbuf(screenBuffer, Math.Max(0, x), Math.Max(0, y), 
 
                        captureAreaWidth, captureAreaHeight);
 
                    //Gdk.Pixbuf outPixBuf = new Gdk.Pixbuf(screenBuffer, Math.Max(0, redPixelStartX), Math.Max(0, redPixelStartY),
 
                    //    ReactionRecorder.Instance.ColorBarWidth, ReactionRecorder.Instance.GreenBarSpacing - ReactionRecorder.Instance.RedBarSpacing);
 
                    //screenBuffer.Save(filename, "png");
 
                    outPixBuf.Save(filename, "png");
 
                }
 
            }
 
            //screenBuffer.Save("screenshot.png", "png");
 

	
 
            if (isCaptured)
 
            {
 
                string warning = "";
 
                if (reactedColor.Red == 0)
 
                {
 
                    warning = warning + "\nRed is too low.";
 
                }
 
                if (reactedColor.Green == 0)
 
                {
 
                    warning = warning + "\nGreen is too low.";
 
                }
 
                if (reactedColor.Blue == 0)
 
                {
 
                    warning = warning + "\nBlue is too low.";
 
                }
 
                if (reactedColor.Red == 255)
 
                {
 
                    warning = warning + "\nRed is too high.";
 
                }
 
                if (reactedColor.Green == 255)
 
                {
 
                    warning = warning + "\nGreen is too high.";
 
                }
 
                if (reactedColor.Blue == 255)
 
                {
 
                    warning = warning + "\nBlue is too high.";
 
                }
 

	
 
                // Always update the reacted swatch
 
                this.reactionSwatch.Color = reactedColor;
 
                if (warning.Length != 0)
 
                {
 
                    isCaptured = true;
 
                    Gtk.MessageDialog md = new Gtk.MessageDialog((Gtk.Window)Toplevel,
 
                    Gtk.DialogFlags.DestroyWithParent,
 
                    Gtk.MessageType.Error, Gtk.ButtonsType.Ok,
 
                    "Reaction clipped.  You will need to do a " +
 
                    "3-way reaction to test this pair.  Details: " +
 
                    warning);
 

	
 
                    md.Run();
 
                    md.Destroy();
 
                    // reaction clipped - don't let them record
 
                    recordButton.Sensitive = false;
 
                }
 
                else
 
                {
 
                    this.reactionSwatch.Color = reactedColor;
 
                    recordButton.Sensitive = recordEnabled;
 
                }
 

	
 
                captureButton.Sensitive = false;
 
            }
 
            else
 
            {
 
                Gtk.MessageDialog md = new Gtk.MessageDialog((Gtk.Window)Toplevel,
 
                    Gtk.DialogFlags.DestroyWithParent,
 
                    Gtk.MessageType.Error, Gtk.ButtonsType.Ok,
 
                    "Pigment Lab dialog box NOT FOUND.  Please ensure " +
 
                    "that there is an unobstructed view of the dialog " +
 
                    "and that your interface size is set to 'small' " +
 
                    "when you press the Capture button.");
 

	
 
                md.Run();
 
                md.Destroy();
 
            }
 

	
 
            progressBar.Hide();
 
            recordButton.Show();
 

	
 
            ingredient1ComboBox.Sensitive = true;
 
            ingredient2ComboBox.Sensitive = true;
 
            ingredient3ComboBox.Sensitive = false;
 
            UpdateIngredients();
 
        }
 

	
 
        private void NotifyCaptureComplete()
 
        {
 
            OnCaptureComplete(
 
                ReactionRecorder.Instance.IsCaptured,
 
                ReactionRecorder.Instance.RecordedColor,
 
                ReactionRecorder.Instance.SwatchX,
 
                ReactionRecorder.Instance.SwatchY);
 
        }
 

	
 
        unsafe void CaptureReactionColor()
 
        {
 
            // Take a screenshot.
 
            int screenWidth, screenHeight;
 
            Gdk.Window rootWindow = Gdk.Global.DefaultRootWindow;
 
            DesertPaintLab.AppSettings.Get("ScreenWidth", out screenWidth);
 
            DesertPaintLab.AppSettings.Get("ScreenHeight", out screenHeight);
 
            Gdk.Image rootImage = rootWindow.GetImage(0, 0, screenWidth, screenHeight);
 
            screenBuffer.GetFromImage(rootImage, rootImage.Colormap, 0, 0, 0, 0, screenWidth, screenHeight);
 
            rootImage.Unref();
 
            System.GC.Collect(); // really, clean up now
 

	
 
            BeginCapture();
 
        }
 

	
 
        protected virtual void OnCapture(object sender, System.EventArgs e)
 
        {
 
            CaptureReactionColor();
 
        }
 
        
 
        protected virtual void OnRecord(object sender, System.EventArgs e)
 
        {
 
            if (ReactionRecorder.Instance.RecordReaction(profile, expectedColor, reactedColor, reagents))
 
            {
 
                recordButton.Sensitive = false;
 
            }
 
        }
 
        
 
        protected virtual void OnChangedIngredient1(object sender, System.EventArgs e)
 
        {
 
            UpdateIngredients();
 
        }
 
        
 
        protected virtual void OnChangedIngredient2(object sender, System.EventArgs e)
 
        {
 
            UpdateIngredients();
 
        }
 
        
 
        protected virtual void OnChangedIngredient3(object sender, System.EventArgs e)
 
        {
 
            UpdateIngredients();
 
        }
 
        
 
        protected void OnClearReaction(object sender, EventArgs e)
 
        {
 
            string reagentName1 = GetSelectedReagentName(1);
 
            string reagentName2 = GetSelectedReagentName(2);
 
            string reagentName3 = GetSelectedReagentName(3);
 

	
 
            if ((reagentName1 != null) && (reagentName2 != null) && (reagentName3 == null))
 
            {
 
                Reagent reagent1 = ReagentManager.GetReagent(reagentName1);
 
                Reagent reagent2 = ReagentManager.GetReagent(reagentName2);
 

	
 
                if (null != profile.FindReaction(reagent1, reagent2))
 
                {
 
                    Gtk.MessageDialog md = new Gtk.MessageDialog((Gtk.Window)Toplevel, 
 
                        Gtk.DialogFlags.DestroyWithParent,
 
                        Gtk.MessageType.Warning, Gtk.ButtonsType.OkCancel, 
0 comments (0 inline, 0 general)