static void SetupUI() { Font font = Font.Load("assets/tex/font.png", 10, 10); Texture panelTexture = Texture.LoadFromFile("assets/tex/panel.png"); ScalablePanel toolbox = new ScalablePanel { Pivot = new Vector2(0, 1), Position = new Vector2(0, 1), Depth = 10 }; toolbox.OnUpdate += ToolboxUpdate; toolbox.Material.Texture = panelTexture; void ToolboxUpdate(object sender, EventArgs e) { ScalablePanel _sender = (ScalablePanel)sender; Vector2 toolboxSize = _sender.ScreenToPixel(new Vector2(1, 0)); _sender.Size = new Vector2(toolboxSize.X, 6); } UI.AddElement(toolbox); Button spawnCubeButton = new Button(panelTexture, font); spawnCubeButton.Body.Parent = toolbox; spawnCubeButton.Body.Pivot = -Vector2.One; spawnCubeButton.Body.Position = -Vector2.One; spawnCubeButton.Body.PixelTranslation = Vector2.One * 8; spawnCubeButton.Body.AllowClickRepetition = true; spawnCubeButton.Body.OnClick += SpawnCube; }
public override void OnAttach() { UI.InitUI(Application.Get().Window.Width, Application.Get().Window.Height); Gl.Enable(EnableCap.DepthTest); Gl.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha); UI.Visible = true; var helloWorld = new Text(Text.FontSize._24pt, "Hello WOrld", BMFont.Justification.Center); helloWorld.Name = "txt1"; helloWorld.RelativeTo = Corner.Center; Text coloredText = new Text(Text.FontSize._24pt, "using C#", BMFont.Justification.Center); coloredText.Position = new Point(0, -30); coloredText.Color = new Vector3(0.2f, 0.3f, 1f); coloredText.RelativeTo = Corner.Center; UI.AddElement(helloWorld); UI.AddElement(coloredText); }
public override void Shown() { try { root = new RootDisposable(); VideoTypes videoType; //video = Video.Init(VideoTypes.D3D11 | VideoTypes.D3D9 | VideoTypes.OpenGL | VideoTypes.XNA | VideoTypes.Vita, out videoType, root, this, true); video = Video.Init(VideoTypes.D3D11, out videoType, root, this, true); DiffuseTextureMaterial.Init(video, "Data/", video.FileTag, ShaderVersions.Max, null); DiffuseTextureMaterial.ApplyInstanceConstantsCallback = applyInstanceData; var materialTypes = new Dictionary<string,Type>(); materialTypes.Add("Material", typeof(DiffuseTextureMaterial)); materialTypes.Add("Material.001", typeof(DiffuseTextureMaterial)); var materialFieldTypes = new List<MaterialFieldBinder>(); materialFieldTypes.Add(new MaterialFieldBinder("Material", "Roxy_dds", "Diffuse")); materialFieldTypes.Add(new MaterialFieldBinder("Material.001", "Wolf_dds", "Diffuse")); var extOverrides = new Dictionary<string,string>(); #if SILVERLIGHT || VITA || (LINUX && ARM) extOverrides.Add(".dds", ".png"); #endif #if iOS extOverrides.Add(".dds", ".pvr"); #endif #if ANDROID if (((Reign.Video.OpenGL.Video)video).Caps.TextureCompression_ATC) extOverrides.Add(".dds", ".atc"); else if (((Reign.Video.OpenGL.Video)video).Caps.TextureCompression_PVR) extOverrides.Add(".dds", ".pvr"); #endif var emptyBinders = new List<MaterialFieldBinder>(); model = new Model(video, "Data/boxes.rm", "Data/", materialTypes, emptyBinders, emptyBinders, emptyBinders, emptyBinders, materialFieldTypes, extOverrides, 0, null); var frame = FrameSize; viewPort = ViewPortAPI.New(video, 0, 0, frame.Width, frame.Height); camera = new Camera(viewPort, new Vector3(5, 5, 5), new Vector3(), new Vector3(5, 5+1, 5), 1, 50, MathUtilities.DegToRad(45)); rasterizerState = RasterizerStateAPI.New(video, RasterizerStateDescAPI.New(RasterizerStateTypes.Solid_CullCW)); depthStencilState = DepthStencilStateAPI.New(video, DepthStencilStateDescAPI.New(DepthStencilStateTypes.ReadWrite_Less)); blendState = BlendStateAPI.New(video, BlendStateDescAPI.New(BlendStateTypes.None)); samplerState = SamplerStateAPI.New(video, SamplerStateDescAPI.New(SamplerStateTypes.Linear_Wrap)); InputTypes inputType; input = Input.Init(InputTypes.WinForms, out inputType, root, this); mouse = MouseAPI.New(input); keyboard = KeyboardAPI.New(input); // ----------------------- FontMaterial.Init(video, "Data/", video.FileTag, ShaderVersions.Max, null); var fontTexture = Texture2DAPI.New(video, "Data/WhiteFont.png", null); font = new Font(video, FontMaterial.Shader, fontTexture, "Data/WhiteFont.font", null); UISolidColorMaterial.Init(video, "Data/", video.FileTag, ShaderVersions.Max, null); UISolidTextureMaterial.Init(video, "Data/", video.FileTag, ShaderVersions.Max, null); UISolidTexture2Material.Init(video, "Data/", video.FileTag, ShaderVersions.Max, null); UISolidTexture3Material.Init(video, "Data/", video.FileTag, ShaderVersions.Max, null); ui = new UI(root, video, UISolidColorMaterial.Shader, UISolidTextureMaterial.Shader, UISolidTexture2Material.Shader, UISolidTexture3Material.Shader, font, 16, mouse); button = new Reign.UI.Button(ui, "Hello World!", 10, 10, 128, 32); ui.AddElement(button); var idleTexture = Texture2DAPI.New(video, "Data/PlayIdle.png", null); var rolloverTexture = Texture2DAPI.New(video, "Data/PlayRollover.png", null); var pressedTexture = Texture2DAPI.New(video, "Data/PlayPressed.png", null); buttonImage = new ButtonImage(ui, idleTexture, rolloverTexture, pressedTexture, 400, 10, 64, 64); ui.AddElement(buttonImage); // ----------------------- loaded = true; } catch (Exception e) { dispose(); Message.Show("Error", e.Message); } }