private void RemoveSelectors()
 {
     _selector.Clear();
     EditorCanvas.Invalidate();
 }
 // ========================================
 // constructor
 // ========================================
 internal DefaultContextMenuProvider(EditorCanvas owner)
 {
     _owner          = owner;
     _detailFormSize = EditorConsts.DefaultDetailFormSize;
 }
Пример #3
0
 protected MultiChemistryAdorner(EditorCanvas currentEditor, List <ChemistryBase> chemistries) : base(currentEditor)
 {
     AdornedChemistries = new List <ChemistryBase>();
     AdornedChemistries.AddRange(chemistries.Distinct());
 }
Пример #4
0
        private void OpenDifficulty()
        {
            // TODO: prompt save
            CloseBeatmap();

            var dialog = new OpenFileDialog
            {
                Title  = "Choose a difficulty file",
                Filter = "DiffTxt file (*.diff.txt)|*.diff.txt"
            };

            if (!(dialog.ShowDialog() ?? false))
            {
                return;
            }

            var bmfile = dialog.FileName;

            dialog.Title  = "Choose a music file";
            dialog.Filter = "WAV file (*.wav)|*.wav";

            if (!(dialog.ShowDialog() ?? false))
            {
                return;
            }

            var wavfile = dialog.FileName;

            try
            {
                var bm = new Beatmap(new BeatmapInfo());
                bm.Parse(File.ReadAllLines(bmfile));

                var wav = FileHelper.ReadFileToMemoryStream(wavfile);
                _musicWave = new WaveFileReader(wav);
                _musicOut  = new WasapiOut(AudioClientShareMode.Shared, 0);
                _musicOut.Init(_musicWave);

                // TODO: refactor
                CurrentGame.NoteDelay       = 1;
                CurrentGame.ButtonHandled   = new List <bool>();
                CurrentGame.ButtonStates    = new List <ButtonState>();
                CurrentGame.NotesCount      = bm.Notes.Count;
                CurrentGame.NumberOfButtons = bm.NumberOfButtons;
                for (int i = 0; i < bm.NumberOfButtons; ++i)
                {
                    CurrentGame.ButtonHandled.Add(false);
                    CurrentGame.ButtonStates.Add(ButtonState.None);
                }

                EditorStatus.Current.SelectedNote   = null;
                EditorStatus.Current.CurrentBeatmap = null;
                EditorStatus.Current.EditingMap     = bm;
                EditorStatus.Current.MusicLength    = (int)_musicWave.TotalTime.TotalMilliseconds;
                EditorStatus.Current.CurrentTime    = 0;

                EditorCanvas.RecomputePositions();

                foreach (var note in bm.Notes)
                {
                    note.GameInit();
                }

                SetCurrentBeatFromTime();
                Update();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Пример #5
0
 private void Contact_SWC_SelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     SetContactHighlight(Contact_SWC, ContactComboBox_SWC, ContactSizeSlider_SWC);
     EditorCanvas.Invalidate();
 }
Пример #6
0
 // ========================================
 // constructor
 // ========================================
 public AbbrevWordProvider(EditorCanvas owner)
 {
     _owner = owner;
 }
Пример #7
0
 // ========================================
 // constructor
 // ========================================
 public HandTool(EditorCanvas canvas)
 {
     _canvas = canvas;
 }
Пример #8
0
 public GroupSelectionAdorner(EditorCanvas currentEditor, List <Molecule> molecules)
     : base(currentEditor, molecules)
 {
 }
 public SingleAtomSelectionAdorner(EditorCanvas currentEditor, Molecule molecule)
     : this(currentEditor, new List <ChemistryBase> {
     molecule
 })
 {
 }
 public SingleAtomSelectionAdorner(EditorCanvas currentEditor, List <Molecule> mols)
     : this(currentEditor, mols.ConvertAll(m => (ChemistryBase)m))
 {
 }
Пример #11
0
 public AtomSelectionAdorner(EditorCanvas currentEditor, Atom adornedAtom) : base(currentEditor, adornedAtom)
 {
     IsHitTestVisible = true;
 }
Пример #12
0
 // Don't forget to do this! You'll leak memory otherwise!
 private void Page_Unloaded(object sender, RoutedEventArgs e)
 {
     EditorCanvas.RemoveFromVisualTree();
     EditorCanvas = null;
 }
Пример #13
0
 private void ReloadButton_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e)
 {
     Shape.Deserialize(_symbol.Data, SymbolShapes);
     EditorCanvas.Invalidate();
 }
Пример #14
0
 protected SingleChemistryAdorner(EditorCanvas currentEditor) : base(currentEditor)
 {
 }
Пример #15
0
 private void CanvasResultingImage_Loaded(object sender, RoutedEventArgs e)
 {
     canvas = new EditorCanvas(CanvasResultingImage);
     ListViewDisplayedElements.ItemsSource = canvas.DrawnPrimitives;
 }
Пример #16
0
 protected SingleChemistryAdorner(EditorCanvas currentEditor, ChemistryBase adornedChemistry) : this(currentEditor)
 {
     AdornedChemistry = adornedChemistry;
 }
Пример #17
0
 public BondSelectionAdorner(EditorCanvas currentEditor, Bond adornedBond) : base(currentEditor, adornedBond)
 {
     IsHitTestVisible = true;
 }
Пример #18
0
        public static void DoPropertyEdit(MouseButtonEventArgs e, EditorCanvas currentEditor)
        {
            EditViewModel evm = (EditViewModel)currentEditor.Chemistry;

            var position       = e.GetPosition(currentEditor);
            var screenPosition = currentEditor.PointToScreen(position);

            // Did RightClick occur on a Molecule Selection Adorner?
            var moleculeAdorner = currentEditor.GetMoleculeAdorner(position);

            if (moleculeAdorner != null)
            {
                if (moleculeAdorner.AdornedMolecules.Count == 1)
                {
                    screenPosition = GetDpiAwareScaledPosition(screenPosition, moleculeAdorner);

                    var mode = Application.Current.ShutdownMode;
                    Application.Current.ShutdownMode = ShutdownMode.OnExplicitShutdown;

                    var model = new MoleculePropertiesModel();
                    model.Centre           = screenPosition;
                    model.Path             = moleculeAdorner.AdornedMolecules[0].Path;
                    model.Used1DProperties = evm.Used1DProperties;

                    model.Data = new Model();
                    Molecule mol = moleculeAdorner.AdornedMolecules[0].Copy();
                    model.Data.AddMolecule(mol);
                    mol.Parent = model.Data;

                    model.Charge               = mol.FormalCharge;
                    model.Count                = mol.Count;
                    model.SpinMultiplicity     = mol.SpinMultiplicity;
                    model.ShowMoleculeBrackets = mol.ShowMoleculeBrackets;

                    var pe = new MoleculePropertyEditor(model);
                    ShowDialog(pe, currentEditor);

                    if (model.Save)
                    {
                        var thisMolecule = model.Data.Molecules.First().Value;
                        evm.UpdateMolecule(moleculeAdorner.AdornedMolecules[0], thisMolecule);
                    }

                    Application.Current.ShutdownMode = mode;
                }
            }
            else
            {
                // Did RightClick occur on a ChemicalVisual?
                var activeVisual = currentEditor.GetTargetedVisual(position);
                if (activeVisual != null)
                {
                    screenPosition = GetDpiAwareScaledPosition(screenPosition, activeVisual);

                    // Did RightClick occur on an AtomVisual?
                    if (activeVisual is AtomVisual av)
                    {
                        var mode = Application.Current.ShutdownMode;

                        Application.Current.ShutdownMode = ShutdownMode.OnExplicitShutdown;

                        var atom  = av.ParentAtom;
                        var model = new AtomPropertiesModel
                        {
                            Centre  = screenPosition,
                            Path    = atom.Path,
                            Element = atom.Element
                        };

                        if (atom.Element is Element)
                        {
                            model.IsFunctionalGroup = false;
                            model.IsElement         = true;

                            model.Charge     = atom.FormalCharge ?? 0;
                            model.Isotope    = atom.IsotopeNumber.ToString();
                            model.ShowSymbol = atom.ShowSymbol;
                        }

                        if (atom.Element is FunctionalGroup)
                        {
                            model.IsElement         = false;
                            model.IsFunctionalGroup = true;
                        }

                        model.MicroModel = new Model();

                        Molecule m = new Molecule();
                        model.MicroModel.AddMolecule(m);
                        m.Parent = model.MicroModel;

                        Atom a = new Atom();
                        a.Element       = atom.Element;
                        a.Position      = atom.Position;
                        a.FormalCharge  = atom.FormalCharge;
                        a.IsotopeNumber = atom.IsotopeNumber;
                        m.AddAtom(a);
                        a.Parent = m;

                        foreach (var bond in atom.Bonds)
                        {
                            Atom ac = new Atom();
                            ac.Element    = Globals.PeriodicTable.C;
                            ac.ShowSymbol = false;
                            ac.Position   = bond.OtherAtom(atom).Position;
                            m.AddAtom(ac);
                            ac.Parent = m;
                            Bond b = new Bond(a, ac);
                            b.Order = bond.Order;
                            if (bond.Stereo != Globals.BondStereo.None)
                            {
                                b.Stereo = bond.Stereo;
                                if (bond.Stereo == Globals.BondStereo.Wedge || bond.Stereo == Globals.BondStereo.Hatch)
                                {
                                    if (atom.Path.Equals(bond.StartAtom.Path))
                                    {
                                        b.StartAtomInternalId = a.InternalId;
                                        b.EndAtomInternalId   = ac.InternalId;
                                    }
                                    else
                                    {
                                        b.StartAtomInternalId = ac.InternalId;
                                        b.EndAtomInternalId   = a.InternalId;
                                    }
                                }
                            }
                            m.AddBond(b);
                            b.Parent = m;
                        }
                        model.MicroModel.ScaleToAverageBondLength(20);

                        var pe = new AtomPropertyEditor(model);
                        ShowDialog(pe, currentEditor);
                        Application.Current.ShutdownMode = mode;

                        if (model.Save)
                        {
                            evm.UpdateAtom(atom, model);

                            evm.ClearSelection();
                            evm.AddToSelection(atom);

                            if (model.AddedElement != null)
                            {
                                AddOptionIfNeeded(model);
                            }
                            evm.SelectedElement = model.Element;
                        }
                    }

                    // Did RightClick occur on a BondVisual?
                    if (activeVisual is BondVisual bv)
                    {
                        var mode = Application.Current.ShutdownMode;

                        Application.Current.ShutdownMode = ShutdownMode.OnExplicitShutdown;

                        var bond  = bv.ParentBond;
                        var model = new BondPropertiesModel
                        {
                            Centre         = screenPosition,
                            Path           = bond.Path,
                            Angle          = bond.Angle,
                            BondOrderValue = bond.OrderValue.Value,
                            IsSingle       = bond.Order.Equals(Globals.OrderSingle),
                            IsDouble       = bond.Order.Equals(Globals.OrderDouble),
                            Is1Point5      = bond.Order.Equals(Globals.OrderPartial12),
                            Is2Point5      = bond.Order.Equals(Globals.OrderPartial23)
                        };

                        model.DoubleBondChoice = DoubleBondType.Auto;

                        if (model.IsDouble | model.Is1Point5 | model.Is2Point5)
                        {
                            if (bond.ExplicitPlacement != null)
                            {
                                model.DoubleBondChoice = (DoubleBondType)bond.ExplicitPlacement.Value;
                            }
                            else
                            {
                                if (model.IsDouble)
                                {
                                    if (bond.Stereo == Globals.BondStereo.Indeterminate)
                                    {
                                        model.DoubleBondChoice = DoubleBondType.Indeterminate;
                                    }
                                }
                            }
                        }

                        if (model.IsSingle)
                        {
                            model.SingleBondChoice = SingleBondType.None;

                            switch (bond.Stereo)
                            {
                            case Globals.BondStereo.Wedge:
                                model.SingleBondChoice = SingleBondType.Wedge;
                                break;

                            case Globals.BondStereo.Hatch:
                                model.SingleBondChoice = SingleBondType.Hatch;
                                break;

                            case Globals.BondStereo.Indeterminate:
                                model.SingleBondChoice = SingleBondType.Indeterminate;
                                break;

                            default:
                                model.SingleBondChoice = SingleBondType.None;
                                break;
                            }
                        }

                        var pe = new BondPropertyEditor(model);
                        ShowDialog(pe, currentEditor);
                        Application.Current.ShutdownMode = mode;

                        if (model.Save)
                        {
                            evm.UpdateBond(bond, model);
                            evm.ClearSelection();

                            bond.Order = Globals.OrderValueToOrder(model.BondOrderValue);
                            evm.AddToSelection(bond);
                        }
                    }
                }
            }

            void AddOptionIfNeeded(AtomPropertiesModel model)
            {
                if (!evm.AtomOptions.Any(ao => ao.Element.Symbol == model.AddedElement.Symbol))
                {
                    AtomOption newOption = null;
                    switch (model.AddedElement)
                    {
                    case Element elem:
                        newOption = new AtomOption(elem);
                        break;

                    case FunctionalGroup group:
                        newOption = new AtomOption(group);
                        break;
                    }
                    evm.AtomOptions.Add(newOption);
                }
            }
        }
Пример #19
0
 public static Bitmap CreateOutline(EditorCanvas canvas)
 {
     return(CreateOutline(canvas, PreviewRatio));
 }