Files
player/Project/Src/MyWin/mywin_cfg.c

470 lines
8.8 KiB
C
Raw Normal View History

2025-07-05 19:05:35 +08:00
#include "mywin_inc.h"
2025-06-27 00:32:57 +08:00
#include "rtthread.h"
#include "main.h"
#include "system_updata.h"
#include "system_file.h"
#include "lcd_rgb.h"
#include "char_encode.h"
#include "ft2build.h"
#include FT_FREETYPE_H
#include "ff.h"
#include "picdeco.h"
#include "bmp.h"
#include "png.h"
#include <zlib.h>
static FT_Library g_ft_library=0;
static FT_Face g_ft_face=0;
void WIN_FontInit (char *path,char *en_path)
{
FT_Error ft_error=0;
FT_Face ft_face=0;
if(g_ft_library==0)
ft_error=FT_Init_FreeType (&g_ft_library);
if (ft_error==0)
{
ft_error=FT_New_Face (g_ft_library,path,0,&ft_face);
if (ft_error==0)
{
2025-07-05 19:05:35 +08:00
2025-06-27 00:32:57 +08:00
if(g_ft_face) {FT_Done_Face(g_ft_face);g_ft_face=0;}
g_ft_face=ft_face;
}
}
}
static unsigned int g_WinTime=0;
2025-07-05 19:47:28 +08:00
//һ<><D2BB><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
2025-06-27 00:32:57 +08:00
static void WIN_TimerAdd1msIrq (void)
{
g_WinTime++;
}
2025-07-05 19:47:28 +08:00
//<2F><>ȡ<EFBFBD><C8A1><EFBFBD>ϴλ<CFB4>ȡʱ<C8A1><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȥ<EFBFBD>˶<EFBFBD><CBB6>ٺ<EFBFBD><D9BA><EFBFBD>
2025-06-27 00:32:57 +08:00
unsigned int WIN_GetTimePast (void)
{
unsigned int ret=g_WinTime;
g_WinTime=0;
return ret;
}
2025-07-05 19:47:28 +08:00
//<2F><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
2025-06-27 00:32:57 +08:00
void WIN_InitCfg (void)
{
2025-07-05 19:47:28 +08:00
//<2F><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD>Ķ<EFBFBD>ʱ<EFBFBD><CAB1>
2025-06-27 00:32:57 +08:00
TIMER_InitStruct timer_init={0};
timer_init.Cycle=1000;
timer_init.Tim=TIM2;
timer_init.UpdataCall=WIN_TimerAdd1msIrq;
TIMER_InitNormal(&timer_init);
2025-07-05 19:47:28 +08:00
//<2F><><EFBFBD><EFBFBD>LCD<43>ӿں<D3BF><DABA><EFBFBD>
2025-06-27 00:32:57 +08:00
static WIN_LcdInterFaceFunStruct g_lcd={0};
WIN_Struct *ewin=WIN_GetWinStruct();
g_lcd.Init=LCD_Init;
g_lcd.drawPoint=(void (*)(int,int,int))LCD_DrawPointSafe;
g_lcd.drawPointColor=LCD_DrawPointSafeColor;
g_lcd.drawPointColorAlpha=LCD_DrawPointSafeColorAlpha;
g_lcd.clearRect=LCD_ClearRect;
g_lcd.fillRectByColor=LCD_FillRectByColor;
g_lcd.fillRectByColorAlpha=LCD_FillRectByColorAlpha;
g_lcd.fillRectOffAt=LCD_FillRectOff16At;
g_lcd.fillRectOffAtAlpha=LCD_FillRectOffAtAlpha;
g_lcd.getColors=LCD_GetColors;
g_lcd.getPointColor=0;
g_lcd.enterLayerBuff=LCD_EnterLayerBuff;
g_lcd.exitLayerBuff=LCD_ExitLayerBuff;
//g_lcd.setScreenDis=LCD_SetScreenDis;
g_lcd.setWindow=LCD_SetWindow;
2025-07-05 19:05:35 +08:00
g_lcd.setDrawMode=LCD_SetLcdDrawMode;
2025-06-27 00:32:57 +08:00
g_lcd.getLcdSizeX=LCD_GetLcdSizeX;
g_lcd.getLcdSizeY=LCD_GetLcdSizeY;
// g_lcd.getWindowSizeX=LCD_GetWindowSizeX;
// g_lcd.getWindowSizeY=LCD_GetWindowSizeY;
g_lcd.getLcdColor=(u16(*)(void))LCD_GetLcdColor16;
g_lcd.getLcdBkColor=(u16(*)(void))LCD_GetLcdBkColor16;
g_lcd.setLcdColor=(u16(*)(u16))LCD_SetLcdColor16;
g_lcd.setLcdBkColor=(u16(*)(u16))LCD_SetLcdBkColor16;
ewin->lcd=&g_lcd;
2025-07-05 19:05:35 +08:00
2025-07-05 19:47:28 +08:00
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>
2025-06-27 00:32:57 +08:00
WIN_FontInit("simfang.ttf",0);
// WIN_FontInit("0:/ttf/simsun6.ttc",0);
2025-07-05 19:47:28 +08:00
// WIN_FontInit("0:/ttf/<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.ttf","0:/ttf/Agency-FB.ttf");
2025-07-05 19:05:35 +08:00
2025-06-27 00:32:57 +08:00
WIN_FontDrawFunStruct *font=&WIN_GetWinStruct()->font;
// font->malloc=mymalloc_ccm;
// font->free=myfree_ccm;
font->malloc=mymalloc_exm;
font->free=myfree;
2025-07-05 19:05:35 +08:00
2025-07-05 19:47:28 +08:00
//<2F><><EFBFBD><EFBFBD>Ĭ<EFBFBD><C4AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
2025-06-27 00:32:57 +08:00
WIN_SetFontSize(24);
WIN_SetFontType(WIN_FONT_TYPE_NORMAL);
2025-07-05 19:05:35 +08:00
2025-06-27 00:32:57 +08:00
}
2025-07-05 19:47:28 +08:00
//<2F><>MYWIN<49><4E><EFBFBD>õ<EFBFBD><C3B5><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>
2025-06-27 00:32:57 +08:00
void WIN_Delay_ms (u32 ms)
{
rt_thread_delay (ms);
}
2025-07-05 19:47:28 +08:00
//ʹ<><CAB9><EFBFBD>ź<EFBFBD><C5BA><EFBFBD><EFBFBD><EFBFBD>GUI<55>̵߳ķ<CCB5><C4B7>ʽ<EFBFBD><CABD>б<EFBFBD><D0B1><EFBFBD>
2025-06-27 00:32:57 +08:00
#if 0
static struct rt_semaphore g_gui={0};
static rt_err_t g_gui_err=RT_ERROR;
2025-07-05 19:05:35 +08:00
2025-06-27 00:32:57 +08:00
#define GUI_CREAT() {g_gui_err=rt_sem_init(&g_gui,"g_gui",1,RT_IPC_FLAG_FIFO);\
rt_sem_take (&g_gui,RT_WAITING_FOREVER);}
#define GUI_DELETE() {g_gui_err=rt_sem_release (&g_gui);\
if (g_gui_err==RT_EOK) rt_sem_detach(&g_gui);}
#define GUI_WAIT() {while (g_gui_err==RT_ERROR) rt_thread_delay(10);\
2025-07-05 19:05:35 +08:00
rt_sem_take (&g_gui,RT_WAITING_FOREVER);}
2025-06-27 00:32:57 +08:00
#define GUI_WAIT_END() {}
2025-07-05 19:05:35 +08:00
2025-06-27 00:32:57 +08:00
#else
#define GUI_CREAT() {}
#define GUI_WAIT() {}
#define GUI_DELETE() {}
#define GUI_WAIT_END() {}
#endif
2025-07-05 19:47:28 +08:00
//<2F><><EFBFBD>ݾ<EFBFBD><DDBE><EFBFBD>ɾ<EFBFBD><C9BE><EFBFBD>߳<EFBFBD>
2025-06-27 00:32:57 +08:00
static int WIN_DeleteThread (WIN_ThreadHandle *handle);
2025-07-05 19:47:28 +08:00
//GUI<55><49>չ<EFBFBD>߳<EFBFBD>
2025-06-27 00:32:57 +08:00
static void g_guiExThread (void *ptr)
{
GUI_CREAT();
WIN_WorkFunStruct *p=ptr;
*p->ret=p->fun(p->ptr);
2025-07-05 19:47:28 +08:00
p->done=1;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>н<EFBFBD><D0BD><EFBFBD>
2025-06-27 00:32:57 +08:00
GUI_DELETE()
WIN_DeleteThread (p->handle);
}
2025-07-05 19:47:28 +08:00
//<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD>߳<EFBFBD><DFB3><EFBFBD><EFBFBD><EFBFBD>״̬<D7B4><CCAC>1<EFBFBD><31><EFBFBD><EFBFBD><EFBFBD>н<EFBFBD><D0BD><EFBFBD>
2025-06-27 00:32:57 +08:00
int WIN_GetExWorkFunStat(WIN_WorkFunStruct *w)
{
int ret=-1;
GUI_WAIT();
ret=w->done;
GUI_WAIT_END()
return ret;
}
2025-07-05 19:47:28 +08:00
//<2F><>MYWIN<49><4E><EFBFBD>õĴ<C3B5><C4B4><EFBFBD><EFBFBD>̺߳<DFB3><CCBA><EFBFBD>,<2C><><EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD><C9B9><EFBFBD><EFBFBD>ع<EFBFBD><D8B9><EFBFBD><EFBFBD>ռ<EFBFBD><D5BC><EFBFBD><E1B9B9>
//fun<75>ǹ<EFBFBD><C7B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ptr<74>Ǵ<EFBFBD><C7B4>͸<EFBFBD><CDB8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>IJ<EFBFBD><C4B2><EFBFBD><EFBFBD><EFBFBD>ret<65>ǹ<EFBFBD><C7B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ķ<EFBFBD><C4B7><EFBFBD>ֵ
2025-06-27 00:32:57 +08:00
WIN_WorkFunStruct *WIN_CreatThread (int (*fun)(void *),void *ptr,int *ret)
{
WIN_ThreadHandle *handle=mymalloc (sizeof (WIN_ThreadHandle));
mymemset (handle,0,sizeof (WIN_ThreadHandle));
handle->tackSize=4096;
handle->tack=mymalloc (handle->tackSize);
2025-07-05 19:05:35 +08:00
2025-06-27 00:32:57 +08:00
WIN_WorkFunStruct *work=mymalloc (sizeof (WIN_WorkFunStruct));
mymemset (work,0,sizeof (WIN_WorkFunStruct));
work->fun=fun;
work->handle=handle;
work->ptr=ptr;
work->ret=ret;
rt_thread_init (&handle->thread,"g_guiExThread",g_guiExThread,work,handle->tack,handle->tackSize,21,100);
rt_thread_startup(&handle->thread);
return work;
}
2025-07-05 19:47:28 +08:00
//<2F><>MYWIN<49><4E><EFBFBD>õĴ<C3B5><C4B4><EFBFBD><EFBFBD>̺߳<DFB3><CCBA><EFBFBD>,<2C><><EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD><C9B9><EFBFBD><EFBFBD>ع<EFBFBD><D8B9><EFBFBD><EFBFBD>ռ<EFBFBD><D5BC><EFBFBD><E1B9B9>
//fun<75>ǹ<EFBFBD><C7B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ptr<74>Ǵ<EFBFBD><C7B4>͸<EFBFBD><CDB8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>IJ<EFBFBD><C4B2><EFBFBD><EFBFBD><EFBFBD>ret<65>ǹ<EFBFBD><C7B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ķ<EFBFBD><C4B7><EFBFBD>ֵ
2025-06-27 00:32:57 +08:00
WIN_WorkFunStruct *WIN_CreatThreadPro (int (*fun)(void *),void *ptr,int *ret,u8 pro)
{
WIN_ThreadHandle *handle=mymalloc (sizeof (WIN_ThreadHandle));
mymemset (handle,0,sizeof (WIN_ThreadHandle));
handle->tackSize=4096;
handle->tack=mymalloc (handle->tackSize);
2025-07-05 19:05:35 +08:00
2025-06-27 00:32:57 +08:00
WIN_WorkFunStruct *work=mymalloc (sizeof (WIN_WorkFunStruct));
mymemset (work,0,sizeof (WIN_WorkFunStruct));
work->fun=fun;
work->handle=handle;
work->ptr=ptr;
work->ret=ret;
rt_thread_init (&handle->thread,"g_guiExThread",g_guiExThread,work,handle->tack,handle->tackSize,pro,80);
rt_thread_startup(&handle->thread);
return work;
}
2025-07-05 19:47:28 +08:00
//<2F><><EFBFBD>ݾ<EFBFBD><DDBE><EFBFBD>ɾ<EFBFBD><C9BE><EFBFBD>߳<EFBFBD>,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> g_guiExThread <20>̺߳<DFB3><CCBA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
2025-06-27 00:32:57 +08:00
static int WIN_DeleteThread (WIN_ThreadHandle *handle)
{
return 0;
}
2025-07-05 19:47:28 +08:00
//<2F>߳<EFBFBD><DFB3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Դ<EFBFBD><D4B4><EFBFBD>պ<EFBFBD><D5BA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɷ<EFBFBD><C9B7><EFBFBD><EFBFBD>̵߳<DFB3><CCB5><EFBFBD>
2025-06-27 00:32:57 +08:00
void WIN_ExWorkFunClear (WIN_WorkFunStruct *w)
{
myfree (w->handle->tack);
myfree (w->handle);
myfree (w);
}
2025-07-05 19:47:28 +08:00
//<2F><><EFBFBD><EFBFBD>pngͼƬ<CDBC><C6AC><EFBFBD>ɹ<EFBFBD><C9B9><EFBFBD><EFBFBD><EFBFBD>1<EFBFBD><31>ʧ<EFBFBD>ܷ<EFBFBD><DCB7><EFBFBD>0
2025-06-27 00:32:57 +08:00
static int decode_png(WIN_PicStruct *pic,const char *name)
{
2025-07-05 19:05:35 +08:00
2025-06-27 00:32:57 +08:00
int png_err=0;
png_image image; /* The control structure used by libpng */
/* Initialize the 'png_image' structure. */
memset(&image, 0, (sizeof image));
image.version = PNG_IMAGE_VERSION;
/* The first argument is the file to read: */
if (png_image_begin_read_from_file(&image, name) != 0)
{
image.format = PNG_FORMAT_BGRA;
pic->data = mymalloc_exm(PNG_IMAGE_SIZE(image));
pic->format=PIC_FORMAT_ARGB8888;
pic->xsize=image.width;
pic->ysize=image.height;
if (
png_err=png_image_finish_read(&image, NULL/*background*/, pic->data,
0/*row_stride*/, NULL/*colormap*/),png_err != 0)
{
return 1;
}
else
{
myfree(pic->data);
return 0;
}
}
return 0;
}
2025-07-05 19:47:28 +08:00
//<2F><><EFBFBD><EFBFBD>ͼƬ0<C6AC><30><EFBFBD>ɹ<EFBFBD><C9B9><EFBFBD>1<EFBFBD><31>ʧ<EFBFBD><CAA7>
2025-06-27 00:32:57 +08:00
int WIN_DecodeImg(WIN_PicStruct *pic,const char *name)
{
2025-07-05 19:47:28 +08:00
//<2F>ж<EFBFBD>ͼƬ<CDBC><C6AC>ʽ
2025-06-27 00:32:57 +08:00
int str_len=strlen(name);
const char *p_str=&name[str_len-4];
2025-07-05 19:05:35 +08:00
2025-07-05 19:47:28 +08:00
//<2F><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>ʾ<EFBFBD><CABE>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
2025-06-27 00:32:57 +08:00
if (strcmp (p_str,".png")==0)
{
if(decode_png(pic,name)==1)
return 0;
}
else if (strcmp (p_str,".jpg")==0)
{
int ret=0;
BITMAP_Struct bmp={0};
ret=JPEG_Decode ((const u8 *)name,&bmp);
if (ret==0)
{
pic->data=bmp.buff;
pic->xsize=bmp.x_size;
pic->ysize=bmp.y_size;
pic->format=PIC_FORMAT_RGB565;
return 0;
}
}
else if (strcmp (p_str,".bmp")==0)
{
int ret=0;
BMP_DecodeStruct bmp={0};
ret=BMP_Decode ((const u8 *)name,&bmp);
if (ret==0)
{
pic->data=bmp.data;
pic->xsize=bmp.x_size;
pic->ysize=bmp.y_size;
pic->format=PIC_FORMAT_RGB565;
return 0;
}
}
else if(strcmp(p_str,".pic")==0)
{
u8 *data=SysFile_GetFileByName((char *)name,0);
if(data)
{
WIN_GetImageSize(data,&pic->xsize,&pic->ysize);
u8 *t=mymalloc(pic->xsize*pic->ysize*2);
mymemcpy(t,data+8,pic->xsize*pic->ysize*2);
pic->format=PIC_FORMAT_RGB565;
pic->data=(u16 *)t;
myfree(data);
return 0;
}
}
return 1;
}
2025-07-05 19:47:28 +08:00
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͻ<EFBFBD>ȡ<EFBFBD><C8A1>ģ<EFBFBD><C4A3><EFBFBD><EFBFBD>
2025-06-27 00:32:57 +08:00
int WIN_GetWordData(u8 size,u8 type,unsigned char *buff, int word, int buff_size)
{
2025-07-05 19:05:35 +08:00
u8 gbk[4]={0};
2025-06-27 00:32:57 +08:00
u8 uni[3]={0};
2025-07-05 19:05:35 +08:00
2025-06-27 00:32:57 +08:00
if (word>0x80)
{
gbk[0]=(word>>16)&0xff;
gbk[1]=(word>>8)&0xff;
2025-07-05 19:05:35 +08:00
// gbk[2]=word&0xff;
2025-06-27 00:32:57 +08:00
}
else
{
gbk[0]=word;
}
2025-07-05 19:05:35 +08:00
gbk2uni_str(gbk,uni);
2025-06-27 00:32:57 +08:00
if (g_ft_face)
{
FT_Error ft_error=0;
2025-07-05 19:05:35 +08:00
2025-06-27 00:32:57 +08:00
load_char:
ft_error=FT_Set_Pixel_Sizes(g_ft_face, size, size);
if(type==WIN_FONT_TYPE_BITMAP)
ft_error=FT_Load_Char (g_ft_face,(uni[0]<<8)|uni[1],FT_LOAD_RENDER|FT_LOAD_MONOCHROME);
else
ft_error=FT_Load_Char (g_ft_face,(uni[0]<<8)|uni[1],FT_LOAD_RENDER);
2025-07-05 19:05:35 +08:00
// if(ft_error)
2025-06-27 00:32:57 +08:00
// {
// printf("%s:err,ft_error=0x%02x,c=%s,uni=%02x,%02x\r\n",__func__,ft_error,gbk,uni[0],uni[1]);
2025-07-05 19:47:28 +08:00
// WIN_FontInit("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.ttf",0);
2025-06-27 00:32:57 +08:00
// goto load_char;
// }
FT_GlyphSlot slot = g_ft_face->glyph;
2025-07-05 19:05:35 +08:00
2025-06-27 00:32:57 +08:00
int w_byte=slot->bitmap.pitch;
u8 *buf=slot->bitmap.buffer;
mymemcpy (buff,buf,buff_size-5);
buff[buff_size-5]=slot->bitmap.width;
buff[buff_size-4]=slot->bitmap.rows;
buff[buff_size-3]=slot->bitmap.pitch;
buff[buff_size-2]=slot->bitmap_left;
buff[buff_size-1]=slot->bitmap_top;
2025-07-05 19:05:35 +08:00
2025-06-27 00:32:57 +08:00
return slot->bitmap.width;
}
else
{
mymemset(buff,0xf0,buff_size-5);
buff[buff_size-5]=size;
buff[buff_size-4]=size;
buff[buff_size-3]=size/8+(size%8)?1:0;
buff[buff_size-2]=0;
buff[buff_size-1]=0;
return size;
}
}