public override IResource LoadContent(string filePath, string rzPath, string subPath,
                                              string contentType, XmlNodeList rzNodes,
                                              out IResource[] loadedDependants,
                                              out IResource[] loadedDependancies,
                                              DeviceInterface devIf)
        {
            ILog log = devIf.CDI.GeneralLog;

            log.AddItem(new LogItem(string.Format("Starting loading texture rz ([{0}]{1})", contentType, rzPath), LogItem.ItemLevel.DebugInfo));

            // load texture first
            ImageInformation imgInf  = TextureLoader.ImageInformationFromFile(filePath);
            Texture          texture = TextureLoader.FromFile(devIf.Device, filePath, imgInf.Width, imgInf.Height, 1, Usage.None,
                                                              imgInf.Format, Pool.Managed, Filter.None, Filter.None, 0);

            log.AddItem(new LogItem(string.Format("Loaded texture rz ([{0}]{1})", contentType, rzPath), LogItem.ItemLevel.DebugInfo));

            // process meta-data nodes
            TextureResource texRz = new TextureResource(rzPath, texture, null,
                                                        imgInf.Width, imgInf.Height);

            TextureResource.Icon[] icons = null;
            TextureResource.Icon   icon  = null;
            if (rzNodes != null)
            {
                foreach (XmlElement item in rzNodes)
                {
                    if (item.Name == "areas")
                    {
                        // process sub-areas
                        ProcessSubAreas(item, texRz, out icons, rzPath + ":areas:icon:");
                    }
                }
            }
            texRz.Icons = icons;

            /*if (subPath != null)
             * {
             *  loadedDependants = icons;
             *  loadedDependancies = new IResource[] { texRz };
             *  return
             * }
             * else
             * {*/
            loadedDependancies = null;
            loadedDependants   = icons;
            return(texRz);
            //}
        }
        public override IResource LoadContent(string filePath, string rzPath, string subPath, string contentType,
                                              XmlNodeList rzNode, out IResource[] loadedDependants,
                                              out IResource[] loadedDependancies, DeviceInterface devIf)
        {
            ILog log = devIf.CDI.GeneralLog;

            log.AddItem(new LogItem(string.Format("Starting loading script rz ([{0}]{1})", contentType, rzPath), LogItem.ItemLevel.DebugInfo));

            BooScript script = BooScript.LoadBooScript(rzPath, filePath);

            log.AddItem(new LogItem(string.Format("Loaded script rz ([{0}]{1})", contentType, rzPath), LogItem.ItemLevel.DebugInfo));

            loadedDependancies = null;
            loadedDependants   = null;

            return(script);
        }
Exemple #3
0
        protected virtual void CreateDevice()
        {
            try
            {
                // Create the device
                device = new Device(outSettings.Adapter, outSettings.DeviceType, targetRenderArea,
                                    outSettings.CreateFlags, presentParams);
                log.AddItem(new LogItem(string.Format("Created rendering device (adapter:{0},deviceType:{1},createFlags:{2},pp:{3})",
                                                      outSettings.Adapter, outSettings.DeviceType, outSettings.CreateFlags, presentParams.AutoDepthStencilFormat),
                                        LogItem.ItemLevel.Info));

                // Setup the event handlers for our device
                device.DeviceLost     += new System.EventHandler(this.DeviceLost);
                device.DeviceReset    += new System.EventHandler(this.DeviceReset);
                device.Disposing      += new System.EventHandler(this.DeviceDisposing);
                device.DeviceResizing += new System.ComponentModel.CancelEventHandler(this.DeviceResizing);

                // Initialize the app's device-dependent objects
                //try
                //{
                //    DeviceReset(null, null);
                isActive = true;
                //}
                //catch
                //{
                //    // Cleanup before we try again
                //    DeviceLost(null, null);
                //    DeviceDisposing(null, null);

                //    device.Dispose();
                //    device = null;
                //    //if (this.Disposing)
                //    //    return;
                //}
            }
            catch
            {
                // FIXME: If that failed, fall back to the reference rasterizer
                throw new Exception("Failed to create desired device");
            }
        }
Exemple #4
0
        public override IResource LoadContent(string filePath, string rzPath, string subPath,
                                              string contentType, XmlNodeList rzNode,
                                              out IResource[] loadedDependants,
                                              out IResource[] loadedDependancies, DeviceInterface devIf)
        {
            ILog log = devIf.CDI.GeneralLog;

            log.AddItem(new LogItem(string.Format("Starting loading layer rz ([{0}]{1})", contentType, rzPath), LogItem.ItemLevel.DebugInfo));

            XmlDocument xml = new XmlDocument();

            xml.Load(filePath);

            List <ISharableResource> sharedRzs = new List <ISharableResource>();

            // look for layer info
            XmlNode layerNode = xml.SelectSingleNode("/layer");
            Point   position = ParsePoint(layerNode.Attributes["position"].InnerText);
            Size    dimensions = ParseSize(layerNode.Attributes["size"].InnerText);
            string  booClass = null, booFile = null;

            if (layerNode.Attributes["classFile"] != null)
            {
                booFile = layerNode.Attributes["classFile"].InnerText;
            }
            if (layerNode.Attributes["className"] != null)
            {
                booClass = layerNode.Attributes["className"].InnerText;
            }

            // parse boo script file
            BooScript     script = null;
            StringBuilder scriptText;

            if (booFile != null && booClass != null)
            {
                string scriptRzPath = rzPath.Substring(0, rzPath.Length - Path.GetFileName(rzPath).Length) + booFile;
                log.AddItem(new LogItem(string.Format("Found Layer Script ({0})", scriptRzPath), LogItem.ItemLevel.DebugInfo));
                script     = (BooScript)devIf.GetSharedResource(scriptRzPath, ref sharedRzs);
                scriptText = new StringBuilder();
                scriptText.Append(script.Script);
            }
            else
            {
                log.AddItem(new LogItem("Generating Layer Script", LogItem.ItemLevel.DebugInfo));
                // build boo script for layer
                BooScriptBuilder.CreateClass(new string[] { "import Genetibase.VisUI.Scripting from \"NuGenVisUI\"" },
                                             "AutoGenLayer", "ScriptLayer", out scriptText);

                script   = new BooScript(scriptText.ToString(), null);
                booClass = "AutoGenLayer";
            }

            // load resources
            Dictionary <string, IResource> refRzs = new Dictionary <string, IResource>();
            XmlElement resourcesNode = (XmlElement)layerNode.SelectSingleNode("resources");

            foreach (XmlNode node in resourcesNode.ChildNodes)
            {
                if (node.NodeType != XmlNodeType.Comment)
                {
                    string    rzName = node.Attributes["name"].InnerText;
                    string    rzUrl  = node.Attributes["url"].InnerText;
                    IResource rz     = devIf.GetSharedResource(rzUrl, ref sharedRzs);
                    refRzs[rzName] = rz;
                }
            }

            SimpleGUILayer layer = new SimpleGUILayer(devIf, position, dimensions, rzPath, null, sharedRzs.ToArray());

            // pre-load script for layer
            XmlNode itemsNode = layerNode.SelectSingleNode("items");

            /*foreach (XmlNode node in itemsNode.ChildNodes)
             * {
             *  // parse common events
             *  if (node.Attributes["onclick"] != null)
             *  {
             *      string booCode = node.Attributes["onclick"].InnerText;
             *      // insert into script
             *      BooScriptBuilder.InsertFunction("", node.Name + "_onclick", "obj as object, args as MouseEventArgs", booCode, ref scriptText);
             *  }
             * }*/

            // compile new script
            log.AddItem(new LogItem(string.Format("Compiling Layer Script (Length: {0})", scriptText.Length), LogItem.ItemLevel.DebugInfo));
            script = new BooScript(scriptText.ToString(), null);
            if (script.Compile())
            {
                log.AddItem(new LogItem("Compiled Layer Script", LogItem.ItemLevel.Success));
            }
            else
            {
                log.AddItem(new LogItem("Failed to Compile Layer Script", LogItem.ItemLevel.Failure));
            }

            // create class instance
            Type        layerClass = script.GeneratedAssembly.GetType(booClass);
            ScriptLayer sLayer     = (ScriptLayer)script.GeneratedAssembly.CreateInstance(booClass);

            // load items
            Font font = new Font("Tahoma", 10);

            foreach (XmlNode node in itemsNode.ChildNodes)
            {
                // TODO: Parse layout instructions
                // TODO: Log building?
                // Parse common attributes
                GUIItemType_Config itemConf;
                Point pos  = Point.Empty;
                Size  size = Size.Empty;
                LayoutRules.Positioning xLayout        = LayoutRules.Positioning.Near;
                LayoutRules.Positioning yLayout        = LayoutRules.Positioning.Near;
                MouseEventHandler       onclickHandler = null;

                // parse and map common events
                if (node.Attributes["onclick"] != null)
                {
                    string methodName = node.Name + "_onclick";
                    BooScriptEventsBridge evBridge = new BooScriptEventsBridge(sLayer, layerClass.GetMethod(methodName));
                    onclickHandler = evBridge.MouseHandler;
                }

                if (guiItemsConfig.TryGetValue(node.Name, out itemConf))
                {
                    if (itemConf.usePos && node.Attributes["position"] != null)
                    {
                        pos = ParsePoint(node.Attributes["position"].InnerText);
                    }
                    if (itemConf.useSize && node.Attributes["size"] != null)
                    {
                        size = ParseSize(node.Attributes["size"].InnerText);
                    }
                    if (itemConf.useLayout && node.Attributes["layout"] != null)
                    {
                        ParseLayout(node.Attributes["layout"].InnerText, out xLayout, out yLayout);
                    }
                }
                GUILayerItem item = null;
                if (node.Name == "label")
                {
                    string text = node.Attributes["text"].InnerText;

                    item = new GUILabel(text, font, Color.Red, pos, Size.Empty);
                }
                else if (node.Name == "icon")
                {
                    string imgRz = node.Attributes["img"].InnerText;
                    TextureResource.Icon icon = (TextureResource.Icon)refRzs[imgRz];
                    bool highlight            = (node.Attributes["highlight"].InnerText == bool.TrueString);
                    bool enabled = (node.Attributes["enabled"].InnerText == bool.TrueString);

                    item = new GUIIcon(pos, size, icon, highlight, enabled);
                }

                if (item != null)
                {
                    item = LayoutManager.AlignItem(item, xLayout, yLayout);
                    if (onclickHandler != null)
                    {
                        layer.AddItem(item, null, null, onclickHandler);
                    }
                    else
                    {
                        layer.AddItem(item);
                    }
                }
            }

            log.AddItem(new LogItem(string.Format("Loaded layer rz ([{0}]{1})", contentType, rzPath), LogItem.ItemLevel.DebugInfo));

            loadedDependancies = null;
            loadedDependants   = null;

            return(layer);
        }