 |
Crossfire JXClient, Trunk
|
Go to the documentation of this file.
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);
final Image cursedImage
The overlay image for cursed objects.
Paints Crossfire item images.
final Image damnedImage
The overlay image for damned objects.
Utility class for mathematical functions.
final Color damnedColor
The background color for damned objects.
final Image unpaidImage
The overlay image for unpaid objects.
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)
Creates a new instance.
final Image lockedImage
The overlay image for locked objects.
final Color selectorColor
The background color for selected objects.
final Color appliedColor
The background color for applied objects.
final Image unidentifiedImage
The overlay image for unidentified objects.
The representation of a Crossfire Item, client-side.
final Color cursedColor
The background color for cursed objects.
void renderText(@NotNull final Graphics2D g, final int dx, final int dy, final int height, @NotNull final String text)
Renders a text string.
static void updateMinimumSize(@NotNull final Dimension minimumSize, @Nullable final Image image)
Updates the minimum size to contain an image.
final Font font
The font for the "nrof" text.
final Image appliedImage
The overlay image for applied objects.
static void paintImage(@NotNull final Graphics g, @Nullable final Image image, final boolean isActive)
Conditionally paints an image.
final Image blessedImage
The overlay image for blessed objects.
final Image markedImage
The overlay image for marked objects.
static int divRound(final int numerator, final int denominator)
Returns the quotient of two values, rounded to the nearest integer.
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 Color nrofColor
The color for the "nrof" text.
final Color markedColor
The background color for marked objects.
final Image magicImage
The overlay image for magical objects.
final Color magicColor
The background color for magical objects.
final Color unpaidColor
The background color for unpaid objects.
static final int TEXT_OFFSET
The indentation of the item's text from the icon.
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.
ItemPainter newItemPainter()
Creates a new instance having the same parameters as this instance except for the item's size.
Dimension getMinimumSize()
Returns the minimal size needed to display this item.
final Color unidentifiedColor
The background color for unidentified objects.
final Color lockedColor
The background color for locked objects.
final Color blessedColor
The background color for blessed objects.
final Image selectorImage
The overlay image for selected objects.