22 package com.realtime.crossfire.jxclient.gui.item;
26 import java.awt.Color;
27 import java.awt.Dimension;
29 import java.awt.Graphics;
30 import java.awt.Graphics2D;
31 import java.awt.Image;
32 import java.awt.geom.RectangularShape;
33 import org.jetbrains.annotations.NotNull;
34 import org.jetbrains.annotations.Nullable;
190 public ItemPainter(@Nullable
final Image cursedImage, @Nullable
final Image damnedImage, @Nullable
final Image magicImage, @Nullable
final Image blessedImage, @Nullable
final Image appliedImage, @Nullable
final Image unidentifiedImage, @Nullable
final Image selectorImage, @Nullable
final Image lockedImage, @Nullable
final Image unpaidImage, @Nullable
final Color cursedColor, @Nullable
final Color damnedColor, @Nullable
final Color magicColor, @Nullable
final Color blessedColor, @Nullable
final Color appliedColor, @Nullable
final Color unidentifiedColor, @Nullable
final Color selectorColor, @Nullable
final Color lockedColor, @Nullable
final Color unpaidColor, @NotNull
final Font font, @NotNull
final Color nrofColor) {
220 return new ItemPainter(cursedImage, damnedImage, magicImage, blessedImage, appliedImage, unidentifiedImage, selectorImage, lockedImage, unpaidImage, cursedColor, damnedColor, magicColor, blessedColor, appliedColor, unidentifiedColor, selectorColor, lockedColor, unpaidColor, font, nrofColor);
229 final Dimension dimension =
new Dimension(32, 32);
245 private static void updateMinimumSize(@NotNull
final Dimension minimumSize, @Nullable
final Image image) {
250 final int width = image.getWidth(null);
251 if (minimumSize.width < width) {
252 minimumSize.width = width;
255 final int height = image.getWidth(null);
256 if (minimumSize.height < height) {
257 minimumSize.height = height;
270 public void paint(@NotNull
final Graphics2D g, @NotNull
final CfItem item,
final boolean selected, @NotNull
final Image face,
final int w,
final int h) {
271 paintColor(g, appliedColor, item.isApplied(), w, h);
272 paintColor(g, unidentifiedColor, item.isUnidentified(), w, h);
273 paintColor(g, cursedColor, item.isCursed(), w, h);
274 paintColor(g, damnedColor, item.isDamned(), w, h);
275 paintColor(g, magicColor, item.isMagic(), w, h);
276 paintColor(g, blessedColor, item.isBlessed(), w, h);
277 paintColor(g, lockedColor, item.isLocked(), w, h);
279 paintColor(g, unpaidColor, item.isUnpaid(), w, h);
280 final int imageW = Math.max(0, face.getWidth(null));
281 final int imageH = Math.max(0, face.getHeight(null));
286 if (imageW > imageH) {
290 offsetY = (h-scaledH)/2;
294 offsetX = (h-scaledW)/2;
297 g.drawImage(face, offsetX, offsetY, scaledW, scaledH, null);
298 paintImage(g, appliedImage, item.isApplied());
299 paintImage(g, unidentifiedImage, item.isUnidentified());
303 paintImage(g, blessedImage, item.isBlessed());
308 if (item.getNrOf() > 1) {
310 g.setColor(nrofColor);
311 g.drawString(String.valueOf(item.getNrOf()), 1, 1+font.getSize());
315 g.setColor(nrofColor);
316 g.setBackground(
new Color(0, 0, 0, 0.0f));
317 renderText(g, TEXT_OFFSET+h, 0, h/2, item.getTooltipText1());
318 renderText(g, TEXT_OFFSET+h, h/2, h/2, item.getTooltipText2());
330 private static void paintColor(@NotNull
final Graphics g, @Nullable
final Color color,
final boolean isActive,
final int w,
final int h) {
331 if (isActive && color != null) {
333 g.fillRect(0, 0, w, h);
343 private static void paintImage(@NotNull
final Graphics g, @Nullable
final Image image,
final boolean isActive) {
345 g.drawImage(image, 0, 0, null);
357 private void renderText(@NotNull
final Graphics2D g,
final int dx,
final int dy,
final int height, @NotNull
final String text) {
358 final RectangularShape rectangle = font.getStringBounds(text, g.getFontRenderContext());
359 final int y = dy+(int)Math.round(height-rectangle.getMaxY()-rectangle.getMinY())/2;
360 g.drawString(text, dx, y);
void paint(@NotNull final Graphics2D g, @NotNull final CfItem item, final boolean selected, @NotNull final Image face, final int w, final int h)
Paints an CfItem.
final Image lockedImage
The overlay image for locked objects.
final Image appliedImage
The overlay image for applied objects.
final Color unidentifiedColor
The background color for unidentified objects.
final Color unpaidColor
The background color for unpaid objects.
final Color magicColor
The background color for magical objects.
final Color nrofColor
The color for the "nrof" text.
ItemPainter newItemPainter()
Creates a new instance having the same parameters as this instance except for the item's size...
static void updateMinimumSize(@NotNull final Dimension minimumSize, @Nullable final Image image)
Updates the minimum size to contain an image.
final Color appliedColor
The background color for applied objects.
static void paintImage(@NotNull final Graphics g, @Nullable final Image image, final boolean isActive)
Conditionally paints an image.
static void paintColor(@NotNull final Graphics g, @Nullable final Color color, final boolean isActive, final int w, final int h)
Conditionally paints the background with a solid color.
Utility class for mathematical functions.
final Font font
The font for the "nrof" text.
final Color blessedColor
The background color for blessed objects.
final Image magicImage
The overlay image for magical objects.
final Image selectorImage
The overlay image for selected objects.
final Image unidentifiedImage
The overlay image for unidentified objects.
final Color lockedColor
The background color for locked objects.
final Color damnedColor
The background color for damned objects.
static int divRound(final int numerator, final int denominator)
Returns the quotient of two values, rounded to the nearest integer.
final Image unpaidImage
The overlay image for unpaid objects.
Dimension getMinimumSize()
Returns the minimal size needed to display this item.
final Image damnedImage
The overlay image for damned objects.
final Image cursedImage
The overlay image for cursed objects.
final Image blessedImage
The overlay image for blessed objects.
void renderText(@NotNull final Graphics2D g, final int dx, final int dy, final int height, @NotNull final String text)
Renders a text string.
final Color cursedColor
The background color for cursed objects.
The representation of a Crossfire Item, client-side.
Paints Crossfire item images.
ItemPainter(@Nullable final Image cursedImage, @Nullable final Image damnedImage, @Nullable final Image magicImage, @Nullable final Image blessedImage, @Nullable final Image appliedImage, @Nullable final Image unidentifiedImage, @Nullable final Image selectorImage, @Nullable final Image lockedImage, @Nullable final Image unpaidImage, @Nullable final Color cursedColor, @Nullable final Color damnedColor, @Nullable final Color magicColor, @Nullable final Color blessedColor, @Nullable final Color appliedColor, @Nullable final Color unidentifiedColor, @Nullable final Color selectorColor, @Nullable final Color lockedColor, @Nullable final Color unpaidColor, @NotNull final Font font, @NotNull final Color nrofColor)
Creates a new instance.
static final int TEXT_OFFSET
The indentation of the item's text from the icon.
final Color selectorColor
The background color for selected objects.