Advertisement
Guest User

Untitled

a guest
Nov 21st, 2015
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.17 KB | None | 0 0
  1. void setup(){
  2. background(175);
  3. size(600,400);
  4. rectMode(CORNER);
  5. }
  6.  
  7. String textBoxInput = "";
  8.  
  9. boolean textLimit = false;
  10. boolean drawCap = false;
  11. boolean drawRev = false;
  12. boolean drawReverse = false;
  13. boolean drawDelSp = false;
  14. boolean drawMidChar = false;
  15. boolean doOnce = true;
  16.  
  17. void draw(){
  18. background(175);
  19.  
  20. float buttonWidth = width*0.2916;
  21. float buttonHeight = height*0.08;
  22. int buttonPosX = (width/14)*9;
  23. int buttonPosY = height/6;
  24.  
  25. int textBoxPosX = width/14;
  26. int textBoxPosY = height/6;
  27. float textBoxWidth = width*0.533;
  28.  
  29. String clearText = "Clear";
  30. String capText = "Capitals";
  31. String revText = "Reverse";
  32. String delSpText = "Delete Spaces";
  33. String midCharText = "Middle Character";
  34.  
  35. float textMarginX = buttonWidth/20;
  36. float textMarginY = buttonHeight/4;
  37.  
  38. String textCap = textBoxInput.toUpperCase();
  39. String textRev ="";
  40. String finalReversed = "";
  41.  
  42.  
  43. //TextBox
  44. fill(255);
  45. rect(textBoxPosX,textBoxPosY,textBoxWidth,buttonHeight);
  46. fill(0);
  47. textSize(width*0.03);
  48. text(textBoxInput,textBoxPosX+textMarginX,textBoxPosY+buttonHeight-textMarginY);
  49.  
  50. //BUTTONS
  51. //Clear button
  52. fill(175);
  53. rect(buttonPosX,buttonPosY,buttonWidth,buttonHeight);
  54. fill(0);
  55. textSize(width*0.03);
  56. text(clearText,buttonPosX+textMarginX,buttonPosY+buttonHeight-textMarginY);
  57.  
  58. //Capital button
  59. fill(175);
  60. rect(buttonPosX,buttonPosY*2,buttonWidth,buttonHeight);
  61. fill(0);
  62. textSize(width*0.03);
  63. text(capText,buttonPosX+textMarginX,(buttonPosY*2)+buttonHeight-textMarginY);
  64.  
  65. //Reverse button
  66. fill(175);
  67. rect(buttonPosX,buttonPosY*3,buttonWidth,buttonHeight);
  68. fill(0);
  69. textSize(width*0.03);
  70. text(revText,buttonPosX+textMarginX,(buttonPosY*3)+buttonHeight-textMarginY);
  71.  
  72. //Delete Spaces button
  73. fill(175);
  74. rect(buttonPosX,buttonPosY*4,buttonWidth,buttonHeight);
  75. fill(0);
  76. textSize(width*0.03);
  77. text(delSpText,buttonPosX+textMarginX,(buttonPosY*4)+buttonHeight-textMarginY);
  78.  
  79. //Middle Character button
  80. fill(175);
  81. rect(buttonPosX,buttonPosY*5,buttonWidth,buttonHeight);
  82. fill(0);
  83. textSize(width*0.03);
  84. text(midCharText,buttonPosX+textMarginX,(buttonPosY*5)+buttonHeight-textMarginY);
  85.  
  86. if(textLimit){
  87. fill(255,0,0);
  88. text("Text limit reached!",textBoxPosX,height/8);
  89. }
  90.  
  91. if(drawRev){
  92. int i = textBoxInput.length();
  93. while(i>0){
  94. textRev += textBoxInput.substring(i-1,i);
  95. i--;
  96. println(i,textRev,"running?");
  97. if(i==0){
  98. finalReversed = textRev;
  99. drawRev = false;
  100. drawReverse = true;
  101. }
  102. }
  103. }
  104. final String revrev = finalReversed;
  105.  
  106. println("rev: ",revrev);
  107.  
  108. //BUTTON BOOLEANS
  109. //CAPITAL
  110. if(drawCap){
  111. text(textCap,textBoxPosX,(buttonPosY*2)+buttonHeight-textMarginY);
  112. }
  113. if(drawReverse){
  114. text(finalReversed,textBoxPosX,(buttonPosY*3)+buttonHeight-textMarginY);
  115. }
  116.  
  117. //BUTTON CLICK
  118. if(mousePressed && doOnce == false){
  119. //Clear button
  120. if(mouseX >= buttonPosX && mouseX <= buttonPosX+buttonWidth && mouseY >= buttonPosY && mouseY <= buttonPosY+buttonHeight){
  121. textBoxInput = "";
  122. }
  123. //Capital button
  124. if(mouseX >= buttonPosX && mouseX <= buttonPosX+buttonWidth && mouseY >= buttonPosY*2 && mouseY <= (buttonPosY*2)+buttonHeight){
  125. drawCap = true;
  126. }
  127. //Reverse button
  128. if(mouseX >= buttonPosX && mouseX <= buttonPosX+buttonWidth && mouseY >= buttonPosY*3 && mouseY <= (buttonPosY*3)+buttonHeight){
  129. drawRev = true;
  130. }
  131. doOnce = true;
  132. }
  133.  
  134. }
  135.  
  136. void mouseReleased(){
  137. doOnce = false;
  138. }
  139.  
  140. void keyTyped(){
  141. if((key >= 'a' && key <= 'z') || key == ' '){
  142. if(textBoxInput.length()<=20){
  143. textBoxInput = textBoxInput + key;
  144. } else {
  145. textLimit = true;
  146. }
  147. } else if ((key == BACKSPACE) && textBoxInput.length()>0){
  148. int inputLength = textBoxInput.length();
  149. textBoxInput = textBoxInput.substring(0,inputLength-1);
  150. }
  151. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement