Exemplo n.º 1
0
        /// <summary>
        /// Adjusts the text size of the event to get make sure it doesn't overflow downward.
        /// </summary>
        private static void AdjustTextSize(TextBlock txtEvent)
        {
            if (txtEvent.Text == "")
            {
                return;
            }

            txtEvent.TextWrapping = TextWrapping.Wrap;
            txtEvent.Width        = DrawClass.CellWidth;

            // We add some margin, due to the linebreaks being sub-optimal (break at spacings, not max line length).
            const double margin = .25;

            // Check if the text has to be reduced in size.
            double width = DrawClass.MeasureString(txtEvent.Text, txtEvent.FontFamily, DrawClass.FontSize).Width;

            if (width > DrawClass.CellWidth)
            {
                int lines = (int)Math.Ceiling(width / DrawClass.CellWidth);

                // Calculate a divider for reducing the text in size, while attempting to keep the maximum number of lines.
                double divider = Math.Ceiling(1 + (lines * DrawClass.FontSize) / (double)DrawClass.CellHeight + margin);
                txtEvent.FontSize /= divider;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Sets up the title, business info.
        /// </summary>
        public static void HeaderSetup()
        {
            Calendar calendar = Global.Calendar;

            int x     = DrawClass.StartX;
            int y     = DrawClass.StartY;
            int width = DrawClass.Width;

            string title      = calendar.MonthName + " " + Text.BusinessTitleSuffix;
            double titleWidth = DrawClass.MeasureString(title, SpecialFont, DrawClass.FontSizeTitle).Width;

            Title = new TextBlock
            {
                Text       = title,
                FontFamily = SpecialFont,
                FontSize   = DrawClass.FontSizeTitle
            };
            Draw.Position(Title, (width - titleWidth) / 2 + x, y);

            // Draw business info.
            string businessInfo =
                Text.BusinessInfo1 + "\n" +
                Text.BusinessInfo2 + "\n" +
                Text.BusinessInfo3 + "\n" +
                Text.BusinessInfo4;

            double businessInfoWidth = DrawClass.MeasureString(businessInfo, Font, DrawClass.FontSizeInfo).Width;

            BusinessInfo = new TextBlock
            {
                Text          = businessInfo,
                FontFamily    = Font,
                FontSize      = DrawClass.FontSizeInfo,
                TextAlignment = TextAlignment.Right
            };
            Draw.Position(BusinessInfo, DrawClass.BusinessInfoX - businessInfoWidth, y);
        }
Exemplo n.º 3
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.º 4
0
 /// <summary>
 /// Calculates the number of rows for the calendar.
 /// <para>Sets the height of the calendar from the result.</para>
 /// </summary>
 private static void CalculateRows()
 {
     Rows       = Global.Calendar.Dates.Count / Calendar.Weekdays.Count;
     CellHeight = (DrawClass.CanvasHeight - DrawClass.StartCalY - DrawClass.BotPadding - DrawClass.WeekRowHeight) / Rows;
     DrawClass.SetHeight((CellHeight * Rows + DrawClass.WeekRowHeight));
 }