Advertisement
Guest User

Untitled

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