CUGL
Cornell University Game Library
|
#include <CUDisplay.h>
Public Types | |
enum | Aspect : unsigned int { Aspect::SQUARE = 0, Aspect::PORTRAIT_3_4 = 1, Aspect::PORTRAIT_2_3 = 2, Aspect::PORTRAIT_10_16 = 3, Aspect::PORTRAIT_3_5 = 4, Aspect::PORTRAIT_9_16 = 5, Aspect::PORTRAIT_600_1024 = 6, Aspect::PORTRAIT_IPAD_PRO = 7, Aspect::LANDSCAPE_4_3 = 8, Aspect::LANDSCAPE_3_2 = 9, Aspect::LANDSCAPE_16_10 = 10, Aspect::LANDSCAPE_5_3 = 11, Aspect::LANDSCAPE_16_9 = 12, Aspect::LANDSCAPE_1024_600 = 13, Aspect::LANDSCAPE_IPAD_PRO = 14, Aspect::UKNOWN = 15 } |
Public Member Functions | |
const Rect & | getBounds () const |
Rect | getPixelBounds () const |
const Rect & | getUsableBounds () const |
const Vec2 & | getPixelDensity () const |
Aspect | getAspect () const |
bool | isLandscape () const |
bool | isPortrait () const |
float | getAspectRatio () const |
const std::string | getAspectName () const |
int | widthForHeight (int height) const |
int | heightForWidth (int width) const |
Static Public Member Functions | |
static bool | start () |
static void | stop () |
static Display * | get () |
static Aspect | getAspect (float ratio) |
static float | getAspectRatio (Aspect aspect) |
static const std::string | getAspectName (Aspect aspect) |
static int | widthForHeight (int height, Aspect aspect) |
static int | heightForWidth (int width, Aspect aspect) |
Protected Member Functions | |
Display () | |
bool | init () |
void | dispose () |
~Display () | |
Protected Attributes | |
Aspect | _aspect |
Rect | _bounds |
Rect | _usable |
Vec2 | _scale |
Static Protected Attributes | |
static Display * | _thedisplay |
This class is a singleton representing the native display.
The static methods of this class start() and stop() the SDL video system. Without it, you cannot draw anything. This should be the first and last methods called in any application. The Application class does this for you automatically.
The singleton display object also has several methods to get the (current) screen resolution and aspect ratio. The most important of these two is the the aspect ratio. Aspect ratio is one of the most unportable parts of cross-platform development. Everything else can be scaled to the screen, but the aspect ratio is fixed from the very beginning.
If the device has multiple displays, this singleton will only refer to the main display.
|
strong |
The display aspect ratio.
This enum includes support for almost every shipping aspect rations. For information on your device, see
http://mydevice.io/devices/
|
protected |
|
inlineprotected |
Deletes this object, releasing all resources.
This method quits the SDL video system, effectively exitting shutting down the entire program.
WARNING: This class is a singleton. You should never access this destructor directly. Use the stop() method instead.
|
protected |
Uninitializes this object, releasing all resources.
This method quits the SDL video system, effectively exitting shutting down the entire program.
WARNING: This class is a singleton. You should never access this method directly. Use the stop() method instead.
|
inlinestatic |
Returns the singleton instance for the display
You must call this static method first to get information about your specific display. This method will return nullptr until start() is called first.
|
inline |
Returns the aspect of this monitor.
The aspect is returned as an enum, not a ratio. Round off error might cause devices with very similar aspect ratios to have slightly different ratio values. Therefore, the enum is a way of normalizing device aspects.
If you would like to know the actual ratio, use the method getAspectRatio() instead. In addition, there are methods for computing width from height and vice versa.
Device aspects are relatively standardized. For information on your device, see
http://mydevice.io/devices/
|
static |
Returns the aspect for the given aspect ratio.
It is safest to represent aspects as an enum, not a ratio. Round off error might cause devices with very similar aspect ratios to have slightly different ratio values. Therefore, the enum is a way of normalizing device aspects.
Device aspects are relatively standardized. For information on your device, see
http://mydevice.io/devices/
This method is guaranteed to match every aspect ratio on that page. If the aspect ratio is not on that page, it will return UNKNOWN.
ratio | The aspect ratio in the form width/height |
|
inline |
Returns a string representation of the device aspect ratio
This value is useful for debugging. The first part of the string, before the space, is guaranteed to be in the format x:y
|
static |
Returns a string representation of the given aspect
This value is useful for debugging. The first part of the string, before the space, is guaranteed to be in the format x:y
aspect | The device aspect value |
|
inline |
Returns the device aspect ratio
The value is computed width/height.
|
static |
Returns the aspect ratio for the given aspect.
The value is computed width/height. If the aspect is UNKNOWN, it will return 0.
aspect | The device aspect value |
|
inline |
Returns the full screen resolution for this display
This method returns the bounds for the current resolution, not the maximum resolution. You should never change the resolution of a display. Allow the user to have their preferred resolution. Instead, you should adjust your camera to scale the viewport.
The value returned represents points, not pixels. If you are using a traditional display, these are the same. However, on Retina displays and other high DPI monitors, these may be different. Regardless, you should always work with points, not pixels, when computing the screen size. In particular, this is what you should assign the OpenGL viewport when using fullscreen.
|
inline |
Returns the full screen resolution for this display
This method returns the bounds for the current resolution, not the maximum resolution. You should never change the resolution of a display. Allow the user to have their preferred resolution. Instead, you should adjust your camera to scale the viewport.
The value returned represents the value pixels, not points. This is to help align the results with input devices on Retina displays and other high DPI monitors.
|
inline |
Returns the number of pixels for each point.
A point is a logical screen pixel. If you are using a traditional display, points and pixels are the same. However, on Retina displays and other high dpi monitors, they may be different. In particular, the number of pixels per point is a scaling factor times the point.
You should never need to use these scaling factor for anything, as it is not useful for determining anything other than whether a high DPI display is present. It does not necessarily refer to physical pixel on the screen. In some cases (OS X Retina displays), it refers to the pixel density of the backing framebuffer, which may be different from the physical framebuffer.
|
inline |
Returns the usable full screen resolution for this display
Usable is a subjective term defined by the operating system. In general, it means the full screen minus any space used by important user interface elements, like a status bar (iPhone), menu bar (OS X), or task bar (Windows).
This method computes the bounds for the current resolution, not the maximum resolution. You should never change the resolution of a display. Allow the user to have their preferred resolution. Instead, you should adjust your camera to scale the viewport.
The value returned represents points, not pixels. If you are using a traditional display, these are the same. However, on Retina displays and other high DPI monitors, these may be different. Regardless, you should always work with points, not pixels, when computing the screen size.
|
inline |
Returns the closest height value for the device aspect ratio.
This value is used when you want to scale a viewpoint to match the display. The value returned is rounded up to the nearest int, assuming that you want the viewport in points.
width | The width in points |
|
inlinestatic |
Returns the closest height value for the given aspect
This value is used when you want to scale a viewpoint to match the display. The value returned is rounded up to the nearest int, assuming that you want the viewport in points.
width | The width in points |
aspect | The device aspect value |
|
protected |
Initializes the display with the current screen information.
This method gathers the native resolution bounds and pixel density using platform-specific tools.
WARNING: This class is a singleton. You should never access this initializer directly. Use the start() method instead.
|
inline |
Returns true if this device has a landscape orientation
|
inline |
Returns true if this device has a portrait orientation
|
static |
Starts up the SDL display and video system.
This static method needs to be the first line of any application, though it is handled automatically in the Application class.
Once this method is called, the get() method will no longer return a null value.
|
static |
Shuts down the SDL display and video system.
This static method needs to be the last line of any application, though it is handled automatically in the Application class.
Once this method is called, the get() method will return nullptr. More importantly, no SDL function calls will work anymore.
|
inline |
Returns the closest width value for the device aspect ratio.
This value is used when you want to scale a viewpoint to match the display. The value returned is rounded up to the nearest int, assuming that you want the viewport in points.
height | The height in points |
|
inlinestatic |
Returns the closest width value for the given aspect
This value is used when you want to scale a viewpoint to match the display. The value returned is rounded up to the nearest int, assuming that you want the viewport in points.
height | The height in points |
aspect | The device aspect value |
|
protected |
The aspect ratio (coded as the enum)
|
protected |
The full screen resolution of this device
|
protected |
The pixel density of the device
|
staticprotected |
The display singleton
|
protected |
The full screen resolution minus menu bars and other features