Пример #1
0
        /// <summary>Service routine to paint the backing store bitmap for the map underlay.</summary>
        protected virtual Bitmap PaintBuffer(Rectangle clipBounds)
        {
            if (DataContext.Model == null)
            {
                return(null);
            }

            Bitmap bitmap = null, temp = null;

            try {
                temp = ClientSize.AllocateBitmap();
                using (var graphics = Graphics.FromImage(temp)) {
                    graphics.Clip = new Region(clipBounds);
                    graphics.Contain(PaintBuffer);
                }

                bitmap = temp;
                temp   = null;
            } finally { if (temp != null)
                        {
                            temp.Dispose();
                        }
            }

            return(bitmap);
        }
Пример #2
0
 private void SetButtonText()
 {
     button1.Text =
         "Form.FormBoderStyle = " + FormBorderStyle.ToString() + "\n" +
         "Form.Size = " + Size.ToString() + "\n" +
         "Form.ClientSize = " + ClientSize.ToString();
 }
Пример #3
0
        /// <summary>Set ScrollBar increments and bounds from map dimensions.</summary>
        public virtual void SetScrollLimits(IMapDisplayWinForms model)
        {
            if (model == null)
            {
                return;
            }
            var smallChange = Size.Ceiling(model.GridSize.Scale(MapScale));

            HorizontalScroll.SmallChange = smallChange.Width;
            VerticalScroll.SmallChange   = smallChange.Height;

            var largeChange = Size.Round(ClientSize.Scale(0.75F));

            HorizontalScroll.LargeChange = Math.Max(largeChange.Width, smallChange.Width);
            VerticalScroll.LargeChange   = Math.Max(largeChange.Height, smallChange.Height);

            var size = Hexgrid.GetSize(MapSizePixels, MapScale);

            if (AutoScrollMinSize != size)
            {
                AutoScrollMinSize        = size;
                HorizontalScroll.Maximum = Math.Min(1, Math.Max(1, Padding.Left + Padding.Right
                                                                + size.Width - ClientSize.Width));
                VerticalScroll.Maximum = Math.Min(1, Math.Max(1, Padding.Top + Padding.Bottom
                                                              + size.Height - ClientSize.Height));
                Invalidate();
            }
        }
Пример #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MapScreenControl"/> class.
        /// </summary>
        public MapScreenControl()
        {
            if (!DesignMode && LicenseManager.UsageMode != LicenseUsageMode.Runtime)
            {
                return;
            }

            _drawingManager  = new DrawingManager();
            _transBoxManager = new TransBoxManager();
            _camera          = new Camera2D(ClientSize.ToVector2())
            {
                KeepInMap = true
            };

            if (DrawingManager.LightManager.DefaultSprite == null)
            {
                DrawingManager.LightManager.DefaultSprite = new Grh(GrhInfo.GetData("Effect", "light"));
            }

            GlobalState.Instance.Map.SelectedObjsManager.SelectedChanged += SelectedObjsManager_SelectedChanged;

            lock (_instancesSync)
            {
                _instances.Add(this);
            }
        }
        /// <summary>Set ScrollBar increments and bounds from map dimensions.</summary>
        public virtual void SetScrollLimits(IMapDisplay model)
        {
            if (model == null || !AutoScroll)
            {
                return;
            }
            var smallChange = Size.Ceiling(model.GridSize.Scale(MapScale));

            HorizontalScroll.SmallChange = smallChange.Width;
            VerticalScroll.SmallChange   = smallChange.Height;

            var largeChange = Size.Round(ClientSize.Scale(0.75F));

            HorizontalScroll.LargeChange = Math.Max(largeChange.Width, smallChange.Width);
            VerticalScroll.LargeChange   = Math.Max(largeChange.Height, smallChange.Height);

            var size = DataContext.Hexgrid.GetSize(MapSizePixels, MapScale)
                       + Margin.Size;

            if (AutoScrollMinSize != size)
            {
                AutoScrollMinSize        = size;
                HorizontalScroll.Maximum = Math.Min(1, Math.Max(1, Margin.Horizontal
                                                                + size.Width - ClientSize.Width));
                VerticalScroll.Maximum = Math.Min(1, Math.Max(1, Margin.Vertical
                                                              + size.Height - ClientSize.Height));
                Invalidate();
            }
        }
Пример #6
0
        /// <summary>
        /// Rescales.  Only used for dpiAware=true/pm.
        /// </summary>
        private void rescale()
        {
#if doLogging
            logger.log("rescale prevDpi=" + previousDpi
                       + " curDpi=" + currentDpi);
            logger.logControls("rescale (Before) ClientSize=" + ClientSize.ToString());
#endif
            if (previousDpi == 0 || currentDpi == 0)
            {
                return;
            }
            if (initialFont != null)
            {
                float size = initialFont.SizeInPoints * currentDpi / initialDpi;
                Font = new Font(initialFont.Name, size);
            }
            float scale = currentDpi / previousDpi;
#if false
            // Doesn't work
            Scale(new SizeF(scale, scale));
#elif false
            // Doesn't work similar to above
            int width  = (int)Math.Round(ClientSize.Width * currentDpi / previousDpi);
            int height = (int)Math.Round(ClientSize.Height * currentDpi / previousDpi);
#elif true
            int width  = (int)Math.Round(initialSize.Width * currentDpi / initialDpi);
            int height = (int)Math.Round(initialSize.Height * currentDpi / initialDpi);
            ClientSize = new Size(width, height);
#endif
#if doLogging
            logger.logControls("rescale (After) ClientSize=" + ClientSize.ToString());
#endif
        }
Пример #7
0
        /// <summary>
        /// Client size changed
        /// </summary>
        /// <param name="e">event args</param>
        protected override void OnClientSizeChanged(EventArgs e)
        {
            base.OnClientSizeChanged(e);
            if (_firstClientChangedCall)
            {
                _designTimeAspectRatio = (float)ClientSize.Height / ClientSize.Width;

                Log.Debug("HIHIHI ClientSize: " + ClientSize.ToString());
                _firstClientChangedCall = false;
            }
        }
Пример #8
0
        /// <summary>
        /// Raises the <see cref="E:System.Windows.Forms.Control.Resize"/> event.
        /// </summary>
        /// <param name="e">An <see cref="T:System.EventArgs"/> that contains the event data.</param>
        protected override void OnResize(EventArgs e)
        {
            base.OnResize(e);

            if (DesignMode)
            {
                return;
            }

            Camera.Size = ClientSize.ToVector2() * Camera.Scale;
        }
Пример #9
0
        /// <inheritdoc/>
        protected override async void OnPaint(PaintEventArgs e)
        {
            if (e == null)
            {
                throw new ArgumentNullException(nameof(e));
            }
            if (DesignMode)
            {
                e.Graphics.FillRectangle(Brushes.Gray, ClientRectangle);  return;
            }

            if (IsMapDirty)
            {
                OnResize(EventArgs.Empty); IsMapDirty = false;
            }

            // TODO - Fix thread timing error work-around of catching and discarding InvalidOperationException.
            if (_mapBuffer != null)
            {
                try { base.OnPaint(e); } catch (InvalidOperationException) { _count++; }
            }

            var status = Interlocked.CompareExchange(ref _cacheStatus, _IS_PAINTING, _NEEDS_PAINTING);

            if (status == _NEEDS_PAINTING)
            {
                try {
                    if (_backBuffer != null)
                    {
                        _backBuffer.Dispose();
                    }

                    _backBuffer = Interlocked.Exchange(ref _mapBuffer, await PaintBufferAsync(ClientRectangle));

                    if (_backBuffer != null)
                    {
                        _backBuffer.Dispose();
                    }
                    _backBuffer = ClientSize.AllocateBitmap();
                } catch (InvalidOperationException) {
                    if (_backBuffer == null)
                    {
                        _backBuffer = ClientSize.AllocateBitmap();
                    }

                    Interlocked.CompareExchange(ref _cacheStatus, _NEEDS_PAINTING, _IS_PAINTING);
                    Thread.Sleep(250);
                } finally { Interlocked.CompareExchange(ref _cacheStatus, _IS_READY, _IS_PAINTING); }
                Refresh();
            }
            IsUnitsDirty = false;
        }
Пример #10
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MapScreenControl"/> class.
 /// </summary>
 public GrhAtlasView()
 {
     TilesetConfiguration = null;
     if (!DesignMode && LicenseManager.UsageMode != LicenseUsageMode.Runtime)
     {
         return;
     }
     _transBoxManager = new TransBoxManager();
     _camera          = new Camera2D(ClientSize.ToVector2())
     {
         KeepInMap = false
     };
 }
Пример #11
0
        /// <summary>
        /// Raises the <see cref="E:System.Windows.Forms.Control.Resize"/> event.
        /// </summary>
        /// <param name="e">An <see cref="T:System.EventArgs"/> that contains the event data.</param>
        protected override void OnResize(EventArgs e)
        {
            base.OnResize(e);

            if (DesignMode)
            {
                return;
            }

            var oldCenter = Camera.Center;

            Camera.Size = ClientSize.ToVector2();
            Camera.CenterOn(oldCenter);
        }
Пример #12
0
        /// <summary>
        /// Allows derived classes to handle when the <see cref="RenderWindow"/> is created or re-created.
        /// </summary>
        /// <param name="newRenderWindow">The current <see cref="RenderWindow"/>.</param>
        protected override void OnRenderWindowCreated(RenderWindow newRenderWindow)
        {
            base.OnRenderWindowCreated(newRenderWindow);

            if (DesignMode)
            {
                return;
            }

            DrawingManager.RenderWindow = newRenderWindow;

            var oldCenter = Camera.Center;

            Camera.Size = ClientSize.ToVector2();
            Camera.CenterOn(oldCenter);
        }
Пример #13
0
        /// <summary>
        /// Derived classes override this to initialize their drawing code.
        /// </summary>
        protected override void Initialize()
        {
            base.Initialize();

            if (DesignMode)
            {
                return;
            }

            Camera.Size = ClientSize.ToVector2();
            Camera.CenterOn(Vector2.Zero);

            var t = new Timer {
                Interval = 1000 / 60
            };

            t.Tick += (EventHandler)((x, y) => InvokeDrawing(this, EventArgsHelper.Create(TickCount.Now)));
            t.Start();
        }
Пример #14
0
        private async void Lyrics_Shown(object sender, EventArgs e)
        {
            // 초기 설정을 위해 대화 상자 열기
            if (!File.Exists(Settings._Path))
            {
                Task.Run(() => Invoke(new MethodInvoker(menuSetting.PerformClick)));
            }
            while (!Osu.Process.HasExited)
            {
                if (!Osu.Show(true))
                {
                    var osu = Osu.WindowInfo();
                    if (!Location.Equals(osu.Location))
                    {
                        Location = osu.Location;
                    }
                    if (!ClientSize.Equals(osu.ClientSize))
                    {
                        ClientSize             = osu.ClientSize;
                        Settings.DrawingOrigin = Point.Empty;
                    }
                    if (Settings == null)
                    {
                        TopMost = true;
                    }
                    Visible = true;
                }
                else if (Settings.ShowWhileOsuTop)
                {
                    Visible = false;
                }

                if (NewLyricAvailable())
                {
                    Refresh();
                }

                await Task.Delay(Settings.RefreshRate);
            }
            Close();
        }
Пример #15
0
        /// <summary>Set ScrollBar increments and bounds from map dimensions.</summary>
        public virtual void SetScroll()
        {
            var smallChange = Size.Ceiling(Host.GridSize.Scale(MapScale));

            HorizontalScroll.SmallChange = smallChange.Width;
            VerticalScroll.SmallChange   = smallChange.Height;

            var largeChange = Size.Round(ClientSize.Scale(0.75F));

            HorizontalScroll.LargeChange = Math.Max(largeChange.Width, smallChange.Width);
            VerticalScroll.LargeChange   = Math.Max(largeChange.Height, smallChange.Height);

            var size = TransposeSize(Size.Ceiling(MapSizePixels.Scale(MapScale)));

            if (AutoScrollMinSize != size)
            {
                AutoScrollMinSize        = size;
                HorizontalScroll.Maximum = Math.Min(1, Math.Max(1, size.Width - ClientSize.Width));
                VerticalScroll.Maximum   = Math.Min(1, Math.Max(1, size.Height - ClientSize.Height));
                Invalidate();
            }
        }