private void RedrawSingleDay(SingleDateInfo sdi) { if (sdi == null) { return; } using (var g = this.pnlMain.CreateGraphics()) { var rect = sdi.RectangleF; g.Clip = new Region(rect); g.Clear(this.pnlMain.BackColor); this.DrawSingleDay(g, sdi.JewishDate, rect.Width, rect.Height, rect.X, rect.Y); } }
private void ShowSingleDayInfo(SingleDateInfo sdi) { if (sdi == null) { return; } var zmanim = new Zmanim(sdi.JewishDate, this._currentLocation); frmDailyInfoEng f; if (!this.DailyPanelIsShowing) { f = new frmDailyInfoEng((sdi.JewishDate == this._todayJewishDate ? this._todayJewishDate : sdi.JewishDate), this._currentLocation); f.TopLevel = false; f.Parent = this; f.OccasionWasChanged += delegate(object sender, JewishDate jd) { var sd = this._singleDateInfoList.FirstOrDefault(d => d.JewishDate == jd); if (sd != null) { sd.UpdateOccasions(); this.RedrawSingleDay(sd); } this.OccasionWasChanged?.Invoke(f, new EventArgs()); }; f.FormClosed += delegate { this.splitContainer1.Panel2Collapsed = true; this.llShowDaily.Visible = true; }; f.Dock = DockStyle.Fill; this.splitContainer1.Panel2.Controls.Add(f); f.Show(); this.llShowDaily.Visible = false; } else { f = this.splitContainer1.Panel2.Controls[0] as frmDailyInfoEng; f.JewishDate = (sdi.JewishDate == this._todayJewishDate ? this._todayJewishDate : sdi.JewishDate); } if (this.splitContainer1.Panel2Collapsed) { this.splitContainer1.Panel2Collapsed = false; } }
private void SelectSingleDay(SingleDateInfo sdi) { if (sdi == null) { return; } this.ClearSelectedDay(); if (this._selectedDay != sdi.JewishDate) { using (var g = this.pnlMain.CreateGraphics()) { g.Clip = new Region(sdi.RectangleF); g.FillRectangle(Program.SelectedDayBackgroundBrush, sdi.RectangleF); this._selectedDay = sdi.JewishDate; } } this.jewishDatePicker1.Value = sdi.JewishDate; if (this.DailyPanelIsShowing) { this.ShowSingleDayInfo(sdi); } }
private UserOccasion GetUserOccasionFromLocation(Point location, SingleDateInfo sdi) => sdi.UserOccasions.FirstOrDefault(t => t.Rectangle.Left <location.X && t.Rectangle.Right> location.X && t.Rectangle.Top <location.Y && t.Rectangle.Bottom> location.Y);
private SingleDateInfo DrawSingleDay(Graphics g, JewishDate currDate, float width, float height, float currX, float currY) { var zmanim = new Zmanim(currDate, this._currentLocation); var rect = new RectangleF(currX, currY, width, height); var text = currDate.Day.ToNumberHeb().Replace("'", ""); var holidays = Zmanim.GetHolidays(currDate, this._currentLocation.IsInIsrael); SingleDateInfo sdi = new SingleDateInfo(currDate, new RectangleF(rect.Location, rect.Size)); this._singleDateInfoList.Add(sdi); if (this._isFirstOpen) { //We will be repainting anyway... return(sdi); } string textZmanim = ""; if (currDate.DayOfWeek == DayOfWeek.Saturday) { bool noSedra = false; width = (this.pnlMain.Width - currX) - 1f; rect.Width = width; foreach (SpecialDay sd in holidays) { if (sd.DayType == SpecialDayTypes.Shabbos) { holidays.Remove(sd); break; } } foreach (SpecialDay sd in holidays) { if (sd.DayType.IsSpecialDayType(SpecialDayTypes.MajorYomTov) || sd.DayType.IsSpecialDayType(SpecialDayTypes.CholHamoed)) { noSedra = true; } if (sd.NameEnglish == "Shabbos Mevarchim") { var nextMonth = currDate + 12; var molad = Molad.GetMolad(nextMonth.Month, nextMonth.Year); sd.NameEnglish += "\nMolad: " + molad.ToString(zmanim.GetShkia()); break; } } if (noSedra) { textZmanim = Zmanim.GetHolidaysText(holidays, "\n", false); } else { textZmanim = string.Join(" - ", Sedra.GetSedra(currDate, this._currentLocation.IsInIsrael).Select(i => i.nameEng)) + "\n" + Zmanim.GetHolidaysText(holidays, "\n", false); } g.FillRectangle(Program.ShabbosBrush, rect); } else if (holidays.Count > 0) { var hlist = holidays.Cast <SpecialDay>(); if (hlist.Any(h => (h.DayType.IsSpecialDayType(SpecialDayTypes.HasCandleLighting)))) { textZmanim += "Candles: " + (zmanim.GetShkia() - this._currentLocation.CandleLighting).ToString() + "\n"; } if (hlist.Any(h => (h.DayType.IsSpecialDayType(SpecialDayTypes.MajorYomTov)))) { g.FillRectangle(Program.MajorYomtovBrush, rect); } else if (hlist.Any(h => (h.DayType.IsSpecialDayType(SpecialDayTypes.MinorYomtov)))) { g.FillRectangle(Program.MinorYomtovBrush, rect); } textZmanim += Zmanim.GetHolidaysText(holidays, "\n", false); } if (sdi.UserOccasions.Any(bc => bc.BackColor != Color.Empty)) { g.FillRectangle(new SolidBrush(sdi.UserOccasions.First(bc => bc.BackColor.Color != Color.Empty).BackColor), rect); } if (this._selectedDay != null && currDate == this._selectedDay) { g.FillRectangle(Program.SelectedDayBackgroundBrush, rect); } g.DrawRectangle(Program.DayCellBorderPen, rect.X, rect.Y, rect.Width, rect.Height); if (currDate == this._todayJewishDate) { var eh = rect.Height / 3.3f; var ew = rect.Width / 3.3f; g.FillClosedCurve(Program.DayHeadersBGBrush, new PointF[] { new PointF(rect.X + ew, rect.Y + eh), new PointF(rect.X + (rect.Width - ew), rect.Y + eh), new PointF(rect.X + (rect.Width - ew), rect.Y + (rect.Height - eh)), new PointF(rect.X + ew, rect.Y + (rect.Height - eh)) }, System.Drawing.Drawing2D.FillMode.Alternate, 3f); } //accumulative height of all text rectangles - keeps track of current Y position in box. float offsetTop = 0f; //Padding top - varies according to what needs to be displayed beneath it rect.Y = currY + (rect.Height / (sdi.UserOccasions.Count + holidays.Count > 1 ? 20 : 10)); //Hebrew day will be on the left, so we cut the rectangle in half. rect.Width /= 2; rect.Height = TextRenderer.MeasureText(g, text, this._dayFont, rect.Size.ToSize(), Program.TextFormatFlags).Height; offsetTop += rect.Height; TextRenderer.DrawText( g, text, this._dayFont, Rectangle.Truncate(rect), Program.DayTextColor, Program.TextFormatFlags); //Secular day will be on the right, so we move the rectangle over to the right of the box. //No need to resize the width. rect.X += rect.Width; TextRenderer.DrawText( g, currDate.GregorianDate.Day.ToString(), this._secularDayFont, Rectangle.Truncate(rect), Program.SecularDayColor, Program.TextFormatFlags); //Move rectangle back over to the left of the box rect.X = currX; //resize rectangle to fix whole box rect.Width = width; offsetTop += rect.Height / (holidays.Count > 1 ? 5 : 3); foreach (var o in sdi.UserOccasions) { //Get the text size for this occasions label. var textSize = TextRenderer.MeasureText(g, o.Name, this._userOccasionFont, rect.Size.ToSize(), Program.TextFormatFlags); //Move the Y position down to empty space. rect.Y = currY + offsetTop; rect.Height = textSize.Height; //Save the exact position of the occasion label so when the user clicks on it afterwards, we can open the occasion for editing. //Note: the occasion labels are centered in the days box, so we can't use the X position of rect (which is always 0). o.Rectangle = new RectangleF(rect.X + ((rect.Width / 2) - (textSize.Width / 2)), rect.Y, textSize.Width, textSize.Height); TextRenderer.DrawText( g, o.Name, this._userOccasionFont, Rectangle.Truncate(rect), o.Color, Program.TextFormatFlags); offsetTop += rect.Height; } if (!string.IsNullOrWhiteSpace(textZmanim)) { rect.Y = currY + offsetTop; rect.Height = height - offsetTop; TextRenderer.DrawText( g, textZmanim, this._zmanimFont, Rectangle.Truncate(rect), Program.ZmanimColor, Program.TextFormatFlags); } return(sdi); }