Bubble.java
     1: //========================================================================================
     2: //  Bubble.java
     3: //    en:Bubble
     4: //    ja:バブル
     5: //  Copyright (C) 2003-2025 Makoto Kamada
     6: //
     7: //  This file is part of the XEiJ (X68000 Emulator in Java).
     8: //  You can use, modify and redistribute the XEiJ if the conditions are met.
     9: //  Read the XEiJ License for more details.
    10: //  https://stdkmd.net/xeij/
    11: //========================================================================================
    12: 
    13: package xeij;
    14: 
    15: import java.awt.*;  //RenderingHints
    16: import java.awt.font.*;  //TextLayout
    17: import java.awt.geom.*;  //Rectangle2D
    18: 
    19: //class Bubble
    20: //  バブル
    21: public class Bubble {
    22: 
    23:   public static final boolean BBL_ON = true;
    24:   public static final int BBL_FONT_SIZE = 24;  //フォントサイズ
    25:   public static final int BBL_Y = BBL_FONT_SIZE * 2;  //Y座標
    26:   public static final int BBL_PADDING_X = BBL_FONT_SIZE * 1;  //X方向パディング
    27:   public static final int BBL_PADDING_Y = BBL_FONT_SIZE / 2;  //Y方向パディング
    28:   public static final Font BBL_FONT = new Font ("SansSerif", Font.PLAIN, BBL_FONT_SIZE);  //フォント
    29: 
    30:   public static Color bblBackground;  //背景色
    31:   public static Color bblForeground;  //文字色
    32:   public static String bblText;  //テキスト
    33:   public static long bblEndTime;  //終了時刻
    34: 
    35:   public static void bblInit () {
    36:     bblBackground = new Color (LnF.lnfRGB[14]);
    37:     bblForeground = new Color (LnF.lnfRGB[0]);
    38:     bblText = null;
    39:     bblEndTime = 0L;
    40:   }  //bblInit
    41: 
    42:   //bblStart (text, time)
    43:   //  開始
    44:   public static void bblStart (String text, long time) {
    45:     bblText = text;
    46:     bblEndTime = System.currentTimeMillis () + time;
    47:   }  //bblStart
    48: 
    49:   //bblDraw (g2)
    50:   //  表示
    51:   public static void bblDraw (Graphics2D g2) {
    52:     if (bblText != null) {
    53:       g2.setRenderingHint (RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
    54:       g2.setFont (BBL_FONT);
    55:       TextLayout tl = new TextLayout (bblText, BBL_FONT, g2.getFontRenderContext ());
    56:       Rectangle2D r = tl.getBounds ();
    57:       int x = (XEiJ.pnlWidth >> 1) - ((int) r.getWidth () >> 1);
    58:       int y = BBL_Y;
    59:       g2.setColor (bblBackground);
    60:       g2.fillRect ((int) r.getX () + x - BBL_PADDING_X,
    61:                    (int) r.getY () + y - BBL_PADDING_Y,
    62:                    (int) r.getWidth () + (BBL_PADDING_X << 1),
    63:                    (int) r.getHeight () + (BBL_PADDING_Y << 1));
    64:       g2.setColor (bblForeground);
    65:       tl.draw (g2, x, y);
    66:       if (bblEndTime <= System.currentTimeMillis ()) {  //終了
    67:         bblEnd ();
    68:       }
    69:     }
    70:   }  //bblDraw
    71: 
    72:   //bblEnd ()
    73:   //  終了
    74:   public static void bblEnd () {
    75:     bblText = null;
    76:     bblEndTime = 0L;
    77:   }  //bblEnd
    78: 
    79: }  //class Bubble