Skip to content

Commit

Permalink
Added temporary mobile UI scaling and multi-touch on Android.
Browse files Browse the repository at this point in the history
The ideal solution with NUI would be to scale the widgets with a RelativeLayout or similar widget but for now this works. Multi-touch support requires additional NUI changes that will need to be merged separately.
  • Loading branch information
BenjaminAmos committed Sep 26, 2021
1 parent 5b0c157 commit e9083d8
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions engine/src/main/java/org/destinationsol/ui/nui/NUIManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -151,14 +151,26 @@ public NUIManager(SolApplication solApplication, Context context, CommonDrawer c
solApplication.addResizeSubscriber(() -> resize(Gdx.graphics.getBackBufferWidth(), Gdx.graphics.getBackBufferHeight()));

setUiScale(options.getNuiUiScale());

// TODO: This is a temporary work-around until the NUI UI scales properly.
// Use RelativeLayout to scale the controls instead of scaling based
// on a reference resolution for mobile.
if (solApplication.isMobile()) {
if (Gdx.graphics.getBackBufferWidth() > 1024) {
setUiScale(Gdx.graphics.getBackBufferWidth() / 1024.0f);
}
}
}

/**
* Processes NUI input events (Keyboard and Mouse) and updates all UI layers.
* @param solApplication the application to use
*/
public void update(SolApplication solApplication) {
canvas.processMousePosition(mouse.getPosition());
for (int pointer = 0; pointer < mouse.getMaxPointers(); pointer++) {
canvas.processMousePosition(mouse.getPosition(pointer), pointer);
}

canvas.setGameTime(System.currentTimeMillis());

for (RawKeyboardAction action : keyboard.getInputQueue()) {
Expand Down Expand Up @@ -192,9 +204,9 @@ public void update(SolApplication solApplication) {
for (MouseAction action : mouse.getInputQueue()) {
if (action.getInput().getType() == InputType.MOUSE_BUTTON) {
if (action.getState().isDown()) {
canvas.processMouseClick((MouseInput) action.getInput(), action.getMousePosition());
canvas.processMouseClick((MouseInput) action.getInput(), action.getMousePosition(), action.getPointer());
} else {
canvas.processMouseRelease((MouseInput) action.getInput(), action.getMousePosition());
canvas.processMouseRelease((MouseInput) action.getInput(), action.getMousePosition(), action.getPointer());
}

NUIMouseButtonEvent event = new NUIMouseButtonEvent((MouseInput) action.getInput(), action.getState(), action.getMousePosition());
Expand Down

0 comments on commit e9083d8

Please sign in to comment.