main.cs 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. function VirtualKeyboard::create(%this)
  2. {
  3. %this.resetState();
  4. }
  5. function VirtualKeyboard::destroy(%this)
  6. {
  7. }
  8. function VirtualKeyboard::resetState(%this)
  9. {
  10. %this.state = "toLower";
  11. %this.dock = "bottom";
  12. %this.targetGui ="";
  13. %this.textBox = "";
  14. }
  15. function VirtualKeyboard::push(%this, %targetGui, %textBox, %showClose)
  16. {
  17. Sandbox.add( TamlRead("./gui/keyboardGui.taml") );
  18. %textBox.setText("");
  19. %this.targetGui = %targetGui;
  20. %this.textBox = %textBox;
  21. Canvas.pushDialog(%targetGui);
  22. // resize to targetGui
  23. %targetExtent = %targetGui.Extent;
  24. KeyboardGui.resize(0, 0, %targetExtent._0, %targetExtent._1);
  25. %this.targetGui.addGuiControl(KeyboardSet);
  26. %textBox.setFirstResponder();
  27. if (%showClose)
  28. keyCloseBtn.setVisible(true);
  29. else
  30. keyCloseBtn.setVisible(false);
  31. %this.toLower();
  32. }
  33. function VirtualKeyboard::Pop(%this)
  34. {
  35. KeyboardSet.delete();
  36. KeyboardGui.delete();
  37. Canvas.popDialog(%this.targetGui);
  38. %this.resetState();
  39. }
  40. function VirtualKeyboard::toLower(%this)
  41. {
  42. %this.state = "toLower";
  43. toLower_NumberBtn.visible = false;
  44. toLowerBtn.visible = false;
  45. toSymbolBtn.visible = false;
  46. toNumber_symbolBtn.visible = false;
  47. toLower_UpperLockBtn.visible = false;
  48. toUpperLockBtn.visible =false;
  49. toUpperBtn.visible = true;
  50. toNumberBtn.visible = true;
  51. keyboardSet.Image = "VirtualKeyboard:keyboardAlphaLower";
  52. }
  53. function VirtualKeyboard::toUpper(%this)
  54. {
  55. %this.state = "toUpper";
  56. toUpperBtn.visible = false;
  57. toLower_NumberBtn.visible = false;
  58. toLowerBtn.visible = false;
  59. toSymbolBtn.visible = false;
  60. toNumber_symbolBtn.visible = false;
  61. toLower_UpperLockBtn.visible = false;
  62. toUpperLockBtn.visible =true;
  63. toNumberBtn.visible = true;
  64. keyboardSet.Image = "VirtualKeyboard:keyboardAlpha";
  65. }
  66. function VirtualKeyboard::toUpperLock(%this)
  67. {
  68. %this.state = "toUpperLock";
  69. toUpperBtn.visible = false;
  70. toUpperLockBtn.visible = false;
  71. toLowerBtn.visible = false;
  72. toLower_NumberBtn.visible = false;
  73. toSymbolBtn.visible = false;
  74. toNumber_symbolBtn.visible = false;
  75. toLower_UpperLockBtn.visible = true;
  76. toNumberBtn.visible = true;
  77. keyboardSet.Image = "VirtualKeyboard:keyboardAlpha";
  78. }
  79. function VirtualKeyboard::toNumber(%this)
  80. {
  81. %this.state = "toNumber";
  82. toNumberBtn.visible = false;
  83. toLowerBtn.visible = false;
  84. toUpperBtn.visible = false;
  85. toNumber_symbolBtn.visible = false;
  86. toLower_UpperLockBtn.visible = false;
  87. toUpperLockBtn.visible =false;
  88. toSymbolBtn.visible = true;
  89. toLower_NumberBtn.visible = true;
  90. keyboardSet.Image = "VirtualKeyboard:keyboardNumber";
  91. }
  92. function VirtualKeyboard::toSymbol(%this)
  93. {
  94. %this.state = "toSymbol";
  95. toSymbolBtn.visible = false;
  96. toUpperBtn.visible = false;
  97. toLowerBtn.visible = false;
  98. toNumberBtn.visible = false;
  99. toLower_UpperLockBtn.visible = false;
  100. toUpperLockBtn.visible =false;
  101. toNumber_symbolBtn.visible = true;
  102. toLower_NumberBtn.visible = true;
  103. keyboardSet.Image = "VirtualKeyboard:keyboardSymbol";
  104. }
  105. function VirtualKeyboard::KeyPress(%this, %letter, %number, %symbol)
  106. {
  107. if (%letter $= "close")
  108. %this.schedule(50, "Pop");
  109. else if (%letter $= "delete")
  110. %this.deleteCommand();
  111. else if (%letter $= "space")
  112. %this.insertChar(" ");
  113. else
  114. %this.insertChar(%letter, %number, %symbol);
  115. }
  116. function VirtualKeyboard::InsertChar(%this, %letter, %number, %symbol)
  117. {
  118. if (strlen(%this.textBox.getText()) >= %this.textBox.MaxLength)
  119. return;
  120. if (%letter $= " ")
  121. {
  122. %this.textBox.setText(%this.textBox.getText() @ " ");
  123. }
  124. else
  125. {
  126. if (%this.state $= "toLower")
  127. %this.textBox.setText(%this.textBox.getText() @ strlwr(%letter));
  128. else if (%this.state $= "toUpper")
  129. {
  130. %this.textBox.setText(%this.textBox.getText() @ strupr(%letter));
  131. %this.toLower();
  132. }
  133. else if (%this.state $= "toUpperLock")
  134. {
  135. %this.textBox.setText(%this.textBox.getText() @ strupr(%letter));
  136. }
  137. else if (%this.state $= "toNumber")
  138. {
  139. if (%letter $= "B")
  140. %number = "'";
  141. else if (%letter $= "K")
  142. %number = "&";
  143. %this.textBox.setText(%this.textBox.getText() @ %number);
  144. }
  145. else if (%this.state $= "toSymbol")
  146. {
  147. if (%letter $= "B")
  148. %symbol = "'";
  149. %this.textBox.setText(%this.textBox.getText() @ %symbol);
  150. }
  151. }
  152. }
  153. function VirtualKeyboard::DeleteCommand(%this)
  154. {
  155. %len = strlen(%this.textBox.getText());
  156. if (%len > 0)
  157. %this.textBox.setText(getSubStr(%this.textBox.getText(), 0, %len - 1));
  158. }
  159. if(!isObject(GuiKeyboardProfile)) new GuiControlProfile (GuiKeyboardProfile)
  160. {
  161. tab = false;
  162. canKeyFocus = false;
  163. hasBitmapArray = false;
  164. mouseOverSelected = false;
  165. // fill color
  166. fillColor = "211 211 211 255";
  167. fillColorHL = "244 244 244 255";
  168. fillColorSL = "244 244 244 255";
  169. fillColorNA = "244 244 244 255";
  170. // border color
  171. border = 0;
  172. borderColor = "100 100 100 255";
  173. borderColorHL = "128 128 128 255";
  174. borderColorSL = "128 128 128 255";
  175. borderColorNA = "64 64 64 255";
  176. // font
  177. fontType = $platformFontType;
  178. fontSize = $platformFontSize;
  179. fontColor = "0 0 0";
  180. fontColorHL = "32 100 100";
  181. fontColorSL= "10 10 10";
  182. fontColorNA = "0 0 0";
  183. // used by guiTextControl
  184. align = "left";
  185. returnTab = false;
  186. numbersOnly = false;
  187. cursorColor = "0 0 0 255";
  188. // sounds
  189. soundButtonDown = "VirtualKeyboard:keypress";
  190. //soundButtonOver = "Sandbox:mouseOver";
  191. };