Пример #1
0
        /// <summary>
        /// Draw current buffer to puncher graphic
        /// </summary>
        /// <param name="g"></param>
        public void DrawTapeHorizontal(Graphics g, int width, int height)
        {
            g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
            Brush tapeBrush = new SolidBrush(Color.FromArgb(0xFF, 0xFF, 0xA0));
            Brush holeBrush = new SolidBrush(Color.FromArgb(0x40, 0x40, 0x40));
            Color backColor = Color.FromArgb(240, 240, 240);
            Brush backBrush = new SolidBrush(backColor);

            g.Clear(backColor);
            int th = (int)(HOLE_DIST * 6 + BORDER * 2 - 2);
            int y0 = height - th - 20;

            g.FillRectangle(tapeBrush, 0, y0, width, th);

            //int pos = DisplayPos - 1;
            int pos;

            //if (EditOn)
            if (true)
            {
                pos = DisplayPos - VisiblePunchLines / 2 - 2 + 1;
            }
            else
            {
                pos = DisplayPos - VisiblePunchLines + 1;
            }

            // draw from left to right
            for (int line = 0; line < VisiblePunchLines; line++)
            {
                if (pos < 0 || pos > _buffer.Count - 1)
                {
                    pos++;
                    continue;
                }
                int       xp        = (int)(line * HOLE_DIST + HOLE_DIST - 2);
                int       bit       = 16;
                PunchLine punchLine = _buffer[pos++];
                for (int col = 0; col < 6; col++)
                {
                    if (col == 2)
                    {
                        int d = (HOLE_SIZE - TRANSPORT_HOLE_SIZE) / 2;
                        g.FillEllipse(holeBrush, xp + d, y0 + BORDER + HOLE_DIST * col + d, TRANSPORT_HOLE_SIZE, TRANSPORT_HOLE_SIZE);
                        continue;
                    }

                    if ((punchLine.Code & bit) != 0)
                    {
                        g.FillEllipse(holeBrush, xp, y0 + BORDER + HOLE_DIST * col, HOLE_SIZE, HOLE_SIZE);
                    }
                    bit >>= 1;
                }

                // draw char, skip left most line
                //if (line < VisiblePunchLines-1)
                {
                    Font   font = new Font("Arial", 8);
                    string text = punchLine.Text;
                    for (int i = 0; i < text.Length; i++)
                    {
                        Point p = new Point(xp - 2, y0 - 5 - 10 * (text.Length - i));
                        g.DrawString(text.Substring(i, 1), font, Brushes.Black, p);
                    }
                }
            }

            // draw tip on the left side
            int len = 20;

            PointF[] pol = new PointF[4];
            pol[0] = new PointF(0, y0);
            pol[1] = new PointF(len, y0);
            pol[2] = new PointF(0, y0 + th / 7 * 3);
            pol[3] = new PointF(0, y0);
            g.FillPolygon(backBrush, pol);
            pol[0] = new PointF(0, y0 + th);
            pol[1] = new PointF(len, y0 + th);
            pol[2] = new PointF(0, y0 + th / 7 * 3);
            pol[3] = new PointF(0, y0 + th);
            g.FillPolygon(backBrush, pol);

            // draw position marker
            int mx;

            if (true)
            //if (EditOn)
            {
                mx = (VisiblePunchLines / 2 + 2) * HOLE_DIST + 1;
            }
            else
            {
                mx = VisiblePunchLines * HOLE_DIST + 1;
            }
            Brush posBrush = new SolidBrush(Color.Red);
            int   my       = y0 + BORDER + HOLE_DIST * 6 + 5;

            g.FillPolygon(posBrush, PosPolygon(mx, my));
        }
Пример #2
0
        private void InternPunchCode(byte baudotCode, ShiftStates shiftState)
        {
            string text = CodeManager.BaudotCodeToPuncherText(baudotCode, shiftState, _config.CodeSet);

            switch (text)
            {
            case "CR":
                text = LngText(LngKeys.TapePunch_CodeCarriageReturn);
                break;

            case "NL":
                text = LngText(LngKeys.TapePunch_CodeLinefeed);
                break;

            case "LTR":
                text = LngText(LngKeys.TapePunch_CodeLetters);
                break;

            case "FIG":
                text = LngText(LngKeys.TapePunch_CodeFigures);
                break;
            }

            PunchLine newLine = new PunchLine(baudotCode, text);

            if (!EditOn)
            {
                _buffer.Add(newLine);
                DisplayPos = _buffer.Count;
            }
            else
            {
                if (EditInsert)
                {
                    if (DisplayPos >= _buffer.Count)
                    {
                        _buffer.Add(newLine);
                    }
                    else
                    {
                        _buffer.Insert(DisplayPos, newLine);
                    }
                    DisplayPos++;
                }
                else
                {
                    if (DisplayPos >= _buffer.Count)
                    {
                        _buffer.Add(newLine);
                    }
                    else
                    {
                        _buffer[DisplayPos] = newLine;
                    }
                    DisplayPos++;
                }
                if (DisplayPos > _buffer.Count)
                {
                    DisplayPos = _buffer.Count;
                }
            }

            InvokeChanged();
        }