License text

/*
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER 
 * Copyright  2008, 2010 Oracle and/or its affiliates.  All rights reserved. 
 * Use is subject to license terms.
 * 
 * This file is available and licensed under the following license:
 * 
 * Redistribution and use in source and binary forms, with or without 
 * modification, are permitted provided that the following conditions are met: 
 * 
 *   * Redistributions of source code must retain the above copyright notice, 
 *     this list of conditions and the following disclaimer. 
 *
 *   * Redistributions in binary form must reproduce the above copyright notice,
 *     this list of conditions and the following disclaimer in the documentation
 *     and/or other materials provided with the distribution.
 *
 *   * Neither the name of Oracle Corporation nor the names of its contributors 
 *     may be used to endorse or promote products derived from this software 
 *     without specific prior written permission. 
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
 */

    

package whiteout;

import javafx.scene.paint.Color;
import javafx.scene.paint.LinearGradient;
import javafx.scene.paint.Stop;
import javafx.scene.text.Font;
import javafx.scene.text.Text;

public class Env {

    public-init var screenWidth: Integer;
    public-init var screenHeight: Integer;
    public def smallFont = 
        if (screenWidth < 320) 
            Font {size: 15}
        else if (screenWidth < 450)
            Font {size: 20}
        else 
            Font {size: 30}

    public def mediumFont = 
        if (screenWidth < 320)
            Font {size: 20}
        else if (screenWidth < 450)
            Font {size: 40}
        else 
            Font {size: 50}

    public def bigFont = 
        if (screenWidth < 320)
            Font {size: 30}
        else if (screenWidth < 450)
            Font {size: 60}
        else 
            Font {size: 70}

    // Compute height / width of the blue buttons based on the size of "Reset"
    def resetSize = Text {
        content: "Reset"
        font: smallFont
    };

    // Leave a bit of space around "Reset"
    public def blueButtonHeight = resetSize.layoutBounds.height + 8;
    public def blueButtonWidth = resetSize.layoutBounds.width + 10;

    // If this is set much greater than 5, the game gets a bit odd since
    // the randomize function just toggles cells in the 0..4 range.
    // It has to do overlapping toggles or else the game is uninteresting.
    public def nButtons = 5;

    // This is the gap we will leave between game buttons, and we want at least this
    // much margin at the top / bottom of the screen.  That makes 5 buttons and 6 gaps.
    def gameButtonGapPercent = .1;

    def nButtonsPlusGaps = nButtons * (1 + gameButtonGapPercent);

    def countSize = Text {
        content: "222"
        font: mediumFont
    }
    public def controlWidth = if (blueButtonWidth > countSize.layoutBounds.width)
                          blueButtonWidth
                      else
                         countSize.layoutBounds.width;

    // If it is landscape, we will put the controls on the right, else
    // they will be on the bottom.
    public def isPortrait = if (screenWidth - controlWidth /*- 10*/ < screenHeight) true else false;

    // size to be occupied by buttons
    public def gameSize = if (isPortrait) {
                       var useableHeight = screenHeight - blueButtonHeight - 10;
                       if (useableHeight <= screenWidth) useableHeight else screenWidth;
                   } else {
                       var useableWidth = screenWidth - controlWidth - 10 ;
                       if (useableWidth <= screenHeight) useableWidth else screenHeight;
                   }

    // 0 .... gameSize will be occupied by n game buttons and n + 1 gaps.
    public def gameButtonSize = gameSize / (nButtonsPlusGaps + gameButtonGapPercent);
    public def gameButtonGap = gameButtonSize * gameButtonGapPercent;

    // This is the stokeWidth of a game button rectangle.  If it is wider than the gap, then two 
    // adjacent strokes will overlap causing multiple mouse events.
    public def gameButtonStrokeWidth = if (gameButtonGap >= 4) 3 else .5 * gameButtonGap;
    public def buttonX = if (isPortrait) gameButtonGap else gameSize + (screenWidth - gameSize - blueButtonWidth) / 2;
    public def topMargin = gameButtonGap; //if (isPortrait) gameButtonGap else (screenHeight - ((gameButtonSize * nButtonsPlusGaps) - gameButtonGap)) / 2;
    public def slateGrad = LinearGradient{
        startX: 0
        startY: 0
        endX: 0
        endY: 1
        stops: [
            Stop {offset: 0.0, color: Color.rgb(0x34, 0x34, 0x34)},
            Stop {offset: 0.5, color: Color.rgb(0x55, 0x55, 0x55)},
            Stop {offset: 1.0, color: Color.rgb(0x43, 0x43, 0x43)}
        ]
    }
    public def blueGrad = LinearGradient{
        startX: 0
        startY: 0
        endX: 0
        endY: 1
        stops: [
            Stop {offset: 0.0, color:Color.rgb(0, 0x33, 0xff)},
            Stop {offset: 0.5, color:Color.rgb(0, 0x55, 0xff)},
            Stop {offset: 1.0, color:Color.BLUE}
        ]
    }
}