首页 > Sktech > 习作BL_另一套自创界面
2018
01-19

习作BL_另一套自创界面

习作BL_另一套自创界面 - 第1张  | Processing编程艺术


乱七八糟想法比较杂:
– 浮动窗口, 承载控件, 用鼠标拖动.
– 浮动窗口可以通过选择按钮选择显示或不显示.
– 选择按钮打包在另一个菜单画面.
– 有一个系统按钮, 可以显示时间, 鼠标划过后显示菜单画面.
– 系统按钮同时是退出按钮, 点击弹出对话框询问是否退出程序.

另外:
– 按回车可以开启一个输入框, 可以输入命令.
– 有一个信息条可以反馈报错等信息. (这里什么都没做, 只把输入命令直接打印到信息条).


鼠标右键:选择窗口
鼠标拖动:拖动被选中的窗口
鼠标双击:关闭被选中的窗口
[上/下]:滚动信息条
[左]:重置信息条位置
[右]:打开或收起信息条
[Q]:退出程序
[F5]:切换是否鼠标坐标
[F6]:定位矩形尺寸


问题:
– 菜单画面点击按钮会用同时造成同一个位置被遮挡的按钮动作.(无论是否得到菜单号都应该离开 mousePressed() )
– 被隐藏的按钮仍能操作.(没有在禁用窗口的同时禁用控件, 窗口也没有检测控件是否被禁用)


在2.0内制作, 用3.0以上运行可能会报错:


/* *** *** *** *** ***
 * Unnamed
 * *** *** *** *** * */

//--
int pbLeRoller=0;
int pbLeMouseID=0;
int pbLeDoubleClicker=0;
boolean pbLeShowsQuitBox=false;
//--
VcContainer pbTheContainer = new VcContainer();
VcMouseAxis pbTheAxis = new VcMouseAxis(false);
VcMessageBar pbTheBar = new VcMessageBar(52, 0, 20, 64);
VcKeyConsole pbTheConsole = new VcKeyConsole();
VcMenu pbTheMenu;
//--
VcTimeItem pbTheSystemSW = new VcTimeItem(48,16,"system",9999);
EcButton pbTheQuitSW = new EcButton(48,16,"quit",9999);
//--

void setup() {size(320, 240);noStroke();frameRate(16);textAlign(LEFT, TOP);ellipseMode(CENTER);
  frame.setTitle("Unnamed");
  //--
  pbTheMenu=new VcMenu(47,16,8,3,2);
  stPannelGate();
  //--
  pbTheQuitSW.ccRepos(null, width/2-24, height*2/3);
  pbTheSystemSW.cmX=2;pbTheSystemSW.cmY=0;
  //--
  pbTheBar.cmWidth=width-56;
  pbTheBar.ccStack("loaded");
  //--
}//+++

void draw() {
  background(0);
  pbLeRoller++;pbLeRoller&=0x0f;
  int lpMilliChekerA=millis();
  //--
  pbTheContainer.ccUpdate();
  pbLeMouseID=pbTheContainer.ccTellMouseID();
  //--
  fill(0x77,0xFF,0x77);
  fnTextInt("frame%16:", pbLeRoller, 12);
  fnTextInt("MouseID:", pbLeMouseID, 13);
  fnTextInt("pbLePannelFocus:", pbTheContainer.cmPannelFocus, 14);
  //--
  pbTheBar.ccUpdate();
  pbTheConsole.ccUpdate();
  pbTheMenu.ccUpdate();
  pbTheSystemSW.ccUpdateAsTimer(pbLeRoller);if(pbTheSystemSW.ccIsMouseOver()){pbTheMenu.cmEnable=true;}
  drQuitBox(pbLeShowsQuitBox);
  //--
  pbTheAxis.ccUpdate();
  //--
  zeldaRefresh(pbLeRoller);
  //--
  if(pbLeDoubleClicker>0){pbLeDoubleClicker--;}
  //--
  int lpMilliChekerB=millis();
  fill(0x77,0xFF,0x77);
  fnTextInt("ms/f:", lpMilliChekerB-lpMilliChekerA, 11);
  //--
}//+++

void mousePressed(){
  //--
  if(mouseButton==RIGHT){
    EcPannel lpClicked=pbTheContainer.ccGetPannelByID(pbTheContainer.ccTellPannelID());
    if(lpClicked!=null){pbTheContainer.ccRightClicked(lpClicked.cmID);}
    else{pbTheContainer.cmPannelFocus=0;}
  }
  //--
  if(mouseButton==LEFT){if(pbLeDoubleClicker>0){fsDoubleClick();}pbLeDoubleClicker=3;
    if(pbTheQuitSW.ccIsMouseOver()&&pbLeShowsQuitBox){fsPover();}    
    if(pbTheSystemSW.ccIsMouseOver()){pbLeShowsQuitBox=!pbLeShowsQuitBox;}else{pbLeShowsQuitBox=false;}
    if(pbTheMenu.ccApplyEnability(pbTheContainer)==0){pbTheMenu.cmEnable=false;}else{return;}
    zeldaClick(pbLeMouseID);
  }
  //--
}//+++

void mouseDragged(){
  EcPannel lpDragged=pbTheContainer.ccGetFocusedPannel();
  if(lpDragged!=null){
    lpDragged.ccRepos(null,mouseX, mouseY);
    lpDragged.ccReposElement();
  }
}//+++


void keyPressed() {//println("0x"+hex(keyCode,4));
  if(pbTheConsole.ccTyped()){fsCommand(pbTheConsole.cmLastLine);}if(pbTheConsole.cmIsOn){return;}
  switch(keyCode){
    //--
    case 0x25:case 0x41:pbTheBar.cmIndex=0;break;//LT..A
    case 0x26:case 0x57:pbTheBar.ccShiftIndex(-1);break;//UP..W
    case 0x27:case 0x44:pbTheBar.ccFlip(2);break;//RT..D
    case 0x28:case 0x53:pbTheBar.ccShiftIndex( 1);break;//DN..S
    //--
    case 0x74:pbTheAxis.ccFlip();break;
    case 0x75:pbTheAxis.ccSetOrigin();break;
    //--
    default:break;
  }
  //--
  switch(key){
    //--
    case 'q':fsPover();
    default:break;
  }
  //--
}//+++

//- --- --- ---
//- --- --- ---

void drQuitBox(boolean pxAct){if(!pxAct){return;}
  fill(0xEE);rect(width/4,height/4,width/2,height/2);
  fill(0x33);text("Quit Application??\n(click anywhere\n to cancel)",width/3,height/3);
  pbTheQuitSW.ccUpdate();
}//+++

void fsCommand(String pxInput){
  //println(pxInput);
  if(pbTheConsole.cmDoEcho){pbTheBar.ccStack("[echo]"+pxInput);}
  //if(pbTheConsole.cmDoTell){pbTheBar.ccStack("[tell]"+nf(lpMode,2)+">> "+nf(lpVal,4)+" | "+lpCommand+" | "+lpParameter);}
}//+++

void fsDoubleClick(){
  //--
  int lpFocus=pbTheContainer.cmPannelFocus;
  if(lpFocus==0){return;}else{
    EcPannel lpDoubleClicked= pbTheContainer.ccGetPannelByID(lpFocus);
    if(lpDoubleClicked!=null){lpDoubleClicked.cmEnable=false;}
    EcMenuItem lpMirror= pbTheMenu.ccGetMenuByID(lpFocus);
    if(lpMirror!=null){lpMirror.cmAct=false;}
    pbTheContainer.cmPannelFocus=0;
  }
  //--
}//+++

void fsPover(){
  exit();
}//+++

void fnTextFloat(String pxTitle, float pxVal, int pxLine){
  text(pxTitle+nfc(pxVal,2),16,16*pxLine);
}//+++

void fnTextInt(String pxTitle,int pxInt, int pxLine){
  text(pxTitle+nf(pxInt,4),16,16*pxLine);
}//+++

//- --- --- ---
//  Class
//- --- --- ---

class EcElement{
  //--
  int cmID;
  int cmX,cmY,cmW,cmH;
  int cmOffColor,cmOnColor;
  boolean cmAct;
  String cmName;
  boolean cmEnable;
  //--
  EcElement cmFollowed;
  int cmOffsetX,cmOffsetY;
  //--
  EcElement(){
    cmID=0;
    cmX=8;cmY=8;cmW=8;cmH=8;
    cmOffColor=color(0x33,0x33,0x33);
    cmOnColor=color(0xFF,0xFF,0x88);
    cmAct=false;
    cmName="n/c";
    cmFollowed=null;
    cmOffsetX=0;cmOffsetY=0;
    cmEnable=true;
  }
  //--
  void ccUpdate(){if(!cmEnable){return;}
    fill(cmAct?cmOnColor:cmOffColor);
    rect(cmX,cmY,cmW,cmH);
  }
  //--
  boolean ccIsMouseOver(){
    return (mouseX>cmX)&&(mouseX<cmX+cmW)&&(mouseY>cmY)&&(mouseY<cmY+cmH)&&cmEnable;
  }
  void ccFlip(){cmAct=!cmAct;}
  void ccAutoAlign(){
    if(cmFollowed==null){cmX=cmOffsetX;cmY=cmOffsetY;}
    else{
      cmX=cmFollowed.cmX+cmOffsetX+(cmOffsetY==0?cmFollowed.cmW:0);
      cmY=cmFollowed.cmY+cmOffsetY+(cmOffsetX==0?cmFollowed.cmH:0);
    }
  }
  //--
  int[] ccGetpos(){
    int[] lpPos=new int[4];
    lpPos[0]=cmX;
    lpPos[1]=cmY;
    lpPos[2]=cmW;
    lpPos[3]=cmH;
    return lpPos;
  }
  void ccRepos(EcElement pxFollowed,int pxOffsetX, int pxOffsetY){
    cmFollowed=pxFollowed;
    cmOffsetX=pxOffsetX;
    cmOffsetY=pxOffsetY;
    ccAutoAlign();
  }
  //--
}//+++


class EcPannel extends EcElement{
  ArrayList<EcElement> cmElementList;
  EcPannel(int pxWidth, int pxHeight, String pxName, int pxID){
    super();
    cmW=pxWidth;cmH=pxHeight;
    cmName=pxName;
    cmID=pxID;
    cmOffColor=color(0xDD,0xDD,0xDD);
    //--
    cmElementList = new ArrayList();
  }
  //--
  @Override
  void ccUpdate(){
    super.ccUpdate();
    fill(0x33);text(cmName,cmX+2,cmY+2);
    rect(cmX+2,cmY+20,cmW-4,cmH-22);
    for(EcElement it:cmElementList){
      it.ccUpdate();
    }
  }
  //--
  void ccAddElement(EcElement pxElement, EcElement pxFollowed, int pxOffsetX, int pxOffsetY){
    pxElement.cmFollowed=pxFollowed;
    pxElement.cmOffsetX=pxOffsetX;
    pxElement.cmOffsetY=pxOffsetY;
    cmElementList.add(pxElement);
  }
  //--
  void ccReposElement(){
    for(EcElement it:cmElementList){it.ccAutoAlign();}
  }
  //--
  EcElement ccGetElementByID(int pxID){
    for(EcElement it:cmElementList){if(it.cmID==pxID){return it;}}
    return null;
  }
  //--
  int ccTellMouseID(){
    for(int i=cmElementList.size()-1;i>=0;i--){
      EcElement it=cmElementList.get(i);
      if(it.ccIsMouseOver()){return it.cmID;}
    }
    return 0;
  }
  //--
}//+++

class EcLable extends EcElement{
  //--
  EcLable(String pxName, int pxID){
    super();
    cmName=pxName;
    cmOffColor=0xEE;
    cmID=pxID;
  }
  @Override
  void ccUpdate(){
    fill(cmAct?cmOnColor:cmOffColor);
    text(cmName,cmX,cmY);
  }
}//+++

class EcButton extends EcElement{
  //--
  //--
  EcButton(int pxWidth, int pxHeight, String pxName, int pxID){
    super();
    cmW=pxWidth;cmH=pxHeight;
    cmName=pxName;
    cmID=pxID;
  }
  //--
  @Override
  void ccUpdate(){if(!cmEnable){return;}
    fill(0x77);rect(cmX,cmY,cmW,cmH);
    stroke(0xDD);fill(ccIsMouseOver()?0xBB:0xAA);
    rect(cmX+2,cmY+2,cmW-5,cmH-5);noStroke();
    fill(cmAct?cmOnColor:cmOffColor);textAlign(CENTER,CENTER);
    text(cmName,cmX+cmW/2,cmY+cmH/2-2);textAlign(LEFT,TOP); 
  }
  //--
  boolean ccIsPressed(){return mousePressed&&ccIsMouseOver();}
  //--
}//+++


class EcLamp extends EcElement{
  //--
  char cmMode;
  //--
  EcLamp(int pxScale, String pxName, int pxID, char pxMode_ablr){
    super();
    cmW=pxScale;cmH=pxScale;
    cmName=pxName;
    cmID=pxID;
    cmMode=pxMode_ablr;
    cmOnColor=color(0x77,0xFF,0x77);
  }
  @Override
  void ccUpdate(){
    fill(0x77);ellipse(cmX+cmW/2,cmY+cmH/2,cmW,cmH);
    fill(cmAct?cmOnColor:cmOffColor);ellipse(cmX+cmW/2,cmY+cmH/2,cmW-4,cmH-4);
    fill(0xEE);
    switch(cmMode){
      case 'a':textAlign(CENTER,BOTTOM);text(cmName,cmX+cmW/2, cmY);textAlign(LEFT,TOP);break;
      case 'b':textAlign(CENTER,TOP);text(cmName,cmX+cmW/2, cmY+cmH+2);textAlign(LEFT,TOP);break;
      case 'l':textAlign(RIGHT,TOP);text(cmName,cmX-2, cmY);textAlign(LEFT,TOP);break;
      case 'r':text(cmName,cmX+cmW+2, cmY);break;
      default:break;
    }
  }
}//+++


class EcValueBox extends EcElement{
  //--
  char cmNameMode;
  String cmUnit;
  //--
  int cmVal;
  //--
  EcValueBox(int pxWidth,int pxHeight, String pxName,String pxUnit, int pxID, char pxNameMode_ablr){
    super();
    cmW=pxWidth;cmH=pxHeight;
    cmName=pxName;
    cmID=pxID;
    cmNameMode=pxNameMode_ablr;
    //--
    cmUnit=pxUnit;
    cmVal=0;
  }
  @Override
  void ccUpdate(){
    fill(0x33);stroke(0xCC);rect(cmX,cmY,cmW,cmH);noStroke();
    fill(0xCC);textAlign(RIGHT,CENTER);text(ccBoxString()+cmUnit,cmX+cmW-2,cmY+cmH/2);textAlign(LEFT,TOP);
    switch(cmNameMode){
      case 'a':textAlign(CENTER,BOTTOM);text(cmName,cmX+cmW/2, cmY);textAlign(LEFT,TOP);break;
      case 'b':textAlign(CENTER,TOP);text(cmName,cmX+cmW/2,cmY+cmH+2);textAlign(LEFT,TOP);break;
      case 'l':textAlign(RIGHT,TOP);text(cmName,cmX-2, cmY);textAlign(LEFT,TOP);break;
      case 'r':textAlign(LEFT,CENTER);text(cmName,cmX+cmW+2, cmY+cmH/2);textAlign(LEFT,TOP);break;
      default:break;
    }
  }
  String ccBoxString(){
    return nf(cmVal,4);
  }
  //--
  void ccShiftValue(int pxOffset){cmVal+=pxOffset;}
  void ccShiftValueInRange(int pxOffset, int pxMin, int pxMax){
    ccShiftValue(pxOffset);cmVal=constrain(cmVal,pxMin,pxMax);
  }
  boolean ccIsInRangeOf(int pxLowBound, int pxHighBound){
    return cmVal>=pxLowBound&&cmVal<=pxHighBound;
  }
  //--
}//+++

class EcRealBox extends EcValueBox{
  float cmOffsetAD,cmOffset;
  float cmSpanAD,cmSpan;
  boolean cmMoreAccuracy;
  EcRealBox(int pxWidth,int pxHeight, String pxName,String pxUnit, int pxID, char pxNameMode_ablr){
    super(pxWidth,pxHeight,pxName,pxUnit,pxID,pxNameMode_ablr);
    cmOffsetAD=400;cmOffset=0;
    cmSpanAD=3600;cmSpan=100;
  }
  @Override
  String ccBoxString(){
    return nfc(ccTellRealValue(1),cmMoreAccuracy?2:1);
  }
  float ccTellRealValue(int pxDivide){
    Integer lpFormap=cmVal;
    return map(lpFormap.floatValue(),cmOffsetAD,cmSpanAD,cmOffset,cmSpan)/pxDivide;
  }  
}//+++

class EcMenuItem extends EcButton{
  EcMenuItem(int pxWidth, int pxHeight, String pxName, int pxID){
    super(pxWidth,pxHeight,pxName,pxID);
  }
  @Override
  void ccUpdate(){if(!cmEnable){return;}
    fill(ccIsMouseOver()?0xBB:0xAA);rect(cmX,cmY,cmW,cmH);
    fill(cmAct?cmOnColor:cmOffColor);textAlign(CENTER,CENTER);
    text(cmName,cmX+cmW/2,cmY+cmH/2-2);textAlign(LEFT,TOP);     
  }  
}//+++

class VcTimeItem extends EcMenuItem{
  VcTimeItem(int pxWidth, int pxHeight, String pxName, int pxID){
    super(pxWidth,pxHeight,pxName,pxID);
  }
  void ccUpdateAsTimer(int pxRoller){
    StringBuffer lpTime = new StringBuffer();
    lpTime.append(nf(hour(),2));
    if(pxRoller<7){lpTime.append(" : ");}else{lpTime.append("   ");}
    lpTime.append(nf(minute(),2));
    cmName = lpTime.toString();
    ccUpdate();
  }
}//+++

class VcContainer{
  ArrayList<EcPannel> cmPannelList;
  int cmPannelFocus;
  VcContainer(){
    cmPannelFocus=0;
    cmPannelList=new ArrayList();
  }
  void ccAddPannel(EcPannel pxPannel){
    cmPannelList.add(pxPannel);
  }
  void ccUpdate(){
    for(EcPannel it:cmPannelList){if(it.cmEnable){
      it.ccUpdate();
      it.cmAct=(it.cmID==cmPannelFocus);
    }}
  }
  void ccReposElement(){
    for(EcPannel it:cmPannelList){it.ccReposElement();}
  }
  int ccTellMouseID(){
    for(int i=cmPannelList.size()-1;i>=0;i--){
      EcPannel it=cmPannelList.get(i);
      if(it.cmEnable){
        int lpID=it.ccTellMouseID();
        if(lpID!=0){return lpID;}
      }
      if(it.ccIsMouseOver()){return it.cmID;}
    }
    return 0;
  }
  void ccRightClicked(int pxID){
    cmPannelFocus=pxID;
    ccSetPriority(cmPannelFocus);
  }
  int ccTellPannelID(){
    for(int i=cmPannelList.size()-1;i>=0;i--){
      EcPannel it=cmPannelList.get(i);
      if(it.ccIsMouseOver()){return it.cmID;}
    }
    return 0;
  }
  //--
  void ccSetPriority(int pxID){
    EcPannel lpTarget=ccGetPannelByID(pxID);
    if(lpTarget==null){return;}
    cmPannelList.remove(cmPannelList.indexOf(lpTarget));
    cmPannelList.add(lpTarget);
  }
  //--
  EcPannel ccGetPannelByID(int pxID){
    for(EcPannel it:cmPannelList){if(it.cmID==pxID){return it;}}
    return null;
  }
  //--
  EcPannel ccGetFocusedPannel(){
    return ccGetPannelByID(cmPannelFocus);
  }
  //--
  }//+++


class VcMenu{
  //--
  int cmX,cmY,cmW,cmH;
  boolean cmEnable;
  //--
  EcMenuItem[] cmThoseMenuItem;
  //--
  VcMenu(int pxWidth, int pxHeight,int pxSize,int pxDiv,int pxBordWeight){
    cmX=width/4;
    cmY=height/4;
    cmW=width/2;
    cmH=height/2;
    cmEnable=false;
    cmThoseMenuItem=new EcMenuItem[pxSize];
    for(int i=0;i<cmThoseMenuItem.length;i++){
      cmThoseMenuItem[i]=new EcMenuItem(pxWidth, pxHeight, "m"+nf(i,2), i);
      cmThoseMenuItem[i].ccRepos(null, i%pxDiv*(pxWidth+pxBordWeight)+cmX+pxBordWeight, i/pxDiv*(pxHeight+pxBordWeight)+cmY+pxBordWeight);
      cmThoseMenuItem[i].cmAct=true;
    }
    cmThoseMenuItem[0].cmID=-1;
  }
  void ccUpdate(){if(!cmEnable){return;}
    fill(0xEE);
    rect(cmX,cmY,cmW,cmH);
    for(EcMenuItem it:cmThoseMenuItem){it.ccUpdate();}
  }
  int ccApplyEnability(VcContainer pxContainer){if(!cmEnable){return 0;}
    for(EcMenuItem it:cmThoseMenuItem){
      if(it.ccIsMouseOver()){
        it.ccFlip();
        EcPannel lpPannel=pxContainer.ccGetPannelByID(it.cmID);
        if(lpPannel!=null){lpPannel.cmEnable=it.cmAct;}
        return it.cmID;
      }
    }
    return 0;
  }
  //--
  EcMenuItem ccGetMenuByID(int pxID){
    for(EcMenuItem it:cmThoseMenuItem){
      if(it.cmID==pxID){return it;}
    }return null;
  }
  //--
}//+++


class VcMouseAxis{
  boolean cmIsAxisOn;
  int cmMouseRelateX,cmMouseRelateY;
  //---
  VcMouseAxis(boolean pxAct){
    cmIsAxisOn=pxAct;
    cmMouseRelateX=0;
    cmMouseRelateY=0;
  }
  //---
  void ccUpdate(){
    if(!cmIsAxisOn){return;}
    stroke(255);fill(255);
    line(0,mouseY,width,mouseY);
    line(mouseX,0,mouseX,height);
    text(str(mouseX)+":"+str(mouseY),mouseX-64,mouseY);
    text(str(cmMouseRelateX)+":"+str(cmMouseRelateY),mouseX-64,mouseY-16);
    text(str(mouseX-cmMouseRelateX)+":"+str(mouseY-cmMouseRelateY),mouseX+2,mouseY-16);
    noFill();rect(cmMouseRelateX,cmMouseRelateY,mouseX-cmMouseRelateX,mouseY-cmMouseRelateY);
    noStroke();
  }
  //--
  void ccFlip(){cmIsAxisOn=!cmIsAxisOn;cmMouseRelateX=cmMouseRelateY=0;}
  void ccSetOrigin(){cmMouseRelateX=mouseX;cmMouseRelateY=mouseY;}
  void ccClicked(){
    if(mouseButton==RIGHT){ccFlip();}
    if(mouseButton==LEFT&&cmIsAxisOn){ccSetOrigin();}
  }
}//--VcMouseAxis


class VcMessageBar{
  int cmX, cmY, cmWidth,cmMax;
  int cmHeight,cmReturn,cmIndex;
  String[] cmLineShower;
  String[] cmLineBuffer;
  boolean cmIsMid,cmIsLarge;
  StringList cmLogger;
  //--
  VcMessageBar(int pxX, int pxY, int pxWidth, int pxMax){
    cmX=pxX;cmY=pxY;cmWidth=pxWidth;cmMax=pxMax;
    cmHeight=16;cmReturn=16;cmIndex=0;
    cmLineShower=new String[8];for(int i=0;i<8;i++){cmLineShower[i]=">> "+str(i);}
    cmLineBuffer=new String[64];for(int i=0;i<64;i++){cmLineBuffer[i]=".. "+str(i);}
    cmLogger=new StringList();
  }
  //--
  void ccUpdate(){
    cmHeight=cmIsLarge? 128 : (cmIsMid? 48: 16);
    fill(0x77,0x77,0x77,0xCC);rect(cmX, cmY, cmWidth,cmHeight);
    for(int i=0;i<8;i++){cmLineShower[i]=cmLineBuffer[i+cmIndex];}
    fill(cmIndex==0? 0xFF:0xAA);text(cmLineShower[0],cmX+2,cmY);
    fill(0xAA);if(cmIsMid){
      text(cmLineShower[1],cmX+2,cmY+cmReturn*1);
      text(cmLineShower[2],cmX+2,cmY+cmReturn*2);
    }
    if(cmIsLarge){for(int i=3;i<8;i++){
      text(cmLineShower[i],cmX+2,cmY+cmReturn*i);
    }}
    if(cmIndex!=0){fill(0x88);text(str(cmIndex),cmX+cmWidth-25,cmY);}
  }
  //--
  void ccFlip(int pxV){switch (pxV){
    case 1:if(cmIsLarge){return;}cmIsMid=!cmIsMid;break;
    case 2:cmIsLarge=!cmIsLarge;cmIsMid=cmIsLarge;break;
    default:break;
  }}
  void ccShiftIndex(int pxOffset){cmIndex+=pxOffset;cmIndex=constrain(cmIndex,0,54);}
  //--
  void ccStack(String pxLine){
    String lpTimeStamp="--"+nf(hour(),2)+":"+nf(minute(),2);
    for(int i=63;i>=1;i--){cmLineBuffer[i]=cmLineBuffer[i-1];}
    if(pxLine.length()>cmMax){cmLineBuffer[0]=pxLine.substring(0,cmMax-1);}
    else{cmLineBuffer[0]=pxLine;}
    cmLineBuffer[0]+=lpTimeStamp;
  }
}//--VcMessageBar


class VcKeyConsole{
  //---
  boolean cmIsOn;
  String cmInputLine;
  String cmLastLine;
  //---
  int cmMax;
  boolean cmDoEcho;
  boolean cmDoTell;
  //---
  IntDict cmCommandSets;
  //--
  VcKeyConsole(){
    cmIsOn=false;
    cmInputLine=">>..";
    cmLastLine="_";
    //--
    cmCommandSets = new IntDict();
    cmCommandSets.set("echo",35);
    cmCommandSets.set("tell",36);
    cmCommandSets.set("quit",99);
    cmCommandSets.set("help",98);
    //--
    cmDoEcho=true;
    cmDoTell=false;
    //--
  }
  //---
  void ccUpdate(){
    if(!cmIsOn){return;}
    fill(0xEE);rect(0,height-20,width,16);
    fill(0x33);text(cmInputLine,2,height-20);
    cmMax=32;
  }
  //--
  void ccFlipEcho(){cmDoEcho=!cmDoEcho;}
  void ccFlipTell(){cmDoTell=!cmDoTell;}
  //--
  int ccHandCommandID(String pxCommand){return cmCommandSets.get(pxCommand);}
  //---
  boolean ccTyped(){
    if(key==0x0A&&!cmIsOn){cmIsOn=true;return false;}
    if(cmIsOn){
      if((key>=',' && key<='z') && cmInputLine.length()<(4+cmMax)){cmInputLine+=str(key);return false;}
      if(cmInputLine.length()>4){if(key==0x08){cmInputLine=cmInputLine.substring(0,cmInputLine.length()-1);}}
    }
    if(key==0x0A&&cmIsOn){
      cmIsOn=false;
      if(cmInputLine.length()==4){return false;}
      cmLastLine=cmInputLine.substring(4,cmInputLine.length());
      cmInputLine=">>..";
      return true;
    }
  return false;}
  //---
  //---
}//--VcKeyConsole


//- --- --- ---
//- Pannel Gate
//- --- --- ---

void stPannelGate(){
  stThatControlPannel();pbTheContainer.ccAddPannel(pbThatControlPannel);
  stThatModelPannel();pbTheContainer.ccAddPannel(pbThatModelPannel);
  stThatViewPannel();pbTheContainer.ccAddPannel(pbThatViewPannel);
}//+++

//-- ** control pannel
EcPannel pbThatControlPannel = new EcPannel(160,140,"control",1);
EcButton pbThisTestA = new EcButton(30,30,"#A",121);
EcButton pbThisTestB = new EcButton(30,30,"#B",122);
EcButton pbThisTestC = new EcButton(30,30,"#C",123);
//--
EcButton pbThisTestD = new EcButton(18,18,"-",131);
EcButton pbThisTestE = new EcButton(18,18,"+",132);
EcButton pbThisTestF = new EcButton(18,18,"$",133);
EcLable pbThisTestG = new EcLable("#XX", 134);
//--
EcButton pbThisTestH = new EcButton(75,25,"Charge",141);

void stThatControlPannel(){
  pbThatControlPannel.ccRepos(null,16,32);
  pbThatControlPannel.ccAddElement(pbThisTestA,pbThatControlPannel,5,25);
  pbThatControlPannel.ccAddElement(pbThisTestB,pbThisTestA,2,0);
  pbThatControlPannel.ccAddElement(pbThisTestC,pbThisTestB,2,0);
  //--
  pbThatControlPannel.ccAddElement(pbThisTestD,pbThisTestA,0,16);
  pbThatControlPannel.ccAddElement(pbThisTestE,pbThisTestD,1,0);
  pbThatControlPannel.ccAddElement(pbThisTestF,pbThisTestE,1,0);
  pbThatControlPannel.ccAddElement(pbThisTestG,pbThisTestF,2,0);
  //--
  pbThatControlPannel.ccAddElement(pbThisTestH,pbThisTestD,0,16);
  //--
  pbThatControlPannel.ccReposElement();
}//+++

//-- ** Model Pannel
EcPannel pbThatModelPannel = new EcPannel(128,99,"model",2);
// <editor-fold defaultstate="collapsed" desc="P002:pbThatModelPannel">
EcLamp pbThisTestJ = new EcLamp(16, "#J", 211, 'r');
EcLamp pbThisTestK = new EcLamp(16, "#K", 212, 'r');
EcLamp pbThisTestL = new EcLamp(16, "#L", 213, 'r');
void stThatModelPannel(){
  pbThatModelPannel.ccRepos(pbThatControlPannel,2,0);
  pbThatModelPannel.ccAddElement(pbThisTestJ,pbThatModelPannel,5,25);
  pbThatModelPannel.ccAddElement(pbThisTestK,pbThisTestJ,0,2);
  pbThatModelPannel.ccAddElement(pbThisTestL,pbThisTestJ,32,0);
  pbThatModelPannel.ccReposElement();
}//+++

//-- ** View Pannel
EcPannel pbThatViewPannel = new EcPannel(128,99,"view",3);
EcValueBox pbThisTestR = new EcValueBox(64,18,"#R"," AD",311,'r');
EcRealBox pbThisTestS = new EcRealBox(64, 18, "#S", " c", 312, 'r');
EcLamp pbThisTestT = new EcLamp(16, "Charge", 313, 'r');
void stThatViewPannel(){
  pbThatViewPannel.ccRepos(pbThatModelPannel,0,2);
  pbThatViewPannel.ccAddElement(pbThisTestR,pbThatViewPannel,5,25);
  pbThatViewPannel.ccAddElement(pbThisTestS,pbThisTestR,0,2);
  pbThatViewPannel.ccAddElement(pbThisTestT,pbThisTestS,0,8);
  pbThatViewPannel.ccReposElement();
}//+++

void zeldaRefresh(int pxRoller){if(false){return;}
  //-- > model pannel < --
  pbThisTestL.cmAct=pbThisTestC.ccIsPressed();
  //-- > view pannel < --
  pbThisTestS.cmVal=pbThisTestR.cmVal;
  if(pbThisTestT.cmAct){pbThisTestR.ccShiftValue(pbThisTestK.cmAct?10:1);}
  //--
}//+++


void zeldaClick(int pxID){switch(pxID){
  //-- >  < --
  //-- > no use < --
  case 0:
    break;
  //-- > control pannel < --
  case 121:
    pbThisTestA.ccFlip();
    pbThisTestJ.cmAct=pbThisTestA.cmAct;
    break;
  //--
  case 122:
    pbThisTestK.ccFlip();
    break;
  //--
  case 131:
    pbThisTestR.ccShiftValue(pbThisTestK.cmAct?-10:-1);
    break;
  //--
  case 132:
    pbThisTestR.ccShiftValue(pbThisTestK.cmAct? 10: 1);
    break;
  //--
  case 133:
    pbThisTestR.cmVal=800;
    break;
  //--
  //--
  case 141:
    pbThisTestT.ccFlip();
    break;
  //--
  //-- >  < --
  default:break;
}}//+++

 



最后编辑:
作者:constrain
constrain
nullpointerexception

留下一个回复

你的email不会被公开。