SpritePatternViewer.java
     1: //========================================================================================
     2: //  SpritePatternViewer.java
     3: //    en:Sprite pattern viewer
     4: //    ja:スプライトパターンビュア
     5: //  Copyright (C) 2003-2017 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: //  http://stdkmd.com/xeij/
    11: //========================================================================================
    12: 
    13: //----------------------------------------------------------------------------------------
    14: //!!! 工事中
    15: //  16x16のパターンを32x32に拡大して表示する
    16: //    パターン
    17: //      幅32px
    18: //      高さ32px
    19: //    セル
    20: //      幅32px+ギャップ4px=幅36px/列
    21: //      高さ32px+ギャップ8px=高さ40px/行
    22: //    パターンエリア
    23: //      幅36px/列*20列=幅720px
    24: //      高さ40px/行*13行=高さ520px
    25: //    PNL_STRETCH_BASEに従って水平方向に拡大してもよいがパネルの幅が変わってしまうので保留
    26: //  パレットブロックは自動的に選択する
    27: //    スプライトスクロールレジスタで使用されたことがあるとき
    28: //      最後に使用されたパレットブロック
    29: //    スプライトスクロールレジスタで使用されたことがないとき
    30: //      直前のパターンと同じパレットブロック
    31: //----------------------------------------------------------------------------------------
    32: 
    33: package xeij;
    34: 
    35: import java.awt.*;  //BasicStroke,BorderLayout,BoxLayout,Color,Component,Container,Cursor,Desktop,Dimension,Font,Frame,Graphics,Graphics2D,GraphicsDevice,GraphicsEnvironment,GridLayout,Image,Insets,Paint,Point,Rectangle,RenderingHints,Robot,Shape,Stroke,TexturePaint,Toolkit
    36: import java.awt.event.*;  //ActionEvent,ActionListener,ComponentAdapter,ComponentEvent,ComponentListener,FocusAdapter,FocusEvent,FocusListener,InputEvent,KeyAdapter,KeyEvent,KeyListener,MouseAdapter,MouseEvent,MouseListener,MouseMotionAdapter,MouseWheelEvent,WindowAdapter,WindowEvent,WindowListener,WindowStateListener
    37: import java.awt.image.*;  //BufferedImage,DataBuffer,DataBufferByte,DataBufferInt,IndexColorModel
    38: import java.lang.*;  //Boolean,Character,Class,Comparable,Double,Exception,Float,IllegalArgumentException,Integer,Long,Math,Number,Object,Runnable,SecurityException,String,StringBuilder,System
    39: import java.util.*;  //ArrayList,Arrays,Calendar,GregorianCalendar,HashMap,Map,Map.Entry,TimeZone,Timer,TimerTask,TreeMap
    40: import javax.swing.*;  //AbstractSpinnerModel,Box,ButtonGroup,DefaultListModel,ImageIcon,JApplet,JButton,JCheckBox,JCheckBoxMenuItem,JDialog,JFileChooser,JFrame,JLabel,JList,JMenu,JMenuBar,JMenuItem,JPanel,JRadioButton,JScrollPane,JSpinner,JTextArea,JTextField,JTextPane,JViewport,ScrollPaneConstants,SpinnerListModel,SpinnerNumberModel,SwingConstants,SwingUtilities,UIManager,UIDefaults,UnsupportedLookAndFeelException
    41: 
    42: public class SpritePatternViewer {
    43: 
    44:   public static final boolean SPV_ON = true;
    45: 
    46:   //キャンバス
    47:   public static final int SPV_CANVAS_WIDTH = 724;
    48:   public static final int SPV_CANVAS_HEIGHT = 522;
    49:   public static final int SPV_BACKGROUND_RGB = 0xff333333;  //背景色
    50:   public static final int SPV_NUMBER_HEX_RGB = 0xff999999;  //スプライト番号(16進数)の色
    51:   public static final int SPV_NUMBER_DEC_RGB = 0xffffffff;  //スプライト番号(10進数)の色
    52:   public static final int SPV_PALET_BLOCK_RGB = 0xff999999;  //パレットブロックの色
    53:   public static BufferedImage spvImage;  //イメージ
    54:   public static int[] spvBitmap;  //ビットマップ
    55: 
    56:   //パネル
    57:   public static JPanel spvPanel;  //パネル
    58: 
    59:   //ウインドウ
    60:   public static JFrame spvFrame;  //ウインドウ
    61: 
    62:   //タイマー
    63:   public static final int SPV_INTERVAL = 10;
    64:   public static int spvTimer;
    65: 
    66:   //パレットブロック
    67:   public static final int[] spvLastPaletBlock = new int[256];  //前回のパレットブロック<<4
    68:   public static final int[] spvPaletBlock = new int[256];  //パレットブロック<<4
    69: 
    70:   public static void spvInit () {
    71: 
    72:     //ウインドウ
    73:     spvFrame = null;
    74: 
    75:     //タイマー
    76:     spvTimer = 0;
    77: 
    78:     //パレットブロック
    79:     for (int n = 0; n < 256; n++) {
    80:       spvLastPaletBlock[n] = 0x10;
    81:     }
    82: 
    83:   }  //spvInit()
    84: 
    85:   //spvStart ()
    86:   public static void spvStart () {
    87:     if (RestorableFrame.rfmGetOpened (Settings.SGS_SPV_FRAME_KEY)) {
    88:       spvOpen ();
    89:     }
    90:   }  //spvStart()
    91: 
    92:   //spvOpen ()
    93:   //  スプライトパターンビュアを開く
    94:   public static void spvOpen () {
    95:     if (spvFrame == null) {
    96:       spvMakeFrame ();
    97:     } else {
    98:       spvUpdateFrame ();
    99:     }
   100:     XEiJ.dbgVisibleMask |= XEiJ.DBG_SPV_VISIBLE_MASK;
   101:     spvFrame.setVisible (true);
   102:   }  //spvOpen()
   103: 
   104:   //spvMakeFrame ()
   105:   //  スプライトパターンビュアを作る
   106:   //  ここでは開かない
   107:   public static void spvMakeFrame () {
   108: 
   109:     //キャンバス
   110:     spvImage = new BufferedImage (SPV_CANVAS_WIDTH, SPV_CANVAS_HEIGHT, BufferedImage.TYPE_INT_RGB);
   111:     spvBitmap = ((DataBufferInt) spvImage.getRaster ().getDataBuffer ()).getData ();
   112:     Arrays.fill (spvBitmap, SPV_BACKGROUND_RGB);
   113:     for (int n = 0; n < 256; n++) {
   114:       //  perl misc/optdiv.pl 255 20
   115:       //  x/20==x*205>>>12 (0<=x<=1038) [255*205==52275]
   116:       int ny = n * 205 >>> 12;
   117:       int nx = n - 20 * ny;
   118:       int x0 = 4 + 36 * nx;
   119:       int y0 = 8 + 40 * ny;
   120:       int i0 = x0 + SPV_CANVAS_WIDTH * y0;
   121:       //0x10の位
   122:       {
   123:         int t = n >>> 4;
   124:         spvPutc (-6 * SPV_CANVAS_WIDTH + i0, (9 - t >> 4 & 7 | 48) + t, SPV_NUMBER_HEX_RGB);
   125:       }
   126:       //0x1の位
   127:       {
   128:         int t = n & 15;
   129:         spvPutc (4 + -6 * SPV_CANVAS_WIDTH + i0, (9 - t >> 4 & 7 | 48) + t, SPV_NUMBER_HEX_RGB);
   130:       }
   131:       //100の位
   132:       int bcd = XEiJ.FMT_BCD4[n];
   133:       if (100 <= n) {
   134:         spvPutc (10 + -6 * SPV_CANVAS_WIDTH + i0, bcd >>> 8 | 48, SPV_NUMBER_DEC_RGB);
   135:       }
   136:       //10の位
   137:       if (10 <= n) {
   138:         spvPutc (14 + -6 * SPV_CANVAS_WIDTH + i0, bcd >>> 4 & 15 | 48, SPV_NUMBER_DEC_RGB);
   139:       }
   140:       //1の位
   141:       spvPutc (18 + -6 * SPV_CANVAS_WIDTH + i0, bcd & 15 | 48, SPV_NUMBER_DEC_RGB);
   142:     }  //for n
   143: 
   144:     //パネル
   145:     spvPanel = ComponentFactory.setFixedSize (
   146:       new JPanel () {
   147:         @Override protected void paintComponent (Graphics g) {
   148:           g.drawImage (spvImage, 0, 0, null);
   149:         }
   150:         @Override protected void paintBorder (Graphics g) {
   151:         }
   152:         @Override protected void paintChildren (Graphics g) {
   153:         }
   154:       },
   155:       SPV_CANVAS_WIDTH, SPV_CANVAS_HEIGHT);
   156:     spvPanel.setBackground (Color.black);
   157:     spvPanel.setOpaque (true);
   158: 
   159:     //ウインドウ
   160:     spvFrame = Multilingual.mlnTitle (
   161:       ComponentFactory.createRestorableSubFrame (
   162:         Settings.SGS_SPV_FRAME_KEY,
   163:         "Sprite Pattern Viewer",
   164:         null,
   165:         spvPanel
   166:         ),
   167:       "ja", "スプライトパターンビュア");  //Multilingual.mlnTitle
   168: 
   169:     //  ウインドウリスナー
   170:     ComponentFactory.addListener (
   171:       spvFrame,
   172:       new WindowAdapter () {
   173:         @Override public void windowClosing (WindowEvent we) {
   174:           XEiJ.dbgVisibleMask &= ~XEiJ.DBG_SPV_VISIBLE_MASK;
   175:         }
   176:       });
   177: 
   178:   }  //spvMakeFrame()
   179: 
   180:   //spvUpdateFrame ()
   181:   //  スプライトパターンビュアを更新する
   182:   public static void spvUpdateFrame () {
   183: 
   184:     if (spvFrame == null) {
   185:       return;
   186:     }
   187: 
   188:     //パレットブロック
   189:     for (int n = 0; n < 256; n++) {
   190:       spvPaletBlock[n] = -1;
   191:     }
   192:     for (int sn = 0; sn < 128; sn++) {  //スプライト番号
   193:       int n = SpriteScreen.sprNum[sn];  //パターン番号
   194:       if (spvPaletBlock[n] < 0) {
   195:         spvPaletBlock[n] = spvLastPaletBlock[n] = SpriteScreen.sprColPort[sn];  //パレットブロック<<4
   196:       }
   197:     }
   198:     for (int n = 0; n < 256; n++) {
   199:       if (spvPaletBlock[n] < 0) {
   200:         spvPaletBlock[n] = spvLastPaletBlock[n];
   201:       }
   202:     }
   203:     int a = 0;
   204:     for (int n = 0; n < 256; n++) {
   205:       //  perl misc/optdiv.pl 255 20
   206:       //  x/20==x*205>>>12 (0<=x<=1038) [255*205==52275]
   207:       int ny = n * 205 >>> 12;
   208:       int nx = n - 20 * ny;
   209:       int x0 = 4 + 36 * nx;
   210:       int y0 = 8 + 40 * ny;
   211:       int i0 = x0 + SPV_CANVAS_WIDTH * y0;
   212:       //パレットブロック
   213:       int p = spvPaletBlock[n];  //パレットブロック<<4
   214:       //10の位
   215:       spvPutc (24 + -6 * SPV_CANVAS_WIDTH + i0, p < 0xa0 ? ' ' : '1', SPV_PALET_BLOCK_RGB);
   216:       //1の位
   217:       spvPutc (28 + -6 * SPV_CANVAS_WIDTH + i0, (p < 0xa0 ? p : p - 0xa0) >>> 4 | 48, SPV_PALET_BLOCK_RGB);
   218:       //パターン
   219:       //  +---+---+
   220:       //  | 0 | 2 |
   221:       //  +---+---+
   222:       //  | 1 | 3 |
   223:       //  +---+---+
   224:       for (int u = 0; u < 32; u += 16) {
   225:         for (int v = 0; v < 32; v += 2) {
   226:           int d = SpriteScreen.sprPatPort[a++];
   227:           int i = u + v * SPV_CANVAS_WIDTH + i0;
   228:           int t = VideoController.vcnPal32TS[d >>> 28 | p];
   229:           spvBitmap[                        i] = t;
   230:           spvBitmap[ 1 +                    i] = t;
   231:           spvBitmap[     SPV_CANVAS_WIDTH + i] = t;
   232:           spvBitmap[ 1 + SPV_CANVAS_WIDTH + i] = t;
   233:           t = VideoController.vcnPal32TS[d >>> 24 & 15 | p];
   234:           spvBitmap[ 2 +                    i] = t;
   235:           spvBitmap[ 3 +                    i] = t;
   236:           spvBitmap[ 2 + SPV_CANVAS_WIDTH + i] = t;
   237:           spvBitmap[ 3 + SPV_CANVAS_WIDTH + i] = t;
   238:           t = VideoController.vcnPal32TS[d >>> 20 & 15 | p];
   239:           spvBitmap[ 4 +                    i] = t;
   240:           spvBitmap[ 5 +                    i] = t;
   241:           spvBitmap[ 4 + SPV_CANVAS_WIDTH + i] = t;
   242:           spvBitmap[ 5 + SPV_CANVAS_WIDTH + i] = t;
   243:           t = VideoController.vcnPal32TS[d >>> 16 & 15 | p];
   244:           spvBitmap[ 6 +                    i] = t;
   245:           spvBitmap[ 7 +                    i] = t;
   246:           spvBitmap[ 6 + SPV_CANVAS_WIDTH + i] = t;
   247:           spvBitmap[ 7 + SPV_CANVAS_WIDTH + i] = t;
   248:           t = VideoController.vcnPal32TS[(char) d >>> 12 | p];
   249:           spvBitmap[ 8 +                    i] = t;
   250:           spvBitmap[ 9 +                    i] = t;
   251:           spvBitmap[ 8 + SPV_CANVAS_WIDTH + i] = t;
   252:           spvBitmap[ 9 + SPV_CANVAS_WIDTH + i] = t;
   253:           t = VideoController.vcnPal32TS[d >>> 8 & 15 | p];
   254:           spvBitmap[10 +                    i] = t;
   255:           spvBitmap[11 +                    i] = t;
   256:           spvBitmap[10 + SPV_CANVAS_WIDTH + i] = t;
   257:           spvBitmap[11 + SPV_CANVAS_WIDTH + i] = t;
   258:           t = VideoController.vcnPal32TS[d >>> 4 & 15 | p];
   259:           spvBitmap[12 +                    i] = t;
   260:           spvBitmap[13 +                    i] = t;
   261:           spvBitmap[12 + SPV_CANVAS_WIDTH + i] = t;
   262:           spvBitmap[13 + SPV_CANVAS_WIDTH + i] = t;
   263:           t = VideoController.vcnPal32TS[d & 15 | p];
   264:           spvBitmap[14 +                    i] = t;
   265:           spvBitmap[15 +                    i] = t;
   266:           spvBitmap[14 + SPV_CANVAS_WIDTH + i] = t;
   267:           spvBitmap[15 + SPV_CANVAS_WIDTH + i] = t;
   268:         }  //for v
   269:       }  //for u
   270:     }  //for n
   271:     spvPanel.repaint ();
   272: 
   273:   }  //spvUpdateFrame()
   274: 
   275:   public static void spvPutc (int i, int c, int f) {
   276:     int t = Indicator.IND_ASCII_3X5[c];
   277:     spvBitmap[                           i] = t << 31 - 14 < 0 ? f : SPV_BACKGROUND_RGB;
   278:     spvBitmap[1 +                        i] = t << 31 - 13 < 0 ? f : SPV_BACKGROUND_RGB;
   279:     spvBitmap[2 +                        i] = t << 31 - 12 < 0 ? f : SPV_BACKGROUND_RGB;
   280:     spvBitmap[    1 * SPV_CANVAS_WIDTH + i] = t << 31 - 11 < 0 ? f : SPV_BACKGROUND_RGB;
   281:     spvBitmap[1 + 1 * SPV_CANVAS_WIDTH + i] = t << 31 - 10 < 0 ? f : SPV_BACKGROUND_RGB;
   282:     spvBitmap[2 + 1 * SPV_CANVAS_WIDTH + i] = t << 31 -  9 < 0 ? f : SPV_BACKGROUND_RGB;
   283:     spvBitmap[    2 * SPV_CANVAS_WIDTH + i] = t << 31 -  8 < 0 ? f : SPV_BACKGROUND_RGB;
   284:     spvBitmap[1 + 2 * SPV_CANVAS_WIDTH + i] = t << 31 -  7 < 0 ? f : SPV_BACKGROUND_RGB;
   285:     spvBitmap[2 + 2 * SPV_CANVAS_WIDTH + i] = t << 31 -  6 < 0 ? f : SPV_BACKGROUND_RGB;
   286:     spvBitmap[    3 * SPV_CANVAS_WIDTH + i] = t << 31 -  5 < 0 ? f : SPV_BACKGROUND_RGB;
   287:     spvBitmap[1 + 3 * SPV_CANVAS_WIDTH + i] = t << 31 -  4 < 0 ? f : SPV_BACKGROUND_RGB;
   288:     spvBitmap[2 + 3 * SPV_CANVAS_WIDTH + i] = t << 31 -  3 < 0 ? f : SPV_BACKGROUND_RGB;
   289:     spvBitmap[    4 * SPV_CANVAS_WIDTH + i] = t << 31 -  2 < 0 ? f : SPV_BACKGROUND_RGB;
   290:     spvBitmap[1 + 4 * SPV_CANVAS_WIDTH + i] = t << 31 -  1 < 0 ? f : SPV_BACKGROUND_RGB;
   291:     spvBitmap[2 + 4 * SPV_CANVAS_WIDTH + i] = t << 31 -  0 < 0 ? f : SPV_BACKGROUND_RGB;
   292:   }  //spvPutc(int,int)
   293: 
   294: }  //class SpritePatternViewer
   295: 
   296: 
   297: