23 package com.realtime.crossfire.jxclient.gui.item;
27 import java.awt.Color;
28 import java.awt.Dimension;
30 import java.awt.Graphics;
31 import java.awt.Graphics2D;
32 import java.awt.Image;
33 import java.awt.geom.RectangularShape;
34 import org.jetbrains.annotations.NotNull;
35 import org.jetbrains.annotations.Nullable;
205 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 Image
markedImage, @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, @Nullable
final Color
markedColor, @NotNull
final Font
font, @NotNull
final Color
nrofColor) {
237 return new ItemPainter(
cursedImage,
damnedImage,
magicImage,
blessedImage,
appliedImage,
unidentifiedImage,
selectorImage,
lockedImage,
unpaidImage,
markedImage,
cursedColor,
damnedColor,
magicColor,
blessedColor,
appliedColor,
unidentifiedColor,
selectorColor,
lockedColor,
unpaidColor,
markedColor,
font,
nrofColor);
246 final Dimension dimension =
new Dimension(32, 32);
263 private static void updateMinimumSize(@NotNull
final Dimension minimumSize, @Nullable
final Image image) {
268 final int width = image.getWidth(
null);
269 if (minimumSize.width < width) {
270 minimumSize.width = width;
273 final int height = image.getWidth(
null);
274 if (minimumSize.height < height) {
275 minimumSize.height = height;
288 public void paint(@NotNull
final Graphics2D g, @NotNull
final CfItem item,
final boolean selected, @NotNull
final Image face,
final int w,
final int h) {
299 final int imageW = Math.max(0, face.getWidth(
null));
300 final int imageH = Math.max(0, face.getHeight(
null));
305 if (imageW > imageH) {
309 offsetY = (h-scaledH)/2;
313 offsetX = (h-scaledW)/2;
316 g.drawImage(face, offsetX, offsetY, scaledW, scaledH,
null);
328 if (item.getNrOf() > 1) {
331 g.drawString(String.valueOf(item.getNrOf()), 1, 1+
font.getSize());
336 g.setBackground(
new Color(0, 0, 0, 0.0f));
337 final String tooltipText1 = item.getTooltipText1();
338 final String tooltipText2 = item.getTooltipText2();
339 renderText(g,
TEXT_OFFSET+h, 0, h, tooltipText2.isEmpty() ? tooltipText1 : tooltipText1+
" ("+tooltipText2+
")");
351 private static void paintColor(@NotNull
final Graphics g, @Nullable
final Color color,
final boolean isActive,
final int w,
final int h) {
352 if (isActive && color !=
null) {
354 g.fillRect(0, 0, w, h);
364 private static void paintImage(@NotNull
final Graphics g, @Nullable
final Image image,
final boolean isActive) {
366 g.drawImage(image, 0, 0,
null);
378 private void renderText(@NotNull
final Graphics2D g,
final int dx,
final int dy,
final int height, @NotNull
final String text) {
379 final RectangularShape rectangle =
font.getStringBounds(text, g.getFontRenderContext());
380 final int y = dy+(int)Math.round(height-rectangle.getMaxY()-rectangle.getMinY())/2;
381 g.drawString(text, dx, y);