Skip to content

Commit

Permalink
新增:支持编辑皮肤中每个项目的文本颜色。
Browse files Browse the repository at this point in the history
  • Loading branch information
zhongyang219 committed Apr 18, 2018
1 parent 65a17fa commit ec686a7
Show file tree
Hide file tree
Showing 17 changed files with 333 additions and 28 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -286,3 +286,4 @@ __pycache__/
*.btm.cs
*.odx.cs
*.xsd.cs
*.diagsession
69 changes: 66 additions & 3 deletions TrafficMonitorSkinEditor/ColorStatic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
//

#include "stdafx.h"
#include "TrafficMonitorSkinEditor.h"
#include "ColorStatic.h"


Expand All @@ -21,10 +20,27 @@ CColorStatic::~CColorStatic()

void CColorStatic::SetFillColor(COLORREF fill_color)
{
m_fill_color = fill_color;
m_colors.resize(1);
m_colors[0] = fill_color;
m_color_num = 1;
//m_fill_color = fill_color;
Invalidate();
}

void CColorStatic::SetColorNum(int color_num)
{
if (color_num <= 0 || color_num > 10)
color_num = 1;
m_colors.resize(color_num);
m_color_num = color_num;
}

void CColorStatic::SetFillColor(int index, COLORREF fill_color)
{
if (index >= 0 && index < m_color_num)
m_colors[index] = fill_color;
}

void CColorStatic::SetLinkCursor(bool link_cursor)
{
m_link_cursor = link_cursor;
Expand Down Expand Up @@ -54,7 +70,54 @@ void CColorStatic::OnPaint()
// 不为绘图消息调用 CStatic::OnPaint()
CRect rect;
GetClientRect(rect);
dc.FillSolidRect(rect, m_fill_color);
rect.MoveToXY(0, 0);
CRect rc_tmp{ rect };
switch (m_color_num)
{
case 1:
dc.FillSolidRect(rect, m_colors[0]);
break;
case 4:
dc.FillSolidRect(rect, RGB(255,255,255));
rc_tmp.right /= 2;
rc_tmp.bottom /= 2;
dc.FillSolidRect(rc_tmp, m_colors[0]);
rc_tmp.MoveToX(rc_tmp.right);
dc.FillSolidRect(rc_tmp, m_colors[1]);
rc_tmp.MoveToXY(0, rc_tmp.bottom);
dc.FillSolidRect(rc_tmp, m_colors[2]);
rc_tmp.MoveToX(rc_tmp.right);
dc.FillSolidRect(rc_tmp, m_colors[3]);
break;
case 8:
dc.FillSolidRect(rect, RGB(255, 255, 255));
rc_tmp.right /= 4;
rc_tmp.bottom /= 2;
dc.FillSolidRect(rc_tmp, m_colors[0]);
rc_tmp.MoveToX(rc_tmp.right);
dc.FillSolidRect(rc_tmp, m_colors[1]);
rc_tmp.MoveToX(rc_tmp.right);
dc.FillSolidRect(rc_tmp, m_colors[4]);
rc_tmp.MoveToX(rc_tmp.right);
dc.FillSolidRect(rc_tmp, m_colors[5]);
rc_tmp.MoveToXY(0, rc_tmp.bottom);
dc.FillSolidRect(rc_tmp, m_colors[2]);
rc_tmp.MoveToX(rc_tmp.right);
dc.FillSolidRect(rc_tmp, m_colors[3]);
rc_tmp.MoveToX(rc_tmp.right);
dc.FillSolidRect(rc_tmp, m_colors[6]);
rc_tmp.MoveToX(rc_tmp.right);
dc.FillSolidRect(rc_tmp, m_colors[7]);
break;
default:
dc.FillSolidRect(rect, RGB(255, 255, 255));
rc_tmp.right = rect.Width() / m_color_num;
for (int i{}; i < m_color_num; i++)
{
rc_tmp.MoveToX(i*(rect.Width() / m_color_num));
dc.FillSolidRect(rc_tmp, m_colors[i]);
}
}
}


Expand Down
13 changes: 8 additions & 5 deletions TrafficMonitorSkinEditor/ColorStatic.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#pragma once


// CColorStatic
//派生自CStatic,用于显示颜色的Static控件
#pragma once
#define WM_STATIC_CLICKED (WM_USER + 1001)

class CColorStatic : public CStatic
Expand All @@ -12,11 +11,15 @@ class CColorStatic : public CStatic
CColorStatic();
virtual ~CColorStatic();

void SetFillColor(COLORREF fill_color); //设置要填充的背景色
void SetFillColor(COLORREF fill_color); //设置要填充单一的背景色
void SetColorNum(int color_num); //设置颜色的数量
void SetFillColor(int index, COLORREF fill_color);
void SetLinkCursor(bool link_cursor = true); //设置指向控件时光标变成超链接形状

protected:
COLORREF m_fill_color{ RGB(255, 255,255) };
//COLORREF m_fill_color{ RGB(255, 255,255) };
vector<COLORREF> m_colors;
int m_color_num;
bool m_hover{ false }; //当鼠标指向控件时为true
bool m_link_cursor{ false }; //是否启用超链接形状的光标

Expand Down
27 changes: 19 additions & 8 deletions TrafficMonitorSkinEditor/DrawScrollView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,17 @@ void CDrawScrollView::OnDraw(CDC* pDC)
cpu_str.Format(_T("%s50%%"), (m_skin_data->no_text ? _T("") : m_skin_data->cpu_string.c_str()));
memory_str.Format(_T("%s51%%"), (m_skin_data->no_text ? _T("") : m_skin_data->memory_string.c_str()));

int text_colors[MAIN_WND_COLOR_NUM];
if (m_skin_data->specify_each_item_color)
{
for (int i{}; i < MAIN_WND_COLOR_NUM; i++)
text_colors[i] = m_skin_data->text_colors[i];
}
else
{
for (int i{}; i < MAIN_WND_COLOR_NUM; i++)
text_colors[i] = m_skin_data->text_colors[0];
}
CPoint point;
//绘制小预览图文本
//绘制“上传”文本
Expand All @@ -79,7 +90,7 @@ void CDrawScrollView::OnDraw(CDC* pDC)
point.Offset(m_skin_data->preview_x_s, m_skin_data->preview_y_s);
CRect rect(point, CSize(m_skin_data->up_width_s, m_skin_data->text_height));
theApp.DPI(rect);
draw.DrawWindowText(rect, up_str, m_skin_data->text_color, m_skin_data->up_align_s);
draw.DrawWindowText(rect, up_str, text_colors[0], m_skin_data->up_align_s);
if (*m_show_item_outline)
draw.DrawRectOutLine(rect, m_outline_color, true);
}
Expand All @@ -90,7 +101,7 @@ void CDrawScrollView::OnDraw(CDC* pDC)
point.Offset(m_skin_data->preview_x_s, m_skin_data->preview_y_s);
CRect rect(point, CSize(m_skin_data->down_width_s, m_skin_data->text_height));
theApp.DPI(rect);
draw.DrawWindowText(rect, down_str, m_skin_data->text_color, m_skin_data->down_align_s);
draw.DrawWindowText(rect, down_str, text_colors[1], m_skin_data->down_align_s);
if (*m_show_item_outline)
draw.DrawRectOutLine(rect, m_outline_color, true);
}
Expand All @@ -101,7 +112,7 @@ void CDrawScrollView::OnDraw(CDC* pDC)
point.Offset(m_skin_data->preview_x_s, m_skin_data->preview_y_s);
CRect rect(point, CSize(m_skin_data->cpu_width_s, m_skin_data->text_height));
theApp.DPI(rect);
draw.DrawWindowText(rect, cpu_str, m_skin_data->text_color, m_skin_data->cpu_align_s);
draw.DrawWindowText(rect, cpu_str, text_colors[2], m_skin_data->cpu_align_s);
if (*m_show_item_outline)
draw.DrawRectOutLine(rect, m_outline_color, true);
}
Expand All @@ -112,7 +123,7 @@ void CDrawScrollView::OnDraw(CDC* pDC)
point.Offset(m_skin_data->preview_x_s, m_skin_data->preview_y_s);
CRect rect(point, CSize(m_skin_data->memory_width_s, m_skin_data->text_height));
theApp.DPI(rect);
draw.DrawWindowText(rect, memory_str, m_skin_data->text_color, m_skin_data->memory_align_s);
draw.DrawWindowText(rect, memory_str, text_colors[3], m_skin_data->memory_align_s);
if (*m_show_item_outline)
draw.DrawRectOutLine(rect, m_outline_color, true);
}
Expand All @@ -125,7 +136,7 @@ void CDrawScrollView::OnDraw(CDC* pDC)
point.Offset(m_skin_data->preview_x_l, m_skin_data->preview_y_l);
CRect rect(point, CSize(m_skin_data->up_width_l, m_skin_data->text_height));
theApp.DPI(rect);
draw.DrawWindowText(rect, up_str, m_skin_data->text_color, m_skin_data->up_align_l);
draw.DrawWindowText(rect, up_str, text_colors[0], m_skin_data->up_align_l);
if (*m_show_item_outline)
draw.DrawRectOutLine(rect, m_outline_color, true);
}
Expand All @@ -136,7 +147,7 @@ void CDrawScrollView::OnDraw(CDC* pDC)
point.Offset(m_skin_data->preview_x_l, m_skin_data->preview_y_l);
CRect rect(point, CSize(m_skin_data->down_width_l, m_skin_data->text_height));
theApp.DPI(rect);
draw.DrawWindowText(rect, down_str, m_skin_data->text_color, m_skin_data->down_align_l);
draw.DrawWindowText(rect, down_str, text_colors[1], m_skin_data->down_align_l);
if (*m_show_item_outline)
draw.DrawRectOutLine(rect, m_outline_color, true);
}
Expand All @@ -147,7 +158,7 @@ void CDrawScrollView::OnDraw(CDC* pDC)
point.Offset(m_skin_data->preview_x_l, m_skin_data->preview_y_l);
CRect rect(point, CSize(m_skin_data->cpu_width_l, m_skin_data->text_height));
theApp.DPI(rect);
draw.DrawWindowText(rect, cpu_str, m_skin_data->text_color, m_skin_data->cpu_align_l);
draw.DrawWindowText(rect, cpu_str, text_colors[2], m_skin_data->cpu_align_l);
if (*m_show_item_outline)
draw.DrawRectOutLine(rect, m_outline_color, true);
}
Expand All @@ -158,7 +169,7 @@ void CDrawScrollView::OnDraw(CDC* pDC)
point.Offset(m_skin_data->preview_x_l, m_skin_data->preview_y_l);
CRect rect(point, CSize(m_skin_data->memory_width_l, m_skin_data->text_height));
theApp.DPI(rect);
draw.DrawWindowText(rect, memory_str, m_skin_data->text_color, m_skin_data->memory_align_l);
draw.DrawWindowText(rect, memory_str, text_colors[3], m_skin_data->memory_align_l);
if (*m_show_item_outline)
draw.DrawRectOutLine(rect, m_outline_color, true);
}
Expand Down
39 changes: 39 additions & 0 deletions TrafficMonitorSkinEditor/IniHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,42 @@ bool CIniHelper::GetBool(const wchar_t * AppName, const wchar_t * KeyName, bool
{
return (GetPrivateProfileIntW(AppName, KeyName, default_value, m_path.c_str()) != 0);
}

bool CIniHelper::WriteIntArray(const wchar_t * AppName, const wchar_t * KeyName, const int * values, int size)
{
CString str, tmp;
for (int i{}; i < size; i++)
{
tmp.Format(_T("%d,"), values[i]);
str += tmp;
}
return (::WritePrivateProfileStringW(AppName, KeyName, str, m_path.c_str()) != FALSE);
}

bool CIniHelper::GetIntArray(const wchar_t * AppName, const wchar_t * KeyName, int * values, int size, int default_value)
{
wchar_t buff[256];
bool result;
CString default_str;
default_str.Format(_T("%d"), default_value);
result = ::GetPrivateProfileStringW(AppName, KeyName, default_str, buff, 256, m_path.c_str());
wstring str{ buff };
size_t index{}, index0{};
for (int i{}; i < size; i++)
{
index0 = index;
if (index0 < 256 && str[index0] == L',')
index0++;
index = str.find(L',', index + 1);
if (index0 == index)
{
values[i] = default_value;
}
else
{
wstring tmp = str.substr(index0, index - index0);
values[i] = _wtoi(tmp.c_str());
}
}
return result;
}
2 changes: 2 additions & 0 deletions TrafficMonitorSkinEditor/IniHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ class CIniHelper
int GetInt(const wchar_t * AppName, const wchar_t * KeyName, int default_value);
bool WriteBool(const wchar_t * AppName, const wchar_t * KeyName, bool value);
bool GetBool(const wchar_t * AppName, const wchar_t * KeyName, bool default_value);
bool WriteIntArray(const wchar_t * AppName, const wchar_t * KeyName, const int* values, int size); //写入一个int数组,元素个数为size
bool GetIntArray(const wchar_t * AppName, const wchar_t * KeyName, int* values, int size, int default_value = 0); //读取一个int数组,储存到values,元素个数为size

protected:
wstring m_path;
Expand Down
87 changes: 87 additions & 0 deletions TrafficMonitorSkinEditor/MainWndColorDlg.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
// MainWndColorDlg.cpp : 实现文件
//

#include "stdafx.h"
#include "Resource.h"
#include "MainWndColorDlg.h"
#include "afxdialogex.h"


// CMainWndColorDlg 对话框

IMPLEMENT_DYNAMIC(CMainWndColorDlg, CDialog)

CMainWndColorDlg::CMainWndColorDlg(COLORREF colors[MAIN_WND_COLOR_NUM], CWnd* pParent /*=NULL*/)
: CDialog(IDD_MAIN_COLOR_DIALOG, pParent)
{
for (int i{}; i < MAIN_WND_COLOR_NUM; i++)
m_colors[i] = colors[i];
}

CMainWndColorDlg::~CMainWndColorDlg()
{
}

void CMainWndColorDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Control(pDX, IDC_UP_STATIC, m_statics[0]);
DDX_Control(pDX, IDC_DOWN_STATIC, m_statics[1]);
DDX_Control(pDX, IDC_CPU_STATIC, m_statics[2]);
DDX_Control(pDX, IDC_MEMORY_STATIC, m_statics[3]);
}


BEGIN_MESSAGE_MAP(CMainWndColorDlg, CDialog)
ON_MESSAGE(WM_STATIC_CLICKED, &CMainWndColorDlg::OnStaticClicked)
END_MESSAGE_MAP()


// CMainWndColorDlg 消息处理程序


BOOL CMainWndColorDlg::OnInitDialog()
{
CDialog::OnInitDialog();

// TODO: 在此添加额外的初始化
for (int i{}; i < MAIN_WND_COLOR_NUM; i++)
{
m_statics[i].SetFillColor(m_colors[i]);
m_statics[i].SetLinkCursor();
}

return TRUE; // return TRUE unless you set the focus to a control
// 异常: OCX 属性页应返回 FALSE
}


afx_msg LRESULT CMainWndColorDlg::OnStaticClicked(WPARAM wParam, LPARAM lParam)
{
int item_id = ::GetDlgCtrlID(((CWnd*)wParam)->m_hWnd);
int index{};
switch (item_id)
{
case IDC_UP_STATIC:
index = 0;
break;
case IDC_DOWN_STATIC:
index = 1;
break;
case IDC_CPU_STATIC:
index = 2;
break;
case IDC_MEMORY_STATIC:
index = 3;
break;
default:
return 0;
}
CColorDialog colorDlg(m_colors[index], 0, this);
if (colorDlg.DoModal() == IDOK)
{
m_colors[index] = colorDlg.GetColor();
m_statics[index].SetFillColor(m_colors[index]);
}
return 0;
}
35 changes: 35 additions & 0 deletions TrafficMonitorSkinEditor/MainWndColorDlg.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#pragma once
#include "ColorStatic.h"
#include "afxwin.h"

// CMainWndColorDlg 对话框

class CMainWndColorDlg : public CDialog
{
DECLARE_DYNAMIC(CMainWndColorDlg)

public:
CMainWndColorDlg(COLORREF colors[MAIN_WND_COLOR_NUM], CWnd* pParent = NULL); // 标准构造函数
virtual ~CMainWndColorDlg();

const COLORREF* GetColors() const { return m_colors; }

// 对话框数据
#ifdef AFX_DESIGN_TIME
enum { IDD = IDD_MAIN_COLOR_DIALOG };
#endif
protected:
COLORREF m_colors[MAIN_WND_COLOR_NUM];

//控件变量
CColorStatic m_statics[MAIN_WND_COLOR_NUM]; //颜色控件

protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持

DECLARE_MESSAGE_MAP()
public:
virtual BOOL OnInitDialog();
protected:
afx_msg LRESULT OnStaticClicked(WPARAM wParam, LPARAM lParam);
};
Loading

0 comments on commit ec686a7

Please sign in to comment.