Ejemplo n.º 1
0
        async Task InitTransformOperationAssist(EngineNS.CRenderContext rc)
        {
            for (int i = 0; i < (int)enTransformOPHandleType.Count; i++)
            {
                var imgInit = new EngineNS.UISystem.Controls.ImageInitializer();
                imgInit.ImageBrush.ImageName = EngineNS.RName.GetRName("uieditor/uva_op_pin.uvanim", EngineNS.RName.enRNameType.Editor);
                imgInit.ImageBrush.TileMode  = EngineNS.UISystem.Brush.enTileMode.None;
                var img = new EngineNS.UISystem.Controls.Image();
                await img.Initialize(rc, imgInit);

                img.Visibility = EngineNS.UISystem.Visibility.Collapsed;

                var rect   = new EngineNS.RectangleF(0, 0, 16, 16);
                var uvAnim = await EngineNS.CEngine.Instance.UVAnimManager.GetUVAnimAsync(rc, imgInit.ImageBrush.ImageName);

                if (uvAnim != null && uvAnim.Frames.Count > 0)
                {
                    await uvAnim.WaitTextureValid(rc);

                    var width  = uvAnim.PixelWidth * uvAnim.Frames[0].SizeU;
                    var height = uvAnim.PixelHeight * uvAnim.Frames[0].SizeV;
                    rect = new EngineNS.RectangleF(0, 0, width, height);
                }

                mTransformHandles[i] = new TransformHandleData()
                {
                    Show    = img,
                    SrcRect = rect,
                };
            }
        }
Ejemplo n.º 2
0
        internal async Task OnReceiveSelectUIs(EngineNS.UISystem.UIElement[] selectedUIs)
        {
            mSelectedUIDatas.Clear();
            if (selectedUIs != null)
            {
                foreach (var ui in selectedUIs)
                {
                    var data = new EngineNS.UISystem.Editor.SelectedData();
                    data.UI        = ui;
                    data.StartRect = ui.DesignRect;
                    var rc           = EngineNS.CEngine.Instance.RenderContext;
                    var showRectInit = new EngineNS.UISystem.Controls.ImageInitializer();
                    showRectInit.ImageBrush.ImageName = EngineNS.RName.GetRName("uieditor/uva_selectrect.uvanim", EngineNS.RName.enRNameType.Editor);
                    showRectInit.ImageBrush.TileMode  = EngineNS.UISystem.Brush.enTileMode.None;
                    var showRect = new EngineNS.UISystem.Controls.Image();
                    await showRect.Initialize(rc, showRectInit);

                    data.ShowRect = showRect;

                    mSelectedUIDatas[ui] = data;
                }
            }
            await InitSlotOperator();

            UpdateSelectedRectShow();
        }
Ejemplo n.º 3
0
        async Task InitCanvasAnchorsHandles(EngineNS.CRenderContext rc)
        {
            string[] pinNames = new string[] { "uieditor/uva_op_center.uvanim",
                                               "uieditor/uva_op_topleft.uvanim",
                                               "uieditor/uva_op_topright.uvanim",
                                               "uieditor/uva_op_bottomright.uvanim",
                                               "uieditor/uva_op_bottomleft.uvanim",
                                               "uieditor/uva_op_left.uvanim",
                                               "uieditor/uva_op_top.uvanim",
                                               "uieditor/uva_op_right.uvanim",
                                               "uieditor/uva_op_bottom.uvanim" };

            for (int i = 0; i < (int)enCanvasAnchors.Count; i++)
            {
                var imgInit = new EngineNS.UISystem.Controls.ImageInitializer();
                imgInit.ImageBrush.ImageName = EngineNS.RName.GetRName(pinNames[i], EngineNS.RName.enRNameType.Editor);
                imgInit.ImageBrush.TileMode  = EngineNS.UISystem.Brush.enTileMode.None;
                var img = new EngineNS.UISystem.Controls.Image();
                await img.Initialize(rc, imgInit);

                img.Visibility = EngineNS.UISystem.Visibility.Collapsed;

                var rect   = new EngineNS.RectangleF(0, 0, 16, 16);
                var uvAnim = await EngineNS.CEngine.Instance.UVAnimManager.GetUVAnimAsync(rc, imgInit.ImageBrush.ImageName);

                if (uvAnim != null && uvAnim.Frames.Count > 0)
                {
                    await uvAnim.WaitTextureValid(rc);

                    var width  = uvAnim.PixelWidth * uvAnim.Frames[0].SizeU;
                    var height = uvAnim.PixelHeight * uvAnim.Frames[0].SizeV;
                    rect = new EngineNS.RectangleF(0, 0, width, height);
                }

                mCanvasAnchorsHandles[i] = new AnchorsHandleData()
                {
                    Show    = img,
                    SrcRect = rect,
                };
            }
        }
Ejemplo n.º 4
0
        internal async Task AddPanelRectShow(EngineNS.CRenderContext rc, EngineNS.UISystem.UIElement uiCtrl)
        {
            var panel = uiCtrl as EngineNS.UISystem.Controls.Containers.Panel;

            if (panel != null)
            {
                var imgInit = new EngineNS.UISystem.Controls.ImageInitializer();
                imgInit.ImageBrush.ImageName = EngineNS.RName.GetRName("uieditor/uvanim_dottedline.uvanim", EngineNS.RName.enRNameType.Editor);
                imgInit.ImageBrush.TileMode  = EngineNS.UISystem.Brush.enTileMode.Both;
                imgInit.ImageBrush.Color     = new EngineNS.Color4(0.8f, 1.0f, 1.0f, 1.0f);
                var show = new EngineNS.UISystem.Controls.Image();
                await show.Initialize(rc, imgInit);

                mPanelRectsShow[panel] = show;

                if (uiCtrl == HostDesignPanel.CurrentUI || !(uiCtrl is EngineNS.UISystem.Controls.UserControl))
                {
                    foreach (var child in panel.ChildrenUIElements)
                    {
                        await AddPanelRectShow(rc, child);
                    }
                }
            }
        }
Ejemplo n.º 5
0
        public async Task SetObjectToEditor(EngineNS.CRenderContext rc, EditorCommon.Resources.ResourceEditorContext context)
        {
            await Viewport.WaitInitComplated();

            if (mWindowRectUIShow == null)
            {
                var imgInit = new EngineNS.UISystem.Controls.ImageInitializer();
                imgInit.ImageBrush.ImageName = EngineNS.RName.GetRName("uieditor/uvanim_dottedline.uvanim", EngineNS.RName.enRNameType.Editor);
                imgInit.ImageBrush.TileMode  = EngineNS.UISystem.Brush.enTileMode.Both;
                mWindowRectUIShow            = new EngineNS.UISystem.Controls.Image();
                await mWindowRectUIShow.Initialize(rc, imgInit);
            }
            if (mMousePointAtUIRectShow == null)
            {
                var imgInit = new EngineNS.UISystem.Controls.ImageInitializer();
                imgInit.ImageBrush.ImageName = EngineNS.RName.GetRName("uieditor/uva_pointatrect.uvanim", EngineNS.RName.enRNameType.Editor);
                imgInit.ImageBrush.TileMode  = EngineNS.UISystem.Brush.enTileMode.None;
                mMousePointAtUIRectShow      = new EngineNS.UISystem.Controls.Image();
                await mMousePointAtUIRectShow.Initialize(rc, imgInit);

                mMousePointAtUIRectShow.Visibility = EngineNS.UISystem.Visibility.Collapsed;
            }
            if (mGridlineImage2D == null)
            {
                mGridlineImage2D = await EngineNS.Graphics.Mesh.CGfxImage2D.CreateImage2D(rc, EngineNS.RName.GetRName("uieditor/mi_background_grid.instmtl", EngineNS.RName.enRNameType.Editor), 0, 0, 0, 1, 1);

                mGridlineImage2D.RenderMatrix = EngineNS.Matrix.Scaling(Viewport.GetViewPortWidth(), Viewport.GetViewPortHeight(), 1);
            }
            await InitPanelRectsShow();

            var font = EngineNS.CEngine.Instance.FontManager.GetFont(EngineNS.CEngine.Instance.Desc.DefaultFont, 12, 1024, 128);

            if (mScaleFontMesh == null)
            {
                var mtl = await EngineNS.CEngine.Instance.MaterialInstanceManager.GetMaterialInstanceAsync(rc, EngineNS.RName.GetRName("Material/font.instmtl"));

                mScaleFontMesh = new EngineNS.Bricks.FreeTypeFont.CFontMesh();
                await mScaleFontMesh.SetMaterial(rc, mtl, "txDiffuse");

                mScaleFontMesh.RenderMatrix = EngineNS.Matrix.Translate(20, 20, 0);
                //mScaleFontMesh.Offset = new EngineNS.Vector2(20, 20);
                //mScaleFontMesh.Scale = new EngineNS.Vector2(1, 1);
            }

            //var color = new EngineNS.FrameBufferClearColor();
            //color.r = 0.1f;
            //color.g = 0.1f;
            //color.b = 0.1f;
            //color.a = 1.0f;
            //Viewport.RPolicy.SetClearColorRT(0, ref color);
            var smp = EngineNS.Thread.ASyncSemaphore.CreateSemaphore(1);

            Viewport.RPolicy.OnDrawUI += (cmd, view) =>
            {
                var mtlmesh = mGridlineImage2D.Mesh.MtlMeshArray[0];
                var pass    = mGridlineImage2D.GetPass();
                pass.ViewPort = view.Viewport;
                if (pass.RenderPipeline == null)
                {
                    var rplDesc = new EngineNS.CRenderPipelineDesc();
                    pass.RenderPipeline = rc.CreateRenderPipeline(rplDesc);
                }
                pass.RenderPipeline.RasterizerState   = mtlmesh.MtlInst.CustomRasterizerState;
                pass.RenderPipeline.DepthStencilState = mtlmesh.MtlInst.CustomDepthStencilState;
                pass.RenderPipeline.BlendState        = mtlmesh.MtlInst.CustomBlendState;
                //pass.ShaderSamplerBinder = mtlmesh.GetSamplerBinder(rc, pass.Effect.ShaderProgram);
                pass.BindCBuffer(pass.Effect.ShaderProgram, pass.Effect.CacheData.CBID_View, view.ScreenViewCB);
                pass.ShadingEnv.BindResources(mGridlineImage2D.Mesh, pass);
                cmd.PushPass(pass);

                mWindowRectUIShow.Draw(rc, cmd, view);

                foreach (var rect in mPanelRectsShow.Values)
                {
                    rect.Draw(rc, cmd, view);
                }

                HostDesignPanel.CurrentUI.Draw(rc, cmd, view);
                mMousePointAtUIRectShow.Draw(rc, cmd, view);
                foreach (var data in mSelectedUIDatas.Values)
                {
                    data.ShowRect?.Draw(rc, cmd, view);
                }
                mSlotOperator?.Draw(rc, cmd, view);
                mScaleFontMesh.DrawText(rc, font, "缩放:" + mUIScale.ToString("F"), true);
                for (int i = 0; i < mScaleFontMesh.PassNum; i++)
                {
                    var fontPass = mScaleFontMesh.GetPass(i);
                    if (fontPass == null)
                    {
                        continue;
                    }

                    fontPass.ViewPort = view.Viewport;
                    fontPass.BindCBuffer(fontPass.Effect.ShaderProgram, fontPass.Effect.CacheData.CBID_View, view.ScreenViewCB);
                    fontPass.ShadingEnv.BindResources(mScaleFontMesh.Mesh, fontPass);
                    cmd.PushPass(fontPass);
                }

                if (smp.IsValid)
                {
                    smp.Release();
                }
            };
            await smp.Await();

            HostDesignPanel.CurrentUI.SetDesignRect(ref mWindowDesignSize);
            ShowAll();
        }