Crossfire JXClient, Trunk
GaugeState.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.gauge;
24 
25 import java.awt.Dimension;
26 import java.awt.Graphics;
27 import java.awt.Image;
28 import org.jetbrains.annotations.NotNull;
29 import org.jetbrains.annotations.Nullable;
30 
35 public class GaugeState {
36 
40  @Nullable
41  private final Image fullImage;
42 
46  @Nullable
47  private final Image lowImage;
48 
52  @Nullable
53  private final Image negativeImage;
54 
58  @NotNull
59  private final Dimension preferredSize;
60 
64  private final int dx;
65 
69  private int dy;
70 
74  private int filledW;
75 
79  private int filledH;
80 
84  private int filledX;
85 
89  private int filledY;
90 
94  @Nullable
95  private Image filledPicture;
96 
106  public GaugeState(@Nullable final Image fullImage, @Nullable final Image lowImage, @Nullable final Image negativeImage, final int dx, final int dy) {
107  this.fullImage = fullImage;
108  this.lowImage = lowImage;
109  this.negativeImage = negativeImage;
110  final int preferredWidth = Math.max(Math.max(Math.max(fullImage == null ? 1 : fullImage.getWidth(null), lowImage == null ? 1 : lowImage.getWidth(null)), negativeImage == null ? 1 : negativeImage.getWidth(null)), 1);
111  final int preferredHeight = Math.max(Math.max(Math.max(fullImage == null ? 1 : fullImage.getHeight(null), lowImage == null ? 1 : lowImage.getHeight(null)), negativeImage == null ? 1 : negativeImage.getHeight(null)), 1);
112  preferredSize = new Dimension(preferredWidth, preferredHeight);
113  this.dx = dx;
114  this.dy = dy;
115  }
116 
121  public void setDy(final int dy) {
122  this.dy = dy;
123  }
124 
130  public boolean setValues(@NotNull final Orientation orientation) {
131  final int newFilledX = orientation.getX();
132  final int newFilledY = orientation.getY();
133  final int newFilledW = orientation.getW();
134  final int newFilledH = orientation.getH();
135  @Nullable final Image newFilledPicture;
136  if (!orientation.isValid()) {
137  newFilledPicture = null;
138  } else if (orientation.isNegativeImage()) {
139  newFilledPicture = negativeImage;
140  } else if (orientation.isLowImage()) {
141  newFilledPicture = lowImage;
142  } else {
143  newFilledPicture = fullImage;
144  }
145 
146  if (filledX == newFilledX && filledY == newFilledY && filledW == newFilledW && filledH == newFilledH && filledPicture == newFilledPicture) {
147  return false;
148  }
149 
150  filledX = newFilledX;
151  filledY = newFilledY;
152  filledW = newFilledW;
153  filledH = newFilledH;
154  filledPicture = newFilledPicture;
155  return true;
156  }
157 
162  public void draw(@NotNull final Graphics g) {
163  if (filledPicture != null) {
165  }
166  }
167 
172  @NotNull
173  public Dimension getPreferredSize() {
174  return new Dimension(preferredSize);
175  }
176 
177 }
com.realtime.crossfire.jxclient.gui.gauge.GaugeState.preferredSize
final Dimension preferredSize
Definition: GaugeState.java:59
com.realtime.crossfire.jxclient.gui.gauge.GaugeState.dx
final int dx
Definition: GaugeState.java:64
com.realtime.crossfire.jxclient.gui.gauge.GaugeState.draw
void draw(@NotNull final Graphics g)
Definition: GaugeState.java:162
com.realtime.crossfire.jxclient.gui.gauge.GaugeState.lowImage
final Image lowImage
Definition: GaugeState.java:47
com.realtime.crossfire.jxclient.gui.gauge.GaugeState.dy
int dy
Definition: GaugeState.java:69
com.realtime.crossfire.jxclient.gui.gauge.GaugeState.getPreferredSize
Dimension getPreferredSize()
Definition: GaugeState.java:173
com.realtime.crossfire.jxclient.gui.gauge.GaugeState
Definition: GaugeState.java:35
com.realtime.crossfire.jxclient.gui.gauge.GaugeState.setDy
void setDy(final int dy)
Definition: GaugeState.java:121
com.realtime.crossfire.jxclient.gui.gauge.GaugeState.setValues
boolean setValues(@NotNull final Orientation orientation)
Definition: GaugeState.java:130
com.realtime.crossfire.jxclient.gui.gauge.GaugeState.negativeImage
final Image negativeImage
Definition: GaugeState.java:53
com.realtime.crossfire.jxclient.gui.gauge.GaugeState.filledH
int filledH
Definition: GaugeState.java:79
com.realtime.crossfire.jxclient.gui.gauge.GaugeState.GaugeState
GaugeState(@Nullable final Image fullImage, @Nullable final Image lowImage, @Nullable final Image negativeImage, final int dx, final int dy)
Definition: GaugeState.java:106
com.realtime.crossfire.jxclient.gui.gauge.GaugeState.filledX
int filledX
Definition: GaugeState.java:84
com.realtime.crossfire.jxclient.gui.gauge.GaugeState.fullImage
final Image fullImage
Definition: GaugeState.java:41
com.realtime.crossfire.jxclient.gui.gauge.GaugeState.filledPicture
Image filledPicture
Definition: GaugeState.java:95
com.realtime.crossfire.jxclient.gui.gauge.Orientation
Definition: Orientation.java:29
com.realtime.crossfire.jxclient.gui.gauge.GaugeState.filledW
int filledW
Definition: GaugeState.java:74
com.realtime.crossfire.jxclient.gui.gauge.GaugeState.filledY
int filledY
Definition: GaugeState.java:89