gwidgets.cpp

来自「一个由Mike Gashler完成的机器学习方面的includes neural」· C++ 代码 · 共 2,638 行 · 第 1/5 页

CPP
2,638
字号
	m_pParent->OnReleaseTextButton(this);}// virtualvoid GWidgetTextButton::Draw(GImage* pCanvas, int x, int y){	// Draw the non-pressed image	int w = m_rect.w;	int h = m_rect.h;	if(m_pressed)	{		int nHorizOfs = (int)(w * (float).05);		int nVertOfs = (int)(h * (float).15);		m_pStyle->DrawVertCurvedInSurface(pCanvas, x, y, w, h);		m_pStyle->DrawButtonText(pCanvas, x + nHorizOfs, y + nVertOfs, w - nHorizOfs, h - nVertOfs, &m_text, true);		pCanvas->DrawBox(x, y, x + w - 1, y + h - 1, gRGB(255, 255, 255));	}	else	{		m_pStyle->DrawVertCurvedOutSurface(pCanvas, x, y, w, h);		m_pStyle->DrawButtonText(pCanvas, x, y, w, h, &m_text, false);		pCanvas->DrawBox(x, y, x + w - 1, y + h - 1, gRGB(64, 64, 64));	}}void GWidgetTextButton::SetText(GString* pText){	m_text.Copy(pText);	m_pParent->Tattle(this);}void GWidgetTextButton::SetText(const char* szText){	m_text.Copy(szText);	m_pParent->Tattle(this);}// ----------------------------------------------------------------------GWidgetTextTab::GWidgetTextTab(GWidgetGroup* pParent, int x, int y, int w, int h, const char* szText, GColor cBackground): GWidgetAtomic(pParent, x, y, w, h){	m_text.Copy(szText);	m_cBackground = cBackground;	m_selected = false;}/*virtual*/ GWidgetTextTab::~GWidgetTextTab(){}/*virtual*/ void GWidgetTextTab::Grab(int button, int x, int y){	m_pParent->OnSelectTextTab(this);}/*virtual*/ void GWidgetTextTab::Release(int button){}// virtualvoid GWidgetTextTab::Draw(GImage* pCanvas, int x, int y){	// Draw the non-pressed image	int w = m_rect.w;	int h = m_rect.h;	if(m_selected)	{		int nHorizOfs = (int)(w * (float).05);		int nVertOfs = (int)(h * (float).15);		m_pStyle->DrawHorizCurvedInSurface(pCanvas, x, y, w, h, m_cBackground);		m_pStyle->DrawButtonText(pCanvas, x + nHorizOfs, y + nVertOfs, w - nHorizOfs, h - nVertOfs, &m_text, true);		pCanvas->DrawBox(x, y, x + w - 1, y + h - 1, gRGB(255, 255, 255));	}	else	{		m_pStyle->DrawHorizCurvedOutSurface(pCanvas, x, y, w, h, m_cBackground);		m_pStyle->DrawButtonText(pCanvas, x, y, w, h, &m_text, false);		pCanvas->DrawBox(x, y, x + w - 1, y + h - 1, gRGB(64, 64, 64));	}}void GWidgetTextTab::SetText(GString* pText){	m_text.Copy(pText);	m_pParent->Tattle(this);}void GWidgetTextTab::SetText(const char* szText){	m_text.Copy(szText);	m_pParent->Tattle(this);}void GWidgetTextTab::SetSelected(bool selected){	m_selected = selected;	m_pParent->Tattle(this);}// ----------------------------------------------------------------------GWidgetImageButton::GWidgetImageButton(GWidgetGroup* pParent, int x, int y, GImage* pImage): GWidgetAtomic(pParent, x, y, pImage->GetWidth() / 2, pImage->GetHeight()){	m_image.CopyImage(pImage);	m_pressed = false;}/*virtual*/ GWidgetImageButton::~GWidgetImageButton(){}/*virtual*/ void GWidgetImageButton::Grab(int button, int x, int y){	m_pressed = true;	m_pParent->Tattle(this);}/*virtual*/ void GWidgetImageButton::Release(int button){	m_pressed = false;	m_pParent->Tattle(this);	m_pParent->OnReleaseImageButton(this);}// virtualvoid GWidgetImageButton::Draw(GImage* pCanvas, int x, int y){	GRect r((m_pressed ? m_rect.w : 0), 0, m_rect.w, m_rect.h);	pCanvas->Blit(x, y, &m_image, &r);}// ----------------------------------------------------------------------GWidgetAnimation::GWidgetAnimation(GWidgetGroup* pParent, int x, int y, GImage* pImage, int nFrames): GWidgetAtomic(pParent, x, y, pImage->GetWidth(), pImage->GetHeight() / nFrames){	m_image.CopyImage(pImage);	m_nFrames = nFrames;	m_nFrame = 0;}/*virtual*/ GWidgetAnimation::~GWidgetAnimation(){}// virtualvoid GWidgetAnimation::Draw(GImage* pCanvas, int x, int y){	GRect r(0, m_nFrame * m_rect.h, m_rect.w, m_rect.h);	pCanvas->Blit(x, y, &m_image, &r);}void GWidgetAnimation::SetFrame(int nFrame){	m_nFrame = nFrame;	m_pParent->Tattle(this);}// ----------------------------------------------------------------------GWidgetTextLabel::GWidgetTextLabel(GWidgetGroup* pParent, int x, int y, int w, int h, GString* pText, GColor c, GColor back): GWidgetAtomic(pParent, x, y, w, h){	m_text.Copy(pText);	m_alignLeft = true;	m_cForeground = c;	m_cBackground = back;}GWidgetTextLabel::GWidgetTextLabel(GWidgetGroup* pParent, int x, int y, int w, int h, const char* szText, GColor c, GColor back): GWidgetAtomic(pParent, x, y, w, h){	m_text.Copy(szText);	m_alignLeft = true;	m_cForeground = c;	m_cBackground = back;}/*virtual*/ GWidgetTextLabel::~GWidgetTextLabel(){}/*virtual*/ void GWidgetTextLabel::Grab(int button, int x, int y){	if(button == 1)		m_pParent->OnClickTextLabel(this);}/*virtual*/ void GWidgetTextLabel::Release(int button){}// virtualvoid GWidgetTextLabel::Draw(GImage* pCanvas, int x, int y){	if(gAlpha(m_cBackground) != 0)		pCanvas->FillBox(x, y, m_rect.w, m_rect.h, m_cBackground);	m_pStyle->DrawLabelText(pCanvas, x, y, m_rect.w, m_rect.h, &m_text, m_alignLeft, m_cForeground);}void GWidgetTextLabel::SetText(GString* pText){	m_text.Copy(pText);	m_pParent->Tattle(this);}void GWidgetTextLabel::SetText(const char* szText){	m_text.Copy(szText);	m_pParent->Tattle(this);}void GWidgetTextLabel::SetForegroundColor(GColor c){	m_cForeground = c;	m_pParent->Tattle(this);}// The default background color is transparent. If you want an opaque// or semi-opaque background then you should call this method.void GWidgetTextLabel::SetBackgroundColor(GColor c){	m_cBackground = c;	m_pParent->Tattle(this);}// Specifies whether the text is left-justified (true) or right-justified (false)void GWidgetTextLabel::SetAlignLeft(bool bAlignLeft){	m_alignLeft = bAlignLeft;	m_pParent->Tattle(this);}// ----------------------------------------------------------------------GWidgetVCRButton::GWidgetVCRButton(GWidgetGroup* pParent, int x, int y, int w, int h, VCR_Type eType): GWidgetAtomic(pParent, x, y, w, h){	m_eType = eType;	m_pressed = false;}/*virtual*/ GWidgetVCRButton::~GWidgetVCRButton(){}/*virtual*/ void GWidgetVCRButton::Grab(int button, int x, int y){	m_pressed = true;	m_pParent->Tattle(this);	m_pParent->OnPushVCRButton(this);}/*virtual*/ void GWidgetVCRButton::Release(int button){	m_pressed = false;	m_pParent->Tattle(this);}void GWidgetVCRButton::DrawIcon(GImage* pCanvas, int nHorizOfs, int nVertOfs){	int nMinSize = m_rect.w;	if(nMinSize > m_rect.h)		nMinSize = m_rect.h;	int nArrowSize = nMinSize / 3;	int hh = m_rect.h / 2;	int n;	if(m_eType == ArrowRight)	{		for(n = 0; n < nArrowSize; n++)			pCanvas->DrawLine(nHorizOfs + hh - nArrowSize / 2 + n,							nVertOfs + hh - nArrowSize + n + 1,							nHorizOfs + hh - nArrowSize / 2 + n,							nVertOfs + hh + nArrowSize - n - 1,							0);	}	else if(m_eType == ArrowLeft)	{		for(n = 0; n < nArrowSize; n++)			pCanvas->DrawLine(nHorizOfs + hh + nArrowSize / 2 - n,							nVertOfs + hh - nArrowSize + n + 1,							nHorizOfs + hh + nArrowSize / 2 - n,							nVertOfs + hh + nArrowSize - n - 1,							0xff000000);	}	if(m_eType == ArrowDown)	{		for(n = 0; n < nArrowSize; n++)			pCanvas->DrawLine(nHorizOfs + hh - nArrowSize + n + 1,							nVertOfs + hh - nArrowSize / 2 + n,							nHorizOfs + hh + nArrowSize - n - 1,							nVertOfs + hh - nArrowSize / 2 + n,							0xff000000);	}	else if(m_eType == ArrowUp)	{		for(n = 0; n < nArrowSize; n++)			pCanvas->DrawLine(nHorizOfs + hh - nArrowSize + n + 1,							nVertOfs + hh + nArrowSize / 2 - n,							nHorizOfs + hh + nArrowSize - n - 1,							nVertOfs + hh + nArrowSize / 2 - n,							0xff000000);	}	else if(m_eType == Square)	{		pCanvas->DrawBox(nHorizOfs + hh - nArrowSize,						nVertOfs + hh - nArrowSize,						nArrowSize * 2,						nArrowSize * 2,						0xff000000);	}}// virtualvoid GWidgetVCRButton::Draw(GImage* pCanvas, int x, int y){	int w = m_rect.w;	int h = m_rect.h;	if(m_pressed)	{		int nHorizOfs = (int)(w * (float).05);		int nVertOfs = (int)(h * (float).15);		m_pStyle->DrawVertCurvedInSurface(pCanvas, x, y, w, h);		DrawIcon(pCanvas, x + nHorizOfs, y + nVertOfs);		pCanvas->DrawBox(x, y, x + w - 1, y + h - 1, gRGB(255, 255, 255));	}	else	{		m_pStyle->DrawVertCurvedOutSurface(pCanvas, x, y, w, h);		DrawIcon(pCanvas, x, y);		pCanvas->DrawBox(x, y, x + w - 1, y + h - 1, gRGB(64, 64, 64));	}}void GWidgetVCRButton::SetType(VCR_Type eType){	m_eType = eType;	m_pParent->Tattle(this);}// ----------------------------------------------------------------------GWidgetProgressBar::GWidgetProgressBar(GWidgetGroup* pParent, int x, int y, int w, int h): GWidgetAtomic(pParent, x, y, w, h){	m_fProgress = 0;}/*virtual*/ GWidgetProgressBar::~GWidgetProgressBar(){}// virtualvoid GWidgetProgressBar::Draw(GImage* pCanvas, int x, int y){	int w = m_rect.w;	int h = m_rect.h;	int pos;	if(w >= h)	{		pos = (int)(m_fProgress * (w - 2));		m_pStyle->DrawVertCurvedOutSurface(pCanvas, x + 1, y + 1, pos, h - 2);		pCanvas->FillBox(x + 1 + pos, y + 1, w - 3 - x - pos, h - 2, 0xff000000);	}	else	{		pos = (int)(m_fProgress * (h - 2));		m_pStyle->DrawHorizCurvedOutSurface(pCanvas, x + 1, y + h - 1 - pos, w - 2, pos);		pCanvas->FillBox(x + 1, y + 1, w - 2, h - 2  - pos, 0xff000000);	}	pCanvas->DrawBox(0, 0, w - 1, h - 1, gRGB(64, 64, 64));}void GWidgetProgressBar::SetProgress(float fProgress){	m_fProgress = fProgress;	m_pParent->Tattle(this);}// ----------------------------------------------------------------------GWidgetCheckBox::GWidgetCheckBox(GWidgetGroup* pParent, int x, int y, int w, int h): GWidgetAtomic(pParent, x, y, w, h){	m_checked = false;}/*virtual*/ GWidgetCheckBox::~GWidgetCheckBox(){}/*virtual*/ void GWidgetCheckBox::Grab(int button, int x, int y){	// todo: gray the box?}/*virtual*/ void GWidgetCheckBox::Release(int button){	m_checked = !m_checked;	m_pParent->Tattle(this);}// virtualvoid GWidgetCheckBox::Draw(GImage* pCanvas, int x, int y){	int w = m_rect.w;	int h = m_rect.h;	pCanvas->DrawBox(x, y, x + w - 1, y + h - 1, 0xff000000);	pCanvas->DrawBox(x + 1, y + 1, x + w - 2, y + h - 2, gRGB(64, 128, 128));	pCanvas->FillBox(x + 2, y + 2, w - 4, h - 4, 0xffffffff);	if(m_checked)	{		pCanvas->DrawLine(x + 4, y + 4, x + w - 5, y + h - 5, 0xff000000);		pCanvas->DrawLine(x + 5, y + 4, x + w - 5, y + h - 6, 0xff000000);		pCanvas->DrawLine(x + 4, y + 5, x + w - 6, y + h - 5, 0xff000000);		pCanvas->DrawLine(x + w - 5, y + 4, x + 4, y + h - 5, 0xff000000);		pCanvas->DrawLine(x + w - 6, y + 4, x + 4, y + h - 6, 0xff000000);		pCanvas->DrawLine(x + w - 5, y + 5, x + 5, y + h - 5, 0xff000000);	}}void GWidgetCheckBox::SetChecked(bool checked){	m_checked = checked;	m_pParent->Tattle(this);}// ----------------------------------------------------------------------GWidgetSliderTab::GWidgetSliderTab(GWidgetGroup* pParent, int x, int y, int w, int h, bool vertical, Style eStyle): GWidgetAtomic(pParent, x, y, w, h){	m_vertical = vertical;	m_eStyle = eStyle;}/*virtual*/ GWidgetSliderTab::~GWidgetSliderTab(){}/*virtual*/ void GWidgetSliderTab::Grab(int button, int x, int y){	m_pParent->OnClickTab(this);}/*virtual*/ void GWidgetSliderTab::Release(int button){}/*virtual*/ void GWidgetSliderTab::OnMouseMove(int dx, int dy){	m_pParent->OnSlideTab(this, dx, dy);}// virtualvoid GWidgetSliderTab::Draw(GImage* pCanvas, int x, int y){	int i, j;	if(m_rect.w <= 0 || m_rect.h <= 0)		return;	if(m_vertical)	{		switch(m_eStyle)		{			case ScrollBarTab:				m_pStyle->DrawHorizCurvedOutSurface(pCanvas, x, y, m_rect.w, m_rect.h);				break;			case ScrollBarArea:				m_pStyle->DrawHorizCurvedInSurface(pCanvas, x, y, m_rect.w, m_rect.h);				break;			case SliderNub:				m_pStyle->DrawHorizCurvedOutSurface(pCanvas, x, y, m_rect.w, m_rect.h);				for(i = m_rect.h / 2; i >= 0; i--)				{					for(j = m_rect.h / 2 - i; j >= 0; j--)					{						pCanvas->SetPixel(x + m_rect.w - 1 - j, y + i, 0xff000000);						pCanvas->SetPixel(x + m_rect.w - 1 - j, y + m_rect.h - 1 - i, 0xff000000);					}				}				break;			case SliderArea:				m_pStyle->DrawHorizCurvedInSurface(pCanvas, x + m_rect.w / 4, y, m_rect.w / 2, m_rect.h);				break;			default:				GAssert(false, "Unexpected case");		}	}	else	{		switch(m_eStyle)		{			case ScrollBarTab:				m_pStyle->DrawVertCurvedOutSurface(pCanvas, x, y, m_rect.w, m_rect.h);				break;			case ScrollBarArea:				m_pStyle->DrawVertCurvedInSurface(pCanvas, x, y, m_rect.w, m_rect.h);				break;			case SliderNub:				m_pStyle->DrawVertCurvedOutSurface(pCanvas, x, y, m_rect.w, m_rect.h);				for(i = m_rect.w / 2; i >= 0; i--)				{					for(j = m_rect.w / 2 - i; j >= 0; j--)					{						pCanvas->SetPixel(x + i, y + j, 0xff000000);						pCanvas->SetPixel(x + m_rect.w - 1 - i, y + j, 0xff000000);					}				}				break;			case SliderArea:				m_pStyle->DrawVertCurvedInSurface(pCanvas, x, y + m_rect.h / 4, m_rect.w, m_rect.h / 2);				break;			default:				GAssert(false, "Unexpected case");		}	}}void GWidgetSliderTab::SetSize(int w, int h){	m_rect.w = w;	m_rect.h = h;	m_pParent->Tattle(this);}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?