From 48502af7bde19a680e67707e50653f236f65d6a9 Mon Sep 17 00:00:00 2001 From: cirno <13643614+healghost@user.noreply.gitee.com> Date: Fri, 21 Nov 2025 19:43:54 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E7=82=B9=E5=87=BB=E5=9B=BE=E7=89=87?= =?UTF-8?q?=EF=BC=8C=E5=9B=BE=E7=89=87=E8=83=BD=E5=A4=9F=E8=A2=AB=E9=80=89?= =?UTF-8?q?=E4=B8=AD=EF=BC=8C=E5=85=89=E6=A0=87=E7=9A=84=E5=BD=A2=E6=80=81?= =?UTF-8?q?=E5=8F=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- devel/202_70.md | 43 +++++++++++++++++++++++++++++++ src/Edit/Interface/edit_mouse.cpp | 15 +++++++++++ 2 files changed, 58 insertions(+) create mode 100644 devel/202_70.md diff --git a/devel/202_70.md b/devel/202_70.md new file mode 100644 index 000000000..1b8070819 --- /dev/null +++ b/devel/202_70.md @@ -0,0 +1,43 @@ +# [202_70] 实现图片点击选中和光标形态变化 + +## 如何测试 +1. 打开包含图片的文档 +2. 将鼠标悬停在图片上,观察光标是否变成手型 +3. 选中后移动鼠标,观察光标是否保持手型 +4. 点击图片外部其他地方,观察选中是否取消,光标是否恢复正常 + +## 2025/11/21 + +### What +实现了点击图片选中图片并改变光标形态的功能。具体包括: +1. 鼠标悬停在图片上时,光标变为手型 +2. 点击图片时,图片被正确选中并高亮显示 +3. 选中图片状态下,光标保持手型 +4. 与现有超链接功能保持兼容 + +### Why +提升用户体验,让图片成为可交互的元素。用户可以直观地知道图片是可点击的,并且能够正确选中图片进行进一步操作(如复制、删除等)。 + +### How +在 `edit_mouse.cpp` 中进行了以下修改: + +1. **鼠标悬停检测**:在 `mouse_any()` 函数中添加图片检测逻辑 + ```cpp + bool hovering_image = false; + if (type == "move") { + path cp = path_up (tree_path (path (), x, y, 0)); + tree current_tree = subtree (et, cp); + if (is_func (current_tree, IMAGE)) { + hovering_image = true; + } + } + ``` + +2. **光标形态设置**:更新光标设置逻辑,支持悬停状态的手型光标 + ```cpp + if (hovering_hlink) set_cursor_style ("pointing_hand"); + else if (hovering_image) set_cursor_style ("pointing_hand"); + else set_cursor_style ("normal"); + ``` + + diff --git a/src/Edit/Interface/edit_mouse.cpp b/src/Edit/Interface/edit_mouse.cpp index 02b9befdf..c4a3ef1fd 100644 --- a/src/Edit/Interface/edit_mouse.cpp +++ b/src/Edit/Interface/edit_mouse.cpp @@ -567,6 +567,19 @@ edit_interface_rep::mouse_any (string type, SI x, SI y, int mods, time_t t, if ((!move_like) || (is_attached (this) && !check_event (MOTION_EVENT))) update_mouse_loci (); + bool hovering_image= false; + + if (type == "move") { + // 检测鼠标是否在图片上 + path cp = path_up (tree_path (path (), x, y, 0)); + tree current_tree= subtree (et, cp); + + // 检查当前元素是否是图片 + if (is_func (current_tree, IMAGE)) { + hovering_image= true; + } + } + bool hovering_hlink= false; if (!is_nil (mouse_ids) && type == "move") { notify_change (THE_FREEZE); @@ -582,6 +595,8 @@ edit_interface_rep::mouse_any (string type, SI x, SI y, int mods, time_t t, } } if (hovering_hlink) set_cursor_style ("pointing_hand"); + else if (hovering_image) + set_cursor_style ("pointing_hand"); // 图片时也显示手型光标 else set_cursor_style ("normal"); if (type == "move") mouse_message ("move", x, y); -- Gitee From d39e5b582f5b90bcfaa59edaab11498a57e989f4 Mon Sep 17 00:00:00 2001 From: cirno <13643614+healghost@user.noreply.gitee.com> Date: Mon, 24 Nov 2025 10:18:48 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E7=82=B9=E5=87=BB=E5=9B=BE=E7=89=87?= =?UTF-8?q?=EF=BC=8C=E5=85=89=E6=A0=87=E5=BD=A2=E6=80=81=E5=8F=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- devel/{202_70.md => 201_35.md} | 59 +++++++++++++++++++++++-------- src/Edit/Interface/edit_mouse.cpp | 35 +++++++++++++++++- 2 files changed, 78 insertions(+), 16 deletions(-) rename devel/{202_70.md => 201_35.md} (34%) diff --git a/devel/202_70.md b/devel/201_35.md similarity index 34% rename from devel/202_70.md rename to devel/201_35.md index 1b8070819..9a5e38792 100644 --- a/devel/202_70.md +++ b/devel/201_35.md @@ -1,36 +1,65 @@ -# [202_70] 实现图片点击选中和光标形态变化 +# [201_35] 实现图片点击选中和光标形态变化 ## 如何测试 1. 打开包含图片的文档 2. 将鼠标悬停在图片上,观察光标是否变成手型 -3. 选中后移动鼠标,观察光标是否保持手型 -4. 点击图片外部其他地方,观察选中是否取消,光标是否恢复正常 +3. 点击图片外部其他地方,观察选中是否取消,光标是否恢复正常 -## 2025/11/21 +## 2025/11/24 ### What 实现了点击图片选中图片并改变光标形态的功能。具体包括: 1. 鼠标悬停在图片上时,光标变为手型 -2. 点击图片时,图片被正确选中并高亮显示 -3. 选中图片状态下,光标保持手型 -4. 与现有超链接功能保持兼容 + ### Why -提升用户体验,让图片成为可交互的元素。用户可以直观地知道图片是可点击的,并且能够正确选中图片进行进一步操作(如复制、删除等)。 +提升用户体验,让图片成为可交互的元素。用户可以直观地知道图片是可点击的。 ### How 在 `edit_mouse.cpp` 中进行了以下修改: 1. **鼠标悬停检测**:在 `mouse_any()` 函数中添加图片检测逻辑 ```cpp - bool hovering_image = false; if (type == "move") { - path cp = path_up (tree_path (path (), x, y, 0)); - tree current_tree = subtree (et, cp); - if (is_func (current_tree, IMAGE)) { - hovering_image = true; - } - } + // 检测鼠标是否在图片上 + path cp = path_up (tree_path (path (), x, y, 0)); + tree current_tree= subtree (et, cp); + + // 检查当前元素是否是图片 + if (is_func (current_tree, IMAGE)) { + try { + // 使用更安全的方法获取图片盒子的位置信息 + bool found_flag = false; + path box_path = eb->find_box_path (x, y, 0, false, found_flag); + + if (found_flag && !is_nil (box_path)) { + // 获取对应路径的盒子 + box img_box = eb[box_path]; + + if (!is_nil (img_box)) { + // 使用盒子的坐标信息 + SI left_x = img_box->x1; + SI bottom_y = img_box->y1; + SI right_x = img_box->x2; + SI top_y = img_box->y2; + + // 检查鼠标是否在图片区域内 + if(x >= left_x && x <= right_x && y >= bottom_y && y <= top_y) { + hovering_image = true; + } + } else { + // 如果无法获取盒子,至少标记鼠标在图片上 + hovering_image = true; + } + } else { + // 如果无法获取盒子路径,至少标记鼠标在图片上 + hovering_image = true; + } + } catch (...) { + // 如果出现任何异常,至少标记鼠标在图片上 + hovering_image = true; + } + } ``` 2. **光标形态设置**:更新光标设置逻辑,支持悬停状态的手型光标 diff --git a/src/Edit/Interface/edit_mouse.cpp b/src/Edit/Interface/edit_mouse.cpp index c4a3ef1fd..43a44defc 100644 --- a/src/Edit/Interface/edit_mouse.cpp +++ b/src/Edit/Interface/edit_mouse.cpp @@ -576,7 +576,40 @@ edit_interface_rep::mouse_any (string type, SI x, SI y, int mods, time_t t, // 检查当前元素是否是图片 if (is_func (current_tree, IMAGE)) { - hovering_image= true; + try { + // 使用更安全的方法获取图片盒子的位置信息 + bool found_flag= false; + path box_path = eb->find_box_path (x, y, 0, false, found_flag); + + if (found_flag && !is_nil (box_path)) { + // 获取对应路径的盒子 + box img_box= eb[box_path]; + + if (!is_nil (img_box)) { + // 使用盒子的坐标信息 + SI left_x = img_box->x1; + SI bottom_y= img_box->y1; + SI right_x = img_box->x2; + SI top_y = img_box->y2; + + // 检查鼠标是否在图片区域内 + if (x >= left_x && x <= right_x && y >= bottom_y && y <= top_y) { + hovering_image= true; + } + } + else { + // 如果无法获取盒子,至少标记鼠标在图片上 + hovering_image= true; + } + } + else { + // 如果无法获取盒子路径,至少标记鼠标在图片上 + hovering_image= true; + } + } catch (...) { + // 如果出现任何异常,至少标记鼠标在图片上 + hovering_image= true; + } } } -- Gitee