Skip to content

Commit

Permalink
Merge pull request #79 from mahomaps/smaller-buttons
Browse files Browse the repository at this point in the history
Smaller buttons on keyboard
  • Loading branch information
Feodor0090 committed Jun 23, 2023
2 parents b76075d + 9097b63 commit 669b5a2
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 11 deletions.
15 changes: 8 additions & 7 deletions src/mahomaps/screens/MapCanvas.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ public class MapCanvas extends MultitouchCanvas implements CommandListener {
public Geopoint geolocation;

// input states
private boolean touch = hasPointerEvents();
private boolean mapFocused = true;
private int repeatCount = 0;
int startPx, startPy;
Expand Down Expand Up @@ -70,6 +69,8 @@ public MapCanvas(TilesProvider tiles) {
searchBox.addCommand(search);
searchBox.setCommandListener(this);

UIElement.touchInput = hasPointerEvents();

controls = new ControlButtonsContainer(this);

CheckApiAcsess();
Expand Down Expand Up @@ -114,7 +115,7 @@ private void repaint(Graphics g) {
drawMap(g, w, h);
drawOverlay(g, w, h);
UIElement.CommitInputQueue();
if (UIElement.IsQueueEmpty() && !touch && !mapFocused) {
if (UIElement.IsQueueEmpty() && !UIElement.touchInput && !mapFocused) {
mapFocused = true;
UIElement.Deselect();
requestRepaint();
Expand Down Expand Up @@ -164,7 +165,7 @@ private void drawMap(Graphics g, int w, int h) {
geolocation.paint(g, ms);
}

if (!touch) {
if (!UIElement.touchInput) {
g.setColor(0xff0000);

g.drawLine(-6, 0, -2, 0);
Expand Down Expand Up @@ -193,7 +194,7 @@ private void drawOverlay(Graphics g, int w, int h) {
throw new RuntimeException("geo infa ebanulas " + e.toString());
}

final boolean t = touch;
final boolean t = UIElement.touchInput;
final RouteTracker rt = MahoMapsApp.route;

int fh = f.getHeight();
Expand Down Expand Up @@ -355,7 +356,7 @@ protected void keyPressed(int k) {
if (k == -12)
return;

touch = false;
UIElement.touchInput = false;

if (MahoMapsApp.route != null) {
// когда маршрут ведётся, можно только изменять масштаб и закрывать маршрут.
Expand Down Expand Up @@ -484,7 +485,7 @@ protected void keyRepeated(int k) {
if (k == -12)
return;

touch = false;
UIElement.touchInput = false;
int ga = 0;
try {
ga = getGameAction(k);
Expand Down Expand Up @@ -525,7 +526,7 @@ protected void keyReleased(int k) {
}

protected void pointerPressed(int x, int y, int n) {
touch = true;
UIElement.touchInput = true;
mapFocused = true;
if (n == 0) {
UIElement.InvokePressEvent(x, y);
Expand Down
12 changes: 10 additions & 2 deletions src/mahomaps/ui/Button.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,21 @@ public Button(String text, int id, IButtonHandler handler) {
this.text = text;
this.id = id;
this.handler = handler;
this.H = Font.getFont(0, 0, 8).getHeight() + margin * 4;
UpdateHeight();
}

public void Paint(Graphics g, int x, int y, int w, int h) {
RegisterForInput(this, x, y, w, h);
UpdateHeight();
g.setFont(Font.getFont(0, 0, 8));
if (hold) {
g.setColor(0xFC6155);
g.fillRoundRect(x + margin, y + margin, w - margin - margin, h - margin - margin, 10, 10);
g.setColor(0x343434);
g.fillRoundRect(x + margin * 2, y + margin * 2, w - margin * 4, h - margin * 4, 10, 10);
if (UIElement.touchInput)
g.fillRoundRect(x + margin * 2, y + margin * 2, w - margin * 4, h - margin * 4, 10, 10);
else
g.fillRoundRect(x + margin * 4, y + margin + 1, w - margin * 8, h - margin * 2 - 2, 10, 10);
} else {
g.setColor(0x343434);
g.fillRoundRect(x + margin, y + margin, w - margin - margin, h - margin - margin, 10, 10);
Expand All @@ -35,6 +39,10 @@ public void Paint(Graphics g, int x, int y, int w, int h) {
g.drawString(text, x + w / 2, y + h / 2 - fh / 2, Graphics.TOP | Graphics.HCENTER);
}

private final void UpdateHeight() {
this.H = Font.getFont(0, 0, 8).getHeight() + margin * (UIElement.touchInput ? 4 : 2);
}

public void OnPress() {
hold = true;
}
Expand Down
2 changes: 1 addition & 1 deletion src/mahomaps/ui/ColumnsContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public ColumnsContainer(UIElement[] elems) {
public void Paint(Graphics g, int x, int y, int w, int h) {
int[] widths = new int[children.size()];
int wsum = 0;
int rh = h;
int rh = 1;
for (int i = 0; i < children.size(); i++) {
UIElement el = ((UIElement) children.elementAt(i));
widths[i] = el.W;
Expand Down
2 changes: 1 addition & 1 deletion src/mahomaps/ui/UIElement.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ public abstract class UIElement {
private static volatile Vector queueTemp = new Vector();
private static int selectedIndex = -1;
private static boolean isSelectedInQueue = false;

private static ITouchAcceptor holdElement = null;
public static boolean touchInput;

protected static synchronized void RegisterForInput(ITouchAcceptor ta, int x, int y, int w, int h) {
queueTemp.addElement(new UITouchZone(ta, x, y, w, h));
Expand Down

0 comments on commit 669b5a2

Please sign in to comment.