マウス対応の追加

This commit is contained in:
2026-05-03 19:10:35 +09:00
parent 7bd77a0da6
commit 07d377fbe8
5 changed files with 53 additions and 2 deletions

View File

@@ -101,6 +101,10 @@ HexEditor::HexEditor(const std::string &filename)
raw();
start_color();
// マウス対応
mousemask(ALL_MOUSE_EVENTS | REPORT_MOUSE_POSITION, nullptr);
isMouse = true;
init_pair(1, COLOR_BLACK, COLOR_WHITE); // カーソル
init_pair(2, COLOR_BLACK, COLOR_GREEN); // 変更
init_pair(3, COLOR_BLACK, COLOR_MAGENTA); // 普通
@@ -182,7 +186,7 @@ void HexEditor::highlightcol(size_t i, size_t row, uint8_t byte) {
void HexEditor::topbar() {
int colorPair = 3;
std::string status = "Hexagon 1.1.0";
std::string status = "Hexagon 1.2.0";
if (!headerType.empty()) status += " | FILETYPE: " + headerType;
std::wstring wstatus(status.begin(), status.end());
@@ -758,6 +762,39 @@ void HexEditor::handleReplace() {
render();
}
void HexEditor::handleMouse() {
MEVENT event;
if (getmouse(&event) != OK) return;
if (!(event.bstate & BUTTON1_PRESSED)) return;
int mx = event.x;
int my = event.y;
if (my == 0 || my == rows - 1) return;
if (my >= 1 && my < rows - 2 && mx < cols / 2) {
// HEXパネル
int panelRow = my - 1;
int panelCol = mx;
if (panelCol < 10) return;
int i = (panelCol - 10) / 3;
size_t offset = dpOffset + panelRow * bpr + i;
if (offset < buf.size()) {
curPos = offset;
render();
}
} else if (my >= 1 && my < rows - 2 && mx >= cols / 2) {
// ASCIIパネル
int panelRow = my - 1;
int i = mx - cols / 2;
size_t offset = dpOffset + panelRow * bpr + i;
if (offset < buf.size()) {
curPos = offset;
render();
}
}
}
void HexEditor::undo() {
if (undoStack.empty()) {
statusMode = Status_Error;
@@ -883,6 +920,9 @@ void HexEditor::input() {
handleSave();
if (statusMode == Status_Error) statusMode = Status_Normal;
}
} else if (ch == KEY_MOUSE) {
handleMouse();
continue;
}
// 画面の動き