// TODO It might be easier to just grab the h/w in the funciton // TODO Find a way to hook this to an event public void SetCharsAndLines() { double height = this.ActualHeight; double width = this.ActualWidth; FormattedText fixedFt = buildFormattedText("A", _fixedFont, true, null, null); FormattedText propFt = buildFormattedText("A", _regularFont, true, null, null); double w = fixedFt.Width; double h = fixedFt.Height; charHeight = Math.Max(fixedFt.Height, propFt.Height); charWidth = fixedFt.Width; // Account for the margin of the Rich Text Box // TODO Find a way to determine what this should be, or to remove the margin double screenWidth = width - 20; double screenHeight = height - 20; if (os_._blorbFile != null) { var standard = os_._blorbFile.StandardSize; if (standard.Height > 0 && standard.Width > 0) { int maxW = (int)Math.Floor(width / os_._blorbFile.StandardSize.Width); int maxH = (int)Math.Floor(height / os_._blorbFile.StandardSize.Height); scale = Math.Min(maxW, maxH); // scale = 2; // Ok, so the rest of things are at the right scale, but we've pulled back the images to 1x screenWidth = os_._blorbFile.StandardSize.Width * scale; screenHeight = os_._blorbFile.StandardSize.Height * scale; } } else { scale = 1; } ActualCharSize = new Size(propFt.Width, propFt.Height); chars = Convert.ToInt32(Math.Floor(screenWidth / charWidth)); // Determine chars based only on fixed width chars since proportional fonts are accounted for as they are written lines = Convert.ToInt32(Math.Floor(screenHeight / charHeight)); // Use the largest character height _metrics = new ScreenMetrics( new ZSize(charHeight, charWidth), // new ZSize(h, w), new ZSize(lines * charHeight, chars * charWidth), // The ZMachine wouldn't take screenHeight as round it down, so this takes care of that lines, chars, scale); Conversion.Metrics = _metrics; _regularLines = new ScreenLines(_metrics.Rows, _metrics.Columns); _fixedWidthLines = new ScreenLines(_metrics.Rows, _metrics.Columns); _cursorCanvas.MinHeight = 2; _cursorCanvas.MinWidth = charWidth; ztc.SetMetrics(_metrics); }
public static ModelResult LoadModel3DGroup(IConfigurationService configService, bool designMode) { if (designMode) { var mesh = new CubeMesh(); var model = new GeometryModel3D(mesh.Geometry, new DiffuseMaterial(new SolidColorBrush(Colors.Red))); var group = new Transform3DGroup(); group.Children.Add(new ScaleTransform3D(new Vector3D(20, 20, 20))); group.Children.Add(new RotateTransform3D( new AxisAngleRotation3D(new Vector3D(1, 1, 0), 30))); model.Transform = group; var designSesult = new ModelResult(); designSesult.Model3DGroup.Children.Add(model); return(designSesult); } var result = new ModelResult(); var model3DGroup = new Model3DGroup(); var modelConfig = configService.GetModelConfiguration(); foreach (var letter in modelConfig.LetterModels) { var dictionary = new ResourceDictionary() { Source = new Uri(letter.ModelPath, UriKind.Relative) }; var mesh = (MeshGeometry3D)dictionary["mesh"]; if (mesh == null) { throw new InvalidOperationException("3D Mesh could not be read in XAML file '" + letter.ModelPath + "'"); } var brush = new SolidColorBrush( (Color)ColorConverter.ConvertFromString(letter.Color)); var materialGroup = new MaterialGroup(); var diffuse = new DiffuseMaterial(brush); var specular = new SpecularMaterial(new SolidColorBrush(Colors.White), 1000); materialGroup.Children.Add(diffuse); materialGroup.Children.Add(specular); var model = new GeometryModel3D(mesh, materialGroup); var transformGroup = new Transform3DGroup(); var scale = new ScaleTransform3D( new Vector3D(letter.Scale, letter.Scale, letter.Scale)); var translate = new TranslateTransform3D( new Vector3D(letter.OffsetX, letter.OffsetY, letter.OffsetZ)); transformGroup.Children.Add(translate); transformGroup.Children.Add(scale); model.Transform = transformGroup; model3DGroup.Children.Add(model); var wireframe = new ScreenLines(); for (var i = 0; i < mesh.Positions.Count; i++) { wireframe.Points.Add(mesh.Positions[i]); wireframe.Thickness = 1; wireframe.Color = Colors.White; } wireframe.Transform = transformGroup; result.Wireframes.Add(wireframe); } result.Model3DGroup = model3DGroup; return(result); }
public static ModelResult LoadModel3DGroup(IConfigurationService configService, bool designMode) { if (designMode) { var mesh = new CubeMesh(); var model = new GeometryModel3D(mesh.Geometry, new DiffuseMaterial(new SolidColorBrush(Colors.Red))); var group = new Transform3DGroup(); group.Children.Add(new ScaleTransform3D(new Vector3D(20, 20, 20))); group.Children.Add(new RotateTransform3D( new AxisAngleRotation3D(new Vector3D(1, 1, 0), 30))); model.Transform = group; var designSesult = new ModelResult(); designSesult.Model3DGroup.Children.Add(model); return designSesult; } var result = new ModelResult(); var model3DGroup = new Model3DGroup(); var modelConfig = configService.GetModelConfiguration(); foreach (var letter in modelConfig.LetterModels) { var dictionary = new ResourceDictionary() { Source = new Uri(letter.ModelPath, UriKind.Relative) }; var mesh = (MeshGeometry3D)dictionary["mesh"]; if (mesh == null) { throw new InvalidOperationException("3D Mesh could not be read in XAML file '" + letter.ModelPath + "'"); } var brush = new SolidColorBrush( (Color)ColorConverter.ConvertFromString(letter.Color)); var materialGroup = new MaterialGroup(); var diffuse = new DiffuseMaterial(brush); var specular = new SpecularMaterial(new SolidColorBrush(Colors.White), 1000); materialGroup.Children.Add(diffuse); materialGroup.Children.Add(specular); var model = new GeometryModel3D(mesh, materialGroup); var transformGroup = new Transform3DGroup(); var scale = new ScaleTransform3D( new Vector3D(letter.Scale, letter.Scale, letter.Scale)); var translate = new TranslateTransform3D( new Vector3D(letter.OffsetX, letter.OffsetY, letter.OffsetZ)); transformGroup.Children.Add(translate); transformGroup.Children.Add(scale); model.Transform = transformGroup; model3DGroup.Children.Add(model); var wireframe = new ScreenLines(); for (var i = 0; i < mesh.Positions.Count; i++) { wireframe.Points.Add(mesh.Positions[i]); wireframe.Thickness = 1; wireframe.Color = Colors.White; } wireframe.Transform = transformGroup; result.Wireframes.Add(wireframe); } result.Model3DGroup = model3DGroup; return result; }
public void SetCharsAndLines() { double height = this.ActualHeight; double width = this.ActualWidth; FormattedText fixedFt = buildFormattedText("A", _fixedFont, _currentInfo, null); FormattedText propFt = buildFormattedText("A", _regularFont, _currentInfo, null); double w = fixedFt.Width; double h = fixedFt.Height; charHeight = Math.Max(fixedFt.Height, propFt.Height); charWidth = fixedFt.Width; double screenWidth = width - 20; double screenHeight = height - 20; if (os_._blorbFile != null) { var standard = os_._blorbFile.StandardSize; if (standard.Height > 0 && standard.Width > 0) { int maxW = (int)Math.Floor(width / os_._blorbFile.StandardSize.Width); int maxH = (int)Math.Floor(height / os_._blorbFile.StandardSize.Height); scale = Math.Min(maxW, maxH); screenWidth = os_._blorbFile.StandardSize.Width * scale; screenHeight = os_._blorbFile.StandardSize.Height * scale; double heightDiff = _parent.ActualHeight - this.ActualHeight; double widthDiff = _parent.ActualWidth - this.ActualWidth; _parent.Height = screenHeight + heightDiff; _parent.Width = screenWidth + widthDiff; } else { scale = 1; } } else { scale = 1; } ActualCharSize = new Size(propFt.Width, propFt.Height); chars = Convert.ToInt32(Math.Floor(screenWidth / charWidth)); // Determine chars based only on fixed width chars since proportional fonts are accounted for as they are written lines = Convert.ToInt32(Math.Floor(screenHeight / charHeight)); // Use the largest character height _metrics = new ScreenMetrics( new ZSize(charHeight, charWidth), // new ZSize(h, w), new ZSize(lines * charHeight, chars * charWidth), // The ZMachine wouldn't take screenHeight as round it down, so this takes care of that lines, chars, scale); _regularLines = new ScreenLines(_metrics.Rows, _metrics.Columns); _fixedWidthLines = new ScreenLines(_metrics.Rows, _metrics.Columns); AfterSetCharsAndLines(); }