Example #1
0
        //
        // Horizontal Scrollbar scroll event
        //
        private void hScrollBar_Scroll(object sender, ScrollEventArgs e)
        {
            offsetPoint.X = e.NewValue;
            Invalidate();

            HorizontalScroll?.Invoke(this, e);
        }
Example #2
0
        //
        // Mouse Move event handler. Used to drag the viewport
        //
        protected override void OnMouseMove(MouseEventArgs e)
        {
            base.OnMouseMove(e);

            if (draggingViewport)
            {
                offsetPoint = new Point(-MousePosition.X + mouseOffset.X, -MousePosition.Y + mouseOffset.Y);

                // Fire scroll events
                HorizontalScroll?.Invoke(this, new ScrollEventArgs(ScrollEventType.ThumbPosition, offsetPoint.X));
                VerticalScroll?.Invoke(this, new ScrollEventArgs(ScrollEventType.ThumbPosition, offsetPoint.Y));

                ClipTransform();
                Invalidate();
            }
        }
Example #3
0
        private void ApplyPreferedSize(Size preferedSize, Size panelSize)
        {
            _needBothScroll = false;
            var needHorizontalScroll = HorizontalScroll.HasScroll;
            var needVerticalScroll   = VerticalScroll.UpdateLength(preferedSize.Height, null, panelSize.Height - (needHorizontalScroll ? HorizontalScroll.BarThickness : 0), panelSize.Width);

            HorizontalScroll.UpdateLength(preferedSize.Width, null, panelSize.Width - (needVerticalScroll ? VerticalScroll.BarThickness : 0), panelSize.Height);

            if (needHorizontalScroll != HorizontalScroll.HasScroll)
            {
                needHorizontalScroll = HorizontalScroll.HasScroll;
                needVerticalScroll   = VerticalScroll.UpdateLength(preferedSize.Height, null, panelSize.Height - (needHorizontalScroll ? HorizontalScroll.BarThickness : 0), panelSize.Width);
            }

            _needBothScroll = needVerticalScroll && needHorizontalScroll;
            if (_needBothScroll)
            {
                _leftoverBar = new Rectangle(panelSize.Width - VerticalScroll.BarThickness, panelSize.Height - HorizontalScroll.BarThickness, VerticalScroll.BarThickness, HorizontalScroll.BarThickness);
            }
        }
        protected void ComputeScrollbars(Size naturalSize, Size availableSize)
        {
            _needBothScroll = false;
            var needHorizontalScroll = HorizontalScroll.HasScroll;
            var needVerticalScroll   = VerticalScroll.UpdateLength(naturalSize.Height, null, availableSize.Height - (needHorizontalScroll ? HorizontalScroll.BarThickness : 0), availableSize.Width);

            HorizontalScroll.UpdateLength(naturalSize.Width, null, availableSize.Width - (needVerticalScroll ? VerticalScroll.BarThickness : 0), availableSize.Height);

            if (needHorizontalScroll != HorizontalScroll.HasScroll)
            {
                needHorizontalScroll = HorizontalScroll.HasScroll;
                needVerticalScroll   = VerticalScroll.UpdateLength(naturalSize.Height, null, availableSize.Height - (needHorizontalScroll ? HorizontalScroll.BarThickness : 0), availableSize.Width);
            }

            // compute the "left over" rectangle on the bottom right between the 2 scrolls
            _needBothScroll = needVerticalScroll && needHorizontalScroll;
            if (_needBothScroll)
            {
                _leftoverBar = new Rectangle(ContentSurfaceWithScrolls.X + ContentSurfaceWithScrolls.Width - VerticalScroll.BarThickness, ContentSurfaceWithScrolls.Y + ContentSurfaceWithScrolls.Height - HorizontalScroll.BarThickness, VerticalScroll.BarThickness, HorizontalScroll.BarThickness);
            }

            ContentSurface = new Rectangle(ContentSurfaceWithScrolls.X, ContentSurfaceWithScrolls.Y, ContentSurfaceWithScrolls.Width - (needVerticalScroll ? VerticalScroll.BarThickness : 0), ContentSurfaceWithScrolls.Height - (needHorizontalScroll ? HorizontalScroll.BarThickness : 0));
        }
        protected virtual void PaintScrollBars(PaintEventArgs e, Region originalRegion)
        {
            if (VerticalScroll.HasScroll && VerticalScroll.BarRect.IntersectsWith(e.ClipRectangle))
            {
                e.Graphics.SetClip(VerticalScroll.BarRect, CombineMode.Intersect);
                VerticalScroll.Paint(e.Graphics);
                e.Graphics.Clip = originalRegion;
            }

            if (_needBothScroll && _leftoverBar.IntersectsWith(e.ClipRectangle))
            {
                e.Graphics.SetClip(_leftoverBar, CombineMode.Intersect);
                e.Graphics.PaintClipRegion(YamuiThemeManager.Current.ScrollNormalBack);
                e.Graphics.Clip = originalRegion;
            }

            if (HorizontalScroll.HasScroll && HorizontalScroll.BarRect.IntersectsWith(e.ClipRectangle))
            {
                e.Graphics.SetClip(HorizontalScroll.BarRect, CombineMode.Intersect);
                HorizontalScroll.Paint(e.Graphics);
                e.Graphics.Clip = originalRegion;
            }
        }
Example #6
0
        protected override void WndProc(ref Message m)
        {
            if (DesignMode)
            {
                base.WndProc(ref m);
                return;
            }

            switch ((Window.Msg)m.Msg)
            {
            case Window.Msg.WM_NCCALCSIZE:

                // Check WPARAM
                if (m.WParam != IntPtr.Zero)
                {
                    // When TRUE, LPARAM Points to a NCCALCSIZE_PARAMS structure
                    var nccsp = (WinApi.NCCALCSIZE_PARAMS)Marshal.PtrToStructure(m.LParam, typeof(WinApi.NCCALCSIZE_PARAMS));
                    ApplyPreferedSize(_preferedSize, nccsp.rectProposed.Size);
                    AdjustClientArea(ref nccsp.rectProposed);
                    Marshal.StructureToPtr(nccsp, m.LParam, true);
                }
                else
                {
                    // When FALSE, LPARAM Points to a RECT structure
                    var clnRect = (WinApi.RECT)Marshal.PtrToStructure(m.LParam, typeof(WinApi.RECT));
                    ApplyPreferedSize(_preferedSize, clnRect.Size);
                    AdjustClientArea(ref clnRect);
                    Marshal.StructureToPtr(clnRect, m.LParam, true);
                }

                //Return Zero
                m.Result = IntPtr.Zero;
                break;

            case Window.Msg.WM_NCPAINT:
                PaintScrollBars(null);
                // we handled everything
                m.Result = IntPtr.Zero;
                break;

            case Window.Msg.WM_NCHITTEST:
                // we need to correctly handle this if we want the non client area events (WM_NC*) to fire properly!
                var point = PointToClient(new Point(m.LParam.ToInt32()));
                if (!ClientRectangle.Contains(point))
                {
                    m.Result = (IntPtr)WinApi.HitTest.HTBORDER;
                }
                else
                {
                    base.WndProc(ref m);
                }

                break;

            case Window.Msg.WM_MOUSEWHEEL:
                if (HasScroll)
                {
                    // delta negative when scrolling up
                    var delta       = (short)(m.WParam.ToInt64() >> 16);
                    var mouseEvent1 = new MouseEventArgs(MouseButtons.None, 0, 0, 0, delta);
                    if (HorizontalScroll.IsHovered)
                    {
                        HorizontalScroll.HandleScroll(null, mouseEvent1);
                    }
                    else
                    {
                        VerticalScroll.HandleScroll(null, mouseEvent1);
                    }
                }
                else
                {
                    // propagate the event
                    base.WndProc(ref m);
                }

                break;

            case Window.Msg.WM_MOUSEMOVE:
                if (VerticalScroll.IsThumbPressed)
                {
                    VerticalScroll.HandleMouseMove(null, null);
                }
                if (HorizontalScroll.IsThumbPressed)
                {
                    HorizontalScroll.HandleMouseMove(null, null);
                }
                base.WndProc(ref m);
                break;

            case Window.Msg.WM_NCMOUSEMOVE:
                // track mouse leaving (otherwise the WM_NCMOUSELEAVE message would not fire)
                WinApi.TRACKMOUSEEVENT tme = new WinApi.TRACKMOUSEEVENT();
                tme.cbSize    = (uint)Marshal.SizeOf(tme);
                tme.dwFlags   = (uint)(WinApi.TMEFlags.TME_LEAVE | WinApi.TMEFlags.TME_NONCLIENT);
                tme.hwndTrack = Handle;
                WinApi.TrackMouseEvent(tme);

                // PointToClient(new Point(m.LParam.ToInt32()));
                VerticalScroll.HandleMouseMove(null, null);
                HorizontalScroll.HandleMouseMove(null, null);
                base.WndProc(ref m);
                break;

            case Window.Msg.WM_NCLBUTTONDOWN:
                VerticalScroll.HandleMouseDown(null, null);
                HorizontalScroll.HandleMouseDown(null, null);
                Focus();
                // here we forward to base button down because it has a internal focus mecanism that we want to exploit
                // if we don't do that, the mouse MOVE events are not fired outside the bounds of this control!
                m.Msg = (int)Window.Msg.WM_LBUTTONDOWN;
                base.WndProc(ref m);
                break;

            case Window.Msg.WM_NCLBUTTONUP:
            case Window.Msg.WM_LBUTTONUP:
                VerticalScroll.HandleMouseUp(null, null);
                HorizontalScroll.HandleMouseUp(null, null);
                // here we forward this message to base WM_LBUTTONUP to release the internal focus on this control
                m.Msg = (int)Window.Msg.WM_LBUTTONUP;
                base.WndProc(ref m);
                break;

            case Window.Msg.WM_NCMOUSELEAVE:
                VerticalScroll.HandleMouseLeave(null, null);
                HorizontalScroll.HandleMouseLeave(null, null);
                base.WndProc(ref m);
                break;

            default:
                base.WndProc(ref m);
                break;
            }
        }
Example #7
0
 /// <summary>
 /// Programatically triggers the OnKeyDown event
 /// </summary>
 public bool PerformKeyDown(KeyEventArgs e)
 {
     e.Handled = HorizontalScroll.HandleKeyDown(null, e) || VerticalScroll.HandleKeyDown(null, e);
     return(e.Handled);
 }
Example #8
0
 private void PaintHorizontalScroll(PaintEventArgs e)
 {
     HorizontalScroll.Paint(e.Graphics);
 }
 protected virtual void MouseLeaveClientArea(EventArgs eventArgs)
 {
     VerticalScroll.HandleMouseLeave(null, null);
     HorizontalScroll.HandleMouseLeave(null, null);
 }
 protected virtual void MouseLUpClientArea(MouseEventArgs mouseEventArgs)
 {
     VerticalScroll.HandleMouseUp(null, null);
     HorizontalScroll.HandleMouseUp(null, null);
 }
 protected virtual void MouseLDownClientArea(MouseEventArgs mouseEventArgs)
 {
     Focus();
     VerticalScroll.HandleMouseDown(null, null);
     HorizontalScroll.HandleMouseDown(null, null);
 }
        protected override void WndProc(ref Message m)
        {
            if (DesignMode)
            {
                base.WndProc(ref m);
                return;
            }

            switch ((Window.Msg)m.Msg)
            {
            case Window.Msg.WM_NCCALCSIZE:

                // Check WPARAM
                if (m.WParam != IntPtr.Zero)
                {
                    // When TRUE, LPARAM Points to a NCCALCSIZE_PARAMS structure
                    var nccsp = (WinApi.NCCALCSIZE_PARAMS)Marshal.PtrToStructure(m.LParam, typeof(WinApi.NCCALCSIZE_PARAMS));
                    if (!nccsp.rectProposed.Size.IsEmpty)
                    {
                        // we are not in this case when the form is minimized
                        //OnSizeChanged(nccsp.rectProposed.Size);
                    }

                    AdjustClientArea(ref nccsp.rectProposed);
                    Marshal.StructureToPtr(nccsp, m.LParam, true);
                }
                else
                {
                    // When FALSE, LPARAM Points to a RECT structure
                    var clnRect = (WinApi.RECT)Marshal.PtrToStructure(m.LParam, typeof(WinApi.RECT));
                    if (!clnRect.Size.IsEmpty)
                    {
                        // we are not in this case when the form is minimized
                        //OnSizeChanged(clnRect.Size);
                    }

                    AdjustClientArea(ref clnRect);
                    Marshal.StructureToPtr(clnRect, m.LParam, true);
                }

                //Return Zero
                m.Result = IntPtr.Zero;
                break;

            case Window.Msg.WM_MOUSEWHEEL:
                if (HasScroll)
                {
                    // delta negative when scrolling up
                    var delta       = (short)(m.WParam.ToInt64() >> 16);
                    var mouseEvent1 = new MouseEventArgs(MouseButtons.None, 0, 0, 0, delta);
                    if (HorizontalScroll.IsHovered)
                    {
                        HorizontalScroll.HandleScroll(null, mouseEvent1);
                    }
                    else
                    {
                        VerticalScroll.HandleScroll(null, mouseEvent1);
                    }
                }
                else
                {
                    // propagate the event
                    base.WndProc(ref m);
                }

                break;

            /*
             * case Window.Msg.WM_KEYDOWN:
             *  // needto override OnPreviewKeyDown or IsInputKey to receive this
             *  var key = (Keys) (m.WParam.ToInt64());
             *  long context = m.LParam.ToInt64();
             *
             *  // on key down
             *  if (!context.IsBitSet(31)) {
             *      var e = new KeyEventArgs(key);
             *      e.Handled = PerformKeyDown(e);
             *      if (!e.Handled)
             *          base.WndProc(ref m);
             *  }
             *
             *  break;
             */
            case Window.Msg.WM_NCPAINT:
                m.Result = IntPtr.Zero;
                break;

            case Window.Msg.WM_ERASEBKGND:
                m.Result = IntPtr.Zero;
                return;

            default:
                base.WndProc(ref m);
                break;
            }
        }
Example #13
0
 private void Start()
 {
     _movingWall = GetComponentInParent <HorizontalScroll>();
 }
Example #14
0
        public void OnInspectorGUI(BaseDestructable[] targets)
        {
            if (targets == null || targets.Length == 0 || targets[0] == null) return;
            if (targets.Length > 1)
            {
                using (new GUIColor(new Color(1.0f, 0.3f, 0.3f)))
                {
                    GUILayout.Label("Cannot use this tool with more than one destructable object selected.", EditorStyles.miniBoldLabel);
                }
                return;
            }

            if (targets[0].stickyZones != null && targets[0].stickyZones.Length != 0)
            {
                using (HorizontalScroll scrollbar = new HorizontalScroll(scrollPosition, Mathf.Min(100, targets[0].stickyZones.Length * 20 + 10)))
                {
                    scrollPosition = scrollbar.Position;
                    using (new Vertical("box"))
                    {
                        foreach (StickyZone zone in targets[0].stickyZones)
                        {
                            using (new Horizontal("toolbarbutton"))
                            {
                                if (zone == null)
                                {
                                    ArrayUtility.Remove(ref targets[0].stickyZones, null);
                                    break;
                                }

                                EditorGUILayout.ObjectField(zone, typeof(StickyZone), false);

                                using (new GUIBackgroundColor(new Color(0.8f, 0.8f, 1.0f)))
                                {
                                    if (GUILayout.Button("Select", "toolbarbutton"))
                                    {
                                        activeObject = zone.gameObject;
                                    }
                                }

                                if (GUILayout.Button("Zero", "toolbarbutton"))
                                {
                                    zone.transform.position = targets[0].transform.position + Vector3.one;
                                    zone.transform.rotation = targets[0].transform.rotation;
                                    zone.transform.localScale = Vector3.one;
                                }

                                using (new GUIBackgroundColor(Color.red))
                                {
                                    if (GUILayout.Button("X", "toolbarbutton", GUILayout.Width(30)))
                                    {
                                        Object.DestroyImmediate(zone.gameObject);
                                        ArrayUtility.Remove(ref targets[0].stickyZones, zone);
                                        break;
                                    }
                                }
                            }
                        }

                        GUILayout.FlexibleSpace();
                    }
                }
            }

            using (new Horizontal("toolbarbutton"))
            {
                GUILayout.FlexibleSpace();

                if (GUILayout.Button("Add New", "toolbarbutton"))
                {
                    var newZone = CreateStickyZone();
                    activeObject = newZone.gameObject;
                    ArrayUtility.Add(ref targets[0].stickyZones, newZone);
                }
            }
        }