Example #1
0
  /**
   * Paint this window. This method should not generally be overridden by subclasses. This method
   * carefully stores the clip, translation, and color before calling into subclasses. The graphics
   * context should be translated such that it is in this window's coordinate space (0,0 is the top
   * left corner of this window).
   *
   * @param g The graphics object to use to paint this window.
   * @param refreshQ The custom queue which holds the set of refresh regions needing to be blitted
   *     to the screen
   */
  public void paint(Graphics g, CGraphicsQ refreshQ) {
    // We reset our dirty flag first. Any layers that become
    // dirty in the duration of this method will then cause it
    // to toggle back to true for the subsequent pass.
    // IMPL NOTE: when layers start to do complex animation, there will
    // likely need to be better atomic handling of the dirty state,
    // and layers becoming dirty and getting painted
    this.dirty = false;

    // Store the clip, translate, font, color
    cX = g.getClipX();
    cY = g.getClipY();
    cW = g.getClipWidth();
    cH = g.getClipHeight();

    tranX = g.getTranslateX();
    tranY = g.getTranslateY();

    font = g.getFont();
    color = g.getColor();

    // We set the basic clip to the size of this window
    g.setClip(bounds[X], bounds[Y], bounds[W], bounds[H]);

    synchronized (layers) {
      sweepAndMarkLayers();
      copyAndCleanDirtyLayers();
    }
    paintLayers(g, refreshQ);

    // We restore the original clip. The original font, color, etc.
    // have already been restored
    g.setClip(cX, cY, cW, cH);
  }
Example #2
0
  /**
   * Second Pass: We sweep through the layers from the bottom to the top and paint each one that is
   * marked as dirty
   *
   * <p>Note, that the painting for copied layers is done here to not hold the layers lock during
   * the painting.
   *
   * @param g The graphics object to use to paint this window.
   * @param refreshQ The custom queue which holds the set of refresh regions needing to be blitted
   *     to the screen
   */
  private void paintLayers(Graphics g, CGraphicsQ refreshQ) {
    if (CGraphicsQ.DEBUG) {
      System.err.println("[Paint dirty layers]");
    }

    for (int i = 0; i < dirtyCount; i++) {
      CLayer l = dirtyLayers[i];

      // Prepare relative dirty region coordinates
      // of the current layer
      int dx = l.dirtyBoundsCopy[X];
      int dy = l.dirtyBoundsCopy[Y];
      int dw = l.dirtyBoundsCopy[W];
      int dh = l.dirtyBoundsCopy[H];

      // Before we call into the layer to paint, we
      // translate the graphics context into the layer's
      // coordinate space
      g.translate(l.boundsCopy[X], l.boundsCopy[Y]);

      if (CGraphicsQ.DEBUG) {
        System.err.println("Painting Layer: " + l);
        System.err.println("\tClip: " + dx + ", " + dy + ", " + dw + ", " + dh);
      }

      // Clip the graphics to only contain the dirty region of
      // the layer (if the dirty region isn't set, clip to the
      // whole layer contents).
      g.clipRect(dx, dy, dw, dh);
      refreshQ.queueRefresh(l.boundsCopy[X] + dx, l.boundsCopy[Y] + dy, dw, dh);
      l.paint(g);

      // We restore our graphics context to prepare
      // for the next layer
      g.translate(-g.getTranslateX(), -g.getTranslateY());
      g.translate(tranX, tranY);

      // We reset our clip to this window's bounds again.
      g.setClip(bounds[X], bounds[Y], bounds[W], bounds[H]);

      g.setFont(font);
      g.setColor(color);
    } // for
  }
  public void drawItem(Graphics g, int offset, boolean selected, boolean drawsec) {
    // g.setColor(0);
    boolean ralign = false;
    boolean underline = false;

    // #if NICK_COLORS
    // # 	boolean nick=false;
    // #endif

    int w = offset;
    int dw;
    int imageYOfs = ((getVHeight() - imgHeight()) >> 1);
    // #if ALCATEL_FONT
    // #         int fontYOfs=(( getVHeight()-font.getHeight() )>>1) +1;
    // #else
    int fontYOfs = ((getVHeight() - font.getHeight()) >> 1);
    // #endif
    int imgWidth = imgWidth();

    g.setFont(font);
    for (int index = 0; index < elementCount; index++) {
      Object ob = elementData[index];
      if (ob != null) {

        if (ob instanceof String) {
          // string element
          String s = (String) ob;
          // #if NICK_COLORS
          // #                     if (nick) {
          // #                         int color=g.getColor();
          // #                         dw=0;
          // #                         int p1=0;
          // #                         while (p1<s.length()) {
          // #                             int p2=p1;
          // #                             char c1=s.charAt(p1);
          // #                             //processing the same cp
          // #                             while (p2<s.length()) {
          // #                                 char c2=s.charAt(p2);
          // #                                 if ( (c1&0xff00) != (c2 &0xff00) ) break;
          // #                                 p2++;
          // #                             }
          // #                             g.setColor( (c1>255) ? ColorScheme.strong(color) :
          // color);
          // #                             dw=font.substringWidth(s, p1, p2-p1);
          // #                             if (ralign) w-=dw;
          // #                             g.drawSubstring( s, p1, p2-p1,
          // #                                     w,fontYOfs,Graphics.LEFT|Graphics.TOP);
          // #                             if (!ralign) w+=dw;
          // #                             p1=p2;
          // #                         }
          // #
          // #                         g.setColor(color);
          // #                     } else {
          // #endif
          dw = font.stringWidth(s);
          if (ralign) w -= dw;
          g.drawString(s, w, fontYOfs, Graphics.LEFT | Graphics.TOP);
          if (underline) {
            int y = getVHeight() - 1;
            g.drawLine(w, y, w + dw, y);
            underline = false;
          }
          if (!ralign) w += dw;
          // #if NICK_COLORS
          // #                     }
          // #endif

        } else if ((ob instanceof Integer)) {
          // image element or color
          int i = ((Integer) ob).intValue();
          switch (i & 0xff000000) {
            case IMAGE:
              if (imageList == null) break;
              if (ralign) w -= imgWidth;
              imageList.drawImage(g, ((Integer) ob).intValue(), w, imageYOfs);
              if (!ralign) w += imgWidth;
              break;
            case COLOR:
              g.setColor(0xFFFFFF & i);
              break;
            case RALIGN:
              ralign = true;
              w = g.getClipWidth() - 1;
              break;
            case UNDERLINE:
              underline = true;
              break;
              // #if NICK_COLORS
              // #                         case NICK_ON:
              // #                             nick=true;
              // #                             break;
              // #                         case NICK_OFF:
              // #                             nick=false;
              // #                             break;
              // #endif
          }
        } /* Integer*/ else if (ob instanceof VirtualElement) {
          int clipw = g.getClipWidth();
          int cliph = g.getClipHeight();
          ((VirtualElement) ob).drawItem(g, 0, false, false);
          g.setClip(g.getTranslateX(), g.getTranslateY(), clipw, cliph);
          // TODO: рисование не с нулевой позиции и вычисление ширины
        }
      } // if ob!=null
    } // for
  }