Exemplo n.º 1
0
        /// <summary>
        /// Sets up the base info (weekday, weeknr, dates).
        /// </summary>
        private static void BaseSetup()
        {
            Weekdays    = new List <UIElement>();
            WeekNumbers = new List <UIElement>();
            Dates       = new List <UIElement>();

            Calendar calendar = Global.Calendar;

            int x       = DrawClass.StartX;
            int y       = DrawClass.StartCalY;
            int padding = DrawClass.Padding;

            Brush black = Brushes.Black;
            Brush gray  = Brushes.Gray;
            Brush white = Brushes.White;

            //Draw weekdays
            for (int i = 0; i < Calendar.Weekdays.Count; i++)
            {
                Point pos = new Point(x + DrawClass.WeekColWidth + DrawClass.CellWidth * i + padding, y);

                TextBlock weekday = new TextBlock
                {
                    Text       = Calendar.Weekdays[i],
                    FontFamily = Font,
                    FontSize   = DrawClass.FontSize,
                    FontWeight = FontWeights.Bold,
                    Foreground = Brushes.White
                };
                Draw.Position(weekday, pos);

                Weekdays.Add(weekday);
            }

            //Draw week nr.
            for (int i = 0; i < Draw.Rows; i++)
            {
                DateTime date = calendar.Dates.First().Time.AddDays(Calendar.Weekdays.Count * i);
                Point    pos  = new Point(x + padding, y + DrawClass.WeekRowHeight + DrawClass.CellHeight * i);

                TextBlock weekNr = new TextBlock
                {
                    Text       = Calendar.GetIso8601WeekOfYear(date).ToString(),
                    FontFamily = Font,
                    FontSize   = DrawClass.FontSize,
                    Foreground = Brushes.White,
                };
                Draw.Position(weekNr, pos);

                WeekNumbers.Add(weekNr);
            }

            //Draw dates
            foreach (Date date in calendar.Dates)
            {
                Brush brush = (date.Time.Month == calendar.Month ? black : gray);
                Point pos   = new Point(date.TopLeft.X + padding, date.TopLeft.Y);

                TextBlock txtDate = new TextBlock
                {
                    Text       = date.Time.Day.ToString("D"),
                    FontFamily = Font,
                    FontSize   = DrawClass.FontSize,
                    Foreground = brush
                };
                Draw.Position(txtDate, pos);

                Dates.Add(txtDate);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Draws the BigText for this and all folowing cells on the same row.
        /// </summary>
        /// <param name="index">The index of the cell to draw BigText for.</param>
        /// <param name="newIndex">The index of the last cell drawn BigText on (if no BigText, returns index).</param>
        private static bool DrawBigText(int index, out int newIndex)
        {
            Calendar calendar = Global.Calendar;
            Date     date     = calendar.Dates[index];

            newIndex = index;

            string bigTextStr = date.Events.First();

            // Return if there's no BigText.
            if (!date.BigText || bigTextStr == "")
            {
                return(false);
            }

            int weekColWidth  = DrawClass.WeekColWidth;
            int weekRowHeight = DrawClass.WeekRowHeight;
            int cellWidth     = DrawClass.CellWidth;
            int cellHeight    = DrawClass.CellHeight;

            // Merge all BigText cells with the same text.
            if (newIndex != calendar.Dates.Count - 1)
            {
                while (bigTextStr == calendar.Dates[newIndex + 1].Events.First() && calendar.Dates[newIndex + 1].BigText)
                {
                    if (newIndex % Calendar.Weekdays.Count == Calendar.Weekdays.Count - 1)
                    {
                        break;
                    }

                    newIndex++;

                    if (newIndex == calendar.Dates.Count - 1)
                    {
                        break;
                    }
                }
            }

            // Calculate the number of times to draw BigText.
            double bigTextWidth      = DrawClass.MeasureString(bigTextStr, SpecialFont, DrawClass.FontSizeTitle).Width;
            int    bigTextWidthTotal = (newIndex - index + 1) * cellWidth;

            int bigTextCnt = 1;

            while (bigTextWidth * (bigTextCnt + 1) < bigTextWidthTotal)
            {
                bigTextCnt++;
            }

            for (int i = 1; i <= bigTextCnt; i++)
            {
                double spacing = (bigTextWidthTotal - (bigTextWidth * bigTextCnt)) / (bigTextCnt + 1);

                int x = (int)(date.TopLeft.X + spacing * i + bigTextWidth * (i - 1));
                int y = (int)(date.TopLeft.Y);

                TextBlock bigText = new TextBlock
                {
                    Text          = bigTextStr,
                    FontFamily    = SpecialFont,
                    FontSize      = DrawClass.FontSizeTitle,
                    TextAlignment = TextAlignment.Center,
                };
                Draw.Position(bigText, x, y);

                Events.Add(bigText);
            }

            return(true);
        }
Exemplo n.º 3
0
 /// <summary>
 /// Draws the selection rectangle.
 /// </summary>
 public static void _Draw() => Draw.Add(SelectionRect);