private void Init(IWindowManager windowManager,
                          IThemeProvider themeProvider,
                          IViewPerspective viewPerspective,
                          DisplayMetrics displayMetrics,
                          AndroidFontProvider fontProvider,
                          IViewState viewState,
                          IUiProvider uiProvider,
                          ref AndroidMeasureKit measureContext,
                          ref AndroidRenderContext renderContext,
                          ref RefreshRenderContext refreshRenderContext)
        {
            var imageProvider = new AndroidImageProvider(displayMetrics);

            var visualLineage = new VisualLineage();

            var lastMeasures = new Dictionary <IVisualElement, ValueSize>();

            var layoutQueue = new LayoutQueue();

            measureContext = new AndroidMeasureKit(windowManager, fontProvider,
                                                   this, lastMeasures, themeProvider, displayMetrics, visualLineage, layoutQueue);

            var visualPositions = new Dictionary <IVisualElement, ValueCube>();

            renderContext = new AndroidRenderContext(viewPerspective,
                                                     fontProvider, viewState, this, visualPositions,
                                                     lastMeasures, themeProvider, visualLineage, layoutQueue);

            refreshRenderContext = new RefreshRenderContext(viewPerspective, this,
                                                            visualPositions, lastMeasures, themeProvider, visualLineage, layoutQueue);

            Container.ResolveTo <IImageProvider>(imageProvider);
            Container.ResolveTo(uiProvider);
            Container.ResolveTo(themeProvider);
        }
        public override void Render(IModelRenderer modelRenderer, IViewState viewState)
        {
            if (Model is StudioModel studioModel)
            {
                var renderData = new StudioModelRenderData
                {
                    Model                   = studioModel,
                    Shared                  = GetSharedModelRenderData(viewState),
                    CurrentTime             = Context.Time.ElapsedTime,
                    Sequence                = Sequence,
                    LastTime                = LastTime,
                    Frame                   = Frame,
                    FrameRate               = FrameRate,
                    Body                    = Body,
                    Skin                    = Skin,
                    BoneData                = new BoneData(),
                    RenderFXLightMultiplier = RenderFXLightMultiplier,
                };

                for (var i = 0; i < MDLConstants.MaxControllers; ++i)
                {
                    renderData.BoneData.SetController(i, Controllers[i]);
                }

                for (var i = 0; i < MDLConstants.MaxBlenders; ++i)
                {
                    renderData.BoneData.SetBlender(i, Blenders[i]);
                }

                modelRenderer.RenderStudioModel(ref renderData);
            }
        }
示例#3
0
        public void Draw(IViewState viewState)
        {
            if (ImGui.BeginMainMenuBar())
            {
                if (ImGui.BeginMenu("Tools"))
                {
                    ImGui.Checkbox("Toggle Console", ref _consoleVisible);

                    ImGui.Checkbox("Toggle Material Control", ref _materialControlVisible);

                    ImGui.Checkbox("Toggle Object Editor", ref _objectEditorVisible);

                    ImGui.EndMenu();
                }

                ImGui.Text(_fta.CurrentAverageFramesPerSecond.ToString("000.0 fps / ") + _fta.CurrentAverageFrameTimeMilliseconds.ToString("#00.00 ms"));

                ImGui.TextUnformatted($"Camera Position: {viewState.Origin} Camera Angles: Pitch {viewState.Angles.X} Yaw {viewState.Angles.Y}");

                ImGui.EndMainMenuBar();
            }

            DrawConsole();

            DrawMaterialControl();

            DrawObjectEditor();
        }
示例#4
0
        void IView.SetSource(IViewState newSource)
        {
            using (Atom.NoWatch)
            {
                if (ReferenceEquals(_source.Value, newSource))
                {
                    return;
                }
            }

            if (!(newSource is TState nextState))
            {
                var expected = typeof(TState).Name;
                var actual   = newSource.GetType().Name;
                Debug.LogError($"Wrong model type at '{name}': expected={expected}, actual={actual}");
                return;
            }

            _renderScope.Link(this);

            if (_renderAtom == null)
            {
                _renderAtom = new ReactionAtom(DoRender, OnRenderFailed);
            }

            _hasSource    = true;
            _source.Value = nextState;

            if (!_renderAtom.IsActive)
            {
                _renderAtom.Get();
            }
        }
示例#5
0
        /// <summary>
        /// Connects to the dotNetify hub server.
        /// </summary>
        /// <param name="vmId">Identifies the view model to request.</param>
        /// <param name="viewState">View state manager.</param>
        /// <param name="options">View model initialization options.</param>
        public async Task ConnectAsync(string vmId, IViewState viewState, VMConnectOptions options = null)
        {
            if (!string.IsNullOrEmpty(_vmId))
            {
                throw new Exception($"The instance was connected to '{_vmId}'. Call Dispose to disconnect.");
            }

            _vmId      = vmId;
            _viewState = viewState;

            await _hubProxy.StartAsync();

            _hubProxy.Response_VM += OnResponseReceived;

            Dictionary <string, object> data = null;

            if (options?.VMArg != null)
            {
                data = new Dictionary <string, object>();
                data.Add(TOKEN_VMARG, options.VMArg);
                if (options?.Headers != null)
                {
                    data.Add(TOKEN_HEADERS, options.Headers);
                }
            }

            await _hubProxy.Request_VM(vmId, data);
        }
示例#6
0
        public (IView, WidgetViewReference) LoadViewPrefab(IViewState viewState)
        {
            var viewReference = viewState.View;

            if (viewReference.Type != WidgetViewReferenceType.Addressable)
            {
                return(null, default);
示例#7
0
        public (IView, WidgetViewReference) LoadViewPrefab(IViewState state)
        {
            var viewReference = state.View;

            if (viewReference.Type != WidgetViewReferenceType.Resource ||
                !viewReference.Path.StartsWith("$$_"))
            {
                return(null, default);
示例#8
0
        void UpdateControls(IViewState state)
        {
            void updateControl(
                Control ctrl,
                ControlState controlState,
                TextBoxBase textBox = null,
                bool backColor      = false,
                bool foreColor      = false
                )
            {
                ctrl.Visible = !controlState.Hidden;
                ctrl.Enabled = !controlState.Disabled;
                if (backColor)
                {
                    ctrl.BackColor = controlState.BackColor != null?controlState.BackColor.Value.ToSystemDrawingObject() : System.Drawing.SystemColors.Control;
                }
                if (foreColor)
                {
                    ctrl.ForeColor = controlState.ForeColor != null?controlState.ForeColor.Value.ToSystemDrawingObject() : System.Drawing.SystemColors.ControlText;
                }
                if (ctrl.Text != controlState.Text)
                {
                    ctrl.Text = controlState.Text;
                    textBox?.Select(0, 0);
                }
                toolTip1.SetToolTip(ctrl, controlState.Tooltip);
            }

            void updateCheckBox(CheckBox control, ControlState controlState)
            {
                updateControl(control, controlState);
                control.Checked = controlState.Checked.GetValueOrDefault();
            }

            void updateTextBox(TextBox control, ControlState controlState)
            {
                updateControl(control, controlState, control);
            }

            updateTextBox(nameTextBox, state.NameEditbox);
            updateTextBox(formatTextBox, state.FormatTextBox);
            updateCheckBox(visibleCheckBox, state.VisibleCheckBox);
            updateControl(colorPanel, state.ColorPanel, backColor: true);
            updateControl(stateDetailsLink, state.StateDetailsLink);
            updateControl(stateLabel, state.StateLabel, foreColor: true);
            updateTextBox(loadedMessagesTextBox, state.LoadedMessagesTextBox);
            updateControl(loadedMessagesWarningIcon, state.LoadedMessagesWarningIcon);
            updateControl(loadedMessagesWarningLinkLabel, state.LoadedMessagesWarningLinkLabel);
            updateControl(trackChangesLabel, state.TrackChangesLabel);
            updateControl(suspendResumeTrackingLink, state.SuspendResumeTrackingLink);
            updateControl(firstMessageLinkLabel, state.FirstMessageLinkLabel);
            updateControl(lastMessageLinkLabel, state.LastMessageLinkLabel);
            updateControl(saveAsButton, state.SaveAsButton);
            updateTextBox(annotationTextBox, state.AnnotationTextBox);
            updateTextBox(timeOffsetTextBox, state.TimeOffsetTextBox);
            updateControl(copyPathLink, state.CopyPathButton);
        }
        public static (RenderFX, RenderMode, int, Vector3) GetProperties(IViewState viewState, Transform transform, RenderProperties renderProperties)
        {
            var renderFX   = renderProperties?.RenderFX ?? RenderFX.None;
            var renderMode = renderProperties?.RenderMode ?? RenderMode.Normal;

            var renderAmount = CalculateFXBlend(viewState, transform, renderFX, renderMode != RenderMode.Normal ? renderProperties?.RenderAmount ?? 0 : 255);

            return(renderFX, renderMode, renderAmount, renderProperties?.RenderColor ?? Vector3.Zero);
        }
示例#10
0
        public (IView, WidgetViewReference) LoadViewPrefab(IViewState viewState)
        {
            foreach (var loader in _loaders)
            {
                var(view, reference) = loader.LoadViewPrefab(viewState);
                if (view != null)
                {
                    return(view, reference);
                }
            }

            return(null, default);
示例#11
0
        public bool Equals(IViewState other)
        {
            if (other.GetType() == GetType())
            {
                ViewState state = (ViewState) other;
                if (state.Name == Name)
                    return true;
                return false;
            }

            return false;
        }
示例#12
0
        protected override IView ResolveView(IViewState state)
        {
            var(prefab, viewRef) = ViewContext.Loader.LoadViewPrefab(state);
            var view = GameObjectPool
                       .Instantiate(prefab.gameObject, _parentSelector.Invoke(), _worldPositionStays)
                       .GetComponent <IView>();

            view.gameObject.name = prefab.gameObject.name;
            view.rectTransform.anchoredPosition = Vector2.zero;
            view.ViewReference = viewRef;
            return(view);
        }
示例#13
0
        public override void Render(IModelRenderer modelRenderer, IViewState viewState)
        {
            if (Model is SpriteModel spriteModel)
            {
                var renderData = new SpriteModelRenderData
                {
                    Model  = spriteModel,
                    Shared = GetSharedModelRenderData(viewState),
                    Frame  = Frame
                };

                modelRenderer.RenderSpriteModel(ref renderData);
            }
        }
 public AndroidRenderContext(IViewPerspective perspective,
                             AndroidFontProvider fontProvider,
                             IViewState viewState,
                             IVisualSurrogateProvider surrogateProvider,
                             Dictionary <IVisualElement, ValueCube> renderPositions,
                             Dictionary <IVisualElement, ValueSize> lastMeasurements,
                             IThemeProvider themeProvider,
                             IVisualLineage visualLineage,
                             ILayoutQueue layoutQueue)
     : base(perspective, surrogateProvider, renderPositions, lastMeasurements,
            themeProvider, visualLineage, layoutQueue)
 {
     _fontProvider = fontProvider;
     _paint        = new Paint();
     ViewState     = viewState;
 }
        public AndroidRenderKit(IViewPerspective viewPerspective,
                                IViewState viewState,
                                AndroidFontProvider fontProvider,
                                IWindowManager windowManager,
                                IUiProvider uiProvider,
                                IThemeProvider themeProvider,
                                DisplayMetrics displayMetrics,
                                IResolver container,
                                IImageProvider imageProvider)
            : base(imageProvider, Serializer,
                   new SvgPathBuilder(imageProvider, Serializer), container)
        {
            ViewState      = viewState;
            DisplayMetrics = displayMetrics;

            Init(windowManager, themeProvider, viewPerspective, displayMetrics,
                 fontProvider, viewState, uiProvider,
                 ref _measureContext !, ref _renderContext !, ref _refreshRenderContext !);
        }
示例#16
0
        void IView.SetSource(IViewState newSource, bool link)
        {
            Initialize();

            _renderScope.Link(this);

            var doRebindAtom = ((AtomBase)_doRebind);

            if (!doRebindAtom.IsActive)
            {
                doRebindAtom.Actualize();
            }

            if (!ReferenceEquals(newSource, _currentState))
            {
                if (newSource is TState typedState)
                {
                    _nextState.Value = typedState;
                }
                else
                {
                    var expected = typeof(TState).Name;
                    var actual   = newSource.GetType().Name;
                    Debug.LogError($"Wrong model type at '{name}': expected={expected}, actual={actual}");
                    return;
                }

                RefreshBounds();
            }

            if (link)
            {
                _doRebind.Get();
            }
            else
            {
                doRebindAtom.Actualize();
            }
        }
示例#17
0
        public ValueSize MeasureMainView <TRenderSize>(IVisualElement element,
                                                       TRenderSize availableSpace,
                                                       IViewState viewState)
            where TRenderSize : IRenderSize
        {
            //Debug.WriteLine("********** BEGIN MEASURE ***********");

            ViewState = viewState;

            if (viewState.ZoomLevel.AreDifferent(1.0))
            {
                var zoomWidth  = availableSpace.Width / viewState.ZoomLevel;
                var zoomHeight = availableSpace.Height / viewState.ZoomLevel;

                if (_contextBounds.Width.AreDifferent(zoomWidth) ||
                    _contextBounds.Height.AreDifferent(zoomHeight))
                {
                    _contextBounds = new ValueSize(zoomWidth, zoomHeight);
                }

                var availableSpace2 = new ValueRenderSize(zoomWidth, zoomHeight, availableSpace.Offset);

                //Debug.WriteLine("********** END MEASURE ***********");
                return(MeasureElement(element, availableSpace2));
            }

            if (_contextBounds.Width.AreDifferent(availableSpace.Width) ||
                _contextBounds.Height.AreDifferent(availableSpace.Height))
            {
                _contextBounds = new ValueSize(availableSpace);
            }

            var res = MeasureElement(element, availableSpace);

            //Debug.WriteLine("********** END MEASURE ***********");
            return(res);
        }
        private int GlowBlend(ref SharedModelRenderData renderData, IViewState viewState)
        {
            var tmp = renderData.Origin - viewState.Origin;

            var distance = tmp.Length();

            //TODO: implement trace

            /*
            pmove->usehull = 2;

            var traceFlags = PM_GLASS_IGNORE;

            if (!r_traceglow.value)
            {
                traceFlags |= PM_STUDIO_IGNORE;
            }

            var trace = pmove->PM_PlayerTrace(viewState.Origin, renderData.Origin, traceFlags, -1);

            if ((1.0 - trace.fraction) * distance > 8.0)
            {
                return 0;
            }
            else */
            if (renderData.RenderFX == RenderFX.NoDissipation)
            {
                return renderData.RenderAmount;
            }
            else
            {
                renderData.Scale = new Vector3(distance * 0.005f);

                return (int)(Math.Clamp(19000.0f / (distance * distance), 0.5f, 1.0f) * 255);
            }
        }
示例#19
0
 public void OnRenderModels(IModelRenderer modelRenderer, IViewState viewState)
 {
     _entities.RenderEntities(modelRenderer, viewState);
 }
        public static int CalculateFXBlend(IViewState viewState, Transform transform, RenderFX renderFX, int renderAmount)
        {
            //Offset is random based on entity index
            var offset = transform.Entity.Id * 363.0f;

            int result;

            //Not all render effects update the render amount
            switch (renderFX)
            {
            //All effects not handled use entity render amount (no special effect)
            default:
                result = renderAmount;
                break;

            //Pulsating transparency
            case RenderFX.PulseSlow:
            case RenderFX.PulseFast:
            case RenderFX.PulseSlowWide:
            case RenderFX.PulseFastWide:
            {
                var multiplier1 = (renderFX == RenderFX.PulseSlow || renderFX == RenderFX.PulseSlowWide) ? 2.0 : 8.0;
                var multiplier2 = (renderFX == RenderFX.PulseSlow || renderFX == RenderFX.PulseFast) ? 16.0 : 64.0;
                result = (int)Math.Floor(renderAmount + (Math.Sin(offset + (EntitySystem.Time.ElapsedTime * multiplier1)) * multiplier2));
                break;
            }

            //Fade out from solid to translucent
            case RenderFX.FadeSlow:
            case RenderFX.FadeFast:
                result = renderAmount = Math.Max(0, renderAmount - (renderFX == RenderFX.FadeSlow ? 1 : 4));
                break;

            //Fade in from translucent to solid
            case RenderFX.SolidSlow:
            case RenderFX.SolidFast:
                result = renderAmount = Math.Min(255, renderAmount + (renderFX == RenderFX.SolidSlow ? 1 : 4));
                break;

            //A strobing effect where the model becomes visible every so often
            case RenderFX.StrobeSlow:
            case RenderFX.StrobeFast:
            case RenderFX.StrobeFaster:
            {
                double multiplier;

                switch (renderFX)
                {
                case RenderFX.StrobeSlow:
                    multiplier = 4.0;
                    break;

                case RenderFX.StrobeFast:
                    multiplier = 16.0;
                    break;

                case RenderFX.StrobeFaster:
                    multiplier = 36.0;
                    break;

                //Will never happen, silences compiler error
                default: throw new InvalidOperationException("Update switch statement to handle render fx strobe cases");
                }

                if ((int)Math.Floor(Math.Sin(offset + (EntitySystem.Time.ElapsedTime * multiplier)) * 20.0) < 0)
                {
                    return(0);
                }

                result = renderAmount;
                break;
            }

            //Flicker in and out of existence
            case RenderFX.FlickerSlow:
            case RenderFX.FlickerFast:
            {
                double multiplier1;
                double multiplier2;

                if (renderFX == RenderFX.FlickerSlow)
                {
                    multiplier1 = 2.0;
                    multiplier2 = 17.0;
                }
                else
                {
                    multiplier1 = 16.0;
                    multiplier2 = 23.0;
                }

                if ((int)Math.Floor(Math.Sin(offset * EntitySystem.Time.ElapsedTime * multiplier2) + (Math.Sin(EntitySystem.Time.ElapsedTime * multiplier1) * 20.0)) < 0)
                {
                    return(0);
                }

                result = renderAmount;
                break;
            }

            //Similar to pulse, but clamped to [148, 211], more chaotic
            case RenderFX.Distort:
            //Hologram effect based on player position and view direction relative to entity
            case RenderFX.Hologram:
            {
                int amount;
                if (renderFX == RenderFX.Distort)
                {
                    amount = renderAmount = 180;
                }
                else
                {
                    var dot = Vector3.Dot(transform.Origin - viewState.Origin, viewState.ViewVectors.Forward);

                    if (dot <= 0)
                    {
                        return(0);
                    }

                    renderAmount = 180;

                    if (dot <= 100)
                    {
                        amount = 180;
                    }
                    else
                    {
                        amount = (int)Math.Floor((1 - ((dot - 100) * 0.0025)) * 180);
                    }
                }
                result = EntitySystem.Scene.Random.Next(-32, 31) + amount;
                break;
            }
            }

            return(Math.Clamp(result, 0, 255));
        }
        private Vector3 GetSpriteAngles(ref SharedModelRenderData renderData, SpriteType type, IViewState viewState)
        {
            //Convert parallel sprites to parallel oriented if a roll was specified
            if (type == SpriteType.Parallel && renderData.Angles.Z != 0)
            {
                type = SpriteType.ParallelOriented;
            }

            Vector3 GetModifiedViewAngles()
            {
                var angles = viewState.Angles;

                //Pitch and roll need to be inverted to operate in the sprite's coordinate system
                //Yaw stays the same
                angles.X = -angles.X;
                angles.Z = -angles.Z;

                return angles;
            }

            switch (type)
            {
                case SpriteType.FacingUpright:
                    {
                        //This is bugged in vanilla since it uses an origin that isn't initialized by sprite models, only other models
                        var angles = VectorUtils.VectorToAngles(-renderData.Origin);

                        //No pitch
                        angles.X = 0;

                        return angles;
                    }

                case SpriteType.ParallelUpright:
                    {
                        var angles = GetModifiedViewAngles();

                        //No pitch
                        angles.X = 0;

                        return angles;
                    }

                case SpriteType.Parallel:
                    {
                        return GetModifiedViewAngles();
                    }

                case SpriteType.Oriented:
                    {
                        return renderData.Angles;
                    }

                case SpriteType.ParallelOriented:
                    {
                        var angles = GetModifiedViewAngles();

                        //Apply roll
                        angles.Z -= renderData.Angles.Z;

                        return angles;
                    }

                default:
                    {
                        Logger.Warning($"{nameof(GetSpriteAngles)}: Bad sprite type {type}");
                        break;
                    }
            }

            return new Vector3();
        }
示例#22
0
 public void SetSource(IViewState source)
 {
     Context = source.Context;
 }
示例#23
0
 public void Update(float deltaSeconds, IViewState viewState)
 {
     _fta.AddTime(deltaSeconds);
 }
示例#24
0
 protected abstract IView ResolveView(IViewState state);
示例#25
0
 public void Change(IViewState state)
 {
     _currentViewState = state;
 }
示例#26
0
 public ViewContext(IViewState vwViewState)
 {
     _currentViewState = vwViewState;
     //ButtonVisibilty = _vmStateContext.ButtonVisibilty;
 }
示例#27
0
 public void SetSource(IViewState source, bool link)
 {
     Context = source.Context;
 }
        void UpdateView(IViewState viewState)
        {
            bool updateControl(ControlState state, NSControl control)
            {
                var  txt    = state.Text ?? "";
                bool result = control.StringValue != txt;

                if (result)
                {
                    control.StringValue = txt;
                }
                control.Hidden  = state.Hidden;
                control.Enabled = !state.Disabled;
                control.ToolTip = state.Tooltip ?? "";
                return(result);
            }

            void updateTextField(ControlState state, NSTextField control)
            {
                if (updateControl(state, control))
                {
                    if (control.CurrentEditor != null)
                    {
                        control.CurrentEditor.SelectedRange = new NSRange();
                    }
                }
                control.BackgroundColor = state.BackColor != null?state.BackColor.Value.ToNSColor() : NSColor.TextBackground;
            }

            void updateLinkLabel(ControlState state, NSLinkLabel control)
            {
                control.StringValue = state.Text ?? "";
                control.Hidden      = state.Hidden;
                control.IsEnabled   = !state.Disabled;
                control.TextColor   = state.ForeColor != null?state.ForeColor.Value.ToNSColor() : NSColor.LinkColor;
            }

            void updateButton(ControlState state, NSButton control)
            {
                updateControl(state, control);
                if (state.Checked != null)
                {
                    control.State = state.Checked == true ? NSCellStateValue.On : NSCellStateValue.Off;
                }
            }

            updateTextField(viewState.NameEditbox, nameTextField);
            updateTextField(viewState.FormatTextBox, formatTextField);
            updateButton(viewState.VisibleCheckBox, visibleCheckbox);
            updateTextField(viewState.ColorPanel, colorPanel);
            updateLinkLabel(viewState.StateDetailsLink, stateDetailsLink);
            updateTextField(viewState.StateLabel, stateLabel);
            updateTextField(viewState.LoadedMessagesTextBox, loadedMessagesLabel);
            updateButton(viewState.LoadedMessagesWarningIcon, loadedMessagesWarningIcon);
            updateLinkLabel(viewState.LoadedMessagesWarningLinkLabel, loadedMessagesWarningLinkLabel);
            updateTextField(viewState.TrackChangesLabel, trackChangesLabel);
            updateLinkLabel(viewState.SuspendResumeTrackingLink, suspendResumeTrackingLinkLabel);
            updateLinkLabel(viewState.FirstMessageLinkLabel, firstMessageLinkLabel);
            updateLinkLabel(viewState.LastMessageLinkLabel, lastMessageLinkLabel);
            updateButton(viewState.SaveAsButton, saveAsButton);
            updateTextField(viewState.AnnotationTextBox, annotationEditBox);
            updateTextField(viewState.TimeOffsetTextBox, timeShiftTextField);
            updateButton(viewState.CopyPathButton, copyPathButton);
            updateButton(viewState.OpenContainingFolderButton, openContainingFolderButton);
        }