fork download
  1. using System;
  2. using System.Collections.Generic;
  3. using Sce.PlayStation.Core;
  4. using Sce.PlayStation.Core.Imaging;
  5. using Sce.PlayStation.Core.Environment;
  6. using Sce.PlayStation.HighLevel.UI;
  7. using System.Linq;
  8. using Sce.PlayStation.Core.Graphics;
  9. using System.Diagnostics;
  10.  
  11. using System.IO;
  12. using System.Net;
  13. using Sce.PlayStation.Core.Input;
  14.  
  15. namespace Test
  16. {
  17. public class AppMain
  18. {
  19. private static GraphicsContext graphics;
  20.  
  21. public static void Main (string[] args)
  22. {
  23. Initialize ();
  24.  
  25. while (true) {
  26. SystemEvents.CheckEvents ();
  27. Update ();
  28. Render ();
  29. }
  30. }
  31.  
  32. public static void Initialize ()
  33. {
  34. // Set up the graphics system
  35. graphics = new GraphicsContext();
  36.  
  37. UISystem.Initialize(graphics);
  38.  
  39. var scene = new TestScene();
  40.  
  41. UISystem.SetScene(scene);
  42. }
  43.  
  44. public static void Update ()
  45. {
  46. // Query gamepad for current state
  47. var gamePadData = GamePad.GetData (0);
  48.  
  49. List<TouchData> touchDataList = Touch.GetData (0);
  50.  
  51. UISystem.Update(touchDataList);
  52. }
  53.  
  54. public static void Render ()
  55. {
  56. // Clear the screen
  57. graphics.SetClearColor (0.0f, 0.0f, 0.0f, 0.0f);
  58. graphics.Clear ();
  59.  
  60. UISystem.Render();
  61.  
  62. // Present the screen
  63. graphics.SwapBuffers ();
  64. }
  65. }
  66.  
  67. public enum ConnectState
  68. {
  69. None,
  70. Ready,
  71. Connect,
  72. Success,
  73. Failed
  74. }
  75.  
  76. class MyLabel : Label
  77. {
  78. private const int maxReadSize = 1024;
  79. private static int totalReadSize;
  80. private static MemoryStream readStream;
  81. private static byte[] readBuffer;
  82. private static string statusCode;
  83. private static long contentLength;
  84.  
  85. public MyLabel ()
  86. {
  87. this.TouchEventReceived += (sender, e) => Touching (e.TouchEvents);
  88. this.SetPosition (100, 100);
  89. this.SetSize (200, 200);
  90. this.BackgroundColor = new UIColor (1, 1, 1, 1);
  91. this.TextColor = new UIColor (0, 0, 0, 1);
  92. this.Text = "Start";
  93. }
  94.  
  95. static ConnectState connectState;
  96.  
  97. void Touching (TouchEventCollection touches)
  98. {
  99.  
  100. if (connectState == ConnectState.None && touches.PrimaryTouchEvent.Type == TouchEventType.Down) {
  101. connectState = ConnectState.Ready;
  102. this.Text = "Ready";
  103. }
  104. }
  105.  
  106. protected override void OnUpdate (float elapsedTime)
  107. {
  108. switch (connectState) {
  109.  
  110. case ConnectState.Ready:
  111. //connectHttpTest ("http://w...content-available-to-author-only...o.jp/index_e.html");
  112. connectHttpTest ("http://h...content-available-to-author-only...h.net/news4vip/subback.html");
  113.  
  114.  
  115. break;
  116. case ConnectState.Success:
  117.  
  118. this.Text = "Success";
  119.  
  120. if (readStream != null) {
  121. //httpText = createTextSprite(readStream.ToArray(), statusCode, contentLength);
  122.  
  123. readStream.Dispose ();
  124. readStream = null;
  125. readBuffer = null;
  126. }
  127.  
  128. connectState = ConnectState.None;
  129. break;
  130. case ConnectState.Failed:
  131. //httpText = createTextSprite(null, statusCode, contentLength);
  132. this.Text += " Failed";
  133. connectState = ConnectState.None;
  134. break;
  135. }
  136. }
  137.  
  138.  
  139. /// Http connection test
  140. bool connectHttpTest (string url)
  141. {
  142. statusCode = "Unknown";
  143. contentLength = 0;
  144.  
  145. try {
  146. var webRequest = HttpWebRequest.Create (url);
  147. // If you use web proxy, uncomment this and set appropriate address.
  148. //webRequest.Proxy = new System.Net.WebProxy("http://your_proxy.com:10080");
  149. webRequest.BeginGetResponse (new AsyncCallback (requestCallBack), webRequest);
  150. connectState = ConnectState.Connect;
  151. } catch (Exception e) {
  152. this.Text = e.GetType().Name + " " + e.Message;
  153. connectState = ConnectState.Failed;
  154. return false;
  155. }
  156.  
  157. return true;
  158. }
  159.  
  160. void requestCallBack (IAsyncResult ar)
  161. {
  162. try {
  163. var webRequest = (HttpWebRequest)ar.AsyncState;
  164. var webResponse = (HttpWebResponse)webRequest.EndGetResponse (ar);
  165.  
  166. statusCode = webResponse.StatusCode.ToString ();
  167. contentLength = webResponse.ContentLength;
  168. readBuffer = new byte[1024];
  169. readStream = new MemoryStream ();
  170. totalReadSize = 0;
  171.  
  172. var stream = webResponse.GetResponseStream ();
  173. stream.BeginRead (readBuffer, 0, readBuffer.Length, new AsyncCallback (readCallBack), stream);
  174. } catch (Exception e) {
  175. this.Text = e.GetType().Name + " " + e.Message;
  176. connectState = ConnectState.Failed;
  177. }
  178. }
  179.  
  180. void readCallBack (IAsyncResult ar)
  181. {
  182. try {
  183. var stream = (Stream)ar.AsyncState;
  184. int readSize = stream.EndRead (ar);
  185.  
  186. if (readSize > 0) {
  187. totalReadSize += readSize;
  188. readStream.Write (readBuffer, 0, readSize);
  189. }
  190.  
  191. if (readSize <= 0) {
  192. stream.Close ();
  193. connectState = ConnectState.Success;
  194. } else {
  195. stream.BeginRead (readBuffer, 0, readBuffer.Length, new AsyncCallback (readCallBack), stream);
  196. }
  197. } catch (Exception e) {
  198. this.Text = e.GetType().Name + " " + e.Message;
  199. connectState = ConnectState.Failed;
  200. }
  201. }
  202. }
  203.  
  204. public class TestScene : Scene
  205. {
  206. public TestScene ()
  207. {
  208. InitializeWidget (LayoutOrientation.Horizontal);
  209. }
  210.  
  211. private void InitializeWidget (LayoutOrientation orientation)
  212. {
  213. var l = new MyLabel ();
  214. this.RootWidget.AddChildLast (l);
  215.  
  216. Button b = new Button();
  217. b.SetSize(100,100);
  218. b.SetPosition(400,400);
  219. b.Text = "ボタン";
  220. this.RootWidget.AddChildLast(b);
  221. }
  222. }
  223. }
  224.  
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty