/// <summary>
        /// Draw the voxel editor and interface
        /// </summary>
        public override void Draw(TimeSpan frameStepTime)
        {
            game.GraphicsDevice.Clear(new Color(64, 64, 64));
            gridRenderer.Draw(spriteBatch.GraphicsDevice, editorCamera);

            base.Draw(frameStepTime);
        }
示例#2
0
        private void Render()
        {
            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

            GL.MatrixMode(MatrixMode.Modelview);
            GL.LoadIdentity();
            Matrix4 modelview = Matrix4.LookAt(0, 0, _realCamera.Z, 0, 0, 0, 0, 1, 0);

            GL.LoadMatrix(ref modelview);

            GL.Rotate(_realCamera.Yaw, Vector3.UnitX);
            GL.Rotate(_realCamera.Roll, Vector3.UnitY);
            GL.Rotate(_realCamera.Pan, Vector3.UnitZ);

            //Draw things
            GL.Color3(Color);
            GL.PointSize(PointSize);
            GL.Disable(EnableCap.Lighting);
            _pointCloudRenderer.Draw();
            _gridRenderer.Draw();
            GL.Enable(EnableCap.Lighting);
            _objectRenderer.Draw();

            SwapBuffers();
        }
示例#3
0
        protected override void OnDraw(SpriteBatch batch)
        {
            GraphicsDevice.Clear(AppColors.WindowBackground);

            batch.Begin(SpriteSortMode.FrontToBack);

            // grid
            GridRenderer.Draw(batch, new Vector2(AppConstants.GridX, AppConstants.GridY));

            batch.End();


            batch.Begin();

            var y = AppConstants.GridY + 10;

            // time
            batch.DrawBitmapFont(AppContents.DefaultFont, new Vector2(AppConstants.GridRight, y), "Time:", AppColors.Descriptions);
            batch.DrawBitmapFont(AppContents.DefaultFont, new Vector2(AppConstants.WindowWidth - AppConstants.ScreenPadding - 140, y), TimeSpan.FromSeconds(Session.Time).ToString(@"hh\:mm\:ss"), AppColors.Texts);
            y += AppContents.DefaultFont.Data.LineHeight + 15;

            // score
            batch.DrawBitmapFont(AppContents.DefaultFont, new Vector2(AppConstants.GridRight, y), $"Score:", AppColors.Descriptions);
            batch.DrawBitmapFont(AppContents.DefaultFont, new Vector2(AppConstants.WindowWidth - AppConstants.ScreenPadding - 140, y), Session.Score.ToString("n0"), AppColors.Texts);
            y += AppContents.DefaultFont.Data.LineHeight + 15;

            batch.DrawBitmapFont(AppContents.DefaultFont, new Vector2(AppConstants.GridRight, y), $"Atoms:", AppColors.Descriptions);
            batch.DrawBitmapFont(AppContents.DefaultFont, new Vector2(AppConstants.WindowWidth - AppConstants.ScreenPadding - 140, y), Session.Atoms.ToString("n0"), AppColors.Texts);
            y += AppContents.DefaultFont.Data.LineHeight + 5;

            batch.DrawBitmapFont(AppContents.DefaultFont, new Vector2(AppConstants.GridRight, y), $"Molecules:", AppColors.Descriptions);
            batch.DrawBitmapFont(AppContents.DefaultFont, new Vector2(AppConstants.WindowWidth - AppConstants.ScreenPadding - 140, y), Session.Molecules.ToString("n0"), AppColors.Texts);
            y += AppContents.DefaultFont.Data.LineHeight + 5;

            // current/next atom
            y = AppConstants.WindowHeight - AppConstants.ScreenPadding - AppConstants.PreviewBoxHeight - AppContents.DefaultFont.Data.LineHeight - 8;

            batch.DrawBitmapFont(AppContents.DefaultFont, new Vector2(AppConstants.GridRight, y), "Current", AppColors.Descriptions);
            batch.DrawBitmapFont(AppContents.DefaultFont, new Vector2(AppConstants.GridRight + AppConstants.PreviewBoxWidth + AppConstants.PreviewBoxPadding, y), "Next", AppColors.Descriptions);
            y += AppContents.DefaultFont.Data.LineHeight + 8;

            batch.DrawRect(new Rectangle(AppConstants.GridRight, y, AppConstants.PreviewBoxWidth, AppConstants.PreviewBoxHeight), 1, AppColors.PreviewBorder);
            batch.DrawRect(new Rectangle(AppConstants.GridRight + AppConstants.PreviewBoxWidth + AppConstants.PreviewBoxPadding, y, AppConstants.PreviewBoxWidth, AppConstants.PreviewBoxHeight), 1, AppColors.PreviewBorder);

            if (Session.CurrentAtom != null)
            {
                Session.CurrentAtom.Draw(batch,
                                         pos: new Vector2(
                                             AppConstants.GridRight + AppConstants.PreviewBoxWidth / 2,
                                             y + AppConstants.PreviewBoxHeight / 2), layerDepth: LayerDepth.Default);
            }

            if (Session.NextAtom != null)
            {
                Session.NextAtom.Draw(batch,
                                      pos: new Vector2(
                                          AppConstants.GridRight + AppConstants.PreviewBoxWidth + AppConstants.PreviewBoxPadding + AppConstants.PreviewBoxWidth / 2,
                                          y + AppConstants.PreviewBoxHeight / 2),
                                      layerDepth: LayerDepth.Default);
            }

            // atom grid preview
            if (Session.CurrentAtom != null && IsMouseOverGrid() && IsOnTop)
            {
                var gridPos = GetMouseGridPos();

                if (Grid.IsValidPos(gridPos.X, gridPos.Y) && !Grid.HasAtom(gridPos.X, gridPos.Y))
                {
                    if (Grid.CanSet(gridPos.X, gridPos.Y, Session.CurrentAtom))
                    {
                        Session.CurrentAtom.Draw(batch, new Vector2(
                                                     AppConstants.GridX + gridPos.X * Grid.TileSize + Grid.TileSize / 2,
                                                     AppConstants.GridY + gridPos.Y * Grid.TileSize + Grid.TileSize / 2),
                                                 LayerDepth.Default,
                                                 AppColors.AtomValidPos);
                    }
                    else
                    {
                        Session.CurrentAtom.Draw(batch, new Vector2(
                                                     AppConstants.GridX + gridPos.X * Grid.TileSize + Grid.TileSize / 2,
                                                     AppConstants.GridY + gridPos.Y * Grid.TileSize + Grid.TileSize / 2),
                                                 LayerDepth.Default,
                                                 AppColors.AtomInvalidPos);
                    }
                }
            }

            batch.End();
        }
示例#4
0
		void OnGUI () {
			if (_gridRenderer == null) _gridRenderer = new GridRenderer();
			Event currentEvent = Event.current;

			Rect scrollViewRect = new Rect(0, 0, position.width - SidebarWidth, position.height);
			Rect sidebarRect = new Rect(position.width - SidebarWidth, 0, SidebarWidth, position.height);

			OperatorInspector.DrawInspector(sidebarRect);

			ScrollPoint = GUI.BeginScrollView(scrollViewRect, ScrollPoint, Canvas);

			bool needsRepaint = false;

			// Mouse wheel event to control zoom
			if (currentEvent.type == EventType.ScrollWheel) {

				float previousZoom = Zoom;
				Vector2 pivotPoint = currentEvent.mousePosition / Zoom;
				float wheelDelta = Event.current.delta.y > 0 ? -0.1f : 0.1f;

				// Apply the delta to the zoom level and clamp to min and max
				Zoom = (Zoom + wheelDelta).Clamp(MinZoom, MaxZoom);
				Zoom = (float) System.Math.Round(Zoom, 2);
				
				if (previousZoom != Zoom) {
					// Keep the viewport anchored to the position of the mouse cursor
					float zoomDelta = Zoom - previousZoom;
					ScrollPoint += pivotPoint * zoomDelta;

					// Repaint if there was a zoom change (after clamping)
					needsRepaint = true;
				}

				currentEvent.Use();
			}

			Canvas = new Rect(0f, 0f, CanvasWidth * Zoom, CanvasHeight * Zoom);

			_gridRenderer.Draw(ScrollPoint, Zoom, Canvas);

			if (Template != null) {

				// Draw the connections
				Template.DrawConnections();

				// Draw the nodes
				string[] guids = new string[Template.Operators.Count];
				Template.Operators.Keys.CopyTo(guids, 0);
				for (int i = 0; i < guids.Length; i++) {
					Node node = GetNode(guids[i]); // kvp.Key = GUID
					needsRepaint = needsRepaint || node.EventsNeedRepaint(Zoom, this);
					node.Draw(Zoom);
				}

				// Handle left mouse button events
				if (currentEvent.button == 0) {

					// MouseDown
					if (currentEvent.type == EventType.MouseDown && CurrentEvent.Type == GEType.None) {
						CurrentEvent = new GraphEvent(GEType.Unresolved, GEContext.Grid, null, IOOutlet.None, currentEvent.mousePosition);
					}

					// MouseDrag
					if (currentEvent.type == EventType.MouseDrag && CurrentEvent.IsType(GEType.Unresolved, GEType.Drag) && CurrentEvent.Context == GEContext.Grid) {
						if (currentEvent.delta.magnitude > 0) {
							CurrentEvent = new GraphEvent(GEType.Drag, GEContext.Grid, null, IOOutlet.None);
							ScrollPoint.x += - currentEvent.delta.x;
							ScrollPoint.y += - currentEvent.delta.y;
							needsRepaint = true;
						}
					}

					// MouseUp
					if (currentEvent.type == EventType.MouseUp) {
						if (CurrentEvent.Type == GEType.Unresolved && CurrentEvent.Context == GEContext.Grid) {
							Selection.Clear();
							needsRepaint = true;
						}
						needsRepaint = needsRepaint || CurrentEvent.IsConnecting();
						CurrentEvent.Empty();
					}

				} // Left mouse down/drag/up

				// Right mouse button
				if (currentEvent.type == EventType.ContextClick) {
					var menu = new GenericMenu();

					var opTypes = Operator.GetAvailableOperators();
					foreach (var opType in opTypes) {
						string menuLabel = opType.Name;
						var meta = System.Attribute.GetCustomAttribute(opType, typeof(OperatorMetadataAttribute)) as OperatorMetadataAttribute;
						if (meta != null) {
							menuLabel = meta.Category + "/" + (meta.Title != null ? meta.Title : opType.Name);
						}
						var payload = new MenuActionPayload() {OperatorType=opType, Position=currentEvent.mousePosition / Zoom};
						menu.AddItem(new GUIContent(menuLabel), false, MenuAction, payload);
					}

					menu.ShowAsContext();
				}

				if (currentEvent.isKey && currentEvent.keyCode == KeyCode.Delete) {
					foreach (var node in Selection.Nodes) {
						Template.RemoveOperator(node.Operator);
					}
					Selection.Clear();
					needsRepaint = true;
				}

			}

			if (needsRepaint) {
				Repaint();
			}

			GUI.EndScrollView();

			// Current Zoom level
			float zoomLabelWidth = 150f;
			float zoomLabelHeight = 20f;
			Rect zoomLabelRect = new Rect(position.width - SidebarWidth - zoomLabelWidth - 20f, position.height - zoomLabelHeight - 20f, zoomLabelWidth, zoomLabelHeight);
			if (LabelStyle == null) {
				LabelStyle = new GUIStyle();
				LabelStyle.normal.textColor = Color.white;
				LabelStyle.alignment = TextAnchor.LowerRight;
			}
			GUI.Label(zoomLabelRect, string.Format("Zoom: {0}%", Zoom * 100f), LabelStyle);

		} // OnGUI