Example #1
0
        private void Form1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            Text = "SkyHD Remote";
            string     m_ipaddress = Controllers[m_currentController].ipaddress;
            ButtonRect item        = CheckButtonHit(e.X, e.Y);

            if (item != null)
            {
                Command c = (Command)commandsHash[item.buttonName];
                if (c != null)
                {
                    SendCommand(m_ipaddress, (byte)c.id);
                }
            }
        }
Example #2
0
        private ButtonRect CheckButtonHit(int x, int y)
        {
            ButtonRect ret = null;
            ArrayList  buttons;

            buttons = buttonRectsPlus;

            foreach (ButtonRect item in buttons)
            {
                if (item.rect.Contains(x, y))
                {
                    Text = "SkyHD Remote [" + item.buttonName + "]";
                    ret  = item;
                    break;
                }
            }

            return(ret);
        }
Example #3
0
        private void loadConfig()
        {
            XmlNodeList   elemList;
            XmlTextReader reader;
            XmlDocument   doc;

            reader = new XmlTextReader("data/controllers.xml");
            doc    = new XmlDocument();
            try
            {
                doc.Load(reader);
            }
            catch (Exception e)
            {
                MessageBox.Show("controllers.xml could not be loaded. (" + e.ToString() + ")", "Error",
                                MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

            // find the controllers/connections configuration
            elemList = doc.GetElementsByTagName("controller");
            for (int i = 0; i < elemList.Count; i++)
            {
                string name      = elemList[i].Attributes["name"].Value;
                string ipaddress = elemList[i].Attributes["ipaddress"].Value;

                skyBoxList.Items.Add(name);

                Controllers.Add(new Controller(name, ipaddress));
            }
            skyBoxList.SelectedIndex = 0;

            // set the width of the dropdown list to accomodate the widest item
            {
                int      width = skyBoxList.DropDownWidth;
                Graphics g     = skyBoxList.CreateGraphics();
                Font     font  = skyBoxList.Font;

                foreach (string s in (skyBoxList.Items))
                {
                    int newWidth = (int)g.MeasureString(s, font).Width +
                                   SystemInformation.VerticalScrollBarWidth;;
                    if (width < newWidth)
                    {
                        width = newWidth;
                    }
                }
                skyBoxList.Width = width;
            }

            reader.Close();

            reader = new XmlTextReader("data/buttons.xml");
            doc    = new XmlDocument();
            try
            {
                doc.Load(reader);
            }
            catch (Exception e)
            {
                MessageBox.Show("buttons.xml could not be loaded. (" + e.ToString() + ")", "Error",
                                MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

            // Setup commands
            elemList = doc.GetElementsByTagName("command");
            for (int i = 0; i < elemList.Count; i++)
            {
                string  name = elemList[i].Attributes["name"].Value;
                int     id   = int.Parse(elemList[i].Attributes["id"].Value);
                Command item = new Command(name, id);

                commands.Add(item);
                commandsHash[item.name] = item;
            }

            // Setup buttons
            XmlNodeList buttons = doc.GetElementsByTagName("buttons");

            if (buttons[0] != null)
            {
                for (XmlNode i = buttons[0].FirstChild; i != null; i = i.NextSibling)
                {
                    String    name   = i.Attributes["name"].Value;
                    int       x      = int.Parse(i.Attributes["x"].Value);
                    int       y      = int.Parse(i.Attributes["y"].Value);
                    int       width  = int.Parse(i.Attributes["width"].Value);
                    int       height = int.Parse(i.Attributes["height"].Value);
                    Rectangle rect   = new Rectangle(x, y, width, height);

                    ButtonRect item = new ButtonRect(name, rect);
                    buttonRects.Add(item);
                }
            }

            XmlNodeList buttonsplus = doc.GetElementsByTagName("buttonsplus");

            if (buttonsplus[0] != null)
            {
                for (XmlNode i = buttonsplus[0].FirstChild; i != null; i = i.NextSibling)
                {
                    String    name   = i.Attributes["name"].Value;
                    int       x      = int.Parse(i.Attributes["x"].Value);
                    int       y      = int.Parse(i.Attributes["y"].Value);
                    int       width  = int.Parse(i.Attributes["width"].Value);
                    int       height = int.Parse(i.Attributes["height"].Value);
                    Rectangle rect   = new Rectangle(x, y, width, height);

                    ButtonRect item = new ButtonRect(name, rect);
                    buttonRectsPlus.Add(item);
                }
            }
            reader.Close();
        }