Exemple #1
0
 /// <summary>
 ///		Initializes a new instance of this class.
 /// </summary>
 /// <param name="width">Width of the resolution of this window.</param>
 /// <param name="height">Height of the resolution of this window.</param>
 /// <param name="flags">Decides how the window is created.</param>
 public GameWindow(int width, int height, GraphicsFlags flags)
 {
     InitializeComponent();
     _canvas = new GraphicsCanvas(this, 0, new CanvasRenderHandler(Render));
     GraphicsManager.RenderTarget = _canvas;
     Reset(width, height, flags);
 }
Exemple #2
0
        /// <summary>
        /// Creates a client window.
        /// </summary>
        public RootWindow(GraphicsDevice graphicsDevice, IWindowManager windowManager, string title, string titleGroup,
                          WindowOptions windowOptions, Vector2i position, Vector2i size, Vector2i?minSize, Vector2i?maxSize,
                          WindowState windowState, IWidget widget, uint multisampleCount, uint multisampleQuality)
        {
            // 1) Copy data.
            this.graphicsDevice = graphicsDevice;

            // 2) We create render target.
            TypelessTexture2D texture = new TypelessTexture2D(graphicsDevice, Usage.Default, TextureUsage.RenderTarget | TextureUsage.Texture,
                                                              CPUAccess.None, PixelFormat.Parse("R.UN8 G.UN8 B.UN8 A.UN8"), (uint)size.X, (uint)size.Y, 1,
                                                              multisampleCount, multisampleQuality, GraphicsLocality.DeviceOrSystemMemory, null);

            texture.DisposeOnViewDispose = true;

            Guid shareGuid = graphicsDevice.RegisterShared(texture, TextureUsage.Texture);

            RenderTargetView renderTarget = texture.CreateRenderTarget(
                PixelFormat.Parse("R.UN8 G.UN8 B.UN8 A.UN8"));

            window = windowManager.CreateWindow(shareGuid, title, titleGroup, this, windowOptions,
                                                position, size, minSize, maxSize, windowState, null, false);

            // 3) We create graphics canvas.
            GraphicsCanvas canvas = new GraphicsCanvas(graphicsDevice, renderTarget, new Vector2f(1, 1));

            // 4) We create GUI manager.
            GuiManager manager = new GuiManager(canvas);

            manager.RootObject    = widget;
            manager.PreRendering += new Action <GuiManager>(PreRenderingInternal);
            manager.Rendered     += new Action <GuiManager>(RenderedInternal);

            this.root = manager;
        }
        /// <summary>
        ///     Called when a new instance of this class is created.
        /// </summary>
        public BitmapFontSelectorWindow()
        {
            InitializeComponent();

            _canvas = new GraphicsCanvas(previewPanel, 0, new CanvasRenderHandler(RenderPreview));

            // Create a callback so we can render the canvas (it won't be done my the main loop due to
            // this window being show in model).
            Application.Idle += new EventHandler(Application_Idle);
        }
        /// <summary>
        ///     Initializes a new instance of this control.
        /// </summary>
        /// <param name="file">Tileset file to display.</param>
        public TilesetWindow(string file)
        {
            InitializeComponent();

            _canvas  = new GraphicsCanvas(canvasPanel, 0, Render);
            _tileset = new Tileset(file);

            TilesetWindow_ResizeEnd(null, new EventArgs());

            EventManager.AttachListener(_listener = new EventListener(EventCaptured));
        }
Exemple #5
0
        private static void DrawGraphics(ReticleDefinition reticle, string baseName)
        {
            var bm1    = new Bitmap(1024, 1024);
            var canvas = GraphicsCanvas.FromImage(bm1, Color.White);

            canvas.Clear();
            var controller = new ReticleDrawController(reticle, canvas);

            controller.DrawReticle();
            bm1.Save($"{baseName}-a.png", ImageFormat.Png);
        }
        /// <summary>
        ///     Called when the application is idle. This function is used to render the canvas.
        /// </summary>
        /// <param name="sender">Object that caused this event to be triggered.</param>
        /// <param name="e">Arguments explaining why this event occured.</param>
        void Application_Idle(object sender, EventArgs e)
        {
            if (Visible == false)
            {
                return;
            }

            while (NativeMethods.IsApplicationIdle == true)
            {
                GraphicsCanvas.RenderAll();
            }
        }
Exemple #7
0
        /// <summary>
        ///     Invoked when a new instance of this class is created.
        /// </summary>
        public EmitterEditorWindow()
        {
            InitializeComponent();

            _emitterProperties.Emitter = _emitterNode;
            _canvas = new GraphicsCanvas(previewPanel, 0, new CanvasRenderHandler(Render));

            // Create a callback so we can render the canvas (it won't be done my the main loop due to
            // this window being show in model).
            Application.Idle += new EventHandler(Application_Idle);

            SyncronizeTypes();
        }
        public TurntableCalibrationWindow(GraphicsCanvas canvas, ScanSettings settings)
        {
            InitializeComponent();
            Canvas     = canvas;
            Settings   = settings;
            Calibrator = new TurntableCalibrator();
            Matrix4x4 mInfraredIntrinsics = settings.InfraredIntrinsics.GrowToMatrix4x4();
            Matrix4x4 mDepthToIRMapping   = settings.DepthToIRMapping.ExpandToMatrix4x4();
            Matrix4x4 mDepthIntrinsics    = mDepthToIRMapping.Inverse * mInfraredIntrinsics;

            VI.WorldViewProjection = Matrix4x4.Scale(1d / KinectManager.DepthWidth, 1d / KinectManager.DepthHeight, 1d) * mDepthIntrinsics;

            SelectedRectangleA = settings.TurntableRectangleA.Value;
            SelectedRectangleB = settings.TurntableRectangleB.Value;
            SelectedEllipse    = settings.TurntableEllipse.Value;
            SetStep(0);
            Settings.ViewProperties.StoreAllValues();
            Settings.ViewProperties.ResetToDefault();
        }
        internal void UpdateImage()
        {
            if (Reticle.Size == null)
            {
                picturePreview.Image = null;
                return;
            }

            AppForm.CalculateReticleImageSize(picturePreview.Size.Width, picturePreview.Size.Height,
                                              Reticle.Size.X, Reticle.Size.Y, out int imageX, out int imageY);

            Bitmap                bm         = new Bitmap(imageX, imageY);
            GraphicsCanvas        canvas     = GraphicsCanvas.FromImage(bm, Color.White);
            ReticleDrawController controller = new ReticleDrawController(Reticle, canvas);

            canvas.Clear();
            controller.DrawElement(Path);
            picturePreview.Image = bm;
        }
        private async Task DrawLayersGeneral(Graphics graph, Func <ILayerDrawing, ICanvas, Task> drawLayerAction)
        {
            var layersDrawingSize = this.ControlCanvas.GetLayersDrawingSize();
            var graphCanvas       = new GraphicsCanvas(graph, this.ControlCanvas.Size.Width, this.ControlCanvas.Size.Height);
            int x = 0;

            _selectionResolver.SetCurrentRootCanvas(graphCanvas);

            IDictionary <NodeBase, INodeDrawing> previousNodesDic = new Dictionary <NodeBase, INodeDrawing>();

            var inputLayer  = this.ControlCanvas.Control.InputLayer;
            var preferences = this.ControlCanvas.Control.Preferences;

            LayerSizesPreCalc      layersCache      = new LayerSizesPreCalc(layersDrawingSize, inputLayer.GetMaxNodeCountInLayer(), preferences);
            SimpleNodeSizesPreCalc simpleNodesCache = new SimpleNodeSizesPreCalc();
            PerceptronSizesPreCalc perceptronCache  = new PerceptronSizesPreCalc(preferences);
            EdgeSizesPreCalc       edgesCache       = new EdgeSizesPreCalc();

            for (LayerBase layer = inputLayer; layer != null; layer = layer.Next)
            {
                ILayerDrawing layerDrawing = null;

                if (layer == inputLayer)
                {
                    layerDrawing = new InputLayerDrawing(layer as InputLayer, preferences, layersCache, simpleNodesCache, _selectionChecker, _selectableElementRegister);
                }
                else
                {
                    layerDrawing = new PerceptronLayerDrawing(layer as PerceptronLayer, previousNodesDic, graphCanvas, preferences, layersCache, perceptronCache, simpleNodesCache, edgesCache, _selectionChecker, _selectableElementRegister);
                }

                var canvasRect  = new Rectangle(x, 0, layersDrawingSize.Width, layersDrawingSize.Height);
                var layerCanvas = new NestedCanvas(canvasRect, graphCanvas);

                await drawLayerAction(layerDrawing, layerCanvas);

                previousNodesDic = layerDrawing.NodesDrawing.ToDictionary(n => n.Node, n => n);

                x += layersDrawingSize.Width;
            }
        }
        public BehaviorTreeControl( ) : base()
        {
            m_nodes = new List <BehaviorNodeControl>();

            m_nodeCache = new EditorNodeTypeCache();
            m_nodeCache.CacheAvailableNodes();

            AddDecorator(new Scrollbars());
            m_canvas = ( GraphicsCanvas )AddDecorator(new GraphicsCanvas());

            m_linkLine          = ( BezierCurve )m_canvas.AddShape(new BezierCurve(Vector2.zero, Vector2.zero, Color.red, 1.0f, BezierCurve.TangentMode.AutoY, Vector2.zero, Vector2.zero));
            m_linkLine.Tangents = BezierCurve.TangentMode.AutoY;

            ContextMenuControl ctx = new ContextMenuControl();

            foreach (EditorCachedNode node in m_nodeCache.Cache)
            {
                ctx.Menu.AddItem(new GUIContent(node.displayName), false, AddNode, node);
            }
            ctx.Positionless = true;
            AddChild(ctx);
        }
        public BehaviorNodeControl(EditorCachedNode node)
        {
            m_fieldControls = new Dictionary <string, Control>();
            m_node          = node;

            int lines = 0;

            foreach (EditorCachedNodeField field in node.fields)
            {
                Control fieldControl = null;
                int     l            = 0;

                // Create fields per type
                if (field.type == typeof(int))
                {
                    fieldControl = AddChild(new IntField(default(int), field.name));
                    l            = 1;
                }
                else if (field.type == typeof(float))
                {
                    fieldControl = AddChild(new FloatField(default(float), field.name));
                    l            = 1;
                }
                else if (field.type == typeof(Vector2))
                {
                    fieldControl = AddChild(new Vector2Field(default(Vector2), field.name));
                    l            = 2;
                }
                else if (field.type == typeof(Vector3))
                {
                    fieldControl = AddChild(new Vector3Field(default(Vector3), field.name));
                    l            = 2;
                }
                else if (field.type == typeof(Vector4))
                {
                    fieldControl = AddChild(new Vector4Field(default(Vector4), field.name));
                    l            = 2;
                }
                else if (field.type == typeof(string))
                {
                    fieldControl = AddChild(new TextField("", field.name));
                    l            = 1;
                }
                else if (field.type == typeof(Rect))
                {
                    fieldControl = AddChild(new RectField(default(Rect), field.name));
                    l            = 3;
                }
                else if (field.type == typeof(Color))
                {
                    fieldControl = AddChild(new ColorField(default(Color), field.name));
                    l            = 1;
                }
                else if (field.type == typeof(Bounds))
                {
                    fieldControl = AddChild(new BoundsField(default(Bounds), field.name));
                    l            = 3;
                }
                else if (field.type.IsEnum)
                {
                    fieldControl = AddChild(new EnumDropdown((System.Enum)Activator.CreateInstance(field.type), field.name));
                    l            = 1;
                }
                else if (field.type == typeof(bool))
                {
                    fieldControl = AddChild(new Toggle(field.name, false, false));
                    l            = 1;
                }
                else if (field.type == typeof(GameObject))
                {
//                    fieldControl = AddChild(new ObjectField(typeof(GameObject), true, null, "Object Target"));
                    fieldControl = AddChild(new ObjectField(new Vector2(50, 50), new Vector2(50, 10), typeof(GameObject), true, null, "Object Target"));
                    l            = 1;
                }
                else
                {
                    Debug.LogWarning(string.Format("Unsupported field type `{0}({1})` encountered in node `{2}`", field.name, field.type, node.displayName));
                }

                if (fieldControl != null)
                {
                    m_fieldControls.Add(field.name, fieldControl);

                    fieldControl
                    .SetPosition(INNER_PADDING, HEADER_SIZE + LINE_SIZE * lines)
                    .SetSize(BOX_WIDTH - INNER_PADDING - INNER_PADDING, LINE_SIZE);

                    lines += l;
                }
            }

            if (m_node.nodeType != BehaviorTrees.BehaviorNodeAttribute.NodeType.Leaf)
            {
                lines++;    // Add extra line of padding at the bottom
            }

            m_canvas = (GraphicsCanvas)AddDecorator(new GraphicsCanvas());

            SetHeight(HEADER_SIZE + FOOTER_PADDING + LINE_SIZE * lines);

            // Create outputs
            m_outputs       = new List <BehaviorNodeControl>();
            m_outputButtons = new List <Button>();
            m_outputLines   = new List <BezierCurve>();

            UpdateOutputs();
        }
Exemple #13
0
        /// <summary>
        ///		Called by the base engine class when its safe to update and render the scene.
        /// </summary>
        protected override void Update()
        {
            // Ignore everything else if we are not running a game.
            if (_gameName == "")
            {
                return;
            }

            //System.Console.WriteLine("Collective Time("+EntityNode.CollectiveCalls+" calls): "+EntityNode.CollectiveTime);
            //EntityNode.CollectiveTime = 0.0f;
            //EntityNode.CollectiveCalls = 0;
            //EntityNode.CollectiveTimer.Restart();

            // Time to load a map?
            if (_mapLoadPending == true)
            {
                // Pump out a MapFinish event.
                EventManager.FireEvent(new Event("map_finish", this, null));

                // Allow the processes some time to be notified of closing events.
                //EventManager.ProcessEvents();
                //ProcessManager.RunProcesses(1);

                // Tell the scripts that we are now loading the new map (so they can show a loadings screen).
                _gameScriptProcess.Process.InvokeFunction("OnLoadingBegin", true, true);

                // Don't want to render the scene graph as its currently being loaded >.<.
                bool priorSceneGraphRender = true;
                if (_isServer == false)
                {
                    priorSceneGraphRender       = _window.RenderSceneGraph;
                    _window.RenderLoadingScreen = true;
                    _window.RenderSceneGraph    = false;
                }

                // Keep track of time :).
                HighPreformanceTimer loadTimer = new HighPreformanceTimer();

                // Get starting memory.
                long startingMemory = GC.GetTotalMemory(true);

                if (GraphicsManager.ThreadSafe == false)
                {
                    // Load the new map.
                    DebugLogger.WriteLog("Loading map from " + _mapLoadFile + " " + (_mapLoadPassword != "" ? " with password " + _mapLoadPassword : "") + ".");
                    LoadMapThread();
                }
                else
                {
                    // Load the new map.
                    DebugLogger.WriteLog("Loading map from " + _mapLoadFile + " " + (_mapLoadPassword != "" ? " with password " + _mapLoadPassword : "") + ".");
                    Thread thread = new Thread(LoadMapThread);
                    thread.Priority = ThreadPriority.Highest;
                    // Thread.CurrentThread.Priority = ThreadPriority.Lowest;
                    thread.IsBackground = true;
                    thread.Start();

                    // Ech, there has to be a better way than this. I hate thread safety >.>.
                    HighPreformanceTimer timer = new HighPreformanceTimer();
                    while (thread != null && thread.IsAlive == true)
                    {
                        // Track frame stats.
                        TrackFrameStatsBegin();

                        // Update the process.
                        //timer = new HighPreformanceTimer();
                        //_gameScriptProcess.Run(_deltaTime);
                        //_processProcessingDuration = (float)timer.DurationMillisecond;

                        // Update the graphical console.
                        if (_isServer == false)
                        {
                            GraphicalConsole.Update(1.0f);
                        }

                        // Tell the window to render
                        if (_isServer == false)
                        {
                            timer.Restart();
                            GraphicsCanvas.RenderAll();
                            _window.Render();
                            _renderingDuration = (float)timer.DurationMillisecond;
                        }

                        // Update network.
                        NetworkManager.Poll();

                        // Process application level events.
                        timer.Restart();
                        Application.DoEvents();
                        _applicationProcessingDuration = (float)timer.DurationMillisecond;

                        // Track frame stats.
                        TrackFrameStatsFinish();
                    }
                }

                // Invoke OnCreate events of scripted entities.
                foreach (SceneNode node in _map.SceneGraph.EnumerateNodes())
                {
                    if (node != null && node is ScriptedEntityNode && node.IsPersistent == false)
                    {
                        ((ScriptedEntityNode)node).ScriptProcess[0].InvokeFunction("OnCreate", true, false);
                    }
                }

                // Run the collision manager quickly so that we can sort out any unplesent problems.
                CollisionManager.ProcessCollisions();

                //Thread.CurrentThread.Priority = ThreadPriority.Normal;

                // We can render again! Oh holy days!
                if (_isServer == false)
                {
                    _window.RenderLoadingScreen = false;
                    _window.RenderSceneGraph    = priorSceneGraphRender;
                }

                // Remove any old resource from the cache that haven't been used for 5 maps :P.
                ResourceManager.CollectGarbage(3);

                // Free up some space.
                GC.Collect();

                // And we are done!
                DebugLogger.WriteLog("Map loaded successfully in " + loadTimer.DurationMillisecond + "ms, " + (((GC.GetTotalMemory(false) - startingMemory) / 1024.0f) / 1024.0f) + "mb allocated during loading.");

                // Yay, loaded!
                _mapLoadPending = false;

                // Reset the delta time!
                _forcedDeltaTimeThisFrame = 1.0f;
            }
        }
Exemple #14
0
 public void AddCanvas(GraphicsCanvas canvas)
 {
     _page.AddCanvas(canvas);
 }