PlayStation Mobile Studio PlayStation(R)Mobile SDK 1.21.01 |
■Playstation Mobile UI Toolkit( Label と PopupList ) | Prev Top Next |
関連ページ:なし |
今回のサンプルでは Label と PopupList( 一般的には Combo box )を使用します。
他にも面白そうな機能があれば紹介するかも。
UI Toolkit では Sce.PlayStation.HighLevel.UI を使用します。ソリューションエクスプローラーの「参照」上で右クリックし、
「参照アセンブリの編集」をクリックして、Sce.PlayStation.HighLevel.UI をチェックしてください。
Common.cs | 共通クラスとか |
Sprite.vcg | バーテックスシェーダーのcgファイル |
Sprite.fcg | フラグメントシェーダーのcgファイル |
Sprite.cs | スプライトシェーダークラス |
SpriteMesh.cs | スプライトメッシュクラス |
DebugFont.cs | デバッグフォントクラス |
AppMain.cs | main関数があるソースファイル |
using System; using Sce.PlayStation.Core.Environment; using Sce.PlayStation.Core.Graphics; using System.Collections.Generic; using Sce.PlayStation.Core.Input; using Sce.PlayStation.HighLevel.UI; using Sce.PlayStation.Core.Imaging; namespace PSM_Samples { public class AppMain { private static string[] screenSize = { "960:544", "800:480", "1280:800", }; private static GraphicsContext graphics; private static DebugFont debugFont; private static bool loop = true; public static void Main (string[] args) { Initialize(0); while (loop) { SystemEvents.CheckEvents (); Update (); Render (); } Destroy(); } private static int GetWidth( string screenSize ) { string[] s = screenSize.Split(':'); return int.Parse( s[0] ); } private static int GetHeight( string screenSize ) { string[] s = screenSize.Split(':'); return int.Parse( s[1] ); } // ポップアップリストで選択項目が変更されたらイベント発生 private static void PopupList_SelectionChanged( object sender, PopupSelectionChangedEventArgs args ) { // リソースをすべて解放 Destroy(); // 初期化 Initialize( args.NewIndex ); } // 初期化 public static void Initialize( int selectedIndex ) { if( screenSize.Length <= selectedIndex || 0 > selectedIndex ) selectedIndex = 0; int Width = GetWidth( screenSize[selectedIndex] ); int Height = GetHeight( screenSize[selectedIndex] ); // GraphicsContext 初期化 graphics = new GraphicsContext( Width, Height, PixelFormat.Rgba, PixelFormat.Depth16, MultiSampleMode.None ); // UI Toolkit 初期化 UISystem.Initialize(graphics); // scene 作成 Scene scene = new Scene(); // ラベル Label label1 = new Label(); label1.Name = "ScreenSizeTitle"; label1.SetSize(180, 30); label1.Font = new UIFont(FontAlias.System, 20, FontStyle.Regular); label1.TextColor = new UIColor(255, 255, 255, 255); label1.Text = "スクリーンサイズ:"; // コンボボックス PopupList plist = new PopupList(); plist.Name = "ScreenSize"; plist.SetSize(200, 30); plist.ListTitleFont = new UIFont(FontAlias.System, 20, FontStyle.Bold); plist.ListItemFont = new UIFont(FontAlias.System, 20, FontStyle.Regular); plist.ListTitle = "スクリーンサイズ"; plist.ListItems.Clear(); plist.ListItems.AddRange( screenSize ); plist.SelectedIndex = selectedIndex; // チェンジされて発生させるイベントを設定 plist.SelectionChanged += new EventHandler<PopupSelectionChangedEventArgs>( PopupList_SelectionChanged ); // 表示位置をスクリーンの右上に移動 label1.SetPosition(Width - label1.Width - plist.Width, 0); plist.SetPosition(label1.X + label1.Width, label1.Y); // Sceneにウィジェットを追加 scene.RootWidget.AddChildLast(label1); scene.RootWidget.AddChildLast(plist); // scene を追加 UISystem.SetScene(scene, null); // デバッグフォントの作成 debugFont = new DebugFont(); } public static void Destroy() { UISystem.Terminate(); debugFont.Dispose(); graphics.Dispose(); } // フレーム更新 public static void Update () { List<TouchData> touchDataList = Touch.GetData (0); // マウスクリックでイベント発生させられるようにする UISystem.Update(touchDataList); } // レンダリング public static void Render() { // クリア graphics.SetClearColor (0.2f, 0.2f, 1, 1 ); graphics.SetClearDepth( 1 ); graphics.Clear (); // デバッグ情報出力 debugFont.Draw( graphics, graphics.Screen.Width.ToString() + ":" + graphics.Screen.Height.ToString() ); // UI Toolkit の描画 UISystem.Render (); // スワップ graphics.SwapBuffers(); } } }