/**
  * 更新游戏画布,成比例调整显示位置(画面变更为指定大小)
  *
  * @param img
  * @param w
  * @param h
  */
 public void updateFull(Bitmap bit, int w, int h) {
   if (!isRunning) {
     return;
   }
   if (bit == null) {
     return;
   }
   canvas = surfaceHolder.lockCanvas(null);
   if (canvas != null) {
     int nw = bit.getWidth();
     int nh = bit.getHeight();
     if (nw == w && nh == h) {
       synchronized (surfaceHolder) {
         canvas.drawBitmap(bit, width / 2 - w / 2, height / 2 - h / 2, null);
         if (emulatorButtons != null) {
           emulatorButtons.draw(canvas);
         }
       }
       surfaceHolder.unlockCanvasAndPost(canvas);
       return;
     }
     if (LSystem.isOverrunOS21()) {
       float scaleWidth = ((float) w) / nw;
       float scaleHeight = ((float) h) / nh;
       tmp_matrix.reset();
       tmp_matrix.postScale(scaleWidth, scaleHeight);
       tmp_matrix.postTranslate(width / 2 - w / 2, height / 2 - h / 2);
       synchronized (surfaceHolder) {
         canvas.drawBitmap(bit, tmp_matrix, null);
         if (emulatorButtons != null) {
           emulatorButtons.draw(canvas);
         }
       }
       surfaceHolder.unlockCanvasAndPost(canvas);
     } else {
       int x = width / 2 - w / 2;
       int y = height / 2 - h / 2;
       Rect srcR = new Rect(0, 0, w, h);
       Rect dstR = new Rect(x, y, x + w, y + h);
       synchronized (surfaceHolder) {
         canvas.drawBitmap(bit, srcR, dstR, null);
         if (emulatorButtons != null) {
           emulatorButtons.draw(canvas);
         }
       }
       surfaceHolder.unlockCanvasAndPost(canvas);
     }
   }
 }
 /**
  * 更有游戏画布为指定大小
  *
  * @param bit
  * @param w
  * @param h
  */
 public void updateResize(Bitmap bit, int w, int h) {
   if (!isRunning) {
     return;
   }
   if (bit == null) {
     return;
   }
   canvas = surfaceHolder.lockCanvas(null);
   if (canvas != null) {
     int nw = bit.getWidth();
     int nh = bit.getHeight();
     float scaleWidth = ((float) w) / nw;
     float scaleHeight = ((float) h) / nh;
     tmp_matrix.reset();
     tmp_matrix.postScale(scaleWidth, scaleHeight);
     tmp_matrix.postTranslate(width / 2 - w / 2, height / 2 - h / 2);
     synchronized (surfaceHolder) {
       if (resizePaint == null) {
         resizePaint = new Paint();
       }
       resizePaint.setFilterBitmap(true);
       canvas.drawBitmap(bit, tmp_matrix, resizePaint);
       resizePaint.setFilterBitmap(false);
       if (emulatorButtons != null) {
         emulatorButtons.draw(canvas);
       }
     }
     surfaceHolder.unlockCanvasAndPost(canvas);
   }
 }
 public boolean onTouchEvent(MotionEvent e) {
   if (emulatorButtons != null) {
     emulatorButtons.onEmulatorButtonEvent(e);
   }
   activity.onTouchEvent(e);
   try {
     Thread.sleep(16);
   } catch (Exception ex) {
   }
   return true;
 }
 /**
  * 设定模拟按钮监听器
  *
  * @param emulatorListener
  */
 public void setEmulatorListener(EmulatorListener emulator) {
   this.emulatorListener = emulator;
   if (emulatorListener != null) {
     if (emulatorButtons == null) {
       emulatorButtons = new EmulatorButtons(emulatorListener, width, height);
     } else {
       emulatorButtons.setEmulatorListener(emulator);
     }
   } else {
     emulatorButtons = null;
   }
 }
 /**
  * 更新游戏画布
  *
  * @param bit
  * @param w
  * @param h
  */
 public void update(Bitmap bit, int w, int h) {
   if (!isRunning) {
     return;
   }
   if (bit == null) {
     return;
   }
   canvas = surfaceHolder.lockCanvas(null);
   if (canvas != null) {
     synchronized (surfaceHolder) {
       canvas.drawBitmap(bit, width / 2 - w / 2, height / 2 - h / 2, null);
       if (emulatorButtons != null) {
         emulatorButtons.draw(canvas);
       }
     }
     surfaceHolder.unlockCanvasAndPost(canvas);
   }
 }
 /**
  * 更新游戏画布
  *
  * @param img
  */
 public void update(Bitmap bit) {
   try {
     if (!isRunning) {
       return;
     }
     if (bit == null) {
       return;
     }
     canvas = surfaceHolder.lockCanvas(null);
     if (canvas != null) {
       synchronized (surfaceHolder) {
         canvas.drawBitmap(bit, 0, 0, null);
         if (emulatorButtons != null) {
           emulatorButtons.draw(canvas);
         }
       }
       surfaceHolder.unlockCanvasAndPost(canvas);
     }
   } catch (Exception e) {
   }
 }