fork download
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using Microsoft.Xna.Framework;
  6. using Microsoft.Xna.Framework.Audio;
  7. using Microsoft.Xna.Framework.Content;
  8. using Microsoft.Xna.Framework.GamerServices;
  9. using Microsoft.Xna.Framework.Graphics;
  10. using Microsoft.Xna.Framework.Input;
  11. using Microsoft.Xna.Framework.Media;
  12.  
  13. namespace WindowsGame1
  14. {
  15. class TextBox
  16. {
  17. Vector2 position;
  18.  
  19. Vector2 boxDim;
  20.  
  21. string labelText;
  22.  
  23. string boxText;
  24.  
  25. int blinkTicks;
  26.  
  27. bool blink = false;
  28.  
  29. bool selected = false;
  30.  
  31. bool mouseDownLast = false;
  32.  
  33. List<Keys> keyPressedLast = new List<Keys>();
  34.  
  35. KeyboardState lastState;
  36. KeyboardState currentState;
  37.  
  38. public string BoxText
  39. {
  40. get
  41. {
  42. return boxText;
  43. }
  44. }
  45.  
  46. int maxCharacters;
  47.  
  48. public TextBox(Vector2 newPosition, Vector2 bounds, string label, string startText, int max)
  49. {
  50. position = newPosition;
  51. boxDim = bounds;
  52. labelText = label;
  53. boxText = startText;
  54. maxCharacters = max;
  55. }
  56.  
  57. public void update()
  58. {
  59. KeyboardState keyboard = Keyboard.GetState();
  60.  
  61. blinkTicks++;
  62.  
  63. if (blinkTicks > 6)
  64. {
  65. blink = !blink;
  66.  
  67. blinkTicks = 0;
  68. }
  69.  
  70. if (new Rectangle((int)position.X, (int)position.Y, (int)boxDim.X, (int)boxDim.Y).Contains(Mouse.GetState().X, Mouse.GetState().Y) && Mouse.GetState().LeftButton == ButtonState.Pressed && !mouseDownLast)
  71. {
  72. selected = !selected;
  73.  
  74. if (!selected)
  75. {
  76. blinkTicks = 0;
  77.  
  78. blink = false;
  79. }
  80.  
  81. }
  82.  
  83.  
  84.  
  85.  
  86. if (selected)
  87. {
  88.  
  89.  
  90. if (keyboard.IsKeyDown(Keys.Back) && boxText.Length > 0)
  91. boxText = boxText.Remove(boxText.Length - 1);
  92.  
  93. string characterPressed = "";
  94.  
  95. if (keyboard.IsKeyDown(Keys.Space))
  96. characterPressed = " ";
  97.  
  98. if (keyboard.IsKeyDown(Keys.A))
  99. characterPressed = "A";
  100.  
  101. if (keyboard.IsKeyDown(Keys.B))
  102. characterPressed = "B";
  103.  
  104. if (keyboard.IsKeyDown(Keys.C))
  105. characterPressed = "C";
  106.  
  107. if (keyboard.IsKeyDown(Keys.D))
  108. characterPressed = "D";
  109.  
  110. if (keyboard.IsKeyDown(Keys.E))
  111. characterPressed = "E";
  112.  
  113. if (keyboard.IsKeyDown(Keys.F))
  114. characterPressed = "F";
  115.  
  116. if (keyboard.IsKeyDown(Keys.G))
  117. characterPressed = "G";
  118.  
  119. if (keyboard.IsKeyDown(Keys.H))
  120. characterPressed = "H";
  121.  
  122. if (keyboard.IsKeyDown(Keys.I))
  123. characterPressed = "I";
  124.  
  125. if (keyboard.IsKeyDown(Keys.J))
  126. characterPressed = "J";
  127.  
  128. if (keyboard.IsKeyDown(Keys.K))
  129. characterPressed = "K";
  130.  
  131. if (keyboard.IsKeyDown(Keys.L))
  132. characterPressed = "L";
  133.  
  134. if (keyboard.IsKeyDown(Keys.M))
  135. characterPressed = "M";
  136.  
  137. if (keyboard.IsKeyDown(Keys.N))
  138. characterPressed = "N";
  139.  
  140. if (keyboard.IsKeyDown(Keys.O))
  141. characterPressed = "O";
  142.  
  143. if (keyboard.IsKeyDown(Keys.P))
  144. characterPressed = "P";
  145.  
  146. if (keyboard.IsKeyDown(Keys.Q))
  147. characterPressed = "Q";
  148.  
  149. if (keyboard.IsKeyDown(Keys.R))
  150. characterPressed = "R";
  151.  
  152. if (keyboard.IsKeyDown(Keys.S))
  153. characterPressed = "S";
  154.  
  155. if (keyboard.IsKeyDown(Keys.T))
  156. characterPressed = "T";
  157.  
  158. if (keyboard.IsKeyDown(Keys.U))
  159. characterPressed = "U";
  160.  
  161. if (keyboard.IsKeyDown(Keys.V))
  162. characterPressed = "V";
  163.  
  164. if (keyboard.IsKeyDown(Keys.W))
  165. characterPressed = "W";
  166.  
  167. if (keyboard.IsKeyDown(Keys.X))
  168. characterPressed = "X";
  169.  
  170. if (keyboard.IsKeyDown(Keys.Y))
  171. characterPressed = "Y";
  172.  
  173. if (keyboard.IsKeyDown(Keys.Z))
  174. characterPressed = "Z";
  175.  
  176. if (characterPressed.Length != 0)
  177. Console.WriteLine(characterPressed);
  178.  
  179. if (characterPressed.Length != 0)
  180. {
  181. if (keyboard.IsKeyDown(Keys.LeftShift) || keyboard.IsKeyDown(Keys.RightShift))
  182. characterPressed = characterPressed.ToUpper();
  183. else
  184. characterPressed = characterPressed.ToLower();
  185.  
  186. Keys key = (Keys) Enum.Parse(typeof(Keys), characterPressed, true);
  187.  
  188. boxText = boxText.Insert(boxText.Length, characterPressed);
  189.  
  190. }
  191.  
  192.  
  193.  
  194. /*switch (pressedKeys[letterIndex])
  195.   {
  196.   case Keys.A:
  197.   case Keys.B:
  198.   case Keys.C:
  199.   case Keys.D:
  200.   case Keys.E:
  201.   case Keys.F:
  202.   case Keys.G:
  203.   case Keys.H:
  204.   case Keys.I:
  205.   case Keys.J:
  206.   case Keys.K:
  207.   case Keys.L:
  208.   case Keys.M:
  209.   case Keys.N:
  210.   case Keys.O:
  211.   case Keys.P:
  212.   case Keys.Q:
  213.   case Keys.R:
  214.   case Keys.S:
  215.   case Keys.T:
  216.   case Keys.U:
  217.   case Keys.V:
  218.   case Keys.W:
  219.   case Keys.X:
  220.   case Keys.Y:
  221.   case Keys.Z:
  222.   char [] appendCharacter = keyboard.GetPressedKeys()[0].ToString().ToCharArray();
  223.  
  224.   if (keyboard.IsKeyDown(Keys.LeftShift) || keyboard.IsKeyDown(Keys.RightShift))
  225.   appendCharacter[0] = Char.ToUpper(appendCharacter[0]);
  226.   else
  227.   appendCharacter[0] = Char.ToLower(appendCharacter[0]);
  228.  
  229.   boxText = boxText.Insert(boxText.Length, appendCharacter[0].ToString());
  230.   break;
  231.  
  232.   }*/
  233.  
  234. }
  235.  
  236. if (boxText.Length > maxCharacters)
  237. boxText = boxText.Remove(maxCharacters);
  238.  
  239. mouseDownLast = Mouse.GetState().LeftButton == ButtonState.Pressed;
  240.  
  241.  
  242.  
  243. }
  244.  
  245. public void draw(SpriteBatch spriteBatch)
  246. {
  247. LineDrawer.drawLine(new Vector2(position.X, position.Y), new Vector2(position.X + boxDim.X, position.Y), spriteBatch);
  248. LineDrawer.drawLine(new Vector2(position.X, position.Y), new Vector2(position.X, position.Y + boxDim.Y), spriteBatch);
  249. LineDrawer.drawLine(new Vector2(position.X, position.Y + boxDim.Y), new Vector2(position.X + boxDim.X, position.Y + boxDim.Y), spriteBatch);
  250. LineDrawer.drawLine(new Vector2(position.X + boxDim.X, position.Y), new Vector2(position.X + boxDim.X, position.Y + boxDim.Y), spriteBatch);
  251.  
  252. TextDrawer.setSize(10);
  253.  
  254. TextDrawer.drawText(labelText, new Vector2((position.X - TextDrawer.measureString(labelText).X) - 10, position.Y), false, spriteBatch);
  255.  
  256. TextDrawer.setSize((int)(boxDim.Y - 10));
  257.  
  258. TextDrawer.drawText(boxText, new Vector2(position.X + 3, position.Y + 3), false, spriteBatch);
  259.  
  260. float cursorX = position.X + 3 + TextDrawer.measureString(boxText).X + 2;
  261.  
  262. if (blink && selected)
  263. LineDrawer.drawLine(new Vector2(cursorX, position.Y + 3), new Vector2(cursorX, position.Y + 3 + TextDrawer.measureString(labelText).Y), spriteBatch);
  264. }
  265.  
  266.  
  267. }
  268.  
  269.  
  270. }
  271.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cs(5,17): error CS0234: The type or namespace name `Xna' does not exist in the namespace `Microsoft'. Are you missing an assembly reference?
prog.cs(6,17): error CS0234: The type or namespace name `Xna' does not exist in the namespace `Microsoft'. Are you missing an assembly reference?
prog.cs(7,17): error CS0234: The type or namespace name `Xna' does not exist in the namespace `Microsoft'. Are you missing an assembly reference?
prog.cs(8,17): error CS0234: The type or namespace name `Xna' does not exist in the namespace `Microsoft'. Are you missing an assembly reference?
prog.cs(9,17): error CS0234: The type or namespace name `Xna' does not exist in the namespace `Microsoft'. Are you missing an assembly reference?
prog.cs(10,17): error CS0234: The type or namespace name `Xna' does not exist in the namespace `Microsoft'. Are you missing an assembly reference?
prog.cs(11,17): error CS0234: The type or namespace name `Xna' does not exist in the namespace `Microsoft'. Are you missing an assembly reference?
prog.cs(19,9): error CS0246: The type or namespace name `Vector2' could not be found. Are you missing a using directive or an assembly reference?
prog.cs(33,14): error CS0246: The type or namespace name `Keys' could not be found. Are you missing a using directive or an assembly reference?
prog.cs(35,9): error CS0246: The type or namespace name `KeyboardState' could not be found. Are you missing a using directive or an assembly reference?
prog.cs(36,9): error CS0246: The type or namespace name `KeyboardState' could not be found. Are you missing a using directive or an assembly reference?
prog.cs(48,24): error CS0246: The type or namespace name `Vector2' could not be found. Are you missing a using directive or an assembly reference?
prog.cs(48,45): error CS0246: The type or namespace name `Vector2' could not be found. Are you missing a using directive or an assembly reference?
prog.cs(245,26): error CS0246: The type or namespace name `SpriteBatch' could not be found. Are you missing a using directive or an assembly reference?
Compilation failed: 14 error(s), 0 warnings
stdout
Standard output is empty