📄 viewercanvas.java
字号:
0, renderer.width, renderer.height, 0, com.nokia.mid.ui.DirectGraphics.TYPE_INT_8888_ARGB);*//**/ // MIDP2.0 g.drawRGB(pixbuf.pixels32, 0, pixbuf.width, 0, 0, pixbuf.width, pixbuf.height, false); /**/ } else //if(load) { //draw the clock g.setColor(0xffffff); g.fillRect(0,0,width,height); g.setColor(0x000000); g.drawString("Wait ...", width/2, height/2, Graphics.LEFT|Graphics.TOP); if(wait!=null) { g.drawImage(wait,0,height-MENU_HEIGHT, g.TOP|g.LEFT); } } } /** * Fetch the image. If the name begins with "http:" * fetch it with connector.open and http. * If it starts with "/" then load it from the * resource file. * @param name of the image to load * @return image created * @exception IOException if errors occuring doing loading */ private Image createImage(String name) throws IOException { if (name.startsWith("/")) { // Load as a resource with Image.createImage if(name.endsWith(".png")) { return Image.createImage(name); } else throw new IOException("Expecting PNG image"); } else if (name.startsWith("http:")) { // Load from a ContentConnection HttpConnection c = null; DataInputStream is = null; try { c = (HttpConnection)Connector.open(name); int status = c.getResponseCode(); if (status != 200) { throw new IOException("HTTP Response Code = " + status); } int len = (int)c.getLength(); String type = c.getType(); if (!type.equals("image/png")) { throw new IOException("Expecting image, received " + type); } if (len > 0) { is = c.openDataInputStream(); byte[] data = new byte[len]; is.readFully(data); return Image.createImage(data, 0, len); } else { throw new IOException("Content length is missing"); } } finally { if (is != null) is.close(); if (c != null) c.close(); } } else { throw new IOException("Unsupported media"); } } /** * Display error message. * @param message the error message */ void alertError(String message) { Alert alert = new Alert("Error", message, null, AlertType.ERROR); Displayable current = display.getCurrent(); if (!(current instanceof Alert)) { alert.setTimeout(Alert.FOREVER); // This next call can't be done when current is an Alert display.setCurrent(alert, current); } } /** * Handle keyboard input. * @param keyCode pressed key. */ protected void keyRepeated(int keyCode) { keyPressed(keyCode); } /** * Handle keyboard input. * @param keyCode pressed key. */ protected void keyPressed(int keyCode) { if(load) return; int action = getGameAction(keyCode); switch (action) { case Canvas.LEFT: if(type == TYPE_PAN) pan(-PAN_STEP,0); break; case Canvas.RIGHT: if(type == TYPE_PAN) pan(PAN_STEP,0); break; case Canvas.UP: if(type == TYPE_PAN) pan(0,-PAN_STEP); else if(type == TYPE_ZOOM) zoom(0); break; case Canvas.DOWN: if(type == TYPE_PAN) pan(0,PAN_STEP); else if(type == TYPE_ZOOM) zoom(1); break; case Canvas.FIRE: break; } // end of switch } /** * Called when the pointer is released. * @param x - the X coordinate where the pointer was released. * @param y - the Y coordinate where the pointer was released. */ protected void pointerReleased(int x, int y) { if(load) return; if(type == TYPE_LINK) { pointerReleased(x,y); } else if(type == TYPE_PAN) { pan(pressedX - x,pressedY - y); } } /** * Called when the pointer is pressed. * @param x - the X coordinate where the pointer was pressed. * @param y - the Y coordinate where the pointer was pressed. */ protected void pointerPressed(int x, int y) { if(load) return; if(type == TYPE_PAN) { pressedX = x; pressedY = y; draggedX = pressedX; draggedY = pressedY; } } /** * Called when the pointer is dragged. * @param x - the X coordinate where the pointer was dragged. * @param y - the Y coordinate where the pointer was dragged. */ protected void pointerDragged(int x, int y) { if(load) return; if(type == TYPE_PAN) { draggedX = x; draggedY = y; } } /** * Zooms in and out the current SVGT document. * @return true if the zoom is allowed; otherwise return false. */ public boolean zoom(int direction) { // zoom in '0' size / 2 if(direction == 0) { zoomLevel--; if(zoomLevel < MIN_ZOOMLEVEL) { zoomLevel = MIN_ZOOMLEVEL; return false; } } else //zoom out size * 2 { zoomLevel++; if(zoomLevel > MAX_ZOOMLEVEL) { zoomLevel = MAX_ZOOMLEVEL; return false; } } SVGRect newView = new SVGRect(); SVGRect view = raster.view; int midX = view.x + view.width/2; int midY = view.y + view.height/2; // zoom in '0' size / 2 if(direction == 0) { newView.width = (view.width/2); newView.height = (view.height/2); } else //zoom out size * 2 { newView.width = (view.width * 2 ); newView.height = (view.height * 2); } newView.x = midX - (newView.width) / 2; newView.y = midY - (newView.height) / 2; // Set a new current viewport view.x = newView.x; view.y = newView.y; view.width = newView.width; view.height = newView.height; // Change the camera transform according to the new current // viewport and update the raster raster.setCamera(); raster.update(); raster.sendPixels(); return true; } /** * Returns the current SVGT document to its original view. */ public void origView() { // Reset the zoom level zoomLevel = 0; // Set a new current viewport raster.view = new SVGRect(raster.origview); // Change the camera transform according to the new current // viewport and update the raster raster.setCamera(); raster.update(); raster.sendPixels(); } /** * Pans the current SVGT document. * @param x The distance on X coordinate. * @param y The distance on Y coordinate. */ public void pan(int x , int y) { // Get the current viewport SVGRect view = raster.view; // Get the SVGT document SVGDocument doc = raster.getSVGDocument(); // Get the root of the SVGT document SVGSVGElem root = (SVGSVGElem)doc.root; // Get the current scale value int scale = root.getCurrentScale(); // Scale pan distances according to the current scale factor // Change the current viewport view.x += TinyUtil.div(x<<TinyUtil.FIX_BITS,scale); view.y += TinyUtil.div(y<<TinyUtil.FIX_BITS,scale); // Change the camera transform according to the new current // viewport and update the raster raster.setCamera(); raster.update(); raster.sendPixels(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -