Skip to content

Commit b82ea0f

Browse files
committed
feat(ui): 增加拖拽窗口功能并优化渲染方法
1 parent 8e6c03f commit b82ea0f

File tree

4 files changed

+320
-324
lines changed

4 files changed

+320
-324
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package cn.langya.ui.clickgui;
2+
3+
import lombok.Getter;
4+
import lombok.Setter;
5+
6+
/**
7+
* @author LangYa466
8+
* @since 2/15/2025
9+
*/
10+
@Getter
11+
@Setter
12+
public class DragWindow {
13+
private int x, y, width, height;
14+
private boolean dragging = false;
15+
private int dragOffsetX, dragOffsetY;
16+
17+
public DragWindow(int x, int y, int width, int height) {
18+
this.x = x;
19+
this.y = y;
20+
this.width = width;
21+
this.height = height;
22+
}
23+
24+
/**
25+
* 判断鼠标是否在窗口标题区域(高度 headerHeight 内)
26+
*/
27+
public boolean isHoveringHeader(int mouseX, int mouseY, int headerHeight) {
28+
return mouseX >= x && mouseX <= x + width && mouseY >= y && mouseY <= y + headerHeight;
29+
}
30+
31+
/**
32+
* 开始拖拽,并记录初始偏移量
33+
*/
34+
public void startDrag(int mouseX, int mouseY) {
35+
dragging = true;
36+
dragOffsetX = mouseX - x;
37+
dragOffsetY = mouseY - y;
38+
}
39+
40+
/**
41+
* 拖拽中,更新窗口位置
42+
*/
43+
public void drag(int mouseX, int mouseY) {
44+
if (dragging) {
45+
x = mouseX - dragOffsetX;
46+
y = mouseY - dragOffsetY;
47+
}
48+
}
49+
50+
/**
51+
* 停止拖拽
52+
*/
53+
public void stopDrag() {
54+
dragging = false;
55+
}
56+
}

0 commit comments

Comments
 (0)