private void Start()
 {
     self          = this.GetComponent <HoverInteraction>();
     ChildText     = GetComponentInChildren <Text>();
     initTextColor = ChildText.color;
     parent        = GetComponentInParent <ButtonInteractionGroup>();
 }
 private void Awake()
 {
     self = this.GetComponent <HoverInteraction>();
     if (this.GetComponent <Button>() != null)
     {
         setButton(this.GetComponent <Button>());
     }
 }
 public void HighlightButton(HoverInteraction h)
 {
     foreach (HoverInteraction _h in btns)
     {
         // if (h != _h)
         _h.Unhighlight();
     }
     h.Highlight();
 }
Exemplo n.º 4
0
        public DataChartGui(Dictionary <string, List <StockDataInterface> > dataSets, StockSession session) : base(dataSets, session)
        {
            GuiPanel             = new Panel();
            GuiPanel.Size        = new System.Drawing.Size(600, 300);
            GuiPanel.AutoSize    = false;
            GuiPanel.BackColor   = GuiStyle.BACKGROUND_COLOR;
            GuiPanel.BorderStyle = BorderStyle.FixedSingle;
            EventHandler resizeHandler = (sender, e) =>
            {
                GuiPanel.Size = new System.Drawing.Size(GuiPanel.Parent.Width - 50, GuiPanel.Parent.Height - GuiPanel.Top - 50);
            };

            GuiPanel.ParentChanged += (sender, e) =>
            {
                GuiPanel.Parent.Resize += resizeHandler;
                resizeHandler(sender, e);
            };
            GuiPanel.Resize += (sender, e) =>
            {
                SymbolTextbox.Location           = new System.Drawing.Point((GuiPanel.Width / 2) - (SymbolTextbox.Width / 2), 5);
                SymbolNextButton.Location        = new Point(SymbolTextbox.Right + 5, SymbolTextbox.Top);
                SymbolPrevButton.Location        = new Point(SymbolTextbox.Left - 5 - SymbolPrevButton.Width, SymbolTextbox.Top);
                SaveImageButton.Location         = new System.Drawing.Point(GuiPanel.Width - (SaveImageButton.Width) - 5, 5);
                ChartDescriptionTextbox.Location = new Point(SymbolNextButton.Right + 15, SymbolTextbox.Top);
                ChartDescriptionTextbox.Size     = new Size((SaveImageButton.Left - ChartDescriptionTextbox.Left) - 15, ChartDescriptionTextbox.Height);
                XAxisTextbox.Location            = new System.Drawing.Point((GuiPanel.Width / 2) - (SymbolTextbox.Width / 2), GuiPanel.Height - XAxisTextbox.Height - 10);
            };

            // Create the symbol search textbox
            SymbolTextbox           = new TextBox();
            SymbolTextbox.BackColor = GuiStyle.DARK_GREY;
            SymbolTextbox.ForeColor = GuiStyle.TEXT_COLOR;
#if false
            SymbolTextbox.AutoCompleteMode   = AutoCompleteMode.Suggest;
            SymbolTextbox.AutoCompleteSource = AutoCompleteSource.CustomSource;
            SymbolTextbox.TextChanged       += (sender, e) =>
            {
                TextBox t = (TextBox)sender;
                if (t.Text.Length >= 1)
                {
                    // Get the available symbols matching the search string
                    AutoCompleteStringCollection collection = new AutoCompleteStringCollection();
                    collection.AddRange(SuggestSymbols(t.Text));

                    t.AutoCompleteCustomSource = collection;
                }
            };
#endif
            SymbolTextbox.KeyDown += (s, eventArgs) =>
            {
                if (eventArgs.KeyCode == Keys.Enter)
                {
                    SetPlotLineSymbol(SymbolTextbox.Text);
                    this.Refresh();
                }
            };
            GuiPanel.Controls.Add(SymbolTextbox);

            // Create the next and previous arrows for the symbol list
            SymbolNextButton        = new PictureBox();
            SymbolNextButton.Image  = System.Drawing.Bitmap.FromFile("Content/GUI/ArrowRight.png");
            SymbolNextButton.Size   = SymbolNextButton.Image.Size;
            SymbolNextButton.Click += (sender, e) =>
            {
                var allSymbols = DataSets.Keys.ToList();
                if (allSymbols.Count > 0)
                {
                    SetPlotLineSymbol(allSymbols[Math.Min(allSymbols.IndexOf(SymbolTextbox.Text) + 1, allSymbols.Count - 1)]);
                    this.Refresh();
                }
            };
            GuiPanel.Controls.Add(SymbolNextButton);
            SymbolPrevButton       = new PictureBox();
            SymbolPrevButton.Image = System.Drawing.Bitmap.FromFile("Content/GUI/ArrowRight.png");
            SymbolPrevButton.Image.RotateFlip(RotateFlipType.RotateNoneFlipX);
            SymbolPrevButton.Size   = SymbolPrevButton.Image.Size;
            SymbolPrevButton.Click += (sender, e) =>
            {
                var allSymbols = DataSets.Keys.ToList();
                if (allSymbols.Count > 0)
                {
                    SetPlotLineSymbol(allSymbols[Math.Max(allSymbols.IndexOf(SymbolTextbox.Text) - 1, 0)]);
                    this.Refresh();
                }
            };
            GuiPanel.Controls.Add(SymbolPrevButton);

            ChartDescriptionTextbox = SymbolTextbox.Clone();
            GuiPanel.Controls.Add(ChartDescriptionTextbox);

            XAxisTextbox              = SymbolTextbox.Clone();
            XAxisTextbox.Text         = "Time";
            XAxisTextbox.TextChanged += (sender, e) =>
            {
                TextBox t = (TextBox)sender;
                if (t.Text.Length >= 1)
                {
                    // Get the available symbols matching the search string
                    AutoCompleteStringCollection collection = new AutoCompleteStringCollection();
                    collection.AddRange(SuggestExpressions(t.Text));

                    t.AutoCompleteCustomSource = collection;
                }
            };
            XAxisTextbox.KeyDown += (s, eventArgs) =>
            {
                if (eventArgs.KeyCode == Keys.Enter)
                {
                    try
                    {
                        SetXAxis(XAxisTextbox.Text);
                        ErrorMessageLabel.Visible = false;
                    }
                    catch (Exception ex)
                    {
                        ErrorMessageLabel.Text    = ex.ToString();
                        ErrorMessageLabel.Visible = true;
                    }
                }
            };
            GuiPanel.Controls.Add(XAxisTextbox);
            XAxisValue                    = new Label();
            XAxisValue.Font               = GuiStyle.Font;
            XAxisValue.ForeColor          = GuiStyle.TEXT_COLOR;
            XAxisTextbox.LocationChanged += (sender, e) =>
            {
                XAxisValue.Location = new System.Drawing.Point(XAxisTextbox.Right + 5, XAxisTextbox.Top);
            };
            XAxisValue.Size      = new System.Drawing.Size(250, XAxisValue.Height);
            XAxisValue.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
            GuiPanel.Controls.Add(XAxisValue);

            AddPlotButton        = new PictureBox();
            AddPlotButton.Image  = System.Drawing.Bitmap.FromFile("Content/GUI/Button_Add.png");
            AddPlotButton.Click += (sender, e) =>
            {
                AddPlotLine();
            };
            GuiPanel.Controls.Add(AddPlotButton);

            // Add the interactive chart controls
            Plot.AddInteraction(new PlotDrag(true, true));
            Plot.AddInteraction(Hover = new HoverInteraction(this));
            LineDrawer = new LineInteraction(this);
            Plot.AddInteraction(LineDrawer);

            var plotCanvas = base.Canvas;
            GuiPanel.Resize += (sender, e) =>
            {
                if ((GuiPanel.Width > 250) && (GuiPanel.Height > 75))
                {
                    plotCanvas.Size     = new System.Drawing.Size(GuiPanel.Width - 250, GuiPanel.Height - 75);
                    plotCanvas.Location = new System.Drawing.Point(GuiPanel.Width - plotCanvas.Width - 5, (GuiPanel.Height - plotCanvas.Height) / 2);
                }
            };
            GuiPanel.Controls.Add(plotCanvas);

            ErrorMessageLabel           = new Label();
            ErrorMessageLabel.ForeColor = GuiStyle.PRICE_COLOR_NEGATIVE;
            ErrorMessageLabel.BackColor = GuiStyle.DARK_GREY;
            ErrorMessageLabel.AutoSize  = false;
            ErrorMessageLabel.Visible   = false;
            ErrorMessageLabel.Width     = plotCanvas.Width - 10;
            ErrorMessageLabel.Height    = plotCanvas.Height - 10;
            plotCanvas.Resize          += (sender, e) =>
            {
                ErrorMessageLabel.Width  = plotCanvas.Width - 10;
                ErrorMessageLabel.Height = plotCanvas.Height - 10;
            };
            ErrorMessageLabel.Location  = new Point(plotCanvas.Left + 5, plotCanvas.Bottom - ErrorMessageLabel.Height - 5);
            plotCanvas.LocationChanged += (sender, e) =>
            {
                ErrorMessageLabel.Location = new Point(plotCanvas.Left + 5, plotCanvas.Top + 5);
            };
            GuiPanel.Controls.Add(ErrorMessageLabel);
            ErrorMessageLabel.BringToFront();

            // Add the button to reload the session
            SaveImageButton          = new GuiButton("Save Img");
            SaveImageButton.Location = new System.Drawing.Point(GuiPanel.Width - (SaveImageButton.Width / 2) - 5, 5);
            SaveImageButton.Click   += (sender, e) =>
            {
                var saveDiag = new System.Windows.Forms.SaveFileDialog();
                saveDiag.Title    = "Save chart image...";
                saveDiag.FileName = SymbolTextbox.Text + "_" + ChartDescriptionTextbox.Text + ".png";
                if (saveDiag.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    SaveImage(saveDiag.FileName);
                }
            };
            GuiPanel.Controls.Add(SaveImageButton);

            ChartChanged += () =>
            {
                XAxisTextbox.Text = XAxis;
                foreach (var l in Lines)
                {
                    if (!l.Locked)
                    {
                        SymbolTextbox.Text = l.Symbol;
                        break;
                    }
                }
            };

            // Start with one line
            AddPlotLine("Price");

            // Reload the chart when the session is reloaded
            session.OnReload += ReloadData;
        }