GUI_成长历程_part3

名    称: GUI_成长历程_part3
文    件:GUI_X_1788.h
          GUI_X_1788.c
          sim_1788.h
          sim_1788.c

/***************************************************************************************************
文    件: GUI_X_1788.h
***************************************************************************************************/
#ifndef __GUI_X_1788_H
#define __GUI_X_1788_H

//**************************************************************************************************
int  GUI_X_GetTime (void);          //还回系统当前时间 ms
void GUI_X_Delay (int period);      //延时 单位:ms
void GUI_X_ExecIdle(void);          //视窗的非阻塞调用,求解。

void GUI_X_Init (void);             //硬件初始化
void GUI_X_Log(const char *s);      //调试用的,发送字符串
void GUI_X_Warn(const char *s);
void GUI_X_ErrorOut(const char *s);
unsigned  char GetKey(void);
//**************************************************************************************************
#endif

/***************************************************************************************************
文    件: GUI_X_1788.C
***************************************************************************************************/
#include<Windows.h>
#include "OpenglLcd.h"
#include "GUI_X_1788.h"

/***************************************************************************************************
*                                        TIMING FUNCTIONS
*        Default time unit (tick), normally is 1 ms.
***************************************************************************************************/
//还回系统当前时间 ms
int  GUI_X_GetTime (void)
{
    return ((int)GlTimeGetMs());
}

//延时 单位:ms
void  GUI_X_Delay (int period)
{
    //OSTimeDly(period);
    while(period > 0)
    {
        period--;
        Sleep(1);
    }
}

//视窗的非阻塞调用,求解。
void GUI_X_ExecIdle(void)
{
    Sleep(1);
}

/***************************************************************************************************
*                                      KEYBOARD INTERFACE FUNCTIONS
仅某些窗口需要键盘,否则可以不用
****************************************************************************************************/

//硬件初始化
void GUI_X_Init (void)
{
    GlInit();
}

//调试用的,发送字符串
void GUI_X_Log(const char *s)
{   ;
}

void GUI_X_Warn(const char *s)
{   ;
}

void GUI_X_ErrorOut(const char *s)
{   ;
}

unsigned  char GetKey(void)
{
    return 0xff;
}

/***************************************************************************************************
*                                      触摸屏支持函数
*
****************************************************************************************************/
//常量激活
void GUI_TOUCH_X_ActivateX(void)
{
}
void GUI_TOUCH_X_ActivateY(void)
{
}

//返回AD转换的X轴结果
int GUI_TOUCH_X_MeasureX(void)
{
 return GlTouchGetAdX();
}

//返回AD转换的Y轴结果
int GUI_TOUCH_X_MeasureY(void)
{
 return GlTouchGetAdY();
}

 

/*****************************************************************************************
文    件:sim_1788.h
功    能:1788底层接口函数实现
*****************************************************************************************/
#ifndef __SIM_1788_H_
#define __SIM_1788_H_
//****************************************************************************************
void LCD_L0_DrawBitmap(int x0, int y0,                  //画位图
                       int xsize, int ysize,
                       int BitsPerPixel,
                       int BytesPerLine,
                       const U8* pData, int Diff,
                       const LCD_PIXELINDEX* pTrans);
void LCD_L0_FillRect(int x0, int y0, int x1, int y1);   //矩形填充
void LCD_L0_DrawVLine  (int x, int y0,  int y1);        //竖线
void LCD_L0_DrawHLine(int x0, int y,  int x1);          //横线
void LCD_L0_XorPixel(int x, int y);                     //反色

unsigned int LCD_L0_GetPixelIndex(int x, int y);                    //设置某点的颜色
void         LCD_L0_SetPixelIndex(int x, int y, int PixelIndex);    //获取某点的颜色
void         delay_Ns (int idly);                                   //延时
//****************************************************************************************
#endif

/*****************************************************************************************
文    件:sim_1788.c
功    能:1788底层接口函数实现
*****************************************************************************************/
#include "LCDConf.h"
#include "LCD_Private.h"
#include "OpenglLcd.h"
#include "sim_1788.h"

#if (LCD_CONTROLLER == 1788)

GUI_CONTEXT GUI_Context;
//****************************************************************************************
#if         LCD_BITSPERPIXEL <= 8       //8
    #define PIXELINDEX U8
#else if    LCD_BITSPERPIXEL <= 16
    #define PIXELINDEX u16              //16
#endif

/*****************************************************************************************
*       Draw Bitmap 1 BPP   2 BPP  4 BPP  8 BPP  16 BPP
*****************************************************************************************/
static void  _DrawBitLine1BPP(int x, int y, U8 const * p, int Diff, int xsize, const LCD_PIXELINDEX*pTrans)
{
    LCD_PIXELINDEX Index0 = *(pTrans+0);
    LCD_PIXELINDEX Index1 = *(pTrans+1);
    x += Diff;

    switch (GUI_Context.DrawMode & (LCD_DRAWMODE_TRANS | LCD_DRAWMODE_XOR))
    {
        case 0:
            do {
                LCD_L0_SetPixelIndex(x++, y, (*p & (0x80 >> Diff)) ? Index1 : Index0);
                if (++Diff == 8)
                {
                    Diff = 0;
                    p++;
                }
            } while (--xsize);
            break;

        case LCD_DRAWMODE_TRANS:
            do{
                if (*p & (0x80 >> Diff))
                LCD_L0_SetPixelIndex(x, y, Index1);
                x++;
                if (++Diff == 8)
                {
                    Diff = 0;
                    p++;
                }
            } while (--xsize);
            break;

        case LCD_DRAWMODE_XOR:;
            do {
                if (*p & (0x80 >> Diff))
                {
                    int Pixel = LCD_L0_GetPixelIndex(x, y);
                    LCD_L0_SetPixelIndex(x, y, LCD_NUM_COLORS - 1 - Pixel);
                }
                x++;
                if (++Diff == 8)
                {
                    Diff = 0;
                  p++;
                }
            } while (--xsize);
            break;
    }
}

#if (LCD_MAX_LOG_COLORS > 2)
static void  _DrawBitLine2BPP(int x, int y, U8 const * p, int Diff, int xsize, const LCD_PIXELINDEX * pTrans)
{
    LCD_PIXELINDEX Pixels = *p;
    int CurrentPixel = Diff;
    x += Diff;
    switch (GUI_Context.DrawMode & (LCD_DRAWMODE_TRANS | LCD_DRAWMODE_XOR))
    {
        case 0:
            do{
                int Shift = (3 - CurrentPixel) << 1;
                int Index = (Pixels & (0xC0 >> (6 - Shift))) >> Shift;
                LCD_PIXELINDEX PixelIndex = *(pTrans + Index);
                LCD_L0_SetPixelIndex(x++, y, PixelIndex);
                if (++CurrentPixel == 4)
                {
                    CurrentPixel = 0;
                    Pixels = *(++p);
                }
            } while (--xsize);
            break;

        case LCD_DRAWMODE_TRANS:
            do{
                int Shift = (3 - CurrentPixel) << 1;
                int Index = (Pixels & (0xC0 >> (6 - Shift))) >> Shift;
                if (Index)
                {
                    LCD_PIXELINDEX PixelIndex = *(pTrans + Index);
                    LCD_L0_SetPixelIndex(x, y, PixelIndex);
                }
                x++;
                if (++CurrentPixel == 4)
                {
                    CurrentPixel = 0;
                    Pixels = *(++p);
                }
            } while (--xsize);
            break;
    }
}
#endif

#if (LCD_MAX_LOG_COLORS > 4)
static void  _DrawBitLine4BPP(int x, int y, U8 const * p, int Diff, int xsize, const LCD_PIXELINDEX * pTrans)
{
    LCD_PIXELINDEX Pixels = *p;
    int CurrentPixel = Diff;
    switch (GUI_Context.DrawMode & (LCD_DRAWMODE_TRANS | LCD_DRAWMODE_XOR))
    {
        case 0:
            do{
                int Shift = (1 - CurrentPixel) << 2;
                int Index = (Pixels & (0xF0 >> (4 - Shift))) >> Shift;
                LCD_PIXELINDEX PixelIndex = *(pTrans + Index);
                LCD_L0_SetPixelIndex(x++, y, PixelIndex);
                if (++CurrentPixel == 2)
                {
                    CurrentPixel = 0;
                    Pixels = *(++p);
                }
            }while (--xsize);
            break;
        case LCD_DRAWMODE_TRANS:
            do{
                int Shift = (1 - CurrentPixel) << 2;
                int Index = (Pixels & (0xF0 >> (4 - Shift))) >> Shift;
                if (Index)
                {
                    LCD_PIXELINDEX PixelIndex   = *(pTrans + Index);
                    LCD_L0_SetPixelIndex(x, y, PixelIndex);
                }
                x++;
                if (++CurrentPixel == 2)
                {
                    CurrentPixel = 0;
                    Pixels = *(++p);
                }
            }while(--xsize);
            break;
    }
}
#endif

#if (LCD_MAX_LOG_COLORS > 16)
static void  _DrawBitLine8BPP(int x, int y, U8 const * p, int xsize, const LCD_PIXELINDEX * pTrans)
{
    LCD_PIXELINDEX Pixel;
    switch (GUI_Context.DrawMode & (LCD_DRAWMODE_TRANS | LCD_DRAWMODE_XOR))
    {
        case 0:
            if (pTrans)
            {
                for (; xsize > 0; xsize--, x++, p++)
                {
                    Pixel   = *p;
                    LCD_L0_SetPixelIndex(x, y, *(pTrans +   Pixel));
                }
            }else
            {
                for (; xsize > 0; xsize--, x++, p++)
                {
                    LCD_L0_SetPixelIndex(x, y, *p);
                }
            }
            break;
        case LCD_DRAWMODE_TRANS:
            if (pTrans)
            {
                for (; xsize > 0; xsize--, x++, p++)
                {
                    Pixel   = *p;
                    if (Pixel)
                    {
                        LCD_L0_SetPixelIndex(x, y, *(pTrans + Pixel));
                    }
                }
            }else
            {
                for (; xsize > 0; xsize--, x++, p++)
                {
                    Pixel   = *p;
                    if (Pixel)
                    {
                        LCD_L0_SetPixelIndex(x, y, Pixel);
                    }
                }
            }
            break;
    }
}
#endif

#if (LCD_BITSPERPIXEL > 8)
static void  DrawBitLine16BPP(int x, int y, U16 const * p, int xsize, const LCD_PIXELINDEX * pTrans)
{
    LCD_PIXELINDEX pixel;
    if ((GUI_Context.DrawMode & LCD_DRAWMODE_TRANS) == 0)   //画图模式
    {
        if (pTrans)
        {   //反色画图
            for (; xsize > 0; xsize--, x++, p++)
            {
                pixel = *p;
                LCD_L0_SetPixelIndex(x, y, *(pTrans + pixel));
            }
        } else
        {
            for (;xsize > 0; xsize--, x++, p++)
            {
                LCD_L0_SetPixelIndex(x, y, *p);
            }
        }
    }else
    {
        if (pTrans)
        {
            for (; xsize > 0; xsize--, x++, p++)
            {
                pixel = *p;
                if (pixel)
                {
                    LCD_L0_SetPixelIndex(x, y, *(pTrans + pixel));
                }
            }
        }else
        {
            for (; xsize > 0; xsize--, x++, p++)
            {
                pixel = *p;
                if (pixel)
                {
                    LCD_L0_SetPixelIndex(x, y, pixel);
                }
            }
        }
    }
}
#endif

/*****************************************************************************************
                        画位图
*****************************************************************************************/
void LCD_L0_DrawBitmap(int x0, int y0,              //绘图的起点
                       int xsize, int ysize,        //绘图的大小
                       int BitsPerPixel,            //像素深度=1、2、4、8时pData使用u8* =16使用u16*
                       int BytesPerLine,            //每行的字节数,u8 u16都算1个字节
                       const U8* pData, int Diff,
                       const LCD_PIXELINDEX* pTrans)
{
    int i;
    /* Use _DrawBitLineXBPP */
    for (i=0; i<ysize; i++)
    {
        switch (BitsPerPixel)
        {
            case 1:
                _DrawBitLine1BPP(x0, i + y0, pData, Diff, xsize, pTrans);
                break;
            case 2:
                _DrawBitLine2BPP(x0, i + y0, pData, Diff, xsize, pTrans);
                break;
            case 4:
                _DrawBitLine4BPP(x0, i + y0, pData, Diff, xsize, pTrans);
                break;
            case 8:
                _DrawBitLine8BPP(x0, i + y0, pData, xsize, pTrans);
                break;
            case 16:
                DrawBitLine16BPP(x0, i + y0, (const U16 *)pData, xsize, pTrans);
                break;
        }
        pData += BytesPerLine;
    }
}
//****************************************************************************************
//--------------------------矩形填充------------------------------------------------------
void LCD_L0_FillRect(int x0, int y0, int x1, int y1)
{
    for (; y0 <= y1; y0++)
    {
        LCD_L0_DrawHLine(x0, y0, x1);
    }
}

//--------------------------画竖线 -------------------------------------------------------
void LCD_L0_DrawVLine  (int x, int y0,  int y1)
{
    if (GUI_Context.DrawMode & LCD_DRAWMODE_XOR)
    {
        for (; y0 <= y1; y0++)
        {
            LCD_L0_XorPixel(x, y0);                     //颜色反转
        }
    }else
    {
        for (; y0 <= y1; y0++)
        {
            LCD_L0_SetPixelIndex(x, y0, LCD_COLORINDEX);//颜色LCD_COLORINDEX
        }
    }
}

//--------------------------画横线 -------------------------------------------------------
void LCD_L0_DrawHLine(int x0, int y,  int x1)
{
    if (GUI_Context.DrawMode & LCD_DRAWMODE_XOR)
    {
        for (; x0 <= x1; x0++)
        {
            LCD_L0_XorPixel(x0, y);                     //颜色反转
        }
    } else
    {
        for (; x0 <= x1; x0++)
        {
            LCD_L0_SetPixelIndex(x0, y, LCD_COLORINDEX);//按LCD_COLORINDEX 颜色
        }
    }
}
//--------------------------颜色反转------------------------------------------------------
void LCD_L0_XorPixel(int x, int y)
{
    LCD_PIXELINDEX PixelIndex = LCD_L0_GetPixelIndex(x, y);
    LCD_L0_SetPixelIndex(x, y, LCD_NUM_COLORS - PixelIndex - 1);
}
//****************************************************************************************
/*****************************************************************************************
** Function name :        delay_Ns
*****************************************************************************************/
void delay_Ns (int idly)
{
    while(idly-- > 0);
}

/*****************************************************************************************
函数名: LCD_L0_SetPixelIndex
功  能: 设置给定点的颜色,
说  明: emWin在调用层保证参数不越界,所以此处可以不用判断。
*****************************************************************************************/
void LCD_L0_SetPixelIndex(int x, int y, int PixelIndex)
{
    /* Convert logical into physical coordinates (Dep. on LCDConf.h) */
    #if LCD_SWAP_XY | LCD_MIRROR_X| LCD_MIRROR_Y
    #else
    #endif
    GlDisPoint(x,y,(u16)PixelIndex);
}

/*****************************************************************************************
函数名: LCD_L0_GetPixelIndex
功  能: 返回给定点的颜色,
说  明: emWin在调用层保证参数不越界,所以此处可以不用判断。
*****************************************************************************************/
unsigned int LCD_L0_GetPixelIndex(int x, int y)
{
    LCD_PIXELINDEX PixelIndex;
    PixelIndex = GlDisPointGet(x,y);
    return PixelIndex;
}

/*****************************************************************************************
*       LCD_L0_SetOrg
*****************************************************************************************/
void LCD_L0_SetOrg(int x, int y)
{
    x = x;
    y = y;
}

/*****************************************************************************************
*       LCD_On / LCD_Off
*****************************************************************************************/
void LCD_On (void)
{
}

void LCD_Off (void)
{
}

/*****************************************************************************************
*       LCD_L0_Init
*****************************************************************************************/
int  LCD_L0_Init(void)
{
    return 0;
}

void LCD_L0_SetLUTEntry(U8 Pos, LCD_COLOR Color)
{
    Pos = Pos;
    Color = Color;
}
//****************************************************************************************
#endif

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值