⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 button.c

📁 一个minigui 工程框架,需要windows 下的minigui 开发环境
💻 C
📖 第 1 页 / 共 4 页
字号:
#include "const.h"#include "resource.h"#include "project.h"#include "page.h"#include "button.h"
#include "microwin.h"
#include "queue.h"#include "liaison.h"


void	ExposureButtonDrawLabel(Button* button)
{
	int i,j,index,offset;
	HDC hdc;
	lattice* latt;
	int 	nwidth ,nheight,x,y,width,height,nx,ny;
	int status;
	eLocation loc;
	unsigned long color;
	int r,g,b;

	
	HWND hWnd = button->m_grButtonID;
	status = button->isdown;
	if(!button->m_tiActiveText.m_szContent)
		return ;
	hdc = BeginPaint (hWnd);
	latt = (lattice*)SearchLattice(atoi(button->m_tiActiveText.m_szContent+1));
	if(!latt)
		return ;
	nwidth= latt->width ;
	nheight = latt->height;
	x = 0;
	y = 0;
	width = button->m_rPosition.right - button->m_rPosition.left;
	height = button->m_rPosition.bottom - button->m_rPosition.top ;
	if(status == 0)
		loc = button->m_tiInActiveText.m_eLocation;
	else
		loc = button->m_tiActiveText.m_eLocation;
	if(status == 0)
		color = button->m_tiInActiveText.m_ulTextColor;
	else
		color = button->m_tiActiveText.m_ulTextColor;
	
	r = (int)(color & 0xFF);
	g = (int)((color >>8) & 0xFF);
	b = (int)((color >> 16) & 0xFF);

	switch(loc)
	{
	case UPPER_LEFT:
		{
			nx=x+2;
			ny=y+2;
		}
		break;
	case MIDDLE_LEFT:
		{
			nx=x+2;
			ny = y+(height-nheight)/2;
		}
		break;
	case LOWER_LEFT:
		{
			nx=x+2;
			ny = y+height-nheight-2;
		}
		break;
	case UPPER_CENTER:
		{
			nx = (width-nwidth)/2+x;	
			ny=y+2;
		}
		break;
	case MIDDLE_CENTER:
		{
			nx = (width-nwidth)/2+x;	
			ny = (height-nheight)/2+y;	
		}
		break;
	case LOWER_CENTER:
		{
			nx = (width-nwidth)/2+x;	
			ny = y+height-nheight-2;
		}
		break;
	case UPPER_RIGHT:
		{
			nx = width-nwidth+x-2;		
			ny=y+2;
		}
		break;
	case MIDDLE_RIGHT:
		{
			nx = width-nwidth+x-2;
			ny = y+(height-nheight)/2;
		}
		break;
	case LOWER_RIGHT:
		{
			nx = width-nwidth+x-2;
			ny = y+height-nheight-2;
		}		
		break;
	default:
		break;
	}
	if(latt)
	{		
		for (j = 0; j<nheight ; j++)
		{
			for ( i = 0; i<nwidth; i++)
			{
				index = (j*nwidth +i)/8;
				offset = 1<<((j*nwidth +i)%8);
				if(latt->pResdata[index] & offset)
				{
					SetPixel(hdc,i+nx,j+ny,(unsigned long)RGBA2Pixel(hdc,r,g,b,0xFF));	
										
				}
			}
		}
	}
	
	EndPaint(hWnd,hdc);
	return ;
}
void		nxDraw3dBox(HWND id,int x,int y,int w,int h,DWORD crTop,DWORD crBottom)
{
	HDC hdc;
	hdc = BeginPaint (id);
	SetPenColor(hdc,crTop);
	MoveTo(hdc, x, y+h-2);
	LineTo(hdc, x, y+1);	
	MoveTo(hdc, x, y);
	LineTo(hdc, x+w-2, y);	
	SetPenColor(hdc,crBottom);
	MoveTo(hdc, x+w-1, y);
	LineTo(hdc, x+w-1, y+h-2);	
	MoveTo(hdc, x+w-1, y+h-1);
	LineTo(hdc, x, y+h-1);	
	EndPaint(id,hdc);
}
void		nxDraw3dEllipse(HWND hWnd,int x,int y,int w,int h,DWORD crTop,DWORD crBottom)
{
	HDC hdc;
	hdc = BeginPaint (hWnd);
	SetPenColor(hdc,crTop);
	Ellipse (hdc, x+w/2,y+h/2,w/2,h/2);
	SetPenColor(hdc,crBottom);
	Ellipse (hdc, x+w/2,y+h/2,w/2,h/2);
	EndPaint(hWnd,hdc);
	
}
void	ExposureButtonDraw3D(Button* button,int offset)
{
	int status ;
	int x = 0+offset;
	int y = 0+offset;
	int w = button->m_rPosition.right - button->m_rPosition.left-2*offset;
	int h = button->m_rPosition.bottom - button->m_rPosition.top-2*offset;
	
	status = button->isdown;
	
	switch(button->m_eShape)
	{
	case  Rectangular:
		if(!status)
		{
			nxDraw3dBox(button->m_grButtonID, x, y, w, h,COLOR_lightgray,COLOR_darkgray);			++x; ++y; w -= 2; h -= 2;
			nxDraw3dBox(button->m_grButtonID, x, y, w, h,COLOR_lightgray,COLOR_darkgray);
		}
		else
		{
			nxDraw3dBox(button->m_grButtonID, x, y, w, h,COLOR_darkgray,COLOR_lightgray);			++x; ++y; w -= 2; h -= 2;
			nxDraw3dBox(button->m_grButtonID, x, y, w, h,COLOR_darkgray,COLOR_lightgray);		}
		break;
	case Elliptical:
		if(!status)
		{
			nxDraw3dEllipse(button->m_grButtonID, x, y, w, h,COLOR_lightgray,COLOR_darkgray);
			++x; ++y; w -= 2; h -= 2;
			nxDraw3dEllipse(button->m_grButtonID, x, y, w, h,COLOR_lightgray,COLOR_darkgray);
		}
		else
		{
			nxDraw3dEllipse(button->m_grButtonID, x, y, w, h,COLOR_darkgray,COLOR_lightgray);
			++x; ++y; w -= 2; h -= 2;
			nxDraw3dEllipse(button->m_grButtonID, x, y, w, h,COLOR_darkgray,COLOR_lightgray);
		}
		break;
	case Obround:
		
		break;
	case Radius:
		break;
	default:
		break;
	}
	
}

void	ExposureButtonDrawShade(Button* button,int offset)
{
	HDC hdc;
	HWND hWnd;
	int status = 0;
	int x = 0+offset;
	int y = 0+offset;
	int width = button->m_rPosition.right - button->m_rPosition.left-2*offset;
	int height = button->m_rPosition.bottom - button->m_rPosition.top-2*offset;
	
	int r0,g0,b0;
	int r,g,b;
	int up,left,right,down,shade1,shade2;
		int i;	
	unsigned long grColor;
	hWnd = button->m_grButtonID;
	hdc = BeginPaint(hWnd);
	status = button->isdown;
	
	if(status)
		grColor = button->m_riActiveRect.m_ulFaceColor;
	else
		grColor = button->m_riInActiveRect.m_ulFaceColor;
	
	if(status)
	{
		up=button->m_riActiveRect .m_pTopLeft .x;
		left=button->m_riActiveRect .m_pTopLeft .x;
		right=button->m_riActiveRect .m_pBottomRight .x ;
		down=button->m_riActiveRect .m_pBottomRight .x ;
		shade1=button->m_riActiveRect .m_pTopLeft .y;
		shade2=button->m_riActiveRect .m_pBottomRight .y;
	}
	else
	{
		up=button->m_riInActiveRect .m_pTopLeft .x;
		left=button->m_riInActiveRect .m_pTopLeft .x;
		right=button->m_riInActiveRect .m_pBottomRight .x ;
		down=button->m_riInActiveRect .m_pBottomRight .x ;
		shade1=button->m_riInActiveRect .m_pTopLeft .y;
		shade2=button->m_riInActiveRect .m_pBottomRight .y;
	}
	
	
	r0 = (int)(grColor & 0xFF);
	g0 = (int)((grColor >>8) & 0xFF);
	b0 = (int)((grColor >> 16) & 0xFF);
	SetPenType (hdc, PT_SOLID);
	
	switch(button->m_eShape)
	{
	case  Rectangular:
		{
			// up.
			r = r0;
			g = g0;
			b = b0;
			
			for(i=0;i<up;i++)
			{
				if(!status)
				{
					if(r < 255 - shade1) { r +=shade1;} else { r = 255;}
					if(g < 255 - shade1) { g +=shade1;} else { g = 255;}
					if(b < 255 - shade1) { b +=shade1;} else { b = 255;}
				}
				else
				{
					if(r > shade1) { r -=shade1;} else { r = 0; }
					if(g > shade1) { g -=shade1;} else { g = 0; }
					if(b > shade1) { b -=shade1;} else { b = 0; }
				}
				
				SetPenColor(hdc,(unsigned long)RGBA2Pixel(hdc,r,g,b,0xFF));
				
				MoveTo(hdc, x+left-(int)((float)left/(float)up*i), y+up-i);
				LineTo(hdc, x+width-right+(int)((float)right/(float)up*i), y+up-i);	
				
				
			}
			// right.
			r = r0;
			g = g0;
			b = b0;
			for(i=0;i<right;i++)
			{
				if(!status)
				{
					if(r >shade2) { r -=shade2;} else r = 0;
					if(g >shade2) { g -=shade2;} else g = 0;
					if(b >shade2) { b -=shade2;} else b = 0;
				}
				else
				{	
					if(r < 255 - shade2) { r +=shade2;} else { r = 255;}
					if(g < 255 - shade2) { g +=shade2;} else { g = 255;}
					if(b < 255 - shade2) { b +=shade2;} else { b = 255;}
				}
				
				SetPenColor(hdc,(unsigned long)RGBA2Pixel(hdc,r,g,b,0xFF));
				MoveTo(hdc, x+width-right+i-1, y+up-(int)((float)up/(float)right*i));
				LineTo(hdc, x+width-right+i-1, y+height-down+(int)((float)down/(float)right*i));	
				
			}
			// down.
			r = r0;
			g = g0;
			b = b0;
			
			for(i=0;i<down;i++)
			{
				if(!status)
				{
					if(r > shade2) { r-=shade2;} else {r = 0;}
					if(g > shade2) { g-=shade2;} else {g = 0;}
					if(b > shade2) { b-=shade2;} else {b = 0;}
				}
				else
				{
					if(r < 255 - shade2) { r +=shade2;} else {r = 255;}
					if(g < 255 - shade2) { g +=shade2;} else {g = 255;}
					if(b < 255 - shade2) { b +=shade2;} else {b = 255;}
					
				}
				SetPenColor(hdc,(unsigned long)RGBA2Pixel(hdc,r,g,b,0xFF));
				MoveTo(hdc, x+left-(int)((float)left/(float)down*i), y+height-down+i-1);
				LineTo(hdc, x+width-right+(int)((float)right/(float)down*i), y+height-down+i-1);	
				
			}
			
			// left.
			r = r0;
			g = g0;
			b = b0;
			
			for(i=0;i<left;i++)
			{
				if(!status)
				{
					if(r <255 - shade1) { r+=shade1;} else {r = 255;}
					if(g <255 - shade1) { g+=shade1;} else {g = 255;}
					if(b <255 - shade1) { b+=shade1;} else {b = 255;}
				}
				else
				{	
					if(r > shade1 ) { r -=shade1;} else {r = 0;}
					if(g > shade1 ) { g -=shade1;} else {g = 0;}
					if(b > shade1 ) { b -=shade1;} else {b = 0;}					
				}
				SetPenColor(hdc,(unsigned long)RGBA2Pixel(hdc,r,g,b,0xFF));
				MoveTo(hdc, x+left-i,y+up-(int)((float)up/(float)left*i));
				LineTo(hdc, x+left-i, y+height-down+(int)((float)down/(float)left*i));	
				
			}
			r = r0;
			g = g0;
			b = b0;
			SetBrushColor(hdc,(unsigned long)RGBA2Pixel(hdc,r,g,b,0xFF));
			FillBox(hdc,x+left,y+up,width-left-right,height-up-down);
		}
		break;
	case Elliptical:
		break;
	case Obround:
		break;
	case Radius:
		break;
	default:
		break;
	}
	EndPaint(hWnd,hdc);
}

void	ExposureButtonDrawFace(Button* button,int offset)
{
	HDC hdc;
	HWND hWnd;
	int status;
	int r,g,b;
	unsigned long color;
	int x = 0+offset;
	int y = 0+offset;
	int w = button->m_rPosition.right - button->m_rPosition.left-2*offset;
	int h = button->m_rPosition.bottom - button->m_rPosition.top-2*offset;
	hWnd = button->m_grButtonID;
	hdc = BeginPaint(hWnd);
	
	status = button->isdown;

	if(status)
		color = button->m_riActiveRect.m_ulFaceColor;		
	else
		color = button->m_riInActiveRect.m_ulFaceColor;
		
	
	r = (int)(color & 0xFF);
	g = (int)((color >>8) & 0xFF);
	b = (int)((color >> 16) & 0xFF);

	SetBrushColor(hdc,(unsigned long)RGBA2Pixel(hdc,r,g,b,0xFF));

	switch(button->m_eShape)
	{
	case  Rectangular:
		FillBox(hdc,x,y,w,h);
		break;
	case Elliptical:
		FillEllipse (hdc,x+w/2,y+h/2,w/2,h/2);
		break;
	case Obround:
		break;
	case Radius:
		break;
	default:
		break;
	}
	

	EndPaint(hWnd,hdc);
}

void	ExposureButtonDrawFrame(Button* button,int rim)
{
	HDC hdc;
	HWND hWnd;
	int status,i;
	unsigned long color;
	int r,g,b;
	
	int x = 0;
	int y = 0;
	int w = button->m_rPosition.right - button->m_rPosition.left;
	int h = button->m_rPosition.bottom - button->m_rPosition.top;
	
	hWnd = button->m_grButtonID;
	hdc = BeginPaint(hWnd);
	
	status = button->isdown;
	if(status)
		color = (DWORD)(button->m_riActiveRect.m_ulFrameColor);
	else
		color = (DWORD)(button->m_riInActiveRect.m_ulFrameColor);

	r = (int)(color & 0xFF);
	g = (int)((color >>8) & 0xFF);
	b = (int)((color >> 16) & 0xFF);

	SetPenColor(hdc,(unsigned long)RGBA2Pixel(hdc,r,g,b,0xFF));
	SetPenType(hdc,PT_SOLID);	
	
	switch(button->m_eShape)
	{
	case  Rectangular:		for(i = 0 ; i < rim ; i++)
			Rectangle(hdc,x+i,y+i,w-i,h-i);
		break;
	case Elliptical:
		for(i = 0 ; i < rim ; i++)
			Ellipse (hdc,x+w/2,y+h/2,w/2-i,h/2-i);
		break;
	case Obround:
		break;
	case Radius:
		break;
	default:
		break;
	}
	EndPaint(hWnd,hdc);
	
}void ExposureButtonBitmap(Button* button){
	HDC hdc;
	HWND hWnd;
	BITMAP bitmap;
	int x,y,w,h;

	if(button->isdown){
		x = button->m_rActiveLockRect.left - button->m_rPosition.left;
		y = button->m_rActiveLockRect.top - button->m_rPosition.top;
		w = button->m_rActiveLockRect.right - button->m_rActiveLockRect.left;
		h = button->m_rActiveLockRect.bottom - button->m_rActiveLockRect.top;
	}
	else
	{
		x = button->m_rInActiveLockRect.left - button->m_rPosition.left;
		y = button->m_rInActiveLockRect.top - button->m_rPosition.top;
		w = button->m_rInActiveLockRect.right - button->m_rInActiveLockRect.left;
		h = button->m_rInActiveLockRect.bottom - button->m_rInActiveLockRect.top;

	}
	hWnd = button->m_grButtonID;
	hdc = BeginPaint(hWnd);


	if(button->isdown){
		if(button->m_iiActiveImage.szImageName != NULL)
		{
			LoadBitmap (hdc, &bitmap, button->m_iiActiveImage.szImageName);
			FillBoxWithBitmap(hdc,x,y,w,h,&bitmap);
			UnloadBitmap (&bitmap);
		}

⌨️ 快捷键说明

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