示例#1
0
        private unsafe void Draw()
        {
            CUIFrame frame;

            if (CUIApp.GetFrameCount() == 0)
            {
                CUIFrameMethods.Create(out frame, CUIFrameType.Main);

                CPadding padding;
                CCommonLib.CCommonInits.InitPaddingAll(out padding, 12);
                for (int row = 0; row < ROWS; row++)
                {
                    for (int col = 0; col < COLS; col++)
                    {
                        var text = string.Format("({0},{1})", col, row);
                        var btn  = CUIViewMethods.Create(CUIViewType.Button);
                        //btn.Text = Utils.StringToUshortArray(text);
                        btn.Text     = Utils.ToCharPointer(text);
                        btn.TextSize = text.Length;
                        btn.Size     = new CSize()
                        {
                            Width = 190, Height = 50
                        };
                        btn.Size.Height           = 50;
                        btn.Style.FontColor       = 0x00;
                        btn.Style.BackColor       = 0xFF;//字体没做好颜色混合,在灰度时,会出现白色内容,所以背景使用纯白色
                        btn.Style.BorderColor     = 0xCC;
                        btn.Style.BorderThickness = 1;

                        btn.ActiveStyle.FontColor       = 0x00;
                        btn.ActiveStyle.BackColor       = 0xEE;
                        btn.ActiveStyle.BorderColor     = 0x30;
                        btn.ActiveStyle.BorderThickness = 1;
                        btn.Location = new CPoint()
                        {
                            X = padding.Left + (padding.Left + btn.Size.Width) * col,
                            Y = padding.Top + (padding.Top + btn.Size.Height) * row
                        };
                        CUIFrameMethods.AddToFrame(ref frame, btn);
                    }
                }
                CUIView button;
                CUIFrameMethods.GetChildView(frame, 0, out button);
                CUIFrameMethods.SetFocus(ref frame, button);

                CUIApp.Add(in frame);
                CUIFrameMethods.Refresh(ref frame);
            }
            else
            {
                CUIApp.GetActivedFrame(out frame);
                CUIFrameMethods.Refresh(ref frame);
            }
            RenderToPictureBox();
        }
示例#2
0
        private void Init()
        {
            if (IT8951API.Open() == 0)
            {
                MessageBox.Show("无法打开设备");
                return;
            }
            UInt32[] deviceInfoData = new UInt32[28];
            if (IT8951API.GetDeviceInfo(deviceInfoData) != deviceInfoData.Length)
            {
                MessageBox.Show("无法获取设备信息");
                return;
            }

            DeviceInfo = new DeviceInfo(deviceInfoData);
            //CUIEnvironment.WidthOfPixel = (int)DeviceInfo.Width;
            CUIEnvironment.WidthOfPixel  = (int)DeviceInfo.Width - 4;
            CUIEnvironment.HeightOfPixel = (int)DeviceInfo.Height;

            LblWidth.Text   = CUIEnvironment.WidthOfPixel.ToString();
            LblHeight.Text  = CUIEnvironment.HeightOfPixel.ToString();
            LblAddress.Text = DeviceInfo.ImageBufBase.ToString();

            var path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Test.txt");

            Contract.Ensures(File.Exists(path));
            //应该做一次文档格式转换,比如,转为Unicode编码,文档的前128个字节固定空出来;

            //todo 加载时,应该往前一段距离加载,将起点落在10-90%之间
            CDocumentInfo documentInfo = new CDocumentInfo();

            //using (Stream stream = File.Open(path, FileMode.Open, FileAccess.Read, FileShare.Read))
            //{
            //    Int32 buffSize = BUFF_SIZE;
            //    Int32 unicodeSize = BUFF_SIZE >> 1;
            //    documentInfo.FileSize = (Int32)stream.Length;
            //    documentInfo.Buffer = (ushort*)Marshal.AllocHGlobal(buffSize);
            //    documentInfo.BufferSize = unicodeSize;
            //    documentInfo.Path = path;
            //    documentInfo.StreamPositon = documentInfo.StreamPositon + buffSize;
            //    documentInfo.IsEnd = documentInfo.StreamPositon < documentInfo.FileSize;
            //}
            LoadDocument(ref documentInfo, path, 0);

            //采用8bits格式
            var image = new Bitmap(CUIEnvironment.WidthOfPixel, CUIEnvironment.HeightOfPixel, System.Drawing.Imaging.PixelFormat.Format8bppIndexed);
            //配置调色板
            ColorPalette palette = image.Palette;//这里取得的似乎是复制体

            for (int i = 0; i < 256; i++)
            {
                palette.Entries[i] = Color.FromArgb(i, i, i);
            }
            image.Palette = palette;
            //for (int i = 0; i < byte.MaxValue; i++)
            //{
            //    var c = image.Palette.Entries[i];
            //    image.Palette.Entries[i] = Color.FromArgb(i, i, i);
            //}
            //刷成白色背景
            var bitmapData = image.LockBits(new Rectangle(0, 0, image.Width, image.Height), ImageLockMode.ReadOnly, image.PixelFormat);
            var temp       = Enumerable.Repeat <byte>(byte.MaxValue, image.Width * image.Height).ToArray();

            Marshal.Copy(temp, 0, bitmapData.Scan0, temp.Length);
            image.UnlockBits(bitmapData);

            Picture.Image = image;
            CUIFrameMethods.Create(out frame, CUIFrameType.Main);

            CPadding padding;

            CCommonLib.CCommonInits.InitPaddingAll(out padding, 12);
            var view = CUIViewMethods.Create(CUIViewType.Document);
            //view.FontSize = 12;
            CFontInfo fontInfo;

            CG.GetValidFontSize(view.Style.FontSize, out fontInfo);
            view.Size = new CSize()
            {
                Width  = (int)(CUIEnvironment.WidthOfPixel - padding.Left - padding.Right),
                Height = (int)(CUIEnvironment.HeightOfPixel - padding.Top - padding.Bottom)
            };
            view.Style.FontSize        = fontInfo.FontSize;
            view.Style.FontColor       = 0x00;
            view.Style.BackColor       = 0xFF;
            view.Style.BorderColor     = 0xFF000030;
            view.Style.BorderThickness = 0;
            //view.Text = (char*)documentInfo.Buffer;
            //view.TextSize = documentInfo.BufferSize;
            view.Location = new CPoint()
            {
                X = padding.Left,
                Y = padding.Top
            };
            documentView       = (CUIDocumentView)view.Properties;
            documentView.Info  = documentInfo;
            documentView.Style = new CUIDocumentStyle()
            {
                MarginLeft   = 0,
                MarginRight  = 0,
                MarginTop    = 0,
                MarginBottom = 0,
                SectionFirstLineMarginLeft = fontInfo.Width * 2,
                //LineMarginTop = fontInfo.Height >> 1,
                LineMarginTop    = 2,
                LineMarginBottom = 0,
                RemainLines      = 1,
            };
            CUIFrameMethods.AddToFrame(ref frame, view);

            CUIApp.Add(in frame);

            Draw();
        }