コード例 #1
0
        public void SendKeyFeature(int key, IButtonPressAction action)
        {
            if (!CheckDevice())
            {
                return;
            }
            int numTimes = 3;
            //lock (lockObj)
            {
                byte[] ret = new byte[34];
                byte[] buf;


                buf = PictureConverter.GetBuffer(action);
                device.Write(buf.Take(8017).ToArray());
                device.Write(buf.Skip(8017).ToArray());

                buf = new byte[] { 0x12, 0x01, 0x00, 0x00, (byte)key, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf6, 0x3c,
                                   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };

                for (int i = 0; i < numTimes; i++)
                {
                    //_device.WriteFeatureData(buf);
                    //_device.ReadFeatureData(out ret);
                    Thread.Sleep(1);
                    device.SendFeatureReport(buf);
                    return;
                    //device.GetFeatureReport(ret);
                }
            }
        }
コード例 #2
0
        public static byte[] GetBuffer(IButtonPressAction action)
        {
            Image  image = action.Icon;
            string title = action.Title;

            if (image == null)
            {
                byte[] buf = new byte[8017 * 2];
                Array.Clear(buf, 0, buf.Length);
                Header1.CopyTo(buf, 0);
                Header2.CopyTo(buf, 8017);
                return(buf);
            }

            Bitmap     bmp   = ResizeImage(image, 72, 72);
            RectangleF rectf = new RectangleF(5, 50, 62, 15);

            if (!string.IsNullOrEmpty(title) && action.ShowTitleLabel)
            {
                using (Graphics g = Graphics.FromImage(bmp))
                {
                    g.SmoothingMode     = SmoothingMode.AntiAlias;
                    g.InterpolationMode = InterpolationMode.HighQualityBicubic;
                    g.PixelOffsetMode   = PixelOffsetMode.HighQuality;
                    g.DrawString(title, new Font(action.Titlefont.Family?.Source, (float)action.Titlefont.Size),
                                 new SolidBrush(Color.FromArgb(action.Titlefont.Color.Brush.Color.R, action.Titlefont.Color.Brush.Color.G, action.Titlefont.Color.Brush.Color.B)), rectf);

                    g.Flush();
                }
            }



            List <byte> imageBuf = new List <byte>(72 * 72 * 3);

            for (int i = 0; i < 72 * 72; i++)
            {
                System.Drawing.Color color = bmp.GetPixel(i / 72, i % 72);

                imageBuf.Add(color.B);
                imageBuf.Add(color.G);
                imageBuf.Add(color.R);
            }

            List <byte> bytes = Header1.Concat(imageBuf.Take(8017 - Header1.Length)).Concat(Header2).Concat(imageBuf.Skip(8017 - Header1.Length)).ToList();

            while (bytes.Count() < 8017 * 2)
            {
                bytes.Add(0);
            }
            return(bytes.ToArray());
        }
コード例 #3
0
        public void AddAction(int index, IButtonPressAction action)
        {
            lock (lockObj)
            {
                string fullPath = string.Join("-", CurrentFolderDir.Reverse()) + "-" + index.ToString();
                fullPath = fullPath.Trim(new[] { '-' });
                if (allActions.ContainsKey(fullPath))
                {
                    allActions[fullPath] = action;
                }
                else
                {
                    allActions.TryAdd(fullPath, action);
                }

                string path = System.IO.Path.Combine("Images", fullPath + ".png");
                action.Icon = action.Icon ?? (action.GetDefaultIconPath() != null ? Bitmap.FromFile(action.GetDefaultIconPath()) : null);

                action?.Icon?.Save(path);

                Save();
            }
            LoadIcons();
        }
コード例 #4
0
        public void Load()
        {
            allActions.Clear();
            if (!File.Exists(SaveFileName))
            {
                return;
            }
            XDocument doc = XDocument.Load(SaveFileName);

            foreach (XElement elem in doc.Element("root").Elements())
            {
                string             path   = "";
                IButtonPressAction action = null;
                switch (elem.Name.LocalName)
                {
                case "FolderAction":
                    FolderAction folderAction = new FolderAction();
                    action                        = folderAction;
                    path                          = elem.Attribute("Key").Value.ToString();
                    folderAction.Title            = elem.Attribute("Title").Value.ToString();
                    folderAction.ExeConditionName = elem.Attribute("ExeCondition").Value.ToString();
                    if (elem.Attribute("BackgroundColor") != null)
                    {
                        folderAction.BackgroundColor =
                            System.Drawing.ColorTranslator.FromHtml(elem.Attribute("BackgroundColor").Value.ToString());
                    }
                    if (elem.Attribute("Font") != null)
                    {
                        folderAction.Titlefont = FontSerializationHelper.Deserialize(elem.Attribute("Font").Value);
                    }
                    folderAction.ShowTitleLabel = bool.Parse(elem.Attribute("ShowTitleLabel")?.Value ?? "False");
                    allActions.TryAdd(path, folderAction);
                    break;

                case "LaunchAction":
                    LaunchAction launchAction = new LaunchAction();
                    action               = launchAction;
                    path                 = elem.Attribute("Key").Value.ToString();
                    launchAction.Title   = elem.Attribute("Title").Value.ToString();
                    launchAction.ExePath = elem.Attribute("ExePath").Value.ToString();
                    launchAction.Args    = elem.Attribute("Args").Value.ToString();
                    if (elem.Attribute("BackgroundColor") != null)
                    {
                        launchAction.BackgroundColor =
                            System.Drawing.ColorTranslator.FromHtml(elem.Attribute("BackgroundColor").Value.ToString());
                    }
                    if (elem.Attribute("Font") != null)
                    {
                        launchAction.Titlefont = FontSerializationHelper.Deserialize(elem.Attribute("Font").Value);
                    }
                    launchAction.ShowTitleLabel = bool.Parse(elem.Attribute("ShowTitleLabel")?.Value ?? "False");
                    var result = LaunchAction.ProcessRunningAction.FocusOldProcess;
                    Enum.TryParse(elem.Attribute("AlreadyRunningAction").Value.ToString(), out result);
                    launchAction.AlreadyRunningAction = result;
                    allActions.TryAdd(path, launchAction);
                    break;

                case "StringAction":
                    TextStringAction textAction = new TextStringAction();
                    action           = textAction;
                    path             = elem.Attribute("Key").Value.ToString();
                    textAction.Title = elem.Attribute("Title").Value.ToString();
                    textAction.Value = elem.Attribute("Value").Value.ToString();
                    if (elem.Attribute("BackgroundColor") != null)
                    {
                        textAction.BackgroundColor =
                            System.Drawing.ColorTranslator.FromHtml(elem.Attribute("BackgroundColor").Value.ToString());
                    }
                    if (elem.Attribute("Font") != null)
                    {
                        textAction.Titlefont = FontSerializationHelper.Deserialize(elem.Attribute("Font").Value);
                    }
                    textAction.ShowTitleLabel = bool.Parse(elem.Attribute("ShowTitleLabel")?.Value ?? "False");
                    allActions.TryAdd(path, textAction);
                    break;

                case "HotkeyAction":
                    HotkeyAction hotkeyAction = new HotkeyAction();
                    action = hotkeyAction;
                    path   = elem.Attribute("Key").Value.ToString();
                    if (elem.Attribute("BackgroundColor") != null)
                    {
                        hotkeyAction.BackgroundColor =
                            System.Drawing.ColorTranslator.FromHtml(elem.Attribute("BackgroundColor").Value.ToString());
                    }
                    if (elem.Attribute("Font") != null)
                    {
                        hotkeyAction.Titlefont = FontSerializationHelper.Deserialize(elem.Attribute("Font").Value);
                    }
                    hotkeyAction.Title          = elem.Attribute("Title").Value.ToString();
                    hotkeyAction.ShowTitleLabel = bool.Parse(elem.Attribute("ShowTitleLabel")?.Value ?? "False");
                    for (int i = 0; i < 3; i++)
                    {
                        VirtualKeyCode key = (VirtualKeyCode)int.Parse(elem.Attribute("Mod" + i).Value.ToString());
                        if (key != 0)
                        {
                            hotkeyAction.Modifiers.Add(key);
                        }
                    }

                    hotkeyAction.MainKey = (VirtualKeyCode)int.Parse(elem.Attribute("MainKey").Value.ToString());
                    allActions.TryAdd(path, hotkeyAction);
                    break;
                }
                if (File.Exists("Images/" + path + ".png"))
                {
                    action.Icon = Bitmap.FromFile("Images/" + path + ".png");
                }
            }
        }