Пример #1
1
        /// <summary>
        /// Binds to specific events of the provided CoreWindow
        /// </summary>
        /// <param name="nativeWindow">A reference to <see cref="CoreWindow"/> or <see cref="UIElement"/> class.</param>
        /// <exception cref="ArgumentNullException">Is thrown when <paramref name="nativeWindow"/> is null.</exception>
        /// <exception cref="ArgumentException">Is thrown when <paramref name="nativeWindow"/> is not a <see cref="CoreWindow"/> and not an <see cref="UIElement"/></exception>
        protected override void BindWindow(object nativeWindow)
        {
            if (nativeWindow == null) throw new ArgumentNullException("nativeWindow");
            var window = nativeWindow as CoreWindow;
            if (window != null)
            {
                windowSize = new Size2F((float)window.Bounds.Width, (float)window.Bounds.Height);
                var position = window.PointerPosition;
                pointerPosition = new Vector2((float)position.X/windowSize.Width, (float)position.Y / windowSize.Height);

                window.PointerPressed += HandleWindowPointerEvent;
                window.PointerReleased += HandleWindowPointerEvent;
                window.PointerWheelChanged += HandleWindowPointerEvent;
                window.PointerMoved += HandleWindowPointerEvent;
                window.SizeChanged += window_SizeChanged;
                return;
            }

            uiElement = nativeWindow as FrameworkElement;
            if (uiElement != null)
            {
                windowSize = new Size2F((float)uiElement.ActualWidth, (float)uiElement.ActualHeight);
                uiElement.Loaded += HandleLoadedEvent;
                uiElement.SizeChanged += HandleSizeChangedEvent;
                uiElement.PointerPressed += HandleUIElementPointerEvent;
                uiElement.PointerReleased += HandleUIElementPointerEvent;
                uiElement.PointerWheelChanged += HandleUIElementPointerEvent;
                uiElement.PointerMoved += HandleUIElementPointerEvent;
                uiElement.PointerEntered += HandleUIElementPointerEvent;
                return;
            }

            throw new ArgumentException("Should be an instance of either CoreWindow or UIElement", "nativeWindow");
        }
Пример #2
0
        public void Size2F_Parse_CanRoundTrip()
        {
            var size1 = Size2F.Parse("123.4 456.7");
            var size2 = Size2F.Parse(size1.ToString());

            TheResultingValue(size1 == size2).ShouldBe(true);
        }
Пример #3
0
        public void Size2F_IsConstructedProperly()
        {
            var result = new Size2F(123.45f, 456.78f);

            TheResultingValue(result)
            .ShouldBe(123.45f, 456.78f);
        }
Пример #4
0
        public TopPanel(IContext9 context, IHudMenu hudMenu)
        {
            this.context = context;

            var centerIndent = Hud.Info.ScreenSize.X * 0.053f;
            var size         = new Size2F(Hud.Info.ScreenSize.X * 0.165f, Hud.Info.ScreenSize.Y * 0.037f);

            var settings = hudMenu.TopPanelSettingsMenu;

            this.debug = settings.Add(new MenuSwitcher("Debug", false));
            this.debug.SetTooltip("Use this to adjust top panel position and size");
            this.debug.AddTranslation(Lang.Ru, "Проверка");
            this.debug.AddTooltipTranslation(Lang.Ru, "Использовать для настройки");
            this.debug.AddTranslation(Lang.Cn, "调试");
            this.debug.AddTooltipTranslation(Lang.Cn, "用它来调整顶板的位置和大小");
            this.debug.DisableSave();

            this.centerPosition = settings.Add(
                new MenuSlider("Center position", "center", (int)centerIndent, 0, (int)(Hud.Info.ScreenSize.X / 4)));
            this.centerPosition.AddTranslation(Lang.Ru, "Центральное положение");
            this.centerPosition.AddTranslation(Lang.Cn, "中间位置");

            this.sidePosition = settings.Add(
                new MenuSlider("Side position", "side", (int)size.Width, 100, (int)(Hud.Info.ScreenSize.X / 2)));
            this.sidePosition.AddTranslation(Lang.Ru, "Боковое положение");
            this.sidePosition.AddTranslation(Lang.Cn, "侧面");

            this.botPosition = settings.Add(new MenuSlider("Bottom position", "bot", (int)size.Height, 25, 100));
            this.botPosition.AddTranslation(Lang.Ru, "Нижнее положение");
            this.botPosition.AddTranslation(Lang.Cn, "底部");
        }
Пример #5
0
        public override void Render()
        {
            base.Render();
            if (!holdKey && WinApi.IsKeyDown(Keys.F10))
            {
                holdKey = true;
                Settings.Enable.Value = !Settings.Enable.Value;
            }
            else if (holdKey && !WinApi.IsKeyDown(Keys.F10))
            {
                holdKey = false;
            }

            if (Settings.Enable)
            {
                Vector2   playerPos     = GameController.Player.GetComponent <Positioned>().GridPos;
                Vector2   position      = StartDrawPointFunc();
                const int BOTTOM_MARGIN = 2;
                bool      shouldUpdate  = false;

                if (Settings.BorderSettings.Enable)
                {
                    Dictionary <EntityWrapper, AlertDrawStyle> tempCopy = new Dictionary <EntityWrapper, AlertDrawStyle>(currentAlerts);
                    var keyValuePairs = tempCopy.AsParallel().Where(x => x.Key.IsValid).ToList();
                    foreach (var kv in keyValuePairs)
                    {
                        if (DrawBorder(kv.Key.Address) && !shouldUpdate)
                        {
                            shouldUpdate = true;
                        }
                    }
                }

                foreach (KeyValuePair <EntityWrapper, AlertDrawStyle> kv in currentAlerts.Where(x => x.Key.IsValid))
                {
                    string text = GetItemName(kv);
                    if (text == null)
                    {
                        continue;
                    }

                    ItemsOnGroundLabelElement entityLabel;
                    if (!currentLabels.TryGetValue(kv.Key.Address, out entityLabel))
                    {
                        shouldUpdate = true;
                    }
                    else
                    if (Settings.ShowText & (!Settings.HideOthers | entityLabel.CanPickUp))
                    {
                        position = DrawText(playerPos, position, BOTTOM_MARGIN, kv, text);
                    }
                }
                Size = new Size2F(0, position.Y); //bug absent width

                if (shouldUpdate)
                {
                    currentLabels = GameController.Game.IngameState.IngameUi.ItemsOnGroundLabels.GroupBy(y => y.ItemOnGround.Address).ToDictionary(y => y.Key, y => y.First());
                }
            }
        }
Пример #6
0
        private bool _有効文字の矩形と文字数を抽出し文字列全体のサイズを返す(string 表示文字列, Size2F 拡大率, out Size2F 文字列全体のサイズ, out int 効文字数, out IEnumerable <RectangleF?> 効文字矩形リスト)
        {
            文字列全体のサイズ = Size2F.Empty;
            効文字矩形リスト  =
                from ch in 表示文字列
                where (this._矩形リスト.文字列to矩形.ContainsKey(ch.ToString()))
                select(this._矩形リスト[ch.ToString()]);

            効文字数 = 効文字矩形リスト.Count();
            if (0 == 効文字数)
            {
                return(false);
            }

            foreach (var 文字矩形 in  効文字矩形リスト)
            {
                文字列全体のサイズ.Width += (文字矩形 !.Value.Width * 拡大率.Width + this.文字幅補正dpx);

                if (文字列全体のサイズ.Height < 文字矩形 !.Value.Height * 拡大率.Height)
                {
                    文字列全体のサイズ.Height = 文字矩形 !.Value.Height * 拡大率.Height;  // 文字列全体の高さは、最大の文字高に一致。
                }
            }

            return(true);
        }
Пример #7
0
        public void Size2F_IsConstructedProperly()
        {
            var result = new Size2F(123.45f, 456.78f);

            TheResultingValue(result)
                .ShouldBe(123.45f, 456.78f);
        }
Пример #8
0
        /**
         * Render the health bar including the colours showing the proportion of life lost,
         * and the flat numbers which overlay it.
         */
        private void DrawHealthBar(HealthBar healthBar, Size2F windowSize, Vector2 coords)
        {
            float scaledWidth  = healthBar.Settings.Width * windowSize.Width;
            float scaledHeight = healthBar.Settings.Height * windowSize.Height;
            Color color        = healthBar.Settings.Color;
            var   life         = healthBar.Entity.GetComponent <Life>();
            float hpPercent    = life.HPPercentage;
            float esPercent    = life.ESPercentage;
            float hpWidth      = hpPercent * scaledWidth;
            float esWidth      = esPercent * scaledWidth;

            // coords must be the position of the bar rectangle. The args for RectangleF are
            // left, top, right, and bottom
            var bg = new RectangleF(coords.X - scaledWidth / 2,
                                    coords.Y - scaledHeight / 2,
                                    scaledWidth,
                                    scaledHeight
                                    );

            if (hpPercent <= 0.1f)
            {
                color = healthBar.Settings.Under10Percent;
            }
            bg.Y = DrawFlatLifeAmount(life, hpPercent, healthBar.Settings, bg);
            DrawFlatESAmount(life, healthBar.Settings, bg);
            DrawPercents(healthBar.Settings, hpPercent, bg);
            DrawBackground(color, healthBar.Settings.Outline, bg, hpWidth, esWidth);
        }
Пример #9
0
        /// <summary>
        ///		画像ファイルからシェーダリソースビューを作成して返す。
        /// </summary>
        /// <remarks>
        ///		(参考: http://qiita.com/oguna/items/c516e09ee57d931892b6 )
        /// </remarks>
        private void _CreateShaderResourceViewFromFile(Device d3dDevice, BindFlags bindFlags, VariablePath 画像ファイルパス)
        {
            using var image = new System.Drawing.Bitmap(画像ファイルパス.数なしパス);
            var 画像の矩形 = new System.Drawing.Rectangle(0, 0, image.Width, image.Height);

            using var bitmap = image.Clone(画像の矩形, System.Drawing.Imaging.PixelFormat.Format32bppArgb);

            var ロック領域       = bitmap.LockBits(画像の矩形, System.Drawing.Imaging.ImageLockMode.ReadOnly, bitmap.PixelFormat);
            var dataBox     = new[] { new DataBox(ロック領域.Scan0, bitmap.Width * 4, bitmap.Height) };
            var textureDesc = new Texture2DDescription()
            {
                ArraySize         = 1,
                BindFlags         = bindFlags,
                CpuAccessFlags    = CpuAccessFlags.None,
                Format            = SharpDX.DXGI.Format.B8G8R8A8_UNorm,
                Height            = bitmap.Height,
                Width             = bitmap.Width,
                MipLevels         = 1,
                OptionFlags       = ResourceOptionFlags.None,
                SampleDescription = new SharpDX.DXGI.SampleDescription(1, 0),
                Usage             = ResourceUsage.Default,
            };

            this.Texture = new Texture2D(d3dDevice, textureDesc, dataBox);
            bitmap.UnlockBits(ロック領域);

            this._ShaderResourceView = new ShaderResourceView(d3dDevice, this.Texture);
            this.サイズ  = new Size2F(画像の矩形.Width, 画像の矩形.Height);
            this.実サイズ = new Size2F(this.Texture.Description.Width, this.Texture.Description.Height);
        }
Пример #10
0
        public static ClientComponentSpriteLightSource CreateLightSourceSpot(
            IClientSceneObject sceneObject,
            Color color,
            Size2F size,
            Size2F?logicalSize        = null,
            Vector2D?spritePivotPoint = null,
            Vector2D?positionOffset   = null)
        {
            var result = sceneObject.AddComponent <ClientComponentSpriteLightSource>();

            result.Color         = color;
            result.RenderingSize = size;
            result.LogicalSize   = logicalSize ?? size;

            if (spritePivotPoint.HasValue)
            {
                result.SpritePivotPoint = spritePivotPoint.Value;
            }

            if (positionOffset.HasValue)
            {
                result.PositionOffset = positionOffset.Value;
            }

            return(result);
        }
Пример #11
0
 /// <summary>
 /// 开始一个拼图游戏。
 /// </summary>
 /// <param name="ct">取消任务的通知。</param>
 private void StartGame(CancellationToken ct)
 {
     this.background = devices.LoadBitmapFromBytes(gameInfo.ImageData);
     this.imageSize  = background.Size;
     this.isDraging  = this.isSelecting = false;
     // 添加事件侦听器。
     this.renderPanel.JigsawRegionChanged += this.renderPanel_JigsawRegionChanged;
     this.renderPanel.JigsawScaleChanging += this.renderPanel_JigsawScaleChanging;
     // 设置渲染区域。
     this.renderPanel.Invoke(new Action(() =>
     {
         this.renderPanel.ImageSize = imageSize;
         this.renderPanel.SetJigsawScale(this.gameInfo.Scale, new Point(0, 0));
         this.renderPanel.AutoScrollPosition = this.gameInfo.ScrollPosition;
     }));
     if (this.gameInfo.UsedTime.Milliseconds == 0)
     {
         // 对于新游戏,重新分布拼图碎片。
         this.pieces.SpreadPieces(renderPanel.JigsawRegion, this.gameInfo.Rotatable);
     }
     this.UpdatePiecesVisible();
     ct.ThrowIfCancellationRequested();
     this.renderer.PrepareRender(gameInfo.ImageData, pieces, gameInfo.Rotatable, ct);
     ct.ThrowIfCancellationRequested();
     this.hasGame     = true;
     this.gameChanged = true;
     this.InvalidateAll();
     this.startTime = DateTime.Now - gameInfo.UsedTime;
     this.UpdateFinishedPercent();
     this.renderPanel.MouseDown += this.renderPanel_MouseDown;
     this.renderPanel.MouseMove += this.renderPanel_MouseMove;
     this.renderPanel.MouseUp   += this.renderPanel_MouseUp;
 }
Пример #12
0
        public void Size2F_SerializesToJson_WhenNullable()
        {
            var size = new Size2F(1.2f, 2.3f);
            var json = JsonConvert.SerializeObject((Size2F?)size);

            TheResultingString(json).ShouldBe(@"{""width"":1.2,""height"":2.3}");
        }
Пример #13
0
        public override bool Initialise()
        {
            Player    = GameController.Player;
            ingameUI  = GameController.IngameState.IngameUi;
            PlayerBar = new HealthBar(Player, Settings);

            GameController.EntityListWrapper.PlayerUpdate += (sender, args) =>
            {
                Player = GameController.Player;

                PlayerBar = new HealthBar(Player, Settings);
            };

            ingameUICheckVisible = new TimeCache <bool>(() =>
            {
                windowRectangle = GameController.Window.GetWindowRectangleReal();
                windowSize      = new Size2F(windowRectangle.Width / 2560, windowRectangle.Height / 1600);
                camera          = GameController.Game.IngameState.Camera;

                return(ingameUI.BetrayalWindow.IsVisibleLocal || ingameUI.SellWindow.IsVisibleLocal ||
                       ingameUI.DelveWindow.IsVisibleLocal || ingameUI.IncursionWindow.IsVisibleLocal ||
                       ingameUI.UnveilWindow.IsVisibleLocal || ingameUI.TreePanel.IsVisibleLocal || ingameUI.AtlasPanel.IsVisibleLocal ||
                       ingameUI.CraftBench.IsVisibleLocal);
            }, 250);

            return(true);
        }
Пример #14
0
        /// <summary>
        ///     指定したサイズの、空のテクスチャを作成する。
        /// </summary>
        public テクスチャ(Size2F サイズ, BindFlags bindFlags = BindFlags.ShaderResource)
        {
            this._画像ファイルパス = null;
            this.ユーザ指定サイズ  = サイズ;

            this._bindFlags = bindFlags;
            this._定数バッファ    = this._定数バッファを作成する();

            // テクスチャとシェーダーリソースビューを生成する。

            if ((0f >= this.ユーザ指定サイズ.Width) && (0f >= this.ユーザ指定サイズ.Height))
            {
                Log.ERROR($"テクスチャサイズが不正です。[{this.ユーザ指定サイズ}]");
                return;
            }

            var テクスチャリソース = FDKUtilities.CreateShaderResourceView(
                DXResources.Instance.D3D11Device1,
                this._bindFlags,
                new Size2((int)this.ユーザ指定サイズ.Width, (int)this.ユーザ指定サイズ.Height));

            this._ShaderResourceView = テクスチャリソース.srv;
            this.サイズ     = this.ユーザ指定サイズ;
            this.Texture = テクスチャリソース.texture;
        }
Пример #15
0
        // 描画


        /// <param name="基点のX位置">左揃えなら左端位置、右揃えなら右端位置のX座標。</param>
        /// <param name="右揃え">trueなら右揃え、falseなら左揃え。</param>
        public void 描画する(DeviceContext dc, float 基点のX位置, float 位置, string 表示文字列, Size2F?拡大率 = null, bool 右揃え = false)
        {
            if (表示文字列.Nullまたは空である())
            {
                return;
            }

            Size2F 拡大率V = (拡大率.HasValue) ? 拡大率.Value : new Size2F(1, 1);


            // 有効文字(矩形リストに登録されている文字)の矩形、文字数を抽出し、文字列全体のサイズを計算する。

            var 文字列全体のサイズ = Size2F.Empty;

            var 効文字矩形リスト =
                from ch in 表示文字列
                where (this._矩形リスト.ContainsKey(ch.ToString()))
                select(this._矩形リスト[ch.ToString()]);

            int 効文字数 = 効文字矩形リスト.Count();

            if (0 == 効文字数)
            {
                return;
            }

            foreach (var 文字矩形 in  効文字矩形リスト)
            {
                文字列全体のサイズ.Width += (文字矩形.Width * 拡大率V.Width + this.文字幅補正dpx);

                if (文字列全体のサイズ.Height < 文字矩形.Height * 拡大率V.Height)
                {
                    文字列全体のサイズ.Height = 文字矩形.Height * 拡大率V.Height;  // 文字列全体の高さは、最大の文字高に一致。
                }
            }


            // 描画する。

            if (右揃え)
            {
                基点のX位置 -= 文字列全体のサイズ.Width;
            }

            for (int i = 0; i < 効文字数; i++)
            {
                var 文字矩形 = 効文字矩形リスト.ElementAt(i);

                this._文字盤.描画する(
                    dc,
                    基点のX位置,
                    位置 + (文字列全体のサイズ.Height - 文字矩形.Height * 拡大率V.Height),
                    転送元矩形: 文字矩形,
                    X方向拡大率: 拡大率V.Width,
                    Y方向拡大率: 拡大率V.Height,
                    透明度0to1: this.透明度);

                基点のX位置 += (文字矩形.Width * 拡大率V.Width + this.文字幅補正dpx);
            }
        }
Пример #16
0
        // 生成と終了


        /// <summary>
        ///     指定した画像ファイルからテクスチャを作成する。
        /// </summary>
        public テクスチャ(VariablePath 画像ファイルパス, BindFlags bindFlags = BindFlags.ShaderResource)
        {
            this._画像ファイルパス = 画像ファイルパス;
            this.ユーザ指定サイズ  = Size2F.Zero;

            this._bindFlags = bindFlags;
            this._定数バッファ    = this._定数バッファを作成する();

            // テクスチャとシェーダーリソースビューを生成する。

            if (this._画像ファイルパス.数なしパス.Nullでも空でもない())
            {
                if (!System.IO.File.Exists(this._画像ファイルパス.数なしパス))
                {
                    Log.ERROR($"画像ファイルが存在しません。[{this._画像ファイルパス.変数付きパス}]");
                    return;
                }

                var テクスチャリソース = FDKUtilities.CreateShaderResourceViewFromFile(
                    DXResources.Instance.D3D11Device1,
                    this._bindFlags,
                    this._画像ファイルパス);

                this._ShaderResourceView = テクスチャリソース.srv;
                this.サイズ     = テクスチャリソース.viewSize;
                this.Texture = テクスチャリソース.texture;
            }
        }
Пример #17
0
        protected override void Initialize(DeviceChild view)
        {
            // The initialize method will override the view.Tag, so we are setting it back
            base.Initialize(view);

            IsRenderView = view is RenderTargetView;

            var shaderResourceView = view as ShaderResourceView;
            int mipLevel           = 0;

            if (shaderResourceView != null)
            {
                var description = shaderResourceView.Description;
                mipLevel = description.Texture1D.MostDetailedMip;
            }
            else
            {
                var renderTargetView = view as RenderTargetView;
                if (renderTargetView == null)
                {
                    throw new ArgumentException("Expecting argument to be a ShaderResourceView or RenderTargetView", "view");
                }
                mipLevel = renderTargetView.Description.Texture1D.MipSlice;
            }
            Size = new Size2(Math.Max(1, Texture.Width >> mipLevel), Math.Max(1, Texture.Height >> mipLevel));

            TexelSize = new Size2F
            {
                Width  = 1.0f / Size.Width,
                Height = 1.0f / Size.Height
            };
        }
Пример #18
0
 protected override Size2F MeasureOverride(Size2F availableSize)
 {
     if (ImageStream != null)
     {
         var imageSize = (RenderCore as ImageRenderCore2D).ImageSize;
         if (Width == 0 && Height == 0)
         {
             return(new Size2F(Math.Min(availableSize.Width, imageSize.Width), Math.Min(availableSize.Height, imageSize.Height)));
         }
         else if (imageSize.Width == 0 || imageSize.Height == 0)
         {
             return(availableSize);
         }
         else
         {
             float aspectRatio = imageSize.Width / imageSize.Height;
             if (Width == 0)
             {
                 var height = Math.Min(availableSize.Height, Height);
                 return(new Size2F(height / aspectRatio, height));
             }
             else
             {
                 var width = Math.Min(availableSize.Width, Width);
                 return(new Size2F(width, width * aspectRatio));
             }
         }
     }
     return(new Size2F(Math.Max(0, Width), Math.Max(0, Height)));
 }
Пример #19
0
        public Image(Size2F サイズdpx, Vector2?位置dpx = null, Vector2?拡大率 = null)
        {
            this.位置dpx = 位置dpx ?? Vector2.Zero;
            this.拡大率   = 拡大率 ?? Vector2.One;

            this.子Activityを追加する(this._画像 = new 描画可能画像(this.サイズdpx));
        }
            public override void GetTexture(Size2F surfaceSize, out DrawingSurfaceSynchronizedTexture synchronizedTexture, out RectangleF textureSubRectangle)
            {
                if (_synchronizedTexture == null)
                {
                    _drawingSurfaceUpdateHandler.CreateDeviceResources();
                    _drawingSurfaceUpdateHandler.CreateWindowSizeDependentResources(surfaceSize);
                    _synchronizedTexture = _host.CreateSynchronizedTexture(_drawingSurfaceUpdateHandler._renderTarget);
                }

                synchronizedTexture = _synchronizedTexture;
                textureSubRectangle = new RectangleF
                {
                    Right  = surfaceSize.Width,
                    Bottom = surfaceSize.Height
                };

                _surfaceUpdateHandler.UpdateGameWindowSize(surfaceSize);

                _synchronizedTexture.BeginDraw();

                _surfaceUpdateHandler.Draw(
                    _drawingSurfaceUpdateHandler._device,
                    _drawingSurfaceUpdateHandler._deviceContext,
                    _drawingSurfaceUpdateHandler._renderTargetView);

                _synchronizedTexture.EndDraw();
            }
Пример #21
0
        private Mathe.RawRectangleF GetBgPosition(Size2F originSize)
        {
            var windowSize  = Settings.Render.WindowSize;
            var windowRatio = windowSize.Width / (float)windowSize.Height;

            var bgRatio = originSize.Width / originSize.Height;

            // deal with different size of image
            if (bgRatio >= windowRatio) // more width
            {
                float scale  = windowSize.Height / originSize.Height;
                float height = windowSize.Height;
                float width  = originSize.Width * scale;
                float x      = -(width - windowSize.Width) / 2;
                float y      = 0;
                return(new Mathe.RawRectangleF(x, y, x + width, y + height));
            }
            else // more height
            {
                float scale  = windowSize.Width / originSize.Width;
                float width  = windowSize.Width;
                float height = originSize.Height * scale;
                float x      = 0;
                float y      = -(height - windowSize.Height) / 2;
                return(new Mathe.RawRectangleF(x, y, x + width, y + height));
            }
        }
Пример #22
0
        // 進行と描画


        /// <summary>
        ///		画像を描画する。
        ///	</summary>
        public void 描画する(
            DeviceContext d3dDeviceContext,
            Size2F 設計画面サイズdpx,
            RawViewportF[] viewports,
            DepthStencilView depthStencilView,
            RenderTargetView renderTargetView,
            DepthStencilState depthStencilState,
            float 左位置,
            float 位置,
            float 透明度0to1    = 1.0f,
            float X方向拡大率     = 1.0f,
            float Y方向拡大率     = 1.0f,
            RectangleF?転送元矩形 = null)
        {
            RectangleF srcRect = 転送元矩形 ?? new RectangleF(0, 0, this.サイズ.Width, this.サイズ.Height);
            var        画面左上dpx = new Vector3(-設 計画面サイズdpx.Width / 2f, +設計画面サイズdpx.Height / 2f, 0f);

            var 換行列 =
                Matrix.Scaling(X方向拡大率, Y方向拡大率, 0f) *
                Matrix.Translation(
                    画面左上dpx.X + (左位置 + X方向拡大率 * srcRect.Width / 2f),
                    画面左上dpx.Y - (位置 + Y方向拡大率 * srcRect.Height / 2f),
                    0f);

            this.描画する(d3dDeviceContext, 設計画面サイズdpx, viewports, depthStencilView, renderTargetView, depthStencilState, 換行列, 透明度0to1, 転送元矩形);
        }
Пример #23
0
 protected グラフィックデバイス(IntPtr hWindow, Size2F 設計画面サイズ, Size2F 物理画面サイズ, bool 深度ステンシルを使う)
 {
     this._hWindow    = hWindow;
     this._深度ステンシルを使う = 深度ステンシルを使う;
     this.設計画面サイズ     = 設計画面サイズ;
     this.物理画面サイズ     = 物理画面サイズ;
 }
Пример #24
0
        public StoryboardObject(Element element, Timing timing, D2D.RenderTarget target, Size2F vSize)
        {
            _timing  = timing;
            _element = element;
            _vSize   = vSize;
            var path = Path.Combine(App.StoryboardProvider.Directory, element.ImagePath);

            if (!File.Exists(path))
            {
                var pngPath = path + ".png";
                if (File.Exists(pngPath))
                {
                    path = pngPath;
                }
                else
                {
                    path = path + ".jpg";
                }
            }

            if (File.Exists(path))
            {
                TextureList = new[] { TextureLoader.LoadBitmap(target, path) };
                Texture     = TextureList[0];
            }
            else
            {
                return;
            }

            SetDefaultValue();
            SetMinMax();
        }
Пример #25
0
        /// <summary>Initializes the specified view.</summary>
        /// <param name="view">The view.</param>
        /// <exception cref="System.ArgumentException">Expecting argument to be a ShaderResourceView or RenderTargetView;view</exception>
        protected override void Initialize(DeviceChild view)
        {
            // The initialize method will override the view.Tag, so we are setting it back
            base.Initialize(view);

            IsRenderView = view is RenderTargetView;

            var shaderResourceView = view as ShaderResourceView;
            int mipLevel = 0;
            if (shaderResourceView != null)
            {
                var description = shaderResourceView.Description;
                mipLevel = description.Texture1D.MostDetailedMip;
            }
            else
            {
                var renderTargetView = view as RenderTargetView;
                if (renderTargetView == null)
                {
                    throw new ArgumentException("Expecting argument to be a ShaderResourceView or RenderTargetView", "view");
                }
                mipLevel = renderTargetView.Description.Texture1D.MipSlice;
            }
            Size = new Size2(Math.Max(1, Texture.Width >> mipLevel), Math.Max(1, Texture.Height >> mipLevel));

            TexelSize = new Size2F
            {
                Width = 1.0f / Size.Width,
                Height = 1.0f / Size.Height
            };
        }
 public override void GetTexture(Size2F surfaceSize, out DrawingSurfaceSynchronizedTexture synchronizedTexture, out RectangleF textureSubRectangle)
 {
     lock (this.lockObject)
     {
         if (this.sharpDXContext == null || this.sharpDXContext.IsDisposed)
         {
             synchronizedTexture = this.synchronizedTexture;
             textureSubRectangle = new RectangleF(0.0f, 0.0f, surfaceSize.Width, surfaceSize.Height);
         }
         else
         {
             if (this.synchronizedTexture == null)
             {
                 this.sharpDXContext.BackBufferSize = new Size((double)surfaceSize.Width, (double)surfaceSize.Height);
                 this.sharpDXContext.RecreateBackBuffer(this.sharpDXContext.BackBufferSize);
                 this.sharpDXContext.D3DContext.Rasterizer.SetViewport(new ViewportF(0.0f, 0.0f, surfaceSize.Width, surfaceSize.Height));
                 this.synchronizedTexture = this.runtimeHost.CreateSynchronizedTexture(this.sharpDXContext.BackBuffer);
             }
             synchronizedTexture = this.synchronizedTexture;
             textureSubRectangle = new RectangleF(0.0f, 0.0f, surfaceSize.Width, surfaceSize.Height);
             this.synchronizedTexture.BeginDraw();
             this.sharpDXContext.OnRender();
             this.synchronizedTexture.EndDraw();
             this.runtimeHost.RequestAdditionalFrame();
         }
     }
 }
Пример #27
0
        public void Size2F_Area_IsCalculatedCorrectly()
        {
            var size1 = new Size2F(123.45f, 456.78f);
            TheResultingValue(size1.Area).ShouldBe(123.45f * 456.78f);

            var size2 = new Size2F(222.22f, 55555.55f);
            TheResultingValue(size2.Area).ShouldBe(222.22f * 55555.55f);
        }
Пример #28
0
 protected override Size2F CalculateInnerDesiredSize(Size2F totalSize)
 {
     using (GraphicsPath p = CalculateTransformedPath(ParsePath(), new SharpDX.RectangleF(0, 0, 0, 0)))
     {
         RectangleF bounds = p.GetBounds();
         return(new Size2F(bounds.Width, bounds.Height));
     }
 }
Пример #29
0
            protected override Size2F MeasureOverride(Size2F availableSize)
            {
                textRenderable.MaxWidth  = availableSize.Width;
                textRenderable.MaxHeight = availableSize.Height;
                var metrices = textRenderable.Metrices;

                return(new Size2F(metrices.WidthIncludingTrailingWhitespace, metrices.Height));
            }
Пример #30
0
        /// <summary>
        ///     指定したサイズの、空のテクスチャを作成する。
        /// </summary>
        public テクスチャ(Size2F サイズ, BindFlags bindFlags = BindFlags.ShaderResource)
        {
            this._bindFlags = bindFlags;

            // ↓ どちらかを選択的に指定すること。
            this._画像ファイルパス = null;   // 非選択
            this.ユーザ指定サイズ  = サイズ;    // 選択
        }
Пример #31
0
        public void Size2F_Parse_SucceedsForValidStrings()
        {
            var str    = "123.45 456.78";
            var result = Size2F.Parse(str);

            TheResultingValue(result)
            .ShouldBe(123.45f, 456.78f);
        }
Пример #32
0
        public void Size2F_EqualsObject()
        {
            var size1 = new Size2F(123.45f, 456.78f);
            var size2 = new Size2F(123.45f, 456.78f);

            TheResultingValue(size1.Equals((Object)size2)).ShouldBe(true);
            TheResultingValue(size1.Equals("This is a test")).ShouldBe(false);
        }
Пример #33
0
 /// <summary>
 ///     指定したサイズの、空の描画可能画像を作成する。
 /// </summary>
 public 描画可能画像(Size2F サイズ, BindFlags bindFlags = BindFlags.ShaderResource | BindFlags.RenderTarget)
     : base(
         Global.GraphicResources.D3D11Device1,
         Global.GraphicResources.既定のD2D1DeviceContext,
         サイズ,
         bindFlags)
 {
 }
Пример #34
0
 public ArcSegment(Vector2 point, Size2F size, float rotation, D2D.SweepDirection sweepDirection, D2D.ArcSize arcSize)
 {
     Point          = point;
     Size           = size;
     Rotation       = rotation;
     SweepDirection = sweepDirection;
     ArcSize        = arcSize;
 }
Пример #35
0
 protected virtual Size2F MeasureOverride(Size2F availableSize)
 {
     for (int i = 0; i < ItemsInternal.Count; ++i)
     {
         ItemsInternal[i].Measure(availableSize);
     }
     return(availableSize);
 }
Пример #36
0
		/// <summary>
		/// 使用指定的设置初始化 <see cref="ArcSegment"/> 类的新实例。
		/// </summary>
		/// <param name="end">弧线路径段的终结点。</param>
		/// <param name="size">弧线路径段的尺寸。</param>
		/// <param name="rotationAngel">弧线路径段的旋转角度。</param>
		/// <param name="sweepDirection">弧线路径段的绘制方向。</param>
		/// <param name="arcSize">弧线路径段是否大于 180 度。</param>
		public ArcSegment(Vector2 end, Size2F size, float rotationAngel,
			SweepDirection sweepDirection, ArcSize arcSize)
			: base(PathType.Arc, end)
		{
			this.Size = size;
			this.RotationAngle = rotationAngel;
			this.SweepDirection = sweepDirection;
			this.ArcSize = arcSize;
		}
Пример #37
0
        public void Size2F_EqualsSize2F()
        {
            var size1 = new Size2F(123.45f, 456.78f);
            var size2 = new Size2F(123.45f, 456.78f);
            var size3 = new Size2F(123.45f, 555.55f);
            var size4 = new Size2F(222.22f, 456.78f);

            TheResultingValue(size1.Equals(size2)).ShouldBe(true);
            TheResultingValue(size1.Equals(size3)).ShouldBe(false);
            TheResultingValue(size1.Equals(size4)).ShouldBe(false);
        }
Пример #38
0
        public void Size2F_OpInequality()
        {
            var size1 = new Size2F(123.45f, 456.78f);
            var size2 = new Size2F(123.45f, 456.78f);
            var size3 = new Size2F(123.45f, 555.55f);
            var size4 = new Size2F(222.22f, 456.78f);

            TheResultingValue(size1 != size2).ShouldBe(false);
            TheResultingValue(size1 != size3).ShouldBe(true);
            TheResultingValue(size1 != size4).ShouldBe(true);
        }
Пример #39
0
 public void DrawBitmap(Bitmap bitmap, Size2F frameSize,
     Vector2 position, RectangleF srcRectangleF, float opacity = 1f)
 {
     target.DrawBitmap(bitmap,
                       new RectangleF(position.X, position.Y,
                                      frameSize.Width,
                                      frameSize.Height),
                       opacity,
                       BitmapInterpolationMode.NearestNeighbor,
                       srcRectangleF
         );
 }
Пример #40
0
        protected override void Initialize(DeviceChild view)
        {
            // The initialize method will override the view.Tag, so we are setting it back
            base.Initialize(view);

            var shaderResourceView = view as ShaderResourceView;
            int mipLevel = 0;
            bool isMultisampled = Texture.Description.SampleDescription.Count > 1;

            if (shaderResourceView != null)
            {
                mipLevel = isMultisampled ? 0 : shaderResourceView.Description.Texture1D.MostDetailedMip;
            }
            else
            {
                var renderTargetView = view as RenderTargetView;
                if (renderTargetView != null)
                {
                    IsRenderView = true;
                    mipLevel = isMultisampled ? 0 : renderTargetView.Description.Texture1D.MipSlice;
                }
                else
                {
                    var depthStencilView = view as DepthStencilView;
                    if (depthStencilView != null)
                    {
                        IsDepthStencilView = true;
                        mipLevel = isMultisampled ? 0 : depthStencilView.Description.Texture1D.MipSlice;
                    }
                    else
                    {
                        throw new ArgumentException("Expecting argument to be a ShaderResourceView, RenderTargetView or DepthStencilView", "view");
                    }
                }
            }
            Size = new Size2(Math.Max(1, Texture.Width >> mipLevel), Math.Max(1, Texture.Height >> mipLevel));

            TexelSize = new Size2F
            {
                Width = 1.0f / Size.Width,
                Height = 1.0f / Size.Height
            };
        }
Пример #41
0
        /// <summary>
        /// Binds to pointer events of specified <paramref name="nativeWindow"/> object and raises the corresponding events on <paramref name="manager"/>.
        /// </summary>
        /// <param name="nativeWindow">An instance of either <see cref="CoreWindow"/> or <see cref="UIElement"/> object.</param>
        /// <exception cref="ArgumentNullException">Is thrown when <paramref name="nativeWindow"/> is null.</exception>
        protected override void BindWindow(object nativeWindow)
        {
            if (nativeWindow == null) throw new ArgumentNullException("nativeWindow");

            var window = nativeWindow as CoreWindow;
            if (window != null)
            {
                windowSize = new Size2F((float)window.Bounds.Width, (float)window.Bounds.Height);
                window.SizeChanged += window_SizeChanged;

                window.PointerCaptureLost += (_, e) => CreateAndAddPoint(PointerEventType.CaptureLost, e.KeyModifiers, e.CurrentPoint);
                window.PointerEntered += (_, e) => CreateAndAddPoint(PointerEventType.Entered, e.KeyModifiers, e.CurrentPoint);
                window.PointerExited += (_, e) => CreateAndAddPoint(PointerEventType.Exited, e.KeyModifiers, e.CurrentPoint);
                window.PointerMoved += (_, e) => CreateAndAddPoint(PointerEventType.Moved, e.KeyModifiers, e.CurrentPoint);
                window.PointerPressed += (_, e) => CreateAndAddPoint(PointerEventType.Pressed, e.KeyModifiers, e.CurrentPoint);
                window.PointerReleased += (_, e) => CreateAndAddPoint(PointerEventType.Released, e.KeyModifiers, e.CurrentPoint);
                window.PointerWheelChanged += (_, e) => CreateAndAddPoint(PointerEventType.WheelChanged, e.KeyModifiers, e.CurrentPoint);
                return;
            }

            uiElement = nativeWindow as FrameworkElement;
            if (uiElement != null)
            {
                windowSize = new Size2F((float)uiElement.ActualWidth, (float)uiElement.ActualHeight);
                uiElement.Loaded += HandleLoadedEvent;
                uiElement.SizeChanged += HandleSizeChangedEvent;
                
                uiElement.PointerCaptureLost += (_, e) => CreateAndAddPoint(PointerEventType.CaptureLost, e.KeyModifiers, e.GetCurrentPoint(uiElement));
                uiElement.PointerEntered += (_, e) => CreateAndAddPoint(PointerEventType.Entered, e.KeyModifiers, e.GetCurrentPoint(uiElement));
                uiElement.PointerExited += (_, e) => CreateAndAddPoint(PointerEventType.Exited, e.KeyModifiers, e.GetCurrentPoint(uiElement));
                uiElement.PointerMoved += (_, e) => CreateAndAddPoint(PointerEventType.Moved, e.KeyModifiers, e.GetCurrentPoint(uiElement));
                uiElement.PointerPressed += (_, e) => CreateAndAddPoint(PointerEventType.Pressed, e.KeyModifiers, e.GetCurrentPoint(uiElement));
                uiElement.PointerReleased += (_, e) => CreateAndAddPoint(PointerEventType.Released, e.KeyModifiers, e.GetCurrentPoint(uiElement));
                uiElement.PointerWheelChanged += (_, e) => CreateAndAddPoint(PointerEventType.WheelChanged, e.KeyModifiers, e.GetCurrentPoint(uiElement));
                return;
            }

            throw new ArgumentException("Should be an instance of either CoreWindow or UIElement", "nativeWindow");
        }
        private void CreateWindowSizeDependentResources(Size2F size)
        {
            Texture2DDescription renderTargetDesc = new Texture2DDescription
            {
                Format = SharpDX.DXGI.Format.B8G8R8A8_UNorm,
                Width = (int)size.Width,
                Height = (int)size.Height,
                ArraySize = 1,
                MipLevels = 1,
                BindFlags = BindFlags.RenderTarget | BindFlags.ShaderResource,
                Usage = ResourceUsage.Default,
                CpuAccessFlags = CpuAccessFlags.None,
                OptionFlags = ResourceOptionFlags.SharedKeyedmutex | ResourceOptionFlags.SharedNthandle,
                SampleDescription = new SharpDX.DXGI.SampleDescription(1, 0)
            };

            _renderTarget = ToDispose(new Texture2D(_device, renderTargetDesc));
            _renderTargetView = ToDispose(new RenderTargetView(_device, _renderTarget));

            var viewport = new SharpDX.ViewportF(0, 0, (float)size.Width, (float)size.Height);
            _deviceContext.Rasterizer.SetViewport(viewport);
        }
Пример #43
0
        public Sprite(string path, int row = 1, int col = 1, float animationDuration = 1f)
        {
            TextureId = Game.Instance.ResourcesManager.GetTextureIdFromPath(path);
            Texture = Game.Instance.ResourcesManager.GetResourceFromId(TextureId);
            Row = row;
            Col = col;
            AnimationDuration = animationDuration;
            FrameIndex = 0;
            FrameCount = Row * Col;
            TrimAreaList = new RectangleF[FrameCount];

            var rectWidth = TextureSize.Width / Col;
            var rectHeight = TextureSize.Height / Row;
            FrameSize = new Size2F(rectWidth, rectHeight);
            for (var i = 0; i < Col; i++) {
                for (var j = 0; j < Row; j++) {
                    TrimAreaList[i + j * Col] = new RectangleF(
                        i * rectWidth, j * rectHeight, rectWidth, rectHeight);
                }
            }
            Game.Instance.UpdateDispatcher.Schedule(AnimationUpdate, AnimationDuration);
            Game.Instance.UpdateDispatcher.Schedule(Update);
        }
Пример #44
0
 private void HandleLoadedEvent(object sender, RoutedEventArgs e)
 {
     windowSize = new Size2F((float)uiElement.ActualWidth, (float)uiElement.ActualHeight);
 }
Пример #45
0
 private void HandleSizeChangedEvent(object sender, SizeChangedEventArgs e)
 {
     windowSize = new Size2F((float)e.NewSize.Width, (float)e.NewSize.Height);
 }
 /// <summary>
 /// Called when the resources need to be prepared.
 /// </summary>
 /// <param name="presentTargetTime">Present target time.</param>
 /// <param name="desiredRenderTargetSize">Desired drawing size.</param>
 public override void PrepareResources(DateTime presentTargetTime, ref Size2F desiredRenderTargetSize)
 {
 }
Пример #47
0
        internal void GetTexture(Size2F surfaceSize, DrawingSurfaceSynchronizedTexture synchronizedTexture, RectangleF textureSubRectangle)
        {
            _timer.Update();
            _renderer.Update(_timer.Total, _timer.Delta);
            _renderer.Render();

            if (RequestAdditionalFrame!=null) RequestAdditionalFrame();
        }
 public abstract void PrepareResources(DateTime presentTargetTime, ref Size2F desiredRenderTargetSize);
Пример #49
0
 protected override Size2F CalculateInnerDesiredSize(Size2F totalSize)
 {
   using (GraphicsPath p = CalculateTransformedPath(ParsePath(), new SharpDX.RectangleF(0, 0, 0, 0)))
   {
     RectangleF bounds = p.GetBounds();
     return new Size2F(bounds.Width, bounds.Height);
   }
 }
        //private string CreateFont(string fontName, float fontSize, CCRawList<char> charset)
        private Font CreateFont(string fontName, float fontSize)
        {
            Font _currentFont;

            if (Factory2D == null)
            {
                Factory2D = new SharpDX.Direct2D1.Factory();
                FactoryDWrite = new SharpDX.DirectWrite.Factory();
                FactoryImaging = new SharpDX.WIC.ImagingFactory();

                dpi = Factory2D.DesktopDpi;
                dpiScale = dpi.Height / 72f;

            }

            _currentFontCollection = FactoryDWrite.GetSystemFontCollection(true);

            if (_defaultFont == null)
            {
                _defaultFont = GenericSanSerif();
            }

            FontFamily fontFamily = GetFontFamily(fontName);


            FontCollection fontCollection;

            if (!_fontCollectionCache.TryGetValue(fontName, out fontCollection))
            {
                var ext = Path.GetExtension(fontName);

                if (!String.IsNullOrEmpty(ext) && ext.ToLower() == ".ttf")
                {
                    try
                    {
                        var fileFontLoader = new FileFontLoader(FactoryDWrite, fontName);
                        var fileFontCollection = new FontCollection(FactoryDWrite, fileFontLoader, fileFontLoader.Key);
                        _currentFontCollection = fileFontCollection;
                        fontFamily = _currentFontCollection.GetFontFamily(0);
                        var ffn = fontFamily.FamilyNames;
                        _currentFont = fontFamily.GetFirstMatchingFont(FontWeight.Regular, FontStretch.Normal, FontStyle.Normal);

                        _fontCollectionCache.Add(fontName, fileFontCollection);
                        _currentFontCollection = fileFontCollection;
                    }
                    catch
                    {
                        _currentFont = GetFont(fontName, fontSize);
                        CCLog.Log("{0} not found.  Defaulting to {1}.", fontName, _currentFont.FontFamily.FamilyNames.GetString(0));
                    }
                }
                else
                {
                    _currentFont = GetFont(fontName, fontSize);
                }

            }
            else
            {
                fontFamily = fontCollection.GetFontFamily(0);

                _currentFont = fontFamily.GetFirstMatchingFont(FontWeight.Regular, FontStretch.Normal, FontStyle.Normal);
                _currentFontCollection = fontCollection;
            }

            return _currentFont;
        }
Пример #51
0
        public void Size2F_SerializesToJson_WhenNullable()
        {
            var size = new Size2F(1.2f, 2.3f);
            var json = JsonConvert.SerializeObject((Size2F?)size);

            TheResultingString(json).ShouldBe(@"{""width"":1.2,""height"":2.3}");
        }
Пример #52
0
 void IDrawingSurfaceBackgroundContentProviderNative.PrepareResources(
     DateTime presentTargetTime,
     ref Size2F desiredRenderTargetSize)
 {
 }
Пример #53
0
        private string CreateFont(string fontName, float fontSize, CCRawList<char> charset)
        {

            if (Factory2D == null)
            {
                Factory2D = new SharpDX.Direct2D1.Factory();
                FactoryDWrite = new SharpDX.DirectWrite.Factory();
                FactoryImaging = new SharpDX.WIC.ImagingFactory();
                
                dpi = Factory2D.DesktopDpi;
                dpiScale = dpi.Height / 72f;
            }

            if (_defaultFont == null)
            {
                _defaultFont = GenericSanSerif();
                //_defaultDIP = ConvertPointSizeToDIP(_defaultFontSizeEm);
            }

            FontFamily fontFamily = GetFontFamily(fontName);


            if (!_fontFamilyCache.TryGetValue(fontName, out fontFamily))
            {
                var ext = Path.GetExtension(fontName);

                _currentFont = _defaultFont;

                if (!String.IsNullOrEmpty(ext) && ext.ToLower() == ".ttf")
                {
                    //var appPath = AppDomain.CurrentDomain.BaseDirectory;
                    //var contentPath = Path.Combine(appPath, CCApplication.SharedApplication.Content.RootDirectory);
                    //var fontPath = Path.Combine(contentPath, fontName);

                    //if (File.Exists(fontPath))
                    //{
                       // try
                        //{
                            //var fontFileReference = new FontCollection(
                            //_loadedFonts.AddFontFile(fontPath);

                    //        //fontFamily = _loadedFonts.Families[_loadedFonts.Families.Length - 1];

                    //        //_currentFont = new Font(fontFamily, fontSize);
                    //    }
                    //    catch
                    //    {
                    //        _currentFont = _defaultFont;
                    //    }
                    //}
                    //else
                    //{
                        _currentFont = _defaultFont;
                        _currentFontSizeEm = fontSize;
                        _currentDIP = ConvertPointSizeToDIP(fontSize);
                    //}
                }
                else
                {
                    _currentFont = GetFont(fontName, fontSize);
                    _currentFontSizeEm = fontSize;
                    _currentDIP = ConvertPointSizeToDIP(fontSize);
                }

                _fontFamilyCache.Add(fontName, _currentFont.FontFamily);
            }
            else
            {
                _currentFont = fontFamily.GetFirstMatchingFont(FontWeight.Regular, FontStretch.Normal, FontStyle.Normal);
                _currentFontSizeEm = fontSize;
                _currentDIP = ConvertPointSizeToDIP(fontSize);
            }
            fontName = _currentFont.FontFamily.FamilyNames.GetString(0); 
            textFormat = new TextFormat(FactoryDWrite, fontName, _currentDIP);
            
            GetKerningInfo(charset);

            return _currentFont.ToString();
        }
Пример #54
0
    protected override Size2F CalculateInnerDesiredSize(Size2F totalSize)
    {
      using (GraphicsPath p = GetLine(new RectangleF(0, 0, totalSize.Width, totalSize.Height)))
      {
        RectangleF bounds = p.GetBounds();

        return new Size2F(bounds.Width, bounds.Height);
      }
    }
        void IDrawingSurfaceContentProviderNative.GetTexture(Size2F surfaceSize, out DrawingSurfaceSynchronizedTexture synchronizedTexture, out RectangleF textureSubRectangle)
        {
            try
            {
                if (!Exiting)
                {
                    // TODO Check if surfaceSize changed to reinitialize the buffers?
                    currentSize = surfaceSize;

                    if (!isInitialized)
                    {
                        InitCallback();
                        isInitialized = true;
                    }
                    else if (this.synchronizedTexture == null)
                    {
                        // Dispose the graphics device
                        if (graphicsDeviceService.GraphicsDevice != null)
                        {
                            graphicsDeviceService.GraphicsDevice.Dispose();
                        }

                        // Make sure that the graphics device is created
                        // This will create indirectly the synchronizedTexture on this instance.
                        graphicsDeviceManager.CreateDevice();
                    }

                    this.synchronizedTexture.BeginDraw();

                    RunCallback();

                    host.RequestAdditionalFrame();

                    this.synchronizedTexture.EndDraw();
                }
            }
            catch (Exception ex)
            {
                // TODO: As we are in a callback from a native code, we cannot pass back this exception,
                // so how to pass back this exception to the user at an appropriate time?
                drawException = ex;
                Debug.WriteLine(drawException);
            }

            // Set output parameters.
            textureSubRectangle = new RectangleF(0f, 0f, surfaceSize.Width, surfaceSize.Height);
            synchronizedTexture = this.synchronizedTexture;
        }
Пример #56
0
 public void UpdateGameWindowSize(Size2F desiredRenderTargetSize)
 {
     WindowsPhoneGameWindow.Width = desiredRenderTargetSize.Width;
     WindowsPhoneGameWindow.Height = desiredRenderTargetSize.Height;
 }
Пример #57
0
 public static RectangleF CreateRectangleF(Vector2 location, Size2F size)
 {
   return new RectangleF(location.X, location.Y, size.Width, size.Height);
 }
Пример #58
0
 /// <summary>
 /// Wraps the specified unit test result for evaluation.
 /// </summary>
 /// <param name="value">The value to wrap.</param>
 /// <returns>The wrapped value.</returns>
 protected static Size2FResult TheResultingValue(Size2F value)
 {
     return new Size2FResult(value);
 }
Пример #59
0
 void window_SizeChanged(CoreWindow sender, WindowSizeChangedEventArgs args)
 {
     windowSize = new Size2F((float)args.Size.Width, (float)args.Size.Height);
     args.Handled = true;
 }
Пример #60
0
        /// <summary>
        /// Draws the text.
        /// </summary>
        /// <param name="p">The position.</param>
        /// <param name="text">The text.</param>
        /// <param name="fill">The fill color.</param>
        /// <param name="fontFamily">The font family.</param>
        /// <param name="fontSize">Size of the font.</param>
        /// <param name="fontWeight">The font weight.</param>
        /// <param name="rotate">The rotation angle.</param>
        /// <param name="halign">The horizontal alignment.</param>
        /// <param name="valign">The vertical alignment.</param>
        /// <param name="maxSize">The maximum size of the text.</param>
        public void DrawText(
            ScreenPoint p,
            string text,
            OxyColor fill,
            string fontFamily,
            double fontSize,
            double fontWeight,
            double rotate,
            OxyPlot.HorizontalAlignment halign,
            OxyPlot.VerticalAlignment valign,
            OxySize? maxSize)
        {
            if (string.IsNullOrWhiteSpace(fontFamily))
            {
                fontFamily = "Arial";
            }

            if (text == null)
            {
                text = string.Empty;
            }

            var format = new TextFormat(this.dwtFactory, fontFamily, GetFontWeight(fontWeight), FontStyle.Normal, FontStretch.Normal, (float)fontSize);
            var maxWidth = 1000f;
            var maxHeight = 1000f;
            if (maxSize != null)
            {
                maxHeight = (float)maxSize.Value.Height;
                maxWidth = (float)maxSize.Value.Width;
            }

            var layout = new TextLayout(this.dwtFactory, text, format, maxWidth, maxHeight);

            var size = new Size2F(layout.Metrics.Width, layout.Metrics.Height);
            if (maxSize != null)
            {
                if (size.Width > maxSize.Value.Width)
                {
                    size.Width = (float)maxSize.Value.Width;
                }

                if (size.Height > maxSize.Value.Height)
                {
                    size.Height = (float)maxSize.Value.Height;
                }
            }

            float dx = 0;
            if (halign == OxyPlot.HorizontalAlignment.Center)
            {
                dx = -size.Width / 2;
            }

            if (halign == OxyPlot.HorizontalAlignment.Right)
            {
                dx = -size.Width;
            }

            float dy = 0;
            if (valign == OxyPlot.VerticalAlignment.Middle)
            {
                dy = -size.Height / 2;
            }

            if (valign == OxyPlot.VerticalAlignment.Bottom)
            {
                dy = -size.Height;
            }

            this.renderUnits.Add(new TextRenderUnit(layout, this.GetBrush(fill), Matrix3x2.Translation(dx, dy) * Matrix3x2.Rotation((float)rotate) * Matrix3x2.Translation(p.ToVector2())));
            format.Dispose();
        }