public NativeDesignControl(DesignView designView) : base(designView) { ClientSize = new Size(10, 10); if (!GameEngine.IsInError) { swapChainId = GameEngine.GetObjectTypeId("SwapChain"); SurfaceId = GameEngine.CreateObject(swapChainId, this.Handle, IntPtr.Size); SizePropId = GameEngine.GetObjectPropertyId(swapChainId, "Size"); GameEngine.SetObjectProperty(swapChainId, SurfaceId, SizePropId, ClientSize); BkgColorPropId = GameEngine.GetObjectPropertyId(swapChainId, "BkgColor"); GameEngine.SetObjectProperty(swapChainId, SurfaceId, BkgColorPropId, BackColor); } if (s_marqueePen == null) { s_marqueePen = new Pen(Color.FromArgb(30, 30, 30), 2); s_marqueePen.DashPattern = new float[] { 3, 3 }; } m_renderState = new RenderState(); m_renderState.RenderFlag = GlobalRenderFlags.Solid | GlobalRenderFlags.Textured | GlobalRenderFlags.Lit | GlobalRenderFlags.Shadows; m_renderState.WireFrameColor = Color.DarkBlue; m_renderState.SelectionColor = Color.FromArgb(66, 255, 161); BackColor = SystemColors.ControlDark; m_renderState.Changed += (sender, e) => Invalidate(); }
public RenderState() { string typeName = typeof(RenderState).Name; m_typeId = GameEngine.GetObjectTypeId(typeName); m_intanceId = GameEngine.CreateObject(m_typeId, IntPtr.Zero, 0); m_renderFlagId = GameEngine.GetObjectPropertyId(m_typeId, "GlobalRenderFlags"); m_wirecolorId = GameEngine.GetObjectPropertyId(m_typeId, "WireframeColor"); m_selColorId = GameEngine.GetObjectPropertyId(m_typeId, "SelectionColor"); }
public ImageData(ulong instanceId) { TypeId = GameEngine.GetObjectTypeId("ImageData"); LoadFromFileId = GameEngine.GetObjectPropertyId(TypeId, "LoadFromFile"); ConvertId = GameEngine.GetObjectPropertyId(TypeId, "Convert"); BufferPointerId = GameEngine.GetObjectPropertyId(TypeId, "BufferPointer"); WidthId = GameEngine.GetObjectPropertyId(TypeId, "Width"); HeightId = GameEngine.GetObjectPropertyId(TypeId, "Height"); BytesPerPixelId = GameEngine.GetObjectPropertyId(TypeId, "BytesPerPixel"); RowPitchId = GameEngine.GetObjectPropertyId(TypeId, "RowPitch"); FormatId = GameEngine.GetObjectPropertyId(TypeId, "Format"); m_instanceId = instanceId; if (m_instanceId == 0) { m_manageLifetime = true; m_instanceId = GameEngine.CreateObject(TypeId, IntPtr.Zero, 0); } RefreshCachedProperties(); }
public TextureRenderSurface(int width, int height) { Size sz = new Size(width, height); IntPtr ptr = IntPtr.Zero; unsafe { ptr = new IntPtr(&sz); }; int sizeInBytes = System.Runtime.InteropServices.Marshal.SizeOf(sz); string typeName = this.GetType().Name; m_typeId = GameEngine.GetObjectTypeId(typeName); BkgColorPropId = GameEngine.GetObjectPropertyId(m_typeId, "BkgColor"); m_intanceId = GameEngine.CreateObject(0, 0, m_typeId, null); }
void IInitializable.Initialize() { m_controlInfo = new ControlInfo("DesignView", "DesignView", StandardControlGroup.CenterPermanent); m_controlHostService.RegisterControl(m_designView.HostControl, m_controlInfo, this); Application.ApplicationExit += delegate { Util3D.Shutdown(); GameEngine.Shutdown(); }; GameEngine.RefreshView += (sender, e) => m_designView.InvalidateViews(); m_gameDocumentRegistry.DocumentAdded += m_gameDocumentRegistry_DocumentAdded; m_gameDocumentRegistry.DocumentRemoved += m_gameDocumentRegistry_DocumentRemoved; string ns = m_schemaLoader.NameSpace; // register GridRenderer on grid child. DomNodeType gridType = m_schemaLoader.TypeCollection.GetNodeType(ns, "gridType"); gridType.Define(new ExtensionInfo <GridRenderer>()); // register NativeGameWorldAdapter on game type. m_schemaLoader.GameType.Define(new ExtensionInfo <NativeDocumentAdapter>()); // parse schema annotation. foreach (DomNodeType domType in m_schemaLoader.TypeCollection.GetNodeTypes()) { var topLevelAnnotations = domType.GetTagLocal <IEnumerable <XmlNode> >(); if (topLevelAnnotations == null) { continue; } // First, go through and interpret the annotations that are not inherited List <NativeAttributeInfo> nativeAttribs = new List <NativeAttributeInfo>(); foreach (XmlNode annot in topLevelAnnotations) { XmlElement elm = annot as XmlElement; if (elm.LocalName == NativeAnnotations.NativeType) { string typeName = elm.GetAttribute(NativeAnnotations.NativeName); domType.SetTag(NativeAnnotations.NativeType, GameEngine.GetObjectTypeId(typeName)); if (domType.IsAbstract == false) { domType.Define(new ExtensionInfo <NativeObjectAdapter>()); } } else if (elm.LocalName == NativeAnnotations.NativeDocumentType) { string typeName = elm.GetAttribute(NativeAnnotations.NativeName); domType.SetTag(NativeAnnotations.NativeDocumentType, GameEngine.GetDocumentTypeId(typeName)); if (domType.IsAbstract == false) { domType.Define(new ExtensionInfo <NativeDocumentAdapter>()); } } } if (domType.GetTag(NativeAnnotations.NativeType) == null) { continue; } uint typeId = (uint)domType.GetTag(NativeAnnotations.NativeType); bool isBoundableType = false; // Now, go through and interpret annotations that can be inheritted from base clases. // Sometimes a native property can be inheritted from a base class. In this model, we // will create a separate "property id" for each concrete class. When a property is // inheritted, the "property ids" for each type in the inheritance chain will be different // and unrelated. foreach (var inherittedType in domType.Lineage) { var annotations = inherittedType.GetTagLocal <IEnumerable <XmlNode> >(); if (annotations == null) { continue; } foreach (XmlNode annot in annotations) { XmlElement elm = annot as XmlElement; if (elm.LocalName == NativeAnnotations.NativeProperty) { // find a prop name and added to the attribute. string nativePropName = elm.GetAttribute(NativeAnnotations.NativeName); string attribName = elm.GetAttribute(NativeAnnotations.Name); uint propId = GameEngine.GetObjectPropertyId(typeId, nativePropName); if (!string.IsNullOrEmpty(attribName)) { AttributeInfo attribInfo = domType.GetAttributeInfo(elm.GetAttribute(NativeAnnotations.Name)); attribInfo.SetTag(NativeAnnotations.NativeProperty, propId); } else { NativeAttributeInfo attribInfo = new NativeAttributeInfo(domType, nativePropName, typeId, propId); nativeAttribs.Add(attribInfo); } if (nativePropName == "Bounds" || nativePropName == "LocalBounds") { isBoundableType = true; } } else if (elm.LocalName == NativeAnnotations.NativeElement) { ChildInfo info = domType.GetChildInfo(elm.GetAttribute(NativeAnnotations.Name)); string name = elm.GetAttribute(NativeAnnotations.NativeName); info.SetTag(NativeAnnotations.NativeElement, GameEngine.GetObjectChildListId(typeId, name)); } else if (elm.LocalName == NativeAnnotations.NativeVis) { using (var transfer = new NativeObjectAdapter.NativePropertyTransfer()) { using (var stream = transfer.CreateStream()) foreach (var a in elm.Attributes) { var attrib = a as XmlAttribute; if (attrib.Name == "geo") { NativeObjectAdapter.PushAttribute( 0, typeof(string), 1, attrib.Value, transfer.Properties, stream); } } GameEngine.SetTypeAnnotation(typeId, "vis", transfer.Properties); } } } } if (nativeAttribs.Count > 0) { domType.SetTag(nativeAttribs.ToArray()); } if (isBoundableType && domType.IsAbstract == false) { domType.Define(new ExtensionInfo <BoundableObject>()); } } // register BoundableObject m_schemaLoader.GameObjectFolderType.Define(new ExtensionInfo <BoundableObject>()); // doesn't have a bound native attributes -- is this really intended?s #region code to handle gameObjectFolder { // This code is fragile and need to be updated whenever // any relevant part of the schema changes. // purpose: // gameObjectFolderType does not exist in C++ // this code will map gameObjectFolderType to gameObjectGroupType. DomNodeType gobFolderType = m_schemaLoader.GameObjectFolderType; DomNodeType groupType = m_schemaLoader.GameObjectGroupType; // map native bound attrib from gameObject to GobFolder NativeAttributeInfo[] nativeAttribs = m_schemaLoader.GameObjectType.GetTag <NativeAttributeInfo[]>(); foreach (var attrib in nativeAttribs) { if (attrib.Name == "Bounds") { gobFolderType.SetTag(new NativeAttributeInfo[] { attrib }); break; } } // map type. // XLE --> Separate GameObjectFolder type from GameObjectGroup type // gobFolderType.Define(new ExtensionInfo<NativeObjectAdapter>()); // gobFolderType.SetTag(NativeAnnotations.NativeType, groupType.GetTag(NativeAnnotations.NativeType)); // map all native attributes of gameObjectGroup to gameFolder foreach (AttributeInfo srcAttrib in groupType.Attributes) { object nativeIdObject = srcAttrib.GetTag(NativeAnnotations.NativeProperty); if (nativeIdObject == null) { continue; } AttributeInfo destAttrib = gobFolderType.GetAttributeInfo(srcAttrib.Name); if (destAttrib == null) { continue; } destAttrib.SetTag(NativeAnnotations.NativeProperty, nativeIdObject); destAttrib.SetTag(NativeAnnotations.MappedAttribute, srcAttrib); } // map native element from gameObjectGroupType to gameObjectFolderType. object gobsId = groupType.GetChildInfo("gameObject").GetTag(NativeAnnotations.NativeElement); foreach (ChildInfo srcChildInfo in gobFolderType.Children) { if (srcChildInfo.IsList) { srcChildInfo.SetTag(NativeAnnotations.NativeElement, gobsId); } } m_schemaLoader.GameType.GetChildInfo("gameObjectFolder").SetTag(NativeAnnotations.NativeElement, gobsId); } #endregion // set up scripting bindings if (m_scriptingService != null) { m_scriptingService.SetVariable("cv", new GUILayer.TweakableBridge()); } }
void IInitializable.Initialize() { m_controlInfo = new ControlInfo("DesignView", "DesignView", StandardControlGroup.CenterPermanent); m_controlHostService.RegisterControl(m_designView.HostControl, m_controlInfo, this); Application.ApplicationExit += delegate { Util3D.Shutdown(); GameEngine.Shutdown(); }; GameEngine.RefreshView += (sender, e) => m_designView.InvalidateViews(); m_gameDocumentRegistry.DocumentAdded += m_gameDocumentRegistry_DocumentAdded; m_gameDocumentRegistry.DocumentRemoved += m_gameDocumentRegistry_DocumentRemoved; string ns = m_schemaLoader.NameSpace; // register GridRenderer on grid child. DomNodeType gridType = m_schemaLoader.TypeCollection.GetNodeType(ns, "gridType"); gridType.Define(new ExtensionInfo <GridRenderer>()); // register NativeGameWorldAdapter on game type. m_schemaLoader.GameType.Define(new ExtensionInfo <NativeGameWorldAdapter>()); // parse schema annotation. foreach (DomNodeType domType in m_schemaLoader.TypeCollection.GetNodeTypes()) { IEnumerable <XmlNode> annotations = domType.GetTagLocal <IEnumerable <XmlNode> >(); if (annotations == null) { continue; } // collect all the properties that only exist in native side. List <NativeAttributeInfo> nativeAttribs = new List <NativeAttributeInfo>(); foreach (XmlNode annot in annotations) { XmlElement elm = annot as XmlElement; if (elm.LocalName == NativeAnnotations.NativeType) { string typeName = elm.GetAttribute(NativeAnnotations.NativeName); domType.SetTag(NativeAnnotations.NativeType, GameEngine.GetObjectTypeId(typeName)); if (domType.IsAbstract == false) { domType.Define(new ExtensionInfo <NativeObjectAdapter>()); } } else if (elm.LocalName == NativeAnnotations.NativeProperty) { // find a prop name and added to the attribute. string nativePropName = elm.GetAttribute(NativeAnnotations.NativeName); string attribName = elm.GetAttribute(NativeAnnotations.Name); uint typeId = (uint)domType.GetTag(NativeAnnotations.NativeType); uint propId = GameEngine.GetObjectPropertyId(typeId, nativePropName); if (!string.IsNullOrEmpty(attribName)) { AttributeInfo attribInfo = domType.GetAttributeInfo(elm.GetAttribute(NativeAnnotations.Name)); attribInfo.SetTag(NativeAnnotations.NativeProperty, propId); } else { NativeAttributeInfo attribInfo = new NativeAttributeInfo(domType, nativePropName, typeId, propId); nativeAttribs.Add(attribInfo); } } else if (elm.LocalName == NativeAnnotations.NativeElement) { ChildInfo info = domType.GetChildInfo(elm.GetAttribute(NativeAnnotations.Name)); uint typeId = (uint)domType.GetTag(NativeAnnotations.NativeType); string name = elm.GetAttribute(NativeAnnotations.NativeName); info.SetTag(NativeAnnotations.NativeElement, GameEngine.GetObjectChildListId(typeId, name)); } } if (nativeAttribs.Count > 0) { domType.SetTag(nativeAttribs.ToArray()); } } // register BoundableObject m_schemaLoader.GameObjectType.Define(new ExtensionInfo <BoundableObject>()); m_schemaLoader.GameObjectFolderType.Define(new ExtensionInfo <BoundableObject>()); #region code to handle gameObjectFolder { // This code is fragile and need to be updated whenever // any relevant part of the schema changes. // purpose: // gameObjectFolderType does not exist in C++ // this code will map gameObjectFolderType to gameObjectGroupType. DomNodeType gobFolderType = m_schemaLoader.GameObjectFolderType; DomNodeType groupType = m_schemaLoader.GameObjectGroupType; // map native bound attrib from gameObject to GobFolder NativeAttributeInfo[] nativeAttribs = m_schemaLoader.GameObjectType.GetTag <NativeAttributeInfo[]>(); foreach (var attrib in nativeAttribs) { if (attrib.Name == "Bounds") { gobFolderType.SetTag(new NativeAttributeInfo[] { attrib }); break; } } // map type. gobFolderType.Define(new ExtensionInfo <NativeObjectAdapter>()); gobFolderType.SetTag(NativeAnnotations.NativeType, groupType.GetTag(NativeAnnotations.NativeType)); // map all native attributes of gameObjectGroup to gameFolder foreach (AttributeInfo srcAttrib in groupType.Attributes) { object nativeIdObject = srcAttrib.GetTag(NativeAnnotations.NativeProperty); if (nativeIdObject == null) { continue; } AttributeInfo destAttrib = gobFolderType.GetAttributeInfo(srcAttrib.Name); if (destAttrib == null) { continue; } destAttrib.SetTag(NativeAnnotations.NativeProperty, nativeIdObject); destAttrib.SetTag(NativeAnnotations.MappedAttribute, srcAttrib); } // map native element from gameObjectGroupType to gameObjectFolderType. object gobsId = groupType.GetChildInfo("gameObject").GetTag(NativeAnnotations.NativeElement); foreach (ChildInfo srcChildInfo in gobFolderType.Children) { if (srcChildInfo.IsList) { srcChildInfo.SetTag(NativeAnnotations.NativeElement, gobsId); } } m_schemaLoader.GameType.GetChildInfo("gameObjectFolder").SetTag(NativeAnnotations.NativeElement, gobsId); } #endregion }
public NativeViewControl() { ClientSize = new Size(16, 16); if (!GameEngine.IsInError) { swapChainId = GameEngine.GetObjectTypeId("SwapChain"); SurfaceId = GameEngine.CreateObject(swapChainId, this.Handle, IntPtr.Size); SizePropId = GameEngine.GetObjectPropertyId(swapChainId, "Size"); GameEngine.SetObjectProperty(swapChainId, SurfaceId, SizePropId, ClientSize); BkgColorPropId = GameEngine.GetObjectPropertyId(swapChainId, "BkgColor"); GameEngine.SetObjectProperty(swapChainId, SurfaceId, BkgColorPropId, BackColor); } m_renderState = new RenderState(); m_renderState.RenderFlag = GlobalRenderFlags.Solid | GlobalRenderFlags.Textured | GlobalRenderFlags.Lit; m_renderState.WireFrameColor = Color.DarkBlue; m_renderState.SelectionColor = Color.FromArgb(66, 255, 161); BackColor = SystemColors.ControlDark; #region Context menu GlobalRenderFlags[] flags = new GlobalRenderFlags[] { GlobalRenderFlags.Solid, GlobalRenderFlags.WireFrame, GlobalRenderFlags.Textured, GlobalRenderFlags.RenderBackFace, GlobalRenderFlags.Lit }; ContextMenuStrip cntx = new ContextMenuStrip(); foreach (var flag in flags) { ToolStripMenuItem item = new ToolStripMenuItem(flag.ToString()); item.Tag = flag; item.Click += delegate(object sender, EventArgs e) { ToolStripMenuItem menu = (ToolStripMenuItem)sender; RenderState.RenderFlag = RenderState.RenderFlag ^ (GlobalRenderFlags)menu.Tag; this.Invalidate(); }; cntx.Items.Add(item); } cntx.Items.Add(new ToolStripSeparator()); ToolStripMenuItem views = new ToolStripMenuItem("View"); cntx.Items.Add(views); views.DropDownOpening += delegate { foreach (ToolStripMenuItem item in views.DropDownItems) { item.Checked = (ViewType == (ViewTypes)item.Tag); } }; foreach (var val in Enum.GetValues(typeof(ViewTypes))) { ViewTypes viewtype = (ViewTypes)val; ToolStripMenuItem item = new ToolStripMenuItem(viewtype.ToString()); item.Tag = viewtype; item.Click += delegate(object sender, EventArgs e) { ToolStripMenuItem menuItem = (ToolStripMenuItem)sender; this.ViewType = (ViewTypes)menuItem.Tag; }; views.DropDownItems.Add(item); } cntx.Opening += delegate { GlobalRenderFlags renderflags = RenderState.RenderFlag; foreach (ToolStripItem item in cntx.Items) { if (item is ToolStripSeparator) { break; } ((ToolStripMenuItem)item).Checked = (renderflags & (GlobalRenderFlags)item.Tag) != 0; } }; this.ContextMenuStrip = cntx; #endregion }