Skip to content

Commit

Permalink
Merge pull request #48 from mahomaps/overlays-shitfix-292
Browse files Browse the repository at this point in the history
Overlays size changes
  • Loading branch information
Feodor0090 committed May 28, 2023
2 parents 20b4831 + cdb7dfb commit a6f7717
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 8 deletions.
7 changes: 6 additions & 1 deletion src/mahomaps/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ private Settings() {
public static int cacheMode = 1;
public static boolean proxyTiles = false;
public static boolean proxyApi = false;
public static int uiSize = 0;

public static String proxyServer = "http://nnp.nnchan.ru:80/mahoproxy.php?u=";

public static final int CACHE_FS = 1;
Expand Down Expand Up @@ -49,6 +51,7 @@ public static boolean Read() {
cacheMode = j.optInt("cache", 1);
proxyTiles = j.optBoolean("proxy_tiles");
proxyApi = j.optBoolean("proxy_api");
uiSize = j.optInt("ui_size", 0);
return true;
} catch (Throwable e) {
e.printStackTrace();
Expand All @@ -62,7 +65,8 @@ private static void ApplyOptimal() {
proxyApi = false;
proxyTiles = false;
} else {
proxyTiles = proxyApi = MahoMapsApp.platform == null || MahoMapsApp.platform.indexOf("platform_version=5.") == -1
proxyTiles = proxyApi = MahoMapsApp.platform == null
|| MahoMapsApp.platform.indexOf("platform_version=5.") == -1
|| MahoMapsApp.platform.indexOf("platform_version=5.0") != -1;
}
}
Expand All @@ -77,6 +81,7 @@ public static String Serialize() {
j.put("cache", cacheMode);
j.put("proxy_tiles", proxyTiles);
j.put("proxy_api", proxyApi);
j.put("ui_size", uiSize);
return j.toString();
}

Expand Down
28 changes: 24 additions & 4 deletions src/mahomaps/screens/MapCanvas.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,11 @@ public class MapCanvas extends MultitouchCanvas implements CommandListener {
public final OverlaysManager overlays = new OverlaysManager(this);
public Line line;

// misc
// draw/input states/temps/caches
boolean dragActive;
private boolean repaintDebugTick = true;
public boolean hidden = false;
private int lastOverlaysW;
public final Gate repaintGate = new Gate(true);
private Graphics cachedGraphics;

Expand Down Expand Up @@ -190,10 +191,14 @@ private void drawOverlay(Graphics g, int w, int h) {
if (!t)
h -= fh;

overlays.Draw(g, w, h);
lastOverlaysW = getOverlaysW(w, h);
overlays.Draw(g, lastOverlaysW, h);

if (t) {
controls.Paint(g, 0, 0, w, h - overlays.overlaysH);
int ch = h;
if (lastOverlaysW == w)
ch -= overlays.overlaysH;
controls.Paint(g, 0, 0, w, ch);
}
controls.PaintInfo(g, 0, 0, w, h - overlays.overlaysH);

Expand Down Expand Up @@ -259,6 +264,21 @@ private Vector GetGeoInfo() {
return v;
}

private static int getOverlaysW(int w, int h) {
if (w <= h) {
// portait
return w;
}

if (h + 100 > w) {
// album, but too square (less than 100 pixels free)
return w;
}

// album, wide enough
return h;
}

public void run() throws InterruptedException {
while (true) {
if (MahoMapsApp.paused || hidden) {
Expand Down Expand Up @@ -491,7 +511,7 @@ protected void pointerReleased(int x, int y, int n) {
if (UIElement.InvokeTouchEvent(x, y))
break handling;

if (y > getHeight() - overlays.overlaysH)
if (y > getHeight() - overlays.overlaysH && x < lastOverlaysW)
break handling;

if (overlays.OnGeopointTap(x, y))
Expand Down
5 changes: 5 additions & 0 deletions src/mahomaps/screens/SettingsScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public class SettingsScreen extends Form implements CommandListener {
new String[] { "Запрещено", "Схема, светлая палитра", }, null);
private ChoiceGroup proxyTiles = new ChoiceGroup("Проксирование", Choice.POPUP,
new String[] { "Отключено", "nnchan.ru", }, null);
private ChoiceGroup uiSize = new ChoiceGroup("Размер кнопок управления (нужен перезапуск)", Choice.POPUP,
new String[] { "Автоматически", "50x50", "30x30" }, null);

public SettingsScreen() {
super("Настройки");
Expand Down Expand Up @@ -65,6 +67,7 @@ public SettingsScreen() {
proxyTiles.setSelectedIndex(Settings.proxyTiles ? 1 : 0, true);
// апи отслеживается отдельно, однако предполагается что оно включено вместе с
// тайлами.
uiSize.setSelectedIndex(Settings.uiSize, true);

append(focusZoom);
append(geoLook);
Expand All @@ -73,6 +76,7 @@ public SettingsScreen() {
append(cache);
append(download);
append(proxyTiles);
append(uiSize);
}

private void Apply() {
Expand All @@ -84,6 +88,7 @@ private void Apply() {
Settings.allowDownload = download.getSelectedIndex() == 1;
Settings.proxyTiles = proxyTiles.getSelectedIndex() == 1;
Settings.proxyApi = proxyTiles.getSelectedIndex() == 1;
Settings.uiSize = uiSize.getSelectedIndex();
if (Settings.allowDownload) {
MahoMapsApp.tiles.ForceMissingDownload();
}
Expand Down
12 changes: 9 additions & 3 deletions src/mahomaps/ui/ControlButton.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import javax.microedition.lcdui.Image;

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

public class ControlButton extends UIElement implements ITouchAcceptor {
Expand All @@ -27,8 +28,13 @@ protected static Image GetUiSheet() {
try {
_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);
if (Settings.uiSize == 1) {
// sheet is already 50x50
} else {
// 30x30 is forced, or automated due to small screen
if (c.getWidth() <= 320 || c.getHeight() <= 320 || Settings.uiSize == 2) {
_sheet = ImageUtils.resize(_sheet, 60, _sheet.getHeight() * 30 / 50, true, false);
}
}
} catch (IOException e) {
_sheet = Image.createImage(1, 1);
Expand All @@ -50,7 +56,7 @@ public void Paint(Graphics g, int x, int y, int w, int h) {
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);
RegisterForInput(this, x, y, W, H);
}

public void OnPress() {
Expand Down

0 comments on commit a6f7717

Please sign in to comment.