Skip to content

Commit

Permalink
Small Update
Browse files Browse the repository at this point in the history
  • Loading branch information
isHarryh committed Feb 13, 2024
1 parent 17ceb23 commit 903fb96
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 49 deletions.
85 changes: 41 additions & 44 deletions core/src/cn/harryh/arkpets/ArkPets.java
Original file line number Diff line number Diff line change
Expand Up @@ -182,49 +182,43 @@ public boolean touchDown(int screenX, int screenY, int pointer, int button) {
if (!isMouseAtSolidPixel()) {
// Transfer mouse event
RelativeWindowPosition rwp = getRelativeWindowPositionAt(screenX, screenY);
if (rwp != null) {
int msg = switch (button) {
if (rwp != null)
rwp.sendMouseEvent(switch (button) {
case Input.Buttons.LEFT -> HWndCtrl.WM_LBUTTONDOWN;
case Input.Buttons.RIGHT -> HWndCtrl.WM_RBUTTONDOWN;
case Input.Buttons.MIDDLE -> HWndCtrl.WM_MBUTTONDOWN;
default -> 0;
};
if (msg != 0)
rwp.sendMouseEvent(msg);
}
});
} else {
if (button == Input.Buttons.LEFT) {
Logger.debug("Status Msg", "FPS" + Gdx.graphics.getFramesPerSecond() + ", Heap" + (int) Math.ceil((Gdx.app.getJavaHeap() >> 10) / 1024f) + "MB");
// Left Click: Play the specified animation
changeAnimation(behavior.clickStart());
tray.hideDialog();
return true;
} else if (button == Input.Buttons.RIGHT) {
// Toggle tray dialog:
tray.toggleDialog((int) (plane.getX() + screenX), (int) (-plane.getY() - WD_H));
return true;
// Right Click: Toggle the menu
tray.toggleDialog((int)(plane.getX() + screenX), (int)(-plane.getY() - WD_H));
}
}
}
return false;
return true;
}

@Override
public boolean touchDragged(int screenX, int screenY, int pointer) {
// Logger.debug("Input", "Dragged to " + screenX + ", " + screenY);
if (!isMouseAtSolidPixel()) {
// Transfer mouse event
RelativeWindowPosition rwp = getRelativeWindowPositionAt(screenX, screenY);
if (rwp != null)
rwp.sendMouseEvent(HWndCtrl.WM_MOUSEMOVE);
} else {
mouse_drag = true;
int t = (int) Math.signum(screenX - mouse_pos.x);
mouse_intention_x = t == 0 ? mouse_intention_x : t;
int x = (int) (windowPosition.now().x + screenX - mouse_pos.x);
int y = (int) (windowPosition.now().y + screenY - mouse_pos.y);
plane.changePosition(Gdx.graphics.getDeltaTime(), x, -(WD_H + y));
windowPosition.setToEnd();
return true;
Logger.debug("Input", "Dragged to " + screenX + ", " + screenY);
if (pointer <= 0) {
if (isMouseAtSolidPixel()) {
mouse_drag = true;
int t = (int)Math.signum(screenX - mouse_pos.x);
mouse_intention_x = t == 0 ? mouse_intention_x : t;
// Update window position
int x = (int)(windowPosition.now().x + screenX - mouse_pos.x);
int y = (int)(windowPosition.now().y + screenY - mouse_pos.y);
plane.changePosition(Gdx.graphics.getDeltaTime(), x, -(WD_H + y));
windowPosition.setToEnd();
tray.hideDialog();
return true;
}
}
return false;
}
Expand All @@ -234,20 +228,8 @@ public boolean touchUp(int screenX, int screenY, int pointer, int button) {
Logger.debug("Input", "Click- Btn " + button +" @ " + screenX + ", " + screenY);
mouse_pos.set(screenX, screenY);
if (pointer <= 0) {
if (!isMouseAtSolidPixel()) {
// Transfer mouse event
RelativeWindowPosition rwp = getRelativeWindowPositionAt(screenX, screenY);
if (rwp != null) {
int msg = switch (button) {
case Input.Buttons.LEFT -> HWndCtrl.WM_LBUTTONUP;
case Input.Buttons.RIGHT -> HWndCtrl.WM_RBUTTONUP;
case Input.Buttons.MIDDLE -> HWndCtrl.WM_MBUTTONUP;
default -> 0;
};
if (msg != 0)
rwp.sendMouseEvent(msg);
}
} else if (mouse_drag) {
if (mouse_drag) {
// Update the z-axis of the character
cha.position.reset(cha.position.end().x, cha.position.end().y, mouse_intention_x);
if (cha.getPlaying() != null && cha.getPlaying().mobility() != 0) {
AnimData anim = cha.getPlaying();
Expand All @@ -257,8 +239,20 @@ public boolean touchUp(int screenX, int screenY, int pointer, int button) {
AnimData anim = tray.keepAnim;
tray.keepAnim = anim.derive(anim.offsetY(), Math.abs(anim.mobility()) * mouse_intention_x);
}
} else if (button == Input.Buttons.LEFT) {
} else if (!isMouseAtSolidPixel()) {
// Transfer mouse event
RelativeWindowPosition rwp = getRelativeWindowPositionAt(screenX, screenY);
if (rwp != null)
rwp.sendMouseEvent(switch (button) {
case Input.Buttons.LEFT -> HWndCtrl.WM_LBUTTONUP;
case Input.Buttons.RIGHT -> HWndCtrl.WM_RBUTTONUP;
case Input.Buttons.MIDDLE -> HWndCtrl.WM_MBUTTONUP;
default -> 0;
});
} else if (button == Input.Buttons.LEFT) {
// Left Click: Play the specified animation
changeAnimation(behavior.clickEnd());
tray.hideDialog();
}
}
mouse_drag = false;
Expand All @@ -278,6 +272,7 @@ public boolean keyUp(int keycode) {
@Override
public boolean keyTyped(char character) {
Logger.debug("Plane Debug Msg", plane.getDebugMsg());
Logger.debug("Status Msg", "FPS" + Gdx.graphics.getFramesPerSecond() + ", Heap" + (int) Math.ceil((Gdx.app.getJavaHeap() >> 10) / 1024f) + "MB");
return false;
}

Expand Down Expand Up @@ -516,8 +511,10 @@ public boolean isExecutable(float deltaTime) {

private record RelativeWindowPosition(HWndCtrl hWndCtrl, int relX, int relY) {
public void sendMouseEvent(int msg) {
//Logger.debug("Input", "Transfer mouse event to `" + hWndCtrl.windowText + "` @ " + relX + ", " + relY);
hWndCtrl.sendMouseEvent(msg, relX, relY);
if (msg == 0)
return;
//Logger.debug("Input", "Transfer mouse event " + msg + " to `" + hWndCtrl.windowText + "` @ " + relX + ", " + relY);
hWndCtrl.updated().sendMouseEvent(msg, relX, relY);
}
}
}
17 changes: 12 additions & 5 deletions core/src/cn/harryh/arkpets/utils/HWndCtrl.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public class HWndCtrl {
public final int posRight;
public final int windowWidth;
public final int windowHeight;

public static final HWndCtrl EMPTY = new HWndCtrl();

public static final int WS_EX_TOPMOST = 0x00000008;
Expand Down Expand Up @@ -195,16 +196,22 @@ public void setWindowTransparent(boolean transparent) {
*/
public void sendMouseEvent(int msg, int x, int y) {
int wParam = switch (msg) {
case WM_LBUTTONDOWN, WM_LBUTTONUP -> MK_LBUTTON;
case WM_RBUTTONDOWN, WM_RBUTTONUP -> MK_RBUTTON;
case WM_MBUTTONDOWN, WM_MBUTTONUP -> MK_MBUTTON;
case WM_LBUTTONDOWN -> MK_LBUTTON;
case WM_RBUTTONDOWN -> MK_RBUTTON;
case WM_MBUTTONDOWN -> MK_MBUTTON;
default -> 0;
};
int lParam = (y << 16) | (x & 0xFFFF);
User32.INSTANCE.SendMessage(hWnd, msg, new WinDef.WPARAM(0x0021), new WinDef.LPARAM(0));
int lParam = (y << 16) | x;
User32.INSTANCE.SendMessage(hWnd, msg, new WinDef.WPARAM(wParam), new WinDef.LPARAM(lParam));
}

/** Gets a new HWndCtrl which contains the updated information of this window.
* @return The up-to-dated HWndCtrl.
*/
public HWndCtrl updated() {
return new HWndCtrl(hWnd);
}

/** Gets the current list of windows.
* @param only_visible Whether exclude the invisible window.
* @return An ArrayList consists of HWndCtrls.
Expand Down

0 comments on commit 903fb96

Please sign in to comment.