diff --git a/devel/202_70.md b/devel/202_70.md new file mode 100644 index 0000000000000000000000000000000000000000..1b80708191338942c417505b15f994dde8fcb9c2 --- /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 02b9befdf47e1e1fba0e763a1dc541fb1ff55dd0..5d049ce6d51ca74a8e76464e84ccd9e00ec17792 100644 --- a/src/Edit/Interface/edit_mouse.cpp +++ b/src/Edit/Interface/edit_mouse.cpp @@ -19,6 +19,7 @@ #include "sys_utils.hpp" #include "tm_buffer.hpp" #include "tm_timer.hpp" +#include "init_glue_l5.hpp" #include #include @@ -521,8 +522,9 @@ detect_right_drag (void* handle, string type, SI x, SI y, time_t t, int m, void edit_interface_rep::mouse_any (string type, SI x, SI y, int mods, time_t t, array data) { - // cout << "Mouse any " << type << ", " << x << ", " << y << "; " << mods << - // ", " << t << ", " << data << "\n"; + cout << "\nMouse any " << type << ", " << x << ", " << y << "; " << mods << ", " << t << ", " << data << "\n"; + cout << "last_x: " << last_x << LF; + cout << "last_y: " << last_y << LF; if (is_nil (eb)) return; if (t < last_t && (last_x != 0 || last_y != 0 || last_t != 0)) { // cout << "Ignored " << type << ", " << x << ", " << y << "; " << mods << @@ -567,6 +569,27 @@ 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)) { + path p = reverse (obtain_ip (current_tree)); + selection sel= search_selection (p * start (current_tree), p * end (current_tree)); + rectangle selr= least_upper_bound (sel->rs); + + cout << "x1: " << selr->x1 << " y1: " << selr->y1 << " x2: " << selr->x2 << " y2: " << selr->y2; + if (last_x >= selr->x1 && last_y >= selr->y1 && last_x <= selr->x2 && last_y <= selr->y2) { + hovering_image= true; + } + } + } + bool hovering_hlink= false; if (!is_nil (mouse_ids) && type == "move") { notify_change (THE_FREEZE); @@ -582,6 +605,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); diff --git a/src/Scheme/L5/init_glue_l5.hpp b/src/Scheme/L5/init_glue_l5.hpp index b4762524aad9f687c60db3ac786b2b0e0ed9a8d9..4780a9d7ec5b960c49318bb430de136b411e58c8 100644 --- a/src/Scheme/L5/init_glue_l5.hpp +++ b/src/Scheme/L5/init_glue_l5.hpp @@ -12,6 +12,10 @@ #ifndef INIT_GLUE_L5_HPP #define INIT_GLUE_L5_HPP +#include "array.hpp" +#include "tree.hpp" + void initialize_glue_l5 (); +array get_bounding_rectangle (tree t); #endif