Android Open Source - candymem Size Helper






From Project

Back to project page candymem.

License

The source code is released under:

GNU General Public License

If you think the Android project candymem listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package se.tube42.kidsmem.logic;
/*from ww w  .j  a  va  2s .  co  m*/
import se.tube42.kidsmem.data.*;
import se.tube42.kidsmem.service.*;
import se.tube42.kidsmem.item.*;

import static se.tube42.kidsmem.data.Assets.*;
import static se.tube42.kidsmem.data.UI.*;
import static se.tube42.kidsmem.data.Constants.*;

public class SizeHelper
{
    public static void resize(int sw, int sh)
    {
        resize_menu(sw, sh);
        resizeBoard(sw, sh);
    }

    private static void resize_menu(int sw, int sh)
    {
        // big menu button
        final int ps = Math.max(32, (~31) & (int)(Math.min(sw / 3, sh / 3.5f)));
        final int y2 = 2 * (sh - ps) / 3;
        button_big_size = ps;
        button_big_x = (sw - ps) / 2;
        button_big_y = y2;

        // small menu button
        final int size = (~15) & Math.min(sw, sh) / 5;
        final int y0 = (int)(size * 0.7f);

        button_small_size = size;
        button_small_y = y0;
        button_small_x0 = (int)(0.5f + size * 0.4f);
        button_small_x1 = (int)(0.5f + (sw - size) / 2);
        button_small_x2 = (int)(0.5f + sw - size * 1.4f);

        // top bar
        top_w = sw + 2;
        top_x = -1;

        top_h0 = sh - y2 - ps / 2;
        top_y0 = sh - top_h0;

        top_h1 = 42;
        top_y1 = sh - top_h1;

        // stats:
        stats_yc = top_y1 + top_h1 / 2;
    }

    public static void resizeBoard(int sw, int sh)
    {
        // calc board size
        final int bw = World.board_w;
        final int bh = World.board_h;

        sh -= top_h1; // remove the upper part

        size = Math.max(8,
                  ~7 & (int)(0.5f + Math.min(
                  sw / (bw + 1.2f),
                  sh / (bh + 1.2f))));

        // calc tile gap
        gap = Math.min(size , Math.min(
                  (sw - bw * size - size / 2) / (bw - 1),
                  (sh - bh * size - size / 2) / (bh - 1)
                  ));

        gap = Math.min(size , Math.min(
                  (sw - bw * size) / (bw + 1),
                  (sh - bh * size) / (bh + 1)
                  ));

        if(gap < 2) gap = 2;
        if(gap > size) gap = size;
        gap += size;

        if(World.tiles != null) {
            for(int i = 0; i < World.tiles.length; i++)
                World.tiles[i].setSize(UI.size, UI.size);
        }


        board_x0 = (int) (0.5f + sw - gap * (bw - 1) - size ) / 2;
        board_y0 = (int) (0.5f + sh - gap * (bh - 1) - size ) / 2;

        System.out.println("board origin=" + board_x0 + "," + board_y0 +
                  " size=" + size + " gap=" + gap);
    }

}




Java Source Code List

com.badlogic.gdx.backends.lwjgl.LwjglApplication.java
se.tube42.kidsmem.KidsMemoryApp.java
se.tube42.kidsmem.SystemHandler.java
se.tube42.kidsmem.android.MainActivity.java
se.tube42.kidsmem.data.Assets.java
se.tube42.kidsmem.data.Constants.java
se.tube42.kidsmem.data.Settings.java
se.tube42.kidsmem.data.UI.java
se.tube42.kidsmem.data.World.java
se.tube42.kidsmem.desktop.DesktopMain.java
se.tube42.kidsmem.item.Button.java
se.tube42.kidsmem.item.FireworkItem.java
se.tube42.kidsmem.item.GameStat.java
se.tube42.kidsmem.item.TileSprite.java
se.tube42.kidsmem.item.TopBar.java
se.tube42.kidsmem.logic.AssetHelper.java
se.tube42.kidsmem.logic.GameHelper.java
se.tube42.kidsmem.logic.SettingsHelper.java
se.tube42.kidsmem.logic.SizeHelper.java
se.tube42.kidsmem.scene.BackgroundScene.java
se.tube42.kidsmem.scene.GameScene.java
se.tube42.kidsmem.scene.MenuScene.java
se.tube42.kidsmem.service.ServiceProvider.java
se.tube42.lib.item.BaseItem.java
se.tube42.lib.item.BaseText.java
se.tube42.lib.item.ParticleItem.java
se.tube42.lib.item.PatchItem.java
se.tube42.lib.item.SpriteItem.java
se.tube42.lib.scene.LayerList.java
se.tube42.lib.scene.Layer.java
se.tube42.lib.scene.SceneManager.java
se.tube42.lib.scene.Scene.java
se.tube42.lib.service.AssetService.java
se.tube42.lib.service.JobService.java
se.tube42.lib.service.RandomService.java
se.tube42.lib.service.StorageService.java
se.tube42.lib.util.BaseApp.java
se.tube42.lib.util.UIC.java