/// <summary> /// 重绘前景方法 /// </summary> /// <param name="paint">绘图对象</param> /// <param name="clipRect">裁剪区域</param> public override void onPaintForeground(FCPaint paint, FCRect clipRect) { if (m_calendar != null) { int width = Width, height = Height; FCFont font = Font; String text = ""; FCCalendarMode mode = m_calendar.Mode; //日 if (mode == FCCalendarMode.Day) { CMonth month = m_calendar.Month; text = month.Year.ToString() + "年" + month.Month.ToString() + "月"; } //月 else if (mode == FCCalendarMode.Month) { text = m_calendar.MonthDiv.Year.ToString() + "年"; } //年 else if (mode == FCCalendarMode.Year) { int startYear = m_calendar.YearDiv.StartYear; text = startYear.ToString() + "年 - " + (startYear + 12).ToString() + "年"; } FCSize tSize = paint.textSize(text, font); FCRect tRect = new FCRect(); tRect.left = (width - tSize.cx) / 2; tRect.top = (height - tSize.cy) / 2; tRect.right = tRect.left + tSize.cx + 1; tRect.bottom = tRect.top + tSize.cy + 1; paint.drawText(text, getPaintingTextColor(), font, tRect); } }
/// <summary> /// 触摸点击方法 /// </summary> /// <param name="touchInfo">触摸信息</param> public virtual void onClick(FCTouchInfo touchInfo) { if (m_calendar != null) { CMonth month = m_calendar.Years.getYear(m_calendar.MonthDiv.Year).Months.get(m_month); m_calendar.Mode = FCCalendarMode.Day; m_calendar.SelectedDay = month.Days.get(1); m_calendar.update(); m_calendar.invalidate(); } }
/// <summary> /// 键盘方法 /// </summary> /// <param name="key">按键</param> public override void onKeyDown(char key) { base.onKeyDown(key); FCHost host = Native.Host; if (!host.isKeyPress(0x10) && !host.isKeyPress(0x11) && !host.isKeyPress(0x12)) { CMonth thisMonth = Month; CMonth lastMonth = getLastMonth(m_year, m_month); CMonth nextMonth = getNextMonth(m_year, m_month); int today = m_selectedDay.Day; if (key >= 37 && key <= 40) { switch ((int)key) { case 37: if (m_selectedDay == thisMonth.FirstDay) { SelectedDay = lastMonth.LastDay; } else { SelectedDay = thisMonth.Days.get(today - 1); } break; case 38: if (today <= 7) { SelectedDay = lastMonth.Days.get(lastMonth.Days.size() - (7 - today)); } else { SelectedDay = thisMonth.Days.get(m_selectedDay.Day - 7); } break; case 39: if (m_selectedDay == thisMonth.LastDay) { SelectedDay = nextMonth.FirstDay; } else { SelectedDay = thisMonth.Days.get(today + 1); } break; case 40: if (today > thisMonth.Days.size() - 7) { SelectedDay = nextMonth.Days.get(7 - (thisMonth.Days.size() - today)); } else { SelectedDay = thisMonth.Days.get(today + 7); } break; } } } }
/// <summary> /// 选中日期 /// </summary> /// <param name="selectedDay">日期</param> public void selectedDay(CDay selectedDay) { if (m_calendar != null) { CMonth m = m_calendar.Years.getYear(selectedDay.Year).Months.get(selectedDay.Month); CMonth thisMonth = m_calendar.Month; if (m != thisMonth) { if (thisMonth.Year * 12 + thisMonth.Month > m.Year * 12 + m.Month) { m_am_Direction = 1; } else { m_am_Direction = 2; } int dayButtonSize = m_dayButtons.size(); for (int i = 0; i < dayButtonSize; i++) { DayButton dayButton = m_dayButtons.get(i); if ((m_am_Direction == 1 && dayButton.Day == thisMonth.FirstDay) || m_am_Direction == 2 && dayButton.Day == thisMonth.LastDay) { m_am_ClickRowFrom = i / 7; if (i % 7 != 0) { m_am_ClickRowFrom += 1; } } } m_calendar.Month = m; onResetDiv(0); int mdayButtonSize = m_dayButtons_am.size(); for (int i = 0; i < mdayButtonSize; i++) { DayButton dayButtonAm = m_dayButtons_am.get(i); if ((m_am_Direction == 1 && dayButtonAm.Day == m.LastDay) || (m_am_Direction == 2 && dayButtonAm.Day == m.FirstDay)) { m_am_ClickRowTo = i / 7; if (i % 7 != 0) { m_am_ClickRowTo += 1; } } } if (m_calendar.UseAnimation) { m_am_Tick = m_am_TotalTick; } } else { int dayButtonSize = m_dayButtons.size(); for (int i = 0; i < dayButtonSize; i++) { DayButton dayButton = m_dayButtons.get(i); if (dayButton.Day != selectedDay) { dayButton.Selected = false; } } m_calendar.Month = m; } } }
/// <summary> /// 重置日期图层 /// </summary> /// <param name="state">状态</param> public virtual void onResetDiv(int state) { if (m_calendar != null) { int size = 0; CMonth thisMonth = m_calendar.Month; CMonth lastMonth = m_calendar.getLastMonth(thisMonth.Year, thisMonth.Month); CMonth nextMonth = m_calendar.getNextMonth(thisMonth.Year, thisMonth.Month); int left = 0; int headHeight = m_calendar.HeadDiv.Height; int top = headHeight; int width = m_calendar.Width; int height = m_calendar.Height; height -= m_calendar.TimeDiv.Height; int dayButtonHeight = height - top; if (dayButtonHeight < 1) { dayButtonHeight = 1; } int subH = 0, toY = 0; ArrayList <DayButton> dayButtons = new ArrayList <DayButton>(); if (m_am_Direction == 1) { subH = (6 - (m_am_ClickRowTo - m_am_ClickRowFrom)) * (dayButtonHeight / 6); toY = -height + subH + headHeight; toY = toY * m_am_Tick / m_am_TotalTick; if (state == 1) { thisMonth = nextMonth; lastMonth = m_calendar.getLastMonth(thisMonth.Year, thisMonth.Month); nextMonth = m_calendar.getNextMonth(thisMonth.Year, thisMonth.Month); } } else if (m_am_Direction == 2) { subH = (6 - (m_am_ClickRowFrom - m_am_ClickRowTo)) * (dayButtonHeight / 6); toY = height - subH - headHeight; toY = toY * m_am_Tick / m_am_TotalTick; if (state == 1) { thisMonth = lastMonth; lastMonth = m_calendar.getLastMonth(thisMonth.Year, thisMonth.Month); nextMonth = m_calendar.getNextMonth(thisMonth.Year, thisMonth.Month); } } if (state == 0) { dayButtons = m_dayButtons; } else if (state == 1) { dayButtons = m_dayButtons_am; } int dheight = dayButtonHeight / 6; HashMap <int, CDay> days = thisMonth.Days; CDay firstDay = days.get(1); int startDayOfWeek = (int)new DateTime(firstDay.Year, firstDay.Month, firstDay.Day).DayOfWeek; int buttonSize = dayButtons.size(); for (int i = 0; i < buttonSize; i++) { if (i == 35) { dheight = height - top; } DayButton dayButton = dayButtons.get(i); int vOffSet = 0; if (state == 1) { if (m_am_Tick > 0) { dayButton.Visible = true; if (m_am_Direction == 1) { vOffSet = toY + dayButtonHeight; } else if (m_am_Direction == 2) { vOffSet = toY - dayButtonHeight; } } else { dayButton.Visible = false; continue; } } else { vOffSet = toY; } if ((i + 1) % 7 == 0) { FCPoint dp = new FCPoint(left, top + vOffSet); FCSize ds = new FCSize(width - left, dheight); dayButton.Bounds = new FCRect(dp.x, dp.y, dp.x + ds.cx, dp.y + ds.cy); left = 0; if (i != 0 && i != size - 1) { top += dheight; } } else { FCPoint dp = new FCPoint(left, top + vOffSet); FCSize ds = new FCSize(width / 7 + ((i + 1) % 7) % 2, dheight); dayButton.Bounds = new FCRect(dp.x, dp.y, dp.x + ds.cx, dp.y + ds.cy); left += ds.cx; } CDay cDay = null; dayButton.InThisMonth = false; if (i >= startDayOfWeek && i <= startDayOfWeek + days.size() - 1) { cDay = days.get(i - startDayOfWeek + 1); dayButton.InThisMonth = true; } else if (i < startDayOfWeek) { cDay = lastMonth.Days.get(lastMonth.Days.size() - startDayOfWeek + i + 1); } else if (i > startDayOfWeek + days.size() - 1) { cDay = nextMonth.Days.get(i - startDayOfWeek - days.size() + 1); } int day = cDay.Day; dayButton.Day = cDay; if (state == 0 && dayButton.Day != null && dayButton.Day == m_calendar.SelectedDay) { dayButton.Selected = true; } else { dayButton.Selected = false; } } } }