private void SendStringToScreen(String text, CharDisplayInfo cdi)
        {
            invoke(() =>
            {
                Image myImage = new Image();

                DrawingVisual dv  = new DrawingVisual();
                DrawingContext dc = dv.RenderOpen();

                double x = _cursorX;
                double y = _cursorY;

                if (lastDrawn != Rect.Empty && inInputMode == false)
                {
                    x = lastDrawn.X + lastDrawn.Width;
                }


                FontInfo fi = _regularFont;
                if (cdi.Font == 4)
                {
                    fi = _fixedFont;
                }

                FormattedText ft = buildFormattedText(text, fi, cdi, dc);

                Brush b = Brushes.Transparent;

                if (cdi.ImplementsStyle(ZStyles.REVERSE_STYLE))
                {
                    b = ZColorCheck.ZColorToBrush(cdi.ForegroundColor, ColorType.Foreground);
                }
                else
                {
                    if (_currentInfo.BackgroundColor != bColor)
                    {
                        b = ZColorCheck.ZColorToBrush(cdi.BackgroundColor, ColorType.Background);
                    }
                }
                dc.DrawRectangle(b, null, new Rect(0, 0, ft.WidthIncludingTrailingWhitespace, charHeight));

                dc.DrawText(ft, new Point(0, 0));
                dc.Close();

                RenderTargetBitmap bmp = new RenderTargetBitmap((int)dv.ContentBounds.Width, (int)charHeight, 96, 96, PixelFormats.Pbgra32);
                bmp.Render(dv);

                myImage.Source = bmp;

                mainCanvas.Children.Add(myImage);
                myImage.SetValue(Canvas.TopProperty, y);
                myImage.SetValue(Canvas.LeftProperty, x);

                lastDrawn = new Rect(x, y, (int)dv.ContentBounds.Width, charHeight);

                removeCoveredImages(myImage);
            });
        }
Exemplo n.º 2
0
        internal void Flush()
        {
            if (_currentText.Length == 0)
            {
                return;
            }
            String text = _currentText.ToString();

            _currentText.Clear();
            int chars = _x.tcw();

            // TODO This is an invalid state, but it still seems to get here... I need to figure out why
            //if (_flushMode == TextFlushMode.Absolute && _x == 1 && Width == 0)
            //{
            //    ySystem.Diagnostics.Debug.WriteLine("How did I get here?");
            //}

            // If _x is 1 and Width == 0, We don't need to be here...
            if (_flushMode == TextFlushMode.Absolute)
            {
                _flushMode = TextFlushMode.Normal;
//                Inlines.Clear();
                if (Inlines.Count == 0)
                {
                    // Add an empty inline to allow for the absolute positioning
                    AddInline("", _defaultInfo);
                }

                if (Inlines.Count == 1 && FirstInline.DisplayInfo.AreSame(_currentInfo) &&
                    (FirstInline.DisplayInfo.Font == ZFont.FIXED_WIDTH_FONT ||
                     FirstInline.DisplayInfo.ImplementsStyle(ZStyles.FIXED_WIDTH_STYLE)))
                {
                    FirstInline.Text = ReplaceText(chars, FirstInline.Text, text);
                    return;
                }
                else
                {
                    if (Width == 0)
                    {
                        if (IsFixedWidth(_currentInfo))
                        {
                            setAbsolute(text, _x, _currentInfo);

                            return;
                        }
                        else
                        {
#if !USEADORNER
                            if (_x > 1)
                            {
                                System.Diagnostics.Debug.WriteLine("Inserting a blank");
                                ZBlankContainer zbc = new ZBlankContainer(_x);
                                Inlines.Add(zbc);
                            }

                            AddInline(text, _currentInfo);
                            return;
#else
                            setAbsolute(text, _x, _currentInfo);
                            return;
#endif
                        }
                    }
                    else
                    {
                        // TODO If the top == 1, it must be the status bar overwriting text... Make this work better
                        if (IsOnlyFixedFont() && IsFixedWidth(_currentInfo) || Top == 1)
                        {
                            // TODO Need to make some calculations here
                            String temp = CurrentText;
                            Inlines.Clear();

                            AddInline(ReplaceText(chars, temp, text), _fixedInfo);

                            return;
                        }
                        else
                        {
                            if (text.Trim() != "" || _currentInfo.ImplementsStyle(ZStyles.REVERSE_STYLE))
                            {
                                setAbsolute(text, _x, _currentInfo);

                                return;
                            }
                            else
                            {
                                // System.Diagnostics.Debug.WriteLine("Do something about Absolute");

                                // Figure f = new Figure();
                                return;
                            }
                        }
                    }
                }
            }
            else if (_flushMode == TextFlushMode.Overwrite)
            {
                _flushMode = TextFlushMode.Normal;
                throw new Exception("In Overwrite mode");
            }

            if (LastInline != null && LastInline.DisplayInfo.AreSame(_currentInfo))
            {
                LastInline.Text += text;
            }
            else
            {
                AddInline(text, _currentInfo);
            }
        }
Exemplo n.º 3
0
 private bool IsFixedWidth(CharDisplayInfo Info)
 {
     return(Info.Font == ZFont.FIXED_WIDTH_FONT || Info.ImplementsStyle(ZStyles.FIXED_WIDTH_STYLE));
 }