1 2 20 21 package javax.microedition.lcdui; 22 23 import com.barteo.emulator.device.DeviceFactory; 24 25 26 public abstract class Screen extends Displayable 27 { 28 29 StringComponent title; 30 Ticker ticker; 31 int viewPortY; 32 int viewPortHeight; 33 34 35 Screen(String title) 36 { 37 this.title = new StringComponent(title); 38 viewPortY = 0; 39 viewPortHeight = DeviceFactory.getDevice().getDeviceDisplay().getHeight() - this.title.getHeight() - 1; 40 } 41 42 43 public Ticker getTicker() 44 { 45 return ticker; 46 } 47 48 49 public String getTitle() 50 { 51 return title.getText(); 52 } 53 54 55 public void setTitle(String s) 56 { 57 title.setText(s); 58 } 59 60 61 public void setTicker(Ticker ticker) 62 { 63 if (this.ticker != null) { 64 viewPortHeight += this.ticker.getHeight(); 65 } 66 this.ticker = ticker; 67 if (this.ticker != null) { 68 viewPortHeight -= this.ticker.getHeight(); 69 } 70 repaint(); 71 } 72 73 74 abstract int traverse(int gameKeyCode, int top, int bottom); 75 76 77 void keyPressed(int keyCode) 78 { 79 int gameKeyCode = Display.getGameAction(keyCode); 80 81 if (gameKeyCode == Canvas.UP || gameKeyCode == Canvas.DOWN) { 82 viewPortY += traverse(gameKeyCode, viewPortY, viewPortY + viewPortHeight); 83 repaint(); 84 } 85 } 86 87 88 void hideNotify() 89 { 90 super.hideNotify(); 91 } 92 93 94 void keyRepeated(int keyCode) 95 { 96 keyPressed(keyCode); 97 } 98 99 100 final void paint(Graphics g) 101 { 102 int contentHeight = 0; 103 int translatedY; 104 105 if (viewPortY == 0) { 106 currentDisplay.setScrollUp(false); 107 } else { 108 currentDisplay.setScrollUp(true); 109 } 110 111 g.setGrayScale(255); 112 g.fillRect(0, 0, 113 DeviceFactory.getDevice().getDeviceDisplay().getWidth(), 114 DeviceFactory.getDevice().getDeviceDisplay().getHeight()); 115 116 g.setGrayScale(0); 117 118 if (ticker != null) { 119 contentHeight += ticker.paintContent(g); 120 } 121 122 g.translate(0, contentHeight); 123 translatedY = contentHeight; 124 125 contentHeight += title.paint(g); 126 g.drawLine(0, title.getHeight(), 127 DeviceFactory.getDevice().getDeviceDisplay().getWidth(), title.getHeight()); 128 contentHeight += 1; 129 130 g.translate(0, contentHeight - translatedY); 131 translatedY = contentHeight; 132 133 g.setClip(0, 0, 134 DeviceFactory.getDevice().getDeviceDisplay().getWidth(), 135 DeviceFactory.getDevice().getDeviceDisplay().getHeight() - contentHeight); 136 g.translate(0, -viewPortY); 137 contentHeight += paintContent(g); 138 g.translate(0, viewPortY); 139 140 if (contentHeight - viewPortY > DeviceFactory.getDevice().getDeviceDisplay().getHeight()) { 141 currentDisplay.setScrollDown(true); 142 } else { 143 currentDisplay.setScrollDown(false); 144 } 145 g.translate(0, -translatedY); 146 } 147 148 149 abstract int paintContent(Graphics g); 150 151 152 void repaint() 153 { 154 super.repaint(); 155 } 156 157 158 void showNotify() 159 { 160 viewPortY = 0; 161 162 super.showNotify(); 163 } 164 165 } 166 | Popular Tags |