Created
October 27, 2012 14:29
-
-
Save hirosof/3964876 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include "CHSLine.h" | |
| #ifndef _CHSLine_CPP_ | |
| #define _CHSLine_CPP_ | |
| //コンストラクタ | |
| CHSLine::CHSLine(void){ | |
| this->hdc = 0; | |
| this->SetColor(0); | |
| this->SetPosition(0,0); | |
| } | |
| CHSLine::CHSLine(HDC hdc){ | |
| this->hdc = hdc; | |
| this->SetColor(0); | |
| this->SetPosition(0,0); | |
| } | |
| //デバイスコンテキスト設定 | |
| HDC CHSLine::SetDC(HDC hdc){ | |
| HDC old_hdc = this->hdc; | |
| this->hdc = hdc; | |
| return old_hdc; | |
| } | |
| //現在選択されているデバイスコンテキストを取得 | |
| HDC CHSLine::GetDC(void){ | |
| return this->hdc; | |
| } | |
| void CHSLine::SetColor(int r , int g , int b){ | |
| this->SetColor(RGB(r,g,b)); | |
| } | |
| void CHSLine::SetColor(COLORREF rgb){ | |
| this->color[0] = rgb & 0x0000FF; | |
| this->color[1] = (rgb & 0x00FF00) >> 8; | |
| this->color[2] = (rgb & 0xFF0000) >> 16; | |
| } | |
| COLORREF CHSLine::GetColor(void){ | |
| return RGB(this->color[0],this->color[1],this->color[2]); | |
| } | |
| void CHSLine::SetPosition(int x,int y){ | |
| this->pos.x = x; | |
| this->pos.y = y; | |
| } | |
| void CHSLine::SetPosition(POINT pos){ | |
| this->pos = pos; | |
| } | |
| POINT CHSLine::GetPosition(void){ | |
| return this->pos; | |
| } | |
| void CHSLine::DrawEx(int start_x ,int start_y,int end_x , int end_y , BOOL SetPosFromEndPos){ | |
| int upper[2] = { 1,1 } , delta[2] = { 0 , 0}; | |
| int xyflag = 0 , namera=0; | |
| delta[0] = end_x - start_x; | |
| delta[1] = end_y - start_y; | |
| int xy[2] ={ start_x , start_y}; | |
| for(int i = 0 ; i < 2 ; i ++){ | |
| if(delta[i] < 0){ | |
| upper[i] = -1; | |
| delta[i] *= -1; | |
| } | |
| } | |
| if( delta[0] <= delta[1]) xyflag = 1; | |
| for(int idx = 0 ; idx < (delta[xyflag] + 1) ; idx++){ | |
| SetPixel(this->hdc , xy[0],xy[1],RGB(this->color[0] * 255 , this->color[1] * 255 , this->color[2] * 255 )); | |
| xy[xyflag]+=upper[xyflag]; | |
| namera += delta[!xyflag]; | |
| if(namera >= delta[xyflag]){ | |
| namera -= delta[xyflag]; | |
| xy[!xyflag]+=upper[!xyflag]; | |
| } | |
| } | |
| if(SetPosFromEndPos) this->SetPosition(end_x , end_y); | |
| } | |
| void CHSLine::DrawEx(POINT start,POINT end_pos,BOOL SetPosFromEndPos ){ | |
| this->DrawEx(start.x,start.y,end_pos.x,end_pos.y,SetPosFromEndPos); | |
| } | |
| void CHSLine::Draw(int end_x , int end_y , BOOL SetPosFromEndPos){ | |
| POINT end_xy = { end_x , end_y }; | |
| this->Draw(end_xy,SetPosFromEndPos); | |
| } | |
| void CHSLine::Draw(POINT end_pos , BOOL SetPosFromEndPos){ | |
| this->DrawEx(this->pos,end_pos,SetPosFromEndPos); | |
| } | |
| BOOL CHSLine::DrawMultiPoint(LPPOINT points,int num,BOOL SetPosFromEndPos){ | |
| return this->DrawMultiPointEx(points,num,FALSE,SetPosFromEndPos); | |
| } | |
| BOOL CHSLine::DrawMultiPointEx(LPPOINT points,int num,BOOL StartOfCurrentPos,BOOL SetPosFromEndPos){ | |
| POINT old_point; | |
| if(!points)return FALSE; | |
| if(!((num>=2 && StartOfCurrentPos == FALSE)||(num>=1 && StartOfCurrentPos)))return FALSE; | |
| old_point = this->GetPosition(); | |
| if(!StartOfCurrentPos){ | |
| this->SetPosition(*points); | |
| points++; | |
| num--; | |
| } | |
| for(int i= 0 ; i < num ; i++){ | |
| this->Draw(*points); | |
| points++; | |
| } | |
| if(!SetPosFromEndPos)this->SetPosition(old_point); | |
| return TRUE; | |
| } | |
| #endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <Windows.h> | |
| #ifndef _CHSLine_H_ | |
| #define _CHSLine_H_ | |
| enum CHSLine_ColorRGBFlag{ | |
| CHSLC_USECOLORREF, | |
| CHSLC_8BIT_RGB, | |
| CHSLC_64BIT_FLOATRGB | |
| }; | |
| typedef struct tagCHSLine_Color{ | |
| CHSLine_ColorRGBFlag rgbflag; | |
| union{ | |
| COLORREF rgb; | |
| struct{ | |
| unsigned __int8 R; | |
| unsigned __int8 G; | |
| unsigned __int8 B; | |
| operator int(void){ | |
| return R | G << 8 | B << 16; | |
| } | |
| }_8bitRGB; | |
| struct{ | |
| double R; | |
| double G; | |
| double B; | |
| }_64bitfloatRGB; | |
| }; | |
| struct{ | |
| double H; | |
| double S; | |
| double V; | |
| }HSV; | |
| }CHSLine_Color,*PCHSLine_Color,*LPCHSLine_Color; | |
| class CHSLine{ | |
| private: //プライベート・変数 | |
| HDC hdc; //デバイスコンテキストハンドル | |
| POINT pos; //現在の位置 | |
| double color[3]; //線の色(RGB、ただし0.0~1.0) | |
| private: //プライベート関数 | |
| void ConvertRGBtoHSV(LPCHSLine_Color color); | |
| void ConvertHSVtoRGB(LPCHSLine_Color color); | |
| public: //パブリック関数 | |
| //コンストラクタ | |
| CHSLine(void); | |
| CHSLine(HDC hdc); | |
| //デバイスコンテキスト設定 | |
| HDC SetDC(HDC hdc); | |
| //現在選択されているデバイスコンテキストを取得 | |
| HDC GetDC(void); | |
| //位置設定 | |
| void SetPosition(int x,int y); | |
| void SetPosition(POINT pos); | |
| //現在の位置取得 | |
| POINT GetPosition(void); | |
| //描画(座標指定系) | |
| void Draw(int end_x , int end_y , BOOL SetPosFromEndPos = TRUE); | |
| void Draw(POINT end_pos , BOOL SetPosFromEndPos = TRUE); | |
| void DrawEx(int start_x ,int start_y,int end_x , int end_y , BOOL SetPosFromEndPos = TRUE); | |
| void DrawEx(POINT start,POINT end_pos,BOOL SetPosFromEndPos = TRUE); | |
| BOOL DrawMultiPoint(LPPOINT points,int num,BOOL SetPosFromEndPos = TRUE); | |
| BOOL DrawMultiPointEx(LPPOINT points,int num,BOOL StartOfCurrentPos = TRUE,BOOL SetPosFromEndPos = TRUE); | |
| /* | |
| //描画(サイズ指定系) | |
| BOOL DrawSize(int size_x , int size_y , BOOL SetPosFromEndPos = TRUE); | |
| BOOL DrawSize(SIZE size , BOOL SetPosFromEndPos = TRUE); | |
| BOOL DrawExSize(int start_x,int start_y,int size_x,int size_y,BOOL SetPosFromEndPos = TRUE); | |
| BOOL DrawExSize(POINT start,SIZE size ,BOOL SetPosFromEndPos = TRUE); | |
| */ | |
| //色設定 | |
| void SetColor(int r , int g , int b); | |
| void SetColor(COLORREF rgb); | |
| void SetColorHSV(double h , double s , double v); | |
| //色設定取得 | |
| COLORREF GetColor(void); | |
| COLORREF GetColorHSV(double *ph , double *ps , double *pv); | |
| }; | |
| #endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment