Example usage for com.badlogic.gdx.math Vector2 Vector2

List of usage examples for com.badlogic.gdx.math Vector2 Vector2

Introduction

In this page you can find the example usage for com.badlogic.gdx.math Vector2 Vector2.

Prototype

public Vector2(float x, float y) 

Source Link

Document

Constructs a vector with the given components

Usage

From source file:CB_UI.GL_UI.Activitys.CreateTrackOverMapActivity.java

License:Open Source License

private void createControls() {
    float btWidth = innerWidth / 3;

    btnOk = new Button(
            new CB_RectF(leftBorder, this.getBottomHeight(), btWidth, UI_Size_Base.that.getButtonHeight()),
            onOkClik);//from w ww.  jav  a 2 s . c  o  m
    btnAdd = new Button(
            new CB_RectF(btnOk.getMaxX(), this.getBottomHeight(), btWidth, UI_Size_Base.that.getButtonHeight()),
            onAddClik);
    btnCancel = new Button(new CB_RectF(btnAdd.getMaxX(), this.getBottomHeight(), btWidth,
            UI_Size_Base.that.getButtonHeight()), onCancelClik);

    // translations
    btnOk.setText(Translation.Get("ok".hashCode()));
    btnAdd.setText(Translation.Get("addWP"));
    btnCancel.setText(Translation.Get("cancel".hashCode()));

    this.addChild(btnOk);
    this.addChild(btnAdd);
    this.addChild(btnCancel);

    lblName = new Label(Translation.Get("Name"));
    editName = new EditTextField(this.name + " editName");
    lblName.setRec(new CB_RectF(leftBorder, this.getHeight() - (lblName.getHeight() + margin),
            lblName.getWidth(), lblName.getHeight()));
    editName.setRec(new CB_RectF(lblName.getMaxX() + margin, lblName.getY(),
            innerWidth - (margin + lblName.getWidth()), lblName.getHeight()));
    this.addChild(lblName);
    this.addChild(editName);

    CB_RectF mapRec = new CB_RectF(leftBorder, btnOk.getMaxY() + margin, innerWidth,
            innerHeight - (btnOk.getHalfHeight() + editName.getHeight() + (4 * margin) + topBorder));

    mapView = new MapView(mapRec, MapMode.Track, "MapView");
    this.addChild(mapView);

    mapView.setOnLongClickListener(new OnClickListener() {

        @Override
        public boolean onClick(GL_View_Base v, int x, int y, int pointer, int button) {
            // chk if any TrackPoint clicked

            double minDist = Double.MAX_VALUE;
            WaypointRenderInfo minWpi = null;
            Vector2 clickedAt = new Vector2(x, y);

            for (int i = 0, n = tmplist.size(); i < n; i++) {
                WaypointRenderInfo wpi = tmplist.get(i);
                Vector2 screen = mapView.worldToScreen(new Vector2(Math.round(wpi.MapX), Math.round(wpi.MapY)));
                if (clickedAt != null) {
                    double aktDist = Math
                            .sqrt(Math.pow(screen.x - clickedAt.x, 2) + Math.pow(screen.y - clickedAt.y, 2));
                    if (aktDist < minDist) {
                        minDist = aktDist;
                        minWpi = wpi;
                    }
                }
            }

            if (minDist < 40) {
                selectedWP = minWpi.Waypoint;

                // Show PopUpMenu
                //               CB_RectF rec = new CB_RectF(x - 1, y - 1, 2, 2);
                //               CB_RectF mapWorld = mapView.getWorldRec();
                //               rec = rec.ScaleCenter(150);
                //               PopUpMenu menu = new PopUpMenu(rec, "popUpMenu");
                //               menu.setPos(mapWorld.getX() + x - menu.getHalfWidth(), mapView.getY() + y - menu.getHalfHeight());
                //               menu.showNotCloseAutomaticly();
            } else {
                selectedWP = null;
            }

            return true;
        }
    });

}

From source file:CB_UI.GL_UI.Activitys.EditFieldNotes.java

License:Open Source License

@Override
public boolean onTouchDown(int x, int y, int pointer, int button) {
    super.onTouchDown(x, y, pointer, button);

    if (etComment.contains(x, y)) {
        // TODO close SoftKeyboard
        scrollBox.setY(0);//from   www.jav a  2 s  .co  m
    }

    // for (Iterator<GL_View_Base> iterator = childs.iterator(); iterator.hasNext();)
    for (Iterator<GL_View_Base> iterator = scrollBox.getchilds().reverseIterator(); iterator.hasNext();) {
        // Child View suchen, innerhalb derer Bereich der touchDown statt gefunden hat.
        GL_View_Base view = iterator.next();

        if (view instanceof FilterSetListViewItem) {
            if (view.contains(x, y)) {
                ((FilterSetListViewItem) view).lastItemTouchPos = new Vector2(x - view.getX(), y - view.getY());
            }
        }
    }
    return true;
}

From source file:CB_UI.GL_UI.Controls.MapInfoPanel.java

License:Open Source License

@Override
protected void Initial() {
    this.removeChilds();

    setBackground(Sprites.InfoBack);/*  w w  w . java2 s . co  m*/

    // initial Image

    CB_RectF CompassRec = new CB_RectF(0, 0, this.getHeight(), this.getHeight());

    compass_frame = new Image(CompassRec, "Compass_Frame", false);
    compass_frame.setDrawable(Sprites.Compass.get(2));
    compass_frame.setOrigin(CompassRec.getWidth() / 2, CompassRec.getHeight() / 2);
    compass_frame.setScale(0.80f);
    this.addChild(compass_frame);

    compas_scale = new Image(CompassRec, "Compass_Scale", false);
    compas_scale.setDrawable(Sprites.Compass.get(3));
    compas_scale.setOrigin(CompassRec.getWidth() / 2, CompassRec.getHeight() / 2);
    compas_scale.setScale(0.80f);
    this.addChild(compas_scale);

    arrow = new Image(CompassRec, "Compass_Arrow", false);
    setArrowDrawable(true);
    arrow.setOrigin(CompassRec.getWidth() / 2, CompassRec.getHeight() / 2);
    arrow.setScale(0.50f);
    this.addChild(arrow);

    float margin = GL_UISizes.margin;

    lblSpeed = new Label(this.name + " lblSpeed", this.ScaleCenter(0.4f));
    lblSpeed.setFont(Fonts.getSmall());
    lblSpeed.setPos(new Vector2(CompassRec.getWidth() + margin, this.getHeight() * 0.1f));
    lblSpeed.setText("---");
    this.addChild(lblSpeed);

    lblDistance = new Label(this.name + " lblDistance", this.ScaleCenter(0.4f));
    lblDistance.setFont(Fonts.getBig());
    lblDistance.setPos(new Vector2(CompassRec.getWidth() + margin, CompassRec.getWidth() / 2));
    lblDistance.setText("---");
    this.addChild(lblDistance);

    lblLatitude = new Label(this.name + " lblLatitude", this.ScaleCenter(0.4f));
    lblLatitude.setFont(Fonts.getSmall());
    lblLatitude.setPos(
            new Vector2(this.getWidth() - lblLatitude.getWidth() - rightBorder, CompassRec.getWidth() / 2));
    lblLatitude.setText("---");
    this.addChild(lblLatitude);

    lblLongitude = new Label(this.name + " lblLongitude", this.ScaleCenter(0.4f));
    lblLongitude.setFont(Fonts.getSmall());
    lblLongitude.setPos(
            new Vector2(this.getWidth() - lblLongitude.getWidth() - rightBorder, this.getHeight() * 0.1f));
    lblLongitude.setText("---");
    this.addChild(lblLongitude);

    CoordSymbol = new Image((new CB_RectF(0, 0, this.getHeight(), this.getHeight())).ScaleCenter(0.62f),
            "CoordSymbol", false);
    CoordSymbol.setX(this.getWidth() - CoordSymbol.getWidth() - (rightBorder / 3));
    CoordSymbol.setDrawable(new SpriteDrawable(Sprites.getSprite("cache-icon")));
    this.addChild(CoordSymbol);
    CoordType tmp = lastCoordType;
    lastCoordType = CoordType.NULL;
    setCoordType(tmp);
}

From source file:CB_UI.GL_UI.Views.MapView.java

License:Open Source License

public MapView(CB_RectF rec, MapMode Mode, String Name) {
    super(rec, Name);
    // statischen that nur setzen wenn die HauptMapView initialisiert wird
    if (Mode == MapMode.Normal) {
        that = this;
    } else {//ww w  .j  a  v a 2  s. c o  m
        this.setOnDoubleClickListener(new OnClickListener() {

            @Override
            public boolean onClick(GL_View_Base v, int x, int y, int pointer, int button) {
                // Center own position!
                setCenter(Locator.getCoordinate());
                return true;
            }
        });
    }

    this.Mode = Mode;

    Config.MapsforgeDayTheme.addChangedEventListener(themeChangedEventHandler);
    Config.MapsforgeNightTheme.addChangedEventListener(themeChangedEventHandler);

    registerSkinChangedEvent();
    setBackground(Sprites.ListBack);
    int maxNumTiles = 0;
    // calculate max Map Tile cache
    try {
        int aTile = 256 * 256;
        maxTilesPerScreen = (int) ((rec.getWidth() * rec.getHeight()) / aTile + 0.5);

        maxNumTiles = (int) (maxTilesPerScreen * 6);// 6 times as much as necessary

    } catch (Exception e) {
        maxNumTiles = 60;
    }

    maxNumTiles = Math.min(maxNumTiles, 60);
    maxNumTiles = Math.max(maxNumTiles, 20);

    mapTileLoader.setMaxNumTiles(maxNumTiles);

    mapScale = new MapScale(new CB_RectF(GL_UISizes.margin, GL_UISizes.margin, this.getHalfWidth(),
            GL_UISizes.ZoomBtn.getHalfWidth() / 4), "mapScale", this, Config.ImperialUnits.getValue());

    if (Mode == MapMode.Normal) {
        this.addChild(mapScale);
    } else {
        mapScale.setInvisible();
    }

    // initial Zoom Buttons
    zoomBtn = new ZoomButtons(GL_UISizes.ZoomBtn, this, "ZoomButtons");

    zoomBtn.setX(this.getWidth() - (zoomBtn.getWidth() + UI_Size_Base.that.getMargin()));

    zoomBtn.setOnClickListenerDown(new OnClickListener() {
        @Override
        public boolean onClick(GL_View_Base v, int x, int y, int pointer, int button) {
            // bei einer Zoom Animation in negativer Richtung muss der setDiffCameraZoom gesetzt werden!
            // zoomScale.setDiffCameraZoom(-1.9f, true);
            // zoomScale.setZoom(zoomBtn.getZoom());
            zoomScale.resetFadeOut();
            inputState = InputState.Idle;

            lastDynamicZoom = zoomBtn.getZoom();

            kineticZoom = new KineticZoom(camera.zoom, MapTileLoader.getMapTilePosFactor(zoomBtn.getZoom()),
                    System.currentTimeMillis(), System.currentTimeMillis() + ZoomTime);
            GL.that.addRenderView(MapView.this, GL.FRAME_RATE_ACTION);
            GL.that.renderOnce();
            calcPixelsPerMeter();
            return true;
        }
    });
    zoomBtn.setOnClickListenerUp(new OnClickListener() {
        @Override
        public boolean onClick(GL_View_Base v, int x, int y, int pointer, int button) {
            setZoomScale(zoomBtn.getZoom());
            zoomScale.resetFadeOut();
            inputState = InputState.Idle;

            lastDynamicZoom = zoomBtn.getZoom();

            kineticZoom = new KineticZoom(camera.zoom, MapTileLoader.getMapTilePosFactor(zoomBtn.getZoom()),
                    System.currentTimeMillis(), System.currentTimeMillis() + ZoomTime);
            GL.that.addRenderView(MapView.this, GL.FRAME_RATE_ACTION);
            GL.that.renderOnce();
            calcPixelsPerMeter();
            return true;
        }
    });

    if (Mode == MapMode.Compass) {
        zoomBtn.setInvisible();
    } else {
        this.addChild(zoomBtn);
        zoomBtn.setMinimumFadeValue(0.25f);
    }

    this.setOnClickListener(onClickListener);

    float InfoHeight = 0;
    if (Mode == MapMode.Normal) {
        info = (MapInfoPanel) this.addChild(new MapInfoPanel(GL_UISizes.Info, "InfoPanel", this));
        InfoHeight = info.getHeight();
    }

    CB_RectF ZoomScaleRec = new CB_RectF();
    ZoomScaleRec.setSize((float) (44.6666667 * GL_UISizes.DPI),
            this.getHeight() - InfoHeight - (GL_UISizes.margin * 4) - zoomBtn.getMaxY());
    ZoomScaleRec.setPos(new Vector2(GL_UISizes.margin, zoomBtn.getMaxY() + GL_UISizes.margin));

    zoomScale = new ZoomScale(ZoomScaleRec, "zoomScale", 2, 21, 12);
    if (Mode == MapMode.Normal)
        this.addChild(zoomScale);

    mapIntWidth = (int) rec.getWidth();
    mapIntHeight = (int) rec.getHeight();
    drawingWidth = mapIntWidth;
    drawingHeight = mapIntHeight;

    InitializeMap();

    // initial Zoom Scale
    // zoomScale = new GL_ZoomScale(6, 20, 13);

    mapCacheList = new MapViewCacheList(MapTileLoader.MAX_MAP_ZOOM);

    // from create

    String[] currentLayerNames = Config.CurrentMapLayer.getValue();
    if (ManagerBase.Manager != null) {
        if (mapTileLoader.getCurrentLayer() == null) {
            mapTileLoader.setCurrentLayer(
                    ManagerBase.Manager.getOrAddLayer(currentLayerNames, currentLayerNames[0], ""));
        }
    }

    String[] currentOverlayLayerName = new String[] { Config.CurrentMapOverlayLayer.getValue() };
    if (ManagerBase.Manager != null) {
        if (mapTileLoader.getCurrentOverlayLayer() == null && currentOverlayLayerName[0].length() > 0)
            mapTileLoader.setCurrentOverlayLayer(
                    ManagerBase.Manager.getOrAddLayer(currentOverlayLayerName, currentOverlayLayerName[0], ""));
    }

    iconFactor = Config.MapViewDPIFaktor.getValue();

    liveButton = new LiveButton();
    liveButton.setState(Config.LiveMapEnabeld.getDefaultValue());
    Config.DisableLiveMap.addChangedEventListener(new IChanged() {
        @Override
        public void isChanged() {
            requestLayout();
        }
    });

    togBtn = new MultiToggleButton(GL_UISizes.Toggle, "toggle");

    togBtn.addState("Free", new HSV_Color(Color.GRAY));
    togBtn.addState("GPS", new HSV_Color(Color.GREEN));
    togBtn.addState("WP", new HSV_Color(Color.MAGENTA));
    togBtn.addState("Lock", new HSV_Color(Color.RED));
    togBtn.addState("Car", new HSV_Color(Color.YELLOW));
    togBtn.setLastStateWithLongClick(true);

    MapState last = MapState.values()[Config.LastMapToggleBtnState.getValue()];
    togBtn.setState(last.ordinal());

    togBtn.setOnStateChangedListener(new OnStateChangeListener() {

        @Override
        public void onStateChange(GL_View_Base v, int State) {
            setMapState(MapState.values()[State]);
        }
    });
    togBtn.registerSkinChangedEvent();

    switch (Mode) {
    case Compass:
        setMapState(MapState.GPS);
        break;
    case Normal:
        setMapState(last);
        break;
    case Track:
        setMapState(MapState.FREE);
        break;
    }

    if (Mode == MapMode.Normal) {
        switch (Config.LastMapToggleBtnState.getValue()) {
        case 0:
            info.setCoordType(CoordType.Map);
            break;
        case 1:
            info.setCoordType(CoordType.GPS);
            break;
        case 2:
            info.setCoordType(CoordType.Cache);
            break;
        case 3:
            info.setCoordType(CoordType.GPS);
            break;
        case 4:
            info.setCoordType(CoordType.GPS);
            break;
        }
    }

    if (Mode == MapMode.Normal) {
        this.addChild(togBtn);
        if (Config.DisableLiveMap.getValue()) {
            liveButton.setState(false);
        }
        this.addChild(liveButton);
    }

    infoBubble = new InfoBubble(GL_UISizes.Bubble, "infoBubble");
    infoBubble.setInvisible();
    infoBubble.setOnClickListener(new OnClickListener() {
        @Override
        public boolean onClick(GL_View_Base v, int x, int y, int pointer, int button) {
            if (infoBubble.saveButtonClicked(x, y)) {
                wd = CancelWaitDialog.ShowWait(Translation.Get("ReloadCacheAPI"),
                        DownloadAnimation.GetINSTANCE(), new IcancelListener() {
                            @Override
                            public void isCanceld() {

                            }
                        }, new cancelRunnable() {

                            @Override
                            public void run() {
                                String GcCode = infoBubble.getCache().getGcCode();

                                SearchGC searchC = new SearchGC(GcCode);
                                searchC.number = 1;
                                searchC.available = false;

                                CB_List<Cache> apiCaches = new CB_List<Cache>();
                                ArrayList<LogEntry> apiLogs = new ArrayList<LogEntry>();
                                ArrayList<ImageEntry> apiImages = new ArrayList<ImageEntry>();

                                try {
                                    CB_UI.SearchForGeocaches.getInstance().SearchForGeocachesJSON(searchC,
                                            apiCaches, apiLogs, apiImages,
                                            infoBubble.getCache().getGPXFilename_ID(), this);
                                    Cache c = apiCaches.get(0);
                                    if (c.getGcCode() == GcCode) {
                                        c.setApiStatus(Cache.NOTLITE);
                                    }
                                    GroundspeakAPI.WriteCachesLogsImages_toDB(apiCaches, apiLogs, apiImages);
                                } catch (InterruptedException e) {
                                    e.printStackTrace();
                                }

                                // Reload result from DB
                                synchronized (Database.Data.Query) {
                                    String sqlWhere = FilterInstances.getLastFilter()
                                            .getSqlWhere(Config.GcLogin.getValue());
                                    CacheListDAO cacheListDAO = new CacheListDAO();
                                    cacheListDAO.ReadCacheList(Database.Data.Query, sqlWhere, false,
                                            Config.ShowAllWaypoints.getValue());
                                }

                                CacheListChangedEventList.Call();
                                Cache selCache = Database.Data.Query.GetCacheByGcCode(GcCode);
                                GlobalCore.setSelectedCache(selCache);
                                infoBubble.setCache(selCache, null, true);
                                wd.close();
                            }

                            @Override
                            public boolean cancel() {
                                // TODO handle cancel
                                return false;
                            }
                        });
            } else {
                if (infoBubble.getWaypoint() == null) {
                    // Wenn ein Cache einen Final waypoint hat dann soll gleich dieser aktiviert werden
                    Waypoint waypoint = infoBubble.getCache().GetFinalWaypoint();
                    // wenn ein Cache keine Final hat, aber einen StartWaypointm, dann wird dieser gleich selektiert
                    if (waypoint == null)
                        waypoint = infoBubble.getCache().GetStartWaypoint();
                    GlobalCore.setSelectedWaypoint(infoBubble.getCache(), waypoint);
                } else {
                    GlobalCore.setSelectedWaypoint(infoBubble.getCache(), infoBubble.getWaypoint());
                }
            }

            infoBubble.setInvisible();
            return true;
        }
    });
    if (Mode == MapMode.Normal)
        this.addChild(infoBubble);

    resize(rec.getWidth(), rec.getHeight());

    try {
        center = new CoordinateGPS(Config.MapInitLatitude.getValue(), Config.MapInitLongitude.getValue());
    } catch (Exception e) {
        e.printStackTrace();
    }

    // Info aktualisieren
    if (Mode == MapMode.Normal)
        info.setCoord(center);
    aktZoom = Config.lastZoomLevel.getValue();
    zoomBtn.setZoom(aktZoom);
    calcPixelsPerMeter();
    mapScale.zoomChanged();

    if ((center.getLatitude() == -1000) && (center.getLongitude() == -1000)) {
        // not initialized
        center = new CoordinateGPS(48, 12);
    }

    // Initial SettingsChanged Events
    MapView.that.SetNightMode(Config.nightMode.getValue());
    Config.nightMode.addChangedEventListener(new IChanged() {
        @Override
        public void isChanged() {
            MapView.this.SetNightMode(Config.nightMode.getValue());
        }
    });

    MapView.that.SetNorthOriented(Config.MapNorthOriented.getValue());
    Config.MapNorthOriented.addChangedEventListener(new IChanged() {

        @Override
        public void isChanged() {
            MapView.this.SetNorthOriented(Config.MapNorthOriented.getValue());
            MapView.this.PositionChanged();
        }
    });

}

From source file:CB_UI.GL_UI.Views.MapView.java

License:Open Source License

private void RenderTargetArrow(Batch batch) {

    if (GlobalCore.getSelectedCache() == null)
        return;//from w  w  w  . j  a  v  a  2 s . co  m

    Coordinate coord = (GlobalCore.getSelectedWaypoint() != null) ? GlobalCore.getSelectedWaypoint().Pos
            : GlobalCore.getSelectedCache().Pos;

    if (coord == null) {
        return;
    }
    float x = (float) (256.0 * Descriptor.LongitudeToTileX(MapTileLoader.MAX_MAP_ZOOM, coord.getLongitude()));
    float y = (float) (-256.0 * Descriptor.LatitudeToTileY(MapTileLoader.MAX_MAP_ZOOM, coord.getLatitude()));

    float halfHeight = (mapIntHeight / 2) - ySpeedVersatz;
    float halfWidth = mapIntWidth / 2;

    // create ScreenRec
    try {
        if (TargetArrowScreenRec == null) {
            TargetArrowScreenRec = new CB_RectF(0, 0, mapIntWidth, mapIntHeight);
            if (Mode != MapMode.Compass) {
                TargetArrowScreenRec.ScaleCenter(0.9f);

                if (Mode == MapMode.Normal) {
                    TargetArrowScreenRec.setHeight(TargetArrowScreenRec.getHeight()
                            - (TargetArrowScreenRec.getHeight() - info.getY()) - zoomBtn.getHeight());
                    TargetArrowScreenRec.setY(zoomBtn.getMaxY());
                }
            }
        }

        Vector2 ScreenCenter = new Vector2(halfWidth, halfHeight);

        Vector2 screen = worldToScreen(new Vector2(x, y));
        Vector2 target = new Vector2(screen.x, screen.y);

        Vector2 newTarget = TargetArrowScreenRec.getIntersection(ScreenCenter, target);

        // Rotation berechnen
        if (newTarget != null) {

            float direction = get_angle(ScreenCenter.x, ScreenCenter.y, newTarget.x, newTarget.y);
            direction = 180 - direction;

            // draw sprite
            Sprite arrow = Sprites.Arrows.get(4);
            arrow.setRotation(direction);

            float boundsX = newTarget.x - GL_UISizes.TargetArrow.halfWidth;
            float boundsY = newTarget.y - GL_UISizes.TargetArrow.height;

            arrow.setBounds(boundsX, boundsY, GL_UISizes.TargetArrow.width, GL_UISizes.TargetArrow.height);

            arrow.setOrigin(GL_UISizes.TargetArrow.halfWidth, GL_UISizes.TargetArrow.height);
            arrow.draw(batch);

            // get real bounding box of TargetArrow
            float t[] = arrow.getVertices();
            float maxX = Math.max(Math.max(t[0], t[5]), Math.max(t[10], t[15]));
            float minX = Math.min(Math.min(t[0], t[5]), Math.min(t[10], t[15]));
            float maxY = Math.max(Math.max(t[1], t[6]), Math.max(t[11], t[16]));
            float minY = Math.min(Math.min(t[1], t[6]), Math.min(t[11], t[16]));
            TargetArrow.set(minX, minY, maxX - minX, maxY - minY);
        } else {
            TargetArrow.set(0, 0, 0, 0);
        }
    } catch (Exception e) {
        TargetArrow.set(0, 0, 0, 0);
    }
}

From source file:CB_UI.GL_UI.Views.MapView.java

License:Open Source License

public void renderWPI(Batch batch, SizeF WpUnderlay, SizeF WpSize, WaypointRenderInfo wpi) {
    Vector2 screen = worldToScreen(new Vector2(wpi.MapX, wpi.MapY));

    screen.y -= ySpeedVersatz;//from  w  w w  .j  a va 2  s . c om
    // FIXME create a LineDrawable class for create one times and set the Coordinates with calculated Triangles
    if (myPointOnScreen != null && showDirectLine && (wpi.Selected)
            && (wpi.Waypoint == GlobalCore.getSelectedWaypoint())) {
        // FIXME render only if visible on screen (intersect the screen rec)
        Quadrangle line = new Quadrangle(myPointOnScreen.x, myPointOnScreen.y, screen.x, screen.y,
                3 * UI_Size_Base.that.getScale());
        if (paint == null) {
            paint = new GL_Paint();
            paint.setGLColor(Color.RED);
        }
        PolygonDrawable po = new PolygonDrawable(line.getVertices(), line.getTriangles(), paint,
                this.mapIntWidth, this.mapIntHeight);
        po.draw(batch, 0, 0, this.mapIntWidth, this.mapIntHeight, 0);
        po.dispose();
    }
    // Don't render if outside of screen !!
    if ((screen.x < 0 - WpSize.width || screen.x > this.getWidth() + WpSize.height)
            || (screen.y < 0 - WpSize.height || screen.y > this.getHeight() + WpSize.height)) {
        if (wpi.Cache != null && (wpi.Cache.Id == infoBubble.getCacheId()) && infoBubble.isVisible()) {
            // check if wp selected
            if (wpi.Waypoint != null && wpi.Waypoint.equals(infoBubble.getWaypoint())
                    || wpi.Waypoint == null && infoBubble.getWaypoint() == null)
                infoBubble.setInvisible();
        }
        return;
    }

    float NameYMovement = 0;

    if ((aktZoom >= zoomCross) && (wpi.Selected) && (wpi.Waypoint == GlobalCore.getSelectedWaypoint())) {
        // Draw Cross and move screen vector
        Sprite cross = Sprites.MapOverlay.get(3);
        cross.setBounds(screen.x - WpUnderlay.halfWidth, screen.y - WpUnderlay.halfHeight, WpUnderlay.width,
                WpUnderlay.height);
        cross.draw(batch);

        screen.add(-WpUnderlay.width, WpUnderlay.height);
        NameYMovement = WpUnderlay.height;
    }

    if (wpi.UnderlayIcon != null) {
        wpi.UnderlayIcon.setBounds(screen.x - WpUnderlay.halfWidth, screen.y - WpUnderlay.halfHeight,
                WpUnderlay.width, WpUnderlay.height);
        wpi.UnderlayIcon.draw(batch);
    }
    if (wpi.Icon != null) {
        wpi.Icon.setBounds(screen.x - WpSize.halfWidth, screen.y - WpSize.halfHeight, WpSize.width,
                WpSize.height);
        wpi.Icon.draw(batch);
    }

    // draw Favorite symbol
    if (wpi.Cache != null && wpi.Cache.isFavorite()) {
        batch.draw(Sprites.getSprite(IconName.favorit.name()), screen.x + (WpSize.halfWidth / 2),
                screen.y + (WpSize.halfHeight / 2), WpSize.width, WpSize.height);
    }

    if (wpi.OverlayIcon != null) {
        wpi.OverlayIcon.setBounds(screen.x - WpUnderlay.halfWidth, screen.y - WpUnderlay.halfHeight,
                WpUnderlay.width, WpUnderlay.height);
        wpi.OverlayIcon.draw(batch);
    }

    boolean drawAsWaypoint = wpi.Waypoint != null;

    // Rating des Caches darstellen
    if (wpi.Cache != null && showRating && (!drawAsWaypoint) && (wpi.Cache.Rating > 0) && (aktZoom >= 15)) {
        Sprite rating = Sprites.MapStars.get((int) Math.min(wpi.Cache.Rating * 2, 5 * 2));
        rating.setBounds(screen.x - WpUnderlay.halfWidth,
                screen.y - WpUnderlay.halfHeight - WpUnderlay.Height4_8, WpUnderlay.width,
                WpUnderlay.Height4_8);
        rating.setOrigin(WpUnderlay.width / 2, WpUnderlay.Height4_8 / 2);
        rating.setRotation(0);
        rating.draw(batch);
        NameYMovement += WpUnderlay.Height4_8;
    }

    // Beschriftung
    if (wpi.Cache != null && showTitles && (aktZoom >= 15)) {
        try {
            String Name = drawAsWaypoint ? wpi.Waypoint.getTitle() : wpi.Cache.getName();

            if (layout == null)
                layout = new GlyphLayout(Fonts.getNormal(), Name);
            else
                layout.setText(Fonts.getNormal(), Name);

            float halfWidth = layout.width / 2;
            Fonts.getNormal().draw(batch, layout, screen.x - halfWidth,
                    screen.y - WpUnderlay.halfHeight - NameYMovement);
        } catch (Exception e) {
        }
    }

    // Show D/T-Rating
    if (wpi.Cache != null && showDT && (!drawAsWaypoint) && (aktZoom >= 15)) {
        Sprite difficulty = Sprites.MapStars.get((int) Math.min(wpi.Cache.getDifficulty() * 2, 5 * 2));
        difficulty.setBounds(screen.x - WpUnderlay.width - GL_UISizes.infoShadowHeight,
                screen.y - (WpUnderlay.Height4_8 / 2), WpUnderlay.width, WpUnderlay.Height4_8);
        difficulty.setOrigin(WpUnderlay.width / 2, WpUnderlay.Height4_8 / 2);
        difficulty.setRotation(90);
        difficulty.draw(batch);

        Sprite terrain = Sprites.MapStars.get((int) Math.min(wpi.Cache.getTerrain() * 2, 5 * 2));
        terrain.setBounds(screen.x + GL_UISizes.infoShadowHeight, screen.y - (WpUnderlay.Height4_8 / 2),
                WpUnderlay.width, WpUnderlay.Height4_8);
        terrain.setOrigin(WpUnderlay.width / 2, WpUnderlay.Height4_8 / 2);
        terrain.setRotation(90);
        terrain.draw(batch);

    }

    if (wpi.Cache != null && (wpi.Cache.Id == infoBubble.getCacheId()) && infoBubble.isVisible()) {
        if (infoBubble.getWaypoint() == wpi.Waypoint) {
            Vector2 pos = new Vector2(screen.x - infoBubble.getHalfWidth(), screen.y);
            infoBubble.setPos(pos);
        }
    }
}

From source file:CB_UI.GL_UI.Views.MapView.java

License:Open Source License

@Override
public void SelectedCacheChanged(Cache cache, Waypoint waypoint) {
    if (cache == null)
        return;/*w  ww. j av  a2s . c o m*/
    try {
        if ((cache == lastSelectedCache) && (waypoint == lastSelectedWaypoint)) {
            return;
        }
    } catch (Exception e) {
        return;
    }

    lastSelectedCache = cache;
    lastSelectedWaypoint = waypoint;
    /*
     * if (InvokeRequired) { Invoke(new targetChangedDelegate(OnTargetChanged), new object[] { cache, waypoint }); return; }
     */

    // mapCacheList = new MapViewCacheList(MAX_MAP_ZOOM);
    MapViewCacheListUpdateData data = new MapViewCacheListUpdateData(screenToWorld(new Vector2(0, 0)),
            screenToWorld(new Vector2(mapIntWidth, mapIntHeight)), aktZoom, true);
    data.hideMyFinds = this.hideMyFinds;
    data.showAllWaypoints = this.showAllWaypoints;
    mapCacheList.update(data);

    if (getCenterGps()) {
        PositionChanged();
        return;
    }

    positionInitialized = true;

    if (getMapState() != MapState.WP)
        setMapState(MapState.FREE);

    try {
        CoordinateGPS target = (waypoint != null)
                ? new CoordinateGPS(waypoint.Pos.getLatitude(), waypoint.Pos.getLongitude())
                : new CoordinateGPS(cache.Pos.getLatitude(), cache.Pos.getLongitude());
        setCenter(target);
    } catch (Exception e) {
    }

    GL.that.addRenderView(MapView.this, GL.FRAME_RATE_ACTION);

    // fr 2sec rendern lassen, bis nderungen der WPI-list neu berechnet wurden
    TimerTask task = new TimerTask() {
        @Override
        public void run() {
            GL.that.removeRenderView(MapView.this);
        }
    };

    Timer timer = new Timer();
    timer.schedule(task, 2000);
    PositionChanged();
}

From source file:CB_UI.GL_UI.Views.MapView.java

License:Open Source License

@Override
protected void loadTiles() {
    MapViewCacheListUpdateData data = new MapViewCacheListUpdateData(screenToWorld(new Vector2(0, 0)),
            screenToWorld(new Vector2(mapIntWidth, mapIntHeight)), aktZoom, false);
    data.hideMyFinds = this.hideMyFinds;
    data.showAllWaypoints = this.showAllWaypoints;
    mapCacheList.update(data);/*  w w w.j  av a2 s  . c  o m*/

    super.loadTiles();

    if (CarMode && CB_UI_Settings.LiveMapEnabeld.getValue()) {

        LiveMapQue.setCenterDescriptor(center);

        // LiveMap queue complete screen
        lo.Data = center;
        LiveMapQue.queScreen(lo, ru);
    }
}

From source file:CB_UI.GL_UI.Views.MapView.java

License:Open Source License

@Override
public void requestLayout() {
    // Log.debug(log, "MapView clacLayout()");
    float margin = GL_UISizes.margin;

    float infoHeight = 0;
    if (Mode == MapMode.Normal) {
        info.setPos(new Vector2(margin, this.mapIntHeight - margin - info.getHeight()));
        info.setVisible(showCompass);//w  w w . j a  v  a 2 s. c o  m
        infoHeight = info.getHeight();
    }
    togBtn.setPos(new Vector2(this.mapIntWidth - margin - togBtn.getWidth(),
            this.mapIntHeight - margin - togBtn.getHeight()));

    if (Config.DisableLiveMap.getValue()) {
        liveButton.setInvisible();
    } else {
        liveButton.setVisible();
    }

    liveButton.setRec(togBtn);
    liveButton.setY(togBtn.getY() - margin - liveButton.getHeight());

    zoomScale.setSize((float) (44.6666667 * GL_UISizes.DPI),
            this.getHeight() - infoHeight - (GL_UISizes.margin * 4) - zoomBtn.getMaxY());

    GL.that.renderOnce();
}

From source file:CB_UI.GL_UI.Views.MapView.java

License:Open Source License

@Override
protected void SkinIsChanged() {
    super.SkinIsChanged();
    MapViewCacheListUpdateData data = new MapViewCacheListUpdateData(screenToWorld(new Vector2(0, 0)),
            screenToWorld(new Vector2(mapIntWidth, mapIntHeight)), aktZoom, true);
    data.hideMyFinds = this.hideMyFinds;
    data.showAllWaypoints = this.showAllWaypoints;
    mapCacheList.update(data);/*from  www.j  av  a 2s  . c o m*/
    if (infoBubble.isVisible()) {
        infoBubble.setCache(infoBubble.getCache(), infoBubble.getWaypoint(), true);
    }
}