comparison Orchestland/Assets/OVR/Scripts/Util/OVRGUI.cs @ 1:f7675884f2a1

Add Orchestland project
author Daiki OYAKAWA <e135764@ie.u-ryukyu.ac.jp>
date Fri, 17 Jul 2015 23:09:20 +0900
parents
children
comparison
equal deleted inserted replaced
0:347d21cdfc22 1:f7675884f2a1
1 /************************************************************************************
2
3 Copyright : Copyright 2014 Oculus VR, LLC. All Rights reserved.
4
5 Licensed under the Oculus VR Rift SDK License Version 3.2 (the "License");
6 you may not use the Oculus VR Rift SDK except in compliance with the License,
7 which is provided at the time of installation or download, or which
8 otherwise accompanies this software in either electronic or hard copy form.
9
10 You may obtain a copy of the License at
11
12 http://www.oculusvr.com/licenses/LICENSE-3.2
13
14 Unless required by applicable law or agreed to in writing, the Oculus VR SDK
15 distributed under the License is distributed on an "AS IS" BASIS,
16 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 See the License for the specific language governing permissions and
18 limitations under the License.
19
20 ************************************************************************************/
21
22 using UnityEngine;
23 using System.Collections.Generic;
24
25 /// <summary>
26 /// OVRGUI is a GUI help class that provides functions for drawing text and other elements
27 /// to the screen
28 /// </summary>
29 public class OVRGUI
30 {
31 private Font FontReplace = null;
32
33 private float PixelWidth = 1280.0f;
34 private float PixelHeight = 800.0f;
35
36 // DK1 resolution of W: (1280 / 2) H: 800
37 private float DisplayWidth = 1280.0f;
38 private float DisplayHeight = 800.0f;
39
40 private Rect DrawRect;
41
42 /// <summary>
43 /// Gets the replacement font.
44 /// </summary>
45 /// <param name="fontReplace">Font replace.</param>
46 public void GetFontReplace(ref Font fontReplace)
47 {
48 fontReplace = FontReplace;
49 }
50 /// <summary>
51 /// Sets the font replace.
52 /// </summary>
53 /// <param name="fontReplace">Font replace.</param>
54 public void SetFontReplace(Font fontReplace)
55 {
56 FontReplace = fontReplace;
57 }
58
59 /// <summary>
60 /// Gets the pixel resolution.
61 /// </summary>
62 /// <param name="pixelWidth">Pixel width.</param>
63 /// <param name="pixelHeight">Pixel height.</param>
64 public void GetPixelResolution(ref float pixelWidth, ref float pixelHeight)
65 {
66 pixelWidth = PixelWidth;
67 pixelHeight = PixelHeight;
68 }
69 /// <summary>
70 /// Sets the pixel resolution.
71 /// </summary>
72 /// <param name="pixelWidth">Pixel width.</param>
73 /// <param name="pixelHeight">Pixel height.</param>
74 public void SetPixelResolution(float pixelWidth, float pixelHeight)
75 {
76 PixelWidth = pixelWidth;
77 PixelHeight = pixelHeight;
78 }
79
80 /// <summary>
81 /// Gets the display resolution.
82 /// </summary>
83 /// <param name="Width">Width.</param>
84 /// <param name="Height">Height.</param>
85 public void GetDisplayResolution(ref float Width, ref float Height)
86 {
87 Width = DisplayWidth;
88 Height = DisplayHeight;
89 }
90 /// <summary>
91 /// Sets the display resolution.
92 /// </summary>
93 /// <param name="Width">Width.</param>
94 /// <param name="Height">Height.</param>
95 public void SetDisplayResolution(float Width, float Height)
96 {
97 DisplayWidth = Width;
98 DisplayHeight = Height;
99 }
100
101 /// <summary>
102 /// StereoBox
103 /// Values go from 0 - PixelSizeX/Y
104 /// </summary>
105 /// <param name="X">X.</param>
106 /// <param name="Y">Y.</param>
107 /// <param name="wX">W x.</param>
108 /// <param name="hY">H y.</param>
109 /// <param name="text">Text.</param>
110 /// <param name="color">Color.</param>
111 public void StereoBox(int X, int Y, int wX, int hY, ref string text, Color color)
112 {
113 Font prevFont = GUI.skin.font;
114 GUI.color = color;
115 // Make sure to change font if it needs replacement
116 if(GUI.skin.font != FontReplace) GUI.skin.font = FontReplace;
117
118 float s = PixelWidth / DisplayWidth;
119
120 CalcPositionAndSize(X * s, Y * s, wX * s, hY * s, ref DrawRect);
121
122 GUI.Box(DrawRect, text);
123
124 GUI.skin.font = prevFont;
125 }
126
127 /// <summary>
128 /// Stereos the box.
129 /// Values go from 0.0 - 1.0f; normalized approach to rendering GUI objects
130 /// </summary>
131 /// <param name="X">X.</param>
132 /// <param name="Y">Y.</param>
133 /// <param name="wX">W x.</param>
134 /// <param name="hY">H y.</param>
135 /// <param name="text">Text.</param>
136 /// <param name="color">Color.</param>
137 public void StereoBox(float X, float Y, float wX, float hY, ref string text, Color color)
138 {
139 StereoBox ((int)(X * PixelWidth),
140 (int)(Y * PixelHeight),
141 (int)(wX * PixelWidth),
142 (int)(hY * PixelHeight),
143 ref text, color);
144 }
145
146 /// <summary>
147 /// Draw a stereo texture.
148 /// </summary>
149 /// <param name="X">X.</param>
150 /// <param name="Y">Y.</param>
151 /// <param name="wX">W x.</param>
152 /// <param name="hY">H y.</param>
153 /// <param name="image">Image.</param>
154 /// <param name="color">Color.</param>
155 public void StereoDrawTexture(int X, int Y, int wX, int hY, ref Texture image, Color color)
156 {
157 GUI.color = color;
158 // Make sure to change font if it needs replacement
159 if(GUI.skin.font != FontReplace) GUI.skin.font = FontReplace;
160
161 float s = PixelWidth / DisplayWidth;
162
163 CalcPositionAndSize(X * s, Y * s, wX * s, hY * s, ref DrawRect);
164
165 GUI.DrawTexture(DrawRect, image);
166 }
167 /// <summary>
168 /// Draw a stereo texture.
169 /// </summary>
170 /// <param name="X">X.</param>
171 /// <param name="Y">Y.</param>
172 /// <param name="wX">W x.</param>
173 /// <param name="hY">H y.</param>
174 /// <param name="image">Image.</param>
175 /// <param name="color">Color.</param>
176 public void StereoDrawTexture(float X, float Y, float wX, float hY, ref Texture image, Color color)
177 {
178 StereoDrawTexture ((int)(X * PixelWidth),
179 (int)(Y * PixelHeight),
180 (int)(wX * PixelWidth),
181 (int)(hY * PixelHeight),
182 ref image, color);
183 }
184
185 /// <summary>
186 /// Calculates the size of the position.
187 /// </summary>
188 /// <param name="X">X.</param>
189 /// <param name="Y">Y.</param>
190 /// <param name="wX">W x.</param>
191 /// <param name="hY">H y.</param>
192 /// <param name="calcPosSize">Calculate position size.</param>
193 private void CalcPositionAndSize(float X, float Y, float wX, float hY,
194 ref Rect calcPosSize)
195 {
196 float sSX = (float)Screen.width / PixelWidth;
197 float sSY = (float)Screen.height / PixelHeight;
198
199 calcPosSize.x = X * sSX;
200 calcPosSize.width = wX * sSX;
201 calcPosSize.y = Y * sSY;
202 calcPosSize.height = hY * sSY;
203 }
204
205 }
206
207