Exemplo n.º 1
0
        private void DrawCell(Graphics g, Dictionary <FontStyle, Font> fonts,
                              bool highlighted, BrushesStorage brushes, int y, ChartIconDropDownRowCells cells, int rowsDisplayed)
        {
            DrawBack(g, highlighted, brushes, y);
            var top = y * cellHeight;
            var cy  = top + cellHeight / 2;

            var itemsLeftAbove = startItemIndex;
            var itemsLeftBelow = formattedValues.Count - rowsDisplayed - startItemIndex - 1;

            if (cells.TypeOfRow == ChartIconDropDownRowCells.RowType.ArrowUp)
            {
                DrawArrowUpDown(g, highlighted, brushes, true, cy, itemsLeftAbove);
                return;
            }
            if (cells.TypeOfRow == ChartIconDropDownRowCells.RowType.ArrowDown)
            {
                DrawArrowUpDown(g, highlighted, brushes, false, cy, itemsLeftBelow);
                return;
            }

            // вписать в ячеи текст
            var leftPos = paddingLeft;

            for (var i = 0; i < cells.cells.Length; i++)
            {
                var col = columns[i];
                DrawText(g, fonts, highlighted, brushes, y, cells.cells[i], leftPos);
                leftPos += col.ColumnWidth;
            }
        }
Exemplo n.º 2
0
        private void DrawList(Graphics g)
        {
            // подготовить массив строк displayedValuesAndButtons
            displayedValuesAndButtons = new List <ChartIconDropDownRowCells>();
            var linesCount = Height / cellHeight;
            var linesSpare = linesCount;

            if (btnUpShown)
            {
                linesSpare--;
            }
            if (btnDownShown)
            {
                linesSpare--;
            }
            rowsDisplayed = Math.Min(linesSpare, formattedValues.Count - startItemIndex);

            if (btnUpShown)
            {
                displayedValuesAndButtons.Add(new ChartIconDropDownRowCells(ChartIconDropDownRowCells.RowType.ArrowUp));
            }
            for (var i = 0; i < rowsDisplayed; i++)
            {
                displayedValuesAndButtons.Add(formattedValues[i + startItemIndex]);
            }
            if (btnDownShown)
            {
                displayedValuesAndButtons.Add(new ChartIconDropDownRowCells(ChartIconDropDownRowCells.RowType.ArrowDown));
            }

            // подготовить словарь шрифтов
            var fonts =
                displayedValuesAndButtons.Where(c => c.cells != null).SelectMany(c => c.cells.Select(cell => cell.FontStyle ?? default(FontStyle)))
                .Distinct()
                .ToDictionary(
                    s => s, s => s == default(FontStyle) ? CellFont : new Font(CellFont, s));

            // нарисовать обычные ячейки с текстом
            using (var brushes = new BrushesStorage())
            {
                // фон
                var brush = brushes.GetBrush(clCellBack);
                g.FillRectangle(brush, 0, 0, Width - 1, Height - 1);

                // ячейки
                for (var i = 0; i < displayedValuesAndButtons.Count; i++)
                {
                    DrawCell(g, fonts, i == selectedCellIndex, brushes, i, displayedValuesAndButtons[i], rowsDisplayed);
                }

                // скроллинг
                scrollPadRect = null;
                if (btnDownShown || btnUpShown)
                {
                    DrawScrollBar(g, brushes);
                }
            }
        }
Exemplo n.º 3
0
        private void DrawText(Graphics g, Dictionary <FontStyle, Font> fonts,
                              bool highlighted, BrushesStorage brushes, int y,
                              ChartIconDropDownCell cell, int left)
        {
            var top = y * cellHeight;
            var cy  = top + cellHeight / 2;

            // вывести текст
            var fontBrush = brushes.GetBrush(!highlighted
                ? cell.ColorFont ?? ClCellFont
                : ClCellFontHl);

            g.DrawString(cell.CellString, fonts[cell.FontStyle ?? default(FontStyle)], fontBrush, left, cy,
                         new StringFormat {
                LineAlignment = StringAlignment.Center
            });
        }
Exemplo n.º 4
0
        private void DrawScrollBar(Graphics g, BrushesStorage brushes)
        {
            // нарисовать фон
            var brushBack = brushes.GetBrush(clCellBack);

            using (var pen = new Pen(ClCellFont))
            {
                var rect = new Rectangle(Width - ScrollBarWidth - 1, 0, ScrollBarWidth, Height - 1);
                g.FillRectangle(brushBack, rect);
                g.DrawRectangle(pen, rect);

                // нарисовать пипочку для перетягивания
                CalcScrollPadRect();
                g.FillRectangle(brushBack, scrollPadRect.Value);
                g.DrawRectangle(pen, scrollPadRect.Value);
            }
        }
Exemplo n.º 5
0
        private void DrawArrowUpDown(Graphics g, bool highlighted, BrushesStorage brushes, bool up, int cy,
                                     int itemsLeft)
        {
            var       cx = Width / 2;
            const int aSzM = 3, sSzL = 3;
            var       points = up
                             ? new[] { new Point(cx, cy - aSzM), new Point(cx + aSzM, cy + sSzL), new Point(cx - aSzM, cy + sSzL) }
                             : new[] { new Point(cx, cy + aSzM), new Point(cx + aSzM, cy - sSzL), new Point(cx - aSzM, cy - sSzL) };
            var brush = brushes.GetBrush(!highlighted ? ClCellFont : ClCellFontHl);

            g.FillPolygon(brush, points);

            // справа подписать - сколько осталось
            g.DrawString(itemsLeft.ToString(), CellFont, brush, cx + aSzM + 3, cy, new StringFormat
            {
                LineAlignment = StringAlignment.Center
            });
        }
Exemplo n.º 6
0
        private void DrawBack(Graphics g, bool highlighted, BrushesStorage brushes, int y)
        {
            if (!highlighted)
            {
                return;
            }

            // подсветить ячейку
            var top   = y * cellHeight;
            var brush = brushes.GetBrush(clCellBackHl);
            var area  = new Rectangle(0, top, Width - 1, cellHeight - 1);

            g.FillRectangle(brush, area);

            // обвести
            using (var pen = new Pen(ClCellFontHl))
            {
                g.DrawRectangle(pen, area);
            }
        }
Exemplo n.º 7
0
        private void DrawText(Graphics g, Dictionary<FontStyle, Font> fonts,
            bool highlighted, BrushesStorage brushes, int y,
            ChartIconDropDownCell cell, int left)
        {
            var top = y * cellHeight;
            var cy = top + cellHeight / 2;

            // вывести текст
            var fontBrush = brushes.GetBrush(!highlighted
                ? cell.ColorFont ?? ClCellFont
                : ClCellFontHl);
            g.DrawString(cell.CellString, fonts[cell.FontStyle ?? default(FontStyle)], fontBrush, left, cy,
                new StringFormat { LineAlignment = StringAlignment.Center });
        }
Exemplo n.º 8
0
        private void DrawScrollBar(Graphics g, BrushesStorage brushes)
        {
            // нарисовать фон
            var brushBack = brushes.GetBrush(clCellBack);
            using (var pen = new Pen(ClCellFont))
            {
                var rect = new Rectangle(Width - ScrollBarWidth - 1, 0, ScrollBarWidth, Height - 1);
                g.FillRectangle(brushBack, rect);
                g.DrawRectangle(pen, rect);

                // нарисовать пипочку для перетягивания
                CalcScrollPadRect();
                g.FillRectangle(brushBack, scrollPadRect.Value);
                g.DrawRectangle(pen, scrollPadRect.Value);
            }
        }
Exemplo n.º 9
0
        private void DrawList(Graphics g)
        {
            // подготовить массив строк displayedValuesAndButtons
            displayedValuesAndButtons = new List<ChartIconDropDownRowCells>();
            var linesCount = Height / cellHeight;
            var linesSpare = linesCount;
            if (btnUpShown) linesSpare--;
            if (btnDownShown) linesSpare--;
            rowsDisplayed = Math.Min(linesSpare, formattedValues.Count - startItemIndex);

            if (btnUpShown)
                displayedValuesAndButtons.Add(new ChartIconDropDownRowCells(ChartIconDropDownRowCells.RowType.ArrowUp));
            for (var i = 0; i < rowsDisplayed; i++)
            {
                displayedValuesAndButtons.Add(formattedValues[i + startItemIndex]);
            }
            if (btnDownShown)
                displayedValuesAndButtons.Add(new ChartIconDropDownRowCells(ChartIconDropDownRowCells.RowType.ArrowDown));

            // подготовить словарь шрифтов
            var fonts =
                displayedValuesAndButtons.Where(c => c.cells != null).SelectMany(c => c.cells.Select(cell => cell.FontStyle ?? default(FontStyle)))
                                         .Distinct()
                                         .ToDictionary(
                                             s => s, s => s == default(FontStyle) ? CellFont : new Font(CellFont, s));
            // нарисовать обычные ячейки с текстом
            using (var brushes = new BrushesStorage())
            {
                // фон
                var brush = brushes.GetBrush(clCellBack);
                g.FillRectangle(brush, 0, 0, Width - 1, Height - 1);

                // ячейки
                for (var i = 0; i < displayedValuesAndButtons.Count; i++)
                {
                    DrawCell(g, fonts, i == selectedCellIndex, brushes, i, displayedValuesAndButtons[i], rowsDisplayed);
                }

                // скроллинг
                scrollPadRect = null;
                if (btnDownShown || btnUpShown)
                    DrawScrollBar(g, brushes);
            }
        }
Exemplo n.º 10
0
        private void DrawCell(Graphics g, Dictionary<FontStyle, Font>  fonts,
            bool highlighted, BrushesStorage brushes, int y, ChartIconDropDownRowCells cells, int rowsDisplayed)
        {
            DrawBack(g, highlighted, brushes, y);
            var top = y * cellHeight;
            var cy = top + cellHeight / 2;

            var itemsLeftAbove = startItemIndex;
            var itemsLeftBelow = formattedValues.Count - rowsDisplayed - startItemIndex - 1;

            if (cells.TypeOfRow == ChartIconDropDownRowCells.RowType.ArrowUp)
            {
                DrawArrowUpDown(g, highlighted, brushes, true, cy, itemsLeftAbove);
                return;
            }
            if (cells.TypeOfRow == ChartIconDropDownRowCells.RowType.ArrowDown)
            {
                DrawArrowUpDown(g, highlighted, brushes, false, cy, itemsLeftBelow);
                return;
            }

            // вписать в ячеи текст
            var leftPos = paddingLeft;
            for (var i = 0; i < cells.cells.Length; i++)
            {
                var col = columns[i];
                DrawText(g, fonts, highlighted, brushes, y, cells.cells[i], leftPos);
                leftPos += col.ColumnWidth;
            }
        }
Exemplo n.º 11
0
        private void DrawBack(Graphics g, bool highlighted, BrushesStorage brushes, int y)
        {
            if (!highlighted) return;

            // подсветить ячейку
            var top = y * cellHeight;
            var brush = brushes.GetBrush(clCellBackHl);
            var area = new Rectangle(0, top, Width - 1, cellHeight - 1);
            g.FillRectangle(brush, area);

            // обвести
            using (var pen = new Pen(ClCellFontHl))
            {
                g.DrawRectangle(pen, area);
            }
        }
Exemplo n.º 12
0
        private void DrawArrowUpDown(Graphics g, bool highlighted, BrushesStorage brushes, bool up, int cy,
            int itemsLeft)
        {
            var cx = Width / 2;
            const int aSzM = 3, sSzL = 3;
            var points = up
                             ? new[] { new Point(cx, cy - aSzM), new Point(cx + aSzM, cy + sSzL), new Point(cx - aSzM, cy + sSzL) }
                             : new[] { new Point(cx, cy + aSzM), new Point(cx + aSzM, cy - sSzL), new Point(cx - aSzM, cy - sSzL) };
            var brush = brushes.GetBrush(!highlighted ? ClCellFont : ClCellFontHl);
            g.FillPolygon(brush, points);

            // справа подписать - сколько осталось
            g.DrawString(itemsLeft.ToString(), CellFont, brush, cx + aSzM + 3, cy, new StringFormat
                {
                    LineAlignment = StringAlignment.Center
                });
        }