CColor类封装
CColor类封装
- Color.h
#pragma once #include <sstream>
#include <string>
using namespace std; class CColor
{
public:
CColor(void);
~CColor(void); CColor(const CColor& color);
CColor& operator=(const CColor& color); CColor(float, float, float);
CColor(int, int, int);
CColor(COLORREF clr); // 以两个逗号分隔的字符串
CColor(const string& strColor); public:
COLORREF GetRGB();
DWORD GetARGB();
float GetR();
float GetG();
float GetB();
void SetStrValue(const string& strColor);
string GetStrValue();
string Trans2Txt(); private:
void ParseStrColor(const string& strColor); private:
byte m_tAlpha;
float m_fRed;
float m_fGreen;
float m_fBlue; };
2. Color.cpp
#include "StdAfx.h" #include "Color.h" #include "Utils.h" CColor::CColor(void) : m_tAlpha(255), m_fRed(.0f), m_fGreen(.0f), m_fBlue(.0f)
{
} CColor::~CColor(void)
{
} CColor::CColor( const CColor& color )
{
*this = color;
} CColor& CColor::operator=(const CColor& color )
{
if (this == &color)
{
return *this;
} m_tAlpha = color.m_tAlpha;
m_fRed = color.m_fRed;
m_fGreen = color.m_fGreen;
m_fBlue = color.m_fBlue; return *this;
} CColor::CColor( float fRed, float fGreen, float fBlue)
{
m_tAlpha = 255;
m_fRed = fRed;
m_fGreen = fGreen;
m_fBlue = fBlue;
} CColor::CColor( int nRed, int nGreen, int nBlue)
{
m_tAlpha = 255;
m_fRed = (float)nRed / 255;
m_fGreen = (float)nGreen / 255;
m_fBlue = (float)nBlue / 255;
} CColor::CColor( COLORREF clr )
{
byte* p = (byte*)&clr;
int nRed = *p++;
int nGreen = *p++;
int nBlue = *p++; m_tAlpha = 255;
m_fRed = (float)nRed / 255;
m_fGreen = (float)nGreen / 255;
m_fBlue = (float)nBlue / 255;
} COLORREF CColor::GetRGB()
{
COLORREF colorrrefRGB;
colorrrefRGB = RGB(byte(m_fRed * 255), byte(m_fGreen * 255), byte(m_fBlue * 255));
return colorrrefRGB;
} DWORD CColor::GetARGB()
{
byte tRed = byte(m_fRed * 255);
byte tGreen = byte(m_fGreen * 255);
byte tBlue = byte(m_fBlue * 255); return (((DWORD)(tBlue) << 0) |
((DWORD)(tGreen) << 8) |
((DWORD)(tRed) << 16) |
((DWORD)(m_tAlpha) << 24));
} float CColor::GetR()
{
return m_fRed;
} float CColor::GetG()
{
return m_fGreen;
} float CColor::GetB()
{
return m_fBlue;
} /**
* @brief 解析颜色字符串
*
* 根据指定字符串解析出颜色的三个分量
* 字符串以逗号或空格分割,如"strR,strG,strB" 其中strR,strG和strB都在0.0到1.0间取值
* @param[in] const string& strColor
* @return void
*/
void CColor::SetStrValue( const string& strColor )
{
ParseStrColor(strColor);
} std::string CColor::GetStrValue()
{
stringstream ss;
ss << Float2Str(m_fRed) << ", ";
ss << Float2Str(m_fGreen) << ", ";
ss << Float2Str(m_fBlue); return ss.str();
} std::string CColor::Trans2Txt()
{
return GetStrValue();
} void CColor::ParseStrColor( const string& strColor )
{
string strTmpValue = strColor;
TrimLineSpace(strTmpValue); string strSplitSymbol = ",";
size_t nSplitPos = strTmpValue.find_first_of(strSplitSymbol); if (nSplitPos == string::npos)
{
strSplitSymbol = " ";
} size_t nFirstPos = strTmpValue.find_first_of(strSplitSymbol); if (nFirstPos != string::npos)
{
string strValue = strTmpValue.substr(0, nFirstPos);
m_fRed = Str2Float(strValue); strTmpValue = strTmpValue.substr(nFirstPos + 1, string::npos);
TrimLineSpace(strTmpValue); nFirstPos = strTmpValue.find_first_of(strSplitSymbol); if (nFirstPos != string::npos)
{
strValue = strTmpValue.substr(0, nFirstPos);
m_fGreen = Str2Float(strValue);
} strTmpValue = strTmpValue.substr(nFirstPos + 1, string::npos);
TrimLineSpace(strTmpValue); if (strTmpValue != "")
{
m_fBlue = Str2Float(strTmpValue);
}
} m_tAlpha = 255;
}
CColor类封装的更多相关文章
- salesforce 零基础学习(四十八)自定义列表分页之Pagination基类封装 ※※※
我们知道,salesforce中系统标准列表页面提供了相应的分页功能,如果要使用其分页功能,可以访问http://www.cnblogs.com/zero-zyq/p/5343287.html查看相关 ...
- Redis操作Set工具类封装,Java Redis Set命令封装
Redis操作Set工具类封装,Java Redis Set命令封装 >>>>>>>>>>>>>>>>& ...
- Redis操作List工具类封装,Java Redis List命令封装
Redis操作List工具类封装,Java Redis List命令封装 >>>>>>>>>>>>>>>> ...
- Redis操作Hash工具类封装,Redis工具类封装
Redis操作Hash工具类封装,Redis工具类封装 >>>>>>>>>>>>>>>>>> ...
- Redis操作字符串工具类封装,Redis工具类封装
Redis操作字符串工具类封装,Redis工具类封装 >>>>>>>>>>>>>>>>>>& ...
- java中基于TaskEngine类封装实现定时任务
主要包括如下几个类: 文章标题:java中基于TaskEngine类封装实现定时任务 文章地址: http://blog.csdn.net/5iasp/article/details/10950529 ...
- C++基础——类封装简单示例
一.前言 在IC前端设计/验证领域,只会HDL远远不够.目前大多数项目使用已开发好的系统架构和IP Core,因此设计部分的工作量慢慢向系统集成和验证方向转移.而在集成和验证过程中,往往以各种脚本和面 ...
- Timber(对Log类封装的一个工具)
Timber(对Log类封装的一个工具) https://blog.csdn.net/hzl9966/article/details/51314137 https://www.jianshu.com/ ...
- Java中使用自定义类封装数组,添加类方法实现数据操作
1.具体见注释 2.后续或有更新 public class MyArray { private long[] array; private int cnt; // 自定义数组类的元素个数 /** 使用 ...
随机推荐
- 【网络流】POJ1273 Drainage Ditches
Drainage Ditches Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 78671 Accepted: 3068 ...
- 解读Scrum燃尽图
我的Understand the burndown chart读书笔记. 什么是燃尽图: 在敏捷开发中,燃尽图主要用于显示某一特定时间段内团队的剩余工作量,从而了解团队状态和项目进度. 燃尽图其实很简 ...
- PHP SPL迭代模式
mode 有模式的两个正交组可以设置: 1.迭代的方向 SplDoublyLinkedList::IT_MODE_LIFO(堆叠型) SplDoublyLinkedList::IT_MODE_FIFO ...
- JavaScript作用域,内部函数比参数优先级高
var x=0; f(); console.log(x); var f=function(){ x=1; } f(); console.log(x); function f(){ x=2; } f ...
- JAVA基础-IO流(二)
一.字节流 字节流是通过字节来进行读写操作的,他的使用对象相比于字符流来说更加的广泛.这主要是因为他们读写文件的方式而决定的.字符流读写文件时是将读取到的字节通过默认编码表转换成字符,在通过默认编码表 ...
- Android基础_web通信
一.发展史 1G 模拟制式手机,只能进行语音通话2G 数字制式手机,增加接收数据等功能3G 智能手机,它已经成了集语音通信和多媒体通信相结合,并且包括图像.音乐.网页浏览.电话会议以及其它一些信息服务 ...
- CVE-2017-8635复现
在最近几个月里,我花了一些时间深入了Device Guard以及如何实现用户模式代码完整性(UMCI).如果您对Device Guard不熟悉,您可以 在这里阅读更多信息.通常情况下,UMCI可防止未 ...
- 【Java学习笔记之十六】浅谈Java中的继承与多态
1. 什么是继承,继承的特点? 子类继承父类的特征和行为,使得子类具有父类的各种属性和方法.或子类从父类继承方法,使得子类具有父类相同的行为. 特点:在继承关系中,父类更通用.子类更具体.父类具有更 ...
- 洛谷 P1055 ISBN号码【字符串+模拟】
P1055 ISBN号码 题目描述 每一本正式出版的图书都有一个ISBN号码与之对应,ISBN码包括9位数字.1位识别码和3位分隔符,其规定格式如“x-xxx-xxxxx-x”,其中符号“-”就是分隔 ...
- HDU_5523Game
Game Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) Total Sub ...