/** * 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); }
public void paint(Graphics g) { // g.setClip(0, 0, this.ui.xWForm.getWidth(), this.ui.xWForm.getWidth()); if (inBox) { posX = (ui.xmlForm.frm_Width - width) / 2; posY = (ui.xmlForm.frm_Height - height) / 2; } else { posX = x + ui.offsetX; posY = y + ui.offsetY; /* if(focus){ if(height<=ui.xWForm.frm_Height-60) if(posY+height+itemHeight-10>ui.xWForm.frm_Height-30){ ui.offsetY=ui.offsetY-(ui.xWForm.frm_Height/2); ui.xWForm.repaint(); } }*/ if (title != null) { // System.out.println("title==="+title); if (posX + smallHeavryFont.stringWidth(title) > ui.xmlForm.frm_Width) { x = 0; y = posY + smallHeavryFont.getHeight() + 5; } posY = y + ui.offsetY + smallHeavryFont.getHeight() + 5; posX = x + ui.offsetX + 10; } } if (title != null) { g.setColor(0); g.setFont(smallHeavryFont); g.drawString(title + ":", x + ui.offsetX, y + ui.offsetY, 0); } // if (focus) { /*if(items.size()==0){ height=0; } if(height!=0)*/ /*int h=0; if(richmode){ h=title!=null?height-smallFont.getHeight()+5:0; }else{ h=height+smallFont.getHeight()-10; }*/ ImageDiv.drawJiuGong( g, UIManager.select_bright, posX - 3, posY - 3, width + 10, title != null ? height - smallFont.getHeight() + 5 : height); // // } // g.setColor(bgTricolorR, bgTricolorG, bgTricolorB); // g.setColor(125); // g.fillRect(posX, posY, width, height-(title!=null?smallFont.getHeight()-5:0)); g.setFont(DisplaySetting.TEXT_FONT); if ((onShowSelectedItemNum + 2) * itemHeight > height) { offsetY = (onShowSelectedItemNum + 2) * itemHeight - height; } else { offsetY = 0; } /*if(focus) if (onShowSelectedItemNum + 1 >= 0) { ImageDiv.drawJiuGong(g, UIManager.connect_bg, posX, posY + (onShowSelectedItemNum + 1) * itemHeight - offsetY, width, itemHeight); }*/ int clipx = g.getClipX(); int clipy = g.getClipY(); int clipwidth = g.getClipWidth(); int clipheight = g.getClipHeight(); g.setClip(posX, posY, width, height); // g.setColor(Attribute.); // g.setFont(font); g.setFont(smallFont); g.setColor(ColorAttribute.label_context); int length = items.size(); for (int i = 0; i < length; i++) { g.setClip(posX, posY, width, height); if (i == onShowSelectedItemNum + 1 && focus) { g.setColor(0, 220, 247); if (posY + (onShowSelectedItemNum + 1) * itemHeight - offsetY > ui.xmlForm.frm_Height - 40) { ui.offsetY -= 20; ui.xmlForm.repaint(); System.out.println("draw it"); } else if (posY + (onShowSelectedItemNum + 1) * itemHeight - offsetY < 20) { ui.offsetY += 20; ui.xmlForm.repaint(); System.out.println("draw it"); } // System.out.println("draw it"); } else { g.setColor(0); } if (items.elementAt(i) != null) { g.drawString( items.elementAt(i).toString(), posX + 5 + (UIManager.select_block.getWidth() >> 2) + 2, posY + i * itemHeight - offsetY, Graphics.LEFT | Graphics.TOP); } if (!hasNonItem) ImageBuilder.drawSmallImage( g, UIManager.select_block, posX + 5, posY + i * itemHeight - offsetY + 2, (UIManager.select_block.getWidth() >> 2), UIManager.select_block.getHeight(), selector.elementAt(i).equals(new Integer(1)) ? (UIManager.select_block.getWidth() >> 2) * 0 : (UIManager.select_block.getWidth() >> 2) * 1, 0); } if (inBox) { g.drawImage( UIManager.select_bright, posX + width - 1, posY + (height * (onShowSelectedItemNum + 1) / length), Graphics.RIGHT | Graphics.TOP); } g.setClip(clipx, clipy, clipwidth, clipheight); /*if(posY+ (onShowSelectedItemNum + 1)* itemHeight - offsetY>ui.xWForm.frm_Height-40){ ui.offsetY-=20; ui.xWForm.repaint(); }else if(posY+ (onShowSelectedItemNum + 1)* itemHeight - offsetY<20){ ui.offsetY+=20; }*/ }
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; }
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); } }
/** * 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; }