📄 lcdugl.c
字号:
#include "LCD.h"
#include "LCD_Private.h" /* include LCDConf.h */
#include "LCDugl.h"
#include "GUI_Private.h"
#include <ugl/ugl.h>
#include <ugl/uglinput.h>
#if LCD_BITSPERPIXEL <= 8
#define PIXELINDEX U8
#else
#define PIXELINDEX WORD
#endif
#ifndef LCD_DISPLAY_INDEX
#define LCD_DISPLAY_INDEX 0
#endif
/*
*********************************************************
* *
* LCD_L0_SetColorIndex *
* LCD_L0_SetBkColorIndex *
* *
*********************************************************
*/
#define COLORINDEX LCD_COLORINDEX
#define BKCOLORINDEX LCD_BKCOLORINDEX
UGL_GC_ID g_uglGc;
UGL_DEVICE_ID g_uglDevId;
UGL_INPUT_SERVICE_ID g_uglInputServiceId;
int LCDUGL_GetPixelIndex(int x, int y)
{
UGL_COLOR color = 0;
uglPixelGet(g_uglGc, x, y, &color);
return LCD_Color2Index_M565(color);
}
void LCDUGL_SetPixelIndex(int x, int y, int Index)
{
uglPixelSet(g_uglGc, x, y, Index&0xffff);
}
/*
*********************************************************
* *
* LCD_L0_DrawPixel *
* *
*********************************************************
Purpose: This routine is called by emWin. It writes 1 pixel into the
display.
*/
void LCD_L0_DrawPixel(int x, int y) {
if (GUI_Context.DrawMode & LCD_DRAWMODE_XOR) {
LCD_L0_XorPixel(x, y);
} else {
LCDUGL_SetPixelIndex(x, y, COLORINDEX);
}
}
/*
*********************************************************
* *
* LCD_DrawLine vertical/horizontal *
* LCD_DrawRect *
* *
*********************************************************
*/
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
{
uglForegroundColorSet(g_uglGc, LCD_GetColorIndex());
uglLine(g_uglGc, x0, y, x1, y);
}
}
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
{
uglForegroundColorSet(g_uglGc, LCD_GetColorIndex());
uglLine(g_uglGc, x, y0, x, y1);
}
}
void LCD_L0_FillRect(int x0, int y0, int x1, int y1)
{
if (x1 - x0 < y1 - y0)
{
for (; x0 < x1; x0++)
{
LCD_L0_DrawVLine(x0, y0, y1);
}
}
else
{
for (; y0 < y1; y0++)
{
LCD_L0_DrawHLine(x0,y0, x1);
}
}
}
/*
***************************************************************
* *
* Internal bitmap routines *
* *
***************************************************************
*/
/*
*********************************************
* *
* Draw Bitmap 1 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;
/*
Jump to right entry point
*/
switch (GUI_Context.DrawMode & (LCD_DRAWMODE_TRANS|LCD_DRAWMODE_XOR))
{
case 0: /* Write mode */
do {
LCDUGL_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))
LCDUGL_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 = LCDUGL_GetPixelIndex(x,y);
LCDUGL_SetPixelIndex(x,y, ~Pixel);
}
x++;
if (++Diff==8)
{
Diff=0;
p++;
}
} while (--xsize);
break;
}
}
/*
*********************************************
* *
* Draw Bitmap 2 BPP *
* *
*********************************************
*/
#if (LCD_MAX_LOG_COLORS > 2)
static void DrawBitLine2BPP(int x, int y, U8 const*p, int Diff, int xsize, const LCD_PIXELINDEX*pTrans) {
PIXELINDEX pixels;
/*
Jump to right entry point
*/
pixels = *p;
if (GUI_Context.DrawMode & LCD_DRAWMODE_TRANS) switch (Diff&3) {
case 0:
goto WriteTBit0;
case 1:
goto WriteTBit1;
case 2:
goto WriteTBit2;
default:
goto WriteTBit3;
} else switch (Diff&3) {
case 0:
goto WriteBit0;
case 1:
goto WriteBit1;
case 2:
goto WriteBit2;
default:
goto WriteBit3;
}
/*
Write without transparency
*/
WriteBit0:
LCDUGL_SetPixelIndex(x+0, y, *(pTrans+(pixels>>6)));
if (!--xsize)
return;
WriteBit1:
LCDUGL_SetPixelIndex(x+1, y, *(pTrans+(3&(pixels>>4))));
if (!--xsize)
return;
WriteBit2:
LCDUGL_SetPixelIndex(x+2, y, *(pTrans+(3&(pixels>>2))));
if (!--xsize)
return;
WriteBit3:
LCDUGL_SetPixelIndex(x+3, y, *(pTrans+(3&(pixels))));
if (!--xsize)
return;
pixels = *(++p);
x+=4;
goto WriteBit0;
/*
Write with transparency
*/
WriteTBit0:
if (pixels&(3<<6))
LCDUGL_SetPixelIndex(x+0, y, *(pTrans+(pixels>>6)));
if (!--xsize)
return;
WriteTBit1:
if (pixels&(3<<4))
LCDUGL_SetPixelIndex(x+1, y, *(pTrans+(3&(pixels>>4))));
if (!--xsize)
return;
WriteTBit2:
if (pixels&(3<<2))
LCDUGL_SetPixelIndex(x+2, y, *(pTrans+(3&(pixels>>2))));
if (!--xsize)
return;
WriteTBit3:
if (pixels&(3<<0))
LCDUGL_SetPixelIndex(x+3, y, *(pTrans+(3&(pixels))));
if (!--xsize)
return;
pixels = *(++p);
x+=4;
goto WriteTBit0;
}
#endif
/*
*********************************************
* *
* Draw Bitmap 4 BPP *
* *
*********************************************
*/
#if (LCD_MAX_LOG_COLORS > 4)
static void DrawBitLine4BPP(int x, int y, U8 const*p, int Diff, int xsize, const LCD_PIXELINDEX*pTrans) {
U8 pixels;
/*
Jump to right entry point
*/
pixels = *p;
if (GUI_Context.DrawMode & LCD_DRAWMODE_TRANS) {
if ((Diff&1) ==0)
goto WriteTBit0;
goto WriteTBit1;
} else {
if ((Diff&1) ==0)
goto WriteBit0;
goto WriteBit1;
}
/*
Write without transparency
*/
WriteBit0:
LCDUGL_SetPixelIndex(x+0, y, *(pTrans+(pixels>>4)));
if (!--xsize)
return;
WriteBit1:
LCDUGL_SetPixelIndex(x+1, y, *(pTrans+(pixels&0xf)));
if (!--xsize)
return;
x+=2;
pixels = *(++p);
goto WriteBit0;
/*
Write with transparency
*/
WriteTBit0:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -