Jypeli  9
The simple game programming library
Device.cs
Siirry tämän tiedoston dokumentaatioon.
1 #region MIT License
2 /*
3  * Copyright (c) 2009 University of Jyväskylä, Department of Mathematical
4  * Information Technology.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22  * THE SOFTWARE.
23  */
24 #endregion
25 
26 /*
27  * Authors: Tero Jäntti, Tomi Karppinen
28  */
29 
30 
31 namespace Jypeli.Devices
32 {
36  public class Device
37  {
40 
44  public Accelerometer Accelerometer { get; protected set; }
45 
49  public FileManager Storage { get; protected set; }
50 
54  public virtual bool IsMobileDevice
55  {
56  get { return false; }
57  }
58 
62  public virtual bool IsPhone
63  {
64  get { return false; }
65  }
66 
71  {
72  get { return _displayResolution; }
73  set
74  {
75  if ( _displayResolution == value )
76  return;
77 
78  _displayResolution = value;
79  if ( Game.Instance != null && Game.Screen != null ) ResetScreen();
80  }
81  }
82 
87  {
88  get { return _displayOrientation; }
89  set
90  {
91  if ( _displayOrientation == value )
92  return;
93 
94  _displayOrientation = value;
95  //Game.Instance.Accelerometer.DisplayOrientation = value;
96  if ( Game.Instance != null && Game.Screen != null ) UpdateScreen();
97  }
98  }
99 
100  protected Device()
101  {
102  // Initialize components as dummy ones if they're not initialized otherwise
103  if (this.Accelerometer == null)
104  this.Accelerometer = new DummyAccelerometer();
105  }
106 
107  internal static Device Create()
108  {
109 #if DESKTOP
110  return new ComputerDevice();
111 #elif ANDROID
112  return new Jypeli.Android.AndroidDevice();
113 #elif WINDOWS_PHONE81
114  return new WindowsPhone81Device();
115 #elif WINDOWS_UAP
116  return new WindowsUniversalDevice();
117 #elif WINRT
118  return new Windows8Device();
119 #else
120  return new Device();
121 #endif
122  }
123 
128  public virtual void Vibrate( int milliSeconds )
129  {
130  }
131 
135  public virtual void StopVibrating()
136  {
137  }
138 
139  protected virtual void UpdateScreen()
140  {
141  Vector defaultSize = Game.Screen.ViewportSize;
142  Vector defaultScale = Vector.Diagonal;
143 
145  {
146  defaultSize = new Vector( 400, 240 );
147  defaultScale = new Vector( Game.Screen.ViewportSize.X / defaultSize.X, Game.Screen.ViewportSize.Y / defaultSize.Y );
148  }
149 
151  {
152  Game.Screen.Size = defaultSize.Transpose();
153  Game.Screen.Scale = defaultScale.Transpose();
155  }
156  else
157  {
158  Game.Screen.Size = defaultSize;
159  Game.Screen.Scale = defaultScale;
161  }
162  }
163 
164  internal virtual void ResetScreen()
165  {
166  }
167  }
168 }
Jypeli.Devices.Device._displayOrientation
DisplayOrientation _displayOrientation
Definition: Device.cs:38
Jypeli.Devices.Device.IsMobileDevice
virtual bool IsMobileDevice
Onko laite mobiililaite.
Definition: Device.cs:55
Jypeli.Devices.Device.Storage
FileManager Storage
Tiedostojen säilytyspaikka.
Definition: Device.cs:49
Jypeli.Vector.X
double X
Definition: Vector.cs:312
Jypeli.ScreenView.Scale
Vector Scale
Näytön skaalaus.
Definition: View.cs:208
Jypeli.Devices.Device.IsPhone
virtual bool IsPhone
Onko laite puhelin.
Definition: Device.cs:63
Jypeli
Definition: Automobile.cs:5
Jypeli.Devices.Device.ResetScreen
virtual void ResetScreen()
Definition: Device.cs:164
Jypeli.Vector.Diagonal
static readonly Vector Diagonal
Diagonaalivektori (1,1)
Definition: Vector.cs:83
Jypeli.ScreenView.Angle
Angle Angle
Näytön kiertokulma.
Definition: View.cs:199
Jypeli.ScreenView.Size
Vector Size
Näytön koko vektorina.
Definition: View.cs:248
Jypeli.Devices.Device.Vibrate
virtual void Vibrate(int milliSeconds)
Värisyttää puhelinta.
Definition: Device.cs:128
Jypeli.DisplayOrientation.Landscape
static DisplayOrientation Landscape
Vaakasuuntainen.
Definition: DisplayOrientation.cs:23
Jypeli.DisplayOrientation.PortraitInverse
static DisplayOrientation PortraitInverse
Pystysuuntainen, ylösalaisin käännetty.
Definition: DisplayOrientation.cs:33
Jypeli.Devices.Device.Create
static Device Create()
Definition: Device.cs:107
Jypeli.ScreenView.ViewportSize
Vector ViewportSize
Näytön todellinen koko.
Definition: View.cs:284
Jypeli.Game.Instance
static Game Instance
Käynnissä olevan pelin pääolio.
Definition: Game.cs:90
Jypeli.Devices.Device._displayResolution
DisplayResolution _displayResolution
Definition: Device.cs:39
Jypeli.Game.Screen
static ScreenView Screen
Näytön dimensiot, eli koko ja reunat.
Definition: Graphics.cs:90
Jypeli.DisplayOrientation
Näytön asemointi.
Definition: DisplayOrientation.cs:9
Jypeli.DisplayResolution.Large
static readonly DisplayResolution Large
Suuri tarkkuus (WVGA, 800 x 480). Oletus WP8:lla.
Definition: DisplayResolution.cs:17
Jypeli.Devices.Device
Fyysinen laite.
Definition: Device.cs:37
Jypeli.Angle.Zero
static readonly Angle Zero
Nollakulma.
Definition: Angle.cs:44
Jypeli.Devices.Device.StopVibrating
virtual void StopVibrating()
Lopettaa puhelimen värinän.
Definition: Device.cs:135
Jypeli.Vector.Transpose
Vector Transpose()
Palauttaa uuden vektorin, jossa x ja y on vaihdettu keskenään.
Definition: Vector.cs:221
Jypeli.Devices
Definition: ComputerDevice.cs:2
Jypeli.DisplayOrientation.LandscapeRight
static DisplayOrientation LandscapeRight
Vaakasuuntainen, oikealle käännetty.
Definition: DisplayOrientation.cs:18
Jypeli.DisplayResolution.Small
static readonly DisplayResolution Small
Pieni tarkkuus (WVGA, 400 x 240). WP7-yhteensopivuustila, ei varsinaisesti paranna suorituskykyä.
Definition: DisplayResolution.cs:11
Jypeli.Vector
2D-vektori.
Definition: Vector.cs:59
Jypeli.Angle.RightAngle
static readonly Angle RightAngle
Suora kulma (90 astetta).
Definition: Angle.cs:49
Jypeli.Accelerometer
Definition: Accelerometer.cs:12
Jypeli.DisplayOrientation.Portrait
static DisplayOrientation Portrait
Pystysuuntainen.
Definition: DisplayOrientation.cs:28
Jypeli.Devices.Device.Device
Device()
Definition: Device.cs:100
Jypeli.Devices.ComputerDevice
Definition: ComputerDevice.cs:4
Jypeli.Devices.Device.UpdateScreen
virtual void UpdateScreen()
Definition: Device.cs:139
Jypeli.DummyAccelerometer
Definition: Accelerometer.cs:8
Jypeli.Game
Definition: Content.cs:46
Jypeli.FileManager
Definition: Assert.cs:6
Jypeli.DisplayResolution
Definition: DisplayResolution.cs:6
Jypeli.Angle.StraightAngle
static readonly Angle StraightAngle
Oikokulma (180 astetta).
Definition: Angle.cs:54
Jypeli.Vector.Y
double Y
Definition: Vector.cs:313
Jypeli.Angle
Suuntakulma (rajoitettu -180 ja 180 asteen välille) asteina ja radiaaneina. Tietoja kulmasta: http://...
Definition: Angle.cs:40