Jypeli 10
The simple game programming library
BarGauge.cs
Siirry tämän tiedoston dokumentaatioon.
1#region MIT License
2/*
3 * Copyright (c) 2009-2011 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, Janne Nikkanen.
28 */
29
30using Microsoft.Xna.Framework;
31
32namespace Jypeli.Widgets
33{
37 public class BarGauge : Widget
38 {
42 public enum BarDirection
43 {
47 BarVerticalUp,
51 BarHorizontalRight,
55 BarVerticalDown,
59 BarHorizontalLeft
60 };
61
62
63 private double h = -1;
64 private double w = -1;
65 private BarDirection direction = BarDirection.BarVerticalUp;
66
72 {
73 get { return direction; }
74 set
75 {
76 direction = value;
77 if (h == -1 && w == -1) { h = Height; w = Width; };
78 switch (value)
79 {
80 case BarDirection.BarVerticalUp:
82 Height = h; Width = w;
83 return;
84 case BarDirection.BarVerticalDown:
85 Angle = Angle.FromDegrees(180);
86 Height = h; Width = w;
87 return;
88 case BarDirection.BarHorizontalLeft:
89 Angle = Angle.FromDegrees(-90);
90 Height = w; Width = h;
91 return;
92 case BarDirection.BarHorizontalRight:
94 Height = w; Width = h;
95 return;
96 }
97
98 }
99 }
100
101 private static readonly Vector[] barVertices = new Vector[]
102 {
103 new Vector(-0.5, 0),
104 new Vector(0.5, 0),
105 new Vector(0.5, 1.0),
106 new Vector(-0.5, 1.0)
107 };
108
109 private static readonly IndexTriangle[] barIndices = new IndexTriangle[]
110 {
111 new IndexTriangle(0, 3, 2),
112 new IndexTriangle(0, 2, 1)
113 };
114
115 private static readonly ShapeCache shapeCache = new ShapeCache(barVertices, barIndices);
116
117 private static readonly DoubleMeter defaultMeter = new DoubleMeter( 0, 0, 100 );
118
120
124 public Color BarColor { get; set; }
125
129 public BarGauge(double width, double height)
130 : base(width, height)
131 {
134 }
135
140 public void BindTo(Meter meter)
141 {
142 boundMeter = meter;
143 }
144
146 public override void Draw(Matrix parentTransformation, Matrix transformation)
147 {
148 double barLength = Size.Y * boundMeter.RelativeValue;
149 Matrix m =
150 Matrix.CreateScale((float)Size.X, (float)barLength, 1f)
151 * Matrix.CreateTranslation(0, (float)(-Height / 2), 0)
152 * Matrix.CreateRotationZ((float)(Angle).Radians)
153 * Matrix.CreateTranslation((float)Position.X, (float)Position.Y, 0.0f)
154 * parentTransformation;
155
157
158 Vector[] borderVertices = new Vector[]
159 {
160 new Vector(-0.5, 0.5),
161 new Vector(-0.5, -0.5),
162 new Vector(0.5, -0.5),
163 new Vector(0.5, 0.5),
164 };
165
166 // The border that is drawn by base class gets obscured by the bar.
167 // Let's draw it again.
168 Renderer.DrawPolygon(borderVertices, ref transformation, BorderColor);
169
170 base.Draw(parentTransformation, transformation);
171
172 }
173 }
174}
Mittari, joka mittaa double-tyyppisiä arvoja. Sidottavissa näyttöihin, kuten ValueDisplay ja BarGa...
Definition: DoubleMeter.cs:11
override Vector?? Position
Definition: Dimensions.cs:72
override Vector Size
Olion koko pelimaailmassa. Kertoo olion äärirajat, ei muotoa.
Definition: Dimensions.cs:44
double Height
Olion korkeus (Y-suunnassa, korkeimmassa kohdassa).
double Width
Olion leveys (X-suunnassa, leveimmässä kohdassa).
Mittari, joka mittaa erityyppisiä arvoja. Sidottavissa näyttöihin, kuten ValueDisplay ja BarGauge.
Definition: Meter.cs:100
abstract double RelativeValue
Mittarin suhteellinen arvo (minimi 0, maksimi 1)
Definition: Meter.cs:65
Luokka, joka sisältää metodeita kuvioiden ja tekstuurien piirtämiseen 2D-tasossa.
Definition: Renderer.cs:50
static void DrawPolygon(Vector[] vertices, ref Matrix matrix, Color color)
Piirtää monikulmion ruudulle
Definition: Renderer.cs:460
static void DrawFilledShape(ShapeCache cache, ref Matrix matrix, Color color)
Definition: Renderer.cs:409
Sisältää valmiiksi lasketut kolmiot, joiden avulla piirtäminen on suoraviivaista.
Definition: Shapes.cs:628
Käyttöliittymän komponentti.
Definition: Appearance.cs:6
Color BorderColor
Reunojen väri.
Definition: Appearance.cs:10
Palkki, jonka korkeutta voi säätää.
Definition: BarGauge.cs:38
static readonly Vector[] barVertices
Definition: BarGauge.cs:101
static readonly ShapeCache shapeCache
Definition: BarGauge.cs:115
static readonly DoubleMeter defaultMeter
Definition: BarGauge.cs:117
BarDirection
Mihin suuntaa liut piirretään
Definition: BarGauge.cs:43
BarGauge(double width, double height)
Palkin rakentaja.
Definition: BarGauge.cs:129
void BindTo(Meter meter)
Asettaa palkin näyttämään meter-olion arvoa. Palkin maksimiarvoksi tulee olion meter maksimiarvo.
Definition: BarGauge.cs:140
static readonly IndexTriangle[] barIndices
Definition: BarGauge.cs:109
BarDirection direction
Definition: BarGauge.cs:65
override void Draw(Matrix parentTransformation, Matrix transformation)
Piirtää elementin ruudulle
Definition: BarGauge.cs:146
Color BarColor
Palkin väri.
Definition: BarGauge.cs:124
Microsoft.Xna.Framework.Matrix Matrix
Definition: Mouse.cs:36
Suuntakulma (rajoitettu -180 ja 180 asteen välille) asteina ja radiaaneina. Tietoja kulmasta: http://...
Definition: Angle.cs:40
static Angle FromDegrees(double degree)
Luo kulman annettujen asteiden mukaan.
Definition: Angle.cs:324
Väri.
Definition: Color.cs:13
static readonly Color Transparent
Läpinäkyvä väri.
Definition: Color.cs:931
static readonly Color Red
Punainen.
Definition: Color.cs:866
Perussuunta tasossa.
Definition: Direction.cs:47
Muotojen määrityksessä käytettävä kolmio.
Definition: Shapes.cs:598
2D-vektori.
Definition: Vector.cs:67
double Y
Vektorin Y-komponentti
Definition: Vector.cs:339
double X
Vektorin X-komponentti.
Definition: Vector.cs:334