Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public abstract class DrawObject
- {
- public float TransformX = 0f, TransformY = 0f;
- public float Rotation = 0f;
- public float Scale = 1f;
- public float CenterX = 0f, CenterY = 0f;
- }
- public class GraphicsHandler
- {
- public static void DrawObject(DrawObject obj, Canvas canvas, Matrix matrix, float scaleX, float scaleY)
- {
- if (obj == null)
- return;
- DrawObject(obj, canvas, matrix, scaleX, scaleY, 1f, 1f);
- if (obj.DrawingMode == DrawMode.VMirror || obj.DrawingMode == DrawMode.VHMirror)
- DrawObject(obj, canvas, matrix, scaleX, scaleY, -1f, 1f);
- if (obj.DrawingMode == DrawMode.HMirror || obj.DrawingMode == DrawMode.VHMirror)
- DrawObject(obj, canvas, matrix, scaleX, scaleY, -1f, -1f);
- if (obj.DrawingMode == DrawMode.VHMirror)
- DrawObject(obj, canvas, matrix, scaleX, scaleY, 1f, -1f);
- }
- // scaleX and scaleY are the scale of the screen. If the original size is 1000x1000 but this is rendered on a 500x500 screen
- // the scale is 0.5 and 0.5
- // sX and and sY are the flip values
- public static void DrawObject(DrawObject obj, Canvas canvas, Matrix matrix, float scaleX, float scaleY, float sx, float sy)
- {
- canvas.save();
- try
- {
- if (matrix == null)
- matrix = new Matrix();
- matrix.reset();
- matrix.setScale(scaleX, scaleY);
- matrix.postScale(sx, sy, (canvas.getWidth())*0.5f, (canvas.getHeight())*0.5f);
- canvas.setMatrix(matrix);
- }
- catch (Exception ex) { }
- try
- {
- canvas.rotate(obj.Rotation, obj.CenterX + obj.TransformX, obj.CenterY + obj.TransformY);
- canvas.translate(obj.TransformX, obj.TransformY);
- canvas.scale(obj.Scale, obj.Scale, obj.CenterX, obj.CenterY);
- // each DrawObject handles it's own drawing: Rectangle, Path and suchs...
- obj.Draw(canvas);
- }
- catch (Exception ex) { }
- canvas.restore();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement