private void OffsetPanel_MouseMove(object sender, MouseEventArgs e)
        {
            if (dragging)
            {
                // Set offset to (mousePos - dragStart)/columnWidth/12 (round to octaves...?)
                int multiplier = (e.Location.X < dragStart.X ? -1 : 1); // Preserve sign

                if (isAdvanced)
                {
                    int oldOffset = trackSelectionManager.MidiChannelOffsets.ContainsKey(dragTarget.Id) ? trackSelectionManager.MidiChannelOffsets[dragTarget.Id] : 0;
                    trackSelectionManager.MidiChannelOffsets[dragTarget.Id] = startOffset + (int)Math.Round(((GetDistance(dragStart, e.Location) * multiplier / columnWidth)) / 12) * 12;
                    if (trackSelectionManager.MidiChannelOffsets[dragTarget.Id] != oldOffset)
                    {
                        OffsetPanel.Refresh();
                    }
                }
                else
                {
                    int oldOffset = trackSelectionManager.NoteOffset;
                    trackSelectionManager.NoteOffset = startOffset + (int)Math.Round(((GetDistance(dragStart, e.Location) * multiplier / columnWidth)) / 12) * 12;
                    if (trackSelectionManager.NoteOffset != oldOffset)
                    {
                        OffsetPanel.Refresh();
                    }
                }
            }

            //OffsetPanel.Refresh(); // See if this is laggy
            // Yeah a little
        }
Exemple #2
0
        private void CreateAndShowMainWindow()
        {
            // ********* Create the application's main Window and Border and instantiate a OffsetPanel *********
            border1 = new Border();
            border1.VerticalAlignment   = VerticalAlignment.Top;
            border1.HorizontalAlignment = HorizontalAlignment.Left;
            border1.BorderThickness     = new Thickness(2);
            border1.BorderBrush         = Brushes.DarkOrange;

            offsetPanel1                     = new OffsetPanel();
            offsetPanel1.Width               = 500;
            offsetPanel1.Height              = 500;
            offsetPanel1.VerticalAlignment   = VerticalAlignment.Stretch;
            offsetPanel1.HorizontalAlignment = HorizontalAlignment.Stretch;

            // ********* Add a child TextBlock Element *********
            txt1            = new TextBlock();
            txt1.Text       = "This is a line of Text within a TextBlock Element.";
            txt1.Background = Brushes.Red;
            OffsetPanel.SetOffsetLeft(txt1, 100);
            OffsetPanel.SetOffsetTop(txt1, 100);
            OffsetPanel.SetInflateSize(txt1, 50);
            OffsetPanel.SetShareCoordinates(txt1, true);

            // ********* Add a Button Element *********
            btn1             = new Button();
            btn1.Background  = Brushes.RoyalBlue;
            btn1.Content     = "A Button";
            btn1.BorderBrush = Brushes.Black;
            OffsetPanel.SetOffsetLeft(btn1, 100);
            OffsetPanel.SetOffsetTop(btn1, 100);
            OffsetPanel.SetInflateSize(btn1, 50);
            OffsetPanel.SetShareCoordinates(btn1, false);

            // ********* Add a child Rectangle Element *********
            rect1      = new Rectangle();
            rect1.Fill = Brushes.Purple;
            OffsetPanel.SetOffsetLeft(rect1, 100);
            OffsetPanel.SetOffsetTop(rect1, 100);
            OffsetPanel.SetInflateSize(rect1, 10);
            OffsetPanel.SetShareCoordinates(rect1, false);

            // ********* Add the text element defined above as a child of the OffsetPanel *********
            offsetPanel1.Children.Add(txt1);
            offsetPanel1.Children.Add(btn1);
            offsetPanel1.Children.Add(rect1);

            // ********* Add the OffsetPanel to the Border *********
            border1.Child = offsetPanel1;

            // ********* Add the OffsetPanel as a Child of the MainWindow and show the Window *********
            mainWindow         = new Window();
            mainWindow.Content = border1;
            mainWindow.Title   = "Custom OffsetPanel Sample";
            mainWindow.Show();
        }
 private void OffsetPanel_MouseEnter(object sender, EventArgs e) => OffsetPanel.Refresh();
 private void OffsetPanel_Resize(object sender, EventArgs e)
 {
     OffsetPanel.Refresh();
 }