コード例 #1
0
ファイル: ctrPages.cs プロジェクト: stuart2w/SAW
        private bool m_DragVisible;                        // true if the current drag is moving the visible area.  False means it is rearranging pages
        // once the user moves far enough to trigger page rearrangement, it never reverts to adjusting the visible area

        private void ctrPages_MouseClick(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Right)
            {
                if (Globals.Root.CurrentConfig.ReadBoolean(Config.Context_Menus))
                {
                    DisplayContextMenu?.Invoke(e.Location);
                }
                return;
            }
            int pageIndex = HitTest(e.Location);

            if (pageIndex < 0 || pageIndex >= m_Document.Count)
            {
                return;
            }
            if (pageIndex != m_DisplayedIndex)
            {
                DisplayPage?.Invoke(pageIndex);
            }
            // don't also move within page (tried it and OK, but I think can be confusing)
            else if (!m_DisplayArea.IsEmpty)
            {
                // if m_rctDisplayArea is empty it implies that the entire page is displayed at once, so no point asking to scroll the display
                Rectangle pageBounds = PageBounds(pageIndex);
                Page      page       = m_Document.Page(pageIndex);
                PointF    data       = new PointF((e.X - pageBounds.Left) * page.Size.Width / pageBounds.Width,
                                                  (pageBounds.Bottom - e.Y) * page.Size.Height / pageBounds.Height); //note that the Y coordinate is inverted between the screen and page
                CentreViewOn?.Invoke(data);
            }
        }
コード例 #2
0
        public void TestDisplayContextMenu()
        {
            var m = new Mobile(0x1);

            m.DefaultMobileInit();

            var item = new ContextMenuItem(Serial.LastItem + 1);
            var menu = new ContextMenu(m, item);

            Span <byte> data = new DisplayContextMenu(menu).Compile();

            int length = 12 + menu.Entries.Length * 8;

            Span <byte> expectedData = stackalloc byte[length];

            int pos = 0;

            expectedData[pos++] = 0xBF;                     // Packet ID
            ((ushort)length).CopyTo(ref pos, expectedData); // Length
            ((ushort)0x14).CopyTo(ref pos, expectedData);   // Command
            ((ushort)0x02).CopyTo(ref pos, expectedData);   // Subcommand
            menu.Target.Serial.CopyTo(ref pos, expectedData);
            var entries = menu.Entries;

            expectedData[pos++] = (byte)entries.Length;

            for (int i = 0; i < entries.Length; i++)
            {
                var entry = entries[i];
                entry.Number.CopyTo(ref pos, expectedData);
                ((ushort)i).CopyTo(ref pos, expectedData);

                var flags = entry.Flags;

                var range = entry.Range;

                if (range == -1)
                {
                    range = 18;
                }

                if (!(entry.Enabled && menu.From.InRange(item.GetWorldLocation(), range)))
                {
                    flags |= CMEFlags.Disabled;
                }

                ((ushort)flags).CopyTo(ref pos, expectedData);
            }

            AssertThat.Equal(data, expectedData);
        }