Crossfire JXClient, Trunk
Expression.java
Go to the documentation of this file.
1 /*
2  * This file is part of JXClient, the Fullscreen Java Crossfire Client.
3  *
4  * JXClient is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * JXClient is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with JXClient; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17  *
18  * Copyright (C) 2005-2008 Yann Chachkoff
19  * Copyright (C) 2006-2017,2019-2023 Andreas Kirschbaum
20  * Copyright (C) 2010-2012,2014-2018,2020-2023 Nicolas Weeger
21  */
22 
23 package com.realtime.crossfire.jxclient.gui.gui;
24 
25 import org.jetbrains.annotations.NotNull;
26 
31 public class Expression {
32 
36  private final int constant;
37 
41  private final float widthFactor;
42 
46  private final float heightFactor;
47 
51  private final float prefWidthFactor;
52 
56  private final float prefHeightFactor;
57 
66  public Expression(final int constant, final float widthFactor, final float heightFactor, final float prefWidthFactor, final float prefHeightFactor) {
67  this.constant = constant;
68  this.widthFactor = widthFactor;
69  this.heightFactor = heightFactor;
70  this.prefWidthFactor = prefWidthFactor;
71  this.prefHeightFactor = prefHeightFactor;
72  }
73 
81  public Expression(@NotNull final Expression expression1, final boolean negative, @NotNull final Expression expression2) {
82  final int factor = negative ? -1 : 1;
83  constant = expression1.constant+expression2.constant*factor;
84  widthFactor = expression1.widthFactor+expression2.widthFactor*factor;
85  heightFactor = expression1.heightFactor+expression2.heightFactor*factor;
86  prefWidthFactor = expression1.prefWidthFactor+expression2.prefWidthFactor*factor;
87  prefHeightFactor = expression1.prefHeightFactor+expression2.prefHeightFactor*factor;
88  }
89 
98  public int evaluate(final int width, final int height, final int prefWidth, final int prefHeight) {
100  }
101 
106  public int evaluateConstant() {
107  if (Math.abs(widthFactor) > 1E-9 || Math.abs(heightFactor) > 1E-9) {
108  throw new IllegalStateException("widthFactor="+widthFactor+", heightFactor="+heightFactor);
109  }
110 
111  return constant;
112  }
113 
120  private static int applyFactor(final int value, final float factor) {
121  return Math.round(value*factor);
122  }
123 
124 }
com.realtime.crossfire.jxclient.gui.gui.Expression.constant
final int constant
Definition: Expression.java:36
com.realtime.crossfire.jxclient.gui.gui.Expression.heightFactor
final float heightFactor
Definition: Expression.java:46
com.realtime.crossfire.jxclient.gui.gui.Expression.widthFactor
final float widthFactor
Definition: Expression.java:41
com.realtime.crossfire.jxclient.gui.gui.Expression.evaluateConstant
int evaluateConstant()
Definition: Expression.java:106
com.realtime.crossfire.jxclient.gui.gui.Expression.Expression
Expression(@NotNull final Expression expression1, final boolean negative, @NotNull final Expression expression2)
Definition: Expression.java:81
com.realtime.crossfire.jxclient.gui.gui.Expression.prefWidthFactor
final float prefWidthFactor
Definition: Expression.java:51
com.realtime.crossfire.jxclient.gui.gui.Expression
Definition: Expression.java:31
com.realtime.crossfire.jxclient.gui.gui.Expression.Expression
Expression(final int constant, final float widthFactor, final float heightFactor, final float prefWidthFactor, final float prefHeightFactor)
Definition: Expression.java:66
com.realtime.crossfire.jxclient.gui.gui.Expression.evaluate
int evaluate(final int width, final int height, final int prefWidth, final int prefHeight)
Definition: Expression.java:98
com.realtime.crossfire.jxclient.gui.gui.Expression.prefHeightFactor
final float prefHeightFactor
Definition: Expression.java:56
com.realtime.crossfire.jxclient.gui.gui.Expression.applyFactor
static int applyFactor(final int value, final float factor)
Definition: Expression.java:120