/// <summary> /// Sets up the event info. /// </summary> public static void EventSetup() { Events = new List <UIElement>(); Calendar calendar = Global.Calendar; Preferences preferences = calendar.Preferences; List <Date> dates = calendar.Dates; int x = DrawClass.StartX; int y = DrawClass.StartCalY; int weekRowHeight = DrawClass.WeekRowHeight; int weekColWidth = DrawClass.WeekColWidth; int cellWidth = DrawClass.CellWidth; int cellHeight = DrawClass.CellHeight; // Loops through the calendar's dates. for (int i = 0; i < dates.Count; i++) { Date date = dates[i]; //Check for and draw eventual bigtext. If not, fill cell. if (DrawBigText(i, out i)) { continue; } int index = i; Date dateCopyFrom = date; while (dateCopyFrom.CopyPrev && index >= 7) { index -= 7; dateCopyFrom = dates[index]; } // Loops through the cell's three lines. for (int j = 0; j < dateCopyFrom.Events.Count; j++) { int color = (int)preferences.LineColor[j]; TextBlock txtEvent = new TextBlock { Text = dateCopyFrom.Events[j], FontFamily = Font, FontSize = DrawClass.FontSize, FontWeight = DrawClass.FontWeight[color], Foreground = DrawClass.ColorBrush[color], }; Draw.Position(txtEvent, date.TopLeft.X + DrawClass.Padding, date.TopLeft.Y + DrawClass.FontSize * (j + 1)); if (dateCopyFrom.WrapText) { AdjustTextSize(txtEvent); } Events.Add(txtEvent); } } }
/// <summary> /// Disables the selection rect. /// </summary> public static void DisableSelectionRect() { SelectionRect.IsEnabled = false; SelectionRect.Width = 0; SelectionRect.Height = 0; Draw.Position(SelectionRect, 0, 0); }
/// <summary> /// The event that triggers when the left mouse button is pressed down once. /// </summary> public static void Select() { if (!Keyboard.Modifiers.HasFlag(ModifierKeys.Control)) { Selection.SelectedCells.Clear(); } Selection.SelectionPoint = Mouse.GetMousePosition(); Selection.SelectionRect.IsEnabled = true; Draw.Position(Selection.SelectionRect, Selection.SelectionPoint); Selection.Update(); }
/// <summary> /// Calculates all fill-related shapes. /// </summary> private static void FillSetup() { int x = DrawClass.StartX; int y = DrawClass.StartCalY; int width = DrawClass.Width; int height = DrawClass.Height; int weekRowHeight = DrawClass.WeekRowHeight; int weekColWidth = DrawClass.WeekColWidth; Background = new Rectangle { Width = DrawClass.CanvasWidth - 1, Height = DrawClass.CanvasHeight - 1, Fill = Brushes.White }; // Fill top column. Weekdays = new Rectangle { Width = width, Height = weekRowHeight, Fill = Brushes.Gray }; Draw.Position(Weekdays, x, y); // Fill left row. WeekNumbers = new Rectangle { Width = weekColWidth, Height = height, Fill = Brushes.Gray }; Draw.Position(WeekNumbers, x, y); // Finds first saturday, fills weekend cells. foreach (Date date in Global.Calendar.Dates) { if (date.Time.DayOfWeek == DayOfWeek.Saturday) { Weekend = new Rectangle { Width = DrawClass.CellWidth * 2, Height = DrawClass.CellHeight * Draw.Rows, Fill = Brushes.LightGray }; Draw.Position(Weekend, date.TopLeft); break; } } }
/// <summary> /// Sets up the Subtext. /// </summary> public static void SubtextSetup() { int x = DrawClass.StartX; int height = DrawClass.Height; Calendar calendar = Global.Calendar; string subtext = calendar.Subtext1 + "\n" + calendar.Subtext2; Subtext = new TextBlock { Text = subtext, FontFamily = Font, FontSize = DrawClass.FontSizeSubtext }; Draw.Position(Subtext, x, DrawClass.StartCalY + height); }
/// <summary> /// The event that triggers when the mouse is moved while in selection mode. /// </summary> public static void Select() { if (!Selection.SelectionRect.IsEnabled) { return; } Point p = Mouse.GetMousePosition(); double x = Selection.SelectionPoint.X; double y = Selection.SelectionPoint.Y; Selection.SelectionRect.Width = Math.Abs(p.X - x); Selection.SelectionRect.Height = Math.Abs(p.Y - y); double rectX = p.X < x ? p.X : x; double rectY = p.Y < y ? p.Y : y; Draw.Position(Selection.SelectionRect, rectX, rectY); Selection.Update(); }
/// <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); }
/// <summary> /// Calculates all outline-related shapes. /// </summary> private static void OutlineSetup() { Outline = new List <UIElement>(); Brush stroke = Brushes.Black; int outlineWidth = Draw.Multiplier; int x = DrawClass.StartX; int y = DrawClass.StartCalY; // Vertical lines. { int height = DrawClass.Height; int weekColWidth = DrawClass.WeekColWidth; int cellWidth = DrawClass.CellWidth; int weekdays = Calendar.Weekdays.Count; // Left line. Line line = new Line { Y2 = height, Stroke = stroke, StrokeThickness = outlineWidth }; Draw.Position(line, x, y); Outline.Add(line); // Remaining lines. for (int i = 0; i <= weekdays; i++) { int lineX = x + weekColWidth + cellWidth * i; line = new Line { Y2 = height, Stroke = stroke, StrokeThickness = (i == 0 || i == weekdays) ? outlineWidth : 1 }; Draw.Position(line, lineX, y); Outline.Add(line); } } // Horizontal lines. { int rows = Draw.Rows; int width = DrawClass.Width; int weekRowHeight = DrawClass.WeekRowHeight; int cellHeight = DrawClass.CellHeight; // Top line (adds a single pixel to its width). Line line = new Line { X2 = width + 1, Stroke = stroke, StrokeThickness = outlineWidth }; Draw.Position(line, x - 1, y); Outline.Add(line); // Remaining lines. for (int i = 0; i <= rows; i++) { int lineY = y + weekRowHeight + cellHeight * i; line = new Line { X2 = width, Stroke = stroke, StrokeThickness = (i == 0 || i == rows) ? outlineWidth : 1 }; Draw.Position(line, x, lineY); Outline.Add(line); } } }
/// <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); }
/// <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); } }