Crossfire JXClient, Trunk
ButtonImages.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.button;
24 
25 import java.awt.Graphics;
26 import java.awt.Image;
27 import org.jetbrains.annotations.NotNull;
28 
35 public class ButtonImages {
36 
40  @NotNull
41  private final Image imageLeft;
42 
46  @NotNull
47  private final Image imageMiddle;
48 
52  @NotNull
53  private final Image imageRight;
54 
58  private final int height;
59 
66  public ButtonImages(@NotNull final Image imageLeft, @NotNull final Image imageMiddle, @NotNull final Image imageRight) {
67  if (imageLeft.getHeight(null) != imageMiddle.getHeight(null)) {
68  throw new IllegalArgumentException("left image height is "+imageLeft.getHeight(null)+" but middle image height is "+imageMiddle.getHeight(null));
69  }
70  if (imageMiddle.getHeight(null) != imageRight.getHeight(null)) {
71  throw new IllegalArgumentException("middle image height is "+imageMiddle.getHeight(null)+" but right image height is "+imageRight.getHeight(null));
72  }
73 
74  this.imageLeft = imageLeft;
75  this.imageMiddle = imageMiddle;
76  this.imageRight = imageRight;
77  height = imageMiddle.getHeight(null);
78  }
79 
84  public int getHeight() {
85  return height;
86  }
87 
93  public void render(@NotNull final Graphics g, final int w) {
94  g.drawImage(imageLeft, 0, 0, null);
95  g.drawImage(imageRight, w-imageRight.getWidth(null), 0, null);
96 
97  final int middleWidth = imageMiddle.getWidth(null);
98  int tmpWidth = w-imageLeft.getWidth(null)-imageRight.getWidth(null);
99  int tmpX = imageLeft.getWidth(null);
100  while (tmpWidth > 0) {
101  final int thisWidth = Math.min(tmpWidth, middleWidth);
102  g.drawImage(imageMiddle, tmpX, 0, tmpX+thisWidth, height, 0, 0, thisWidth, height, null);
103  tmpX += thisWidth;
104  tmpWidth -= thisWidth;
105  }
106  }
107 
108 }
com.realtime.crossfire.jxclient.gui.button.ButtonImages.render
void render(@NotNull final Graphics g, final int w)
Definition: ButtonImages.java:93
com.realtime.crossfire.jxclient.gui.button.ButtonImages.imageLeft
final Image imageLeft
Definition: ButtonImages.java:41
com.realtime.crossfire.jxclient.gui.button.ButtonImages.ButtonImages
ButtonImages(@NotNull final Image imageLeft, @NotNull final Image imageMiddle, @NotNull final Image imageRight)
Definition: ButtonImages.java:66
com.realtime.crossfire.jxclient.gui.button.ButtonImages
Definition: ButtonImages.java:35
com.realtime.crossfire.jxclient.gui.button.ButtonImages.height
final int height
Definition: ButtonImages.java:58
com.realtime.crossfire.jxclient.gui.button.ButtonImages.getHeight
int getHeight()
Definition: ButtonImages.java:84
com.realtime.crossfire.jxclient.gui.button.ButtonImages.imageMiddle
final Image imageMiddle
Definition: ButtonImages.java:47
com.realtime.crossfire.jxclient.gui.button.ButtonImages.imageRight
final Image imageRight
Definition: ButtonImages.java:53