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; // 自定义数组类的元素个数 /** 使用 ...
随机推荐
- Flask分页
一.flask实现的分页组件 from urllib.parse import urlencode,quote,unquote class Pagination(object): "&quo ...
- centos6.8 docker0: iptables: No chain/target/match by that name
现象:之前docker gitlab运行的一直好好的,突然有一天访问不了,但容器却还运行着.于是我把gitlab容器重启,发现启动不了了,报错:docker0: iptables: No chain/ ...
- JMeter-接口自动化之正则表达式关联
jmeter中,接口自动化的关键在于参数关联.比如需要登录的接口,如何调用登录口令?一个增删改查的闭环,如何将接口参数上下传递?下面就以实际的例子来仔细说一说 1:登录接口 这里有一个实际的登录接口, ...
- 什么时候可以用delete替代delete[]
针对gcc编译器 C++内存分配和释放函数 //分配单个对象 operator new(std::size_t size) //分配数组对象 operator new[](std::size_t si ...
- JSON 数据操作
2018,狗年.如果在你出生日期的年份上加12等于2018的话,私聊我,今年是你的本命年,你得发红包!!! 子(鼠).丑(牛).寅(虎).卯(兔).辰(龙).巳(蛇).午(马).未(羊).申(猴).酉 ...
- KinectFusion解析
三维重建是指获取真实物体的三维外观形貌,并建立可复用模型的一种技术.它是当下计算机视觉的一个研究热点,主要有三方面的用途:1)相比于二维图像,可以获取更全面的几何信息:2)在VR/AR中,建立真实 ...
- HDU 1166 敌兵布阵(线段树单点更新,板子题)
敌兵布阵 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submi ...
- hdu_1031_结构体排序
题目很好理解,将列求和,取前k大的 我的代码思路:对列求和,后取出前k大的id加入结果数组,对比后面和第k大相同的评分id也加入到结果数组,最后对结果数组排序 代码: #include<cstd ...
- Java集合系列[4]----LinkedHashMap源码分析
这篇文章我们开始分析LinkedHashMap的源码,LinkedHashMap继承了HashMap,也就是说LinkedHashMap是在HashMap的基础上扩展而来的,因此在看LinkedHas ...
- 微信小程序监听input输入并取值
小程序的事件分为两种,冒泡和非冒泡事件,像<form/>的submit事件,<input/>的input事件,<scroll-view/>的scroll事件等非冒泡 ...