Esempio n. 1
0
 public override void KeyPress(ViewerState state, Key key, char?character, int relativeOffset)
 {
     if (key == Key.SPACE)
     {
         OpenDocument(state);
     }
 }
Esempio n. 2
0
 private void LadderBtn_Click(object sender, EventArgs e)
 {
     mainBackPanel.Controls.Clear();
     _viewState = ViewerState.LadderState;
     for (int i = _MainSeason.ladder.Count - 1; i >= 0; i--)
     {
         Panel p = new Panel();
         p.Name      = $"";
         p.BackColor = Color.FromArgb(95, 173, 43, 200);
         Label lbl = new Label();
         lbl.Name   = "lbl" + i;
         lbl.Tag    = i.ToString();
         lbl.Click += ladderPanel_Click;
         lbl.Size   = new Size(mainBackPanel.ClientSize.Width - 40, 65);
         lbl.Text   = $"{i + 1}. {_MainSeason.ladder[i].name}\nWins: {_MainSeason.ladder[i].wins} | Lost: {_MainSeason.ladder[i].lost}\nPoints: {_MainSeason.ladder[i].points}\nPoints Difference: {_MainSeason.ladder[i].pointsfor - _MainSeason.ladder[i].pointsagainst}";
         p.Size     = new Size(mainBackPanel.ClientSize.Width - 40, 65);
         p.Controls.Add(lbl);
         mainBackPanel.Controls.Add(p);
         mainBackPanel.Controls.SetChildIndex(p, 0);  // this moves the new one to the top!
                                                      // this is just for fun:
         p.Paint += (ss, ee) => { ee.Graphics.DrawString(p.Name, Font, Brushes.White, 22, 11); };
         p.Click += matchPanel_Click;
         mainBackPanel.Invalidate();
     }
 }
Esempio n. 3
0
        public override void KeyPress(ViewerState state, Key key, char?character, int relativeOffset)
        {
            if (key == Key.ENTER)
            {
                state.Document.PromptEntered(builder.ToString());
                state.Cursor.Down();
                return;
            }
            else if (key == Key.BACKSPACE)
            {
                if (builder.Length <= 0)
                {
                    return;
                }

                builder.Remove(relativeOffset - 1, 1);
                state.Cursor.SetPosition(state.Cursor.DocumentPosition - 1);
            }

            if (!character.HasValue)
            {
                return;
            }
            state.Cursor.SetPosition(state.Cursor.DocumentPosition + 1);

            builder.Insert(relativeOffset, character.Value);
        }
Esempio n. 4
0
 public override void KeyPress(ViewerState state, Key key, char?character, int relativeOffset)
 {
     if (key == Key.SPACE || key == Key.ENTER)
     {
         state.Document.ButtonClicked(this);
     }
 }
Esempio n. 5
0
        private void LoadKeyFile(string keyFileName)
        {
            if (string.IsNullOrEmpty(keyFileName))
            {
                throw new ArgumentNullException("keyFileName");
            }
            var file = new FileInfo(keyFileName);

            if (!file.Exists)
            {
                throw new FileNotFoundException(keyFileName);
            }

            var oldViewerState = (ViewerState)_viewerState.Clone();

            try
            {
                _viewerState.Filename = keyFileName;
                _viewerState.KeyFile  = KeyFile.Load(keyFileName);
                ParseKeyFile();
            }
            catch (Exception e)
            {
                MessageBox.Show(string.Format("An error occurred while loading the file.\n\n {0}", e.Message),
                                Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error,
                                MessageBoxDefaultButton.Button1);
                _viewerState = oldViewerState;
            }
        }
Esempio n. 6
0
 public override void KeyPress(ViewerState state, Key key, char?character, int relativeOffset)
 {
     if (key == Key.SPACE || key == Key.ENTER)
     {
         Toggle(state);
     }
 }
Esempio n. 7
0
 private void LdrBoardBtn_Click(object sender, EventArgs e)
 {
     currentRound    = 0;
     RoundLabel.Text = (currentRound + 1).ToString();
     _viewState      = ViewerState.LeaderboardState;
     LoadLeaderboard(currentRound);
 }
Esempio n. 8
0
 private void hmePage_Click(object sender, EventArgs e)
 {
     _viewState      = ViewerState.MatchupsState;
     currentRound    = 0;
     RoundLabel.Text = (currentRound + 1).ToString();
     LoadRoundMatchups(currentRound);
 }
Esempio n. 9
0
 public EntryRenderContext(Document document, ViewerState state, RenderOptions renderOptions)
 {
     State              = state;
     Document           = document;
     RenderPosition     = 0;
     renderOptionsStack = new Stack <RenderOptions>();
     renderOptionsStack.Push(renderOptions);
 }
Esempio n. 10
0
        public void WriteToFrameBuffer(ViewerState state, byte[] frameBuffer, int pixelOffset)
        {
            var ctx = new SpriteRenderContext(state);

            foreach (var element in _spriteElements)
            {
                element.Render(ctx, frameBuffer, pixelOffset);
                Console.WriteLine("Rendered {0}", element);
            }
        }
Esempio n. 11
0
        private void UpdateInnerState(ViewerState state)
        {
            InnerState = state;
            UpdateAppBar();

            if (reloadLater && state == ViewerState.Single)
            {
                LoadContents();
            }
        }
    public void SendViewerState(List <ReceiverState> receiverStates)
    {
        var viewerState      = new ViewerState(UserId, receiverStates);
        var viewerStateJson  = JsonUtility.ToJson(viewerState);
        var viewerStateBytes = Encoding.ASCII.GetBytes(viewerStateJson);

        var ms = new MemoryStream();

        ms.Write(BitConverter.GetBytes(viewerStateBytes.Length), 0, 4);
        ms.Write(viewerStateBytes, 0, viewerStateBytes.Length);
        tcpSocket.Send(ms.ToArray());
    }
Esempio n. 13
0
        private void SelectNextValue(ViewerState state)
        {
            selectedIndex++;
            if (selectedIndex >= values.Count)
            {
                selectedIndex = 0;
            }

            var k = values.Keys.ToArray()[selectedIndex];

            state.Document.FieldChanged(GetArgument("PROP"), values[k]);
        }
Esempio n. 14
0
        public void MoveLeft_DoesNotMovePastTheBeginning()
        {
            var doc    = new Document("$TX,\"Hello World!\"$");
            var state  = new ViewerState(null, doc, 640, 480);
            var cursor = new Cursor(state);

            doc.Refresh();

            cursor.Left();

            Assert.AreEqual(0, cursor.DocumentPosition);
        }
Esempio n. 15
0
        public void MoveRight_WithinSameEntry()
        {
            var doc    = new Document("$TX,\"Hello World!\"$");
            var state  = new ViewerState(null, doc, 640, 480);
            var cursor = new Cursor(state);

            doc.Refresh();

            cursor.Right();

            Assert.AreEqual(1, cursor.DocumentPosition);
        }
Esempio n. 16
0
        private void Toggle(ViewerState state)
        {
            // Invoke macro call if an LM argument is provided.
            if (HasArgument("LM"))
            {
                state.Document.Macro(this);
            }

            var @checked = state.Document.GetData(Property) as bool? ?? false;

            state.Document.FieldChanged(GetArgument("PROP"), !@checked);
        }
Esempio n. 17
0
        public void MoveRight_ToNextEntry()
        {
            var doc    = new Document("$TX,\"ABC\"$$TX+CX,\"Centered\"$");
            var state  = new ViewerState(null, doc, 640, 480);
            var cursor = new Cursor(state);

            doc.Refresh();

            cursor.Right();
            cursor.Right();
            cursor.Right();

            Assert.AreEqual(36, cursor.DocumentPosition);
        }
Esempio n. 18
0
        private void Toggle(ViewerState state)
        {
            if (HasFlag("C", false))
            {
                // It is expended, collapse it.
                Flags.Remove(Flags.FirstOrDefault(f => f.Value == "C" && !f.Status));
            }
            else
            {
                Flags.Add(new Flag(false, "C"));
            }

            state.Document.Reload();
        }
Esempio n. 19
0
        public void MoveLeft_MovesWithinSameEntry()
        {
            var doc    = new Document("$TX,\"Hello World!\"$");
            var state  = new ViewerState(null, doc, 640, 480);
            var cursor = new Cursor(state);

            cursor.SetPosition(5);
            doc.Refresh();

            cursor.Left();

            Assert.AreEqual(doc.Entries.First.Value, cursor.SelectedEntry);
            Assert.AreEqual(4, cursor.DocumentPosition);
        }
Esempio n. 20
0
        public void MoveRight_DoesNotMovePastTheEnd()
        {
            var doc    = new Document("$TX,\"ABC\"$");
            var state  = new ViewerState(null, doc, 640, 480);
            var cursor = new Cursor(state);

            doc.Refresh();

            for (int i = 0; i < 10; i++)
            {
                cursor.Right();
            }

            Assert.AreEqual(2, cursor.DocumentPosition);
        }
Esempio n. 21
0
        public void MoveDown_ToNextEntry()
        {
            var doc    = new Document("$TX,\"ABC\"$\nDEF");
            var state  = new ViewerState(null, doc, 640, 480);
            var cursor = new Cursor(state);

            doc.Refresh();

            Assert.AreEqual(doc.Entries.First.Value, cursor.SelectedEntry);

            cursor.Down();

            Assert.AreEqual(state.Columns, cursor.DocumentPosition);
            Assert.AreEqual(doc.Entries.First.Next.Value, cursor.SelectedEntry);
        }
Esempio n. 22
0
        public void MoveDown_WithinSameEntry()
        {
            var doc    = new Document(new string('A', 80 * 2));
            var state  = new ViewerState(null, doc, 640, 480);
            var cursor = new Cursor(state);

            doc.Refresh();

            Assert.AreEqual(doc.Entries.First.Value, cursor.SelectedEntry);

            cursor.Down();

            Assert.AreEqual(state.Columns, cursor.DocumentPosition);
            Assert.AreEqual(doc.Entries.First.Value, cursor.SelectedEntry);
        }
Esempio n. 23
0
        public void Show(string title, int width, int height, Document document = null)
        {
            thread = new Thread(() =>
            {
                Log.Verbose("Starting OpenGLNativeWindow thread...");
                _framebuffer = new EgaColor[width * height];

                nativeWindow = new NativeWindow(new NativeWindowSettings
                {
                    Size          = new Vector2i(width, height),
                    Profile       = ContextProfile.Compatability,
                    WindowBorder  = WindowBorder.Fixed,
                    IsEventDriven = false,
                    Title         = title
                });

                unsafe
                {
                    graphicsContext = new GLFWGraphicsContext(nativeWindow.WindowPtr);
                }

                nativeWindow.CenterWindow();
                this.document = document ?? new Document();
                viewerState   = new ViewerState(this, this.document, width, height, new YaffFontProvider(), "Terminal_VGA_cp861");

                viewerState.Pages.Clear();
                document.Refresh();

                ulong ticks = 0;
                timer       = new Timer(_ => viewerState.Tick(ticks++), null, 0, 1000 / 30);

                OnLoad();
                nativeWindow.KeyDown    += NativeWindow_KeyDown;
                nativeWindow.MouseMove  += NativeWindow_MouseMove;
                nativeWindow.MouseUp    += NativeWindow_MouseUp;
                nativeWindow.MouseWheel += NativeWindow_MouseWheel;

                while (nativeWindow.Exists)
                {
                    nativeWindow.ProcessEvents();
                    // TODO: fps restrict
                    OnRenderFrame();
                    Thread.Sleep(1);
                }
            });

            thread.Start();
        }
Esempio n. 24
0
        private void OpenDocument(ViewerState state)
        {
            var file = string.IsNullOrEmpty(Aux) ? Tag : Aux;

            // Follow the link.
            if (!File.Exists(file))
            {
                return;
            }

            using (var fs = File.Open(file, FileMode.Open))
            {
                var document = DocumentLoader.Load(fs, file);
                state.LoadDocument(document, true);
            }
        }
Esempio n. 25
0
        public void MoveDown_UpdatesViewLine()
        {
            var doc    = new Document(new string('A', 80 * 60 * 2));
            var state  = new ViewerState(null, doc, 640, 480);
            var cursor = new Cursor(state);

            doc.Refresh();

            Assert.AreEqual(doc.Entries.First.Value, cursor.SelectedEntry);

            for (int i = 0; i < 62; i++)
            {
                cursor.Down();
            }

            Assert.AreEqual(3, cursor.ViewLine);
        }
Esempio n. 26
0
        public override void KeyPress(ViewerState state, Key key, char?character, int relativeOffset)
        {
            var value = state.Document.GetData(Property)?.ToString() ?? string.Empty;

            if (key == Key.BACKSPACE && value.Length > 0)
            {
                value = value.Remove(value.Length - 1, 1);
                state.Document.FieldChanged(Property, value);
                return;
            }

            if (!character.HasValue)
            {
                return;
            }

            value += character.Value;
            state.Document.FieldChanged(Property, value);
        }
Esempio n. 27
0
        public void MoveLeft_ToPreviousEntry()
        {
            /*
             * ABC--------------------------------Centered-------------------------------------
             */

            var doc    = new Document("$TX,\"ABC\"$$TX+CX,\"Centered\"$");
            var state  = new ViewerState(null, doc, 640, 480);
            var cursor = new Cursor(state);

            cursor.SetPosition(36);
            doc.Refresh();

            Assert.AreEqual(doc.Entries.First.Next.Value, cursor.SelectedEntry);

            cursor.Left();

            Assert.AreEqual(2, cursor.DocumentPosition);
            Assert.AreEqual(doc.Entries.First.Value, cursor.SelectedEntry);
        }
Esempio n. 28
0
        public override void KeyPress(ViewerState state, Key key, char?character, int relativeOffset)
        {
            if (character.HasValue)
            {
                Arguments[0].Value = Arguments[0].Value.Insert(relativeOffset, new string(character.Value, 1));
                //state.CursorPosition++;
                state.Cursor.Right();
            }

            switch (key)
            {
            case Key.ENTER:
                Arguments[0].Value = Arguments[0].Value.Insert(relativeOffset, new string('\n', 1));
                break;

            case Key.DEL:
                Arguments[0].Value = Arguments[0].Value.Remove(relativeOffset, 1);
                break;

            case Key.BACKSPACE:
                if (relativeOffset > 0)
                {
                    Arguments[0].Value = Arguments[0].Value.Remove(relativeOffset - 1, 1);
                    //state.CursorPosition--;
                    state.Cursor.Left();
                }
                else if (state.Pages[state.CursorPosition - 1].HasEntry)
                {
                    state.Document.Entries.Remove(state.Pages[state.CursorPosition - 1].Entry);
                    // TODO: update cursor minus length of entry
                    // state.CursorPosition -=
                }

                break;
            }
        }
Esempio n. 29
0
 public Cursor(ViewerState viewerState)
 {
     _viewerState = viewerState;
 }
Esempio n. 30
0
 public void ChangeState(ViewerState to)
 {
     ;
 }