1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
| public static float perspective_ANGULARSPEED = (float) Math.PI / (24f * 1000f); private static Map<String, Float> lastTransformTheta = Collections.synchronizedMap(new HashMap<String, Float>()); private static Map<String, Long> lastTransformTime = Collections.synchronizedMap(new HashMap<String, Long>()); private static Map<String, GradientPaint> gradients = Collections.synchronizedMap(new HashMap<String, GradientPaint>()); public final static int FX_DOWNREFLEXION = 4; public final static int FX_ROTATION = 2; public final static int FX_NONE = 1;
public static void _drawLogo(Component c, Graphics2D g2, String logo, Dimension size, int hpos, int vpos, int fx) throws InterruptedException { Sprite logo_sp = _getLogo(c, logo, size); GraphicsJAI g = Sprite.createGraphicsJAI(g2, c); g.setRenderingHints(Sprite._getRenderingHints()); Point translate = new Point(0, 0); Insets insets = new Insets(10, 10, 10, 10); switch (hpos) { case GUIConsoleOutput.LEFT: translate.x = insets.left; break; case GUIConsoleOutput.CENTER: translate.x = (int) ((float) c.getWidth() / 2.0f - (float) size.width / 2.0f); break; case GUIConsoleOutput.RIGHT: translate.x = -insets.right + (int) (c.getWidth() - size.width); break; default: break; } switch (vpos) { case GUIConsoleOutput.TOP: translate.y = insets.top; break; case GUIConsoleOutput.CENTER: translate.y = (int) ((float) c.getHeight() / 2.0f - (float) size.height / 2.0f); break; case GUIConsoleOutput.BOTTOM: translate.y = -insets.bottom + (int) (c.getHeight() - size.height); break; default: break; } AffineTransform tx = null; AffineTransform tx2 = null; System.err.println("FX " + logo + " fx & rotation = " + (fx & FX_ROTATION) + " fx & reflexion = " + (fx & FX_DOWNREFLEXION)); if ((fx & FX_ROTATION) != 0) { long now = System.currentTimeMillis(); if (!(lastTransformTime.get(logo) instanceof Long)) { lastTransformTime.put(logo, now); } float lastTransformTheta = RenderingScene.lastTransformTheta.containsKey(logo) ? RenderingScene.lastTransformTheta.get(logo) : (1f - 1f / 360f) * 2f * (float) Math.PI; lastTransformTheta -= (float) (now - lastTransformTime.get(logo)) * perspective_ANGULARSPEED; lastTransformTheta = lastTransformTheta % (2f * (float) Math.PI); tx = AffineTransform.getRotateInstance(lastTransformTheta, (float) size.width / 2f, (float) size.height / 2f); tx2 = (fx & FX_DOWNREFLEXION) != 0 ? AffineTransform.getRotateInstance(-lastTransformTheta, (float) size.width / 2f, (float) size.height / 2f) : tx; RenderingScene.lastTransformTheta.put(logo, lastTransformTheta); lastTransformTime.put(logo, now); } if ((fx & FX_DOWNREFLEXION) != 0) { Sprite shadow = (Sprite) logo_sp.clone(); if (shadow == null) { return; } shadow.setTX(tx2); shadow.setFlipEnabled(true, Sprite.VERTICAL); shadow.setCompositeEnabled(true); if (!(gradients.get(logo) instanceof GradientPaint)) { gradients.put(logo, new GradientPaint(0, 0, new Color(1.0f, 1.0f, 1.0f, 1.0f), 0, (float) size.height * 0.66f, new Color(1.0f, 1.0f, 1.0f, 0.0f), false)); } else if (gradients.get(logo).getPoint2().distance(gradients.get(logo).getPoint1()) != (float) size.height * 0.66f) { gradients.put(logo, new GradientPaint(0, 0, new Color(1.0f, 1.0f, 1.0f, 1.0f), 0, (float) size.height * 0.66f, new Color(1.0f, 1.0f, 1.0f, 0.0f), false)); } Paint shadow_gradient = gradients.get(logo); shadow.setPaint(shadow_gradient); shadow.setComposite(AlphaComposite.getInstance(AlphaComposite.DST_IN, 1.0f)); shadow.validate(); g.translate(translate.x, translate.y + size.height); shadow.draw(c, g); g.translate(-translate.x, -translate.y - size.height); } g.translate(translate.x, translate.y); logo_sp.validate(); logo_sp.draw(c, g, tx, null); g.translate(-translate.x, -translate.y); }
|