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

📄 tft_disp.c

📁 一款收款机C源代码!因为是几年前的代码了
💻 C
📖 第 1 页 / 共 3 页
字号:
/******************************************************************************
*       file name : tft_disp.c
*       
*
*
*  Fonction:
*
*       use the TFT to display all kinds of windows the user want.
*
*       The basic functions are all in the tft.c
*
*
*******************************************************************************/
#include "ecrsys.h"
#include "data.h"
#include "keydef.h"
#include "tft_disp.h"
#include "tft.h"
#include "font.h"
#include <stdlib.h>
#include <string.h>



/*----------------------------------------------------------------------------*
function: 
    使用背景色清除屏幕所有显示
*----------------------------------------------------------------------------*/
void Lcd_Screen_Clr(byte color)
{
    TFT_Clear(color); //color: 背景色
}

/*----------------------------------------------------------------------------*
function: 
    画按键的边框, 
    (x0, y0), 左上顶点
    (x1, y1), 右下顶点
*----------------------------------------------------------------------------*/
void Lcd_Draw_Btn_Edge(int x0, int y0, int x1, int y1, byte active)
{
    if(active == FALSE)
    {
        Lcd_Draw_HLine(x0+1, y1-1, x1-1, TFT_BACK_COLOR);//(x0, y1) ,  (x1, y1)
        Lcd_Draw_HLine(x0, y1, x1, TFT_BACK_COLOR);      //(x0, y1) ,  (x1, y1)
        Lcd_Draw_VLine(x1-1, y0+1, y1-1, TFT_BACK_COLOR);//(x1, y0) ,  (x1, y1)
        Lcd_Draw_VLine(x1, y0, y1, TFT_BACK_COLOR);      //(x1, y0) ,  (x1, y1)
        
        Lcd_Draw_HLine(x0+1, y0+1, x1-1, LIGHTGRAY);    //(x0, y0) ,  (x1, y0)
        Lcd_Draw_VLine(x0+1, y0+2, y1-1, LIGHTGRAY);    //(x0, y0) ,  (x0, y1)
        Lcd_Draw_HLine(x0, y0, x1, LIGHTGRAY);          //(x0, y0) ,  (x1, y0)
        Lcd_Draw_VLine(x0, y0, y1, LIGHTGRAY);          //(x0, y0) ,  (x0, y1)
    }
    else//反显边框
    {
        Lcd_Draw_HLine(x0+1, y1-1, x1-1, LIGHTGRAY);    //(x0, y1) ,  (x1, y1)
        Lcd_Draw_VLine(x1-1, y0+1, y1-1, LIGHTGRAY);    //(x1, y0) ,  (x1, y1)
        Lcd_Draw_HLine(x0, y1, x1, LIGHTGRAY);          //(x0, y1) ,  (x1, y1)
        Lcd_Draw_VLine(x1, y0, y1, LIGHTGRAY);          //(x1, y0) ,  (x1, y1)
        
        Lcd_Draw_HLine(x0+1, y0+1, x1-1, TFT_BACK_COLOR);//(x0, y0) ,  (x1, y0)
        Lcd_Draw_VLine(x0+1, y0+2, y1-1, TFT_BACK_COLOR);//(x0, y0) ,  (x0, y1)
        Lcd_Draw_HLine(x0, y0, x1, TFT_BACK_COLOR);      //(x0, y0) ,  (x1, y0)
        Lcd_Draw_VLine(x0, y0, y1, TFT_BACK_COLOR);      //(x0, y0) ,  (x0, y1)
    }
}

/*----------------------------------------------------------------------------*
function: 
    画一个按键, 只是针对右半部分的功能键
    输入参数:
        Btn --- 按键
          按键的大小
          按键的位置(只支持右半部分按键的画出)
          按键的背景色和字体色
          按键名(18个字符以内)
   按键效果
        按键名默认为使用尽可能大的字体显示
*----------------------------------------------------------------------------*/
void Lcd_Draw_Button(BUTTON_DEF Btn)
{
    int x1, x2, y1, y2;
    byte posi;
    byte size;
    byte BOLD;

    size = Btn.size;
    if(((size&0x0f) == 0)||((size&0xf0) == 0))
        return;
    
    posi = Btn.posi;
    
    x1 = (posi%LINE_KEY_NUM)*KEY_ITEM_WIDTH + LCD_X0dot;
    y1 = (posi/LINE_KEY_NUM)*KEY_ITEM_HEIGHT;
    x2 = x1 + KEY_ITEM_WIDTH*((size)&0x0f);
    y2 = y1 + KEY_ITEM_HEIGHT*((size>>4)&0x0f);

    BOLD = Btn.desc[MAX_BTN_DESC_LEN];
    Lcd_Draw_Rect_Fill(x1+2, y1+2, x2-2, y2-2, Btn.fill_color);
    Lcd_Cvt_Btn_Text(Btn.desc,MAX_BTN_DESC_LEN,BOLD, Btn.font_color,x1+3, y1+3, x2-3, y2-3);
    
    Lcd_Draw_Btn_Edge(x1, y1,x2-1,y2-1, FALSE);
}

/*----------------------------------------------------------------------------*
function: 
    画一个按键的边沿, 只是针对右半部分的功能键
    输入参数:
        posi --- 按键的位置(0 ~ 59)(只支持右半部分按键的画出)
        size --- 按键的大小
        Rev --- 按键是否反显
   按键效果
    1> 如果Rev == 1, 边框反显画出
    2> 否则, 边框正显画出
*----------------------------------------------------------------------------*/
void Lcd_Draw_Func_Button_Edge(byte posi, byte size, byte Rev)
{
    int x1, x2, y1, y2;

    if(((size&0x0f) == 0)||((size&0xf0) == 0))
        return;
    
    x1 = (posi%LINE_KEY_NUM)*KEY_ITEM_WIDTH + LCD_X0dot;
    y1 = (posi/LINE_KEY_NUM)*KEY_ITEM_HEIGHT;
    x2 = x1 + KEY_ITEM_WIDTH*((size)&0x0f);
    y2 = y1 + KEY_ITEM_HEIGHT*((size>>4)&0x0f);
    
    Lcd_Draw_Btn_Edge(x1, y1,x2-1,y2-1, Rev);
}

/*----------------------------------------------------------------------------*
*   画一个按键, 但是按键名称使用的是传入的字符串, 不支持含控制字的字符串
*   如果需要分行显示, 以后再做调整
*
*----------------------------------------------------------------------------*/
void Lcd_Draw_Button_Ex(BUTTON_DEF Btn, char *str, byte lenth, byte align)
{
    int x1, x2, y1, y2;
    int x0, y0;
    int height;
    byte posi;
    byte size;
    byte BOLD;
    byte Line_Len;//每行最大字符长度
    byte Max_Line;//最大允许显示行数
    byte Line_Ary[5];//最多只允许5行
    byte i, line;
    byte *tmp_Src;

    if((align != ALIGN_LEFT)&&(align != ALIGN_MID)&&(align != ALIGN_RIGHT))
        return;
    size = Btn.size;
    if((size&0x0f == 0)||(size&0xf0 == 0))
        return;
    
    posi = Btn.posi;
    
    x1 = (posi%LINE_KEY_NUM)*KEY_ITEM_WIDTH + LCD_X0dot;
    y1 = (posi/LINE_KEY_NUM)*KEY_ITEM_HEIGHT;
    x2 = x1 + KEY_ITEM_WIDTH*((size)&0x0f);
    y2 = y1 + KEY_ITEM_HEIGHT*((size>>4)&0x0f);

    Line_Len = (x2-x1-8)/(Font_Size[BTN_DFT_FONT][0]);//计算每行最大字符长度
    Max_Line = (y2-y1-8)/(Font_Size[BTN_DFT_FONT][1]);//计算最大可显行数

    //清除原来的显示
    Lcd_Draw_Rect_Fill(x1+2, y1+2, x2-2, y2-2, Btn.fill_color);

    //检测需要显示的实际行数
    tmp_Src = str;
    for(i = 0; (i< 5)&&(i<Max_Line); i++)
    {
        Line_Ary[i] = Chk_Line(tmp_Src, lenth, Line_Len);
        if(lenth < Line_Ary[i])
            break;
        tmp_Src += Line_Ary[i];
        lenth -= Line_Ary[i];
    }
    Line_Ary[i] = (lenth > Line_Ary[i]) ? Line_Len : Line_Ary[i];
    line = i;//取实际显示行数

    y0 = y1 + (y2 - y1 - ((int)line)*(Font_Size[BTN_DFT_FONT][1]))/2;

    x0 = x1 + 4;//左对齐时, 统一的x0; 其它, 需要根据字符长度调整
 
    for(i = 0; i < line; i++)
    {
        if(align == ALIGN_MID)
            x0 = x1 + (x2 - x1 - Line_Ary[i]*Font_Size[BTN_DFT_FONT][0])/2;
        else if(align == ALIGN_RIGHT)
            x0 = (x2 - 4) - Line_Ary[i]*Font_Size[BTN_DFT_FONT][0];
            
        TFT_Lcd_Disp_Text(str, Line_Ary[i], BTN_DFT_FONT, 0x11, TRUE, 
            Btn.font_color, x0, y0 + ((int)i)*(Font_Size[BTN_DFT_FONT][1]));
        str += Line_Ary[i];
    }
    
    Lcd_Draw_Btn_Edge(x1, y1,x2-1,y2-1, FALSE);
}

const int Func_Btn_Posi[][4] =
{   //x0,   x1,               y0,                   y1
    {0,                 LCD_X0dot,          0,                    1*KEY_ITEM_HEIGHT},//Title_Btn
    {KEY_ITEM_WIDTH,     2*KEY_ITEM_WIDTH,  1*KEY_ITEM_HEIGHT,    2*KEY_ITEM_HEIGHT},//UP_Btn
    {0,                  KEY_ITEM_WIDTH,    1*KEY_ITEM_HEIGHT,    2*KEY_ITEM_HEIGHT},//PGUP_Btn
    {3*KEY_ITEM_WIDTH,   LCD_X0dot,         1*KEY_ITEM_HEIGHT,    2*KEY_ITEM_HEIGHT},//PGDN_Btn
    {2*KEY_ITEM_WIDTH,   3*KEY_ITEM_WIDTH,  1*KEY_ITEM_HEIGHT,    2*KEY_ITEM_HEIGHT},//DN_Btn
    {0,                  LCD_X0dot,         2*KEY_ITEM_HEIGHT,    (HORI_KEY_NUM-2)*KEY_ITEM_HEIGHT},//Text_Btn
    {0,                  LCD_X0dot,         (HORI_KEY_NUM-2)*KEY_ITEM_HEIGHT,    (HORI_KEY_NUM-1)*KEY_ITEM_HEIGHT},//Subttl_Btn
    {0,                  LCD_X0dot,         (HORI_KEY_NUM-1)*KEY_ITEM_HEIGHT,    LCD_Ydot         },//Input_Btn

    {0,                  2*KEY_ITEM_WIDTH,  (HORI_KEY_NUM-1)*KEY_ITEM_HEIGHT,    LCD_Ydot         },//PRN_Rpt-BTN
    {2*KEY_ITEM_WIDTH,   LCD_X0dot,         (HORI_KEY_NUM-1)*KEY_ITEM_HEIGHT,    LCD_Ydot         },//Clear_RPT_BTN

    {LCD_X0dot,          4*KEY_ITEM_WIDTH + LCD_X0dot,  2*KEY_ITEM_HEIGHT,    5*KEY_ITEM_HEIGHT}//POP BTN
};
const byte Func_Btn_Color[][2] =
{   //  fill_color,  font_color
    {BLUE,      YELLOW  },
    {YELLOW,    BLACK   },
    {YELLOW,    BLACK   },
    {YELLOW,    BLACK   },
    {YELLOW,    BLACK   },
    {BLACK,     WHITE   },
    {GRAY,      BLACK   },
    {DARKGRAY,  WHITE   },
    {RED,       BLACK   },
    {BLUE,      BLACK   }
};

#if COUNTRY == HONGKONG
const char *Str_Clr_Prn_Rpt_Text[]  = 
{
    "\xB2\x4D\xB0\xA3\xB3\xF8\xAA\xED\x00",
    "\xA5\xB4\xA6\x4C\xB3\xF8\xAA\xED\x00",
};
const char Str_PageUP[]         =   {0xA4,0x57,0xAD,0xB6,0x00};
const char Str_PageDN[]         =   {0xA4,0x55,0xAD,0xB6,0x00};
#else
const char *Str_Clr_Prn_Rpt_Text[]  = 
{
    {"Clear Report"},
    {"Print Report"}
};
const char Str_PageUP[]         =   {"PAGE UP"};
const char Str_PageDN[]         =   {"PAGEDOWN"};
#endif


/*----------------------------------------------------------------------------*
    画出一个Text按键的基本键出来
    一些画出后不必更新的按键, 将键名标志也画出来
    一些需要实时填充文字显示的区域, 画空白键名
    Rev为1时, 只是画边框
*----------------------------------------------------------------------------*/
void Lcd_Draw_Text_Btn(BYTE Btn_ID)
{
    int x1, y1, x2, y2;
    byte fill_color, font_color;
    int x0, y0;
    byte len;
    byte *src_buf;
    char text_Buf[MAX_BTN_DESC_LEN+1];

    x1 = Func_Btn_Posi[Btn_ID][0];
    x2 = Func_Btn_Posi[Btn_ID][1];
    y1 = Func_Btn_Posi[Btn_ID][2];
    y2 = Func_Btn_Posi[Btn_ID][3];

    fill_color = Func_Btn_Color[Btn_ID][0];
    font_color = Func_Btn_Color[Btn_ID][1];

    Lcd_Draw_Rect_Fill(x1+2, y1+2, x2-2, y2-2,fill_color);
    if((Btn_ID == KD_DOWN_TEXT)||(Btn_ID == KD_UP_TEXT))
    {
        x0 = x1 + (x2 - x1 - 16)/2;
        y0 = y1 + (y2 - y1 - 24)/2;
        if(Btn_ID == KD_DOWN_TEXT)
            src_buf = (byte *)Font_DN;
        else 
            src_buf = (byte *)Font_UP;
        TFT_LCD_Disp_LOGO(src_buf, font_color, 16, 24, x0, y0);
    }
    else 
    {
        if((Btn_ID == PGUP_TEXT)||(Btn_ID == PGDN_TEXT))
        {
            memset(text_Buf, 0x20, MAX_BTN_DESC_LEN);
            if(Btn_ID == PGUP_TEXT)
                memcpy(text_Buf, Str_PageUP, strlen(Str_PageUP));
            else
                memcpy(text_Buf, Str_PageDN, strlen(Str_PageDN));
            text_Buf[MAX_BTN_DESC_LEN] = BOLD_FONT;
            Lcd_Cvt_Btn_Text(text_Buf,MAX_BTN_DESC_LEN,BOLD_FONT, font_color,x1+3, y1+3, x2-3, y2-3);
        }
        else
        {
            if(Btn_ID == BUF_ID_TL_TITLE)
            {
                (char*)src_buf = Tl_Title.text;
            }
            else if((Btn_ID == CLR_RPT_TEXT)||(Btn_ID == PRN_RPT_TEXT))
            {
                (char*)src_buf = (char *)Str_Clr_Prn_Rpt_Text[Btn_ID - CLR_RPT_TEXT];
            }
            else
            {
                (char*)src_buf = (char *)Str_Null;
            }
            len = strlen(src_buf);
            if(len > 0)//如果字符串为空, 就不必画了
            {
                x0 = x1 + (x2 - x1 - len*Font_Size[BTN_DFT_FONT][0])/2;
                y0 = y1 + (y2 - y1 - Font_Size[BTN_DFT_FONT][1])/2; 
                TFT_Lcd_Disp_Text((char*)src_buf, len, BTN_DFT_FONT, 0x11, TRUE, font_color, x0, y0);
            }

⌨️ 快捷键说明

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