/************************************************************************************ Copyright : Copyright 2014 Oculus VR, LLC. All Rights reserved. Licensed under the Oculus VR Rift SDK License Version 3.2 (the "License"); you may not use the Oculus VR Rift SDK except in compliance with the License, which is provided at the time of installation or download, or which otherwise accompanies this software in either electronic or hard copy form. You may obtain a copy of the License at http://www.oculusvr.com/licenses/LICENSE-3.2 Unless required by applicable law or agreed to in writing, the Oculus VR SDK distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ************************************************************************************/ using UnityEngine; using System.Collections.Generic; /// /// OVRGUI is a GUI help class that provides functions for drawing text and other elements /// to the screen /// public class OVRGUI { private Font FontReplace = null; private float PixelWidth = 1280.0f; private float PixelHeight = 800.0f; // DK1 resolution of W: (1280 / 2) H: 800 private float DisplayWidth = 1280.0f; private float DisplayHeight = 800.0f; private Rect DrawRect; /// /// Gets the replacement font. /// /// Font replace. public void GetFontReplace(ref Font fontReplace) { fontReplace = FontReplace; } /// /// Sets the font replace. /// /// Font replace. public void SetFontReplace(Font fontReplace) { FontReplace = fontReplace; } /// /// Gets the pixel resolution. /// /// Pixel width. /// Pixel height. public void GetPixelResolution(ref float pixelWidth, ref float pixelHeight) { pixelWidth = PixelWidth; pixelHeight = PixelHeight; } /// /// Sets the pixel resolution. /// /// Pixel width. /// Pixel height. public void SetPixelResolution(float pixelWidth, float pixelHeight) { PixelWidth = pixelWidth; PixelHeight = pixelHeight; } /// /// Gets the display resolution. /// /// Width. /// Height. public void GetDisplayResolution(ref float Width, ref float Height) { Width = DisplayWidth; Height = DisplayHeight; } /// /// Sets the display resolution. /// /// Width. /// Height. public void SetDisplayResolution(float Width, float Height) { DisplayWidth = Width; DisplayHeight = Height; } /// /// StereoBox /// Values go from 0 - PixelSizeX/Y /// /// X. /// Y. /// W x. /// H y. /// Text. /// Color. public void StereoBox(int X, int Y, int wX, int hY, ref string text, Color color) { Font prevFont = GUI.skin.font; GUI.color = color; // Make sure to change font if it needs replacement if(GUI.skin.font != FontReplace) GUI.skin.font = FontReplace; float s = PixelWidth / DisplayWidth; CalcPositionAndSize(X * s, Y * s, wX * s, hY * s, ref DrawRect); GUI.Box(DrawRect, text); GUI.skin.font = prevFont; } /// /// Stereos the box. /// Values go from 0.0 - 1.0f; normalized approach to rendering GUI objects /// /// X. /// Y. /// W x. /// H y. /// Text. /// Color. public void StereoBox(float X, float Y, float wX, float hY, ref string text, Color color) { StereoBox ((int)(X * PixelWidth), (int)(Y * PixelHeight), (int)(wX * PixelWidth), (int)(hY * PixelHeight), ref text, color); } /// /// Draw a stereo texture. /// /// X. /// Y. /// W x. /// H y. /// Image. /// Color. public void StereoDrawTexture(int X, int Y, int wX, int hY, ref Texture image, Color color) { GUI.color = color; // Make sure to change font if it needs replacement if(GUI.skin.font != FontReplace) GUI.skin.font = FontReplace; float s = PixelWidth / DisplayWidth; CalcPositionAndSize(X * s, Y * s, wX * s, hY * s, ref DrawRect); GUI.DrawTexture(DrawRect, image); } /// /// Draw a stereo texture. /// /// X. /// Y. /// W x. /// H y. /// Image. /// Color. public void StereoDrawTexture(float X, float Y, float wX, float hY, ref Texture image, Color color) { StereoDrawTexture ((int)(X * PixelWidth), (int)(Y * PixelHeight), (int)(wX * PixelWidth), (int)(hY * PixelHeight), ref image, color); } /// /// Calculates the size of the position. /// /// X. /// Y. /// W x. /// H y. /// Calculate position size. private void CalcPositionAndSize(float X, float Y, float wX, float hY, ref Rect calcPosSize) { float sSX = (float)Screen.width / PixelWidth; float sSY = (float)Screen.height / PixelHeight; calcPosSize.x = X * sSX; calcPosSize.width = wX * sSX; calcPosSize.y = Y * sSY; calcPosSize.height = hY * sSY; } }