Skip to content

Commit

Permalink
Merge pull request #45 from mahomaps/small-ui
Browse files Browse the repository at this point in the history
Small UI
  • Loading branch information
Feodor0090 authored May 27, 2023
2 parents 65633e2 + 3e82e2c commit 00374d1
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 14 deletions.
33 changes: 24 additions & 9 deletions src/mahomaps/ui/ControlButton.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,54 @@

import java.io.IOException;

import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;

import mahomaps.MahoMapsApp;
import tube42.lib.imagelib.ImageUtils;

public class ControlButton extends UIElement implements ITouchAcceptor {

private static Image sheet;
/**
* Do not access this directly! Use {@link #GetUiSheet()}.
*/
private static Image _sheet;
protected int n;
private final int size;
private final IButtonHandler handler;
private final int uid;
private boolean hold;
private int margin = 5;

static {
protected static Image GetUiSheet() {
if (_sheet != null)
return _sheet;
try {
sheet = Image.createImage("/ui50.png");
_sheet = Image.createImage("/ui50.png");
Canvas c = MahoMapsApp.GetCanvas();
if (c.getWidth() <= 320 || c.getHeight() <= 320) {
_sheet = ImageUtils.resize(_sheet, 60, _sheet.getHeight() * 30 / 50, true, false);
}
} catch (IOException e) {
sheet = Image.createImage(1, 1);
_sheet = Image.createImage(1, 1);
e.printStackTrace();
}

return _sheet;
}

public ControlButton(int n, IButtonHandler handler, int uid) {
this.n = n;
this.handler = handler;
this.uid = uid;
size = sheet.getWidth() >> 1;
W = size + margin;
H = size + margin;
}

public void Paint(Graphics g, int x, int y, int w, int h) {
g.drawRegion(sheet, hold ? size : 0, n * size, size, size, 0, x, y, 0);
Image s = GetUiSheet();
final int size = s.getWidth() >> 1;
W = size + margin;
H = size + margin;
g.drawRegion(s, hold ? size : 0, n * size, size, size, 0, x, y, 0);
RegisterForInput(this, x, y, size, size);
}

Expand Down
21 changes: 16 additions & 5 deletions src/mahomaps/ui/ControlButtonsContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,30 @@

public class ControlButtonsContainer extends UIElement implements IButtonHandler {

private final FillFlowContainer flow;
private final MapCanvas map;

private final UIElement[] btns;
public Vector info;

public ControlButtonsContainer(MapCanvas map) {
this.map = map;
this.flow = new FillFlowContainer(new UIElement[] { new SearchButton(this), new ControlButton(1, this, 2),
new ControlButton(2, this, 3), new ControlButton(3, this, 4), new GeolocationButton(map) });
btns = new UIElement[] { new SearchButton(this), new ControlButton(1, this, 2), new ControlButton(2, this, 3),
new ControlButton(3, this, 4), new GeolocationButton(map) };
}

public void Paint(Graphics g, int x, int y, int w, int h) {
flow.Paint(g, w - flow.W, h - flow.H, flow.W, flow.H);
int cy = h;
int cx = w;
for (int i = 4; i >= 0; i--) {
UIElement elem = btns[i];
cy -= elem.H;
if (cy < 0) {
cy = h - elem.H;
cx -= elem.W;
if (cy < 0)
return;
}
elem.Paint(g, cx - elem.W, cy, elem.W, elem.H);
}
}

public void PaintInfo(Graphics g, int x, int y, int w, int h) {
Expand Down

0 comments on commit 00374d1

Please sign in to comment.