Пример #1
0
        public static void Main()
        {
            tft.Initialize();

#if DRAWTOFILE
            StorageDevice.MountSD("SD", SPI.SPI_module.SPI1, Pins.GPIO_PIN_D10);
            var file    = new FileStream(@"SD\VirtualCanvas.bin", FileMode.Create);
            var context = new BasicTypeSerializerContext(file);
#else
            var context = new BasicTypeSerializerContext();
#endif
            var virtualCanvas       = new VirtualCanvas(context);
            var fontDejaVuSansBold9 = new DejaVuSansBold9();
            var fontDejaVuSans9     = new DejaVuSans9();
            var fontDejaVuSansMono8 = new DejaVuSansMono8();

            virtualCanvas.DrawFill(ColorBackground);

            virtualCanvas.DrawString(5, 10, BasicColor.Black, fontDejaVuSansBold9.GetFontInfo(), "DejaVu Sans 9 Bold");
            virtualCanvas.DrawString(5, 30, BasicColor.Black, fontDejaVuSans9.GetFontInfo(), "DejaVu Sans 9");
            virtualCanvas.DrawString(5, 50, BasicColor.Black, fontDejaVuSansMono8.GetFontInfo(), "DejaVu Sans Mono 8");

            // Check if the screen orientation can be changed
            if (tft.GetProperties().Orientation == true)
            {
                // Change the orientation
                virtualCanvas.SetOrientation(LCD.Orientation.Landscape);
                // Render some text in the new orientation
                virtualCanvas.DrawString(5, 10, BasicColor.Black, new DejaVuSans9().GetFontInfo(), "DejaVu Sans 9 (Rotated)");
                // Change the orientation back
                virtualCanvas.SetOrientation(LCD.Orientation.Portrait);
            }

            RenderPrimitiveShapes(virtualCanvas);
            RenderCompoundShapes(virtualCanvas, fontDejaVuSans9.GetFontInfo());
            RenderIcons(virtualCanvas);

            var localCanvas = new Canvas(tft);

#if DRAWTOFILE
            file.Flush();
            file.Close();
            localCanvas.Replay(new BasicTypeDeSerializerContext(new FileStream(@"SD\VirtualCanvas.bin", FileMode.Open)));
            StorageDevice.Unmount("SD");
#else
            //localCanvas.Replay(new BasicTypeDeSerializerContext(context.GetBuffer()));

            StorageDevice.MountSD("SD", SPI.SPI_module.SPI1, Pins.GPIO_PIN_D10);
            var file = new FileStream(@"SD\VirtualCanvas.bin", FileMode.Create);

            int    contentSize = 0;
            byte[] buffer      = context.GetBuffer(ref contentSize);

            file.Write(buffer, 0, contentSize);
            file.Flush();
            file.Close();
            StorageDevice.Unmount("SD");
#endif
        }
Пример #2
0
        public static void BasicTouchEventTest(VirtualCanvas canvas)
        {
            var message      = "Touch Event Test";
            var fontInfo     = new DejaVuSansBold9().GetFontInfo();
            var stringLength = fontInfo.GetStringWidth(message);

            canvas.SetOrientation(Orientation.Portrait);
            canvas.DrawFill(ColorBackground);
            canvas.DrawString(
                (canvas.Width - stringLength) / 2, 150,
                (ushort)BasicColor.Black, fontInfo.ID, message);

            canvas.TouchscreenWaitForEvent();

            canvas.DrawCircleFilled(lastTouchX, lastTouchY, 4, (ushort)BasicColor.Red);
            canvas.Execute();

            Thread.Sleep(1000);
        }
Пример #3
0
        public static void NonBlockingTouchEventTest(VirtualCanvas canvas)
        {
            var message      = "Touch To Continue";
            var fontInfo     = new DejaVuSansBold9().GetFontInfo();
            var stringLength = fontInfo.GetStringWidth(message);

            canvas.DrawFill(ColorBackground);
            canvas.DrawString(
                (canvas.Width - stringLength) / 2, 150,
                (ushort)BasicColor.Black, fontInfo.ID, message);

            var random = new Random(lastTouchX * lastTouchY);

            lastTouchIsValid = 0;
            while (lastTouchIsValid == 0)
            {
                canvas.DrawCircleFilled(random.Next(canvas.Width), random.Next(canvas.Height), 4, (ushort)BasicColor.Red);
                canvas.Execute();
                canvas.TouchscreenWaitForEvent(TouchScreenEventMode.NonBlocking);
            }
        }