Esempio n. 1
0
 public void btnidlebrowse_Click(object s, EventArgs a)
 {
     AppearanceManager.SetupDialog(new FileDialog(new[] { ".png", ".gif", ".jpg", ".bmp", ".pic" }, FileOpenerStyle.Open, new Action <string>((file) =>
     {
         ImageAsBinary = Utils.ReadAllBytes(file);
         System.IO.File.WriteAllBytes("temp_bin.bmp", ImageAsBinary);
         Image = SkinEngine.ImageFromBinary(ImageAsBinary);
         Setup();
     })));
 }
Esempio n. 2
0
 public byte[] ProcessImage(byte[] original)
 {
     try
     {
         var img      = SkinEngine.ImageFromBinary(original);
         var dithered = DitheringEngine.DitherImage(img);
         using (var mstr = new MemoryStream())
         {
             dithered.Save(mstr, System.Drawing.Imaging.ImageFormat.Bmp);
             return(mstr.ToArray());
         }
     }
     catch
     {
         return(original);
     }
 }
Esempio n. 3
0
        public Image GetImage(string id)
        {
            var type = typeof(ShiftOS.Engine.Skin);

            foreach (var field in type.GetFields(BindingFlags.Public | BindingFlags.Instance))
            {
                foreach (var attrib in field.GetCustomAttributes(false))
                {
                    if (attrib is ImageAttribute)
                    {
                        var img = attrib as ImageAttribute;
                        if (img.Name == id)
                        {
                            return(SkinEngine.ImageFromBinary((byte[])field.GetValue(LoadedSkin)));
                        }
                    }
                }
            }
            return(null);
        }
Esempio n. 4
0
        public Image GetImage(string img)
        {
            var type = typeof(Skin);

            foreach (var field in type.GetFields())
            {
                foreach (var attr in field.GetCustomAttributes(false))
                {
                    if (attr is ImageAttribute)
                    {
                        var iattr = attr as ImageAttribute;
                        if (iattr.Name == img)
                        {
                            byte[] image = (byte[])field.GetValue(LoadedSkin);
                            return(SkinEngine.ImageFromBinary(image));
                        }
                    }
                }
            }

            return(null);
        }
Esempio n. 5
0
        public void PopulateBody(string cat, string subcat)
        {
            flbody.Controls.Clear();

            List <ShifterSetting> cats = new List <ShifterSetting>();

            foreach (var c in this.settings)
            {
                if (c.SubCategory == subcat && c.Category == cat)
                {
                    if (c.Field.FlagFullfilled(LoadedSkin))
                    {
                        if (!cats.Contains(c))
                        {
                            cats.Add(c);
                        }
                    }
                }
            }

            foreach (var c in cats)
            {
                var lbl         = new Label();
                int labelHeight = 0;
                lbl.AutoSize = true;
                lbl.Text     = c.Name + ":";
                flbody.Controls.Add(lbl);
                lbl.TextAlign = ContentAlignment.MiddleLeft;
                lbl.Show();
                //Cool - label's in.
                if (c.Field.FieldType == typeof(Point))
                {
                    var width  = new TextBox();
                    var height = new TextBox();
                    labelHeight  = width.Height; //irony?
                    width.Width  = 30;
                    height.Width = width.Width;
                    width.Text   = ((Point)c.Field.GetValue(this.LoadedSkin)).X.ToString();
                    height.Text  = ((Point)c.Field.GetValue(this.LoadedSkin)).Y.ToString();
                    flbody.SetFlowBreak(height, true);
                    ControlManager.SetupControl(width);
                    ControlManager.SetupControl(height);

                    flbody.Controls.Add(width);
                    width.Show();
                    flbody.Controls.Add(height);
                    height.Show();

                    EventHandler tc = (o, a) =>
                    {
                        try
                        {
                            int x = Convert.ToInt32(width.Text);
                            int y = Convert.ToInt32(height.Text);

                            int oldx = ((Point)c.Field.GetValue(this.LoadedSkin)).X;
                            int oldy = ((Point)c.Field.GetValue(this.LoadedSkin)).Y;

                            if (x != oldx || y != oldy)
                            {
                                c.Field.SetValue(LoadedSkin, new Point(x, y));
                                CodepointValue += 200;
                            }
                        }
                        catch
                        {
                            width.Text  = ((Point)c.Field.GetValue(this.LoadedSkin)).X.ToString();
                            height.Text = ((Point)c.Field.GetValue(this.LoadedSkin)).Y.ToString();
                        }
                    };

                    width.TextChanged  += tc;
                    height.TextChanged += tc;
                }
                else if (c.Field.FieldType == typeof(string))
                {
                    var str = new TextBox();
                    str.Width = 120;
                    ControlManager.SetupControl(str);
                    labelHeight = str.Height;
                    str.Text    = c.Field.GetValue(LoadedSkin).ToString();
                    flbody.SetFlowBreak(str, true);
                    str.TextChanged += (o, a) => { c.Field.SetValue(LoadedSkin, str.Text); CodepointValue += 100; };
                    flbody.Controls.Add(str);
                    str.Show();
                }
                else if (c.Field.FieldType == typeof(byte[]))
                {
                    //We'll assume that this is an image file.
                    var color = new Button();
                    color.Width = 40;
                    labelHeight = color.Height;
                    //just so it's flat like the system.
                    ControlManager.SetupControl(color);
                    flbody.SetFlowBreak(color, true);

                    color.BackgroundImage = SkinEngine.ImageFromBinary((byte[])c.Field.GetValue(this.LoadedSkin));
                    color.Click          += (o, a) =>
                    {
                        AppearanceManager.SetupDialog(new GraphicPicker(color.BackgroundImage, c.Name, GetLayout(c.Field.GetImageName()), new Action <byte[], Image, ImageLayout>((col, gdiImg, layout) =>
                        {
                            c.Field.SetValue(LoadedSkin, col);
                            color.BackgroundImage       = SkinEngine.ImageFromBinary(col);
                            color.BackgroundImageLayout = layout;
                            LoadedSkin.SkinImageLayouts[c.Field.GetImageName()] = layout;
                            CodepointValue += 700;
                        })));
                    };
                    flbody.Controls.Add(color);
                    color.Show();
                }
                else if (c.Field.FieldType == typeof(Size))
                {
                    var width  = new TextBox();
                    var height = new TextBox();
                    width.Width  = 30;
                    height.Width = width.Width;
                    labelHeight  = width.Height;
                    flbody.SetFlowBreak(height, true);

                    width.Text  = ((Size)c.Field.GetValue(this.LoadedSkin)).Width.ToString();
                    height.Text = ((Size)c.Field.GetValue(this.LoadedSkin)).Height.ToString();
                    ControlManager.SetupControl(width);
                    ControlManager.SetupControl(height);

                    flbody.Controls.Add(width);
                    width.Show();
                    flbody.Controls.Add(height);
                    height.Show();

                    EventHandler tc = (o, a) =>
                    {
                        try
                        {
                            int x = Convert.ToInt32(width.Text);
                            int y = Convert.ToInt32(height.Text);

                            int oldx = ((Size)c.Field.GetValue(this.LoadedSkin)).Width;
                            int oldy = ((Size)c.Field.GetValue(this.LoadedSkin)).Height;

                            if (x != oldx || y != oldy)
                            {
                                c.Field.SetValue(LoadedSkin, new Size(x, y));
                                CodepointValue += 200;
                            }
                        }
                        catch
                        {
                            width.Text  = ((Size)c.Field.GetValue(this.LoadedSkin)).Width.ToString();
                            height.Text = ((Size)c.Field.GetValue(this.LoadedSkin)).Height.ToString();
                        }
                    };

                    width.TextChanged  += tc;
                    height.TextChanged += tc;
                }
                else if (c.Field.FieldType == typeof(bool))
                {
                    var check = new CheckBox();
                    check.Checked         = ((bool)c.Field.GetValue(LoadedSkin));
                    labelHeight           = check.Height;
                    check.CheckedChanged += (o, a) =>
                    {
                        c.Field.SetValue(LoadedSkin, check.Checked);
                        CodepointValue += 50;
                    };
                    flbody.SetFlowBreak(check, true);

                    flbody.Controls.Add(check);
                    check.Show();
                }
                else if (c.Field.FieldType == typeof(Font))
                {
                    var name  = new ComboBox();
                    var size  = new TextBox();
                    var style = new ComboBox();

                    name.Width  = 120;
                    labelHeight = name.Height;
                    size.Width  = 40;
                    style.Width = 80;
                    flbody.SetFlowBreak(style, true);

                    ControlManager.SetupControl(name);
                    ControlManager.SetupControl(size);
                    ControlManager.SetupControl(style);

                    //populate the font name box
                    foreach (var font in FontFamily.Families)
                    {
                        name.Items.Add(font.Name);
                    }
                    name.Text = ((Font)c.Field.GetValue(LoadedSkin)).Name;

                    size.Text = ((Font)c.Field.GetValue(LoadedSkin)).Size.ToString();

                    //populate the style box
                    foreach (var s in (FontStyle[])Enum.GetValues(typeof(FontStyle)))
                    {
                        style.Items.Add(s.ToString());
                    }
                    style.Text = ((Font)c.Field.GetValue(LoadedSkin)).Style.ToString();

                    name.SelectedIndexChanged += (o, a) =>
                    {
                        var en = (FontStyle[])Enum.GetValues(typeof(FontStyle));

                        var f = en[style.SelectedIndex];

                        c.Field.SetValue(LoadedSkin, new Font(name.Text, (float)Convert.ToInt32(size.Text), f));
                        CodepointValue += 100;
                    };

                    style.SelectedIndexChanged += (o, a) =>
                    {
                        var en = (FontStyle[])Enum.GetValues(typeof(FontStyle));

                        var f = en[style.SelectedIndex];

                        c.Field.SetValue(LoadedSkin, new Font(name.Text, (float)Convert.ToInt32(size.Text), f));
                        CodepointValue += 50;
                    };

                    size.TextChanged += (o, a) =>
                    {
                        try
                        {
                            var en = (FontStyle[])Enum.GetValues(typeof(FontStyle));

                            var f = en[style.SelectedIndex];

                            c.Field.SetValue(LoadedSkin, new Font(name.Text, (float)Convert.ToInt32(size.Text), f));
                        }
                        catch
                        {
                            size.Text = ((Font)c.Field.GetValue(LoadedSkin)).Size.ToString();
                        }
                        CodepointValue += 50;
                    };

                    flbody.Controls.Add(name);
                    flbody.Controls.Add(size);
                    flbody.Controls.Add(style);

                    name.Show();
                    size.Show();
                    style.Show();
                }
                else if (c.Field.FieldType == typeof(Color))
                {
                    var color = new Button();
                    color.Width = 40;
                    labelHeight = color.Height;
                    //just so it's flat like the system.
                    ControlManager.SetupControl(color);

                    color.BackColor         = ((Color)c.Field.GetValue(LoadedSkin));
                    color.BackColorChanged += (o, a) =>
                    {
                        c.Field.SetValue(LoadedSkin, color.BackColor);
                    };
                    color.Click += (o, a) =>
                    {
                        AppearanceManager.SetupDialog(new ColorPicker(color.BackColor, c.Name, new Action <Color>((col) =>
                        {
                            color.BackColor = col;
                            CodepointValue += 300;
                        })));
                    };
                    flbody.SetFlowBreak(color, true);

                    flbody.Controls.Add(color);
                    color.Show();
                }
                else if (c.Field.FieldType == typeof(int))
                {
                    if (c.Field.HasShifterEnumMask())
                    {
                        var name = new ComboBox();
                        name.Width = 120;
                        ControlManager.SetupControl(name);
                        string[] items = c.Field.GetShifterEnumMask();
                        foreach (var item in items)
                        {
                            name.Items.Add(item);
                        }
                        name.SelectedIndex         = (int)c.Field.GetValue(LoadedSkin);
                        name.SelectedIndexChanged += (o, a) =>
                        {
                            c.Field.SetValue(LoadedSkin, name.SelectedIndex);
                            CodepointValue += 75;
                        };
                        labelHeight = name.Height;
                        flbody.Controls.Add(name);
                        name.Show();
                        flbody.SetFlowBreak(name, true);
                    }
                    else
                    {
                        var width = new TextBox();
                        width.Width = 30;
                        width.Text  = ((int)c.Field.GetValue(this.LoadedSkin)).ToString();
                        ControlManager.SetupControl(width);
                        labelHeight = width.Height;
                        flbody.Controls.Add(width);
                        width.Show();

                        EventHandler tc = (o, a) =>
                        {
                            try
                            {
                                int x = Convert.ToInt32(width.Text);

                                int oldx = ((int)c.Field.GetValue(this.LoadedSkin));

                                if (x != oldx)
                                {
                                    c.Field.SetValue(LoadedSkin, x);
                                    CodepointValue += 75;
                                }
                            }
                            catch
                            {
                                width.Text = ((int)c.Field.GetValue(this.LoadedSkin)).ToString();
                            }
                        };

                        width.TextChanged += tc;
                        flbody.SetFlowBreak(width, true);
                    }
                }
                lbl.AutoSize  = false;
                lbl.Width     = (int)this.CreateGraphics().MeasureString(lbl.Text, SkinEngine.LoadedSkin.MainFont).Width + 15;
                lbl.Height    = labelHeight;
                lbl.TextAlign = ContentAlignment.MiddleLeft;

                if (!string.IsNullOrWhiteSpace(c.Description))
                {
                    var desc = new Label();
                    flbody.SetFlowBreak(desc, true);
                    desc.Text     = c.Description;
                    desc.AutoSize = true;
                    flbody.Controls.Add(desc);
                    desc.Show();
                }
            }
        }