Example #1
0
 public void HandleInput(Point loc, SideBarState state)
 {
     if (GotInput != null && rect.BoundingBox.Contains(loc))
     {
         GotInput(state);
     }
 }
Example #2
0
 public void SetSideBarState(SideBarState state)
 {
     if (!state.Equals(sidebarState))
     {
         sidebarState = state;
         OnStateChanged(state);
     }
 }
Example #3
0
 public Rectangle2D(Vector2 pos, int sizeX, int sizeY, Color4 col, Action <object> act, SideBarState state, object data = null, Texture2D tex = null) : this(pos, sizeX, sizeY, col, tex)
 {
     Data      = data;
     GotInput += s => { if (state.HasFlag(s))
                        {
                            act(this);
                        }
     };
 }
Example #4
0
        public SideBar(TextureInput iHandler)
        {
            inputHandler = iHandler;

            sideBarBackground.Add(new Rectangle2D(new Vector2(0, 0), Width, Config.Height, Color.FromArgb(200, 200, 200, 200)));
            sideBarBackground.Add(new Rectangle2D(new Vector2(0, 0), Width / 2, (int)(0.074 * Config.Height), Color.DimGray, (s) => State = SideBarState.LeftTab, SideBarState.RightTab));           // left tab
            GotInputClick += sideBarBackground.Last().HandleInput;
            sideBarBackground.Add(new Rectangle2D(new Vector2(Width / 2f, 0), Width / 2, (int)(0.074 * Config.Height), activeTabColor, (s) => State = SideBarState.RightTab, SideBarState.LeftTab)); //right tab
            GotInputClick += sideBarBackground.Last().HandleInput;
            rightTab.Add(new Rectangle2D(new Vector2(0, Config.Height - (int)(0.093 * Config.Height)), Width, (int)(0.093 * Config.Height), Color.DimGray, (s) => State = SideBarState.Minimized, SideBarState.LeftTab | SideBarState.RightTab));
            GotInputClick += rightTab.Last().HandleInput;
            maximize       = new Rectangle2D(new Vector2(0, 0), MinimizedWidth, Config.Height, Color.FromArgb(200, 200, 200, 200), (s) => State = SideBarState.RightTab, SideBarState.Minimized);
            GotInputClick += maximize.HandleInput;

            var leftTabString  = new DrawableString("Muster", new Vector2((float)0.1625 * Width, 5) + offset, Color.White);
            var rightTabString = new DrawableString("Einstellungen", new Vector2(Width / 2f + (float)0.0625 * Width, 5) + offset, Color.White);
            var minimizeString = new DrawableString("Einklappen", new Vector2((float)0.35 * Width, Config.Height - (int)(0.06 * Config.Height)), Color.White);

            maximizeString = new DrawableString(">", new Vector2((float)0.0125 * Width, Config.Height / 2f), Color.White);

            var pausebtn = new Rectangle2D(new Vector2((float)0.0625 * Width, (int)(0.093 * Config.Height)), (int)(0.25 * Width), (int)(0.074 * Config.Height), Color.DimGray, (s) => Config.Paused = !Config.Paused, SideBarState.RightTab);

            rightTab.Add(pausebtn);
            GotInputClick += pausebtn.HandleInput;
            var clearbtn = new Rectangle2D(new Vector2((float)0.0625 * Width * 2 + (int)(0.25 * Width), (int)(0.093 * Config.Height)), (int)(0.25 * Width), (int)(0.074 * Config.Height), Color.DimGray, (s) => inputHandler.ClearWorld(), SideBarState.RightTab);

            rightTab.Add(clearbtn);
            GotInputClick += clearbtn.HandleInput;
            var closebtn = new Rectangle2D(new Vector2((float)0.0625 * Width * 3 + (int)(0.25 * Width) * 2, (int)(0.093 * Config.Height)), (int)(0.25 * Width), (int)(0.074 * Config.Height), Color.DarkRed, (s) => RenderFrame.Instance.Exit(), SideBarState.RightTab);

            rightTab.Add(closebtn);
            GotInputClick += closebtn.HandleInput;

            //Farben
            int colorSize = (int)(0.0463 * Config.Height);

            rightTab.Add(new Rectangle2D(new Vector2((float)0.1875 * Width, 0) + 16 * offset, colorSize, colorSize, Color.Red, (s) => inputHandler.ChangeColor(new Color4(1, 1, 0, 0)), SideBarState.RightTab));
            GotInputClick += rightTab.Last().HandleInput;
            rightTab.Add(new Rectangle2D(new Vector2((float)0.375 * Width, 0) + 16 * offset, colorSize, colorSize, Color.Green, (s) => inputHandler.ChangeColor(new Color4(1, 0, 1, 0)), SideBarState.RightTab));
            GotInputClick += rightTab.Last().HandleInput;
            rightTab.Add(new Rectangle2D(new Vector2((float)0.5625 * Width, 0) + 16 * offset, colorSize, colorSize, Color.Blue, (s) => inputHandler.ChangeColor(new Color4(1, 0, 0, 1)), SideBarState.RightTab));
            GotInputClick += rightTab.Last().HandleInput;
            rightTab.Add(new Rectangle2D(new Vector2((float)0.75 * Width, 0) + 16 * offset, colorSize, colorSize, Color.Black, (s) => inputHandler.ChangeColor(new Color4(1, 0, 0, 0)), SideBarState.RightTab));
            GotInputClick += rightTab.Last().HandleInput;

            // Birth setting buttons
            for (int i = 0; i < 9; i++)
            {
                birth.Add(new Rectangle2D(new Vector2((float)0.175 * Width, (int)(-0.011 * Config.Height)) + (23 + i * 3) * offset, (int)(0.25 * Width), (int)(0.046 * Config.Height), (Config.BirthRule & 1 << i) > 0 ? Color.Green : Color.DimGray, OnBirthChanged, SideBarState.RightTab, i));
            }
            // Death setting buttons
            for (int i = 0; i < 9; i++)
            {
                death.Add(new Rectangle2D(new Vector2((float)0.625 * Width, (int)(-0.011 * Config.Height)) + (23 + i * 3) * offset, (int)(0.25 * Width), (int)(0.046 * Config.Height), (Config.DeathRule & 1 << i) > 0 ? Color.Green : Color.DimGray, OnDeathChanged, SideBarState.RightTab, i));
            }

            foreach (var r in birth.Concat(death))
            {
                rightTab.Add(r);
                GotInputClick += r.HandleInput;
            }
            var size = DrawableString.Measure("Pause");

            rightTabStrings.Add(new DrawableString("Pause", pausebtn.Location + pausebtn.Size / 2 - size / 2, Color.White));
            size = DrawableString.Measure("Leeren");
            rightTabStrings.Add(new DrawableString("Leeren", clearbtn.Location + clearbtn.Size / 2 - size / 2, Color.White));
            rightTabStrings.Add(new DrawableString("Leben", new Vector2((float)0.2 * Width, 0) + 20 * offset, Color.White));
            rightTabStrings.Add(new DrawableString("Tod", new Vector2((float)0.7 * Width, 0) + 20 * offset, Color.White));
            size = DrawableString.Measure("Beenden");
            rightTabStrings.Add(new DrawableString("Beenden", closebtn.Location + closebtn.Size / 2 - size / 2, Color.White));
            rightTabStrings.Add(new DrawableString("Farbe", new Vector2(10, 10) + 16 * offset, Color.White));
            for (int i = 0; i < 9; i++)
            {
                rightTabStrings.Add(new DrawableString(i.ToString(), new Vector2((float)0.025 * Width, 0) + (23 + 3 * i) * offset, Color.White));
            }
            rightTabStrings.Add(minimizeString);

            rightTabStrings.Add(rightTabString);
            leftTabStrings.Add(rightTabString);

            rightTabStrings.Add(leftTabString);
            leftTabStrings.Add(leftTabString);
        }
Example #5
0
 protected void OnStateChanged(SideBarState state)
 {
     SideBarStateChanged?.Invoke(state);
 }
Example #6
0
        public SideBar(TextureInput iHandler)
        {
            inputHandler = iHandler;

            var d = RenderFrame.Instance.device;

            screenshotTex = Texture2D.FromFile(d, @".\Content\floppy_save.png");
            fileLoadTex   = Texture2D.FromFile(d, @".\Content\file_open.png");
            minusTex      = Texture2D.FromFile(d, @".\Content\minus.png");
            plusTex       = Texture2D.FromFile(d, @".\Content\plus.png");

            playTex   = Texture2D.FromFile(d, @".\Content\playpause.png");
            clearTex  = Texture2D.FromFile(d, @".\Content\clear.png");
            exitTex   = Texture2D.FromFile(d, @".\Content\exit.png");
            cornerTex = Texture2D.FromFile(d, @".\Content\corner.png");

            // hintergrund
            sideBarBackground.Add(new Rectangle2D(new Vector2(0, 0), Width, Config.Height, Color.FromArgb(200, 200, 200, 200)));
            // 2 button oben zum umschalten zwischen den tabs
            rightTab.Add(new Rectangle2D(new Vector2(0, 0), Width / 2, (int)(0.074 * Config.Height), Color.DimGray, (s) => State = SideBarState.LeftTab, SideBarState.RightTab));         // left tab
            GotInputClick += rightTab.Last().HandleInput;
            leftTab.Add(new Rectangle2D(new Vector2(Width / 2f, 0), Width / 2, (int)(0.074 * Config.Height), Color.DimGray, (s) => State = SideBarState.RightTab, SideBarState.LeftTab)); //right tab
            GotInputClick += leftTab.Last().HandleInput;

            sideBarBackground.Add(new Rectangle2D(new Vector2(0, Config.Height - (int)(0.074 * Config.Height)), Width, (int)(0.093 * Config.Height), Color.DimGray, (s) => State = SideBarState.Minimized, SideBarState.LeftTab | SideBarState.RightTab));
            GotInputClick += sideBarBackground.Last().HandleInput;
            maximize       = new Rectangle2D(new Vector2(0, 0), MinimizedWidth, Config.Height, Color.FromArgb(200, 200, 200, 200), (s) => State = SideBarState.RightTab, SideBarState.Minimized);
            GotInputClick += maximize.HandleInput;

            var leftTabString  = new DrawableString("Muster", new Vector2((float)0.1625 * Width, 5) + offset, Color.White);
            var rightTabString = new DrawableString("Allgemein", new Vector2(Width / 2f + (float)0.11 * Width, 5) + offset, Color.White);
            var minimizeString = new DrawableString("Einklappen", new Vector2((float)0.35 * Width, Config.Height - (int)(0.05 * Config.Height)), Color.White);

            maximizeString = new DrawableString(">", new Vector2((float)0.0125 * Width, Config.Height / 2f), Color.White);

            int btnSize = (int)(0.15 * Width);

            var closebtn = new Rectangle2D(new Vector2(0.1875f * Width, 0.093f * Config.Height), btnSize, btnSize, Color.OrangeRed, (s) => RenderFrame.Instance.Exit(), SideBarState.RightTab, null, exitTex);

            rightTab.Add(closebtn);
            GotInputClick += closebtn.HandleInput;
            var pausebtn = new Rectangle2D(new Vector2(0.5625f * Width, 0.093f * Config.Height), btnSize, btnSize, Color.White, (s) => { Config.Paused = !Config.Paused; }, SideBarState.RightTab, null, playTex);

            rightTab.Add(pausebtn);
            GotInputClick += pausebtn.HandleInput;
            var clearbtn = new Rectangle2D(new Vector2(0.375f * Width, 0.093f * Config.Height), btnSize, btnSize, Color.White, (s) => inputHandler.ClearWorld(), SideBarState.RightTab, null, clearTex);

            rightTab.Add(clearbtn);
            GotInputClick += clearbtn.HandleInput;
            rightTab.Add(new Rectangle2D(new Vector2(0.75f * Width, 0.093f * Config.Height), btnSize, btnSize, Color.White, (s) => SamplerStates.Instance.SwitchWrapMode(), SideBarState.RightTab, null, cornerTex));
            GotInputClick += rightTab.Last().HandleInput;


            //Farben
            rightTab.Add(new Rectangle2D(new Vector2(0.1875f * Width, 0.27f * Config.Height), btnSize, btnSize, Color.Red, (s) => inputHandler.ChangeColor(new Color4(1, 1, 0, 0)), SideBarState.RightTab));
            GotInputClick += rightTab.Last().HandleInput;
            rightTab.Add(new Rectangle2D(new Vector2(0.375f * Width, 0.27f * Config.Height), btnSize, btnSize, Color.Green, (s) => inputHandler.ChangeColor(new Color4(1, 0, 1, 0)), SideBarState.RightTab));
            GotInputClick += rightTab.Last().HandleInput;
            rightTab.Add(new Rectangle2D(new Vector2(0.5625f * Width, 0.27f * Config.Height), btnSize, btnSize, Color.Blue, (s) => inputHandler.ChangeColor(new Color4(1, 0, 0, 1)), SideBarState.RightTab));
            GotInputClick += rightTab.Last().HandleInput;
            rightTab.Add(new Rectangle2D(new Vector2(0.75f * Width, 0.27f * Config.Height), btnSize, btnSize, Color.Black, (s) => inputHandler.ChangeColor(new Color4(1, 0, 0, 0)), SideBarState.RightTab));
            GotInputClick += rightTab.Last().HandleInput;

            rightTab.Add(new Rectangle2D(new Vector2(0.1875f * Width, 0.18f * Config.Height), btnSize, btnSize, Color.White, (s) => MakeScreenshot(), SideBarState.RightTab, null, screenshotTex));
            GotInputClick += rightTab.Last().HandleInput;
            rightTab.Add(new Rectangle2D(new Vector2(0.375f * Width, 0.18f * Config.Height), btnSize, btnSize, Color.White, (s) => LoadFile(), SideBarState.RightTab, null, fileLoadTex));
            GotInputClick += rightTab.Last().HandleInput;
            rightTab.Add(new Rectangle2D(new Vector2(0.5625f * Width, 0.18f * Config.Height), btnSize, btnSize, Color.White, (s) => Config.LineThickness--, SideBarState.RightTab, null, minusTex));
            GotInputClick += rightTab.Last().HandleInput;
            rightTab.Add(new Rectangle2D(new Vector2(0.75f * Width, 0.18f * Config.Height), btnSize, btnSize, Color.White, (s) => Config.LineThickness++, SideBarState.RightTab, null, plusTex));
            GotInputClick += rightTab.Last().HandleInput;

            // Birth setting buttons
            for (int i = 1; i < 9; i++)
            {
                birth.Add(new Rectangle2D(new Vector2((float)0.175 * Width, (int)(-0.011 * Config.Height)) + (24 + i * 3) * offset, (int)(0.25 * Width), (int)(0.046 * Config.Height), (Config.BirthRule & 1 << i) > 0 ? Color.Green : Color.DimGray, OnBirthChanged, SideBarState.RightTab, i));
            }
            // Death setting buttons
            for (int i = 1; i < 9; i++)
            {
                death.Add(new Rectangle2D(new Vector2((float)0.625 * Width, (int)(-0.011 * Config.Height)) + (24 + i * 3) * offset, (int)(0.25 * Width), (int)(0.046 * Config.Height), (Config.DeathRule & 1 << i) > 0 ? Color.Green : Color.DimGray, OnDeathChanged, SideBarState.RightTab, i));
            }

            foreach (var r in birth.Concat(death))
            {
                rightTab.Add(r);
                GotInputClick += r.HandleInput;
            }
            rightTabStrings.Add(new DrawableString("Leben", new Vector2((float)0.235 * Width, 0) + 24 * offset, Color.White));
            rightTabStrings.Add(new DrawableString("Tod", new Vector2((float)0.705 * Width, 0) + 24 * offset, Color.White));
            rightTabStrings.Add(new DrawableString("Farbe", new Vector2(10, 0.275f * Config.Height + btnSize / 2f - offset.Y), Color.White));
            for (int i = 1; i < 9; i++)
            {
                rightTabStrings.Add(new DrawableString(i.ToString(), new Vector2((float)0.10 * Width, 0) + (24 + 3 * i) * offset, Color.White));
            }
            rightTabStrings.Add(minimizeString);
            leftTabStrings.Add(minimizeString);

            rightTabStrings.Add(rightTabString);
            leftTabStrings.Add(rightTabString);

            rightTabStrings.Add(leftTabString);
            leftTabStrings.Add(leftTabString);

            sliderbackground = new Rectangle2D(new Vector2(0.1875f * Width, (int)(0.36f * Config.Height)), (int)(0.714f * Width), (int)(0.046 * Config.Height), Color.DarkGray, s => speed = location.X, SideBarState.RightTab);
            slider           = new Rectangle2D(new Vector2(0.1875f * Width, (int)(0.36f * Config.Height)), (int)(0.02 * Width), (int)(0.046 * Config.Height), Color.White);
            GotInputClick   += sliderbackground.HandleInput;

            rightTabStrings.Add(new DrawableString("Langsam", new Vector2(sliderbackground.Location.X + 10, sliderbackground.Location.Y + sliderbackground.Size.Y / 2 - DrawableString.Measure("a", 1).Y / 2), Color.White, 1));
            rightTabStrings.Add(new DrawableString("Schnell", new Vector2(sliderbackground.Location.X + sliderbackground.Size.X - 10 - DrawableString.Measure("Schnell", 1).X, sliderbackground.Location.Y + sliderbackground.Size.Y / 2 - DrawableString.Measure("a", 1).Y / 2), Color.White, 1));

            rightTab.Add(sliderbackground);
            rightTab.Add(slider);

            pm = new PatternManager(0, (int)(0.074 * Config.Height), Width, Config.Height - 2 * (int)(0.074 * Config.Height), this); //oberen und unteren button abziehen ....

            speed = 0.1875f * Width * 3f;

            Config.RulesChanged += Config_RulesChanged;
        }