예제 #1
0
파일: Form1.cs 프로젝트: CMatri/FadeBar
        public void SelectBitmap(Bitmap bitmap, int opacity)
        {
            // Does this bitmap contain an alpha channel?
            if (bitmap.PixelFormat != PixelFormat.Format32bppArgb)
            {
                throw new ApplicationException("The bitmap must be 32bpp with alpha-channel.");
            }

            // Get device contexts
            IntPtr screenDc   = GetDC(IntPtr.Zero);
            IntPtr memDc      = CreateCompatibleDC(screenDc);
            IntPtr hBitmap    = IntPtr.Zero;
            IntPtr hOldBitmap = IntPtr.Zero;

            try
            {
                // Get handle to the new bitmap and select it into the current
                // device context.
                hBitmap    = bitmap.GetHbitmap(Color.FromArgb(0));
                hOldBitmap = SelectObject(memDc, hBitmap);

                // Set parameters for layered window update.
                PSize         newSize        = new PSize(bitmap.Width, bitmap.Height);
                PPoint        sourceLocation = new PPoint(0, 0);
                PPoint        newLocation    = new PPoint(this.Left, this.Top);
                BLENDFUNCTION blend          = new BLENDFUNCTION();
                blend.BlendOp             = AC_SRC_OVER;
                blend.BlendFlags          = 0;
                blend.SourceConstantAlpha = (byte)opacity;
                blend.AlphaFormat         = AC_SRC_ALPHA;

                // Update the window.
                UpdateLayeredWindow(
                    this.Handle,        // Handle to the layered window
                    screenDc,           // Handle to the screen DC
                    ref newLocation,    // New screen position of the layered window
                    ref newSize,        // New size of the layered window
                    memDc,              // Handle to the layered window surface DC
                    ref sourceLocation, // Location of the layer in the DC
                    0,                  // Color key of the layered window
                    ref blend,          // Transparency of the layered window
                    ULW_ALPHA           // Use blend as the blend function
                    );
            }
            finally
            {
                // Release device context.
                ReleaseDC(IntPtr.Zero, screenDc);
                if (hBitmap != IntPtr.Zero)
                {
                    SelectObject(memDc, hOldBitmap);
                    DeleteObject(hBitmap);
                }
                DeleteDC(memDc);
            }
        }
예제 #2
0
        /// <summary>
        /// Rounds all values of the coordinate to <paramref name="decimals"/> decimals.
        /// </summary>
        /// <param name="p"></param>
        /// <param name="decimals"></param>
        /// <returns></returns>
        public static PPoint RoundAll(this PPoint p, int decimals)
        {
            PPoint pc = new PPoint(
                Math.Round(p.X, decimals),
                Math.Round(p.Y, decimals),
                Math.Round(p.Z, decimals),
                Math.Round(p.T, decimals));

            pc.Axis = p.Axis;
            return(pc);
        }
예제 #3
0
파일: PPoint.cs 프로젝트: TrutzX/9Nations
        /// <summary>
        /// Compare points.
        /// </summary>
        public bool Equals(PPoint p)
        {
            // check if other is null
            if (ReferenceEquals(null, p))
            {
                return(false);
            }

            // Return true if the fields match:
            return((x == p.x) && (y == p.y));
        }
예제 #4
0
        public void DistanceDemo()
        {
            // Demo case from https://www.mkompf.com/gps/distcalc.html
            PPoint RusselsheimStation    = new PPoint(49.9917, 8.41321);
            PPoint RusselsheimOpelBridge = new PPoint(50.0049, 8.42182);
            PPoint BerlinBrandenburgGate = new PPoint(52.5164, 13.3777);
            PPoint LisbonTagusBridge     = new PPoint(38.692668, -9.177944);

            using (var ctx = new ProjContext())
                using (var wgs84 = CoordinateReferenceSystem.Create("EPSG:4326", ctx))
                {
                    Assert.AreEqual(1592.7, Math.Round(wgs84.DistanceTransform.GeoDistance(RusselsheimStation, RusselsheimOpelBridge), 1));

                    Assert.AreEqual(2318217, Math.Round(wgs84.DistanceTransform.GeoDistance(BerlinBrandenburgGate, LisbonTagusBridge)));
                }
        }
예제 #5
0
파일: PPoint.cs 프로젝트: TrutzX/9Nations
        /// <summary>
        /// Compare points.
        /// </summary>
        public override bool Equals(System.Object obj)
        {
            // check type
            if (!(obj.GetType() == typeof(PathFind.PPoint)))
            {
                return(false);
            }

            // check if other is null
            PPoint p = (PPoint)obj;

            if (ReferenceEquals(null, p))
            {
                return(false);
            }

            // Return true if the fields match:
            return((x == p.x) && (y == p.y));
        }
예제 #6
0
        /// <summary>
        /// Converts the <see cref="PPoint"/> to a <see cref="Coordinate"/>
        /// </summary>
        /// <param name="p"></param>
        /// <returns></returns>
        /// <remarks>Error PPoints are mapped to NULL</remarks>
        public static Coordinate ToCoordinate(this PPoint p)
        {
            if (!p.HasValues)
            {
                return(null); //
            }
            switch (p.Axis)
            {
            case 1:
            case 2:
                return(new Coordinate(p.X, p.Y));

            case 3:
                return(new CoordinateZ(p.X, p.Y, p.Z));

            case 4:
            default:
                return(new CoordinateZM(p.X, p.Y, p.Z, p.T));
            }
        }
예제 #7
0
        public MainWindow()
        {
            InitializeComponent();

            clients = new PPoint[256];
            for (int i = 0; i < clients.Length; ++i)
                clients[i] = new PPoint();

            this.doDraw = this.canDraw = this.connected = false;
            drawingBox.Background = new SolidColorBrush(Color.FromRgb(235, 235, 235));

            drawingBox.MouseEnter += drawingBox_MouseEnter;
            drawingBox.MouseLeave += drawingBox_MouseLeave;
            drawingBox.MouseMove += drawingBox_MouseMove;
            drawingBox.MouseLeftButtonDown += drawingBox_MouseLeftButtonDown;
            drawingBox.MouseLeftButtonUp += drawingBox_MouseLeftButtonUp;

            chooseColor.Click += chooseColor_Click;
            chooseBackgroundColor.Click += chooseBackgroundColor_Click;

            Random random = new Random();

            userBrush = new SolidColorBrush(Color.FromRgb((byte)random.Next(256), (byte)random.Next(256), (byte)random.Next(256)));

            udpClient = new UdpClient(addressField.Text, 22222);
            chosenColor.Background = userBrush;

            disconnectButton.IsEnabled = false;

            connectButton.Click += connectButton_Click;
            disconnectButton.Click += disconnectButton_Click;

            drawer = new BackgroundWorker();

            drawer.DoWork += drawer_DoWork;

            drawer.ProgressChanged += drawer_ProgressChanged;
        }
예제 #8
0
        public void NtsMeterDistance()
        {
            PPoint amersfoortRD = new PPoint(155000, 463000);

            var srid = SridRegister.GetById(Epsg.Netherlands);

            var t1 = CreateTriangle(srid.Factory, amersfoortRD.Offset(-50000, 0).ToCoordinate(), 5000);
            var t2 = CreateTriangle(srid.Factory, amersfoortRD.Offset(20, 50000).ToCoordinate(), 5000);
            var t3 = CreateTriangle(srid.Factory, amersfoortRD.ToCoordinate(), 100000);


            Assert.AreEqual(300000, Math.Round(t3.ExteriorRing.Length, 5));                       // Pythagoras. By definition

            Assert.AreEqual(65908.18, Math.Round(t1.Distance(t2), 2), "Distance pythagoras");     // Pythagoras
            Assert.AreEqual(65913.62, Math.Round(t1.MeterDistance(t2).Value, 2), "Geo distance"); // Via NL CRS



            Assert.AreEqual(300024.180, Math.Round(t3.ExteriorRing.MeterLength().Value, 3));



            Assert.IsTrue(t1.IsWithinMeterDistance(t2, 70000).Value);
            Assert.IsFalse(t2.IsWithinMeterDistance(t1, 64000).Value);


            Assert.IsTrue(t1.Centroid.Coordinate.Equals3D(t1.Centroid.Coordinate));

            Assert.AreEqual(4330127018.92, Math.Round(t3.Area, 2));

            // Test the raw (signed) operations to return the same thing. On polygon the value is taken absolute (unsigned)
            Assert.AreEqual(4330127018.92, Math.Round(NetTopologySuite.Algorithm.Area.OfRingSigned(t3.ExteriorRing.Coordinates), 2));
            Assert.AreEqual(4330957964.64, Math.Round(srid.CRS.DistanceTransform.GeoArea(t3.Coordinates), 2));

            Assert.AreEqual(4330957964.64, Math.Round(t3.MeterArea().Value, 2)); // Not using backing data yet
        }
예제 #9
0
    public List <Vector3> GetPath(GameObject starting_point, GameObject ending_point)
    {
        List <Vector3> ret = new List <Vector3>();

        if (IsPoint(starting_point) && IsPoint(ending_point))
        {
            // Expand --------- (BFS)

            List <PPoint> frontier      = new List <PPoint>();
            List <PPoint> memory_points = new List <PPoint>();

            PPoint point = new PPoint();
            point.point = starting_point;
            frontier.Add(point);

            while (frontier.Count > 0)
            {
                memory_points.Add(frontier[0]);

                if (frontier[0].point == ending_point)
                {
                    break;
                }

                NavigationPoint np = frontier[0].point.GetComponent <NavigationPoint>();

                List <GameObject> neigh = np.GetNeighbours();

                for (int i = 0; i < neigh.Count; i++)
                {
                    PPoint npoint = new PPoint();
                    npoint.parent = frontier[0].point;
                    npoint.point  = neigh[i];

                    bool exists = false;
                    for (int y = 0; y < memory_points.Count; y++)
                    {
                        if (memory_points[y].point == npoint.point)
                        {
                            exists = true;
                            break;
                        }
                    }

                    if (!exists)
                    {
                        frontier.Add(npoint);
                    }
                }

                frontier.RemoveAt(0);
            }

            // ----------------

            // Backtrack ------

            PPoint curr_point = memory_points[memory_points.Count - 1];

            while (memory_points.Count > 0)
            {
                ret.Add(curr_point.point.transform.position);

                if (curr_point.point == starting_point)
                {
                    Debug.Log("Pathfinding finished correctly");
                    break;
                }

                memory_points.RemoveAt(memory_points.Count - 1);

                for (int i = 0; i < memory_points.Count; i++)
                {
                    if (memory_points[i].point == curr_point.parent)
                    {
                        curr_point = memory_points[i];
                        break;
                    }
                }
            }

            // ----------------
        }

        return(ret);
    }
예제 #10
0
 public static SKPoint ToSKPoint(this PPoint pPoint)
 {
     return(new SKPoint(pPoint.X, pPoint.Y));
 }
예제 #11
0
파일: Form1.cs 프로젝트: CMatri/FadeBar
 static extern bool UpdateLayeredWindow(IntPtr hwnd, IntPtr hdcDst,
                                        ref PPoint pptDst, ref PSize psize, IntPtr hdcSrc, ref PPoint pprSrc,
                                        Int32 crKey, ref BLENDFUNCTION pblend, Int32 dwFlags);
예제 #12
0
파일: PPoint.cs 프로젝트: TrutzX/9Nations
 /// <summary>
 /// Init the point with a single value.
 /// </summary>
 public PPoint(PPoint b)
 {
     x = b.x;
     y = b.y;
 }