//class INputTextfield begin //------------------------------------------// class INputTextfield { float x, y, w, h, tfw, tfh, ntl; int l; //leading int tlength; String textContents; String labeltext; String samet; float margin; PFont pf; Brect fieldArea; Textbox textField, textField2; boolean isTyping; boolean reset; INputTextfield(String a_, float x_, float y_, float w_, float h_,int l_,PFont ts_){ labeltext = a_; textContents = labeltext; samet = labeltext; x = x_; y = y_; w = w_; h = h_; l = l_; pf = ts_; margin = 6; tfw = w-margin*2; tfh = h-margin*2; //textfield textField = new Textbox(textContents, x+margin, y+margin, tfw, tfh, l, pf ); textField2 = new Textbox(textContents, x+margin, y+margin, tfw, tfh, l, pf ); tlength = 1; reset = false; // backgroud of box fieldArea = new Brect(x, y, w, h, 1); fieldArea.n = color(255); fieldArea.r = color(255); fieldArea.o = color(255); fieldArea.p = color(255); fieldArea.b = color(0,60); } void display(){ update(); fieldArea.display(); fill(0,100); textField.textBox(); fill(0,160); textField2.textBox(); } void update(){ // check activate it or not if(fieldArea.isPressed){ fieldArea.isLocked = true; fieldArea.b = color(234,82,21); } if(!fieldArea.isOver && mousePressed){ fieldArea.isLocked = false; fieldArea.b = color(0,60); } // reset intro-text if(reset){ //labeltext = textContents ; textField2.textContent = textField.textContent = labeltext; } } void write(){ // start-clean up if(fieldArea.isLocked){ if(labeltext.length() > 0){ textContents = ""; labeltext = ""; reset = false; } // add character char k = char(key); textContents = textContents + str(k); textField.textContent = textContents; // light color textField2.textContent = textContents.substring(0, textContents.length()-1); // dark color } } void delete(){ if(fieldArea.isLocked){ if(textContents.length() >0){ int temm = textContents.length()-1; textContents = textContents.substring(0, temm); textField.textContent = textContents; // light color // check null- zero point of length() of dark color type if(textField2.textContent.length() > 0){ textField2.textContent = textContents.substring(0, textContents.length()-1);// dark color } // temporary reset if(textContents.length() == 0){ textField.textContent = "Rewrite"; } } } } float getTextLegnth(String xx){ float teml = textWidth(xx); ntl = teml; return ntl; } int getLineNums(float teml){ return ceil(teml/tfw); } int getStringL(){ return textContents.length(); } } //class INputTextfield end /////////////////////////////////////////////////////////////// // class Textbox start -----------------------------// class Textbox{ float x, y, w, h, tl, fonth ; float th, ted, tea; String textContent; PFont px; int leading; Textbox(){ } Textbox(String a_, float x_, float y_, float w_, float h_,int l_,PFont ts_){ textContent = a_; px = ts_; textFont(px); tl = textWidth(textContent); fonth = textDescent()+textAscent(); ted = textDescent(); tea = textAscent(); x = x_; y = y_; w = w_; h = h_; leading = l_; } void textBox(){ textFont(px); textLeading(leading); text(textContent,int(x), int(y), int(w),int(h)); //getTh(); //rect(x, y,10, th); } void textBox_R(){ pushMatrix(); translate(x,y); rotate(radians(90)); textFont(px); textLeading(leading); text(textContent,-textWidth(textContent)/2, 0); popMatrix(); } void setPosition(float x_, float y_){ x = x_; y = y_; } void setString(String dd){ textContent = dd; } float getTh(){ int lineNum = ceil(tl/w); if(lineNum > 1){ float hh =leading*lineNum-ted; // println(tea); return th = hh; } else { float hh =leading*lineNum; return th = hh; } } float getLength(){ return tl; //=textWidth(textContent); } } // class Textbox end -----------------------------// ////class Choise start////////////////////////////////////////////// class Choise { String[] item; String selectItem; float x,y, w, sellh; int num; int caseID; int selectId; Button2[] sellB; BArrow baB; boolean isFirst; boolean isSpread; PFont pff; Choise(String[] a, float x_, float y_,float w_, PFont pff_){ item = a; num = item.length; //println(num); pff = pff_; x = x_; y = y_; w = w_; isFirst = true; isSpread = false; caseID = 1; selectId = 0; selectItem = item[0]; sellB = new Button2[num]; for(int i=0; ix+sellB[0].w+baB.w && mousePressed) || (mouseY < y && mousePressed) || (mouseY > y+(sellB[0].h*num) && mousePressed) ){ caseID = 2; } } } void showHide(int xx){ switch(xx){ case 1: selectId =0; for(int i=0; i= x_ && mouseX <= x_+w_ && mouseY >= y_ && mouseY <= y_+h_){ return true; } else{ return false; } } void setColor_o(color x){ o = x; } void setColor_p(color x){ p = x; } void setColor_n(color x){ n = x; } void setColor_r(color x){ r = x; } void setColor_b(color x){ b = x; } float getX(){ return x; } float getY(){ return y; } float getW(){ return w; } float getH(){ return h; } } ///class Brect2 end///////////////////////////////////// ///class Brect start///////////////////////////////////// class Brect{ // position and size float x,y,w,h,m; // case of use 1: button 2: other- change color as it pressed and remain color changed int ca; int con; int on; // boolean over and pressed boolean isOver; boolean isPressed; boolean isLocked; //style of rect color n= color(211,211,211); color r= color(211,211,211); color o= color(245, 59, 12); color p= color(100, 21, 1); color c= color(33, 9, 3); color b= color(255, 255, 255); Brect(){ } Brect(float x_, float y_, float w_, float h_, float m_, int f){ x = x_; y = y_; m = m_; w = w_; h = h_; ca = f; con =0; isOver = false; isPressed = false; isLocked = false; } Brect(float x_, float y_, float w_, float h_, int f){ x = x_; y = y_; w = w_; h = h_; ca = f; con =0; isOver = false; isPressed = false; isLocked = false; } void update(){ over(); press(); switch(ca){ case 1: if(isOver && isPressed){ n = p; on = 1; } else if(isOver && isPressed==false){ n = o; } else{ n = r; on = 0; } break; case 2: if(isOver && isPressed && isLocked){ n = p; } else if(isOver){ n = o; } else if(!isLocked){ n = r; } break; } } void over(){ if(overShape(x, y, w, h)){ //cursor(TEXT); isOver = true; } else{ isOver = false; } } void press(){ switch(ca){ case 1: if(isOver && mousePressed ){ isPressed = true; } else{ isPressed = false; } break; case 2: if( isOver && mousePressed || isLocked){ isPressed = true; isLocked = true; } else if(isOver && isLocked && mousePressed){ isLocked = false; } else{ isPressed = false; } break; } } void release(){ isLocked = false; } void display(){ update(); noStroke(); switch(ca){ case 1: stroke(b); //rect(x-1, y-1, w+2, h+2); fill(n); rect(x, y, w, h); break; case 2: if(isOver){ fill(b); rect(x-1, y-1, w+2, h+2); fill(n); rect(x, y, w, h); stroke(b); line(x+2,y+2,x+w-2,y+h-2); line(x+2,y+h-2,x+w-2,y+2); } else if(isLocked){ fill(b); rect(x-1, y-1, w+2, h+2); fill(n); rect(x, y, w, h); stroke(b); line(x+2,y+2,x+w-2,y+h-2); line(x+2,y+h-2,x+w-2,y+2); } else{ rect(x, y, w, h); } break; } } void setPosition(float xx, float yy){ x = xx; y = yy; } void setSize(float ww, float hh){ w = ww; h = hh; } boolean overShape(float x_, float y_, float w_, float h_){ if(mouseX >= x_ && mouseX <= x_+w_ && mouseY >= y_ && mouseY <= y_+h_){ return true; } else{ return false; } } void setColor_o(color x){ o = x; } void setColor_p(color x){ p = x; } void setColor_n(color x){ n = x; } void setColor_r(color x){ r = x; } void setColor_b(color x){ b = x; } float getX(){ return x; } float getY(){ return y; } float getW(){ return w; } float getH(){ return h; } } ///class Brect end/////////////////////////////////////