Jypeli  9
The simple game programming library
ProgressBar.cs
Siirry tämän tiedoston dokumentaatioon.
2 
3 namespace Jypeli.Widgets
4 {
8  public class ProgressBar : BindableWidget
9  {
10  // private double h = -1;
11  // private double w = -1;
12 
13  private static readonly Vector[] barVertices = new Vector[]
14  {
15  new Vector(-0.5, 0),
16  new Vector(0.5, 0),
17  new Vector(0.5, 1.0),
18  new Vector(-0.5, 1.0)
19  };
20 
21  private static readonly IndexTriangle[] barIndices = new IndexTriangle[]
22  {
23  new IndexTriangle(0, 3, 2),
24  new IndexTriangle(0, 2, 1)
25  };
26 
27  private static readonly Vector[] borderVertices = new Vector[]
28  {
29  new Vector(-0.5, 0.5),
30  new Vector(-0.5, -0.5),
31  new Vector(0.5, -0.5),
32  new Vector(0.5, 0.5),
33  };
34 
35  private static readonly ShapeCache shapeCache = new ShapeCache(barVertices, barIndices);
36 
41  public Image BarImage { get; set; }
42 
46  public Color BarColor { get; set; }
47 
53  public ProgressBar(double width, double height)
54  : base(width, height)
55  {
57  BarColor = Color.Red;
58  BarImage = null;
59  }
60 
67  public ProgressBar(double width, double height, Meter meter)
68  : this(width, height)
69  {
70  BindTo(meter);
71  }
72 
76 
77  protected override void UpdateValue()
78  {
79  double barLength = Size.X * Meter.RelativeValue;
80 
81  imgPart =
82  Matrix.CreateScale((float)barLength, (float)Size.Y, 1f)
83  * Matrix.CreateTranslation((float)(barLength / 2), 0, 0)
84  * Matrix.CreateTranslation((float)(-Width / 2), 0, 0)
85  * Matrix.CreateRotationZ((float)(Angle).Radians)
86  * Matrix.CreateTranslation((float)Position.X, (float)Position.Y, 0.0f);
87 
88  imgFull =
89  Matrix.CreateScale((float)Size.X, (float)Size.Y, 1f)
90  * Matrix.CreateRotationZ((float)(Angle).Radians)
91  * Matrix.CreateTranslation((float)Position.X, (float)Position.Y, 0.0f);
92 
93  colorPart =
94  Matrix.CreateScale((float)barLength, (float)Size.Y, 1f)
95  * Matrix.CreateTranslation((float)(barLength / 2), 0, 0)
96  * Matrix.CreateTranslation((float)(-Width / 2), (float)(-Height / 2), 0)
97  * Matrix.CreateRotationZ((float)(Angle).Radians)
98  * Matrix.CreateTranslation((float)Position.X, (float)Position.Y, 0.0f);
99  }
100 
101  public override void Draw(Matrix parentTransformation, Matrix transformation)
102  {
103  // TODO: Optimization?
104  UpdateValue();
105 
106  if (BarImage != null)
107  {
108  Matrix imp = imgPart * parentTransformation;
109  Matrix imf = imgFull * parentTransformation;
110 
112  Renderer.DrawImage(BarImage, ref imf, TextureWrapSize);
114  }
115  else
116  {
117  Matrix m = colorPart * parentTransformation;
119  }
120 
121  // The border that is drawn by base class gets obscured by the bar.
122  // Let's draw it again.
123  Renderer.DrawPolygon(borderVertices, ref transformation, BorderColor);
124 
125  base.Draw(parentTransformation, transformation);
126  }
127  }
128 }
Jypeli.Meter
Mittari, joka mittaa erityyppisiä arvoja. Sidottavissa näyttöihin, kuten ValueDisplay ja BarGauge.
Definition: Meter.cs:61
Jypeli.Widgets.ProgressBar.imgPart
Matrix imgPart
Definition: ProgressBar.cs:74
Jypeli.Renderer
Luokka, joka sisältää metodeita kuvioiden ja tekstuurien piirtämiseen 2D-tasossa.
Definition: Renderer.cs:48
Jypeli.Matrix
Microsoft.Xna.Framework.Matrix Matrix
Definition: Mouse.cs:36
Microsoft.Xna
Definition: JypeliContentManager.cs:6
Jypeli.Widgets.BindableWidget.BindTo
virtual void BindTo(Meter meter)
Asettaa kontrollin seuraamaan mittarin arvoa.
Definition: BindableWidget.cs:108
Jypeli.Color.Red
static readonly Color Red
Punainen.
Definition: Color.cs:813
Jypeli.Widgets.ProgressBar.colorPart
Matrix colorPart
Definition: ProgressBar.cs:75
Jypeli.Renderer.DrawFilledShape
static void DrawFilledShape(ShapeCache cache, ref Matrix matrix, Color color)
Definition: Renderer.cs:365
Jypeli.ShapeCache
Sisältää valmiiksi lasketut kolmiot, joiden avulla piirtäminen on suoraviivaista.
Definition: Shapes.cs:583
Jypeli.Widgets.ProgressBar.BarColor
Color BarColor
Palkin väri.
Definition: ProgressBar.cs:46
Microsoft
Definition: JypeliContentManager.cs:6
Microsoft.Xna.Framework
Definition: JypeliContentManager.cs:6
Jypeli.Widgets.ProgressBar.BarImage
Image BarImage
Palkin kuva. Jos erisuuri kuin null, piirretään värin (BarColor) sijasta.
Definition: ProgressBar.cs:41
Jypeli.Widgets.ProgressBar.barVertices
static readonly Vector[] barVertices
Definition: ProgressBar.cs:13
Jypeli.Shape
Kuvio.
Definition: Shapes.cs:47
Jypeli.Widgets.ProgressBar
Palkki, jolla voidaan ilmaista mittarin arvoa graafisesti.
Definition: ProgressBar.cs:9
Jypeli.Widgets.BindableWidget
Widget, joka voidaan asettaa näyttämään halutun mittarin arvoa.
Definition: BindableWidget.cs:9
Jypeli.Shape.Rectangle
static readonly Rectangle Rectangle
Suorakulmio.
Definition: Shapes.cs:70
Jypeli.Color.Transparent
static readonly Color Transparent
Läpinäkyvä väri.
Definition: Color.cs:878
Jypeli.Widgets.ProgressBar.imgFull
Matrix imgFull
Definition: ProgressBar.cs:73
Jypeli.Widgets.ProgressBar.ProgressBar
ProgressBar(double width, double height)
Palkin rakentaja.
Definition: ProgressBar.cs:53
Jypeli.Renderer.DrawImage
static void DrawImage(Image texture, ref Matrix matrix, Vector wrapSize)
Definition: Renderer.cs:122
Jypeli.Widgets.ProgressBar.borderVertices
static readonly Vector[] borderVertices
Definition: ProgressBar.cs:27
Jypeli.Color
Väri.
Definition: Color.cs:13
Jypeli.Widgets.ProgressBar.ProgressBar
ProgressBar(double width, double height, Meter meter)
Palkin rakentaja. Sitoo palkin arvon mittarin arvoon.
Definition: ProgressBar.cs:67
Jypeli.Renderer.EndDrawingInsideShape
static void EndDrawingInsideShape()
Definition: Renderer.cs:256
Jypeli.Widgets.ProgressBar.UpdateValue
override void UpdateValue()
Kutsutaan automaattisesti, kun mittarin arvo on muuttunut. Ylikirjoita tämä koodilla,...
Definition: ProgressBar.cs:77
Jypeli.IndexTriangle
Muotojen määrityksessä käytettävä kolmio.
Definition: Shapes.cs:553
Jypeli.Widgets
Definition: Background.cs:34
Jypeli.Image
Kuva.
Definition: Image.cs:29
Jypeli.Vector
2D-vektori.
Definition: Vector.cs:59
Jypeli.Widgets.ProgressBar.shapeCache
static readonly ShapeCache shapeCache
Definition: ProgressBar.cs:35
Jypeli.Widget.BorderColor
Color BorderColor
Reunojen väri.
Definition: Appearance.cs:10
Jypeli.Renderer.BeginDrawingInsideShape
static void BeginDrawingInsideShape(Shape shape, ref Matrix transformation)
Makes all the subsequent draw calls until EndDrawingInsideShape limit the drawing inside shape (trans...
Definition: Renderer.cs:238
Jypeli.Widgets.ProgressBar.barIndices
static readonly IndexTriangle[] barIndices
Definition: ProgressBar.cs:21
Jypeli.Widgets.ProgressBar.Draw
override void Draw(Matrix parentTransformation, Matrix transformation)
Definition: ProgressBar.cs:101
Jypeli.Renderer.DrawPolygon
static void DrawPolygon(Vector[] vertices, ref Matrix matrix, Color color)
Definition: Renderer.cs:410
Jypeli.Angle
Suuntakulma (rajoitettu -180 ja 180 asteen välille) asteina ja radiaaneina. Tietoja kulmasta: http://...
Definition: Angle.cs:40