Exemplo n.º 1
0
        protected void doResolveTopPick(DrawContext dc, Point pickPoint)
        {
            PickedObjectList pol = dc.getPickedObjects();

            if (pol != null && pol.size() == 1)
            {
                // If there is only one picked object, then it must be the top object so we're done.
                pol.get(0).setOnTop();
            }
            else if (pol != null && pol.size() > 1)
            {
                // If there is more than one picked object, then find the picked object corresponding to the top color at
                // the pick point, and mark it as on top
                int colorCode = dc.getPickColorAtPoint(pickPoint);
                if (colorCode != 0)
                {
                    foreach (PickedObject po in pol)
                    {
                        if (po != null && po.getColorCode() == colorCode)
                        {
                            po.setOnTop();
                            break; // No need to check the remaining picked objects.
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        public Position getCurrentPosition()
        {
            if (this.sceneController == null)
            {
                return(null);
            }

            PickedObjectList pol = this.getSceneController().getPickedObjectList();

            if (pol == null || pol.size() < 1)
            {
                return(null);
            }

            Position     p   = null;
            PickedObject top = pol.getTopPickedObject();

            if (top != null && top.hasPosition())
            {
                p = top.getPosition();
            }
            else if (pol.getTerrainObject() != null)
            {
                p = pol.getTerrainObject().getPosition();
            }

            return(p);
        }
Exemplo n.º 3
0
        protected PickedObjectList getCurrentBoxSelection()
        {
            if (this.sceneController == null)
            {
                return(null);
            }

            PickedObjectList pol = this.sceneController.getObjectsInPickRectangle();

            return(pol != null && pol.size() > 0 ? pol : null);
        }
Exemplo n.º 4
0
        protected PickedObject getCurrentSelection()
        {
            if (this.sceneController == null)
            {
                return(null);
            }

            PickedObjectList pol = this.getSceneController().getPickedObjectList();

            if (pol == null || pol.size() < 1)
            {
                return(null);
            }

            PickedObject top = pol.getTopPickedObject();

            return(top.isTerrain() ? null : top);
        }
Exemplo n.º 5
0
        protected void doResolveTopPick(DrawContext dc, Rectangle pickRect)
        {
            PickedObjectList pol = dc.getObjectsInPickRectangle();

            if (pol != null && pol.size() == 1)
            {
                // If there is only one picked object, then it must be the top object so we're done.
                pol.get(0).setOnTop();
            }
            else if (pol != null && pol.size() > 1)
            {
                int[] minAndMaxColorCodes = null;

                foreach (PickedObject po in pol)
                {
                    int colorCode = po.getColorCode();

                    // Put all of the eligible picked objects in a map to provide constant time access to a picked object
                    // by its color code. Since the number of unique color codes and picked objects may both be large, using
                    // a hash map reduces the complexity of the next loop from O(n*m) to O(n*c), where n and m are the
                    // lengths of the unique color list and picked object list, respectively, and c is the constant time
                    // associated with a hash map access.
                    this.pickableObjects.put(colorCode, po);

                    // Keep track of the minimum and maximum color codes of the scene's picked objects. These values are
                    // used to cull the number of colors that the draw context must consider with identifying the unique
                    // pick colors in the specified screen rectangle.
                    if (minAndMaxColorCodes == null)
                    {
                        minAndMaxColorCodes = new int[] { colorCode, colorCode }
                    }
                    ;
                    else
                    {
                        if (minAndMaxColorCodes[0] > colorCode)
                        {
                            minAndMaxColorCodes[0] = colorCode;
                        }
                        if (minAndMaxColorCodes[1] < colorCode)
                        {
                            minAndMaxColorCodes[1] = colorCode;
                        }
                    }
                }

                // If there is more than one picked object, then find the picked objects corresponding to each of the top
                // colors in the pick rectangle, and mark them all as on top.
                int[] colorCodes = dc.getPickColorsInRectangle(pickRect, minAndMaxColorCodes);
                if (colorCodes != null && colorCodes.length > 0)
                {
                    // Find the top picked object for each unique color code, if any, and mark it as on top.
                    foreach (int colorCode in colorCodes)
                    {
                        if (colorCode != 0) // This should never happen, but we check anyway.
                        {
                            PickedObject po = this.pickableObjects.get(colorCode);
                            if (po != null)
                            {
                                po.setOnTop();
                            }
                        }
                    }
                }

                // Clear the map of eligible picked objects so that the picked objects from this frame do not affect the
                // next frame. This also ensures that we do not leak memory by retaining references to picked objects.
                this.pickableObjects.clear();
            }
        }