Пример #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
 private FontInfo FontInfoLookUp(ushort fontInfoID) {
     if (_fontInfoTable.Contains(fontInfoID) == true) {
         return ((FontDefinition)_fontInfoTable[fontInfoID]).GetFontInfo();
     } else if (fontInfoID == DejaVuSans9.ID) {
         _fontInfoTable[fontInfoID] = new DejaVuSans9();
     } else if (fontInfoID == DejaVuSansBold9.ID) {
         _fontInfoTable[fontInfoID] = new DejaVuSansBold9();
     } else if (fontInfoID == DejaVuSansCondensed9.ID) {
         _fontInfoTable[fontInfoID] = new DejaVuSansCondensed9();
     } else if (fontInfoID == DejaVuSansMono8.ID) {
         _fontInfoTable[fontInfoID] = new DejaVuSansMono8();
     } else if (fontInfoID == DejaVuSansMonoBold8.ID) {
         _fontInfoTable[fontInfoID] = new DejaVuSansMonoBold8();
     } else if (fontInfoID == Verdana14.ID) {
         _fontInfoTable[fontInfoID] = new Verdana14();
     } else if (fontInfoID == Verdana9.ID) {
         _fontInfoTable[fontInfoID] = new Verdana9();
     } else if (fontInfoID == VerdanaBold14.ID) {
         _fontInfoTable[fontInfoID] = new VerdanaBold14();
     } else {
         throw new ArgumentOutOfRangeException("fontInfoID");
     }
     return ((FontDefinition)_fontInfoTable[fontInfoID]).GetFontInfo();
 }