Ejemplo n.º 1
0
        static void Init()
        {
            var font = new Font("Assets/NotoSans-Regular.ttf", FontCharSet.BasicLatin);
            var size = new FontSize(font, 128f);

            var builder = new AtlasBuilder(2048);

            builder.AddBitmap("Assets/star.png", true, true);
            builder.AddBitmap("Assets/face.png", true, true);
            builder.AddBitmap("Assets/maritte.png", true, true);
            builder.AddFont("font", size, true);

            atlas = builder.Build(1);
            if (atlas == null)
            {
                throw new Exception("Failed to build atlas.");
            }

            batch  = new DrawBatch2D();
            shader = new Shader(Shader.Basic2D);

            view = new GuiView(shader, Screen.DrawWidth, Screen.DrawHeight, LayoutMode.Horizontal);
            view.BackgroundColor = Color4.Grey;
            view.Spacing         = 16;
            view.SetPadding(16);

            var left = view.AddChild(new GuiContainer());

            left.BackgroundColor = Color4.Black * 0.25f;
            left.FlexX           = left.FlexY = true;
            left.Spacing         = 16;

            var right = view.AddChild(new GuiContainer());

            right.BackgroundColor = Color4.Blue;
            right.FlexX           = right.FlexY = true;

            var items = left.AddChild(new GuiContainer());

            items.BackgroundColor = Color4.Black * 0.25f;
            items.FlexX           = items.FlexY = true;
            items.Spacing         = 1;
            items.ScrollableY     = true;

            var padding = left.AddChild(new GuiContainer(100, 100, LayoutMode.Vertical));

            padding.BackgroundColor = Color4.White * 0.25f;
            padding.FlexX           = true;
            padding.FlexY           = false;

            for (int i = 0; i < 50; ++i)
            {
                var item = items.AddChild(new GuiElement(16, 40));
                item.FlexY     = false;
                item.OnRender += b => b.DrawRect(item.RectX, item.RectY, item.RectW, item.RectH, Color4.Red);
            }

            Screen.ClearColor = Color4.Black;
            Screen.OnResized += () => view.SetSize(Screen.DrawWidth, Screen.DrawHeight);
        }
    private void InitView()
    {
        _view = new GuiView(new Rect(5, 5, 890, 590));

        GuiButton button = new GuiButton(new Rect(0, 0, 110, 20), "刷新资源数据库");

        button.RegisterHandler(RefreshAssets);
        _view.AddChild(button);

        button = new GuiButton(new Rect(340, 2, 16, 16), "?");
        button.RegisterHandler(ShowHelpInfo);
        _view.AddChild(button);

        _searchTextField = new GuiSearchTextField(new Rect(130, 1, 196, 20));
        _searchTextField.OnTextChange(OnSearchTextChange);
        _view.AddChild(_searchTextField);

        _timeLabel = new GuiLabel(new Rect(400, 0, 500, 20), "");
        _view.AddChild(_timeLabel);

        _assetDataSelectedGrid = new GuiSelectionGrid(new Rect(0, 35, 200, 20), new string[] { "资源列表", "无引用资源" }, new Action[] { ShowAllAssets, ShowUnusedAssets });
        _view.AddChild(_assetDataSelectedGrid);

        _dependenceSelectedGrid = new GuiSelectionGrid(new Rect(345, 35, 200, 20), new string[] { "资源依赖项", "反向引用" }, new Action[] { ShowDependencies, ShowRedependencies });
        _view.AddChild(_dependenceSelectedGrid);

        GuiScrollView scrollView = new GuiScrollView(new Rect(0, 60, 320, 530));

        _view.AddChild(scrollView);

        _assetDatafoldoutTree = new GuiFoldoutTree(new Rect(0, 60, 320, 3000));
        _assetDatafoldoutTree.AttachDrawer(new AssetDatasDrawer(_assetDatafoldoutTree));
        scrollView.AddChild(_assetDatafoldoutTree);

        scrollView = new GuiScrollView(new Rect(340, 60, 550, 530));
        _view.AddChild(scrollView);

        _dependencefoldoutTree = new GuiFoldoutTree(new Rect(340, 60, 320, 3000));
        _dependencefoldoutTree.AttachDrawer(new DependenceInfoDrawer(_dependencefoldoutTree));
        scrollView.AddChild(_dependencefoldoutTree);
    }