diff --git a/.gitignore b/.gitignore index 081c214885802b782752a96117322b97a96f6638..0f7fe6bb598900c87bc407d2283bd35edfca06d3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ -build/ + .vs/ .vscode/ +build diff --git a/app.c b/app.c index 9f5fdb563966c3f2dc9e4c567d0fb73a53d5dbe9..cb63ed3048e438d079078454dccdb4616d9c3df0 100644 --- a/app.c +++ b/app.c @@ -135,7 +135,7 @@ uint8_t WinProcessFunction(void *Object, void *arg, p_msg_t hMsg) WindowsAdd(Object, SLIDE_MARK_HEAD(Create)(5, 180, 100, 20)); - p_xlist_widget_t hListWidge = LIST_WIDGE_MARK_HEAD(Create)(160, 5, 240, 250); + p_xlist_widget_t hListWidge = LIST_WIDGE_MARK_HEAD(Create)(160, 5, 240, 500); _OpenListAnimation(hListWidge); WidgetSetColor(&hListWidge->groupWidge.widgeBase, ARGB565_GEN(128, 0xff, 0x00, 0xff)); @@ -164,8 +164,11 @@ uint8_t WinProcessFunction(void *Object, void *arg, p_msg_t hMsg) LIST_WIDGE_MARK_HEAD(Add) (hListWidge, listBitmap); - LIST_WIDGE_MARK_HEAD(Add) - (hListWidge, BitmapWidgetCreate(0, 0, 256, 240, &xGirlBitmap)); + for (int i = 0; i < 5; i++) + { + LIST_WIDGE_MARK_HEAD(Add) + (hListWidge, BitmapWidgetCreate(0, 0, 256, 240, &xGirlBitmap)); + } WindowsAdd(Object, hListWidge); @@ -474,16 +477,18 @@ uint8_t WinProcess1Function(void *Object, void *arg, p_msg_t hMsg) } else if (hMsg->msgID == MSG_WIN_PAINT) { - /*画一个正方形*/ - xrect_t drawRect; - drawRect.x = ((p_widget_base_t)(Object))->rect.x + 50; - drawRect.y = ((p_widget_base_t)(Object))->rect.y + 50; - drawRect.w = 35; - drawRect.h = 45; - uintColor temp = ((p_widget_base_t)(Object))->pencil.DrawColor; - ((p_widget_base_t)(Object))->pencil.DrawColor = 0x0000; - DrawCutRect(Object, &drawRect); - ((p_widget_base_t)(Object))->pencil.DrawColor = temp; + // /*画一个正方形*/ + // xrect_t drawRect; + // drawRect.x = ((p_widget_base_t)(Object))->rect.x + 50; + // drawRect.y = ((p_widget_base_t)(Object))->rect.y + 50; + // drawRect.w = 35; + // drawRect.h = 45; + // uintColor temp = ((p_widget_base_t)(Object))->pencil.DrawColor; + // ((p_widget_base_t)(Object))->pencil.DrawColor = 0x0000; + // DrawCutRect(Object, &drawRect); + // ((p_widget_base_t)(Object))->pencil.DrawColor = temp; + DrawLine(Object, &(xpoint_t){.x = 250, .y = 250}, &(xpoint_t){.x = 400, .y = 400}, RGB565_RED); + DrawCircle(Object, &(xpoint_t){.x = 300, .y = 300}, 50, RGB565_RED); } break; } diff --git a/main.c b/main.c index 837ecb9f5778d66cb4435dadb9685fbd1d0391ac..30ebcf74dcc1b28ef442438f589898f160f6bf15 100644 --- a/main.c +++ b/main.c @@ -71,18 +71,20 @@ int timer_draw_screen(void *p) // 回调函数 #endif int timer_event_screen(void *p) // 回调函数 { + uint32_t last_tick = SDL_GetTicks(); + while (1) { - uint32_t st_tick = SDL_GetTicks(); // 事件处理 GUIEvent(); - // nes处理 - NesFrameCycle(); - uint32_t en_tick = SDL_GetTicks(); - if (en_tick - st_tick < 1000 / 60) - { - SDL_Delay((1000 / 60) - (en_tick - st_tick)); - } + + // uint32_t en_tick = SDL_GetTicks(); + // if (en_tick - last_tick >= 1000 / 60) + // { + // // nes处理 + // NesFrameCycle(); + // last_tick = SDL_GetTicks(); + // } } return 0; } diff --git a/xtinygui/inc/gui.h b/xtinygui/inc/gui.h index bb4e3843999b6cdc908215ca0e96b6f91f88e4be..b9034a349a2e3c1591e3cff7f1301253e95a4722 100644 --- a/xtinygui/inc/gui.h +++ b/xtinygui/inc/gui.h @@ -22,7 +22,7 @@ #define LCD_SCREEN_W 900 #define LCD_SCREEN_H 600 -#define LCD_CACHE_LINE LCD_SCREEN_H /*缓冲区行数*/ +#define LCD_CACHE_LINE 1 /*缓冲区行数*/ /*********返回的事件说明********/ #define RES_ASSERT_ERR -1 diff --git a/xtinygui/inc/paint.h b/xtinygui/inc/paint.h index 69c498671dc4a0e982c42033203631a3167b7631..ce8b8a775d5e0762457609da86eb735ba1282920 100644 --- a/xtinygui/inc/paint.h +++ b/xtinygui/inc/paint.h @@ -1,22 +1,23 @@ /** * @file paint.h * @author ATShining (1358745329@qq.com) - * @brief + * @brief * @version 0.1 * @date 2024-02-10 - * + * * @copyright Copyright (c) 2024 - * + * */ #pragma once #include "x_types.h" #include "widget_define.h" #include "font.h" #include "bitmap.h" - uintColor _GetPixel(int16_t x, int16_t y); void DrawPixel(uintColor color, int16_t x, int16_t y); void DrawAPixel(uintColor aColor, int16_t x, int16_t y); +void DrawLine(void* hWidgeBase, xpoint_t *st_point, xpoint_t *end_point, uintColor color); +void DrawCircle(void *obj, xpoint_t *center, int radius, uintColor color); // uint8_t DrawLineH(p_pencil_t hPencil, int16_t x0, int16_t y, int16_t x1); // uint8_t DrawLineV(p_pencil_t hPencil, int16_t x, int16_t y0, int16_t y1); uint8_t DrawRect(p_pencil_t hPencil, p_xrect_t hXRECT); diff --git a/xtinygui/inc/x_types.h b/xtinygui/inc/x_types.h index 3e67d51ce2ca454f7897261a13647298e85569b0..d21f6397c10ce5bd85b392a5b11c45596e4c2f07 100644 --- a/xtinygui/inc/x_types.h +++ b/xtinygui/inc/x_types.h @@ -11,6 +11,7 @@ #pragma once #include "config.h" #include +#include typedef struct { uint8_t a; diff --git a/xtinygui/src/group_widge.c b/xtinygui/src/group_widge.c index be83f842c6ef034f7df451dfc88b42c5f6aaec9d..ec86514405b033dcc27c73c82a52c01d6ce63a86 100644 --- a/xtinygui/src/group_widge.c +++ b/xtinygui/src/group_widge.c @@ -87,6 +87,7 @@ PUBLIC void GROUP_MARK_HEAD(Resize)(p_group_widget_t hObject, int16_t x, int16_t int16_t dx, dy; + dx = x - ((p_xrect_t)hObject)->x; dy = y - ((p_xrect_t)hObject)->y; WidgetResize((p_widget_base_t)hObject, x, y, w, h); @@ -185,8 +186,9 @@ PUBLIC void GROUP_MARK_HEAD(Paint)(void *hObject) } PUBLIC void GROUP_MARK_HEAD(MoveTo)(p_group_widget_t hObject, int16_t x, int16_t y) { - int16_t dx = 0; - int16_t dy = 0; + int32_t dx = 0; + int32_t dy = 0; + if (!hObject) { return; diff --git a/xtinygui/src/list_widge.c b/xtinygui/src/list_widge.c index 1cef639c77d7f20ef6ac486641fe745b3e176645..f945b8b25d64bf2aea037e1af33dbca0e6e2f06d 100644 --- a/xtinygui/src/list_widge.c +++ b/xtinygui/src/list_widge.c @@ -38,15 +38,12 @@ PUBLIC p_xlist_widget_t LIST_WIDGE_MARK_HEAD(Create)(int16_t x, int16_t y, uint1 hObject->flag = 0; hObject->itemGap = 5; hObject->dSP = 0; - hObject->hGUITimeout = GUITimeoutCreate(17, hObject, GUITimeoutCb); + hObject->hGUITimeout = GUITimeoutCreate(1000 / 60, hObject, GUITimeoutCb); GUITimeoutClose(hObject->hGUITimeout); - /*����Ӧģʽ*/ _SetListWidgeMode(hObject); - /*Ĭ�ϴ�ֱ����*/ _SetOTN_V(hObject); - /*�򿪶���*/ - //_OpenListAnimation(hObject); + _OpenListAnimation(hObject); hObject->itemsSize.itemsH = 0; return hObject; @@ -70,7 +67,6 @@ PUBLIC void LIST_WIDGE_MARK_HEAD(Close)(p_xlist_widget_t hObject) GROUP_MARK_HEAD(Close) ((p_group_widget_t)hObject); } -/*����һ���ؼ�*/ PUBLIC uint8_t LIST_WIDGE_MARK_HEAD(Add)(p_xlist_widget_t hBaseWidge, p_widget_base_t widge) { uint16_t widgeLength; @@ -85,10 +81,9 @@ PUBLIC uint8_t LIST_WIDGE_MARK_HEAD(Add)(p_xlist_widget_t hBaseWidge, p_widget_b } widgeLength = ((p_group_widget_t)hBaseWidge)->widgeLength - 1; if (!_GetListWidgeMode(hBaseWidge)) - { /*����ģʽ*/ + { if (_GetOTN(hBaseWidge)) { - /*�������ÿؼ�����Ϣ*/ ((p_xrect_t)widge)->x = hBaseWidge->groupWidge.widgeBase.rect.x + hBaseWidge->itemsSize.itemSize * widgeLength + widgeLength; ((p_xrect_t)widge)->y = hBaseWidge->groupWidge.widgeBase.rect.y; @@ -103,8 +98,7 @@ PUBLIC uint8_t LIST_WIDGE_MARK_HEAD(Add)(p_xlist_widget_t hBaseWidge, p_widget_b ((p_xrect_t)widge)->w = hBaseWidge->groupWidge.widgeBase.rect.w; } else - { /*�߶�����Ӧ*/ - /*�������ÿؼ�����Ϣ*/ + { if (_GetOTN(hBaseWidge)) { ((p_xrect_t)widge)->x = hBaseWidge->groupWidge.widgeBase.rect.x + @@ -123,38 +117,33 @@ PUBLIC uint8_t LIST_WIDGE_MARK_HEAD(Add)(p_xlist_widget_t hBaseWidge, p_widget_b } } - /*ˢ��*/ WindowsInvaildRect((p_widget_base_t)hBaseWidge, NULL); return TRUE; } -/*ListWidge�ڲ��ؼ���λ�û���*/ PRIVATE uint8_t LIST_WIDGE_MARK_HEAD(ListSlide)(p_xlist_widget_t hBaseWidge, int16_t dXY) { p_xrect_t widgeRectLast; p_xrect_t widgeRectFirst; - if (!hBaseWidge) - { - return FALSE; - } - /*��ȡ��һ�ؼ�*/ + assert(hBaseWidge); widgeRectFirst = (p_xrect_t)GROUP_MARK_HEAD(GetWidge)((p_group_widget_t)hBaseWidge, 0); if (widgeRectFirst == NULL) { return FALSE; } - /*��ȡ���һ���ؼ�*/ widgeRectLast = (p_xrect_t)GROUP_MARK_HEAD(GetWidge)((p_group_widget_t)hBaseWidge, hBaseWidge->groupWidge.widgeLength - 1); if (widgeRectLast == NULL) { return FALSE; } + //!< 重新计算偏移的位置 if (_GetOTN(hBaseWidge)) - { /*����*/ - if (widgeRectLast->x + dXY + widgeRectLast->w < ((p_xrect_t)(hBaseWidge))->x + ((p_xrect_t)(hBaseWidge))->w) + { + if (widgeRectLast->x + dXY + widgeRectLast->w < + ((p_xrect_t)(hBaseWidge))->x + ((p_xrect_t)(hBaseWidge))->w) { - // return FALSE; - dXY = ((p_xrect_t)(hBaseWidge))->x + ((p_xrect_t)(hBaseWidge))->w - (widgeRectLast->x + widgeRectLast->w); + dXY = ((p_xrect_t)(hBaseWidge))->x + + ((p_xrect_t)(hBaseWidge))->w - (widgeRectLast->x + widgeRectLast->w); } if (widgeRectFirst->x + dXY > ((p_xrect_t)(hBaseWidge))->x) { @@ -162,10 +151,13 @@ PRIVATE uint8_t LIST_WIDGE_MARK_HEAD(ListSlide)(p_xlist_widget_t hBaseWidge, int } } else - { /*����*/ - if (widgeRectLast->y + dXY + widgeRectLast->h < ((p_xrect_t)(hBaseWidge))->y + ((p_xrect_t)(hBaseWidge))->h) + { + if (widgeRectLast->y + dXY + widgeRectLast->h < + ((p_xrect_t)(hBaseWidge))->y + ((p_xrect_t)(hBaseWidge))->h) { - dXY = (((p_xrect_t)(hBaseWidge))->y + ((p_xrect_t)(hBaseWidge))->h) - (widgeRectLast->y + widgeRectLast->h); + dXY = (((p_xrect_t)(hBaseWidge))->y + + ((p_xrect_t)(hBaseWidge))->h) - + (widgeRectLast->y + widgeRectLast->h); } if (widgeRectFirst->y + dXY > ((p_xrect_t)(hBaseWidge))->y) { @@ -174,6 +166,7 @@ PRIVATE uint8_t LIST_WIDGE_MARK_HEAD(ListSlide)(p_xlist_widget_t hBaseWidge, int } widget_base_t *pos; + //!< 改变内部每个组件的位置 list_foreach(pos, &_PToHGroupWidgeType(hBaseWidge)->widgetList.head, widget_node) { p_xrect_t hWidge = (p_xrect_t)_PToHWidgeBaseType(pos); @@ -199,9 +192,10 @@ static void GUITimeoutCb(void *arg) return; } if (_GetListAnimation(hBaseWidge)) - { /*�Ƿ������˶���*/ + { if (!(hBaseWidge->dSP >= -1 && hBaseWidge->dSP <= 1)) { + //!< 滑动listview if (!LIST_WIDGE_MARK_HEAD(ListSlide)(hBaseWidge, hBaseWidge->dSP)) { hBaseWidge->dSP = 0; @@ -266,7 +260,6 @@ PUBLIC void LIST_WIDGE_MARK_HEAD(Paint)(void *hObject) DrawResetArea((p_widget_base_t)hBaseWidge); } -/*�¼��ص�����*/ PUBLIC int8_t LIST_WIDGE_MARK_HEAD(CallBack)(void *hObject, p_msg_t hMsg) { p_xlist_widget_t hBaseWidge = hObject; @@ -284,40 +277,36 @@ PUBLIC int8_t LIST_WIDGE_MARK_HEAD(CallBack)(void *hObject, p_msg_t hMsg) &(_PToHGroupWidgeType(hBaseWidge)->widgeBase.rect))) { int16_t dXY = 0; - /*�����¼�*/ + if (hMsg->msgType == MSG_TOUCH) { switch (hMsg->msgID) { case MSG_TOUCH_PRESS: if (_GetOTN(hBaseWidge)) - { /*����*/ + { hBaseWidge->lastXY = hMsg->msgVal.rect.x; - /*�����˶����Ż��õ��������*/ hBaseWidge->firstXY = hMsg->msgVal.rect.x; } else - { /*����*/ + { hBaseWidge->lastXY = hMsg->msgVal.rect.y; - /*�����˶����Ż��õ��������*/ hBaseWidge->firstXY = hMsg->msgVal.rect.y; } if (_GetListAnimation(hBaseWidge)) { - /*��������˶�������¼��ʱ���µ�ʱ��*/ hBaseWidge->firstTime = (uint16_t)GUIGetTick(); } break; case MSG_TOUCH_MOVE: if (_GetOTN(hBaseWidge)) - { /*����*/ - /*������Ҫƫ�Ƶ�*/ + { dXY = hMsg->msgVal.rect.x - hBaseWidge->lastXY; } else - { /*����*/ + { dXY = hMsg->msgVal.rect.y - hBaseWidge->lastXY; } if (dXY != 0) @@ -329,7 +318,7 @@ PUBLIC int8_t LIST_WIDGE_MARK_HEAD(CallBack)(void *hObject, p_msg_t hMsg) LIST_WIDGE_MARK_HEAD(ListSlide) (hBaseWidge, dXY); if (_GetOTN(hBaseWidge)) - { /*����*/ + { hBaseWidge->lastXY = hMsg->msgVal.rect.x; } else @@ -381,22 +370,22 @@ PUBLIC int8_t LIST_WIDGE_MARK_HEAD(CallBack)(void *hObject, p_msg_t hMsg) return 0; } else - { /*������*/ + { if (_GetSlideState(hBaseWidge)) { if (_GetListAnimation(hBaseWidge)) - { /*��������˶���*/ + { int16_t dis = 0; + if (_GetOTN(hBaseWidge)) - { /*����*/ + { dis = hMsg->msgVal.rect.x - hBaseWidge->firstXY; } else - { /*����*/ + { dis = hMsg->msgVal.rect.y - hBaseWidge->firstXY; } - /*�����ϴβ�ֵ�����ٶ�*/ hBaseWidge->dSP = (dis) / ((uint16_t)((uint16_t)GUIGetTick() - hBaseWidge->firstTime)); if (hBaseWidge->dSP != 0) { diff --git a/xtinygui/src/paint.c b/xtinygui/src/paint.c index 89b2f6eb0e43ae94ccbe9588ef0a1e4ef5ab4105..86d0b68766b25933adc792c171562bc07cf4112b 100644 --- a/xtinygui/src/paint.c +++ b/xtinygui/src/paint.c @@ -20,6 +20,7 @@ #include "GUI_cursor.h" #include "GUI_interface_extern.h" #include +#include /*读点*/ uintColor _GetPixel(int16_t x, int16_t y) @@ -39,6 +40,17 @@ void DrawPixel(uintColor color, int16_t x, int16_t y) int16_t rX = x - hXDesktop->hMemDev->rect.x; int16_t rY = y - hXDesktop->hMemDev->rect.y; + if (rX < 0 || rY < 0) + { + return; + } + + if (rX >= hXDesktop->hMemDev->rect.w || + rY >= hXDesktop->hMemDev->rect.h) + { + return; + } + MemDevDrawPT(hXDesktop->hMemDev, rX, rY, color); #else /*USE_MEM_DEV*/ #if USE_CURSOR @@ -51,6 +63,13 @@ void DrawPixel(uintColor color, int16_t x, int16_t y) #endif /*USE_CURSOR*/ #endif /*USE_MEM_DEV*/ } +void DrawPixelX(uintColor color, int16_t x, int16_t y, int16_t h_lim) +{ + if (y < h_lim) + { + DrawPixel(color, x, y); + } +} /*画一个透明的点*/ void DrawAPixel(uintColor aColor, int16_t x, int16_t y) @@ -674,6 +693,67 @@ uint8_t DrawCutBitmap(void *hObject, p_xrect_t border, p_xbitmap_t hXBitmap) return (uint8_t)1; } +void DrawCircle(void *obj, xpoint_t *center, int radius, uintColor color) +{ + widget_base_t *hWidgeBase = obj; + + int x = hWidgeBase->rect.x + center->x; + int y = hWidgeBase->rect.y + center->y; + int r = radius; + int tx = 0, ty = r, d = 1.25 - r; + + while (tx <= ty) + { + // 利用圆的八分对称性画点 + DrawPixelX(color, x + tx, y + ty, hWidgeBase->rect.y + hWidgeBase->rect.h); + DrawPixelX(color, x + tx, y - ty, hWidgeBase->rect.y + hWidgeBase->rect.h); + DrawPixelX(color, x - tx, y + ty, hWidgeBase->rect.y + hWidgeBase->rect.h); + DrawPixelX(color, x - tx, y - ty, hWidgeBase->rect.y + hWidgeBase->rect.h); + DrawPixelX(color, x + ty, y + tx, hWidgeBase->rect.y + hWidgeBase->rect.h); + DrawPixelX(color, x + ty, y - tx, hWidgeBase->rect.y + hWidgeBase->rect.h); + DrawPixelX(color, x - ty, y + tx, hWidgeBase->rect.y + hWidgeBase->rect.h); + DrawPixelX(color, x - ty, y - tx, hWidgeBase->rect.y + hWidgeBase->rect.h); + + if (d < 0) + d += 2 * tx + 3; + else + d += 2 * (tx - ty) + 5, ty--; + + tx++; + } +} +void DrawLine(void *obj, xpoint_t *st_point, xpoint_t *end_point, uintColor color) +{ + int x1; + int y1; + int x2; + int y2; + p_xrect_t nextCutRect = NULL; + widget_base_t *hWidgeBase = obj; + assert(hWidgeBase); + + x1 = st_point->x + (hWidgeBase->rect.x); + y1 = st_point->y + (hWidgeBase->rect.y); + x2 = end_point->x + (hWidgeBase->rect.x); + y2 = end_point->y + (hWidgeBase->rect.y); + float increx, increy, x, y, length; // 变量定义 + int i; + + if (abs(x2 - x1) > abs(y2 - y1)) // 判断以哪个作增量 + length = abs(x2 - x1); + else + length = abs(y2 - y1); + increx = (x2 - x1) / length; // 设置增量,一个为1,一个为k + increy = (y2 - y1) / length; + x = x1, y = y1; // 起点 + for (i = 1; i <= length; i++) + { + DrawPixelX(color, (int)(x + 0.5), (int)(y + 0.5), + hWidgeBase->rect.y + hWidgeBase->rect.h); // 因为没有半个像素点,所以需要强制转换为整型 + x += increx; // x+增量 + y += increy; // y+增量 + } +} /*矩形剪裁绘制*/ uint8_t DrawCutRect(void *hObject, p_xrect_t hXRECT) { diff --git a/xtinygui/src/paint_cut.c b/xtinygui/src/paint_cut.c index 7d326338679416626af6cfb612a79800ea952e0a..e5ac56239980ac0f9de0244873e7f493fe692289 100644 --- a/xtinygui/src/paint_cut.c +++ b/xtinygui/src/paint_cut.c @@ -13,12 +13,11 @@ #include "gui.h" #include "list.h" #include -extern void fill_rect(int x, int y, int w, int h, int color); +// extern void fill_rect(int x, int y, int w, int h, int color); -xrect_t xResRect; -/*和那个矩形产生了碰撞*/ -p_xrect_t lastRightRect = NULL; -list_t rectCutList = {0}; /*剪裁矩形*/ +static xrect_t xResRect; +static p_xrect_t lastRightRect = NULL; +static list_t rectCutList = {0}; /*剪裁矩形*/ static p_list_t rectItem = NULL; /*临时用*/ static xrect_t bgRect; /*被剪裁的矩形*/ static xpoint_t startPoint; /*初始扫描起点*/ diff --git a/xtinygui/src/xwindows.c b/xtinygui/src/xwindows.c index 448c9c01ffea2beb2c6749a3e6b2a4cb77d1a9c9..9f61dfe7618362ef49b9a1729bc1dcce46dabb4d 100644 --- a/xtinygui/src/xwindows.c +++ b/xtinygui/src/xwindows.c @@ -421,8 +421,8 @@ void WindowsClose(p_win_t hWin) void WindowsMoveTo(p_win_t hWin, int16_t x, int16_t y) { assert(hWin); - int16_t dx; - int16_t dy; + int32_t dx; + int32_t dy; xrect_t lastRect; xrect_t updateRect; diff --git a/xtinygui/src/xwindows_head.c b/xtinygui/src/xwindows_head.c index 883c92bc6c038473be9af351dbe0d1a57f1818c4..8d45b8b531762a504e6803276b1812e3112d1cd4 100644 --- a/xtinygui/src/xwindows_head.c +++ b/xtinygui/src/xwindows_head.c @@ -149,11 +149,6 @@ PUBLIC void WindowsHeadWidgeClose(p_win_head_t hWinHead) { return; } - /*�������ͷŴ����е��ڴ�*/ - - /*�ͷű����е�ռ�õ��ڴ�*/ - - /*���ø���Ĺرպ���*/ GROUP_MARK_HEAD(Close) ((p_group_widget_t)hWinHead); }