示例#1
0
  /**
   * Metoda wyswietlajaca pasek postepu nad przyciskami
   *
   * @param g Referencja do obiektu klasy Graphics, ktory pozwala na narysowanie pasku postepu
   * @param current Aktualny czas trwania piosenki, 0 <= progress <= max
   * @param max Calkowity czas trwania piosenki
   */
  public void showProgressBar(Graphics g, int current, int max) {
    int color = g.getColor(); // przechowanie uzywanego koloru
    int progressBarWidth = screenWidth - 25; // szerokosc paska postepu
    int progress = (progressBarWidth * current) / max;

    if (current == -1) // jesli timer jest wylaczony
    progress = 0;

    g.setColor(110, 110, 110); // narysowanie szarej obwodki
    g.drawRect(10, screenHeight - 29 + buttonsLocation, progressBarWidth + 3, 17);

    g.setColor(90, 90, 90); // narysowanie ciemnej obwodki
    g.drawRect(11, screenHeight - 28 + buttonsLocation, progressBarWidth + 1, 15);

    g.setColor(BACKGROUND_COLOR);
    g.fillRect(12, screenHeight - 27 + buttonsLocation, progressBarWidth, 14);

    g.setColor(230, 230, 230);
    g.fillRect(12, screenHeight - 27 + buttonsLocation, progress, 14);

    g.setColor(70, 70, 70);

    if (this.displayedScreen == MainCanvas.PLAYER_SCREEN)
      g.drawString(
          bluetoothPlayer.getCurrentTimeString(),
          screenWidth / 2 - 17,
          screenHeight - 26 + buttonsLocation,
          Graphics.TOP | Graphics.LEFT);

    g.setColor(color);
  }
示例#2
0
  protected void doPaintAxis(final Graphics g) {
    if (scaleSizeInPixel == 0 || mapBackground != null) {
      return;
    }

    final Font font = Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_SMALL);
    g.setFont(font);
    g.setColor(0x00000000);

    final int textBottom = height - 4 - SCALE_HEIGTH;
    int left = 0;
    for (int i = 0; i < scaleConfiguration.labelLocation.length; i++) {
      final float location = scaleConfiguration.labelLocation[i];
      final float value = scaleConfiguration.labelValue[i];
      String label = Utils.floatToString(value, true);
      if (location == 0) {
        left = (font.stringWidth(label) / 2) + 2;
      } else if (location == 1) {
        label += " " + scaleConfiguration.unit;
      }
      g.drawString(
          label,
          left + (int) (scaleSizeInPixel * location),
          textBottom,
          Graphics.BOTTOM | Graphics.HCENTER);
    }
    g.drawRect(left, height - 2 - SCALE_HEIGTH, scaleSizeInPixel, SCALE_HEIGTH);
    g.fillRect(left, height - 2 - SCALE_HEIGTH, scaleSizeInPixel / 2, SCALE_HEIGTH);
  }
  void displayCharacterMap(Graphics g) {
    if (currentChars != null) {
      g.setColor(0xffffff);
      g.fillRect(0, getHeight() - inputHeight - 2, getWidth(), inputHeight + 2);
      g.setColor(0x000000);
      g.drawLine(0, getHeight() - inputHeight - 2, getWidth(), getHeight() - inputHeight - 2);
      for (int i = 0; i < currentChars.length; i++) {
        char ch = currentChars[i];
        if (isUppercase) {
          ch = String.valueOf(currentChars[i]).toUpperCase().charAt(0);
        }

        // TODO: if i*12 > getWidth() ?

        g.drawChar(ch, i * 12, getHeight() - inputHeight, Graphics.LEFT | Graphics.TOP);
        if (currentChars[currentKeyStep] == currentChars[i]) {
          g.drawRect(
              i * 12 - 2,
              getHeight() - inputHeight - 2,
              inputFont.charWidth(ch) + 4,
              inputHeight + 4);
        }
      }
    }
  }
示例#4
0
 // 顯示畫面
 public void drawDisplay() {
   g = getGraphics();
   g.setColor(0, 0, 0);
   g.drawRect(disWidth - 1, disHeight - 1, 176 + 1, 208 + 1);
   layMa.paint(g, disWidth, disHeight);
   g.drawString(getWidth() + "|" + getHeight(), 0, 0, 0);
   flushGraphics();
 }
示例#5
0
 public void repaint(Graphics g) {
   if (isFocusable && isFocused) {
     g.setColor(actOuterLight);
     g.drawRect(x, y, width, height);
     g.setColor(actInnerLight);
     g.drawRect(x + 1, y + 1, width - 2, height - 2);
   }
   smileLink.updateLocation(
       x + (isCenteredHorizontally ? (width / 2 - smileLink.getWidth() / 2) : 0),
       y
           + (isCenteredVertically
               ? (height / 2 - smileLink.getHeight() / 2)
               : (isUpSize ? Theme.upSize : 0)));
   if (g != null) {
     Smiles.smiles[smileLink.smileIndex].paint(g, smileLink.x, smileLink.y, smileLink.frameIndex);
     smileLink.analyzeFrame();
   }
 }
示例#6
0
 public void drawFightCheck(Graphics g, int viewX, int viewY) {
   g.setColor(255, 255, 255);
   int x, y;
   for (int i = 0; i < fightRange.length; i++) {
     if (!canMoveFight(i)) continue;
     x = fightRange[i][1] * MyGameCanvas.CHECKWIDTH;
     y = fightRange[i][0] * MyGameCanvas.CHECKHEIGHT;
     g.drawRect(x - viewX, y - viewY, MyGameCanvas.CHECKWIDTH, MyGameCanvas.CHECKHEIGHT);
   }
 }
示例#7
0
  public void paint(Graphics g) {
    int w = getWidth();
    int h = getHeight();

    g.setColor(0xffffff);
    g.fillRect(0, 0, w, h);
    g.setColor(0x000000);

    for (int x = 0; x < w; x += 10) g.drawLine(0, w - x, x, 0);

    int z = 50;
    g.drawRect(z, z, 20, 20);
    z += 20;
    g.fillRoundRect(z, z, 20, 20, 5, 5);
    z += 20;
    g.drawArc(z, z, 20, 20, 0, 360);
  }
  /**
   * Paint the canvas with the current color and controls to change it.
   *
   * @param g the graphics context to draw to the screen.
   */
  protected void paint(Graphics g) {
    int w = getWidth();
    int h = getHeight();

    int sample_w = w - 1;
    int sample_h = h - ((BAR_H + BORDER) * 3);
    int sample_y = BORDER;

    int b_y = sample_y + sample_h + (BORDER * 2);
    int g_y = b_y + BAR_H;
    int r_y = g_y + BAR_H;

    // Fill the background
    g.setColor(0x000000);
    g.fillRect(0, 0, w, h);

    // Fill in the color sample
    g.setColor(rgbColor);
    g.fillRect(BORDER, sample_y, sample_w, sample_h);

    // Draw the color bars
    int blue = (rgbColor >> 0) & 0xff;
    g.setColor(0, 0, 255);
    g.fillRect(20, b_y, blue / 4, 10);

    int green = (rgbColor >> 8) & 0xff;
    g.setColor(0, 255, 0);
    g.fillRect(20, g_y, green / 4, 10);

    int red = (rgbColor >> 16) & 0xff;
    g.setColor(255, 0, 0);
    g.fillRect(20, r_y, red / 4, 10);

    g.setColor(255, 255, 255);
    g.drawString(Integer.toString(blue), 18, b_y - 3, Graphics.RIGHT | Graphics.TOP);
    g.drawString(Integer.toString(green), 18, g_y - 3, Graphics.RIGHT | Graphics.TOP);
    g.drawString(Integer.toString(red), 18, r_y - 3, Graphics.RIGHT | Graphics.TOP);

    if (ndx >= 0) {
      int y = b_y + (ndx * BAR_H);
      g.drawRect(20, y, 63, 10);
    }
  }
示例#9
0
 public void drawMoveCheck(Graphics g, int viewX, int viewY) {
   g.setColor(255, 255, 255);
   int startR = oldRow - moveRangeR;
   if (startR < 0) startR = 0;
   int endR = oldRow + moveRangeR;
   if (endR >= checkMsg.length) endR = checkMsg.length - 1;
   int startC = oldCol - moveRangeC;
   if (startC < 0) startC = 0;
   int endC = oldCol + moveRangeC;
   if (endC >= checkMsg[0].length) endC = checkMsg[0].length - 1;
   int x, y;
   for (int i = startR; i <= endR; i++) {
     for (int j = startC; j <= endC; j++) {
       if (checkMsg[i][j] != -1) continue;
       x = j * MyGameCanvas.CHECKWIDTH;
       y = i * MyGameCanvas.CHECKHEIGHT;
       g.drawRect(x - viewX, y - viewY, MyGameCanvas.CHECKWIDTH, MyGameCanvas.CHECKHEIGHT);
     }
   }
 }
示例#10
0
 public void drawHp(Graphics g, int viewX, int viewY) {
   if (isDeath) return;
   if (showHpCount == 0) return;
   showHpCount++;
   if (showHpCount > 40) showHpCount = 0;
   g.setColor(0, 0, 255);
   g.drawString(
       grade + "",
       getX() - viewX + getWidth() / 2,
       getY() - viewY - 3,
       Graphics.TOP | Graphics.LEFT);
   g.setColor(174, 174, 174);
   g.drawRect(getX() - viewX, getY() - viewY - 2, getWidth(), 2);
   g.setColor(128, 128, 128);
   g.fillRect(getX() - viewX, getY() - viewY - 2, getWidth(), 2);
   g.setColor(255, 0, 0);
   if (hpNow < 0) hpNow = 0;
   int width = hpNow * getWidth() / 100;
   g.fillRect(getX() - viewX, getY() - viewY - 2, width, 2);
 }
示例#11
0
  /**
   * Metoda wyswietlajaca biblioteke muzyczna na wyswietlaczu
   *
   * @param g Referencja do obiektu klasy Graphics, ktory pozwala na wyswietlenie tekstu
   * @param player Referencja do obiektu klasy odtwarzacza muzycznego
   * @param screenSelectedItemIndex Indeks wybranego elementu na wyswietlaczu
   * @param screenNumberOfItems Liczba elementow wyswietlonych na wyswietlaczu
   */
  public void showMediaLibrary(
      Graphics g, BluetoothPlayer player, int screenSelectedItemIndex, int screenNumberOfItems) {
    int color = g.getColor(); // przechowanie uzywanego koloru
    int textPos = 0;
    String text;

    g.setColor(255, 255, 255); // biala czcionka

    for (int i = 0; i < screenNumberOfItems; i++) {
      text =
          bluetoothPlayer
              .getMediaLibrary()
              .getItem(
                  bluetoothPlayer.getMediaLibrary().getMediaLibrarySelectedItem()
                      - screenSelectedItemIndex
                      + i,
                  g);

      if (text != null) {
        // jesli zmienil sie wybrany tekst
        if ((screenSelectedItemIndex == i) && (text.equals(mediaLibraryLastText) == false)) {
          mediaLibraryLastText = text;
          mediaLibraryTextPos = 0;
          mediaLibraryWaitTimeText = SCROLL_TIME_WAIT;
        }
        textPos = mediaLibraryTextPos;

        // if whole text can be displayed at once
        if (Font.getDefaultFont().stringWidth(text) <= screenWidth - 32) {
          g.setColor(255, 255, 255); // biala czcionka
          g.drawString(text, 10, i * (fontHeight + 5) + 8, Graphics.TOP | Graphics.LEFT);
        }
        // if text doesn't fit into the screen
        else {
          String leftTextTmp = "";
          int j = 0;

          // cut text from the left as long as it doesn't fit to the screen (only for selected item)
          if (screenSelectedItemIndex == i)
            while (Font.getDefaultFont().stringWidth(leftTextTmp) < textPos) {
              leftTextTmp = text.substring(0, ++j);
            }

          String textTmp = text.substring(j, text.length());

          boolean textRightCut = false;
          // cut text from the right as long as it doesn't fit to the screen
          while (Font.getDefaultFont().stringWidth(textTmp) > screenWidth - 24) {
            textTmp = textTmp.substring(0, textTmp.length() - 1);
            textRightCut = true;
          }

          g.setColor(255, 255, 255); // biala czcionka
          g.drawString(textTmp, 10, i * (fontHeight + 5) + 8, Graphics.TOP | Graphics.LEFT);

          g.setColor(BACKGROUND_COLOR); // zamazanie tekstu po bokach
          g.fillRect(screenWidth - 10, i * (fontHeight + 5) + 8, 5, fontHeight);

          if (screenSelectedItemIndex == i) {
            if ((textRightCut == false)
                && (mediaLibraryWaitTimeText == 0)) // jesli tekst przewinal sie do konca
            mediaLibraryWaitTimeText = SCROLL_TIME_WAIT;

            if (mediaLibraryWaitTimeText == 0) mediaLibraryTextPos += 2; // przewiniecie tekstu
            // if text is going to be displayed statically (without scrolling it)
            else {
              mediaLibraryWaitTimeText--;
              // if wait time has ended, start scrolling from the beginning
              if ((mediaLibraryWaitTimeText == 0) && (mediaLibraryTextPos != 0)) {
                mediaLibraryWaitTimeText = SCROLL_TIME_WAIT;
                mediaLibraryTextPos = 0;
              }
            }
          }
        }
      }
    }

    g.setColor(255, 255, 255);

    // obwodka dla podswietlonego elementu
    if (screenNumberOfItems > 0)
      g.drawRect(
          7, screenSelectedItemIndex * (fontHeight + 5) + 6, screenWidth - 16, fontHeight + 1);

    g.setColor(color);
  }
示例#12
0
  public void paint(Graphics g) {

    int strHeight = FireScreen.defaultTickerFont.getHeight();

    int xpos = PADLEFT;
    int ypos = PADTOP;
    int selColor = FireScreen.defaultPointerColor;
    if (FireScreen.selectedLinkBgColor != null)
      selColor = FireScreen.selectedLinkBgColor.intValue();

    if (label != null) {
      g.setFont(label.getFont());
      g.setColor(0x00000000);
      Vector lines = label.getFormatedText();
      int rowHeight = label.getRowHeight();

      for (int i = 0; i < lines.size(); ++i) {
        String str = (String) lines.elementAt(i);
        g.drawString(
            str,
            xpos,
            ypos + (i * (rowHeight + FString.LINE_DISTANCE)),
            Graphics.TOP | Graphics.LEFT);
      }

      ypos += label.getHeight() + PADTOP;
    }

    g.setFont(FireScreen.defaultTickerFont);
    // day
    g.setColor(0xFFFFFFFF);
    g.fillRect(xpos, ypos, dayWidth, strHeight);
    if (pointer == DAY) g.setColor(selColor);
    else g.setColor(0x00000000);

    int d = date.get(Calendar.DAY_OF_MONTH) + 1;
    String day;
    if (d < 10) day = "0" + d;
    else day = d + "";
    g.drawString(day, xpos + 1, ypos + 1, Graphics.TOP | Graphics.LEFT);
    g.setColor(0x00000000);
    g.drawRect(xpos, ypos, dayWidth, strHeight);

    xpos += dayWidth + 2;
    g.drawString("/", xpos, ypos + 1, Graphics.TOP | Graphics.LEFT);
    xpos += SPACER;

    // month
    g.setColor(0xFFFFFFFF);
    g.fillRect(xpos, ypos, monthWidth, strHeight);
    if (pointer == MONTH) g.setColor(selColor);
    else g.setColor(0x00000000);
    int m = date.get(Calendar.MONTH) + 1;
    String month;
    if (m < 10) month = "0" + m;
    else month = m + "";
    g.drawString(month, xpos + 1, ypos + 1, Graphics.TOP | Graphics.LEFT);
    g.drawRect(xpos, ypos, monthWidth, strHeight);

    xpos += monthWidth + 2;
    g.drawString("/", xpos, ypos + 1, Graphics.TOP | Graphics.LEFT);
    xpos += SPACER;

    // year
    g.setColor(0xFFFFFFFF);
    g.fillRect(xpos, ypos, yearWidth, strHeight);
    if (pointer == YEAR) g.setColor(selColor);
    else g.setColor(0x00000000);
    g.drawString(date.get(Calendar.YEAR) + "", xpos + 1, ypos + 1, Graphics.TOP | Graphics.LEFT);
    g.drawRect(xpos, ypos, yearWidth, strHeight);

    xpos += yearWidth;

    if (showTime) {
      xpos += SPACER + SPACER;
      int h = 0;
      m = 0;

      try {
        h = date.get(Calendar.HOUR_OF_DAY);
        m = date.get(Calendar.MINUTE);
      } catch (Throwable e) {
        try {
          date.set(Calendar.HOUR_OF_DAY, 0);
          date.set(Calendar.MINUTE, 0);
        } catch (Throwable ee) {
        }
      }

      String hour;
      if (h < 10) hour = "0" + h;
      else hour = h + "";

      // hour
      g.setColor(0xFFFFFFFF);
      g.fillRect(xpos, ypos, hourWidth, strHeight);
      if (pointer == HOUR) g.setColor(selColor);
      else g.setColor(0x00000000);
      g.drawString(hour, xpos + 1, ypos + 1, Graphics.TOP | Graphics.LEFT);
      g.drawRect(xpos, ypos, hourWidth, strHeight);

      xpos += hourWidth + 2;
      g.drawString(":", xpos, ypos + 1, Graphics.TOP | Graphics.LEFT);
      xpos += SPACER;

      String min;
      if (m < 10) min = "0" + m;
      else min = m + "";

      // minute
      g.setColor(0xFFFFFFFF);
      g.fillRect(xpos, ypos, minuteWidth, strHeight);
      if (pointer == MINUTE) g.setColor(selColor);
      else g.setColor(0x00000000);
      g.drawString(min, xpos + 1, ypos + 1, Graphics.TOP | Graphics.LEFT);
      g.drawRect(xpos, ypos, minuteWidth, strHeight);

      xpos += minuteWidth;
    }

    if (isSelected()) {
      if (FireScreen.selectedLinkBgColor != null) {
        g.setColor(FireScreen.selectedLinkBgColor.intValue());
      } else {
        g.setColor(FireScreen.linkColor);
      }
      g.drawRect(PADLEFT, ypos, xpos - PADLEFT, strHeight);
    }
  }
示例#13
0
  protected void paint(Graphics g) {
    int w = getWidth();
    int h = getHeight();

    if (_fullRepaintPending) {
      boolean design =
          _state == STATE_CHOOSE_WIDGET
              || _state == STATE_MOVE_WIDGET
              || _state == STATE_RESIZE_WIDGET;
      if (design) g.setColor(0x202060);
      else g.setColor(0);
      g.fillRect(0, 0, w, h);

      // long start = System.currentTimeMillis();
      // paint all widgets
      WidgetInfo.update();
      for (int i = 0; i < _widgets.length; i++) {
        WidgetPosition wp = _widgets[i];
        g.setClip(
            w * wp.col / _ncols,
            h * wp.row / _nrows,
            w * (wp.col + wp.ncols) / _ncols - w * wp.col / _ncols,
            h * (wp.row + wp.nrows) / _nrows - h * wp.row / _nrows);

        if (design) {
          g.setColor(0);
          g.fillRect(g.getClipX(), g.getClipY(), g.getClipWidth(), g.getClipHeight());
        }

        try {
          wp.widget.paint(g, wp.settings);
        } catch (Exception e) {
          Log.error("Widget paint failed! widget=" + wp.widget.getName(), e);
        }
      }
      // Log.info("Widgets repaint: "+(System.currentTimeMillis()-start)+"ms");
      g.setClip(0, 0, getWidth(), getHeight());
      _fullRepaintPending = false;
    }

    if (_state == STATE_WIDGET_MENU
        || _state == STATE_CHOOSE_WIDGET
        || _state == STATE_MOVE_WIDGET
        || _state == STATE_RESIZE_WIDGET) {
      int x1, y1, x2, y2;
      WidgetPosition wp;
      // paint rectangle around all widgets
      for (int i = 0; i < _widgets.length; i++) {
        if (i != _widgetIndex) {
          wp = _widgets[i];
          x1 = wp.col * w / _ncols;
          y1 = wp.row * h / _nrows;
          x2 = (wp.col + wp.ncols) * w / _ncols - 1;
          y2 = (wp.row + wp.nrows) * h / _nrows - 1;
          g.setColor(0x808080);
          g.drawRect(x1, y1, x2 - x1, y2 - y1);
          g.drawRect(x1 - 1, y1 - 1, x2 - x1 + 2, y2 - y1 + 2);
        }
      }

      // paint rectangle around selected widget
      wp = _widgets[_widgetIndex];
      x1 = wp.col * w / _ncols;
      y1 = wp.row * h / _nrows;
      x2 = (wp.col + wp.ncols) * w / _ncols - 1;
      y2 = (wp.row + wp.nrows) * h / _nrows - 1;
      g.setColor(0xff0000);
      g.drawRect(x1, y1, x2 - x1, y2 - y1);
      g.drawRect(x1 - 1, y1 - 1, x2 - x1 + 2, y2 - y1 + 2);

      // paint move/resize icon
      if (_imageMove != null) {
        if (_state == STATE_MOVE_WIDGET)
          g.drawImage(
              _imageMove, (x1 + x2) / 2, (y1 + y2) / 2, Graphics.HCENTER | Graphics.VCENTER);
        else if (_state == STATE_RESIZE_WIDGET)
          g.drawImage(_imageMove, x2, y2, Graphics.HCENTER | Graphics.VCENTER);
      }
    }

    // paint menu
    if (_state == STATE_MAIN_MENU) {
      _mainMenu.paint(g);
    }

    if (_state == STATE_WIDGET_MENU) {
      _widgetMenu.paint(g);
    }

    if (isSoftkeyVisibleState()) {
      g.drawImage(
          _selectedSoftkey == KEY_LEFT ? _imgSoftkeyLeftSel : _imgSoftkeyLeft,
          _softkeysPanelX + _softkeyW / 2,
          _softkeysPanelY + _softkeyH * 3 / 2,
          Graphics.VCENTER | Graphics.HCENTER);
      g.drawImage(
          _selectedSoftkey == KEY_UP ? _imgSoftkeyUpSel : _imgSoftkeyUp,
          _softkeysPanelX + _softkeyW * 3 / 2,
          _softkeysPanelY + _softkeyH / 2,
          Graphics.VCENTER | Graphics.HCENTER);
      g.drawImage(
          _selectedSoftkey == KEY_FIRE ? _imgSoftkeyFireSel : _imgSoftkeyFire,
          _softkeysPanelX + _softkeyW * 3 / 2,
          _softkeysPanelY + _softkeyH * 3 / 2,
          Graphics.VCENTER | Graphics.HCENTER);
      g.drawImage(
          _selectedSoftkey == KEY_DOWN ? _imgSoftkeyDownSel : _imgSoftkeyDown,
          _softkeysPanelX + _softkeyW * 3 / 2,
          _softkeysPanelY + _softkeyH * 5 / 2,
          Graphics.VCENTER | Graphics.HCENTER);
      g.drawImage(
          _selectedSoftkey == KEY_RIGHT ? _imgSoftkeyRightSel : _imgSoftkeyRight,
          _softkeysPanelX + _softkeyW * 5 / 2,
          _softkeysPanelY + _softkeyH * 3 / 2,
          Graphics.VCENTER | Graphics.HCENTER);
    }

    if (_state == STATE_SHOW && _touchHintDisplayTimeout > System.currentTimeMillis()) {
      int s = (w < h ? w : h) / 3;
      g.setColor(0xFF0000);
      g.drawRect(w - s, 0, s - 1, s - 1);
      g.drawRect(w - s + 1, 1, s - 3, s - 3);
      _touchHintMenuPainter.paint(
          g, "MENU", 0, w - s, 0, s, s, Graphics.HCENTER | Graphics.VCENTER);
    }
  }
示例#14
0
  protected void paint(Graphics g) {
    int x = g.getClipX();
    int y = g.getClipY();
    int w = g.getClipWidth();
    int h = g.getClipHeight();

    // Draw the frame
    g.setColor(0xffffff);
    g.fillRect(x, y, w, h);

    // Draw each ball
    for (int i = 0; i < numBalls; i++) {
      if (balls[i].inside(x, y, x + w, y + h)) {
        balls[i].paint(g);
      }
    }

    g.setColor(0);
    g.drawRect(0, 0, width - 1, height - 1);

    long now = System.currentTimeMillis();
    String str = null;

    if (times_idx >= NUM_HISTORY) {
      long oldTime = times[times_idx % NUM_HISTORY];

      if (oldTime == now) {
        // in case of divide-by-zero
        oldTime = now - 1;
      }

      long fps = ((long) 1000 * (long) NUM_HISTORY) / (now - oldTime);

      if ((times_idx % 20) == 0) {
        str = numBalls + " Ball(s) " + fps + " fps";
      }
    } else {
      if ((times_idx % 20) == 0) {
        str = numBalls + " Ball(s)";
      }
    }

    if (msg != null) {
      g.setColor(0xffffff);
      g.setClip(0, height - STATUSBAR_HEIGHT, width, height);
      g.fillRect(0, height - STATUSBAR_HEIGHT, width, STATUSBAR_HEIGHT);

      g.setColor(0);
      g.drawString(msg, 5, height - STATUSBAR_HEIGHT - 2, 0);
      g.drawRect(0, 0, width - 1, height - 1);

      // draw a reflection line
      g.drawLine(0, height - STATUSBAR_HEIGHT, w, height - STATUSBAR_HEIGHT);

      msg = null;
    }

    if (str != null) {
      /*
       * Do a complete repaint, so that the message will
       * be shown even in double-buffer mode.
       */
      repaint();
      msg = str;
    }

    times[times_idx % NUM_HISTORY] = now;
    ++times_idx;
  }
示例#15
0
文件: Game.java 项目: skjApp/J2ME
  public void paint(Graphics g) {
    g.setColor(255, 255, 255);
    g.fillRect(0, 0, maxX, maxY);

    g.setColor(0, 0, 0);
    // This vertical line start at x/2 position
    g.fillRect((this.maxX / 3) - 1, 0, 3, this.maxY);

    // This vertical line start at 2x/3 position
    g.fillRect(((2 * this.maxX) / 3) - 1, 0, 3, this.maxY);

    // This horizontal line start at this.maxY / 3 - 1 position
    g.fillRect(0, (this.maxY / 3) - 1, this.maxX, 3);

    // This horaizental line start at this.maxY / 3 - 1 position
    g.fillRect(0, ((2 * this.maxY) / 3) - 1, this.maxX, 3);

    // Drawing the selecting rectangle
    g.setColor(255, 0, 0);

    g.drawRect(
        ((this.colSelected * this.maxX) / 3) - 1,
        ((this.rowSelected * this.maxY) / 3) - 1,
        (this.maxX / 3) + 2,
        (this.maxY / 3) + 2);
    g.drawRect(
        (this.colSelected * this.maxX / 3),
        (this.rowSelected * this.maxY / 3),
        this.maxX / 3,
        this.maxY / 3);
    g.drawRect(
        (this.colSelected * this.maxX / 3) + 1,
        (this.rowSelected * this.maxY / 3) + 1,
        (this.maxX / 3) - 2,
        (this.maxY / 3) - 2);

    // Setting X variable for proper placement
    int refX = ((this.maxX / 3) - this.imgWidth) / 2;
    int refY = ((this.maxY / 3) - this.imgHeight) / 2;

    for (int i = 0; i < 3; i++) {
      for (int j = 0; j < 3; j++) {
        if (this.sq[i][j] == 0) {
          g.setClip(
              (i * this.maxX / 3) + refX,
              (j * this.maxY / 3) + refY,
              this.imgWidth,
              this.imgHeight);
          g.drawImage(
              this.zeroImage,
              ((i * this.maxX / 3) + refX) - this.frame * this.imgWidth,
              (j * this.maxY / 3) + refY,
              Graphics.TOP | Graphics.LEFT);
        } else if (this.sq[i][j] == 1) {
          g.setClip(
              (i * this.maxX / 3) + refX,
              (j * this.maxY / 3) + refY,
              this.imgWidth,
              this.imgHeight);
          g.drawImage(
              this.crossImage,
              ((i * this.maxX / 3) + refX) - this.frame * this.imgWidth,
              (j * this.maxY / 3) + refY,
              Graphics.TOP | Graphics.LEFT);
        }

        g.setClip(0, 0, this.maxX, this.maxY);
      }
    }
  }
示例#16
0
  /**
   * Draws one character. It called from drawChar(), drawString() and drawSubstrung().
   *
   * @param g the graphics context
   * @param c the character to be drawn
   * @param x the x coordinate of the anchor point
   * @param y the y coordinate of the anchor point
   * @return the x coordinate for the next character
   */
  public int drawOneChar(Graphics g, char c, int x, int y) {
    // skip if it is a space
    if (c == ' ') {
      return x + this.spaceWidth + xIndent + charWidthIncrement;
    }
    int charIndex = charIndex(c);
    // draw the unknown character as a rectangle
    if (charIndex < 0) {
      int squareWidth = this.spaceWidth + xIndent + charWidthIncrement;
      g.drawRect(x, y, squareWidth - 1, height - 1);
      return x + squareWidth;
    }

    int charX = this.x[charIndex];
    int charY = this.y[charIndex];
    int cw = widthes[charIndex];
    int imageIndex = idx[charIndex];

    y += yIndent / 2;

    Image image = this.currentImages[imageIndex];

    int clipX = g.getClipX();
    int clipY = g.getClipY();
    int clipWidth = g.getClipWidth();
    int clipHeight = g.getClipHeight();

    int ix = x - charX;
    int iy = y - charY;

    if (!italic && !bold) {
      g.clipRect(x, y, cw, this.height);
      g.drawImage(image, ix, iy, Graphics.LEFT | Graphics.TOP);
    } else if (italic & bold) {
      int halfHeight = height / 2;
      g.clipRect(x + 1, y, cw, this.height);
      g.drawImage(image, ix + 1, iy, Graphics.LEFT | Graphics.TOP);
      g.setClip(clipX, clipY, clipWidth, clipHeight);
      g.clipRect(x + 2, y, cw, halfHeight);
      g.drawImage(image, ix + 2, iy, Graphics.LEFT | Graphics.TOP);
      g.setClip(clipX, clipY, clipWidth, clipHeight);
      g.clipRect(x, y + halfHeight, cw, height - halfHeight);
      g.drawImage(image, ix, iy, Graphics.LEFT | Graphics.TOP);
    } else if (italic) {
      int halfHeight = height / 2;
      g.clipRect(x + 1, y, cw, halfHeight);
      g.drawImage(image, ix + 1, iy, Graphics.LEFT | Graphics.TOP);
      g.setClip(clipX, clipY, clipWidth, clipHeight);
      g.clipRect(x, y + halfHeight, cw, height - halfHeight);
      g.drawImage(image, ix, iy, Graphics.LEFT | Graphics.TOP);
    } else { // just a bold
      g.clipRect(x, y, cw, this.height);
      g.drawImage(image, ix, iy, Graphics.LEFT | Graphics.TOP);
      g.setClip(clipX, clipY, clipWidth, clipHeight);
      g.clipRect(x + 1, y, cw, this.height);
      g.drawImage(image, ix + 1, iy, Graphics.LEFT | Graphics.TOP);
    }
    // restore clipping
    g.setClip(clipX, clipY, clipWidth, clipHeight);
    return x + cw + xIndent + charWidthIncrement;
  }