Example #1
0
        public void Reload()
        {
            //lock (PreviewTools.renderLock)
            //{
            Console.WriteLine("Reload");
            if (NodeToPixel == null)
            {
                PreviewTools.Throw("PreviewBase.NodeToPixel == null");
            }
            NodeToPixel.Clear();

            if (DisplayItems == null)
            {
                PreviewTools.Throw("DisplayItems == null");
            }
            foreach (DisplayItem item in DisplayItems)
            {
                if (item.Shape.Pixels == null)
                {
                    PreviewTools.Throw("item.Shape.Pixels == null");
                }
                foreach (PreviewPixel pixel in item.Shape.Pixels)
                {
                    if (pixel.Node != null)
                    {
                        List <PreviewPixel> pixels;
                        if (NodeToPixel.TryGetValue(pixel.Node, out pixels))
                        {
                            if (!pixels.Contains(pixel))
                            {
                                pixels.Add(pixel);
                            }
                        }
                        else
                        {
                            pixels = new List <PreviewPixel>();
                            pixels.Add(pixel);
                            NodeToPixel.Add(pixel.Node, pixels);
                        }
                    }
                }
            }
            LoadBackground();
            //}
        }
Example #2
0
        public void ResizeBackground(int width, int height)
        {
            double aspect = (double)width / (double)_background.Width;
            //Console.WriteLine("Resizing background to: " + width + ", " + height);
            Bitmap newBackground = PreviewTools.ResizeBitmap(new Bitmap(_background), new Size(width, height));
            // Copy the file to the Vixen folder
            string imageFileName = Guid.NewGuid().ToString() + ".jpg";
            var    destFileName  = System.IO.Path.Combine(VixenPreviewDescriptor.ModulePath, imageFileName);

            newBackground.Save(destFileName, ImageFormat.Jpeg);
            Data.BackgroundFileName = destFileName;
            LoadBackground(destFileName);

            foreach (Shapes.DisplayItem item in DisplayItems)
            {
                item.Shape.Resize(aspect);
            }
        }
Example #3
0
 public void AddTtemplateToPreview(string fileName)
 {
     if (System.IO.File.Exists(fileName))
     {
         // Read the entire template file (stoopid waste of resources, but how else?)
         string      xml            = System.IO.File.ReadAllText(fileName);
         DisplayItem newDisplayItem = PreviewTools.DeSerializeToObject(xml, typeof(DisplayItem));
         if (newDisplayItem != null)
         {
             DeSelectSelectedDisplayItem();
             AddDisplayItem(newDisplayItem);
             _selectedDisplayItem = newDisplayItem;
             OnSelectDisplayItem(this, _selectedDisplayItem);
             _selectedDisplayItem.Shape.MoveTo(10, 10);
             _selectedDisplayItem.Shape.Select(true);
             _selectedDisplayItem.Shape.SetSelectPoint(null);
         }
     }
 }
Example #4
0
        public bool Paste()
        {
            string      xml            = Clipboard.GetText();
            DisplayItem newDisplayItem = (DisplayItem)PreviewTools.DeSerializeToObject(xml, typeof(DisplayItem));

            if (newDisplayItem != null)
            {
                DeSelectSelectedDisplayItem();
                Console.WriteLine("Pasted: " + newDisplayItem.Shape.GetType().ToString());
                AddDisplayItem(newDisplayItem);
                _selectedDisplayItem = newDisplayItem;
                _selectedDisplayItem.Shape.Select(true);
                _selectedDisplayItem.Shape.SetSelectPoint(null);
                OnSelectDisplayItem(this, _selectedDisplayItem);
                return(true);
            }
            else
            {
                return(false);
            }
        }
Example #5
0
        private void PopulateTemplateList()
        {
            TemplateComboBoxItem selectedTemplateItem = comboBoxTemplates.SelectedItem as TemplateComboBoxItem;

            comboBoxTemplates.Items.Clear();

            IEnumerable <string> files = System.IO.Directory.EnumerateFiles(PreviewTools.TemplateFolder, "*.xml");

            foreach (string file in files)
            {
                string fileName = PreviewTools.TemplateWithFolder(file);
                try
                {
                    // Read the entire template file (stoopid waste of resources, but how else?)
                    string               xml             = System.IO.File.ReadAllText(fileName);
                    DisplayItem          newDisplayItem  = PreviewTools.DeSerializeToDisplayItem(xml, typeof(DisplayItem));
                    TemplateComboBoxItem newTemplateItem = new TemplateComboBoxItem(newDisplayItem.Shape.Name, fileName);
                    comboBoxTemplates.Items.Add(newTemplateItem);
                }
                catch (Exception ex)
                {
                    //messageBox Arguments are (Text, Title, No Button Visible, Cancel Button Visible)
                    MessageBoxForm.msgIcon = SystemIcons.Error;                     //this is used if you want to add a system icon to the message form.
                    var messageBox = new MessageBoxForm("There was an error loading the template file (" + file + "): " + ex.Message,
                                                        "Error Loading Template", false, true);
                    messageBox.ShowDialog();
                }
                finally
                {
                    if (selectedTemplateItem != null && comboBoxTemplates.Items.IndexOf(selectedTemplateItem) >= 0)
                    {
                        comboBoxTemplates.SelectedItem = selectedTemplateItem;
                    }
                    if (comboBoxTemplates.SelectedItem == null && comboBoxTemplates.Items.Count > 0)
                    {
                        comboBoxTemplates.SelectedIndex = 0;
                    }
                }
            }
        }
Example #6
0
        private void PopulateTemplateList()
        {
            TemplateComboBoxItem selectedTemplateItem = comboBoxTemplates.SelectedItem as TemplateComboBoxItem;

            comboBoxTemplates.Items.Clear();

            IEnumerable <string> files = System.IO.Directory.EnumerateFiles(PreviewTools.TemplateFolder, "*.xml");

            foreach (string file in files)
            {
                string fileName = PreviewTools.TemplateWithFolder(file);
                try
                {
                    // Read the entire template file (stoopid waste of resources, but how else?)
                    string               xml             = System.IO.File.ReadAllText(fileName);
                    DisplayItem          newDisplayItem  = (DisplayItem)PreviewTools.DeSerializeToObject(xml, typeof(DisplayItem));
                    TemplateComboBoxItem newTemplateItem = new TemplateComboBoxItem(newDisplayItem.Shape.Name, fileName);
                    comboBoxTemplates.Items.Add(newTemplateItem);
                }
                catch (Exception ex)
                {
                    MessageBox.Show("There was an error loading the template file (" + file + "): " + ex.Message, "Error Loading Template", MessageBoxButtons.OKCancel);
                }
                finally
                {
                    if (selectedTemplateItem != null && comboBoxTemplates.Items.IndexOf(selectedTemplateItem) >= 0)
                    {
                        comboBoxTemplates.SelectedItem = selectedTemplateItem;
                    }
                    if (comboBoxTemplates.SelectedItem == null && comboBoxTemplates.Items.Count > 0)
                    {
                        comboBoxTemplates.SelectedIndex = 0;
                    }
                }
            }
        }
Example #7
0
        /// <summary>
        /// This is used in edit mode only!!
        /// Need to make it go away so we only have one render engine
        /// </summary>
        public void RenderInForeground()
        {
            renderTimer.Reset();
            renderTimer.Start();

            if (_background != null)
            {
                //FastPixel fp = new FastPixel(_background.Width, _background.Height);
                FastPixel fp      = new FastPixel(new Bitmap(_alphaBackground));
                Bitmap    floodBG = null;
                if (UseFloods)
                {
                    floodBG = PreviewTools.Copy32BPPBitmapSafe(_blankAlphaBackground);
                    //floodBG = new Bitmap(_blankAlphaBackground);
                    //floodBG = new Bitmap(_blankAlphaBackground.Width, _blankAlphaBackground.Height);
                    //Graphics g = Graphics.FromImage(floodBG);
                    //g.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceCopy;
                    //SolidBrush brush = new SolidBrush(Color.FromArgb(50, 255, 0, 0));
                    //g.FillEllipse(brush, new Rectangle(200, 200, 300, 300));
                    //g.DrawImage(_blankAlphaBackground, 0, 0);
                    //g.FillRectangle(_backgroundBrush, new Rectangle(0, 0, _blankAlphaBackground.Width, _blankAlphaBackground.Height));
                }
                fp.Lock();
                foreach (DisplayItem displayItem in DisplayItems)
                {
                    //if (UseFloods && displayItem.Shape.StringType == PreviewBaseShape.StringTypes.Flood)
                    //{
                    //    displayItem.Shape.Draw(floodBG, _editMode, null);
                    //}
                    //else
                    //{
                    if (_editMode)
                    {
                        displayItem.Draw(fp, true, HighlightedElements, SelectedDisplayItems.Contains(displayItem));
                    }
                    else
                    {
                        displayItem.Draw(fp, false, null, false);
                    }
                    //}
                }
                fp.Unlock(true);

                // Finally, are we drawing a banded rectangle?
                if (_mouseCaptured && _selectedDisplayItem == null)
                {
                    Graphics g = Graphics.FromImage(fp.Bitmap);
                    g.DrawRectangle(Pens.White, _bandRect);
                }

                //lock (renderLock)
                //{
                // First, draw our background image opaque
                bufferedGraphics.Graphics.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceCopy;
                //bufferedGraphics.Graphics.DrawImage(_background, 0, 0, _background.Width, _background.Height);
                if (UseFloods)
                {
                    bufferedGraphics.Graphics.DrawImage(_background, 0, 0, _background.Width, _background.Height);
                }
                else
                {
                    //bufferedGraphics.Graphics.DrawImage(_alphaBackground, 0, 0, _alphaBackground.Width, _alphaBackground.Height);
                }

                //bufferedGraphics.Graphics.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceOver;
                if (UseFloods)
                {
                    bufferedGraphics.Graphics.DrawImage(floodBG, 0, 0, _blankAlphaBackground.Width, _blankAlphaBackground.Height);
                }
                // Now, draw our "pixel" image using alpha blending
                bufferedGraphics.Graphics.DrawImage(fp.Bitmap, 0, 0, fp.Width, fp.Height);
                //}
            }

            bufferedGraphics.Render(Graphics.FromHwnd(this.Handle));
            renderTimer.Stop();
            lastRenderUpdateTime = renderTimer.ElapsedMilliseconds;
        }
Example #8
0
        public void ProcessUpdate(ElementIntentStates elementStates)
        {
            renderTimer.Reset();
            renderTimer.Start();
            if (!_paused)
            {
                //FastPixel fp = new FastPixel(_background.Width, _background.Height);
                FastPixel fp      = new FastPixel(new Bitmap(_alphaBackground));
                Bitmap    floodBG = null;
                if (UseFloods)
                {
                    floodBG = PreviewTools.Copy32BPPBitmapSafe(_blankAlphaBackground);
                    //floodBG = new Bitmap(_blankAlphaBackground);
                    //floodBG = new Bitmap(_blankAlphaBackground.Width, _blankAlphaBackground.Height);
                    //Graphics g = Graphics.FromImage(floodBG);
                    //g.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceCopy;
                    //SolidBrush brush = new SolidBrush(Color.FromArgb(50, 255, 0, 0));
                    //g.FillEllipse(brush, new Rectangle(200, 200, 300, 300));
                    //g.DrawImage(_blankAlphaBackground, 0, 0);
                    //g.FillRectangle(_backgroundBrush, new Rectangle(0, 0, _blankAlphaBackground.Width, _blankAlphaBackground.Height));
                }
                fp.Lock();

                foreach (var channelIntentState in elementStates)
                {
                    var     elementId = channelIntentState.Key;
                    Element element   = VixenSystem.Elements.GetElement(elementId);
                    if (element == null)
                    {
                        continue;
                    }
                    ElementNode node = VixenSystem.Elements.GetElementNodeForElement(element);
                    if (node == null)
                    {
                        continue;
                    }

                    //foreach (IIntentState intentState in channelIntentState.Value)
                    //{
                    //    intentState.Dispatch(DisplayItems[0]);
                    //}

                    foreach (IIntentState <LightingValue> intentState in channelIntentState.Value)
                    {
                        if (_background != null)
                        {
                            List <PreviewPixel> pixels;
                            if (NodeToPixel.TryGetValue(node, out pixels))
                            {
                                foreach (PreviewPixel pixel in pixels)
                                {
                                    //Color.FromArgb((int)(Intensity * byte.MaxValue), Color.R, Color.G, Color.B);
                                    //LightingValue v = intentState.GetValue();
                                    //Color c = v.GetOpaqueIntensityAffectedColor();
                                    //Color c = v.GetAlphaChannelIntensityAffectedColor();
                                    Color c = intentState.GetValue().GetAlphaChannelIntensityAffectedColor();
                                    //Color c = Color.White;
                                    pixel.Draw(fp, c);
                                }
                            }
                        }
                    }
                }

                //if (UseFloods)
                //{
                //    foreach (DisplayItem displayItem in DisplayItems)
                //    {
                //        if (displayItem.Shape.StringType == PreviewBaseShape.StringTypes.Flood)
                //        {
                //            Color c = displayItem.Shape._pixels[0].PixelColor;
                //            int alpha = c.A;
                //            //int maxAlpha = 255 - BackgroundAlpha;
                //            //if (maxAlpha < 255)
                //            //{

                //            //}
                //            displayItem.Shape._pixels[0].PixelColor = Color.FromArgb(alpha, c.R, c.G, c.B);
                //            displayItem.Shape.Draw(floodBG, false, null);
                //            displayItem.Shape._pixels[0].PixelColor = Color.FromArgb(255 - BackgroundAlpha, 0, 0, 0);
                //        }
                //    }
                //}
                fp.Unlock(true);

                // First, draw our background image opaque
                bufferedGraphics.Graphics.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceCopy;
                //if (UseFloods)
                //{
                //    bufferedGraphics.Graphics.DrawImage(_background, 0, 0, _background.Width, _background.Height);
                //}
                //else
                //{
                //    bufferedGraphics.Graphics.DrawImage(_alphaBackground, 0, 0, _alphaBackground.Width, _alphaBackground.Height);
                //}

                // Now, draw our "pixel" image using alpha blending
                ///bufferedGraphics.Graphics.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceOver;
                if (UseFloods)
                {
                    bufferedGraphics.Graphics.DrawImage(floodBG, 0, 0, _blankAlphaBackground.Width, _blankAlphaBackground.Height);
                }
                bufferedGraphics.Graphics.DrawImage(fp.Bitmap, 0, 0, fp.Width, fp.Height);

                if (!this.Disposing && bufferedGraphics != null)
                {
                    bufferedGraphics.Render(Graphics.FromHwnd(this.Handle));
                }

                fp = null;
            }

            renderTimer.Stop();
            lastRenderUpdateTime = renderTimer.ElapsedMilliseconds;
        }