public static IVisualElementRenderer CreateRenderer(VisualElement element) { if (element == null) { throw new ArgumentNullException(nameof(element)); } IVisualElementRenderer renderer = null; // temporary hack to fix the following issues // https://github.com/xamarin/Xamarin.Forms/issues/13261 // https://github.com/xamarin/Xamarin.Forms/issues/12484 if (element is RadioButton tv && tv.ResolveControlTemplate() != null) { renderer = new DefaultRenderer(); } if (renderer == null) { renderer = Registrar.Registered.GetHandlerForObject <IVisualElementRenderer>(element) ?? new DefaultRenderer(); } renderer.SetElement(element); return(renderer); }
public static IVisualElementRenderer CreateRenderer(VisualElement element) { IVisualElementRenderer renderer = null; // temporary hack to fix the following issues // https://github.com/xamarin/Xamarin.Forms/issues/13261 // https://github.com/xamarin/Xamarin.Forms/issues/12484 if (element is RadioButton tv && tv.ResolveControlTemplate() != null) { renderer = new DefaultRenderer(); } // This code is duplicated across all platforms currently // So if any changes are made here please make sure to apply them to other platform.cs files if (renderer == null) { IViewHandler handler = null; //TODO: Handle this with AppBuilderHost try { handler = Forms.ActivationState.Context.Handlers.GetHandler(element.GetType()); } catch { // TODO define better catch response or define if this is needed? } if (handler == null) { renderer = Microsoft.Maui.Controls.Internals.Registrar.Registered.GetHandlerForObject <IVisualElementRenderer>(element) ?? new DefaultRenderer(); } // This means the only thing registered is the RendererToHandlerShim // Which is only used when you are running a .NET MAUI app // This indicates that the user hasn't registered a specific handler for this given type else if (handler is RendererToHandlerShim shim) { renderer = shim.VisualElementRenderer; if (renderer == null) { renderer = Microsoft.Maui.Controls.Internals.Registrar.Registered.GetHandlerForObject <IVisualElementRenderer>(element) ?? new DefaultRenderer(); } } else if (handler is IVisualElementRenderer ver) { renderer = ver; } else if (handler is INativeViewHandler vh) { renderer = new HandlerToRendererShim(vh); } } renderer.SetElement(element); return(renderer); }
/// <summary> /// Render the html and adds it to the cache. /// </summary> /// <param name="helper">The helper.</param> /// <param name="partialRequest">The partial request.</param> /// <param name="content">The content.</param> /// <param name="templateModel">The template model.</param> /// <param name="settings">The settings.</param> /// <param name="cacheKey">The cache key.</param> protected virtual void RenderAndAddToCache(HtmlHelper helper, PartialRequest partialRequest, IContent content, TemplateModel templateModel, ICacheableSettings settings, string cacheKey) { using (var cacheWriter = new StringWriter()) { var currentWriter = helper.ViewContext.Writer; helper.ViewContext.Writer = cacheWriter; DefaultRenderer.Render(helper, partialRequest, content, templateModel); var html = cacheWriter.ToString(); currentWriter.Write(html); helper.ViewContext.Writer = currentWriter; if (helper.ViewContext.HttpContext.Error == null) { InsertToCache(html); } } void InsertToCache(string html) { if (settings.MaxTimeInCache == TimeSpan.Zero) { Cache.Insert(cacheKey, html, new CacheEvictionPolicy(null, MasterCacheKeys)); } else { Cache.Insert(cacheKey, html, new CacheEvictionPolicy(settings.MaxTimeInCache, CacheTimeoutType.Absolute, null, MasterCacheKeys)); } } }
protected void initializeGraphics() { renderer = new DefaultRenderer(100, this.camera); renderer.shouldDebugRender = true; this.addRenderer(renderer); this.getRenderer <DefaultRenderer>().render(this); setDesignResolution(512, 256, Scene.SceneResolutionPolicy.ShowAllPixelPerfect); Screen.setSize(512 * 3, 256 * 3); }
protected void Attach() { if (Renderer == null) { return; } //Init objects here renderer = new DefaultRenderer(Renderer); }
public FireBullet(Vector2 initialPosition, Vector2 direction, float range, Vector2 velocity, GameObject parent, Texture2D texture, float effectValue) { this.parent = parent; this.direction = direction; this.range = range; this.initialPosition = initialPosition; this.velocity = velocity; this.effectValue = effectValue; Renderer = new DefaultRenderer(this, texture); }
static public void Setup(OperatorPartContext context, DefaultRenderer renderer) { context.D3DDevice.ImmediateContext.OutputMerger.SetTargets(context.DepthStencilView, context.RenderTargetView); context.D3DDevice.ImmediateContext.Rasterizer.SetViewport(context.Viewport); if (context.DepthStencilView != null) { context.D3DDevice.ImmediateContext.ClearDepthStencilView(context.DepthStencilView, DepthStencilClearFlags.Depth | DepthStencilClearFlags.Stencil, 1.0f, 0); } context.D3DDevice.ImmediateContext.ClearRenderTargetView(context.RenderTargetView, new SharpDX.Color4(0.0f, 0.0f, 0.0f, 0.0f)); context.D3DDevice.ImmediateContext.InputAssembler.InputLayout = context.InputLayout; }
protected DefaultRenderer BuildCategoryRenderer(int[] colors) { DefaultRenderer renderer = new DefaultRenderer(); renderer.LabelsTextSize = 15; renderer.LegendTextSize = 15; renderer.SetMargins(new[] { 20, 30, 15, 0 }); foreach (int color in colors) { SimpleSeriesRenderer r = new SimpleSeriesRenderer(); r.Color = color; renderer.AddSeriesRenderer(r); } return(renderer); }
/// <summary> /// Builds a category renderer to use the provided colors. /// </summary> /// <param name="colors"> the colors </param> /// <returns> the category renderer </returns> protected internal virtual DefaultRenderer buildCategoryRenderer(int[] colors) { DefaultRenderer renderer = new DefaultRenderer(); renderer.LabelsTextSize = 15; renderer.LegendTextSize = 15; renderer.Margins = new int[] { 20, 30, 15, 0 }; foreach (int color in colors) { SimpleSeriesRenderer r = new SimpleSeriesRenderer(); r.Color = color; renderer.addSeriesRenderer(r); } return(renderer); }
public static IVisualElementRenderer CreateRenderer(VisualElement element) { IVisualElementRenderer renderer = null; if (element is TemplatedView tv && tv.ResolveControlTemplate() != null) { renderer = new DefaultRenderer(); } if (renderer == null) { renderer = Internals.Registrar.Registered.GetHandlerForObject <IVisualElementRenderer>(element) ?? new DefaultRenderer(); } renderer.SetElement(element); return(renderer); }
public static DefaultRenderer BuildCategoryRenderer(int[] colors) { DefaultRenderer renderer = new DefaultRenderer(); renderer.LabelsTextSize = 15; renderer.LegendTextSize = 15; renderer.ShowLabels = false; renderer.ShowLegend = false; renderer.Scale = (float)1.44; renderer.SetMargins(new int[] { 2, 30, 15, 0 }); foreach (int color in colors) { SimpleSeriesRenderer r = new SimpleSeriesRenderer(); r.Color = color; renderer.AddSeriesRenderer(r); } return(renderer); }
/// <summary> /// Executes the chart demo. /// </summary> /// <param name="context"> the context </param> /// <returns> the built intent </returns> public override Intent execute(Context context) { IList <double[]> values = new List <double[]>(); values.Add(new double[] { 12, 14, 11, 10, 19 }); values.Add(new double[] { 10, 9, 14, 20, 11 }); IList <string[]> titles = new List <string[]>(); titles.Add(new string[] { "P1", "P2", "P3", "P4", "P5" }); titles.Add(new string[] { "Project1", "Project2", "Project3", "Project4", "Project5" }); int[] colors = new int[] { Color.BLUE, Color.GREEN, Color.MAGENTA, Color.YELLOW, Color.CYAN }; DefaultRenderer renderer = buildCategoryRenderer(colors); renderer.ApplyBackgroundColor = true; renderer.BackgroundColor = Color.rgb(222, 222, 200); renderer.LabelsColor = Color.GRAY; return(ChartFactory.getDoughnutChartIntent(context, buildMultipleCategoryDataset("Project budget", titles, values), renderer, "Doughnut chart demo")); }
public override Android.Content.Intent Execute(Android.Content.Context context) { IList <double[]> values = new List <double[]>(); values.Add(new double[] { 12, 14, 11, 10, 19 }); values.Add(new double[] { 10, 9, 14, 20, 11 }); IList <string[]> titles = new List <string[]>(); titles.Add(new String[] { "P1", "P2", "P3", "P4", "P5" }); titles.Add(new String[] { "Project1", "Project2", "Project3", "Project4", "Project5" }); int[] colors = new int[] { Color.Blue, Color.Green, Color.Magenta, Color.Yellow, Color.Cyan }; DefaultRenderer renderer = BuildCategoryRenderer(colors); renderer.ApplyBackgroundColor = true; renderer.BackgroundColor = Color.Rgb(222, 222, 200); renderer.LabelsColor = Color.Gray; return(ChartFactory.GetDoughnutChartIntent(context, BuildMultipleCategoryDataset("Project budget", titles, values), renderer, "Doughnut chart demo")); }
public void Setup(OperatorPart outputOp, double width, double height) { if (_outputOp == outputOp && _width == (int)width && _height == (int)height) { return; } try { Dispose(); _outputOp = outputOp; _width = (int)width; _height = (int)height; _samples = 2; _renderer = new DefaultRenderer(); _texture = ShaderResourceView.FromFile(D3DDevice.Device, "./assets-common/image/white.png"); _renderTargetResource = null; ResourceManager.ValidateRenderTargetResource(ref _renderTargetResource, _outputOp, D3DDevice.Device, _width, _height); _renderTargetView = new RenderTargetView(D3DDevice.Device, _renderTargetResource.Texture); _renderTargetDepthResource = null; ResourceManager.ValidateDepthStencilResource(ref _renderTargetDepthResource, _outputOp, D3DDevice.Device, _width, _height); var depthViewDesc = new DepthStencilViewDescription(); depthViewDesc.Format = Format.D32_Float; depthViewDesc.Dimension = DepthStencilViewDimension.Texture2D; _renderTargetDepthView = new DepthStencilView(D3DDevice.Device, _renderTargetDepthResource.Texture, depthViewDesc); _gpuSyncer = new BlockingGpuSyncer(D3DDevice.Device); D3DDevice.Device.ImmediateContext.OutputMerger.SetTargets(_renderTargetDepthView, _renderTargetView); _viewport = new ViewportF(0, 0, _width, _height, 0.0f, 1.0f); D3DDevice.Device.ImmediateContext.Rasterizer.SetViewport(_viewport); } catch (Exception e) { Logger.Error("Failed to setup imagefile-sequence: {0}", e.Message); } }
public void TestObjectRenderDataFactory() { IObject obj; obj = new RAMObject(); DefaultRenderer renderer = new DefaultRenderer(); MeshRenderDataFactory meshFactory = new MeshRenderDataFactory(renderer); ObjectRenderDataFactory factory = new ObjectRenderDataFactory(); factory.AddObjectDataFactory(meshFactory); ObjectRenderElement el = factory.CreateRenderElement(obj); el.WorldMatrix = Matrix.Identity; renderer.RunTest(); }
internal static IVisualElementRenderer CreateRenderer(VisualElement element, Context context) { IVisualElementRenderer renderer = null; // temporary hack to fix the following issues // https://github.com/xamarin/Xamarin.Forms/issues/13261 // https://github.com/xamarin/Xamarin.Forms/issues/12484 if (element is RadioButton tv && tv.ResolveControlTemplate() != null) { renderer = new DefaultRenderer(context); } if (renderer == null) { renderer = Registrar.Registered.GetHandlerForObject <IVisualElementRenderer>(element, context) ?? new DefaultRenderer(context); } renderer.SetElement(element); return(renderer); }
/// <summary> /// Executes the chart demo. /// </summary> /// <param name="context"> the context </param> /// <returns> the built intent </returns> public override Intent Execute(Context context) { double[] values = new double[] { 12, 14, 11, 10, 19 }; int[] colors = new int[] { Color.Blue, Color.Green, Color.Magenta, Color.Yellow, Color.Cyan }; DefaultRenderer renderer = BuildCategoryRenderer(colors); renderer.ZoomButtonsVisible = true; renderer.ZoomEnabled = true; renderer.ChartTitleTextSize = 20; renderer.DisplayValues = true; renderer.ShowLabels = false; SimpleSeriesRenderer r = renderer.GetSeriesRendererAt(0); r.GradientEnabled = true; r.SetGradientStart(0, Color.Blue); r.SetGradientStop(0, Color.Green); r.Highlighted = true; Intent intent = ChartFactory.GetPieChartIntent(context, BuildCategoryDataset("Project budget", values), renderer, "Budget"); return(intent); }
public static GraphicalView OEE(Context context, int value, int value2, string color1, string color2) { IList <double[]> values = new List <double[]>(); values.Add(new double[] { value, value2 }); IList <string[]> titles = new List <string[]>(); titles.Add(new string[] { "A", "B" }); int[] colors = new int[] { Color.ParseColor(color1), Color.ParseColor(color2) }; DefaultRenderer renderer = BuildCategoryRenderer(colors); renderer.BackgroundColor = Color.Transparent; renderer.LabelsColor = Color.Gray; renderer.PanEnabled = false; renderer.ZoomEnabled = false; renderer.StartAngle = 270; return(ChartFactory.GetDoughnutChartView(context, BuildMultipleCategoryDataset("MyDoughnut", titles, values), renderer)); }
/// <summary> /// Tries to render the HTML from cache, falls back to the default renderer if the content is not cacheable. /// </summary> /// <param name="htmlHelper">The HTML helper.</param> /// <param name="partialRequest">The partial request.</param> /// <param name="contentData">The content data.</param> /// <param name="templateModel">The template model.</param> public void RenderFromCache(HtmlHelper htmlHelper, PartialRequest partialRequest, IContentData contentData, TemplateModel templateModel) { if (SettingsService.TryGetSettingsFromContentData(contentData, out ICacheableSettings settings) && IsCacheEnabled() && contentData is IContent content) { RenderFromOrAddToCache(htmlHelper, partialRequest, content, templateModel, settings); } else { DefaultRenderer.Render(htmlHelper, partialRequest, contentData, templateModel); } bool IsCacheEnabled() { if (PageEditing.PageIsInEditMode) { return(settings.IsCacheEnabled && settings.CacheInCmsEditor); } return(settings.IsCacheEnabled); } }
public static IVisualElementRenderer CreateRenderer(VisualElement element) { if (element == null) { throw new ArgumentNullException(nameof(element)); } IVisualElementRenderer renderer = null; if (element is TemplatedView tv && tv.ResolveControlTemplate() != null) { renderer = new DefaultRenderer(); } if (renderer == null) { renderer = Registrar.Registered.GetHandlerForObject <IVisualElementRenderer>(element) ?? new DefaultRenderer(); } renderer.SetElement(element); return(renderer); }
public void TestDefaultRendererRenderModel() { //TODO: maybe detach this from the defaultrenderer? DefaultRenderer renderer = new DefaultRenderer(); TangentVertex[] vertices; short[] indices; var mat = new DefaultModelMaterialTextured(); BoxMesh.CreateUnitBoxVerticesAndIndices(out vertices, out indices); var renderable = renderer.CreateModelRenderable(vertices, indices, mat); var el = renderer.CreateRenderElement(renderable); XNAGame game = new XNAGame(); game.InitializeEvent += delegate { //TODO: make the renderer manage textures!!! using (var fs = new FileStream(TestFiles.WoodPlanksBareJPG, FileMode.Open, FileAccess.Read, FileShare.Read)) { mat.DiffuseTexture = Texture2D.FromFile(game.GraphicsDevice, fs); } }; game.AddXNAObject(renderer); game.Run(); }
public static void Setup(OperatorPartContext context, Operator op, DefaultRenderer renderer, Matrix worldToCamera, float nearClipping = 0.01f, float farClipping = 10000) { context.D3DDevice.ImmediateContext.OutputMerger.SetTargets(context.DepthStencilView, context.RenderTargetView); context.D3DDevice.ImmediateContext.Rasterizer.SetViewport(context.Viewport); if (context.DepthStencilView != null) { context.D3DDevice.ImmediateContext.ClearDepthStencilView(context.DepthStencilView, DepthStencilClearFlags.Depth | DepthStencilClearFlags.Stencil, 1.0f, 0); } context.D3DDevice.ImmediateContext.ClearRenderTargetView(context.RenderTargetView, new Color4(0.4f, 0.4f, 0.4f, 1.0f)); context.D3DDevice.ImmediateContext.InputAssembler.InputLayout = context.InputLayout; if (op == null) { return; } ICameraProvider camOp = null; if (op.InternalParts.Count > 0) { camOp = op.InternalParts[0].Func as ICameraProvider; } if (camOp == null) { context.WorldToCamera = worldToCamera; float aspect = context.Viewport.Width / context.Viewport.Height; context.CameraProjection = Matrix.PerspectiveFovLH(3.1415f / 4.0f, aspect, nearClipping, farClipping); } else { context.WorldToCamera = camOp.GetLastWorldToCamera(); context.CameraProjection = camOp.GetLastCameraToView(); } }
public void Setup(OperatorPart outputOpPart, double startTime = 0, double endTime = 184, double frameRate = 30, double width = 1920, double height = 1080, string fileExtension = "png", bool skipExistingFiles = false, string directory = "output", string filenameFormat = "[T]", SharpDX.DXGI.Format imageFormat = Format.R8G8B8A8_UNorm) { try { Dispose(); _outputOpPart = outputOpPart; _directory = directory; _fileNameFormat = filenameFormat; _startTime = startTime; _endTime = endTime; _frameRate = frameRate; _width = (int)width; _height = (int)height; _samples = 2; _fileExtension = fileExtension.ToLower(); _skipExistingFiles = skipExistingFiles; _defaultContext = new OperatorPartContext(0.0f); _defaultContext.Variables.Add("Screensize.Width", _width); _defaultContext.Variables.Add("Screensize.Height", _height); _defaultContext.Variables.Add("AspectRatio", (float)_width / _height); _defaultContext.Variables.Add("Samples", _samples); _defaultContext.Variables.Add("FullScreen", 0.0f); _defaultContext.Variables.Add("LoopMode", 0.0f); _defaultContext.ImageBufferFormat = imageFormat; _frameTime = 1.0 / _frameRate; Directory.CreateDirectory(_directory); _renderer = new DefaultRenderer(); _texture = ShaderResourceView.FromFile(D3DDevice.Device, "./assets-common/image/white.png"); _renderTargetResource = null; ResourceManager.ValidateRenderTargetResource(ref _renderTargetResource, _outputOpPart, D3DDevice.Device, _width, _height, imageFormat); _renderTargetView = new RenderTargetView(D3DDevice.Device, _renderTargetResource.Texture); _renderDepthResource = null; ResourceManager.ValidateDepthStencilResource(ref _renderDepthResource, _outputOpPart, D3DDevice.Device, _width, _height); var depthViewDesc = new DepthStencilViewDescription(); depthViewDesc.Format = Format.D32_Float; depthViewDesc.Dimension = DepthStencilViewDimension.Texture2D; _renderTargetDepthView = new DepthStencilView(D3DDevice.Device, _renderDepthResource.Texture, depthViewDesc); _gpuSyncer = new BlockingGpuSyncer(D3DDevice.Device); D3DDevice.Device.ImmediateContext.OutputMerger.SetTargets(_renderTargetDepthView, _renderTargetView); _viewport = new ViewportF(0, 0, _width, _height, 0.0f, 1.0f); D3DDevice.Device.ImmediateContext.Rasterizer.SetViewport(_viewport); var timeAccessorCollector = new OperatorPart.CollectOpPartFunctionsOfType <OperatorPartTraits.ITimeAccessor>(); _outputOpPart.TraverseWithFunction(timeAccessorCollector, null); _timeAccessorOpPartFunctions = new List <OperatorPart.Function>(); foreach (var opPartFunction in timeAccessorCollector.CollectedOpPartFunctions) { _timeAccessorOpPartFunctions.Add(opPartFunction as OperatorPart.Function); } _currentTime = _startTime; } catch (Exception e) { Logger.Error("Failed to setup image-sequence {0}", e.Message); } }
/// <summary> /// Builds a category renderer to use the provided colors. /// </summary> /// <param name="colors"> the colors </param> /// <returns> the category renderer </returns> protected internal virtual DefaultRenderer buildCategoryRenderer(int[] colors) { DefaultRenderer renderer = new DefaultRenderer(); renderer.LabelsTextSize = 15; renderer.LegendTextSize = 15; renderer.Margins = new int[] {20, 30, 15, 0}; foreach (int color in colors) { SimpleSeriesRenderer r = new SimpleSeriesRenderer(); r.Color = color; renderer.addSeriesRenderer(r); } return renderer; }
protected override void OnRestoreInstanceState(Bundle savedState) { base.OnRestoreInstanceState(savedState); mSeries = (CategorySeries)savedState.GetSerializable("current_series"); mRenderer = (DefaultRenderer)savedState.GetSerializable("current_renderer"); }
internal static IVisualElementRenderer CreateRenderer( VisualElement element, Context context, AndroidX.Fragment.App.FragmentManager fragmentManager = null, global::Android.Views.LayoutInflater layoutInflater = null) { IVisualElementRenderer renderer = null; // temporary hack to fix the following issues // https://github.com/xamarin/Microsoft.Maui.Controls.Compatibility/issues/13261 // https://github.com/xamarin/Microsoft.Maui.Controls.Compatibility/issues/12484 if (element is RadioButton tv && tv.ResolveControlTemplate() != null) { renderer = new DefaultRenderer(context); } // This code is duplicated across all platforms currently // So if any changes are made here please make sure to apply them to other platform.cs files if (renderer == null) { IViewHandler handler = null; //TODO: Handle this with AppBuilderHost try { var mauiContext = Forms.MauiContext; if (fragmentManager != null || layoutInflater != null) { mauiContext = new ScopedMauiContext(mauiContext, null, null, layoutInflater, fragmentManager); } handler = mauiContext.Handlers.GetHandler(element.GetType()) as IViewHandler; handler.SetMauiContext(mauiContext); } catch { // TODO define better catch response or define if this is needed? } if (handler == null) { renderer = Registrar.Registered.GetHandlerForObject <IVisualElementRenderer>(element, context) ?? new DefaultRenderer(context); } // This means the only thing registered is the RendererToHandlerShim // Which is only used when you are running a .NET MAUI app // This indicates that the user hasn't registered a specific handler for this given type else if (handler is RendererToHandlerShim shim) { renderer = shim.VisualElementRenderer; if (renderer == null) { renderer = Registrar.Registered.GetHandlerForObject <IVisualElementRenderer>(element, context) ?? new DefaultRenderer(context); } } else if (handler is IVisualElementRenderer ver) { renderer = ver; } else if (handler is INativeViewHandler vh) { renderer = new HandlerToRendererShim(vh); element.Handler = handler; SetRenderer(element, renderer); } } renderer.SetElement(element); if (fragmentManager != null) { var managesFragments = renderer as IManageFragments; managesFragments?.SetFragmentManager(fragmentManager); } return(renderer); }
public static Scene sceneTwo() { var scene = new Scene(); scene.clearColor = Color.Coral; var moonTexture = scene.contentManager.Load <Texture2D>("bin/MacOSX/Images/moon"); var bmFont = scene.contentManager.Load <BitmapFont>("bin/MacOSX/Fonts/pixelfont"); bmFont.spacing = 2f; // setup a renderer that renders everything to a RenderTarget making sure its order is before standard renderers! var renderer = new DefaultRenderer(-1); renderer.renderTarget = RenderTarget.create(320, 240); renderer.renderTargetClearColor = Color.CornflowerBlue; scene.addRenderer(renderer); // add a standard renderer that renders to the screen scene.addRenderer(new DefaultRenderer()); // stick a couple moons on screen var entity = scene.createEntity("moon"); var image = new Sprite(moonTexture); entity.transform.scale = new Vector2(2); entity.addComponent(image); entity.addComponent(new FramesPerSecondCounter(Graphics.instance.bitmapFont, Color.White, FramesPerSecondCounter.FPSDockPosition.TopLeft)); entity.transform.position = new Vector2(120f, 0f); entity.colliders.add(new CircleCollider(moonTexture.Width * 1.5f)); entity = scene.createEntity("new-moon"); image = new Sprite(moonTexture); entity.transform.position = new Vector2(130f, 230f); entity.addComponent(image); entity = scene.createEntity("bmfont"); entity.addComponent(new Text(Graphics.instance.bitmapFont, "This text is a BMFont\nPOOOP", new Vector2(0, 30), Color.Red)); entity.addComponent(new Text(bmFont, "This text is a BMFont\nPOOOP", new Vector2(0, 70), Color.Cornsilk)); // texture atlas tester var anotherAtlas = scene.contentManager.Load <TextureAtlas>("bin/MacOSX/TextureAtlasTest/AnotherAtlas"); var textureAtlas = scene.contentManager.Load <TextureAtlas>("bin/MacOSX/TextureAtlasTest/AtlasImages"); entity = scene.createEntity("texture-atlas-sprite"); entity.transform.position = new Vector2(30f, 330f); // create a sprite animation from an atlas var spriteAnimation = new SpriteAnimation() { loop = true, fps = 10 }; spriteAnimation.addFrame(textureAtlas.getSubtexture("Ninja_Idle_0")); spriteAnimation.addFrame(textureAtlas.getSubtexture("Ninja_Idle_1")); spriteAnimation.addFrame(textureAtlas.getSubtexture("Ninja_Idle_2")); spriteAnimation.addFrame(textureAtlas.getSubtexture("Ninja_Idle_3")); spriteAnimation.addFrame(anotherAtlas.getSubtexture("airDash-Ninja_Air Dash_0")); spriteAnimation.addFrame(anotherAtlas.getSubtexture("airDash-Ninja_Air Dash_1")); spriteAnimation.addFrame(anotherAtlas.getSubtexture("airDash-Ninja_Air Dash_2")); spriteAnimation.addFrame(anotherAtlas.getSubtexture("airDash-Ninja_Air Dash_3")); var sprite = new Sprite <int>(1, anotherAtlas.getSpriteAnimation("hardLanding")); sprite.addAnimation(0, spriteAnimation); sprite.play(1); entity.addComponent(sprite) .addComponent(new SimpleMoonMover()) .addComponent(new SpriteTrail(sprite)); entity.getComponent <SpriteTrail>().enableSpriteTrail(); // add a post processor to display the RenderTarget var effect = scene.contentManager.loadEffect("Content/Effects/Invert.mgfxo"); var postProcessor = new SimplePostProcessor(renderer.renderTarget, effect); scene.addPostProcessor(postProcessor); return(scene); }
public PowerUp(Vector2 position, Texture2D texture, float effectValue) { base.Position = position; this.effectValue = effectValue; Renderer = new DefaultRenderer(this, texture); }
public override void OnAddedToEntity() { #region Load up texture atlas... //Load up character texture atlas var idleTexture = Entity.Scene.Content.Load <Texture2D>(Content.Textures.HeroIdle); var runTexture = Entity.Scene.Content.Load <Texture2D>(Content.Textures.HeroRun); var attackTexture = Entity.Scene.Content.Load <Texture2D>(Content.Textures.HeroAttack); var jumpTexture = Entity.Scene.Content.Load <Texture2D>(Content.Textures.HeroJump); var fallTexture = Entity.Scene.Content.Load <Texture2D>(Content.Textures.HeroFall); var idleSprite = Sprite.SpritesFromAtlas(idleTexture, 50, 37); var runSprite = Sprite.SpritesFromAtlas(runTexture, 50, 37); var attackSprite = Sprite.SpritesFromAtlas(attackTexture, 50, 37); var jumpSprite = Sprite.SpritesFromAtlas(jumpTexture, 50, 37); var fallSprite = Sprite.SpritesFromAtlas(fallTexture, 50, 37); #endregion Load up texture atlas... #region add componentents... //Movement component var map = Entity.Scene as SandBoxScene; Mover = Entity.AddComponent(new TiledMapMover(map.TiledMap.GetLayer <TmxLayer>("main"))); //animator component Animator = Entity.AddComponent <SpriteAnimator>(); //Set up collider Collider = Entity.AddComponent <BoxCollider>(); Collider.Width = 16; Collider.Height = 30; Collider.SetLocalOffset(new Vector2(0, 3)); Flags.SetFlagExclusive(ref Collider.CollidesWithLayers, 1); Flags.SetFlagExclusive(ref Collider.PhysicsLayer, 1); //CollisionListener CollisionListener = Entity.AddComponent <CollisionListener>(); //SetType Type = Entity.AddComponent <TypeComponent>(); Type.SetType(EntityType.PLAYER); //Set up StateMachine StateMachine = Entity.AddComponent(new StateMachine()); StateMachine.AddState(STATES.PLAYER_FREE, new PlayerPlatformerStateFree(this)); StateMachine.AddState(STATES.PLAYER_ATTACK, new PlayerStateAttack(this)); StateMachine.CurrentState = STATES.PLAYER_FREE; //Set up Camera var camera = new FollowCamera(Entity); camera.MapLockEnabled = true; Entity.AddComponent(camera); var renderer = new DefaultRenderer(camera: camera.Camera); Entity.Scene.AddRenderer(renderer); //camera.Camera.Position = Entity.Transform.Position; camera.MapSize = new Vector2(1280, 0); camera.FollowLerp = .3f; #endregion add componentents... #region Animations... Animator.AddAnimation("IdleSheathed", 3.5f, new[] { idleSprite[0], idleSprite[1], idleSprite[2], idleSprite[3] }); Animator.AddAnimation("IdleUnSheathed", 3.5f, new[] { idleSprite[4], idleSprite[5], idleSprite[6], idleSprite[7] }); Animator.AddAnimation("RunSheathed", 7.5f, new[] { runSprite[0], runSprite[1], runSprite[2], runSprite[3], runSprite[4], runSprite[5] }); Animator.AddAnimation("RunUnSheathed", 7.5f, new[] { runSprite[6], runSprite[7], runSprite[8], runSprite[9], runSprite[10], runSprite[11] }); Animator.AddAnimation("Attack0", 12, new[] { attackSprite[0], attackSprite[1], attackSprite[2], attackSprite[3], attackSprite[4], attackSprite[5], }); Animator.AddAnimation("Attack1", 12, new[] { attackSprite[6], attackSprite[7], attackSprite[8], attackSprite[9], attackSprite[10] }); Animator.AddAnimation("Attack2", 12, new[] { attackSprite[11], attackSprite[12], attackSprite[13], attackSprite[14], attackSprite[15], attackSprite[16] }); Animator.AddAnimation("Jump", 15, new[] { //jumpSprite[0], //jumpSprite[1], jumpSprite[2], jumpSprite[3] }); Animator.AddAnimation("Fall", 8, new[] { fallSprite[0], fallSprite[1] }); #endregion Animations... //Set up Input SetupInput(); base.OnAddedToEntity(); }
public void Run(ContextSettings settings) { SharpDX.RawInput.Device.RegisterDevice(UsagePage.Generic, UsageId.GenericKeyboard, SharpDX.RawInput.DeviceFlags.None); SharpDX.RawInput.Device.RegisterDevice(UsagePage.Generic, UsageId.GenericMouse, SharpDX.RawInput.DeviceFlags.None); SharpDX.RawInput.Device.RegisterDevice(UsagePage.Generic, UsageId.GenericJoystick, SharpDX.RawInput.DeviceFlags.None); Logger.Debug("Start fullscreen with resolution: {0} x {1}...", settings.DisplayMode.Height, settings.DisplayMode.Width); Size = new System.Drawing.Size(settings.DisplayMode.Width, settings.DisplayMode.Height); _defaultContext = OperatorPartContext.createDefault(settings); var desc = new SwapChainDescription() { BufferCount = 3, ModeDescription = new ModeDescription(ClientSize.Width, ClientSize.Height, new Rational(settings.DisplayMode.RefreshRate, 1), Format.R8G8B8A8_UNorm), IsWindowed = false, OutputHandle = Handle, SampleDescription = new SampleDescription(1, 0), SwapEffect = SwapEffect.Discard, Usage = Usage.RenderTargetOutput, Flags = SwapChainFlags.AllowModeSwitch }; var dxgiDevice = D3DDevice.Device.QueryInterface <SharpDX.DXGI.Device>(); var factory = dxgiDevice.Adapter.GetParent <Factory>(); _swapChain = new SwapChain(factory, D3DDevice.Device, desc); _swapChain.ResizeBuffers(3, ClientSize.Width, ClientSize.Height, _swapChain.Description.ModeDescription.Format, _swapChain.Description.Flags); using (var texture = Texture2D.FromSwapChain <Texture2D>(_swapChain, 0)) _renderTargetView = new RenderTargetView(D3DDevice.Device, texture); var depthdesc = new Texture2DDescription { BindFlags = BindFlags.DepthStencil, Format = Format.D32_Float_S8X24_UInt, Width = ClientSize.Width, Height = ClientSize.Height, MipLevels = 1, SampleDescription = new SampleDescription(1, 0), Usage = ResourceUsage.Default, OptionFlags = ResourceOptionFlags.None, CpuAccessFlags = CpuAccessFlags.None, ArraySize = 1 }; _depthTex = new Texture2D(D3DDevice.Device, depthdesc); _depthStencilView = new DepthStencilView(D3DDevice.Device, _depthTex); D3DDevice.Device.ImmediateContext.OutputMerger.SetTargets(_depthStencilView, _renderTargetView); _viewport = new ViewportF(0, 0, ClientSize.Width, ClientSize.Height, 0.0f, 1.0f); D3DDevice.Device.ImmediateContext.Rasterizer.SetViewport(_viewport); _shaderResourceView = ShaderResourceView.FromFile(D3DDevice.Device, "./assets-common/image/white.png"); _renderer = new DefaultRenderer(); _globalTime.Start(); RenderLoop.Run(this, UpdateLocalShownContent); }
public bool Initialize(ContextSettings settings) { Logger.Info("Initializing ..."); // GCSettings.LatencyMode = GCLatencyMode.LowLatency; _undoRedoStack = new UndoRedoStack(false); Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture; Thread.CurrentThread.CurrentUICulture = CultureInfo.InvariantCulture; for (int i = 0; i < _numMeasureValues; ++i) { _averagedElapsed.Add(10000); } ProjectSettings = new Settings("Config/ProjectSettings.json"); _settings = settings; _defaultContext = OperatorPartContext.createDefault(_settings); var registrationEmail = ProjectSettings.TryGet("Tooll.Sound.BassNetLicense.Email", ""); var registrationKey = ProjectSettings.TryGet("Tooll.Sound.BassNetLicense.Key", ""); if (!String.IsNullOrEmpty(registrationEmail) && !String.IsNullOrEmpty(registrationKey)) { BassNet.Registration(registrationEmail, registrationKey); } Bass.BASS_Init(-1, 44100, BASSInit.BASS_DEVICE_LATENCY, IntPtr.Zero); var soundFilePath = (string)ProjectSettings["Soundtrack.Path"]; _soundStream = Bass.BASS_StreamCreateFile(soundFilePath, 0, 0, BASSFlag.BASS_STREAM_PRESCAN); if (_soundStream == 0) { Logger.Error("Error loading sound file {0}", soundFilePath); return(false); } _soundLength = Bass.BASS_ChannelBytes2Seconds(_soundStream, Bass.BASS_ChannelGetLength(_soundStream, BASSMode.BASS_POS_BYTES)); SharpDX.RawInput.Device.RegisterDevice(UsagePage.Generic, UsageId.GenericKeyboard, SharpDX.RawInput.DeviceFlags.None); SharpDX.RawInput.Device.RegisterDevice(UsagePage.Generic, UsageId.GenericMouse, SharpDX.RawInput.DeviceFlags.None); SharpDX.RawInput.Device.RegisterDevice(UsagePage.Generic, UsageId.GenericJoystick, SharpDX.RawInput.DeviceFlags.None); _form = new RenderForm("Framefield T2 Player"); _form.Icon = Properties.Resources.t2; _form.Visible = true; _form.Size = new Size(_settings.DisplayMode.Width, _settings.DisplayMode.Height); var desc = new SwapChainDescription() { BufferCount = 3, ModeDescription = new ModeDescription(_settings.DisplayMode.Width, _settings.DisplayMode.Height, new Rational(_settings.DisplayMode.RefreshRate, 1), Format.R8G8B8A8_UNorm), IsWindowed = !_settings.FullScreen, OutputHandle = _form.Handle, SampleDescription = new SampleDescription(1, 0), SwapEffect = SwapEffect.Discard, Usage = Usage.RenderTargetOutput, Flags = SwapChainFlags.AllowModeSwitch }; var featureLevels = new FeatureLevel[] { FeatureLevel.Level_11_0, FeatureLevel.Level_10_1 }; SharpDX.Direct3D11.Device.CreateWithSwapChain(DriverType.Hardware, DeviceCreationFlags.None, featureLevels, desc, out D3DDevice.Device, out D3DDevice.SwapChain); if (D3DDevice.Device == null) { Logger.Error("Failed to setup a Direct3d 11 device"); return(false); } if (D3DDevice.SwapChain == null) { Logger.Error("Failed to setup swap chain"); return(false); } using (var dxgiDevice = D3DDevice.Device.QueryInterface <SharpDX.DXGI.Device1>()) { var adapter = dxgiDevice.Adapter; D3DDevice.DX10_1Device = new SharpDX.Direct3D10.Device1(adapter, SharpDX.Direct3D10.DeviceCreationFlags.BgraSupport, SharpDX.Direct3D10.FeatureLevel.Level_10_1); } D3DDevice.Direct2DFactory = new SharpDX.Direct2D1.Factory(); D3DDevice.DirectWriteFactory = new SharpDX.DirectWrite.Factory(); _texture = ShaderResourceView.FromFile(D3DDevice.Device, "./assets-common/image/white.png"); _renderer = new DefaultRenderer(); _form.KeyUp += KeyUpHandler; _form.KeyDown += KeyDownHandler; _form.Resize += ResizeHandler; SetupRenderBuffers(); if (_settings.FullScreen) { Cursor.Hide(); } D3DDevice.TouchWidth = 1920; D3DDevice.TouchHeight = 1080; return(true); }