Example #1
0
        internal void InitControls()
        {
            if (__controlsInitialized)
            {
                throw new Exception("Controls reinitialized");
            }
            var ctrl = new ControlBase(Canvas);

            ctrl.Name = "buttons";
            var pos = 0;
            Func <Bitmap, Bitmap, string, string, ImageButton> createbutton =
                delegate(Bitmap bmp, Bitmap bmp2, string tooltip, string name)
            {
                var ret = new ImageButton(ctrl)
                {
                    Name = name
                };
                if (tooltip != null)
                {
                    ret.SetToolTipText(tooltip);
                }
                ret.SetImage(bmp, bmp2);
                ret.SetSize(32, 32);
                ret.X = pos;
                pos  += 32;
                return(ret);
            };
            //Warning:
            //the name parameter needs to stay consistent for these buttons
            //other parts of code reference it.
            var btn = createbutton(GameResources.pencil_icon, GameResources.pencil_icon_white, "Pencil Tool (Q)", "penciltool");

            btn.Clicked += (o, e) => { SetTool(Tools.PencilTool); };
            btn          = createbutton(GameResources.line_icon, GameResources.line_icon_white, "Line Tool (W)", "linetool");
            btn.Clicked += (o, e) => { SetTool(Tools.LineTool); };
            btn          = createbutton(GameResources.eraser_icon, GameResources.eraser_icon_white, "Eraser Tool (E)", "erasertool");
            btn.Clicked += (o, e) => { SetTool(Tools.EraserTool); };
            btn          = createbutton(GameResources.line_adjust_icon, GameResources.line_adjust_icon_white, "Line Adjustment Tool (R)",
                                        "lineadjusttool");
            btn.Clicked += (o, e) => { SetTool(Tools.LineAdjustTool); };
            //  btn = createbutton(Content.gwell_tool, Content.gwell_tool, "Gravity Well Tool (T)",
            //       "gwelltool");
            //   btn.Clicked += (o, e) => { SetTool(Tools.GwellTool); };
            btn          = createbutton(GameResources.move_icon, GameResources.move_icon_white, "Hand Tool (Space) (T)", "handtool");
            btn.Clicked += (o, e) =>
            {
                SetTool(Tools.HandTool);
                _handToolOverride = false;
            };
            btn          = createbutton(GameResources.play_icon, GameResources.play_icon_white, "Start (Y)", "start");
            btn.Clicked += (o, e) =>
            {
                if (Track.Animating && Track.Paused)
                {
                    Track.TogglePause();
                }
                else
                {
                    Track.Start();
                }
            };
            pos              -= 32; //occupy same space as the start button
            btn               = createbutton(GameResources.pause, GameResources.pause_white, null, "pause");
            btn.IsHidden      = true;
            btn.Clicked      += (o, e) => { Track.TogglePause(); };
            btn               = createbutton(GameResources.stop_icon, GameResources.stop_icon_white, "Stop (U)", "stop");
            btn.Clicked      += (o, e) => { Track.Stop(); };
            btn               = createbutton(GameResources.flag_icon, GameResources.flag_icon_white, "Flag (I)", "flag");
            btn.Clicked      += (o, e) => { Track.Flag(); };
            btn.RightClicked += (o, e) => { Canvas.CalculateFlag(Track.GetFlag()); };
            Canvas.FlagTool   = btn;
            btn               = createbutton(GameResources.menu_icon, GameResources.menu_icon_white, "Menu", "menu");
            var _menuEdit = new Menu(Canvas);
            var item      = _menuEdit.AddItem("Save");

            item.AutoSizeToContents = false;
            item.Clicked           += (snd, evt) => { Canvas.ShowSaveWindow(); };
            item = _menuEdit.AddItem("Load");
            item.AutoSizeToContents = false;
            item.Clicked           += (snd, evt) => { Canvas.ShowLoadWindow(); };
            item = _menuEdit.AddItem("Delete");
            item.AutoSizeToContents = false;
            item.Clicked           += (snd, evt) => { Canvas.ShowDelete(); };
            item = _menuEdit.AddItem("Preferences");
            item.AutoSizeToContents = false;
            item.Clicked           += (snd, msg) => { Canvas.ShowPreferences(); };
            item = _menuEdit.AddItem("Song");
            item.AutoSizeToContents = false;
            item.Clicked           += (snd, msg) => { Canvas.ShowSongWindow(); };
            item = _menuEdit.AddItem("Export SOL");
            item.AutoSizeToContents = false;
            item.Clicked           += (snd, msg) => { Track.ExportAsSol(); };
            item = _menuEdit.AddItem("Export Video");
            item.AutoSizeToContents = false;
            item.Clicked           += (snd, msg) =>
            {
                if (SafeFrameBuffer.CanRecord)
                {
                    ExportVideoWindow x = new ExportVideoWindow(Canvas, this);

                    x.Show();
                    x.SetPosition(RenderSize.Width / 2 - (x.Width / 2), RenderSize.Height / 2 - (x.Height / 2));
                }
                else
                {
                    var wc = PopupWindow.Create(Canvas, this, "This computer does not support recording.\nTry updating your graphics drivers.", "Error!", true, false);
                    wc.FindChildByName("Okay", true).Clicked += (o, e) => { wc.Close(); };
                }
            };
            btn.Clicked += (o, e) =>
            {
                var canvaspos = ctrl.LocalPosToCanvas(new Point(btn.X, btn.Y));
                _menuEdit.MoveTo(canvaspos.X, canvaspos.Y + 32);
                _menuEdit.Show();
            };
            _menuEdit.DeleteOnClose = false;
            _menuEdit.Close();
            var cc = new ColorControls(ctrl, new Vector2(0, 32 + 3));

            cc.Selected          = LineType.Blue;
            Canvas.ColorControls = cc;
            ctrl.SizeToChildren();
            ctrl.ShouldCacheToTexture = true;
            ctrl.Position(Pos.CenterH);

            __controlsInitialized = true;
            Canvas.ButtonsToggleNightmode();
        }