Skip to content

Commit

Permalink
Merge pull request #102 from Feodor0090/num-touch
Browse files Browse the repository at this point in the history
Add touch support for number box
  • Loading branch information
Feodor0090 authored Nov 2, 2022
2 parents 903e816 + c1c89dd commit 12654d6
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
54 changes: 54 additions & 0 deletions src/nmania/ui/ng/NumberBox.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ public class NumberBox extends Screen {
private Font num = Font.getFont(0, 0, 8);
private Font buttons = Font.getFont(0, 0, 0);
private boolean sign;
private final char[][] pad = new char[][] {
new char[] {'1','2','3'},
new char[] {'4','5','6'},
new char[] {'7','8','9'},
new char[] {'-','0','<'},
};

public NumberBox(String title, int UUID, INumberBoxHandler handler, int value, boolean allowNegative) {
this.title = title;
Expand Down Expand Up @@ -51,6 +57,22 @@ public void Paint(Graphics g, int w, int h) {
g.drawString(sign ? "0" : "-0", w - fh - (fh >> 1), 10, Graphics.TOP | Graphics.RIGHT);
else
g.drawString(String.valueOf(value), w - fh - (fh >> 1), 10, Graphics.TOP | Graphics.RIGHT);
PaintPad(g, w, fh + 20);
}

private final void PaintPad(Graphics g, int w, int y) {
int fh = num.getHeight();
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 3; j++) {
if(i == 3 && j == 0 && !allowNegative)
continue;
g.setColor(NmaniaDisplay.PINK_COLOR);
g.fillRoundRect(j*w/3 + 1, y, w/3 - 2, fh, fh, fh);
g.setColor(-1);
g.drawChar(pad[i][j], j*w/3 + w/6, y, Graphics.TOP | Graphics.HCENTER);
}
y += fh + 2;
}
}

public void OnKey(IDisplay d, int k) {
Expand Down Expand Up @@ -85,5 +107,37 @@ private void ApplySign() {
}

public void OnTouch(IDisplay d, int s, int x, int y, int dx, int dy, int w, int h) {
if (s == 1) {
int fh = num.getHeight();
y -= fh + 20;
if (y < 0)
return;
if (y < fh + 2) {
OnKey(d, '1'+(x*3/w));
return;
}
y -= fh + 2;
if (y < fh + 2) {
OnKey(d, '4'+(x*3/w));
return;
}
y -= fh + 2;
if (y < fh + 2) {
OnKey(d, '7'+(x*3/w));
return;
}
y -= fh + 2;
if (y < fh + 2) {
if (x < w/3) {
if (allowNegative)
OnKey(d, Canvas.KEY_STAR);
} else if (x < w*2/3) {
OnKey(d, '0');
} else {
OnKey(d, Canvas.KEY_POUND);
}
return;
}
}
}
}
2 changes: 2 additions & 0 deletions src/nmania/ui/ng/VisualSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ public void OnSelect(ListItem item, ListScreen screen, IDisplay display) {
switch (item.UUID) {
case 0:
display.Push(new NumberBox("Dim %", 0, this, Settings.dimLevel, false));
break;
case 1:
display.Push(new NumberBox("Scroll speed (divider)", 1, this, Settings.speedDiv, false));
break;
case 2:
Settings.drawHUD = !Settings.drawHUD;
((SwitchItem) item).Toggle();
Expand Down

0 comments on commit 12654d6

Please sign in to comment.