Beispiel #1
0
        private void timerSync_Tick(object sender, EventArgs e)
        {
            if (NativeMethods.GetWindowRect(ownerHandle, out NativeMethods.RECT rect))
            {
                IWMPMedia    media    = Player.currentMedia;
                IWMPControls controls = Player.controls;

                int ownerLeft   = rect.Left;
                int ownerTop    = rect.Top;
                int ownerWidth  = rect.Right - rect.Left + 1;
                int ownerHeight = rect.Bottom - rect.Top + 1;

                // roughly matches MinimumSize for client bounds, adjusted a bit for weirdness with higher DPI
                int minWidth  = DpiScaled(356);
                int minHeight = DpiScaled(386);

                if (NativeMethods.GetClientRect(ownerHandle, out NativeMethods.RECT clientSize))
                {
                    minWidth  = Math.Min(minWidth, clientSize.Right);
                    minHeight = Math.Min(minHeight, clientSize.Bottom);
                }

                int maxWidth  = Math.Min(DpiScaled(media.imageSourceWidth), ownerWidth * 3 / 4);
                int maxHeight = Math.Min(DpiScaled(media.imageSourceHeight), ownerHeight * 3 / 4);

                bool isCursorInside = ClientRectangle.Contains(PointToClient(Cursor.Position));

                Size  newSize     = new Size(Math.Max(minWidth + 2, maxWidth), Math.Max(minHeight + 2, maxHeight));
                Point newLocation = new Point(ownerLeft + (ownerWidth - newSize.Width) / 2, ownerTop + (ownerHeight - newSize.Height + SystemInformation.CaptionHeight) / 2);

                if (ClientSize != newSize || Location != newLocation)
                {
                    ClientSize = newSize;
                    Location   = newLocation;
                    RefreshControlPanel();
                }

                if (isCursorInside || isDragging)
                {
                    labelTime.Text = $"{controls.currentPositionString} / {media.durationString}";

                    int value = (int)Math.Round(progressSeek.Maximum * controls.currentPosition / media.duration);

                    if (value >= progressSeek.Maximum)
                    {
                        progressSeek.Value = progressSeek.Maximum;
                        progressSeek.Value = progressSeek.Maximum - 1;
                        progressSeek.Value = progressSeek.Maximum;
                    }
                    else
                    {
                        progressSeek.Value = value + 1;
                        progressSeek.Value = value;
                    }

                    if (tablePanelFull.Enabled)
                    {
                        tablePanelFull.Visible = true;
                    }
                    else
                    {
                        tablePanelCompactBottom.Visible = true;
                        tablePanelCompactTop.Visible    = true;
                    }
                }
                else
                {
                    tablePanelFull.Visible          = false;
                    tablePanelCompactBottom.Visible = false;
                    tablePanelCompactTop.Visible    = false;
                }

                if (controls.currentPosition > media.duration)  // pausing near the end of the video causes WMP to play beyond the end of the video wtf
                {
                    try{
                        controls.stop();
                        controls.currentPosition = 0;
                        controls.play();
                    }catch (AccessViolationException) {
                        // something is super retarded here because shit gets disposed between the start of this method and
                        // the controls.play() call even though it runs on the UI thread
                    }
                }

                if (isCursorInside && !wasCursorInside)
                {
                    wasCursorInside = true;

                    if (IsCursorOverVideo)
                    {
                        Cursor.Current = Cursors.Default;
                    }
                }
                else if (!isCursorInside && wasCursorInside)
                {
                    wasCursorInside = false;

                    if (!Player.fullScreen && Handle == NativeMethods.GetForegroundWindow())
                    {
                        NativeMethods.SetForegroundWindow(ownerHandle);
                    }
                }

                Marshal.ReleaseComObject(media);
                Marshal.ReleaseComObject(controls);
            }
            else
            {
                Environment.Exit(Program.CODE_OWNER_GONE);
            }
        }
Beispiel #2
0
        private Point OffsetForChildRect(Rectangle rect)
        {
            // Begin by using the current offset
            Point offset = _offset;

            // Find how far to over position the viewport
            int overs = 0;

            // We might not be provided with metrics, so only use if reference provided
            if (_paletteMetrics != null)
            {
                overs = _paletteMetrics.GetMetricInt(State, _metricOvers) + _scrollOvers;
            }

            // Move the required rectangle more than exactly into view in order to make it
            // easier for users to see extra pages before and after it for easy selection
            if ((Orientation == VisualOrientation.Top) ||
                (Orientation == VisualOrientation.Bottom))
            {
                rect.X     -= overs;
                rect.Width += overs * 2;
            }
            else
            {
                rect.Y      -= overs;
                rect.Height += overs * 2;
            }

            //If all the children are completely visible then nothing to do
            if ((_limit.X != 0) || (_limit.Y != 0))
            {
                // Is part of the required rectangle not currently visible
                if (!ClientRectangle.Contains(rect))
                {
                    // Correct the alignmnet to take right to left into account
                    RelativePositionAlign alignment = AlignmentRTL;

                    // Center alignment needs changing to near or far for scrolling
                    if (alignment == RelativePositionAlign.Center)
                    {
                        alignment = RelativePositionAlign.Near;
                    }

                    // How to scroll into view depends on the alignmnent of items
                    switch (alignment)
                    {
                    case RelativePositionAlign.Near:
                        if (rect.Right > ClientRectangle.Right)
                        {
                            offset.X += (ClientRectangle.Right - rect.Right);
                        }

                        if (rect.Left < ClientRectangle.Left)
                        {
                            offset.X += (ClientRectangle.Left - rect.Left);
                        }

                        if (rect.Bottom > ClientRectangle.Bottom)
                        {
                            offset.Y += (ClientRectangle.Bottom - rect.Bottom);
                        }

                        if (rect.Top < ClientRectangle.Top)
                        {
                            offset.Y += (ClientRectangle.Top - rect.Top);
                        }

                        break;

                    case RelativePositionAlign.Far:
                        if (rect.Right > ClientRectangle.Right)
                        {
                            offset.X -= (ClientRectangle.Right - rect.Right);
                        }

                        if (rect.Left < ClientRectangle.Left)
                        {
                            offset.X -= (ClientRectangle.Left - rect.Left);
                        }

                        if (rect.Bottom > ClientRectangle.Bottom)
                        {
                            offset.Y -= (ClientRectangle.Bottom - rect.Bottom);
                        }

                        if (rect.Top < ClientRectangle.Top)
                        {
                            offset.Y -= (ClientRectangle.Top - rect.Top);
                        }

                        break;
                    }
                }
            }

            // Enforce the offset back to the limits
            offset.X = Math.Min(Math.Max(offset.X, _limit.X), 0);
            offset.Y = Math.Min(Math.Max(offset.Y, _limit.Y), 0);

            return(offset);
        }
Beispiel #3
0
 /// <summary>
 /// Should a mouse down at the provided point cause it to become the current tracking popup.
 /// </summary>
 /// <param name="m">Original message.</param>
 /// <param name="pt">Client coordinates point.</param>
 /// <returns>True to become current; otherwise false.</returns>
 public virtual bool DoesStackedClientMouseDownBecomeCurrent(Message m, Point pt)
 {
     return(ClientRectangle.Contains(pt));
 }
Beispiel #4
0
        /// <summary>
        /// Performs the default handling for mouse movememnt, and decides
        /// whether or not to fire an ItemMouseMove event.
        /// </summary>
        /// <param name="e">A MouseEventArgs</param>
        protected override void OnMouseMove(MouseEventArgs e)
        {
            if (_legendBoxes == null)
            {
                return;
            }
            bool      cursorHandled = false;
            LegendBox currentBox    = null;
            Point     loc           = new Point(e.X + ControlRectangle.X, e.Location.Y + ControlRectangle.Top);

            foreach (LegendBox box in _legendBoxes)
            {
                if (box.Bounds.Contains(loc))
                {
                    currentBox = box;
                    ItemMouseEventArgs args = new ItemMouseEventArgs(e, box);
                    DoItemMouseMove(args);
                }
            }
            if (_isDragging)
            {
                _dragTarget = null;
                if (currentBox != null)
                {
                    _dragTarget = currentBox;
                }
                if (ClientRectangle.Contains(e.Location))
                {
                    if (currentBox == null)
                    {
                        _dragTarget = BottomBox;
                    }
                }
                if (_previousLine.IsEmpty == false)
                {
                    Invalidate(_previousLine);
                }
                _previousLine = Rectangle.Empty;

                if (_dragTarget != null && _dragItem != null && _dragTarget != _dragItem)
                {
                    LegendBox boxOverLine;
                    int       left      = 0;
                    LegendBox container = BoxFromItem(_dragTarget.Item.GetValidContainerFor(_dragItem.Item));
                    if (container != null)
                    {
                        left = (container.Indent + 1) * _indentation;
                    }
                    if (_dragTarget.Item.CanReceiveItem(_dragItem.Item))
                    {
                        boxOverLine = _dragTarget;
                    }
                    else
                    {
                        boxOverLine = BoxFromItem(_dragTarget.Item.BottomMember());
                    }
                    if (boxOverLine == null)
                    {
                        _previousLine = Rectangle.Empty;
                        Cursor        = Cursors.No;
                        cursorHandled = true;
                    }
                    else
                    {
                        _previousLine = new Rectangle(left, boxOverLine.Bounds.Bottom, Width - left, 4);
                        Cursor        = Cursors.Hand;
                        cursorHandled = true;
                        Invalidate(_previousLine);
                    }
                }
                if (cursorHandled == false)
                {
                    Cursor        = Cursors.No;
                    cursorHandled = true;
                }
            }
            if (cursorHandled == false)
            {
                Cursor = Cursors.Arrow;
            }
            base.OnMouseMove(e);
        }
Beispiel #5
0
        private void AppMenuItem_Click(object sender, EventArgs e)
        {
            if (appsListView.SelectedItems.Count == 0)
            {
                return;
            }
            var selectedItem = appsListView.SelectedItems.Cast <ListViewItem>().FirstOrDefault();

            if (selectedItem == default)
            {
                return;
            }
            var appData = CacheData.FindAppData(selectedItem.Text);

            if (appData == default)
            {
                return;
            }
            var owner = sender as ToolStripMenuItem;

            switch (owner?.Name)
            {
            case nameof(appMenuItem1):
            case nameof(appMenuItem2):
            case nameof(appMenuItem3):
                if (Opacity > 0)
                {
                    Opacity = 0;
                }
                switch (owner.Name)
                {
                case nameof(appMenuItem1):
                case nameof(appMenuItem2):
                    PreventClosure = true;
                    appData.StartApplication(true, owner.Name.EqualsEx(nameof(appMenuItem2)));
                    break;

                case nameof(appMenuItem3):
                    PreventClosure = true;
                    appData.OpenLocation(true);
                    break;
                }
                break;

            case nameof(appMenuItem4):
            {
                var linkPath = PathEx.Combine(Environment.SpecialFolder.Desktop, selectedItem.Text);
                var created  = FileEx.CreateShellLink(appData.FilePath, linkPath);
                MessageBoxEx.CenterMousePointer = !ClientRectangle.Contains(PointToClient(MousePosition));
                MessageBoxEx.Show(this, Language.GetText(created ? nameof(en_US.appMenuItem4Msg0) : nameof(en_US.appMenuItem4Msg1)), Resources.GlobalTitle, MessageBoxButtons.OK, created ? MessageBoxIcon.Asterisk : MessageBoxIcon.Warning);
                break;
            }

            case nameof(appMenuItem6):
                if (appsListView.SelectedItems.Count > 0)
                {
                    if (!appsListView.LabelEdit)
                    {
                        appsListView.LabelEdit = true;
                    }
                    selectedItem.BeginEdit();
                }
                break;

            case nameof(appMenuItem7):
                MessageBoxEx.CenterMousePointer = !ClientRectangle.Contains(PointToClient(MousePosition));
                if (MessageBoxEx.Show(this, string.Format(CultureInfo.InvariantCulture, Language.GetText(nameof(en_US.appMenuItem7Msg)), selectedItem.Text), Resources.GlobalTitle, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    MessageBoxEx.CenterMousePointer = !ClientRectangle.Contains(PointToClient(MousePosition));
                    PreventClosure = true;
                    if (appData.RemoveApplication(this))
                    {
                        MenuViewFormUpdate(false);
                    }
                    PreventClosure = false;
                }
                else
                {
                    MessageBoxEx.CenterMousePointer = !ClientRectangle.Contains(PointToClient(MousePosition));
                    MessageBoxEx.Show(this, Language.GetText(nameof(en_US.OperationCanceledMsg)), Resources.GlobalTitle, MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                }
                break;

            case nameof(appMenuItem8):
                OpenForm(new SettingsForm(appData));
                break;
            }
            if (MessageBoxEx.CenterMousePointer)
            {
                MessageBoxEx.CenterMousePointer = false;
            }
        }
Beispiel #6
0
        public void SimulateKeyPress(char ch)
        {
            if (SelectionManager.HasSomethingSelected)
            {
                if (SelectionManager.SelectionIsReadonly)
                {
                    return;
                }
            }
            else if (IsReadOnly(Caret.Offset))
            {
                return;
            }

            if (ch < ' ')
            {
                return;
            }

            if (!_hiddenMouseCursor && Shared.TEP.HideMouseCursor)
            {
                if (ClientRectangle.Contains(PointToClient(Cursor.Position)))
                {
                    _mouseCursorHidePosition = Cursor.Position;
                    _hiddenMouseCursor       = true;
                    Cursor.Hide();
                }
            }
            CloseToolTip();

            BeginUpdate();
            Document.UndoStack.StartUndoGroup();

            try
            {
                // INSERT char
                if (!HandleKeyPress(ch))
                {
                    switch (Caret.CaretMode)
                    {
                    case CaretMode.InsertMode:
                        InsertChar(ch);
                        break;

                    case CaretMode.OverwriteMode:
                        ReplaceChar(ch);
                        break;

                    default:
                        //Debug.Assert(false, "Unknown caret mode " + Caret.CaretMode);
                        break;
                    }
                }

                int currentLineNr = Caret.Line;
                Document.FormattingStrategy.FormatLine(this, currentLineNr, Document.PositionToOffset(Caret.Position), ch);

                EndUpdate();
            }
            finally
            {
                Document.UndoStack.EndUndoGroup();
            }
        }
Beispiel #7
0
 private bool IsMouseInCheckArea()
 {
     return(ClientRectangle.Contains(MouseLocation));
 }
Beispiel #8
0
        private bool CheckMouseHover()
        {
            var pt = PointToClient(Cursor.Position);

            return(ClientRectangle.Contains(pt));
        }
Beispiel #9
0
        protected override void OnPaint(PaintEventArgs e)
        {
            this.Settings.BorderColor     = ((MWindow)this.Parent).ExtendedSettings.BorderColor;
            this.Settings.BorderThickness = ((MWindow)this.Parent).ExtendedSettings.BorderThickness;
            BorderPen.Color = this.Settings.BorderColor;

            if (BackColor != ((MWindow)Parent).BackColor)
            {
                BackColor = ((MWindow)Parent).BackColor;
            }
            Point MousePosition = PointToClient(Control.MousePosition);

            if (TextInvertedColor == null)
            {
                TextInvertedColor = new SolidBrush(InvertColor(this.Settings.MouseDownBackColor));
                TextColor         = new SolidBrush(this.ForeColor);
            }

            if (ClientRectangle.Contains(MousePosition))
            {
                isMouseOver = true;

                if (isMoveOffDown && !isMouseDown)
                {
                    isMouseDown = true;
                }
                else
                {
                    isMouseDown = false;
                }

                if ((Control.MouseButtons & MouseButtons.Left) != 0)
                {
                    isMouseDown = true;
                }
            }
            else
            {
                isMouseOver = false;
                isMouseDown = false;
            }

            if (ForceMouseLeave)
            {
                isMouseOver     = false;
                ForceMouseLeave = false;
            }

            Rectangle r = this.ClientRectangle;

            e.Graphics.Clear(Color.FromArgb(255, BackColor));

            e.Graphics.SmoothingMode     = SmoothingMode.None;
            e.Graphics.InterpolationMode = InterpolationMode.HighQualityBilinear;
            //e.Graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;

            SizeF  stringSize     = e.Graphics.MeasureString(this.Text, this.Font);
            PointF stringPosition = new PointF();

            if (stringSize.Width > this.Width)
            {
                stringPosition.X = 0;
            }
            else
            {
                stringPosition.X = (this.Width - stringSize.Width) / 2;
            }
            stringPosition.Y = (this.Height - stringSize.Height) / 2;

            if (isMouseOver)
            {
                if (Settings.VistaStyleGradientBackground)
                {
                    using (GraphicsPath gp = new GraphicsPath()) {
                        gp.AddEllipse(this.ClientRectangle.X - this.Settings.CornerRadius, this.ClientRectangle.Y - this.Settings.CornerRadius, this.ClientRectangle.Width + (this.Settings.CornerRadius * 2), this.ClientRectangle.Height + (this.Settings.CornerRadius * 2));
                        using (PathGradientBrush pgb = new PathGradientBrush(gp)) {
                            pgb.CenterPoint    = new Point(this.Width / 2, this.Height);//PointToClient(Cursor.Position);
                            pgb.CenterColor    = Settings.MouseOverBackColor;
                            pgb.SurroundColors = new Color[] { Color.FromArgb(0, 0, 0, 0), Color.FromArgb(0, 0, 0, 0), Color.FromArgb(0, 0, 0, 0), Color.FromArgb(0, 0, 0, 0) };
                            e.Graphics.DrawRoundedRectangle(Color.Black, r, Settings.CornerRadius, this.Settings.RoundCorners, BorderPen, pgb);
                            pgb.Dispose();
                        }
                        gp.Dispose();
                    }
                }
                else
                {
                    e.Graphics.DrawRoundedRectangle(Settings.MouseOverBackColor, r, Settings.CornerRadius, this.Settings.RoundCorners, BorderPen);
                }
            }

            if (isMouseDown)
            {
                if (Settings.VistaStyleGradientBackground)
                {
                    using (GraphicsPath gp = new GraphicsPath()) {
                        gp.AddEllipse(this.ClientRectangle.X - 10, this.ClientRectangle.Y - 10, this.ClientRectangle.Width + 20, this.ClientRectangle.Height + 20);
                        using (PathGradientBrush pgb = new PathGradientBrush(gp)) {
                            pgb.CenterPoint    = new Point(this.Width / 2, this.Height);
                            pgb.CenterColor    = Settings.MouseDownBackColor;
                            pgb.SurroundColors = new Color[] { Settings.MouseDownBackColorAlt };
                            e.Graphics.DrawRoundedRectangle(Color.Black, r, Settings.CornerRadius, this.Settings.RoundCorners, BorderPen, pgb);
                            pgb.Dispose();
                        }
                        gp.Dispose();
                    }
                }
                else
                {
                    e.Graphics.DrawRoundedRectangle(Settings.MouseDownBackColor, r, Settings.CornerRadius, this.Settings.RoundCorners, BorderPen);
                }
                stringPosition.X += 1;
                stringPosition.Y += 1;
            }

            e.Graphics.DrawRoundedRectangle(Settings.BorderColor, r, Settings.CornerRadius, this.Settings.RoundCorners, BorderPen, null, true);

            if (this.UseCompatibleTextRendering)
            {
                stringPosition.Y += 2;
            }

            e.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SingleBitPerPixelGridFit; //System.Drawing.Text.TextRenderingHint.AntiAliasGridFit;
            if (isMouseDown && Settings.InvertForeColorOnMouseDown)
            {
                e.Graphics.DrawString(this.Text, this.Font, TextInvertedColor, stringPosition);
            }
            else
            {
                e.Graphics.DrawString(this.Text, this.Font, TextColor, stringPosition);
            }

            e.Graphics.Flush();
            return;
        }
 private void TextBox_MouseLeave(object sender, EventArgs e)
 {
     IsHot = ClientRectangle.Contains(PointToClient(Cursor.Position));
     Repaint();
 }
Beispiel #11
0
        protected override void OnMouseDown(MouseButtonEventArgs e)
        {
            if (e.Button != MouseButton.Left || _holding != null || !ClientRectangle.Contains(e.Position))
            {
                return;
            }

            if (_inventoryGui != null && _inventoryGui.IsShown())
            {
                var picked = _inventoryGui.PickElement(e.X, e.Y);

                if (picked != null)
                {
                    _holding     = new ElementEntity(e.X, e.Y, picked);
                    _clickOffset = new PointF();

                    _elementEntities.Add(_holding);
                }

                return;
            }

            //double click, clone double clicked item
            if (_clicks >= 1)
            {
                _clicks = 0;
                _doubleClickTimer.Stop();

                if (GetTopElementAtPoint(e.Position) is ElementEntity entity && _lastClicked == entity)
                {
                    _clickOffset = new PointF();
                    _holding     = new ElementEntity(e.X, e.Y, entity.Element);

                    _elementEntities.Add(_holding);
                }
                if (_lastClicked == null)
                {
                    AddBaseElements(e.Position);
                }

                return;
            }

            _clicks++;

            _doubleClickTimer.Interval = _doubleClickTimer.Interval = SystemInformation.DoubleClickTime / 2;
            _doubleClickTimer.Start();

            if (_elementEntities.Count > 0 && GetTopElementAtPoint(e.Position) is ElementEntity top)
            {
                _clickOffset = new PointF(top.X - e.X, top.Y - e.Y);

                _lastClicked = _holding = top;

                _elementEntities.Remove(_holding);
                _elementEntities.Add(_holding);
            }
            else
            {
                _lastClicked = null;
            }
        }
Beispiel #12
0
        private void timerSync_Tick(object sender, EventArgs e)
        {
            if (NativeMethods.GetWindowRect(ownerHandle, out NativeMethods.RECT rect))
            {
                int width  = rect.Right - rect.Left + 1;
                int height = rect.Bottom - rect.Top + 1;

                IWMPMedia    media    = Player.currentMedia;
                IWMPControls controls = Player.controls;

                bool isCursorInside = ClientRectangle.Contains(PointToClient(Cursor.Position));

                ClientSize = new Size(Math.Max(MinimumSize.Width, Math.Min(media.imageSourceWidth, width * 3 / 4)), Math.Max(MinimumSize.Height, Math.Min(media.imageSourceHeight, height * 3 / 4)));
                Location   = new Point(rect.Left + (width - ClientSize.Width) / 2, rect.Top + (height - ClientSize.Height + SystemInformation.CaptionHeight) / 2);

                tablePanel.Visible = isCursorInside || isDragging;

                if (tablePanel.Visible)
                {
                    labelTime.Text = $"{controls.currentPositionString} / {media.durationString}";

                    int value = (int)Math.Round(progressSeek.Maximum * controls.currentPosition / media.duration);

                    if (value >= progressSeek.Maximum)
                    {
                        progressSeek.Value = progressSeek.Maximum;
                        progressSeek.Value = progressSeek.Maximum - 1;
                        progressSeek.Value = progressSeek.Maximum;
                    }
                    else
                    {
                        progressSeek.Value = value + 1;
                        progressSeek.Value = value;
                    }
                }

                if (controls.currentPosition > media.duration)  // pausing near the end of the video causes WMP to play beyond the end of the video wtf
                {
                    try{
                        controls.stop();
                        controls.currentPosition = 0;
                        controls.play();
                    }catch (AccessViolationException) {
                        // something is super retarded here because shit gets disposed between the start of this method and
                        // the controls.play() call even though it runs on the UI thread
                    }
                }

                if (isCursorInside && !wasCursorInside)
                {
                    wasCursorInside = true;
                }
                else if (!isCursorInside && wasCursorInside)
                {
                    wasCursorInside = false;

                    if (!Player.fullScreen && Handle == NativeMethods.GetForegroundWindow())
                    {
                        NativeMethods.SetForegroundWindow(ownerHandle);
                    }
                }

                Marshal.ReleaseComObject(media);
                Marshal.ReleaseComObject(controls);
            }
            else
            {
                Environment.Exit(Program.CODE_OWNER_GONE);
            }
        }
Beispiel #13
0
 protected override void OnMouseMove(MouseEventArgs args)
 {
     base.OnMouseMove(args);
     tmr.Enabled = Capture & ClientRectangle.Contains(args.Location);
 }
Beispiel #14
0
 protected override void OnMouseMove(MouseEventArgs e)
 {
     selected = (ClientRectangle.Contains(e.X, e.Y));
     Invalidate();
     base.OnMouseMove(e);
 }
Beispiel #15
0
 public bool IsMouseOverMe()
 {
     return(ClientRectangle.Contains(PointToClient(Control.MousePosition)));
 }
Beispiel #16
0
 protected override void OnMouseUp(MouseEventArgs mevent)
 {
     base.OnMouseUp(mevent);
     cs = (ClientRectangle.Contains(mevent.Location)) ? ControlState.Hover : ControlState.Normal;
     Invalidate();
 }
Beispiel #17
0
        private bool IsMouseInWindow()
        {
            Point clientPoint = PointToClient(Cursor.Position);

            return(ClientRectangle.Contains(clientPoint));
        }
        private void AppMenuItem_Click(object sender, EventArgs e)
        {
            if (appsListView.SelectedItems.Count == 0)
            {
                return;
            }
            var owner = sender as ToolStripMenuItem;

            switch (owner?.Name)
            {
            case "appMenuItem1":
            case "appMenuItem2":
            case "appMenuItem3":
                if (Opacity > 0)
                {
                    Opacity = 0;
                }
                switch (owner.Name)
                {
                case "appMenuItem1":
                case "appMenuItem2":
                    _appStartEventCalled = true;
                    Main.StartApp(appsListView.SelectedItems[0].Text, true, owner.Name.EqualsEx("appMenuItem2"));
                    break;

                case "appMenuItem3":
                    _appStartEventCalled = true;
                    Main.OpenAppLocation(appsListView.SelectedItems[0].Text, true);
                    break;
                }
                break;

            case "appMenuItem4":
                MessageBoxEx.CenterMousePointer = !ClientRectangle.Contains(PointToClient(MousePosition));
                var targetPath = EnvironmentEx.GetVariablePathFull(Main.GetAppPath(appsListView.SelectedItems[0].Text), false);
                var linkPath   = Path.Combine("%Desktop%", appsListView.SelectedItems[0].Text);
                if (Data.CreateShortcut(targetPath, linkPath))
                {
                    MessageBoxEx.Show(this, Lang.GetText($"{owner.Name}Msg0"), Text, MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                }
                else
                {
                    MessageBoxEx.Show(this, Lang.GetText($"{owner.Name}Msg1"), Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
                break;

            case "appMenuItem5":
                MessageBoxEx.CenterMousePointer = !ClientRectangle.Contains(PointToClient(MousePosition));
                var appPath = Main.GetAppPath(appsListView.SelectedItems[0].Text);
                if (Data.PinToTaskbar(appPath))
                {
                    MessageBoxEx.Show(this, Lang.GetText(nameof(en_US.appMenuItem4Msg0)), Text, MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                }
                else
                {
                    MessageBoxEx.Show(this, Lang.GetText(nameof(en_US.appMenuItem4Msg1)), Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
                break;

            case "appMenuItem6":
                if (appsListView.SelectedItems.Count > 0)
                {
                    if (!appsListView.LabelEdit)
                    {
                        appsListView.LabelEdit = true;
                    }
                    appsListView.SelectedItems[0].BeginEdit();
                }
                break;

            case "appMenuItem7":
                MessageBoxEx.CenterMousePointer = !ClientRectangle.Contains(PointToClient(MousePosition));
                if (MessageBoxEx.Show(this, string.Format(Lang.GetText($"{owner.Name}Msg"), appsListView.SelectedItems[0].Text), Text, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    MessageBoxEx.CenterMousePointer = !ClientRectangle.Contains(PointToClient(MousePosition));
                    try
                    {
                        var appInfo = Main.GetAppInfo(appsListView.SelectedItems[0].Text);
                        var appDir  = Main.GetAppLocation(appInfo.ShortName);
                        if (Directory.Exists(appDir))
                        {
                            try
                            {
                                var imgCachePath = PathEx.Combine(Main.TmpDir, "images.dat");
                                if (File.Exists(imgCachePath))
                                {
                                    File.Delete(imgCachePath);
                                }
                                Directory.Delete(appDir, true);
                            }
                            catch
                            {
                                if (!Data.ForceDelete(appDir))
                                {
                                    _appStartEventCalled = true;
                                    Data.ForceDelete(appDir, true);
                                }
                            }
                            Ini.RemoveSection(appInfo.ShortName);
                            Ini.WriteAll();
                            MenuViewForm_Update(false);
                            MessageBoxEx.Show(this, Lang.GetText(nameof(en_US.OperationCompletedMsg)), Text, MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                            _appStartEventCalled = false;
                        }
                    }
                    catch (Exception ex)
                    {
                        Log.Write(ex);
                        MessageBoxEx.Show(this, Lang.GetText(nameof(en_US.OperationFailedMsg)), Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                }
                else
                {
                    MessageBoxEx.CenterMousePointer = !ClientRectangle.Contains(PointToClient(MousePosition));
                    MessageBoxEx.Show(this, Lang.GetText(nameof(en_US.OperationCanceledMsg)), Text, MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                }
                break;
            }
            if (MessageBoxEx.CenterMousePointer)
            {
                MessageBoxEx.CenterMousePointer = false;
            }
        }
Beispiel #19
0
        /// <summary>
        /// Draws the Map in MainView.
        /// </summary>
        /// <param name="e"></param>
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            if (MapBase != null)
            {
                _graphics = e.Graphics;
                _graphics.InterpolationMode = InterpolationLocal;
                _graphics.PixelOffsetMode   = PixelOffsetMode.HighQuality;

                if (_spriteShadeEnabled)
                {
                    _spriteAttributes.SetGamma(SpriteShadeLocal, ColorAdjustType.Bitmap);
                }

                // Image Processing using C# - https://www.codeproject.com/Articles/33838/Image-Processing-using-C
                // ColorMatrix Guide - https://docs.rainmeter.net/tips/colormatrix-guide/

                ControlPaint.DrawBorder3D(_graphics, ClientRectangle, Border3DStyle.Etched);


                var dragRect = new Rectangle();
                if (FirstClick)
                {
                    var start = GetAbsoluteDragStart();
                    var end   = GetAbsoluteDragEnd();

                    dragRect = new Rectangle(
                        start.X, start.Y,
                        end.X - start.X + 1,
                        end.Y - start.Y + 1);
                }

                for (int
                     lev = MapBase.MapSize.Levs - 1;
                     lev >= MapBase.Level && lev != -1;
                     --lev)
                {
                    if (_showGrid && lev == MapBase.Level)
                    {
                        DrawGrid();
                    }

                    for (int
                         row = 0,
                         startY = Origin.Y + (HalfHeight * lev * 3),
                         startX = Origin.X;
                         row != MapBase.MapSize.Rows;
                         ++row,
                         startY += HalfHeight,
                         startX -= HalfWidth)
                    {
                        for (int
                             col = 0,
                             x = startX,
                             y = startY;
                             col != MapBase.MapSize.Cols;
                             ++col,
                             x += HalfWidth,
                             y += HalfHeight)
                        {
                            bool isClicked = FirstClick &&                          //&& Cuboid != null
                                             ((col == DragStart.X && row == DragStart.Y) ||
                                              (col == DragEnd.X && row == DragEnd.Y));

                            if (isClicked)
                            {
                                Cuboid.DrawCuboid(
                                    _graphics,
                                    x, y,
                                    HalfWidth,
                                    HalfHeight,
                                    false,
                                    lev == MapBase.Level);
                            }

                            if (lev == MapBase.Level || !MapBase[row, col, lev].Occulted)
                            {
                                DrawTile(
                                    (XCMapTile)MapBase[row, col, lev],
                                    x, y,
                                    _graySelection && FirstClick &&
                                    lev == MapBase.Level &&
                                    dragRect.Contains(col, row));
                            }

                            if (isClicked)
                            {
                                Cuboid.DrawCuboid(
                                    _graphics,
                                    x, y,
                                    HalfWidth,
                                    HalfHeight,
                                    true,
                                    lev == MapBase.Level);
                            }
                            else if (Focused &&
                                     !_suppressTargeter &&
                                     ClientRectangle.Contains(PointToClient(Cursor.Position)) &&
                                     col == _colOver &&
                                     row == _rowOver &&
                                     lev == MapBase.Level)
                            {
                                Cuboid.DrawTargeter(
                                    _graphics,
                                    x, y,
                                    HalfWidth,
                                    HalfHeight);
                            }
                        }
                    }
                }

//				if (_drawSelectionBox) // always false.
//				if (FirstClick && !_graySelection)
                if (dragRect.Width > 2 || dragRect.Height > 2 ||
                    (dragRect.Width > 1 && dragRect.Height > 1))
                {
                    DrawSelectionBorder(dragRect);
                }
            }
        }
Beispiel #20
0
 protected virtual bool IsMouseOver(Point p)
 {
     return(ClientRectangle.Contains(p));
 }
Beispiel #21
0
        protected override void OnLatePaint(PaintEventArgs e)
        {
            base.OnLatePaint(e);

            e.Graphics.DrawRectangle(new Pen(BorderColor), 0, 0, Width, Height);

            /*if (!AlwaysFocused && !Focused)
             *  e.Graphics.FillRectangle(new SolidBrush(Color.FromArgb(64, 180, 180, 180)), 0, 0, Width, Height);*/

            var g = e.Graphics;

            #region Show resize.
            if (HighlightResizeBorders && !ResizeIcon)
            {
                if (ClientRectangle.Contains(PointToClient(MousePosition)))
                {
                    if (_resizeShow == DNDResizeType.None)
                    {
                        _resizeAlpha = MathHelper.FloatLerp(_resizeAlpha, 0, 1);
                    }
                    else
                    {
                        _resizeAlpha = MathHelper.FloatLerp(_resizeAlpha, 255, 1);
                    }
                }
                else
                {
                    _resizeAlpha = MathHelper.FloatLerp(_resizeAlpha, 0, 1);
                }

                //SolidBrush resizeBrush = new SolidBrush(Color.FromArgb((int)_resizeAlpha, 8, 122, 204));
                if (_resizeAlpha > 0)
                {
                    switch (_resizeShow)
                    {
                    case DNDResizeType.Right:
                        //g.FillRectangle(resizeBrush, Width - _resizeOffset, 0, _resizeOffset, Height);
                        g.DrawTexture(
                            ApplicationBehaviour.Resources.Images.ArrowRight,
                            Width - ApplicationBehaviour.Resources.Images.ArrowRight.width,
                            Height / 2 - ApplicationBehaviour.Resources.Images.ArrowRight.height / 2,
                            ApplicationBehaviour.Resources.Images.ArrowRight.width,
                            ApplicationBehaviour.Resources.Images.ArrowRight.height,
                            Color.FromArgb((int)_resizeAlpha, Color.White));
                        break;

                    case DNDResizeType.RightDown:
                        g.DrawTexture(
                            ApplicationBehaviour.Resources.Images.ArrowRight,
                            Width - ApplicationBehaviour.Resources.Images.ArrowRight.width,
                            Height / 2 - ApplicationBehaviour.Resources.Images.ArrowRight.height / 2,
                            ApplicationBehaviour.Resources.Images.ArrowRight.width,
                            ApplicationBehaviour.Resources.Images.ArrowRight.height,
                            Color.FromArgb((int)_resizeAlpha, Color.White)
                            );
                        g.DrawTexture(
                            ApplicationBehaviour.Resources.Images.ArrowDown,
                            Width / 2 - ApplicationBehaviour.Resources.Images.ArrowDown.width / 2,
                            Height - ApplicationBehaviour.Resources.Images.ArrowDown.height,
                            ApplicationBehaviour.Resources.Images.ArrowDown.width,
                            ApplicationBehaviour.Resources.Images.ArrowDown.height,
                            Color.FromArgb((int)_resizeAlpha, Color.White)
                            );
                        //g.FillRectangle(resizeBrush, Width - _resizeOffset, 0, _resizeOffset, Height - _resizeOffset);
                        //g.FillRectangle(resizeBrush, 0, Height - _resizeOffset, Width, _resizeOffset);
                        break;

                    case DNDResizeType.Down:
                        g.DrawTexture(
                            ApplicationBehaviour.Resources.Images.ArrowDown,
                            Width / 2 - ApplicationBehaviour.Resources.Images.ArrowDown.width / 2,
                            Height - ApplicationBehaviour.Resources.Images.ArrowDown.height,
                            ApplicationBehaviour.Resources.Images.ArrowDown.width,
                            ApplicationBehaviour.Resources.Images.ArrowDown.height,
                            Color.FromArgb((int)_resizeAlpha, Color.White)
                            );
                        //g.FillRectangle(resizeBrush, 0, Height - _resizeOffset, Width, _resizeOffset);
                        break;

                    case DNDResizeType.LeftDown:
                        g.DrawTexture(
                            ApplicationBehaviour.Resources.Images.ArrowLeft,
                            0,
                            Height / 2 - ApplicationBehaviour.Resources.Images.ArrowLeft.height / 2,
                            ApplicationBehaviour.Resources.Images.ArrowLeft.width,
                            ApplicationBehaviour.Resources.Images.ArrowLeft.height,
                            Color.FromArgb((int)_resizeAlpha, Color.White)
                            );
                        g.DrawTexture(
                            ApplicationBehaviour.Resources.Images.ArrowDown,
                            Width / 2 - ApplicationBehaviour.Resources.Images.ArrowDown.width / 2,
                            Height - ApplicationBehaviour.Resources.Images.ArrowDown.height,
                            ApplicationBehaviour.Resources.Images.ArrowDown.width,
                            ApplicationBehaviour.Resources.Images.ArrowDown.height,
                            Color.FromArgb((int)_resizeAlpha, Color.White)
                            );
                        //g.FillRectangle(resizeBrush, 0, 0, _resizeOffset, Height - _resizeOffset);
                        //g.FillRectangle(resizeBrush, 0, Height - _resizeOffset, Width, _resizeOffset);
                        break;

                    case DNDResizeType.Left:
                        g.DrawTexture(
                            ApplicationBehaviour.Resources.Images.ArrowLeft,
                            0,
                            Height / 2 - ApplicationBehaviour.Resources.Images.ArrowLeft.height / 2,
                            ApplicationBehaviour.Resources.Images.ArrowLeft.width,
                            ApplicationBehaviour.Resources.Images.ArrowLeft.height,
                            Color.FromArgb((int)_resizeAlpha, Color.White)
                            );
                        //g.FillRectangle(resizeBrush, 0, 0, _resizeOffset, Height);
                        break;

                    case DNDResizeType.LeftUp:
                        g.DrawTexture(
                            ApplicationBehaviour.Resources.Images.ArrowLeft,
                            0,
                            Height / 2 - ApplicationBehaviour.Resources.Images.ArrowLeft.height / 2,
                            ApplicationBehaviour.Resources.Images.ArrowLeft.width,
                            ApplicationBehaviour.Resources.Images.ArrowLeft.height,
                            Color.FromArgb((int)_resizeAlpha, Color.White)
                            );
                        g.DrawTexture(
                            ApplicationBehaviour.Resources.Images.ArrowUp,
                            Width / 2 - ApplicationBehaviour.Resources.Images.ArrowUp.width / 2,
                            0,
                            ApplicationBehaviour.Resources.Images.ArrowUp.width,
                            ApplicationBehaviour.Resources.Images.ArrowUp.height,
                            Color.FromArgb((int)_resizeAlpha, Color.White)
                            );
                        //g.FillRectangle(resizeBrush, 0, _resizeOffset, _resizeOffset, Height - _resizeOffset);
                        //g.FillRectangle(resizeBrush, 0, 0, Width, _resizeOffset);
                        break;

                    case DNDResizeType.Up:
                        g.DrawTexture(
                            ApplicationBehaviour.Resources.Images.ArrowUp,
                            Width / 2 - ApplicationBehaviour.Resources.Images.ArrowUp.width / 2,
                            0,
                            ApplicationBehaviour.Resources.Images.ArrowUp.width,
                            ApplicationBehaviour.Resources.Images.ArrowUp.height,
                            Color.FromArgb((int)_resizeAlpha, Color.White)
                            );
                        //g.FillRectangle(resizeBrush, 0, 0, Width, _resizeOffset);
                        break;

                    case DNDResizeType.RightUp:
                        g.DrawTexture(
                            ApplicationBehaviour.Resources.Images.ArrowRight,
                            Width - ApplicationBehaviour.Resources.Images.ArrowRight.width,
                            Height / 2 - ApplicationBehaviour.Resources.Images.ArrowRight.height / 2,
                            ApplicationBehaviour.Resources.Images.ArrowRight.width,
                            ApplicationBehaviour.Resources.Images.ArrowRight.height,
                            Color.FromArgb((int)_resizeAlpha, Color.White));
                        g.DrawTexture(
                            ApplicationBehaviour.Resources.Images.ArrowUp,
                            Width / 2 - ApplicationBehaviour.Resources.Images.ArrowUp.width / 2,
                            0,
                            ApplicationBehaviour.Resources.Images.ArrowUp.width,
                            ApplicationBehaviour.Resources.Images.ArrowUp.height,
                            Color.FromArgb((int)_resizeAlpha, Color.White)
                            );
                        //g.FillRectangle(resizeBrush, Width - _resizeOffset, _resizeOffset, _resizeOffset, Height - _resizeOffset);
                        //g.FillRectangle(resizeBrush, 0, 0, Width, _resizeOffset);
                        break;
                    }
                }
            }
            #endregion
        }
Beispiel #22
0
 /// <summary>
 /// Checks if this container contains a position
 /// </summary>
 /// <param name="pos">position in screen coordinates</param>
 /// <returns>true if this container contains the position</returns>
 public bool ContainsPos(Point pos)
 {
     return(Visible && ClientRectangle.Contains(PointToClient(pos)));
 }
Beispiel #23
0
        protected override void OnMouseMove(MouseEventArgs e)
        {
            base.OnMouseMove(e);

            if (e.Button == MouseButtons.Left)
            {
                if (thumbClicked)
                {
                    int oldScrollValue = curValue;

                    int pos       = orientation == ScrollOrientation.Vertical ? e.Location.Y : e.Location.X;
                    int thumbSize = orientation == ScrollOrientation.Vertical ? (pos / Height) / thumbHeight : (pos / Width) / thumbWidth;

                    if (pos <= (thumbTopLimit + thumbPosition))
                    {
                        ChangeThumbPosition(thumbTopLimit);
                        curValue = minimum;
                        Invalidate();
                    }
                    else if (pos >= (thumbBottomLimitTop + thumbPosition))
                    {
                        ChangeThumbPosition(thumbBottomLimitTop);
                        curValue = maximum;
                        Invalidate();
                    }
                    else
                    {
                        ChangeThumbPosition(pos - thumbPosition);

                        int pixelRange, thumbPos;

                        if (Orientation == ScrollOrientation.Vertical)
                        {
                            pixelRange = Height - thumbSize;
                            thumbPos   = thumbRectangle.Y;
                        }
                        else
                        {
                            pixelRange = Width - thumbSize;
                            thumbPos   = thumbRectangle.X;
                        }

                        float perc = 0f;

                        if (pixelRange != 0)
                        {
                            perc = (thumbPos) / (float)pixelRange;
                        }

                        curValue = Convert.ToInt32((perc * (maximum - minimum)) + minimum);
                    }

                    if (oldScrollValue != curValue)
                    {
                        OnScroll(ScrollEventType.ThumbTrack, oldScrollValue, curValue, scrollOrientation);
                        Refresh();
                    }
                }
            }
            else if (!ClientRectangle.Contains(e.Location))
            {
                ResetScrollStatus();
            }
            else if (e.Button == MouseButtons.None)
            {
                if (thumbRectangle.Contains(e.Location))
                {
                    Invalidate(thumbRectangle);
                }
                else if (ClientRectangle.Contains(e.Location))
                {
                    Invalidate();
                }
            }
        }
 public bool HasCapturedMouse()
 {
     return(ClientRectangle.Contains(PointToClient(Cursor.Position)));
 }
        protected override void OnPaint(PaintEventArgs e)
        {
            int height = ClientSize.Height;

            int  pixelsPerMinute = (PixelsPerMinute * (_Scrollable ? ZoomRatio : 100)) / 100;
            long maxValue = MaximumThreshold;
            long minTicks = 0, maxTicks = 0;
            int  contentWidth;

            const long minuteInTicks = Squared.Util.Time.SecondInTicks * 60;

            if (Items.Count > 0)
            {
                maxValue = Math.Max(MaximumThreshold, (from s in Items select _ItemValueGetter(s)).Max());
                minTicks = (from s in Items select s.Timestamp.Ticks).Min();
                maxTicks = (from s in Items select s.Timestamp.Ticks).Max();

                bool rescaled = false;

rescale:
                _ContentWidth = contentWidth = (int)(
                    (maxTicks - minTicks)
                    * pixelsPerMinute / minuteInTicks
                    ) + MarginWidth;

                if (!_Scrollable && !rescaled)
                {
                    _ZoomRatio      = (int)Math.Floor(ClientSize.Width / (double)(contentWidth + 1) * 100.0);
                    pixelsPerMinute = (PixelsPerMinute * _ZoomRatio) / 100;
                    rescaled        = true;

                    goto rescale;
                }
            }
            else
            {
                _ContentWidth = contentWidth = MarginWidth;
            }

            if (_Scrollable)
            {
                height -= ScrollBar.Height;

                if (_ScrollOffset > contentWidth - ClientSize.Width)
                {
                    _ScrollOffset = contentWidth - ClientSize.Width;
                }
                if (_ScrollOffset < 0)
                {
                    _ScrollOffset = 0;
                }

                int  scrollMax = contentWidth - ClientSize.Width + ScrollBar.LargeChange - 1;
                bool enabled   = (scrollMax > 0);
                if (scrollMax < 0)
                {
                    scrollMax = 0;
                }

                // WinForms' scrollbar control is terrible
                if (ScrollBar.Maximum != scrollMax)
                {
                    ScrollBar.Maximum = scrollMax;
                }
                if (ScrollBar.Value != _ScrollOffset)
                {
                    ScrollBar.Value = _ScrollOffset;
                }
                if (ScrollBar.Enabled != enabled)
                {
                    ScrollBar.Enabled = enabled;
                }
                if (!ScrollBar.Visible)
                {
                    ScrollBar.Visible = true;
                }
                if (!ZoomInButton.Visible)
                {
                    ZoomInButton.Visible = true;
                }
                if (!ZoomOutButton.Visible)
                {
                    ZoomOutButton.Visible = true;
                }
            }
            else
            {
                if (ScrollBar.Visible)
                {
                    ScrollBar.Visible = false;
                }
                if (ZoomInButton.Visible)
                {
                    ZoomInButton.Visible = false;
                }
                if (ZoomOutButton.Visible)
                {
                    ZoomOutButton.Visible = false;
                }

                _ScrollOffset = 0;
            }

            using (var outlinePen = new Pen(Color.Black))
                using (var gridPen = new Pen(Color.FromArgb(96, 0, 0, 0)))
                    using (var scratch = Scratch.Get(e.Graphics, ClientRectangle)) {
                        var g = scratch.Graphics;
                        g.Clear(BackColor);

                        g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;

                        float y = 0;
                        using (var textBrush = new SolidBrush(ForeColor))
                        {
                            g.DrawLine(gridPen, 0, height - VerticalMargin, ClientSize.Width, height - VerticalMargin);
                            g.DrawLine(gridPen, 0, VerticalMargin, Width, VerticalMargin);

                            var lineHeight = g.MeasureString("AaBbYyZz", Font).Height;
                            var numLines   = (int)Math.Min(
                                Math.Max(2, Math.Floor((height / lineHeight) * GridLineRatio)),
                                MaxGridLines
                                );
                            for (int i = 0; i <= numLines; i++)
                            {
                                var value = (maxValue * i / numLines);
                                var text  = _ItemValueFormatter(value);
                                y = (float)(height - VerticalMargin - ((value / (double)maxValue) * (height - VerticalMargin * 2)));

                                g.DrawLine(gridPen, 0, y, ClientSize.Width, y);
                                g.DrawString(text, Font, textBrush, new PointF(4, y));
                            }
                        }

                        var itemXCoordinates = (from item in Items
                                                select
                                                    (int)((item.Timestamp.Ticks - minTicks)
                                                          * pixelsPerMinute / minuteInTicks
                                                          ) - _ScrollOffset);
                        var itemYCoordinates = (from item in Items
                                                select
                                                    (float)(height - VerticalMargin - (
                                                                (_ItemValueGetter(item) / (double)maxValue) *
                                                                (height - VerticalMargin * 2)
                                                                )));

                        var firstIndex = Math.Max(0, IndexFromPoint(new Point(0, 0), -1));

                        using (var brush = new SolidBrush(Color.FromArgb(127, ForeColor)))
                            DrawValueSeries(
                                g,
                                itemXCoordinates.Skip(firstIndex),
                                itemYCoordinates.Skip(firstIndex),
                                ClientSize.Width, height,
                                brush, outlinePen
                                );

                        firstIndex = Selection.First;
                        var takeCount = Selection.Second - Selection.First + 1;

                        using (var brush = new SolidBrush(SystemColors.Highlight))
                            using (var pen = new Pen(SystemColors.HighlightText)
                            {
                                Width = 2.0f
                            })
                                DrawValueSeries(
                                    g,
                                    itemXCoordinates.Skip(firstIndex).Take(takeCount),
                                    itemYCoordinates.Skip(firstIndex).Take(takeCount),
                                    ClientSize.Width, height,
                                    brush, pen
                                    );

                        var cursorPos = PointToClient(Cursor.Position);

                        DateTime mouseTime;
                        if (ClientRectangle.Contains(cursorPos) && TimeFromPoint(_MouseMoveLocation, out mouseTime))
                        {
                            using (var pen = new Pen(Color.FromArgb(127, SystemColors.HighlightText))) {
                                pen.Width = 2.0f;
                                g.DrawLine(pen, _MouseMoveLocation.X, 0, _MouseMoveLocation.X, height);
                            }

                            var mouseIndex = IndexFromTime(mouseTime, -1);
                            if (!_MouseDownLocation.HasValue)
                            {
                                using (var pen = new Pen(SystemColors.HighlightText)) {
                                    pen.Width = 2.0f;
                                    var item = Items[mouseIndex];
                                    var x    = (int)((item.Timestamp.Ticks - minTicks) * pixelsPerMinute / minuteInTicks) - _ScrollOffset;
                                    g.DrawLine(
                                        pen,
                                        x, 0, x, height
                                        );
                                }
                            }
                        }
                    }
        }
        //any controls other than pan and zoom
        private void HandleInput()
        {
            if (MainForm.ApplicationIsActivated())
            {
                MouseState mouseState = Mouse.GetState();
                //DETECT MOUSE UP AND DOWN
                rMouseDown = false;
                rMouseUp   = false;
                lMouseDown = false;
                lMouseUp   = false;

                bool spaceDown = false;
                bool delDown   = false;
                bool dDown     = false;


                #region button up/down checks;

                if (kbState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.D) &&
                    oldKbState.IsKeyUp(Microsoft.Xna.Framework.Input.Keys.D))
                {
                    dDown = true;
                }
                else
                {
                    dDown = false;
                }

                if (kbState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Space) &&
                    oldKbState.IsKeyUp(Microsoft.Xna.Framework.Input.Keys.Space))
                {
                    spaceDown = true;
                }
                else
                {
                    spaceDown = false;
                }

                if (kbState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Delete) &&
                    oldKbState.IsKeyUp(Microsoft.Xna.Framework.Input.Keys.Delete))
                {
                    delDown = true;
                }
                else
                {
                    delDown = false;
                }

                if (lastRMouse != mouseState.RightButton)
                {
                    if (lastRMouse == Microsoft.Xna.Framework.Input.ButtonState.Released)
                    {
                        rMouseDown = true;
                    }
                    if (lastRMouse == Microsoft.Xna.Framework.Input.ButtonState.Pressed)
                    {
                        rMouseUp = true;
                    }
                }

                if (lastLMouse != mouseState.LeftButton)
                {
                    if (lastLMouse == Microsoft.Xna.Framework.Input.ButtonState.Released)
                    {
                        lMouseDown = true;
                    }
                    if (lastLMouse == Microsoft.Xna.Framework.Input.ButtonState.Pressed)
                    {
                        lMouseUp = true;
                    }
                }
                #endregion

                #region mouse input handling

                if (ClientRectangle.Contains(PointToClient(Control.MousePosition))) //if mouse position is over the control
                {
                    if (!this.Focused && mouseState.LeftButton == Microsoft.Xna.Framework.Input.ButtonState.Pressed)
                    {
                        this.Focus(); //if not in focus, and left click is on control: give controlfocus
                    }
                    else //control is in focus
                    {
                        if (delDown)
                        {
                            parentForm.DeleteSelected();
                        }

                        if (parentForm.selectedToolTreeNode.Index == 0)//led is selected
                        {
                            #region ledMode

                            if (lMouseDown)
                            {
                                AddNewMasses(new Vector2(GetMousePos().X, GetMousePos().Y));
                            }

                            #endregion
                        }

                        else if (parentForm.selectedToolTreeNode.Index == 1) //select is selected
                        {
                            #region selectMode

                            bool offMass = false;
                            if (lMouseDown && selectedMass != null)
                            {
                                foreach (SimString massString in stringLists)
                                {
                                    foreach (SimMass mass in massString.MassList)
                                    {
                                        if (!(GetMousePos().X > mass.CurrPositionX - (massTexture.Width / 2) - 5f &&
                                              GetMousePos().X < mass.CurrPositionX + (massTexture.Width / 2) + 5f &&
                                              GetMousePos().Y > mass.CurrPositionY - (massTexture.Height / 2) - 5f &&
                                              GetMousePos().Y < mass.CurrPositionY + (massTexture.Height / 2) + 5f))          // deteect of mouse down over a mass
                                        {
                                            offMass = true;
                                        }
                                    }
                                }
                                if (offMass) //click was not on a mass
                                {
                                    if (selectedMass.SimObjectType == SimObjectType.PASSIVETEMP)
                                    {
                                        selectedMass.SimObjectType = SimObjectType.ACTIVE;
                                    }
                                    ClearSelection();
                                    offMass = false;
                                }
                            }

                            if (lMouseDown && selectedMass == null)
                            {
                                SimMass   newMass   = null;
                                SimString newString = null;
                                foreach (SimString massString in stringLists)
                                {
                                    foreach (SimMass mass in massString.MassList)
                                    {
                                        if (GetMousePos().X > mass.CurrPositionX - (massTexture.Width / 2) - 5f &&
                                            GetMousePos().X < mass.CurrPositionX + (massTexture.Width / 2) + 5f &&
                                            GetMousePos().Y > mass.CurrPositionY - (massTexture.Height / 2) - 5f &&
                                            GetMousePos().Y < mass.CurrPositionY + (massTexture.Height / 2) + 5f)            // deteect of mouse down over a mass
                                        {
                                            //mouse click was on a mass
                                            newMass   = mass;
                                            newString = massString;
                                        }
                                    }
                                }


                                if (newMass != null && newString != null)
                                {
                                    MakeSelection(newMass, newString);
                                }
                            }


                            if (dDown)
                            {
                                if (selectedMass != null)
                                {
                                    if (selectedMass.SimObjectType == SimObjectType.PASSIVETEMP)
                                    {
                                        selectedMass.SimObjectType = SimObjectType.ACTIVE;
                                    }
                                }
                                ClearSelection();

                                parentForm.saveState();
                            }

                            if ((spaceDown || rMouseDown) && selectedMass != null)
                            {
                                if (selectedMass.SimObjectType == SimObjectType.PASSIVETEMP) //toggle (temp)passive/active
                                {
                                    selectedMass.SimObjectType = SimObjectType.PASSIVE;
                                }
                                else
                                {
                                    selectedMass.SimObjectType = SimObjectType.PASSIVETEMP;
                                }

                                parentForm.saveState();
                            }


                            if (mouseState.LeftButton == Microsoft.Xna.Framework.Input.ButtonState.Pressed)
                            {
                                if (selectedMass != null) //if left mouse held and mass is selected, mass is being moved
                                {
                                    selectedMass.CurrPosition = GetMousePos();

                                    if (selectedMass.SimObjectType == SimObjectType.ACTIVE)
                                    {
                                        selectedMass.SimObjectType = SimObjectType.PASSIVETEMP;
                                    }
                                }
                            }
                            #endregion
                        }

                        else if (parentForm.selectedToolTreeNode.Index == 2) //rectangle select is selected
                        {
                            #region rectSelectMode

                            if (lMouseDown)
                            {
                                startVector = new Vector2(this.PointToClient(Control.MousePosition).X, this.PointToClient(Control.MousePosition).Y);
                            }

                            if (mouseState.LeftButton == Microsoft.Xna.Framework.Input.ButtonState.Pressed)
                            {
                                Vector2 endVector  = new Vector2(this.PointToClient(Control.MousePosition).X, this.PointToClient(Control.MousePosition).Y);
                                int     rectWidth  = (int)(this.PointToClient(Control.MousePosition).X - startVector.X);
                                int     rectHeight = (int)(this.PointToClient(Control.MousePosition).Y - startVector.Y);

                                Vector2 startVectorTrans = TransformPos(startVector);
                                Vector2 endVectorTrans   = TransformPos(endVector);
                                Vector2 rectVector;
                                if (endVectorTrans.Length() > startVectorTrans.Length())
                                {
                                    rectVector = endVectorTrans - startVectorTrans;
                                }
                                else
                                {
                                    rectVector = startVectorTrans - endVectorTrans;
                                }

                                selectionRectangle = new Rectangle((int)startVectorTrans.X, (int)startVectorTrans.Y, (int)rectVector.X, (int)rectVector.Y);
                                spriteBatch.Begin();

                                spriteBatch.DrawRectangle(new Rectangle((int)startVector.X, (int)startVector.Y, rectWidth, rectHeight), Color.Black);

                                spriteBatch.End();
                            }

                            if (lMouseUp)
                            {
                                //check if any masses are inside rectangle
                                ObjectGroup currentGroup = new ObjectGroup();
                                foreach (SimString massString in stringLists)
                                {
                                    foreach (SimMass mass in massString.MassList)
                                    {
                                        if (selectionRectangle.Contains(new Point((int)mass.CurrPositionX, (int)mass.CurrPositionY)))
                                        {
                                            mass.Selected = true;
                                            foreach (SimMass sMass in massString.MassList)
                                            {
                                                sMass.Selected = true;
                                            }
                                        }
                                    }
                                }
                            }

                            if (dDown)
                            {
                                foreach (SimString massString in stringLists)
                                {
                                    foreach (SimMass mass in massString.MassList)
                                    {
                                        mass.Selected = false;
                                    }
                                }
                            }

                            if (spaceDown || rMouseDown)
                            {
                                foreach (SimString massString in stringLists)
                                {
                                    foreach (SimMass mass in massString.MassList)
                                    {
                                        if (mass.Selected)
                                        {
                                            if (mass.SimObjectType == SimObjectType.ACTIVE || mass.SimObjectType == SimObjectType.PASSIVETEMP)
                                            {
                                                mass.SimObjectType = SimObjectType.GROUPPASSIVE;
                                            }
                                            else if (mass.SimObjectType == SimObjectType.GROUPPASSIVE)
                                            {
                                                mass.SimObjectType = SimObjectType.ACTIVE;
                                            }
                                        }
                                    }
                                }
                            }
                            #endregion
                        }
                    }
                }
                #endregion

                oldKbState = kbState;
                lastLMouse = mouseState.LeftButton;
                lastRMouse = mouseState.RightButton;
                spaceDown  = false;
            }
        }
 protected override void OnMouseMove(MouseEventArgs mevent)
 {
     if (Enabled && (mevent.Button & MouseButtons.Left) == MouseButtons.Left && !ClientRectangle.Contains(mevent.Location))
     {
         //Hot
         isHotTracking = false;
         //
         ReleaseButton();
     }
     base.OnMouseMove(mevent);
 }
Beispiel #28
0
 private bool PointerIsInsideControl()
 {
     return(ClientRectangle.Contains(PointToClient(Control.MousePosition)));
 }
Beispiel #29
0
 public DockStyle HitTest(Point pt)
 {
     return(this.Visible && ClientRectangle.Contains(PointToClient(pt)) ? DockStyle : DockStyle.None);
 }
        public MonthCalanderHitTestInfo HitTest(Point p)
        {
            var info = new MonthCalanderHitTestInfo();

            if (leftRectangle.Contains(p))
            {
                info.Area = HitTestArea.LeftButton;
            }
            else if (rightRectangle.Contains(p))
            {
                info.Area = HitTestArea.RightButton;
            }
            else if (monthRectangle.Contains(p))
            {
                info.Area = HitTestArea.MonthText;
            }
            else if (yearRectangle.Contains(p))
            {
                info.Area = HitTestArea.YearText;
            }
            else if (MarkerRectangle.Contains(p))
            {
                info.Area = HitTestArea.DayMarker;
                int dayIndx = (p.X - MarkerRectangle.X) / (MarkerRectangle.Width / 7);
                info.MarkerDay = ((DayOfWeek)dayIndx);
            }
            else
            {
                int indx = GetCellIndex(p.X, p.Y);
                if (indx >= 0)
                {
                    switch (displayType)
                    {
                    case DisplayType.Dates:
                        info.Area = HitTestArea.Days;
                        info.Day  = days[indx];
                        break;

                    case DisplayType.Monthes:
                        info.Area  = HitTestArea.Month;
                        info.Month = indx + 1;
                        break;

                    case DisplayType.Years:
                        info.Area = HitTestArea.Year;
                        info.Year = 10 * (selectedDate.Year / 10) + indx;
                        break;

                    case DisplayType.YearsRange:
                        info.Area           = HitTestArea.YearsRange;
                        info.YearRangeStart = 100 * (selectedDate.Year / 100) + indx * 100;
                        info.YearRangeEnd   = info.YearRangeStart + 99;
                        break;
                    }
                }
                else
                {
                    var rect = new Rectangle(BottomLabelsPos.X, BottomLabelsPos.Y, Width - BottomLabelsPos.X, Height - BottomLabelsPos.Y);
                    if (rect.Contains(p))
                    {
                        info.Area = HitTestArea.TodayBar;
                    }
                    else if (ClientRectangle.Contains(p))
                    {
                        info.Area = HitTestArea.Client;
                    }
                }
            }
            return(info);
        }