Jypeli  9
The simple game programming library
Canvas.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.
28  */
29 
30 using System;
31 using Microsoft.Xna.Framework;
32 
33 namespace Jypeli
34 {
38  public class Canvas
39  {
41  internal Matrix worldMatrix;
42 
46  public double Left { get; private set; }
47 
51  public double Right { get; private set; }
52 
56  public double Bottom { get; private set; }
57 
61  public double Top { get; private set; }
62 
66  public Vector TopLeft { get; private set; }
67 
71  public Vector TopRight { get; private set; }
72 
76  public Vector BottomLeft { get; private set; }
77 
81  public Vector BottomRight { get; private set; }
82 
86  public Color BrushColor { get; set; }
87 
88  internal Canvas()
89  {
90  Reset();
91  }
92 
93  public void Begin( ref Matrix worldMatrix, Dimensional dimensionSource )
94  {
96  Graphics.ImageBatch.Begin( ref worldMatrix, null );
97  Graphics.Canvas.Reset( dimensionSource );
98  this.worldMatrix = worldMatrix;
99  }
100 
101  public void End()
102  {
105  }
106 
107  private void Reset()
108  {
110  previousImage = null;
111  }
112 
113  internal void Reset( Dimensional dimensionSource )
114  {
115  Reset();
116  Left = dimensionSource.Left;
117  Right = dimensionSource.Right;
118  Bottom = dimensionSource.Bottom;
119  Top = dimensionSource.Top;
120  TopLeft = new Vector( Left, Top );
121  TopRight = new Vector( Right, Top );
122  BottomLeft = new Vector( Left, Bottom );
123  BottomRight = new Vector( Right, Bottom );
124  }
125 
131  public void DrawLine( Vector startPoint, Vector endPoint )
132  {
133  Graphics.LineBatch.Draw( startPoint, endPoint, BrushColor );
134  }
135 
143  public void DrawLine( double x1, double y1, double x2, double y2 )
144  {
145  Graphics.LineBatch.Draw( new Vector( x1, y1 ), new Vector( x2, y2 ), BrushColor );
146  }
147 
155  public void DrawImage( Vector point, Image image, Vector scale, Angle angle )
156  {
157  if ( !Object.ReferenceEquals( image, previousImage ) )
158  {
159  // Start a new batch with different image
162  previousImage = image;
163  }
164 
165  Vector2 scaleV = new Vector2( (float)( image.Width * scale.X ), (float)( image.Height * scale.Y ) );
166  Graphics.ImageBatch.Draw( Graphics.DefaultTextureCoords, (Vector2)point, scaleV, (float)angle.Radians );
167  }
168 
174  public void DrawImage( Vector point, Image image )
175  {
176  DrawImage( point, image, Vector.Diagonal, Angle.Zero );
177  }
178  }
179 }
Jypeli.LineBatch.End
void End()
Definition: LineBatch.cs:26
Jypeli.Color.Black
static readonly Color Black
Musta.
Definition: Color.cs:503
Jypeli.Graphics.ImageBatch
static ImageBatch ImageBatch
Definition: Graphics.cs:45
Jypeli.Canvas.Reset
void Reset()
Definition: Canvas.cs:107
Jypeli.Matrix
Microsoft.Xna.Framework.Matrix Matrix
Definition: Mouse.cs:36
Microsoft.Xna
Definition: JypeliContentManager.cs:6
Jypeli.Vector.X
double X
Definition: Vector.cs:312
Jypeli.Dimensional.Top
double Top
Yläreuna.
Definition: Dimensional.cs:21
Jypeli.ImageBatch.Begin
void Begin(ref Matrix matrix, Texture2D texture)
Definition: ImageBatch.cs:74
Jypeli.Graphics.DefaultTextureCoords
static readonly TextureCoordinates DefaultTextureCoords
Definition: Graphics.cs:51
Jypeli
Definition: Automobile.cs:5
Jypeli.Graphics.LineBatch
static LineBatch LineBatch
Definition: Graphics.cs:47
Jypeli.Vector.Diagonal
static readonly Vector Diagonal
Diagonaalivektori (1,1)
Definition: Vector.cs:83
Jypeli.Canvas.Reset
void Reset(Dimensional dimensionSource)
Definition: Canvas.cs:113
Microsoft
Definition: JypeliContentManager.cs:6
Jypeli.Canvas.Begin
void Begin(ref Matrix worldMatrix, Dimensional dimensionSource)
Definition: Canvas.cs:93
Jypeli.Canvas.End
void End()
Definition: Canvas.cs:101
Microsoft.Xna.Framework
Definition: JypeliContentManager.cs:6
Jypeli.Canvas.DrawLine
void DrawLine(double x1, double y1, double x2, double y2)
Piirtää janan.
Definition: Canvas.cs:143
Jypeli.Canvas.BrushColor
Color BrushColor
Pensselin väri.
Definition: Canvas.cs:86
Jypeli.Canvas.Canvas
Canvas()
Definition: Canvas.cs:88
Jypeli.Canvas.previousImage
Image previousImage
Definition: Canvas.cs:40
Jypeli.Canvas
Piirtoalusta.
Definition: Canvas.cs:39
Jypeli.Canvas.Top
double Top
Yläreuna.
Definition: Canvas.cs:61
Jypeli.Angle.Radians
double Radians
Palauttaa tai asettaa kulman radiaaneina.
Definition: Angle.cs:85
Jypeli.Dimensional.Right
double Right
Oikea reuna.
Definition: Dimensional.cs:16
Jypeli.Image.Height
int Height
Korkeus pikseleinä.
Definition: Image.cs:376
Jypeli.Image.XNATexture
Texture2D XNATexture
Definition: Image.cs:71
Jypeli.Canvas.Bottom
double Bottom
Alareuna.
Definition: Canvas.cs:56
Jypeli.Canvas.TopLeft
Vector TopLeft
Vasen ylänurkka.
Definition: Canvas.cs:66
Jypeli.Canvas.Left
double Left
Vasen reuna.
Definition: Canvas.cs:46
Jypeli.Canvas.DrawImage
void DrawImage(Vector point, Image image, Vector scale, Angle angle)
Piirtää kuvan.
Definition: Canvas.cs:155
Jypeli.Image.Width
int Width
Leveys pikseleinä.
Definition: Image.cs:368
Jypeli.Canvas.TopRight
Vector TopRight
Oikea ylänurkka.
Definition: Canvas.cs:71
Jypeli.Angle.Zero
static readonly Angle Zero
Nollakulma.
Definition: Angle.cs:44
Jypeli.Dimensional.Bottom
double Bottom
Alareuna.
Definition: Dimensional.cs:26
Jypeli.ImageBatch.Draw
void Draw(TextureCoordinates c, Vector2 position, Vector2 size, float angle)
Definition: ImageBatch.cs:119
Jypeli.Color
Väri.
Definition: Color.cs:13
Jypeli.Canvas.DrawImage
void DrawImage(Vector point, Image image)
Piirtää kuvan.
Definition: Canvas.cs:174
Jypeli.Dimensional.Left
double Left
Vasen reuna.
Definition: Dimensional.cs:11
Jypeli.Canvas.DrawLine
void DrawLine(Vector startPoint, Vector endPoint)
Piirtää janan.
Definition: Canvas.cs:131
Jypeli.Canvas.BottomRight
Vector BottomRight
Oikea alanurkka.
Definition: Canvas.cs:81
Jypeli.Canvas.BottomLeft
Vector BottomLeft
Vasen alanurkka.
Definition: Canvas.cs:76
Jypeli.Graphics
Contains graphics resources.
Definition: Graphics.cs:36
Jypeli.Image
Kuva.
Definition: Image.cs:29
Jypeli.Vector
2D-vektori.
Definition: Vector.cs:59
System
Definition: CFFauxAttributes.cs:29
Jypeli.Dimensional
Olio jolla on reunat.
Definition: Dimensional.cs:7
Jypeli.LineBatch.Draw
void Draw(Vector startPoint, Vector endPoint, Color color)
Definition: LineBatch.cs:48
Jypeli.LineBatch.Begin
void Begin(ref Matrix matrix)
Definition: LineBatch.cs:17
Jypeli.Canvas.worldMatrix
Matrix worldMatrix
Definition: Canvas.cs:41
Jypeli.Vector.Y
double Y
Definition: Vector.cs:313
Jypeli.ImageBatch.End
void End()
Definition: ImageBatch.cs:84
Jypeli.Canvas.Right
double Right
Oikea reuna.
Definition: Canvas.cs:51
Jypeli.Angle
Suuntakulma (rajoitettu -180 ja 180 asteen välille) asteina ja radiaaneina. Tietoja kulmasta: http://...
Definition: Angle.cs:40
Jypeli.Graphics.Canvas
static Canvas Canvas
Definition: Graphics.cs:49