private void OnPanelClick(object sender, StatusBarPanelClickEventArgs e)
        {
            if (e.StatusBarPanel == iconPanel && sender == this)
            {
                MenuCommand c = menu.TrackPopup(PointToScreen(new Point(0, -90)), false);
                if (c != null)
                {
                    switch (c.Text)
                    {
                    case "Debug":
                        MpeLog.Threshold = MpeLogLevel.Debug;
                        MpeLog.Debug("Log Level set to Debug");
                        break;

                    case "Info":
                        MpeLog.Threshold = MpeLogLevel.Info;
                        MpeLog.Info("Log Level set to Info");
                        break;

                    case "Warn":
                        MpeLog.Threshold = MpeLogLevel.Warn;
                        MpeLog.Warn("Log Level set to Warn");
                        break;

                    case "Error":
                        MpeLog.Threshold = MpeLogLevel.Error;
                        MpeLog.Error("Log Level set to Error");
                        break;
                    }
                }
            }
        }
 public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
 {
     if (context.Instance is MpeControl)
     {
         try
         {
             MpeControl mpc = (MpeControl)context.Instance;
             IWindowsFormsEditorService editorService =
                 (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
             MpeTextAreaEditorForm selector = new MpeTextAreaEditorForm((string)value, editorService);
             editorService.DropDownControl(selector);
             if (selector.Result == DialogResult.Cancel)
             {
                 return(value);
             }
             return(selector.TextValue);
         }
         catch (Exception ee)
         {
             MpeLog.Debug(ee);
             MpeLog.Error(ee);
         }
     }
     return(base.EditValue(context, provider, value));
 }
Exemple #3
0
 public void OnControlClick(object sender, EventArgs e)
 {
     if (activeMouseEvent != null)
     {
         if (mask.SelectedControl != sender && (sender is MaskComponent) == false)
         {
             try
             {
                 mask.SelectedControl = (MpeControl)sender;
                 Focus();
                 UpdatePropertyManager();
             }
             catch (Exception ee)
             {
                 MpeLog.Debug(ee);
                 MpeLog.Error(ee);
             }
         }
         if (activeMouseEvent.Button == MouseButtons.Right)
         {
             if (sender != null && sender is Control)
             {
                 Control c = (Control)sender;
                 UpdateContextMenu(mask.SelectedControl);
                 MenuCommand mc =
                     contextMenu.TrackPopup(c.PointToScreen(new Point(activeMouseEvent.X, activeMouseEvent.Y)), false);
                 OnMenuSelection(mc);
             }
         }
         activeMouseEvent = null;
     }
 }
 public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
 {
     if (context.Instance is MpeControl)
     {
         try
         {
             MpeControl mpc = (MpeControl)context.Instance;
             IWindowsFormsEditorService editorService =
                 (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
             MpeImageEditorForm selector = new MpeImageEditorForm((FileInfo)value, mpc.Parser, editorService);
             editorService.DropDownControl(selector);
             if (selector.SelectedImageName == null)
             {
                 MpeLog.Info("Clearing Image...");
                 return(null);
             }
             MpeLog.Info("Changing texture to [" + selector.SelectedImageName + "]");
             return(mpc.Parser.GetImageFile(selector.SelectedImageName));
         }
         catch (Exception ee)
         {
             MpeLog.Debug(ee);
             MpeLog.Error(ee);
         }
     }
     return(base.EditValue(context, provider, value));
 }
Exemple #5
0
 private void okButton_Click(object sender, EventArgs e)
 {
     try
     {
         preferences.Save();
     }
     catch (Exception ee)
     {
         MpeLog.Error(ee);
         return;
     }
     DialogResult = DialogResult.OK;
     Close();
 }
        public override void Save(XmlDocument doc, XmlNode node, MpeParser parser, MpeControl reference)
        {
            if (doc != null && node != null)
            {
                base.Save(doc, node, parser, reference);
                //parser.SetValue(doc, node, "animation", Animation.ToString());

                XmlElement mpenode = doc.CreateElement("mpe");
                node.AppendChild(mpenode);

                parser.SetValue(doc, mpenode, "layout", LayoutStyle.ToString());
                parser.SetValue(doc, mpenode, "spring", Spring ? "yes" : "no");
                parser.SetInt(doc, mpenode, "spacing", Spacing);
                parser.SetPadding(doc, mpenode, "padding", Padding);

                if (backImage != null && backImage.Texture != null)
                {
                    XmlElement image = doc.CreateElement("control");
                    backImage.Location = AbsoluteLocation;
                    backImage.Save(doc, image, parser, parser.GetControl(MpeControlType.Image));
                    backImage.Location = Point.Empty;
                    node.AppendChild(image);
                }

                if (reference != null)
                {
                    for (int i = Controls.Count - 1; i >= 0; i--)
                    {
                        if (Controls[i] is MpeControl)
                        {
                            MpeControl control = (MpeControl)Controls[i];
                            try
                            {
                                XmlElement element          = doc.CreateElement("control");
                                MpeControl referenceControl = parser.GetControl(control.Type);
                                control.Save(doc, element, parser, referenceControl);
                                node.AppendChild(element);
                            }
                            catch (Exception e)
                            {
                                MpeLog.Debug(e);
                                MpeLog.Error(e);
                                throw new MpeParserException(e.Message);
                            }
                        }
                    }
                }
            }
        }
Exemple #7
0
 public void ShowHelp(FileInfo file)
 {
     if (file == null || file.Exists == false)
     {
         throw new DesignerException("Invalid help file");
     }
     try
     {
         browser.Navigate(FileToUrl(file));
     }
     catch (Exception e)
     {
         MpeLog.Error(e);
         throw new DesignerException(e.Message);
     }
 }
Exemple #8
0
 public override void Initialize()
 {
     try
     {
         screen = Parser.CreateScreen(screenInfo.File, Mask.NodeSize, Mask.NodeSize, MpeScreenSize.PAL);
         AddControl(screen);
         ClearControlStatus(screen);
         MpeLog.Info("Screen designer initialized [" + ResourceName + "]");
     }
     catch (MpeParserException e)
     {
         MpeLog.Debug(e);
         MpeLog.Error(e);
         throw new DesignerException(e.Message);
     }
 }
 public Rectangle GetStringRectangle(string text, Size maxSize)
 {
     if (Texture != null)
     {
         try
         {
             int      x1 = int.MaxValue;
             int      x2 = int.MinValue;
             Color    c  = Color.FromArgb(255, 255, 255, 255);
             Bitmap   b  = new Bitmap(maxSize.Width, maxSize.Height);
             Graphics g  = Graphics.FromImage(b);
             g.Clear(c);
             g.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
             g.SmoothingMode     = SmoothingMode.HighQuality;
             g.TextContrast      = 0;
             g.DrawString(text, SystemFont, Brushes.Black, 0, 0);
             Size size = g.MeasureString(text, SystemFont).ToSize();
             //for (int y = 0; y < size.Height; y++)
             //{
             //  for (int x = 0; x < b.Width; x++)
             //  {
             //    if (b.GetPixel(x, y) != c)
             //    {
             //      if (x < x1)
             //      {
             //        x1 = x;
             //      }
             //      if (x > x2)
             //      {
             //        x2 = x;
             //      }
             //    }
             //  }
             //}
             x1 = 0;
             x2 = b.Width;
             return(new Rectangle(x1, 0, x2 - x1 + 1, textureData[0].Height));
         }
         catch (Exception ee)
         {
             MpeLog.Debug(ee);
             MpeLog.Error(ee);
         }
     }
     return(Rectangle.Empty);
 }
 public void Save()
 {
     MpeLog.Debug("MpeStringDesigner.Save()");
     try
     {
         stringTable.Clear();
         DataRow[] rows = dataTable.Select("", "Id");
         for (int i = 0; rows != null && i < rows.Length; i++)
         {
             MpeData.MpeDbStringRow r = (MpeData.MpeDbStringRow)rows[i];
             stringTable.Add(r.Id, r.Value);
         }
         mpe.Parser.SaveStringTable(stringTable);
         mpe.ToggleDesignerStatus(ResourceName, false);
     }
     catch (Exception ee)
     {
         MpeLog.Debug(ee);
         MpeLog.Error(ee);
     }
 }
Exemple #11
0
 private void OnDoubleClick(object sender, EventArgs e)
 {
     if (selectedNode == null || selectedNode.Parent == null)
     {
         return;
     }
     try
     {
         TreeNode parent = selectedNode.Parent;
         if (parent == screenNode)
         {
             mpe.AddDesigner(new MpeScreenDesigner(mpe, (MpeScreenInfo)selectedNode.Tag));
         }
         else if (parent == languageNode)
         {
             mpe.AddDesigner(
                 new MpeStringDesigner(mpe, Parser.GetStringTable("English"), (MpeStringTable)selectedNode.Tag));
         }
         else if (parent == imageNode)
         {
             mpe.AddDesigner(new MpeImageDesigner(mpe, (FileInfo)selectedNode.Tag));
         }
         else if (parent == controlNode)
         {
             MpeControl c = Parser.CreateControl((MpeControlType)selectedNode.Tag);
             mpe.AddDesigner(new MpeControlDesigner(mpe, c));
         }
         else if (parent == fontNode)
         {
             MpeFont font = new MpeFont(Parser.GetFont(selectedNode.Text));
             mpe.AddDesigner(new FontDesigner(mpe, font));
         }
     }
     catch (Exception ee)
     {
         MpeLog.Debug(ee);
         MpeLog.Error(ee);
     }
 }
Exemple #12
0
 public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
 {
     if (context.Instance is MpeControl)
     {
         try
         {
             MpeControl mpc = (MpeControl)context.Instance;
             IWindowsFormsEditorService editorService =
                 (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
             MpeStringEditorForm selector = new MpeStringEditorForm((string)value, mpc.Parser, editorService);
             editorService.DropDownControl(selector);
             return(selector.SelectedValue);
         }
         catch (Exception ee)
         {
             MpeLog.Debug(ee);
             MpeLog.Error(ee);
         }
     }
     else if (context.Instance is MpeItem)
     {
         try
         {
             IWindowsFormsEditorService editorService =
                 (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
             MpeStringEditorForm selector =
                 new MpeStringEditorForm((string)value, MediaPortalEditor.Global.Parser, editorService);
             editorService.DropDownControl(selector);
             return(selector.SelectedValue);
         }
         catch (Exception ee)
         {
             MpeLog.Debug(ee);
             MpeLog.Error(ee);
         }
     }
     return(base.EditValue(context, provider, value));
 }
Exemple #13
0
 public virtual void CutControl()
 {
     if (AllowDeletions)
     {
         if (mask.SelectedControl != screen && mask.SelectedControl.MpeParent != null)
         {
             try
             {
                 MpeControl   control = mask.SelectedControl;
                 MpeContainer parent  = control.MpeParent;
                 parent.Controls.Remove(control);
                 mpe.Clipboard        = control;
                 mask.SelectedControl = null;
                 UpdatePropertyManager();
             }
             catch (Exception ee)
             {
                 MpeLog.Debug(ee);
                 MpeLog.Error(ee);
             }
         }
     }
 }
Exemple #14
0
        public void LoadSkin(DirectoryInfo skinDir)
        {
            try
            {
                // Cleanup used resources
                CloseSkin();
                // Initialize a parser to get the skin info
                Parser = new MpeParser(skinDir, new DirectoryInfo(MediaPortalEditor.Global.Preferences.MediaPortalDir));
                Parser.Load();

                // Create rootNode
                rootNode                    = skinTree.Nodes.Add("Skin (" + Parser.SkinName + ")");
                rootNode.ImageIndex         = 0;
                rootNode.SelectedImageIndex = 0;
                // Load skin resources
                LoadControls();
                LoadFonts();
                LoadImages();
                LoadLanguages();
                LoadScreens();
                // Setup tree
                skinTree.Scrollable = true;
                skinTree.Nodes[0].Expand();
                skinTree.Enabled = true;
                skinTree.Focus();
            }
            catch (MpeParserException spe)
            {
                MpeLog.Debug(spe);
                MpeLog.Error(spe);
            }
            catch (Exception e)
            {
                MpeLog.Debug(e);
                MpeLog.Error(e);
            }
        }
Exemple #15
0
 public virtual void PasteControl()
 {
     if (mask.SelectedControl is MpeContainer)
     {
         if (mpe.Clipboard != null && mpe.Clipboard is MpeControl)
         {
             try
             {
                 MpeControl c = ((MpeControl)mpe.Clipboard).Copy();
                 c.Left += mask.GridSize.Width;
                 c.Top  += mask.GridSize.Height;
                 mask.SelectedControl.Controls.Add(c);
                 mask.SelectedControl = c;
                 UpdatePropertyManager();
                 MpeLog.Info("Pasted control...");
             }
             catch (Exception ee)
             {
                 MpeLog.Debug(ee);
                 MpeLog.Error(ee);
             }
         }
     }
 }
Exemple #16
0
        protected void OnMenuSelection(MenuCommand c)
        {
            if (c == null)
            {
                return;
            }
            if (selectedNode == null || selectedNode.Parent == null)
            {
                return;
            }
            switch (c.Text)
            {
            case "Delete":
                if (mpe.IsResourceOpen(selectedNode.Text))
                {
                    MpeLog.Warn("The resource file cannot be deleted because it is currently being editted.");
                    MessageBox.Show(this, "The resource file cannot be deleted because it is currently being editted.",
                                    "Error Deleting File", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
                if (selectedNode.Parent == imageNode)
                {
                    DialogResult result =
                        MessageBox.Show(this,
                                        "Are you sure you want to permanently delete the selected image?\n\n" + selectedNode.Text,
                                        "Delete Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                    if (result == DialogResult.Yes)
                    {
                        try
                        {
                            Parser.DeleteImageFile(selectedNode.Text);
                            MpeLog.Info("Deleted image file [" + selectedNode.Text + "]");
                        }
                        catch (Exception ee)
                        {
                            MpeLog.Debug(ee);
                            MpeLog.Error(ee);
                        }
                        finally
                        {
                            LoadImages();
                        }
                    }
                }
                else if (selectedNode.Parent == screenNode)
                {
                    DialogResult result =
                        MessageBox.Show(this,
                                        "Are you sure you want to permanently delete the selected screen?\n\n" + selectedNode.Text,
                                        "Delete Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                    if (result == DialogResult.Yes)
                    {
                        try
                        {
                            Parser.DeleteScreenFile(selectedNode.Text);
                            MpeLog.Info("Deleted screen file [" + selectedNode.Text + "]");
                        }
                        catch (Exception ee)
                        {
                            MpeLog.Debug(ee);
                            MpeLog.Error(ee);
                        }
                        finally
                        {
                            LoadScreens();
                        }
                    }
                }
                else if (selectedNode.Parent == fontNode)
                {
                    DialogResult result =
                        MessageBox.Show(this,
                                        "Are you sure you want to permanently delete the selected font?\n\n" + selectedNode.Text,
                                        "Delete Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                    if (result == DialogResult.Yes)
                    {
                        try
                        {
                            Parser.DeleteFont(selectedNode.Text);
                            MpeLog.Info("Deleted font [" + selectedNode.Text + "]");
                        }
                        catch (Exception ee)
                        {
                            MpeLog.Debug(ee);
                            MpeLog.Error(ee);
                        }
                        finally
                        {
                            LoadFonts();
                        }
                    }
                }
                break;

            case "Rename":
                if (selectedNode.Parent == imageNode || selectedNode.Parent == screenNode || selectedNode.Parent == fontNode)
                {
                    skinTree.SelectedNode = selectedNode;
                    skinTree.LabelEdit    = true;
                    if (selectedNode.IsEditing == false)
                    {
                        selectedNode.BeginEdit();
                    }
                }
                break;

            case "Add Existing...":
                if (selectedNode == imageNode)
                {
                    openFileDialog.Title  = "Add Existing Image";
                    openFileDialog.Filter = "Image Files (*.png;*.jpg;*.gif;*.bmp)|*.PNG;*.JPG;*.GIF;*.BMP";
                    DialogResult result = openFileDialog.ShowDialog(this);
                    if (result == DialogResult.OK)
                    {
                        try
                        {
                            FileInfo newImageFile = Parser.AddImageFile(new FileInfo(openFileDialog.FileName));
                            LoadImages();
                            for (int i = 0; i < imageNode.Nodes.Count; i++)
                            {
                                if (imageNode.Nodes[i].Text.Equals(newImageFile.Name))
                                {
                                    selectedNode          = imageNode.Nodes[i];
                                    skinTree.SelectedNode = imageNode.Nodes[i];
                                    skinTree.LabelEdit    = true;
                                    selectedNode.BeginEdit();
                                    break;
                                }
                            }
                            MpeLog.Info("Added image file [" + newImageFile.FullName + "]");
                        }
                        catch (Exception ee)
                        {
                            MpeLog.Debug(ee);
                            MpeLog.Error(ee);
                        }
                    }
                }
                else if (selectedNode == screenNode)
                {
                    openFileDialog.Title  = "Add Existing Screen";
                    openFileDialog.Filter = "Screen Files (*.xml)|*.XML";
                    DialogResult result = openFileDialog.ShowDialog(this);
                    if (result == DialogResult.OK)
                    {
                        try
                        {
                            FileInfo newScreenFile = Parser.AddScreenFile(new FileInfo(openFileDialog.FileName));
                            LoadScreens();
                            for (int i = 0; i < screenNode.Nodes.Count; i++)
                            {
                                if (screenNode.Nodes[i].Text.Equals(newScreenFile.Name))
                                {
                                    selectedNode          = screenNode.Nodes[i];
                                    skinTree.SelectedNode = screenNode.Nodes[i];
                                    skinTree.LabelEdit    = true;
                                    selectedNode.BeginEdit();
                                    break;
                                }
                            }
                            MpeLog.Info("Added screen file [" + openFileDialog.FileName + "]");
                        }
                        catch (Exception ee)
                        {
                            MpeLog.Debug(ee);
                            MpeLog.Error(ee);
                        }
                    }
                }
                break;

            case "Add New...":
                if (selectedNode == screenNode)
                {
                    try
                    {
                        FileInfo f = Parser.AddScreenFile();
                        MpeLog.Info("Added new screen file [" + f.Name + "]");
                        LoadScreens();
                        for (int i = 0; i < screenNode.Nodes.Count; i++)
                        {
                            if (screenNode.Nodes[i].Text.Equals(f.Name))
                            {
                                skinTree.SelectedNode = screenNode.Nodes[i];
                                selectedNode          = screenNode.Nodes[i];
                                skinTree.LabelEdit    = true;
                                selectedNode.BeginEdit();
                                return;
                            }
                        }
                    }
                    catch (Exception ee)
                    {
                        MpeLog.Debug(ee);
                        MpeLog.Error(ee);
                    }
                }
                else if (selectedNode == fontNode)
                {
                    try
                    {
                        string s = Parser.AddFont();
                        MpeLog.Info("Added new font [" + s + "]");
                        LoadFonts();
                        for (int i = 0; i < fontNode.Nodes.Count; i++)
                        {
                            if (fontNode.Nodes[i].Text.Equals(s))
                            {
                                skinTree.SelectedNode = fontNode.Nodes[i];
                                selectedNode          = fontNode.Nodes[i];
                                skinTree.LabelEdit    = true;
                                selectedNode.BeginEdit();
                                return;
                            }
                        }
                    }
                    catch (Exception ee)
                    {
                        MpeLog.Debug(ee);
                        MpeLog.Error(ee);
                    }
                }
                break;

            case "Window":
                if (mpe.IsResourceOpen(selectedNode.Text))
                {
                    MpeLog.Warn("The screen type cannot be modified because it is currently being editted.");
                    MessageBox.Show(this, "The screen type cannot be modified because it is currently being editted..",
                                    "Error Modifying Screen Type", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
                else
                {
                    if (DialogResult.Yes ==
                        MessageBox.Show(this, "Are you sure you want to change this screen's type?", "Screen Type Confirmation",
                                        MessageBoxButtons.YesNo, MessageBoxIcon.Question))
                    {
                        MpeScreenInfo info = Parser.ModifyScreenType(selectedNode.Text, MpeScreenType.Window);
                        selectedNode.Tag                = info;
                        selectedNode.ImageIndex         = 6;
                        selectedNode.SelectedImageIndex = 6;
                    }
                }
                break;

            case "Dialog":
                if (mpe.IsResourceOpen(selectedNode.Text))
                {
                    MpeLog.Warn("The screen type cannot be modified because it is currently being editted.");
                    MessageBox.Show(this, "The screen type cannot be modified because it is currently being editted..",
                                    "Error Modifying Screen Type", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
                else
                {
                    if (DialogResult.Yes ==
                        MessageBox.Show(this, "Are you sure you want to change this screen's type?", "Screen Type Confirmation",
                                        MessageBoxButtons.YesNo, MessageBoxIcon.Question))
                    {
                        MpeScreenInfo info = Parser.ModifyScreenType(selectedNode.Text, MpeScreenType.Dialog);
                        selectedNode.Tag                = info;
                        selectedNode.ImageIndex         = 7;
                        selectedNode.SelectedImageIndex = 7;
                    }
                }
                break;

            case "OnScreenDisplay":
                if (mpe.IsResourceOpen(selectedNode.Text))
                {
                    MpeLog.Warn("The screen type cannot be modified because it is currently being editted.");
                    MessageBox.Show(this, "The screen type cannot be modified because it is currently being editted..",
                                    "Error Modifying Screen Type", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
                else
                {
                    if (DialogResult.Yes ==
                        MessageBox.Show(this, "Are you sure you want to change this screen's type?", "Screen Type Confirmation",
                                        MessageBoxButtons.YesNo, MessageBoxIcon.Question))
                    {
                        MpeScreenInfo info = Parser.ModifyScreenType(selectedNode.Text, MpeScreenType.OnScreenDisplay);
                        selectedNode.Tag                = info;
                        selectedNode.ImageIndex         = 8;
                        selectedNode.SelectedImageIndex = 8;
                    }
                }
                break;
            }
        }
Exemple #17
0
 private void OnAfterLabelEdit(object sender, NodeLabelEditEventArgs e)
 {
     if (e.Node == null || e.Label == null)
     {
         return;
     }
     if (e.Node.Parent == imageNode)
     {
         int    i1 = e.Node.Text.LastIndexOf(".");
         string s1 = (i1 > 0) ? e.Node.Text.Substring(i1) : "";
         int    i2 = e.Label.LastIndexOf(".");
         string s2 = (i2 > 0) ? e.Label.Substring(i2) : "";
         if (s1.ToLower().Equals(s2.ToLower()) == false)
         {
             MessageBox.Show(this, "You cannot change an image file's extension.", "Error Renaming File",
                             MessageBoxButtons.OK, MessageBoxIcon.Warning);
             e.CancelEdit = true;
             e.Node.BeginEdit();
             return;
         }
         try
         {
             FileInfo f = Parser.RenameImageFile(e.Node.Text, e.Label);
             e.Node.EndEdit(false);
             e.Node.Tag = f;
             MpeLog.Info("Renamed image file from [" + e.Node.Text + "] to [" + e.Label + "]");
             skinTree.LabelEdit = false;
             return;
         }
         catch (Exception ee)
         {
             MpeLog.Debug(ee);
             if (ee.Message.IndexOf("being used by another process") > 0)
             {
                 MpeLog.Warn("The image file cannot be renamed because it is locked by another process.");
                 MessageBox.Show(this,
                                 "The image cannot be renamed because it is locked by another process.\n\nIf the image is currently open inside the MediaPortal Editor, please close the image, and try again.",
                                 "Error Renaming File", MessageBoxButtons.OK, MessageBoxIcon.Warning);
             }
             else if (ee.Message.IndexOf("already exists") > 0)
             {
                 MpeLog.Warn("An image file with the name [" + e.Label + "] already exists.");
                 MessageBox.Show(this, "An image file with the name \"" + e.Label + "\" already exists.",
                                 "Error Renaming File", MessageBoxButtons.OK, MessageBoxIcon.Warning);
             }
             else
             {
                 MpeLog.Error(ee);
                 MessageBox.Show(this, ee.Message, "Error Renaming File", MessageBoxButtons.OK, MessageBoxIcon.Error);
             }
         }
         e.CancelEdit = true;
         e.Node.EndEdit(true);
     }
     else if (e.Node.Parent == screenNode)
     {
         if (e.Label.ToLower().EndsWith(".xml") == false)
         {
             MessageBox.Show(this, "You cannot change a screen file's extension.", "Error Renaming File",
                             MessageBoxButtons.OK, MessageBoxIcon.Warning);
             e.CancelEdit = true;
             e.Node.BeginEdit();
             return;
         }
         try
         {
             MpeScreenInfo info = Parser.RenameScreenFile(e.Node.Text, e.Label);
             e.Node.EndEdit(false);
             e.Node.Tag = info;
             MpeLog.Info("Renamed screen file from [" + e.Node.Text + "] to [" + e.Label + "]");
             skinTree.LabelEdit = false;
             return;
         }
         catch (Exception ee)
         {
             MpeLog.Debug(ee);
             if (ee.Message.IndexOf("being used by another process") > 0)
             {
                 MpeLog.Warn("The screen file cannot be renamed because it is locked by another process.");
                 MessageBox.Show(this,
                                 "The screen cannot be renamed because it is locked by another process.\n\nIf the screen is currently open inside the MediaPortal Editor, please close the screen, and try again.",
                                 "Error Renaming File", MessageBoxButtons.OK, MessageBoxIcon.Warning);
             }
             else if (ee.Message.IndexOf("already exists") > 0)
             {
                 MpeLog.Warn("A screen file with the name [" + e.Label + "] already exists.");
                 MessageBox.Show(this, "A screen file with the name \"" + e.Label + "\" already exists.",
                                 "Error Renaming File", MessageBoxButtons.OK, MessageBoxIcon.Warning);
             }
             else
             {
                 MpeLog.Error(ee);
                 MessageBox.Show(this, ee.Message, "Error Renaming File", MessageBoxButtons.OK, MessageBoxIcon.Error);
             }
         }
         e.CancelEdit = true;
         e.Node.EndEdit(true);
     }
     else if (e.Node.Parent == fontNode)
     {
         try
         {
             Parser.RenameFont(e.Node.Text, e.Label);
             e.Node.EndEdit(false);
             e.Node.Tag = Parser.GetFont(e.Label);
             MpeLog.Info("Renamed font from [" + e.Node.Text + "] to [" + e.Label + "]");
             skinTree.LabelEdit = false;
             return;
         }
         catch (Exception ee)
         {
             MpeLog.Debug(ee);
             if (ee.Message.IndexOf("already exists") > 0)
             {
                 MpeLog.Warn("A font with the name [" + e.Label + "] already exists.");
                 MessageBox.Show(this, "A font with the name \"" + e.Label + "\" already exists.", "Error Renaming File",
                                 MessageBoxButtons.OK, MessageBoxIcon.Warning);
             }
             else
             {
                 MpeLog.Error(ee);
                 MessageBox.Show(this, ee.Message, "Error Renaming Font", MessageBoxButtons.OK, MessageBoxIcon.Error);
             }
         }
         e.CancelEdit = true;
         e.Node.EndEdit(true);
     }
     skinTree.LabelEdit = false;
 }
Exemple #18
0
        public void OnMenuSelection(MenuCommand command)
        {
            if (command == null || command.Enabled == false || mask.SelectedControl == null)
            {
                return;
            }
            switch (command.Text)
            {
            case "Parent":
                mask.SelectedControl = mask.SelectedControl.MpeParent;
                UpdatePropertyManager();
                break;

            case "Send To Back":
                mask.SelectedControl.SendToBack();
                break;

            case "Bring To Front":
                mask.SelectedControl.BringToFront();
                break;

            case "Cut":
                CutControl();
                break;

            case "Copy":
                CopyControl();
                break;

            case "Paste":
                PasteControl();
                break;

            case "Delete":
                if (AllowDeletions)
                {
                    if (mask.SelectedControl.MpeParent != null)
                    {
                        try
                        {
                            MpeControl   control = mask.SelectedControl;
                            MpeContainer parent  = control.MpeParent;
                            parent.Controls.Remove(control);
                            mask.SelectedControl = null;
                            UpdatePropertyManager();
                        }
                        catch (Exception ee)
                        {
                            MpeLog.Debug(ee);
                            MpeLog.Error(ee);
                        }
                    }
                }
                break;

            case "Properties":
                mpe.FocusPropertyManager();
                break;

            case "Test":
                //mask2.SelectedControl = mask.SelectedControl;
                break;
            }
        }
Exemple #19
0
        public override void Save(XmlDocument doc, XmlNode node, MpeParser parser, MpeControl reference)
        {
            if (reference == null)
            {
                // Update reference.xml file
                if (node.Name != "controls")
                {
                    throw new MpeParserException("Invalid root node <" + node.Name + "> provided.");
                }
                // Update the skin node
                XmlNode skin = node.SelectSingleNode("skin");
                if (skin == null)
                {
                    throw new MpeParserException(
                              "Invalid reference.xml file. The <skin> element must be the first child in the document.");
                }
                skin.RemoveAll();
                parser.SetValue(doc, skin, "width", Width.ToString());
                parser.SetValue(doc, skin, "height", Height.ToString());
                // Update the image control node that defines the window background
                XmlNode image = skin.NextSibling;
                if (image == null || image.Name.Equals("control") == false)
                {
                    throw new MpeParserException(
                              "Invalid reference.xml file. A <control> element of type image must follow the <skin> element.");
                }
                XmlNode test = image.SelectSingleNode("type");
                if (test == null || test.InnerXml.Equals("image") == false)
                {
                    throw new MpeParserException(
                              "Invalid reference.xml file. A <control> element of type image must follow the <skin> element.");
                }
                image.RemoveAll();
                backImage.Save(doc, image, parser, null);
            }
            else
            {
                // Update screen.xml file
                if (node == null || node.Name.Equals("window") == false)
                {
                    throw new MpeParserException("Invalid root node <" + node.Name + "> provided. Looking for a <window> element.");
                }
                node.RemoveAll();

                if (screenType != MpeScreenType.Window)
                {
                    parser.SetValue(doc, node, "type", screenType.ToString().ToLower());
                }

                parser.SetValue(doc, node, "id", Id.ToString());
                parser.SetValue(doc, node, "defaultcontrol", DefaultControl.ToString());
                parser.SetValue(doc, node, "allowoverlay", AllowOverlay ? "yes" : "no");
                parser.SetValue(doc, node, "autohidetopbar", AutohideTopbar ? "yes" : "no");

                XmlElement controls = doc.CreateElement("controls");
                node.AppendChild(controls);

                if (ScreenType == MpeScreenType.Dialog)
                {
                    MpeGroup dg = DialogGroup;

                    //if (dg.TextureBack != null) {
                    XmlElement image = doc.CreateElement("control");
                    dg.TextureBackImage.Save(doc, image, parser, parser.GetControl(MpeControlType.Image));
                    controls.AppendChild(image);
                    //}

                    for (int i = dg.Controls.Count - 1; i >= 0; i--)
                    {
                        if (dg.Controls[i] is MpeControl)
                        {
                            MpeControl control = (MpeControl)dg.Controls[i];
                            try
                            {
                                XmlElement element          = doc.CreateElement("control");
                                MpeControl referenceControl = parser.GetControl(control.Type);
                                control.Save(doc, element, parser, referenceControl);
                                controls.AppendChild(element);
                            }
                            catch (Exception e)
                            {
                                MpeLog.Debug(e);
                                MpeLog.Error(e);
                                throw new MpeParserException(e.Message);
                            }
                        }
                    }
                }
                else
                {
                    if (TextureBack != null)
                    {
                        XmlElement image = doc.CreateElement("control");
                        backImage.Save(doc, image, parser, parser.GetControl(MpeControlType.Image));
                        controls.AppendChild(image);
                    }

                    for (int i = Controls.Count - 1; i >= 0; i--)
                    {
                        if (Controls[i] is MpeControl)
                        {
                            MpeControl control = (MpeControl)Controls[i];
                            try
                            {
                                XmlElement element          = doc.CreateElement("control");
                                MpeControl referenceControl = parser.GetControl(control.Type);
                                control.Save(doc, element, parser, referenceControl);
                                controls.AppendChild(element);
                            }
                            catch (Exception e)
                            {
                                MpeLog.Debug(e);
                                MpeLog.Error(e);
                                throw new MpeParserException(e.Message);
                            }
                        }
                    }
                }
            }
        }
        public void Save(XmlDocument doc, XmlNode node, MpeParser parser, MpeControl reference)
        {
            MpeLog.Debug("MpeFont.Save()");
            textureWorkDir = parser.FontDir.FullName;
            parser.SetValue(doc, node, "name", Name);
            parser.SetValue(doc, node, "filename", Family);
            parser.SetInt(doc, node, "height", Size);
            parser.SetValue(doc, node, "style", Style);
            parser.SetInt(doc, node, "start", StartCharacter);
            parser.SetInt(doc, node, "end", EndCharacter - 1);
            // Setup Texture Files
            if (textureWorkDir != null)
            {
                int    size     = Size;
                string sTexture = textureWorkDir + "\\" + name + "_" + size + ".png";
                string sData    = sTexture + ".xml";
                if (textureFile != null && textureFile.Exists && textureFile.FullName.Equals(sTexture) == false)
                {
                    MpeLog.Info("Moving texture file...");
                    textureFile.MoveTo(sTexture);
                    textureFile.Refresh();
                }
                else
                {
                    textureFile = new FileInfo(sTexture);
                }
                if (textureDataFile != null && textureDataFile.Exists && textureDataFile.FullName.Equals(sData) == false)
                {
                    MpeLog.Info("Moving texture data file...");
                    textureDataFile.MoveTo(sData);
                    textureDataFile.Refresh();
                }
                else
                {
                    textureDataFile = new FileInfo(sData);
                }
            }
            // Save Texture
            try
            {
                textureFile.Delete();
                texture.Save(textureFile.FullName);
                textureFile.Refresh();
            }
            catch (Exception e)
            {
                MpeLog.Error(e);
                throw new MpeParserException("Error saving font. Could not write to texture file.");
            }
            // Save Texture Data
            Stream s = null;

            try
            {
                textureDataFile.Delete();
                s = File.Open(textureDataFile.FullName, FileMode.CreateNew, FileAccess.ReadWrite);
                SoapFormatter b = new SoapFormatter();
                b.Serialize(s, (object)textureCoordinates);
                textureDataFile.Refresh();
            }
            catch (Exception e)
            {
                MpeLog.Debug(e);
                throw new MpeParserException("Error saving font. Could not write to texture data file.");
            }
            finally
            {
                if (s != null)
                {
                    s.Close();
                }
            }
        }
        private void GenerateTexture()
        {
            //Create an array to store character dimensions
            textureCoordinates = new float[(10 + endChar - startChar), 4];

            // Create a bitmap on which to measure the alphabet
            Bitmap bmp = new Bitmap(1, 1, PixelFormat.Format32bppArgb);

            Graphics g = Graphics.FromImage(bmp);

            g.SmoothingMode     = SmoothingMode.AntiAlias;
            g.TextRenderingHint = TextRenderingHint.AntiAlias;
            g.TextContrast      = 0;

            // Establish the font and texture size
            float textureScale = 1.0f; // Draw fonts into texture without scaling

            // Calculate the dimensions for the smallest power-of-two texture which
            // can hold all the printable characters
            int textureWidth;
            int textureHeight;

            textureWidth = textureHeight = 64;
            for (;;)
            {
                try
                {
                    // Measure the alphabet
                    MpeLog.Debug("Calculating texture size. Scale=" + textureScale + " Width=" + textureWidth + " Height=" +
                                 textureHeight);
                    PaintTexture(g, true, textureScale, textureWidth, textureHeight);
                }
                catch (InvalidOperationException)
                {
                    // Scale up the texture size and try again
                    textureWidth  *= 2;
                    textureHeight *= 2;
                    continue;
                }

                break;
            }
            MpeLog.Debug("Calculated texture size. Scale = [" + textureScale + "] Width = [" + textureWidth + "] Height = [" +
                         textureHeight + "]");
            bmp.Dispose();

            // Release the bitmap used for measuring and create one for drawing
            bmp                 = new Bitmap(textureWidth, textureHeight, PixelFormat.Format32bppArgb);
            g                   = Graphics.FromImage(bmp);
            g.SmoothingMode     = SmoothingMode.AntiAlias;
            g.TextRenderingHint = TextRenderingHint.AntiAlias;
            g.TextContrast      = 0;

            // Draw the alphabet
            PaintTexture(g, false, textureScale, textureWidth, textureHeight);
            textureCoordinates[endChar - startChar, 0] = spacingPerChar;

            // Create a new texture and data for the font from the bitmap we just created
            try
            {
                if (texture != null)
                {
                    texture.Dispose();
                }
                texture = new Bitmap(bmp);
                ConvertTextureData();
                MpeLog.Info("Generated font texture and data [" + name + "]");
            }
            catch (Exception e)
            {
                MpeLog.Error(e);
            }
            finally
            {
                if (bmp != null)
                {
                    bmp.Dispose();
                }
                if (g != null)
                {
                    g.Dispose();
                }
            }
        }