win32 gui: mouse drag
initial implementation for left mouse drag
This commit is contained in:
parent
22ddaef78f
commit
21a7106fe3
2 changed files with 68 additions and 13 deletions
|
@ -274,6 +274,39 @@ pub fn process_renderer_event(self: *Self, msg: []const u8) !void {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
{
|
||||||
|
var args: struct {
|
||||||
|
pos: MousePos,
|
||||||
|
button_id: u8,
|
||||||
|
} = undefined;
|
||||||
|
if (try cbor.match(msg, .{
|
||||||
|
cbor.any,
|
||||||
|
"D",
|
||||||
|
cbor.extract(&args.button_id),
|
||||||
|
cbor.extract(&args.pos.col),
|
||||||
|
cbor.extract(&args.pos.row),
|
||||||
|
cbor.extract(&args.pos.xoffset),
|
||||||
|
cbor.extract(&args.pos.yoffset),
|
||||||
|
})) {
|
||||||
|
var buf: [200]u8 = undefined;
|
||||||
|
if (self.dispatch_mouse_drag) |f| f(
|
||||||
|
self.handler_ctx,
|
||||||
|
@intCast(args.pos.row),
|
||||||
|
@intCast(args.pos.col),
|
||||||
|
fmtmsg(&buf, .{
|
||||||
|
"D",
|
||||||
|
input.event.press,
|
||||||
|
args.button_id,
|
||||||
|
input.utils.button_id_string(@enumFromInt(args.button_id)),
|
||||||
|
args.pos.col,
|
||||||
|
args.pos.row,
|
||||||
|
args.pos.xoffset,
|
||||||
|
args.pos.yoffset,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
return error.UnexpectedRendererEvent;
|
return error.UnexpectedRendererEvent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -588,6 +588,16 @@ pub fn fmtmsg(buf: []u8, value: anytype) []const u8 {
|
||||||
return buf[0..fbs.pos];
|
return buf[0..fbs.pos];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const MouseFlags = packed struct(u8) {
|
||||||
|
left_down: bool,
|
||||||
|
right_down: bool,
|
||||||
|
shift_down: bool,
|
||||||
|
control_down: bool,
|
||||||
|
middle_down: bool,
|
||||||
|
xbutton1_down: bool,
|
||||||
|
xbutton2_down: bool,
|
||||||
|
_: bool,
|
||||||
|
};
|
||||||
fn sendMouse(
|
fn sendMouse(
|
||||||
hwnd: win32.HWND,
|
hwnd: win32.HWND,
|
||||||
kind: enum {
|
kind: enum {
|
||||||
|
@ -597,6 +607,7 @@ fn sendMouse(
|
||||||
right_down,
|
right_down,
|
||||||
right_up,
|
right_up,
|
||||||
},
|
},
|
||||||
|
wparam: win32.WPARAM,
|
||||||
lparam: win32.LPARAM,
|
lparam: win32.LPARAM,
|
||||||
) void {
|
) void {
|
||||||
const point = ddui.pointFromLparam(lparam);
|
const point = ddui.pointFromLparam(lparam);
|
||||||
|
@ -607,14 +618,25 @@ fn sendMouse(
|
||||||
};
|
};
|
||||||
const cell = CellPos.init(cell_size, point.x, point.y);
|
const cell = CellPos.init(cell_size, point.x, point.y);
|
||||||
switch (kind) {
|
switch (kind) {
|
||||||
.move => state.pid.send(.{
|
.move => {
|
||||||
|
const flags: MouseFlags = @bitCast(@as(u8, @intCast(0xff & wparam)));
|
||||||
|
if (flags.left_down) state.pid.send(.{
|
||||||
|
"RDR",
|
||||||
|
"D",
|
||||||
|
@intFromEnum(input.mouse.BUTTON1),
|
||||||
|
cell.cell.x,
|
||||||
|
cell.cell.y,
|
||||||
|
cell.offset.x,
|
||||||
|
cell.offset.y,
|
||||||
|
}) catch |e| onexit(e) else state.pid.send(.{
|
||||||
"RDR",
|
"RDR",
|
||||||
"M",
|
"M",
|
||||||
cell.cell.x,
|
cell.cell.x,
|
||||||
cell.cell.y,
|
cell.cell.y,
|
||||||
cell.offset.x,
|
cell.offset.x,
|
||||||
cell.offset.y,
|
cell.offset.y,
|
||||||
}) catch |e| onexit(e),
|
}) catch |e| onexit(e);
|
||||||
|
},
|
||||||
else => |b| state.pid.send(.{
|
else => |b| state.pid.send(.{
|
||||||
"RDR",
|
"RDR",
|
||||||
"B",
|
"B",
|
||||||
|
@ -953,23 +975,23 @@ fn WndProc(
|
||||||
|
|
||||||
switch (msg) {
|
switch (msg) {
|
||||||
win32.WM_MOUSEMOVE => {
|
win32.WM_MOUSEMOVE => {
|
||||||
sendMouse(hwnd, .move, lparam);
|
sendMouse(hwnd, .move, wparam, lparam);
|
||||||
return 0;
|
return 0;
|
||||||
},
|
},
|
||||||
win32.WM_LBUTTONDOWN => {
|
win32.WM_LBUTTONDOWN => {
|
||||||
sendMouse(hwnd, .left_down, lparam);
|
sendMouse(hwnd, .left_down, wparam, lparam);
|
||||||
return 0;
|
return 0;
|
||||||
},
|
},
|
||||||
win32.WM_LBUTTONUP => {
|
win32.WM_LBUTTONUP => {
|
||||||
sendMouse(hwnd, .left_up, lparam);
|
sendMouse(hwnd, .left_up, wparam, lparam);
|
||||||
return 0;
|
return 0;
|
||||||
},
|
},
|
||||||
win32.WM_RBUTTONDOWN => {
|
win32.WM_RBUTTONDOWN => {
|
||||||
sendMouse(hwnd, .right_down, lparam);
|
sendMouse(hwnd, .right_down, wparam, lparam);
|
||||||
return 0;
|
return 0;
|
||||||
},
|
},
|
||||||
win32.WM_RBUTTONUP => {
|
win32.WM_RBUTTONUP => {
|
||||||
sendMouse(hwnd, .right_up, lparam);
|
sendMouse(hwnd, .right_up, wparam, lparam);
|
||||||
return 0;
|
return 0;
|
||||||
},
|
},
|
||||||
win32.WM_MOUSEWHEEL => {
|
win32.WM_MOUSEWHEEL => {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue