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

📄 drv_gui.c

📁 该模板使用于周立功公司研发的EasyARM2100系列开发板
💻 C
📖 第 1 页 / 共 3 页
字号:
/******************************************************************************
  Copyright (C), 2007-2008, wanyi Tech. Co., Ltd.
  FileName		:app_gui.c
  Author		:kevin 
  modify		:       
  Version 		:1.0          
  Date			:2007-6-28
  Description	:other application function       
  Function List	:none
******************************************************************************/
#include "\inc\system.h"

#define  PX_MAX    319
#define  PY_MAX    239






/******************************************************************************
  Function:       // void test_power_pin(void)
  Description:    // for test power control pin
  Calls:          // none
  Called By:      // init ()
  Table Accessed: // none
  Table Updated:  // none
  Input:          // x:0-319
  				  // y:0-239
  Output:         // none
  Return:         // void
  Others:         // none
******************************************************************************/
void gui_point(unsigned short x,unsigned short y)
{
	unsigned char tmp=0,tmp1=0,tmp2=0;
	 
	if(x<=PX_MAX && y<=PY_MAX)
	{
		

		CmdWrite(0x00,0xc5);									// normal power mode, Graphic mode

    	tmp1=x/8;
    	tmp2=y;
		lcd_cursorxy(tmp1,tmp2);
		tmp=lcd_ramread();
		
		tmp1=x/8;
		tmp2=x%8;
		switch(tmp2)
		{
			case 0:
				tmp =tmp |0x80;
				break;
			case 1:
				tmp =tmp |0x40;
				break;
			case 2:
				tmp =tmp |0x20;
				break;
			case 3:
				tmp =tmp |0x10;
				break;
			case 4:
				tmp =tmp |0x08;
				break;
			case 5:
				tmp =tmp |0x04;
				break;
			case 6:
				tmp =tmp |0x02;
				break;
			case 7:
				tmp =tmp |0x01;
				break;
			default:
				break;	
		}
		lcd_cursorxy(tmp1,y);
		DataWrite(tmp);
		delay(1);
	}
}
//=============================================================================



/******************************************************************************
  Function:       // void gui_rline(unsigned short x_start,unsigned short y_start,unsigned short y_end)
  Description:    // for 
  Calls:          // none
  Called By:      // none
  Table Accessed: // none
  Table Updated:  // none
  Input:          // x:0-319
  		    // y:0-239
  Output:         // none
  Return:         // void
  Others:         // none
******************************************************************************/
void gui_rline(unsigned short x_start,unsigned short y_start,unsigned short y_end)
{ 
	unsigned char direction;
 	
 	if(y_start>y_end)
 	{
 		direction=y_end;
		y_end=y_start;
		y_start=direction;
 	}
 	do
 	{
 		gui_point(x_start, y_start);
		y_start++;
 	}
 	while(y_end>=y_start); 
}
//=============================================================================



/******************************************************************************
  Function:       // void gui_rline(unsigned short x0,unsigned short y_start,unsigned short y_end)
  Description:    // for 
  Calls:          // none
  Called By:      // none
  Table Accessed: // none
  Table Updated:  // none
  Input:          // x:0-319
  				  // y:0-239
  Output:         // none
  Return:         // void
  Others:         // none
******************************************************************************/
void gui_hline(unsigned short x_start,unsigned short y_start,unsigned short x_end)
{ 
	unsigned char direction;
 	
 	if(x_start>x_end)
 	{
 		direction=x_end;
		x_end=x_start;
		x_start=direction;
 	}
 	do
 	{
 		gui_point(x_start, y_start);
		x_start++;
 	}
 	while(x_end>=x_start); 
}
//=============================================================================



/******************************************************************************
  Function:       // void gui_rect(unsigned short x_start,unsigned short y_start,unsigned short x_end,unsigned short y_end)
  Description:    // for 
  Calls:          // none
  Called By:      // none
  Table Accessed: // none
  Table Updated:  // none
  Input:          // x:0-319
  				  // y:0-239
  Output:         // none
  Return:         // void
  Others:         // none
******************************************************************************/
void gui_rect(unsigned short x_start,unsigned short y_start,unsigned short x_end,unsigned short y_end)
{
	gui_hline(x_start,y_start,x_end);
	gui_rline(x_end,y_start,y_end);
	gui_hline(x_end,y_end,x_start);
	gui_rline(x_start,y_end,y_start);	
}
//=============================================================================



/****************************************************************************
* 名称:GUI_DrawRectFill()
* 功能:填充矩形。画一个填充的矩形,填充色与边框色一样。
* 入口参数: x0		矩形左上角的x坐标值
*           y_start		矩形左上角的y坐标值
*           x_end      矩形右下角的x坐标值
*           y_end      矩形右下角的y坐标值
*           color	填充颜色
* 出口参数:无
* 说明:操作失败原因是指定地址超出有效范围。
****************************************************************************/
void gui_rectfill(unsigned short x_start,unsigned short y_start,unsigned short x_end,unsigned short y_end)
{  
	unsigned short i;

  							 														/* 先找出矩形左上角与右下角的两个点,保存在(x0,y_start),(x_end,y_end) */
   if(x_start>x_end) 																// 若x0>x_end,则x0与x_end交换
   {  i = x_start;
      x_start = x_end;
      x_end = i;
   }
   if(y_start>y_end)																// 若y_start>y_end,则y_start与y_end交换
   {  i = y_start;
      y_start = y_end;
      y_end = i;
   }
   
   /* 判断是否只是直线 */
   if(y_start==y_end) 
   {  gui_hline(x_start, y_start, x_end);
      return;
   }
   if(x_start==x_end) 
   {  gui_rline(x_start, y_start, y_end);
      return;
   }

   while(y_start<=y_end)						
   {  gui_hline(x_start, y_start, x_end);											// 当前画水平线
      y_start++;																	// 下一行
   }
}
//=============================================================================




/****************************************************************************
* 名称:GUI_DrawLine()
* 功能:画任意两点之间的直线。
* 入口参数: x0		直线起点的x坐标值
*           y_start		直线起点的y坐标值
*           x_end      直线终点的x坐标值
*           y_end      直线终点的y坐标值
*           color	显示颜色(对于黑白色LCM,为0时灭,为1时显示)
* 出口参数:无
* 说明:操作失败原因是指定地址超出有效范围。
****************************************************************************/
void  gui_line(unsigned short x_start, unsigned short y_start, unsigned short x_end, unsigned short y_end)
{  
	unsigned short   dx;						// 直线x轴差值变量
	unsigned short   dy;          				// 直线y轴差值变量
	unsigned char    dx_sym;					// x轴增长方向,为-1时减值方向,为1时增值方向
	unsigned char    dy_sym;					// y轴增长方向,为-1时减值方向,为1时增值方向
	unsigned short   dx_x2;						// dx*2值变量,用于加快运算速度
	unsigned short   dy_x2;						// dy*2值变量,用于加快运算速度
	unsigned short   di;						// 决策变量
   
   
   dx = x_end-x_start;														// 求取两点之间的差值
   dy = y_end-y_start;
   
   																			/* 判断增长方向,或是否为水平线、垂直线、点 */
   if(dx>0)																	// 判断x轴方向
   {  dx_sym = 1;															// dx>0,设置dx_sym=1
   }
   else
   {  if(dx<0)
      {  dx_sym = -1;														// dx<0,设置dx_sym=-1
      }
      else
      {  																	// dx==0,画垂直线,或一点
         gui_rline(x_start, y_start, y_end);
      	 return;
      }
   }
   
   if(dy>0)																	// 判断y轴方向
   {  dy_sym = 1;															// dy>0,设置dy_sym=1
   }
   else
   {  if(dy<0)
      {  dy_sym = -1;														// dy<0,设置dy_sym=-1
      }
      else
      {  																	// dy==0,画水平线,或一点
         gui_hline(x_start, y_start, x_end);
      	 return;
      }
   }
    
   																			/* 将dx、dy取绝对值 */
   dx = dx_sym * dx;
   dy = dy_sym * dy;
 
   																			/* 计算2倍的dx及dy值 */
   dx_x2 = dx*2;
   dy_x2 = dy*2;
   
   																			/* 使用Bresenham法进行画直线 */
   if(dx>=dy)																// 对于dx>=dy,则使用x轴为基准
   {  di = dy_x2 - dx;
      while(x_start!=x_end)
      {  gui_point(x_start, y_start);
         x_start += dx_sym;
         if(di<0)
         {  di += dy_x2;													// 计算出下一步的决策值
         }
         else
         {  di += dy_x2 - dx_x2;
            y_start += dy_sym;
         }
      }
      gui_point(x_start, y_start);											// 显示最后一点
   }
   else																		// 对于dx<dy,则使用y轴为基准
   {  di = dx_x2 - dy;
      while(y_start!=y_end)
      {  gui_point(x_start, y_start);
         y_start += dy_sym;
         if(di<0)
         {  di += dx_x2;
         }
         else
         {  di += dx_x2 - dy_x2;
            x_start += dx_sym;
         }
      }
      gui_point(x_start, y_start);											// 显示最后一点
   } 
}
//=============================================================================



/****************************************************************************
* 名称:GUI_LineWith()
* 功能:画任意两点之间的直线,并且可设置线的宽度。
* 入口参数: x0		直线起点的x坐标值
*           y_start		直线起点的y坐标值
*           x_end      直线终点的x坐标值
*           y_end      直线终点的y坐标值
*           with    线宽(0-50)
*           color	显示颜色
* 出口参数:无
* 说明:操作失败原因是指定地址超出有效范围。
****************************************************************************/
void  gui_linewith(unsigned short x_start, unsigned short y_start, unsigned short x_end, unsigned short y_end,unsigned char with)
{  
	unsigned short   dx;						// 直线x轴差值变量
   	unsigned short   dy;          			// 直线y轴差值变量
   	unsigned char    dx_sym;					// x轴增长方向,为-1时减值方向,为1时增值方向
   	unsigned char    dy_sym;					// y轴增长方向,为-1时减值方向,为1时增值方向
   	unsigned short   dx_x2;					// dx*2值变量,用于加快运算速度
   	unsigned short   dy_x2;					// dy*2值变量,用于加快运算速度
   	unsigned short   di;						// 决策变量
   
   	unsigned short   wx, wy;					// 线宽变量
   	unsigned short   draw_a, draw_b;
   
   // 参数过滤 
   if(with==0) return;
   if(with>50) with = 50;
   
   dx = x_end-x_start;						// 求取两点之间的差值
   dy = y_end-y_start;

⌨️ 快捷键说明

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