硬汉嵌入式论坛

 找回密码
 立即注册
查看: 3413|回复: 5
收起左侧

[emWin] emwin 图片显示,选择指定区域显示

[复制链接]

100

主题

94

回帖

394

积分

高级会员

积分
394
发表于 2021-2-18 15:36:01 | 显示全部楼层 |阅读模式
我创建一个win ,在上面显示图1,然后期望:1.不分割这两张图,只用这两张图。
2.点击图1的01区域(艺术字),显示出图2 的01区域(艺术字)效果,其他部分都不变。
3.松开,恢复成图1。
4.  02,03,04,05区域同01区域
请问emwin 如何实现?

图1

图1

图2

图2
回复

使用道具 举报

1万

主题

7万

回帖

11万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
115804
QQ
发表于 2021-2-18 16:45:47 | 显示全部楼层
这个还是将图标裁剪出来比较方便(ps搞这个很容易),再配合按钮自定义回调。
回复

使用道具 举报

42

主题

126

回帖

252

积分

特别照顾组

积分
252
发表于 2021-2-19 09:16:44 | 显示全部楼层
看到迪文科技,觉得你使用的是串口组态屏吧?
回复

使用道具 举报

100

主题

94

回帖

394

积分

高级会员

积分
394
 楼主| 发表于 2021-2-19 10:59:27 | 显示全部楼层
eric2013 发表于 2021-2-18 16:45
这个还是将图标裁剪出来比较方便(ps搞这个很容易),再配合按钮自定义回调。
  1. void copy_part_of_bitmap(int x, int y, const GUI_BITMAP *bmp, int x0, int y0, int width, int height)
  2. {
  3.   GUI_RECT rect;

  4.   rect.x0 = x;
  5.   rect.y0 = y;
  6.   rect.x1 = x + width - 1;
  7.   rect.y1 = y + height - 1;
  8.   GUI_SetClipRect(&rect);
  9.   GUI_DrawBitmap(bmp, x0, y0);
  10.   GUI_SetClipRect(NULL);
  11. }

  12. static void _CbHome(WM_MESSAGE * pMsg)
  13. {
  14.         WM_HWIN hWin;
  15.         hWin = pMsg->hWin;
  16.         switch (pMsg->MsgId)
  17.         {
  18.                 case WM_PAINT:
  19.                 {
  20.                         printf("WM_PAINT:_CbHome\n");
  21.                         copy_part_of_bitmap(g_tBmpPara.iX,g_tBmpPara.iY,g_tBmpPara.pBmp,g_tBmpPara.iX0,g_tBmpPara.iY0,g_tBmpPara.iWidth,g_tBmpPara.iHeight);
  22.                         //GUI_DrawBitmap(g_tBmpPara.pBmp, 160, 93);

  23.                         break;
  24.                 }
  25.                 default:
  26.                         BUTTON_Callback(pMsg);
  27.         }
  28. }

  29. static void _CbRvDmHome(WM_MESSAGE * pMsg)
  30. {
  31.         WM_HWIN hItem;

  32.     switch (pMsg->MsgId)
  33.     {
  34.             case WM_PAINT:
  35.             {
  36. //                        GUI_DrawBitmap(&(g_tRwDm.hPic[16]), 0, 0);
  37.                         //copy_part_of_bitmap(g_tBmpPara.iX,g_tBmpPara.iY,g_tBmpPara.pBmp,g_tBmpPara.iX0,g_tBmpPara.iY0,g_tBmpPara.iWidth,g_tBmpPara.iHeight);
  38.                         break;
  39.             }
  40.         case WM_INIT_DIALOG:
  41.                         g_tBmpPara.pBmp = &(g_tRwDm.hPic[16]);
  42.                         g_tBmpPara.iX = 44;
  43.                         g_tBmpPara.iY = 144;
  44.                         g_tBmpPara.iX0 = 0;
  45.                         g_tBmpPara.iY0 = 0;
  46.                         g_tBmpPara.iWidth  = 389;
  47.                         g_tBmpPara.iHeight = 186;

  48.                         hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_2);
  49.                         WM_SetCallback(hItem, _CbHome);
  50.                        
  51. #if 0
  52.                         hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_3);
  53.                         WM_SetCallback(hItem, _CbHome);
  54. #endif
  55.             break;

  56.         case WM_NOTIFY_PARENT:
  57.             switch(WM_GetId(pMsg->hWinSrc))
  58.             {
  59.                 case ID_BUTTON_2:
  60.                                         switch(pMsg->Data.v)
  61.                                         {
  62.                                                 case WM_NOTIFICATION_CLICKED:
  63.                                                         g_tBmpPara.pBmp = &(g_tRwDm.hPic[16]);
  64.                                                         g_tBmpPara.iX = 0;
  65.                                                         g_tBmpPara.iY = 86;
  66.                                                         g_tBmpPara.iX0 = 0;
  67.                                                         g_tBmpPara.iY0 = 0;
  68.                                                         g_tBmpPara.iWidth  = 389;
  69.                                                         g_tBmpPara.iHeight = 186;
  70.                                                         printf("WM_NOTIFY_PARENT:ID_BUTTON_2:WM_NOTIFICATION_CLICKED\n");
  71.                                                         break;
  72.                                                 case WM_NOTIFICATION_RELEASED:
  73.                                                         g_tBmpPara.pBmp = &(g_tRwDm.hPic[17]);
  74.                                                         g_tBmpPara.iX = 0;
  75.                                                         g_tBmpPara.iY = 0;
  76.                                                         g_tBmpPara.iX0 = 0;
  77.                                                         g_tBmpPara.iY0 = 0;
  78.                                                         g_tBmpPara.iWidth  = 389;
  79.                                                         g_tBmpPara.iHeight = 186;
  80.                                                         printf("WM_NOTIFY_PARENT:ID_BUTTON_2:WM_NOTIFICATION_RELEASED\n");
  81.                                                         break;
  82.                                         }
  83.                         break;
  84.             }
  85.                         break;
  86.                        
  87.         default:
  88.             WM_DefaultProc(pMsg);
  89.             break;
  90.       }
  91. }
复制代码
回复

使用道具 举报

100

主题

94

回帖

394

积分

高级会员

积分
394
 楼主| 发表于 2021-2-19 11:05:27 | 显示全部楼层
eric2013 发表于 2021-2-18 16:45
这个还是将图标裁剪出来比较方便(ps搞这个很容易),再配合按钮自定义回调。
  1. void copy_part_of_bitmap(int x, int y, const GUI_BITMAP *bmp, int x0, int y0, int width, int height)
  2. {
  3.   GUI_RECT rect;

  4.   rect.x0 = x;
  5.   rect.y0 = y;
  6.   rect.x1 = x + width - 1;
  7.   rect.y1 = y + height - 1;
  8.   GUI_SetClipRect(&rect);
  9.   GUI_DrawBitmap(bmp, x0, y0);
  10.   GUI_SetClipRect(NULL);
  11. }

  12. static void _CbHome(WM_MESSAGE * pMsg)
  13. {
  14.         WM_HWIN hWin;
  15.         hWin = pMsg->hWin;
  16.         switch (pMsg->MsgId)
  17.         {
  18.                 case WM_PAINT:
  19.                 {
  20.                         printf("WM_PAINT:_CbHome\n");
  21.                         copy_part_of_bitmap(g_tBmpPara.iX,g_tBmpPara.iY,g_tBmpPara.pBmp,g_tBmpPara.iX0,g_tBmpPara.iY0,g_tBmpPara.iWidth,g_tBmpPara.iHeight);
  22.                         //GUI_DrawBitmap(g_tBmpPara.pBmp, 160, 93);

  23.                         break;
  24.                 }
  25.                 default:
  26.                         BUTTON_Callback(pMsg);
  27.         }
  28. }

  29. static void _CbRvDmHome(WM_MESSAGE * pMsg)
  30. {
  31.         WM_HWIN hItem;

  32.     switch (pMsg->MsgId)
  33.     {
  34.             case WM_PAINT:
  35.             {
  36. //                        GUI_DrawBitmap(&(g_tRwDm.hPic[16]), 0, 0);
  37.                         //copy_part_of_bitmap(g_tBmpPara.iX,g_tBmpPara.iY,g_tBmpPara.pBmp,g_tBmpPara.iX0,g_tBmpPara.iY0,g_tBmpPara.iWidth,g_tBmpPara.iHeight);
  38.                         break;
  39.             }
  40.         case WM_INIT_DIALOG:
  41.                         g_tBmpPara.pBmp = &(g_tRwDm.hPic[16]);
  42.                         g_tBmpPara.iX = 44;
  43.                         g_tBmpPara.iY = 144;
  44.                         g_tBmpPara.iX0 = 0;
  45.                         g_tBmpPara.iY0 = 0;
  46.                         g_tBmpPara.iWidth  = 389;
  47.                         g_tBmpPara.iHeight = 186;

  48.                         hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_2);
  49.                         WM_SetCallback(hItem, _CbHome);
  50.                        
  51. #if 0
  52.                         hItem = WM_GetDialogItem(pMsg->hWin, ID_BUTTON_3);
  53.                         WM_SetCallback(hItem, _CbHome);
  54. #endif
  55.             break;

  56.         case WM_NOTIFY_PARENT:
  57.             switch(WM_GetId(pMsg->hWinSrc))
  58.             {
  59.                 case ID_BUTTON_2:
  60.                                         switch(pMsg->Data.v)
  61.                                         {
  62.                                                 case WM_NOTIFICATION_CLICKED:
  63.                                                         g_tBmpPara.pBmp = &(g_tRwDm.hPic[16]);
  64.                                                         g_tBmpPara.iX = 0;
  65.                                                         g_tBmpPara.iY = 86;
  66.                                                         g_tBmpPara.iX0 = 0;
  67.                                                         g_tBmpPara.iY0 = 0;
  68.                                                         g_tBmpPara.iWidth  = 389;
  69.                                                         g_tBmpPara.iHeight = 186;
  70.                                                         printf("WM_NOTIFY_PARENT:ID_BUTTON_2:WM_NOTIFICATION_CLICKED\n");
  71.                                                         break;
  72.                                                 case WM_NOTIFICATION_RELEASED:
  73.                                                         g_tBmpPara.pBmp = &(g_tRwDm.hPic[17]);
  74.                                                         g_tBmpPara.iX = 0;
  75.                                                         g_tBmpPara.iY = 0;
  76.                                                         g_tBmpPara.iX0 = 0;
  77.                                                         g_tBmpPara.iY0 = 0;
  78.                                                         g_tBmpPara.iWidth  = 389;
  79.                                                         g_tBmpPara.iHeight = 186;
  80.                                                         printf("WM_NOTIFY_PARENT:ID_BUTTON_2:WM_NOTIFICATION_RELEASED\n");
  81.                                                         break;
  82.                                         }
  83.                         break;
  84.             }
  85.                         break;
  86.                        
  87.         default:
  88.             WM_DefaultProc(pMsg);
  89.             break;
  90.       }
  91. }
复制代码



我用代码实现图片切割,将图片显示在按钮上。按下时g_tBmpPara.iY = 86;我想把图片往上挪动一下,但是效果与我想法不一样,图片不仅没有挪动,而且按钮上半部分变成白屏,其他地方不变(同样的方法在win 上可以正常实现)。百思不得其解,请指教?
回复

使用道具 举报

100

主题

94

回帖

394

积分

高级会员

积分
394
 楼主| 发表于 2021-2-19 11:06:12 | 显示全部楼层
xlzhu 发表于 2021-2-19 09:16
看到迪文科技,觉得你使用的是串口组态屏吧?

我们用的RGB 屏幕。这个图片只是借用一下。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|Archiver|手机版|硬汉嵌入式论坛

GMT+8, 2025-5-20 07:04 , Processed in 0.493554 second(s), 27 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2023, Tencent Cloud.

快速回复 返回顶部 返回列表