This repository has been archived by the owner on Sep 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TimeEditPopupControlPainter.cs
100 lines (85 loc) · 3.83 KB
/
TimeEditPopupControlPainter.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
using System;
using System.Collections.Generic;
using System.Linq;
using DevExpress.Skins;
using System.Drawing;
using DevExpress.Utils.Drawing;
namespace TimeEditControl
{
public class TimeEditPopupControlPainter
{
TimeEditPopupControlViewInfo PopupViewInfo;
Pen drawPen = new Pen(new SolidBrush(Color.Black));
public TimeEditPopupControlPainter(TimeEditPopupControlViewInfo viewInfo)
{
PopupViewInfo = viewInfo;
}
~TimeEditPopupControlPainter()
{
drawPen = null;
PopupViewInfo = null;
}
public void Draw(GraphicsCache cache)
{
DrawContent(cache);
}
private void DrawContent(GraphicsCache cache)
{
DrawLabels(cache);
DrawCells(cache);
}
protected virtual void DrawLabels(GraphicsCache cache)
{
drawPen.Color =PopupViewInfo.PopupAppearance.BackColor;
SizeF HourSize = cache.Graphics.MeasureString("Hour", PopupViewInfo.PopupAppearance.Font);
SizeF MinuteSize = cache.Graphics.MeasureString("Minute", PopupViewInfo.PopupAppearance.Font);
PointF HourPoint = CalcLabelPoint(PopupViewInfo.CellsList[1], HourSize);
PointF MinutePoint = CalcLabelPoint(PopupViewInfo.CellsList[13], MinuteSize);
cache.Graphics.DrawString("Hour", PopupViewInfo.PopupAppearance.Font, drawPen.Brush, HourPoint);
cache.Graphics.DrawString("Minute", PopupViewInfo.PopupAppearance.Font, drawPen.Brush, MinutePoint);
}
protected virtual void DrawCells(GraphicsCache cache)
{
foreach (CellViewInfo cellInfo in PopupViewInfo.CellsList)
{
drawPen.Color = PopupViewInfo.PopupAppearance.BackColor;
if (cellInfo.isSelected)
{
ObjectPainter.DrawObject(cache, SkinElementPainter.Default, GetCellElementInfo(cellInfo, cache, true));
drawPen.Color = PopupViewInfo.PopupAppearance.BackColor2;
}
if (cellInfo.isHotPointed)
{
ObjectPainter.DrawObject(cache, SkinElementPainter.Default, GetCellElementInfo(cellInfo, cache, false));
drawPen.Color = PopupViewInfo.PopupAppearance.BackColor2;
}
cache.Graphics.DrawString(cellInfo.CellText, cellInfo.cellTextFont,drawPen.Brush, SetTextPoint(cellInfo, cache.Graphics));
}
}
private PointF SetTextPoint(CellViewInfo cellInfo, Graphics g)
{
SizeF textSize = g.MeasureString(cellInfo.CellText, PopupViewInfo.PopupAppearance.Font);
float x = cellInfo.cellBounds.X + cellInfo.cellBounds.Width - 3 - textSize.Width;
float y = cellInfo.cellBounds.Y + cellInfo.cellBounds.Height - 1 - textSize.Height;
return new PointF(x, y);
}
protected virtual SkinElementInfo GetCellElementInfo(CellViewInfo cell, GraphicsCache cache, bool selected)
{
Skin skin = CommonSkins.GetSkin(PopupViewInfo.ownerControl.OwnerEdit.LookAndFeel.ActiveLookAndFeel);
SkinElementInfo skinInfo;
if (selected)
skinInfo = new SkinElementInfo(skin[CommonSkins.SkinSelection], cell.cellBounds);
else
skinInfo = new SkinElementInfo(skin[CommonSkins.SkinHighlightedItem], cell.cellBounds);
skinInfo.Cache = cache;
return skinInfo;
}
private PointF CalcLabelPoint(CellViewInfo cell, SizeF textSize)
{
const int indent = 2;
float x = cell.cellBounds.X + cell.cellBounds.Width / 2 - textSize.Width / 2;
float y = cell.cellBounds.Y - textSize.Height - indent;
return new PointF(x, y);
}
}
}