Jypeli 10
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
30using System;
31using Microsoft.Xna.Framework;
32
33namespace Jypeli
34{
38 public class Canvas
39 {
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
99 public void Begin( ref Matrix worldMatrix, Dimensional dimensionSource )
100 {
103 Graphics.Canvas.Reset( dimensionSource );
104 this.worldMatrix = worldMatrix;
105 }
106
111 public void End()
112 {
115 }
116
117 private void Reset()
118 {
120 previousImage = null;
121 }
122
123 internal void Reset( Dimensional dimensionSource )
124 {
125 Reset();
126 Left = dimensionSource.Left;
127 Right = dimensionSource.Right;
128 Bottom = dimensionSource.Bottom;
129 Top = dimensionSource.Top;
130 TopLeft = new Vector( Left, Top );
131 TopRight = new Vector( Right, Top );
132 BottomLeft = new Vector( Left, Bottom );
133 BottomRight = new Vector( Right, Bottom );
134 }
135
141 public void DrawLine( Vector startPoint, Vector endPoint )
142 {
143 Graphics.LineBatch.Draw( startPoint, endPoint, BrushColor );
144 }
145
153 public void DrawLine( double x1, double y1, double x2, double y2 )
154 {
155 Graphics.LineBatch.Draw( new Vector( x1, y1 ), new Vector( x2, y2 ), BrushColor );
156 }
157
165 public void DrawImage( Vector point, Image image, Vector scale, Angle angle )
166 {
167 if ( !Object.ReferenceEquals( image, previousImage ) )
168 {
169 // Start a new batch with different image
172 previousImage = image;
173 }
174
175 Vector2 scaleV = new Vector2( (float)( image.Width * scale.X ), (float)( image.Height * scale.Y ) );
176 Graphics.ImageBatch.Draw( Graphics.DefaultTextureCoords, (Vector2)point, scaleV, (float)angle.Radians );
177 }
178
184 public void DrawImage( Vector point, Image image )
185 {
186 DrawImage( point, image, Vector.Diagonal, Angle.Zero );
187 }
188 }
189}
System.Numerics.Vector2 Vector2
Piirtoalusta.
Definition: Canvas.cs:39
Vector BottomRight
Oikea alanurkka.
Definition: Canvas.cs:81
double Top
Yläreuna.
Definition: Canvas.cs:61
Vector TopRight
Oikea ylänurkka.
Definition: Canvas.cs:71
void Reset()
Definition: Canvas.cs:117
void End()
Lopettaa piirtämisen. Sinun ei tarvitse kutsua tätä.
Definition: Canvas.cs:111
void Begin(ref Matrix worldMatrix, Dimensional dimensionSource)
Aloittaa canvaksen piirtämisen. Sinun ei tarvitse kutsua tätä.
Definition: Canvas.cs:99
void DrawLine(Vector startPoint, Vector endPoint)
Piirtää janan.
Definition: Canvas.cs:141
Vector TopLeft
Vasen ylänurkka.
Definition: Canvas.cs:66
Vector BottomLeft
Vasen alanurkka.
Definition: Canvas.cs:76
double Left
Vasen reuna.
Definition: Canvas.cs:46
void DrawLine(double x1, double y1, double x2, double y2)
Piirtää janan.
Definition: Canvas.cs:153
void DrawImage(Vector point, Image image)
Piirtää kuvan.
Definition: Canvas.cs:184
void DrawImage(Vector point, Image image, Vector scale, Angle angle)
Piirtää kuvan.
Definition: Canvas.cs:165
Image previousImage
Definition: Canvas.cs:40
void Reset(Dimensional dimensionSource)
Definition: Canvas.cs:123
double Bottom
Alareuna.
Definition: Canvas.cs:56
double Right
Oikea reuna.
Definition: Canvas.cs:51
Color BrushColor
Pensselin väri.
Definition: Canvas.cs:86
Matrix worldMatrix
Definition: Canvas.cs:41
Contains graphics resources.
Definition: Graphics.cs:36
static LineBatch LineBatch
Definition: Graphics.cs:49
static ImageBatch ImageBatch
Definition: Graphics.cs:47
static Canvas Canvas
Definition: Graphics.cs:51
static readonly TextureCoordinates DefaultTextureCoords
Definition: Graphics.cs:53
void Begin(ref Matrix matrix, Texture2D texture)
Definition: ImageBatch.cs:74
void Draw(TextureCoordinates c, Vector2 position, Vector2 size, float angle)
Definition: ImageBatch.cs:119
Kuva.
Definition: Image.cs:30
Texture2D XNATexture
Definition: Image.cs:72
int Width
Leveys pikseleinä.
Definition: Image.cs:374
int Height
Korkeus pikseleinä.
Definition: Image.cs:382
void Draw(Vector startPoint, Vector endPoint, Color color)
Definition: LineBatch.cs:48
void Begin(ref Matrix matrix)
Definition: LineBatch.cs:17
Olio jolla on reunat.
Definition: Dimensional.cs:7
double Left
Vasen reuna.
Definition: Dimensional.cs:11
double Bottom
Alareuna.
Definition: Dimensional.cs:26
double Top
Yläreuna.
Definition: Dimensional.cs:21
double Right
Oikea reuna.
Definition: Dimensional.cs:16
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 readonly Angle Zero
Nollakulma.
Definition: Angle.cs:44
double Radians
Palauttaa tai asettaa kulman radiaaneina.
Definition: Angle.cs:85
Väri.
Definition: Color.cs:13
static readonly Color Black
Musta.
Definition: Color.cs:556
2D-vektori.
Definition: Vector.cs:67
double Y
Vektorin Y-komponentti
Definition: Vector.cs:339
double X
Vektorin X-komponentti.
Definition: Vector.cs:334
static readonly Vector Diagonal
Diagonaalivektori (1,1)
Definition: Vector.cs:91