Duilib Round head Image

Source: Internet
Author: User

#ifndef __uiheadicon_h__
#define __uiheadicon_h__


/*
Name: Round avatar Control (derived Cbuttonui Class)
*/


Class Cheadui:public Cbuttonui
{
Public

Cheadui ();

LPCTSTR getclass () const;
LPVOID GetInterface (LPCTSTR pstrname);

void SetAttribute (LPCTSTR pstrname, LPCTSTR pstrvalue);

void Paintbkimage (hdc hdc);

void SetBkImage (LPCTSTR pstrimage);

void Setdefaultbkimage (LPCTSTR pstrimage) {m_sdefaultbkimage = Pstrimage;}
Cduistring Getdefaultbkimage () {return m_sdefaultbkimage;}
void Setautopencolor (bool bauto) {m_bautopencolor = Bauto;}
BOOL Isautopencolor () {return m_bautopencolor;}
void Setpencolor (DWORD dwcolor) {m_dwpencolor = Dwcolor;}
DWORD Getpencolor (hdc hdc);
void setpenwidth (int npenwidth) {m_npenwidth = Npenwidth;}
int Getpenwidth () {return m_npenwidth;}

BOOL Isheadimageexist (LPCTSTR pstrimage);

Private

Cduistring M_sdefaultbkimage;
BOOL M_bautopencolor;
DWORD M_dwpencolor;
int m_npenwidth;
};

#endif//__uiheadicon_h__

#include "StdAfx.h"
#include "UIHeadIcon.h"

Cheadui::cheadui ()
{
M_sdefaultbkimage = _t ("Head\\100_1.png");
M_bautopencolor = false;
M_dwpencolor = Color (255, 255, 255, 255). GetValue ();
M_npenwidth = 2;
}

LPCTSTR Cheadui::getclass () const
{
Return _t ("Headiconui");
}

LPVOID cheadui::getinterface (LPCTSTR pstrname)
{
if (_tcscmp (Pstrname, _t ("headicon") = = = 0) return static_cast<cheadui*> (this);
Return Ccontrolui::getinterface (Pstrname);
}

Void Cheadui::setattribute (LPCTSTR pstrname, LPCTSTR pstrvalue)
{
if (_tcscmp (Pstrname, _t ("Defaultbkimage" )) = = 0) setdefaultbkimage (pstrvalue);
Else if (_tcscmp (Pstrname, _t ("bkimage")) = = 0) setbkimage (pstrvalue);
Else if (_tcscmp (Pstrname, _t ("PenColor")) = = 0) {
while (*pstrvalue > _t (' + ') && *pstrvalue <= _t (‘ ‘)) Pstrvalue =:: Charnext (Pstrvalue);
if (*pstrvalue = = _t (' # ')) Pstrvalue =:: Charnext (Pstrvalue);
LPTSTR pstr = NULL;
DWORD clrcolor = _tcstoul (Pstrvalue, &pstr, 16);
Setpencolor (Clrcolor);
}
Else if (_tcscmp (Pstrname, _t ("Autopencolor")) = = 0) setautopencolor (_tcscmp (Pstrvalue, _t ("true")) = = 0);
else if (_tcscmp (Pstrname, _t ("penwidth") = = = 0) setpenwidth (_ttoi (Pstrvalue));
Else return Cbuttonui::setattribute (Pstrname, Pstrvalue);
}

void Cheadui::setbkimage (LPCTSTR pstrimage)
{
if (Isheadimageexist (pstrimage))
{
M_sbkimage = Pstrimage;
}
Else
{
TCHAR Tszmodule[max_path + 1] = {0};
:: GetModuleFileName (Cpaintmanagerui::getinstance (), Tszmodule, MAX_PATH);
cduistring Sinstancepath = Tszmodule;
int pos = Sinstancepath.reversefind (_t (' \ \ '));
if (POS >= 0) Sinstancepath = sinstancepath.left (pos + 1);
Sinstancepath.append (Pstrimage);

if (Isheadimageexist (Sinstancepath))
{
M_sbkimage = Sinstancepath;
}
Else
{
M_sbkimage = Pstrimage;
}
}

Invalidate ();
}

void Cheadui::P aintbkimage (HDC hdc)
{
Coordinate
Point pt = {m_rcitem.left, m_rcitem.top};

Size
SIZE sz = {m_rcitem.right-m_rcitem.left, m_rcitem.bottom-m_rcitem.top};

Graphics graphics (HDC);
if (graphics. Getlaststatus ()! = Ok)
Return

Anti-aliasing
Graphics. Setsmoothingmode (smoothingmodehighquality);

GraphicsPath GraphicsPath;
if (GraphicsPath. Getlaststatus ()! = Ok)
Return

GraphicsPath. AddEllipse (Pt.x, Pt.y, sz.cx, sz.cy);

Set Clipping circle
Graphics. SetClip (&graphicspath, combinemodereplace);

Image Image (Getbkimage ());
if (image. Getlaststatus ()! = Ok)
Return

Drawing an image
Graphics. DrawImage (&image, Pt.x, Pt.y, sz.cx, sz.cy);

Draws a 1-pixel-wide circle for anti-aliasing
Pen Mypen (Getpencolor (HDC), Getpenwidth ());
if (mypen.getlaststatus () = Ok)
Return

Graphics. DrawEllipse (&mypen, Pt.x, Pt.y, sz.cx, sz.cy);
}

DWORD Cheadui::getpencolor (HDC hdc)
{
if (Isautopencolor ())
{
Values for pixel value color pickup (pt.x + 1, Pt.y + 1)
RECT rc = GetPos ();
COLORREF color = GetPixel (HDC, Rc.left + 1, rc.top + 1);

BYTE r = getrvalue (color);
BYTE g = getgvalue (color);
BYTE B = getbvalue (color);

return Color (255, R, G, b). GetValue ();
}

return m_dwpencolor;
}

BOOL Cheadui::isheadimageexist (LPCTSTR pstrimage)
{
return GetFileAttributes (pstrimage) = =-1? False:true;
}


ccontrolui* Cloginwnd::createcontrol (LPCTSTR pstrclassname)
{
if (_tcsicmp (Pstrclassname, _t ("headicon") = = = 0)
{
return new Cheadui;
}
return NULL;
}

Duilib Round head Image

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.