Skip to content

Instantly share code, notes, and snippets.

Created July 19, 2017 18:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/eb3eb4f14e9aeb16ffe5eb04c5575bc4 to your computer and use it in GitHub Desktop.
Save anonymous/eb3eb4f14e9aeb16ffe5eb04c5575bc4 to your computer and use it in GitHub Desktop.
ScreenAdapter.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;
using System.Threading.Tasks;
namespace Pharmakon
{
class ScreenAdapter
{
static public Rectangle safe_bounds;
static public Rectangle safe_ui;
static public float supported_w;
static public float supported_h;
static public bool fullscreen = true;
static public float offset;
public ScreenAdapter(GraphicsDeviceManager screen)
{
screen.HardwareModeSwitch = false;
supported_w = 1366;
supported_h = 768;
if (fullscreen == true)
{
screen.PreferredBackBufferWidth = (int)supported_w;
screen.PreferredBackBufferHeight = (int)supported_h;
screen.IsFullScreen = true;
}
if (fullscreen == false)
{
screen.PreferredBackBufferWidth = (int)supported_w;
screen.PreferredBackBufferHeight = (int)supported_h;
screen.IsFullScreen = false;
}
safe_bounds = new Rectangle(0, 0, screen.PreferredBackBufferWidth, screen.PreferredBackBufferHeight);
float marge_factor = (float)supported_w / 30;
float marge = (float)screen.PreferredBackBufferWidth / marge_factor;
marge = (int)marge;
float offset_factor = (float)supported_w / 400;
offset = screen.PreferredBackBufferWidth / offset_factor;
offset = (int)offset;
safe_ui = new Rectangle(safe_bounds.X + 15, safe_bounds.Y + 15, safe_bounds.Width - (int)marge, safe_bounds.Height - (int)marge);
screen.ApplyChanges();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment