Esempio n. 1
0
        public AttachedHelper([NotNull] BaseFormWrapper parent, [NotNull] Window window, int offset = -1, int padding = 10)
        {
            _padding = padding;

            _parent                   = parent.Form;
            _parent.Closed           += OnClosed;
            _parent.UserResized      += OnResize;
            _parent.Move             += OnMove;
            _parent.Load             += OnLoad;
            _parent.GotFocus         += OnGotFocus;
            _parent.LostFocus        += OnLostFocus;
            parent.FullscreenChanged += OnFullscreenChanged;

            _child = window;
            var child = _child;

            child.Owner     = null;
            child.MaxHeight = _parent.Height - _padding;
            ElementHost.EnableModelessKeyboardInterop(child);

            child.Show();
            child.Activate();

            _offset = offset < 0 ? (int)child.ActualWidth - 12 : offset;

            UpdatePosition();

            child.Activated       += ChildActivated;
            child.Deactivated     += ChildDeactivated;
            child.Closed          += ChildClosed;
            child.KeyUp           += ChildKeyUp;
            child.LocationChanged += ChildLocationChanged;
            child.SizeChanged     += ChildSizeChanged;

            child.Topmost = true;
            Visible       = true;
        }
Esempio n. 2
0
        public static async Task StartLiteAsync(string kn5, string skinId = null)
        {
            if (_starting)
            {
                return;
            }
            _starting = true;

            _last?.Stop();
            _last = null;

            ForwardKn5ObjectRenderer renderer = null;

            Logging.Write("Custom Showroom: Magick.NET IsSupported=" + ImageUtils.IsMagickSupported);
            RenderLogging.Initialize(Logging.Filename, true);

            try {
                var carDirectory = Path.GetDirectoryName(kn5);
                if (Path.GetFileName(Path.GetDirectoryName(carDirectory)) == @"..")
                {
                    carDirectory = Path.GetDirectoryName(Path.GetDirectoryName(carDirectory));
                }

                var carObject   = CarsManager.Instance.GetById(Path.GetFileName(carDirectory) ?? "");
                var toolboxMode = IsSameDirectories(carObject?.Location, carDirectory);

                LiteShowroomWrapper wrapper;
                using (var waiting = new WaitingDialog()) {
                    waiting.Report(ControlsStrings.CustomShowroom_Loading);

                    var description = new CarDescription(kn5, carDirectory, carObject?.AcdData);
                    if (toolboxMode)
                    {
                        ExtraModelProvider.Initialize();

                        var toolsRenderer = await Task.Run(() => SettingsHolder.CustomShowroom.UseOldLiteShowroom?
                                                           new ToolsKn5ObjectRenderer(description) {
                            VisibleUi = false,
                            UseSprite = false,
                            UseMsaa   = SettingsHolder.CustomShowroom.LiteUseMsaa,
                            UseFxaa   = SettingsHolder.CustomShowroom.LiteUseFxaa,
                            UseBloom  = SettingsHolder.CustomShowroom.LiteUseBloom
                        } :
                                                           new DarkKn5ObjectRenderer(description)
                        {
                            VisibleUi = false,
                            UseSprite = false
                        });

                        wrapper  = new LiteShowroomWrapperWithTools(toolsRenderer, carObject, skinId);
                        renderer = toolsRenderer;
                    }
                    else
                    {
                        Logging.Warning($"Can’t find CarObject for “{carDirectory}”");
                        Logging.Warning($"Found location: “{carObject?.Location ?? @"NULL"}”");

                        renderer = await Task.Run(() => SettingsHolder.CustomShowroom.UseOldLiteShowroom?
                                                  new ForwardKn5ObjectRenderer(description) {
                            UseMsaa  = SettingsHolder.CustomShowroom.LiteUseMsaa,
                            UseFxaa  = SettingsHolder.CustomShowroom.LiteUseFxaa,
                            UseBloom = SettingsHolder.CustomShowroom.LiteUseBloom
                        } :
                                                  new DarkKn5ObjectRenderer(description)
                        {
                            FlatMirror = true,
                            VisibleUi  = true,
                            UseSprite  = true
                        });

                        wrapper = new LiteShowroomWrapper(renderer);

                        if (skinId != null)
                        {
                            renderer.SelectSkin(skinId);
                        }
                    }

                    _last = wrapper;
                    SetProperties(wrapper, renderer);

                    wrapper.Form.Icon = AppIconService.GetAppIcon();
                }

                wrapper.Run(() => _starting = false);
                GC.Collect();
            } catch (Exception e) {
                NonfatalError.Notify(ControlsStrings.CustomShowroom_CannotStart, e);
            } finally {
                renderer?.Dispose();
                _last     = null;
                _starting = false;
            }
        }