Jump to content
  • Advertisement
Steven Ford

C# Custom Control Scaling issue in Level Designer (WinForms)

This topic is 455 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi,

I'm currently writing a level designer for my 2D game*. To do so, I'm writing this using c# / WinForms. The editor is designed to look a bit like VS, ie. a set of tool boxes surrounding a central panel to show the various tiles and game objects. I've got this central panel as a custom control (inheriting directly from Control) using custom rendering. The development machine that I'm using is using a 27" 4k display and so I've set Windows up to use a text zoom of 150% to avoid killing my eyes.

Unfortunately, when I use my standard drawing code of (within the OnPaint override):

                    var location = new System.Drawing.Point(
                        offsetX + (tilePair.Key.X * tileLayer.TileSize.Width ),
                        offsetY + (tilePair.Key.Y * tileLayer.TileSize.Height ) );
                    var destRectangle = new Rectangle( location, tileLayer.TileSize );

                    if( pe.ClipRectangle.IntersectsWith( destRectangle ) )
                    {
                        pe.Graphics.DrawImage( tilePair.Value.Image,
                            destRectangle,
                            tilePair.Value.TileRectangle,
                            GraphicsUnit.Pixel );
                    }

The actual rendering is being done at 150% size of the destRectangle (~96 pixels vs. 64 that's expected). 

This isn't necessarily a problem so long as I can source that scale factor in advance so I can ensure the appropriate resizing / layout code. Googling doesn't lead to much info on how to source this information and there's nothing obvious that I can find in intellisense as to give me pointers as to where to investigate further.

So... does anyone have either any ideas as to how to solve this or links to places where I can investigate this sort of issue.

Thanks in advance

Steve

*originally, I was using Tiled - which is rather good, but for various reasons I wanted to write my own. 1. so I can define custom objects with a fixed set of properties for level designers who aren't that technical to use and 2. to use it as a learning exercise around the command pattern.

Share this post


Link to post
Share on other sites
Advertisement

This article may be of some use to you. IIRC you can directly access the display's DPI (dots per inch) settings from a Graphics object in C#/WinForms, but I'd recommend reading the whole article as there are some subtle gotchas in DPI-awareness.

Share this post


Link to post
Share on other sites

Thanks @ApochPiQ.

It's now vaguely working - I'm now needing to get the control embedded within a centring control with scrollbars, but I think that's a slightly different question! :-)

Share this post


Link to post
Share on other sites

You should be able to just drop your control inside a Panel control and call it a day, if I understand your requirements correctly.

Share this post


Link to post
Share on other sites

Unfortunately, just dropping it within a panel, setting that to AutoScroll=true requires my control to be anchored to top, left (if anchored to bottom / right, then the scrollbars disappear). This doesn't handle centring nicely. So currently, I've done the above and said that it's a tool for me and so I can deal with the ugliness.

Given that I want to, shortly, add a zoom feature into the custom control, I guess I'll park this complexity and come back to it. Get the rest of the functionality working before worrying about the prettification

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!