fix: fix render bugs
This commit is contained in:
@ -36,7 +36,7 @@ namespace HFUTCourseSimulation.Dialog {
|
||||
// Initialize UI layout by semester
|
||||
// Setup grid rows and columns
|
||||
uiCoreGrid.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Auto) });
|
||||
for (int i = 0; i < WeekNames.Length; ++i) {
|
||||
for (int i = 0; i < 7; ++i) {
|
||||
uiCoreGrid.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Star) });
|
||||
}
|
||||
uiCoreGrid.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(1, GridUnitType.Auto) });
|
||||
@ -50,10 +50,10 @@ namespace HFUTCourseSimulation.Dialog {
|
||||
Grid.SetRow(headbar, 0);
|
||||
Grid.SetRowSpan(headbar, 2);
|
||||
Grid.SetColumn(headbar, 0);
|
||||
Grid.SetColumnSpan(headbar, WeekNames.Length + 1);
|
||||
Grid.SetColumnSpan(headbar, 7 + 1);
|
||||
uiCoreGrid.Children.Add(headbar);
|
||||
// Setup week text block
|
||||
for (int week = 1; week <= WeekNames.Length; ++week) {
|
||||
for (int week = 1; week <= 7; ++week) {
|
||||
var weekLabel = new TextBlock();
|
||||
weekLabel.Text = WeekNames.Names[week - 1];
|
||||
weekLabel.Foreground = new SolidColorBrush(ColorConsistency.HeadbarColor.Foreground);
|
||||
@ -101,7 +101,7 @@ namespace HFUTCourseSimulation.Dialog {
|
||||
Grid.SetRowSpan(cornerLabel, 2);
|
||||
uiCoreGrid.Children.Add(cornerLabel);
|
||||
// Add chessboard
|
||||
for (int week = 1; week <= WeekNames.Length; ++week) {
|
||||
for (int week = 1; week <= 7; ++week) {
|
||||
for (int index = 1; index <= CurrentSemester.indexCount; ++index) {
|
||||
if ((week + index) % 2 != 0) continue;
|
||||
|
||||
|
@ -52,19 +52,20 @@ namespace HFUTCourseSimulation.Kernel {
|
||||
_verticalCount = weekCount / _horizontalCount;
|
||||
if (weekCount % _horizontalCount != 0) _verticalCount++;
|
||||
|
||||
_weekWidth = SIDEBAR_WIDTH + 7 * CELL_WIDTH + 2 * MARGIN;
|
||||
_weekHeight = TITLE_HEIGHT + HEADBAR_HEIGHT + indexCount * CELL_HEIGHT + 2 * MARGIN;
|
||||
_weekWidth = SIDEBAR_WIDTH + 7 * CELL_WIDTH;
|
||||
_weekHeight = TITLE_HEIGHT + HEADBAR_HEIGHT + indexCount * CELL_HEIGHT;
|
||||
|
||||
_weekWidthWithMargin = _weekWidth + 2 * MARGIN;
|
||||
_weekHeightWithMargin = _weekHeight + 2 * MARGIN;
|
||||
|
||||
_width = _weekWidth * _horizontalCount;
|
||||
_height = _weekHeight * _verticalCount;
|
||||
}
|
||||
|
||||
int _horizontalCount;
|
||||
int _verticalCount;
|
||||
int _weekWidth;
|
||||
int _weekHeight;
|
||||
int _width;
|
||||
int _height;
|
||||
int _horizontalCount, _verticalCount;
|
||||
int _weekWidth, _weekHeight;
|
||||
int _weekWidthWithMargin, _weekHeightWithMargin;
|
||||
int _width, _height;
|
||||
|
||||
/// <summary>
|
||||
/// 图片宽度
|
||||
@ -82,12 +83,13 @@ namespace HFUTCourseSimulation.Kernel {
|
||||
week -= 1;
|
||||
|
||||
var row = week / _horizontalCount;
|
||||
var column = week % _verticalCount;
|
||||
return new Point(column * _weekWidth + MARGIN, row * _weekHeight + MARGIN);
|
||||
var column = week % _horizontalCount;
|
||||
return new Point(column * _weekWidthWithMargin + MARGIN, row * _weekHeightWithMargin + MARGIN);
|
||||
}
|
||||
|
||||
public Point GetTitleTextPos(int week) {
|
||||
return GetWeekPos(week);
|
||||
public Rectangle GetTitleTextRect(int week) {
|
||||
var pos = GetWeekPos(week);
|
||||
return new Rectangle(pos, new Size(_weekWidth, TITLE_HEIGHT));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -99,32 +101,29 @@ namespace HFUTCourseSimulation.Kernel {
|
||||
return pos;
|
||||
}
|
||||
|
||||
public Rectangle GetHeadbarTextRect(int week, int day) {
|
||||
day -= 1;
|
||||
|
||||
var pos = GetTablePos(week);
|
||||
pos.Offset(SIDEBAR_WIDTH + day * CELL_WIDTH, 0);
|
||||
return new Rectangle(pos, new Size(CELL_WIDTH, HEADBAR_HEIGHT));
|
||||
}
|
||||
|
||||
public Rectangle GetHeadbarBoxRect(int week) {
|
||||
var pos = GetTablePos(week);
|
||||
return new Rectangle(pos, new Size(7 * CELL_WIDTH, HEADBAR_HEIGHT));
|
||||
}
|
||||
|
||||
public Point GetHeadbarTextPos(int week, int day) {
|
||||
day -= 1;
|
||||
|
||||
var pos = GetTablePos(week);
|
||||
pos.Offset(day * CELL_WIDTH, 0);
|
||||
return pos;
|
||||
public Rectangle GetSidebarTextRect(int week, int index) {
|
||||
return GetSidebarBoxRect(week, index);
|
||||
}
|
||||
|
||||
public Rectangle GetSidebarBoxRect(int week, int index) {
|
||||
index -= 1;
|
||||
|
||||
var pos = GetTablePos(week);
|
||||
return new Rectangle(pos, new Size(0, index * CELL_HEIGHT));
|
||||
}
|
||||
|
||||
public Point GetSidebarTextPos(int week, int index) {
|
||||
index -= 1;
|
||||
|
||||
var pos = GetTablePos(week);
|
||||
pos.Offset(0, index * CELL_HEIGHT);
|
||||
return pos;
|
||||
pos.Offset(0, HEADBAR_HEIGHT + index * CELL_HEIGHT);
|
||||
return new Rectangle(pos, new Size(SIDEBAR_WIDTH, CELL_HEIGHT));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -148,13 +147,13 @@ namespace HFUTCourseSimulation.Kernel {
|
||||
return pos;
|
||||
}
|
||||
|
||||
public Point GetCellTextPos(int week, int day, int index) {
|
||||
return GetCellPos(week, day, index);
|
||||
public Rectangle GetCellTextRect(int week, int day, int index, int span = 1) {
|
||||
return GetCellBoxRect(week, day, index, span);
|
||||
}
|
||||
|
||||
public Rectangle GetCellBoxRect(int week, int day, int index, int index_span = 1) {
|
||||
public Rectangle GetCellBoxRect(int week, int day, int index, int span = 1) {
|
||||
var pos = GetCellPos(week, day, index);
|
||||
return new Rectangle(pos, new Size(CELL_WIDTH, index_span * CELL_HEIGHT));
|
||||
return new Rectangle(pos, new Size(CELL_WIDTH, span * CELL_HEIGHT));
|
||||
}
|
||||
|
||||
}
|
||||
@ -216,7 +215,7 @@ namespace HFUTCourseSimulation.Kernel {
|
||||
|
||||
// 创建绘画资源
|
||||
var brushes = new RenderBrushes();
|
||||
var font = new Font("Source Hans Sans CN", 12);
|
||||
var font = new Font("Sarasa Mono SC", 12);
|
||||
|
||||
// 填充背景为白色
|
||||
g.Clear(Color.White);
|
||||
@ -226,26 +225,26 @@ namespace HFUTCourseSimulation.Kernel {
|
||||
var week_instance = semester.weeks[week - 1];
|
||||
|
||||
// 教学周文本
|
||||
g.DrawString($"教学周:{week}", font, brushes.GetBrush(Color.Black), geometry.GetTitleTextPos(week));
|
||||
g.DrawString($"教学周:{week}", font, brushes.GetBrush(Color.Black), geometry.GetTitleTextRect(week));
|
||||
|
||||
// 绘制Headbar底层
|
||||
g.FillRectangle(brushes.GetBrush(ColorConsistency.HeadbarColor.Background), geometry.GetHeadbarBoxRect(week));
|
||||
// 绘制Header文本
|
||||
for (int day = 1; day <= WeekNames.Length; ++day) {
|
||||
for (int day = 1; day <= 7; ++day) {
|
||||
var day_instance = week_instance.days[day - 1];
|
||||
g.DrawString($@"{WeekNames.Names[day - 1]}
|
||||
{day_instance.date}", font, brushes.GetBrush(ColorConsistency.HeadbarColor.Foreground), geometry.GetHeadbarTextPos(week, day));
|
||||
{day_instance.date}", font, brushes.GetBrush(ColorConsistency.HeadbarColor.Foreground), geometry.GetHeadbarTextRect(week, day));
|
||||
}
|
||||
|
||||
// 绘制Sidebar底层和文本
|
||||
for (int index = 1; index <= semester.indexCount; ++index) {
|
||||
var colorPair = ColorConsistency.GetSidebarColor(semester.GetIndexKind(index));
|
||||
g.FillRectangle(brushes.GetBrush(colorPair.Background), geometry.GetSidebarBoxRect(week, index));
|
||||
g.DrawString(index.ToString(), font, brushes.GetBrush(colorPair.Foreground), geometry.GetSidebarTextPos(week, index));
|
||||
g.DrawString(index.ToString(), font, brushes.GetBrush(colorPair.Foreground), geometry.GetSidebarTextRect(week, index));
|
||||
}
|
||||
|
||||
// 绘制Chessboard
|
||||
for (int day = 1; day <= WeekNames.Length; ++day) {
|
||||
for (int day = 1; day <= 7; ++day) {
|
||||
for (int index = 1; index <= semester.indexCount; ++index) {
|
||||
if ((day + index) % 2 == 0) continue;
|
||||
g.FillRectangle(brushes.GetBrush(ColorConsistency.ChessboardColor), geometry.GetCellBoxRect(week, day, index));
|
||||
@ -253,12 +252,12 @@ namespace HFUTCourseSimulation.Kernel {
|
||||
}
|
||||
|
||||
// 绘制课程
|
||||
for (int day = 1; day <= WeekNames.Length; ++day) {
|
||||
for (int day = 1; day <= 7; ++day) {
|
||||
var day_instance = week_instance.days[day - 1];
|
||||
foreach (var lesson_instance in day_instance.lessons) {
|
||||
g.FillRectangle(brushes.GetBrush(lesson_instance.color.Background), geometry.GetCellBoxRect(week, day, lesson_instance.startIndex, lesson_instance.indexSpan));
|
||||
g.DrawString($@"{lesson_instance.name}
|
||||
{lesson_instance.description}", font, brushes.GetBrush(lesson_instance.color.Foreground), geometry.GetCellTextPos(week, day, lesson_instance.startIndex));
|
||||
{lesson_instance.description}", font, brushes.GetBrush(lesson_instance.color.Foreground), geometry.GetCellTextRect(week, day, lesson_instance.startIndex, lesson_instance.indexSpan));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -17,7 +17,6 @@ namespace HFUTCourseSimulation.Util {
|
||||
"星期日"
|
||||
};
|
||||
|
||||
public static int Length => Names.Length;
|
||||
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user