// Internal methods //////////////////// static void TestRenderDiff() { var ar = W.Row( W.Text("hello"), W.FillWidth(null), W.Border( W.Text("world") ) ); var br = W.Row( W.Text("halo"), W.FillWidth(null), W.Border( W.Text("world") ) ); var c = new Constraint { xMin = 0, xMax = 50, yMin = 0, yMax = 50, }; ar.Layout(c); br.Layout(c); using (var t = new Rendering.Terminal(50, 50, "layout test")) { RenderLayout.Tree(t, ar); RenderLayout.Diff(t, ar, br); t.Render(); while (!t.ShouldClose) { t.Poll(); } } }
private void LayoutControl_Loaded(object sender, RoutedEventArgs e) { try { FinishedRegionList.Clear(); //this.LayoutRoot.Children.Clear(); //Read Layout List //RenderLayout.PrepareLayout(RenderSchedule.ListLayouts[_layoutListID]); RenderLayout.PrepareLayout(_layoutID, _layout); //Reoder _layout.RegionList = _layout.RegionList.OrderBy(x => x.zIndex).ToList(); //Timer dispatcherTimer.Tick += DispatcherTimer_Tick; //Stat view ViewLayout(); //PlayerSettings.firstLoadCheck = 1; this.Cursor = Cursors.None; var bc = new BrushConverter(); this.Background = (Brush)bc.ConvertFrom(_layout.backgroundColor); //set background image if (_layout.backgroundImage != "") { string BackgroundImage = _layout.backgroundImage; this.Background = new ImageBrush(new BitmapImage(new Uri(BackgroundImage))); } } catch (Exception ex) { PlayerSettings.ErrorLog(ex); } }
/// <summary> /// Attaches the scene to the device specified in <paramref name="device"/>, and allocate resources specific to that device. /// </summary> /// <param name="device">The device to attach to.</param> /// <param name="hostSize">The size of the device.</param> public void Attach(Device device, PointD2D hostSize) { if (null != _cachedDevice) { throw new InvalidOperationException("Try to attach to device without deattach former device!"); } _cachedDevice = device ?? throw new ArgumentNullException(nameof(device)); _hostSize = hostSize; using (var stream = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("Altaxo.CompiledShaders.Effects.Lighting.cso")) { if (null == stream) { throw new InvalidOperationException(string.Format("Compiled shader resource not found: {0}", "Altaxo.CompiledShaders.Effects.Lighting.cso")); } using (var shaderBytes = ShaderBytecode.FromStream(stream)) { _lightingEffect = new Effect(device, shaderBytes); } } for (int i = 0; i < _layoutNames.Length; ++i) { string techniqueName = "Shade_" + _layoutNames[i]; var technique = _lightingEffect.GetTechniqueByName(techniqueName); if (null == technique || !technique.IsValid) { throw new InvalidProgramException(string.Format("Technique {0} was not found or is invalid", techniqueName)); } var pass = technique.GetPassByIndex(0); if (null == pass || !pass.IsValid) { throw new InvalidProgramException(string.Format("Pass[0] of technique {0} was not found or is invalid", techniqueName)); } InputLayout inputLayout; switch (i) { case 0: inputLayout = new InputLayout(device, pass.Description.Signature, new[] { new InputElement("POSITION", 0, Format.R32G32B32A32_Float, 0, 0) }); break; case 1: inputLayout = new InputLayout(device, pass.Description.Signature, new[] { new InputElement("POSITION", 0, Format.R32G32B32A32_Float, 0, 0), new InputElement("COLOR", 0, Format.R32G32B32A32_Float, 16, 0) }); break; case 2: inputLayout = new InputLayout(device, pass.Description.Signature, new[] { new InputElement("POSITION", 0, Format.R32G32B32A32_Float, 0, 0), new InputElement("TEXCOORD", 0, Format.R32G32_Float, 16, 0) }); break; case 3: inputLayout = new InputLayout(device, pass.Description.Signature, new[] { new InputElement("POSITION", 0, Format.R32G32B32A32_Float, 0, 0), new InputElement("NORMAL", 0, Format.R32G32B32A32_Float, 16, 0) }); break; case 4: inputLayout = new InputLayout(device, pass.Description.Signature, new[] { new InputElement("POSITION", 0, Format.R32G32B32A32_Float, 0, 0), new InputElement("NORMAL", 0, Format.R32G32B32A32_Float, 16, 0), new InputElement("COLOR", 0, Format.R32G32B32A32_Float, 32, 0) }); break; case 5: inputLayout = new InputLayout(device, pass.Description.Signature, new[] { new InputElement("POSITION", 0, Format.R32G32B32A32_Float, 0, 0), new InputElement("NORMAL", 0, Format.R32G32B32A32_Float, 16, 0), new InputElement("TEXCOORD", 0, Format.R32G32_Float, 32, 0) }); break; case 6: inputLayout = new InputLayout(device, pass.Description.Signature, new[] { new InputElement("POSITION", 0, Format.R32G32B32_Float, 0, 0), new InputElement("NORMAL", 0, Format.R32G32B32_Float, 12, 0), new InputElement("TEXCOORD", 0, Format.R32G32_Float, 24, 0) }); break; default: throw new NotImplementedException(); } _renderLayouts[i] = new RenderLayout(technique, pass, inputLayout); } // Create Constant Buffers //_constantBuffer = new Buffer(device, Utilities.SizeOf<Matrix>(), ResourceUsage.Default, BindFlags.ConstantBuffer, CpuAccessFlags.None, ResourceOptionFlags.None); //_constantBufferForColor = new Buffer(device, Utilities.SizeOf<Vector4>(), ResourceUsage.Default, BindFlags.ConstantBuffer, CpuAccessFlags.None, ResourceOptionFlags.None); //_constantBufferForSixPlanes = new Buffer(device, Utilities.SizeOf<Vector4>() * 6, ResourceUsage.Default, BindFlags.ConstantBuffer, CpuAccessFlags.None, ResourceOptionFlags.None); // View transformation variables _cbViewTransformation = _lightingEffect.GetConstantBufferByName("cbViewTransformation"); _evWorldViewProj = _cbViewTransformation.GetMemberByName("WorldViewProj").AsMatrix(); _evEyePosition = _cbViewTransformation.GetMemberByName("EyePosition").AsVector(); _cbMaterial = _lightingEffect.GetConstantBufferByName("cbMaterial"); _evMaterialDiffuseColor = _cbMaterial.GetMemberByName("MaterialDiffuseColor").AsVector(); _evMaterialSpecularExponent = _cbMaterial.GetMemberByName("MaterialSpecularExponent").AsScalar(); _evMaterialSpecularExponent.Set(4.0f); _evMaterialSpecularIntensity = _cbMaterial.GetMemberByName("MaterialSpecularIntensity").AsScalar(); _evMaterialSpecularIntensity.Set(1.0f); _evMaterialDiffuseIntensity = _cbMaterial.GetMemberByName("MaterialDiffuseIntensity").AsScalar(); _evMaterialMetalnessValue = _cbMaterial.GetMemberByName("MaterialMetalnessValue").AsScalar(); _evMaterialMetalnessValue.Set(0.75f); // Color providers BindTextureFor1DColorProviders(); // Clip plane variables _cbClipPlanes = _lightingEffect.GetConstantBufferByName("cbClipPlanes"); for (int i = 0; i < 6; ++i) { _evClipPlanes[i] = _cbClipPlanes.GetMemberByName("ClipPlane" + i.ToString(System.Globalization.CultureInfo.InvariantCulture)).AsVector(); } // Lighting variables _lighting = new Lighting(_lightingEffect); _lighting.SetDefaultLighting(); // -------------------- now draw the scene again with the new attached device -------------- if (null != _altaxoCamera && null != _altaxoLightSettings) { if (_altaxoDrawingGeometry != null) { BringDrawingIntoBuffers(_altaxoDrawingGeometry); } if (null != _altaxoMarkerGeometry) { BringMarkerGeometryIntoDeviceBuffers(_altaxoMarkerGeometry); } if (null != _altaxoOverlayGeometry) { BringOverlayGeometryIntoDeviceBuffers(_altaxoOverlayGeometry); } } }
static void TestRenderResponsive() { Func <BaseWidget> build = () => W.Row( W.FillWidth( W.FillHeight( W.Border(null))), W.FixedWidth( 20, W.Column( W.Row( W.Text("Blacksmith"), W.FillWidth(null), W.Text("friendly") ), W.Row( W.Text("Mouse"), W.FillWidth(null), W.Text("neutral") ), W.Row( W.Text("Fire Imp"), W.FillWidth(null), W.Text("hostile") ) ) ) ); using (var t = new Rendering.Terminal(50, 50, "layout test")) { var c = new Constraint { xMin = 0, xMax = -1, yMin = 0, yMax = -1, }; var prev = default(BaseWidget); var next = build(); while (!t.ShouldClose) { var(newWidth, newHeight) = t.Size; if (c.xMax != newWidth || c.yMax != newHeight) { c = c with { xMax = newWidth, yMax = newHeight, }; next.Layout(c); if (prev == null) { LayoutUtils.PrintTree(next); RenderLayout.Tree(t, next); } else { RenderLayout.Diff(t, prev, next); } t.Render(); prev = next; next = build(); } t.Poll(); } } }