📄 screen.java
字号:
*/ int getMinimumContentHeight(int width, int height) { return (hasBorder ? (CONTENT_HEIGHT * 2 + 8) : CONTENT_HEIGHT * 2); } /** * Signal this Screen that its layout has changed */ void layoutChanged() { if (layoutDoneOnce) { doLayout(); if (visible) { repaint(0, 0, Display.WIDTH, Display.HEIGHT); } } } /** * Layout the contents of this Screen */ final void doLayout() { int tickerHeight = 0; if (ticker != null) { // By default, the ticker is visible. Below will calculate // whether we optimize out the display of the ticker or not tickerIsVisible = true; tickerHeight = ticker.PREFERRED_HEIGHT; } int titleHeight = 0; int titleBorder = 0; String title = getTitleImpl(); if (title != null && !title.equals("")) { screenTitle.setMaxHeight(2 * TITLE_HEIGHT); titleHeight = screenTitle.setWidth(Display.WIDTH); titleBorder = TITLE_IMG.getHeight() + 1; } int h = tickerHeight + titleHeight + titleBorder + getMinimumContentHeight(Display.WIDTH, Display.HEIGHT - TITLE_HEIGHT); // reset the global viewport globalViewPortY = 0; // If there is not enough space to fit everything: // 1. ticker should not be displayed if it is present // 2. two line title should be reduced to 1 line if it is present // 3. content should be modified if (tickerHeight > 0 && h > Display.HEIGHT) { h -= tickerHeight; tickerIsVisible = false; } else { globalViewPortY = tickerHeight; } if (titleHeight != 0) { if (h > Display.HEIGHT && titleHeight > TITLE_HEIGHT) { h = h - titleHeight + TITLE_HEIGHT; titleHeight = TITLE_HEIGHT; screenTitle.setMaxHeight(titleHeight); } } globalViewPortY += titleHeight + titleBorder; viewPortWidth = Display.WIDTH; viewPortHeight = Display.HEIGHT - globalViewPortY; if (hasBorder) { globalViewPortX = 4; globalViewPortY += 4; viewPortWidth -= 8; viewPortHeight -= 8; } childHeight = layoutContent(viewPortWidth, viewPortHeight); viewPortY = initHilight(viewPortY, viewPortHeight); layoutDoneOnce = true; } /** * Set the child height of this Screen * * @param height The childHeight */ void setChild(int height) { childHeight = height; } /** * Initializes hilight when form is shown. * @param vpY y coordinate of viewport location * @param vpH viewport height * @return new y coordinate of viewport location * child (all items) coordinate system */ int initHilight(int vpY, int vpH) { return 0; } /** * Signal this Screen that its height has changed * * @param vpY * @param vpH * @param deltaHeight * @return int */ int heightChanged(int vpY, int vpH, int deltaHeight) { childHeight += deltaHeight; if (vpY + vpH > childHeight) { vpY = childHeight - vpH; if (vpY < 0) { vpY = 0; } } return vpY; } /** * This method is called to change child height - must be * called by any operation that can change the height of the screens * child. * * @param item The Item which changed * @param x The x coordinate of the change * @param y The y coordinate of the change * @param deltaHeight The change in height caused by the change */ void contentChanged(Item item, int x, int y, int deltaHeight) { if (!initLayoutDone()) { return; } // Only call heightChanged if there's really a height delta // Fix of bug 4366597 if (deltaHeight != 0) { viewPortY = heightChanged(viewPortY, viewPortHeight, deltaHeight); } // Repaint if this screen is visible if (isShown()) { setVerticalScroll(); if (deltaHeight == 0 && item != null) { item.repaint(x, y, viewPortWidth, item.getHeight() - y); return; } repaintContent(); } } /** * Set the vertical scroll indicators for this Screen */ void setVerticalScroll() { // Previously, Screen was always resetting the left/right // scroll indicators to 0 when it set the up/down indicators, // now it sets the up/down indicators as appropriate, but // maintains the left/right indicators as they were, and it // is the component's responsibility (ie Gauge) to update // the right/left scroll indicators if necessary if (childHeight <= viewPortHeight) { super.setVerticalScroll(0, 100); } else { super.setVerticalScroll( (viewPortY * 100 / (childHeight - viewPortHeight)), (viewPortHeight * 100 / childHeight)); } } /** * Determine if the initial layout has been done * * @return boolean True if the initial layout has been done */ final boolean initLayoutDone() { return layoutDoneOnce; } /** * Repaint the content of this Screen */ final void repaintContent() { repaint(globalViewPortX, globalViewPortY, viewPortWidth, viewPortHeight); } /** * Repaint the content of this Screen in the given clip rect * * @param x The x coordinate of the clip * @param y The y coordinate of the clip * @param width The width of the clip * @param height The height of the clip */ final void repaintContent(int x, int y, int width, int height) { // do not repaint content that is entirely not visible if (y < viewPortY + viewPortHeight && y + height > viewPortY) { repaint(x + globalViewPortX, y + globalViewPortY - viewPortY, width, height); } } /** * Paint this Screen * * @param g The Graphics context to paint to */ final void paint(Graphics g) { int clipRectY1 = g.getClipY(); int clipRectY2 = clipRectY1 + g.getClipHeight(); int translatedY = 0; int titleTextHeight = 0; int titleHeight = 0; synchronized (Display.LCDUILock) { String title = getTitleImpl(); if (title != null && !title.equals("") && screenTitle != null) { titleTextHeight = screenTitle.getHeight() + 2; titleHeight = titleTextHeight + TITLE_IMG.getHeight(); } // paint ticker if (tickerIsVisible) { if (clipRectY2 > 0 && clipRectY1 < ticker.PREFERRED_HEIGHT) { ticker.paintContent(g); } translatedY += ticker.PREFERRED_HEIGHT; g.translate(0, ticker.PREFERRED_HEIGHT); } // paint title if (titleHeight != 0) { if (clipRectY2 > translatedY && clipRectY1 < translatedY + titleHeight) { g.setColor(Display.ERASE_COLOR); g.fillRect(0, 0, Display.WIDTH, titleHeight); screenTitle.paint(g, false, false); // NOTE: We test to see if the width of the Display is // wider than the width of our image, if so, we re-draw // the image offset to the right as many times as necessary // to fill the width of the Display. Specific ports would // probably want to optimize this for the specific width // of their device. for (int imgLoc = 0; imgLoc < Display.WIDTH; imgLoc += 96) { g.drawImage(TITLE_IMG, imgLoc, titleTextHeight, Graphics.LEFT | Graphics.BOTTOM); } } translatedY += titleHeight; g.translate(0, titleHeight); } // paint content // doLayout has already worked out the size of the content if (clipRectY2 > translatedY && clipRectY1 < Display.HEIGHT) { if (hasBorder) { g.setColor(Display.ERASE_COLOR); g.drawRect(0, 0, viewPortWidth + 7, viewPortHeight + 7); g.drawRect(1, 1, viewPortWidth + 5, viewPortHeight + 5); g.drawRect(3, 3, viewPortWidth + 1, viewPortHeight + 1); g.setColor(Display.FG_COLOR); g.drawRect(2, 2, viewPortWidth + 3, viewPortHeight + 3); } g.translate(globalViewPortX, globalViewPortY - translatedY - viewPortY); g.clipRect(0, viewPortY, viewPortWidth, viewPortHeight); paintContent(g); } } // synchronized } /** * Traverse this Screen's contents * * @param dir The direction of traversal * @param top * @param bottom * @return -1 if there is no need to scroll and * there is no need to repaint; * 0 if there is no need to scroll but * content should be repainted * scrollHeight by which the viewPortY has to be adjusted */ int traverse(int dir, int top, int bottom) { // if we are at the top of the screen and we are scrolling up or // if we are scrolling down and we are at the very bottom, // then don't scroll. if (dir == Canvas.UP) { if (top <= 0) { return -1; } } else if (dir == Canvas.DOWN) { if (bottom >= childHeight) { return -1; } } else {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -