PictureZBoxTransformation.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. namespace SOTF_Savegame_Editor.PictureZBoxHelper {
  7. public struct PictureZBoxTransformation {
  8. public Point Translation { get { return _translation; } }
  9. public double Scale { get { return _scale; } }
  10. private readonly Point _translation;
  11. private readonly double _scale = 1.0d;
  12. public PictureZBoxTransformation(Point translation, double scale) {
  13. _translation = translation;
  14. _scale = scale;
  15. }
  16. public Point ConvertToIm(Point p) {
  17. return new Point((int)(p.X * _scale + _translation.X), (int)(p.Y * _scale + _translation.Y));
  18. }
  19. public Size ConvertToIm(Size p) {
  20. return new Size((int)(p.Width * _scale), (int)(p.Height * _scale));
  21. }
  22. public Rectangle ConvertToIm(Rectangle r) {
  23. return new Rectangle(ConvertToIm(r.Location), ConvertToIm(r.Size));
  24. }
  25. public Point ConvertToPb(Point p) {
  26. return new Point((int)((p.X - _translation.X) / _scale), (int)((p.Y - _translation.Y) / _scale));
  27. }
  28. public Size ConvertToPb(Size p) {
  29. return new Size((int)(p.Width / _scale), (int)(p.Height / _scale));
  30. }
  31. public Rectangle ConvertToPb(Rectangle r) {
  32. return new Rectangle(ConvertToPb(r.Location), ConvertToPb(r.Size));
  33. }
  34. public PictureZBoxTransformation SetTranslate(Point p) {
  35. return new PictureZBoxTransformation(p, _scale);
  36. }
  37. public PictureZBoxTransformation SetTranslate(Point p, double scale) {
  38. return new PictureZBoxTransformation(p, scale);
  39. }
  40. public PictureZBoxTransformation AddTranslate(Point p) {
  41. return SetTranslate(new Point(p.X + _translation.X, p.Y + _translation.Y));
  42. }
  43. public PictureZBoxTransformation SetScale(double scale) {
  44. return new PictureZBoxTransformation(_translation, scale);
  45. }
  46. }
  47. }