/* * aNNiMON 2010 * For more info visit http://annimon.com/ */ /* * На основе класса MultiLineText от А.С. Ледкова * www.mobilab.ru */ import com.annimon.XID; import com.annimon.ui.ESkin; import com.annimon.ui.EWindow; import java.util.Vector; import javax.microedition.lcdui.*; public class About extends EWindow { private static final String PATH = "/about"; private Font def; private int defHeight; private String str; // текст private int mh, y0; // Положение верхнего края текста private int dy; // Шаг при прокрутке текста private int textheight; // Общая высота текста private Vector strLines; public About(String about) { super(about); str = new XID().loadText(PATH); def = Font.getDefaultFont(); dy = defHeight = def.getHeight()+2; mh = super.hh - 1; SetTextPar(); } public void paint(Graphics g, int w, int h) { g.setFont(def); g.setColor(ESkin.textColor); int y1 = y0; for (int i = 0; i < strLines.size(); i++) { if ((y1 + defHeight) > 0) { g.drawString(strLines.elementAt(i).toString(), 1, 3 + y1, Graphics.LEFT | Graphics.TOP); } y1 += defHeight; if (y1 > mh) break; } } public void keyEvent(int key, byte state) { if(state!=RELEASED) { int ga = getGameAction(key); if(ga==UP) MoveUp(); else if(ga==DOWN) MoveDown(); else if(ga==LEFT) PageUp(); else if(ga==RIGHT) PageDown(); else if(ga==FIRE || key==KEY_LSK || key==KEY_RSK) Main.midlet.dsp.setCurrent(Main.midlet.main); redraw(); } } protected void pointerPressed(int x, int y) { int w3 = w/3; int h3 = h/3; if(y

w3 && x<(w-w3))) keyPressed(UP); else if(y>(h-h3) && (x>w3 && x<(w-w3))) keyPressed(DOWN); if(xh3 && y<(h-h3))) keyPressed(LEFT); else if(x>(w-w3) && (y>h3 && y<(h-h3))) keyPressed(RIGHT); else if(x(h-h3)) keyPressed(-6); else if(x>(w-w3) && y>(h-h3)) keyPressed(-7); else if( (x>w3 && x<(w-w3)) && (y>h3 && y<(h-h3)) ) keyPressed(FIRE); } private void SetTextPar() { //Разбиваем строку на массив строк strLines = null; strLines = new Vector(); String[] arr = splitString(str, "\n"); for(int i=0; i w) {//Слово полностью не умещается в строке space = i0; while (jw > w) { j = 0; while (j < w) { space++; j = def.stringWidth(substr.substring(in, space)); } space = space - 1; j = def.stringWidth(substr.substring(in, space)); strLines.addElement(substr.substring(in, space)); jw = jw - j; i0 = space; in = space; } jw = 0; } else { i0 = space; } } } strLines.addElement(substr.substring(in, imax)); } textheight = strLines.size() * defHeight; } private void MoveDown() { if (textheight > mh) { y0 = y0 - dy; if (mh - y0 > textheight) { y0 = mh - textheight; } } } private void MoveUp() { if (textheight > mh) { y0 = y0 + dy; if (y0 > 0) { y0 = 0; } } } private void PageUp() { if (textheight > mh) { y0 = y0 + mh; if (y0 > 0) { y0 = 0; } } } private void PageDown() { if (textheight > mh) { y0 = y0 - mh; if (mh - y0 > textheight) { y0 = mh - textheight; } } } private String[] splitString(String str, String delim) { if ("".equals(str) || delim == null || delim.length() == 0) return new String[]{str}; Vector v = new Vector(); int pos = 0; int newpos = str.indexOf(delim, 0); while (newpos != -1) { v.addElement(str.substring(pos, newpos)); pos = newpos + delim.length(); newpos = str.indexOf(delim, pos); } v.addElement(str.substring(pos)); String[] s = new String[v.size()]; v.copyInto(s); return s; } }