protected override void Initialise() { //draw targets usually need a camera. Camera3D camera = new Camera3D(); //look at the sphere, which will be at 0,0,0 camera.LookAt(Vector3.Zero, new Vector3(0, 0, 4), Vector3.UnitY); //create the draw target. drawToScreen = new DrawTargetScreen(this, camera); drawToScreen.ClearBuffer.ClearColour = Color.CornflowerBlue; //create the sphere SphereDrawer sphere = new SphereDrawer(Vector3.Zero); //before adding the sphere, add a rect over half the background to show blending is active //element covers half the screen SolidColourElement element = new SolidColourElement(Color.DarkGray, new Vector2(0.5f, 1), true); //element is added before the sphere (so it draws first) drawToScreen.Add(element); //add it to be drawn to the screen drawToScreen.Add(sphere); }
public SolidColourElementState(SolidColourElementState existing, SolidColourElement other, RenderContext context) { props = other.Props; brush = existing?.brush ?? new SharpDX.Direct2D1.SolidColorBrush(Renderer.AssertRendererType(context.Renderer).d2dTarget, new SharpDX.Mathematics.Interop.RawColor4 { R = other.Props.Colour.R, G = other.Props.Colour.G, B = other.Props.Colour.B, A = other.Props.Colour.A }); context.Disposables.Add(brush); boundingBox = other.Props.Location != null?other.Props.Location(context.Bounds) : context.Bounds; }
public RenderConfigEditor(ContentRegister content) { //setup the text elements this.stateText = new List <TextElement>(); this.visibleElementGap = new List <bool>(); #if XBOX360 this.helpText = new TextElement("Use 'A' and the DPad to interact with the menu"); #else this.helpText = new TextElement("Use the Arrow Keys and 'Enter' to interact with the menu"); #endif this.helpText.HorizontalAlignment = HorizontalAlignment.Left; this.helpText.VerticalAlignment = VerticalAlignment.Bottom; this.helpText.Colour = Color.Black; this.backgroundContainer = new SolidColourElement(new Color(0, 0, 0, 200), new Vector2(0, 0)); this.backgroundContainer.AlphaBlendState = Xen.Graphics.State.AlphaBlendState.Alpha; foreach (string name in ConfigProperties.Keys) { //create the text TextElement text = new TextElement(); //if it's a ediable value, then put a '[X]' infront if (ConfigProperties[name].CanRead) { text.Text.SetText("[ ] " + name); } else { text.Text.SetText(name); } text.VerticalAlignment = VerticalAlignment.Bottom; this.stateText.Add(text); bool gap = false; if (ConfigProperties[name].GetCustomAttributes(typeof(RenderConfiguration.GapAttribute), false).Length > 0) { gap = true; } this.visibleElementGap.Add(gap); } //select top instance this.editSelection = this.stateText.Count - 1; //sizes of the elements are setup in LoadContent() content.Add(this); }
public void Initalise(IGameStateManager stateManager) { this.stateManager = stateManager; //Put up a beautiful and intricate loading bar (a green box on top of a black box) this.loadingBar = new SolidColourElement(Color.Lime, new Vector2(0, 0.15f), true); this.loadingBackground = new SolidColourElement(Color.Black, new Vector2(0.52f, 0.17f), true); this.loadingBar.Position = new Vector2(0.25f, 0.35f); this.loadingBackground.Position = new Vector2(0.24f, 0.34f); //tell the next state (in this case, it'll be the game) to begin loading this.stateToLoad.BeginLoad(); }
protected override void Initialise() { //DrawStatisticsDisplay requires that resource tracking is enabled Resource.EnableResourceTracking(); //Xen.Ex provides a very useful Camera3D called 'FirstPersonControlledCamera3D'. //This camera uses player input to act as a simple first-person style flythrough camera Xen.Ex.Camera.FirstPersonControlledCamera3D camera = null; //it uses player input, so the UpdateManager must be passed in camera = new Xen.Ex.Camera.FirstPersonControlledCamera3D(this.UpdateManager); //in this case, we want the z-axis to be the up/down axis (otherwise it's the Y-axis) camera.ZAxisUp = true; //also it's default is a bit too fast moving camera.MovementSensitivity *= 0.1f; camera.LookAt(new Vector3(1, 0, 0), new Vector3(), new Vector3(0, 0, 1)); this.camera = camera; //create the draw target. drawToScreen = new DrawTargetScreen(this, camera); //create a large number of actor instance from tutorial 10.. for (int n = 0; n <= 16; n++) { //create in a half circle float angle = (n / 16.0f) * MathHelper.Pi; Vector3 position = new Vector3((float)Math.Sin(angle), (float)Math.Cos(angle), 0); //not too close together position *= 10; drawToScreen.Add(new Tutorial_10.Actor(this.Content, position)); } //this element will display the camera position positionDisplay = new TextElement(); //TextElement (unlike other Elements) defaults to Top Left alignment //So, in order to bring it closer to the centre of the screen (due to potential overscan) //it's position needs to be set 'right' and 'down' from 'top left' //(this is just an example, see XNA docs for correct overscan compensation behaviour) positionDisplay.Position = new Vector2(40, -40); //offset from top left corner alignment //add it to the screen drawToScreen.Add(positionDisplay); Vector2 sizeInPixels = new Vector2(400, 200); //create the main block of yellow text this.yellowElement = new TextElementRect(sizeInPixels); this.yellowElement.Colour = Color.Yellow; //first line of text... this will have a flashing 2D element embedded string embeddedText = @"This is a text box with a large amount of custom text! It also includes an embedded 2D element: , which is a 16x16 SolidColourElement"; uint insertAtIndex = 96; // Hard coded to insert a 2D element at character index 96 which is about here: ^ //add a bunch of text... this.yellowElement.Text.AppendLine(embeddedText); this.yellowElement.Text.AppendLine(); this.yellowElement.Text.AppendLine(@"This class is:"); this.yellowElement.Text.AppendLine(this.GetType().FullName); this.yellowElement.Text.AppendLine(@"It is located in assembly:"); this.yellowElement.Text.AppendLine(this.GetType().Assembly.FullName); this.yellowElement.Text.AppendLine(); //add an embedded 2D element within the text //create it.. this.embeddedElement = new SolidColourElement(Color.Red, new Vector2(16, 16)); // quite small this.embeddedElement.AlphaBlendState = AlphaBlendState.Alpha; //add it. this.yellowElement.AddInline(this.embeddedElement, insertAtIndex); #if XBOX360 this.yellowElement.Text.AppendLine(@"Press and hold both thumbsticks to show the debug overlay"); #else this.yellowElement.Text.AppendLine(@"Press F12 to show the debug overlay"); #endif //align the element rectangle to the bottom centre of the screen this.yellowElement.VerticalAlignment = VerticalAlignment.Bottom; this.yellowElement.HorizontalAlignment = HorizontalAlignment.Centre; //centre align the text this.yellowElement.TextHorizontalAlignment = TextHorizontalAlignment.Centre; //centre the text in the middle of the 400x200 area of the element rectangle this.yellowElement.TextVerticalAlignment = VerticalAlignment.Centre; //add it to the screen drawToScreen.Add(yellowElement); //create the statistics display //this class will query the DrawState for the previous frames DrawStatistics structure. //this structure provides a large number of statistics for the drawn frame. //The DrawStatisticsDisplay displays some of the more important statistics. It will also //display thread activity on the xbox. //DrawStatistics are only available in DEBUG xen builds //They can be accessed at runtime with DrawState GetPreviousFrameStatistics() //at runtime, pressing 'F12' will toggle the overlay (or holding both thumbsticks on x360) this.statisticsOverlay = new Xen.Ex.Graphics2D.Statistics.DrawStatisticsDisplay(this.UpdateManager); //As of xen 1.5, by default the DrawStatisticsDisplay displays a significantly reduced number of graphs. //To display the full set of graphs (which generally takes up the entire screen), set the following //property to 'true': //this.statisticsOverlay.DisplayFullGraphList = true; //then add it to the screen drawToScreen.Add(statisticsOverlay); }
public ISolidColourElementState UpdateSolidColourElementState(IElementState existing, SolidColourElement b2, RenderContext context) { return(new SolidColourElementState(existing as SolidColourElementState, b2, context)); }