Example #1
0
        internal virtual void MouseOver(GH_Canvas sender, GHCustomComponent customComponent, GH_CanvasMouseEvent e, ref GHMouseEventResult result)
        {
            if (this is IGHPanel)
            {
                ((IGHPanel)this).MouseOverChildren(sender, customComponent, e, ref result);
                if (result.HasFlag(GHMouseEventResult.Invalidated | GHMouseEventResult.Handled))
                {
                    return;
                }
            }

            if (ActiveZone.Contains(e.CanvasLocation))
            {
                if (!isMouseIn)
                {
                    isMouseIn = true;
                    result    = result | GHMouseEventResult.Invalidated | GHMouseEventResult.Handled;
                    return;
                }
            }
            else
            {
                if (isMouseIn)
                {
                    isMouseIn = false;
                    result    = result | GHMouseEventResult.Invalidated | GHMouseEventResult.Handled;
                }
            }
        }
Example #2
0
 internal override void MouseLeftClick(GH_Canvas sender, GHCustomComponent customComponent, GH_CanvasMouseEvent e, ref GHMouseEventResult result)
 {
     if (_toggleRec.Contains(e.CanvasLocation))
     {
         // click inside the button
         CurrentValue = !(bool)CurrentValue;
         result       = result | GHMouseEventResult.Handled | GHMouseEventResult.Invalidated | GHMouseEventResult.UpdateSolution;
     }
 }
        public override void SetupTooltip(PointF canvasPoint, GH_TooltipDisplayEventArgs e)
        {
            GHCustomComponent owner = Owner as GHCustomComponent;

            foreach (GHControl item in owner.CustomControls.Values)
            {
                if (item.Bounds.Contains(canvasPoint) && item.Enabled)
                {
                    item.SetupToolTip(canvasPoint, e);
                    return;
                }
            }
            base.SetupTooltip(canvasPoint, e);
        }
        public override GH_ObjectResponse RespondToMouseUp(GH_Canvas sender, GH_CanvasMouseEvent e)
        {
            GHCustomComponent  owner  = Owner as GHCustomComponent;
            GHMouseEventResult result = GHMouseEventResult.None;
            var backup = sender.Cursor;

            if (Bounds.Contains(e.CanvasLocation))
            {
                foreach (GHControl item in owner.CustomControls.Values)
                {
                    if (!item.Enabled)
                    {
                        continue;
                    }
                    if (item.Bounds.Contains(e.CanvasLocation))
                    {
                        item.MouseKeyUp(sender, owner, e, ref result);
                        if (item is GHParameter && !((GHParameter)item).UpdateSolution)
                        {
                            result &= ~GHMouseEventResult.UpdateSolution;
                        }
                        if (result.HasFlag(GHMouseEventResult.Handled))
                        {
                            break;
                        }
                    }
                }

                if (result.HasFlag(GHMouseEventResult.Invalidated))
                {
                    sender.Invalidate();
                }

                if (result.HasFlag(GHMouseEventResult.UpdateSolution))
                {
                    owner.ExpireSolution(true);
                }


                if (result.HasFlag(GHMouseEventResult.Handled))
                {
                    return(GH_ObjectResponse.Handled);
                }
            }
            return(base.RespondToMouseUp(sender, e));
        }
Example #5
0
 internal virtual void MouseLeave(GH_Canvas sender, GHCustomComponent customComponent, GH_CanvasMouseEvent e, ref GHMouseEventResult result)
 {
     if (isMouseIn)
     {
         isMouseIn = false;
         result    = result | GHMouseEventResult.Invalidated | GHMouseEventResult.Handled;
         return;
     }
     if (this is IGHPanel)
     {
         ((IGHPanel)this).MouseOverChildren(sender, customComponent, e, ref result);
         if (result.HasFlag(GHMouseEventResult.Invalidated | GHMouseEventResult.Handled))
         {
             return;
         }
     }
 }
Example #6
0
 internal virtual void MouseKeyUp(GH_Canvas sender, GHCustomComponent customComponent, GH_CanvasMouseEvent e, ref GHMouseEventResult result)
 {
     if (this is IGHPanel)
     {
         IGHPanel panel = (IGHPanel)this;
         foreach (GHControl control in panel.Items)
         {
             if (control.Bounds.Contains(e.CanvasLocation))
             {
                 control.MouseKeyUp(sender, customComponent, e, ref result);
                 if (result.HasFlag(GHMouseEventResult.Handled))
                 {
                     return;
                 }
             }
         }
     }
 }
        public override GH_ObjectResponse RespondToMouseDown(GH_Canvas sender, GH_CanvasMouseEvent e)
        {
            GHCustomComponent owner = Owner as GHCustomComponent;

            if (Bounds.Contains(e.CanvasLocation))
            {
                // click is inside the component
                // check which control is clicked
                GHMouseEventResult result = GHMouseEventResult.None;
                foreach (GHControl control in owner.CustomControls.Values)
                {
                    if (control.Bounds.Contains(e.CanvasLocation))
                    {
                        // click happened in this control
                        if (e.Button == System.Windows.Forms.MouseButtons.Left)
                        {
                            control.MouseLeftClick(sender, owner, e, ref result);
                        }
                        else if (e.Button == System.Windows.Forms.MouseButtons.Right)
                        {
                            control.MouseRightClick(sender, owner, e, ref result);
                        }
                        if (control is GHParameter && !((GHParameter)control).UpdateSolution)
                        {
                            result &= ~GHMouseEventResult.UpdateSolution;
                        }
                    }
                }
                if (result.HasFlag(GHMouseEventResult.Invalidated))
                {
                    sender.Invalidate();
                }
                if (result.HasFlag(GHMouseEventResult.UpdateSolution))
                {
                    owner.ExpireSolution(true);
                }
                if (result.HasFlag(GHMouseEventResult.Handled))
                {
                    return(GH_ObjectResponse.Handled);
                }
            }

            return(base.RespondToMouseDown(sender, e));
        }
        //internal override void MouseOver(GH_Canvas sender, GHCustomComponent customComponent, GH_CanvasMouseEvent e, ref GHMouseEventResult result)
        //{

        //    //if (Highlighted==0)
        //    //    return;
        //    //result = result | GHMouseEventResult.Invalidated ;
        //    //Highlighted = 0;



        //}

        //internal override void MouseLeave(GH_Canvas sender, GHCustomComponent customComponent, GH_CanvasMouseEvent e, ref GHMouseEventResult result)
        //{

        //    //if (Highlighted!=0)
        //    //    return;
        //    //Highlighted = -1;
        //    result = result | GHMouseEventResult.Invalidated;


        //}

        internal override void MouseLeftClick(GH_Canvas sender, GHCustomComponent customComponent, GH_CanvasMouseEvent e, ref GHMouseEventResult result)
        {
            //if (Bounds.Contains(e.CanvasLocation))
            //{
            //    // clicked on this toggle
            //    if (IsSelected)
            //        return; // already selected nothing happens
            //    IsSelected = true;
            //    result = result | GHMouseEventResult.Handled | GHMouseEventResult.UpdateSolution;
            //}
            //else {
            //    // outside of this toggle
            //    if (!IsSelected)
            //        return; // nothing happens
            //    IsSelected = false;
            //    result = result | GHMouseEventResult.Invalidated;

            //}
        }
        internal override void MouseRightClick(GH_Canvas sender, GHCustomComponent customComponent, GH_CanvasMouseEvent e, ref GHMouseEventResult result)
        {
            base.MouseRightClick(sender, customComponent, e, ref result);
            if (result.HasFlag(GHMouseEventResult.Handled))
            {
                return;
            }
            decimal d = Convert.ToDecimal(CurrentValue);
            NumericUpDownData <decimal> numeric = new NumericUpDownData <decimal>(d, Convert.ToDecimal(_min), Convert.ToDecimal(_max), FormatString);

            if (numeric.GetInput(PointToScreen(sender, Pos), out decimal val))
            {
                CurrentValue = (float)val;
                result       = result | GHMouseEventResult.UpdateSolution | GHMouseEventResult.Handled;
            }
            else
            {
                result = result | GHMouseEventResult.Handled;
            }
            showLabel = true;
        }
        internal override void MouseRightClick(GH_Canvas sender, GHCustomComponent customComponent, GH_CanvasMouseEvent e, ref GHMouseEventResult result)
        {
            base.MouseRightClick(sender, customComponent, e, ref result);
            if (result.HasFlag(GHMouseEventResult.Handled))
            {
                return;
            }
            int d = (int)CurrentValue;
            NumericUpDownData <int> numeric = new NumericUpDownData <int>(d, (int)_min, (int)_max, FormatString);

            if (numeric.GetInput(PointToScreen(sender, Pos), out int val))
            {
                CurrentValue = val;
                result       = result | GHMouseEventResult.UpdateSolution | GHMouseEventResult.Handled;
            }
            else
            {
                result = result | GHMouseEventResult.Handled;
            }
            showLabel = true;
        }
        internal override void MouseRightClick(GH_Canvas sender, GHCustomComponent customComponent, GH_CanvasMouseEvent e, ref GHMouseEventResult result)
        {
            base.MouseRightClick(sender, customComponent, e, ref result);
            if (result.HasFlag(GHMouseEventResult.Handled))
            {
                return;
            }
            double d = (double)CurrentValue;
            NumericUpDownData <double> numeric = new NumericUpDownData <double>(d, _min, _max, FormatString);

            //float s = GH_FontServer.MeasureString("A", SmallFont).Height * sender.Viewport.Zoom / 20;
            if (numeric.GetInput(PointToScreen(sender, Pos), out double val))
            {
                CurrentValue = val;
                result       = result | GHMouseEventResult.UpdateSolution | GHMouseEventResult.Handled;
            }
            else
            {
                result = result | GHMouseEventResult.Handled;
            }
            showLabel = true;
        }
        protected override void Render(GH_Canvas canvas, System.Drawing.Graphics graphics, GH_CanvasChannel channel)
        {
            switch (channel)
            {
            case GH_CanvasChannel.Objects:
                //We need to draw everything ourselves.
                base.RenderComponentCapsule(canvas, graphics, true, true, false, true, true, true);
                //if (Owner.IconDisplayMode == GH_IconDisplayMode.icon)
                //{
                //    PointF iconPos = new PointF((Bounds.Left + Bounds.Right) / 2 - 12, Pivot.Y);
                //    graphics.DrawImage(Owner.Icon_24x24, new RectangleF(iconPos, new Size(24,24)));
                //}
                if (canvas.Viewport.Zoom < 0.5)
                {
                    return;
                }
                GHCustomComponent owner = Owner as GHCustomComponent;

                foreach (GHControl item in owner.CustomControls.Values)
                {
                    //if (!item.Bounds.Contains(canvas.CursorCanvasPosition))
                    //    item.MouseLeave(owner,new GH_CanvasMouseEvent(),ref invalidate);

                    if (item.IsVisible)
                    {
                        item.Render(graphics, canvas.CursorCanvasPosition, this.Selected, Owner.Locked || !item.Enabled, Owner.Hidden);
                    }
                }


                break;

            default:
                base.Render(canvas, graphics, channel);
                break;
            }
        }
Example #13
0
 internal abstract void MouseRightClick(GH_Canvas sender, GHCustomComponent customComponent, GH_CanvasMouseEvent e, ref GHMouseEventResult result);
 public GHCustomAttributes(GHCustomComponent owner) : base(owner)
 {
 }
 /// <summary>
 /// finds the children in which the cursor is inside and then call the MouseOver method for that child
 /// </summary>
 /// <param name="gHContainer"></param>
 /// <param name="customComponent"></param>
 /// <param name="e"></param>
 /// <param name="result"></param>
 public static void MouseOverChildren(this IGHPanel gHContainer, GH_Canvas sender, GHCustomComponent customComponent, GH_CanvasMouseEvent e, ref GHMouseEventResult result)
 {
     foreach (GHControl control in gHContainer.Items)
     {
         if (control.Bounds.Contains(e.CanvasLocation) && control.Enabled)
         {
             control.MouseOver(sender, customComponent, e, ref result);
             if (result.HasFlag(GHMouseEventResult.Invalidated)) // no need to continue as this child already set the flag
             {
                 return;
             }
         }
         else
         {
             control.MouseLeave(sender, customComponent, e, ref result);
             //if (result.HasFlag(GHMouseEventResult.Invalidated)) // no need to continue as this child already set the flag
             //    return;
         }
     }
 }
 /// <summary>
 /// finds the children in which the cursor is inside and then call the MouseClick method for that child
 /// </summary>
 /// <param name="gHContainer"></param>
 /// <param name="customComponent"></param>
 /// <param name="e"></param>
 /// <param name="result"></param>
 public static void MouseClickChildren(this IGHPanel gHContainer, GH_Canvas sender, GHCustomComponent customComponent, GH_CanvasMouseEvent e, ref GHMouseEventResult result)
 {
     foreach (GHControl control in gHContainer.Items)
     {
         if (control.Enabled && control.Bounds.Contains(e.CanvasLocation))
         {
             if (e.Button == System.Windows.Forms.MouseButtons.Left)
             {
                 control.MouseLeftClick(sender, customComponent, e, ref result);
             }
             else
             {
                 control.MouseRightClick(sender, customComponent, e, ref result);
             }
             if (control is GHParameter && !((GHParameter)control).UpdateSolution)
             {
                 result &= ~GHMouseEventResult.UpdateSolution;
             }
             if (result.HasFlag(GHMouseEventResult.Handled))
             {
                 return;
             }
         }
     }
 }
Example #17
0
        //internal override void SetupToolTip(PointF canvasPoint, GH_TooltipDisplayEventArgs e)
        //{
        //    e.Title = Name;
        //    //e.Description = Description;
        //    e.Text = Description;
        //}

        public abstract void OnMouseClick(GH_Canvas sender, GHCustomComponent customComponent, GH_CanvasMouseEvent e, ref GHMouseEventResult result);
        protected override void Layout()
        {
            _layout = true;
            // draw basic layout
            base.Layout();
            PointF            p     = Pivot;
            RectangleF        b     = Bounds;
            GHCustomComponent owner = Owner as GHCustomComponent;

            if (owner.CustomControls.Values.Count == 0)
            {
                return;
            }
            // we add the custom constrols to the buttom of each other in the same order they have been added to the dictionary
            // the value buttom records the buttom postion of the controls as they are being added
            float buttom = Bounds.Bottom;

            // to find the overal widht of the component we find the maximum width of the customcontrols
            float maxWidth = Bounds.Width;

            foreach (GHControl item in owner.CustomControls.Values)
            {
                float w = (item.IsVisible)? item.GetWidth():0;
                if (maxWidth < w)
                {
                    maxWidth = w;
                }
            }

            foreach (GHControl item in owner.CustomControls.Values)
            {
                float h = (item.IsVisible)? item.GetHeight():0;
                // set the item bounds , we expand the bounds by 2 units from each side
                item.Bounds = new RectangleF(Bounds.X, buttom, maxWidth, h);
                buttom     += h + _offset; // update the buttom value
            }
            float currentWidth = Bounds.Width;
            var   corner       = new PointF(Bounds.X - _offset, Bounds.Y - _offset);

            Bounds = new RectangleF(corner, new SizeF(maxWidth + 2 * _offset, Bounds.Height + buttom - Bounds.Bottom + 2 * _offset));

            if (maxWidth > currentWidth)
            {
                //    // update the output parameter layout
                //    int paramWidth = Owner.Params.Output.Max(
                //        p => GH_FontServer.StringWidth(
                //            (CentralSettings.CanvasFullNames) ? p.Name : p.NickName
                //            , SmallFont
                //            )
                //        );

                //LayoutOutputParams(Owner, new RectangleF(Bounds.X , Bounds.Y, maxWidth, Bounds.Height));

                foreach (var param in Owner.Params.Output)
                {
                    RectangleF rec = param.Attributes.Bounds;
                    rec.Offset(Bounds.Right - param.Attributes.Bounds.Right, 0);
                    param.Attributes.Bounds = rec;
                }
            }



            //Pivot = new PointF((Bounds.X + Bounds.Width) / 2 -12, Pivot.Y);
        }
Example #19
0
 internal override void MouseRightClick(GH_Canvas sender, GHCustomComponent customComponent, GH_CanvasMouseEvent e, ref GHMouseEventResult result)
 {
 }
Example #20
0
 internal override void MouseLeftClick(GH_Canvas sender, GHCustomComponent customComponent, GH_CanvasMouseEvent e, ref GHMouseEventResult result)
 {
     OnMouseClick(sender, customComponent, e, ref result);
 }