private static bool ShouldNavigate(
            Key key,
            MathBox mathBox,
            out Direction logicalDirection)
        {
            logicalDirection = Direction.Right;

            if (key == Key.Up)
            {
                logicalDirection = Direction.Up;
                return(true);
            }

            if (key == Key.Down)
            {
                logicalDirection = Direction.Down;
                return(true);
            }

            if (key == Key.Right && mathBox.CaretPosition.IsAtDocumentEnd())
            {
                logicalDirection = Direction.Right;
                return(true);
            }

            if (key == Key.Left && mathBox.CaretPosition.IsAtDocumentStart())
            {
                logicalDirection = Direction.Left;
                return(true);
            }

            return(false);
        }
Esempio n. 2
0
        private static bool TryGetNotationAndDirection(
            MathBox mathBox, Key key, out LogicalDirection direction,
            out NotationBase notation
            )
        {
            direction = LogicalDirection.Forward;

            InlineUIContainer forwardElement  = mathBox.ForwardUiElement;
            InlineUIContainer backwardElement = mathBox.BackwardUiElement;

            InlineUIContainer inlineUiContainer = null;

            if (key == Key.Right && forwardElement != null)
            {
                inlineUiContainer = forwardElement;
                direction         = LogicalDirection.Forward;
            }
            else if (key == Key.Left && backwardElement != null)
            {
                inlineUiContainer = backwardElement;
                direction         = LogicalDirection.Backward;
            }

            if (!(inlineUiContainer?.Child is NotationBase control))
            {
                notation = null;
                return(false);
            }

            notation = control;
            return(true);
        }
Esempio n. 3
0
 private static void DetachEvents(MathBox mathBox)
 {
     mathBox.Loaded      -= HandleLoaded;
     mathBox.TextChanged -= HandleTextChanged;
     mathBox.SizeChanged -= HandleSizeChanged;
     DetachResized(mathBox, HandleResized);
 }
Esempio n. 4
0
    public Slot(Player player, float width, float height)
    {
        this.player = player;

        _width = width;
        _height = height;

        nameCell = new Cell();

        AddChild(handleBox = new HandleBox(this));
        AddChild(nameBox = new NameBox(this));
        AddChild(scoreBox = new ScoreBox(this));
        AddChild(minusBox = new MathBox(this, MathType.Minus));
        AddChild(plusBox = new MathBox(this, MathType.Plus));

        minusBox.SignalTick += HandleMinusTick;
        plusBox.SignalTick += HandlePlusTick;
        scoreBox.SignalRelease += HandleScoreTap;
        nameBox.SignalRelease += HandleNameTap;

        ListenForUpdate(HandleUpdate);
        DoLayout();

        _resetTweenable = new RXTweenable(0.0f, HandleResetTweenableChange);
        buildInTweenable = new RXTweenable(0.0f, HandleBuildInChange);

        HandleBuildInChange();
    }
Esempio n. 5
0
    public Slot(Player player, float width, float height)
    {
        this.player = player;

        _width  = width;
        _height = height;

        nameCell = new Cell();

        AddChild(handleBox = new HandleBox(this));
        AddChild(nameBox   = new NameBox(this));
        AddChild(scoreBox  = new ScoreBox(this));
        AddChild(minusBox  = new MathBox(this, MathType.Minus));
        AddChild(plusBox   = new MathBox(this, MathType.Plus));

        minusBox.SignalTick    += HandleMinusTick;
        plusBox.SignalTick     += HandlePlusTick;
        scoreBox.SignalRelease += HandleScoreTap;
        nameBox.SignalRelease  += HandleNameTap;

        ListenForUpdate(HandleUpdate);
        DoLayout();

        _resetTweenable  = new RXTweenable(0.0f, HandleResetTweenableChange);
        buildInTweenable = new RXTweenable(0.0f, HandleBuildInChange);

        HandleBuildInChange();
    }
Esempio n. 6
0
 public static bool AreEqual(MathBox x, MathBox y, StringBuilder report)
 {
     if (AreNull(x, y))
     {
         return(true);
     }
     return(AreEqual(x.Document, y.Document, report));
 }
Esempio n. 7
0
        private IIndexBuilder BuildInto(MathBox mathBox, Action <IDocumentBuilder> build)
        {
            var documentBuilder = new Document();

            build(documentBuilder);
            mathBox.Document = documentBuilder.Build();
            return(this);
        }
Esempio n. 8
0
 private static void Deserialize(MathDocument mathDocument, MathBox mathBox)
 {
     if (mathDocument?.IsEmpty() ?? true)
     {
         return;
     }
     Deserialize(mathDocument, mathBox.Document);
 }
Esempio n. 9
0
 public static void connectToAutocomplete(MathBox mBox)
 {
     Editor                   = mBox;
     Editor.apopup            = AutocompleteMenu;
     Editor.PreviewKeyDown   += new KeyEventHandler(PreviewKeyDownHandler);
     Editor.PreviewKeyUp     += new KeyEventHandler(PreviewKeyUpHandler);
     Editor.KeyUp            += new KeyEventHandler(KeyUpHandler);
     Editor.SelectionChanged += new RoutedEventHandler(selectionChangedHandler);
 }
Esempio n. 10
0
 private void reloadPreview(object sender)
 {
     try
     {
         LMD_Document lmdDoc = new LMD_Document(MathBox.getDocument(mbox.Document));
         pwindow.loadHTMLToPreview(lmdDoc.toHTML(LMD_Document.RenderingMode.LOCAL));
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "Error!", MessageBoxButton.OK, MessageBoxImage.Error);
     }
 }
Esempio n. 11
0
        public static String uploadProcedure(FlowDocument toBeUploaded)
        {
            try
            {
                String ptext = MathBox.getDocumentUni(toBeUploaded);

                String htmlBody = new LMD_Document(ptext).getHTMLBody();

                return(NetworkManager.uploadData(ptext, htmlBody));
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error!", MessageBoxButton.OK, MessageBoxImage.Error);
                return("");
            }
        }
Esempio n. 12
0
        public static void Resize(this MathBox mathBox)
        {
            if (mathBox.Visibility != Visibility.Visible)
            {
                return;
            }

            mathBox.Width = ManyMuch;
            mathBox.Arrange(new Rect(0, 0, ManyMuch, ManyMuch));

            Rect lastRect = mathBox.Document.ContentEnd.GetCharacterRect(LogicalDirection.Forward);

            if (lastRect == Rect.Empty)
            {
                return;
            }
            mathBox.Width = lastRect.Right + mathBox.Document.PagePadding.Left + mathBox.Document.PagePadding.Right;
        }
Esempio n. 13
0
        /// <returns>Whether the current action should continue</returns>
        public static String saveAsProcedure(FlowDocument document)
        {
            try
            {
                SaveFileDialog sfd = new SaveFileDialog();
                sfd.FileName   = "Document";
                sfd.DefaultExt = ".txt";
                sfd.Filter     = "TXT (editable)|*.txt|HTML (read-only)|*.html";

                Nullable <bool> result = sfd.ShowDialog();
                if (result != true)
                {
                    return("");
                }

                DataStream ds = null;
                int        br = sfd.FilterIndex;

                String documentString = MathBox.getDocumentUni(document);

                if (br == 1)
                {
                    ds             = new DataStream(documentString, DataStream.Type.TXT);
                    lastRegistered = cloneFlowDocument(document);
                    fullPath       = sfd.FileName;
                    name           = sfd.SafeFileName;
                }
                else
                {
                    documentString = new LMD_Document(documentString).toHTML(LMD_Document.RenderingMode.WEB);
                    ds             = new DataStream(documentString, DataStream.Type.HTML);
                }

                FileManager.WriteDataToFile(ds, sfd.FileName);

                return(name);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error!", MessageBoxButton.OK, MessageBoxImage.Error);
                return("");
            }
        }
Esempio n. 14
0
 private void InitiatePreview()
 {
     if (PreviewIsOpen)
     {
         reloadPreview(null);
         return;
     }
     try
     {
         pwindow = new PreviewWindow();
         pwindow.ReloadRequested += new ReloadRequestedHandler(reloadPreview);
         pwindow.Closed          += new EventHandler(optimizator);
         LMD_Document lmdDoc = new LMD_Document(MathBox.getDocument(mbox.Document));
         pwindow.loadHTMLToPreview(lmdDoc.toHTML(LMD_Document.RenderingMode.LOCAL));
         pwindow.Show();
         PreviewIsOpen = true;
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "Error!", MessageBoxButton.OK, MessageBoxImage.Error);
     }
 }
Esempio n. 15
0
 public static String saveProcedure(FlowDocument current)
 {
     if (fullPath == "")
     {
         return(saveAsProcedure(current));
     }
     else
     {
         try
         {
             String     documentString = MathBox.getDocumentUni(current);
             DataStream ds             = new DataStream(documentString, DataStream.Type.TXT);
             FileManager.WriteDataToFile(ds, fullPath);
             lastRegistered = cloneFlowDocument(current);
             return(name);
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message, "Error!", MessageBoxButton.OK, MessageBoxImage.Error);
             return("");
         }
     }
 }
Esempio n. 16
0
        private static void FocusSibling(MathBox mathBox, Direction direction)
        {
            NotationBase parent = mathBox.FindParent <NotationBase>();

            parent?.FocusDirection(direction);
        }
Esempio n. 17
0
 private static void PrepareMathBox(MathBox mathBox)
 {
     mathBox.Document.PagePadding          = new Thickness(0);
     mathBox.Document.PageWidth            = ManyMuch;
     mathBox.HorizontalScrollBarVisibility = ScrollBarVisibility.Disabled;
 }
Esempio n. 18
0
 private static void DetachResized(MathBox mathBox, RoutedEventHandler handler)
 {
     mathBox.RemoveHandler(ResizedEvent, handler);
 }
Esempio n. 19
0
 private static void AttachResized(MathBox mathBox, RoutedEventHandler handler)
 {
     mathBox.AddHandler(ResizedEvent, handler);
 }
Esempio n. 20
0
 public RootNotation()
 {
     InitializeComponent();
     AvailableBoxes = AllBoxes = new MathBox[] { boxRootBase, boxUnderRoot };
 }
Esempio n. 21
0
    public ResetGroup(float width)
    {
        this.width = width;

        AddChild(plusBox  = new MathBox(MathType.Plus));
        AddChild(minusBox = new MathBox(MathType.Minus));

        AddChild(zeroBox = new ZeroBox());

        AddChild(cancelBox = new SpriteBox(Player.NullPlayer, "Icons/Cancel", 100, 100));
        AddChild(okBox     = new SpriteBox(Player.NullPlayer, "Icons/Checkmark", 100, 100));

        plusBox.hasFastRepeatZones  = true;
        minusBox.hasFastRepeatZones = true;

        if (PlayerPrefs.HasKey(PREFS_KEY))
        {
            zeroBox.resetAmount = PlayerPrefs.GetInt(PREFS_KEY);
        }

        float boxSize = Config.SLOT_HEIGHT;
        float padding = Config.PADDING_S;

        plusBox.SetSize(boxSize, boxSize);
        minusBox.SetSize(boxSize, boxSize);
        zeroBox.SetSize(width - boxSize * 2 - padding * 2, boxSize);

        plusBox.SetPosition(zeroBox.width / 2 + padding + plusBox.width / 2, padding / 2 + plusBox.height / 2);
        minusBox.SetPosition(-zeroBox.width / 2 - padding - minusBox.width / 2, padding / 2 + minusBox.height / 2);
        zeroBox.SetPosition(0, padding / 2 + zeroBox.height / 2);

        cancelBox.SetSize((width - padding) / 2, boxSize);
        okBox.SetSize((width - padding) / 2, boxSize);

        cancelBox.SetPosition(-padding / 2 - cancelBox.width / 2, -padding / 2 - cancelBox.height / 2);
        okBox.SetPosition(padding / 2 + okBox.width / 2, -padding / 2 - okBox.height / 2);

        minusBox.SignalTick += (b, ticks) =>
        {
            zeroBox.resetAmount -= ticks;
            UpdateResetAmount();
        };

        plusBox.SignalTick += (b, ticks) =>
        {
            zeroBox.resetAmount += ticks;
            UpdateResetAmount();
        };

        zeroBox.SignalRelease += (b) =>
        {
            zeroBox.DoTapEffect();
            FSoundManager.PlaySound("UI/ResetToZero");
            zeroBox.resetAmount = 0;
            UpdateResetAmount();
        };

        cancelBox.SignalRelease += (b) =>
        {
            Keeper.instance.slotList.ApplyResetScores(false);
            cancelBox.isTouchable = false;
            cancelBox.DoTapEffect();
            Keeper.instance.EndResetMode();
            FSoundManager.PlaySound("UI/Cancel");
        };

        okBox.SignalRelease += (b) =>
        {
            Keeper.instance.slotList.ApplyResetScores(true);
            okBox.isTouchable = false;
            okBox.DoTapEffect();
            Keeper.instance.EndResetMode();
            FSoundManager.PlaySound("UI/ResetOk");

            SKDataManager.MarkDirty();
        };

        UpdateResetAmount();

        instance = this;
    }
Esempio n. 22
0
 private static void Serialize(MathBox mathBox, MathDocument document)
 {
     Serialize(mathBox.Document, document);
 }
Esempio n. 23
0
    public ResetGroup(float width)
    {
        this.width = width;

        AddChild(plusBox = new MathBox(MathType.Plus));
        AddChild(minusBox = new MathBox(MathType.Minus));

        AddChild(zeroBox = new ZeroBox());

        AddChild(cancelBox = new SpriteBox(Player.NullPlayer,"Icons/Cancel",100,100));
        AddChild(okBox = new SpriteBox(Player.NullPlayer,"Icons/Checkmark",100,100));

        plusBox.hasFastRepeatZones = true;
        minusBox.hasFastRepeatZones = true;

        if(PlayerPrefs.HasKey(PREFS_KEY))
        {
            zeroBox.resetAmount = PlayerPrefs.GetInt(PREFS_KEY);
        }

        float boxSize = Config.SLOT_HEIGHT;
        float padding = Config.PADDING_S;

        plusBox.SetSize(boxSize,boxSize);
        minusBox.SetSize(boxSize,boxSize);
        zeroBox.SetSize(width-boxSize*2-padding*2,boxSize);

        plusBox.SetPosition(zeroBox.width/2 + padding + plusBox.width/2, padding/2 + plusBox.height/2);
        minusBox.SetPosition(-zeroBox.width/2 - padding - minusBox.width/2, padding/2 + minusBox.height/2);
        zeroBox.SetPosition(0,padding/2 + zeroBox.height/2);

        cancelBox.SetSize((width-padding)/2,boxSize);
        okBox.SetSize((width-padding)/2,boxSize);

        cancelBox.SetPosition(-padding/2 - cancelBox.width/2, -padding/2 - cancelBox.height/2);
        okBox.SetPosition(padding/2 + okBox.width/2, -padding/2 - okBox.height/2);

        minusBox.SignalTick += (b,ticks) =>
        {
            zeroBox.resetAmount -= ticks;
            UpdateResetAmount();
        };

        plusBox.SignalTick += (b,ticks) =>
        {
            zeroBox.resetAmount += ticks;
            UpdateResetAmount();
        };

        zeroBox.SignalRelease += (b) =>
        {
            zeroBox.DoTapEffect();
            FSoundManager.PlaySound("UI/ResetToZero");
            zeroBox.resetAmount = 0;
            UpdateResetAmount();
        };

        cancelBox.SignalRelease += (b) =>
        {
            Keeper.instance.slotList.ApplyResetScores(false);
            cancelBox.isTouchable = false;
            cancelBox.DoTapEffect();
            Keeper.instance.EndResetMode();
            FSoundManager.PlaySound("UI/Cancel");
        };

        okBox.SignalRelease += (b) =>
        {
            Keeper.instance.slotList.ApplyResetScores(true);
            okBox.isTouchable = false;
            okBox.DoTapEffect();
            Keeper.instance.EndResetMode();
            FSoundManager.PlaySound("UI/ResetOk");

            SKDataManager.MarkDirty();
        };

        UpdateResetAmount();

        instance = this;
    }