package moder.view; import java.io.IOException; import javax.microedition.lcdui.Font; import javax.microedition.lcdui.Graphics; import javax.microedition.lcdui.Image; import javax.microedition.lcdui.game.Sprite; public class Menu { private int W; private int H; private int arcr;//小圆的直径44 int dxr,dyd,dxl,dyu,dxm,dymd,dymu,sxl,sxr,sxml,sxmr,sym,sxy,syd,syu; // int no1x,no1y,no2x,no2y,no3x,no3y,no4x,no4y,no5x,no5y,no6x,no6y, // no7x,no7y,no8x,no8y,no9x,no9y,no10x,no10y,no11x,no11y,no12x,no12y; Font font=Font.getFont (Font.FACE_SYSTEM,Font.STYLE_PLAIN,Font.SIZE_SMALL); private int[] xlocal,ylocal; private int[] xpoint,ypoint; private int index; public static final String[] fulist={"阅读历史","分类列表","图书搜索","我的收藏","火爆排行","最新上架"}; private String selectedlist; private Image img_pp; // private int arcx[],arcy[]; public Menu(int SW,int SH){ W=SW; H=SH; if(W>H) arcr=H/4; else arcr=W/4; // int cos30=87*3*arcr/2/100; // int haw=W/2,hah=H/2; // no1x=haw-arcr/2; no1y=hah-2*arcr; // no2x=haw+arcr/4; no2y=hah-cos30-arcr/2; // no3x=haw+cos30-arcr/2; no3y=hah-5*arcr/4; // no4x=haw+arcr; no4y=hah-arcr/2; // no5x=haw+cos30-arcr/2; no5y=hah+arcr/4; // no6x=haw+arcr/4; no6y=hah+cos30-arcr/2; // no7x=haw-arcr/2; no7y=hah+arcr; // no8x=haw-arcr/4; no8y=hah+cos30-arcr/2; // no9x=haw-cos30-arcr/2; no9y=hah+arcr/4; // no10x=haw-2*arcr; no10y=hah-arcr/2; // no11x=haw-cos30-arcr/2; no11y=hah-arcr*5/4; // no12x=haw-arcr/4; no12y=hah-cos30-arcr/2; // // arcx=new int[]{no1x,no2x,no3x,no4x,no5x,no6x,no7x,no8x,no9x,no10x,no11x,no12x}; // arcy=new int[]{no1y,no2y,no3y,no4y,no5y,no6y,no7y,no8y,no9y,no10y,no11y,no12y}; dxr=W/2+87*arcr*3/2/100-arcr/2; dyu=H/2-arcr*3/4-arcr/2; dxl=W/2-87*arcr*3/2/100-arcr/2; dyd=H/2+arcr*3/4-arcr/2; dxm=W/2-arcr/2; dymu=H/2-2*arcr; dymd=H/2+arcr; sxl=W/2-arcr*5/4; sxr=W/2+arcr*3/4-arcr/2; sxml=W/2-2*arcr; sxmr=W/2+arcr; sym=H/2-arcr/2; syu=H/2-87*arcr*3/2/100-arcr/2; syd=H/2+87*arcr*3/2/100-arcr/2; try { img_pp=Image.createImage("/pp.png"); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } xlocal=new int[]{dxm,dxr,dxr,dxm,dxl,dxl}; ylocal=new int[]{dymu,dyu,dyd,dymd,dyd,dyu}; xpoint=new int[]{sxl,sxr,sxmr,sxr,sxl,sxml}; ypoint=new int[]{syu,syu,sym,syd,syd,sym}; } /** * 画菜单 * 调用时只需要将icoindex改变并转换change状态 * @param g * @param icoindex 图片索引 * @param charge 切换状态 * @return 所选字段 */ public String showIco(Graphics g,int icoindex,boolean change){ g.setColor(255,127,127); selectedlist=fulist[(icoindex+3)%6]; g.drawString(selectedlist, W/2-font.charWidth('最')*2, H/2-font.getHeight()/2, 20); if(!change) icolist(g,icoindex); else{ if(index+5==icoindex) icolistturn(g,icoindex); else icolistturn(g,icoindex-1); index=icoindex; } return selectedlist; } public String getSelectedlist(int input){ return fulist[(input+3)%6]; } private void icolistturn(Graphics g,int icoindex){//左右类型 g.drawRegion(img_pp, 44*(icoindex%6), 0, 44, 44, Sprite.TRANS_NONE, xpoint[0],ypoint[0], 20); icoindex++; g.drawRegion(img_pp, 44*(icoindex%6), 0, 44, 44, Sprite.TRANS_NONE, xpoint[1],ypoint[1], 20); icoindex++; g.drawRegion(img_pp, 44*(icoindex%6), 0, 44, 44, Sprite.TRANS_NONE, xpoint[2],ypoint[2], 20); icoindex++; g.drawRegion(img_pp, 44*(icoindex%6), 0, 44, 44, Sprite.TRANS_NONE, xpoint[3],ypoint[3], 20); icoindex++; g.drawRegion(img_pp, 44*(icoindex%6), 0, 44, 44, Sprite.TRANS_NONE, xpoint[4],ypoint[4], 20); icoindex++; g.drawRegion(img_pp, 44*(icoindex%6), 0, 44, 44, Sprite.TRANS_NONE, xpoint[5],ypoint[5], 20); } private void icolist(Graphics g,int icoindex){//上下类型 g.drawRegion(img_pp, 44*(icoindex%6), 0, 44, 44, Sprite.TRANS_NONE, xlocal[0],ylocal[0], 20); icoindex++; g.drawRegion(img_pp, 44*(icoindex%6), 0, 44, 44, Sprite.TRANS_NONE, xlocal[1],ylocal[1], 20); icoindex++; g.drawRegion(img_pp, 44*(icoindex%6), 0, 44, 44, Sprite.TRANS_NONE, xlocal[2],ylocal[2], 20); icoindex++; g.drawRegion(img_pp, 44*(icoindex%6), 44, 44, 44, Sprite.TRANS_NONE, xlocal[3],ylocal[3], 20); icoindex++; g.drawRegion(img_pp, 44*(icoindex%6), 0, 44, 44, Sprite.TRANS_NONE, xlocal[4],ylocal[4], 20); icoindex++; g.drawRegion(img_pp, 44*(icoindex%6), 0, 44, 44, Sprite.TRANS_NONE, xlocal[5],ylocal[5], 20); } }